SUMMARY="Open Motorsport Simulator"
DESCRIPTION="Speed Dreams is a 3d cross-platform, open source motorsport \
simulation and racing game.  It is also intended for any research, study or \
teaching activity, around physics and AI."
HOMEPAGE="http://www.speed-dreams.org/"
COPYRIGHT="2009-2018 Jean-Philippe Meuret"
LICENSE="GNU GPL v2"
REVISION="2"
SOURCE_URI="https://sourceforge.net/projects/speed-dreams/files/$portVersion/speed-dreams-src-base-$portVersion-r7616.tar.xz"

CHECKSUM_SHA256="c67e48a083cd86f6c0062f0b38ed91a5d25274ea8aa656ee182f3f5074e96ff0"
SOURCE_DIR=""

PATCHES="speed_dreams-$portVersion.patchset"
ADDITIONAL_FILES="speed_dreams.rdef.in"

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

PROVIDES="
	speed_dreams$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libenet$secondaryArchSuffix
	lib:libexpat$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libGLU$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libopenal$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix	
	lib:libvorbis$secondaryArchSuffix
	lib:libvorbisfile$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcurl$secondaryArchSuffix
	devel:libenet$secondaryArchSuffix
	devel:libexpat$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libGLU$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
	devel:libopenal$secondaryArchSuffix
	devel:libplibjs$secondaryArchSuffix
	devel:libplibsg$secondaryArchSuffix
	devel:libplibsl$secondaryArchSuffix
	devel:libplibssg$secondaryArchSuffix
	devel:libplibssgaux$secondaryArchSuffix
	devel:libplibul$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	devel:libvorbisfile$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	mkdir -p build && cd build

	cmake .. -Wno-dev -DCMAKE_INSTALL_PREFIX=$appsDir/SpeedDreams \
		-DSD_LOCALDIR=~/config/settings/speed-dreams \
		-DCMAKE_BUILD_TYPE=Release \
		-DOPTION_OFFICIAL_ONLY:BOOL=true \
		-DOPTION_OSGGRAPH:BOOL=false \
		-DOPTION_WEBSERVER:BOOL=false \
		-DOPTION_SDL2:BOOL=true
	make $jobArgs
}

INSTALL()
{
	cd build
	make install
	
	local APP_SIGNATURE="application/x-vnd.speed_dreams"
	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/speed_dreams.rdef.in > $sourceDir/speed_dreams.rdef

	
	addResourcesToBinaries $sourceDir/speed_dreams.rdef $appsDir/SpeedDreams/games/speed-dreams-2
	addAppDeskbarSymlink $appsDir/SpeedDreams/games/speed-dreams-2 "Speed Dreams 2"
}
