#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1


export DEB_BUILD_MAINT_OPTIONS := qa=+bug hardening=+all reproducible=+all
export DEB_CFLAGS_MAINT_APPEND := -Wno-error=array-bounds


%:
	dh $@ --without single-binary


override_dh_auto_configure:
	dh_auto_configure -- --auto-features=enabled \
	                     -Ddocs=$(if $(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)),disabled,enabled) \
	                     -Dwerror=false \
	                     $(empty)

# The tests are all interactive and/or require root privileges
override_dh_auto_test:

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp

override_dh_installchangelogs:
	dh_installchangelogs NEWS

# dh_installsystemd does not enable template units, so build maintscripts
# manually from autoscripts.
# This can go once #889635 is fixed.
override_dh_installsystemd:
	printf '#!/bin/sh\nset -e\n\n#DEBHELPER#\n\n' | tee debian/kmscon.postinst debian/kmscon.postrm > /dev/null
	printf 'if [ "$$1" = configure ] && dpkg --compare-versions "$$2" lt-nl "9.0.0-3~"; then\n\trm -f "$$DPKG_ROOT/etc/systemd/system/getty.target.wants/kmsconvt@.service"\nfi\n\n' >> debian/kmscon.postinst
	sed 's/#UNITFILE#/kmsconvt@.service/g' /usr/share/debhelper/autoscripts/postinst-systemd-enable >> debian/kmscon.postinst
	sed 's/#UNITFILES#/kmsconvt@.service/g' /usr/share/debhelper/autoscripts/postrm-systemd >> debian/kmscon.postrm
	cat /usr/share/debhelper/autoscripts/postrm-systemd-reload-only >> debian/kmscon.postrm

override_dh_gencontrol:
	dh_gencontrol -- -VBuilt-Using="$$(dpkg-query --showformat='$${source:Package} (= $${source:Version})' --show unifont)"
