#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk # for DEB_HOST_GNU_TYPE

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure --               \
		-DCMAKE_BUILD_TYPE=Release \
		-DAMPL=OFF                 \
		-DEXPRINT=none             \
		-DSYM=nauty                \
		-DZIMPL=ON

execute_before_dh_auto_build: src/scip/githash.c

# not in git repository; update this at each release
src/scip/githash.c:
	echo "#define SCIP_GITHASH \"76a50c97d6\"" > $@

execute_after_dh_auto_build-indep:
	cd obj-$(DEB_HOST_GNU_TYPE) && $(MAKE) doc

execute_before_dh_installman: debian/scip.1

debian/scip.1:
	help2man -N -o $@ -n "Solving Constraint Integer Programs" \
		debian/tmp/usr/bin/scip
	sed -i '/^invalid parameter <\\-\\-help>$$/ { N; /\n\.PP$$/d }' $@
	sed -i 's|debian/tmp/usr/bin/||' $@

override_dh_auto_test:
	cd obj-$(DEB_HOST_GNU_TYPE) && $(MAKE) check

# generate test file for autopkgtest; update this at each release
debian/tests/CTestTestfile.cmake: obj-$(DEB_HOST_GNU_TYPE)/check/CTestTestfile.cmake
	cp $< $@
	sed -i '/default/!d' $@
	sed -i '/Objlim/d' $@ # only fails in autopkgtest, not during build (why?)
	sed -i 's/DEPENDS "scip-build" //g' $@
	sed -i 's/ _BACKTRACE_TRIPLES "[^"]*"//g' $@
	sed -i 's|"[^"]*/bin/scip|"/usr/bin/scip|g' $@
	sed -Ei 's|(["<])[^"<]*/check|\1@BUILDDIR@/check|g' $@
