# Template file for 'qt5-webkit'
pkgname=qt5-webkit
version=5.9.0
revision=4
wrksrc=qtwebkit-opensource-src-${version}
hostmakedepends="bison flex gperf perl python ruby pkg-config"
makedepends="libwebp-devel libxslt-devel libXcomposite-devel sqlite-devel libjpeg-turbo-devel
 gst-plugins-base1-devel qt5-declarative-devel qt5-location-devel
 qt5-sensors-devel qt5-webchannel-devel"
short_desc="A cross-platform application and UI framework (Qt5) - WebKit2 component"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
license="GPL-3, LGPL-2.1"
homepage="https://www.qt.io/"
distfiles="https://download.qt.io/community_releases/${version%.*}/${version}-final/qtwebkit-opensource-src-${version}.tar.xz"
checksum=8dad193b740055a998312e04a040f2e32a923c0823b2d239b24eab08276a4e04

CXXFLAGS="-std=c++11 -fno-delete-null-pointer-checks"
LDFLAGS="-ldl"
if [ -n "$CROSS_BUILD" ]; then
	hostmakedepends+=" qt5-host-tools qt5-declarative-devel libjpeg-turbo-devel"
fi

do_configure() {
	mkdir -p build
	cd build
	# Generate headers
	syncqt.pl-qt5 -version ${version} ${wrksrc}/Source/sync.profile
	# Patch to enable video
	sed -i ${wrksrc}/Tools/qmake/mkspecs/features/features.pri \
		-e"s;\(ENABLE_VIDEO\)=0;\1=1;" \
		-e"s;\(ENABLE_WEB_AUDIO\)=0;\1=1;"
	# Patch for QtWebProcess LFLAGS
	sed -i ${wrksrc}/Source/WebKit2/WebProcess.pro \
		-e"/TARGET = QtWebProcess/i QMAKE_LFLAGS = $LDFLAGS"
	qmake PREFIX=/usr LIB=/usr/lib QMAKE_LFLAGS_USE_GOLD= ${wrksrc}
}
do_build() {
	cd build
	make ${makejobs} CC=$CC CXX=$CXX LINK=$CXX LD=$CXX \
		AR="$AR cru" RANLIB=$RANLIB
}
do_install() {
	cd build
	make PREFIX=/usr INSTALL_ROOT=${DESTDIR} install
	# QMAKE_PRL_BUILD_DIR contains a reference to the build dir; drop it
	find ${DESTDIR}/usr/lib -type f -name '*.prl' -exec \
		sed -i "{}" -e "/^QMAKE_PRL_BUILD_DIR/d" \;
}

qt5-webkit-devel_package() {
	short_desc+=" (development)"
	depends="${sourcepkg}>=${version}_${revision}"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/*.so
		vmove usr/lib/*.prl
		vmove usr/lib/pkgconfig
	}
}
