#!/usr/bin/make -f

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

export DH_GOLANG_INSTALL_EXTRA := examples
export DH_GOLANG_EXCLUDES := examples site
export DH_GOLANG_GO_GENERATE := 0

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

override_dh_auto_build:
	dh_auto_build -- -ldflags "-X main.Version=$(DEB_VERSION_UPSTREAM)"
	# Generate shell completions using the just-built binary.
	_build/bin/darkman completion bash > debian/darkman.bash-completion
	_build/bin/darkman completion zsh  > debian/_darkman
	_build/bin/darkman completion fish > debian/darkman.fish

override_dh_auto_install:
	dh_auto_install -- --no-source
	# Tidy up: dh-golang would otherwise leave the cmd/darkman source
	# behind. We're a binary-only package; drop /usr/share/gocode entirely.
	rm -rf debian/darkman/usr/share/gocode

override_dh_install:
	dh_install
	# Bash completion is a single file at completions/<command>; using
	# debian/darkman.install for this creates a stray directory because
	# dh_install treats the destination as a directory. Install by hand.
	install -d debian/darkman/usr/share/bash-completion/completions
	install -m 0644 debian/darkman.bash-completion \
	    debian/darkman/usr/share/bash-completion/completions/darkman

override_dh_auto_test:
	# Upstream tests need a session bus.
	dbus-run-session -- dh_auto_test

# darkman has no /etc config, no daemon footprint, no setuid bits;
# the standard dh sequence covers everything else.
