media-libs/portaudio: Version bump
[gentoo.git] / eclass / gnome2.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: gnome2.eclass
6 # @MAINTAINER:
7 # gnome@gentoo.org
8 # @BLURB: Provides phases for Gnome/Gtk+ based packages.
9 # @DESCRIPTION:
10 # Exports portage base functions used by ebuilds written for packages using the
11 # GNOME framework. For additional functions, see gnome2-utils.eclass.
12
13 # @ECLASS-VARIABLE: GNOME2_EAUTORECONF
14 # @DEFAULT_UNSET
15 # @DESCRIPTION:
16 # Run eautoreconf instead of only elibtoolize
17 GNOME2_EAUTORECONF=${GNOME2_EAUTORECONF:-""}
18
19 [[ ${GNOME2_EAUTORECONF} == 'yes' ]] && inherit autotools
20 inherit eutils libtool gnome.org gnome2-utils xdg
21
22 case "${EAPI:-0}" in
23         4|5)
24                 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install pkg_preinst pkg_postinst pkg_postrm
25                 ;;
26         6)
27                 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install pkg_preinst pkg_postinst pkg_postrm
28                 ;;
29         *) die "EAPI=${EAPI} is not supported" ;;
30 esac
31
32 # @ECLASS-VARIABLE: DOCS
33 # @DEFAULT_UNSET
34 # @DESCRIPTION:
35 # String containing documents passed to dodoc command for eapi4.
36 # In eapi5 we rely on einstalldocs (from eutils.eclass) and for newer EAPIs we
37 # follow PMS spec.
38
39 # @ECLASS-VARIABLE: ELTCONF
40 # @DEFAULT_UNSET
41 # @DESCRIPTION:
42 # Extra options passed to elibtoolize
43 ELTCONF=${ELTCONF:-""}
44
45 # @ECLASS-VARIABLE: G2CONF
46 # @DEFAULT_UNSET
47 # @DESCRIPTION:
48 # Extra configure opts passed to econf.
49 # Deprecated, pass extra arguments to gnome2_src_configure.
50 # Banned in eapi6 and newer.
51 if has ${EAPI:-0} 4 5; then
52         G2CONF=${G2CONF:-""}
53 fi
54
55 # @ECLASS-VARIABLE: GCONF_DEBUG
56 # @DEFAULT_UNSET
57 # @DESCRIPTION: 
58 # Whether to handle debug or not.
59 # Some gnome applications support various levels of debugging (yes, no, minimum,
60 # etc), but using --disable-debug also removes g_assert which makes debugging   
61 # harder. This variable should be set to yes for such packages for the eclass   
62 # to handle it properly. It will enable minimal debug with USE=-debug.
63 # Note that this is most commonly found in configure.ac as GNOME_DEBUG_CHECK.
64 #
65 # Banned since eapi6 as upstream is moving away from this obsolete macro in favor
66 # of autoconf-archive macros, that do not expose this issue (bug #270919)
67 if has ${EAPI:-0} 4 5; then
68         if [[ ${GCONF_DEBUG} != "no" ]]; then
69                 IUSE="debug"
70         fi
71 fi
72     
73 # @ECLASS-VARIABLE: GNOME2_ECLASS_GIO_MODULES
74 # @INTERNAL
75 # @DESCRIPTION:
76 # Array containing glib GIO modules
77
78 # @ECLASS-VARIABLE: GNOME2_LA_PUNT
79 # @DESCRIPTION:
80 # For eapi4 it sets if we should delete ALL or none of the .la files
81 # For eapi5 and newer it relies on prune_libtool_files (from eutils.eclass)
82 # for this. Available values for GNOME2_LA_PUNT:
83 # - "no": will not clean any .la files
84 # - "yes": will run prune_libtool_files --modules
85 # - If it is not set, it will run prune_libtool_files
86 if has ${EAPI:-0} 4; then
87         GNOME2_LA_PUNT=${GNOME2_LA_PUNT:-"no"}
88 else
89         GNOME2_LA_PUNT=${GNOME2_LA_PUNT:-""}
90 fi
91
92 # @FUNCTION: gnome2_src_unpack
93 # @DESCRIPTION:
94 # Stub function for old EAPI.
95 gnome2_src_unpack() {
96         if has ${EAPI:-0} 4 5; then
97                 unpack ${A}
98                 cd "${S}"
99         else
100                 die "gnome2_src_unpack is banned from eapi6"
101         fi
102 }
103
104 # @FUNCTION: gnome2_src_prepare
105 # @DESCRIPTION:
106 # Prepare environment for build, fix build of scrollkeeper documentation,
107 # run elibtoolize.
108 gnome2_src_prepare() {
109         xdg_src_prepare
110
111         # Prevent assorted access violations and test failures
112         gnome2_environment_reset
113
114         # Prevent scrollkeeper access violations
115         # We stop to run it from eapi6 as scrollkeeper helpers from
116         # rarian are not running anything and, then, access violations
117         # shouldn't occur.
118         has ${EAPI:-0} 4 5 && gnome2_omf_fix
119
120         # Disable all deprecation warnings
121         gnome2_disable_deprecation_warning
122
123         # Run libtoolize or eautoreconf, bug #591584
124         # https://bugzilla.gnome.org/show_bug.cgi?id=655517
125         if [[ ${GNOME2_EAUTORECONF} == 'yes' ]]; then
126                 eautoreconf
127         else
128                 elibtoolize ${ELTCONF}
129         fi
130 }
131
132 # @FUNCTION: gnome2_src_configure
133 # @DESCRIPTION:
134 # Gnome specific configure handling
135 gnome2_src_configure() {
136         # Deprecated for a long time now and banned since eapi6, see Gnome team policies
137         if [[ -n ${G2CONF} ]] ; then
138                 if has ${EAPI:-0} 4 5; then
139                         eqawarn "G2CONF set, please review documentation at https://wiki.gentoo.org/wiki/Project:GNOME/Gnome_Team_Ebuild_Policies#G2CONF_and_src_configure"
140                 else
141                         die "G2CONF set, please review documentation at https://wiki.gentoo.org/wiki/Project:GNOME/Gnome_Team_Ebuild_Policies#G2CONF_and_src_configure"
142                 fi
143         fi
144
145         local g2conf=()
146
147         if has ${EAPI:-0} 4 5; then
148                 if [[ ${GCONF_DEBUG} != 'no' ]] ; then
149                         if use debug ; then
150                                 g2conf+=( --enable-debug=yes )
151                         fi
152                 fi
153         else
154                 if [[ -n ${GCONF_DEBUG} ]] ; then
155                         die "GCONF_DEBUG is banned since eapi6 in favor of each ebuild taking care of the proper handling of debug configure option"
156                 fi
157         fi
158
159         # Starting with EAPI=5, we consider packages installing gtk-doc to be
160         # handled by adding DEPEND="dev-util/gtk-doc-am" which provides tools to
161         # relink URLs in documentation to already installed documentation.
162         # This decision also greatly helps with constantly broken doc generation.
163         # Remember to drop 'doc' USE flag from your package if it was only used to
164         # rebuild docs.
165         # Preserve old behavior for older EAPI.
166         if grep -q "enable-gtk-doc" "${ECONF_SOURCE:-.}"/configure ; then
167                 if has ${EAPI:-0} 4 && in_iuse doc ; then
168                         g2conf+=( $(use_enable doc gtk-doc) )
169                 else
170                         g2conf+=( --disable-gtk-doc )
171                 fi
172         fi
173
174         # Pass --disable-maintainer-mode when needed
175         if grep -q "^[[:space:]]*AM_MAINTAINER_MODE(\[enable\])" \
176                 "${ECONF_SOURCE:-.}"/configure.*; then
177                 g2conf+=( --disable-maintainer-mode )
178         fi
179
180         # Pass --disable-scrollkeeper when possible
181         if grep -q "disable-scrollkeeper" "${ECONF_SOURCE:-.}"/configure; then
182                 g2conf+=( --disable-scrollkeeper )
183         fi
184
185         # Pass --disable-silent-rules when possible (not needed since eapi5), bug #429308
186         if has ${EAPI:-0} 4; then
187                 if grep -q "disable-silent-rules" "${ECONF_SOURCE:-.}"/configure; then
188                         g2conf+=( --disable-silent-rules )
189                 fi
190         fi
191
192         # Pass --disable-schemas-install when possible
193         if grep -q "disable-schemas-install" "${ECONF_SOURCE:-.}"/configure; then
194                 g2conf+=( --disable-schemas-install )
195         fi
196
197         # Pass --disable-schemas-compile when possible
198         if grep -q "disable-schemas-compile" "${ECONF_SOURCE:-.}"/configure; then
199                 g2conf+=( --disable-schemas-compile )
200         fi
201
202         # Pass --disable-update-mimedb when possible
203         if grep -q "disable-update-mimedb" "${ECONF_SOURCE:-.}"/configure; then
204                 g2conf+=( --disable-update-mimedb )
205         fi
206
207         # Pass --enable-compile-warnings=minimum as we don't want -Werror* flags, bug #471336
208         if grep -q "enable-compile-warnings" "${ECONF_SOURCE:-.}"/configure; then
209                 g2conf+=( --enable-compile-warnings=minimum )
210         fi
211
212         # Pass --docdir with proper directory, bug #482646 (not needed since eapi6)
213         if has ${EAPI:-0} 4 5; then
214                 if grep -q "^ *--docdir=" "${ECONF_SOURCE:-.}"/configure; then
215                         g2conf+=( --docdir="${EPREFIX}"/usr/share/doc/${PF} )
216                 fi
217         fi
218
219         # Avoid sandbox violations caused by gnome-vfs (bug #128289 and #345659)
220         if has ${EAPI:-0} 4 5; then
221                 addwrite "$(unset HOME; echo ~)/.gnome2"
222         else
223                 addpredict "$(unset HOME; echo ~)/.gnome2"
224         fi
225
226         if has ${EAPI:-0} 4 5; then
227                 econf ${g2conf[@]} ${G2CONF} "$@"
228         else
229                 econf ${g2conf[@]} "$@"
230         fi
231 }
232
233 # @FUNCTION: gnome2_src_compile
234 # @DESCRIPTION:
235 # Only default src_compile for now
236 gnome2_src_compile() {
237         if has ${EAPI:-0} 4 5; then
238                 emake
239         else
240                 default
241         fi
242 }
243
244 # @FUNCTION: gnome2_src_install
245 # @DESCRIPTION:
246 # Gnome specific install. Handles typical GConf and scrollkeeper setup
247 # in packages and removal of .la files if requested
248 gnome2_src_install() {
249         # we must delay gconf schema installation due to sandbox
250         export GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL="1"
251
252         local sk_tmp_dir="/var/lib/scrollkeeper"
253         # scrollkeeper-update from rarian doesn't do anything. Then, since eapi6
254         # we stop taking care of it
255         #
256         # if this is not present, scrollkeeper-update may segfault and
257         # create bogus directories in /var/lib/
258         if has ${EAPI:-0} 4 5; then
259                 dodir "${sk_tmp_dir}" || die "dodir failed"
260                 emake DESTDIR="${D}" "scrollkeeper_localstate_dir=${ED}${sk_tmp_dir} " "$@" install || die "install failed"
261         else
262                 default
263         fi
264
265         unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
266
267         # Handle documentation as 'default' for eapi5, bug #373131
268         # Since eapi6 this is handled by default on its own plus MAINTAINERS and HACKING
269         # files that are really common in gnome packages (bug #573390)
270         if has ${EAPI:-0} 4; then
271                 # Manual document installation
272                 if [[ -n "${DOCS}" ]]; then
273                         dodoc ${DOCS} || die "dodoc failed"
274                 fi
275         elif has ${EAPI:-0} 5; then
276                 einstalldocs
277         else
278                 local d
279                 for d in HACKING MAINTAINERS; do
280                         [[ -s "${d}" ]] && dodoc "${d}"
281                 done
282         fi
283
284         # Do not keep /var/lib/scrollkeeper because:
285         # 1. The scrollkeeper database is regenerated at pkg_postinst()
286         # 2. ${ED}/var/lib/scrollkeeper contains only indexes for the current pkg
287         #    thus it makes no sense if pkg_postinst ISN'T run for some reason.
288         rm -rf "${ED}${sk_tmp_dir}"
289         rmdir "${ED}/var/lib" 2>/dev/null
290         rmdir "${ED}/var" 2>/dev/null
291
292         # Make sure this one doesn't get in the portage db
293         rm -fr "${ED}/usr/share/applications/mimeinfo.cache"
294
295         # Delete all .la files
296         if has ${EAPI:-0} 4; then
297                 if [[ "${GNOME2_LA_PUNT}" != "no" ]]; then
298                         ebegin "Removing .la files"
299                         if ! use_if_iuse static-libs ; then
300                                 find "${D}" -name '*.la' -exec rm -f {} + || die "la file removal failed"
301                         fi
302                         eend
303                 fi
304         else
305                 case "${GNOME2_LA_PUNT}" in
306                         yes)    prune_libtool_files --modules;;
307                         no)     ;;
308                         *)      prune_libtool_files;;
309                 esac
310         fi
311 }
312
313 # @FUNCTION: gnome2_pkg_preinst
314 # @DESCRIPTION:
315 # Finds Icons, GConf and GSettings schemas for later handling in pkg_postinst
316 gnome2_pkg_preinst() {
317         xdg_pkg_preinst
318         gnome2_gconf_savelist
319         gnome2_icon_savelist
320         gnome2_schemas_savelist
321         gnome2_scrollkeeper_savelist
322         gnome2_gdk_pixbuf_savelist
323
324         local f
325
326         GNOME2_ECLASS_GIO_MODULES=()
327         while IFS= read -r -d '' f; do
328                 GNOME2_ECLASS_GIO_MODULES+=( ${f} )
329         done < <(cd "${D}" && find usr/$(get_libdir)/gio/modules -type f -print0 2>/dev/null)
330
331         export GNOME2_ECLASS_GIO_MODULES
332 }
333
334 # @FUNCTION: gnome2_pkg_postinst
335 # @DESCRIPTION:
336 # Handle scrollkeeper, GConf, GSettings, Icons, desktop and mime
337 # database updates.
338 gnome2_pkg_postinst() {
339         xdg_pkg_postinst
340         gnome2_gconf_install
341         gnome2_icon_cache_update
342         gnome2_schemas_update
343         gnome2_scrollkeeper_update
344         gnome2_gdk_pixbuf_update
345
346         if [[ ${#GNOME2_ECLASS_GIO_MODULES[@]} -gt 0 ]]; then
347                 gnome2_giomodule_cache_update
348         fi
349 }
350
351 # # FIXME Handle GConf schemas removal
352 #gnome2_pkg_prerm() {
353 #       gnome2_gconf_uninstall
354 #}
355
356 # @FUNCTION: gnome2_pkg_postrm
357 # @DESCRIPTION:
358 # Handle scrollkeeper, GSettings, Icons, desktop and mime database updates.
359 gnome2_pkg_postrm() {
360         xdg_pkg_postrm
361         gnome2_icon_cache_update
362         gnome2_schemas_update
363         gnome2_scrollkeeper_update
364
365         if [[ ${#GNOME2_ECLASS_GIO_MODULES[@]} -gt 0 ]]; then
366                 gnome2_giomodule_cache_update
367         fi
368 }