#!/usr/bin/make -f
#export DH_VERBOSE = 1

# Build daemons have no network access: the crates are taken from the Debian
# packages instead, and cargo must not write into $HOME.
export CARGO_HOME = $(CURDIR)/debian/cargo-home
export CARGO_NET_OFFLINE = true
# wasm-pack caches the version of wasm-opt it runs under $HOME/.cache/.wasm-pack,
# and $HOME is not writable inside the build chroot: without this the build fails
# with "Error: Permission denied (os error 13)".
export HOME = $(CURDIR)/debian/home
# Where upstream's compile.sh puts its output.
export OUTPUT = $(CURDIR)/debian/build
export OUTPUT_NAME = qcms

%:
	dh $@

override_dh_auto_build:
	# Resolve the Rust dependencies against the packaged crates.
	mkdir -p .cargo
	cp debian/cargo-config.toml .cargo/config.toml
	# Upstream pins wasm-bindgen 0.2.100; Debian ships 0.2.108, and the crate
	# version has to match the wasm-bindgen command line tool.
	rm -f Cargo.lock
	sh compile.sh

override_dh_auto_install:
	# Nothing to do, debian/install lists the files built above.

override_dh_auto_test:
	# The generated module needs a WebAssembly runtime to be exercised.
