#!/usr/bin/make -f

# DH_VERBOSE := 1

# Verbose make output
export VERBOSE=1

DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)

%:
	dh $@ --parallel --builddirectory=build

override_dh_auto_configure:
	dh_auto_configure -- -DCMAKE_VERBOSE_MAKEFILE=1

override_dh_auto_build-arch:
	dh_auto_build --arch

override_dh_auto_build-indep:
	(cd build && $(MAKE) doc)

override_dh_auto_test-arch:
# Ignore test failures on problematic architectures only
ifneq (,$(findstring $(DEB_BUILD_ARCH),"arm64 mips mipsel ppc64 ppc64el sparc64"))
	(cd build && ctest -V || echo "Ignoring test failures")
else
	(cd build && ctest -V)
endif

override_dh_auto_test-indep:
	# Skip tests when build-arch target was not executed

override_dh_installchangelogs:
	dh_installchangelogs -k CHANGELOG.md

override_dh_installdocs:
	dh_installdocs

	# Remove embedded jquery.js in favor of libjs-jquery
	$(RM) debian/*/usr/share/doc/*/html/jquery.js

	# Remove useless autogenerated doxygen file
	$(RM) debian/*/usr/share/doc/*/html/*.md5

