#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This is the debhelper compatability version to use.
export DH_COMPAT=3

DDEBUG=`if (echo $(DEB_BUILD_OPTIONS) | grep -q debug) then \
		echo "--enable-debug"; \
	else \
		echo ""; \
	fi`
DTEST=`if (echo $(DEB_BUILD_OPTIONS) | grep -q ztest) then \
		echo "-Werror"; \
	else \
		echo ""; \
	fi`

build: debfiles-stamp build-stamp
build-stamp:
	dh_testdir

	CFLAGS=$(DTEST) ./configure \
		--prefix=/usr \
		--mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--localstatedir=/var/lib/zorp \
		--sysconfdir=/etc \
		--with-pidfiledir=/var/run/zorp/ \
		--disable-dmalloc \
		$(DDEBUG) \
		--enable-tproxy=netfilter

	# Add here commands to compile the package.
	$(MAKE)

	touch build-stamp

debfiles: debfiles-stamp

debfiles-stamp:
	echo -n "" > debian/zorp-modules.files
	echo -n "" > debian/zorp-modules.conffiles
	for i in `cat module.list` x; do \
		if test "$$i" != "x"; then \
			if test -r modules/$$i/debian/zorp-pro-modules.files; then \
				cat modules/$$i/debian/zorp-pro-modules.files >> debian/zorp-modules.files; \
			fi; \
			if test -r modules/$$i/debian/zorp-pro-modules.conffiles; then \
				cat modules/$$i/debian/zorp-pro-modules.conffiles >> debian/zorp-modules.conffiles; \
			fi; \
		fi; \
	done;
	touch debfiles-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	rm -f modules/config-stamp
	rm -f debfiles-stamp

	# Add here commands to clean up after the build process.
	-$(MAKE) distclean

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/tmp.
	$(MAKE) install DESTDIR=`pwd`/debian/tmp/
	mv `pwd`/debian/tmp/etc/zorp/zorpctl.conf.sample `pwd`/debian/tmp/etc/zorp/zorpctl.conf
	dh_movefiles
	mkdir -p `pwd`/debian/zorp-tests/usr/share/zorp/testdb
	cp -r tests/functional/* `pwd`/debian/zorp-tests/usr/share/zorp/testdb/
	(cd pylib/kznf && python@PYTHON_MIN_VERSION@ setup.py install --prefix ../../debian/python-kzorp@BINARY_BRANCH@/usr)
	

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.
#	dh_testversion -i
	dh_testdir -i
	dh_testroot -i
#	dh_installdebconf -i
	dh_installdocs -i
#	dh_installexamples -i
#	dh_installmenu -i
#	dh_installemacsen -i
#	dh_installpam -i
#	dh_installinit -i --package=zorp
#	dh_installcron -i
#	dh_installmanpages
#	dh_installinfo -i
	dh_installchangelogs -i 
#-k NEWS
	dh_link -i
	dh_strip -i
	dh_compress -i
	dh_fixperms -i
	# You may want to make some executables suid here.
	dh_suidregister -i
#	dh_makeshlibs -i
	dh_installdeb -i
#	dh_perl -i
	dh_shlibdeps -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: build install
#	dh_testversion -a
	dh_testdir -a
	dh_testroot -a
#	dh_installdebconf -a
#	dh_installdocs --package=zorp-doc
#	dh_installexamples -a
#	dh_installmenu -a
#	dh_installemacsen -a
#	dh_installpam -a
	dh_installinit --package=zorp
#	dh_installcron -a
	dh_installmanpages --package=zorp zorp.8 zorpctl.8 instances.conf.5
#	dh_installinfo -a
	dh_installchangelogs -a 
#-k NEWS
	dh_link -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	chmod 700 `pwd`/debian/zorp/etc/zorp
	# You may want to make some executables suid here.
#	dh_suidregister -a
#	dh_makeshlibs -a
	dh_installdeb -a
#	dh_perl -a
	dh_shlibdeps -a -l`pwd`/debian/zorp-lib/usr/lib:`pwd`/debian/zorp/usr/lib
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

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