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