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.27 2011/11/26 20:43:55 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 base eutils libtool |
97 |
|
98 |
EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test |
99 |
|
100 |
# @ECLASS-VARIABLE: AUTOTOOLS_BUILD_DIR |
101 |
# @DESCRIPTION: |
102 |
# Build directory, location where all autotools generated files should be |
103 |
# placed. For out of source builds it defaults to ${WORKDIR}/${P}_build. |
104 |
|
105 |
# @ECLASS-VARIABLE: AUTOTOOLS_IN_SOURCE_BUILD |
106 |
# @DESCRIPTION: |
107 |
# Set to enable in-source build. |
108 |
|
109 |
# @ECLASS-VARIABLE: ECONF_SOURCE |
110 |
# @DESCRIPTION: |
111 |
# Specify location of autotools' configure script. By default it uses ${S}. |
112 |
|
113 |
# @ECLASS-VARIABLE: myeconfargs |
114 |
# @DESCRIPTION: |
115 |
# Optional econf arguments as Bash array. Should be defined before calling src_configure. |
116 |
# @CODE |
117 |
# src_configure() { |
118 |
# local myeconfargs=( |
119 |
# --disable-readline |
120 |
# --with-confdir="/etc/nasty foo confdir/" |
121 |
# $(use_enable debug cnddebug) |
122 |
# $(use_enable threads multithreading) |
123 |
# ) |
124 |
# autotools-utils_src_configure |
125 |
# } |
126 |
# @CODE |
127 |
|
128 |
# Determine using IN or OUT source build |
129 |
_check_build_dir() { |
130 |
: ${ECONF_SOURCE:=${S}} |
131 |
if [[ -n ${AUTOTOOLS_IN_SOURCE_BUILD} ]]; then |
132 |
AUTOTOOLS_BUILD_DIR="${ECONF_SOURCE}" |
133 |
else |
134 |
: ${AUTOTOOLS_BUILD_DIR:=${WORKDIR}/${P}_build} |
135 |
fi |
136 |
echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\"" |
137 |
} |
138 |
|
139 |
# @FUNCTION: remove_libtool_files |
140 |
# @USAGE: [all] |
141 |
# @DESCRIPTION: |
142 |
# Determines unnecessary libtool files (.la) and libtool static archives (.a) |
143 |
# and removes them from installation image. |
144 |
# |
145 |
# To unconditionally remove all libtool files, pass 'all' as argument. |
146 |
# Otherwise, libtool archives required for static linking will be preserved. |
147 |
# |
148 |
# In most cases it's not necessary to manually invoke this function. |
149 |
# See autotools-utils_src_install for reference. |
150 |
remove_libtool_files() { |
151 |
debug-print-function ${FUNCNAME} "$@" |
152 |
local removing_all |
153 |
[[ ${#} -le 1 ]] || die "Invalid number of args to ${FUNCNAME}()" |
154 |
if [[ ${#} -eq 1 ]]; then |
155 |
case "${1}" in |
156 |
all) |
157 |
removing_all=1 |
158 |
;; |
159 |
*) |
160 |
die "Invalid argument to ${FUNCNAME}(): ${1}" |
161 |
esac |
162 |
fi |
163 |
|
164 |
local pc_libs=() |
165 |
if [[ ! ${removing_all} ]]; then |
166 |
local arg |
167 |
for arg in $(find "${D}" -name '*.pc' -exec \ |
168 |
sed -n -e 's;^Libs:;;p' {} +); do |
169 |
[[ ${arg} == -l* ]] && pc_libs+=(lib${arg#-l}.la) |
170 |
done |
171 |
fi |
172 |
|
173 |
local f |
174 |
find "${D}" -type f -name '*.la' -print0 | while read -r -d '' f; do |
175 |
local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}") |
176 |
local archivefile=${f/%.la/.a} |
177 |
[[ "${f}" != "${archivefile}" ]] || die 'regex sanity check failed' |
178 |
|
179 |
# Remove static libs we're not supposed to link against. |
180 |
if [[ ${shouldnotlink} ]]; then |
181 |
einfo "Removing unnecessary ${archivefile#${D%/}}" |
182 |
rm -f "${archivefile}" || die |
183 |
# The .la file may be used by a module loader, so avoid removing it |
184 |
# unless explicitly requested. |
185 |
[[ ${removing_all} ]] || continue |
186 |
fi |
187 |
|
188 |
# Remove .la files when: |
189 |
# - user explicitly wants us to remove all .la files, |
190 |
# - respective static archive doesn't exist, |
191 |
# - they are covered by a .pc file already, |
192 |
# - they don't provide any new information (no libs & no flags). |
193 |
local removing |
194 |
if [[ ${removing_all} ]]; then removing='forced' |
195 |
elif [[ ! -f ${archivefile} ]]; then removing='no static archive' |
196 |
elif has "$(basename "${f}")" "${pc_libs[@]}"; then |
197 |
removing='covered by .pc' |
198 |
elif [[ ! $(sed -n -e \ |
199 |
"s/^\(dependency_libs\|inherited_linker_flags\)='\(.*\)'$/\2/p" \ |
200 |
"${f}") ]]; then removing='no libs & flags' |
201 |
fi |
202 |
|
203 |
if [[ ${removing} ]]; then |
204 |
einfo "Removing unnecessary ${f#${D%/}} (${removing})" |
205 |
rm -f "${f}" || die |
206 |
fi |
207 |
done |
208 |
} |
209 |
|
210 |
# @FUNCTION: autotools-utils_src_prepare |
211 |
# @DESCRIPTION: |
212 |
# The src_prepare function. |
213 |
# |
214 |
# Supporting PATCHES array and user patches. See base.eclass(5) for reference. |
215 |
autotools-utils_src_prepare() { |
216 |
debug-print-function ${FUNCNAME} "$@" |
217 |
|
218 |
base_src_prepare |
219 |
elibtoolize --patch-only |
220 |
} |
221 |
|
222 |
# @FUNCTION: autotools-utils_src_configure |
223 |
# @DESCRIPTION: |
224 |
# The src_configure function. For out of source build it creates build |
225 |
# directory and runs econf there. Configuration parameters defined |
226 |
# in myeconfargs are passed here to econf. Additionally following USE |
227 |
# flags are known: |
228 |
# |
229 |
# IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static |
230 |
# to econf respectively. |
231 |
autotools-utils_src_configure() { |
232 |
debug-print-function ${FUNCNAME} "$@" |
233 |
|
234 |
[[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \ |
235 |
|| die 'autotools-utils.eclass: myeconfargs has to be an array.' |
236 |
|
237 |
# Common args |
238 |
local econfargs=() |
239 |
|
240 |
# Handle static-libs found in IUSE, disable them by default |
241 |
if in_iuse static-libs; then |
242 |
econfargs+=( |
243 |
--enable-shared |
244 |
$(use_enable static-libs static) |
245 |
) |
246 |
fi |
247 |
|
248 |
# Append user args |
249 |
econfargs+=("${myeconfargs[@]}") |
250 |
|
251 |
_check_build_dir |
252 |
mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed" |
253 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null || die |
254 |
base_src_configure "${econfargs[@]}" "$@" |
255 |
popd > /dev/null || die |
256 |
} |
257 |
|
258 |
# @FUNCTION: autotools-utils_src_compile |
259 |
# @DESCRIPTION: |
260 |
# The autotools src_compile function, invokes emake in specified AUTOTOOLS_BUILD_DIR. |
261 |
autotools-utils_src_compile() { |
262 |
debug-print-function ${FUNCNAME} "$@" |
263 |
|
264 |
_check_build_dir |
265 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null || die |
266 |
base_src_compile "$@" |
267 |
popd > /dev/null || die |
268 |
} |
269 |
|
270 |
# @FUNCTION: autotools-utils_src_install |
271 |
# @DESCRIPTION: |
272 |
# The autotools src_install function. Runs emake install, unconditionally |
273 |
# removes unnecessary static libs (based on shouldnotlink libtool property) |
274 |
# and removes unnecessary libtool files when static-libs USE flag is defined |
275 |
# and unset. |
276 |
# |
277 |
# DOCS and HTML_DOCS arrays are supported. See base.eclass(5) for reference. |
278 |
autotools-utils_src_install() { |
279 |
debug-print-function ${FUNCNAME} "$@" |
280 |
|
281 |
_check_build_dir |
282 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null || die |
283 |
base_src_install "$@" |
284 |
popd > /dev/null || die |
285 |
|
286 |
# Remove libtool files and unnecessary static libs |
287 |
remove_libtool_files |
288 |
} |
289 |
|
290 |
# @FUNCTION: autotools-utils_src_test |
291 |
# @DESCRIPTION: |
292 |
# The autotools src_test function. Runs emake check in build directory. |
293 |
autotools-utils_src_test() { |
294 |
debug-print-function ${FUNCNAME} "$@" |
295 |
|
296 |
_check_build_dir |
297 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null || die |
298 |
# Run default src_test as defined in ebuild.sh |
299 |
default_src_test |
300 |
popd > /dev/null || die |
301 |
} |