#!/usr/bin/make -f
# -*- makefile -*-

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

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

ifneq (,$(filter $(DEB_HOST_ARCH_CPU), i386))
  export DEB_CXXFLAGS_MAINT_APPEND += -ffloat-store
endif


%:
	dh $@ --buildsystem=cmake --builddirectory=build-dir-for-deb

# For automating the d/*.links stuff.
export LIBPAPPSOMSPP_VERSION=$(DEB_VERSION_UPSTREAM)
export LIBPAPPSOMSPP_SOVERSION=0

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
  CMAKE_EXTRA_TESTING_ARGS = -DMAKE_TESTS=1 -DBUILD_TESTING=1
endif
# Remove -DMAKE_TESTS=1 \ for the moment
# See comment below.
override_dh_auto_configure:
	dh_auto_configure -- \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_SKIP_RPATH=0 \
		-DUSEPAPPSOTREE=0 \
		$(CMAKE_EXTRA_TESTING_ARGS)

override_dh_auto_build:
	dh_auto_build
	dh_auto_build -- doc

override_dh_auto_test:
	# With the monstrous mess of Catch2
	# in version 3.x having totally changed
	# the header files structure with respect
	# to version 2.x, it is not humanely possible
	# to deal with the tests in stable and unstable.
	#
	# Make Catch2-based tests separately
	# so that their output is conserved.
	# See tests/CMakeLists.txt for details.
	cd build-dir-for-deb && make catch2-tests
	dh_auto_test

