#!/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=2

# This has to be exported to make some magic below work.
export DH_OPTIONS

CONFIG_OPTIONS= --prefix=/ \
		--bindir=\$${prefix}usr/bin \
		--sbindir=\$${prefix}usr/sbin \
		--mandir=\$${prefix}usr/share/man \
		--sysconfdir=\$${prefix}etc \
		--with-pid-dir=\$${prefix}var/run \
		--with-log-dir=\$${prefix}var/log \
		--with-var-dir=\$${prefix}var/lib

build: build-stamp
build-stamp:
	dh_testdir
	./configure --enable-client --enable-server ${CONFIG_OPTIONS}
	$(MAKE)
	touch build-stamp

build-ddt-client:
	dh_testdir
	./configure --enable-client --disable-server ${CONFIG_OPTIONS}
	$(MAKE)
	touch build-stamp

build-ddt-server:
	dh_testdir
	./configure --disable-client --enable-server ${CONFIG_OPTIONS}
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 
	-$(MAKE) distclean
	dh_clean

install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	$(MAKE) prefix=`pwd`/debian/tmp/ install

	# install ip-{up,down} scripts
	install -D -o root -g root -m 0755 debian/ddt-client.ip-up \
		debian/ddt-client/etc/ppp/ip-up.d/ddt-client
	install -D -o root -g root -m 0755 debian/ddt-client.ip-down \
		debian/ddt-client/etc/ppp/ip-down.d/ddt-client

	# install default config files
	#install -D -o root -g root -m 0600 debian/ddtcd.conf \
	#	debian/ddt-client/etc/ddtcd.conf
	#install -D -o root -g root -m 0600 debian/ddtd.conf \
	#	debian/ddt-server/etc/ddtd.conf

	# install logrotate files
	install -D -o root -g root -m 644 debian/ddt-client.logrotate \
		debian/ddt-client/etc/logrotate.d/ddt-client
	install -D -o root -g root -m 644 debian/ddt-server.logrotate \
		debian/ddt-server/etc/logrotate.d/ddt-server

	dh_movefiles

# This single target is used to build all the packages, all at once, or
# one at a time. So keep in mind: any options passed to commands here will
# affect _all_ packages. Anything you want to only affect one package
# should be put in another target, such as the install target.
binary-common:
	dh_testdir
	dh_testroot
	dh_installdebconf
	dh_installdocs
	dh_installexamples
	-dh_installinit -Nddt-server --init-script=ddt-client -- defaults 20
	-dh_installinit -Nddt-client --init-script=ddt-server -- defaults 25
	dh_installchangelogs
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture independant packages using the common target.
binary-indep: build install
# (Uncomment this next line if you have such packages.)
#        $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: build install
	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common

# Any other binary targets build just one binary package at a time.
binary-%: build-%
	make -f debian/rules install DH_OPTIONS=-p$*
	make -f debian/rules binary-common DH_OPTIONS=-p$*

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