#!/usr/bin/make -f
# Copyright 2026 California Institute of Technology
#
# You should have received a copy of the licensing terms for this
# software included in the file “LICENSE” located in the top-level
# directory of this package. If you did not, you can view a copy at
# http://dcc.ligo.org/M1500244/LICENSE.txt

# Offline build against the crates unpacked from the orig-vendor
# component tarball (see debian/README.source).
export CARGO_HOME = $(CURDIR)/debian/cargo_home

%:
	dh $@

# dh_clean treats *.orig as editor cruft, but the vendored crates ship
# Cargo.toml.orig files listed in their cargo checksums; keep them.
override_dh_clean:
	dh_clean -XCargo.toml.orig

override_dh_auto_configure:
	mkdir -p $(CARGO_HOME)
	printf '[source.crates-io]\nreplace-with = "vendored-sources"\n\n[source.vendored-sources]\ndirectory = "%s"\n' \
		'$(CURDIR)/vendor' > $(CARGO_HOME)/config.toml

override_dh_auto_build:
	cargo build --release --frozen --workspace

# Unit tests only; the live-IOC e2e test is #[ignore]d and stays a
# developer-run check (see debian/README.source).
override_dh_auto_test:
	cargo test --release --frozen --workspace

override_dh_auto_install:
	install -D -m 0755 target/release/term_scope \
		debian/term-scope/usr/bin/term_scope

override_dh_auto_clean:
	-cargo clean
	rm -rf $(CARGO_HOME)
