#!/usr/bin/make -f

export DH_GOLANG_INSTALL_EXTRA := test

PAGES = reposurgeon.adoc repocutter.adoc repomapper.adoc repotool.adoc repobench.adoc
DOCS = $(PAGES) repository-editing.adoc oops.svg
MANPAGES  = $(PAGES:.adoc=.1)
HTMLFILES = $(DOCS:.adoc=.html)

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

execute_before_dh_auto_configure:
	sh extractversion.sh -g <NEWS.adoc >surgeon/version.go

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

execute_after_dh_auto_build:
	for i in cutter mapper surgeon tool; do \
		cp -al _build/bin/$$i repo$$i ; \
		done
	./reposurgeon "help options" | sed '/:/s//::/' >options.adoc
	$(MAKE) $(MANPAGES) $(HTMLFILES)

override_dh_auto_install:
	DH_INTERNAL_OPTIONS= dh_auto_install -- prefix=/usr

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

execute_after_dh_auto_clean:
	DH_INTERNAL_OPTIONS= dh_auto_clean
