#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# be strict when comparing symbols
export DPKG_GENSYMBOLS_CHECK_LEVEL=4

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure-arch:
	dh_auto_configure -- -DSYSREPO_UMASK=002 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DNACM_SRMON_DATA_PERM=660 -DSYSREPO_GROUP=sysrepo -DNOTIFD_SETUP=OFF -DREPO_SHM_SETUP=OFF -DPRINTED_CONTEXT_ADDRESS=0

# Upstream test suite is timing-sensitive on slow ports: on armhf/sparc64 run
# the tests serially, bound each test with a timeout (so a hang cannot stall
# the build), and skip the tests whose timeout/retry logic is known to be racy
# under load there (https://github.com/sysrepo/sysrepo/issues/3717). Re-evaluate
# once an upstream release fixes them.
FLAKY_TEST_ARCHS = armhf sparc64
FLAKY_TESTS = test_rwlock|test_apply_changes|test_process|test_notifd_dispatch

override_dh_auto_test:
ifneq ($(filter nocheck,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)),)
	@echo "Tests skipped (nocheck)"
else ifneq ($(filter $(DEB_HOST_ARCH),$(FLAKY_TEST_ARCHS)),)
	cd obj-$(DEB_HOST_GNU_TYPE) && ctest --output-on-failure --timeout 600 -E '$(FLAKY_TESTS)'
else
	dh_auto_test
endif

ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
override_dh_auto_build-indep:
	dh_auto_build -- doc
endif

override_dh_auto_install-indep:

execute_after_dh_installinit:
	dh_installsysusers
