#!/usr/bin/make -f
# -*- makefile -*-

include /usr/share/rustc/architecture.mk


%:
	dh $@ --buildsystem=cargo

# 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)

override_dh_auto_build:
	# actually does the build
	DEB_BUILD_OPTIONS= dh_auto_test -- --release

# we ship the build result, skipping dh-cargo's test build
override_dh_auto_test:

override_dh_auto_install:
	dh_install target/$(DEB_HOST_RUST_TYPE)/release/wlgreet /usr/sbin/

# similarly to https://bugzilla.redhat.com/show_bug.cgi?id=1564880
# and other cases (see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1016563)
# I got:
#   dwz: debian/wlgreet/usr/sbin/wlgreet: Couldn't find DIE at [2c865] referenced by DW_AT_abstract_origin from DIE at [2cae7]
# Therefore I decide to skip it.
override_dh_dwz:

execute_after_dh_auto_clean:
	rm -f debian/cargo-checksum.json

