#!/usr/bin/make -f
# -*- makefile -*-

clean: 
	dh_testdir
	dh_testroot

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_prep  
	dh_installdirs
	dh_lintian

# Build architecture-independent files here.
binary-indep: install
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs
	dh_installexamples
	dh_install
	cat var/kolab/www/client/config/registry.php | \
		sed -e "s/'fileroot' *=> *dirname(__FILE__)/'fileroot' => '\/usr\/share\/horde3\/lib'/"| \
		sed -e "s/'templates' *=> *dirname(__FILE__)/'templates' => '\/usr\/share\/horde3\/lib'/"| \
		sed -e "s/'webroot' *=> *_detect_webroot()/'webroot' => '\/horde3'/" > \
		debian/kolab-webclient/etc/kolab-webclient/horde3/registry.php
	cat var/kolab/www/client/imp/config/prefs.php | \
        sed -e "5,10s@require_once dirname(__FILE__) . '/../lib/IMP.php';@require_once '/usr/share/horde3/imp/lib/IMP.php';@" > \
        debian/kolab-webclient/etc/kolab-webclient/imp4/prefs.php
	cat var/kolab/www/client/ingo/config/prefs.php | \
        	sed -e "7,10s@require_once dirname(__FILE__) . '/../lib/Storage.php';@require_once '/usr/share/horde3/ingo/lib/Storage.php';@" > \
        	debian/kolab-webclient/etc/kolab-webclient/ingo1/prefs.php
	cat var/kolab/www/client/mnemo/config/prefs.php | \
	 	sed -e "s@dirname(__FILE__) . '/../@'/usr/share/horde3/mnemo/@" > \
		debian/kolab-webclient/etc/kolab-webclient/mnemo2/prefs.php
	cat var/kolab/www/client/nag/config/prefs.php | \
	 	sed -e "s@dirname(__FILE__) . '/../@'/usr/share/horde3/nag/@" > \
		debian/kolab-webclient/etc/kolab-webclient/nag2/prefs.php
	#
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	chown -R www-data:www-data debian/kolab-webclient/var/lib/kolab-webclient
	chmod -R o-rx debian/kolab-webclient/var/lib/kolab-webclient
	chown -R www-data:www-data debian/kolab-webclient/var/log/kolab-webclient
	chmod -R o-rx debian/kolab-webclient/var/log/kolab-webclient
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
# This is an architecture-independent packages, we have nothing to do
binary-arch: install

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