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.30 |
# $Header: /var/cvsroot/gentoo-x86/eclass/autotools-utils.eclass,v 1.29 2011/11/27 09:57:20 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 |
|
|
autotools-utils_src_prepare() { |
259 |
|
|
debug-print-function ${FUNCNAME} "$@" |
260 |
|
|
|
261 |
mgorny |
1.30 |
[[ ${PATCHES} ]] && epatch "${PATCHES[@]}" |
262 |
|
|
epatch_user |
263 |
|
|
|
264 |
mgorny |
1.25 |
elibtoolize --patch-only |
265 |
reavertm |
1.1 |
} |
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 |
mgorny |
1.22 |
[[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \ |
280 |
|
|
|| die 'autotools-utils.eclass: myeconfargs has to be an array.' |
281 |
|
|
|
282 |
reavertm |
1.1 |
# Common args |
283 |
|
|
local econfargs=() |
284 |
|
|
|
285 |
|
|
# Handle static-libs found in IUSE, disable them by default |
286 |
mgorny |
1.24 |
if in_iuse static-libs; then |
287 |
reavertm |
1.1 |
econfargs+=( |
288 |
|
|
--enable-shared |
289 |
|
|
$(use_enable static-libs static) |
290 |
|
|
) |
291 |
|
|
fi |
292 |
|
|
|
293 |
|
|
# Append user args |
294 |
reavertm |
1.5 |
econfargs+=("${myeconfargs[@]}") |
295 |
reavertm |
1.1 |
|
296 |
|
|
_check_build_dir |
297 |
|
|
mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed" |
298 |
mgorny |
1.29 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
299 |
mgorny |
1.30 |
econf "${econfargs[@]}" "$@" |
300 |
mgorny |
1.29 |
popd > /dev/null |
301 |
reavertm |
1.1 |
} |
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 |
mgorny |
1.29 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
311 |
mgorny |
1.30 |
emake "$@" || die 'emake failed' |
312 |
mgorny |
1.29 |
popd > /dev/null |
313 |
reavertm |
1.1 |
} |
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 |
mgorny |
1.29 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
328 |
mgorny |
1.30 |
emake DESTDIR="${D}" "$@" install || die "emake install failed" |
329 |
mgorny |
1.29 |
popd > /dev/null |
330 |
reavertm |
1.1 |
|
331 |
mgorny |
1.30 |
# 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 |
reavertm |
1.1 |
# Remove libtool files and unnecessary static libs |
340 |
mgorny |
1.14 |
remove_libtool_files |
341 |
reavertm |
1.1 |
} |
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 |
mgorny |
1.29 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
351 |
reavertm |
1.1 |
# Run default src_test as defined in ebuild.sh |
352 |
|
|
default_src_test |
353 |
mgorny |
1.29 |
popd > /dev/null |
354 |
reavertm |
1.1 |
} |