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