#!/usr/bin/make -f

built_binaries := $(shell dh_listpackages)

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,-O1 -Wl,-O1 -Wl,-z,defs

include /usr/share/dpkg/default.mk

ifeq ($(DEB_HOST_ARCH_OS), hurd)
	EXTRA_CONFIGURE_OPTIONS=-Dlibv4l=disabled -Dlibv4l2=disabled
else
	EXTRA_CONFIGURE_OPTIONS=
endif

ifeq ($(filter %-doc,$(built_binaries)),)
EXTRA_CONFIGURE_OPTIONS += -Dgi-docgen=disabled
else
EXTRA_CONFIGURE_OPTIONS += -Dgi-docgen=enabled
endif

# Upstream test timeouts assume an otherwise unloaded system, but that
# isn't necessarily the case for a porterbox or multiple parallel builds
test_timeout_multiplier = 3

ifneq ($(filter aarch64 arm% hppa mips% sparc%,$(DEB_HOST_ARCH_CPU)),)
# These architectures are typically slower, particularly for the sort of
# floating-point processing we're doing here
test_timeout_multiplier = 10
endif

ifneq ($(filter m68k riscv64 sh4,$(DEB_HOST_ARCH_CPU)),)
# These architectures are known to have qemu buildds, which are really slow
test_timeout_multiplier = 20
endif

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
		-Dauto_features=enabled \
		-Ddocs=true \
		-Djasper=disabled \
		-Dlibav=disabled \
		-Dlua=disabled \
		-Dmrg=disabled \
		-Dpygobject=disabled \
		-Dsdl1=disabled \
		-Dsdl2=disabled \
		$(EXTRA_CONFIGURE_OPTIONS)

# These json files appear to only be needed for distcheck according to git log
override_dh_missing:
	dh_missing -Xgrey2.json -Xdropshadow2.json

override_dh_makeshlibs:
	dh_makeshlibs -X/usr/lib/$(DEB_HOST_MULTIARCH)/gegl-0.4/ -- -c4

override_dh_auto_test:
	dh_auto_test --no-parallel -- --timeout-multiplier $(test_timeout_multiplier)

override_dh_gnome_clean:
	dh_gnome_clean --no-control

# No dbgsym packages:
override_dh_strip:
	@echo "NO--THANKS ANYWAY--but not building dbgsym packages for MX Linux"
	dh_strip --no-automatic-dbgsym
