#!/usr/bin/make -f

export DH_OPTIONS
export DH_GOPKG := github.com/prometheus/common

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

BUILDDIR := $(shell perl -w -MDebian::Debhelper::Buildsystem::golang -e \
    'print Debian::Debhelper::Buildsystem::golang->new()->get_builddir()')
PROTODIR := $(CURDIR)/$(BUILDDIR)/src/$(DH_GOPKG)/client_model

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

# All this is a hack to embed cleanly the protobuf definition which upstream
# maintains in a separate repo. The upstream .proto is included in the debian/
# directory, then compiled into a go source file in the place expected by the
# rest of the code.

override_dh_auto_configure:
	dh_auto_configure -O--buildsystem=golang
	mkdir -p $(PROTODIR)
	cd debian; protoc metrics.proto --go_out=$(PROTODIR)
	# Include test fixtures.
	cp -av expfmt/testdata $(BUILDDIR)/src/$(DH_GOPKG)/expfmt

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
