#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.
#export DH_VERBOSE = 1


# See FEATURE AREAS in dpkg-buildflags(1).
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# build-hardening flags
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# ignore Lua destructor test failures on archs where it doesn't pass
ifeq ($(DEB_HOST_ARCH),$(filter $(DEB_HOST_ARCH),armel armhf loong64 mips64el))
	export LUANTI_CMAKE_TEST_FLAGS = -DIGNORE_LUA_DESTRUCTOR_TEST_FAILURE=TRUE
endif

# See ENVIRONMENT in dpkg-buildflags(1).
# Package maintainers to append CFLAGS.
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# Package maintainers to append LDFLAGS.
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


%:
	dh $@


# dh_make generated override targets.
# This is an example for Cmake (see <https://bugs.debian.org/641051>).
#override_dh_auto_configure:
#	dh_auto_configure -- \
#	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

override_dh_auto_configure:
	dh_auto_configure -- \
		-DRUN_IN_PLACE=0 \
		-DBUILD_DOCUMENTATION=FALSE \
		-DCMAKE_VERBOSE_MAKEFILE=ON \
		-DENABLE_SYSTEM_JSONCPP=1 \
		-DENABLE_SYSTEM_GMP=1 \
		-DENABLE_SPATIAL=ON \
		-DJSON_INCLUDE_DIR=/usr/include/jsoncpp \
		-DENABLE_GETTEXT=1 \
		-DFREETYPE_INCLUDE_DIR_freetype2=/usr/include/freetype2 \
		-DFREETYPE_INCLUDE_DIR_ft2build=/usr/include \
		-DENABLE_LEVELDB=1 \
		-DENABLE_POSTGRESQL=1 \
		-DLEVELDB_INCLUDE_DIR=/usr/include/leveldb \
		-DCUSTOM_LOCALEDIR=/usr/share/locale \
		-DCUSTOM_SHAREDIR=/usr/share/luanti \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SERVER=1 \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DENABLE_UPDATE_CHECKER=OFF \
		-DREQUIRE_LUAJIT=TRUE \
		-DINSTALL_DEVTEST=TRUE \
		-DENABLE_PROMETHEUS=TRUE \
		${LUANTI_CMAKE_TEST_FLAGS}

override_dh_installchangelogs:
	dh_installchangelogs debian/changelog.upstream

override_dh_auto_test:
	HOME=$$(mktemp -d) bin/luanti --run-unittests
	dh_auto_test

override_dh_auto_install:
	install -D -m 444 $(CURDIR)/doc/luanti.6 $(CURDIR)/debian/luanti-server/usr/share/man/man6/luantiserver.6
	dh_auto_install