SUMMARY="A cross-platform, open source MUD client with scripting in Lua"
DESCRIPTION="A completely redesigned MUD (Multi User Dungeon) client that is \
easy to use and customise. Both power users and plain gamers alike will feel \
at home with Mudlet, without having to waste too much timer figuring out how \
to do something.

Mudlet is designed to be very fast and efficient right from the start. Its \
scripting engine is designed to handle thousands of lines under one second. \
The scripting framework uses Lua - a small, fast and efficient scripting \
language."
HOMEPAGE="https://www.mudlet.org/"
COPYRIGHT="2008-2013 Heiko Koehn
	2013 Chris Mitchell
	2014 Ahmed Charles
	2016 Chris Leacy
	2016-2017 Ian Adkins
	2017 Stephen Lyons
	2017 Tom Scheper
	2017 Fae"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/Mudlet/Mudlet/archive/Mudlet-$portVersion.tar.gz"
CHECKSUM_SHA256="109d542d789426f589925702a06c1793609fc10952ce5620519b02299be21c9b"
SOURCE_DIR="Mudlet-Mudlet-$portVersion"
srcGitRev_2="051d679cfff2c006e3c740ef6c0466180b2e79cd"
SOURCE_URI_2="https://github.com/edbee/edbee-lib/archive/$srcGitRev_2.tar.gz"
CHECKSUM_SHA256_2="93005068dd13b29621d9c1a6b59194a808ea1147fca7cbd5ed1117ea70f2ff46"
SOURCE_FILENAME_2="edbee-lib-$srcGitRev_2.tar.gz"
SOURCE_DIR_2="edbee-lib-$srcGitRev_2"
ADDITIONAL_FILES="mudlet.rdef.in"
PATCHES="mudlet-$portVersion.patchset"

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

PROVIDES="
	mudlet$secondaryArchSuffix = $portVersion
	app:mudlet$secondaryArchSuffix = $portVersion
	lib:libmudlet$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libboost_graph$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libGLU$secondaryArchSuffix
	lib:libhunspell_1.7$secondaryArchSuffix
	lib:liblua$secondaryArchSuffix
	lib:libpcre$secondaryArchSuffix
	lib:libpcrecpp$secondaryArchSuffix
	lib:libpcreposix$secondaryArchSuffix
	lib:libpugixml$secondaryArchSuffix
	lib:libQt5Concurrent$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gamepad$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Multimedia$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5OpenGL$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libyajl$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	lib:libzip$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libboost_graph$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libGLU$secondaryArchSuffix
	devel:libhunspell_1.7$secondaryArchSuffix
	devel:liblua$secondaryArchSuffix >= 5.1
	devel:libpcre$secondaryArchSuffix
	devel:libpcrecpp$secondaryArchSuffix
	devel:libpcreposix$secondaryArchSuffix
	devel:libpugixml$secondaryArchSuffix
	devel:libQt5Concurrent$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gamepad$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Multimedia$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5OpenGL$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libyajl$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:libzip$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:cmake
	cmd:cmp
	cmd:dd
	cmd:diff
	cmd:g++$secondaryArchSuffix
	cmd:grep
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python2
	cmd:sed
	cmd:strip
	"

defineDebugInfoPackage mudlet$secondaryArchSuffix \
	$appsDir/Mudlet

BUILD()
{
	rm -rf 3rdparty/edbee-lib
	ln -sfn $sourceDir2 3rdparty/edbee-lib

	touch translations/translated/translation-stats.json # Shouldn't be required

	rm -rf build_haiku
	mkdir -p build_haiku
	cd build_haiku

	export LUA_DIR="$portPackageLinksDir/lua${secondaryArchSuffix}_devel/develop/headers/$ARCH_SUBDIR/lua5.1"
	export HUNSPELL_DIR="$portPackageLinksDir/hunspell${secondaryArchSuffix}_devel/develop/"

	cmake .. \
		-DCMAKE_INSTALL_PREFIX=$appsDir/Mudlet

	make $jobArgs
}

INSTALL()
{
	cd build_haiku

	mkdir -p $appsDir
	cp src/mudlet $appsDir/Mudlet

	# Add Haiku resources
	local APP_SIGNATURE="application/x-vnd.qt5-mudlet"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		$portDir/additional-files/mudlet.rdef.in > mudlet.rdef

	addResourcesToBinaries mudlet.rdef $appsDir/Mudlet
	addAppDeskbarSymlink $appsDir/Mudlet
}
