#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export CARGO_HOME = $(CURDIR)/debian/cargo_home
export CARGO_TARGET_DIR = $(CURDIR)/debian/cargo_target
export RUSTC = /usr/bin/rustc
export RUSTDOC = /usr/bin/rustdoc

%:
	dh $@ --buildsystem cargo --with cargo

override_dh_auto_clean:
	manifest=$$(if [ -f pixie/Cargo.toml ]; then echo pixie/Cargo.toml; elif [ -f Cargo.toml ]; then echo Cargo.toml; else echo ""; fi); \
	test -n "$$manifest"; \
	dh_auto_clean -- --manifest-path "$$manifest"

override_dh_auto_build:
	manifest=$$(if [ -f pixie/Cargo.toml ]; then echo pixie/Cargo.toml; elif [ -f Cargo.toml ]; then echo Cargo.toml; else echo ""; fi); \
	test -n "$$manifest"; \
	dh_auto_build -- --manifest-path "$$manifest" --release --locked --offline

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	manifest=$$(if [ -f pixie/Cargo.toml ]; then echo pixie/Cargo.toml; elif [ -f Cargo.toml ]; then echo Cargo.toml; else echo ""; fi); \
	test -n "$$manifest"; \
	dh_auto_test -- --manifest-path "$$manifest" --locked --offline --lib --bins
	manifest=$$(if [ -f pixie/Cargo.toml ]; then echo pixie/Cargo.toml; elif [ -f Cargo.toml ]; then echo Cargo.toml; else echo ""; fi); \
	test -n "$$manifest"; \
	dh_auto_test -- --manifest-path "$$manifest" --locked --offline --test config_tests --test logger_tests --test router_tests --test threadpool_tests
endif
