#!/usr/bin/make -f

## needs "mockery" (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=940153)
#export DH_GOLANG_GO_GENERATE := 1

export DH_GOLANG_INSTALL_EXTRA := \
    command/connect/ca/set/test-fixtures \
    test

#export DH_GOLANG_EXCLUDES :=

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

override_dh_clean:
	dh_clean
	## Remove Files-Excluded (when built from checkout or non-DFSG tarball):
	$(RM) -rv `perl -0nE 'say $$1 if m{^Files\-Excluded\:\s*(.*?)(?:\n\n|Files:|Comment:)}sm;' debian/copyright`
#	-find . -type f -name '*.pb.go' -delete -printf 'removed %p\n'            ## delete generated .pb.go files
	-find vendor -type d -empty -delete -print

override_dh_auto_configure:
	dh_auto_configure
	
	mkdir -v -p _build/src/github.com/keybase/
	ln -sv /usr/share/gocode/src/golang.org/x/crypto  _build/src/github.com/keybase/go-crypto
	
	mkdir -v -p _build/src/github.com/SermoDigital/
	ln -sv /usr/share/gocode/src/gopkg.in/square/go-jose.v1  _build/src/github.com/SermoDigital/jose

#LIBSELF:=github.com/hashicorp/consul
#override_dh_auto_build:
#	## https://salsa.debian.org/onlyjob/notes/wikis/golang
#	## "go generate" in "vendor":
#	DH_GOLANG_EXCLUDES="github.com/hashicorp/consul/vendor/github.com/googleapis/gnostic/extensions github.com/envoyproxy/go-control-plane $(LIBSELF)/vendor/k8s.io/apimachinery/pkg github.com/hashicorp/vault github.com/hashicorp/go-plugin" \
#	DH_GOPKG="github.com/hashicorp/consul/vendor" \
#	dh_auto_build -v
#	cd _build && GOPATH=$(CURDIR)/_build go generate -v $(LIBSELF)/vendor
#	sleep 8
#	dh_auto_build

override_dh_auto_test:
	PATH="$(CURDIR)/_build/bin:$${PATH}" \
        DH_GOLANG_EXCLUDES="${DH_GOLANG_EXCLUDES} api agent" \
        dh_auto_test --max-parallel=2 -- -test.short -timeout 20m -failfast

override_dh_install:
	## Do not install "github.com/hashicorp/consul/vendor" to -dev package.
	dh_install  -X/src/github.com/hashicorp/consul/vendor  -Xcertgen

override_dh_installsystemd:
	dh_installsystemd --no-enable --no-start
