1 # Copyright 1999-2018 Gentoo Foundation
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 gnome2-utils kde5-functions virtualx xdg
37 6) inherit eapi7-ver eutils ;;
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_TESTPATTERN
124 # DANGER: Only touch it if you know what you are doing.
125 # By default, matches autotest(s), unittest(s) and test(s) pattern inside
126 # cmake add_subdirectory calls.
127 : ${KDE_TESTPATTERN:="\(auto|unit\)\?tests\?"}
129 # @ECLASS-VARIABLE: KDE_TEST
131 # If set to "false", do nothing.
132 # For any other value, add test to IUSE and add a dependency on dev-qt/qttest:5.
133 # If set to "optional", configure with -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Test=ON
135 # If set to "forceoptional", remove a Qt5Test dependency and comment test
136 # subdirs from the root CMakeLists.txt in addition to the above.
137 # If set to "forceoptional-recursive", remove Qt5Test dependencies and make
138 # test subdirs according to KDE_TESTPATTERN from *any* CMakeLists.txt in ${S}
139 # and below conditional on BUILD_TESTING. This is always meant as a short-term
140 # fix and creates ${T}/${P}-tests-optional.patch to refine and submit upstream.
141 if [[ ${CATEGORY} = kde-frameworks ]]; then
146 # @ECLASS-VARIABLE: KDE_SELINUX_MODULE
148 # If set to "none", do nothing.
149 # For any other value, add selinux to IUSE, and depending on that useflag
150 # add a dependency on sec-policy/selinux-${KDE_SELINUX_MODULE} to (R)DEPEND.
151 : ${KDE_SELINUX_MODULE:=none}
153 # @ECLASS-VARIABLE: KDE_SUBSLOT
155 # If set to "false", do nothing.
156 # If set to "true", add a subslot to the package, where subslot is either
157 # defined as major.minor version for kde-*/ categories or ${PV} if other.
158 # For any other value, that value will be used as subslot.
159 : ${KDE_SUBSLOT:=false}
161 # @ECLASS-VARIABLE: KDE_UNRELEASED
164 # An array of $CATEGORY-$PV pairs of packages that are unreleased upstream.
165 # Any package matching this will have fetch restriction enabled, and receive
166 # a proper error message via pkg_nofetch.
169 if [[ ${KDEBASE} = kdevelop ]]; then
170 HOMEPAGE="https://www.kdevelop.org/"
171 elif [[ ${KMNAME} = kdepim ]]; then
172 HOMEPAGE="https://www.kde.org/applications/office/kontact/"
174 HOMEPAGE="https://www.kde.org/"
181 if [[ ${CATEGORY} = kde-frameworks ]]; then
185 case ${KDE_SUBSLOT} in
192 SLOT+="/$(ver_cut 1-2)"
200 SLOT+="/${KDE_SUBSLOT}"
204 case ${KDE_AUTODEPS} in
207 DEPEND+=" $(add_frameworks_dep extra-cmake-modules)"
208 RDEPEND+=" >=kde-frameworks/kf-env-4"
209 COMMONDEPEND+=" $(add_qt_dep qtcore)"
211 # all packages need breeze/oxygen icons for basic iconset, bug #564838
212 if [[ ${PN} != breeze-icons && ${PN} != oxygen-icons ]]; then
213 RDEPEND+=" || ( $(add_frameworks_dep breeze-icons) kde-frameworks/oxygen-icons:* )"
216 if [[ ${CATEGORY} = kde-apps ]]; then
217 [[ ${KDE_BLOCK_SLOT4} = true ]] && RDEPEND+=" !kde-apps/${PN}:4"
218 RDEPEND+=" !kde-apps/kde-l10n" # TODO: drop after 18.08.3 removal
230 case ${KDE_DESIGNERPLUGIN} in
234 DEPEND+=" designer? ( $(add_frameworks_dep kdesignerplugin) )"
237 case ${KDE_EXAMPLES} in
244 case ${KDE_HANDBOOK} in
248 DEPEND+=" handbook? ( $(add_frameworks_dep kdoctools) )"
252 case ${KDE_QTHELP} in
256 COMMONDEPEND+=" doc? ( $(add_qt_dep qt-docs) )"
259 >=app-doc/doxygen-1.8.13-r1
268 DEPEND+=" test? ( $(add_qt_dep qttest) )"
272 case ${KDE_SELINUX_MODULE} in
276 RDEPEND+=" selinux? ( sec-policy/selinux-${KDE_SELINUX_MODULE} )"
280 DEPEND+=" ${COMMONDEPEND} dev-util/desktop-file-utils"
281 RDEPEND+=" ${COMMONDEPEND}"
284 if [[ -n ${KMNAME} && ${KMNAME} != ${PN} && ${KDE_BUILD_TYPE} = release ]]; then
285 S=${WORKDIR}/${KMNAME}-${PV}
288 if [[ -n ${KDEBASE} && ${KDEBASE} = kdevelop && ${KDE_BUILD_TYPE} = release ]]; then
289 if [[ -n ${KMNAME} ]]; then
290 S=${WORKDIR}/${KMNAME}-${PV}
296 _kde_is_unreleased() {
298 for pair in "${KDE_UNRELEASED[@]}" ; do
299 if [[ "${pair}" = "${CATEGORY}-${PV}" ]]; then
307 # Determine fetch location for released tarballs
308 _calculate_src_uri() {
309 debug-print-function ${FUNCNAME} "$@"
313 if [[ -n ${KMNAME} ]]; then
326 _kmname="portingAids/${_kmname}"
330 DEPEND+=" app-arch/xz-utils"
335 ??.?.[6-9]? | ??.??.[6-9]? )
336 SRC_URI="mirror://kde/unstable/applications/${PV}/src/${_kmname}-${PV}.tar.xz"
340 SRC_URI="mirror://kde/stable/applications/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
344 SRC_URI="mirror://kde/stable/frameworks/${PV%.*}/${_kmname}-${PV}.tar.xz" ;;
346 local plasmapv=$(ver_cut 1-3)
349 5.?.[6-9]? | 5.??.[6-9]? )
350 # Plasma 5 beta releases
351 SRC_URI="mirror://kde/unstable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz"
355 # Plasma 5 stable releases
356 SRC_URI="mirror://kde/stable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz" ;;
361 if [[ -z ${SRC_URI} && -n ${KDEBASE} ]] ; then
367 _kdebase=${KDEBASE} ;;
371 SRC_URI="mirror://kde/unstable/${_kdebase}/${PV}/src/${_kmname}-${PV}.tar.xz"
375 SRC_URI="mirror://kde/stable/${_kdebase}/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
380 if _kde_is_unreleased ; then
385 # Determine fetch location for live sources
386 _calculate_live_repo() {
387 debug-print-function ${FUNCNAME} "$@"
391 # @ECLASS-VARIABLE: EGIT_MIRROR
393 # This variable allows easy overriding of default kde mirror service
394 # (anongit) with anything else you might want to use.
395 EGIT_MIRROR=${EGIT_MIRROR:=https://anongit.kde.org}
399 # @ECLASS-VARIABLE: EGIT_REPONAME
401 # This variable allows overriding of default repository
402 # name. Specify only if this differ from PN and KMNAME.
403 if [[ -n ${EGIT_REPONAME} ]]; then
404 # the repository and kmname different
405 _kmname=${EGIT_REPONAME}
406 elif [[ -n ${KMNAME} ]]; then
412 if [[ ${PV} == ??.??.49.9999 && ${CATEGORY} = kde-apps ]]; then
413 EGIT_BRANCH="Applications/$(ver_cut 1-2)"
416 if [[ ${PV} != 9999 && ${CATEGORY} = kde-plasma ]]; then
417 EGIT_BRANCH="Plasma/$(ver_cut 1-2)"
420 EGIT_REPO_URI="${EGIT_MIRROR}/${_kmname}"
423 case ${KDE_BUILD_TYPE} in
424 live) _calculate_live_repo ;;
425 *) _calculate_src_uri ;;
428 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: SRC_URI is ${SRC_URI}"
430 # @FUNCTION: kde5_pkg_pretend
432 # Checks if the active compiler meets the minimum version requirements.
433 # phase function is only exported if KDE_GCC_MINIMAL is defined.
435 debug-print-function ${FUNCNAME} "$@"
439 # @FUNCTION: kde5_pkg_setup
441 # Checks if the active compiler meets the minimum version requirements.
443 debug-print-function ${FUNCNAME} "$@"
447 # @FUNCTION: kde5_pkg_nofetch
449 # Intended for use in the KDE overlay. If this package matches something in
450 # KDE_UNRELEASED, display a giant warning that the package has not yet been
451 # released upstream and should not be used.
453 if ! _kde_is_unreleased ; then
457 eerror " _ _ _ _ ____ _____ _ _____ _ ____ _____ ____ "
458 eerror "| | | | \ | | _ \| ____| | | ____| / \ / ___|| ____| _ \ "
459 eerror "| | | | \| | |_) | _| | | | _| / _ \ \___ \| _| | | | |"
460 eerror "| |_| | |\ | _ <| |___| |___| |___ / ___ \ ___) | |___| |_| |"
461 eerror " \___/|_| \_|_| \_\_____|_____|_____/_/ \_\____/|_____|____/ "
463 eerror " ____ _ ____ _ __ _ ____ _____ "
464 eerror "| _ \ / \ / ___| |/ / / \ / ___| ____|"
465 eerror "| |_) / _ \| | | ' / / _ \| | _| _| "
466 eerror "| __/ ___ \ |___| . \ / ___ \ |_| | |___ "
467 eerror "|_| /_/ \_\____|_|\_\/_/ \_\____|_____|"
469 eerror "${CATEGORY}/${P} has not been released to the public yet"
470 eerror "and is only available to packagers right now."
472 eerror "This is not a bug. Please do not file bugs or contact upstream about this."
474 eerror "Please consult the upstream release schedule to see when this "
475 eerror "package is scheduled to be released:"
476 eerror "https://community.kde.org/Schedules"
479 # @FUNCTION: kde5_src_unpack
481 # Unpack the sources, automatically handling both release and live ebuilds.
483 debug-print-function ${FUNCNAME} "$@"
485 if [[ ${KDE_BUILD_TYPE} = live ]]; then
492 # @FUNCTION: kde5_src_prepare
494 # Wrapper for cmake-utils_src_prepare with lots of extra logic for magic
495 # handling of linguas, tests, handbook etc.
497 debug-print-function ${FUNCNAME} "$@"
499 cmake-utils_src_prepare
501 # only build examples when required
502 if ! { in_iuse examples && use examples; } ; then
503 cmake_comment_add_subdirectory examples
506 # only enable handbook when required
507 if in_iuse handbook && ! use handbook ; then
508 cmake_comment_add_subdirectory ${KDE_DOC_DIR}
510 if [[ ${KDE_HANDBOOK} = forceoptional ]] ; then
511 punt_bogus_dep KF5 DocTools
512 sed -i -e "/kdoctools_install/ s/^/#DONT/" CMakeLists.txt || die
516 # drop translations when nls is not wanted
517 if in_iuse nls && ! use nls ; then
519 for po in ${KDE_PO_DIRS}; do
520 if [[ -d ${po} ]] ; then
526 # enable only the requested translations when required
527 if [[ -v LINGUAS ]] ; then
529 for po in ${KDE_PO_DIRS}; do
530 if [[ -d ${po} ]] ; then
531 pushd ${po} > /dev/null || die
534 if [[ -e ${lang} ]] && ! has ${lang/.po/} ${LINGUAS} ; then
539 *) rm -r ${lang} || die ;;
541 if [[ -e CMakeLists.txt ]] ; then
542 cmake_comment_add_subdirectory ${lang}
543 sed -e "/add_subdirectory([[:space:]]*${lang}\/.*[[:space:]]*)/d" \
544 -i CMakeLists.txt || die
548 popd > /dev/null || die
553 if [[ ${KDE_BUILD_TYPE} = release && ${CATEGORY} != kde-apps ]] ; then
554 if [[ ${KDE_HANDBOOK} != false && -d ${KDE_DOC_DIR} && -v LINGUAS ]] ; then
555 pushd ${KDE_DOC_DIR} > /dev/null || die
558 if ! has ${lang} ${LINGUAS} ; then
559 cmake_comment_add_subdirectory ${lang}
562 popd > /dev/null || die
566 # only build unit tests when required
567 if ! { in_iuse test && use test; } ; then
568 if [[ ${KDE_TEST} = forceoptional ]] ; then
569 punt_bogus_dep Qt5 Test
570 # if forceoptional, also cover non-kde categories
571 cmake_comment_add_subdirectory autotests test tests
572 elif [[ ${KDE_TEST} = forceoptional-recursive ]] ; then
573 punt_bogus_dep Qt5 Test
574 local f pf="${T}/${P}"-tests-optional.patch
575 touch ${pf} || die "Failed to touch patch file"
576 for f in $(find . -type f -name "CMakeLists.txt" -exec \
577 grep -l "^\s*add_subdirectory\s*\(\s*.*${KDE_TESTPATTERN}\s*)\s*\)" {} \;); do
578 cp ${f} ${f}.old || die "Failed to prepare patch origfile"
579 pushd ${f%/*} > /dev/null || die
580 punt_bogus_dep Qt5 Test
581 sed -i CMakeLists.txt -e \
582 "/^#/! s/add_subdirectory\s*\(\s*.*${KDE_TESTPATTERN}\s*)\s*\)/if(BUILD_TESTING)\n&\nendif()/" \
584 popd > /dev/null || die
585 diff -Naur ${f}.old ${f} 1>>${pf}
586 rm ${f}.old || die "Failed to clean up"
588 einfo "Build system was modified by KDE_TEST=forceoptional-recursive."
589 einfo "Unified diff file ready for pickup in:"
591 einfo "Push it upstream to make this message go away."
592 elif [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma || ${CATEGORY} = kde-apps ]] ; then
593 cmake_comment_add_subdirectory autotests test tests
597 # in frameworks, tests = manual tests so never build them
598 if [[ ${CATEGORY} = kde-frameworks ]] && [[ ${PN} != extra-cmake-modules ]]; then
599 cmake_comment_add_subdirectory tests
603 # @FUNCTION: kde5_src_configure
605 # Wrapper for cmake-utils_src_configure with extra logic for magic handling of
606 # handbook, tests etc.
607 kde5_src_configure() {
608 debug-print-function ${FUNCNAME} "$@"
610 # we rely on cmake-utils.eclass to append -DNDEBUG too
611 if in_iuse debug && ! use debug; then
612 append-cppflags -DQT_NO_DEBUG
617 if in_iuse test && ! use test ; then
618 cmakeargs+=( -DBUILD_TESTING=OFF )
620 if [[ ${KDE_TEST} = optional ]] ; then
621 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Test=ON )
625 if in_iuse handbook && ! use handbook && [[ ${KDE_HANDBOOK} = optional ]] ; then
626 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_KF5DocTools=ON )
629 if in_iuse designer && ! use designer && [[ ${KDE_DESIGNERPLUGIN} != false ]] ; then
630 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_KF5DesignerPlugin=ON )
633 if [[ ${KDE_QTHELP} != false ]]; then
634 cmakeargs+=( -DBUILD_QCH=$(usex doc) )
637 if [[ ${ECM_KDEINSTALLDIRS} != false ]] ; then
639 # install mkspecs in the same directory as qt stuff
640 -DKDE_INSTALL_USE_QT_SYS_PATHS=ON
644 # allow the ebuild to override what we set here
645 mycmakeargs=("${cmakeargs[@]}" "${mycmakeargs[@]}")
647 cmake-utils_src_configure
650 # @FUNCTION: kde5_src_compile
652 # Wrapper for cmake-utils_src_compile. Currently doesn't do anything extra, but
653 # is included as part of the API just in case it's needed in the future.
655 debug-print-function ${FUNCNAME} "$@"
657 cmake-utils_src_compile "$@"
660 # @FUNCTION: kde5_src_test
662 # Wrapper for cmake-utils_src_test with extra logic for magic handling of dbus
665 debug-print-function ${FUNCNAME} "$@"
668 if [[ -n "${VIRTUALDBUS_TEST}" ]]; then
669 export $(dbus-launch)
675 # When run as normal user during ebuild development with the ebuild command, the
676 # kde tests tend to access the session DBUS. This however is not possible in a real
677 # emerge or on the tinderbox.
678 # > make sure it does not happen, so bad tests can be recognized and disabled
679 unset DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
681 if [[ ${VIRTUALX_REQUIRED} = always || ${VIRTUALX_REQUIRED} = test ]]; then
687 if [[ -n "${DBUS_SESSION_BUS_PID}" ]] ; then
688 kill ${DBUS_SESSION_BUS_PID}
692 # @FUNCTION: kde5_src_install
694 # Wrapper for cmake-utils_src_install with extra logic to avoid compressing
695 # certain types of files. For example, khelpcenter is not able to read
696 # compressed handbooks.
698 debug-print-function ${FUNCNAME} "$@"
700 cmake-utils_src_install
702 # We don't want QCH and tags files to be compressed, because then
703 # cmake can't find the tags and qthelp viewers can't find the docs
704 local p=$(best_version dev-qt/qtcore:5)
705 local pv=$(echo ${p/%-r[0-9]*/} | rev | cut -d - -f 1 | rev)
706 if [[ -d ${ED%/}/usr/share/doc/qt-${pv} ]]; then
707 docompress -x /usr/share/doc/qt-${pv}
710 # We don't want /usr/share/doc/HTML to be compressed,
711 # because then khelpcenter can't find the docs
712 if [[ -d ${ED%/}/usr/share/doc/HTML ]]; then
713 docompress -x /usr/share/doc/HTML
717 # @FUNCTION: kde5_pkg_preinst
719 # Sets up environment variables required in kde5_pkg_postinst.
721 debug-print-function ${FUNCNAME} "$@"
727 # @FUNCTION: kde5_pkg_postinst
729 # Updates the various XDG caches (icon, desktop, mime) if necessary.
730 kde5_pkg_postinst() {
731 debug-print-function ${FUNCNAME} "$@"
733 if [[ -n ${GNOME2_ECLASS_ICONS} ]]; then
734 gnome2_icon_cache_update
738 if [[ -z ${I_KNOW_WHAT_I_AM_DOING} ]]; then
739 if [[ ${KDE_BUILD_TYPE} = live ]]; then
741 einfo "WARNING! This is an experimental live ebuild of ${CATEGORY}/${PN}"
742 einfo "Use it at your own risk."
743 einfo "Do _NOT_ file bugs at bugs.gentoo.org because of this ebuild!"
748 # @FUNCTION: kde5_pkg_postrm
750 # Updates the various XDG caches (icon, desktop, mime) if necessary.
752 debug-print-function ${FUNCNAME} "$@"
754 if [[ -n ${GNOME2_ECLASS_ICONS} ]]; then
755 gnome2_icon_cache_update