#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

#export GOMAXPROCS=1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DH_GOLANG_GO_GENERATE := 1
export DH_GOLANG_INSTALL_EXTRA := $(shell find -type d -name test-fixtures)

export DH_GOLANG_EXCLUDES = demo vault/external_tests

%:
	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 . -type f -name '*.generated.go' -print -delete ## delete .generated.go files
	-find vendor -type d -empty -delete -print

override_dh_auto_build:
## `go generate` sub-vendored component(s):
#	cd _build/src/github.com/hashicorp/vault/vendor/ \
#	&& GO111MODULE=off go generate -v -x ./...
#	
	dh_auto_build -v

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	mkdir -v -p debian/tmp
	touch debian/tmp/.vault-token
	PATH="$(CURDIR)/_build/bin:$$PATH" \
        HOME="$(CURDIR)/debian/tmp" \
        DH_GOLANG_EXCLUDES="$(DH_GOLANG_EXCLUDES) api_test builtin/credential/cert" \
        dh_auto_test -v --max-parallel=3 -- -short -failfast
endif

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp

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

override_dh_installinit:
	dh_installinit --no-enable
#--no-start
