#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

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

override_dh_auto_test:
	# Force Go's new asynchronous timer channel behaviour. dh-golang builds in
	# GOPATH mode so the "go 1.25.0" directive from go.mod does not affect the
	# default GODEBUG settings. Without this asynctimerchan keeps its legacy
	# value of 1 which is rejected by testing/synctest in Go 1.26.
	#
	# Skip TestMountIndex - requires a working FUSE mount via fusermount
	# which is not available in Debian build chroots.
	GODEBUG=asynctimerchan=0 \
		dh_auto_test -- -test.skip="^TestMountIndex$$"

# Trim the CLI sources and the test fixtures from the source shipped in the
# -dev package. Nothing imports github.com/folbricht/desync/cmd/..., and
# testdata/ is ~11MB of binary blobs plus a throwaway TLS CA which are of no
# use to library consumers.
#
# The excludes are scoped to dh_auto_install rather than exported globally:
# DH_GOLANG_EXCLUDES also filters the targets handed to "go install" and
# "go test", so exporting it would stop the desync binary being built and the
# upstream test suite being run.
override_dh_auto_install:
	DH_GOLANG_EXCLUDES='^cmd/ (^|/)testdata/' dh_auto_install

# Generate man page from the --help/--version output with help2man.
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
execute_after_dh_auto_build:
	help2man -N \
		-n "desync" \
		--version-string='$(DEB_VERSION_UPSTREAM)' \
		-o debian/desync.1 \
		debian/_build/bin/desync
endif
