#!/usr/bin/make -f

p=$(shell sed '1s/Source: \(.*\)/\1/; 2,$$d' debian/control)
v=1.1

build:
	$(checkdir)
	make $p LIBDIR="/etc/uucp" VERSION=\"$(v)\"
	touch build

clean:
	$(checkdir)
	-rm -f build
	-$(MAKE) -i distclean || $(MAKE) -f Makefile.in -i distclean
	-rm -rf debian/tmp* *~ *.orig ./#*# tmp.* debian/files*
	find -name '*~' -print0 | xargs -r0 rm --

binary:		binary-arch binary-indep

binary-indep:

binary-arch:	checkroot build
	$(checkdir)
	-rm -rf debian/tmp
	install -d debian/tmp debian/tmp/DEBIAN debian/tmp/etc/uucp
	install -d debian/tmp/usr/doc/$(p)
	install -g root -o root -m 644 debian/copyright\
	  debian/tmp/usr/doc/$(p)/copyright
	install -g root -o root -m 644 debian/changelog\
	  debian/tmp/usr/doc/$(p)/changelog.Debian
	gzip -9f debian/tmp/usr/doc/$(p)/changelog.Debian
	make install prefix=debian/tmp
	dpkg-shlibdeps $(p)
	dpkg-gencontrol
	chown -R root.root debian/tmp
	chmod -R g-ws,a+r,u+w debian/tmp
	dpkg-deb --build debian/tmp ..

define checkdir
	test -f $(p).c
endef

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

.PHONY: binary source diff clean checkroot
