#!/usr/bin/make -f

# Uncomment to enable verbose build.
#DH_VERBOSE = 1

# Check for changes in the symbols file.
export DPKG_GENSYMBOLS_CHECK_LEVEL=4

# Enable the default build hardening flags.  <https://wiki.debian.org/HardeningWalkthrough>
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# Append the CPPFLAGS to the standard CFLAGS variables.  <https://wiki.debian.org/Hardening#Notes_for_packages_using_CMake>
# These shouldn't be required with debhelper >= 9, but without it blhc detects a missing D_FORTIFY_SOURCE=2.
CFLAGS += $(CPPFLAGS)

# Build the package.
%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
		--with-authdaemonvar=/run/courier/authdaemon \
		--with-mailuser=courier \
		--with-mailgroup=courier \
		--with-pkgconfdir=/etc/courier

execute_after_dh_auto_install:
	#TODO.  See if upstream wants to handle the man page.
	pod2man --center='Debian GNU/Linux Documentation' \
		--release='Debian GNU/Linux '`cat /etc/debian_version` \
		--section=8 debian/authenumerate.pod \
		--verbose \
		> debian/tmp/usr/share/man/man8/authenumerate.8

	# Remove any undefined "an-trap" macros from the man pages.  <https://github.com/svarshavchik/courier/issues/58>
	sed -i '/an-trap/d' debian/tmp/usr/share/man/man1/*
	sed -i '/an-trap/d' debian/tmp/usr/share/man/man3/*

override_dh_makeshlibs:
	# Don't install the ldconfig trigger, as the shared libraries are installed in the courier-authlib subdirectory.
	# <https://man7.org/linux/man-pages/man1/dh_makeshlibs.1.html>
	dh_makeshlibs --no-scripts
