/[gentoo-x86]/eclass/autotools-utils.eclass
Gentoo

Contents of /eclass/autotools-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.35 - (hide annotations) (download)
Sat Jan 14 14:50:05 2012 UTC (2 years, 9 months ago) by mgorny
Branch: MAIN
Changes since 1.34: +22 -2 lines
Pass --docdir to configure, and install docs from it; wrt bug #350423.

1 mgorny 1.32 # Copyright 1999-2012 Gentoo Foundation
2 reavertm 1.1 # Distributed under the terms of the GNU General Public License v2
3 mgorny 1.35 # $Header: /var/cvsroot/gentoo-x86/eclass/autotools-utils.eclass,v 1.34 2012/01/14 14:41:10 mgorny Exp $
4 reavertm 1.1
5     # @ECLASS: autotools-utils.eclass
6     # @MAINTAINER:
7     # Maciej Mrozowski <reavertm@gentoo.org>
8 reavertm 1.10 # Michał Górny <mgorny@gentoo.org>
9 reavertm 1.1 # @BLURB: common ebuild functions for autotools-based packages
10     # @DESCRIPTION:
11     # autotools-utils.eclass is autotools.eclass(5) and base.eclass(5) wrapper
12     # providing all inherited features along with econf arguments as Bash array,
13     # out of source build with overridable build dir location, static archives
14 mgorny 1.28 # handling, libtool files removal.
15     #
16     # Please note note that autotools-utils does not support mixing of its phase
17     # functions with regular econf/emake calls. If necessary, please call
18     # autotools-utils_src_compile instead of the latter.
19 reavertm 1.1 #
20     # @EXAMPLE:
21     # Typical ebuild using autotools-utils.eclass:
22     #
23     # @CODE
24     # EAPI="2"
25     #
26     # inherit autotools-utils
27     #
28     # DESCRIPTION="Foo bar application"
29     # HOMEPAGE="http://example.org/foo/"
30     # SRC_URI="mirror://sourceforge/foo/${P}.tar.bz2"
31     #
32     # LICENSE="LGPL-2.1"
33     # KEYWORDS=""
34     # SLOT="0"
35     # IUSE="debug doc examples qt4 static-libs tiff"
36     #
37     # CDEPEND="
38     # media-libs/libpng:0
39     # qt4? (
40     # x11-libs/qt-core:4
41     # x11-libs/qt-gui:4
42     # )
43     # tiff? ( media-libs/tiff:0 )
44     # "
45     # RDEPEND="${CDEPEND}
46     # !media-gfx/bar
47     # "
48     # DEPEND="${CDEPEND}
49     # doc? ( app-doc/doxygen )
50     # "
51     #
52     # # bug 123456
53     # AUTOTOOLS_IN_SOURCE_BUILD=1
54     #
55     # DOCS=(AUTHORS ChangeLog README "Read me.txt" TODO)
56     #
57     # PATCHES=(
58     # "${FILESDIR}/${P}-gcc44.patch" # bug 123458
59     # "${FILESDIR}/${P}-as-needed.patch"
60     # "${FILESDIR}/${P}-unbundle_libpng.patch"
61     # )
62     #
63     # src_configure() {
64 reavertm 1.6 # local myeconfargs=(
65 mgorny 1.23 # $(use_enable debug)
66 reavertm 1.1 # $(use_with qt4)
67     # $(use_enable threads multithreading)
68     # $(use_with tiff)
69     # )
70     # autotools-utils_src_configure
71     # }
72     #
73     # src_compile() {
74     # autotools-utils_src_compile
75     # use doc && autotools-utils_src_compile docs
76     # }
77     #
78     # src_install() {
79     # use doc && HTML_DOCS=("${AUTOTOOLS_BUILD_DIR}/apidocs/html/")
80     # autotools-utils_src_install
81     # if use examples; then
82     # dobin "${AUTOTOOLS_BUILD_DIR}"/foo_example{1,2,3} \\
83     # || die 'dobin examples failed'
84     # fi
85     # }
86     #
87     # @CODE
88    
89     # Keep variable names synced with cmake-utils and the other way around!
90    
91     case ${EAPI:-0} in
92 scarabeus 1.8 2|3|4) ;;
93 reavertm 1.2 *) die "EAPI=${EAPI} is not supported" ;;
94 reavertm 1.1 esac
95    
96 mgorny 1.32 # @ECLASS-VARIABLE: AUTOTOOLS_AUTORECONF
97 jlec 1.33 # @DEFAULT_UNSET
98 mgorny 1.32 # @DESCRIPTION:
99     # Set to a non-empty value in order to enable running autoreconf
100     # in src_prepare() and adding autotools dependencies.
101     #
102     # The eclass will try to determine the correct autotools to run including a few
103     # external tools: gettext, glib-gettext, intltool, gtk-doc, gnome-doc-prepare.
104     # If your tool is not supported, please open a bug and we'll add support for it.
105     #
106     # Note that dependencies are added for autoconf, automake and libtool only.
107     # If your package needs one of the external tools listed above, you need to add
108     # appropriate packages to DEPEND yourself.
109     [[ ${AUTOTOOLS_AUTORECONF} ]] || _autotools_auto_dep=no
110    
111     AUTOTOOLS_AUTO_DEPEND=${_autotools_auto_dep} \
112 mgorny 1.30 inherit autotools eutils libtool
113 reavertm 1.1
114     EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test
115    
116 mgorny 1.32 unset _autotools_auto_dep
117    
118 reavertm 1.1 # @ECLASS-VARIABLE: AUTOTOOLS_BUILD_DIR
119 mgorny 1.30 # @DEFAULT_UNSET
120 reavertm 1.1 # @DESCRIPTION:
121     # Build directory, location where all autotools generated files should be
122     # placed. For out of source builds it defaults to ${WORKDIR}/${P}_build.
123    
124     # @ECLASS-VARIABLE: AUTOTOOLS_IN_SOURCE_BUILD
125 mgorny 1.30 # @DEFAULT_UNSET
126 reavertm 1.1 # @DESCRIPTION:
127     # Set to enable in-source build.
128    
129     # @ECLASS-VARIABLE: ECONF_SOURCE
130 mgorny 1.30 # @DEFAULT_UNSET
131 reavertm 1.1 # @DESCRIPTION:
132     # Specify location of autotools' configure script. By default it uses ${S}.
133    
134     # @ECLASS-VARIABLE: myeconfargs
135 mgorny 1.30 # @DEFAULT_UNSET
136 reavertm 1.1 # @DESCRIPTION:
137     # Optional econf arguments as Bash array. Should be defined before calling src_configure.
138     # @CODE
139     # src_configure() {
140 reavertm 1.7 # local myeconfargs=(
141 reavertm 1.1 # --disable-readline
142     # --with-confdir="/etc/nasty foo confdir/"
143     # $(use_enable debug cnddebug)
144     # $(use_enable threads multithreading)
145     # )
146     # autotools-utils_src_configure
147     # }
148     # @CODE
149    
150 mgorny 1.30 # @ECLASS-VARIABLE: DOCS
151     # @DEFAULT_UNSET
152     # @DESCRIPTION:
153     # Array containing documents passed to dodoc command.
154     #
155     # Example:
156     # @CODE
157     # DOCS=( NEWS README )
158     # @CODE
159    
160     # @ECLASS-VARIABLE: HTML_DOCS
161     # @DEFAULT_UNSET
162     # @DESCRIPTION:
163     # Array containing documents passed to dohtml command.
164     #
165     # Example:
166     # @CODE
167     # HTML_DOCS=( doc/html/ )
168     # @CODE
169    
170     # @ECLASS-VARIABLE: PATCHES
171     # @DEFAULT_UNSET
172     # @DESCRIPTION:
173     # PATCHES array variable containing all various patches to be applied.
174     #
175     # Example:
176     # @CODE
177     # PATCHES=( "${FILESDIR}"/${P}-mypatch.patch )
178     # @CODE
179    
180 reavertm 1.1 # Determine using IN or OUT source build
181     _check_build_dir() {
182     : ${ECONF_SOURCE:=${S}}
183     if [[ -n ${AUTOTOOLS_IN_SOURCE_BUILD} ]]; then
184     AUTOTOOLS_BUILD_DIR="${ECONF_SOURCE}"
185     else
186     : ${AUTOTOOLS_BUILD_DIR:=${WORKDIR}/${P}_build}
187     fi
188     echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\""
189     }
190    
191     # @FUNCTION: remove_libtool_files
192 mgorny 1.14 # @USAGE: [all]
193 reavertm 1.1 # @DESCRIPTION:
194     # Determines unnecessary libtool files (.la) and libtool static archives (.a)
195     # and removes them from installation image.
196 mgorny 1.14 #
197 reavertm 1.1 # To unconditionally remove all libtool files, pass 'all' as argument.
198 mgorny 1.14 # Otherwise, libtool archives required for static linking will be preserved.
199 reavertm 1.1 #
200     # In most cases it's not necessary to manually invoke this function.
201     # See autotools-utils_src_install for reference.
202     remove_libtool_files() {
203     debug-print-function ${FUNCNAME} "$@"
204 mgorny 1.16 local removing_all
205     [[ ${#} -le 1 ]] || die "Invalid number of args to ${FUNCNAME}()"
206     if [[ ${#} -eq 1 ]]; then
207     case "${1}" in
208     all)
209     removing_all=1
210     ;;
211     *)
212     die "Invalid argument to ${FUNCNAME}(): ${1}"
213     esac
214     fi
215 reavertm 1.1
216 mgorny 1.19 local pc_libs=()
217     if [[ ! ${removing_all} ]]; then
218     local arg
219     for arg in $(find "${D}" -name '*.pc' -exec \
220     sed -n -e 's;^Libs:;;p' {} +); do
221     [[ ${arg} == -l* ]] && pc_libs+=(lib${arg#-l}.la)
222     done
223     fi
224    
225 reavertm 1.1 local f
226 mgorny 1.12 find "${D}" -type f -name '*.la' -print0 | while read -r -d '' f; do
227 reavertm 1.1 local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}")
228 mgorny 1.14 local archivefile=${f/%.la/.a}
229 mgorny 1.15 [[ "${f}" != "${archivefile}" ]] || die 'regex sanity check failed'
230 mgorny 1.14
231 mgorny 1.18 # Remove static libs we're not supposed to link against.
232 mgorny 1.17 if [[ ${shouldnotlink} ]]; then
233     einfo "Removing unnecessary ${archivefile#${D%/}}"
234     rm -f "${archivefile}" || die
235 mgorny 1.18 # The .la file may be used by a module loader, so avoid removing it
236     # unless explicitly requested.
237 mgorny 1.17 [[ ${removing_all} ]] || continue
238     fi
239    
240 mgorny 1.18 # Remove .la files when:
241     # - user explicitly wants us to remove all .la files,
242     # - respective static archive doesn't exist,
243 mgorny 1.19 # - they are covered by a .pc file already,
244 mgorny 1.18 # - they don't provide any new information (no libs & no flags).
245     local removing
246 mgorny 1.20 if [[ ${removing_all} ]]; then removing='forced'
247     elif [[ ! -f ${archivefile} ]]; then removing='no static archive'
248     elif has "$(basename "${f}")" "${pc_libs[@]}"; then
249     removing='covered by .pc'
250 mgorny 1.18 elif [[ ! $(sed -n -e \
251     "s/^\(dependency_libs\|inherited_linker_flags\)='\(.*\)'$/\2/p" \
252 mgorny 1.20 "${f}") ]]; then removing='no libs & flags'
253 mgorny 1.18 fi
254    
255     if [[ ${removing} ]]; then
256 mgorny 1.20 einfo "Removing unnecessary ${f#${D%/}} (${removing})"
257 mgorny 1.15 rm -f "${f}" || die
258 reavertm 1.1 fi
259     done
260 mgorny 1.29
261     # check for invalid eclass use
262     # this is the most commonly used function, so do it here
263     _check_build_dir
264     if [[ ! -d "${AUTOTOOLS_BUILD_DIR}" ]]; then
265     eqawarn "autotools-utils used but autotools-utils_src_configure was never called."
266     eqawarn "This is not supported and never was. Please report a bug against"
267     eqawarn "the offending ebuild. This will become a fatal error in a near future."
268     fi
269 reavertm 1.1 }
270    
271 mgorny 1.32 # @FUNCTION: autotools-utils_autoreconf
272     # @DESCRIPTION:
273     # Reconfigure the sources (like gnome-autogen.sh or eautoreconf).
274     autotools-utils_autoreconf() {
275     debug-print-function ${FUNCNAME} "$@"
276    
277     # Override this func to not require unnecessary eaclocal calls.
278     autotools_check_macro() {
279     local x
280    
281     # Add a few additional variants as we don't get expansions.
282     [[ ${1} = AC_CONFIG_HEADERS ]] && set -- "${@}" AC_CONFIG_HEADER
283    
284     for x; do
285     grep -h "^${x}" configure.{ac,in} 2>/dev/null
286     done
287     }
288    
289     einfo "Autoreconfiguring '${PWD}' ..."
290    
291     local auxdir=$(sed -n -e 's/^AC_CONFIG_AUX_DIR(\(.*\))$/\1/p' \
292     configure.{ac,in} 2>/dev/null)
293     if [[ ${auxdir} ]]; then
294     auxdir=${auxdir%%]}
295     mkdir -p ${auxdir##[}
296     fi
297    
298     # Support running additional tools like gnome-autogen.sh.
299     # Note: you need to add additional depends to the ebuild.
300    
301     # gettext
302     if [[ $(autotools_check_macro AM_GLIB_GNU_GETTEXT) ]]; then
303     echo 'no' | autotools_run_tool glib-gettextize --copy
304     elif [[ $(autotools_check_macro AM_GNU_GETTEXT) ]]; then
305     eautopoint
306     fi
307    
308     # intltool
309     if [[ $(autotools_check_macro AC_PROG_INTLTOOL IT_PROG_INTLTOOL) ]]
310     then
311     autotools_run_tool intltoolize --copy --automake
312     fi
313    
314     # gtk-doc
315     if [[ $(autotools_check_macro GTK_DOC_CHECK) ]]; then
316     autotools_run_tool gtkdocize --copy
317     fi
318    
319     # gnome-doc
320     if [[ $(autotools_check_macro GNOME_DOC_INIT) ]]; then
321     autotools_run_tool gnome-doc-prepare --copy
322     fi
323    
324     # We need to perform the check twice to know whether to run eaclocal.
325     # (_elibtoolize does that itself)
326     if [[ $(autotools_check_macro AC_PROG_LIBTOOL AM_PROG_LIBTOOL LT_INIT) ]]
327     then
328     _elibtoolize --copy --force --install
329     else
330     eaclocal
331     fi
332    
333     eautoconf
334     eautoheader
335     eautomake
336    
337     local x
338     for x in $(autotools_get_subdirs); do
339     if [[ -d ${x} ]] ; then
340     pushd "${x}" >/dev/null
341     autotools-utils_eautoreconf
342     popd >/dev/null
343     fi
344     done
345     }
346    
347 reavertm 1.1 # @FUNCTION: autotools-utils_src_prepare
348     # @DESCRIPTION:
349     # The src_prepare function.
350     #
351     # Supporting PATCHES array and user patches. See base.eclass(5) for reference.
352     autotools-utils_src_prepare() {
353     debug-print-function ${FUNCNAME} "$@"
354    
355 mgorny 1.32 local want_autoreconf=${AUTOTOOLS_AUTORECONF}
356    
357 mgorny 1.30 [[ ${PATCHES} ]] && epatch "${PATCHES[@]}"
358     epatch_user
359    
360 mgorny 1.32 [[ ${want_autoreconf} ]] && autotools-utils_autoreconf
361 mgorny 1.25 elibtoolize --patch-only
362 reavertm 1.1 }
363    
364     # @FUNCTION: autotools-utils_src_configure
365     # @DESCRIPTION:
366     # The src_configure function. For out of source build it creates build
367     # directory and runs econf there. Configuration parameters defined
368     # in myeconfargs are passed here to econf. Additionally following USE
369     # flags are known:
370     #
371     # IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static
372     # to econf respectively.
373     autotools-utils_src_configure() {
374     debug-print-function ${FUNCNAME} "$@"
375    
376 mgorny 1.22 [[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \
377     || die 'autotools-utils.eclass: myeconfargs has to be an array.'
378    
379 mgorny 1.35 [[ ${EAPI} == 2 ]] && ! use prefix && EPREFIX=
380    
381 reavertm 1.1 # Common args
382 mgorny 1.35 local econfargs=(
383     --docdir="${EPREFIX}/usr/share/doc/${PF}"
384     )
385 reavertm 1.1
386     # Handle static-libs found in IUSE, disable them by default
387 mgorny 1.24 if in_iuse static-libs; then
388 reavertm 1.1 econfargs+=(
389     --enable-shared
390     $(use_enable static-libs static)
391     )
392     fi
393    
394     # Append user args
395 reavertm 1.5 econfargs+=("${myeconfargs[@]}")
396 reavertm 1.1
397     _check_build_dir
398     mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed"
399 mgorny 1.29 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
400 mgorny 1.30 econf "${econfargs[@]}" "$@"
401 mgorny 1.29 popd > /dev/null
402 reavertm 1.1 }
403    
404     # @FUNCTION: autotools-utils_src_compile
405     # @DESCRIPTION:
406     # The autotools src_compile function, invokes emake in specified AUTOTOOLS_BUILD_DIR.
407     autotools-utils_src_compile() {
408     debug-print-function ${FUNCNAME} "$@"
409    
410     _check_build_dir
411 mgorny 1.29 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
412 mgorny 1.30 emake "$@" || die 'emake failed'
413 mgorny 1.29 popd > /dev/null
414 reavertm 1.1 }
415    
416     # @FUNCTION: autotools-utils_src_install
417     # @DESCRIPTION:
418     # The autotools src_install function. Runs emake install, unconditionally
419     # removes unnecessary static libs (based on shouldnotlink libtool property)
420     # and removes unnecessary libtool files when static-libs USE flag is defined
421     # and unset.
422     #
423     # DOCS and HTML_DOCS arrays are supported. See base.eclass(5) for reference.
424     autotools-utils_src_install() {
425     debug-print-function ${FUNCNAME} "$@"
426    
427     _check_build_dir
428 mgorny 1.29 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
429 mgorny 1.30 emake DESTDIR="${D}" "$@" install || die "emake install failed"
430 mgorny 1.29 popd > /dev/null
431 reavertm 1.1
432 mgorny 1.35 # Move docs installed by autotools (in EAPI < 4).
433     if [[ ${EAPI} == [23] && -d ${D}${EPREFIX}/usr/share/doc/${PF} ]]; then
434     mkdir "${T}"/temp-docdir
435     mv "${D}${EPREFIX}"/usr/share/doc/${PF}/* "${T}"/temp-docdir/ \
436     || die "moving docs to tempdir failed"
437    
438     local f
439     for f in "${T}"/temp-docdir/*; do
440     [[ -d ${f} ]] \
441     && die "directories in docdir require at least EAPI 4"
442     done
443    
444     dodoc "${T}"/temp-docdir/* || die "docdir dodoc failed"
445     rm -r "${T}"/temp-docdir || die
446     fi
447    
448 mgorny 1.30 # XXX: support installing them from builddir as well?
449     if [[ ${DOCS} ]]; then
450     dodoc "${DOCS[@]}" || die "dodoc failed"
451 mgorny 1.34 else
452     local f
453     # same list as in PMS
454     for f in README* ChangeLog AUTHORS NEWS TODO CHANGES \
455     THANKS BUGS FAQ CREDITS CHANGELOG; do
456     if [[ -s ${f} ]]; then
457     dodoc "${f}" || die "(default) dodoc ${f} failed"
458     fi
459     done
460 mgorny 1.30 fi
461     if [[ ${HTML_DOCS} ]]; then
462     dohtml -r "${HTML_DOCS[@]}" || die "dohtml failed"
463     fi
464    
465 reavertm 1.1 # Remove libtool files and unnecessary static libs
466 mgorny 1.14 remove_libtool_files
467 reavertm 1.1 }
468    
469     # @FUNCTION: autotools-utils_src_test
470     # @DESCRIPTION:
471     # The autotools src_test function. Runs emake check in build directory.
472     autotools-utils_src_test() {
473     debug-print-function ${FUNCNAME} "$@"
474    
475     _check_build_dir
476 mgorny 1.29 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
477 reavertm 1.1 # Run default src_test as defined in ebuild.sh
478     default_src_test
479 mgorny 1.29 popd > /dev/null
480 reavertm 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.20