#!/usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.

package=zmailer

build:
	$(checkdir)
	if [ -d /etc/zmailer ]; then echo "Cannot build zmailer on a system with zmailer installed"; exit 5; fi
	autoconf
	./configure --prefix=/usr/lib/zmailer --with-postoffice=/var/spool/postoffice \
		--with-system-malloc --with-mailshare=/etc/zmailer --with-mailvar=/etc/zmailer \
		--with-yp --with-zconfig=/etc/zmailer/zmailer.conf --with-mailbin=/usr/lib/zmailer
	make COPTS="-O5"

	touch build

clean:
	$(checkdir)
	-rm -f build
	-make distclean
	-rm -f `find . -name "*~"`
	-rm -rf debian/tmp debian/files* core debian/substvars /etc/zmailer /usr/lib/zmailer /var/spool/postoffice
	-rm man/index.bt

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

binary-arch:	checkroot build
	$(checkdir)
	-rm -rf debian/tmp
	install -d debian/tmp
	cd debian/tmp && install -d `cat ../dirs`
	-mkdir /usr/lib/zmailer /etc/zmailer
	make install
	cd man;make install MANDIR=../debian/tmp/usr/man
	cp -a /usr/lib/zmailer debian/tmp/usr/lib
	rm -r debian/tmp/usr/lib/zmailer/lib
	cp -a /var/spool/postoffice debian/tmp/var/spool
	cd debian/tmp/usr/sbin; for i in sendmail rmail; do ln -s ../lib/zmailer/$$i; done
	cd debian/tmp/usr/bin; for i in mailq newaliases newfqdnaliases vacation; do ln -s ../lib/zmailer/$$i; done
	cp -a /etc/zmailer debian/tmp/etc
	mv debian/tmp/usr/lib/zmailer/zmailer debian/init.d
	cp debian/tmp/etc/zmailer/cf/SMTP+UUCP.cf debian/tmp/etc/zmailer/router.cf
	rmdir debian/tmp/etc/zmailer/forms/bak debian/tmp/etc/zmailer/bak debian/tmp/usr/lib/zmailer/bak
	install -m644 debian/localnames debian/tmp/etc/zmailer/db
	install -m644 debian/scheduler.conf debian/tmp/etc/zmailer
	install -m644 utils/maillog.1 debian/tmp/usr/man/man1
	install utils/maillog debian/tmp/usr/bin
	install -m644 utils/mailpath.1 debian/tmp/usr/man/man1
	install utils/mailpath debian/tmp/usr/bin
	install -m644 debian/zmailstats.8 debian/tmp/usr/man/man8
	install debian/zmailstats debian/zmailcheck debian/tmp/usr/sbin
# Must have debmake installed for this to work. Otherwise please copy
# /usr/bin/debstd into the debian directory and change debstd to debian/debstd
	debstd -m ChangeLog BUGS README README.PERFORMANCE README.UPGRADING INSTALL SiteConfig Overview 
	dpkg-gencontrol
	chown -R root.root debian/tmp/usr debian/tmp/etc
	chmod -R go=rX debian/tmp/usr debian/tmp/etc
	dpkg --build debian/tmp ..

define checkdir
	test -f debian/rules
endef

# Below here is fairly generic really

binary:		binary-indep binary-arch

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

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