#!/usr/bin/make -f
# Meson builds, tests and installs everything into debian/tmp (the cargo
# builds are run by Meson, into its build directory); the .install files
# split that up into the packages. The crates come from vendor/ in the
# source archive: the build needs no network. cargo must not write into the
# builder's home directory.
export CARGO_HOME = $(CURDIR)/debian/cargo_home

%:
	dh $@ --buildsystem=meson

# The unit goes where dh_installsystemd looks for it, the sleep hook into
# /usr/lib/systemd/system-sleep, the helper into
# /usr/libexec (the udev rule names it by that path), and the guard's example
# configuration is moved into its package's documentation directory by
# asus-zenbook-duo-ux8406-tcc-guard.install. -Dlicensedir has Meson install
# the notices of the Rust programs plus the licence texts and its own
# depmf.json; Debian conveys licences in debian/copyright and common-licenses,
# so only the notices are kept (see override_dh_auto_install). Debian's
# udev-hid-bpf loads programs from /usr/lib/<multiarch>/bpf only; the
# keyboard package is amd64 only.
override_dh_auto_configure:
	dh_auto_configure -- \
	    --libexecdir=libexec \
	    -Dlicensedir=share/licenses \
	    -Dudevdir=/usr/lib/udev \
	    -Dsystemdsystemunitdir=/usr/lib/systemd/system \
	    -Dsystemdsleepdir=/usr/lib/systemd/system-sleep \
	    -Dhidbpfdir=/usr/lib/x86_64-linux-gnu/bpf

override_dh_auto_install:
	dh_auto_install
	rm -f debian/tmp/usr/share/licenses/depmf.json
	rm -f debian/tmp/usr/share/licenses/*/MIT.txt \
	      debian/tmp/usr/share/licenses/*/GPL-2.0-only.txt

override_dh_auto_clean:
	dh_auto_clean
	rm -rf debian/cargo_home

# The HID-BPF object is not a host binary.
override_dh_strip:
	dh_strip -X.bpf.o

override_dh_dwz:
	dh_dwz -X.bpf.o

# The QML modules of plasma-workspace, which the applet of
# plasma-builtin-screen-rotation imports: Debian moved them into
# qml6-module-org-kde-plasma-workspace in 4:6.6.3-3, Ubuntu keeps them in
# plasma-workspace (26.10: 4:6.7.5-0ubuntu1). There, the package comes first,
# for the day Ubuntu also moves them.
ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes),yes)
PLASMA_WORKSPACE = qml6-module-org-kde-plasma-workspace | plasma-workspace
else
PLASMA_WORKSPACE = qml6-module-org-kde-plasma-workspace | plasma-workspace (<< 4:6.6.3-3~)
endif

override_dh_gencontrol:
	dh_gencontrol -- "-Vplasma:Workspace=$(PLASMA_WORKSPACE)"

# xz, as Debian: Ubuntu 26.10 compresses with zstd by default, which lintian
# of the Debian profile refuses.
override_dh_builddeb:
	dh_builddeb -- -Zxz

# vendor/ holds the crates as published, among them files that dh_clean takes
# for editor leftovers (Cargo.toml.orig), and cargo wants them: cargo checks
# every file of a crate against its checksum list. The build is out of tree,
# but the clean target runs on the unpacked source.
override_dh_clean:
	dh_clean -Xvendor/

# The notices are for people to read: keep them as plain text.
override_dh_compress:
	dh_compress -XTHIRD-PARTY-NOTICES.txt

override_dh_missing:
	dh_missing --fail-missing
