#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

export PERL_MM_USE_DEFAULT=1

LMSHAREDIR=/usr/share/lemonldap-ng/
LMVARDIR=/var/lib/lemonldap-ng/

configure: configure-stamp
configure-stamp:
	dh_testdir

	# Add here commands to configure the package.
	$(MAKE) configure STORAGECONFFILE=/etc/lemonldap-ng/storage.conf \
			PERLOPTIONS="INSTALLDIRS=vendor"

	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp 
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE)

	touch $@

clean:
	dh_testdir
	dh_testroot
	debconf-updatepo
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	[ ! -f Makefile ] || $(MAKE) clean

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/lemonldap-ng.
	$(MAKE) test
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp \
			PREFIX=/usr/ \
			BINDIR=$(LMSHAREDIR)bin/ \
			DOCUMENTROOT=$(LMVARDIR) \
			EXAMPLESDIR=/examples/ \
			HANDLERDIR=$(LMVARDIR)handler/ \
			PORTALSKINSDIR=$(LMSHAREDIR)portal-skins/ \
			MANAGERDATADIR=$(LMSHAREDIR)manager-imgs/ \
			SESSIONSEXPLORERDATADIR=$(LMSHAREDIR)sessions-explorer-imgs/ \
			STORAGECONFFILE=/etc/lemonldap-ng/storage.conf \
			TOOLSDIR=$(LMSHAREDIR)ressources/ \
			CONFDIR=/etc/lemonldap-ng/ \
			CRONDIR=/etc/cron.d/ \
			DATADIR=$(LMVARDIR) \
			APACHEUSER=www-data \
			APACHEGROUP=www-data

	# Since Lenny, jquery.js is provided by libjs-jquery
	rm -f $(CURDIR)/debian/tmp$(LMSHAREDIR)portal-skins/*/jquery.js \
		$(CURDIR)/debian/tmp$(LMVARDIR)manager/jquery.js \
		debian/tmp/examples/manager/jquery.js
	perl -i -pe 's#(["'"'"'])[\w-\./]*jquery.js#$$1/javascript/jquery/jquery.js#' \
			$(CURDIR)/debian/tmp/examples/manager/*.pl \
			$(CURDIR)/debian/tmp$(LMSHAREDIR)portal-skins/pastel/header.tpl
	# postinst provides initial portal, manager and sessions-explorer
	rm -f debian/tmp/var/lib/lemonldap-ng/portal/index.pl \
		debian/tmp/var/lib/lemonldap-ng/liberty-alliance-sp-portal/index.pl \
		debian/tmp/var/lib/lemonldap-ng/manager/index.pl \
		debian/tmp/var/lib/lemonldap-ng/manager/sessions.pl

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs changelog
	dh_installdocs
	dh_installexamples
	dh_install
	mkdir -p debian/lemonldap-ng/usr/share/doc/lemonldap-ng/examples && \
		cd debian/lemonldap-ng/usr/share/doc/lemonldap-ng/examples && \
		ln -s ../../liblemonldap-ng-handler-perl/examples handler && \
		ln -s ../../liblemonldap-ng-manager-perl/examples manager && \
		ln -s ../../liblemonldap-ng-portal-perl/examples portal && \
		ln -s ../../liblemonldap-ng-conf-perl/examples/ conf
	chmod +x debian/liblemonldap-ng-portal-perl$(LMSHAREDIR)bin/purgeCentralCache
#	dh_installmenu
	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_python
#	dh_installinit
	dh_installcron
#	dh_installinfo
	dh_installman
	dh_link
	dh_strip
	dh_compress -X.pm -X.pl
	dh_fixperms
#	dh_perl
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch: build install

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