#!/usr/bin/make -f
# debian/rules for Debian-_CDD_.
# GNU copyright 2004 _CDD_Maintainer, GPL.

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

cdd=_CDD_
pkgsrc=debian-$(cdd)

control: gen-control debian/control.stub tasks/* control-stamp
control-stamp:
	rm -f debian/control
	cdd-gen-control -s local -c -m -i

	touch control-stamp

build: control-stamp build-stamp
build-stamp:
	# Fix *.dsc file to mention all binary targets
	TASKS="" ; \
	if [ -d common ] ; then TASKS="$(cdd)-common" ; fi ; \
	for task in `ls -1 tasks | sort` ; do \
		if [ "$${TASKS}" != "" ] ; then TASKS="$${TASKS}, " ; fi ; \
		TASKS="$${TASKS}$(cdd)-$${task}" ; \
	done ; \
	sed "s/^\(Binary: \)$(cdd)/\1$${TASKS}/" ../$(pkgsrc)_*.dsc > tmp.dsc ; \
	mv tmp.dsc ../$(pkgsrc)_*.dsc
	dh_testdir

	touch build-stamp

clean: debian/control
	dh_testdir
	dh_testroot
	rm -f build-stamp control-stamp
	rm -rf tmp
	rm -f tasks/*~
	[ -d menu ] && rm -f debian/$(cdd)-*.post{inst,rm}
	rm -f debian/$(cdd)-common.{templates,config,install} debian/90$(cdd)-common
	rm -rf debian/po

	if [ -f debian/control ] ; then dh_clean ; fi
	rm -f debian/control
	ln -s control.stub debian/control


install: control-stamp build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

# Build architecture-dependent files here.
binary-arch: build install
# We have nothing to do by default.

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installexamples
	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
	dh_installcron
	dh_installman
	cdd-install-helper
	# dh_install must be called after cdd-install-helper because
	# some files which have to be copied are created in this call
	dh_install
	dh_installdebconf
#	dh_installinfo
	dh_installchangelogs 
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

dist:
	distdir=$(pkgsrc)-`cat VERSION` ; \
	rm -rf $${distdir} ; \
	mkdir $${distdir} ; \
	chmod 777 $${distdir} ; \
	rsync -a --exclude $${distdir} --exclude CVS * $${distdir} ; \
	GZIP=-9 tar -czf ../$(pkgsrc)_`cat VERSION`.tar.gz $${distdir} ; \
	rm -rf $${distdir}

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