#!/usr/bin/make -f
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

include /usr/share/dpkg/architecture.mk
include /usr/share/rustc/architecture.mk
export DEB_HOST_GNU_TYPE DEB_HOST_RUST_TYPE

# The CMake build runs plain cargo, which reads the Debian registry from here.
export CARGO_HOME = $(CURDIR)/debian/cargo_home
export DEB_CARGO_CRATE = ngosen-bamboo_0.1.0

BUILDDIR = obj-$(DEB_HOST_GNU_TYPE)

%:
	dh $@ --buildsystem=cmake --builddirectory=$(BUILDDIR)

override_dh_auto_configure:
	/usr/share/cargo/bin/cargo prepare-debian debian/cargo_registry --link-from-system
	dh_auto_configure -- \
		-DNGOSEN_VENDORED_CRATES=OFF \
		-DNGOSEN_BYTECOMPILE_PYTHON=OFF \
		-DBUILD_TESTING=$(if $(filter nocheck,$(DEB_BUILD_OPTIONS)),OFF,ON)

override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3

# debian/copyright already carries these texts.
execute_after_dh_auto_install:
	rm -rf debian/fcitx5-ngosen/usr/share/licenses

execute_before_dh_gencontrol:
	CARGO_BUILT_USING_TARGET_DIR=$(BUILDDIR)/bamboo-rs/target/release \
		/usr/share/cargo/bin/dh-cargo-built-using fcitx5-ngosen

execute_after_dh_auto_clean:
	rm -rf debian/cargo_home debian/cargo_registry bamboo-rs/Cargo.lock
