#!/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 $@ --with pkgkde_symbolshelper --builddirectory=build --buildsystem=cmake

override_dh_clean:
	dh_clean debian/libgeos++-dev.install

override_dh_auto_configure:
	dh_auto_configure -- -DBUILD_DOCUMENTATION=ON

override_dh_auto_build:
	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 mips mips64el mipsel ppc64el s390x alpha hppa ia64 powerpc ppc64 riscv64 sparc64))
	dh_auto_test || echo "Ignoring test failures"
else
	dh_auto_test
endif

override_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

	# Remove .la files
	find debian/tmp/usr/lib -name '*.la' -delete

	dh_install

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

override_dh_strip:
	dh_strip --dbgsym-migration='libgeos-dbg (<< 3.5.1-4~)'

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