SUMMARY="A GUI for virtual machines using QEMU as the backend"
DESCRIPTION="AQEMU is a Qt5 graphical interface used to manage QEMU and KVM \
virtual machines. It has a user-friendly interface and allows one to set up \
the majority of QEMU and KVM options."
HOMEPAGE="https://github.com/tobimensch/aqemu/"
COPYRIGHT="2008-2017 Andrey Rijov"
LICENSE="GNU GPL v2"
REVISION="7"
SOURCE_URI="https://github.com/tobimensch/aqemu/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="e3d54de00ebdce3754f97f7e0e7cce8cebb588e8ce6bc249401cc909281b08de"
PATCHES="aqemu-$portVersion.patchset"
ADDITIONAL_FILES="
	aqemu.rdef.in
	haikuicons.zip
	"

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

PROVIDES="
	aqemu$secondaryArchSuffix = $portVersion
	app:AQEMU$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	qemu$secondaryArchSuffix
	lib:libdbus_1$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5PrintSupport$secondaryArchSuffix
	lib:libQt5Test$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libvncclient$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libdbus_1$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5PrintSupport$secondaryArchSuffix
	devel:libQt5Test$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libvncserver$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:qdbuscpp2xml$secondaryArchSuffix >= 5
	"

PATCH()
{
	unzip -o $sourceDir/../../additional-files/haikuicons.zip -d $sourceDir/resources
}

BUILD()
{
	mkdir -p build
	cd build
	cmake .. -DCMAKE_BUILD_TYPE=Release
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir/AQEMU
	cp build/aqemu $appsDir/AQEMU/AQEMU
	cp -rf resources/{docs,os_icons,os_templates} $appsDir/AQEMU
	cp -rf *.rcc $appsDir/AQEMU

	# Add Haiku resources
	local APP_SIGNATURE="application/x-vnd.qt5-aqemu"
	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/aqemu.rdef.in > aqemu.rdef

	addResourcesToBinaries aqemu.rdef $appsDir/AQEMU/AQEMU
	addAppDeskbarSymlink $appsDir/AQEMU/AQEMU
}
