| 1 | # Copyright 1999-2010 Gentoo Foundation |
1 | # Copyright 1999-2011 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/autotools-utils.eclass,v 1.8 2011/01/31 14:09:01 scarabeus Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/autotools-utils.eclass,v 1.30 2011/12/14 14:55:03 mgorny Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: autotools-utils.eclass |
5 | # @ECLASS: autotools-utils.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # Maciej Mrozowski <reavertm@gentoo.org> |
7 | # Maciej Mrozowski <reavertm@gentoo.org> |
|
|
8 | # Michał Górny <mgorny@gentoo.org> |
| 8 | # @BLURB: common ebuild functions for autotools-based packages |
9 | # @BLURB: common ebuild functions for autotools-based packages |
| 9 | # @DESCRIPTION: |
10 | # @DESCRIPTION: |
| 10 | # autotools-utils.eclass is autotools.eclass(5) and base.eclass(5) wrapper |
11 | # autotools-utils.eclass is autotools.eclass(5) and base.eclass(5) wrapper |
| 11 | # providing all inherited features along with econf arguments as Bash array, |
12 | # providing all inherited features along with econf arguments as Bash array, |
| 12 | # out of source build with overridable build dir location, static archives |
13 | # out of source build with overridable build dir location, static archives |
| 13 | # handling, libtool files removal, enable/disable debug handling. |
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. |
| 14 | # |
19 | # |
| 15 | # @EXAMPLE: |
20 | # @EXAMPLE: |
| 16 | # Typical ebuild using autotools-utils.eclass: |
21 | # Typical ebuild using autotools-utils.eclass: |
| 17 | # |
22 | # |
| 18 | # @CODE |
23 | # @CODE |
| … | |
… | |
| 55 | # "${FILESDIR}/${P}-unbundle_libpng.patch" |
60 | # "${FILESDIR}/${P}-unbundle_libpng.patch" |
| 56 | # ) |
61 | # ) |
| 57 | # |
62 | # |
| 58 | # src_configure() { |
63 | # src_configure() { |
| 59 | # local myeconfargs=( |
64 | # local myeconfargs=( |
|
|
65 | # $(use_enable debug) |
| 60 | # $(use_with qt4) |
66 | # $(use_with qt4) |
| 61 | # $(use_enable threads multithreading) |
67 | # $(use_enable threads multithreading) |
| 62 | # $(use_with tiff) |
68 | # $(use_with tiff) |
| 63 | # ) |
69 | # ) |
| 64 | # autotools-utils_src_configure |
70 | # autotools-utils_src_configure |
| … | |
… | |
| 85 | case ${EAPI:-0} in |
91 | case ${EAPI:-0} in |
| 86 | 2|3|4) ;; |
92 | 2|3|4) ;; |
| 87 | *) die "EAPI=${EAPI} is not supported" ;; |
93 | *) die "EAPI=${EAPI} is not supported" ;; |
| 88 | esac |
94 | esac |
| 89 | |
95 | |
| 90 | inherit autotools base |
96 | inherit autotools eutils libtool |
| 91 | |
97 | |
| 92 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test |
98 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test |
| 93 | |
99 | |
| 94 | # @ECLASS-VARIABLE: AUTOTOOLS_BUILD_DIR |
100 | # @ECLASS-VARIABLE: AUTOTOOLS_BUILD_DIR |
|
|
101 | # @DEFAULT_UNSET |
| 95 | # @DESCRIPTION: |
102 | # @DESCRIPTION: |
| 96 | # Build directory, location where all autotools generated files should be |
103 | # Build directory, location where all autotools generated files should be |
| 97 | # placed. For out of source builds it defaults to ${WORKDIR}/${P}_build. |
104 | # placed. For out of source builds it defaults to ${WORKDIR}/${P}_build. |
| 98 | |
105 | |
| 99 | # @ECLASS-VARIABLE: AUTOTOOLS_IN_SOURCE_BUILD |
106 | # @ECLASS-VARIABLE: AUTOTOOLS_IN_SOURCE_BUILD |
|
|
107 | # @DEFAULT_UNSET |
| 100 | # @DESCRIPTION: |
108 | # @DESCRIPTION: |
| 101 | # Set to enable in-source build. |
109 | # Set to enable in-source build. |
| 102 | |
110 | |
| 103 | # @ECLASS-VARIABLE: ECONF_SOURCE |
111 | # @ECLASS-VARIABLE: ECONF_SOURCE |
|
|
112 | # @DEFAULT_UNSET |
| 104 | # @DESCRIPTION: |
113 | # @DESCRIPTION: |
| 105 | # Specify location of autotools' configure script. By default it uses ${S}. |
114 | # Specify location of autotools' configure script. By default it uses ${S}. |
| 106 | |
115 | |
| 107 | # @ECLASS-VARIABLE: myeconfargs |
116 | # @ECLASS-VARIABLE: myeconfargs |
|
|
117 | # @DEFAULT_UNSET |
| 108 | # @DESCRIPTION: |
118 | # @DESCRIPTION: |
| 109 | # Optional econf arguments as Bash array. Should be defined before calling src_configure. |
119 | # Optional econf arguments as Bash array. Should be defined before calling src_configure. |
| 110 | # @CODE |
120 | # @CODE |
| 111 | # src_configure() { |
121 | # src_configure() { |
| 112 | # local myeconfargs=( |
122 | # local myeconfargs=( |
| … | |
… | |
| 117 | # ) |
127 | # ) |
| 118 | # autotools-utils_src_configure |
128 | # autotools-utils_src_configure |
| 119 | # } |
129 | # } |
| 120 | # @CODE |
130 | # @CODE |
| 121 | |
131 | |
|
|
132 | # @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 | |
| 122 | # Determine using IN or OUT source build |
162 | # Determine using IN or OUT source build |
| 123 | _check_build_dir() { |
163 | _check_build_dir() { |
| 124 | : ${ECONF_SOURCE:=${S}} |
164 | : ${ECONF_SOURCE:=${S}} |
| 125 | if [[ -n ${AUTOTOOLS_IN_SOURCE_BUILD} ]]; then |
165 | if [[ -n ${AUTOTOOLS_IN_SOURCE_BUILD} ]]; then |
| 126 | AUTOTOOLS_BUILD_DIR="${ECONF_SOURCE}" |
166 | AUTOTOOLS_BUILD_DIR="${ECONF_SOURCE}" |
| … | |
… | |
| 129 | fi |
169 | fi |
| 130 | echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\"" |
170 | echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\"" |
| 131 | } |
171 | } |
| 132 | |
172 | |
| 133 | # @FUNCTION: remove_libtool_files |
173 | # @FUNCTION: remove_libtool_files |
| 134 | # @USAGE: [all|none] |
174 | # @USAGE: [all] |
| 135 | # @DESCRIPTION: |
175 | # @DESCRIPTION: |
| 136 | # Determines unnecessary libtool files (.la) and libtool static archives (.a) |
176 | # Determines unnecessary libtool files (.la) and libtool static archives (.a) |
| 137 | # and removes them from installation image. |
177 | # and removes them from installation image. |
|
|
178 | # |
| 138 | # To unconditionally remove all libtool files, pass 'all' as argument. |
179 | # To unconditionally remove all libtool files, pass 'all' as argument. |
| 139 | # To leave all libtool files alone, pass 'none' as argument. |
180 | # Otherwise, libtool archives required for static linking will be preserved. |
| 140 | # Unnecessary static archives are removed in any case. |
|
|
| 141 | # |
181 | # |
| 142 | # In most cases it's not necessary to manually invoke this function. |
182 | # In most cases it's not necessary to manually invoke this function. |
| 143 | # See autotools-utils_src_install for reference. |
183 | # See autotools-utils_src_install for reference. |
| 144 | remove_libtool_files() { |
184 | remove_libtool_files() { |
| 145 | debug-print-function ${FUNCNAME} "$@" |
185 | debug-print-function ${FUNCNAME} "$@" |
|
|
186 | 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 | |
|
|
198 | 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 |
| 146 | |
206 | |
| 147 | local f |
207 | local f |
| 148 | for f in $(find "${D}" -type f -name '*.la'); do |
208 | find "${D}" -type f -name '*.la' -print0 | while read -r -d '' f; do |
| 149 | # Keep only .la files with shouldnotlink=yes - likely plugins |
|
|
| 150 | local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}") |
209 | local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}") |
|
|
210 | local archivefile=${f/%.la/.a} |
|
|
211 | [[ "${f}" != "${archivefile}" ]] || die 'regex sanity check failed' |
|
|
212 | |
|
|
213 | # Remove static libs we're not supposed to link against. |
| 151 | if [[ "$1" == 'all' || -z ${shouldnotlink} ]]; then |
214 | if [[ ${shouldnotlink} ]]; then |
| 152 | if [[ "$1" != 'none' ]]; then |
215 | einfo "Removing unnecessary ${archivefile#${D%/}}" |
| 153 | echo "Removing unnecessary ${f}" |
216 | rm -f "${archivefile}" || die |
| 154 | rm -f "${f}" |
217 | # The .la file may be used by a module loader, so avoid removing it |
| 155 | fi |
218 | # unless explicitly requested. |
|
|
219 | [[ ${removing_all} ]] || continue |
| 156 | fi |
220 | fi |
| 157 | # Remove static libs we're not supposed to link against |
221 | |
| 158 | if [[ -n ${shouldnotlink} ]]; then |
222 | # Remove .la files when: |
| 159 | local remove=${f/%.la/.a} |
223 | # - user explicitly wants us to remove all .la files, |
| 160 | [[ "${f}" != "${remove}" ]] || die 'regex sanity check failed' |
224 | # - respective static archive doesn't exist, |
|
|
225 | # - they are covered by a .pc file already, |
|
|
226 | # - they don't provide any new information (no libs & no flags). |
|
|
227 | local removing |
|
|
228 | 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 | elif [[ ! $(sed -n -e \ |
|
|
233 | "s/^\(dependency_libs\|inherited_linker_flags\)='\(.*\)'$/\2/p" \ |
|
|
234 | "${f}") ]]; then removing='no libs & flags' |
|
|
235 | fi |
|
|
236 | |
|
|
237 | if [[ ${removing} ]]; then |
| 161 | echo "Removing unnecessary ${remove}" |
238 | einfo "Removing unnecessary ${f#${D%/}} (${removing})" |
| 162 | rm -f "${remove}" |
239 | rm -f "${f}" || die |
| 163 | fi |
240 | fi |
| 164 | done |
241 | done |
|
|
242 | |
|
|
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 |
| 165 | } |
251 | } |
| 166 | |
252 | |
| 167 | # @FUNCTION: autotools-utils_src_prepare |
253 | # @FUNCTION: autotools-utils_src_prepare |
| 168 | # @DESCRIPTION: |
254 | # @DESCRIPTION: |
| 169 | # The src_prepare function. |
255 | # The src_prepare function. |
| 170 | # |
256 | # |
| 171 | # Supporting PATCHES array and user patches. See base.eclass(5) for reference. |
257 | # Supporting PATCHES array and user patches. See base.eclass(5) for reference. |
| 172 | autotools-utils_src_prepare() { |
258 | autotools-utils_src_prepare() { |
| 173 | debug-print-function ${FUNCNAME} "$@" |
259 | debug-print-function ${FUNCNAME} "$@" |
| 174 | |
260 | |
| 175 | base_src_prepare |
261 | [[ ${PATCHES} ]] && epatch "${PATCHES[@]}" |
|
|
262 | epatch_user |
|
|
263 | |
|
|
264 | elibtoolize --patch-only |
| 176 | } |
265 | } |
| 177 | |
266 | |
| 178 | # @FUNCTION: autotools-utils_src_configure |
267 | # @FUNCTION: autotools-utils_src_configure |
| 179 | # @DESCRIPTION: |
268 | # @DESCRIPTION: |
| 180 | # The src_configure function. For out of source build it creates build |
269 | # The src_configure function. For out of source build it creates build |
| 181 | # directory and runs econf there. Configuration parameters defined |
270 | # directory and runs econf there. Configuration parameters defined |
| 182 | # in myeconfargs are passed here to econf. Additionally following USE |
271 | # in myeconfargs are passed here to econf. Additionally following USE |
| 183 | # flags are known: |
272 | # flags are known: |
| 184 | # |
273 | # |
| 185 | # IUSE="debug" passes --disable-debug/--enable-debug to econf respectively. |
|
|
| 186 | # |
|
|
| 187 | # IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static |
274 | # IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static |
| 188 | # to econf respectively. |
275 | # to econf respectively. |
| 189 | autotools-utils_src_configure() { |
276 | autotools-utils_src_configure() { |
| 190 | debug-print-function ${FUNCNAME} "$@" |
277 | debug-print-function ${FUNCNAME} "$@" |
| 191 | |
278 | |
|
|
279 | [[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \ |
|
|
280 | || die 'autotools-utils.eclass: myeconfargs has to be an array.' |
|
|
281 | |
| 192 | # Common args |
282 | # Common args |
| 193 | local econfargs=() |
283 | local econfargs=() |
| 194 | |
284 | |
| 195 | # Handle debug found in IUSE |
|
|
| 196 | if has debug ${IUSE//+}; then |
|
|
| 197 | econfargs+=($(use_enable debug)) |
|
|
| 198 | fi |
|
|
| 199 | |
|
|
| 200 | # Handle static-libs found in IUSE, disable them by default |
285 | # Handle static-libs found in IUSE, disable them by default |
| 201 | if has static-libs ${IUSE//+}; then |
286 | if in_iuse static-libs; then |
| 202 | econfargs+=( |
287 | econfargs+=( |
| 203 | --enable-shared |
288 | --enable-shared |
| 204 | $(use_enable static-libs static) |
289 | $(use_enable static-libs static) |
| 205 | ) |
290 | ) |
| 206 | fi |
291 | fi |
| … | |
… | |
| 209 | econfargs+=("${myeconfargs[@]}") |
294 | econfargs+=("${myeconfargs[@]}") |
| 210 | |
295 | |
| 211 | _check_build_dir |
296 | _check_build_dir |
| 212 | mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed" |
297 | mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed" |
| 213 | pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
298 | pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
| 214 | base_src_configure "${econfargs[@]}" "$@" |
299 | econf "${econfargs[@]}" "$@" |
| 215 | popd > /dev/null |
300 | popd > /dev/null |
| 216 | } |
301 | } |
| 217 | |
302 | |
| 218 | # @FUNCTION: autotools-utils_src_compile |
303 | # @FUNCTION: autotools-utils_src_compile |
| 219 | # @DESCRIPTION: |
304 | # @DESCRIPTION: |
| … | |
… | |
| 221 | autotools-utils_src_compile() { |
306 | autotools-utils_src_compile() { |
| 222 | debug-print-function ${FUNCNAME} "$@" |
307 | debug-print-function ${FUNCNAME} "$@" |
| 223 | |
308 | |
| 224 | _check_build_dir |
309 | _check_build_dir |
| 225 | pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
310 | pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
| 226 | base_src_compile "$@" |
311 | emake "$@" || die 'emake failed' |
| 227 | popd > /dev/null |
312 | popd > /dev/null |
| 228 | } |
313 | } |
| 229 | |
314 | |
| 230 | # @FUNCTION: autotools-utils_src_install |
315 | # @FUNCTION: autotools-utils_src_install |
| 231 | # @DESCRIPTION: |
316 | # @DESCRIPTION: |
| … | |
… | |
| 238 | autotools-utils_src_install() { |
323 | autotools-utils_src_install() { |
| 239 | debug-print-function ${FUNCNAME} "$@" |
324 | debug-print-function ${FUNCNAME} "$@" |
| 240 | |
325 | |
| 241 | _check_build_dir |
326 | _check_build_dir |
| 242 | pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
327 | pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null |
| 243 | base_src_install |
328 | emake DESTDIR="${D}" "$@" install || die "emake install failed" |
| 244 | popd > /dev/null |
329 | popd > /dev/null |
| 245 | |
330 | |
|
|
331 | # 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 | |
| 246 | # Remove libtool files and unnecessary static libs |
339 | # Remove libtool files and unnecessary static libs |
| 247 | local args |
|
|
| 248 | has static-libs ${IUSE//+} && ! use static-libs || args='none' |
|
|
| 249 | remove_libtool_files ${args} |
340 | remove_libtool_files |
| 250 | } |
341 | } |
| 251 | |
342 | |
| 252 | # @FUNCTION: autotools-utils_src_test |
343 | # @FUNCTION: autotools-utils_src_test |
| 253 | # @DESCRIPTION: |
344 | # @DESCRIPTION: |
| 254 | # The autotools src_test function. Runs emake check in build directory. |
345 | # The autotools src_test function. Runs emake check in build directory. |