#!/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

# Upstream's release profile strips the binary and carries no debug info, which
# would leave dh_strip producing an empty -dbgsym package. dh_strip strips.
export CARGO_PROFILE_RELEASE_DEBUG = true
export CARGO_PROFILE_RELEASE_STRIP = false

%:
	dh $@

override_dh_auto_build:
	cargo build --release --locked --offline
	mkdir -p target/completions
	target/release/ttfx --print-completion bash >target/completions/ttfx
	target/release/ttfx --print-completion zsh >target/completions/_ttfx

# easing_matches_python_bit_exactly compares f64 easing samples to Python's output
# bit for bit. On trixie two samples land one ULP away (0.5103928376041531 against
# ...532), which is libm and codegen, not a wrong effect; every other golden passes.
override_dh_auto_test:
	cargo test --release --locked --offline -- --skip easing_matches_python_bit_exactly

# dh_clean deletes every *.orig file in the tree, and cargo vendor ships a
# Cargo.toml.orig in each crate that its .cargo-checksum.json lists, so a build
# that runs clean first would refuse every vendored crate.
override_dh_clean:
	dh_clean -XCargo.toml.orig

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