#!/usr/bin/make -f

# there's Go code in hack/ but nothing we should test/ship
export DH_GOLANG_EXCLUDES := \
	github.com/docker/containerd/hack \
	github.com/docker/containerd/integration-test \
	vendor

# set DH_GOPKG for older dh-golang (backports)
export DH_GOPKG := github.com/docker/containerd

# prefer Go 1.6 if it's available (golang-1.6-go)
export PATH := /usr/lib/go-1.6/bin:$(PATH)

override_dh_auto_configure:
	dh_auto_configure
	# use vendored deps
	rm -r '_build/src/$(DH_GOPKG)/vendor' \
		&& mkdir '_build/src/$(DH_GOPKG)/vendor' \
		&& cd vendor/src \
		&& cp -r . '$(CURDIR)/_build/src/$(DH_GOPKG)/vendor'

# The go tool does not fully support vendoring with gccgo, but we can
# work around that by constructing the appropriate -I flag by hand.
GCCGO := $(shell go tool dist env > /dev/null 2>&1 && echo no || echo yes)

ifeq ($(GCCGO),yes)
GOARCH := $(shell go env GOARCH)
GOOS := $(shell go env GOOS)

override_dh_auto_build:
	dh_auto_build -- -gccgoflags="-I $(CURDIR)/_build/pkg/gccgo_$(GOOS)_$(GOARCH)/$(DH_GOPKG)/vendor"

override_dh_auto_test:
	dh_auto_test -- -gccgoflags="-I $(CURDIR)/_build/pkg/gccgo_$(GOOS)_$(GOARCH)/$(DH_GOPKG)/vendor"
endif

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