#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic -include errno.h

%:
	dh $@

override_dh_auto_build:
	# Makefile uses files instead of environment variable for...
	# ..compiler command and flags
	test -e conf-cc.orig || cp conf-cc conf-cc.orig
	echo '$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)' > conf-cc

	# ..linker command and flags
	test -e conf-ld.orig || cp conf-ld conf-ld.orig
	echo '$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)' > conf-ld

	test -e conf-home.orig || cp conf-home conf-home.orig
	echo '/usr' > conf-home

	# Finally, make target all
	dh_auto_build

override_dh_installchangelogs:
	dh_installchangelogs package/CHANGES

# Cleanup conf files
override_dh_auto_clean:
	dh_auto_clean

	# Revert Makefile configuration
	for file in conf-cc conf-ld conf-home; do \
	    test ! -r $$file.orig || mv -f $$file.orig $$file || exit 1; \
	done
