#!/usr/bin/make -f

include /usr/share/rustc/architecture.mk

export CARGO_HOME=$(CURDIR)/debian/cargo_home
# Set codegen-units to 1 for reproducible builds (parallel codegen is non-deterministic)
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
# Enable debug logging if 'debug' is in DEB_BUILD_OPTIONS
ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
export RUST_LOG=debug
endif
ZSH_COMPDIR = /usr/share/zsh/vendor-completions/

CARGO_BASE_ARGS= --release --target $(DEB_HOST_RUST_TYPE)

%:
	dh $@ --with bash_completion

execute_before_dh_auto_configure:
	if test -f Cargo.lock; then mv Cargo.lock Cargo.lock.upstream; fi

override_dh_auto_build:
	cargo build $(CARGO_BASE_ARGS)

override_dh_auto_test:
	make testsuite

execute_after_dh_auto_install:
	mkdir -p debian/lintian-brush/$(ZSH_COMPDIR)
	install -m644 debian/lintian-brush.zsh-completion \
	    debian/lintian-brush/$(ZSH_COMPDIR)/_lintian-brush

override_dh_auto_clean:
	if test -f Cargo.lock.upstream; then mv Cargo.lock.upstream Cargo.lock; fi
	cargo clean || true

update-deps:
	update-rust-deps --drop-unreferenced --exclude-local-crate
