1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
7 # @BLURB: Support eclass for packages that follow KDE packaging conventions.
9 # This eclass is intended to streamline the creation of ebuilds for packages
10 # that follow KDE upstream packaging conventions. It's primarily intended for
11 # the three upstream release groups (Frameworks, Plasma, Applications) but
12 # is also for any package that follows similar conventions.
14 # This eclass unconditionally inherits kde5-functions.eclass and all its public
15 # functions and variables may be considered as part of this eclass's API.
17 # This eclass unconditionally inherits cmake-utils.eclass and all its public
18 # variables and helper functions (not phase functions) may be considered as part
19 # of this eclass's API.
21 # This eclass's phase functions are not intended to be mixed and matched, so if
22 # any phase functions are overridden the version here should also be called.
24 if [[ -z ${_KDE5_ECLASS} ]]; then
27 # @ECLASS-VARIABLE: VIRTUALX_REQUIRED
29 # For proper description see virtualx.eclass manpage.
30 # Here we redefine default value to be manual, if your package needs virtualx
31 # for tests you should proceed with setting VIRTUALX_REQUIRED=test.
32 : ${VIRTUALX_REQUIRED:=manual}
34 inherit cmake-utils flag-o-matic kde5-functions virtualx xdg
37 6) inherit eapi7-ver eutils gnome2-utils ;;
40 if [[ ${KDE_BUILD_TYPE} = live ]]; then
44 if [[ -v KDE_GCC_MINIMAL ]]; then
45 EXPORT_FUNCTIONS pkg_pretend
48 EXPORT_FUNCTIONS pkg_setup pkg_nofetch src_unpack src_prepare src_configure src_compile src_test src_install pkg_preinst pkg_postinst pkg_postrm
50 # @ECLASS-VARIABLE: ECM_KDEINSTALLDIRS
52 # If set to "false", do nothing.
53 # For any other value, assume the package is using KDEInstallDirs macro and switch
54 # KDE_INSTALL_USE_QT_SYS_PATHS to ON.
55 : ${ECM_KDEINSTALLDIRS:=true}
57 # @ECLASS-VARIABLE: KDE_AUTODEPS
59 # If set to "false", do nothing.
60 # For any other value, add dependencies on dev-qt/qtcore:5, kde-frameworks/kf-env
61 # and kde-frameworks/extra-cmake-modules:5. Additionally, required blockers may
62 # be set depending on the value of CATEGORY.
63 : ${KDE_AUTODEPS:=true}
65 # @ECLASS-VARIABLE: KDE_BLOCK_SLOT4
67 # This variable only has any effect when when CATEGORY = "kde-apps" and
68 # KDE_AUTODEPS is also set. If set to "true", add RDEPEND block on kde-apps/${PN}:4
69 : ${KDE_BLOCK_SLOT4:=true}
71 # @ECLASS-VARIABLE: KDE_DEBUG
73 # If set to "false", add -DNDEBUG (via cmake-utils_src_configure) and -DQT_NO_DEBUG
75 # Otherwise, add debug to IUSE.
78 # @ECLASS-VARIABLE: KDE_DESIGNERPLUGIN
80 # If set to "false", do nothing.
81 # Otherwise, add "designer" to IUSE to toggle build of designer plugins
82 # and add the necessary DEPENDs.
83 : ${KDE_DESIGNERPLUGIN:=false}
85 # @ECLASS-VARIABLE: KDE_EXAMPLES
87 # If set to "false", unconditionally ignore a top-level examples subdirectory.
88 # Otherwise, add "examples" to IUSE to toggle adding that subdirectory.
89 : ${KDE_EXAMPLES:=false}
91 # @ECLASS-VARIABLE: KDE_HANDBOOK
93 # If set to "false", do nothing.
94 # Otherwise, add "+handbook" to IUSE, add the appropriate dependency, and
95 # generate and install KDE handbook.
96 # If set to "optional", config with -DCMAKE_DISABLE_FIND_PACKAGE_KF5DocTools=ON
97 # when USE=!handbook. In case package requires KF5KDELibs4Support, see next:
98 # If set to "forceoptional", remove a KF5DocTools dependency from the root
99 # CMakeLists.txt in addition to the above.
100 : ${KDE_HANDBOOK:=false}
102 # @ECLASS-VARIABLE: KDE_DOC_DIR
104 # Specifies the location of the KDE handbook if not the default.
105 : ${KDE_DOC_DIR:=doc}
107 # @ECLASS-VARIABLE: KDE_PO_DIRS
109 # Specifies the possible locations of KDE l10n files if not the default.
110 : ${KDE_PO_DIRS:="po poqm"}
112 # @ECLASS-VARIABLE: KDE_QTHELP
114 # If set to "false", do nothing.
115 # Otherwise, add "doc" to IUSE, add the appropriate dependency, generate
116 # and install Qt compressed help files with -DBUILD_QCH=ON when USE=doc.
117 if [[ ${CATEGORY} = kde-frameworks ]]; then
118 : ${KDE_QTHELP:=true}
120 : ${KDE_QTHELP:=false}
122 # @ECLASS-VARIABLE: KDE_TEST
124 # If set to "false", do nothing.
125 # For any other value, add test to IUSE and add a dependency on dev-qt/qttest:5.
126 # If set to "optional", configure with -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Test=ON
128 # If set to "forceoptional", remove a Qt5Test dependency and comment test
129 # subdirs from the root CMakeLists.txt in addition to the above.
130 # If set to "forceoptional-recursive", remove Qt5Test dependencies and make
131 # autotest(s), unittest(s) and test(s) subdirs from *any* CMakeLists.txt in ${S}
132 # and below conditional on BUILD_TESTING. This is always meant as a short-term
133 # fix and creates ${T}/${P}-tests-optional.patch to refine and submit upstream.
134 if [[ ${CATEGORY} = kde-frameworks ]]; then
139 # @ECLASS-VARIABLE: KDE_SELINUX_MODULE
141 # If set to "none", do nothing.
142 # For any other value, add selinux to IUSE, and depending on that useflag
143 # add a dependency on sec-policy/selinux-${KDE_SELINUX_MODULE} to (R)DEPEND.
144 : ${KDE_SELINUX_MODULE:=none}
146 # @ECLASS-VARIABLE: KDE_SUBSLOT
148 # If set to "false", do nothing.
149 # If set to "true", add a subslot to the package, where subslot is either
150 # defined as major.minor version for kde-*/ categories or ${PV} if other.
151 # For any other value, that value will be used as subslot.
152 : ${KDE_SUBSLOT:=false}
154 # @ECLASS-VARIABLE: KDE_UNRELEASED
157 # An array of $CATEGORY-$PV pairs of packages that are unreleased upstream.
158 # Any package matching this will have fetch restriction enabled, and receive
159 # a proper error message via pkg_nofetch.
162 HOMEPAGE="https://kde.org/"
167 if [[ ${CATEGORY} = kde-frameworks ]]; then
171 case ${KDE_SUBSLOT} in
178 SLOT+="/$(ver_cut 1-2)"
186 SLOT+="/${KDE_SUBSLOT}"
190 case ${KDE_AUTODEPS} in
193 BDEPEND+=" $(add_frameworks_dep extra-cmake-modules)"
194 RDEPEND+=" >=kde-frameworks/kf-env-4"
195 COMMONDEPEND+=" $(add_qt_dep qtcore)"
197 # all packages need breeze/oxygen icons for basic iconset, bug #564838
198 if [[ ${PN} != breeze-icons && ${PN} != oxygen-icons ]]; then
199 RDEPEND+=" || ( $(add_frameworks_dep breeze-icons) kde-frameworks/oxygen-icons:* )"
211 case ${KDE_DESIGNERPLUGIN} in
215 BDEPEND+=" designer? ( $(add_frameworks_dep kdesignerplugin) )"
218 case ${KDE_EXAMPLES} in
225 case ${KDE_HANDBOOK} in
229 BDEPEND+=" handbook? ( $(add_frameworks_dep kdoctools) )"
233 case ${KDE_QTHELP} in
237 COMMONDEPEND+=" doc? ( $(add_qt_dep qt-docs) )"
240 >=app-doc/doxygen-1.8.13-r1
249 DEPEND+=" test? ( $(add_qt_dep qttest) )"
253 case ${KDE_SELINUX_MODULE} in
257 RDEPEND+=" selinux? ( sec-policy/selinux-${KDE_SELINUX_MODULE} )"
262 6) DEPEND+=" ${BDEPEND}" ;;
265 DEPEND+=" ${COMMONDEPEND}"
266 RDEPEND+=" ${COMMONDEPEND}"
269 if [[ -n ${KMNAME} && ${KMNAME} != ${PN} && ${KDE_BUILD_TYPE} = release ]]; then
270 S=${WORKDIR}/${KMNAME}-${PV}
273 _kde_is_unreleased() {
275 for pair in "${KDE_UNRELEASED[@]}" ; do
276 if [[ "${pair}" = "${CATEGORY}-${PV}" ]]; then
284 # Determine fetch location for released tarballs
285 _calculate_src_uri() {
286 debug-print-function ${FUNCNAME} "$@"
290 if [[ -n ${KMNAME} ]]; then
303 _kmname="portingAids/${_kmname}"
310 ??.?.[6-9]? | ??.??.[6-9]? )
311 SRC_URI="mirror://kde/unstable/applications/${PV}/src/${_kmname}-${PV}.tar.xz"
315 SRC_URI="mirror://kde/stable/applications/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
319 SRC_URI="mirror://kde/stable/frameworks/${PV%.*}/${_kmname}-${PV}.tar.xz" ;;
321 local plasmapv=$(ver_cut 1-3)
324 5.?.[6-9]? | 5.??.[6-9]? )
325 # Plasma 5 beta releases
326 SRC_URI="mirror://kde/unstable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz"
330 # Plasma 5 stable releases
331 SRC_URI="mirror://kde/stable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz" ;;
336 if [[ ${PN} = kdevelop* ]]; then
339 SRC_URI="mirror://kde/unstable/kdevelop/${PV}/src/${_kmname}-${PV}.tar.xz"
343 SRC_URI="mirror://kde/stable/kdevelop/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
347 if _kde_is_unreleased ; then
352 # Determine fetch location for live sources
353 _calculate_live_repo() {
354 debug-print-function ${FUNCNAME} "$@"
358 # @ECLASS-VARIABLE: EGIT_MIRROR
360 # This variable allows easy overriding of default kde mirror service
361 # (anongit) with anything else you might want to use.
362 EGIT_MIRROR=${EGIT_MIRROR:=https://anongit.kde.org}
366 # @ECLASS-VARIABLE: EGIT_REPONAME
368 # This variable allows overriding of default repository
369 # name. Specify only if this differ from PN and KMNAME.
370 if [[ -n ${EGIT_REPONAME} ]]; then
371 # the repository and kmname different
372 _kmname=${EGIT_REPONAME}
373 elif [[ -n ${KMNAME} ]]; then
379 if [[ ${PV} == ??.??.49.9999 && ${CATEGORY} = kde-apps ]]; then
380 EGIT_BRANCH="Applications/$(ver_cut 1-2)"
383 if [[ ${PV} != 9999 && ${CATEGORY} = kde-plasma ]]; then
384 EGIT_BRANCH="Plasma/$(ver_cut 1-2)"
387 if [[ ${PV} != 9999 && ${PN} = kdevelop* ]]; then
388 EGIT_BRANCH="$(ver_cut 1-2)"
391 EGIT_REPO_URI="${EGIT_MIRROR}/${_kmname}"
394 case ${KDE_BUILD_TYPE} in
395 live) _calculate_live_repo ;;
396 *) _calculate_src_uri ;;
399 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: SRC_URI is ${SRC_URI}"
401 # @FUNCTION: kde5_pkg_pretend
403 # Checks if the active compiler meets the minimum version requirements.
404 # phase function is only exported if KDE_GCC_MINIMAL is defined.
406 debug-print-function ${FUNCNAME} "$@"
410 # @FUNCTION: kde5_pkg_setup
412 # Checks if the active compiler meets the minimum version requirements.
414 debug-print-function ${FUNCNAME} "$@"
418 # @FUNCTION: kde5_pkg_nofetch
420 # Intended for use in the KDE overlay. If this package matches something in
421 # KDE_UNRELEASED, display a giant warning that the package has not yet been
422 # released upstream and should not be used.
424 if ! _kde_is_unreleased ; then
428 eerror " _ _ _ _ ____ _____ _ _____ _ ____ _____ ____ "
429 eerror "| | | | \ | | _ \| ____| | | ____| / \ / ___|| ____| _ \ "
430 eerror "| | | | \| | |_) | _| | | | _| / _ \ \___ \| _| | | | |"
431 eerror "| |_| | |\ | _ <| |___| |___| |___ / ___ \ ___) | |___| |_| |"
432 eerror " \___/|_| \_|_| \_\_____|_____|_____/_/ \_\____/|_____|____/ "
434 eerror " ____ _ ____ _ __ _ ____ _____ "
435 eerror "| _ \ / \ / ___| |/ / / \ / ___| ____|"
436 eerror "| |_) / _ \| | | ' / / _ \| | _| _| "
437 eerror "| __/ ___ \ |___| . \ / ___ \ |_| | |___ "
438 eerror "|_| /_/ \_\____|_|\_\/_/ \_\____|_____|"
440 eerror "${CATEGORY}/${P} has not been released to the public yet"
441 eerror "and is only available to packagers right now."
443 eerror "This is not a bug. Please do not file bugs or contact upstream about this."
445 eerror "Please consult the upstream release schedule to see when this "
446 eerror "package is scheduled to be released:"
447 eerror "https://community.kde.org/Schedules"
450 # @FUNCTION: kde5_src_unpack
452 # Unpack the sources, automatically handling both release and live ebuilds.
454 debug-print-function ${FUNCNAME} "$@"
456 if [[ ${KDE_BUILD_TYPE} = live ]]; then
463 # @FUNCTION: kde5_src_prepare
465 # Wrapper for cmake-utils_src_prepare with lots of extra logic for magic
466 # handling of linguas, tests, handbook etc.
468 debug-print-function ${FUNCNAME} "$@"
470 cmake-utils_src_prepare
472 # only build examples when required
473 if ! { in_iuse examples && use examples; } ; then
474 cmake_comment_add_subdirectory examples
477 # only enable handbook when required
478 if in_iuse handbook && ! use handbook ; then
479 cmake_comment_add_subdirectory ${KDE_DOC_DIR}
481 if [[ ${KDE_HANDBOOK} = forceoptional ]] ; then
482 punt_bogus_dep KF5 DocTools
483 sed -i -e "/kdoctools_install/ s/^/#DONT/" CMakeLists.txt || die
487 # drop translations when nls is not wanted
488 if in_iuse nls && ! use nls ; then
490 for po in ${KDE_PO_DIRS}; do
491 if [[ -d ${po} ]] ; then
497 # enable only the requested translations when required
498 # always install unconditionally for kconfigwidgets - if you use language
499 # X as system language, and there is a combobox with language names, the
500 # translated language name for language Y is taken from /usr/share/locale/Y/kf5_entry.desktop
501 if [[ -v LINGUAS && ${PN} != kconfigwidgets ]] ; then
503 for po in ${KDE_PO_DIRS}; do
504 if [[ -d ${po} ]] ; then
505 pushd ${po} > /dev/null || die
508 if [[ -e ${lang} ]] && ! has ${lang/.po/} ${LINGUAS} ; then
513 *) rm -r ${lang} || die ;;
515 if [[ -e CMakeLists.txt ]] ; then
516 cmake_comment_add_subdirectory ${lang}
517 sed -e "/add_subdirectory([[:space:]]*${lang}\/.*[[:space:]]*)/d" \
518 -i CMakeLists.txt || die
522 popd > /dev/null || die
527 if [[ ${KDE_BUILD_TYPE} = release && ${CATEGORY} != kde-apps ]] ; then
528 if [[ ${KDE_HANDBOOK} != false && -d ${KDE_DOC_DIR} && -v LINGUAS ]] ; then
529 pushd ${KDE_DOC_DIR} > /dev/null || die
532 if ! has ${lang} ${LINGUAS} ; then
533 cmake_comment_add_subdirectory ${lang}
536 popd > /dev/null || die
540 # only build unit tests when required
541 if ! { in_iuse test && use test; } ; then
542 if [[ ${KDE_TEST} = forceoptional ]] ; then
543 punt_bogus_dep Qt5 Test
544 # if forceoptional, also cover non-kde categories
545 cmake_comment_add_subdirectory autotests test tests
546 elif [[ ${KDE_TEST} = forceoptional-recursive ]] ; then
547 punt_bogus_dep Qt5 Test
548 local f pf="${T}/${P}"-tests-optional.patch
549 touch ${pf} || die "Failed to touch patch file"
550 for f in $(find . -type f -name "CMakeLists.txt" -exec \
551 grep -l "^\s*add_subdirectory\s*\(\s*.*\(auto|unit\)\?tests\?\s*)\s*\)" {} \;); do
552 cp ${f} ${f}.old || die "Failed to prepare patch origfile"
553 pushd ${f%/*} > /dev/null || die
554 punt_bogus_dep Qt5 Test
555 sed -i CMakeLists.txt -e \
556 "/^#/! s/add_subdirectory\s*\(\s*.*\(auto|unit\)\?tests\?\s*)\s*\)/if(BUILD_TESTING)\n&\nendif()/" \
558 popd > /dev/null || die
559 diff -Naur ${f}.old ${f} 1>>${pf}
560 rm ${f}.old || die "Failed to clean up"
562 einfo "Build system was modified by KDE_TEST=forceoptional-recursive."
563 einfo "Unified diff file ready for pickup in:"
565 einfo "Push it upstream to make this message go away."
566 elif [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma || ${CATEGORY} = kde-apps ]] ; then
567 cmake_comment_add_subdirectory autotests test tests
571 # in frameworks, tests = manual tests so never build them
572 if [[ ${CATEGORY} = kde-frameworks ]] && [[ ${PN} != extra-cmake-modules ]]; then
573 cmake_comment_add_subdirectory tests
577 # @FUNCTION: kde5_src_configure
579 # Wrapper for cmake-utils_src_configure with extra logic for magic handling of
580 # handbook, tests etc.
581 kde5_src_configure() {
582 debug-print-function ${FUNCNAME} "$@"
584 # we rely on cmake-utils.eclass to append -DNDEBUG too
585 if in_iuse debug && ! use debug; then
586 append-cppflags -DQT_NO_DEBUG
591 if in_iuse test && ! use test ; then
592 cmakeargs+=( -DBUILD_TESTING=OFF )
594 if [[ ${KDE_TEST} = optional ]] ; then
595 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Test=ON )
599 if in_iuse handbook && ! use handbook && [[ ${KDE_HANDBOOK} = optional ]] ; then
600 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_KF5DocTools=ON )
603 if in_iuse designer && ! use designer && [[ ${KDE_DESIGNERPLUGIN} != false ]] ; then
604 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_KF5DesignerPlugin=ON )
607 if [[ ${KDE_QTHELP} != false ]]; then
608 cmakeargs+=( -DBUILD_QCH=$(usex doc) )
611 if [[ ${ECM_KDEINSTALLDIRS} != false ]] ; then
613 # install mkspecs in the same directory as qt stuff
614 -DKDE_INSTALL_USE_QT_SYS_PATHS=ON
616 # move handbook outside of doc dir for at least two QA warnings, bug 667138
617 [[ ${EAPI} != 6 ]] && cmakeargs+=( -DKDE_INSTALL_DOCBUNDLEDIR="${EPREFIX}/usr/share/help" )
620 # allow the ebuild to override what we set here
621 mycmakeargs=("${cmakeargs[@]}" "${mycmakeargs[@]}")
623 cmake-utils_src_configure
626 # @FUNCTION: kde5_src_compile
628 # Wrapper for cmake-utils_src_compile. Currently doesn't do anything extra, but
629 # is included as part of the API just in case it's needed in the future.
631 debug-print-function ${FUNCNAME} "$@"
633 cmake-utils_src_compile "$@"
636 # @FUNCTION: kde5_src_test
638 # Wrapper for cmake-utils_src_test with extra logic for magic handling of dbus
641 debug-print-function ${FUNCNAME} "$@"
644 if [[ -n "${VIRTUALDBUS_TEST}" ]]; then
645 export $(dbus-launch)
651 # When run as normal user during ebuild development with the ebuild command, the
652 # kde tests tend to access the session DBUS. This however is not possible in a real
653 # emerge or on the tinderbox.
654 # > make sure it does not happen, so bad tests can be recognized and disabled
655 unset DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
657 if [[ ${VIRTUALX_REQUIRED} = always || ${VIRTUALX_REQUIRED} = test ]]; then
663 if [[ -n "${DBUS_SESSION_BUS_PID}" ]] ; then
664 kill ${DBUS_SESSION_BUS_PID}
668 # @FUNCTION: kde5_src_install
670 # Wrapper for cmake-utils_src_install with extra logic to avoid compressing
671 # certain types of files. For example, khelpcenter is not able to read
672 # compressed handbooks.
674 debug-print-function ${FUNCNAME} "$@"
676 cmake-utils_src_install
678 # We don't want QCH and tags files to be compressed, because then
679 # cmake can't find the tags and qthelp viewers can't find the docs
680 local p=$(best_version dev-qt/qtcore:5)
681 local pv=$(echo ${p/%-r[0-9]*/} | rev | cut -d - -f 1 | rev)
682 if [[ ${pv} = 5.11* ]]; then
683 #todo: clean up trailing slash check when EAPI <7 is removed
684 if [[ -d ${ED%/}/usr/share/doc/qt-${pv} ]]; then
685 docompress -x /usr/share/doc/qt-${pv}
689 if [[ ${EAPI} = 6 ]]; then
690 # We don't want /usr/share/doc/HTML to be compressed,
691 # because then khelpcenter can't find the docs
692 #todo: clean up trailing slash check when EAPI <7 is removed
693 if [[ -d ${ED%/}/usr/share/doc/HTML ]]; then
694 docompress -x /usr/share/doc/HTML
699 # @FUNCTION: kde5_pkg_preinst
701 # Sets up environment variables required in kde5_pkg_postinst.
703 debug-print-function ${FUNCNAME} "$@"
708 # @FUNCTION: kde5_pkg_postinst
710 # Updates the various XDG caches (icon, desktop, mime) if necessary.
711 kde5_pkg_postinst() {
712 debug-print-function ${FUNCNAME} "$@"
716 if [[ -z ${I_KNOW_WHAT_I_AM_DOING} ]]; then
717 if [[ ${KDE_BUILD_TYPE} = live ]]; then
719 einfo "WARNING! This is an experimental live ebuild of ${CATEGORY}/${PN}"
720 einfo "Use it at your own risk."
721 einfo "Do _NOT_ file bugs at bugs.gentoo.org because of this ebuild!"
726 # @FUNCTION: kde5_pkg_postrm
728 # Updates the various XDG caches (icon, desktop, mime) if necessary.
730 debug-print-function ${FUNCNAME} "$@"