#! /usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# Same set of components the old autotools --enable-* flags turned on;
# BUILD_MONOLITHIC/BUILD_ED2K/ENABLE_* default to ON upstream but are
# spelled out so the package does not silently change if those defaults do.
confflags = \
	-DBUILD_MONOLITHIC=ON \
	-DBUILD_DAEMON=ON \
	-DBUILD_REMOTEGUI=ON \
	-DBUILD_AMULECMD=ON \
	-DBUILD_WEBSERVER=ON \
	-DBUILD_ED2K=ON \
	-DBUILD_CAS=ON \
	-DBUILD_WXCAS=ON \
	-DBUILD_ALC=ON \
	-DBUILD_ALCC=ON \
	-DENABLE_NLS=ON \
	-DENABLE_UPNP=ON \
	-DENABLE_IP2COUNTRY=ON \
	-DTRANSLATED_MANPAGES=ON

# Keep binutils-dev out of the build (the old rules passed BFD_LIB= to make
# for the same reason), never wrap the compiler in a stray ccache, and ship
# with the "check for new version" preference off (#554623), which used to
# be done with debian/patches/version_check.diff.
confflags += \
	-DENABLE_BFD=OFF \
	-DENABLE_CCACHE=OFF \
	-DDEFAULT_VERSION_CHECK=OFF

# Build the muleunit tests so dh_auto_test runs them with ctest; dh's own
# -DBUILD_TESTING=OFF for nocheck would be overridden by this, so guard it.
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
confflags += -DBUILD_TESTING=ON
endif

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure -- $(confflags)

override_dh_installchangelogs:
	dh_installchangelogs docs/CHANGELOG.md

override_dh_bugfiles:
	dh_bugfiles -A

import-orig:
	# call it like ./debian/rules import-orig TARBALL=<path to the new tarball>
	git-import-orig --filter=debian/* --filter=config.{sub,guess} --pristine-tar --filter-pristine-tar ${TARBALL}

.PHONY: import-orig
