#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# Clipper2's integer clipping code uses floating-point intermediates when
# calculating rounded intersection coordinates.  On 32-bit x86, GCC's x87
# excess precision changes a few borderline results and makes the upstream
# test suite fail.  Force intermediate values to be stored as declared
# doubles on the affected Debian architectures.
ifneq (,$(filter i386 hurd-i386,$(DEB_HOST_ARCH)))
export DEB_CXXFLAGS_MAINT_APPEND = -ffloat-store
endif

ifneq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
CLIPPER2_ENABLE_TESTS = OFF
else
CLIPPER2_ENABLE_TESTS = ON
endif
CLIPPER2_ENABLE_UTILS = ON

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure --sourcedirectory=CPP --builddirectory=debian/build -- \
		-DBUILD_SHARED_LIBS=ON \
		-DCLIPPER2_UTILS=$(CLIPPER2_ENABLE_UTILS) \
		-DCLIPPER2_EXAMPLES=OFF \
		-DCLIPPER2_TESTS=$(CLIPPER2_ENABLE_TESTS) \
		-DUSE_EXTERNAL_GTEST=ON \
		-DCLIPPER2_USINGZ=ON

override_dh_auto_build:
	dh_auto_build --builddirectory=debian/build

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dh_auto_test --builddirectory=debian/build
endif

override_dh_auto_install:
	dh_auto_install --builddirectory=debian/build
