#!/usr/bin/make -f

# Sample debian.rules file - for GNU Hello (1.3).
# Copyright 1994,1995 by Ian Jackson.
# I hereby give you perpetual unlimited permission to copy,
# modify and relicense this file, provided that you do not remove
# my name from the file itself.  (I assert my moral right of
# paternity under the Copyright, Designs and Patents Act 1988.)
# This file may have to be extensively modified
#
# Modified to be a prototype for debmake by Christoph Lameter
# <clameter@debian.org>

package=bind
version=$(shell expr `pwd` : '.*-\([0-9.].*\)')
version_main=$(shell expr `pwd` : '.*-\([0-9]*.[0-9.]*\)')
include OLD/BSD/Makefile.maninc
moresed = -e s@/usr/share/misc/nslookup@/usr/lib/nslookup@g
rblcheck=rblcheck-1.0

SHELL=/bin/bash

build: stamp-build

stamp-build:
	$(checkdir)
	-$(MAKE) DST=target SRC=$$(pwd) links
	cp -avf port/linux/include/sys/* target/port/linux/include/sys
	touch target/port/linux/include/nlist.h
	cd target; $(MAKE) CC="$(CC) -I/usr/include/libelf" CDEBUG=""
	cd host; $(MAKE) CC="$(CC)" COPTS="-O2"
	cd $(rblcheck); $(MAKE) CC="$(CC)"
	install -d debian/tmp/usr/man/man{1,8}
	touch stamp-build


stamp-man:
	install -d debian/tmp/usr/man/man{1,3,5,7,8}
	for file in debian/{dig,dnsquery}.1 debian/{*.3,*.5,*.7,*.8}; do \
	    base=$$(basename $$file); \
	    ext=$$(echo $$file | sed -e "s/.*\(.\)$$/\1/"); \
	    ( $(EXT_SED_CMD) $(moresed) ) < $$file \
		> debian/tmp/usr/man/man$$ext/$${base}bind; \
	done;
	touch stamp-man


clean:
	$(checkdir)
	$(MAKE) clean
	cd host; $(MAKE) clean
	cd $(rblcheck); $(MAKE) clean
	rm -rf $$(find . -name "*~") $$(find debian/* -type d) stamp-*
	rm -rf target debian/files* target debian/*substvars* pgptemp*
	find .. -name $(package)*.asc -size 0 -maxdepth 1 -exec rm {} ";"
	chmod +x debian/{pre*,post*,bindconfig,dnsutils.p*,init.d,ppp.d}


binary-indep:	checkroot stamp-build
	$(checkdir)
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.


dnsutils: stamp-build stamp-man
	$(checkdir)
	rm -rf debian/dnsutils && install -d debian/dnsutils/{DEBIAN,usr/bin}
	install -d debian/dnsutils/usr/{lib,doc/dnsutils,man/man{1,8}}
	install debian/dnsutils.preinst debian/dnsutils/DEBIAN/preinst
	install debian/dnsutils.postrm debian/dnsutils/DEBIAN/postrm
	cp host/RELEASE_NOTES debian/dnsutils/usr/doc/dnsutils/changelog
	cp debian/changelog debian/dnsutils/usr/doc/dnsutils/changelog.Debian
	install host/host debian/dnsutils/usr/bin/host
	cd debian/dnsutils; cat ../hosts | xargs -t -i sh -c \
		"ln -s host usr/bin/{}"
	cp host/host.1 debian/dnsutils/usr/man/man1/host.1
	cp debian/tmp/usr/man/man1/dig.1bind \
		debian/dnsutils/usr/man/man1/dig.1
	cp debian/tmp/usr/man/man8/nslookup.8bind \
		debian/dnsutils/usr/man/man8/nslookup.8
	ln -s ../man7/undocumented.7.gz \
		debian/dnsutils/usr/man/man1/mxlookup.1.gz
	ln -s ../man7/undocumented.7.gz \
		debian/dnsutils/usr/man/man1/rblcheck.1.gz
	ln -s ../man7/undocumented.7.gz \
		debian/dnsutils/usr/man/man1/addr.1.gz
	cd debian/dnsutils; cat ../hosts | xargs -t -i sh -c \
		"ln -s host.1.gz usr/man/man1/{}.1.gz"
	install target/bin/addr/addr debian/dnsutils/usr/bin
	install target/bin/dig/dig debian/dnsutils/usr/bin
	install target/bin/nslookup/nslookup debian/dnsutils/usr/bin
	install host/mxlookup debian/dnsutils/usr/bin/mxlookup
	install $(rblcheck)/rblcheck debian/dnsutils/usr/bin/rblcheck
	cp $(rblcheck)/README \
		debian/dnsutils/usr/doc/dnsutils/README.rblcheck
	cp $(rblcheck)/INSTALL \
		debian/dnsutils/usr/doc/dnsutils/INSTALL.rblcheck
	cp bin/nslookup/nslookup.help debian/dnsutils/usr/lib/nslookup.help
	gzip -v9 debian/dnsutils/usr/{doc/dnsutils/*,man/*/*{1,8}}
	cp debian/copyright debian/dnsutils/usr/doc/dnsutils
	dh_shlibdeps -pdnsutils -Pdebian/dnsutils -v
	dpkg-gencontrol -pdnsutils -Pdebian/dnsutils
	dh_strip -v -pdnsutils -Pdebian/dnsutils
	chown -R root.root debian/dnsutils
	chmod -R go=rX debian/dnsutils
	dpkg --build debian/dnsutils ..
 

bind: stamp-build stamp-man
	$(checkdir)
	rm -rf debian/bind && install -d debian/bind/{DEBIAN,usr/{bin,sbin}}
	install -d debian/bind/{/usr/{lib,doc/bind,man/man{1,8}},var/named}
	install -d debian/bind/etc/{ppp/ip-up.d,ppp/ip-down.d,init.d}
	cp -p debian/{pre*,post*,conffiles} debian/bind/DEBIAN
	install debian/init.d debian/bind/etc/init.d/bind
	cp debian/changelog debian/bind/usr/doc/bind/changelog.Debian
	cp CHANGES debian/bind/usr/doc/bind/changelog
	cp INSTALL debian/bind/usr/doc/bind
	install debian/ppp.d debian/bind/etc/ppp/ip-up.d/bind
	install debian/ppp.d debian/bind/etc/ppp/ip-down.d/bind
	install -d debian/bind/usr/{lib,doc/bind,man/man{1,8}}
	install debian/{bindconfig,named-bootconf} debian/bind/usr/sbin
	install target/bin/named/named debian/bind/usr/sbin
	install target/bin/named-xfer/named-xfer debian/bind/usr/sbin
	sed "s/ps -p/ps p/g" target/bin/ndc/ndc > debian/bind/usr/sbin/ndc \
	    && chmod 755 debian/bind/usr/sbin/ndc
	install target/bin/nsupdate/nsupdate debian/bind/usr/sbin
	install target/bin/dnsquery/dnsquery debian/bind/usr/bin
	cp -a debian/tmp/usr/man debian/bind/usr
	rm -r debian/bind/usr/man/man3
	ln -s ../man7/undocumented.7.gz \
		debian/bind/usr/man/man8/named-bootconf.8bind.gz
	ln -s ../man7/undocumented.7.gz \
		debian/bind/usr/man/man8/bindconfig.8bind.gz
	ln -s ../man7/undocumented.7.gz \
		debian/bind/usr/man/man8/nsupdate.8bind.gz
	ln -s ../man7/undocumented.7.gz \
		debian/bind/usr/man/man8/named-bootconf.pl.8bind.gz
	rm debian/bind/usr/man/man{1/dig.1bind,8/nslookup.8bind}
	gzip -v9 debian/bind/usr/{doc/bind/*,man/*/*bind}
	cp debian/copyright debian/bind/usr/doc/bind
	cp README TODO debian/bind/usr/doc/bind
	cp bin/named/named-bootconf.pl debian/bind/usr/sbin
	cp debian/named.{l*,r*} debian/bind/var/named
	dh_shlibdeps -pbind -Pdebian/bind -v
	dpkg-gencontrol -pbind -Pdebian/bind
	dh_strip -v -pbind -Pdebian/bind
	$(MAKE) -f debian/rules buildinfo
	chown -R root.root debian/bind
	chmod -R go=rX debian/bind
	dpkg --build debian/bind ..


buildinfo:
	@echo; dpkg -l gcc "libc*" binutils ldso make dpkg-dev $(BUILDINFO) \
		| awk '$$1 == "ii" { printf("%s-%s\n", $$2, $$3) }' \
		| tee debian/bind/usr/doc/$(package)/buildinfo.Debian; echo
	cd debian/bind && md5sum $$(find * -type f -not -regex "DEBIAN/.*") \
		> DEBIAN/md5sums
	-cd debian/bind && pgp -sat +clearsig=on DEBIAN/md5sums -o files.sig \
		&& mv -v files.sig usr/doc/$(package)/checksums.txt
	rm -f debian/bind/files.sig
	cd debian/bind && md5sum $$(find * -type f -not -regex "DEBIAN/.*") \
		> DEBIAN/md5sums


 
binary-arch: checkroot dnsutils bind


define checkdir
	test -f debian/rules
endef

# Below here is fairly generic really

binary:		binary-indep binary-arch

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

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

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