#!/usr/bin/make -f
%:
	dh $@

override_dh_clean:
	dh_clean -X.orig

override_dh_auto_configure:
	mkdir $(CURDIR)/.cargo
	cp $(CURDIR)/debian/cargo-config $(CURDIR)/.cargo
	mv $(CURDIR)/.cargo/cargo-config $(CURDIR)/.cargo/config

override_dh_auto_build:
	RUSTFLAGS=-Clink-arg=-Wl,-z,relro,-z,now CARGO_HOME=$(CURDIR)/.cargo cargo build --release

override_dh_auto_install:
	# rustflags must be exported again at install as cargo build will
	# rebuild the project if it detects flags have changed (to none or other)
	# install stage also requires re-export of 'cargo-home' or cargo
	# will try to download source deps and rebuild
	# cargo install appends /bin to the path
	RUSTFLAGS=-Clink-arg=-Wl,-z,relro,-z,now CARGO_HOME=$(CURDIR)/.cargo cargo install --root=$(CURDIR)/debian/cbindgen/usr --path .
	# remove spurious file
	rm $(CURDIR)/debian/cbindgen/usr/.crates.toml

override_dh_installman:
	help2man debian/cbindgen/usr/bin/cbindgen > debian/cbindgen.1
	dh_installman -O--buildsystem=cargo
