#!/usr/bin/make -f

include /usr/share/dpkg/default.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 CARGO_REGISTRY=$(CURDIR)/debian/cargo_registry
export DEB_CARGO_CRATE=$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM)
export DEB_BUILD_MAINT_OPTIONS=hardening=+bindnow
export CARGO_TARGET_DIR=$(CURDIR)/debian/target
export DEB_CARGO_PACKAGE_TO_INSTALL = phoinix-cli
export DEB_CARGO_PACKAGE_PATH = $(CURDIR)/apps/phoinix-cli

%:
	dh $@ --buildsystem=cargo

execute_after_dh_auto_clean:
	rm -rf debian/cargo_registry debian/target

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

override_dh_auto_install:
	/usr/bin/cargo -Zavoid-dev-deps --verbose install \
		--path $(DEB_CARGO_PACKAGE_PATH) \
		--root $(CARGO_TARGET_DIR) \
		--profile=release

execute_after_dh_auto_install:
	mkdir -p debian/phoinix-cli/usr/share/man/man1
	help2man --no-info --name="data-recovery engine and command-line tool" \
		--output=debian/phoinix.1 \
		debian/target/bin/phoinix

override_dh_auto_test:
	@echo "Skipping automated wrapper test phase"
