#!/usr/bin/make -f
# Made with the aid of dh_make, by Craig Small
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# Some lines taken from debmake, by Cristoph Lameter.

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

build: 
	#**** Off we go... ****

clean:
	dh_testdir
	rm -f install-stamp 
	-rm -f debian/files
	-rm -f debian/substvars
	dh_clean

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

	for i in `ls | grep -v debian | grep -v packaging`; do \
	  cp -R $$i debian/tmp/usr/share/horde/imp ; \
	done
	-cp -R debian/tmp/usr/share/horde/imp/scripts/* debian/tmp/usr/share/doc/imp/examples/
	-rm -rf debian/tmp/usr/share/horde/imp/scripts
	-rm -rf `find debian/tmp/ -print | grep CVS`
	-mv debian/tmp/usr/share/horde/imp/docs/* debian/tmp/usr/share/doc/imp/
	-rm -rf debian/tmp/usr/share/horde/imp/docs debian/tmp/usr/share/horde/imp/packaging
	mv debian/tmp/usr/share/horde/imp/config/* debian/tmp/etc/imp
	mv debian/tmp/etc/imp/defaults.php3.dist debian/tmp/usr/share/doc/imp/examples
	mv debian/tmp/etc/imp/servers.php3.dist debian/tmp/etc/imp/servers.php3
	mv debian/tmp/etc/imp/mime.php3.dist debian/tmp/usr/share/doc/imp/examples
	mv debian/tmp/etc/imp/ldap.php3.dist debian/tmp/etc/imp/ldap.php3
	-rm -rf debian/tmp/usr/share/horde/imp/config
	chmod 644 `find debian/tmp/usr/share -type f -print `
	chmod 644 `find debian/tmp/usr/share/doc -type f -print `
	cp debian/Debian.Install debian/tmp/usr/share/doc/imp
	cp debian/pgsql_* debian/tmp/usr/share/doc/imp/examples
	cp debian/mysql* debian/tmp/usr/share/doc/imp/examples
	cp debian/defaults.php3.in debian/tmp/etc/imp
	cp debian/custom_from.in debian/tmp/etc/imp
	cp debian/mime.php3 debian/tmp/etc/imp
	chmod 644 debian/tmp/etc/imp/*
	cp debian/update-imp debian/tmp/usr/sbin
	cp debian/impcleanup debian/tmp/usr/sbin
	cp debian/version.php debian/tmp/usr/share/horde/imp/lib
	cd debian/tmp/usr/share/horde/imp && rm -f COPYING README
	-chmod 755 debian/tmp/usr/share/doc/imp/examples/*.sh \
		debian/tmp/usr/share/doc/imp/examples/*pl \
		debian/tmp/usr/share/doc/imp/examples/*cron \
		debian/tmp/usr/sbin/impcleanup

	# add prepend code
	for i in debian/tmp/usr/share/horde/imp/*; do \
	  if [ -f $$i ]; then \
	    printf "<?php if (!defined(\"HORDE_LIB\")) { include '/etc/horde/prepend.php3'; } ?>" > $$i.tmp; \
	    cat $$i >> $$i.tmp; \
	    mv -f $$i.tmp $$i; \
	  fi; \
	done 
	for i in `find debian/tmp/usr/share/horde/imp/`; do \
	  if [ -f $$i ]; then \
	    sed -e "s#\../config/#/etc/horde/#; s#./config/#/etc/imp/#" $$i > $$i.tmp; \
	    mv -f $$i.tmp $$i; \
	  fi; \
	done    
     


	touch install-stamp

binary-indep: install
	dh_testdir
	dh_testroot
	dh_installdebconf
	dh_installdocs 
	dh_installcron
	dh_installexamples
	dh_undocumented  
	dh_installchangelogs docs/CHANGES
	dh_link
	dh_strip
	dh_compress
	dh_fixperms 
	chown -R www-data.root debian/tmp/usr/share/horde/imp 
	-chmod 755 debian/tmp/usr/share/doc/imp/examples/*.sh \
	           debian/tmp/usr/share/doc/imp/examples/*pl \
		   debian/tmp/usr/share/doc/imp/examples/*cron \
		   debian/tmp/etc/imp/defaults.php3.in \
		   debian/tmp/usr/sbin/update-imp
	chown www-data.www-data debian/tmp/usr/sbin/impcleanup 
	chmod u+s debian/tmp/usr/sbin/impcleanup
	dh_suidregister usr/sbin/impcleanup
	dh_perl
	dh_installdeb
	dh_shlibdeps

	cd debian/tmp && find ./etc -type f -print | sed -e 's#^./#/#' > DEBIAN/conffiles

	dh_gencontrol
	dh_md5sums
	dh_builddeb

source diff:                                                                  
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

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