SUMMARY="A QtWebEngine browser"
DESCRIPTION="Falkon is a KDE web browser using QtWebEngine rendering engine, \
previously known as QupZilla. It aims to be a lightweight web browser available \
through all major platforms."
HOMEPAGE="https://falkon.org/"
COPYRIGHT="2009-2019 Falkon Browser Team"
LICENSE="GNU GPL v3"
REVISION="4"
SOURCE_URI="https://github.com/KDE/falkon/archive/refs/tags/v3.2.0.tar.gz"
CHECKSUM_SHA256="5b8fba93ca53b8e5f69ea913e36b01084b65ccb3f399281dbc1b0df89916f4ca"
PATCHES="falkon-$portVersion.patchset"
ADDITIONAL_FILES="
	falkon.rdef.in
	icons.zip
	"

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

PROVIDES="
	falkon$secondaryArchSuffix = $portVersion
	app:Falkon$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5DBus$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libKF5Archive$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5Positioning$secondaryArchSuffix
	lib:libQt5PrintSupport$secondaryArchSuffix
	lib:libQt5Qml$secondaryArchSuffix
	lib:libQt5QmlModels$secondaryArchSuffix
	lib:libQt5Quick$secondaryArchSuffix
	lib:libQt5QuickWidgets$secondaryArchSuffix
	lib:libQt5Sql$secondaryArchSuffix
	lib:libQt5WebChannel$secondaryArchSuffix
	lib:libQt5WebEngine$secondaryArchSuffix
	lib:libQt5WebEngineCore$secondaryArchSuffix
	lib:libQt5WebEngineWidgets$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libintl$secondaryArchSuffix
	devel:libKF5I18n$secondaryArchSuffix
	devel:libKF5Archive$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5DBus$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5PrintSupport$secondaryArchSuffix
	devel:libQt5Positioning$secondaryArchSuffix
	devel:libQt5Qml$secondaryArchSuffix
	devel:libQt5QmlModels$secondaryArchSuffix
	devel:libQt5Quick$secondaryArchSuffix
	devel:libQt5QuickWidgets$secondaryArchSuffix
	devel:libQt5Sql$secondaryArchSuffix
	devel:libQt5WebChannel$secondaryArchSuffix
	devel:libQt5WebEngine$secondaryArchSuffix
	devel:libQt5WebEngineCore$secondaryArchSuffix
	devel:libQt5WebEngineWidgets$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	extra_cmake_modules
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:ninja
	cmd:pkg_config$secondaryArchSuffix
	cmd:qdbuscpp2xml$secondaryArchSuffix >= 5
	cmd:sed
	"

defineDebugInfoPackage falkon$secondaryArchSuffix \
	"$appsDir"/Falkon/Falkon \
	"$appsDir"/Falkon/lib/libFalkonPrivate.so.$portVersion \
	"$addOnsDir"/Qt5/falkon/AutoScroll.so \
	"$addOnsDir"/Qt5/falkon/FlashCookieManager.so \
	"$addOnsDir"/Qt5/falkon/GreaseMonkey.so \
	"$addOnsDir"/Qt5/falkon/MouseGestures.so \
	"$addOnsDir"/Qt5/falkon/PIM.so \
	"$addOnsDir"/Qt5/falkon/StatusBarIcons.so \
	"$addOnsDir"/Qt5/falkon/TabManager.so \
	"$addOnsDir"/Qt5/falkon/VerticalTabs.so

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

BUILD()
{
	cmake -S . -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX:PATH="$appsDir/Falkon" \
		-DCMAKE_INSTALL_DATAROOTDIR:PATH="$dataDir" \
		-DKDE_INSTALL_PLUGINDIR=$addOnsDir/Qt5 \
		-DECM_MKSPECS_INSTALL_DIR=$dataDir/Qt5/mkspecs \
		-DECM_DIR=/system/data/cmake/Modules/ECM/cmake
	cd build
	ninja $jobArgs
}

INSTALL()
{
	cd build
	ninja install

	mv $appsDir/Falkon/bin/falkon \
		$appsDir/Falkon/Falkon

	rm -rf $appsDir/Falkon/bin

	local APP_SIGNATURE="application/x-vnd.falkon"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		$portDir/additional-files/falkon.rdef.in > falkon.rdef

	addResourcesToBinaries falkon.rdef \
		$appsDir/Falkon/Falkon

	addAppDeskbarSymlink $appsDir/Falkon/Falkon "Falkon"
}
