#!/usr/bin/make -f

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

%:
	dh $@ --builddirectory=_build --buildsystem=golang

# little of the self-checks appears to work (require internet connection?)
# so we ignore the error code but keep output in build logs
override_dh_auto_test:
	-dh_auto_test $(DH_BUILD_OPTS)

execute_after_dh_install-arch:
	rm -v $(CURDIR)/debian/litetlog/usr/bin/tlogclient-warmup
	mv -v $(CURDIR)/debian/litetlog/usr/bin/spicy $(CURDIR)/debian/litetlog/usr/bin/spicy-litetlog

B = $(CURDIR)/debian/tmp/usr/bin
M = $(CURDIR)/debian/tmp/usr/share/man/man1

ifeq (,$(filter nodoc,$(DEB_BUILD_PROFILES)))
execute_before_dh_installman-arch:
	mkdir -pv $(M)
	env PATH="$(B):$$PATH" \
		help2man --version-string="$(DEB_VERSION)" \
		--no-info --no-discard-stderr \
		--name="transparency cosigning witness" \
		--output $(M)/litewitness.1 \
		litewitness
	env PATH="$(B):$$PATH" \
		help2man --version-string="$(DEB_VERSION)" \
		--no-info --no-discard-stderr \
		--name="operate on the litewitness(1) database" \
		--output $(M)/witnessctl.1 \
		witnessctl
	env PATH="$(B):$$PATH" \
		help2man --version-string="$(DEB_VERSION)" \
		--no-info --no-discard-stderr \
		--name="reverse proxy for transparency witnesses" \
		--output $(M)/litebastion.1 \
		litebastion
	env PATH="$(B):$$PATH" \
		help2man --version-string="$(DEB_VERSION)" \
		--no-info --no-discard-stderr \
		--name="spicy signature tool" \
		--output $(M)/spicy-litetlog.1 \
		spicy
endif
