SUMMARY="A system emulator for the RISC-V architecture"
DESCRIPTION="TinyEMU is a system emulator for the RISC-V architecture. \
Its purpose is to be small and simple while being complete.

Main features:

RISC-V system emulator supporting the RV128IMAFDQC base ISA \
(user level ISA version 2.2, priviledged architecture version 1.10) \
including:
* 32/64/128 bit integer registers
* 32/64/128 bit floating point instructions (using the SoftFP Library)
* Compressed instructions
* Dynamic XLEN change
* VirtIO console, network, block device, input and 9P filesystem
* Graphical display with SDL
* JSON configuration file
* Remote HTTP block device and filesystem
* Small code, easy to modify, few external dependancies."
HOMEPAGE="https://bellard.org/tinyemu/"
COPYRIGHT="2017-2019 Fabrice Bellard"
LICENSE="MIT"
REVISION="3"
SOURCE_URI="https://bellard.org/tinyemu/tinyemu-${portVersion//./-}.tar.gz"
CHECKSUM_SHA256="be8351f2121819b3172fcedce5cb1826fa12c87da1b7ed98f269d3e802a05555"
SOURCE_DIR="tinyemu-${portVersion//./-}"
PATCHES="tinyemu-$portVersion.patchset"
ADDITIONAL_FILES="tinyemu.rdef.in"

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

commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

PROVIDES="
	tinyemu$secondaryArchSuffix = $portVersion
	cmd:temu$commandSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libSDL_1.2$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcrypto$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libSDL_1.2$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:make
	"

BUILD()
{
	make $jobArgs
}

INSTALL()
{
	mkdir $commandBinDir
	cp temu $commandBinDir

	local APP_SIGNATURE="application/x-vnd.tinyemu"
	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/tinyemu.rdef.in > tinyemu.rdef

	addResourcesToBinaries tinyemu.rdef $commandBinDir/temu
}
