x11-misc/alock: Take ownership of package
[gentoo.git] / eclass / kde5.eclass
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: kde5.eclass
6 # @MAINTAINER:
7 # kde@gentoo.org
8 # @BLURB: Support eclass for KDE 5-related packages.
9 # @DESCRIPTION:
10 # The kde5.eclass provides support for building KDE 5-related packages.
11
12 if [[ -z ${_KDE5_ECLASS} ]]; then
13 _KDE5_ECLASS=1
14
15 # @ECLASS-VARIABLE: VIRTUALX_REQUIRED
16 # @DESCRIPTION:
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}
21
22 inherit kde5-functions fdo-mime flag-o-matic gnome2-utils versionator virtualx eutils cmake-utils
23
24 if [[ ${KDE_BUILD_TYPE} = live ]]; then
25         case ${KDE_SCM} in
26                 svn) inherit subversion ;;
27                 git) inherit git-r3 ;;
28         esac
29 fi
30
31 EXPORT_FUNCTIONS pkg_pretend pkg_setup src_unpack src_prepare src_configure src_compile src_test src_install pkg_preinst pkg_postinst pkg_postrm
32
33 # @ECLASS-VARIABLE: QT_MINIMAL
34 # @DESCRIPTION:
35 # Minimal Qt version to require for the package.
36 : ${QT_MINIMAL:=5.4.2}
37
38 # @ECLASS-VARIABLE: KDE_AUTODEPS
39 # @DESCRIPTION:
40 # If set to "false", do nothing.
41 # For any other value, add a dependency on dev-qt/qtcore:5 and kde-frameworks/extra-cmake-modules:5.
42 : ${KDE_AUTODEPS:=true}
43
44 # @ECLASS-VARIABLE: KDE_BLOCK_SLOT4
45 # @DESCRIPTION:
46 # This variable is used when KDE_AUTODEPS is set.
47 # If set to "true", add RDEPEND block on kde-{base,apps}/${PN}:4
48 : ${KDE_BLOCK_SLOT4:=true}
49
50 # @ECLASS-VARIABLE: KDE_DEBUG
51 # @DESCRIPTION:
52 # If set to "false", unconditionally build with -DNDEBUG.
53 # Otherwise, add debug to IUSE to control building with that flag.
54 : ${KDE_DEBUG:=true}
55
56 # @ECLASS-VARIABLE: KDE_DOXYGEN
57 # @DESCRIPTION:
58 # If set to "false", do nothing.
59 # Otherwise, add "doc" to IUSE, add appropriate dependencies, and generate and
60 # install API documentation.
61 if [[ ${CATEGORY} = kde-frameworks ]]; then
62         : ${KDE_DOXYGEN:=true}
63 else
64         : ${KDE_DOXYGEN:=false}
65 fi
66
67 # @ECLASS-VARIABLE: KDE_DOX_DIR
68 # @DESCRIPTION:
69 # Defaults to ".". Otherwise, use alternative KDE doxygen path.
70 : ${KDE_DOX_DIR:=.}
71
72 # @ECLASS-VARIABLE: KDE_EXAMPLES
73 # @DESCRIPTION:
74 # If set to "false", unconditionally ignore a top-level examples subdirectory.
75 # Otherwise, add "examples" to IUSE to toggle adding that subdirectory.
76 : ${KDE_EXAMPLES:=false}
77
78 # @ECLASS-VARIABLE: KDE_HANDBOOK
79 # @DESCRIPTION:
80 # If set to "false", do nothing.
81 # Otherwise, add "+handbook" to IUSE, add the appropriate dependency, and
82 # generate and install KDE handbook.
83 # If set to "forceoptional", remove a KF5DocTools dependency from the root
84 # CMakeLists.txt in addition to the above.
85 : ${KDE_HANDBOOK:=false}
86
87 # @ECLASS-VARIABLE: KDE_DOC_DIR
88 # @DESCRIPTION:
89 # Defaults to "doc". Otherwise, use alternative KDE handbook path.
90 : ${KDE_DOC_DIR:=doc}
91
92 # @ECLASS-VARIABLE: KDE_TEST
93 # @DESCRIPTION:
94 # If set to "false", do nothing.
95 # For any other value, add test to IUSE and add a dependency on dev-qt/qttest:5.
96 # If set to "forceoptional", remove a Qt5Test dependency from the root
97 # CMakeLists.txt in addition to the above.
98 if [[ ${CATEGORY} = kde-frameworks ]]; then
99         : ${KDE_TEST:=true}
100 else
101         : ${KDE_TEST:=false}
102 fi
103
104 # @ECLASS-VARIABLE: KDE_PUNT_BOGUS_DEPS
105 # @DESCRIPTION:
106 # If set to "false", do nothing.
107 # For any other value, do black magic to make hardcoded-but-optional dependencies
108 # optional again. An upstream solution is preferable and this is a last resort.
109 : ${KDE_PUNT_BOGUS_DEPS:=false}
110
111 # @ECLASS-VARIABLE: KDE_SELINUX_MODULE
112 # @DESCRIPTION:
113 # If set to "none", do nothing.
114 # For any other value, add selinux to IUSE, and depending on that useflag
115 # add a dependency on sec-policy/selinux-${KDE_SELINUX_MODULE} to (R)DEPEND.
116 : ${KDE_SELINUX_MODULE:=none}
117
118 if [[ ${KDEBASE} = kdevelop ]]; then
119         HOMEPAGE="https://www.kdevelop.org/"
120 else
121         HOMEPAGE="https://www.kde.org/"
122 fi
123
124 LICENSE="GPL-2"
125
126 if [[ ${CATEGORY} = kde-frameworks ]]; then
127         SLOT=5/$(get_version_component_range 1-2)
128 else
129         SLOT=5
130 fi
131
132 case ${KDE_AUTODEPS} in
133         false)  ;;
134         *)
135                 if [[ ${KDE_BUILD_TYPE} = live ]]; then
136                         case ${CATEGORY} in
137                                 kde-frameworks)
138                                         FRAMEWORKS_MINIMAL=9999
139                                 ;;
140                                 kde-plasma)
141                                         FRAMEWORKS_MINIMAL=9999
142                                 ;;
143                                 *) ;;
144                         esac
145                 fi
146
147                 DEPEND+=" $(add_frameworks_dep extra-cmake-modules)"
148                 RDEPEND+=" >=kde-frameworks/kf-env-3"
149                 COMMONDEPEND+=" >=dev-qt/qtcore-${QT_MINIMAL}:5"
150
151                 if [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma && ${PN} != polkit-kde-agent ]]; then
152                         RDEPEND+="
153                                 !kde-apps/kde4-l10n[-minimal(-)]
154                                 !<kde-apps/kde4-l10n-15.08.0-r1
155                         "
156                 fi
157
158                 if [[ ${KDE_BLOCK_SLOT4} = true && ${CATEGORY} = kde-apps ]]; then
159                         RDEPEND+=" !kde-apps/${PN}:4"
160                 fi
161                 ;;
162 esac
163
164 case ${KDE_DOXYGEN} in
165         false)  ;;
166         *)
167                 IUSE+=" doc"
168                 DEPEND+=" doc? (
169                                 $(add_frameworks_dep kapidox)
170                                 app-doc/doxygen
171                         )"
172                 ;;
173 esac
174
175 case ${KDE_DEBUG} in
176         false)  ;;
177         *)
178                 IUSE+=" debug"
179                 ;;
180 esac
181
182 case ${KDE_EXAMPLES} in
183         false)  ;;
184         *)
185                 IUSE+=" examples"
186                 ;;
187 esac
188
189 case ${KDE_HANDBOOK} in
190         false)  ;;
191         *)
192                 IUSE+=" +handbook"
193                 DEPEND+=" handbook? ( $(add_frameworks_dep kdoctools) )"
194                 ;;
195 esac
196
197 case ${KDE_TEST} in
198         false)  ;;
199         *)
200                 IUSE+=" test"
201                 DEPEND+=" test? ( >=dev-qt/qttest-${QT_MINIMAL}:5 )"
202                 ;;
203 esac
204
205 case ${KDE_SELINUX_MODULE} in
206         none)   ;;
207         *)
208                 IUSE+=" selinux"
209                 RDEPEND+=" selinux? ( sec-policy/selinux-${KDE_SELINUX_MODULE} )"
210                 ;;
211 esac
212
213 DEPEND+=" ${COMMONDEPEND} dev-util/desktop-file-utils"
214 RDEPEND+=" ${COMMONDEPEND}"
215 unset COMMONDEPEND
216
217 if [[ -n ${KMNAME} && ${KMNAME} != ${PN} && ${KDE_BUILD_TYPE} = release ]]; then
218         S=${WORKDIR}/${KMNAME}-${PV}
219 fi
220
221 # Determine fetch location for released tarballs
222 _calculate_src_uri() {
223         debug-print-function ${FUNCNAME} "$@"
224
225         local _kmname
226
227         if [[ -n ${KMNAME} ]]; then
228                 _kmname=${KMNAME}
229         else
230                 _kmname=${PN}
231         fi
232
233         case ${PN} in
234                 kdelibs4support | \
235                 khtml | \
236                 kjs | \
237                 kjsembed | \
238                 kmediaplayer | \
239                 kross | \
240                 krunner)
241                         _kmname="portingAids/${_kmname}"
242                         ;;
243         esac
244
245         DEPEND+=" app-arch/xz-utils"
246
247         case ${CATEGORY} in
248                 kde-apps)
249                         case ${PV} in
250                                 ??.?.[6-9]? | ??.??.[6-9]? )
251                                         SRC_URI="mirror://kde/unstable/applications/${PV}/src/${_kmname}-${PV}.tar.xz"
252                                         RESTRICT+=" mirror"
253                                         ;;
254                                 *)
255                                         SRC_URI="mirror://kde/stable/applications/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
256                         esac
257                         ;;
258                 kde-frameworks)
259                         SRC_URI="mirror://kde/stable/frameworks/${PV%.*}/${_kmname}-${PV}.tar.xz" ;;
260                 kde-plasma)
261                         local plasmapv=$(get_version_component_range 1-3)
262
263                         case ${PV} in
264                                 5.?.[6-9]? )
265                                         # Plasma 5 beta releases
266                                         SRC_URI="mirror://kde/unstable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz"
267                                         RESTRICT+=" mirror"
268                                         ;;
269                                 *)
270                                         # Plasma 5 stable releases
271                                         SRC_URI="mirror://kde/stable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz" ;;
272                         esac
273                         ;;
274         esac
275 }
276
277 # Determine fetch location for live sources
278 _calculate_live_repo() {
279         debug-print-function ${FUNCNAME} "$@"
280
281         SRC_URI=""
282
283         case ${KDE_SCM} in
284                 svn)
285                         # @ECLASS-VARIABLE: ESVN_MIRROR
286                         # @DESCRIPTION:
287                         # This variable allows easy overriding of default kde mirror service
288                         # (anonsvn) with anything else you might want to use.
289                         ESVN_MIRROR=${ESVN_MIRROR:=svn://anonsvn.kde.org/home/kde}
290
291                         local branch_prefix="trunk/KDE"
292
293                         if [[ ${PV} == ??.??.49.9999 && ${CATEGORY} = kde-apps ]]; then
294                                 branch_prefix="branches/Applications/$(get_version_component_range 1-2)"
295                         fi
296
297                         if [[ ${PV} != 9999 && ${CATEGORY} = kde-plasma ]]; then
298                                 branch_prefix="branches/plasma/$(get_version_component_range 1-2)"
299                         fi
300
301                         local _kmname
302
303                         if [[ -n ${KMNAME} ]]; then
304                                 _kmname=${KMNAME}
305                         else
306                                 _kmname=${PN}
307                         fi
308
309                         ESVN_REPO_URI="${ESVN_MIRROR}/${branch_prefix}/${_kmname}"
310                         ;;
311                 git)
312                         # @ECLASS-VARIABLE: EGIT_MIRROR
313                         # @DESCRIPTION:
314                         # This variable allows easy overriding of default kde mirror service
315                         # (anongit) with anything else you might want to use.
316                         EGIT_MIRROR=${EGIT_MIRROR:=git://anongit.kde.org}
317
318                         local _kmname
319
320                         # @ECLASS-VARIABLE: EGIT_REPONAME
321                         # @DESCRIPTION:
322                         # This variable allows overriding of default repository
323                         # name. Specify only if this differ from PN and KMNAME.
324                         if [[ -n ${EGIT_REPONAME} ]]; then
325                                 # the repository and kmname different
326                                 _kmname=${EGIT_REPONAME}
327                         elif [[ -n ${KMNAME} ]]; then
328                                 _kmname=${KMNAME}
329                         else
330                                 _kmname=${PN}
331                         fi
332
333                         if [[ ${PV} == ??.??.49.9999 && ${CATEGORY} = kde-apps ]]; then
334                                 EGIT_BRANCH="Applications/$(get_version_component_range 1-2)"
335                         fi
336
337                         if [[ ${PV} != 9999 && ${CATEGORY} = kde-plasma ]]; then
338                                 EGIT_BRANCH="Plasma/$(get_version_component_range 1-2)"
339                         fi
340
341                         EGIT_REPO_URI="${EGIT_MIRROR}/${_kmname}"
342                         ;;
343         esac
344 }
345
346 case ${KDE_BUILD_TYPE} in
347         live) _calculate_live_repo ;;
348         *) _calculate_src_uri ;;
349 esac
350
351 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: SRC_URI is ${SRC_URI}"
352
353 # @FUNCTION: kde5_pkg_pretend
354 # @DESCRIPTION:
355 # Do some basic settings
356 kde5_pkg_pretend() {
357         debug-print-function ${FUNCNAME} "$@"
358         if [[ ${MERGE_TYPE} != binary ]]; then
359                 _check_gcc_version
360         fi
361 }
362
363 # @FUNCTION: kde5_pkg_setup
364 # @DESCRIPTION:
365 # Do some basic settings
366 kde5_pkg_setup() {
367         debug-print-function ${FUNCNAME} "$@"
368         if [[ ${MERGE_TYPE} != binary ]]; then
369                 _check_gcc_version
370         fi
371 }
372
373 # @FUNCTION: kde5_src_unpack
374 # @DESCRIPTION:
375 # Function for unpacking KDE 5.
376 kde5_src_unpack() {
377         debug-print-function ${FUNCNAME} "$@"
378
379         if [[ ${KDE_BUILD_TYPE} = live ]]; then
380                 case ${KDE_SCM} in
381                         svn)
382                                 subversion_src_unpack
383                                 ;;
384                         git)
385                                 git-r3_src_unpack
386                                 ;;
387                 esac
388         else
389                 default
390         fi
391 }
392
393 # @FUNCTION: kde5_src_prepare
394 # @DESCRIPTION:
395 # Function for preparing the KDE 5 sources.
396 kde5_src_prepare() {
397         debug-print-function ${FUNCNAME} "$@"
398
399         cmake-utils_src_prepare
400
401         # only build examples when required
402         if ! use_if_iuse examples || ! use examples ; then
403                 comment_add_subdirectory examples
404         fi
405
406         # only enable handbook when required
407         if ! use_if_iuse handbook ; then
408                 comment_add_subdirectory ${KDE_DOC_DIR}
409
410                 if [[ ${KDE_HANDBOOK} = forceoptional ]] ; then
411                         punt_bogus_dep KF5 DocTools
412                 fi
413         fi
414
415         # enable only the requested translations
416         # when required
417         if [[ ${KDE_BUILD_TYPE} = release ]] ; then
418                 if [[ -d po ]] ; then
419                         pushd po > /dev/null || die
420                         for lang in *; do
421                                 if ! has ${lang} ${LINGUAS} ; then
422                                         if [[ ${lang} != CMakeLists.txt ]] ; then
423                                                 rm -rf ${lang}
424                                         fi
425                                         if [[ -e CMakeLists.txt ]] ; then
426                                                 comment_add_subdirectory ${lang}
427                                         fi
428                                 fi
429                         done
430                         popd > /dev/null || die
431                 fi
432
433                 if [[ ${KDE_HANDBOOK} != false && -d ${KDE_DOC_DIR} && ${CATEGORY} != kde-apps ]] ; then
434                         pushd ${KDE_DOC_DIR} > /dev/null || die
435                         for lang in *; do
436                                 if ! has ${lang} ${LINGUAS} ; then
437                                         comment_add_subdirectory ${lang}
438                                 fi
439                         done
440                         popd > /dev/null || die
441                 fi
442         else
443                 rm -rf po
444         fi
445
446         # in frameworks, tests = manual tests so never build them
447         if [[ ${CATEGORY} = kde-frameworks ]]; then
448                 comment_add_subdirectory tests
449         fi
450
451         case ${KDE_PUNT_BOGUS_DEPS} in
452                 false)  ;;
453                 *)
454                         if ! use_if_iuse test ; then
455                                 punt_bogus_dep Qt5 Test
456                         fi
457                         if ! use_if_iuse handbook ; then
458                                 punt_bogus_dep KF5 DocTools
459                         fi
460                         ;;
461         esac
462
463         # only build unit tests when required
464         if ! use_if_iuse test ; then
465                 if [[ ${KDE_TEST} = forceoptional ]] ; then
466                         punt_bogus_dep Qt5 Test
467                         # if forceoptional, also cover non-kde categories
468                         comment_add_subdirectory autotests
469                         comment_add_subdirectory test
470                         comment_add_subdirectory tests
471                 elif [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma || ${CATEGORY} = kde-apps ]] ; then
472                         comment_add_subdirectory autotests
473                         comment_add_subdirectory test
474                         comment_add_subdirectory tests
475                 fi
476         fi
477 }
478
479 # @FUNCTION: kde5_src_configure
480 # @DESCRIPTION:
481 # Function for configuring the build of KDE 5.
482 kde5_src_configure() {
483         debug-print-function ${FUNCNAME} "$@"
484
485         # we rely on cmake-utils.eclass to append -DNDEBUG too
486         if ! use_if_iuse debug; then
487                 append-cppflags -DQT_NO_DEBUG
488         fi
489
490         local cmakeargs
491
492         if ! use_if_iuse test ; then
493                 cmakeargs+=( -DBUILD_TESTING=OFF )
494         fi
495
496         # install mkspecs in the same directory as qt stuff
497         cmakeargs+=(-DKDE_INSTALL_USE_QT_SYS_PATHS=ON)
498
499         # allow the ebuild to override what we set here
500         mycmakeargs=("${cmakeargs[@]}" "${mycmakeargs[@]}")
501
502         cmake-utils_src_configure
503 }
504
505 # @FUNCTION: kde5_src_compile
506 # @DESCRIPTION:
507 # Function for compiling KDE 5.
508 kde5_src_compile() {
509         debug-print-function ${FUNCNAME} "$@"
510
511         cmake-utils_src_compile "$@"
512
513         # Build doxygen documentation if applicable
514         if use_if_iuse doc ; then
515                 kgenapidox ${KDE_DOX_DIR} || die
516         fi
517 }
518
519 # @FUNCTION: kde5_src_test
520 # @DESCRIPTION:
521 # Function for testing KDE 5.
522 kde5_src_test() {
523         debug-print-function ${FUNCNAME} "$@"
524
525         _test_runner() {
526                 if [[ -n "${VIRTUALDBUS_TEST}" ]]; then
527                         export $(dbus-launch)
528                 fi
529
530                 cmake-utils_src_test
531         }
532
533         # When run as normal user during ebuild development with the ebuild command, the
534         # kde tests tend to access the session DBUS. This however is not possible in a real
535         # emerge or on the tinderbox.
536         # > make sure it does not happen, so bad tests can be recognized and disabled
537         unset DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
538
539         if [[ ${VIRTUALX_REQUIRED} = always || ${VIRTUALX_REQUIRED} = test ]]; then
540                 VIRTUALX_COMMAND="_test_runner" virtualmake
541         else
542                 _test_runner
543         fi
544
545         if [[ -n "${DBUS_SESSION_BUS_PID}" ]] ; then
546                 kill ${DBUS_SESSION_BUS_PID}
547         fi
548 }
549
550 # @FUNCTION: kde5_src_install
551 # @DESCRIPTION:
552 # Function for installing KDE 5.
553 kde5_src_install() {
554         debug-print-function ${FUNCNAME} "$@"
555
556         # Install doxygen documentation if applicable
557         if use_if_iuse doc ; then
558                 dodoc -r apidocs/html
559         fi
560
561         cmake-utils_src_install
562
563         # We don't want ${PREFIX}/share/doc/HTML to be compressed,
564         # because then khelpcenter can't find the docs
565         if [[ -d ${ED}/${PREFIX}/share/doc/HTML ]]; then
566                 docompress -x ${PREFIX}/share/doc/HTML
567         fi
568 }
569
570 # @FUNCTION: kde5_pkg_preinst
571 # @DESCRIPTION:
572 # Function storing icon caches
573 kde5_pkg_preinst() {
574         debug-print-function ${FUNCNAME} "$@"
575
576         gnome2_icon_savelist
577 }
578
579 # @FUNCTION: kde5_pkg_postinst
580 # @DESCRIPTION:
581 # Function to rebuild the KDE System Configuration Cache after an application has been installed.
582 kde5_pkg_postinst() {
583         debug-print-function ${FUNCNAME} "$@"
584
585         gnome2_icon_cache_update
586         fdo-mime_desktop_database_update
587 }
588
589 # @FUNCTION: kde5_pkg_postrm
590 # @DESCRIPTION:
591 # Function to rebuild the KDE System Configuration Cache after an application has been removed.
592 kde5_pkg_postrm() {
593         debug-print-function ${FUNCNAME} "$@"
594
595         gnome2_icon_cache_update
596         fdo-mime_desktop_database_update
597 }
598
599 fi