#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/buildflags.mk
include /usr/share/rustc/architecture.mk
export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
export DEB_CARGO_CRATE=waypipe_0.11.0
export DEB_HOST_RUST_TYPE DEB_HOST_GNU_TYPE
export PATH := /usr/share/cargo/bin/:$(PATH)
export CARGO_HOME=$(CURDIR)/debian/cargo_home
export CARGO_REGISTRY=$(CURDIR)/debian/local-registry

RUNTIME_LIBS=libavcodec.so libgbm.so

%:
	dh $@

execute_before_dh_auto_configure:
	mkdir -p .cargo
	cargo prepare-debian $(CARGO_REGISTRY) --link-from-system
	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_REGISTRY)
	rm -rf $(CARGO_HOME)

override_dh_auto_configure:

override_dh_auto_build:
	cargo build --release
	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 --release

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