#!/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-system-kpathsea \
	  --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_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
	mkdir -p debian/tmp/etc/kde2
	make DESTDIR=`pwd`/debian/tmp/ install 
	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
	list=`cd debian/tmp && find ./ -type l -name "lib*.so" | sed -e 's#^./##'` ;\
	dh_movefiles -pkdegraphics-dev $$list usr/lib/*.a usr/include/kde

	for package in `cat debian/control | grep Package | grep -v kdegraphics | sed -e 's#^Package: ##'`; do \
		dh_movefiles -p$$package usr/bin/$$package* \
			usr/share/doc/kdegraphics/*$$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/Graphics/$$package*.desktop \
			usr/share/sounds/$$package* \
			usr/share/man/man1/$$package* ;\
	done
	dh_movefiles -pkview usr/lib/kview* usr/lib/libkview* \
		usr/lib/libbaglayout* usr/lib/*dvi* usr/lib/*fax* \
		usr/lib/libkmultipage* usr/lib/libkpagetest* \
		usr/bin/kdvi usr/bin/kfax usr/share/man/man1/kdvi* \
		usr/share/man/man1/kfax* usr/share/apps/kdvi* \
		usr/share/apps/kview* usr/share/apps/kfax* \
		usr/share/doc/kde/HTML/en/kdvi* \
		usr/share/doc/kde/HTML/en/kfax* \
		usr/share/doc/kdegraphics/kdvi* \
		usr/share/doc/kdegraphics/kfax* \
		usr/share/doc/kdegraphics/kviewshell* \
		usr/share/applnk/Graphics/kdvi* \
		usr/share/applnk/Graphics/kfax* \
		usr/share/icons/hicolor/*/apps/kdvi* \
		usr/share/icons/hicolor/*/apps/kfax*
	dh_movefiles -pkghostview usr/lib/*kghostview*
	dh_movefiles -ppixie usr/lib/*pixie* usr/lib/libkif* \
		usr/lib/libminimagick* usr/bin/kpixmap2bitmap \
		etc/kde2/applnk/Graphics/kpixmap2bitmap.desktop \
		usr/share/man/man1/kpixmap2bitmap*
	dh_installdocs
	dh_installmenu
	dh_installmime
	dh_installchangelogs
	dh_strip
	dh_compress
	dh_fixperms
	dh_suidregister
	dh_installdeb
	dh_perl
	dh_makeshlibs
	dh_shlibdeps
	dh_gencontrol
	-for package in `cat debian/control | grep Package | grep -v kdegraphics | 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
