#!/usr/bin/make -f

export DH_GOLANG_INSTALL_EXTRA := test

VERS := $(shell sed -n <NEWS.adoc '/^[0-9]/s/:.*//p' | head -1)
GOFLAGS := -ldflags='-X main.version=$(VERS)'

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

execute_before_dh_auto_configure:
	$(MAKE) surgeon/help-index.go

execute_after_dh_auto_configure:
	ln -s $(CURDIR)/debian/go/_src _build/src/gitlab.com/esr/reposurgeon/vendor

override_dh_auto_build:
	dh_auto_build -- $(GOFLAGS)
	for i in cutter mapper surgeon tool; do \
		cp -al _build/bin/$$i repo$$i ; \
		done
	$(MAKE)

override_dh_auto_install:
	DH_INTERNAL_OPTIONS= dh_auto_install -- prefix=/usr
	rm -f debian/reposurgeon/usr/share/doc/reposurgeon/INSTALL.adoc
	rm -f debian/reposurgeon/usr/share/doc/reposurgeon/INSTALL.html

execute_after_dh_auto_test:
	$(MAKE) -k -C test --quiet check BINDIR=$(realpath $(CURDIR))

execute_after_dh_auto_clean:
	DH_INTERNAL_OPTIONS= dh_auto_clean
	-git restore '*.1'
