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