#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

BUILDFLAGS :=
ifeq (,$(filter $(DEB_BUILD_ARCH), mipsel mips64el))
BUILDFLAGS += -buildmode=pie
endif

override_dh_auto_configure:
	# We're building `gotest.tools/gotestum`, and we depend on `gotest.tools`.
	# That's a bit problematic, and here's why:
	# - dh_auto_configure first creates symlinks to build dependencies, hence:
	#     _build/src/gotest.tools -> /usr/share/gocode/src/gotest.tools
	# - then dh_auto_configure creates the directory for the sources we build:
	#     _build/src/gotest.tools/gotestsum
	# - hence overriding the initial symlink to gotest.tools...
	# So instead of one symlink to gotest.tools, we need symlinks to every
	# packages that gotest.tools provide.
	mkdir -p _build/src/gotest.tools
	for dir in /usr/share/gocode/src/gotest.tools/*/; do \
	    ln -s $$dir _build/src/gotest.tools/; \
	done
	dh_auto_configure

override_dh_auto_build:
	dh_auto_build -- $(BUILDFLAGS)

override_dh_auto_install:
	dh_auto_install -- --no-source

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