#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export DH_GOPKG := github.com/danos/vci
export DH_GOLANG_INSTALL_ALL := 1

GOCOVER=$(if $(shell go doc cmd/cover >/dev/null 2>&1 && echo true),-cover,)

GOBUILDDIR := _build

%:
	dh $@ --buildsystem=golang --with=golang --builddirectory=$(GOBUILDDIR)

override_dh_auto_build: vet
	dh_auto_build

override_dh_auto_test:
	dh_auto_test -- $(GORACE) $(GOCOVER)

override_dh_systemd_enable:
	dh_systemd_enable --name=vyatta-vci-bus

# We do not vet vendor code
# For Debian11 (versus 10 and earlier) we need to explicitly set GO111MODULE to
# avoid 'go vet' failing due to module-related issues. We also need to restrict
# the package list found to the GOBUILDDIR subset or external packages cause
# errors.
vet:
	if go doc cmd/vet >/dev/null 2>&1; then \
		GO111MODULE=off GOPATH=$(CURDIR)/$(GOBUILDDIR) go vet $$(find . -type f -name \*.go | \
		xargs dirname | sort -u | grep $(GOBUILDDIR) | grep -v services | grep -v "/vendor/"); \
	fi
