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