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

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# Enable hardening build flags
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

# testrunner fails on some architectures
DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)

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

UPSTREAM_VERSION = $(shell echo $(DEB_VERSION_UPSTREAM) | sed -e 's/\+.*//')

export DEB_CXXFLAGS_MAINT_PREPEND=-fpermissive

%:
	dh $@ --builddirectory=build --buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure -- -DBUILD_DOCUMENTATION=ON

execute_after_dh_auto_build:
	$(MAKE) -C build docs

override_dh_auto_test:
# Ignore test failures on problematic architectures only
ifneq (,$(filter $(DEB_BUILD_ARCH),arm64 armel armhf i386 ppc64el riscv64 s390x alpha hppa hurd-i386 ia64 powerpc ppc64 sparc64))
	dh_auto_test || echo "Ignoring test failures"
else
	dh_auto_test
endif

execute_before_dh_install:
	# add C++ headers to C++ dev package install file
	cp debian/libgeos++-dev.install.in debian/libgeos++-dev.install
	find debian/tmp/usr/include/geos \( -name "*.h" -o -name "*.hpp" \) -a ! -name "export.h" | sed -e 's/^debian\/tmp\///' >> debian/libgeos++-dev.install

	# Remove .asm files
	rm -f debian/tmp/usr/include/geos/algorithm/ttmath/ttmathuint_x86_64_msvc.asm

execute_after_dh_installexamples:
	rm -f debian/*/usr/share/doc/libgeos-dev/examples/capi_indexed_predicate

override_dh_installman:
	dh_installman -plibgeos-dev debian/geos-config.1

override_dh_makeshlibs:
	dh_makeshlibs -- -v$(UPSTREAM_VERSION) -c0
