# Template file for 'qt6-tools'
pkgname=qt6-tools
version=6.8.2
revision=1
build_style=cmake
configure_args="-DEXTERNAL_GUMBO=ON -DLITEHTML_UTF8=ON -DUSE_ICU=ON
 -DQT_BUILD_SHARED_LIBS=ON -DQT_FEATURE_assistant=ON
 -DQT_FEATURE_pixeltool=ON -DLITEHTML_BUILD_TESTING=OFF
 -DQT_FEATURE_distancefieldgenerator=ON"
hostmakedepends="qt6-base perl qt6-plugin-sqlite clang17 clang-tools-extra17
 qt6-declarative-host-tools"
makedepends="qt6-base-private-devel qt6-plugin-sqlite qt6-declarative-private-devel
 gumbo-parser-devel icu-devel llvm17-devel"
short_desc="Cross-platform application and UI framework (QT6) - qt6-tools component"
maintainer="John <me@johnnynator.dev>"
license="custom:GPL-3.0-only-with-Qt-GPL-exception-1.0, LGPL-3.0-only, GPL-2.0-or-later"
homepage="https://qt.io/"
distfiles="http://download.qt.io/official_releases/qt/${version%.*}/${version}/submodules/qttools-everywhere-src-${version}.tar.xz"
checksum=326381b7d43f07913612f291abc298ae79bd95382e2233abce982cff2b53d2c0

if [ "$CROSS_BUILD" ]; then
	configure_args+=" -DQT_FORCE_BUILD_TOOLS=TRUE"
	hostmakedepends+=" qt6-tools"
fi
case "$XBPS_TARGET_MACHINE" in
	x86_64*|aarch64*)
		makedepends+=" libomp-devel" ;;
esac

if [ "$XBPS_CHECK_PKGS" ]; then
	configure_args+=" -DQT_BUILD_TESTS=ON"
fi

subpackages="qt6-designer qt6-help qt6-ui-tools qt6-tools-private-devel qt6-tools-devel"

post_patch() {
	vsed -i -e 's/gumbo/litehtml/' src/assistant/qlitehtml/src/CMakeLists.txt
}

post_install() {
	vlicense LICENSES/Qt-GPL-exception-1.0.txt
}

#post_build() {
#	ninja -C build ${makejobs} lib/qt6/libexec/qhelpgenerator
#}

do_check() {
	cd build
	export QT_BUILD_BIN_PATH=$wrksrc/build/lib/qt6/bin
	# Some of these tests expect that qt6-tools is already
	# installed in /usr/lib/qt6
	ctest -E 'tst_(lrelease|lconvert|lupdate|qtattributionsscanner|qhelpcontentmodel|qhelpenginecore|qhelpgenerator|qhelpindexmode|generatedOutput|validateQdocOutputFiles)'
}

qt6-help_package() {
	short_desc+=" - Help libraries"
	pkg_install() {
		vmove "usr/lib/libQt6Help.so.*"
	}
}

qt6-designer_package() {
	short_desc+=" - Designer libraries"
	pkg_install() {
		vmove "usr/lib/libQt6Designer*.so.*"
	}
}

qt6-ui-tools_package() {
	short_desc+=" - UI Tools libraries"
	pkg_install() {
		vmove "usr/lib/libQt6UiTools.so.*"
	}
}

qt6-tools-private-devel_package() {
	depends="qt6-tools-devel>=${version}_${revision}"
	short_desc+=" - private development files"
	pkg_install() {
		for dir in $(cd ${DESTDIR} && find usr/include -type d -name private); do
			vmove "$dir"
		done
		vmove "usr/lib/cmake/*Private"
		vmove "usr/lib/qt6/metatypes/*private_*_metatypes.json"
		vmove "usr/lib/qt6/mkspecs/modules/*_private.pri"
		vmove "usr/lib/qt6/modules/*Private.json"
	}
}

qt6-tools-devel_package() {
	depends="${sourcepkg}>=${version}_${revision} qt6-base-devel>=${version}_1"
	short_desc+=" - development files"
	pkg_install() {
		local _f
		vmove usr/include
		vmove usr/lib/qt6/metatypes
		vmove usr/lib/pkgconfig
		vmove usr/lib/qt6/mkspecs
		vmove "usr/lib/*.so"
		vmove "usr/lib/*.prl"
		vmove usr/lib/qt6/modules
		for _f in ${DESTDIR}/usr/lib/cmake/*; do
			case "$_f" in
			*ToolsTools|*/Qt6LinguistTools) ;;
			*)	vmove "usr/lib/cmake/${_f##*/}" ;;
			esac
		done
	}
}
