#!/usr/bin/make -f
export CARGO_VENDOR_DIR=$(CURDIR)/vendor
export PATH:=/usr/lib/llvm-16/bin:$(PATH)
export LLVM_CONFIG_PATH=/usr/bin/llvm-config-16
export LIBCLANG_PATH=/usr/lib/llvm-16/lib/

%:
	dh $@ --buildsystem cargo

execute_after_dh_auto_configure:
	if [ -d debian/cargo_registry ]; then rm -rf debian/cargo_registry; ln -s vendor debian/cargo_registry; fi

execute_after_dh_testdir:
	find . ! -newermt "jan 01, 2000" -exec touch {} +

override_dh_auto_configure:
	mv $(CURDIR)/Cargo.toml $(CURDIR)/Cargo.toml.orig
	dh_auto_configure --buildsystem=cargo
	mv $(CURDIR)/Cargo.toml.orig $(CURDIR)/Cargo.toml

override_dh_auto_install:
	DEB_CARGO_CRATE_IN_REGISTRY=1 \
	dh_auto_install --buildsystem=cargo -- --path bindgen-cli

execute_after_dh_install:
	cd debian/bindgen-0.65/usr/bin/ && mv bindgen bindgen-0.65

recreate-debian-vendor:
	rm -rf vendor
	cargo vendor --versioned-dirs vendor
	rm -f debian/vendor/libloading*/tests/*.dll
	rm -rf vendor/winapi* vendor/windows* vendor/hermit-abi-* vendor/objc-*
