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 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_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 if [[ ${KDEBASE} = kdevelop ]]; then
163 HOMEPAGE="https://www.kdevelop.org/"
164 elif [[ ${KMNAME} = kdepim ]]; then
165 HOMEPAGE="https://www.kde.org/applications/office/kontact/"
167 HOMEPAGE="https://www.kde.org/"
174 if [[ ${CATEGORY} = kde-frameworks ]]; then
178 case ${KDE_SUBSLOT} in
185 SLOT+="/$(ver_cut 1-2)"
193 SLOT+="/${KDE_SUBSLOT}"
197 case ${KDE_AUTODEPS} in
200 DEPEND+=" $(add_frameworks_dep extra-cmake-modules)"
201 RDEPEND+=" >=kde-frameworks/kf-env-4"
202 COMMONDEPEND+=" $(add_qt_dep qtcore)"
204 # all packages need breeze/oxygen icons for basic iconset, bug #564838
205 if [[ ${PN} != breeze-icons && ${PN} != oxygen-icons ]]; then
206 RDEPEND+=" || ( $(add_frameworks_dep breeze-icons) kde-frameworks/oxygen-icons:* )"
209 if [[ ${CATEGORY} = kde-apps && ${PV} = 18.08.3 ]]; then
210 [[ ${KDE_BLOCK_SLOT4} = true ]] && RDEPEND+=" !kde-apps/${PN}:4"
211 RDEPEND+=" !kde-apps/kde-l10n"
223 case ${KDE_DESIGNERPLUGIN} in
227 DEPEND+=" designer? ( $(add_frameworks_dep kdesignerplugin) )"
230 case ${KDE_EXAMPLES} in
237 case ${KDE_HANDBOOK} in
241 DEPEND+=" handbook? ( $(add_frameworks_dep kdoctools) )"
245 case ${KDE_QTHELP} in
249 COMMONDEPEND+=" doc? ( $(add_qt_dep qt-docs) )"
252 >=app-doc/doxygen-1.8.13-r1
261 DEPEND+=" test? ( $(add_qt_dep qttest) )"
265 case ${KDE_SELINUX_MODULE} in
269 RDEPEND+=" selinux? ( sec-policy/selinux-${KDE_SELINUX_MODULE} )"
273 DEPEND+=" ${COMMONDEPEND} dev-util/desktop-file-utils"
274 RDEPEND+=" ${COMMONDEPEND}"
277 if [[ -n ${KMNAME} && ${KMNAME} != ${PN} && ${KDE_BUILD_TYPE} = release ]]; then
278 S=${WORKDIR}/${KMNAME}-${PV}
281 if [[ -n ${KDEBASE} && ${KDEBASE} = kdevelop && ${KDE_BUILD_TYPE} = release ]]; then
282 if [[ -n ${KMNAME} ]]; then
283 S=${WORKDIR}/${KMNAME}-${PV}
289 _kde_is_unreleased() {
291 for pair in "${KDE_UNRELEASED[@]}" ; do
292 if [[ "${pair}" = "${CATEGORY}-${PV}" ]]; then
300 # Determine fetch location for released tarballs
301 _calculate_src_uri() {
302 debug-print-function ${FUNCNAME} "$@"
306 if [[ -n ${KMNAME} ]]; then
319 _kmname="portingAids/${_kmname}"
323 DEPEND+=" app-arch/xz-utils"
328 ??.?.[6-9]? | ??.??.[6-9]? )
329 SRC_URI="mirror://kde/unstable/applications/${PV}/src/${_kmname}-${PV}.tar.xz"
333 SRC_URI="mirror://kde/stable/applications/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
337 SRC_URI="mirror://kde/stable/frameworks/${PV%.*}/${_kmname}-${PV}.tar.xz" ;;
339 local plasmapv=$(ver_cut 1-3)
342 5.?.[6-9]? | 5.??.[6-9]? )
343 # Plasma 5 beta releases
344 SRC_URI="mirror://kde/unstable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz"
348 # Plasma 5 stable releases
349 SRC_URI="mirror://kde/stable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz" ;;
354 if [[ -z ${SRC_URI} && -n ${KDEBASE} ]] ; then
360 _kdebase=${KDEBASE} ;;
364 SRC_URI="mirror://kde/unstable/${_kdebase}/${PV}/src/${_kmname}-${PV}.tar.xz"
368 SRC_URI="mirror://kde/stable/${_kdebase}/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
373 if _kde_is_unreleased ; then
378 # Determine fetch location for live sources
379 _calculate_live_repo() {
380 debug-print-function ${FUNCNAME} "$@"
384 # @ECLASS-VARIABLE: EGIT_MIRROR
386 # This variable allows easy overriding of default kde mirror service
387 # (anongit) with anything else you might want to use.
388 EGIT_MIRROR=${EGIT_MIRROR:=https://anongit.kde.org}
392 # @ECLASS-VARIABLE: EGIT_REPONAME
394 # This variable allows overriding of default repository
395 # name. Specify only if this differ from PN and KMNAME.
396 if [[ -n ${EGIT_REPONAME} ]]; then
397 # the repository and kmname different
398 _kmname=${EGIT_REPONAME}
399 elif [[ -n ${KMNAME} ]]; then
405 if [[ ${PV} == ??.??.49.9999 && ${CATEGORY} = kde-apps ]]; then
406 EGIT_BRANCH="Applications/$(ver_cut 1-2)"
409 if [[ ${PV} != 9999 && ${CATEGORY} = kde-plasma ]]; then
410 EGIT_BRANCH="Plasma/$(ver_cut 1-2)"
413 EGIT_REPO_URI="${EGIT_MIRROR}/${_kmname}"
416 case ${KDE_BUILD_TYPE} in
417 live) _calculate_live_repo ;;
418 *) _calculate_src_uri ;;
421 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: SRC_URI is ${SRC_URI}"
423 # @FUNCTION: kde5_pkg_pretend
425 # Checks if the active compiler meets the minimum version requirements.
426 # phase function is only exported if KDE_GCC_MINIMAL is defined.
428 debug-print-function ${FUNCNAME} "$@"
432 # @FUNCTION: kde5_pkg_setup
434 # Checks if the active compiler meets the minimum version requirements.
436 debug-print-function ${FUNCNAME} "$@"
440 # @FUNCTION: kde5_pkg_nofetch
442 # Intended for use in the KDE overlay. If this package matches something in
443 # KDE_UNRELEASED, display a giant warning that the package has not yet been
444 # released upstream and should not be used.
446 if ! _kde_is_unreleased ; then
450 eerror " _ _ _ _ ____ _____ _ _____ _ ____ _____ ____ "
451 eerror "| | | | \ | | _ \| ____| | | ____| / \ / ___|| ____| _ \ "
452 eerror "| | | | \| | |_) | _| | | | _| / _ \ \___ \| _| | | | |"
453 eerror "| |_| | |\ | _ <| |___| |___| |___ / ___ \ ___) | |___| |_| |"
454 eerror " \___/|_| \_|_| \_\_____|_____|_____/_/ \_\____/|_____|____/ "
456 eerror " ____ _ ____ _ __ _ ____ _____ "
457 eerror "| _ \ / \ / ___| |/ / / \ / ___| ____|"
458 eerror "| |_) / _ \| | | ' / / _ \| | _| _| "
459 eerror "| __/ ___ \ |___| . \ / ___ \ |_| | |___ "
460 eerror "|_| /_/ \_\____|_|\_\/_/ \_\____|_____|"
462 eerror "${CATEGORY}/${P} has not been released to the public yet"
463 eerror "and is only available to packagers right now."
465 eerror "This is not a bug. Please do not file bugs or contact upstream about this."
467 eerror "Please consult the upstream release schedule to see when this "
468 eerror "package is scheduled to be released:"
469 eerror "https://community.kde.org/Schedules"
472 # @FUNCTION: kde5_src_unpack
474 # Unpack the sources, automatically handling both release and live ebuilds.
476 debug-print-function ${FUNCNAME} "$@"
478 if [[ ${KDE_BUILD_TYPE} = live ]]; then
485 # @FUNCTION: kde5_src_prepare
487 # Wrapper for cmake-utils_src_prepare with lots of extra logic for magic
488 # handling of linguas, tests, handbook etc.
490 debug-print-function ${FUNCNAME} "$@"
492 cmake-utils_src_prepare
494 # only build examples when required
495 if ! { in_iuse examples && use examples; } ; then
496 cmake_comment_add_subdirectory examples
499 # only enable handbook when required
500 if in_iuse handbook && ! use handbook ; then
501 cmake_comment_add_subdirectory ${KDE_DOC_DIR}
503 if [[ ${KDE_HANDBOOK} = forceoptional ]] ; then
504 punt_bogus_dep KF5 DocTools
505 sed -i -e "/kdoctools_install/ s/^/#DONT/" CMakeLists.txt || die
509 # drop translations when nls is not wanted
510 if in_iuse nls && ! use nls ; then
512 for po in ${KDE_PO_DIRS}; do
513 if [[ -d ${po} ]] ; then
519 # enable only the requested translations when required
520 if [[ -v LINGUAS ]] ; then
522 for po in ${KDE_PO_DIRS}; do
523 if [[ -d ${po} ]] ; then
524 pushd ${po} > /dev/null || die
527 if [[ -e ${lang} ]] && ! has ${lang/.po/} ${LINGUAS} ; then
532 *) rm -r ${lang} || die ;;
534 if [[ -e CMakeLists.txt ]] ; then
535 cmake_comment_add_subdirectory ${lang}
536 sed -e "/add_subdirectory([[:space:]]*${lang}\/.*[[:space:]]*)/d" \
537 -i CMakeLists.txt || die
541 popd > /dev/null || die
546 if [[ ${KDE_BUILD_TYPE} = release && ${CATEGORY} != kde-apps ]] ; then
547 if [[ ${KDE_HANDBOOK} != false && -d ${KDE_DOC_DIR} && -v LINGUAS ]] ; then
548 pushd ${KDE_DOC_DIR} > /dev/null || die
551 if ! has ${lang} ${LINGUAS} ; then
552 cmake_comment_add_subdirectory ${lang}
555 popd > /dev/null || die
559 # only build unit tests when required
560 if ! { in_iuse test && use test; } ; then
561 if [[ ${KDE_TEST} = forceoptional ]] ; then
562 punt_bogus_dep Qt5 Test
563 # if forceoptional, also cover non-kde categories
564 cmake_comment_add_subdirectory autotests test tests
565 elif [[ ${KDE_TEST} = forceoptional-recursive ]] ; then
566 punt_bogus_dep Qt5 Test
567 local f pf="${T}/${P}"-tests-optional.patch
568 touch ${pf} || die "Failed to touch patch file"
569 for f in $(find . -type f -name "CMakeLists.txt" -exec \
570 grep -l "^\s*add_subdirectory\s*\(\s*.*\(auto|unit\)\?tests\?\s*)\s*\)" {} \;); do
571 cp ${f} ${f}.old || die "Failed to prepare patch origfile"
572 pushd ${f%/*} > /dev/null || die
573 punt_bogus_dep Qt5 Test
574 sed -i CMakeLists.txt -e \
575 "/^#/! s/add_subdirectory\s*\(\s*.*\(auto|unit\)\?tests\?\s*)\s*\)/if(BUILD_TESTING)\n&\nendif()/" \
577 popd > /dev/null || die
578 diff -Naur ${f}.old ${f} 1>>${pf}
579 rm ${f}.old || die "Failed to clean up"
581 einfo "Build system was modified by KDE_TEST=forceoptional-recursive."
582 einfo "Unified diff file ready for pickup in:"
584 einfo "Push it upstream to make this message go away."
585 elif [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma || ${CATEGORY} = kde-apps ]] ; then
586 cmake_comment_add_subdirectory autotests test tests
590 # in frameworks, tests = manual tests so never build them
591 if [[ ${CATEGORY} = kde-frameworks ]] && [[ ${PN} != extra-cmake-modules ]]; then
592 cmake_comment_add_subdirectory tests
596 # @FUNCTION: kde5_src_configure
598 # Wrapper for cmake-utils_src_configure with extra logic for magic handling of
599 # handbook, tests etc.
600 kde5_src_configure() {
601 debug-print-function ${FUNCNAME} "$@"
603 # we rely on cmake-utils.eclass to append -DNDEBUG too
604 if in_iuse debug && ! use debug; then
605 append-cppflags -DQT_NO_DEBUG
610 if in_iuse test && ! use test ; then
611 cmakeargs+=( -DBUILD_TESTING=OFF )
613 if [[ ${KDE_TEST} = optional ]] ; then
614 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Test=ON )
618 if in_iuse handbook && ! use handbook && [[ ${KDE_HANDBOOK} = optional ]] ; then
619 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_KF5DocTools=ON )
622 if in_iuse designer && ! use designer && [[ ${KDE_DESIGNERPLUGIN} != false ]] ; then
623 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_KF5DesignerPlugin=ON )
626 if [[ ${KDE_QTHELP} != false ]]; then
627 cmakeargs+=( -DBUILD_QCH=$(usex doc) )
630 if [[ ${ECM_KDEINSTALLDIRS} != false ]] ; then
632 # install mkspecs in the same directory as qt stuff
633 -DKDE_INSTALL_USE_QT_SYS_PATHS=ON
637 # allow the ebuild to override what we set here
638 mycmakeargs=("${cmakeargs[@]}" "${mycmakeargs[@]}")
640 cmake-utils_src_configure
643 # @FUNCTION: kde5_src_compile
645 # Wrapper for cmake-utils_src_compile. Currently doesn't do anything extra, but
646 # is included as part of the API just in case it's needed in the future.
648 debug-print-function ${FUNCNAME} "$@"
650 cmake-utils_src_compile "$@"
653 # @FUNCTION: kde5_src_test
655 # Wrapper for cmake-utils_src_test with extra logic for magic handling of dbus
658 debug-print-function ${FUNCNAME} "$@"
661 if [[ -n "${VIRTUALDBUS_TEST}" ]]; then
662 export $(dbus-launch)
668 # When run as normal user during ebuild development with the ebuild command, the
669 # kde tests tend to access the session DBUS. This however is not possible in a real
670 # emerge or on the tinderbox.
671 # > make sure it does not happen, so bad tests can be recognized and disabled
672 unset DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
674 if [[ ${VIRTUALX_REQUIRED} = always || ${VIRTUALX_REQUIRED} = test ]]; then
680 if [[ -n "${DBUS_SESSION_BUS_PID}" ]] ; then
681 kill ${DBUS_SESSION_BUS_PID}
685 # @FUNCTION: kde5_src_install
687 # Wrapper for cmake-utils_src_install with extra logic to avoid compressing
688 # certain types of files. For example, khelpcenter is not able to read
689 # compressed handbooks.
691 debug-print-function ${FUNCNAME} "$@"
693 cmake-utils_src_install
695 # We don't want QCH and tags files to be compressed, because then
696 # cmake can't find the tags and qthelp viewers can't find the docs
697 local p=$(best_version dev-qt/qtcore:5)
698 local pv=$(echo ${p/%-r[0-9]*/} | rev | cut -d - -f 1 | rev)
699 if [[ -d ${ED%/}/usr/share/doc/qt-${pv} ]]; then
700 docompress -x /usr/share/doc/qt-${pv}
703 # We don't want /usr/share/doc/HTML to be compressed,
704 # because then khelpcenter can't find the docs
705 if [[ -d ${ED%/}/usr/share/doc/HTML ]]; then
706 docompress -x /usr/share/doc/HTML
710 # @FUNCTION: kde5_pkg_preinst
712 # Sets up environment variables required in kde5_pkg_postinst.
714 debug-print-function ${FUNCNAME} "$@"
720 # @FUNCTION: kde5_pkg_postinst
722 # Updates the various XDG caches (icon, desktop, mime) if necessary.
723 kde5_pkg_postinst() {
724 debug-print-function ${FUNCNAME} "$@"
726 if [[ -n ${GNOME2_ECLASS_ICONS} ]]; then
727 gnome2_icon_cache_update
731 if [[ -z ${I_KNOW_WHAT_I_AM_DOING} ]]; then
732 if [[ ${KDE_BUILD_TYPE} = live ]]; then
734 einfo "WARNING! This is an experimental live ebuild of ${CATEGORY}/${PN}"
735 einfo "Use it at your own risk."
736 einfo "Do _NOT_ file bugs at bugs.gentoo.org because of this ebuild!"
741 # @FUNCTION: kde5_pkg_postrm
743 # Updates the various XDG caches (icon, desktop, mime) if necessary.
745 debug-print-function ${FUNCNAME} "$@"
747 if [[ -n ${GNOME2_ECLASS_ICONS} ]]; then
748 gnome2_icon_cache_update