SUMMARY="A free physics sandbox game"
DESCRIPTION="The Powder Toy is a free physics sandbox game,\
which simulates air pressure and velocity, heat, gravity and \
a countless number of interactions between different substances! \
The game provides you with various building materials, liquids, gases \
and electronic components which can be used to construct complex machines,\
guns, bombs, realistic terrains and almost anything else."
HOMEPAGE="http://powdertoy.co.uk/"
COPYRIGHT="2008-2010 Stanislaw Skowronek
	2010-2021 Simon Robertshaw"
LICENSE="GNU GPL v3"
REVISION="2"
SOURCE_URI="https://github.com/simtr/The-Powder-Toy/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="d95cbadee22632687661e8fc488bd64405d81c0dca737e16420f26e93ea5bf58"
SOURCE_DIR="The-Powder-Toy-$portVersion"
PATCHES="thepowdertoy-$portVersion.patchset"
ADDITIONAL_FILES="thepowdertoy.rdef.in"

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

PROVIDES="
	thepowdertoy$secondaryArchSuffix = $portVersion
	app:Powder = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libfftw3$secondaryArchSuffix
	lib:libfftw3f$secondaryArchSuffix
	lib:liblua$secondaryArchSuffix
	lib:libluajit_5.1$secondaryArchSuffix
	lib:libsdl2_2.0$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libbz2$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libfftw3$secondaryArchSuffix
	devel:libfftw3f$secondaryArchSuffix
	devel:liblua5.1$secondaryArchSuffix
	devel:libluajit_5.1$secondaryArchSuffix
	devel:libsdl2_2.0$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:meson
	cmd:ninja
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3.7
	"

BUILD()
{
	export DISABLE_ASLR=1

	meson build
	ninja -C build $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir
	cp build/powder $appsDir/Powder

	local APP_SIGNATURE="application/x-vnd.the-powder-toy"
	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/thepowdertoy.rdef.in > $sourceDir/thepowdertoy.rdef

	addResourcesToBinaries  $sourceDir/thepowdertoy.rdef $appsDir/Powder

	addAppDeskbarSymlink $appsDir/Powder "The Powder Toy"
}
