#!/usr/bin/make -f
# Sample debian/rules that uses debhelper. 
# GNU copyright 1997 by Joey Hess.
#
# This version is for a hypothetical package that builds an
# architecture-dependant package, as well as an architecture-independent
# package.

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

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

# This has to be exported to make some magic below work.
export DH_OPTIONS
SONAME=3
CONFIGURE_ROOT= --prefix=/usr 			\
		--mandir=/usr/share/man 	\
	       	--infodir=/usr/share/info 	\
		--sysconfdir=/etc 		\
	       	--datadir=/etc 			\
		--with-krb4=/usr 		\
		--with-krb5=/usr		\
		--enable-cmu-zctl-punt 		\
	       	--with-x 			\
		--with-comerr=/usr 		\
		--with-ss=/usr			\
		CFLAGS='-DHAVE_OPENSSL -DHAVE_STRERROR'

BUILD_ROOT=`pwd`

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
	-mkdir build-tree
	cd build-tree&&../configure $(CONFIGURE_ROOT)
	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.

	# Why do I need this?
	cp zwgc/*.c build-tree/zwgc/
	cp zwgc/*.h build-tree/zwgc/

	set -e; \
	for dir in build-tree ; do  \
		cd $$dir; \
	rm -f lib/*.o || true; \
		$(MAKE) -C lib	\
		 FPIC= 					\
		 LIBEXT=a; \
		rm -f lib/*.o; \
		$(MAKE) LIBEXT=so \
		 FPIC=-fpic SONAME=$(SONAME); \
		cd ..; \
		done

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	-rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	-rm -rf build-tree debian/tmp

	dh_clean

install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	-rm -rf debian/tmp
	dh_installdirs

	# Add here commands to install the package into debian/tmp.
#	cd build-tree&&$(MAKE)  DESTDIR=`pwd`/../debian/tmp install
	mkdir -p debian/tmp/usr/man/man1
	mkdir -p debian/tmp/usr/man/man8	
	cd build-tree&&$(MAKE)  DESTDIR=$(BUILD_ROOT)/../debian/tmp install
	mv debian/tmp/usr/lib/libzephyr.so debian/tmp/usr/lib/libzephyr.so.$(SONAME)
	echo "soname = libzephyr.so.$(SONAME)"
	ln -s libzephyr.so.$(SONAME) debian/tmp/usr/lib/libzephyr.so
	mkdir -p debian/tmp/etc/zephyr/acl
	set -x; for i in debian/acl/*; do install -c -m 644 -o root $$i debian/tmp/etc/zephyr/acl; done; set +x
	install -c -m 644 local/zephyr.vars debian/tmp/etc/zephyr/zephyr.vars
	install -c -m 644 debian/default.subscriptions debian/tmp/etc/zephyr
#	install -c -m 644 debian/zephyr.conf debian/tmp/etc/zephyr/zephyr.conf
	install -c -m 644 local/zwgc.desc debian/tmp/etc/zwgc.desc

# Build architecture-independent files here.
# Pass -i to all debhelper commands in this target to reduce clutter.
binary-indep: build install


# Build architecture-dependent files here.
# Pass -a to all debhelper commands in this target to reduce clutter.
binary-arch: build install
	dh_testdir
	dh_testroot
	set -e; \
	mkdir -p debian/tmp/usr/share/man
#	mv debian/tmp/usr/man/man1/* debian/tmp/usr/share/man/man1/
#	mv debian/tmp/usr/man/man8/* debian/tmp/usr/share/man/man8/
	rm -rf debian/tmp/usr/man
	dh_movefiles -plibzephyrcclub -pzephyr-server-cclub 
	dh_movefiles -pzephyr-client-cclub -plibzephyr-dev-cclub
	dh_movefiles --sourcedir=debian/tmp -plibzephyr-cclub 
	dh_installdebconf 
	dh_installdocs
	dh_installinit -pzephyr-client-cclub --init-script=zephyr
	dh_installinit -pzephyr-server-cclub --init-script=zephyrd
	dh_installchangelogs 
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_shlibdeps
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch

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


