SUMMARY="A game inspired by the arcade classic Space Invaders"
DESCRIPTION="SDLInvaders is a game inspired by the arcade classic Space Invaders using SDL"
HOMEPAGE="https://sourceforge.net/projects/sdlinvaders/"
COPYRIGHT="Niels Weber"
LICENSE="GNU GPL v2"
REVISION="2"
SOURCE_URI="https://master.dl.sourceforge.net/project/sdlinvaders/sdlinvaders/0.7.6/SDLInvaders-0.7.6.tar.bz2?viasf=1"
CHECKSUM_SHA256="7646ce1d6f93e554f972f47529bcca01cb7228ccc6cd41fd5fa28d7e5e91fd75"
SOURCE_FILENAME="SDLInvaders-0.7.6.tar.bz2"
SOURCE_DIR="SDLInvaders"
PATCHES="sdlinvaders-0.7.6.patchset"
ADDITIONAL_FILES="sdlinvaders.rdef.in"

ARCHITECTURES="all"

GLOBAL_WRITABLE_FILES="
	settings/sdlinvaders/highscores keep-old
	"

PROVIDES="
	sdlinvaders$secondaryArchSuffix = $portVersion
	app:SDLInvaders = $portVersion
	"	
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libSDL_1.2$secondaryArchSuffix
	lib:libSDL_image_1.2$secondaryArchSuffix
	lib:libSDL_mixer_1.2$secondaryArchSuffix
	"
	
BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libSDL_1.2$secondaryArchSuffix
	devel:libSDL_image_1.2$secondaryArchSuffix
	devel:libSDL_mixer_1.2$secondaryArchSuffix
	"

BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:make$secondaryArchSuffix
	"
	
BUILD() {
	make $jobArgs
}

INSTALL() {
	# prepare the rdef file
	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/sdlinvaders.rdef.in > $portDir/sdlinvaders.rdef

	mkdir -p $appsDir
	mkdir -p $settingsDir/sdlinvaders
	mkdir -p $dataDir/sdlinvaders
	
	cp SDLInvaders $appsDir/SDLInvaders
	cp -r data $dataDir/sdlinvaders/data
	mv $dataDir/sdlinvaders/data/highscores $settingsDir/sdlinvaders/highscores

	addResourcesToBinaries $portDir/sdlinvaders.rdef $appsDir/SDLInvaders
	addAppDeskbarSymlink $appsDir/SDLInvaders
}
