#!/usr/bin/make -f
# based on the sample debian/rules file for debhelper by Joey Hess.

#export DH_VERBOSE=1

build: build-stamp
build-stamp:
	dh_testdir
	./configure \
	--without-prefixext \
	--with-serverbindir=/usr/sbin \
	--with-serverlibdir=/etc/afbackup \
	--with-servervardir=/var/lib/afbackup \
	--with-serverlogdir=/var/log/afbackup \
	--with-clientbindir=/usr/sbin \
	--with-clientlibdir=/etc/afbackup \
	--with-clientvardir=/var/lib/afbackup \
	--with-clientlogdir=/var/log/afbackup \
	--with-rexecdir=/usr/lib/afbackup/rexec \
	--with-clientconf=client.conf \
	--with-serverconf=server.conf \
	--with-servermandir=/usr/share/man \
	--with-clientmandir=/usr/share/man \
	--with-commondir=/usr/lib/afbackup \
	--with-zlib \
	--with-zlib-include=/usr/include/zlib.h \
	--with-zlib-libdir=/usr/lib/
	make all DEBUG='-Wall -g' OPTIMIZE=-O2 afserver < debian/cryptkey
#	make all DEBUG='-Wall' OPTIMIZE=-O2 < debian/cryptkey
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -rf build-stamp debian/tmp debian/afbackup-client
	-make distclean
	dh_clean

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

binary-arch: build
	dh_testdir
	dh_testroot
	dh_clean
	dh_installdirs
	make install.client \
		install.server \
		SERVERBINDIR=`pwd`/debian/tmp/usr/sbin \
		SERVERLIBDIR=`pwd`/debian/tmp/etc/afbackup \
		SERVERVARDIR=`pwd`/debian/tmp/var/lib/afbackup \
		CLIENTBINDIR=`pwd`/debian/afbackup-client/usr/sbin \
		CLIENTLIBDIR=`pwd`/debian/afbackup-client/etc/afbackup \
		CLIENTVARDIR=`pwd`/debian/afbackup-client/var/lib/afbackup \
		SERVERREXECDIR=`pwd`/debian/afbackup-client/usr/lib/afbackup/rexec \
		COMMONDIR=`pwd`/debian/afbackup-client/usr/lib/afbackup \
		COMMONDATADIR=`pwd`/debian/afbackup-client/usr/lib/afbackup/share \
		COMMONSHLIBDIR=`pwd`/debian/afbackup-client/usr/lib/afbackup/share/lib \
		CLIENTMANDIR=`pwd`/debian/afbackup-client/usr/share/man \
		SERVERMANDIR=`pwd`/debian/tmp/usr/share/man
	make install.rexeclinks \
		 CLIENTBINDIR=/usr/sbin \
		 SERVERREXECDIR=`pwd`/debian/afbackup-client/usr/lib/afbackup/rexec
	dh_installdocs CONFIG HOWTO.FAQ.DO-DONT INTRO README debian/README.server.Debian
	dh_installdocs -pafbackup-client -Pdebian/afbackup-client CONFIG HOWTO.FAQ.DO-DONT debian/README.client.Debian
	dh_installcron
	(cd debian/afbackup-client/usr/share/man/man8; ln -s afclient.8 afbackup.8)
	(cd debian/afbackup-client/usr/share/man/man8; ln -s afclient.8 backout.8)
	(cd debian/tmp/usr/share/man/man8; ln -s afserver.conf.8 afserverconfig.8)
	(cd debian/tmp/usr/share/man/man8; ln -s afserver.conf.8 xafserverconfig.8)
	(cd debian/afbackup-client/usr/share/man/man8; ln -s afclient.conf.8 afclientconfig.8)
	(cd debian/afbackup-client/usr/share/man/man8; ln -s afclient.conf.8 xafclientconfig.8)
	dh_undocumented
	dh_installchangelogs Changes
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
#	dh_du
	dh_md5sums
	dh_builddeb

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