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