#!/usr/bin/make -f

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

%:
	dh $@ --with openrc,runit,python3

override_dh_installinit:
	dh_installinit --no-scripts

override_dh_installsystemd:
	:

override_dh_auto_configure:
	dh_auto_configure -- \
		-Dmanpage=enabled \
		-Dbashcomp=enabled \
		-Dzshcomp="/usr/share/zsh/vendor-completions" \
		-Dsystemdsystemunitdir=/usr/lib/systemd/system \
		$(NULL)

	# Newer python3-argparse-manpage is in debian but let's wait removing this
	# until it's there for a while, so that there's not a mismatch.
	if dpkg --compare-versions \
		"$$(dpkg-query --showformat='${Version}' --show python3-argparse-manpage)" lt "4.0"; then \
		sed -i s,argparse-manpage,powerprofilesctl,g \
			$(CURDIR)/obj-$(DEB_HOST_GNU_TYPE)/src/powerprofilesctl.1; \
	fi

execute_after_dh_auto_install:
	# Do not ship the systemd unit; OpenRC and runit manage the daemon.
	rm -f debian/tmp/usr/lib/systemd/system/power-profiles-daemon.service
	rmdir -p --ignore-fail-on-non-empty debian/tmp/usr/lib/systemd/system 2>/dev/null || true
