#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk
include /usr/share/rustc/architecture.mk

# Upstream prefers so, leaving the version field in Cargo.toml always at 0.1.
export SHOTMAN_VERSION := $(DEB_VERSION_UPSTREAM)
export DEB_HOST_RUST_TYPE
CARGO_BASE_ARGS= --release --target $(DEB_HOST_RUST_TYPE)

%:
	dh $@ --with shell_completions

execute_after_dh_auto_clean:
	-mv Makefile.upstream Makefile

execute_before_dh_auto_configure:
	mkdir -p .cargo
	cp debian/cargo-config.toml .cargo/config.toml
	# Do not use upstream Makefile, as it does not take into account the
	# difference of build and host architectures, some installs are not wanted,
	# and some are installed in places other than we prefer.
	-mv Makefile Makefile.upstream

override_dh_auto_build:
	cargo build $(CARGO_BASE_ARGS)
	scdoc < shotman.1.scd > debian/shotman.1

override_dh_auto_test:
	cargo test $(CARGO_BASE_ARGS)
