#!/usr/bin/make -f

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

export DH_GOPKG := github.com/opencontainers/runc

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

export DH_GOLANG_EXCLUDES := vendor

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

override_dh_auto_configure:
	#$(MAKE) -C libcontainer/criurpc
	cd man && ./md2man-all.sh
	dh_auto_configure
	# use vendored deps
	rm -r '_build/src/$(DH_GOPKG)/Godeps/_workspace' \
		&& rm -rf '_build/src/$(DH_GOPKG)/vendor' \
		&& mkdir '_build/src/$(DH_GOPKG)/vendor' \
		&& cd Godeps/_workspace/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 -- -tags apparmor -gccgoflags="-I $(CURDIR)/_build/pkg/gccgo_$(GOOS)_$(GOARCH)/$(DH_GOPKG)/vendor"

override_dh_auto_test:
	-dh_auto_test -- -test.short -gccgoflags="-I $(CURDIR)/_build/pkg/gccgo_$(GOOS)_$(GOARCH)/$(DH_GOPKG)/vendor"
else
override_dh_auto_test:
	## Ignoring errors (some tests need network):
	-dh_auto_test -- -test.short

override_dh_auto_build:
	dh_auto_build -- -tags apparmor
endif
