#!/usr/bin/make -f

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

# resolve crate version
# * append package version if upstream part and crate version differ
crate_version = \
 $(shell perl -n \
 -E '/version\W+\K[^"]+/ and $$_ = $$& =~ s/-PRE/~pre/r ' \
 -E 'and say $$_ eq "$(DEB_VERSION_UPSTREAM)" ? "$(DEB_VERSION)" : "$$_+$(DEB_VERSION_UPSTREAM_REVISION)" and exit' \
 $1/Cargo.toml)

%:
	dh $@

# declare version for virtually provided embedded crate
override_dh_gencontrol:
	dh_gencontrol -- -V'derive:Version=$(call crate_version,signature_derive)'

# avoid cleaning unless source is patched
override_dh_auto_clean:
	grep -q '"crypto"' Cargo.toml || dh_auto_clean --buildsystem rust
