#!/usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.


BUILDDIR = ./build

build: $(BUILDDIR)/build-stamp

-include debian/debiandirs

debian/debiandirs: admin/debianrules
	perl -w admin/debianrules echodirs > debian/debiandirs

$(BUILDDIR)/build-stamp:
	dh_testdir
	if test ! -f configure; then \
	  $(MAKE) -f admin/Makefile.common ;\
	fi 
	test -d $(BUILDDIR) || mkdir $(BUILDDIR) ;\
	cd $(BUILDDIR) ;\
	$$PWD/../configure $(configkde) --with-rpm --with-pam=kde
	make -C $(BUILDDIR)
	touch $(BUILDDIR)/build-stamp

clean: debian-clean
	-rm -rf $(BUILDDIR)
	dh_clean

debian-clean:
	dh_testdir
	-rm -f $(BUILDDIR)/build-stamp
	if test -d CVS; then \
	  make -f admin/Makefile.common cvs-clean ;\
	fi

binary-indep: build
	dh_testroot
	dh_testdir
# 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 -k
	-rm -f debian/undocumented
	make -C $(BUILDDIR) install DESTDIR=`pwd`/debian/tmp/
	-rm -f usr/share/apps/ksysctrl/LICENSE
	mkdir -p debian/tmp/$(kde_confdir)
	echo "# KDE Config File"          > debian/tmp/$(kde_confdir)/ksysvrc
	echo "[Path Settings]"            >> debian/tmp/$(kde_confdir)/ksysvrc
	echo "ScriptPath=/etc/init.d" >> debian/tmp/$(kde_confdir)/ksysvrc
	echo "RunlevelPath=/etc" >> debian/tmp/$(kde_confdir)/ksysvrc
	perl -w admin/debianrules
	for i in `find debian/tmp/$(kde_bindir) | sed -e 's#^debian/tmp/$(kde_bindir)/##'  | grep -v "debian/tmp"`; do \
	  echo "$$i.1" >> debian/undocumented ;\
	done
	for i in `cat debian/undocumented.in | grep -v "#"`; do \
	  echo "$$i.1" >> debian/undocumented ; \
	done                                              
	dh_movefiles
	dh_undocumented 
	dh_installdocs
	dh_installmenu
	dh_installchangelogs
	dh_strip
	dh_compress
	dh_fixperms
	dh_suidregister
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	cd debian/tmp && find ./$(kde_confdir) -type f -print | sed -e 's#^./#/#' > DEBIAN/conffiles
	chmod 644 debian/tmp/DEBIAN/conffiles 
	dh_md5sums
	perl -w admin/debianrules update
	dh_builddeb       	

# Below here is fairly generic really

binary:		binary-indep binary-arch

.PHONY: binary binary-arch binary-indep clean
