#!/usr/bin/make -f

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

# resolve if release is experimental
DEB_SUITE_EXP = $(filter experimental% UNRELEASED,$(DEB_DISTRIBUTION))

# generate documentation unless nodoc requested
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
MANPAGES = debian/build/safe-vdash.1
endif

# use local fork of dh-cargo and cargo wrapper
PATH := $(CURDIR)/debian/dh-cargo/bin:$(PATH)
PERL5LIB = $(CURDIR)/debian/dh-cargo/lib
export PATH PERL5LIB

%:
	dh $@ --buildsystem=cargo

override_dh_auto_test:
	dh_auto_test $(if $(DEB_SUITE_EXP),|| true)

execute_after_dh_auto_install: $(MANPAGES)

# build manpages
debian/build/safe-vdash.1: debian/build/%.1: debian/safe-vdash/usr/bin/%
	mkdir --parents $(dir $@)
	help2man --section 1 --no-info \
		--name "CLI tool to monitor nodes on the Safe Network" \
		--output $@ $< \
		|| { $1 --help; false; }
