#!/usr/bin/make -f

# resolve DEB_VERSION_UPSTREAM
include /usr/share/dpkg/pkg-info.mk

DEB_VERSION_UPSTREAM_ORIG = $(firstword $(subst ~,$() ,$(DEB_VERSION_UPSTREAM)))

DEB_CARGO_CRATE = $(shell grep -Po '^name\s*=\s*"\K[^"]+' Cargo.toml)
TARGET = debian/lib$(DEB_SOURCE)-dev/usr/share/cargo/registry/$(DEB_CARGO_CRATE)-$(DEB_VERSION_UPSTREAM_ORIG)

# generate cargo-checksum file
_mkchecksum = printf '{"package":"%s","files":{}}\n' \
 $$(sha256sum $(or $2,$(dir $1)Cargo.toml) | grep -Po '^\S+') > $1;

execute_before_dh_auto_configure:
	$(call _mkchecksum,debian/cargo-checksum.json,Cargo.toml)

execute_after_dh_auto_install:
	rm -rf $(addprefix $(TARGET)/,.github)
	rm -f $(addprefix $(TARGET)/,.gitignore LICENSE-*)

%:
	dh $@ --buildsystem cargo
