SUMMARY="An InfiniMiner/Minecraft inspired game"
DESCRIPTION="Minetest, an open source infinite-world block sandbox game engine with support for survival and crafting."
HOMEPAGE="https://www.minetest.net/"
COPYRIGHT="2021 The Minetest Team"
LICENSE="GNU LGPL v2.1
	Apache v2"
REVISION="1"
SOURCE_URI="https://github.com/minetest/minetest/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="de9e4410583c845c104b4be25f9d0b8743d8573c120149b8910ae2519f9ab14e"
SOURCE_FILENAME="minetest-$portVersion.tar.gz"
SOURCE_DIR="minetest-$portVersion"
SOURCE_URI_2="https://github.com/minetest/minetest_game/archive/$portVersion.tar.gz"
CHECKSUM_SHA256_2="b4bfa0755b88230cf4bdb6af6a0951dd1248f6cdf87fecc340e43ac12c80b0b2"
SOURCE_FILENAME_2="minetest_game-$portVersion.tar.gz"
SOURCE_DIR_2="minetest_game-$portVersion"
PATCHES="minetest-$portVersion.patchset"
ADDITIONAL_FILES="minetest.rdef.in"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

PROVIDES="
	minetest$secondaryArchSuffix = $portVersion
	app:Minetest$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libgmp$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libIrrlicht$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libjsoncpp$secondaryArchSuffix
	lib:libluajit_5.1$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libopenal$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libsqlite3$secondaryArchSuffix
	lib:libvorbis$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libbz2$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libgmp$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libIrrlicht$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libjsoncpp$secondaryArchSuffix
	devel:libluajit_5.1$secondaryArchSuffix
	devel:libncurses$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
	devel:libopenal$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libsqlite3$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:cmake
	cmd:make
	cmd:pkg_config
	"

BUILD()
{
	rm -rf $sourceDir/games/minetest_game
	cp -rf $sourceDir2 $sourceDir/games/minetest_game

	cmake . \
		-DCMAKE_BUILD_TYPE=Release \
		-DCUSTOM_BINDIR="$appsDir/Minetest" \
		-DCUSTOM_DOCDIR="$docDir" \
		-DCUSTOM_MANDIR="$docDir" \
		-DCUSTOM_EXAMPLE_CONF_DIR="$docDir" \
		-DCUSTOM_LOCALEDIR="$appsDir/Minetest/locale" \
		-DCUSTOM_SHAREDIR="$appsDir/Minetest" \
		-DRUN_IN_PLACE=OFF \
		-DBUILD_CLIENT=ON \
		-DENABLE_CURL=ON \
		-DENABLE_CURSES=ON \
		-DENABLE_FREETYPE=ON \
		-DENABLE_GETTEXT=ON \
		-DENABLE_GLES=OFF \
		-DENABLE_LEVELDB=OFF \
		-DENABLE_LUAJIT=ON \
		-DENABLE_POSTGRESQL=OFF \
		-DENABLE_REDIS=OFF \
		-DENABLE_SPATIAL=OFF \
		-DENABLE_SOUND=ON \
		-DENABLE_SYSTEM_JSONCPP=ON

	make $jobArgs
}

INSTALL()
{
	make install
	mv $appsDir/Minetest/minetest $appsDir/Minetest/Minetest

	local APP_SIGNATURE="application/x-vnd.minetest"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/minetest.rdef.in > $sourceDir/minetest.rdef

	addResourcesToBinaries  $sourceDir/minetest.rdef \
		"$appsDir/Minetest/Minetest"
	addAppDeskbarSymlink "$appsDir/Minetest/Minetest"
}
