#! /usr/bin/make -f

.PHONY: build clean binary binary-indep binary-arch checkdir checkroot

package = timidity-patches
d=$(shell pwd)/debian/tmp

build: checkdir

clean: checkdir
	rm -rf debian/{files,substvars,tmp}
	find . -name \*~ -print0 | xargs -0 $(RM)

binary:	binary-indep binary-arch

binary-arch:

binary-indep:
	rm -rf $(d)

	install -d $(d)/DEBIAN 
	install -d $(d)/usr/lib/timidity/patches
	install -d $(d)/usr/doc/$(package)

	cp -p cfg/*.cfg $(d)/usr/lib/timidity/patches
	cp -p pat/*.pat $(d)/usr/lib/timidity/patches

	cp debian/changelog $(d)/usr/doc/$(package)/changelog.Debian
	gzip -9v $(d)/usr/doc/$(package)/*
	cp debian/copyright $(d)/usr/doc/$(package)/copyright

	chown -R root.root $(d)
	find $(d) \! -type d -print0 | xargs -0 chmod 644
	find $(d) -type d -print0 | xargs -0 chmod 755

	dpkg-gencontrol -p$(package) -P$(d)
	dpkg --build $(d) ..

checkdir:
	test -d pat

checkroot:
	test "`whoami`" = "root"
