#!/usr/bin/make -f

clean:
	dh_testdir
	dh_testroot
	debconf-updatepo
	dh_clean

build: build-arch build-indep

build-arch: build-stamp

build-indep: build-stamp
	debian/minify

build-stamp:

install:
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	install -D --mode=644 index.html debian/ldap-account-manager/usr/share/ldap-account-manager/index.html
	install -D --mode=644 VERSION debian/ldap-account-manager/usr/share/ldap-account-manager/VERSION
	install -D --mode=644 pwa_worker.js debian/ldap-account-manager/usr/share/ldap-account-manager/pwa_worker.js
	install -D --mode=644 tmp/.htaccess debian/ldap-account-manager/var/lib/ldap-account-manager/tmp/.htaccess
	install -D --mode=644 tmp/internal/.htaccess debian/ldap-account-manager/var/lib/ldap-account-manager/tmp/internal/.htaccess
	install -D --mode=644 config/.htaccess debian/ldap-account-manager/var/lib/ldap-account-manager/config/.htaccess
	install -D --mode=644 config/language debian/ldap-account-manager/var/lib/ldap-account-manager/config/language
	install -D --mode=644 config/*.conf.sample debian/ldap-account-manager/var/lib/ldap-account-manager/config/
	install -D --mode=644 config/config.cfg.sample debian/ldap-account-manager/var/lib/ldap-account-manager/config/config.cfg.sample
	install -d --mode=755 debian/ldap-account-manager/var/lib/ldap-account-manager/config/pdf
	install -d --mode=755 debian/ldap-account-manager/var/lib/ldap-account-manager/config/profiles
	install -d --mode=755 debian/ldap-account-manager/var/lib/ldap-account-manager/config/selfService
	install -d --mode=755 debian/ldap-account-manager/usr/share/ldap-account-manager/config-samples
	cp -r config/templates/profiles debian/ldap-account-manager/usr/share/ldap-account-manager/config-samples/
	cp -r config/templates/pdf debian/ldap-account-manager/usr/share/ldap-account-manager/config-samples/
	cp -r graphics debian/ldap-account-manager/usr/share/ldap-account-manager/
	install -D --mode=644 help/help.inc debian/ldap-account-manager/usr/share/ldap-account-manager/help/help.inc
	install -D --mode=644 lib/.htaccess debian/ldap-account-manager/usr/share/ldap-account-manager/lib/.htaccess
	install -D --mode=644 lib/*.inc debian/ldap-account-manager/usr/share/ldap-account-manager/lib
	install -D --mode=755 lib/*.sh debian/ldap-account-manager/usr/share/ldap-account-manager/lib
	cp -r lib/modules debian/ldap-account-manager/usr/share/ldap-account-manager/lib/
	cp -r lib/types debian/ldap-account-manager/usr/share/ldap-account-manager/lib/
	cp -r lib/tools debian/ldap-account-manager/usr/share/ldap-account-manager/lib/

	# 3rd party libs are linked
	install -d --mode=755 debian/ldap-account-manager/usr/share/ldap-account-manager/lib/3rdParty
	cp -r lib/3rdParty/yubico debian/ldap-account-manager/usr/share/ldap-account-manager/lib/3rdParty/
	cp -r lib/3rdParty/tcpdf debian/ldap-account-manager/usr/share/ldap-account-manager/lib/3rdParty/
	cp -r lib/3rdParty/duo debian/ldap-account-manager/usr/share/ldap-account-manager/lib/3rdParty/

	cp -r locale debian/ldap-account-manager/usr/share/ldap-account-manager/
	install -D --mode=644 sess/.htaccess debian/ldap-account-manager/var/lib/ldap-account-manager/sess/.htaccess
	cp -r style debian/ldap-account-manager/usr/share/ldap-account-manager/
	cp -r templates debian/ldap-account-manager/usr/share/ldap-account-manager/

	install -D --mode=755 lib/lamdaemon.pl debian/ldap-account-manager-lamdaemon/usr/share/ldap-account-manager/lib/lamdaemon.pl
	install -D --mode=755 debian/README-lamdaemon.Debian debian/ldap-account-manager-lamdaemon/usr/share/doc/ldap-account-manager-lamdaemon/README.Debian

# Build architecture-independent files here.
binary-dep: build install

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs HISTORY
	dh_installdocs
	dh_install
	dh_compress
	dh_fixperms
	dh_link /usr/share/doc/ldap-account-manager/docs /usr/share/ldap-account-manager/docs
	install -D --mode=644 debian/lam.apache.conf debian/ldap-account-manager/etc/ldap-account-manager/apache.conf
	install -D --mode=644 debian/lam.nginx.conf debian/ldap-account-manager/etc/ldap-account-manager/nginx.conf
	install -D --mode=644 config/config.cfg.sample debian/ldap-account-manager/etc/ldap-account-manager/config.cfg
	dh_link /etc/ldap-account-manager/config.cfg /var/lib/ldap-account-manager/config/config.cfg
	dh_installdebconf
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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

binary-arch: