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

export DEB_BUILD_MAINT_OPTIONS = hardening=+pie

# Keep track of files we don't install
NOT_INSTALLED := \
	etc/rc.d/init.d/dirsrv-snmp \
	etc/rc.d/init.d/dirsrv \
	etc/default/dirsrv

REALFILE = \
	bin/cl-dump.pl \
	bin/dbgen.pl \
	bin/ds-logpipe.py \
	bin/logconv.pl \
	bin/repl-monitor.pl \
	bin/dbscan-bin \
	bin/dsktune-bin \
	bin/infadd-bin \
	bin/ldclt-bin \
	bin/ldif-bin \
	bin/migratecred-bin \
	bin/mmldif-bin \
	bin/pwdhash-bin \
	bin/rsearch-bin	\
	sbin/ldap-agent-bin \
	sbin/migrate-ds.pl \
	sbin/remove-ds.pl \
	sbin/setup-ds.pl \
	share/man/man1/dbgen.pl.1 \
	share/man/man1/ds-logpipe.py.1 \
	share/man/man1/logconv.pl.1 \
	share/man/man8/migrate-ds.pl.8 \
	share/man/man8/setup-ds.pl.8 \
	share/man/man8/remove-ds.pl.8

override_dh_auto_configure:
	dh_auto_configure -- \
		--with-openldap \
		--enable-autobind

override_dh_install:
	# lets do the renaming here afterall, instead of in 389-ds-base.install
	for file in $(REALFILE); do mv -f $(CURDIR)/debian/tmp/usr/$$file \
		$(CURDIR)/debian/tmp/usr/`echo $$file | \
		sed -s 's/\-bin//;s/\.pl//;s/\.py//'`; \
		done
	# purge .la files
	find $(CURDIR)/debian/tmp -name "*.la" -type f -exec rm -f "{}" \;
	# fix template script headers
	find $(CURDIR)/debian/tmp/usr/share/dirsrv/script-templates/ -type f -exec perl -pi -e  's,#\{\{PERL-EXEC\}\},#!/usr/bin/perl,' "{}" \;	

	# Also get rid of other files which aren't installed. Do not
	# use -f to ensure we notice disappearing files:
	set -e; for file in $(NOT_INSTALLED); do rm debian/tmp/$$file; done

	dh_install --fail-missing

override_dh_installinit:
	dh_installinit --name dirsrv --error-handler=invoke_failure -- defaults 15 85

override_dh_strip:
	dh_strip -p389-ds-base-libs --dbg-package=389-ds-base-libs-dbg
	dh_strip -p389-ds-base --dbg-package=389-ds-base-dbg

override_dh_shlibdeps:
	dh_shlibdeps -l"debian/389-ds-base/usr/lib/$(DEB_HOST_MULTIARCH)/dirsrv" -a

%:
	dh $@ --with autoreconf --builddir build/
