SUMMARY="Chromium-based rendering library for the Qt5 framework"
DESCRIPTION="QtWebEngine provides a Web browser engine that integrates \
Chromium's fast moving web capabilities into Qt. "
HOMEPAGE="https://www.qt.io"
COPYRIGHT="2015-2021 The Qt Company Ltd."
LICENSE="BSD (3-clause)
	GNU LGPL v2.1"
REVISION="1"
srcGitRev="d95937135297d7b0439b6e919c89892e80de48b8"
SOURCE_URI="https://github.com/korli/qtwebengine-haiku/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="02c50666d2a3cd28df49da57a12ad96ec4b8b333e2ae1d6e5c532f85f0fe8bfd"
SOURCE_FILENAME="qtwebengine-haiku-$portVersion-$srcGitRev.tar.gz"
SOURCE_DIR="qtwebengine-haiku-$srcGitRev"
PATCHES="qtwebengine-$portVersion.patchset"

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

libVersion="$portVersion"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	qtwebengine$secondaryArchSuffix = $portVersion compat >= 5
	lib:libQt5Pdf$secondaryArchSuffix = $libVersionCompat
	lib:libQt5PdfWidgets$secondaryArchSuffix = $libVersionCompat
	lib:libQt5WebEngine$secondaryArchSuffix = $libVersionCompat
	lib:libQt5WebEngineCore$secondaryArchSuffix = $libVersionCompat
	lib:libQt5WebEngineWidgets$secondaryArchSuffix = $libVersionCompat
	cmd:qwebengine_convert_dict
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libavcodec$secondaryArchSuffix
	lib:libavformat$secondaryArchSuffix
	lib:libavutil$secondaryArchSuffix
	lib:libdbus_1$secondaryArchSuffix
	lib:libexecinfo$secondaryArchSuffix
	lib:libexpat$secondaryArchSuffix
	lib:libfontconfig$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libgl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:liblcms2$secondaryArchSuffix
	lib:libminizip$secondaryArchSuffix
	lib:libnspr4$secondaryArchSuffix
	lib:libnss3$secondaryArchSuffix
	lib:libnssutil3$secondaryArchSuffix
	lib:libopus$secondaryArchSuffix
	lib:libplc4$secondaryArchSuffix
	lib:libplds4$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Network$secondaryArchSuffix
	lib:libQt5Positioning$secondaryArchSuffix
	lib:libQt5Qml$secondaryArchSuffix
	lib:libQt5QmlModels$secondaryArchSuffix
	lib:libQt5Quick$secondaryArchSuffix
	lib:libQt5WebChannel$secondaryArchSuffix
	lib:libsmime3$secondaryArchSuffix
	lib:libsnappy$secondaryArchSuffix
	lib:libvpx$secondaryArchSuffix
	lib:libwebp$secondaryArchSuffix
	lib:libwebpdemux$secondaryArchSuffix
	lib:libwebpmux$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	qtwebengine${secondaryArchSuffix}_devel = $portVersion compat >= 5
	devel:libQt5Pdf$secondaryArchSuffix = $libVersionCompat
	devel:libQt5PdfWidgets$secondaryArchSuffix = $libVersionCompat
	devel:libQt5WebEngine$secondaryArchSuffix = $libVersionCompat
	devel:libQt5WebEngineCore$secondaryArchSuffix = $libVersionCompat
	devel:libQt5WebEngineWidgets$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	haiku$secondaryArchSuffix
	qtwebengine$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libavcodec$secondaryArchSuffix
	devel:libdbus_1$secondaryArchSuffix
	devel:libexecinfo$secondaryArchSuffix
	devel:libexpat$secondaryArchSuffix
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libharfbuzz$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libjsoncpp$secondaryArchSuffix
	devel:liblcms2$secondaryArchSuffix
	devel:libminizip$secondaryArchSuffix
	devel:libnss3$secondaryArchSuffix
	devel:libopus$secondaryArchSuffix
	devel:libprotobuf$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Network$secondaryArchSuffix
	devel:libQt5Positioning$secondaryArchSuffix
	devel:libQt5Qml$secondaryArchSuffix
	devel:libQt5QmlModels$secondaryArchSuffix
	devel:libQt5Quick$secondaryArchSuffix
	devel:libQt5WebChannel$secondaryArchSuffix
	devel:libsnappy$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libvpx$secondaryArchSuffix
	devel:libvulkan$secondaryArchSuffix
	devel:libwebp$secondaryArchSuffix >= 7
	devel:libxslt$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:bison
	cmd:find
	cmd:flex
	cmd:g++$secondaryArchSuffix
	cmd:gcc$secondaryArchSuffix
	cmd:gperf
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:ninja
	cmd:node >= 16
	cmd:perl
	pkgconfig$secondaryArchSuffix
	cmd:pkg_config$secondaryArchSuffix
	cmd:python2
	cmd:qmake >= 5
	cmd:which
	"
TEST_REQUIRES="
	cmd:wget
	"

BUILD()
{
	mkdir -p build && cd build

	qmake .. -- \
		-system-ffmpeg \
		-webp
	NINJAJOBS=$jobArgs make
}

INSTALL()
{
	cd build
	make install INSTALL_ROOT=$prefix

	mv $prefix/boot/system/* $prefix/
	rm -rf $prefix/boot

	rm $prefix/lib/Qt5*.la

	sed -e "/^QMAKE_PRL_BUILD_DIR/d" -i $libDir/libQt*.prl
	sed -e "s|$portVersion\ |5.15.2 |" -i $libDir/cmake/*/*Config.cmake

	fixPkgconfig
	prepareInstalledDevelLibs libQt5Pdf libQt5PdfWidgets \
		libQt5WebEngine libQt5WebEngineCore libQt5WebEngineWidgets

	packageEntries devel \
		$developDir \
		$libDir/cmake \
		$dataDir/Qt5/mkspecs
}

TEST()
{
	wget https://chromium.googlesource.com/chromium/src/+archive/refs/tags/87.0.4280.144/base/test/data.tar.gz

	# cd src/3rdparty/chromium
	# ../../../build/src/3rdparty/gn/out/Release/gn ls ../../../build/src/core/release/  //base/test/*
}
