#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.

built_binaries := $(shell dh_listpackages)

#export DH_VERBOSE = 1


# See FEATURE AREAS in dpkg-buildflags(1).
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# See ENVIRONMENT in dpkg-buildflags(1).
# Package maintainers to append CFLAGS.
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# Package maintainers to append LDFLAGS.
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

export DEB_LDFLAGS_MAINT_APPEND = -Wl,-O1 -Wl,-O1 -Wl,-z,defs
export DPKG_GENSYMBOLS_CHECK_LEVEL = 4

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 $@


# dh_make generated override targets.
# This is an example for Cmake (see <https://bugs.debian.org/641051>).
#override_dh_auto_configure:
#	dh_auto_configure -- \
#	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

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/

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

override_dh_gnome_clean:
	dh_gnome_clean --no-control