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

# Plain `dh` invocation; every override below delegates the actual
# work to the top-level Makefile so the build / install logic is
# single-sourced for packagers and the `make install PREFIX=$$prefix`
# convention.

# Cross-build: when the host (target) arch differs from the build arch,
# compile for the matching Rust triple so an arm64 .deb can be produced
# on an amd64 builder (e.g. `dpkg-buildpackage -a arm64`). The linker
# and pkg-config cross settings come from .cargo/config.toml.
RUST_TARGET_arm64 = aarch64-unknown-linux-gnu
RUST_TARGET_amd64 = x86_64-unknown-linux-gnu
ifneq ($(DEB_HOST_ARCH),$(DEB_BUILD_ARCH))
CARGO_TARGET = $(RUST_TARGET_$(DEB_HOST_ARCH))
endif
MAKE_ARGS = CARGO_TARGET=$(CARGO_TARGET)

%:
	dh $@

override_dh_auto_build:
	$(MAKE) all $(MAKE_ARGS)

override_dh_auto_install:
	$(MAKE) install DESTDIR=$(CURDIR)/debian/crustace-notifier PREFIX=/usr $(MAKE_ARGS)

override_dh_auto_clean:
	$(MAKE) clean
	dh_clean

override_dh_auto_test:
