1 |
# Copyright 1999-2010 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.11 2011/09/12 20:32:41 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, 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 |
# local myeconfargs=( |
61 |
# $(use_with qt4) |
62 |
# $(use_enable threads multithreading) |
63 |
# $(use_with tiff) |
64 |
# ) |
65 |
# autotools-utils_src_configure |
66 |
# } |
67 |
# |
68 |
# src_compile() { |
69 |
# autotools-utils_src_compile |
70 |
# use doc && autotools-utils_src_compile docs |
71 |
# } |
72 |
# |
73 |
# src_install() { |
74 |
# use doc && HTML_DOCS=("${AUTOTOOLS_BUILD_DIR}/apidocs/html/") |
75 |
# autotools-utils_src_install |
76 |
# if use examples; then |
77 |
# dobin "${AUTOTOOLS_BUILD_DIR}"/foo_example{1,2,3} \\ |
78 |
# || die 'dobin examples failed' |
79 |
# fi |
80 |
# } |
81 |
# |
82 |
# @CODE |
83 |
|
84 |
# Keep variable names synced with cmake-utils and the other way around! |
85 |
|
86 |
case ${EAPI:-0} in |
87 |
2|3|4) ;; |
88 |
*) die "EAPI=${EAPI} is not supported" ;; |
89 |
esac |
90 |
|
91 |
inherit autotools base |
92 |
|
93 |
EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test |
94 |
|
95 |
# @ECLASS-VARIABLE: AUTOTOOLS_BUILD_DIR |
96 |
# @DESCRIPTION: |
97 |
# Build directory, location where all autotools generated files should be |
98 |
# placed. For out of source builds it defaults to ${WORKDIR}/${P}_build. |
99 |
|
100 |
# @ECLASS-VARIABLE: AUTOTOOLS_IN_SOURCE_BUILD |
101 |
# @DESCRIPTION: |
102 |
# Set to enable in-source build. |
103 |
|
104 |
# @ECLASS-VARIABLE: ECONF_SOURCE |
105 |
# @DESCRIPTION: |
106 |
# Specify location of autotools' configure script. By default it uses ${S}. |
107 |
|
108 |
# @ECLASS-VARIABLE: myeconfargs |
109 |
# @DESCRIPTION: |
110 |
# Optional econf arguments as Bash array. Should be defined before calling src_configure. |
111 |
# @CODE |
112 |
# src_configure() { |
113 |
# local myeconfargs=( |
114 |
# --disable-readline |
115 |
# --with-confdir="/etc/nasty foo confdir/" |
116 |
# $(use_enable debug cnddebug) |
117 |
# $(use_enable threads multithreading) |
118 |
# ) |
119 |
# autotools-utils_src_configure |
120 |
# } |
121 |
# @CODE |
122 |
|
123 |
# Determine using IN or OUT source build |
124 |
_check_build_dir() { |
125 |
: ${ECONF_SOURCE:=${S}} |
126 |
if [[ -n ${AUTOTOOLS_IN_SOURCE_BUILD} ]]; then |
127 |
AUTOTOOLS_BUILD_DIR="${ECONF_SOURCE}" |
128 |
else |
129 |
: ${AUTOTOOLS_BUILD_DIR:=${WORKDIR}/${P}_build} |
130 |
fi |
131 |
echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\"" |
132 |
} |
133 |
|
134 |
# @FUNCTION: remove_libtool_files |
135 |
# @USAGE: [all|none] |
136 |
# @DESCRIPTION: |
137 |
# Determines unnecessary libtool files (.la) and libtool static archives (.a) |
138 |
# and removes them from installation image. |
139 |
# To unconditionally remove all libtool files, pass 'all' as argument. |
140 |
# To leave all libtool files alone, pass 'none' as argument. |
141 |
# Unnecessary static archives are removed in any case. |
142 |
# |
143 |
# In most cases it's not necessary to manually invoke this function. |
144 |
# See autotools-utils_src_install for reference. |
145 |
remove_libtool_files() { |
146 |
debug-print-function ${FUNCNAME} "$@" |
147 |
|
148 |
local f |
149 |
find "${D}" -type f -name '*.la' -print0 | while read -r -d '' f; do |
150 |
# Keep only .la files with shouldnotlink=yes - likely plugins |
151 |
local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}") |
152 |
if [[ "$1" == 'all' || -z ${shouldnotlink} ]]; then |
153 |
if [[ "$1" != 'none' ]]; then |
154 |
einfo "Removing unnecessary ${f}" |
155 |
rm -f "${f}" |
156 |
fi |
157 |
fi |
158 |
# Remove static libs we're not supposed to link against |
159 |
if [[ -n ${shouldnotlink} ]]; then |
160 |
local remove=${f/%.la/.a} |
161 |
[[ "${f}" != "${remove}" ]] || die 'regex sanity check failed' |
162 |
einfo "Removing unnecessary ${remove}" |
163 |
rm -f "${remove}" |
164 |
fi |
165 |
done |
166 |
} |
167 |
|
168 |
# @FUNCTION: autotools-utils_src_prepare |
169 |
# @DESCRIPTION: |
170 |
# The src_prepare function. |
171 |
# |
172 |
# Supporting PATCHES array and user patches. See base.eclass(5) for reference. |
173 |
autotools-utils_src_prepare() { |
174 |
debug-print-function ${FUNCNAME} "$@" |
175 |
|
176 |
base_src_prepare |
177 |
} |
178 |
|
179 |
# @FUNCTION: autotools-utils_src_configure |
180 |
# @DESCRIPTION: |
181 |
# The src_configure function. For out of source build it creates build |
182 |
# directory and runs econf there. Configuration parameters defined |
183 |
# in myeconfargs are passed here to econf. Additionally following USE |
184 |
# flags are known: |
185 |
# |
186 |
# IUSE="debug" passes --disable-debug/--enable-debug to econf respectively. |
187 |
# |
188 |
# IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static |
189 |
# to econf respectively. |
190 |
autotools-utils_src_configure() { |
191 |
debug-print-function ${FUNCNAME} "$@" |
192 |
|
193 |
# Common args |
194 |
local econfargs=() |
195 |
|
196 |
# Handle debug found in IUSE |
197 |
if has debug ${IUSE//+}; then |
198 |
econfargs+=($(use_enable debug)) |
199 |
fi |
200 |
|
201 |
# Handle static-libs found in IUSE, disable them by default |
202 |
if has static-libs ${IUSE//+}; then |
203 |
econfargs+=( |
204 |
--enable-shared |
205 |
$(use_enable static-libs static) |
206 |
) |
207 |
fi |
208 |
|
209 |
# Append user args |
210 |
econfargs+=("${myeconfargs[@]}") |
211 |
|
212 |
_check_build_dir |
213 |
mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed" |
214 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
215 |
base_src_configure "${econfargs[@]}" "$@" |
216 |
popd > /dev/null |
217 |
} |
218 |
|
219 |
# @FUNCTION: autotools-utils_src_compile |
220 |
# @DESCRIPTION: |
221 |
# The autotools src_compile function, invokes emake in specified AUTOTOOLS_BUILD_DIR. |
222 |
autotools-utils_src_compile() { |
223 |
debug-print-function ${FUNCNAME} "$@" |
224 |
|
225 |
_check_build_dir |
226 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
227 |
base_src_compile "$@" |
228 |
popd > /dev/null |
229 |
} |
230 |
|
231 |
# @FUNCTION: autotools-utils_src_install |
232 |
# @DESCRIPTION: |
233 |
# The autotools src_install function. Runs emake install, unconditionally |
234 |
# removes unnecessary static libs (based on shouldnotlink libtool property) |
235 |
# and removes unnecessary libtool files when static-libs USE flag is defined |
236 |
# and unset. |
237 |
# |
238 |
# DOCS and HTML_DOCS arrays are supported. See base.eclass(5) for reference. |
239 |
autotools-utils_src_install() { |
240 |
debug-print-function ${FUNCNAME} "$@" |
241 |
|
242 |
_check_build_dir |
243 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
244 |
base_src_install "$@" |
245 |
popd > /dev/null |
246 |
|
247 |
# Remove libtool files and unnecessary static libs |
248 |
local args |
249 |
has static-libs ${IUSE//+} && ! use static-libs || args='none' |
250 |
remove_libtool_files ${args} |
251 |
} |
252 |
|
253 |
# @FUNCTION: autotools-utils_src_test |
254 |
# @DESCRIPTION: |
255 |
# The autotools src_test function. Runs emake check in build directory. |
256 |
autotools-utils_src_test() { |
257 |
debug-print-function ${FUNCNAME} "$@" |
258 |
|
259 |
_check_build_dir |
260 |
pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
261 |
# Run default src_test as defined in ebuild.sh |
262 |
default_src_test |
263 |
popd > /dev/null |
264 |
} |