SUMMARY="Simple Text Adventures, The Interpreter"
DESCRIPTION="INSTEAD was designed to make the textographic games. \
These games are a mix of interactive fiction, visual novels and classic \
point & click adventures. Adventure begins!
(Get games from http://instead-games.ru. You can install zip file from the INSTEAD \
'Select game/[...]' menu.
Also, you can just unpack zip file with game in ~/config/settings/Instead/games)"
HOMEPAGE="https://instead-hub.github.io/"
COPYRIGHT="2009-2020 Peter Kosyh"
LICENSE="MIT"
REVISION="1"
SOURCE_URI="https://github.com/instead-hub/instead/releases/download/$portVersion/instead_$portVersion.tar.gz"
CHECKSUM_SHA256="bb98f6903291bcc40fb06f2203ab8e05272ec84fded412482b6faa54bea3a90b"
PATCHES="instead-$portVersion.patchset"
ADDITIONAL_FILES="instead.rdef.in"

ARCHITECTURES="all !x86_gcc2"
if [ "$targetArchitecture" = "x86_gcc2" ]; then
SECONDARY_ARCHITECTURES="x86"
fi

PROVIDES="
	instead$secondaryArchSuffix = $portVersion
	app:Instead = $portVersion
	"

REQUIRES="
	haiku$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libluajit_5.1$secondaryArchSuffix
	lib:libSDL_1.2$secondaryArchSuffix
	lib:libSDL_image_1.2$secondaryArchSuffix
	lib:libSDL_mixer_1.2$secondaryArchSuffix
	lib:libSDL_ttf_2.0$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libiconv$secondaryArchSuffix
	devel:libluajit_5.1$secondaryArchSuffix
	devel:libSDL_1.2$secondaryArchSuffix
	devel:libSDL_image_1.2$secondaryArchSuffix
	devel:libSDL_mixer_1.2$secondaryArchSuffix
	devel:libSDL_ttf_2.0$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	mkdir doc/saved && mv doc/*.pdf doc/*.txt doc/saved
	echo "2" | ./configure.sh
	mv doc/saved/* doc/ && rm -rf doc/saved
	make $jobArgs PREFIX=$appsDir/Instead \
		BIN=$appsDir/Instead \
		DESTDIR=/ \
		DATAPATH=$appsDir/Instead/data \
		DOCPATH=$appsDir/Instead/documentation \
		ICONPATH=$appsDir/Instead/data/icon
}

INSTALL()
{
	make install PREFIX=$appsDir/Instead \
		BIN=$appsDir/Instead \
		DESTDIR=/ \
		DATAPATH=$appsDir/Instead/data \
		DOCPATH=$appsDir/Instead/documentation \
		ICONPATH=$appsDir/Instead/data/icon

	# Clean up some unnecessary things from the package
	rm -rf $appsDir/Instead/{share,instead}
	mv $appsDir/Instead/sdl-instead $appsDir/Instead/Instead

	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|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/instead.rdef.in > instead.rdef

	addResourcesToBinaries instead.rdef $appsDir/Instead/Instead
	addAppDeskbarSymlink $appsDir/Instead/Instead INSTEAD
}
