#!/usr/bin/make -f
# -*- makefile -*-

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

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# the build system silences build flags without this set
export V=1

# Skip automatic generation of serno.h, generate our own.
export SKIP_SERNO_H_GENERATION=yes

define SERNO_VERSION
#ifndef ATHEME_INC_SERNO_H
#define ATHEME_INC_SERNO_H 1
#define SERNO "$(DEB_VERSION_UPSTREAM)"
#endif
endef
export SERNO_VERSION

%:
	dh $@

override_dh_auto_configure:
	@echo "$$SERNO_VERSION" > include/atheme/serno.h
	dh_auto_configure -- \
		--docdir=/usr/share/doc/atheme-services/ \
		--sysconfdir=/etc/atheme \
		--disable-rpath \
		--enable-contrib \
		--enable-fhs-paths \
		--enable-reproducible-builds \
		--enable-legacy-pwcrypto \
		--with-libmowgli=no \
		--without-cracklib \
		--without-ldap \
		--without-perl

override_dh_install:
	dh_install -p atheme-services -X/contrib/
	dh_install --remaining-packages

	# atheme-services allows wide configure latitude, so we want to make sure the user
	# reads the config files...
	rm -f $(CURDIR)/debian/atheme-services/etc/atheme/*example

	# shut lintian up by not installing the LICENSE...
	rm -f $(CURDIR)/debian/atheme-services/usr/share/doc/atheme-services/LICENSE
	rm -f $(CURDIR)/debian/atheme-services/usr/share/doc/atheme/LICENSE

	# shut lintian up by removing the run folder.
	rm -rf $(CURDIR)/debian/atheme-services/var/run

# libpasswdqc is only needed if one uses the pwquality, so don't make it a hard depend.
override_dh_shlibdeps:
	dh_shlibdeps -Xpwquality.so
	dh_shlibdeps -patheme-services -- -patheme-services -dRecommends debian/atheme-services/usr/lib/*/atheme/modules/nickserv/pwquality.so

override_dh_installinit:
	dh_installinit --no-enable

override_dh_installsystemd:
	dh_installsystemd --no-enable

override_dh_clean:
	dh_clean dist/atheme.conf.operserv-example dist/atheme.conf.userserv-example libmowgli-2/src/libmowgli/platform/autoconf.h
