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

# 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_build:
	$(MAKE) CARGO_TARGET=$(CARGO_TARGET)

override_dh_auto_install:
	$(MAKE) install DESTDIR=$(CURDIR)/debian/eydos-installer PREFIX=/usr CARGO_TARGET=$(CARGO_TARGET)

override_dh_auto_clean:
	$(MAKE) clean || true

override_dh_auto_test:
	# tests need a running Wayland compositor — skipped in build env

# The named unit (debian/eydos-installer.eydos-installer-daemon.service)
# is only picked up with an explicit --name; without this override it is
# silently ignored and the daemon never ships.
override_dh_installsystemd:
	dh_installsystemd
	dh_installsystemd --name=eydos-installer-daemon
