#!/usr/bin/make -f

export CARGO_HOME=$(CURDIR)/debian/cargo-home
export CARGO_NET_OFFLINE=true

# Ubuntu 24.04 ships current Rust releases as versioned commands, while
# Debian backports and newer Ubuntu releases provide the unversioned names.
CARGO_BIN := $(shell command -v cargo-1.91 2>/dev/null || command -v cargo)
RUSTC_BIN := $(shell command -v rustc-1.91 2>/dev/null || command -v rustc)
export RUSTC=$(RUSTC_BIN)

%:
	dh $@

override_dh_auto_build:
	$(CARGO_BIN) build --release --frozen --offline

override_dh_auto_test:
	$(CARGO_BIN) test --release --all-targets --frozen --offline

override_dh_auto_clean:
	$(CARGO_BIN) clean

override_dh_auto_install:
	$(MAKE) install DESTDIR=$(CURDIR)/debian/pixelkit PREFIX=/usr \
		CARGO="$(CARGO_BIN) --offline"

override_dh_clean:
	# Cargo verifies every vendored file, including crates' Cargo.toml.orig.
	# Do not let dh_clean mistake those upstream files for packaging backups.
	dh_clean -Xvendor/

override_dh_dwz:
	# Rust DWARF is not always accepted by dwz; stripping is handled by dh_strip.
