#!/usr/bin/make -f
# -*- makefile -*-

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.
export DH_GOPKG := golang.org/x/net

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

BUILDDIR := $(shell perl -w -MDebian::Debhelper::Buildsystem::golang -e \
        'print Debian::Debhelper::Buildsystem::golang->new()->get_builddir()')

override_dh_auto_configure:
	dh_auto_configure -O--buildsystem=golang
	# Include test fixtures.
	cp -av html/charset/testdata $(BUILDDIR)/src/$(DH_GOPKG)/html/charset/
	cp -av html/testdata $(BUILDDIR)/src/$(DH_GOPKG)/html/

override_dh_auto_test:
	# Some tests require root, need -short to skip them for now.
	dh_auto_test -O--buildsystem=golang -- -short

DEBVERS    ?= $(shell dpkg-parsechangelog | sed -n -e 's/^Version: //p')
VERSION    ?= $(shell echo '$(DEBVERS)' | sed 's/^[[:digit:]]*://; s/[-].*//')
DEBPKGNAME ?= $(shell dpkg-parsechangelog | sed -n -e 's/^Source: //p')
GITCOMMIT  ?= $(shell echo '$(VERSION)' | \
              sed -e 's/.*+git[[:digit:]]*\.\([[:xdigit:]]*\).*/\1/')

gen-orig-tgz:
	if [ ! -f ../$(DEBPKGNAME)_$(VERSION).orig.tar.gz ] ; then \
	    git archive --format=tar.gz --prefix=$(DEBPKGNAME)-$(VERSION)/ \
                $(GITCOMMIT) >../$(DEBPKGNAME)_$(VERSION).orig.tar.gz ; \
	fi
