#!/usr/bin/make -f

export DH_GOLANG_GO_GENERATE := 1
export DH_GOLANG_INSTALL_EXTRA := $(shell find . -name fixtures-expired) \
                                  $(shell find . -name fixtures)

# The ignored pkgs are aligned with upstream ./test file,
# see variables IGNORE_PKGS and INTEGRATION_PKGS in ./test
export TEST_EXCLUDES := cmd/ etcdserverpb rafttest gopath.proto v3lockpb v3electionpb \
                        integration e2e contrib functional

# The ignored pkgs are the first line from TEST_EXCLUDES, plus the most time-consuming
# tests from the regression tests. So the INTEGRATION_PKGS tests are the main
# leftovers.
export INTEGRATION_TEST_EXCLUDES := cmd/ etcdserverpb rafttest gopath.proto v3lockpb \
			v3electionpb \
			compactor etcdserver lease mvcc pkg proxy raft rafthttp snap \
			store wal

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

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	DH_GOLANG_EXCLUDES="$(TEST_EXCLUDES)" dh_auto_test -- -run=Test
	find _build -type s -delete
endif

# Handle package name (etcd-server) != service name (etcd)
override_dh_installinit:
	dh_installinit -p etcd-server --name=etcd
override_dh_installsystemd:
	dh_installsystemd -p etcd-server --name=etcd

# autopktest-pkg-go integration runs "debian/rules build", which is a no-op due
# to a script "build" present in the upstream source. This (PHONY) target
# overrides this.
build:
	dh build --buildsystem=golang --with=golang --builddirectory=_build

autopkgtest:
	DH_GOLANG_EXCLUDES="$(INTEGRATION_TEST_EXCLUDES)" dh_auto_test -O--buildsystem=golang -O--builddirectory=_build -- -run=Test
	find _build -type s -delete

.PHONY: build
