#!/usr/bin/make -f
export DH_VERBOSE = 1
export CARGO_HOME = $(CURDIR)/.cargo-home
# Official rustc install prefix (no ':' — rustc rejects that in library paths).
export PATH := /tmp/am5-rust/bin:$(PATH)
# Cargo already strips release binaries; do not emit a dbgsym companion.
export DEB_BUILD_OPTIONS := $(DEB_BUILD_OPTIONS) noautodbgsym

%:
	dh $@

override_dh_auto_configure:
	# Extract vendor after dh_clean so vendor/*/Cargo.toml.orig is not deleted.
	$(CURDIR)/scripts/obs_prep.sh
	dh_auto_configure

override_dh_auto_build:
	$(MAKE) build

override_dh_auto_test:
	$(MAKE) test

override_dh_auto_install:
	# Debian 12 dh_installsystemd only scans lib/systemd/system, not usr/lib.
	$(MAKE) DESTDIR=$(CURDIR)/debian/am5-spd-diag PREFIX=/usr \
		UNITDIR=/lib/systemd/system install

# Enable on install. Start the boot oneshot for a baseline capture; do not
# start sleep units (those fire on suspend/resume). --no-stop-on-upgrade
# uses start rather than restart so ExecStop (shutdown capture) is not run.
# Uninstall still disables via dh_installsystemd maintainer scripts.
override_dh_installsystemd:
	dh_installsystemd --no-start --no-stop-on-upgrade \
		am5-spd-diag-pre-sleep.service am5-spd-diag-post-sleep.service
	dh_installsystemd --no-stop-on-upgrade am5-spd-diag.service

override_dh_strip:
	dh_strip --no-automatic-dbgsym
