#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

# GOPKG is the upstream path which you would normally “go get”.
# Using it allows us to build applications without patching locations.
GOPKG := github.com/mstap/godebiancontrol

# Temporary working directory to which the source will be copied, then
# compiled.
TMPGOPATH = $(CURDIR)/debian/tmp/usr/share/gocode

override_dh_auto_install:
	mkdir -p ${TMPGOPATH}/src/${GOPKG}
	# Copy all .go files to /usr/share/gocode (we compile and ship).
	find . -path ./debian -prune -o -type f -name "*.go" -exec tar cf - {} + | (cd "${TMPGOPATH}/src/${GOPKG}" && tar xvf -)

override_dh_auto_test:
	# TODO(stapelberg): It would be better if we could find a way to copy
	# the files only once, but dh_prep is run after dh_auto_test and before
	# dh_auto_install, so we cannot use e.g. dh_auto_build (unless we want
	# to work with two separate go directories).
	mkdir -p ${TMPGOPATH}/src/${GOPKG}
	# Copy all .go files to /usr/share/gocode (we compile and ship).
	find . -path ./debian -prune -o -type f -name "*.go" -exec tar cf - {} + | (cd "${TMPGOPATH}/src/${GOPKG}" && tar xvf -)
	# Ensure that GOPATH is clean: It should only contain the temporary
	# /usr/src/golang containing the package we want to install and the
	# /usr/src/golang of the system we are building on. It should
	# specifically NOT contain the user’s local ~/gocode.
	GOPATH=${TMPGOPATH}:/usr/share/gocode go test -v ${GOPKG}/...

%:
	dh $@ 
