#!/usr/bin/make -f

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

export DH_OPTIONS
export DH_GOPKG := github.com/coreos/etcd
export DH_GOLANG_EXCLUDES := github.com/coreos/etcd/Godeps etcdctlv3 tools/v3benchmark

%:
	dh $@ --buildsystem=golang --with=golang,systemd --parallel

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`

PB_GO_FILES = $(patsubst %.proto, %.pb.go, $(wildcard */*/*.proto))
$(PB_GO_FILES):
	grep -Pq "syntax\s*=\s*\"proto3\"" $(@:.pb.go=.proto) \
        || protoc -I/usr/share/gocode/src/github.com/gogo/protobuf -I/usr/include -I$(dir $@) --gogo_out=$(dir $@) $(@:.pb.go=.proto)

override_dh_auto_configure: $(PB_GO_FILES)
	dh_auto_configure
	./debian/cleanup_third_party.sh

override_dh_auto_test:
	-dh_auto_test

override_dh_auto_clean:
	dh_auto_clean
	rm -rf bin/
	rm -rf gopath/
