#!/usr/bin/make -f

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

include /usr/share/dpkg/architecture.mk

# When the host arch differs from the build arch (e.g. building the arm64
# package on amd64), derive the cargo target triple from the host GNU CPU
# and hand it to the Makefile so it cross-compiles instead of building for
# the build machine. pkg-config calls must then resolve against the host.
ifneq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
RUST_TARGET := $(DEB_HOST_GNU_CPU)-unknown-linux-gnu
export PKG_CONFIG := $(DEB_HOST_GNU_TYPE)-pkg-config
endif

%:
	dh $@

override_dh_auto_build:
	$(MAKE) all RUST_TARGET=$(RUST_TARGET)

override_dh_auto_install:
	$(MAKE) install DESTDIR=$(CURDIR)/debian/contacts-server PREFIX=/usr RUST_TARGET=$(RUST_TARGET)

override_dh_auto_clean:
	$(MAKE) clean
	dh_clean

# `cargo test` would pull dependencies from the network, which a sandboxed
# Debian build forbids. Disabled here; run `cargo test` manually.
override_dh_auto_test:
