#!/usr/bin/make -f

#export DH_VERBOSE=1

# Enable hardening build flags
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

# Remove buildpath from binaries
export DEB_CFLAGS_MAINT_APPEND=-DNDEBUG

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

HDF5_INCLUDE_PATH=/usr/include/hdf5/serial
HDF5_LIBRARY_PATH=/usr/lib/$(DEB_HOST_MULTIARCH)/hdf5/serial

include /usr/share/dpkg/pkg-info.mk

UPSTREAM_VERSION = $(shell echo $(DEB_VERSION_UPSTREAM) | sed -e 's/\+.*//')

# Verbose test output
export VERBOSE=1

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure -- \
		-DCMAKE_SKIP_RPATH:BOOL=OFF \
		-DCMAKE_VERBOSE_MAKEFILE=1 \
		-DENABLE_TESTS:BOOL=ON \
		-DENABLE_DOXYGEN:BOOL=ON \
		-DENABLE_PLUGINS:BOOL=OFF \
		-DHDF5_INCLUDE_PATH=$(HDF5_INCLUDE_PATH) \
		-DHDF5_LIBRARY_PATH=$(HDF5_LIBRARY_PATH)

override_dh_auto_test:
	ARGS="--output-on-failure" dh_auto_test --max-parallel=1 || echo "Ignoring test failures"

execute_after_dh_auto_install:
	# Strip RPATH
	-find $(CURDIR)/debian/tmp/usr/bin -type f -not -name nc-config -exec chrpath --delete {} \;
	-find $(CURDIR)/debian/tmp/usr/lib -type f -name "*.so*" -exec chrpath --delete {} \;

override_dh_installchangelogs:
	dh_installchangelogs RELEASE_NOTES.md

override_dh_makeshlibs:
	dh_makeshlibs -- -v$(UPSTREAM_VERSION)
