#!/usr/bin/make -f

VERSION := v$(shell dpkg-parsechangelog -SVersion | sed 's/[~+]ds.*//; s/-.*//; s/~/-/g')+debian

DEB_HOST_ARCH_CPU := $(shell dpkg-architecture -qDEB_HOST_ARCH_CPU 2>/dev/null)
RUN_TESTS := false
ifeq (amd64, $(DEB_HOST_ARCH_CPU))
	# TODO figure out why tests fail on all other arches
	RUN_TESTS := true
endif

override_dh_auto_build:
	dh_auto_build -- -ldflags '-X github.com/docker/distribution/version.Version=$(VERSION)'

override_dh_auto_test:
ifeq (true, $(RUN_TESTS))
	# health/checks hit the internet, and thus fail
	DH_GOLANG_EXCLUDES='distribution/registry/handlers health/checks' dh_auto_test -- -test.short
else
	# skip the tests on platforms where they fail
endif

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