#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export PATH := /usr/share/cargo/bin:$(PATH)

include /usr/share/dpkg/default.mk
include /usr/share/rustc/architecture.mk
export DEB_HOST_RUST_TYPE DEB_HOST_GNU_TYPE
export CARGO=/usr/share/cargo/bin/cargo
export CARGO_HOME=$(CURDIR)/debian/cargo_home
export CARGO_REGISTRY=$(CURDIR)/debian/cargo_registry
export DEB_CARGO_CRATE=$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM)

ifeq ($(DEB_HOST_ARCH_BITS),32)
    export DEB_BUILD_OPTIONS += optimize=-lto
endif

%:
	dh $@

execute_after_dh_auto_clean:
	$(CARGO) clean
	rm -rf $(CARGO_HOME)
	rm -rf $(CARGO_REGISTRY)

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

override_dh_auto_test:
	dh_auto_test -- --timeout-multiplier 4

execute_after_dh_auto_install:
	mv debian/Cargo.lock .