1 |
commit: 036914971ecdc867fde5874cd57f6eda084a1423 |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Nov 29 21:04:41 2011 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Nov 29 21:04:41 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=dev/mgorny.git;a=commit;h=03691497 |
7 |
|
8 |
Import autotools-utils from gx86 |
9 |
|
10 |
--- |
11 |
eclass/autotools-utils.eclass | 310 +++++++++++++++++++++++++++++++++++++++++ |
12 |
1 files changed, 310 insertions(+), 0 deletions(-) |
13 |
|
14 |
diff --git a/eclass/autotools-utils.eclass b/eclass/autotools-utils.eclass |
15 |
new file mode 100644 |
16 |
index 0000000..0aa1679 |
17 |
--- /dev/null |
18 |
+++ b/eclass/autotools-utils.eclass |
19 |
@@ -0,0 +1,310 @@ |
20 |
+# Copyright 1999-2011 Gentoo Foundation |
21 |
+# Distributed under the terms of the GNU General Public License v2 |
22 |
+# $Header: /var/cvsroot/gentoo-x86/eclass/autotools-utils.eclass,v 1.29 2011/11/27 09:57:20 mgorny Exp $ |
23 |
+ |
24 |
+# @ECLASS: autotools-utils.eclass |
25 |
+# @MAINTAINER: |
26 |
+# Maciej Mrozowski <reavertm@g.o> |
27 |
+# Michał Górny <mgorny@g.o> |
28 |
+# @BLURB: common ebuild functions for autotools-based packages |
29 |
+# @DESCRIPTION: |
30 |
+# autotools-utils.eclass is autotools.eclass(5) and base.eclass(5) wrapper |
31 |
+# providing all inherited features along with econf arguments as Bash array, |
32 |
+# out of source build with overridable build dir location, static archives |
33 |
+# handling, libtool files removal. |
34 |
+# |
35 |
+# Please note note that autotools-utils does not support mixing of its phase |
36 |
+# functions with regular econf/emake calls. If necessary, please call |
37 |
+# autotools-utils_src_compile instead of the latter. |
38 |
+# |
39 |
+# @EXAMPLE: |
40 |
+# Typical ebuild using autotools-utils.eclass: |
41 |
+# |
42 |
+# @CODE |
43 |
+# EAPI="2" |
44 |
+# |
45 |
+# inherit autotools-utils |
46 |
+# |
47 |
+# DESCRIPTION="Foo bar application" |
48 |
+# HOMEPAGE="http://example.org/foo/" |
49 |
+# SRC_URI="mirror://sourceforge/foo/${P}.tar.bz2" |
50 |
+# |
51 |
+# LICENSE="LGPL-2.1" |
52 |
+# KEYWORDS="" |
53 |
+# SLOT="0" |
54 |
+# IUSE="debug doc examples qt4 static-libs tiff" |
55 |
+# |
56 |
+# CDEPEND=" |
57 |
+# media-libs/libpng:0 |
58 |
+# qt4? ( |
59 |
+# x11-libs/qt-core:4 |
60 |
+# x11-libs/qt-gui:4 |
61 |
+# ) |
62 |
+# tiff? ( media-libs/tiff:0 ) |
63 |
+# " |
64 |
+# RDEPEND="${CDEPEND} |
65 |
+# !media-gfx/bar |
66 |
+# " |
67 |
+# DEPEND="${CDEPEND} |
68 |
+# doc? ( app-doc/doxygen ) |
69 |
+# " |
70 |
+# |
71 |
+# # bug 123456 |
72 |
+# AUTOTOOLS_IN_SOURCE_BUILD=1 |
73 |
+# |
74 |
+# DOCS=(AUTHORS ChangeLog README "Read me.txt" TODO) |
75 |
+# |
76 |
+# PATCHES=( |
77 |
+# "${FILESDIR}/${P}-gcc44.patch" # bug 123458 |
78 |
+# "${FILESDIR}/${P}-as-needed.patch" |
79 |
+# "${FILESDIR}/${P}-unbundle_libpng.patch" |
80 |
+# ) |
81 |
+# |
82 |
+# src_configure() { |
83 |
+# local myeconfargs=( |
84 |
+# $(use_enable debug) |
85 |
+# $(use_with qt4) |
86 |
+# $(use_enable threads multithreading) |
87 |
+# $(use_with tiff) |
88 |
+# ) |
89 |
+# autotools-utils_src_configure |
90 |
+# } |
91 |
+# |
92 |
+# src_compile() { |
93 |
+# autotools-utils_src_compile |
94 |
+# use doc && autotools-utils_src_compile docs |
95 |
+# } |
96 |
+# |
97 |
+# src_install() { |
98 |
+# use doc && HTML_DOCS=("${AUTOTOOLS_BUILD_DIR}/apidocs/html/") |
99 |
+# autotools-utils_src_install |
100 |
+# if use examples; then |
101 |
+# dobin "${AUTOTOOLS_BUILD_DIR}"/foo_example{1,2,3} \\ |
102 |
+# || die 'dobin examples failed' |
103 |
+# fi |
104 |
+# } |
105 |
+# |
106 |
+# @CODE |
107 |
+ |
108 |
+# Keep variable names synced with cmake-utils and the other way around! |
109 |
+ |
110 |
+case ${EAPI:-0} in |
111 |
+ 2|3|4) ;; |
112 |
+ *) die "EAPI=${EAPI} is not supported" ;; |
113 |
+esac |
114 |
+ |
115 |
+inherit autotools base eutils libtool |
116 |
+ |
117 |
+EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test |
118 |
+ |
119 |
+# @ECLASS-VARIABLE: AUTOTOOLS_BUILD_DIR |
120 |
+# @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 |
+# @DESCRIPTION: |
126 |
+# Set to enable in-source build. |
127 |
+ |
128 |
+# @ECLASS-VARIABLE: ECONF_SOURCE |
129 |
+# @DESCRIPTION: |
130 |
+# Specify location of autotools' configure script. By default it uses ${S}. |
131 |
+ |
132 |
+# @ECLASS-VARIABLE: myeconfargs |
133 |
+# @DESCRIPTION: |
134 |
+# Optional econf arguments as Bash array. Should be defined before calling src_configure. |
135 |
+# @CODE |
136 |
+# src_configure() { |
137 |
+# local myeconfargs=( |
138 |
+# --disable-readline |
139 |
+# --with-confdir="/etc/nasty foo confdir/" |
140 |
+# $(use_enable debug cnddebug) |
141 |
+# $(use_enable threads multithreading) |
142 |
+# ) |
143 |
+# autotools-utils_src_configure |
144 |
+# } |
145 |
+# @CODE |
146 |
+ |
147 |
+# Determine using IN or OUT source build |
148 |
+_check_build_dir() { |
149 |
+ : ${ECONF_SOURCE:=${S}} |
150 |
+ if [[ -n ${AUTOTOOLS_IN_SOURCE_BUILD} ]]; then |
151 |
+ AUTOTOOLS_BUILD_DIR="${ECONF_SOURCE}" |
152 |
+ else |
153 |
+ : ${AUTOTOOLS_BUILD_DIR:=${WORKDIR}/${P}_build} |
154 |
+ fi |
155 |
+ echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\"" |
156 |
+} |
157 |
+ |
158 |
+# @FUNCTION: remove_libtool_files |
159 |
+# @USAGE: [all] |
160 |
+# @DESCRIPTION: |
161 |
+# Determines unnecessary libtool files (.la) and libtool static archives (.a) |
162 |
+# and removes them from installation image. |
163 |
+# |
164 |
+# To unconditionally remove all libtool files, pass 'all' as argument. |
165 |
+# Otherwise, libtool archives required for static linking will be preserved. |
166 |
+# |
167 |
+# In most cases it's not necessary to manually invoke this function. |
168 |
+# See autotools-utils_src_install for reference. |
169 |
+remove_libtool_files() { |
170 |
+ debug-print-function ${FUNCNAME} "$@" |
171 |
+ local removing_all |
172 |
+ [[ ${#} -le 1 ]] || die "Invalid number of args to ${FUNCNAME}()" |
173 |
+ if [[ ${#} -eq 1 ]]; then |
174 |
+ case "${1}" in |
175 |
+ all) |
176 |
+ removing_all=1 |
177 |
+ ;; |
178 |
+ *) |
179 |
+ die "Invalid argument to ${FUNCNAME}(): ${1}" |
180 |
+ esac |
181 |
+ fi |
182 |
+ |
183 |
+ local pc_libs=() |
184 |
+ if [[ ! ${removing_all} ]]; then |
185 |
+ local arg |
186 |
+ for arg in $(find "${D}" -name '*.pc' -exec \ |
187 |
+ sed -n -e 's;^Libs:;;p' {} +); do |
188 |
+ [[ ${arg} == -l* ]] && pc_libs+=(lib${arg#-l}.la) |
189 |
+ done |
190 |
+ fi |
191 |
+ |
192 |
+ local f |
193 |
+ find "${D}" -type f -name '*.la' -print0 | while read -r -d '' f; do |
194 |
+ local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}") |
195 |
+ local archivefile=${f/%.la/.a} |
196 |
+ [[ "${f}" != "${archivefile}" ]] || die 'regex sanity check failed' |
197 |
+ |
198 |
+ # Remove static libs we're not supposed to link against. |
199 |
+ if [[ ${shouldnotlink} ]]; then |
200 |
+ einfo "Removing unnecessary ${archivefile#${D%/}}" |
201 |
+ rm -f "${archivefile}" || die |
202 |
+ # The .la file may be used by a module loader, so avoid removing it |
203 |
+ # unless explicitly requested. |
204 |
+ [[ ${removing_all} ]] || continue |
205 |
+ fi |
206 |
+ |
207 |
+ # Remove .la files when: |
208 |
+ # - user explicitly wants us to remove all .la files, |
209 |
+ # - respective static archive doesn't exist, |
210 |
+ # - they are covered by a .pc file already, |
211 |
+ # - they don't provide any new information (no libs & no flags). |
212 |
+ local removing |
213 |
+ if [[ ${removing_all} ]]; then removing='forced' |
214 |
+ elif [[ ! -f ${archivefile} ]]; then removing='no static archive' |
215 |
+ elif has "$(basename "${f}")" "${pc_libs[@]}"; then |
216 |
+ removing='covered by .pc' |
217 |
+ elif [[ ! $(sed -n -e \ |
218 |
+ "s/^\(dependency_libs\|inherited_linker_flags\)='\(.*\)'$/\2/p" \ |
219 |
+ "${f}") ]]; then removing='no libs & flags' |
220 |
+ fi |
221 |
+ |
222 |
+ if [[ ${removing} ]]; then |
223 |
+ einfo "Removing unnecessary ${f#${D%/}} (${removing})" |
224 |
+ rm -f "${f}" || die |
225 |
+ fi |
226 |
+ done |
227 |
+ |
228 |
+ # check for invalid eclass use |
229 |
+ # this is the most commonly used function, so do it here |
230 |
+ _check_build_dir |
231 |
+ if [[ ! -d "${AUTOTOOLS_BUILD_DIR}" ]]; then |
232 |
+ eqawarn "autotools-utils used but autotools-utils_src_configure was never called." |
233 |
+ eqawarn "This is not supported and never was. Please report a bug against" |
234 |
+ eqawarn "the offending ebuild. This will become a fatal error in a near future." |
235 |
+ fi |
236 |
+} |
237 |
+ |
238 |
+# @FUNCTION: autotools-utils_src_prepare |
239 |
+# @DESCRIPTION: |
240 |
+# The src_prepare function. |
241 |
+# |
242 |
+# Supporting PATCHES array and user patches. See base.eclass(5) for reference. |
243 |
+autotools-utils_src_prepare() { |
244 |
+ debug-print-function ${FUNCNAME} "$@" |
245 |
+ |
246 |
+ base_src_prepare |
247 |
+ elibtoolize --patch-only |
248 |
+} |
249 |
+ |
250 |
+# @FUNCTION: autotools-utils_src_configure |
251 |
+# @DESCRIPTION: |
252 |
+# The src_configure function. For out of source build it creates build |
253 |
+# directory and runs econf there. Configuration parameters defined |
254 |
+# in myeconfargs are passed here to econf. Additionally following USE |
255 |
+# flags are known: |
256 |
+# |
257 |
+# IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static |
258 |
+# to econf respectively. |
259 |
+autotools-utils_src_configure() { |
260 |
+ debug-print-function ${FUNCNAME} "$@" |
261 |
+ |
262 |
+ [[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \ |
263 |
+ || die 'autotools-utils.eclass: myeconfargs has to be an array.' |
264 |
+ |
265 |
+ # Common args |
266 |
+ local econfargs=() |
267 |
+ |
268 |
+ # Handle static-libs found in IUSE, disable them by default |
269 |
+ if in_iuse static-libs; then |
270 |
+ econfargs+=( |
271 |
+ --enable-shared |
272 |
+ $(use_enable static-libs static) |
273 |
+ ) |
274 |
+ fi |
275 |
+ |
276 |
+ # Append user args |
277 |
+ econfargs+=("${myeconfargs[@]}") |
278 |
+ |
279 |
+ _check_build_dir |
280 |
+ mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed" |
281 |
+ pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
282 |
+ base_src_configure "${econfargs[@]}" "$@" |
283 |
+ popd > /dev/null |
284 |
+} |
285 |
+ |
286 |
+# @FUNCTION: autotools-utils_src_compile |
287 |
+# @DESCRIPTION: |
288 |
+# The autotools src_compile function, invokes emake in specified AUTOTOOLS_BUILD_DIR. |
289 |
+autotools-utils_src_compile() { |
290 |
+ debug-print-function ${FUNCNAME} "$@" |
291 |
+ |
292 |
+ _check_build_dir |
293 |
+ pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
294 |
+ base_src_compile "$@" |
295 |
+ popd > /dev/null |
296 |
+} |
297 |
+ |
298 |
+# @FUNCTION: autotools-utils_src_install |
299 |
+# @DESCRIPTION: |
300 |
+# The autotools src_install function. Runs emake install, unconditionally |
301 |
+# removes unnecessary static libs (based on shouldnotlink libtool property) |
302 |
+# and removes unnecessary libtool files when static-libs USE flag is defined |
303 |
+# and unset. |
304 |
+# |
305 |
+# DOCS and HTML_DOCS arrays are supported. See base.eclass(5) for reference. |
306 |
+autotools-utils_src_install() { |
307 |
+ debug-print-function ${FUNCNAME} "$@" |
308 |
+ |
309 |
+ _check_build_dir |
310 |
+ pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
311 |
+ base_src_install "$@" |
312 |
+ popd > /dev/null |
313 |
+ |
314 |
+ # Remove libtool files and unnecessary static libs |
315 |
+ remove_libtool_files |
316 |
+} |
317 |
+ |
318 |
+# @FUNCTION: autotools-utils_src_test |
319 |
+# @DESCRIPTION: |
320 |
+# The autotools src_test function. Runs emake check in build directory. |
321 |
+autotools-utils_src_test() { |
322 |
+ debug-print-function ${FUNCNAME} "$@" |
323 |
+ |
324 |
+ _check_build_dir |
325 |
+ pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
326 |
+ # Run default src_test as defined in ebuild.sh |
327 |
+ default_src_test |
328 |
+ popd > /dev/null |
329 |
+} |