#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk
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_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 $@

override_dh_auto_clean:
	dh_auto_clean
	rm -rf debian/cargo_registry

# Disable lto on armel/hf since it OOMs otherwise
execute_before_dh_auto_configure:
ifneq ($(filter armel armhf,$(DEB_HOST_ARCH)),)
export DEB_BUILD_OPTIONS += optimize=-lto
endif

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)"

# Give the tests more time on slow arches
override_dh_auto_test:
	dh_auto_test --  --timeout-multiplier 5
