#!/usr/bin/make -f

export DH_VERBOSE := 1

# - v3/integrations/nrawssdk-v1 requires github.com/aws/aws-sdk-go v1.15.0
#   and tests are failing. add v3/integrations/nrawssdk-v1 to build once
#   golang-github-aws-aws-sdk-go-dev is updated to 1.15.0
# - v3/integrations/nrgraphgophers depends on
#   golang-github-graph-gophers-graphql-go-dev which is also outdated.
#   revisit once v1.1 has entered unstable

export DH_GOPKG := github.com/newrelic/go-agent
export DH_GOLANG_BUILDPKG := $(DH_GOPKG) \
                             $(DH_GOPKG)/internal \
                             $(DH_GOPKG)/_integrations/logcontext \
                             $(DH_GOPKG)/_integrations/logcontext/nrlogrusplugin \
                             $(DH_GOPKG)/_integrations/nrb3 \
                             $(DH_GOPKG)/_integrations/nrecho \
                             $(DH_GOPKG)/_integrations/nrgin/v1 \
                             $(DH_GOPKG)/_integrations/nrgorilla/v1 \
                             $(DH_GOPKG)/_integrations/nrgrpc \
                             $(DH_GOPKG)/_integrations/nrhttprouter \
                             $(DH_GOPKG)/_integrations/nrlogrus \
                             $(DH_GOPKG)/_integrations/nrmysql \
                             $(DH_GOPKG)/_integrations/nrpkgerrors \
                             $(DH_GOPKG)/_integrations/nrsqlite3 \
                             $(DH_GOPKG)/_integrations/nrzap \
                             $(DH_GOPKG)/v3/newrelic \
                             $(DH_GOPKG)/v3/integrations/logcontext \
                             $(DH_GOPKG)/v3/integrations/logcontext/nrlogrusplugin \
                             $(DH_GOPKG)/v3/integrations/nrb3 \
                             $(DH_GOPKG)/v3/integrations/nrecho-v3 \
                             $(DH_GOPKG)/v3/integrations/nrgin \
                             $(DH_GOPKG)/v3/integrations/nrgorilla \
                             $(DH_GOPKG)/v3/integrations/nrgrpc \
                             $(DH_GOPKG)/v3/integrations/nrhttprouter \
                             $(DH_GOPKG)/v3/integrations/nrlogrus \
                             $(DH_GOPKG)/v3/integrations/nrmysql \
                             $(DH_GOPKG)/v3/integrations/nrpkgerrors \
                             $(DH_GOPKG)/v3/integrations/nrsqlite3 \
                             $(DH_GOPKG)/v3/integrations/nrzap \
                             $(DH_GOPKG)/v3/internal
export DH_GOLANG_EXCLUDES := example/ \
		             examples/ \
			     example_test.go \
			     examples_test.go \
		             integrations/nrecho-v4 \
                             integrations/nrelasticsearch-v7 \
                             integrations/nrgraphqlgo \
                             integrations/nrlambda \
                             integrations/nrlogxi \
                             integrations/nrmicro \
                             integrations/nrmongo \
                             integrations/nrnats \
                             integrations/nrpq \
                             integrations/nrredis-v7 \
                             integrations/nrredis-v8 \
                             integrations/nrsnowflake \
                             integrations/nrstan \
			     integrations/nrawssdk-v1 \
			     integrations/nrgraphgophers
export DH_GOLANG_EXCLUDES_ALL := 1
export DH_GOLANG_INSTALL_EXTRA := v3/internal/crossagent/cross_agent_tests/ \
                                  internal/crossagent/cross_agent_tests/

PKG := golang-github-newrelic-go-agent-dev
export EXAMPLE_DIR := debian/$(PKG)/usr/share/doc/$(PKG)/examples
export EXAMPLE_PLUGINS := $(shell find . -iwholename '*integrations/*/example*' -not -path './_build*' | paste -s)

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

#override_dh_auto_test:

override_dh_installexamples:
	mkdir -p $(EXAMPLE_DIR)/v2 $(EXAMPLE_DIR)/v3
	cp -a ./examples/* $(EXAMPLE_DIR)/v2/
	cp -a ./examples_test.go $(EXAMPLE_DIR)/v2/
	cp -a ./v3/examples/* $(EXAMPLE_DIR)/v3/
	cp -a ./v3/newrelic/examples_test.go $(EXAMPLE_DIR)/v3/
	for file in $(EXAMPLE_PLUGINS); do \
	    dir=$$(dirname $$file); \
	    mkdir -p $(EXAMPLE_DIR)/$$dir; \
	    cp -av $$file $(EXAMPLE_DIR)/$$dir; \
	done
	mv $(EXAMPLE_DIR)/_integrations $(EXAMPLE_DIR)/v2/_integrations
	find $(EXAMPLE_DIR) -iname "LICENSE.txt" -delete
