#!/usr/bin/make -f

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

export DH_GOLANG_EXCLUDES := docs/cli

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

# For some reason Go's testing.Tempdir() doesn't find a suitable
# temporary directory in some debci/autopkgtest environments, and
# instead default to /tmp which doesn't always exists.
# === RUN   TestRemoveRule
#     targets_test.go:379: failed to run command /usr/bin/ssh-keygen -m rfc4716 -e -f /tmp/TestRemoveRule-1dfa01853253dae5bd29526a195910359a81799f6d3a66a3606d6e7d0642cd6c: exit status 255 ssh-keygen: /tmp/TestRemoveRule-1dfa01853253dae5bd29526a195910359a81799f6d3a66a3606d6e7d0642cd6c: No such file or directory
# --- FAIL: TestRemoveRule (0.00s)
override_dh_auto_test:
	mkdir -pv $(CURDIR)/debian/gotmp
	env GOTMPDIR=$(CURDIR)/debian/gotmp TMPDIR=$(CURDIR)/debian/gotmp \
		dh_auto_test
	rm -rfv $(CURDIR)/debian/gotmp

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)
	help2man --version-string="$(DEB_VERSION)" \
		--no-info \
		--name="security layer for git(1) repositories" \
		--output $(M)/gittuf.1 \
		$(B)/gittuf
	help2man --version-string="$(DEB_VERSION)" \
		--no-info --no-discard-stderr \
		--name="gittuf remote plugin for git" \
		--output $(M)/git-remote-gittuf.1 \
		$(B)/git-remote-gittuf
endif
