#!/usr/bin/make -f

%:
	dh $@ --with bash-completion

override_dh_auto_build:
	make -C $(CURDIR)/doc -f Makefile debian

override_dh_clean:
	dh_clean
	make -C $(CURDIR)/doc -f Makefile clean

override_dh_install:
	dh_install -X .gitignore -X .placefolder -X tmp

	# Move local directory as /usr/local/share/ldapsaisie
	# Note: a symbolic link will be install by dh_link
	mv $(CURDIR)/debian/ldapsaisie/usr/share/ldapsaisie/local $(CURDIR)/debian/ldapsaisie/usr/local/share/ldapsaisie
	# Remove all files in local directory
	find $(CURDIR)/debian/ldapsaisie/usr/local/share/ldapsaisie -type f -exec rm -f \{\} \;

	# Change default log file path
	sed -i 's/tmp\/LS.log/\/var\/log\/ldapsaisie\/ldapsaisie.log/' $(CURDIR)/debian/ldapsaisie/usr/share/ldapsaisie/conf/config.inc.php
	# Change default public_root_url
	sed -i "s/^\(\s*'public_root_url' => \).*/\1'\/ldapsaisie\/',/" $(CURDIR)/debian/ldapsaisie/usr/share/ldapsaisie/conf/config.inc.php
	# Change LS_VERSION
	sed -i "s/^define('LS_VERSION',.*/define('LS_VERSION', '$(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ')');/" $(CURDIR)/debian/ldapsaisie/usr/share/ldapsaisie/includes/core.php

	# Make a copy of default config.inc.php to /usr/local/share/ldapsaisie/conf/config.inc.example.php (=/etc/ldapsaisie/local/conf/config.inc.php)
	cp $(CURDIR)/debian/ldapsaisie/usr/share/ldapsaisie/conf/config.inc.php $(CURDIR)/debian/ldapsaisie/usr/local/share/ldapsaisie/conf/config.inc.example.php

override_dh_usrlocal: