#!/usr/bin/make -f

SHELL := sh -e

include /usr/share/dpkg/architecture.mk

%:
	dh ${@} --buildsystem=meson

override_dh_builddeb:
	dh_builddeb -- -Zgzip

override_dh_auto_configure-indep:

override_dh_auto_build-indep:

override_dh_auto_test:
	# The reverse_proxy and paywall suites need a completed `make install'
	# -- they resolve paivana-httpd and its templates through the prefix --
	# and start listeners, neither of which belongs in a build chroot.  The
	# rest have no such requirement, so run those rather than nothing at
	# all; the ones needing node or tsc report themselves skipped when the
	# chroot has neither.
	#
	# Named tests have to go to `meson test' directly: at debhelper compat
	# 12 dh_auto_test runs `ninja test', which has no per-test targets, so
	# the names would reach ninja as unknown targets and fail the build.
	# Going around dh_auto_test means honouring nocheck here as well.
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	meson test -C obj-$(DEB_HOST_GNU_TYPE) --print-errorlogs \
	  client_address cookie_header cookie_access base64url paywall_typecheck
endif

override_dh_auto_install-arch:
	# paivana-httpd is the only binary package, so dh_auto_install would
	# install into debian/paivana-httpd/ and leave debian/tmp/, which
	# debian/paivana-httpd.install reads from, empty.
	dh_auto_install --destdir=debian/tmp

	# Upstream installs README and COPYING into /usr/share/doc/paivana,
	# which is not a path Debian wants: policy 12.3 puts documentation in
	# /usr/share/doc/<binary package>, i.e. .../paivana-httpd.  Drop the
	# whole upstream directory -- COPYING is redundant with
	# debian/copyright, and README is installed at the policy path by
	# dh_installdocs out of debian/paivana-httpd.docs.
	rm -rf debian/tmp/usr/share/doc/paivana

override_dh_auto_install-indep:

override_dh_auto_clean:
	dh_auto_clean

override_dh_installsystemd:
	dh_installsystemd -ppaivana-httpd --name=paivana-httpd --no-start --no-enable
	# final invocation to generate daemon reload
	dh_installsystemd

override_dh_install:
	dh_install
# Done manually for debhelper-compat<13
	dh_installtmpfiles
# Remove files already present in libpaivana-dev from paivana-httpd/libpaivana packages
