#!/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.

build: 
	#***Here 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
	#### Move all the stuff over to the debian dir ###
	for i in `ls | grep -v debian | grep -v packaging`; do  \
	  cp -R $$i debian/tmp/usr/share/horde ; \
	done
	#### Get rid of the documentation (it get's put back later) ###
	cd debian/tmp/usr/share/horde && rm -f COPYING README
	#### Remove all the CVS files and dirs ####
	-rm -rf `find debian/tmp -print | grep CVS`
	### Move stuff around so it plays nicely on Debian ####
	mv debian/tmp/usr/share/horde/scripts debian/tmp/usr/share/doc/horde/examples
	mv debian/tmp/usr/share/horde/config/* debian/tmp/etc/horde/
	mv debian/tmp/usr/share/horde/phplib/* debian/tmp/etc/horde/
	mv debian/tmp/etc/horde/*.dist debian/tmp/usr/share/doc/horde/examples
	-rm -f debian/tmp/etc/horde/horde_phplib.inc debian/tmp/etc/horde/prepend.php3
	-rm -rf debian/tmp/usr/share/horde/phplib 
	mv debian/tmp/etc/horde/README debian/tmp/usr/share/doc/horde/README.phplib
	-rm -rf debian/tmp/usr/share/horde/config
	mv debian/tmp/usr/share/horde/docs/* debian/tmp/usr/share/doc/horde/
	cp debian/Debian.Install debian/tmp/usr/share/doc/horde
	cp debian/*.sql.in debian/tmp/usr/share/doc/horde/examples
	cp debian/pgsql_cuser.sh debian/tmp/usr/share/doc/horde/examples
	cp debian/apache_* debian/tmp/usr/share/doc/horde/examples
	cp debian/prepend.php3.in debian/tmp/etc/horde
	cp debian/horde_phplib.inc.in debian/tmp/etc/horde
	cp debian/horde.php3.in debian/tmp/etc/horde
	cp debian/update-horde debian/tmp/usr/sbin
	chmod 755 debian/tmp/etc/horde/horde.php3.in
	-rm -rf debian/tmp/usr/share/horde/scripts \
		debian/tmp/usr/share/horde/docs
	chmod 644 `find debian/tmp -type f -print`
	mv debian/tmp/usr/share/horde/install.sh debian/tmp/usr/share/doc/horde/examples
	mv debian/tmp/usr/share/horde/secure.sh debian/tmp/usr/share/doc/horde/examples
	chmod 755 debian/tmp/usr/share/doc/horde/examples/*.sh

	# add prepend code
	for i in debian/tmp/usr/share/horde/*; 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/`; do \
	  if [ -f $$i ]; then \
	    sed -e "s#./config/#/etc/horde/#" $$i > $$i.tmp; \
	    mv -f $$i.tmp $$i; \
	  fi; \
	done    

	### Done ###

	touch install-stamp

binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdebconf
	dh_installdocs 
	dh_installexamples
	dh_undocumented 
	dh_installchangelogs docs/CHANGES
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	chmod 755 debian/tmp/usr/share/doc/horde/examples/*.sh \
		debian/tmp/usr/share/doc/horde/examples/*.pl \
		debian/tmp/etc/horde/horde.php3.in \
		debian/tmp/usr/sbin/update-horde
	-rm -f install debian/tmp/usr/share/horde/install
	chown -R www-data.root debian/tmp/usr/share/horde debian/tmp/etc/horde
	dh_suidregister
	dh_installdeb
	dh_perl
	dh_shlibdeps
	dh_gencontrol
	cd debian/tmp && find ./etc/horde -type f -print | sed -e 's#^./#/#' > DEBIAN/conffiles
	dh_md5sums
	dh_builddeb

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

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