SUMMARY="2D animation and drawing program based on Qt5"
DESCRIPTION="Pencil2D lets you create traditional hand-drawn animation (cartoon) \
using both bitmap and vector graphics on Windows, MacOS and Linux. \
Pencil2D is free and open source."
HOMEPAGE="https://www.pencil2d.org/"
COPYRIGHT="Pascal Naidon, Patrick Corrieri, Matt Chang"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/pencil2d/pencil/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="31903c54c8f0a79385cc5f519b380d26524219984e619204820b946c96fc2482"
ADDITIONAL_FILES="pencil.rdef.in"

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

PROVIDES="
	pencil$secondaryArchSuffix = $portVersion
	app:Pencil2D$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	cmd:ffmpeg
	lib:libGL$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Multimedia$secondaryArchSuffix
	lib:libQt5Svg$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libQt5Xml$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libfreetype$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Multimedia$secondaryArchSuffix
	devel:libQt5Svg$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libQt5Xml$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:g++$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:qmake$secondaryArchSuffix >= 5
	cmd:which
	"

PATCH()
{
	sed -e '/tests/ s/^#*/#/' -i $sourceDir/pencil2d.pro
}

BUILD()
{
	export DISABLE_ASLR=1

	qmake
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir
	cp bin/pencil2d $appsDir/Pencil2D

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

	addResourcesToBinaries pencil.rdef $appsDir/Pencil2D

	addAppDeskbarSymlink $appsDir/Pencil2D
}
