#!/usr/bin/make -f

# https://wiki.debian.org/HardeningWalkthrough
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

#export DH_VERBOSE=1

# Needed to pass the dh-generated buildflags to the configure script
export EXTRA_CFLAGS=$(CFLAGS) $(CPPFLAGS)
export EXTRA_LDFLAGS=$(LDFLAGS)

%:
	dh $@

override_dh_auto_clean:
	-dh_auto_clean -- clean

override_dh_auto_configure:
	# We need to fix the value of OS, OSENV, and OSFULLSPEC variables
	# in order to make the package reproducible.
	OS=debian OSENV=debian OSFULLSPEC=debian $(MAKE) config \
		VAL_PREFIX=/usr \
		VAL_LIBEXECDIR=/usr/lib/s-nail \
		VAL_SYSCONFDIR=/etc \
		VAL_MTA=/usr/sbin/sendmail \
		VAL_MAIL=/var/mail

override_dh_auto_test: export HOME=$(shell mktemp -d TESTHOME.XXXXXXXX)
override_dh_auto_test:
# Avoid override_dh_auto_test-does-not-check-DEB_BUILD_OPTIONS
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dh_auto_test
	rm -rf TESTHOME.*
endif

override_dh_fixperms:
	dh_fixperms
	chmod 4755 $(CURDIR)/debian/s-nail/usr/lib/s-nail/s-nail-privsep

override_dh_installchangelogs:
	dh_installchangelogs NEWS

