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

Contents of /eclass/autotools-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.31 - (show annotations) (download)
Thu Dec 22 18:01:12 2011 UTC (2 years, 8 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 # Copyright 1999-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/autotools-utils.eclass,v 1.30 2011/12/14 14:55:03 mgorny Exp $
4
5 # @ECLASS: autotools-utils.eclass
6 # @MAINTAINER:
7 # Maciej Mrozowski <reavertm@gentoo.org>
8 # Michał Górny <mgorny@gentoo.org>
9 # @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 # 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 #
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 # local myeconfargs=(
65 # $(use_enable debug)
66 # $(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 2|3|4) ;;
93 *) die "EAPI=${EAPI} is not supported" ;;
94 esac
95
96 inherit autotools eutils libtool
97
98 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test
99
100 # @ECLASS-VARIABLE: AUTOTOOLS_BUILD_DIR
101 # @DEFAULT_UNSET
102 # @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 # @DEFAULT_UNSET
108 # @DESCRIPTION:
109 # Set to enable in-source build.
110
111 # @ECLASS-VARIABLE: ECONF_SOURCE
112 # @DEFAULT_UNSET
113 # @DESCRIPTION:
114 # Specify location of autotools' configure script. By default it uses ${S}.
115
116 # @ECLASS-VARIABLE: myeconfargs
117 # @DEFAULT_UNSET
118 # @DESCRIPTION:
119 # Optional econf arguments as Bash array. Should be defined before calling src_configure.
120 # @CODE
121 # src_configure() {
122 # local myeconfargs=(
123 # --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 # @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 # 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 # @USAGE: [all]
175 # @DESCRIPTION:
176 # Determines unnecessary libtool files (.la) and libtool static archives (.a)
177 # and removes them from installation image.
178 #
179 # To unconditionally remove all libtool files, pass 'all' as argument.
180 # Otherwise, libtool archives required for static linking will be preserved.
181 #
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 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
198 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 local f
208 find "${D}" -type f -name '*.la' -print0 | while read -r -d '' f; do
209 local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}")
210 local archivefile=${f/%.la/.a}
211 [[ "${f}" != "${archivefile}" ]] || die 'regex sanity check failed'
212
213 # Remove static libs we're not supposed to link against.
214 if [[ ${shouldnotlink} ]]; then
215 einfo "Removing unnecessary ${archivefile#${D%/}}"
216 rm -f "${archivefile}" || die
217 # The .la file may be used by a module loader, so avoid removing it
218 # unless explicitly requested.
219 [[ ${removing_all} ]] || continue
220 fi
221
222 # Remove .la files when:
223 # - user explicitly wants us to remove all .la files,
224 # - respective static archive doesn't exist,
225 # - they are covered by a .pc file already,
226 # - they don't provide any new information (no libs & no flags).
227 local removing
228 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 elif [[ ! $(sed -n -e \
233 "s/^\(dependency_libs\|inherited_linker_flags\)='\(.*\)'$/\2/p" \
234 "${f}") ]]; then removing='no libs & flags'
235 fi
236
237 if [[ ${removing} ]]; then
238 einfo "Removing unnecessary ${f#${D%/}} (${removing})"
239 rm -f "${f}" || die
240 fi
241 done
242
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 }
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 #
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 autotools-utils_src_prepare() {
262 debug-print-function ${FUNCNAME} "$@"
263
264 [[ ${PATCHES} ]] && epatch "${PATCHES[@]}"
265 epatch_user
266
267 elibtoolize --patch-only
268 }
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 [[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \
283 || die 'autotools-utils.eclass: myeconfargs has to be an array.'
284
285 # Common args
286 local econfargs=()
287
288 # Handle static-libs found in IUSE, disable them by default
289 if in_iuse static-libs; then
290 econfargs+=(
291 --enable-shared
292 $(use_enable static-libs static)
293 )
294 fi
295
296 # Append user args
297 econfargs+=("${myeconfargs[@]}")
298
299 _check_build_dir
300 mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed"
301 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
302 econf "${econfargs[@]}" "$@"
303 popd > /dev/null
304 }
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 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
314 emake "$@" || die 'emake failed'
315 popd > /dev/null
316 }
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 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
331 emake DESTDIR="${D}" "$@" install || die "emake install failed"
332 popd > /dev/null
333
334 # 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 # Remove libtool files and unnecessary static libs
343 remove_libtool_files
344 }
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 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
354 # Run default src_test as defined in ebuild.sh
355 default_src_test
356 popd > /dev/null
357 }

  ViewVC Help
Powered by ViewVC 1.1.20