#!/usr/bin/make -f

export DH_VERBOSE := 1
export DH_GOLANG_INSTALL_EXTRA := extra
# Disable binary from internal/customvet
export DH_GOLANG_EXCLUDES := example doctests internal/customvet

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

override_dh_auto_test:
	# Bypass tests due to missing build-deps on github.com/bsm/ginkgo/v2 and github.com/bsm/gomega.
	dh_auto_test -- -v -short || true

# go-redis is a multi-module repo:
#   root:                       github.com/redis/go-redis/v9
#   extra/rediscmd:             github.com/redis/go-redis/extra/rediscmd/v9
#   extra/rediscensus:          github.com/redis/go-redis/extra/rediscensus/v9
#   extra/redisotel:            github.com/redis/go-redis/extra/redisotel/v9
#   extra/redisprometheus:      github.com/redis/go-redis/extra/redisprometheus/v9
#
# dh-golang copies everything under debian/_build/src/<XS-Go-Import-Path>,
# so the nested modules end up at .../v9/extra/<name> instead of
# .../extra/<name>/v9. Symlink them at their declared import paths so the
# cross-module imports (e.g. rediscensus -> extra/rediscmd/v9) resolve
# during dh_auto_build.
execute_after_dh_auto_configure:
	set -e; base=debian/_build/src/github.com/redis/go-redis; \
	mkdir -p $$base/extra; \
	for m in rediscmd rediscensus redisotel redisprometheus; do \
		mkdir -p $$base/extra/$$m; \
		ln -sfn ../../v9/extra/$$m $$base/extra/$$m/v9; \
	done
