#!/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) \
	--libdir=$(kde_libdir) --includedir=$(kde_includedir)

	make

	touch build-stamp

clean: debian-clean
	dh_clean

debian-clean:
	dh_testdir
	-rm -f debian/debiandirs
	if test -d CVS; then \
	  make -f admin/Makefile.common cvs-clean ;\
	fi
	-make distclean

binary-indep:	build
	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
	mkdir -p debian/tmp/etc/kde2
	make DESTDIR=`pwd`/debian/tmp/ install 
	echo "# KDE Config File"          > debian/tmp/etc/kde2/knurc
	echo "[Traceroute]"              >> debian/tmp/etc/kde2/knurc
	echo "path=/usr/sbin/traceroute" >> debian/tmp/etc/kde2/knurc
	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
	list=`cd debian/tmp && find ./ -type l -name "lib*.so" | sed -e 's#^./##'` ;\
	dh_movefiles -pkdenetwork-dev $$list usr/lib/*.a usr/include/kde
	dh_undocumented 
	for package in `cat debian/control | grep Package | grep -v kdenetwork | sed -e 's#^Package: ##'`; do \
		dh_movefiles -p$$package usr/bin/$$package* \
			usr/share/doc/kdenetwork/*$$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/Internet/$$package*.desktop \
			usr/share/sounds/$$package* \
			usr/share/man/man1/$$package* ;\
        done
	dh_movefiles -pkmail usr/bin/mail.local usr/share/man/man1/mail.local* \
			etc/kde2/applnk/Internet/KMail.desktop \
			usr/share/icons/hicolor/22x22/actions/message_get.png
	dh_movefiles -pktalkd etc/kde2/applnk/Settings/Network/*ktalkd* \
		etc/kde2/ktalkdrc usr/bin/*talk* usr/share/man/man1/*talk* \
		usr/lib/*talk*
	dh_movefiles -pkeystone etc/kde2/protocols/vnc.desktop
	dh_movefiles -pknode etc/kde2/knurc \
			etc/kde2/applnk/Internet/KNode.desktop
	dh_movefiles -pksirc usr/lib/*irc* usr/bin/*ksticker* \
		usr/share/man/man1/*ksticker* etc/kde2/applnk/Internet/ksirc* \
		usr/share/man/man1/dsirc* usr/bin/dsirc*
	dh_movefiles -pkorn etc/kde2/applnk/Internet/KOrn.desktop
	dh_movefiles -pkppp etc/kde2/applnk/Internet/Kppp.desktop
	#-rm -rf debian/tmp/usr debian/tmp/etc
	dh_installdocs
	dh_installmenu
	dh_installmime
	dh_installchangelogs
	dh_strip
	dh_compress
	dh_fixperms
	chmod 755 debian/ksirc/usr/share/apps/ksirc/convert_commands.pl \
		debian/ksirc/usr/share/apps/ksirc/tester.pl
	dh_suidregister
	dh_makeshlibs
	dh_perl
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	-for package in `cat debian/control | grep Package | grep -v kdenetwork | 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
