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 from the root
95 # CMakeLists.txt in addition to the above.
96 if [[ ${CATEGORY} = kde-frameworks ]]; then
102 # @ECLASS-VARIABLE: KDE_L10N
104 # This is an array of translations this ebuild supports. These translations
105 # are automatically added to IUSE.
106 if [[ ${KDEBASE} = kdel10n ]]; then
107 if [[ -n ${KDE_L10N} ]]; then
108 IUSE="${IUSE} $(printf 'l10n_%s ' ${KDE_L10N[@]})"
112 # @ECLASS-VARIABLE: KDE_PUNT_BOGUS_DEPS
114 # If set to "false", do nothing.
115 # For any other value, do black magic to make hardcoded-but-optional dependencies
116 # optional again. An upstream solution is preferable and this is a last resort.
117 : ${KDE_PUNT_BOGUS_DEPS:=false}
119 # @ECLASS-VARIABLE: KDE_SELINUX_MODULE
121 # If set to "none", do nothing.
122 # For any other value, add selinux to IUSE, and depending on that useflag
123 # add a dependency on sec-policy/selinux-${KDE_SELINUX_MODULE} to (R)DEPEND.
124 : ${KDE_SELINUX_MODULE:=none}
126 if [[ ${KDEBASE} = kdevelop ]]; then
127 HOMEPAGE="https://www.kdevelop.org/"
128 elif [[ ${KDEBASE} = kdel10n ]]; then
129 HOMEPAGE="http://l10n.kde.org"
131 HOMEPAGE="https://www.kde.org/"
136 if [[ ${CATEGORY} = kde-frameworks ]]; then
137 SLOT=5/$(get_version_component_range 1-2)
142 case ${KDE_AUTODEPS} in
145 if [[ ${KDE_BUILD_TYPE} = live ]]; then
148 FRAMEWORKS_MINIMAL=9999
151 FRAMEWORKS_MINIMAL=9999
157 DEPEND+=" $(add_frameworks_dep extra-cmake-modules)"
158 RDEPEND+=" >=kde-frameworks/kf-env-3"
159 COMMONDEPEND+=" $(add_qt_dep qtcore)"
161 if [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma && ${PN} != polkit-kde-agent ]]; then
163 !kde-apps/kde4-l10n[-minimal(+)]
164 !<kde-apps/kde4-l10n-15.12.3-r1
168 if [[ ${KDE_BLOCK_SLOT4} = true && ${CATEGORY} = kde-apps ]]; then
169 RDEPEND+=" !kde-apps/${PN}:4"
181 case ${KDE_DESIGNERPLUGIN} in
185 DEPEND+=" designer? (
186 $(add_frameworks_dep kdesignerplugin)
187 $(add_qt_dep designer)
192 case ${KDE_EXAMPLES} in
199 case ${KDE_HANDBOOK} in
203 DEPEND+=" handbook? ( $(add_frameworks_dep kdoctools) )"
211 DEPEND+=" test? ( $(add_qt_dep qttest) )"
215 case ${KDE_SELINUX_MODULE} in
219 RDEPEND+=" selinux? ( sec-policy/selinux-${KDE_SELINUX_MODULE} )"
223 DEPEND+=" ${COMMONDEPEND} dev-util/desktop-file-utils"
224 RDEPEND+=" ${COMMONDEPEND}"
227 if [[ -n ${KMNAME} && ${KMNAME} != ${PN} && ${KDE_BUILD_TYPE} = release ]]; then
228 S=${WORKDIR}/${KMNAME}-${PV}
231 # Determine fetch location for released tarballs
232 _calculate_src_uri() {
233 debug-print-function ${FUNCNAME} "$@"
237 if [[ -n ${KMNAME} ]]; then
250 _kmname="portingAids/${_kmname}"
254 DEPEND+=" app-arch/xz-utils"
259 ??.?.[6-9]? | ??.??.[6-9]? )
260 SRC_URI="mirror://kde/unstable/applications/${PV}/src/${_kmname}-${PV}.tar.xz"
264 SRC_URI="mirror://kde/stable/applications/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
268 SRC_URI="mirror://kde/stable/frameworks/${PV%.*}/${_kmname}-${PV}.tar.xz" ;;
270 local plasmapv=$(get_version_component_range 1-3)
274 # Plasma 5 beta releases
275 SRC_URI="mirror://kde/unstable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz"
279 # Plasma 5 stable releases
280 SRC_URI="mirror://kde/stable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz" ;;
285 if [[ ${KDEBASE} = kdel10n ]] ; then
286 local uri_base="${SRC_URI/${_kmname}-${PV}.tar.xz/}kde-l10n/kde-l10n"
288 for my_l10n in ${KDE_L10N[@]} ; do
290 sr | sr-ijekavsk | sr-Latn-ijekavsk | sr-Latn)
291 SRC_URI="${SRC_URI} l10n_${my_l10n}? ( ${uri_base}-sr-${PV}.tar.xz )"
294 SRC_URI="${SRC_URI} l10n_${my_l10n}? ( ${uri_base}-$(kde_l10n2lingua ${my_l10n})-${PV}.tar.xz )"
301 # Determine fetch location for live sources
302 _calculate_live_repo() {
303 debug-print-function ${FUNCNAME} "$@"
309 # @ECLASS-VARIABLE: EGIT_MIRROR
311 # This variable allows easy overriding of default kde mirror service
312 # (anongit) with anything else you might want to use.
313 EGIT_MIRROR=${EGIT_MIRROR:=https://anongit.kde.org}
317 # @ECLASS-VARIABLE: EGIT_REPONAME
319 # This variable allows overriding of default repository
320 # name. Specify only if this differ from PN and KMNAME.
321 if [[ -n ${EGIT_REPONAME} ]]; then
322 # the repository and kmname different
323 _kmname=${EGIT_REPONAME}
324 elif [[ -n ${KMNAME} ]]; then
330 if [[ ${PV} == ??.??.49.9999 && ${CATEGORY} = kde-apps ]]; then
331 EGIT_BRANCH="Applications/$(get_version_component_range 1-2)"
334 if [[ ${PV} != 9999 && ${CATEGORY} = kde-plasma ]]; then
335 EGIT_BRANCH="Plasma/$(get_version_component_range 1-2)"
338 EGIT_REPO_URI="${EGIT_MIRROR}/${_kmname}"
343 case ${KDE_BUILD_TYPE} in
344 live) _calculate_live_repo ;;
345 *) _calculate_src_uri ;;
348 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: SRC_URI is ${SRC_URI}"
350 # @FUNCTION: kde5_pkg_pretend
352 # Do some basic settings
354 debug-print-function ${FUNCNAME} "$@"
358 # @FUNCTION: kde5_pkg_setup
360 # Do some basic settings
362 debug-print-function ${FUNCNAME} "$@"
366 # @FUNCTION: kde5_src_unpack
368 # Function for unpacking KDE 5.
370 debug-print-function ${FUNCNAME} "$@"
372 if [[ ${KDE_BUILD_TYPE} = live ]]; then
378 elif [[ ${KDEBASE} = kdel10n ]]; then
380 [[ ${PN} = kde4-l10n ]] && l10npart=4
381 mkdir -p "${S}" || die "Failed to create source dir ${S}"
383 for my_tar in ${A}; do
384 tar -xpf "${DISTDIR}/${my_tar}" --xz \
385 "${my_tar/.tar.xz/}/CMakeLists.txt" "${my_tar/.tar.xz/}/${l10npart}" 2> /dev/null ||
386 elog "${my_tar}: tar extract command failed at least partially - continuing"
393 # @FUNCTION: kde5_src_prepare
395 # Function for preparing the KDE 5 sources.
397 debug-print-function ${FUNCNAME} "$@"
399 if [[ ${KDEBASE} = kdel10n ]]; then
401 [[ ${PN} = kde4-l10n ]] && l10npart=4
402 # move known variant subdirs to root dir, currently sr@*
403 use_if_iuse l10n_sr-ijekavsk && _l10n_variant_subdir2root sr-ijekavsk sr
404 use_if_iuse l10n_sr-Latn-ijekavsk && _l10n_variant_subdir2root sr-Latn-ijekavsk sr
405 use_if_iuse l10n_sr-Latn && _l10n_variant_subdir2root sr-Latn sr
406 if use_if_iuse l10n_sr; then
407 rm -rf kde-l10n-sr-${PV}/${l10npart}/sr/sr@* || die "Failed to cleanup L10N=sr"
408 _l10n_variant_subdir_buster sr
409 elif [[ -d kde-l10n-sr-${PV} ]]; then
410 # having any variant selected means parent lingua will be unpacked as well
411 rm -r kde-l10n-sr-${PV} || die "Failed to remove sr parent lingua"
414 # add all l10n directories to cmake
415 cat <<-EOF > CMakeLists.txt || die
417 cmake_minimum_required(VERSION 2.8.12)
418 $(printf "add_subdirectory( %s )\n" \
419 `find . -mindepth 1 -maxdepth 1 -type d | sed -e "s:^\./::"`)
422 # for KF5: drop KDE4-based part; for KDE4: drop KF5-based part
424 5) find -maxdepth 2 -type f -name CMakeLists.txt -exec \
425 sed -i -e "/add_subdirectory(4)/ s/^/#DONT/" {} + || die ;;
426 4) find -maxdepth 2 -type f -name CMakeLists.txt -exec \
427 sed -i -e "/add_subdirectory(5)/ s/^/#DONT/" {} + || die ;;
431 cmake-utils_src_prepare
433 # only build examples when required
434 if ! use_if_iuse examples || ! use examples ; then
435 cmake_comment_add_subdirectory examples
438 # only enable handbook when required
439 if ! use_if_iuse handbook ; then
440 cmake_comment_add_subdirectory ${KDE_DOC_DIR}
442 if [[ ${KDE_HANDBOOK} = forceoptional ]] ; then
443 punt_bogus_dep KF5 DocTools
447 # drop translations when nls is not wanted
448 if [[ -d po ]] && in_iuse nls && ! use nls ; then
452 # enable only the requested translations
454 if [[ -d po && -v LINGUAS ]] ; then
455 pushd po > /dev/null || die
457 if [[ -d ${lang} ]] && ! has ${lang} ${LINGUAS} ; then
459 if [[ -e CMakeLists.txt ]] ; then
460 cmake_comment_add_subdirectory ${lang}
462 elif ! has ${lang/.po/} ${LINGUAS} ; then
463 if [[ ${lang} != CMakeLists.txt ]] ; then
468 popd > /dev/null || die
471 if [[ ${KDE_BUILD_TYPE} = release ]] ; then
472 if [[ ${KDE_HANDBOOK} != false && -d ${KDE_DOC_DIR} && ${CATEGORY} != kde-apps ]] ; then
473 pushd ${KDE_DOC_DIR} > /dev/null || die
475 if ! has ${lang} ${LINGUAS} ; then
476 cmake_comment_add_subdirectory ${lang}
479 popd > /dev/null || die
483 # in frameworks, tests = manual tests so never build them
484 if [[ ${CATEGORY} = kde-frameworks ]] && [[ ${PN} != extra-cmake-modules ]]; then
485 cmake_comment_add_subdirectory tests
488 case ${KDE_PUNT_BOGUS_DEPS} in
491 if ! use_if_iuse test ; then
492 punt_bogus_dep Qt5 Test
494 if ! use_if_iuse handbook ; then
495 punt_bogus_dep KF5 DocTools
500 # only build unit tests when required
501 if ! use_if_iuse test ; then
502 if [[ ${KDE_TEST} = forceoptional ]] ; then
503 punt_bogus_dep Qt5 Test
504 # if forceoptional, also cover non-kde categories
505 cmake_comment_add_subdirectory autotests
506 cmake_comment_add_subdirectory test
507 cmake_comment_add_subdirectory tests
508 elif [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma || ${CATEGORY} = kde-apps ]] ; then
509 cmake_comment_add_subdirectory autotests
510 cmake_comment_add_subdirectory test
511 cmake_comment_add_subdirectory tests
516 # @FUNCTION: kde5_src_configure
518 # Function for configuring the build of KDE 5.
519 kde5_src_configure() {
520 debug-print-function ${FUNCNAME} "$@"
522 # we rely on cmake-utils.eclass to append -DNDEBUG too
523 if ! use_if_iuse debug; then
524 append-cppflags -DQT_NO_DEBUG
529 if ! use_if_iuse test ; then
530 cmakeargs+=( -DBUILD_TESTING=OFF )
532 if [[ ${KDE_TEST} = optional ]] ; then
533 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Test=ON )
537 if ! use_if_iuse handbook && [[ ${KDE_HANDBOOK} = optional ]] ; then
538 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_KF5DocTools=ON )
541 if ! use_if_iuse designer && [[ ${KDE_DESIGNERPLUGIN} != false ]] ; then
542 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Designer=ON )
545 # install mkspecs in the same directory as qt stuff
546 cmakeargs+=(-DKDE_INSTALL_USE_QT_SYS_PATHS=ON)
548 # allow the ebuild to override what we set here
549 mycmakeargs=("${cmakeargs[@]}" "${mycmakeargs[@]}")
551 cmake-utils_src_configure
554 # @FUNCTION: kde5_src_compile
556 # Function for compiling KDE 5.
558 debug-print-function ${FUNCNAME} "$@"
560 cmake-utils_src_compile "$@"
563 # @FUNCTION: kde5_src_test
565 # Function for testing KDE 5.
567 debug-print-function ${FUNCNAME} "$@"
570 if [[ -n "${VIRTUALDBUS_TEST}" ]]; then
571 export $(dbus-launch)
577 # When run as normal user during ebuild development with the ebuild command, the
578 # kde tests tend to access the session DBUS. This however is not possible in a real
579 # emerge or on the tinderbox.
580 # > make sure it does not happen, so bad tests can be recognized and disabled
581 unset DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
583 if [[ ${VIRTUALX_REQUIRED} = always || ${VIRTUALX_REQUIRED} = test ]]; then
589 if [[ -n "${DBUS_SESSION_BUS_PID}" ]] ; then
590 kill ${DBUS_SESSION_BUS_PID}
594 # @FUNCTION: kde5_src_install
596 # Function for installing KDE 5.
598 debug-print-function ${FUNCNAME} "$@"
600 cmake-utils_src_install
602 # We don't want ${PREFIX}/share/doc/HTML to be compressed,
603 # because then khelpcenter can't find the docs
604 if [[ -d ${ED}/${PREFIX}/share/doc/HTML ]]; then
605 docompress -x ${PREFIX}/share/doc/HTML
609 # @FUNCTION: kde5_pkg_preinst
611 # Function storing icon caches
613 debug-print-function ${FUNCNAME} "$@"
619 # @FUNCTION: kde5_pkg_postinst
621 # Function to rebuild the KDE System Configuration Cache after an application has been installed.
622 kde5_pkg_postinst() {
623 debug-print-function ${FUNCNAME} "$@"
625 gnome2_icon_cache_update
629 # @FUNCTION: kde5_pkg_postrm
631 # Function to rebuild the KDE System Configuration Cache after an application has been removed.
633 debug-print-function ${FUNCNAME} "$@"
635 gnome2_icon_cache_update
639 _l10n_variant_subdir2root() {
641 [[ ${PN} = kde4-l10n ]] && l10npart=4
642 local lingua=$(kde_l10n2lingua ${1})
643 local src=kde-l10n-${2}-${PV}
644 local dest=kde-l10n-${lingua}-${PV}/${l10npart}
646 # create variant rootdir structure from parent lingua and adapt it
647 mkdir -p ${dest} || die "Failed to create ${dest}"
648 mv ${src}/${l10npart}/${2}/${lingua} ${dest}/${lingua} || die "Failed to create ${dest}/${lingua}"
649 cp -f ${src}/CMakeLists.txt kde-l10n-${lingua}-${PV} || die "Failed to prepare L10N=${1} subdir"
650 echo "add_subdirectory(${lingua})" > ${dest}/CMakeLists.txt ||
651 die "Failed to prepare ${dest}/CMakeLists.txt"
652 cp -f ${src}/${l10npart}/${2}/CMakeLists.txt ${dest}/${lingua} ||
653 die "Failed to create ${dest}/${lingua}/CMakeLists.txt"
654 sed -e "s/${2}/${lingua}/" -i ${dest}/${lingua}/CMakeLists.txt ||
655 die "Failed to prepare ${dest}/${lingua}/CMakeLists.txt"
657 _l10n_variant_subdir_buster ${1}
660 _l10n_variant_subdir_buster() {
662 [[ ${PN} = kde4-l10n ]] && l10npart=4
663 local dir=kde-l10n-$(kde_l10n2lingua ${1})-${PV}/${l10npart}/$(kde_l10n2lingua ${1})
666 5) sed -e "/^add_subdirectory(/d" -i ${dir}/CMakeLists.txt || die "Failed to cleanup ${dir} subdir" ;;
667 4) sed -e "/^macro.*subdirectory(/d" -i ${dir}/CMakeLists.txt || die "Failed to cleanup ${dir} subdir" ;;
670 for subdir in $(find ${dir} -mindepth 1 -maxdepth 1 -type d | sed -e "s:^\./::"); do
671 echo "add_subdirectory(${subdir##*/})" >> ${dir}/CMakeLists.txt