#!/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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# 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:
	cp -r irrlicht/ lib/irrlichtmt/
	cp -r mtg/ games/minetest_game/
	dh_auto_configure -- \
		-DRUN_IN_PLACE=0 \
		-DCMAKE_VERBOSE_MAKEFILE=ON \
		-DENABLE_SYSTEM_JSONCPP=1 \
		-DENABLE_SYSTEM_GMP=1 \
		-DENABLE_SPATIAL=ON \
		-DJSON_INCLUDE_DIR=/usr/include/jsoncpp \
		-DENABLE_GETTEXT=1 \
		-DENABLE_FREETYPE=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/games/minetest \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SERVER=1 \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo\
		-DENABLE_UPDATE_CHECKER=OFF

override_dh_installchangelogs:
	dh_installchangelogs debian/changelog.upstream

ifneq ($(filter nocheck,$(DEB_BUILD_PROFILES)),)
# They are are needed for autopkgtest.
# run unittests when nocheck is active, but non-gating. Solves #1052671
# The unittest creates files that are to be installed in the minetest-data package.
# This files are required for autopkgtest, if the package is built with
# nocheck, this would break autopkgtest.
override_dh_auto_build:
	dh_auto_build
	HOME=$$(mktemp -d) bin/minetest --run-unittests || echo "nocheck: Ignoring unittests error."
endif

override_dh_install:
	dh_install -X.gitignore -Xoptimize_textures.sh
	find debian/ -iname "license.txt" -delete

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