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.29 2011/11/27 09:57:20 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 |
autotools-utils_src_prepare() { |
259 |
debug-print-function ${FUNCNAME} "$@" |
260 |
|
261 |
[[ ${PATCHES} ]] && epatch "${PATCHES[@]}" |
262 |
epatch_user |
263 |
|
264 |
elibtoolize --patch-only |
265 |
} |
266 |
|
267 |
# @FUNCTION: autotools-utils_src_configure |
268 |
# @DESCRIPTION: |
269 |
# The src_configure function. For out of source build it creates build |
270 |
# directory and runs econf there. Configuration parameters defined |
271 |
# in myeconfargs are passed here to econf. Additionally following USE |
272 |
# flags are known: |
273 |
# |
274 |
# IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static |
275 |
# to econf respectively. |
276 |
autotools-utils_src_configure() { |
277 |
debug-print-function ${FUNCNAME} "$@" |
278 |
|
279 |
[[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \ |
280 |
|| die 'autotools-utils.eclass: myeconfargs has to be an array.' |
281 |
|
282 |
# Common args |
283 |
local econfargs=() |
284 |
|
285 |
# Handle static-libs found in IUSE, disable them by default |
286 |
if in_iuse static-libs; then |
287 |
econfargs+=( |
288 |
--enable-shared |
289 |
$(use_enable static-libs static) |
290 |
) |
291 |
fi |
292 |
|
293 |
# Append user args |
294 |
econfargs+=("${myeconfargs[@]}") |
295 |
|
296 |
_check_build_dir |
297 |
mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed" |
298 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
299 |
econf "${econfargs[@]}" "$@" |
300 |
popd > /dev/null |
301 |
} |
302 |
|
303 |
# @FUNCTION: autotools-utils_src_compile |
304 |
# @DESCRIPTION: |
305 |
# The autotools src_compile function, invokes emake in specified AUTOTOOLS_BUILD_DIR. |
306 |
autotools-utils_src_compile() { |
307 |
debug-print-function ${FUNCNAME} "$@" |
308 |
|
309 |
_check_build_dir |
310 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
311 |
emake "$@" || die 'emake failed' |
312 |
popd > /dev/null |
313 |
} |
314 |
|
315 |
# @FUNCTION: autotools-utils_src_install |
316 |
# @DESCRIPTION: |
317 |
# The autotools src_install function. Runs emake install, unconditionally |
318 |
# removes unnecessary static libs (based on shouldnotlink libtool property) |
319 |
# and removes unnecessary libtool files when static-libs USE flag is defined |
320 |
# and unset. |
321 |
# |
322 |
# DOCS and HTML_DOCS arrays are supported. See base.eclass(5) for reference. |
323 |
autotools-utils_src_install() { |
324 |
debug-print-function ${FUNCNAME} "$@" |
325 |
|
326 |
_check_build_dir |
327 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
328 |
emake DESTDIR="${D}" "$@" install || die "emake install failed" |
329 |
popd > /dev/null |
330 |
|
331 |
# XXX: support installing them from builddir as well? |
332 |
if [[ ${DOCS} ]]; then |
333 |
dodoc "${DOCS[@]}" || die "dodoc failed" |
334 |
fi |
335 |
if [[ ${HTML_DOCS} ]]; then |
336 |
dohtml -r "${HTML_DOCS[@]}" || die "dohtml failed" |
337 |
fi |
338 |
|
339 |
# Remove libtool files and unnecessary static libs |
340 |
remove_libtool_files |
341 |
} |
342 |
|
343 |
# @FUNCTION: autotools-utils_src_test |
344 |
# @DESCRIPTION: |
345 |
# The autotools src_test function. Runs emake check in build directory. |
346 |
autotools-utils_src_test() { |
347 |
debug-print-function ${FUNCNAME} "$@" |
348 |
|
349 |
_check_build_dir |
350 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
351 |
# Run default src_test as defined in ebuild.sh |
352 |
default_src_test |
353 |
popd > /dev/null |
354 |
} |