#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk
export CARGO_VENDOR_DIR=$(CURDIR)/vendor

%:
	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:
	mkdir -p debian/bindgen-0.71/usr/lib/bindgen-0.71/bin
	cd debian/bindgen-0.71/usr/bin/ && mv bindgen ../lib/bindgen-0.71/bin

recreate-debian-vendor:
	rm -rf vendor
	cargo vendor --versioned-dirs vendor
	find vendor -name '*.dll' -exec rm '{}' ';'
	rm -rf vendor/winapi* vendor/windows* vendor/hermit-abi-* vendor/objc-*

gentarball:
	tar --transform 's,^.\/,$(DEB_SOURCE)-$(DEB_VERSION_UPSTREAM)/,' \
		--exclude 'debian' --exclude '.git.*' --exclude-vcs \
		-cJf ../$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM).orig.tar.xz .
