#!/usr/bin/make -f

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

export PATH := /usr/share/cargo/bin:$(PATH)
export CARGO_HOME = $(CURDIR)/debian/cargo_home
export DEB_CARGO_CRATE = $(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@ --buildsystem=pybuild

override_dh_auto_clean:
	test ! -f Cargo.lock.saved || \
		mv Cargo.lock.saved Cargo.lock
	dh_auto_clean

override_dh_auto_configure:
	cargo prepare-debian debian/cargo_registry --link-from-system
	dh_auto_configure

override_dh_auto_build:
	mv Cargo.lock Cargo.lock.saved
	cargo generate-lockfile --offline
	dh_auto_build

execute_before_dh_gencontrol:
	CARGO_BUILT_USING_TARGET_DIR="target/$(DEB_HOST_RUST_TYPE)/release" \
		dh-cargo-built-using python3-rammappy
