#!/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$$"

# Generate man page from the --help/--version output with help2man.
#
# Guard on the binary existing: the autopkgtest-pkg-go testsuite rebuilds the
# package via dh_golang_autopkgtest using only the library source shipped in the
# -dev package. Since cmd/ is trimmed from that package the CLI binary is never
# built; so skip manpage generation.
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
execute_after_dh_auto_build:
	if [ -x debian/_build/bin/desync ]; then \
		help2man -N \
			-n "desync" \
			--version-string='$(DEB_VERSION_UPSTREAM)' \
			-o debian/desync.1 \
			debian/_build/bin/desync; \
	fi
endif
