#! /usr/bin/make -f

include /usr/share/dune/dune-debian.mk

# The ctest run aborts in gmsh4readertest (see debian/changelog), so the test
# suite is skipped through the standard DEB_BUILD_OPTIONS=nocheck switch.
# override_dh_auto_test below calls ctest directly instead of dh_auto_test,
# hence the explicit nocheck check there.
export DEB_BUILD_OPTIONS := $(DEB_BUILD_OPTIONS) nocheck

ifneq ("$(DEB_HOST_ARCH_BITS)", "64")
	# exclude test of reading binary gmsh files on non-64 bit machines
	# # Those files are written withe integer size 64bit but implementation
	# # throws because it only allows for reading 32bit integers
	export DUNE_CTEST_OPTIONS=-E "(gmsh4readertest|gmshtest-uggrid)"
endif

override_dh_install:
	# Manual delete runpath set by openmpi 5.0.5
	# See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1085509
	find debian/tmp/ -name \*.so -o  -name \*.so.\* -exec chrpath -d '{}' \; || true
	dh_install

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dh_auto_build -- $(DUNE_TEST_BUILD_TARGETS)
	cd build; PATH=$(CURDIR)/debian/tmp-test:$$PATH $(DUNE_CTEST) $(DUNE_CTEST_OPTIONS) $(DUNE_TEST_CTEST_LABELS)
else
	@echo "Skipping test suite (nocheck)"
endif

%:
	dh $@ --builddirectory=build --buildsystem=cmake
