#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk
include /usr/share/rustc/architecture.mk

CARGO_BASE_ARGS=--verbose --release --target $(DEB_HOST_RUST_TYPE)
RUNTIME_LIBS=libavcodec.so libgbm.so

%:
	dh $@

execute_before_dh_auto_configure:
	mkdir -p .cargo
	cp debian/cargo-config.toml .cargo/config.toml
	mv Cargo.lock Cargo.lock.ignored

execute_after_dh_auto_clean:
	rm -f waypipe.1
	rm -rf target
	if [ -f Cargo.lock.ignored ]; then \
	  mv Cargo.lock.ignored Cargo.lock; \
	fi
	rm -rf .cargo

override_dh_auto_configure:

override_dh_auto_build:
	cargo build $(CARGO_BASE_ARGS)
	scdoc < waypipe.scd > waypipe.1

override_dh_auto_install:
	install -D target/$(DEB_HOST_RUST_TYPE)/release/waypipe debian/tmp/usr/bin/waypipe

override_dh_auto_test:
	cargo test $(CARGO_BASE_ARGS)

execute_before_dh_gencontrol:
	CARGO_REGISTRY=/usr/share/cargo/registry debian/dh-cargo-built-using waypipe
	DEB_HOST_MULTIARCH=$(DEB_HOST_MULTIARCH) debian/runtime-recommends.sh $(RUNTIME_LIBS)
