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

SARGE_PACKAGE=`cat debian/changelog  | head -n1 | grep sarge`
ETCH_PACKAGE=`cat debian/changelog  | head -n1 | grep etch`
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

build: patch 
	#*************************************************
	#* Building GOsa into a Debian/GNU Linux Package *
	#*                 please stand by               *
	#*************************************************

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

unpatch:
	dpatch deapply-all
	rm -rf patch-stamp debian/patched

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

	for i in `ls | grep -v debian`; do \
	  cp -R $$i debian/gosa/usr/share/gosa ; \
	done
	-find debian/gosa -type d -name ".svn" -exec rm -rf {} \; &> /dev/null || /bin/true
	-cp -R debian/gosa/usr/share/gosa/contrib/* debian/gosa/usr/share/doc/gosa/contrib/
	-cp debian/gosa/usr/share/gosa/contrib/openldap/go*.schema debian/gosa-schema/etc/ldap/schema
	-cp -R INSTALL debian/gosa/usr/share/doc/gosa/README.INSTALL
	-gzip -c9 debian/changelog > debian/gosa/usr/share/doc/gosa/changelog.Debian.gz
	-mkdir -p debian/gosa-schema/usr/share/doc/gosa-schema
	-gzip -c9 debian/changelog > debian/gosa-schema/usr/share/doc/gosa-schema/changelog.Debian.gz
	-mkdir -p debian/gosa-desktop/usr/share/doc/gosa-desktop
	-gzip -c9 debian/changelog > debian/gosa-desktop/usr/share/doc/gosa-desktop/changelog.Debian.gz
	-mkdir -p debian/gosa-help-de/usr/share/doc/gosa-help-de
	-gzip -c9 debian/changelog > debian/gosa-help-de/usr/share/doc/gosa-help-de/changelog.Debian.gz
	-mkdir -p debian/gosa-help-en/usr/share/doc/gosa-help-en
	-gzip -c9 debian/changelog > debian/gosa-help-en/usr/share/doc/gosa-help-en/changelog.Debian.gz
	-mkdir -p debian/gosa-help-fr/usr/share/doc/gosa-help-fr
	-gzip -c9 debian/changelog > debian/gosa-help-fr/usr/share/doc/gosa-help-fr/changelog.Debian.gz
	-mkdir -p debian/gosa-help-nl/usr/share/doc/gosa-help-nl
	-gzip -c9 debian/changelog > debian/gosa-help-nl/usr/share/doc/gosa-help-nl/changelog.Debian.gz
	-gzip -c9 Changelog > debian/gosa/usr/share/doc/gosa/changelog.gz
	-cp AUTHORS README FAQ doc/README.pptp doc/README.glpi doc/README.nagios doc/README.phpscheduleit doc/README.safemode doc/README.devel doc/README.openxchange debian/gosa/usr/share/doc/gosa/
	-rm debian/gosa/usr/share/gosa/README debian/gosa/usr/share/gosa/INSTALL
	-rm debian/gosa/usr/share/gosa/AUTHORS debian/gosa/usr/share/gosa/Changelog
	-rm debian/gosa/usr/share/gosa/FAQ debian/gosa/usr/share/gosa/COPYING
	-mkdir -p debian/gosa/var/spool/gosa/compile
	-mkdir -p debian/gosa/var/spool/gosa/config
	-mkdir -p debian/gosa/var/spool/gosa/cache
	-rm -rf debian/gosa/usr/share/gosa/compile
	-mv debian/gosa/usr/share/gosa/update-config debian/gosa/usr/share/doc/gosa/contrib
	-mkdir -p debian/gosa/etc/gosa/vacation
	-cp -R debian/apache.conf debian/gosa/etc/gosa/apache.conf
	-cp -R contrib/encodings debian/gosa/etc/gosa/encodings
	-cp -R plugins/personal/mail/sieve-*.txt debian/gosa/etc/gosa
	-cp contrib/shells debian/gosa/etc/gosa
	-rm debian/gosa/usr/share/gosa/bin/gosa
	-mkdir -p debian/gosa/usr/lib/gosa
	-mv debian/gosa/usr/share/gosa/bin/* debian/gosa/usr/bin
	-rm -rf debian/gosa/usr/share/gosa/bin
	-rm -rf debian/gosa/usr/share/doc/gosa/marketing
	-find debian/gosa -type f -exec chmod -x {} \; &> /dev/null
	-chmod +x debian/gosa/usr/bin/mkntpasswd
	-rm -rf debian/gosa/usr/share/gosa/doc/guide/user/*/lyx-source
	-rm -rf debian/gosa/usr/share/gosa/doc/guide/admin
	-rm -rf debian/gosa/usr/share/gosa/doc/guide/devel
	-for lang in en de fr nl; do mkdir -p debian/gosa-help-$$lang/usr/share/gosa/doc/guide/user/$$lang; done
	-for lang in en de fr nl; do mv debian/gosa/usr/share/gosa/doc/guide/user/$$lang/* debian/gosa-help-$$lang/usr/share/gosa/doc/guide/user/$$lang/; done
	-cp -R debian/gosa/usr/share/gosa/doc/* debian/gosa/usr/share/doc/gosa
	-cp -R contrib/scripts/desktoprc debian/gosa-desktop/etc/gosa/desktoprc
	-cp -R contrib/scripts/start-gosa.sh debian/gosa-desktop/usr/bin/gosa
	-cp -R debian/gosa*.xpm debian/gosa-desktop/usr/share/pixmaps
	-cp -R debian/gosa-desktop.desktop debian/gosa-desktop/usr/share/applications/gosa.desktop
	-rm -rf debian/gosa/usr/share/gosa/contrib
	-rm -rf debian/gosa/usr/share/gosa/locale/en
	-rm -rf debian/gosa/usr/share/gosa/update-locale
	-rm -rf debian/gosa/usr/share/gosa/update-pdf-help
	-rm -rf debian/gosa/usr/share/gosa/patch-stamp
	-rm -rf debian/gosa/usr/share/gosa/update-online-help
	-rm -rf debian/gosa/usr/share/gosa/update-gosa
	-rm -rf debian/gosa/usr/share/gosa/update-config
	-rm -rf debian/gosa/usr/share/doc/gosa/guide*
	sed 's%"CONFIG_TEMPLATE_DIR", "../contrib/"%"CONFIG_TEMPLATE_DIR", "/usr/share/doc/gosa/contrib/"%g' debian/gosa/usr/share/gosa/include/functions.inc > debian/gosa/usr/share/gosa/include/functions.inc.new; \
	mv debian/gosa/usr/share/gosa/include/functions.inc.new debian/gosa/usr/share/gosa/include/functions.inc;
	-if [ -z "${SARGE_PACKAGE}" ]; then \
		rm -rf debian/gosa/usr/share/gosa/include/smarty; \
		sed 's%require("smarty/Smarty.class.php");%require("/usr/share/php/smarty/libs/Smarty.class.php");%g' debian/gosa/usr/share/gosa/include/php_setup.inc > debian/gosa/usr/share/gosa/include/php_setup.inc.new; \
		mv debian/gosa/usr/share/gosa/include/php_setup.inc.new debian/gosa/usr/share/gosa/include/php_setup.inc; \
	fi
	install -D -m 644 debian/overrides-lintian debian/gosa/usr/share/lintian/overrides/gosa
	install -D -m 644 debian/overrides-linda debian/gosa/usr/share/linda/overrides/gosa
	touch install-stamp

patch: patch-stamp
patch-stamp:
	dpatch apply-all
	dpatch cat-all >patch-stamp

binary-indep: install
	dh_testdir
	dh_testroot
	dh_installdocs 
	dh_installcron
	dh_installexamples
	dh_installdebconf
	dh_installmenu
	dh_installman --package=gosa debian/mkntpasswd.1
	dh_installman --package=gosa-desktop debian/gosa.1
	dh_link
	dh_strip
	dh_compress --exclude=gosa.conf
	dh_fixperms 
	dh_perl
	dh_installdeb
	dh_shlibdeps

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

	-if [ -z "${SARGE_PACKAGE}" ]; then \
		if [ -z "${ETCH_PACKAGE}" ]; then \
			dh_gencontrol; \
		else \
			dh_gencontrol -- -cdebian/control.etch; \
		fi ; \
	else \
		dh_gencontrol -- -cdebian/control.sarge; \
	fi
	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

binary-arch:

