#!/usr/bin/make -f

# This has to be exported to make some magic below work.
export DH_OPTIONS

# Make use of security features through hardening-wrapper
export DEB_BUILD_HARDENING=1

# Check for this output after running configure
check_options = \
"  AVFS usage                  : no" \
"  Large file support          : yes" \
"  Regular expressions support : yes" \
"  X11 XIM usage               : yes" \
"  UTF8 support                : yes" \
"  Libmagic support            : yes"

# Check this output does not appear after running configure
check_options_not_there = \
"  XFT support                 : yes (EXPERIMENTAL)" \
"  Debug code                  : yes"

%:
	dh $@

build: build-stamp
build-stamp:
	dh build --before configure
	# Do not support the avfs library (enabled by default since 2.11.2)
	dh_auto_configure -- --with-avfs=no --with-libmagic \
		| tee configure-output
	# check whether all wanted features are included and no other
	# options are enabled errorneously -- otherwise exit with an error
	for tmp in $(check_options) ; do \
		echo -n "Checking for \"$$tmp\" ... " ; \
		grep "$$tmp" configure-output > /dev/null \
			&& echo "OK" \
			|| (echo "FAILED" ; touch check_options_failed) ; \
	done
	# check whether these features do not appear --
	# otherwise exit with an error
	for tmp in $(check_options_not_there) ; do \
		echo -n "Checking that \"$$tmp\" does not appear ... " ; \
		grep -v "$$tmp" configure-output > /dev/null \
			&& echo "OK" \
			|| (echo "FAILED" ; touch check_options_failed) ; \
	done
	rm -f configure-output
	if [ -e check_options_failed ] ; then \
		rm -f check_options_failed ; \
		/bin/false ; \
	fi
	dh build --after configure
	touch $@
