#!/usr/bin/make -f

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

export DH_GOLANG_GO_GENERATE := 1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DH_GOLANG_EXCLUDES := demo e2e internal/testing/apitests
export DH_GOLANG_INSTALL_EXTRA = \
    drivers/java/test-resources \
    command/agent/test-resources \
    jobspec/test-fixtures \
    nomad/structs/generate.sh

%:
	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 vendor -mindepth 1 -type d -empty -delete -printf 'removed %p\n'
	-find . -type f -name '*.generated.go' -delete -printf 'removed %p\n'     ## delete .generated.go files
	-find . -type f -name '*.pb.go' -delete -printf 'removed %p\n'            ## delete generated .pb.go files

override_dh_auto_configure:
	dh_auto_configure

override_dh_auto_build:
	export GOPATH=$(CURDIR)/_build \
	&& $(MAKE) -C _build/src/github.com/hashicorp/nomad --makefile=$(CURDIR)/GNUmakefile proto
	
	dh_auto_build -v -- -a -tags release

override_dh_auto_test:
	PATH="$(CURDIR)/_build/bin:$$PATH" \
        DH_GOLANG_EXCLUDES="${DH_GOLANG_EXCLUDES} client api command/agent drivers/shared/executor drivers/shared/eventer nomad/deploymentwatcher" \
        skipOnlineTestsEnvVar=1 \
        dh_auto_test -v --max-parallel=4 -- -short -failfast -timeout 5m

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp

override_dh_installinit:
	dh_installinit --no-start

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