#!/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: build-stamp

-include debian/debiandirs

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

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

clean: debian-clean
	dh_clean

debian-clean:
	dh_testdir
	-rm -f build-stamp
	if test -d CVS; then \
	  make -f admin/Makefile.common cvs-clean ;\
	fi
	-make distclean
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
	mkdir -p debian/tmp/etc/kde2
	-rm -f debian/undocumented
	make install DESTDIR=`pwd`/debian/tmp/
	-rm -f debian/tmp/usr/share/icons/locolor/16x16/apps/package.png
	echo "# KDE Config File"          > debian/tmp/etc/kde2/ksysvrc
	echo "[Path Settings]"            >> debian/tmp/etc/kde2/ksysvrc
	echo "ScriptPath=/etc/init.d" >> debian/tmp/etc/kde2/ksysvrc
	echo "RunlevelPath=/etc" >> debian/tmp/etc/kde2/ksysvrc
	perl -w admin/debianrules cleanup
	for i in `find debian/tmp/usr/bin | sed -e 's#^debian/tmp/usr/bin/##'  | 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 

	for i in `find debian/ -type l -name "common"`; do \
		rm $$i; \
		ln -s ../common $$i ;\
	done
	dh_undocumented
	for package in `cat debian/control | grep Package | grep -v kdeadmin | sed -e 's#^Package: ##'`; do \
		dh_movefiles -p$$package usr/bin/$$package* \
			usr/share/doc/kdeadmin/*$$package/* \
			usr/share/apps/$$package*/* \
			usr/share/doc/kde/HTML/en/$$package*/* \
			usr/share/icons/hicolor/*/*/$$package* \
			usr/share/icons/locolor/*/*/$$package* \
			etc/kde2/applnk/*/$$package*.desktop \
			usr/share/sounds/$$package* \
			usr/share/man/man1/$$package* ;\
	done
	dh_movefiles -pkdat usr/share/icons/locolor/16x16/apps/closed.png \
		usr/share/icons/locolor/16x16/apps/open.png
	dh_movefiles -pksysv usr/share/icons/locolor/16x16/actions/toggle_log.png \
		usr/share/mimelnk/application/x-ksysv.desktop \
		usr/share/mimelnk/text/x-ksysv-log.desktop \
		etc/kde2/ksysvrc usr/share/icons/hicolor/32x32/actions/togg*
	dh_movefiles -pksysctrl usr/share/icons/locolor/16x16/apps/*.png \
		usr/bin/printversion usr/share/man/man1/printversion.*
	dh_movefiles -pkuser usr/share/icons/locolor/22x22/actions/*
	dh_installdocs
	dh_installmenu
	dh_installmime
	-rm -f debian/ksysctrl/usr/share/apps/ksysctrl/LICENSE        
	dh_installchangelogs
	dh_strip
	dh_compress
	dh_fixperms
	dh_suidregister
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	-for package in `cat debian/control | grep Package | grep -v kdeadmin | sed -e 's#^Package: ##'`; do \
		cd debian/$$package ;\
		find ./etc/kde2 -type f -print | sed -e 's#^./#/#' > DEBIAN/conffiles ;\
		chmod 644 debian/$$package/DEBIAN/conffiles ;\
		cd ../../ ;\
	done
	dh_md5sums
	dh_builddeb       	

# Below here is fairly generic really

binary:		binary-indep binary-arch

.PHONY: binary binary-arch binary-indep clean
