#!/usr/bin/make -f

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

export GOPATH = $(shell pwd)/obj-$(DEB_BUILD_GNU_TYPE)

override_dh_auto_build:
	# Regenerate proto files for each build
	(cd obj-$(DEB_BUILD_GNU_TYPE)/src/github.com/docker/swarmkit && \
		export PATH=$$PATH:`pwd`/bin && \
		make -f ../../../../../Makefile generate)
	# Clean up generated binary
	rm -rf obj-$(DEB_BUILD_GNU_TYPE)/src/github.com/docker/swarmkit/bin
	# Perform regular build
	dh_auto_build

override_dh_auto_test:
	-dh_auto_test

## http://wiki.debian.org/onlyjob/get-orig-source
PKD  = $(abspath $(dir $(MAKEFILE_LIST)))
PKG  = $(word 2,$(shell dpkg-parsechangelog -l$(PKD)/changelog | grep ^Source))
VER ?= $(shell dpkg-parsechangelog -l$(PKD)/changelog | perl -ne 'print $$1 if m{^Version:\s*([\d\.]+)}')

.PHONY: get-orig-source

get-orig-source:
	@echo "# Downloading..."
	uscan --noconf --verbose --rename --repack --compression xz --destdir=$(CURDIR) \
              --check-dirname-level=0 --force-download --download-version $(VER) $(PKD)
