#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk
include /usr/share/rustc/architecture.mk

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
        NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
else
        NUMJOBS = 1
endif

CARGO_BUILD_FLAGS = \
	--release \
	--target $(DEB_HOST_RUST_TYPE) \
	--offline \
	-v \
	-j $(NUMJOBS)

%:
	dh $@ --buildsystem cargo

override_dh_auto_test:
	dh_auto_test -- test --all


execute_after_dh_auto_build:
	CARGO_HOME=debian/cargo_home \
		/usr/share/cargo/bin/cargo build $(CARGO_BUILD_FLAGS)

override_dh_auto_install:
	# generate substvars since we override dh_auto_install from dh-cargo.
	/usr/share/cargo/bin/dh-cargo-built-using triforce-lv2
	# install using upstream Makefile. Work around --target usage.
	ln target/$(DEB_HOST_RUST_TYPE)/release/libtriforce.so target/release/libtriforce.so
	$(MAKE) install DESTDIR=debian/triforce-lv2 LIBDIR=/usr/lib
	rm -f target/release/libtriforce.so