#!/usr/bin/make -f
# -*- makefile -*-
#
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

include /usr/share/dpkg/default.mk
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

ifneq ($(filter pkg.solanum.mbedtls,$(DEB_BUILD_PROFILES)),)
	CONFIGURE_ARGS+=-Dopenssl=disabled -Dmbedtls=enabled
else ifneq ($(filter pkg.solanum.gnutls,$(DEB_BUILD_PROFILES)),)
	CONFIGURE_ARGS+=-Dopenssl=disabled -Dgnutls=enabled
else
	CONFIGURE_ARGS+=-Dopenssl=enabled
endif

ifdef DEB_NICKLEN
    CONFIGURE_ARGS+=-Dnicklen=$(DEB_NICKLEN)
endif

EXTERNAL_BUILD_TIMESTAMP?=$(shell LC_ALL=C date --utc -d @$(SOURCE_DATE_EPOCH))
export EXTERNAL_BUILD_TIMESTAMP

override_dh_auto_configure:
	[ ! -f include/serno.h ] && \
		echo '#include "datecode.h"' > include/serno.h && \
		echo '#define SERNO "'$(DEB_VERSION_UPSTREAM)'"' >> include/serno.h
	[ ! -f include/datecode.h ] && \
		echo '#define DATECODE $(SOURCE_DATE_EPOCH)UL' >> include/datecode.h
	dh_auto_configure --buildsystem=meson -- \
		-Dprogram_prefix=solanum- \
		-Dfhs_paths=true \
		--libdir=/usr/lib/solanum \
		-Dconfdir=/etc/solanum \
		-Dhelpdir=/usr/share/doc/solanum/help \
		-Dmoduledir=/usr/lib/solanum/modules \
		-Drundir=/run/solanum \
		${CONFIGURE_ARGS}

override_dh_auto_install:
	dh_auto_install --buildsystem=meson --destdir=debian/solanum
	# maybe this should be in /usr/share/doc, but then users won't know when to update their configs...
	mv $(CURDIR)/debian/solanum/etc/solanum/ircd.conf.example $(CURDIR)/debian/solanum/etc/solanum/ircd.conf

# Don't restart the ircd
override_dh_installinit:
	dh_installinit --no-stop-on-upgrade
override_dh_installsystemd:
	dh_installsystemd --no-stop-on-upgrade

override_dh_shlibdeps:
	dh_shlibdeps -X/usr/lib/solanum/modules/extensions -- \
    -dRecommends debian/solanum/usr/lib/solanum/modules/extensions/* -dDepends

%:
	dh $@ --buildsystem=meson --without autoreconf
