# Template file for 'qt6-base'
#
# On update rebuild all pkg with qt6-base-private-devel
pkgname=qt6-base
version=6.8.2
revision=1
build_style=cmake
configure_args="-DINSTALL_DATADIR=share/qt6
 -DINSTALL_ARCHDATADIR=lib${XBPS_TARGET_WORDSIZE}/qt6
 -DINSTALL_BINDIR=lib${XBPS_TARGET_WORDSIZE}/qt6/bin
 -DINSTALL_MKSPECSDIR=lib${XBPS_TARGET_WORDSIZE}/qt6/mkspecs
 -DINSTALL_INCLUDEDIR=include/qt6
 -DINSTALL_EXAMPLESDIR=lib${XBPS_TARGET_WORDSIZE}/qt6/examples
 -DINSTALL_TESTSDIR=lib${XBPS_TARGET_WORDSIZE}/qt6/tests
 -DINSTALL_SYSCONFDIR=/etc/xdg
 -DQT_FEATURE_openssl_linked=ON
 -DQT_FEATURE_system_sqlite=ON
 -DQT_FEATURE_system_xcb_xinput=ON
 -DQT_FEATURE_libproxy=ON
 -DQT_FEATURE_qmake=ON
 -DBUILD_WITH_PCH=OFF"
hostmakedepends="perl pkg-config xmlstarlet"
makedepends="zlib-devel libzstd-devel dbus-devel libmd4c-devel
 double-conversion-devel glib-devel libxcb-devel libSM-devel
 xcb-util-image-devel xcb-util-keysyms-devel
 xcb-util-renderutil-devel xcb-util-wm-devel
 MesaLib-devel pcre2-devel icu-devel mtdev-devel harfbuzz-devel
 libpng-devel tslib-devel libinput-devel gtk+3-devel
 libmariadbclient-devel postgresql-libs-devel
 unixodbc-devel cups-devel libproxy-devel brotli-devel
 sqlite-devel mit-krb5-devel vulkan-loader-devel libb2-devel
 xcb-util-cursor-devel"
short_desc="Cross-platform application and UI framework (QT6)"
maintainer="John <me@johnnynator.dev>"
license="GPL-3.0-only WITH Qt-GPL-exception-1.0, LGPL-3.0-only, GPL-2.0-or-later"
homepage="https://www.qt.io"
distfiles="https://download.qt.io/official_releases/qt/${version%.*}/${version}/submodules/qtbase-everywhere-src-${version}.tar.xz"
checksum=012043ce6d411e6e8a91fdc4e05e6bedcfa10fcb1347d3c33908f7fdd10dfe05
python_version=3

if [ "$CROSS_BUILD" ]; then
	hostmakedepends+=" qt6-base"
	# QtSetup fails native builds if this is set
	configure_args+=" -DQT_FORCE_BUILD_TOOLS=true"
fi

# It is currently expected that quite a few patches do fail
if [ "$XBPS_CHECK_PKGS" ]; then
	configure_args+=" -DQT_BUILD_TESTS=ON"
fi

subpackages="qt6-concurrent qt6-core qt6-dbus qt6-gui qt6-network
 qt6-opengl-widgets qt6-plugin-mysql qt6-plugin-networkinformation
 qt6-plugin-odbc qt6-plugin-pgsql qt6-plugin-sqlite qt6-plugin-tls-openssl
 qt6-plugin-tls-qcertonly qt6-printsupport qt6-sql qt6-test qt6-widgets qt6-xml
 qt6-base-private-devel qt6-base-doc qt6-base-devel"

do_check() {
	cd build
	export QT_QPA_PLATFORM=offscreen
	export QMAKESPEC=$wrksrc/mkspecs/linux-g++
	local failing_tests="tst_selftests tst_qmake tst_moc
		tst_rcc tst_qfile tst_qstandardpaths
		tst_qtemporarydir tst_qtemporaryfile tst_qdir
		tst_qpluginloader tst_qlibrary tst_qtextstream
		test_build_simple_widget_app_qmake
		test_interface test_interface_link_libraries
		tst_qfont tst_qfontdatabase
		tst_qfontmetrics tst_qglyphrun tst_qrawfont
		tst_qtextdocumentlayout	tst_qopenglconfig
		tst_qopengl tst_qfiledialog
		tst_qgraphicsview tst_qapplication tst_qfontcombobox
		tst_qlineedit tst_qmenubar tst_qopenglwidget
		tst_qx11info tst_qcomplextext
		tst_qaddpreroutine tst_qtextcursor
		test_widgets_app_deployment tst_qnetworkinterface
		tst_qgraphicsproxywidget tst_qdnslookup"
	# Unknown platform linux-g++ :/
	failing_tests+=" mockplugins test_import_plugins
	 test_static_resources test_generating_cpp_exports"
	failing_tests+=" tst_qstorageinfo"
	# cmake
	failing_tests+=" test_qt_add_resources_rebuild test_collecting_plugins
	 test_standalone_test test_qt_extract_metatypes"
	# Failing readonly and out-of-memory
	failing_tests+=" tst_qsharedmemory"
	if [ "$XBPS_TARGET_LIBC" = musl ]; then
		# Some glibc specific DNS Lookup
		failing_tests+=" tst_qdnslookup"
	fi
	if [ "$XBPS_TARGET_WORDSIZE" = 32 ]; then
		# failing on i686, not checked on arm
		failing_tests+=" tst_qvectorrnd tst_json tst_qvectornd tst_qdoublevalidator"
	fi
	local ctest_exclude="("
	for failure in $failing_tests; do
		ctest_exclude+="$failure|"
	done
	ctest_exclude="${ctest_exclude%|})"
	if [ ! -e "$wrksrc/build/include/qt6" ]; then
		ln -s .. "$wrksrc/build/include/qt6"
	fi
	ctest -E "$ctest_exclude"
	rm "$wrksrc/build/include/qt6"
}

post_install() {
	rm -rf ${DESTDIR}/usr/tests
	cat <<-EOF >${DESTDIR}/usr/lib/qt6/bin/target_qt.conf
	[Paths]
	Prefix=../../../
	HostPrefix=/usr
	Binaries=lib${XBPS_TARGET_WORDSIZE}/qt6/bin
	HostBinaries=lib/qt6/bin
	Libraries=lib${XBPS_TARGET_WORDSIZE}
	HostLibraries=lib
	LibraryExecutables=lib${XBPS_TARGET_WORDSIZE}/qt6/libexec
	HostLibraryExecutables=lib/qt6/libexec
	ArchData=lib${XBPS_TARGET_WORDSIZE}/qt6
	HostArchData=lib/qt6
	Data=share/qt6
	HostData=share/qt6
	Sysroot=
	SysrootifyPrefix=false
	TargetSpec=linux-g++
	HostSpec=linux-g++
	EOF
}

qt6-gui_package() {
	short_desc+=" - Gui"
	pkg_install() {
		vmove "usr/lib/libQt6Gui.so.*"
		vmove "usr/lib/libQt6XcbQpa.so.*"
		vmove "usr/lib/libQt6EglFSDeviceIntegration.so.*"
		vmove "usr/lib/libQt6EglFsKmsGbmSupport.so.*"
		vmove "usr/lib/libQt6EglFsKmsSupport.so.*"
		vmove "usr/lib/libQt6OpenGL.so.*"
		vmove usr/lib/qt6/plugins/generic
		vmove usr/lib/qt6/plugins/platforms
		vmove usr/lib/qt6/plugins/xcbglintegrations
		vmove usr/lib/qt6/plugins/imageformats
		vmove usr/lib/qt6/plugins/egldeviceintegrations
		vmove usr/lib/qt6/plugins/platforminputcontexts
		vmove usr/lib/qt6/plugins/platformthemes
	}
}

qt6-opengl-widgets_package() {
	short_desc+=" - OpenGL Widgets"
	pkg_install() {
		vmove "usr/lib/libQt6OpenGLWidgets.so.*"
	}
}

qt6-dbus_package() {
	short_desc+=" - DBus"
	pkg_install() {
		vmove "usr/lib/libQt6DBus.so.*"
	}
}

qt6-core_package() {
	short_desc+=" - Core"
	pkg_install() {
		vmove "usr/lib/libQt6Core.so.*"
	}
}

qt6-printsupport_package() {
	short_desc+=" - Print Support"
	pkg_install() {
		vmove "usr/lib/libQt6PrintSupport.so.*"
		vmove usr/lib/qt6/plugins/printsupport
	}
}

qt6-concurrent_package() {
	short_desc+=" - Concurrency"
	pkg_install() {
		vmove "usr/lib/libQt6Concurrent.so.*"
	}
}

qt6-widgets_package() {
	short_desc+=" - Widgets"
	pkg_install() {
		vmove "usr/lib/libQt6Widgets.so.*"
	}
}

qt6-network_package() {
	short_desc+=" - Network"
	pkg_install() {
		vmove "usr/lib/libQt6Network.so.*"
	}
}

qt6-sql_package() {
	short_desc+=" - Sql"
	pkg_install() {
		vmove "usr/lib/libQt6Sql.so.*"
	}
}

qt6-test_package() {
	short_desc+=" - Test"
	pkg_install() {
		vmove "usr/lib/libQt6Test.so*"
	}
}

qt6-xml_package() {
	short_desc+=" - Xml"
	pkg_install() {
		vmove "usr/lib/libQt6Xml.so.*"
	}
}

qt6-base-doc_package() {
	short_desc+=" - Documentation"
	pkg_install() {
		vmove usr/share/qt6/doc
	}
}


qt6-plugin-odbc_package() {
	short_desc+=" - ODBC plugin"
	pkg_install() {
		vmove usr/lib/qt6/plugins/sqldrivers/libqsqlodbc.so
	}
}

qt6-plugin-pgsql_package() {
	short_desc+=" - PostgreSQL plugin"
	pkg_install() {
		vmove usr/lib/qt6/plugins/sqldrivers/libqsqlpsql.so
	}
}

qt6-plugin-mysql_package() {
	short_desc+=" - MySQL plugin"
	pkg_install() {
		vmove usr/lib/qt6/plugins/sqldrivers/libqsqlmysql.so
	}
}

qt6-plugin-sqlite_package() {
	short_desc+=" - SQLite plugin"
	pkg_install() {
		vmove usr/lib/qt6/plugins/sqldrivers/libqsqlite.so
	}
}

qt6-plugin-tls-openssl_package() {
	short_desc+=" - TLS plugin"
	pkg_install() {
		vmove usr/lib/qt6/plugins/tls/libqopensslbackend.so
	}
}

qt6-plugin-tls-qcertonly_package() {
	short_desc+=" - TLS plugin"
	pkg_install() {
		vmove usr/lib/qt6/plugins/tls/libqcertonlybackend.so
	}
}

qt6-plugin-networkinformation_package() {
	short_desc+=" - NetworkInformation plugin"
	pkg_install() {
		vmove usr/lib/qt6/plugins/networkinformation
	}
}

qt6-base-private-devel_package() {
	short_desc+=" - private development files"
	depends="qt6-base-devel>=${version}_${revision}"
	pkg_install() {
		for dir in $(cd ${DESTDIR} && pwd >&2 && find usr/include -type d -name private); do
			vmove "$dir"
		done
		vmove "usr/lib/cmake/*Private"
		vmove "usr/lib/qt6/metatypes/*private_*_metatypes.json"
		# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=921930
		# vmove "usr/lib/qt6/mkspecs/modules/*_private.pri"
		vmove "usr/lib/qt6/modules/*Private.json"
	}
}

qt6-base-devel_package() {
	short_desc+=" - Development files"
	depends="qt6-base>=${version}_${revision}
	 qt6-gui>=${version}_${revision}
	 qt6-core>=${version}_${revision}
	 qt6-widgets>=${version}_${revision}
	 qt6-opengl-widgets>=${version}_${revision}
	 qt6-printsupport>=${version}_${revision}
	 qt6-concurrent>=${version}_${revision}
	 qt6-sql>=${version}_${revision}
	 qt6-test>=${version}_${revision}
	 qt6-network>=${version}_${revision}
	 qt6-xml>=${version}_${revision}
	 qt6-plugin-odbc>=${version}_${revision}
	 qt6-plugin-pgsql>=${version}_${revision}
	 qt6-plugin-mysql>=${version}_${revision}
	 qt6-plugin-sqlite>=${version}_${revision}
	 qt6-plugin-tls-openssl>=${version}_${revision}
	 qt6-plugin-tls-qcertonly>=${version}_${revision}
	 qt6-plugin-networkinformation>=${version}_${revision}
	 ${makedepends}"
	pkg_install() {
		local _f
		vmove usr/include
		vmove usr/lib/pkgconfig
		vmove usr/lib/qt6/metatypes
		vmove usr/lib/qt6/mkspecs/modules
		vmove "usr/lib/*.a"
		vmove "usr/lib/*.so"
		vmove "usr/lib/*.prl"
		vmove usr/lib/qt6/modules
		for _f in ${DESTDIR}/usr/lib/cmake/*; do
			case "$_f" in
			*Tools|*HostInfo|*/Qt6) ;;
			*)	vmove "usr/lib/cmake/${_f##*/}" ;;
			esac
		done
	}
}
