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

Contents of /eclass/autotools-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.31 - (hide annotations) (download)
Thu Dec 22 18:01:12 2011 UTC (2 years, 7 months ago) by mgorny
Branch: MAIN
Changes since 1.30: +4 -1 lines
Add a note on AT_NOELIBTOOLIZE=yes in src_prepare(). Fixes #395649.

1 mgorny 1.26 # Copyright 1999-2011 Gentoo Foundation
2 reavertm 1.1 # Distributed under the terms of the GNU General Public License v2
3 mgorny 1.31 # $Header: /var/cvsroot/gentoo-x86/eclass/autotools-utils.eclass,v 1.30 2011/12/14 14:55:03 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.30 inherit autotools eutils libtool
97 reavertm 1.1
98     EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test
99    
100     # @ECLASS-VARIABLE: AUTOTOOLS_BUILD_DIR
101 mgorny 1.30 # @DEFAULT_UNSET
102 reavertm 1.1 # @DESCRIPTION:
103     # Build directory, location where all autotools generated files should be
104     # placed. For out of source builds it defaults to ${WORKDIR}/${P}_build.
105    
106     # @ECLASS-VARIABLE: AUTOTOOLS_IN_SOURCE_BUILD
107 mgorny 1.30 # @DEFAULT_UNSET
108 reavertm 1.1 # @DESCRIPTION:
109     # Set to enable in-source build.
110    
111     # @ECLASS-VARIABLE: ECONF_SOURCE
112 mgorny 1.30 # @DEFAULT_UNSET
113 reavertm 1.1 # @DESCRIPTION:
114     # Specify location of autotools' configure script. By default it uses ${S}.
115    
116     # @ECLASS-VARIABLE: myeconfargs
117 mgorny 1.30 # @DEFAULT_UNSET
118 reavertm 1.1 # @DESCRIPTION:
119     # Optional econf arguments as Bash array. Should be defined before calling src_configure.
120     # @CODE
121     # src_configure() {
122 reavertm 1.7 # local myeconfargs=(
123 reavertm 1.1 # --disable-readline
124     # --with-confdir="/etc/nasty foo confdir/"
125     # $(use_enable debug cnddebug)
126     # $(use_enable threads multithreading)
127     # )
128     # autotools-utils_src_configure
129     # }
130     # @CODE
131    
132 mgorny 1.30 # @ECLASS-VARIABLE: DOCS
133     # @DEFAULT_UNSET
134     # @DESCRIPTION:
135     # Array containing documents passed to dodoc command.
136     #
137     # Example:
138     # @CODE
139     # DOCS=( NEWS README )
140     # @CODE
141    
142     # @ECLASS-VARIABLE: HTML_DOCS
143     # @DEFAULT_UNSET
144     # @DESCRIPTION:
145     # Array containing documents passed to dohtml command.
146     #
147     # Example:
148     # @CODE
149     # HTML_DOCS=( doc/html/ )
150     # @CODE
151    
152     # @ECLASS-VARIABLE: PATCHES
153     # @DEFAULT_UNSET
154     # @DESCRIPTION:
155     # PATCHES array variable containing all various patches to be applied.
156     #
157     # Example:
158     # @CODE
159     # PATCHES=( "${FILESDIR}"/${P}-mypatch.patch )
160     # @CODE
161    
162 reavertm 1.1 # Determine using IN or OUT source build
163     _check_build_dir() {
164     : ${ECONF_SOURCE:=${S}}
165     if [[ -n ${AUTOTOOLS_IN_SOURCE_BUILD} ]]; then
166     AUTOTOOLS_BUILD_DIR="${ECONF_SOURCE}"
167     else
168     : ${AUTOTOOLS_BUILD_DIR:=${WORKDIR}/${P}_build}
169     fi
170     echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\""
171     }
172    
173     # @FUNCTION: remove_libtool_files
174 mgorny 1.14 # @USAGE: [all]
175 reavertm 1.1 # @DESCRIPTION:
176     # Determines unnecessary libtool files (.la) and libtool static archives (.a)
177     # and removes them from installation image.
178 mgorny 1.14 #
179 reavertm 1.1 # To unconditionally remove all libtool files, pass 'all' as argument.
180 mgorny 1.14 # Otherwise, libtool archives required for static linking will be preserved.
181 reavertm 1.1 #
182     # In most cases it's not necessary to manually invoke this function.
183     # See autotools-utils_src_install for reference.
184     remove_libtool_files() {
185     debug-print-function ${FUNCNAME} "$@"
186 mgorny 1.16 local removing_all
187     [[ ${#} -le 1 ]] || die "Invalid number of args to ${FUNCNAME}()"
188     if [[ ${#} -eq 1 ]]; then
189     case "${1}" in
190     all)
191     removing_all=1
192     ;;
193     *)
194     die "Invalid argument to ${FUNCNAME}(): ${1}"
195     esac
196     fi
197 reavertm 1.1
198 mgorny 1.19 local pc_libs=()
199     if [[ ! ${removing_all} ]]; then
200     local arg
201     for arg in $(find "${D}" -name '*.pc' -exec \
202     sed -n -e 's;^Libs:;;p' {} +); do
203     [[ ${arg} == -l* ]] && pc_libs+=(lib${arg#-l}.la)
204     done
205     fi
206    
207 reavertm 1.1 local f
208 mgorny 1.12 find "${D}" -type f -name '*.la' -print0 | while read -r -d '' f; do
209 reavertm 1.1 local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}")
210 mgorny 1.14 local archivefile=${f/%.la/.a}
211 mgorny 1.15 [[ "${f}" != "${archivefile}" ]] || die 'regex sanity check failed'
212 mgorny 1.14
213 mgorny 1.18 # Remove static libs we're not supposed to link against.
214 mgorny 1.17 if [[ ${shouldnotlink} ]]; then
215     einfo "Removing unnecessary ${archivefile#${D%/}}"
216     rm -f "${archivefile}" || die
217 mgorny 1.18 # The .la file may be used by a module loader, so avoid removing it
218     # unless explicitly requested.
219 mgorny 1.17 [[ ${removing_all} ]] || continue
220     fi
221    
222 mgorny 1.18 # Remove .la files when:
223     # - user explicitly wants us to remove all .la files,
224     # - respective static archive doesn't exist,
225 mgorny 1.19 # - they are covered by a .pc file already,
226 mgorny 1.18 # - they don't provide any new information (no libs & no flags).
227     local removing
228 mgorny 1.20 if [[ ${removing_all} ]]; then removing='forced'
229     elif [[ ! -f ${archivefile} ]]; then removing='no static archive'
230     elif has "$(basename "${f}")" "${pc_libs[@]}"; then
231     removing='covered by .pc'
232 mgorny 1.18 elif [[ ! $(sed -n -e \
233     "s/^\(dependency_libs\|inherited_linker_flags\)='\(.*\)'$/\2/p" \
234 mgorny 1.20 "${f}") ]]; then removing='no libs & flags'
235 mgorny 1.18 fi
236    
237     if [[ ${removing} ]]; then
238 mgorny 1.20 einfo "Removing unnecessary ${f#${D%/}} (${removing})"
239 mgorny 1.15 rm -f "${f}" || die
240 reavertm 1.1 fi
241     done
242 mgorny 1.29
243     # check for invalid eclass use
244     # this is the most commonly used function, so do it here
245     _check_build_dir
246     if [[ ! -d "${AUTOTOOLS_BUILD_DIR}" ]]; then
247     eqawarn "autotools-utils used but autotools-utils_src_configure was never called."
248     eqawarn "This is not supported and never was. Please report a bug against"
249     eqawarn "the offending ebuild. This will become a fatal error in a near future."
250     fi
251 reavertm 1.1 }
252    
253     # @FUNCTION: autotools-utils_src_prepare
254     # @DESCRIPTION:
255     # The src_prepare function.
256     #
257     # Supporting PATCHES array and user patches. See base.eclass(5) for reference.
258 mgorny 1.31 #
259     # This function calls elibtoolize implicitly. If you need to call eautoreconf
260     # afterwards, please use AT_NOELIBTOOLIZE=yes to avoid it being called twice.
261 reavertm 1.1 autotools-utils_src_prepare() {
262     debug-print-function ${FUNCNAME} "$@"
263    
264 mgorny 1.30 [[ ${PATCHES} ]] && epatch "${PATCHES[@]}"
265     epatch_user
266    
267 mgorny 1.25 elibtoolize --patch-only
268 reavertm 1.1 }
269    
270     # @FUNCTION: autotools-utils_src_configure
271     # @DESCRIPTION:
272     # The src_configure function. For out of source build it creates build
273     # directory and runs econf there. Configuration parameters defined
274     # in myeconfargs are passed here to econf. Additionally following USE
275     # flags are known:
276     #
277     # IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static
278     # to econf respectively.
279     autotools-utils_src_configure() {
280     debug-print-function ${FUNCNAME} "$@"
281    
282 mgorny 1.22 [[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \
283     || die 'autotools-utils.eclass: myeconfargs has to be an array.'
284    
285 reavertm 1.1 # Common args
286     local econfargs=()
287    
288     # Handle static-libs found in IUSE, disable them by default
289 mgorny 1.24 if in_iuse static-libs; then
290 reavertm 1.1 econfargs+=(
291     --enable-shared
292     $(use_enable static-libs static)
293     )
294     fi
295    
296     # Append user args
297 reavertm 1.5 econfargs+=("${myeconfargs[@]}")
298 reavertm 1.1
299     _check_build_dir
300     mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed"
301 mgorny 1.29 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
302 mgorny 1.30 econf "${econfargs[@]}" "$@"
303 mgorny 1.29 popd > /dev/null
304 reavertm 1.1 }
305    
306     # @FUNCTION: autotools-utils_src_compile
307     # @DESCRIPTION:
308     # The autotools src_compile function, invokes emake in specified AUTOTOOLS_BUILD_DIR.
309     autotools-utils_src_compile() {
310     debug-print-function ${FUNCNAME} "$@"
311    
312     _check_build_dir
313 mgorny 1.29 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
314 mgorny 1.30 emake "$@" || die 'emake failed'
315 mgorny 1.29 popd > /dev/null
316 reavertm 1.1 }
317    
318     # @FUNCTION: autotools-utils_src_install
319     # @DESCRIPTION:
320     # The autotools src_install function. Runs emake install, unconditionally
321     # removes unnecessary static libs (based on shouldnotlink libtool property)
322     # and removes unnecessary libtool files when static-libs USE flag is defined
323     # and unset.
324     #
325     # DOCS and HTML_DOCS arrays are supported. See base.eclass(5) for reference.
326     autotools-utils_src_install() {
327     debug-print-function ${FUNCNAME} "$@"
328    
329     _check_build_dir
330 mgorny 1.29 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
331 mgorny 1.30 emake DESTDIR="${D}" "$@" install || die "emake install failed"
332 mgorny 1.29 popd > /dev/null
333 reavertm 1.1
334 mgorny 1.30 # XXX: support installing them from builddir as well?
335     if [[ ${DOCS} ]]; then
336     dodoc "${DOCS[@]}" || die "dodoc failed"
337     fi
338     if [[ ${HTML_DOCS} ]]; then
339     dohtml -r "${HTML_DOCS[@]}" || die "dohtml failed"
340     fi
341    
342 reavertm 1.1 # Remove libtool files and unnecessary static libs
343 mgorny 1.14 remove_libtool_files
344 reavertm 1.1 }
345    
346     # @FUNCTION: autotools-utils_src_test
347     # @DESCRIPTION:
348     # The autotools src_test function. Runs emake check in build directory.
349     autotools-utils_src_test() {
350     debug-print-function ${FUNCNAME} "$@"
351    
352     _check_build_dir
353 mgorny 1.29 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
354 reavertm 1.1 # Run default src_test as defined in ebuild.sh
355     default_src_test
356 mgorny 1.29 popd > /dev/null
357 reavertm 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.20