# Template file for 'qt5-webview'
pkgname=qt5-webview
version=5.15.1
revision=1
wrksrc="qtwebview-everywhere-src-${version}"
build_style=qmake
hostmakedepends="qt5-qmake perl qt5-declarative-devel"
makedepends="qt5-location-devel qt5-webchannel-devel qt5-tools-devel qt5-declarative-devel
 $(vopt_if webengine qt5-webengine-devel)"
short_desc="Cross-platform application and UI framework (QT5) - WebEngine component"
maintainer="John <me@johnnynator.dev>"
license="GPL-3.0-or-later, LGPL-3.0-or-later"
homepage="https://qt.io/"
distfiles="http://download.qt.io/official_releases/qt/${version%.*}/${version}/submodules/qtwebview-everywhere-src-${version}.tar.xz"
checksum=426852a3f569da82aa84dfd7f06c6aeb06488a927b66342a612401b41392b260

build_options="webengine"
if [ "$XBPS_TARGET_ENDIAN" = "le" ] && [ "$XBPS_WORDSIZE" = "$XBPS_TARGET_WORDSIZE" ]; then
	build_options_default="webengine"
fi

_cleanup_wrksrc_leak() {
	if [ -d "${PKGDESTDIR}/usr/lib/cmake" ]; then
		# Replace references to ${wrksrc} in cmake files
		sed -i ${PKGDESTDIR}/usr/lib/cmake/*/*.cmake \
			-e "s;${wrksrc}/host;/usr/lib/qt5;g" \
			-e "s;devices/void-${XBPS_CROSS_TRIPLET}-g++;linux-g++;g"
	fi
	if [ -d "${PKGDESTDIR}/usr/lib/pkgconfig" ]; then
		# Replace references to ${wrksrc} in pkgconfig files
		sed -i ${PKGDESTDIR}/usr/lib/pkgconfig/*.pc \
			-e "s;${wrksrc}/host;/usr/lib/qt5;g" \
			-e "s;devices/void-${XBPS_CROSS_TRIPLET}-g++;linux-g++;g"
	fi
	# Remove QMAKE_PRL_BUILD_DIR from hint files for static libraries
	# and replace references to ${wrksrc}
	find ${PKGDESTDIR} -iname "*.prl" -exec sed -i "{}" \
		-e "/^QMAKE_PRL_BUILD_DIR/d" \
		-e "s;-L${wrksrc}/qtbase/lib;-L/usr/lib;g" \;
	# Replace ${wrksrc} in project include files
	find ${PKGDESTDIR} -iname "*.pri" -exec sed -i "{}" \
		-e "s;${wrksrc}/qtbase;/usr/lib/qt5;g" \;
}

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