#!/usr/bin/make -f

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

export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
export DEB_HOST_RUST_TYPE DEB_HOST_GNU_TYPE
export PATH := /usr/share/cargo/bin:$(PATH)
export CARGO=/usr/share/cargo/bin/cargo
export CARGO_HOME=$(CURDIR)/debian/cargo_home
export DEB_CARGO_CRATE=$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM)
export DEB_BUILD_MAINT_OPTIONS=hardening=+bindnow

%:
	dh $@

execute_after_dh_auto_clean:
	rm -rf debian/cargo_registry

override_dh_auto_configure:
	$(CARGO) prepare-debian debian/cargo_registry --link-from-system
	rm -f Cargo.lock
	dh_auto_configure -- -Dhost_arch="$(DEB_HOST_RUST_TYPE)"

# without timeout multiplier, buildd for riscv hit the timeout
override_dh_auto_test:
	xvfb-run -a dh_auto_test --  --timeout-multiplier 5

# Generate (Static-)Built-Using
# Symlink the meson target dir to target/$(DEB_HOST_RUST_TYPE)/release
# since dh-cargo-built-using expects it there
execute_after_dh_auto_install:
	mkdir -p $(CURDIR)/target/$(DEB_HOST_RUST_TYPE)/
	ln -s $(CURDIR)/obj-$(DEB_HOST_GNU_TYPE)/podcasts-gtk/src/$(DEB_HOST_RUST_TYPE)/release target/$(DEB_HOST_RUST_TYPE)/
	/usr/share/cargo/bin/dh-cargo-built-using podcasts-gtk
