#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# OBS has no network at build time, so cargo builds from the vendor/ directory
# the orig tarball carries and never from crates.io (debian/README.source).
# CARGO_HOME has to be inside the tree as well: the build user on an OBS worker
# has no writable home.
export CARGO_HOME = $(CURDIR)/debian/cargo_home
export CARGO_NET_OFFLINE = true

# cargo's release profile carries no debug info, which would leave dh_strip
# producing an empty -dbgsym package.
export CARGO_PROFILE_RELEASE_DEBUG = true

# trixie's plain cargo is 1.85, which is what this needs; noble's is 1.75 and
# its 1.85 toolchain is the versioned cargo-1.85 package, so build with
# whichever of the two debian/control's alternative got installed.
CARGO := $(or $(wildcard /usr/bin/cargo-1.85),cargo)

%:
	dh $@

override_dh_auto_build:
	$(CARGO) build --release --locked --offline

override_dh_auto_test:
	$(CARGO) test --release --locked --offline

override_dh_auto_clean:
	$(CARGO) clean --offline
	$(RM) -r $(CARGO_HOME)
