#!/usr/bin/make -f
#export DH_VERBOSE=1

DPKG_EXPORT_BUILDFLAGS=1
export DEB_BUILD_MAINT_OPTIONS=hardening=+all reproducible=+all
include /usr/share/dpkg/buildflags.mk
include /usr/share/dpkg/architecture.mk

# qhelpgenerator stamps CreationTime/LastRegisterTime and the per-file
# TimeStamp into the embedded Qt Help collection (manual-en_US.qhc), which is
# zstd-compressed into the binary's .rodata. It only honors SOURCE_DATE_EPOCH,
# so unless that is pinned, every build bakes in a different wall-clock time
# and the resulting binary (and thus the whole .deb) differs between builds.
#
# We always pass the package's own changelog timestamp below (the same value
# dpkg-buildpackage computes) and override any value the build environment may
# have pre-set: rebuild systems may export a different SOURCE_DATE_EPOCH (e.g.
# their own build timestamp), which would otherwise be baked into the .qhc and
# change the whole binary. The ?= export below covers the rest of the build.
export SOURCE_DATE_EPOCH ?= $(shell dpkg-parsechangelog -STimestamp)

%:
	dh $@ --buildsystem=cmake

SDE := $(shell dpkg-parsechangelog -STimestamp)

execute_before_dh_auto_configure:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
	cd doc/src && SOURCE_DATE_EPOCH=$(SDE) \
		$(MAKE) -B QHELPGENERATOR=/usr/lib/qt6/libexec/qhelpgenerator \
		build-bundled update-prebuilt-manual
endif

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	QT_QPA_PLATFORM=offscreen dh_auto_test -- 'ARGS+=-E ^testdisplayui'
endif
