#!/usr/bin/make -f

# Uncomment below to enable verbose logging.
#DH_VERBOSE = 1

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

# TODO:  This might not be needed.
include /usr/share/dpkg/default.mk

# Enable all build hardening flags.
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# Export the DPKG default build flags.
DPKG_EXPORT_BUILDFLAGS = 1

# Include the default build flags.  <https://wiki.debian.org/Hardening#dpkg-buildflags>
include /usr/share/dpkg/buildflags.mk

# Append the CPPFLAGS to the standard CFLAGS and CXXFLAGS variables.  <https://wiki.debian.org/Hardening#Notes_for_packages_using_CMake>
CFLAGS += $(CPPFLAGS)
CXXFLAGS += $(CPPFLAGS)


# TODO:  Figure out if this is needed.
, := ,
SED_VERSION=sed -ne 's/^Version: \(.*\)/\1/p'

# Build the package.
%:
	dh $@

execute_before_dh_install:
	# 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/man3/*

override_dh_autoreconf:
	cp unicode_ultcasetab.c unicode_ultcasetab.c.orig
	dh_autoreconf

# TODO:  See if this can be handled by debian/clean.
override_dh_auto_clean:
	dh_auto_clean
	rm -vrf \
		GraphemeBreakProperty.txt \
		LineBreakTest.txt \
		WordBreakProperty.txt \
		WordBreakTest.txt \
		emoji-data.txt \
		DerivedBidiClass.txt \
		BidiBrackets.txt \
		BidiCharacterTest.txt \
		BidiMirroring.txt \
		BidiTest.txt \
		DerivedCoreProperties.txt \
		DerivedNormalizationProps.txt \
		EastAsianWidth.txt \
		LineBreak.txt \
		Scripts.txt \
		UnicodeData.txt \
		a.out \
		xhtml-lat1.ent \
		xhtml-special.ent \
		xhtml-symbol.ent
	[ ! -f unicode_ultcasetab.c.orig ] \
		|| mv -v unicode_ultcasetab.c.orig unicode_ultcasetab.c
	dh_auto_clean
