#!/usr/bin/make -f
# -*- makefile -*-

#export DH_VERBOSE := 1

# Exclude "cover" since it is included in core as of Go 1.5+. Exclude heapview
# due to weird javascript dependencies. Exclude gopls/forward, as it does not
# seem to be used, and conflicts with binaries in other packages.
export DH_GOLANG_EXCLUDES := golang.org/x/tools/cmd/cover \
    golang.org/x/tools/cmd/heapview golang.org/x/tools/godoc/static \
    golang.org/x/tools/cmd/gopls/forward

# godoc/static is needed for tests.
export DH_GOLANG_INSTALL_EXTRA := godoc/static

BUILDDIR := $(CURDIR)/build

# Some tests require GOCACHE to be enabled, and with path including a component
# named 'go-build'.
export GOCACHE := $(BUILDDIR)/go-build

override_dh_auto_install:
	dh_auto_install
	# Rename “eg” to “golang-eg” (#753978)
	mv debian/tmp/usr/bin/eg debian/tmp/usr/bin/golang-eg
	# Rename “stress” to “golang-stress” (#793693)
	mv debian/tmp/usr/bin/stress debian/tmp/usr/bin/golang-stress
	# Rename “bundle” to “golang-bundle” (#818551)
	mv debian/tmp/usr/bin/bundle debian/tmp/usr/bin/golang-bundle
	# Rename “guru” to “golang-guru”
	mv debian/tmp/usr/bin/guru debian/tmp/usr/bin/golang-guru

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# use short tests where possible (especially to skip tests like
	# TestWebIndex which are very slow)
	dh_auto_test -- -test.short
endif

%:
	dh $@ --buildsystem=golang --with=golang --builddir=$(BUILDDIR)
