#!/usr/bin/make -f

# meson.build already sets -D_FORTIFY_SOURCE=3; dpkg's =2 would override it.
export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-fortify

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

# The About dialog shows the build date; take it from the changelog so the
# build is reproducible.
BUILD_DATE := $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" +%Y-%m-%d)

%:
	dh $@

# Source builds run in a network-isolated chroot (sbuild/pbuilder), and
# wgpu-native is not packaged, so WebGPU is left out. The optional codecs are
# required explicitly so a missing build dependency fails the build instead of
# silently dropping a feature.
# PDF.js, Wuffs and WAMR are wraps meson normally downloads. An offline build
# gets them from debian/vendor/, filled by scripts/fetch-wrap-sources.sh before
# the source package is made (see docs/Debian.md). Wuffs is required; without
# PDF.js the package builds with no PDF viewer.
execute_before_dh_auto_configure:
	mkdir -p subprojects/packagecache
	cp debian/vendor/*.tgz debian/vendor/*.tar.gz subprojects/packagecache/ 2>/dev/null || true

override_dh_auto_configure:
	dh_auto_configure -- \
		-Dwebgpu=disabled \
		-Davif=enabled \
		-Djxl=enabled \
		-Dgstreamer=enabled \
		-Daudio=enabled \
		-Dbuild_date=$(BUILD_DATE)

# libnordstjernen.so and its header are the embedding API for other
# applications. Nothing in this package links them and the library carries no
# SONAME version, so they are not shipped.
execute_after_dh_auto_install:
	rm debian/nordstjernen-browser/usr/bin/open-browser-nordstjernen
	rm debian/nordstjernen-browser/usr/lib/$(DEB_HOST_MULTIARCH)/libnordstjernen.so
	rm -r debian/nordstjernen-browser/usr/include
	find debian/nordstjernen-browser/usr/lib -type d -empty -delete
