SUMMARY="Free e-book reader"
DESCRIPTION="CoolReader is fast and small cross-platform XML/CSS based eBook reader for \
desktops and handheld devices. Supported formats: FB2, TXT, RTF, DOC, TCR, HTML, EPUB, \
CHM, PDB, MOBI. Platforms: Win32, Linux, Android. Ported on some eInk based devices."
HOMEPAGE="https://sourceforge.net/projects/crengine/"
COPYRIGHT="1998-2009 Vadim Lopatin"
LICENSE="GNU GPL v2"
REVISION="2"
srcGitRev="d8a3a1bb60b6d03968469c0b866065af787a7373"
SOURCE_URI="https://sourceforge.net/code-snapshots/git/c/cr/crengine/crengine.git/crengine-crengine-$srcGitRev.zip"
CHECKSUM_SHA256="72f472fe0231b214df3cb31861ccabdf588bdb18efc37ba65eacdb6d0542c44c"
SOURCE_DIR="crengine-crengine-$srcGitRev"
PATCHES="coolreader3-$portVersion.patchset"
ADDITIONAL_FILES="
	coolreader.rdef.in
	haikuicons.zip
	"

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

PROVIDES="
	coolreader3$secondaryArchSuffix = $portVersion
	app:coolreader3$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libfontconfig$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5PrintSupport$secondaryArchSuffix
	lib:libQt5Svg$secondaryArchSuffix
	lib:libQt5WebKit$secondaryArchSuffix
	lib:libQt5WebKitWidgets$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libpng$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5PrintSupport$secondaryArchSuffix
	devel:libQt5Svg$secondaryArchSuffix
	devel:libQt5WebKit$secondaryArchSuffix
	devel:libQt5WebKitWidgets$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:gcc$secondaryArchSuffix
	cmd:git
	cmd:ld$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:unzip
	cmd:which
	"

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

BUILD()
{
	mkdir -p build
	cd build
	cmake .. -DGUI=QT5 \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX:PATH=$appsDir/CoolReader3

	make $jobArgs
}

INSTALL()
{
	cd build
	make install
	mv -f $appsDir/CoolReader3/cr3 $appsDir/CoolReader3/CoolReader

	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	local INTERNAL="`echo "$portVersion" | cut -d. -f4`"

	sed \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@INTERNAL@|$INTERNAL|" \
		$portDir/additional-files/coolreader.rdef.in > coolreader.rdef

	addResourcesToBinaries coolreader.rdef $appsDir/CoolReader3/CoolReader
	mimeset -f $appsDir/CoolReader3/CoolReader
	addAppDeskbarSymlink $appsDir/CoolReader3/CoolReader
}
