#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export PATH := /usr/share/cargo/bin:$(PATH)

include /usr/share/dpkg/default.mk
include /usr/share/rustc/architecture.mk
export CARGO=/usr/share/cargo/bin/cargo
export CARGO_HOME=$(shell pwd)/debian/cargo_home
export CARGO_REGISTRY=$(shell pwd)/debian/cargo_registry
export DEB_CARGO_CRATE=$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM)
export DEB_HOST_RUST_TYPE

ifeq ($(DEB_HOST_ARCH_BITS),32)
    export DEB_BUILD_OPTIONS += optimize=-lto
endif

%:
	dh $@

execute_after_dh_auto_clean:
	$(CARGO) clean
	rm -rf $(CARGO_HOME)
	rm -rf $(CARGO_REGISTRY)

execute_before_dh_auto_configure:
	$(CARGO) prepare-debian $(CARGO_REGISTRY) --link-from-system
	rm -f Cargo.lock
	rm -f .cargo/config

# Generate (Static-)Built-Using
# Symlink the meson target dir to target/$(DEB_HOST_RUST_TYPE)/release
# since dh-cargo-built-using expects it there
execute_after_dh_auto_install:
	mkdir -p $(CURDIR)/target/$(DEB_HOST_RUST_TYPE)/
	ln -s $(CURDIR)/obj-$(DEB_HOST_GNU_TYPE)/src target/$(DEB_HOST_RUST_TYPE)/
	/usr/share/cargo/bin/dh-cargo-built-using gnome-video-trimmer
