SUMMARY="A GUI for FS-UAE"
DESCRIPTION="FS-UAE is a cross-platform Amiga emulator based on updated \
emulation code from WinUAE. FS-UAE uses SDL for input, OpenAL for audio \
and OpenGL for graphics.

This package contains the launcher, a graphical user interface for \
setting up FS-UAE."
HOMEPAGE="https://fs-uae.net/launcher/"
COPYRIGHT="2011-2017 Frode Solheim"
LICENSE="GNU GPL v2"
REVISION="4"
SOURCE_URI="https://fs-uae.net/stable/$portVersion/fs-uae-launcher-$portVersion.tar.gz"
CHECKSUM_SHA256="27797a04b9fc0be2805ae992c2950ff6228383fa153eccefbdebfc6789ca76b6"
SOURCE_DIR="fs-uae-launcher-$portVersion"
PATCHES="fs_uae_launcher-$portVersion.patchset"
ADDITIONAL_FILES="fs-uae-launcher.rdef.in"

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

PROVIDES="
	fs_uae_launcher$secondaryArchSuffix = $portVersion
	"
REQUIRES="
    haiku$secondaryArchSuffix
    fs_uae$secondaryArchSuffix
    pip_python38$secondaryArchSuffix
    pyqt5_python38$secondaryArchSuffix
    requests_python38$secondaryArchSuffix
    "

BUILD_REQUIRES="
    haiku${secondaryArchSuffix}_devel
    "
BUILD_PREREQUIRES="
	cmd:make
	cmd:msgfmt
	cmd:python3.8
	"

PATCH()
{
	sed -i -e "s|python3|python3.8|g" Makefile
}

BUILD()
{
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"

	sed \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@SHORT@|$SUMMARY|" \
		$portDir/additional-files/fs-uae-launcher.rdef.in \
			> fs-uae-launcher.rdef
	make
}

INSTALL()
{
	local FS_UAE_LAUNCHER_NAME="FS-UAE Launcher"

	make install

	mkdir -p "$appsDir/$FS_UAE_LAUNCHER_NAME"
	cp -a usr/local/share/fs-uae-launcher/* "$appsDir/$FS_UAE_LAUNCHER_NAME"

	chmod +x "$appsDir/$FS_UAE_LAUNCHER_NAME/fs-uae-launcher"

	# Installing extra-attribs
	rc fs-uae-launcher.rdef
	resattr -o "$appsDir/$FS_UAE_LAUNCHER_NAME/fs-uae-launcher" \
		fs-uae-launcher.rsrc

	# Rename the main program
	mv "$appsDir/$FS_UAE_LAUNCHER_NAME/fs-uae-launcher" \
		"$appsDir/$FS_UAE_LAUNCHER_NAME/$FS_UAE_LAUNCHER_NAME"

	# Creating Deskbar link
	addAppDeskbarSymlink "$appsDir/$FS_UAE_LAUNCHER_NAME/$FS_UAE_LAUNCHER_NAME" \
		"$FS_UAE_LAUNCHER_NAME"

	# Copy docs
	mkdir -p $docDir
	cp -a usr/local/share/doc/fs-uae-launcher/* $docDir

	# Tidy up
	rm -rf usr
}
