#!/usr/bin/make -f

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

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

# Exclude sample code from compilation and installation.
export DH_GOLANG_EXCLUDES := examples

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

# 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.

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
DESTDEPSDIR := $(BUILDDIR)/src/$(DH_GOPKG)/deps

override_dh_auto_configure:
	dh_auto_configure -O--buildsystem=golang
	mkdir -p $(PROTODIR)
	cd debian; protoc metrics.proto --go_out=$(PROTODIR)
	# Move vendored dependencies to a saner path.
	mv -v $(BUILDDIR)/src/$(DH_GOPKG)/Godeps/_workspace/src $(DESTDEPSDIR)
	rm -rf $(BUILDDIR)/src/$(DH_GOPKG)/Godeps
	# Include test fixtures.
	cp -av extraction/fixtures $(BUILDDIR)/src/$(DH_GOPKG)/extraction
	cp -av Godeps/_workspace/src/github.com/beorn7/perks/quantile/exampledata.txt \
	    $(DESTDEPSDIR)/github.com/beorn7/perks/quantile/
