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 eutils flag-o-matic gnome2-utils kde5-functions versionator virtualx xdg
36 if [[ ${KDE_BUILD_TYPE} = live ]]; then
38 git) inherit git-r3 ;;
42 if [[ -v KDE_GCC_MINIMAL ]]; then
43 EXPORT_FUNCTIONS pkg_pretend
46 EXPORT_FUNCTIONS pkg_setup pkg_nofetch src_unpack src_prepare src_configure src_compile src_test src_install pkg_preinst pkg_postinst pkg_postrm
48 # @ECLASS-VARIABLE: KDE_AUTODEPS
50 # If set to "false", do nothing.
51 # For any other value, add dependencies on dev-qt/qtcore:5, kde-frameworks/kf-env
52 # and kde-frameworks/extra-cmake-modules:5. Additionally, required blockers may
53 # be set depending on the value of CATEGORY.
54 : ${KDE_AUTODEPS:=true}
56 # @ECLASS-VARIABLE: KDE_BLOCK_SLOT4
58 # This variable only has any effect when when CATEGORY = "kde-apps" and
59 # KDE_AUTODEPS is also set. If set to "true", add RDEPEND block on kde-apps/${PN}:4
60 : ${KDE_BLOCK_SLOT4:=true}
62 # @ECLASS-VARIABLE: KDE_DEBUG
64 # If set to "false", add -DNDEBUG (via cmake-utils_src_configure) and -DQT_NO_DEBUG
66 # Otherwise, add debug to IUSE.
69 # @ECLASS-VARIABLE: KDE_DESIGNERPLUGIN
71 # If set to "false", do nothing.
72 # Otherwise, add "designer" to IUSE to toggle build of designer plugins
73 # and add the necessary DEPENDs.
74 : ${KDE_DESIGNERPLUGIN:=false}
76 # @ECLASS-VARIABLE: KDE_EXAMPLES
78 # If set to "false", unconditionally ignore a top-level examples subdirectory.
79 # Otherwise, add "examples" to IUSE to toggle adding that subdirectory.
80 : ${KDE_EXAMPLES:=false}
82 # @ECLASS-VARIABLE: KDE_HANDBOOK
84 # If set to "false", do nothing.
85 # Otherwise, add "+handbook" to IUSE, add the appropriate dependency, and
86 # generate and install KDE handbook.
87 # If set to "optional", config with -DCMAKE_DISABLE_FIND_PACKAGE_KF5DocTools=ON
88 # when USE=!handbook. In case package requires KF5KDELibs4Support, see next:
89 # If set to "forceoptional", remove a KF5DocTools dependency from the root
90 # CMakeLists.txt in addition to the above.
91 : ${KDE_HANDBOOK:=false}
93 # @ECLASS-VARIABLE: KDE_DOC_DIR
95 # Specifies the location of the KDE handbook if not the default.
98 # @ECLASS-VARIABLE: KDE_PO_DIRS
100 # Specifies the possible locations of KDE l10n files if not the default.
101 : ${KDE_PO_DIRS:="po poqm"}
103 # @ECLASS-VARIABLE: KDE_QTHELP
105 # If set to "false", do nothing.
106 # Otherwise, add "doc" to IUSE, add the appropriate dependency, generate
107 # and install Qt compressed help files with -DBUILD_QCH=ON when USE=doc.
108 if [[ ${CATEGORY} = kde-frameworks ]]; then
109 : ${KDE_QTHELP:=true}
111 : ${KDE_QTHELP:=false}
113 # @ECLASS-VARIABLE: KDE_TESTPATTERN
115 # DANGER: Only touch it if you know what you are doing.
116 # By default, matches autotest(s), unittest(s) and test(s) pattern inside
117 # cmake add_subdirectory calls.
118 : ${KDE_TESTPATTERN:="\(auto|unit\)\?tests\?"}
120 # @ECLASS-VARIABLE: KDE_TEST
122 # If set to "false", do nothing.
123 # For any other value, add test to IUSE and add a dependency on dev-qt/qttest:5.
124 # If set to "optional", configure with -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Test=ON
126 # If set to "forceoptional", remove a Qt5Test dependency and comment test
127 # subdirs from the root CMakeLists.txt in addition to the above.
128 # If set to "forceoptional-recursive", remove Qt5Test dependencies and make
129 # test subdirs according to KDE_TESTPATTERN from *any* CMakeLists.txt in ${S}
130 # and below conditional on BUILD_TESTING. This is always meant as a short-term
131 # fix and creates ${T}/${P}-tests-optional.patch to refine and submit upstream.
132 if [[ ${CATEGORY} = kde-frameworks ]]; then
137 # @ECLASS-VARIABLE: KDE_SELINUX_MODULE
139 # If set to "none", do nothing.
140 # For any other value, add selinux to IUSE, and depending on that useflag
141 # add a dependency on sec-policy/selinux-${KDE_SELINUX_MODULE} to (R)DEPEND.
142 : ${KDE_SELINUX_MODULE:=none}
144 # @ECLASS-VARIABLE: KDE_SUBSLOT
146 # If set to "false", do nothing.
147 # If set to "true", add a subslot to the package, where subslot is either
148 # defined as major.minor version for kde-*/ categories or ${PV} if other.
149 # For any other value, that value will be used as subslot.
150 : ${KDE_SUBSLOT:=false}
152 # @ECLASS-VARIABLE: KDE_UNRELEASED
155 # An array of $CATEGORY-$PV pairs of packages that are unreleased upstream.
156 # Any package matching this will have fetch restriction enabled, and receive
157 # a proper error message via pkg_nofetch.
160 if [[ ${KDEBASE} = kdevelop ]]; then
161 HOMEPAGE="https://www.kdevelop.org/"
162 elif [[ ${KMNAME} = kdepim ]]; then
163 HOMEPAGE="https://www.kde.org/applications/office/kontact/"
165 HOMEPAGE="https://www.kde.org/"
172 if [[ ${CATEGORY} = kde-frameworks ]]; then
176 case ${KDE_SUBSLOT} in
183 SLOT+="/$(get_version_component_range 1-2)"
191 SLOT+="/${KDE_SUBSLOT}"
195 case ${KDE_AUTODEPS} in
198 DEPEND+=" $(add_frameworks_dep extra-cmake-modules)"
199 RDEPEND+=" >=kde-frameworks/kf-env-4"
200 COMMONDEPEND+=" $(add_qt_dep qtcore)"
202 # all packages need breeze/oxygen icons for basic iconset, bug #564838
203 if [[ ${PN} != breeze-icons && ${PN} != oxygen-icons ]]; then
204 RDEPEND+=" || ( $(add_frameworks_dep breeze-icons) kde-frameworks/oxygen-icons:* )"
207 if [[ ${CATEGORY} = kde-apps ]]; then
208 [[ ${KDE_BLOCK_SLOT4} = true ]] && RDEPEND+=" !kde-apps/${PN}:4"
211 !<kde-apps/kde4-l10n-16.12.0:4
212 !kde-apps/kdepim-l10n:5
225 case ${KDE_DESIGNERPLUGIN} in
229 DEPEND+=" designer? ( $(add_frameworks_dep kdesignerplugin) )"
232 case ${KDE_EXAMPLES} in
239 case ${KDE_HANDBOOK} in
243 DEPEND+=" handbook? ( $(add_frameworks_dep kdoctools) )"
247 case ${KDE_QTHELP} in
251 COMMONDEPEND+=" doc? ( $(add_qt_dep qt-docs) )"
254 >=app-doc/doxygen-1.8.13-r1
263 DEPEND+=" test? ( $(add_qt_dep qttest) )"
267 case ${KDE_SELINUX_MODULE} in
271 RDEPEND+=" selinux? ( sec-policy/selinux-${KDE_SELINUX_MODULE} )"
275 DEPEND+=" ${COMMONDEPEND} dev-util/desktop-file-utils"
276 RDEPEND+=" ${COMMONDEPEND}"
279 if [[ -n ${KMNAME} && ${KMNAME} != ${PN} && ${KDE_BUILD_TYPE} = release ]]; then
280 S=${WORKDIR}/${KMNAME}-${PV}
283 if [[ -n ${KDEBASE} && ${KDEBASE} = kdevelop && ${KDE_BUILD_TYPE} = release ]]; then
284 if [[ -n ${KMNAME} ]]; then
285 S=${WORKDIR}/${KMNAME}-${PV}
291 _kde_is_unreleased() {
293 for pair in "${KDE_UNRELEASED[@]}" ; do
294 if [[ "${pair}" = "${CATEGORY}-${PV}" ]]; then
302 # Determine fetch location for released tarballs
303 _calculate_src_uri() {
304 debug-print-function ${FUNCNAME} "$@"
308 if [[ -n ${KMNAME} ]]; then
321 _kmname="portingAids/${_kmname}"
325 DEPEND+=" app-arch/xz-utils"
330 ??.?.[6-9]? | ??.??.[6-9]? )
331 SRC_URI="mirror://kde/unstable/applications/${PV}/src/${_kmname}-${PV}.tar.xz"
335 SRC_URI="mirror://kde/stable/applications/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
339 SRC_URI="mirror://kde/stable/frameworks/${PV%.*}/${_kmname}-${PV}.tar.xz" ;;
341 local plasmapv=$(get_version_component_range 1-3)
344 5.?.[6-9]? | 5.??.[6-9]? )
345 # Plasma 5 beta releases
346 SRC_URI="mirror://kde/unstable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz"
350 # Plasma 5 stable releases
351 SRC_URI="mirror://kde/stable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz" ;;
356 if [[ -z ${SRC_URI} && -n ${KDEBASE} ]] ; then
362 _kdebase=${KDEBASE} ;;
366 SRC_URI="mirror://kde/unstable/${_kdebase}/${PV}/src/${_kmname}-${PV}.tar.xz"
370 SRC_URI="mirror://kde/stable/${_kdebase}/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
375 if _kde_is_unreleased ; then
380 # Determine fetch location for live sources
381 _calculate_live_repo() {
382 debug-print-function ${FUNCNAME} "$@"
388 # @ECLASS-VARIABLE: EGIT_MIRROR
390 # This variable allows easy overriding of default kde mirror service
391 # (anongit) with anything else you might want to use.
392 EGIT_MIRROR=${EGIT_MIRROR:=https://anongit.kde.org}
396 # @ECLASS-VARIABLE: EGIT_REPONAME
398 # This variable allows overriding of default repository
399 # name. Specify only if this differ from PN and KMNAME.
400 if [[ -n ${EGIT_REPONAME} ]]; then
401 # the repository and kmname different
402 _kmname=${EGIT_REPONAME}
403 elif [[ -n ${KMNAME} ]]; then
409 if [[ ${PV} == ??.??.49.9999 && ${CATEGORY} = kde-apps ]]; then
410 EGIT_BRANCH="Applications/$(get_version_component_range 1-2)"
413 if [[ ${PV} != 9999 && ${CATEGORY} = kde-plasma ]]; then
414 EGIT_BRANCH="Plasma/$(get_version_component_range 1-2)"
417 EGIT_REPO_URI="${EGIT_MIRROR}/${_kmname}"
422 case ${KDE_BUILD_TYPE} in
423 live) _calculate_live_repo ;;
424 *) _calculate_src_uri ;;
427 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: SRC_URI is ${SRC_URI}"
429 # @FUNCTION: kde5_pkg_pretend
431 # Checks if the active compiler meets the minimum version requirements.
432 # phase function is only exported if KDE_GCC_MINIMAL is defined.
434 debug-print-function ${FUNCNAME} "$@"
438 # @FUNCTION: kde5_pkg_setup
440 # Checks if the active compiler meets the minimum version requirements.
442 debug-print-function ${FUNCNAME} "$@"
446 # @FUNCTION: kde5_pkg_nofetch
448 # Intended for use in the KDE overlay. If this package matches something in
449 # KDE_UNRELEASED, display a giant warning that the package has not yet been
450 # released upstream and should not be used.
452 if ! _kde_is_unreleased ; then
456 eerror " _ _ _ _ ____ _____ _ _____ _ ____ _____ ____ "
457 eerror "| | | | \ | | _ \| ____| | | ____| / \ / ___|| ____| _ \ "
458 eerror "| | | | \| | |_) | _| | | | _| / _ \ \___ \| _| | | | |"
459 eerror "| |_| | |\ | _ <| |___| |___| |___ / ___ \ ___) | |___| |_| |"
460 eerror " \___/|_| \_|_| \_\_____|_____|_____/_/ \_\____/|_____|____/ "
462 eerror " ____ _ ____ _ __ _ ____ _____ "
463 eerror "| _ \ / \ / ___| |/ / / \ / ___| ____|"
464 eerror "| |_) / _ \| | | ' / / _ \| | _| _| "
465 eerror "| __/ ___ \ |___| . \ / ___ \ |_| | |___ "
466 eerror "|_| /_/ \_\____|_|\_\/_/ \_\____|_____|"
468 eerror "${CATEGORY}/${P} has not been released to the public yet"
469 eerror "and is only available to packagers right now."
471 eerror "This is not a bug. Please do not file bugs or contact upstream about this."
473 eerror "Please consult the upstream release schedule to see when this "
474 eerror "package is scheduled to be released:"
475 eerror "https://community.kde.org/Schedules"
478 # @FUNCTION: kde5_src_unpack
480 # Unpack the sources, automatically handling both release and live ebuilds.
482 debug-print-function ${FUNCNAME} "$@"
484 if [[ ${KDE_BUILD_TYPE} = live ]]; then
495 # @FUNCTION: kde5_src_prepare
497 # Wrapper for cmake-utils_src_prepare with lots of extra logic for magic
498 # handling of linguas, tests, handbook etc.
500 debug-print-function ${FUNCNAME} "$@"
502 cmake-utils_src_prepare
504 # only build examples when required
505 if ! use_if_iuse examples || ! use examples ; then
506 cmake_comment_add_subdirectory examples
509 # only enable handbook when required
510 if ! use_if_iuse handbook ; then
511 cmake_comment_add_subdirectory ${KDE_DOC_DIR}
513 if [[ ${KDE_HANDBOOK} = forceoptional ]] ; then
514 punt_bogus_dep KF5 DocTools
515 sed -i -e "/kdoctools_install/ s/^/#DONT/" CMakeLists.txt || die
519 # drop translations when nls is not wanted
520 if in_iuse nls && ! use nls ; then
522 for po in ${KDE_PO_DIRS}; do
523 if [[ -d ${po} ]] ; then
529 # enable only the requested translations when required
530 if [[ -v LINGUAS ]] ; then
532 for po in ${KDE_PO_DIRS}; do
533 if [[ -d ${po} ]] ; then
534 pushd ${po} > /dev/null || die
537 if [[ -e ${lang} ]] && ! has ${lang/.po/} ${LINGUAS} ; then
542 *) rm -r ${lang} || die ;;
544 if [[ -e CMakeLists.txt ]] ; then
545 cmake_comment_add_subdirectory ${lang}
546 sed -e "/add_subdirectory([[:space:]]*${lang}\/.*[[:space:]]*)/d" \
547 -i CMakeLists.txt || die
551 popd > /dev/null || die
556 if [[ ${KDE_BUILD_TYPE} = release && ${CATEGORY} != kde-apps ]] ; then
557 if [[ ${KDE_HANDBOOK} != false && -d ${KDE_DOC_DIR} && -v LINGUAS ]] ; then
558 pushd ${KDE_DOC_DIR} > /dev/null || die
561 if ! has ${lang} ${LINGUAS} ; then
562 cmake_comment_add_subdirectory ${lang}
565 popd > /dev/null || die
569 # only build unit tests when required
570 if ! use_if_iuse test ; then
571 if [[ ${KDE_TEST} = forceoptional ]] ; then
572 punt_bogus_dep Qt5 Test
573 # if forceoptional, also cover non-kde categories
574 cmake_comment_add_subdirectory autotests test tests
575 elif [[ ${KDE_TEST} = forceoptional-recursive ]] ; then
576 punt_bogus_dep Qt5 Test
577 local f pf="${T}/${P}"-tests-optional.patch
578 touch ${pf} || die "Failed to touch patch file"
579 for f in $(find . -type f -name "CMakeLists.txt" -exec \
580 grep -l "^\s*add_subdirectory\s*\(\s*.*${KDE_TESTPATTERN}\s*)\s*\)" {} \;); do
581 cp ${f} ${f}.old || die "Failed to prepare patch origfile"
582 pushd ${f%/*} > /dev/null || die
583 punt_bogus_dep Qt5 Test
584 sed -i CMakeLists.txt -e \
585 "/^#/! s/add_subdirectory\s*\(\s*.*${KDE_TESTPATTERN}\s*)\s*\)/if(BUILD_TESTING)\n&\nendif()/" \
587 popd > /dev/null || die
588 diff -Naur ${f}.old ${f} 1>>${pf}
589 rm ${f}.old || die "Failed to clean up"
591 einfo "Build system was modified by KDE_TEST=forceoptional-recursive."
592 einfo "Unified diff file ready for pickup in:"
594 einfo "Push it upstream to make this message go away."
595 elif [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma || ${CATEGORY} = kde-apps ]] ; then
596 cmake_comment_add_subdirectory autotests test tests
600 # in frameworks, tests = manual tests so never build them
601 if [[ ${CATEGORY} = kde-frameworks ]] && [[ ${PN} != extra-cmake-modules ]]; then
602 cmake_comment_add_subdirectory tests
606 # @FUNCTION: kde5_src_configure
608 # Wrapper for cmake-utils_src_configure with extra logic for magic handling of
609 # handbook, tests etc.
610 kde5_src_configure() {
611 debug-print-function ${FUNCNAME} "$@"
613 # we rely on cmake-utils.eclass to append -DNDEBUG too
614 if ! use_if_iuse debug; then
615 append-cppflags -DQT_NO_DEBUG
620 if in_iuse test && ! use test ; then
621 cmakeargs+=( -DBUILD_TESTING=OFF )
623 if [[ ${KDE_TEST} = optional ]] ; then
624 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Test=ON )
628 if ! use_if_iuse handbook && [[ ${KDE_HANDBOOK} = optional ]] ; then
629 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_KF5DocTools=ON )
632 if ! use_if_iuse designer && [[ ${KDE_DESIGNERPLUGIN} != false ]] ; then
633 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_KF5DesignerPlugin=ON )
636 if [[ ${KDE_QTHELP} != false ]]; then
637 cmakeargs+=( -DBUILD_QCH=$(usex doc) )
640 # install mkspecs in the same directory as qt stuff
641 cmakeargs+=(-DKDE_INSTALL_USE_QT_SYS_PATHS=ON)
643 # allow the ebuild to override what we set here
644 mycmakeargs=("${cmakeargs[@]}" "${mycmakeargs[@]}")
646 cmake-utils_src_configure
649 # @FUNCTION: kde5_src_compile
651 # Wrapper for cmake-utils_src_compile. Currently doesn't do anything extra, but
652 # is included as part of the API just in case it's needed in the future.
654 debug-print-function ${FUNCNAME} "$@"
656 cmake-utils_src_compile "$@"
659 # @FUNCTION: kde5_src_test
661 # Wrapper for cmake-utils_src_test with extra logic for magic handling of dbus
664 debug-print-function ${FUNCNAME} "$@"
667 if [[ -n "${VIRTUALDBUS_TEST}" ]]; then
668 export $(dbus-launch)
674 # When run as normal user during ebuild development with the ebuild command, the
675 # kde tests tend to access the session DBUS. This however is not possible in a real
676 # emerge or on the tinderbox.
677 # > make sure it does not happen, so bad tests can be recognized and disabled
678 unset DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
680 if [[ ${VIRTUALX_REQUIRED} = always || ${VIRTUALX_REQUIRED} = test ]]; then
686 if [[ -n "${DBUS_SESSION_BUS_PID}" ]] ; then
687 kill ${DBUS_SESSION_BUS_PID}
691 # @FUNCTION: kde5_src_install
693 # Wrapper for cmake-utils_src_install with extra logic to avoid compressing
694 # certain types of files. For example, khelpcenter is not able to read
695 # compressed handbooks.
697 debug-print-function ${FUNCNAME} "$@"
699 cmake-utils_src_install
701 # We don't want QCH and tags files to be compressed, because then
702 # cmake can't find the tags and qthelp viewers can't find the docs
703 local p=$(best_version dev-qt/qtcore:5)
704 local pv=$(echo ${p/%-r[0-9]*/} | rev | cut -d - -f 1 | rev)
705 if [[ -d ${ED%/}/usr/share/doc/qt-${pv} ]]; then
706 docompress -x /usr/share/doc/qt-${pv}
709 # We don't want /usr/share/doc/HTML to be compressed,
710 # because then khelpcenter can't find the docs
711 if [[ -d ${ED%/}/usr/share/doc/HTML ]]; then
712 docompress -x /usr/share/doc/HTML
716 # @FUNCTION: kde5_pkg_preinst
718 # Sets up environment variables required in kde5_pkg_postinst.
720 debug-print-function ${FUNCNAME} "$@"
726 # @FUNCTION: kde5_pkg_postinst
728 # Updates the various XDG caches (icon, desktop, mime) if necessary.
729 kde5_pkg_postinst() {
730 debug-print-function ${FUNCNAME} "$@"
732 if [[ -n ${GNOME2_ECLASS_ICONS} ]]; then
733 gnome2_icon_cache_update
737 if [[ -z ${I_KNOW_WHAT_I_AM_DOING} ]]; then
738 if [[ ${KDE_BUILD_TYPE} = live ]]; then
740 einfo "WARNING! This is an experimental live ebuild of ${CATEGORY}/${PN}"
741 einfo "Use it at your own risk."
742 einfo "Do _NOT_ file bugs at bugs.gentoo.org because of this ebuild!"
747 # @FUNCTION: kde5_pkg_postrm
749 # Updates the various XDG caches (icon, desktop, mime) if necessary.
751 debug-print-function ${FUNCNAME} "$@"
753 if [[ -n ${GNOME2_ECLASS_ICONS} ]]; then
754 gnome2_icon_cache_update