#!/usr/bin/make -f
# You must remove unused comment lines for the released package.
#export DH_VERBOSE = 1

# Not comptible with gcc-4.8
export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-fortify,-stackprotectorstrong,-stackprotector
%:
	dh $@

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    NUMJOBS=$(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
endif

override_dh_autoreconf:
	echo "VERSION=$$(head -1 debian/changelog | sed -e "s/^.*(\(.*\)).*$$/\1/")" > VERSION
	aclocal -I m4
	autoconf

.PHONY: bootstrap
bootstrap :
	DEFAULT_GRADE=hlc.gc.pregen \
	   ./configure --prefix /tmp//mer-boot \
		--enable-libgrades=hlc.gc.pregen
	make PARALLEL=-j$(NUMJOBS) install
	make realclean

override_dh_auto_configure: bootstrap
	PATH=$$PATH:/tmp/mer-boot/bin dh_auto_configure -- \
		--disable-csharp-grade --disable-java-grade

override_dh_auto_build:
	make PARALLEL=-j$(NUMJOBS) all

override_dh_auto_install:
	PARALLEL=-j$(NUMJOBS) dh_auto_install

override_dh_auto_clean:
	chmod a-x samples extras benchmarks
	if [ -x scripts/mmake ]; then dh_auto_clean; fi

# Don't build dbgsym packages, they don't make sense for Mercury.
override_dh_strip:
	dh_strip --no-automatic-dbgsym

# Testing isn't going to work until we can fix the Mercury build system.
override_dh_auto_test:

override_dh_gencontrol:
	dh_gencontrol -- -Tdebian/substvars

