#!/usr/bin/make -f

# bring in DEB_VERSION
include /usr/share/dpkg/default.mk

# export DH_VERBOSE = 1
export DH_GOLANG_EXCLUDES = ^\. assets/ docs/ examples/ scripts/ tools/ web/
export DH_GOLANG_INSTALL_EXTRA = mail/mailer_emoji_map.json server/templates \
	util/embedfs
export GOFLAGS="-tags=nofirebase,nowebpush,nopayments"

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

# 1. override version/commit/date, this way --help says something like:
#     ntfy 2.11.0-1 (debian-), runtime go1.23.5, built at 2024-12-15
# 2. show a message when accessing the ntfy web root
# 3. upstream Makefile uses these tags, but skipping:
#    sqlite_omit_load_extension,osusergo,netgo
override_dh_auto_build:
	mkdir -pv debian/_build/src/heckel.io/ntfy/v2/server/docs \
		debian/_build/src/heckel.io/ntfy/v2/server/site
	touch debian/_build/src/heckel.io/ntfy/v2/server/docs/index.html
	echo "<html><body>" \
		"ntfy web root: no web app is running in the debian version" \
		"</body></html>" > \
		debian/_build/src/heckel.io/ntfy/v2/server/site/app.html
	dh_auto_build -- \
		-ldflags "-X main.version=$(DEB_VERSION) -X main.commit=debian- \
			-X main.date=$(shell date -I --date='@$(SOURCE_DATE_EPOCH)')"

override_dh_auto_install:
	dh_auto_install -- --no-source

# install services without enabling or starting them as
# ntfy/ntfy-client are noisy and configured for port 80 by default
override_dh_installsystemd:
	dh_installsystemd --no-start --no-enable --restart-after-upgrade

override_dh_installsystemduser:
	dh_installsystemduser --no-enable

# Skip tests that depend on features disabled by the build tags in GOFLAGS
override_dh_auto_test:
	DH_GOLANG_EXCLUDES='$(DH_GOLANG_EXCLUDES) /server$$' \
		dh_auto_test -- -skip 'TestCLI_WebPush_'
