1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
8 # @BLURB: Support eclass for KDE 5-related packages.
10 # The kde5.eclass provides support for building KDE 5-related packages.
12 if [[ -z ${_KDE5_ECLASS} ]]; then
15 # @ECLASS-VARIABLE: VIRTUALX_REQUIRED
17 # For proper description see virtualx.eclass manpage.
18 # Here we redefine default value to be manual, if your package needs virtualx
19 # for tests you should proceed with setting VIRTUALX_REQUIRED=test.
20 : ${VIRTUALX_REQUIRED:=manual}
22 inherit cmake-utils eutils flag-o-matic gnome2-utils kde5-functions versionator virtualx xdg
24 if [[ ${KDE_BUILD_TYPE} = live ]]; then
26 git) inherit git-r3 ;;
30 if [[ -v KDE_GCC_MINIMAL ]]; then
31 EXPORT_FUNCTIONS pkg_pretend
34 EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_test src_install pkg_preinst pkg_postinst pkg_postrm
36 # @ECLASS-VARIABLE: QT_MINIMAL
38 # Minimal Qt version to require for the package.
39 : ${QT_MINIMAL:=5.6.1}
41 # @ECLASS-VARIABLE: KDE_AUTODEPS
43 # If set to "false", do nothing.
44 # For any other value, add a dependency on dev-qt/qtcore:5 and kde-frameworks/extra-cmake-modules:5.
45 : ${KDE_AUTODEPS:=true}
47 # @ECLASS-VARIABLE: KDE_BLOCK_SLOT4
49 # This variable is used when KDE_AUTODEPS is set.
50 # If set to "true", add RDEPEND block on kde-apps/${PN}:4
51 : ${KDE_BLOCK_SLOT4:=true}
53 # @ECLASS-VARIABLE: KDE_DEBUG
55 # If set to "false", unconditionally build with -DNDEBUG.
56 # Otherwise, add debug to IUSE to control building with that flag.
59 # @ECLASS-VARIABLE: KDE_DESIGNERPLUGIN
61 # If set to "false", do nothing.
62 # Otherwise, add "designer" to IUSE to toggle build of designer plugins
63 # and add the necessary DEPENDs.
64 : ${KDE_DESIGNERPLUGIN:=false}
66 # @ECLASS-VARIABLE: KDE_EXAMPLES
68 # If set to "false", unconditionally ignore a top-level examples subdirectory.
69 # Otherwise, add "examples" to IUSE to toggle adding that subdirectory.
70 : ${KDE_EXAMPLES:=false}
72 # @ECLASS-VARIABLE: KDE_HANDBOOK
74 # If set to "false", do nothing.
75 # Otherwise, add "+handbook" to IUSE, add the appropriate dependency, and
76 # generate and install KDE handbook.
77 # If set to "optional", config with -DCMAKE_DISABLE_FIND_PACKAGE_KF5DocTools=ON
78 # when USE=!handbook. In case package requires KF5KDELibs4Support, see next:
79 # If set to "forceoptional", remove a KF5DocTools dependency from the root
80 # CMakeLists.txt in addition to the above.
81 : ${KDE_HANDBOOK:=false}
83 # @ECLASS-VARIABLE: KDE_DOC_DIR
85 # Defaults to "doc". Otherwise, use alternative KDE handbook path.
88 # @ECLASS-VARIABLE: KDE_TEST
90 # If set to "false", do nothing.
91 # For any other value, add test to IUSE and add a dependency on dev-qt/qttest:5.
92 # If set to "optional", configure with -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Test=ON
94 # If set to "forceoptional", remove a Qt5Test dependency and comment test
95 # subdirs from the root CMakeLists.txt in addition to the above.
96 # If set to "forceoptional-recursive", remove a Qt5Test dependency and comment
97 # test subdirs from *any* CMakeLists.txt in addition to the above.
98 if [[ ${CATEGORY} = kde-frameworks ]]; then
104 # @ECLASS-VARIABLE: KDE_L10N
106 # This is an array of translations this ebuild supports. These translations
107 # are automatically added to IUSE.
108 if [[ ${KDEBASE} = kdel10n ]]; then
109 if [[ -n ${KDE_L10N} ]]; then
110 IUSE="${IUSE} $(printf 'l10n_%s ' ${KDE_L10N[@]})"
114 # @ECLASS-VARIABLE: KDE_SELINUX_MODULE
116 # If set to "none", do nothing.
117 # For any other value, add selinux to IUSE, and depending on that useflag
118 # add a dependency on sec-policy/selinux-${KDE_SELINUX_MODULE} to (R)DEPEND.
119 : ${KDE_SELINUX_MODULE:=none}
121 if [[ ${KDEBASE} = kdevelop ]]; then
122 HOMEPAGE="https://www.kdevelop.org/"
123 elif [[ ${KDEBASE} = kdel10n ]]; then
124 HOMEPAGE="http://l10n.kde.org"
125 elif [[ ${KMNAME} = kdepim ]]; then
126 HOMEPAGE="https://www.kde.org/applications/office/kontact/"
128 HOMEPAGE="https://www.kde.org/"
133 if [[ ${CATEGORY} = kde-frameworks ]]; then
134 SLOT=5/$(get_version_component_range 1-2)
139 case ${KDE_AUTODEPS} in
142 if [[ ${KDE_BUILD_TYPE} = live ]]; then
145 FRAMEWORKS_MINIMAL=9999
148 FRAMEWORKS_MINIMAL=9999
154 DEPEND+=" $(add_frameworks_dep extra-cmake-modules)"
155 RDEPEND+=" >=kde-frameworks/kf-env-3"
156 COMMONDEPEND+=" $(add_qt_dep qtcore)"
158 if [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma && ${PN} != polkit-kde-agent ]]; then
160 !kde-apps/kde4-l10n[-minimal(+)]
161 !<kde-apps/kde4-l10n-15.12.3-r1
165 if [[ ${KDE_BLOCK_SLOT4} = true && ${CATEGORY} = kde-apps ]]; then
166 RDEPEND+=" !kde-apps/${PN}:4"
178 case ${KDE_DESIGNERPLUGIN} in
182 DEPEND+=" designer? (
183 $(add_frameworks_dep kdesignerplugin)
184 $(add_qt_dep designer)
189 case ${KDE_EXAMPLES} in
196 case ${KDE_HANDBOOK} in
200 DEPEND+=" handbook? ( $(add_frameworks_dep kdoctools) )"
208 DEPEND+=" test? ( $(add_qt_dep qttest) )"
212 case ${KDE_SELINUX_MODULE} in
216 RDEPEND+=" selinux? ( sec-policy/selinux-${KDE_SELINUX_MODULE} )"
220 DEPEND+=" ${COMMONDEPEND} dev-util/desktop-file-utils"
221 RDEPEND+=" ${COMMONDEPEND}"
224 if [[ -n ${KMNAME} && ${KMNAME} != ${PN} && ${KDE_BUILD_TYPE} = release ]]; then
225 S=${WORKDIR}/${KMNAME}-${PV}
228 # Drop this when kdepim is finally split upstream
229 if [[ -n ${KMNAME} && ${KMNAME} != ${PN} && ${KMNAME} = kdepim ]]; then
233 if [[ -n ${KDEBASE} && ${KDEBASE} = kdevelop && ${KDE_BUILD_TYPE} = release ]]; then
234 if [[ -n ${KMNAME} ]]; then
235 S=${WORKDIR}/${KMNAME}-${PV%.0} # kdevelop missing trailing .0 in first release
237 S=${WORKDIR}/${PN}-${PV%.0} # kdevelop missing trailing .0 in first release
241 # Determine fetch location for released tarballs
242 _calculate_src_uri() {
243 debug-print-function ${FUNCNAME} "$@"
247 if [[ -n ${KMNAME} ]]; then
260 _kmname="portingAids/${_kmname}"
264 DEPEND+=" app-arch/xz-utils"
269 ??.?.[6-9]? | ??.??.[6-9]? )
270 SRC_URI="mirror://kde/unstable/applications/${PV}/src/${_kmname}-${PV}.tar.xz"
274 SRC_URI="mirror://kde/stable/applications/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
278 SRC_URI="mirror://kde/stable/frameworks/${PV%.*}/${_kmname}-${PV}.tar.xz" ;;
280 local plasmapv=$(get_version_component_range 1-3)
284 # Plasma 5 beta releases
285 SRC_URI="mirror://kde/unstable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz"
289 # Plasma 5 stable releases
290 SRC_URI="mirror://kde/stable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz" ;;
295 if [[ -z ${SRC_URI} && -n ${KDEBASE} ]] ; then
301 _kdebase=${KDEBASE} ;;
305 SRC_URI="mirror://kde/unstable/${_kdebase}/${PV}/src/${_kmname}-${PV}.tar.xz"
309 SRC_URI="mirror://kde/stable/${_kdebase}/${PV}/src/${_kmname}-${PV%.0}.tar.xz" ;;
314 if [[ ${KDEBASE} = kdel10n ]] ; then
315 local uri_base="${SRC_URI/${_kmname}-${PV}.tar.xz/}kde-l10n/kde-l10n"
317 for my_l10n in ${KDE_L10N[@]} ; do
319 sr | sr-ijekavsk | sr-Latn-ijekavsk | sr-Latn)
320 SRC_URI="${SRC_URI} l10n_${my_l10n}? ( ${uri_base}-sr-${PV}.tar.xz )"
323 SRC_URI="${SRC_URI} l10n_${my_l10n}? ( ${uri_base}-$(kde_l10n2lingua ${my_l10n})-${PV}.tar.xz )"
330 # Determine fetch location for live sources
331 _calculate_live_repo() {
332 debug-print-function ${FUNCNAME} "$@"
338 # @ECLASS-VARIABLE: EGIT_MIRROR
340 # This variable allows easy overriding of default kde mirror service
341 # (anongit) with anything else you might want to use.
342 EGIT_MIRROR=${EGIT_MIRROR:=https://anongit.kde.org}
346 # @ECLASS-VARIABLE: EGIT_REPONAME
348 # This variable allows overriding of default repository
349 # name. Specify only if this differ from PN and KMNAME.
350 if [[ -n ${EGIT_REPONAME} ]]; then
351 # the repository and kmname different
352 _kmname=${EGIT_REPONAME}
353 elif [[ -n ${KMNAME} ]]; then
359 if [[ ${PV} == ??.??.49.9999 && ${CATEGORY} = kde-apps ]]; then
360 EGIT_BRANCH="Applications/$(get_version_component_range 1-2)"
363 if [[ ${PV} != 9999 && ${CATEGORY} = kde-plasma ]]; then
364 EGIT_BRANCH="Plasma/$(get_version_component_range 1-2)"
367 EGIT_REPO_URI="${EGIT_MIRROR}/${_kmname}"
372 case ${KDE_BUILD_TYPE} in
373 live) _calculate_live_repo ;;
374 *) _calculate_src_uri ;;
377 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: SRC_URI is ${SRC_URI}"
379 # @FUNCTION: kde5_pkg_pretend
381 # Do some basic settings
383 debug-print-function ${FUNCNAME} "$@"
387 # @FUNCTION: kde5_pkg_setup
389 # Do some basic settings
391 debug-print-function ${FUNCNAME} "$@"
395 # @FUNCTION: kde5_src_unpack
397 # Function for unpacking KDE 5.
399 debug-print-function ${FUNCNAME} "$@"
401 if [[ ${KDE_BUILD_TYPE} = live ]]; then
407 elif [[ ${KDEBASE} = kdel10n ]]; then
409 [[ ${PN} = kde4-l10n ]] && l10npart=4
410 mkdir -p "${S}" || die "Failed to create source dir ${S}"
412 for my_tar in ${A}; do
413 tar -xpf "${DISTDIR}/${my_tar}" --xz \
414 "${my_tar/.tar.xz/}/CMakeLists.txt" "${my_tar/.tar.xz/}/${l10npart}" 2> /dev/null ||
415 elog "${my_tar}: tar extract command failed at least partially - continuing"
422 # @FUNCTION: kde5_src_prepare
424 # Function for preparing the KDE 5 sources.
426 debug-print-function ${FUNCNAME} "$@"
428 if [[ ${KDEBASE} = kdel10n ]]; then
430 [[ ${PN} = kde4-l10n ]] && l10npart=4
431 # move known variant subdirs to root dir, currently sr@*
432 use_if_iuse l10n_sr-ijekavsk && _l10n_variant_subdir2root sr-ijekavsk sr
433 use_if_iuse l10n_sr-Latn-ijekavsk && _l10n_variant_subdir2root sr-Latn-ijekavsk sr
434 use_if_iuse l10n_sr-Latn && _l10n_variant_subdir2root sr-Latn sr
435 if use_if_iuse l10n_sr; then
436 rm -rf kde-l10n-sr-${PV}/${l10npart}/sr/sr@* || die "Failed to cleanup L10N=sr"
437 _l10n_variant_subdir_buster sr
438 elif [[ -d kde-l10n-sr-${PV} ]]; then
439 # having any variant selected means parent lingua will be unpacked as well
440 rm -r kde-l10n-sr-${PV} || die "Failed to remove sr parent lingua"
443 # add all l10n directories to cmake
444 cat <<-EOF > CMakeLists.txt || die
446 cmake_minimum_required(VERSION 2.8.12)
447 $(printf "add_subdirectory( %s )\n" \
448 `find . -mindepth 1 -maxdepth 1 -type d | sed -e "s:^\./::"`)
451 # for KF5: drop KDE4-based part; for KDE4: drop KF5-based part
453 5) find -maxdepth 2 -type f -name CMakeLists.txt -exec \
454 sed -i -e "/add_subdirectory(4)/ s/^/#DONT/" {} + || die ;;
455 4) find -maxdepth 2 -type f -name CMakeLists.txt -exec \
456 sed -i -e "/add_subdirectory(5)/ s/^/#DONT/" {} + || die ;;
460 cmake-utils_src_prepare
462 # only build examples when required
463 if ! use_if_iuse examples || ! use examples ; then
464 cmake_comment_add_subdirectory examples
467 # only enable handbook when required
468 if ! use_if_iuse handbook ; then
469 cmake_comment_add_subdirectory ${KDE_DOC_DIR}
471 if [[ ${KDE_HANDBOOK} = forceoptional ]] ; then
472 punt_bogus_dep KF5 DocTools
476 # drop translations when nls is not wanted
477 if [[ -d po ]] && in_iuse nls && ! use nls ; then
481 # enable only the requested translations
483 if [[ -d po && -v LINGUAS ]] ; then
484 pushd po > /dev/null || die
487 if [[ -d ${lang} ]] && ! has ${lang} ${LINGUAS} ; then
489 if [[ -e CMakeLists.txt ]] ; then
490 cmake_comment_add_subdirectory ${lang}
492 elif ! has ${lang/.po/} ${LINGUAS} ; then
493 if [[ ${lang} != CMakeLists.txt && ${lang} != ${PN}.pot ]] ; then
498 popd > /dev/null || die
501 if [[ ${KDE_BUILD_TYPE} = release && ${CATEGORY} != kde-apps ]] ; then
502 if [[ ${KDE_HANDBOOK} != false && -d ${KDE_DOC_DIR} && -v LINGUAS ]] ; then
503 pushd ${KDE_DOC_DIR} > /dev/null || die
506 if ! has ${lang} ${LINGUAS} ; then
507 cmake_comment_add_subdirectory ${lang}
510 popd > /dev/null || die
514 # in frameworks, tests = manual tests so never build them
515 if [[ ${CATEGORY} = kde-frameworks ]] && [[ ${PN} != extra-cmake-modules ]]; then
516 cmake_comment_add_subdirectory tests
519 # only build unit tests when required
520 if ! use_if_iuse test ; then
521 if [[ ${KDE_TEST} = forceoptional ]] ; then
522 punt_bogus_dep Qt5 Test
523 # if forceoptional, also cover non-kde categories
524 cmake_comment_add_subdirectory autotests test tests
525 elif [[ ${KDE_TEST} = forceoptional-recursive ]] ; then
526 punt_bogus_dep Qt5 Test
528 for d in $(find . -type d -name "autotests" -or -name "tests" -or -name "test" -or -name "unittests"); do
529 pushd ${d%/*} > /dev/null || die
530 punt_bogus_dep Qt5 Test
531 cmake_comment_add_subdirectory autotests test tests
532 popd > /dev/null || die
534 elif [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma || ${CATEGORY} = kde-apps ]] ; then
535 cmake_comment_add_subdirectory autotests test tests
540 # @FUNCTION: kde5_src_configure
542 # Function for configuring the build of KDE 5.
543 kde5_src_configure() {
544 debug-print-function ${FUNCNAME} "$@"
546 # we rely on cmake-utils.eclass to append -DNDEBUG too
547 if ! use_if_iuse debug; then
548 append-cppflags -DQT_NO_DEBUG
553 if ! use_if_iuse test ; then
554 cmakeargs+=( -DBUILD_TESTING=OFF )
556 if [[ ${KDE_TEST} = optional ]] ; then
557 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Test=ON )
561 if ! use_if_iuse handbook && [[ ${KDE_HANDBOOK} = optional ]] ; then
562 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_KF5DocTools=ON )
565 if ! use_if_iuse designer && [[ ${KDE_DESIGNERPLUGIN} != false ]] ; then
566 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Designer=ON )
569 # install mkspecs in the same directory as qt stuff
570 cmakeargs+=(-DKDE_INSTALL_USE_QT_SYS_PATHS=ON)
572 # allow the ebuild to override what we set here
573 mycmakeargs=("${cmakeargs[@]}" "${mycmakeargs[@]}")
575 cmake-utils_src_configure
578 # @FUNCTION: kde5_src_compile
580 # Function for compiling KDE 5.
582 debug-print-function ${FUNCNAME} "$@"
584 cmake-utils_src_compile "$@"
587 # @FUNCTION: kde5_src_test
589 # Function for testing KDE 5.
591 debug-print-function ${FUNCNAME} "$@"
594 if [[ -n "${VIRTUALDBUS_TEST}" ]]; then
595 export $(dbus-launch)
601 # When run as normal user during ebuild development with the ebuild command, the
602 # kde tests tend to access the session DBUS. This however is not possible in a real
603 # emerge or on the tinderbox.
604 # > make sure it does not happen, so bad tests can be recognized and disabled
605 unset DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
607 if [[ ${VIRTUALX_REQUIRED} = always || ${VIRTUALX_REQUIRED} = test ]]; then
613 if [[ -n "${DBUS_SESSION_BUS_PID}" ]] ; then
614 kill ${DBUS_SESSION_BUS_PID}
618 # @FUNCTION: kde5_src_install
620 # Function for installing KDE 5.
622 debug-print-function ${FUNCNAME} "$@"
624 cmake-utils_src_install
626 # We don't want ${PREFIX}/share/doc/HTML to be compressed,
627 # because then khelpcenter can't find the docs
628 if [[ -d ${ED}/${PREFIX}/share/doc/HTML ]]; then
629 docompress -x ${PREFIX}/share/doc/HTML
633 # @FUNCTION: kde5_pkg_preinst
635 # Function storing icon caches
637 debug-print-function ${FUNCNAME} "$@"
643 # @FUNCTION: kde5_pkg_postinst
645 # Function to rebuild the KDE System Configuration Cache after an application has been installed.
646 kde5_pkg_postinst() {
647 debug-print-function ${FUNCNAME} "$@"
649 gnome2_icon_cache_update
653 # @FUNCTION: kde5_pkg_postrm
655 # Function to rebuild the KDE System Configuration Cache after an application has been removed.
657 debug-print-function ${FUNCNAME} "$@"
659 gnome2_icon_cache_update
663 _l10n_variant_subdir2root() {
665 [[ ${PN} = kde4-l10n ]] && l10npart=4
666 local lingua=$(kde_l10n2lingua ${1})
667 local src=kde-l10n-${2}-${PV}
668 local dest=kde-l10n-${lingua}-${PV}/${l10npart}
670 # create variant rootdir structure from parent lingua and adapt it
671 mkdir -p ${dest} || die "Failed to create ${dest}"
672 mv ${src}/${l10npart}/${2}/${lingua} ${dest}/${lingua} || die "Failed to create ${dest}/${lingua}"
673 cp -f ${src}/CMakeLists.txt kde-l10n-${lingua}-${PV} || die "Failed to prepare L10N=${1} subdir"
674 echo "add_subdirectory(${lingua})" > ${dest}/CMakeLists.txt ||
675 die "Failed to prepare ${dest}/CMakeLists.txt"
676 cp -f ${src}/${l10npart}/${2}/CMakeLists.txt ${dest}/${lingua} ||
677 die "Failed to create ${dest}/${lingua}/CMakeLists.txt"
678 sed -e "s/${2}/${lingua}/" -i ${dest}/${lingua}/CMakeLists.txt ||
679 die "Failed to prepare ${dest}/${lingua}/CMakeLists.txt"
681 _l10n_variant_subdir_buster ${1}
684 _l10n_variant_subdir_buster() {
686 [[ ${PN} = kde4-l10n ]] && l10npart=4
687 local dir=kde-l10n-$(kde_l10n2lingua ${1})-${PV}/${l10npart}/$(kde_l10n2lingua ${1})
690 5) sed -e "/^add_subdirectory(/d" -i ${dir}/CMakeLists.txt || die "Failed to cleanup ${dir} subdir" ;;
691 4) sed -e "/^macro.*subdirectory(/d" -i ${dir}/CMakeLists.txt || die "Failed to cleanup ${dir} subdir" ;;
694 for subdir in $(find ${dir} -mindepth 1 -maxdepth 1 -type d | sed -e "s:^\./::"); do
695 echo "add_subdirectory(${subdir##*/})" >> ${dir}/CMakeLists.txt