#!/usr/bin/make -f
include /usr/share/rustc/architecture.mk

export DH_VERBOSE = 1

# Keep Cargo's cache inside the build tree so parallel builds don't collide.
export CARGO_HOME = $(CURDIR)/debian/.cargo-home

# Cross-build (e.g. dpkg-buildpackage -aarm64 on amd64): build for the host
# arch's Rust target and let cargo use the cross linker / pkg-config wired up
# in .cargo/config.toml. Native builds leave CARGO_TARGET empty and use
# target/release as before.
ifneq ($(DEB_HOST_RUST_TYPE),$(DEB_BUILD_RUST_TYPE))
CARGO_TARGET := $(DEB_HOST_RUST_TYPE)
endif

%:
	dh $@

override_dh_auto_configure:
	# nothing — cargo does not use configure

override_dh_auto_build:
	$(MAKE) CARGO_TARGET=$(CARGO_TARGET)

override_dh_auto_install:
	$(MAKE) install DESTDIR=$(CURDIR)/debian/forge PREFIX=/usr CARGO_TARGET=$(CARGO_TARGET)

override_dh_auto_test:
	# no automated tests

override_dh_auto_clean:
	$(MAKE) clean || true
