#!/usr/bin/make -f

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

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

# needed with the Ubuntu toolchain to avoid issues
export DEB_LDFLAGS_MAINT_STRIP := -Wl,-Bsymbolic-functions

ifeq (,$(filter $(DEB_HOST_ARCH), amd64 arm64 armel armhf i386 mips64el ppc64el riscv64 s390x hppa loong64 powerpc ppc64 sh4))
	BUILD_UNWIND += -Dlibunwind=disabled
endif
# see https://gitlab.gnome.org/GNOME/geary/issues/726:
ifneq (,$(filter $(DEB_HOST_ARCH), powerpc ppc64 s390x))
	DISABLE_YTNEF += -Dtnef=disabled
endif

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- $(BUILD_UNWIND) $(DISABLE_YTNEF) -Drevno=$(DEB_VENDOR)/$(DEB_VERSION) -Dprofile=release

# Upstream test timeouts assume an otherwise unloaded system, but that
# isn't necessarily the case for a porterbox or multiple parallel builds.
# Keep the timeout reasonably short for architectures where interactive
# debugging is more likely, but extend it a lot on architectures that might
# be very slow or using qemu for buildds.
ifneq ($(filter amd64 i386,$(DEB_HOST_ARCH_CPU)),)
test_timeout_multiplier = 3
else
test_timeout_multiplier = 20
endif

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	LIBGL_ALWAYS_SOFTWARE=true localehelper LC_COLLATE=en_US.UTF-8 dbus-run-session -- xvfb-run -a dh_auto_test --no-parallel -- --verbose --timeout-multiplier $(test_timeout_multiplier)
endif

override_dh_shlibdeps:
	dh_shlibdeps -l/usr/lib/$(DEB_HOST_MULTIARCH)/geary

override_dh_makeshlibs:
	dh_makeshlibs --no-scripts
