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