#!/usr/bin/make -f
#export DH_VERBOSE = 1

# Select the Debian install layout for Python
export DEB_PYTHON_INSTALL_LAYOUT=deb

# tests usually take just under an hour
# repro build servers can take longer
# use 3h instead of the default 25m
TEST_ARGS = --timeout 10800

# ctest normally suppresses test output
# https://cmake.org/cmake/help/latest/manual/ctest.1.html#options
# debhelper 13.5 enables ctest output when build is not terse
# reimplement this when debhelper is too old to support this
ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
DEBHELPER_VERSION = $(strip $(shell dpkg-query -f '$${Version}' -W debhelper))
DEBHELPER_OK = $(strip $(shell dpkg --compare-versions $(DEBHELPER_VERSION) ge 13.5~; echo $$?))
ifneq ($(DEBHELPER_OK),0)
	TEST_ARGS += --verbose
endif
endif

# Boost tests normally don't print the test entry/exit
# https://www.boost.org/doc/libs/release/libs/test/doc/html/boost_test/utf_reference/rt_param_reference/log_level.html
# Since the SPTAG tests print a lot of output and sometimes fail
# it is useful to have the test names printed during the output
# so enable that when the build is not terse
ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
export BOOST_TEST_LOG_LEVEL=test_suite
endif

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic

%:
	dh $@ --buildsystem=cmake

override_dh_auto_test:
	# Workaround one test breaking several others
	# by running it during a separate test run.
	# https://github.com/microsoft/SPTAG/issues/375
	# https://bugs.debian.org/1033944
	BOOST_TEST_RUN_FILTERS='!AlgoTest/SPANNTest' dh_auto_test -- ARGS+="$(TEST_ARGS)"
	BOOST_TEST_RUN_FILTERS='AlgoTest/SPANNTest' dh_auto_test -- ARGS+="$(TEST_ARGS)"
