#!/usr/bin/make -f

package = gcc-m68k-gnu
docdir = debian/tmp/usr/doc/$(package)

build:
	$(checkdir)
	touch build

clean:
	$(checkdir)
	-rm -f build
	-rm -f `find . -name "*~"`
	-rm -rf debian/tmp debian/files* core debian/substvars

binary-indep: checkroot build
	$(checkdir)

binary-arch: checkroot build
	$(checkdir)
	-rm -rf debian/tmp
	install -d debian/tmp/DEBIAN $(docdir)
	cd debian/tmp && install -d usr
	sh debian/populate-debian-tmp
	ln -s gcc debian/tmp/usr/m68k-gnu/bin/cc
	ln -s /gnu/lib debian/tmp/usr/m68k-gnu/lib
	ln -s /gnu/include debian/tmp/usr/m68k-gnu/include
	sh debian/putldso
	cp -p debian/copyright debian/README $(docdir)
	cp -p debian/changelog $(docdir)/changelog.Debian
	cp -p ChangeLog $(docdir)/changelog
	cd $(docdir) && gzip -9 changelog changelog.Debian
	dpkg-gencontrol
	chown -R root.root debian/tmp
	chmod -R go=rX debian/tmp
	dpkg --build debian/tmp ..

define checkdir
	test -f debian/rules
endef

binary: binary-indep binary-arch

checkroot:
	$(checkdir)
	test root = "`whoami`"

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