Merge github#920: app-arch/zopfli: Version bump 1.0.1.
[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 inherit eutils libtool gnome.org gnome2-utils xdg
14
15 case "${EAPI:-0}" in
16         4|5)
17                 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install pkg_preinst pkg_postinst pkg_postrm
18                 ;;
19         *) die "EAPI=${EAPI} is not supported" ;;
20 esac
21
22 # @ECLASS-VARIABLE: G2CONF
23 # @DEFAULT_UNSET
24 # @DESCRIPTION:
25 # Extra configure opts passed to econf.
26 # Deprecated, pass extra arguments to gnome2_src_configure.
27 G2CONF=${G2CONF:-""}
28
29 # @ECLASS-VARIABLE: GNOME2_LA_PUNT
30 # @DESCRIPTION:
31 # Should we delete ALL the .la files?
32 # NOT to be used without due consideration.
33 if has ${EAPI:-0} 4; then
34         GNOME2_LA_PUNT=${GNOME2_LA_PUNT:-"no"}
35 else
36         GNOME2_LA_PUNT=${GNOME2_LA_PUNT:-""}
37 fi
38
39 # @ECLASS-VARIABLE: ELTCONF
40 # @DEFAULT_UNSET
41 # @DESCRIPTION:
42 # Extra options passed to elibtoolize
43 ELTCONF=${ELTCONF:-""}
44
45 # @ECLASS-VARIABLE: DOCS
46 # @DEFAULT_UNSET
47 # @DESCRIPTION:
48 # String containing documents passed to dodoc command.
49
50 # @ECLASS-VARIABLE: GCONF_DEBUG
51 # @DEFAULT_UNSET
52 # @DESCRIPTION:
53 # Whether to handle debug or not.
54 # Some gnome applications support various levels of debugging (yes, no, minimum,
55 # etc), but using --disable-debug also removes g_assert which makes debugging
56 # harder. This variable should be set to yes for such packages for the eclass
57 # to handle it properly. It will enable minimal debug with USE=-debug.
58 # Note that this is most commonly found in configure.ac as GNOME_DEBUG_CHECK.
59
60 # @ECLASS-VARIABLE: GNOME2_ECLASS_GIO_MODULES
61 # @INTERNAL
62 # @DESCRIPTION:
63 # Array containing glib GIO modules
64
65 if [[ ${GCONF_DEBUG} != "no" ]]; then
66         IUSE="debug"
67 fi
68
69 # @FUNCTION: gnome2_src_unpack
70 # @DESCRIPTION:
71 # Stub function for old EAPI.
72 gnome2_src_unpack() {
73         unpack ${A}
74         cd "${S}"
75 }
76
77 # @FUNCTION: gnome2_src_prepare
78 # @DESCRIPTION:
79 # Prepare environment for build, fix build of scrollkeeper documentation,
80 # run elibtoolize.
81 gnome2_src_prepare() {
82         xdg_src_prepare
83
84         # Prevent assorted access violations and test failures
85         gnome2_environment_reset
86
87         # Prevent scrollkeeper access violations
88         gnome2_omf_fix
89
90         # Disable all deprecation warnings
91         gnome2_disable_deprecation_warning
92
93         # Run libtoolize
94         # https://bugzilla.gnome.org/show_bug.cgi?id=655517
95         elibtoolize ${ELTCONF}
96 }
97
98 # @FUNCTION: gnome2_src_configure
99 # @DESCRIPTION:
100 # Gnome specific configure handling
101 gnome2_src_configure() {
102         # Deprecated for a long time now, see Gnome team policies
103         if [[ -n ${G2CONF} ]] ; then
104                 eqawarn "G2CONF set, please review documentation at https://wiki.gentoo.org/wiki/Project:GNOME/Gnome_Team_Ebuild_Policies#G2CONF_and_src_configure"
105         fi
106
107         local g2conf=()
108
109         # Update the GNOME configuration options
110         if [[ ${GCONF_DEBUG} != 'no' ]] ; then
111                 if use debug ; then
112                         g2conf+=( --enable-debug=yes )
113                 fi
114         fi
115
116         # Starting with EAPI=5, we consider packages installing gtk-doc to be
117         # handled by adding DEPEND="dev-util/gtk-doc-am" which provides tools to
118         # relink URLs in documentation to already installed documentation.
119         # This decision also greatly helps with constantly broken doc generation.
120         # Remember to drop 'doc' USE flag from your package if it was only used to
121         # rebuild docs.
122         # Preserve old behavior for older EAPI.
123         if grep -q "enable-gtk-doc" "${ECONF_SOURCE:-.}"/configure ; then
124                 if has ${EAPI:-0} 4 && in_iuse doc ; then
125                         g2conf+=( $(use_enable doc gtk-doc) )
126                 else
127                         g2conf+=( --disable-gtk-doc )
128                 fi
129         fi
130
131         # Pass --disable-maintainer-mode when needed
132         if grep -q "^[[:space:]]*AM_MAINTAINER_MODE(\[enable\])" \
133                 "${ECONF_SOURCE:-.}"/configure.*; then
134                 g2conf+=( --disable-maintainer-mode )
135         fi
136
137         # Pass --disable-scrollkeeper when possible
138         if grep -q "disable-scrollkeeper" "${ECONF_SOURCE:-.}"/configure; then
139                 g2conf+=( --disable-scrollkeeper )
140         fi
141
142         # Pass --disable-silent-rules when possible (not needed for eapi5), bug #429308
143         if has ${EAPI:-0} 4; then
144                 if grep -q "disable-silent-rules" "${ECONF_SOURCE:-.}"/configure; then
145                         g2conf+=( --disable-silent-rules )
146                 fi
147         fi
148
149         # Pass --disable-schemas-install when possible
150         if grep -q "disable-schemas-install" "${ECONF_SOURCE:-.}"/configure; then
151                 g2conf+=( --disable-schemas-install )
152         fi
153
154         # Pass --disable-schemas-compile when possible
155         if grep -q "disable-schemas-compile" "${ECONF_SOURCE:-.}"/configure; then
156                 g2conf+=( --disable-schemas-compile )
157         fi
158
159         # Pass --disable-update-mimedb when possible
160         if grep -q "disable-update-mimedb" "${ECONF_SOURCE:-.}"/configure; then
161                 g2conf+=( --disable-update-mimedb )
162         fi
163
164         # Pass --enable-compile-warnings=minimum as we don't want -Werror* flags, bug #471336
165         if grep -q "enable-compile-warnings" "${ECONF_SOURCE:-.}"/configure; then
166                 g2conf+=( --enable-compile-warnings=minimum )
167         fi
168
169         # Pass --docdir with proper directory, bug #482646
170         if grep -q "^ *--docdir=" "${ECONF_SOURCE:-.}"/configure; then
171                 g2conf+=( --docdir="${EPREFIX}"/usr/share/doc/${PF} )
172         fi
173
174         # Avoid sandbox violations caused by gnome-vfs (bug #128289 and #345659)
175         addwrite "$(unset HOME; echo ~)/.gnome2"
176
177         econf ${g2conf[@]} ${G2CONF} "$@"
178 }
179
180 # @FUNCTION: gnome2_src_compile
181 # @DESCRIPTION:
182 # Only default src_compile for now
183 gnome2_src_compile() {
184         emake
185 }
186
187 # @FUNCTION: gnome2_src_install
188 # @DESCRIPTION:
189 # Gnome specific install. Handles typical GConf and scrollkeeper setup
190 # in packages and removal of .la files if requested
191 gnome2_src_install() {
192         # if this is not present, scrollkeeper-update may segfault and
193         # create bogus directories in /var/lib/
194         local sk_tmp_dir="/var/lib/scrollkeeper"
195         dodir "${sk_tmp_dir}" || die "dodir failed"
196
197         # we must delay gconf schema installation due to sandbox
198         export GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL="1"
199
200         debug-print "Installing with 'make install'"
201         emake DESTDIR="${D}" "scrollkeeper_localstate_dir=${ED}${sk_tmp_dir} " "$@" install || die "install failed"
202
203         unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
204
205         # Handle documentation as 'default' for eapi5 and newer, bug #373131
206         if has ${EAPI:-0} 4; then
207                 # Manual document installation
208                 if [[ -n "${DOCS}" ]]; then
209                         dodoc ${DOCS} || die "dodoc failed"
210                 fi
211         else
212                 einstalldocs
213         fi
214
215         # Do not keep /var/lib/scrollkeeper because:
216         # 1. The scrollkeeper database is regenerated at pkg_postinst()
217         # 2. ${ED}/var/lib/scrollkeeper contains only indexes for the current pkg
218         #    thus it makes no sense if pkg_postinst ISN'T run for some reason.
219         rm -rf "${ED}${sk_tmp_dir}"
220         rmdir "${ED}/var/lib" 2>/dev/null
221         rmdir "${ED}/var" 2>/dev/null
222
223         # Make sure this one doesn't get in the portage db
224         rm -fr "${ED}/usr/share/applications/mimeinfo.cache"
225
226         # Delete all .la files
227         if has ${EAPI:-0} 4; then
228                 if [[ "${GNOME2_LA_PUNT}" != "no" ]]; then
229                         ebegin "Removing .la files"
230                         if ! use_if_iuse static-libs ; then
231                                 find "${D}" -name '*.la' -exec rm -f {} + || die "la file removal failed"
232                         fi
233                         eend
234                 fi
235         else
236                 case "${GNOME2_LA_PUNT}" in
237                         yes)    prune_libtool_files --modules;;
238                         no)     ;;
239                         *)      prune_libtool_files;;
240                 esac
241         fi
242 }
243
244 # @FUNCTION: gnome2_pkg_preinst
245 # @DESCRIPTION:
246 # Finds Icons, GConf and GSettings schemas for later handling in pkg_postinst
247 gnome2_pkg_preinst() {
248         xdg_pkg_preinst
249         gnome2_gconf_savelist
250         gnome2_icon_savelist
251         gnome2_schemas_savelist
252         gnome2_scrollkeeper_savelist
253         gnome2_gdk_pixbuf_savelist
254
255         local f
256
257         GNOME2_ECLASS_GIO_MODULES=()
258         while IFS= read -r -d '' f; do
259                 GNOME2_ECLASS_GIO_MODULES+=( ${f} )
260         done < <(cd "${D}" && find usr/$(get_libdir)/gio/modules -type f -print0 2>/dev/null)
261
262         export GNOME2_ECLASS_GIO_MODULES
263 }
264
265 # @FUNCTION: gnome2_pkg_postinst
266 # @DESCRIPTION:
267 # Handle scrollkeeper, GConf, GSettings, Icons, desktop and mime
268 # database updates.
269 gnome2_pkg_postinst() {
270         xdg_pkg_postinst
271         gnome2_gconf_install
272         gnome2_icon_cache_update
273         gnome2_schemas_update
274         gnome2_scrollkeeper_update
275         gnome2_gdk_pixbuf_update
276
277         if [[ ${#GNOME2_ECLASS_GIO_MODULES[@]} -gt 0 ]]; then
278                 gnome2_giomodule_cache_update
279         fi
280 }
281
282 # # FIXME Handle GConf schemas removal
283 #gnome2_pkg_prerm() {
284 #       gnome2_gconf_uninstall
285 #}
286
287 # @FUNCTION: gnome2_pkg_postrm
288 # @DESCRIPTION:
289 # Handle scrollkeeper, GSettings, Icons, desktop and mime database updates.
290 gnome2_pkg_postrm() {
291         xdg_pkg_postrm
292         gnome2_icon_cache_update
293         gnome2_schemas_update
294         gnome2_scrollkeeper_update
295
296         if [[ ${#GNOME2_ECLASS_GIO_MODULES[@]} -gt 0 ]]; then
297                 gnome2_giomodule_cache_update
298         fi
299 }