#!/usr/bin/make -f

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

ifneq (,$(filter $(DEB_HOST_ARCH), armel m68k mips mipsel powerpc sh4))
	export DEB_CXXFLAGS_MAINT_APPEND += -Wl,--no-as-needed -latomic -Wl,--as-needed
	export DEB_LDFLAGS_MAINT_APPEND += -Wl,--no-as-needed -latomic -Wl,--as-needed
endif

# Tell CMake what the package version will be, to embed in the version string.
# We do this for upstream's benefit, in lieu of including a git commit hash.
CMAKEOPTS=-DDEBVERSION=$(DEB_VERSION)
CMAKEOPTS+= -DENABLE_OPENMP=yes
CMAKEOPTS+= -DENABLE_LTO=yes

#speed up the build if we are skipping the tests
ifneq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
ifneq (amd64,$(DEB_HOST_ARCH))
CMAKEOPTS+= -DENABLE_TESTS=off
endif
endif

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- $(CMAKEOPTS)

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
ifeq (amd64,$(DEB_HOST_ARCH))
	cd obj-* && $(MAKE) -j$(nproc) test_solvespace
endif
endif
