SUMMARY="Classes for QML and JavaScript languages"
DESCRIPTION="Qt is a cross-platform application framework that is widely \
used for developing software with a graphical user interface, and also used \
for developing non-GUI programs such as command-line tools and consoles for \
servers."
HOMEPAGE="https://qt.io/"
COPYRIGHT="2015-2021 The Qt Company Ltd."
LICENSE="GNU LGPL v2.1
	GNU LGPL v3
	GNU FDL v1"
REVISION="1"
SOURCE_URI="https://download.qt.io/official_releases/qt/${portVersion%.*}/$portVersion/submodules/qtdeclarative-everywhere-src-$portVersion.tar.xz"
CHECKSUM_SHA256="1a04ef0092b31354e0fded0d8391865719cb58f9ca5dc604da2b1f62c742cf28"
SOURCE_DIR="qtdeclarative-everywhere-src-$portVersion"
PATCHES="qt6_declarative-$portVersion.patchset"

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

PROVIDES="
	qt6_declarative$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6LabsAnimation$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6LabsFolderListModel$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6LabsQmlModels$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6LabsSettings$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6LabsSharedImage$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6LabsWavefrontMesh$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6Qml$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QmlCore$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QmlLocalStorage$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QmlModels$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QmlWorkerScript$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QmlXmlListModel$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6Quick$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QuickControls2$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QuickControls2Impl$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QuickDialogs2$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QuickDialogs2QuickImpl$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QuickDialogs2Utils$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QuickLayouts$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QuickParticles$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QuickShapes$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QuickTemplates2$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QuickTest$secondaryArchSuffix = $portVersion compat >= 6
	lib:libQt6QuickWidgets$secondaryArchSuffix = $portVersion compat >= 6
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libQt6Core$secondaryArchSuffix
	lib:libQt6Gui$secondaryArchSuffix
	lib:libQt6Network$secondaryArchSuffix
	lib:libQt6OpenGL$secondaryArchSuffix
	lib:libQt6Widgets$secondaryArchSuffix
	lib:libQt6Test$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	"

PROVIDES_devel="
	qt6_declarative${secondaryArchSuffix}_devel = $portVersion compat >= 6
	devel:libQt6LabsAnimation$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6LabsFolderListModel$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6LabsQmlModels$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6LabsSettings$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6LabsSharedImage$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6LabsWavefrontMesh$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6PacketProtocol$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6Qml$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QmlCompiler$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QmlCore$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QmlDebug$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QmlDevTools$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QmlDom$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QmlLocalStorage$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QmlModels$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QmlWorkerScript$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QmlXmlListModel$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6Quick$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QuickControlsTestUtils$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QuickControls2$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QuickControls2Impl$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QuickDialogs2$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QuickDialogs2QuickImpl$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QuickDialogs2Utils$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QuickLayouts$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QuickParticles$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QuickShapes$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QuickTemplates2$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QuickTest$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QuickTestUtils$secondaryArchSuffix = $portVersion compat >= 6
	devel:libQt6QuickWidgets$secondaryArchSuffix = $portVersion compat >= 6
	"
REQUIRES_devel="
	qt6_declarative$secondaryArchSuffix == $portVersion base
	qt6_base${secondaryArchSuffix}_devel
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcrypto$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libQt6Core$secondaryArchSuffix
	devel:libQt6Gui$secondaryArchSuffix
	devel:libQt6Network$secondaryArchSuffix
	devel:libQt6OpenGL$secondaryArchSuffix
	devel:libQt6ShaderTools$secondaryArchSuffix
	devel:libQt6Widgets$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:cmake
	cmd:find
	cmd:g++$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:ninja
	cmd:perl
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3.7
	cmd:sed
	cmd:xargs
	"

BUILD()
{
	export DISABLE_ASLR=1

	cmake -B build -S $sourceDir -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_CXX_FLAGS=-fPIC

	find -name cmake_install.cmake -exec sed -i "s|set(CMAKE_INSTALL_PREFIX.*|set(CMAKE_INSTALL_PREFIX \"$prefix\")|" {} \;

	ninja -C build $jobArgs
}

INSTALL()
{
	ninja -C build install

	prepareInstalledDevelLibs libQt6LabsAnimation libQt6LabsFolderListModel \
		libQt6LabsQmlModels libQt6LabsSettings libQt6LabsSharedImage \
		libQt6LabsWavefrontMesh libQt6Qml libQt6QmlCore libQt6QmlLocalStorage \
		libQt6QmlModels libQt6QmlWorkerScript libQt6QmlXmlListModel libQt6Quick \
		libQt6QuickControls2 libQt6QuickControls2Impl libQt6QuickControlsTestUtils \
		libQt6QuickDialogs2 libQt6QuickDialogs2QuickImpl libQt6QuickDialogs2Utils \
		libQt6QuickLayouts libQt6QuickParticles libQt6QuickShapes libQt6QuickTemplates2 \
		libQt6QuickTestUtils libQt6QuickTest libQt6QuickWidgets libQt6PacketProtocol \
		libQt6QmlCompiler libQt6QmlDebug libQt6QmlDevTools libQt6QmlDom

	# fix static lib paths
	sed -i 's,${_IMPORT_PREFIX}/lib',$developDir/lib, \
		$libDir/cmake/Qt6QmlDevToolsPrivate/Qt6QmlDevToolsPrivateTargets-release.cmake
	sed -i 's,${_IMPORT_PREFIX}/lib',$developDir/lib, \
		$libDir/cmake/Qt6QmlDomPrivate/Qt6QmlDomPrivateTargets-release.cmake
	sed -i 's,${_IMPORT_PREFIX}/lib',$developDir/lib, \
		$libDir/cmake/Qt6QmlDebugPrivate/Qt6QmlDebugPrivateTargets-release.cmake
	sed -i 's,${_IMPORT_PREFIX}/lib',$developDir/lib, \
		$libDir/cmake/Qt6QmlCompilerPrivate/Qt6QmlCompilerPrivateTargets-release.cmake
	sed -i 's,${_IMPORT_PREFIX}/lib',$developDir/lib, \
		$libDir/cmake/Qt6PacketProtocolPrivate/Qt6PacketProtocolPrivateTargets-release.cmake

	cd $libDir
	for i in lib*.so.6.*;do
		ln -fs $i $(echo $i | cut -f1,2 -d.)
	done

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