#!/usr/bin/make -f

export DH_COMPAT=2

build:
	$(checkdir)

	make prefix=/usr RELEASE=true
	touch build

clean:
	$(checkdir)
	-rm -f build
	-make clean
	-rm -f `find . -name "*~"`
	-rm -rf debian/tmp `find debian/* -type d ! -name CVS ! -name po` debian/files* core
	-rm -f debian/*substvars
	dh_clean -k

binary-indep: checkroot build
	$(checkdir)
	mkdir -p debian/tmp/etc/modutils
	mkdir -p debian/tmp/etc/default
	mkdir -p debian/tmp/usr/share/doc/dnet-common
	mkdir -p debian/tmp/sbin
	echo "alias net-pf-12 decnet" > debian/tmp/etc/modutils/decnet
	echo '# DNET_INTERFACES specifies the names of ethernet interfaces whose' >> debian/tmp/etc/default/decnet
	echo '# MAC address is to be set to the DECnet node address' >> debian/tmp/etc/default/decnet
	echo "DNET_INTERFACES=\"all\"" >> debian/tmp/etc/default/decnet
	echo '# DNET_DAEMONS lists the daemons to start when dnet-progs is installed.' >> debian/tmp/etc/default/decnet
	echo "DNET_DAEMONS=\"dnetd phoned #dnroute\"" >> debian/tmp/etc/default/decnet
	echo "#" >> debian/tmp/etc/default/decnet
	echo "# The following two lines enable routing, note that if you are" >> debian/tmp/etc/default/decnet
	echo "# being a router, then add dnroute to the DNET_DAEMONS too" >> debian/tmp/etc/default/decnet
	echo "#ROUTING=1" >> debian/tmp/etc/default/decnet
	echo "PRIORITY=32" >> debian/tmp/etc/default/decnet
	cp README debian/tmp/usr/share/doc/dnet-common
	cp Documentation/*README debian/tmp/usr/share/doc/dnet-common
	cp debian/dnet-common.README debian/tmp/usr/share/doc/dnet-common/README.Debian
	cp apps/decnet.conf debian/tmp/usr/share/doc/dnet-common/decnet.conf.sample
	make install DESTDIR=`pwd`/debian/tmp MAKEDEB=true RELEASE=true
	mv debian/tmp/usr/man debian/tmp/usr/share
	rm debian/tmp/usr/sbin/startnet
	install -m755 apps/setether.sh debian/tmp/sbin/setether
	dh_installdirs -pdnet-common
	dh_installchangelogs  -pdnet-common
	dh_installdocs  -pdnet-common
	dh_link  -pdnet-common
	dh_installdebconf  -pdnet-common
	dh_installinit  -pdnet-common  --init-script=decnet --update-rcd-params="start\ 39\ S\ .\ \ stop\ 11\ 1\ ."
	dh_strip  -pdnet-common
	dh_movefiles  -pdnet-common
	dh_compress  -pdnet-common
	dh_fixperms  -pdnet-common
	dh_shlibdeps  -pdnet-common
	dh_gencontrol  -pdnet-common
	dh_makeshlibs  -pdnet-common
	dh_installdeb  -pdnet-common
	dh_md5sums  -pdnet-common
	dh_builddeb  -pdnet-common

binary-arch: checkroot build
	$(checkdir)
	-rm -rf debian/tmp `find debian/* -type d ! -name CVS ! -name po`
	install -d debian/tmp
	mkdir -p debian/tmp/etc/modutils
	mkdir -p debian/tmp/etc/default
	mkdir -p debian/tmp/usr/share/doc/libdnet
	mkdir -p debian/tmp/usr/share/doc/libdnet-dev
	mkdir -p debian/tmp/usr/share/doc/dnet-progs
	mkdir -p debian/tmp/sbin
	cp README debian/tmp/usr/share/doc/libdnet
	cp README debian/tmp/usr/share/doc/dnet-progs
	cp README debian/tmp/usr/share/doc/libdnet-dev
	cp Documentation/*README debian/tmp/usr/share/doc/libdnet
	cp Documentation/*README debian/tmp/usr/share/doc/dnet-progs
	cp Documentation/*README debian/tmp/usr/share/doc/libdnet-dev
	make install DESTDIR=`pwd`/debian/tmp MAKEDEB=true RELEASE=true
	mv debian/tmp/usr/man debian/tmp/usr/share
	mv debian/tmp/usr/sbin/startnet debian/tmp/sbin
	dh_installdirs -Ndnet-common
	dh_installchangelogs -Ndnet-common
	dh_installdocs -Ndnet-common
	dh_link -Ndnet-common
	dh_installdebconf -Ndnet-common
	dh_installinit  -pdnet-progs  --init-script=dnet-progs
	dh_strip -Ndnet-common
	dh_movefiles -Ndnet-common
	dh_compress -Ndnet-common
	dh_fixperms -Ndnet-common
	dh_shlibdeps -Ndnet-common
	dh_gencontrol -Ndnet-common
	dh_makeshlibs -Ndnet-common
	dh_installdeb -Ndnet-common
	dh_md5sums -Ndnet-common
	dh_builddeb -Ndnet-common


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
