#!/usr/bin/make -f

include /usr/share/rustc/architecture.mk
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)
export DEB_HOST_RUST_TYPE

export CARGO_TARGET_DIR=$(CURDIR)/target
export INSTALL_DIR=$(CURDIR)/debian/tmp/usr
export DESTDIR=$(CURDIR)/debian/lomiri-keepassrx-app/usr

%:
	dh $@ --buildsystem cargo

execute_before_dh_auto_configure:
	$(CARGO) prepare-debian debian/cargo_registry --link-from-system

override_dh_auto_build:
	$(CARGO) build --release

override_dh_auto_test-arch:
	$(CARGO) test --release

override_dh_auto_test-indep:
	# no arch-indep tests

# dh-cargo doesn't handle workspace apps
# so we need to duplicate its install function except for setting path manually
# https://github.com/rust-lang/cargo/issues/7599
# https://salsa.debian.org/rust-team/dh-cargo/-/work_items/3
override_dh_auto_install:
	/usr/bin/cargo install --path $(CURDIR)/keepass-rx
	CARGO_BUILT_USING_SRC_DIR=$(CURDIR)/keepass-rx /usr/share/cargo/bin/dh-cargo-built-using lomiri-keepassrx-app

override_dh_auto_clean:
	$(CARGO) clean
