#!/usr/bin/make -f

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

export DH_GOPKG := github.com/appc/acbuild
#export DH_GOLANG_INSTALL_ALL := 1
#export DH_GOLANG_EXCLUDES :=

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

override_dh_clean:
	dh_clean
	## Remove Files-Excluded (when built from checkout or non-DFSG tarball):
	$(RM) -rv `perl -0nE 'say $$1 if m{^Files\-Excluded\:\s*(.*?)(?:\n\n|Files:|Comment:)}sm;' debian/copyright`

override_dh_auto_configure:
	dh_auto_configure
	perl -0nE 'say $$1 if m{^Files\-Excluded\:\s*(.*?)(?:\n\n|Files:|Comment:)}sm;' debian/copyright \
        | while read D; do D="$${D##Godeps/_workspace/src/}" ; printf "Patching 3rd party includes: $$D\n" ;\
            perl -pi -E "s{$(DH_GOPKG)/Godeps/_workspace/src/$$D}{$$D}msg;" `find _build/src -type f -name "*.go"` ;\
        done

override_dh_auto_test:
	-ACBUILD_BIN="$(CURDIR)/_build/bin/acbuild" dh_auto_test

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp
