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

export DH_VERBOSE=1
# Exclude building the unused h2i binary to avoid circular dependency
# with golang-golang-x-crypto-dev.
export DH_GOLANG_EXCLUDES := golang.org/x/net/http2/h2i
# Include test fixtures.
export DH_GOLANG_INSTALL_EXTRA := html/charset/testdata html/testdata \
    bpf/testdata

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

override_dh_auto_configure:
	dh_auto_configure -O--buildsystem=golang
	# Remove tests that depends on non-free RFC spec.
	rm -v build/src/golang.org/x/net/http2/*_test.go

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')

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

gen-orig-tar-xz:
	if [ ! -f ../$(DEBPKGNAME)_$(VERSION).orig.tar.xz ] ; then \
            git archive --format=tar --prefix=$(DEBPKGNAME)-$(VERSION)/ \
            upstream/$(VERSION) | xz -9e \
            >../$(DEBPKGNAME)_$(VERSION).orig.tar.xz ; \
	fi
