kde5.eclass: Add KDE_PO_DIRS
[gentoo.git] / eclass / gnome2-utils.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: gnome2-utils.eclass
5 # @MAINTAINER:
6 # gnome@gentoo.org
7 # @BLURB: Auxiliary functions commonly used by Gnome packages.
8 # @DESCRIPTION:
9 # This eclass provides a set of auxiliary functions needed by most Gnome
10 # packages. It may be used by non-Gnome packages as needed for handling various
11 # Gnome stack related functions such as:
12 #  * Gtk+ icon cache management
13 #  * GSettings schemas management
14 #  * GConf schemas management
15 #  * scrollkeeper (old Gnome help system) management
16
17 [[ ${EAPI:-0} == [012345] ]] && inherit multilib
18 inherit eutils xdg-utils
19
20 case "${EAPI:-0}" in
21         0|1|2|3|4|5|6) ;;
22         *) die "EAPI=${EAPI} is not supported" ;;
23 esac
24
25 # @ECLASS-VARIABLE: GCONFTOOL_BIN
26 # @INTERNAL
27 # @DESCRIPTION:
28 # Path to gconftool-2
29 : ${GCONFTOOL_BIN:="/usr/bin/gconftool-2"}
30
31 # @ECLASS-VARIABLE: SCROLLKEEPER_DIR
32 # @INTERNAL
33 # @DESCRIPTION:
34 # Directory where scrollkeeper-update should do its work
35 : ${SCROLLKEEPER_DIR:="/var/lib/scrollkeeper"}
36
37 # @ECLASS-VARIABLE: SCROLLKEEPER_UPDATE_BIN
38 # @INTERNAL
39 # @DESCRIPTION:
40 # Path to scrollkeeper-update
41 : ${SCROLLKEEPER_UPDATE_BIN:="/usr/bin/scrollkeeper-update"}
42
43 # @ECLASS-VARIABLE: GTK_UPDATE_ICON_CACHE
44 # @INTERNAL
45 # @DESCRIPTION:
46 # Path to gtk-update-icon-cache
47 : ${GTK_UPDATE_ICON_CACHE:="/usr/bin/gtk-update-icon-cache"}
48
49 # @ECLASS-VARIABLE: GLIB_COMPILE_SCHEMAS
50 # @INTERNAL
51 # @DESCRIPTION:
52 # Path to glib-compile-schemas
53 : ${GLIB_COMPILE_SCHEMAS:="/usr/bin/glib-compile-schemas"}
54
55 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCHEMAS
56 # @INTERNAL
57 # @DEFAULT_UNSET
58 # @DESCRIPTION:
59 # List of GConf schemas provided by the package
60
61 # @ECLASS-VARIABLE: GNOME2_ECLASS_ICONS
62 # @INTERNAL
63 # @DEFAULT_UNSET
64 # @DESCRIPTION:
65 # List of icons provided by the package
66
67 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCROLLS
68 # @INTERNAL
69 # @DEFAULT_UNSET
70 # @DESCRIPTION:
71 # List of scrolls (documentation files) provided by the package
72
73 # @ECLASS-VARIABLE: GNOME2_ECLASS_GLIB_SCHEMAS
74 # @INTERNAL
75 # @DEFAULT_UNSET
76 # @DESCRIPTION:
77 # List of GSettings schemas provided by the package
78
79 # @ECLASS-VARIABLE: GNOME2_ECLASS_GDK_PIXBUF_LOADERS
80 # @INTERNAL
81 # @DEFAULT_UNSET
82 # @DESCRIPTION:
83 # List of gdk-pixbuf loaders provided by the package
84
85 DEPEND=">=sys-apps/sed-4"
86
87
88 # @FUNCTION: gnome2_environment_reset
89 # @DESCRIPTION:
90 # Reset various variables inherited from root's evironment to a reasonable
91 # default for ebuilds to help avoid access violations and test failures.
92 gnome2_environment_reset() {
93         xdg_environment_reset
94
95         # Respected by >=glib-2.30.1-r1
96         export G_HOME="${T}"
97
98         # GST_REGISTRY is to work around gst utilities trying to read/write /root
99         export GST_REGISTRY="${T}/registry.xml"
100
101         # Ensure we don't rely on dconf/gconf while building, bug #511946
102         export GSETTINGS_BACKEND="memory"
103
104         if has ${EAPI:-0} 6; then
105                 # Try to cover the packages honoring this variable, bug #508124
106                 export GST_INSPECT="$(type -P true)"
107
108                 # Stop relying on random DISPLAY variable values, bug #534312
109                 unset DISPLAY
110         fi
111 }
112
113 # @FUNCTION: gnome2_gconf_savelist
114 # @DESCRIPTION:
115 # Find the GConf schemas that are about to be installed and save their location
116 # in the GNOME2_ECLASS_SCHEMAS environment variable.
117 # This function should be called from pkg_preinst.
118 gnome2_gconf_savelist() {
119         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
120         pushd "${ED}" > /dev/null || die
121         export GNOME2_ECLASS_SCHEMAS=$(find 'etc/gconf/schemas/' -name '*.schemas' 2> /dev/null)
122         popd > /dev/null || die
123 }
124
125 # @FUNCTION: gnome2_gconf_install
126 # @DESCRIPTION:
127 # Applies any schema files installed by the current ebuild to Gconf's database
128 # using gconftool-2.
129 # This function should be called from pkg_postinst.
130 gnome2_gconf_install() {
131         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
132         local updater="${EROOT}${GCONFTOOL_BIN}"
133
134         if [[ ! -x "${updater}" ]]; then
135                 debug-print "${updater} is not executable"
136                 return
137         fi
138
139         if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
140                 debug-print "No GNOME 2 GConf schemas found"
141                 return
142         fi
143
144         # We are ready to install the GCONF Scheme now
145         unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
146         export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
147
148         einfo "Installing GNOME 2 GConf schemas"
149
150         local F
151         for F in ${GNOME2_ECLASS_SCHEMAS}; do
152                 if [[ -e "${EROOT}${F}" ]]; then
153                         debug-print "Installing schema: ${F}"
154                         "${updater}" --makefile-install-rule "${EROOT}${F}" 1>/dev/null
155                 fi
156         done
157
158         # have gconf reload the new schemas
159         pids=$(pgrep -x gconfd-2)
160         if [[ $? == 0 ]] ; then
161                 ebegin "Reloading GConf schemas"
162                 kill -HUP ${pids}
163                 eend $?
164         fi
165 }
166
167 # @FUNCTION: gnome2_gconf_uninstall
168 # @DESCRIPTION:
169 # Removes schema files previously installed by the current ebuild from Gconf's
170 # database.
171 gnome2_gconf_uninstall() {
172         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
173         local updater="${EROOT}${GCONFTOOL_BIN}"
174
175         if [[ ! -x "${updater}" ]]; then
176                 debug-print "${updater} is not executable"
177                 return
178         fi
179
180         if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
181                 debug-print "No GNOME 2 GConf schemas found"
182                 return
183         fi
184
185         unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
186         export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
187
188         einfo "Uninstalling GNOME 2 GConf schemas"
189
190         local F
191         for F in ${GNOME2_ECLASS_SCHEMAS}; do
192                 if [[ -e "${EROOT}${F}" ]]; then
193                         debug-print "Uninstalling gconf schema: ${F}"
194                         "${updater}" --makefile-uninstall-rule "${EROOT}${F}" 1>/dev/null
195                 fi
196         done
197
198         # have gconf reload the new schemas
199         pids=$(pgrep -x gconfd-2)
200         if [[ $? == 0 ]] ; then
201                 ebegin "Reloading GConf schemas"
202                 kill -HUP ${pids}
203                 eend $?
204         fi
205 }
206
207 # @FUNCTION: gnome2_icon_savelist
208 # @DESCRIPTION:
209 # Find the icons that are about to be installed and save their location
210 # in the GNOME2_ECLASS_ICONS environment variable.
211 # This function should be called from pkg_preinst.
212 gnome2_icon_savelist() {
213         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
214         pushd "${ED}" > /dev/null || die
215         export GNOME2_ECLASS_ICONS=$(find 'usr/share/icons' -maxdepth 1 -mindepth 1 -type d 2> /dev/null)
216         popd > /dev/null || die
217 }
218
219 # @FUNCTION: gnome2_icon_cache_update
220 # @DESCRIPTION:
221 # Updates Gtk+ icon cache files under /usr/share/icons if the current ebuild
222 # have installed anything under that location.
223 # This function should be called from pkg_postinst and pkg_postrm.
224 gnome2_icon_cache_update() {
225         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
226         local updater="${EROOT}${GTK_UPDATE_ICON_CACHE}"
227
228         if [[ ! -x "${updater}" ]] ; then
229                 debug-print "${updater} is not executable"
230                 return
231         fi
232
233         ebegin "Updating icons cache"
234
235         local retval=0
236         local fails=( )
237
238         for dir in "${EROOT%/}"/usr/share/icons/*
239         do
240                 if [[ -f "${dir}/index.theme" ]] ; then
241                         local rv=0
242
243                         "${updater}" -qf "${dir}"
244                         rv=$?
245
246                         if [[ ! $rv -eq 0 ]] ; then
247                                 debug-print "Updating cache failed on ${dir}"
248
249                                 # Add to the list of failures
250                                 fails+=( "${dir}" )
251
252                                 retval=2
253                         fi
254                 elif [[ $(ls "${dir}") = "icon-theme.cache" ]]; then
255                         # Clear stale cache files after theme uninstallation
256                         rm "${dir}/icon-theme.cache"
257                 fi
258
259                 if [[ -z $(ls "${dir}") ]]; then
260                         # Clear empty theme directories after theme uninstallation
261                         rmdir "${dir}"
262                 fi
263         done
264
265         eend ${retval}
266
267         for f in "${fails[@]}" ; do
268                 eerror "Failed to update cache with icon $f"
269         done
270 }
271
272 # @FUNCTION: gnome2_omf_fix
273 # @DESCRIPTION:
274 # Workaround applied to Makefile rules in order to remove redundant
275 # calls to scrollkeeper-update and sandbox violations.
276 # This function should be called from src_prepare.
277 gnome2_omf_fix() {
278         local omf_makefiles filename
279
280         omf_makefiles="$@"
281
282         if [[ -f ${S}/omf.make ]] ; then
283                 omf_makefiles="${omf_makefiles} ${S}/omf.make"
284         fi
285
286         if [[ -f ${S}/gnome-doc-utils.make ]] ; then
287                 omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make"
288         fi
289
290         # testing fixing of all makefiles found
291         # The sort is important to ensure .am is listed before the respective .in for
292         # maintainer mode regeneration not kicking in due to .am being newer than .in
293         for filename in $(find "${S}" -name "Makefile.in" -o -name "Makefile.am" |sort) ; do
294                 omf_makefiles="${omf_makefiles} ${filename}"
295         done
296
297         ebegin "Fixing OMF Makefiles"
298
299         local retval=0
300         local fails=( )
301
302         for omf in ${omf_makefiles} ; do
303                 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
304                 retval=$?
305
306                 if [[ $retval -ne 0 ]] ; then
307                         debug-print "updating of ${omf} failed"
308
309                         # Add to the list of failures
310                         fails[$(( ${#fails[@]} + 1 ))]=$omf
311
312                         retval=2
313                 fi
314         done
315
316         eend $retval
317
318         for f in "${fails[@]}" ; do
319                 eerror "Failed to update OMF Makefile $f"
320         done
321 }
322
323 # @FUNCTION: gnome2_scrollkeeper_savelist
324 # @DESCRIPTION:
325 # Find the scrolls that are about to be installed and save their location
326 # in the GNOME2_ECLASS_SCROLLS environment variable.
327 # This function should be called from pkg_preinst.
328 gnome2_scrollkeeper_savelist() {
329         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
330         pushd "${ED}" > /dev/null || die
331         export GNOME2_ECLASS_SCROLLS=$(find 'usr/share/omf' -type f -name "*.omf" 2> /dev/null)
332         popd > /dev/null || die
333 }
334
335 # @FUNCTION: gnome2_scrollkeeper_update
336 # @DESCRIPTION:
337 # Updates the global scrollkeeper database.
338 # This function should be called from pkg_postinst and pkg_postrm.
339 gnome2_scrollkeeper_update() {
340         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
341         local updater="${EROOT}${SCROLLKEEPER_UPDATE_BIN}"
342
343         if [[ ! -x "${updater}" ]] ; then
344                 debug-print "${updater} is not executable"
345                 return
346         fi
347
348         if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then
349                 debug-print "No scroll cache to update"
350                 return
351         fi
352
353         ebegin "Updating scrollkeeper database ..."
354         "${updater}" -q -p "${EROOT}${SCROLLKEEPER_DIR}"
355         eend $?
356 }
357
358 # @FUNCTION: gnome2_schemas_savelist
359 # @DESCRIPTION:
360 # Find if there is any GSettings schema to install and save the list in
361 # GNOME2_ECLASS_GLIB_SCHEMAS variable.
362 # This function should be called from pkg_preinst.
363 gnome2_schemas_savelist() {
364         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
365         pushd "${ED}" > /dev/null || die
366         export GNOME2_ECLASS_GLIB_SCHEMAS=$(find 'usr/share/glib-2.0/schemas' -name '*.gschema.xml' 2>/dev/null)
367         popd > /dev/null || die
368 }
369
370 # @FUNCTION: gnome2_schemas_update
371 # @USAGE: gnome2_schemas_update
372 # @DESCRIPTION:
373 # Updates GSettings schemas if GNOME2_ECLASS_GLIB_SCHEMAS has some.
374 # This function should be called from pkg_postinst and pkg_postrm.
375 gnome2_schemas_update() {
376         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
377         local updater="${EROOT}${GLIB_COMPILE_SCHEMAS}"
378
379         if [[ ! -x ${updater} ]]; then
380                 debug-print "${updater} is not executable"
381                 return
382         fi
383
384         ebegin "Updating GSettings schemas"
385         ${updater} --allow-any-name "$@" "${EROOT%/}/usr/share/glib-2.0/schemas" &>/dev/null
386         eend $?
387 }
388
389 # @FUNCTION: gnome2_gdk_pixbuf_savelist
390 # @DESCRIPTION:
391 # Find if there is any gdk-pixbuf loader to install and save the list in
392 # GNOME2_ECLASS_GDK_PIXBUF_LOADERS variable.
393 # This function should be called from pkg_preinst.
394 gnome2_gdk_pixbuf_savelist() {
395         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
396         pushd "${ED}" > /dev/null || die
397         export GNOME2_ECLASS_GDK_PIXBUF_LOADERS=$(find usr/lib*/gdk-pixbuf-2.0 -type f 2>/dev/null)
398         popd > /dev/null || die
399 }
400
401 # @FUNCTION: gnome2_gdk_pixbuf_update
402 # @USAGE: gnome2_gdk_pixbuf_update
403 # @DESCRIPTION:
404 # Updates gdk-pixbuf loader cache if GNOME2_ECLASS_GDK_PIXBUF_LOADERS has some.
405 # This function should be called from pkg_postinst and pkg_postrm.
406 gnome2_gdk_pixbuf_update() {
407         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
408         local updater="${EROOT}/usr/bin/${CHOST}-gdk-pixbuf-query-loaders"
409
410         if [[ ! -x ${updater} ]]; then
411                 updater="${EROOT}/usr/bin/gdk-pixbuf-query-loaders"
412         fi
413
414         if [[ ! -x ${updater} ]]; then
415                 debug-print "${updater} is not executable"
416                 return
417         fi
418
419         if [[ -z ${GNOME2_ECLASS_GDK_PIXBUF_LOADERS} ]]; then
420                 debug-print "gdk-pixbuf loader cache does not need an update"
421                 return
422         fi
423
424         ebegin "Updating gdk-pixbuf loader cache"
425         local tmp_file=$(emktemp)
426         ${updater} 1> "${tmp_file}" &&
427         chmod 0644 "${tmp_file}" &&
428         cp -f "${tmp_file}" "${EROOT}usr/$(get_libdir)/gdk-pixbuf-2.0/2.10.0/loaders.cache" &&
429         rm "${tmp_file}" # don't replace this with mv, required for SELinux support
430         eend $?
431 }
432
433 # @FUNCTION: gnome2_query_immodules_gtk2
434 # @USAGE: gnome2_query_immodules_gtk2
435 # @DESCRIPTION:
436 # Updates gtk2 immodules/gdk-pixbuf loaders listing.
437 gnome2_query_immodules_gtk2() {
438         local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-2.0
439         [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-2.0
440
441         ebegin "Updating gtk2 input method module cache"
442         GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-2.0/2.10.0/immodules.cache" \
443                 "${updater}" --update-cache
444         eend $?
445 }
446
447 # @FUNCTION: gnome2_query_immodules_gtk3
448 # @USAGE: gnome2_query_immodules_gtk3
449 # @DESCRIPTION:
450 # Updates gtk3 immodules/gdk-pixbuf loaders listing.
451 gnome2_query_immodules_gtk3() {
452         local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-3.0
453         [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-3.0
454
455         ebegin "Updating gtk3 input method module cache"
456         GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-3.0/3.0.0/immodules.cache" \
457                 "${updater}" --update-cache
458         eend $?
459 }
460
461 # @FUNCTION: gnome2_giomodule_cache_update
462 # @USAGE: gnome2_giomodule_cache_update
463 # @DESCRIPTION:
464 # Updates glib's gio modules cache.
465 # This function should be called from pkg_postinst and pkg_postrm.
466 gnome2_giomodule_cache_update() {
467         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
468         local updater="${EROOT}/usr/bin/${CHOST}-gio-querymodules"
469
470         if [[ ! -x ${updater} ]]; then
471                 updater="${EROOT}/usr/bin/gio-querymodules"
472         fi
473
474         if [[ ! -x ${updater} ]]; then
475                 debug-print "${updater} is not executable"
476                 return
477         fi
478
479         ebegin "Updating GIO modules cache"
480         ${updater} "${EROOT%/}"/usr/$(get_libdir)/gio/modules
481         eend $?
482 }
483
484 # @FUNCTION: gnome2_disable_deprecation_warning
485 # @DESCRIPTION:
486 # Disable deprecation warnings commonly found in glib based packages.
487 # Should be called from src_prepare.
488 gnome2_disable_deprecation_warning() {
489         local retval=0
490         local fails=( )
491         local makefile
492
493         ebegin "Disabling deprecation warnings"
494         # The sort is important to ensure .am is listed before the respective .in for
495         # maintainer mode regeneration not kicking in due to .am being newer than .in
496         while read makefile ; do
497                 if ! grep -qE "(DISABLE_DEPRECATED|GSEAL_ENABLE)" "${makefile}"; then
498                         continue
499                 fi
500
501                 LC_ALL=C sed -r -i \
502                         -e 's:-D[A-Z_]+_DISABLE_DEPRECATED:$(/bin/true):g' \
503                         -e 's:-DGSEAL_ENABLE(=[A-Za-z0-9_]*)?:$(/bin/true):g' \
504                         -i "${makefile}"
505
506                 if [[ $? -ne 0 ]]; then
507                         # Add to the list of failures
508                         fails+=( "${makefile}" )
509                         retval=2
510                 fi
511         done < <(find "${S}" -name "Makefile.in" \
512                 -o -name "Makefile.am" -o -name "Makefile.decl" \
513                 | sort; [[ -f "${S}"/configure ]] && echo configure)
514 # TODO: sedding configure.ac can trigger maintainer mode; bug #439602
515 #               -o -name "configure.ac" -o -name "configure.in" \
516 #               | sort; echo configure)
517         eend ${retval}
518
519         for makefile in "${fails[@]}" ; do
520                 ewarn "Failed to disable deprecation warnings in ${makefile}"
521         done
522 }