#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# generate documentation unless nodoc requested
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
DOCS = README.html README.txt
endif

%:
	dh $@ --buildsystem=meson+ninja

%.html: %.md
	cmark-gfm $< > $@

%.txt: %.md
	cmark-gfm --to plaintext $< > $@

execute_after_dh_auto_build: $(DOCS)

override_dh_installdocs:
	dh_installdocs -- $(DOCS)

override_dh_auto_configure:
	dh_auto_configure --buildsystem=meson+ninja -- \
		--localstatedir=/var/lib \
		-Dwith-appletalk=true \
		-Dwith-dbus-daemon-path=/usr/bin/dbus-daemon \
		-Dwith-docbook-path=/usr/share/xml/docbook/stylesheet/docbook-xsl \
		-Dwith-init-hooks=false \
		-Dwith-init-style=debian-sysv,systemd \
		-Dwith-install-hooks=false \
		-Dwith-krbV-uam=true \
		-Dwith-ldsoconf=false \
		-Dwith-manual=local \
		-Dwith-overwrite=true \
		-Dwith-pam-config-path=/etc/pam.d \
		-Dwith-pkgconfdir-path=/etc/netatalk \
		-Dwith-readmes=false \
		-Dwith-rpath=false \
		-Dwith-spooldir=/var/spool/netatalk \
		-Dwith-tests=true

execute_after_dh_auto_install:
# Install initscripts with debhelper to add pre- and postinst routines
	mv debian/tmp/etc/init.d/a2boot debian/a2boot.init
	mv debian/tmp/etc/init.d/atalkd debian/atalkd.init
	mv debian/tmp/etc/init.d/macipgw debian/macipgw.init
	mv debian/tmp/etc/init.d/netatalk debian/netatalk.init
	mv debian/tmp/etc/init.d/papd debian/papd.init
	mv debian/tmp/etc/init.d/timelord debian/timelord.init
	mv debian/tmp/usr/lib/systemd/system/a2boot.service debian/
	mv debian/tmp/usr/lib/systemd/system/atalkd.service debian/
	mv debian/tmp/usr/lib/systemd/system/macipgw.service debian/
	mv debian/tmp/usr/lib/systemd/system/netatalk.service debian/
	mv debian/tmp/usr/lib/systemd/system/papd.service debian/
	mv debian/tmp/usr/lib/systemd/system/timelord.service debian/

override_dh_installsystemd:
# TODO: Figure out why dh_installsystemd attempts to install atalkd.service for the a2boot package
	dh_installsystemd || true
