/[gentoo-x86]/eclass/autotools-utils.eclass
Gentoo

Diff of /eclass/autotools-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.10 Revision 1.31
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.10 2011/09/12 19:11:20 reavertm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/autotools-utils.eclass,v 1.31 2011/12/22 18:01:12 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# Michał Górny <mgorny@gentoo.org>
9# @BLURB: common ebuild functions for autotools-based packages 9# @BLURB: common ebuild functions for autotools-based packages
10# @DESCRIPTION: 10# @DESCRIPTION:
11# 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
12# providing all inherited features along with econf arguments as Bash array, 12# providing all inherited features along with econf arguments as Bash array,
13# out of source build with overridable build dir location, static archives 13# out of source build with overridable build dir location, static archives
14# 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.
15# 19#
16# @EXAMPLE: 20# @EXAMPLE:
17# Typical ebuild using autotools-utils.eclass: 21# Typical ebuild using autotools-utils.eclass:
18# 22#
19# @CODE 23# @CODE
56# "${FILESDIR}/${P}-unbundle_libpng.patch" 60# "${FILESDIR}/${P}-unbundle_libpng.patch"
57# ) 61# )
58# 62#
59# src_configure() { 63# src_configure() {
60# local myeconfargs=( 64# local myeconfargs=(
65# $(use_enable debug)
61# $(use_with qt4) 66# $(use_with qt4)
62# $(use_enable threads multithreading) 67# $(use_enable threads multithreading)
63# $(use_with tiff) 68# $(use_with tiff)
64# ) 69# )
65# autotools-utils_src_configure 70# autotools-utils_src_configure
86case ${EAPI:-0} in 91case ${EAPI:-0} in
87 2|3|4) ;; 92 2|3|4) ;;
88 *) die "EAPI=${EAPI} is not supported" ;; 93 *) die "EAPI=${EAPI} is not supported" ;;
89esac 94esac
90 95
91inherit autotools base 96inherit autotools eutils libtool
92 97
93EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test 98EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test
94 99
95# @ECLASS-VARIABLE: AUTOTOOLS_BUILD_DIR 100# @ECLASS-VARIABLE: AUTOTOOLS_BUILD_DIR
101# @DEFAULT_UNSET
96# @DESCRIPTION: 102# @DESCRIPTION:
97# Build directory, location where all autotools generated files should be 103# Build directory, location where all autotools generated files should be
98# 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.
99 105
100# @ECLASS-VARIABLE: AUTOTOOLS_IN_SOURCE_BUILD 106# @ECLASS-VARIABLE: AUTOTOOLS_IN_SOURCE_BUILD
107# @DEFAULT_UNSET
101# @DESCRIPTION: 108# @DESCRIPTION:
102# Set to enable in-source build. 109# Set to enable in-source build.
103 110
104# @ECLASS-VARIABLE: ECONF_SOURCE 111# @ECLASS-VARIABLE: ECONF_SOURCE
112# @DEFAULT_UNSET
105# @DESCRIPTION: 113# @DESCRIPTION:
106# Specify location of autotools' configure script. By default it uses ${S}. 114# Specify location of autotools' configure script. By default it uses ${S}.
107 115
108# @ECLASS-VARIABLE: myeconfargs 116# @ECLASS-VARIABLE: myeconfargs
117# @DEFAULT_UNSET
109# @DESCRIPTION: 118# @DESCRIPTION:
110# 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.
111# @CODE 120# @CODE
112# src_configure() { 121# src_configure() {
113# local myeconfargs=( 122# local myeconfargs=(
118# ) 127# )
119# autotools-utils_src_configure 128# autotools-utils_src_configure
120# } 129# }
121# @CODE 130# @CODE
122 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
123# Determine using IN or OUT source build 162# Determine using IN or OUT source build
124_check_build_dir() { 163_check_build_dir() {
125 : ${ECONF_SOURCE:=${S}} 164 : ${ECONF_SOURCE:=${S}}
126 if [[ -n ${AUTOTOOLS_IN_SOURCE_BUILD} ]]; then 165 if [[ -n ${AUTOTOOLS_IN_SOURCE_BUILD} ]]; then
127 AUTOTOOLS_BUILD_DIR="${ECONF_SOURCE}" 166 AUTOTOOLS_BUILD_DIR="${ECONF_SOURCE}"
130 fi 169 fi
131 echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\"" 170 echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\""
132} 171}
133 172
134# @FUNCTION: remove_libtool_files 173# @FUNCTION: remove_libtool_files
135# @USAGE: [all|none] 174# @USAGE: [all]
136# @DESCRIPTION: 175# @DESCRIPTION:
137# Determines unnecessary libtool files (.la) and libtool static archives (.a) 176# Determines unnecessary libtool files (.la) and libtool static archives (.a)
138# and removes them from installation image. 177# and removes them from installation image.
178#
139# To unconditionally remove all libtool files, pass 'all' as argument. 179# To unconditionally remove all libtool files, pass 'all' as argument.
140# To leave all libtool files alone, pass 'none' as argument. 180# Otherwise, libtool archives required for static linking will be preserved.
141# Unnecessary static archives are removed in any case.
142# 181#
143# 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.
144# See autotools-utils_src_install for reference. 183# See autotools-utils_src_install for reference.
145remove_libtool_files() { 184remove_libtool_files() {
146 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
147 206
148 local f 207 local f
149 for f in $(find "${D}" -type f -name '*.la'); do 208 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}") 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.
152 if [[ "$1" == 'all' || -z ${shouldnotlink} ]]; then 214 if [[ ${shouldnotlink} ]]; then
153 if [[ "$1" != 'none' ]]; then 215 einfo "Removing unnecessary ${archivefile#${D%/}}"
154 echo "Removing unnecessary ${f}" 216 rm -f "${archivefile}" || die
155 rm -f "${f}" 217 # The .la file may be used by a module loader, so avoid removing it
156 fi 218 # unless explicitly requested.
219 [[ ${removing_all} ]] || continue
157 fi 220 fi
158 # Remove static libs we're not supposed to link against 221
159 if [[ -n ${shouldnotlink} ]]; then 222 # Remove .la files when:
160 local remove=${f/%.la/.a} 223 # - user explicitly wants us to remove all .la files,
161 [[ "${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
162 echo "Removing unnecessary ${remove}" 238 einfo "Removing unnecessary ${f#${D%/}} (${removing})"
163 rm -f "${remove}" 239 rm -f "${f}" || die
164 fi 240 fi
165 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
166} 251}
167 252
168# @FUNCTION: autotools-utils_src_prepare 253# @FUNCTION: autotools-utils_src_prepare
169# @DESCRIPTION: 254# @DESCRIPTION:
170# The src_prepare function. 255# The src_prepare function.
171# 256#
172# 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.
258#
259# This function calls elibtoolize implicitly. If you need to call eautoreconf
260# afterwards, please use AT_NOELIBTOOLIZE=yes to avoid it being called twice.
173autotools-utils_src_prepare() { 261autotools-utils_src_prepare() {
174 debug-print-function ${FUNCNAME} "$@" 262 debug-print-function ${FUNCNAME} "$@"
175 263
176 base_src_prepare 264 [[ ${PATCHES} ]] && epatch "${PATCHES[@]}"
265 epatch_user
266
267 elibtoolize --patch-only
177} 268}
178 269
179# @FUNCTION: autotools-utils_src_configure 270# @FUNCTION: autotools-utils_src_configure
180# @DESCRIPTION: 271# @DESCRIPTION:
181# The src_configure function. For out of source build it creates build 272# The src_configure function. For out of source build it creates build
182# directory and runs econf there. Configuration parameters defined 273# directory and runs econf there. Configuration parameters defined
183# in myeconfargs are passed here to econf. Additionally following USE 274# in myeconfargs are passed here to econf. Additionally following USE
184# flags are known: 275# flags are known:
185# 276#
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 277# IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static
189# to econf respectively. 278# to econf respectively.
190autotools-utils_src_configure() { 279autotools-utils_src_configure() {
191 debug-print-function ${FUNCNAME} "$@" 280 debug-print-function ${FUNCNAME} "$@"
192 281
282 [[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \
283 || die 'autotools-utils.eclass: myeconfargs has to be an array.'
284
193 # Common args 285 # Common args
194 local econfargs=() 286 local econfargs=()
195 287
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 288 # Handle static-libs found in IUSE, disable them by default
202 if has static-libs ${IUSE//+}; then 289 if in_iuse static-libs; then
203 econfargs+=( 290 econfargs+=(
204 --enable-shared 291 --enable-shared
205 $(use_enable static-libs static) 292 $(use_enable static-libs static)
206 ) 293 )
207 fi 294 fi
210 econfargs+=("${myeconfargs[@]}") 297 econfargs+=("${myeconfargs[@]}")
211 298
212 _check_build_dir 299 _check_build_dir
213 mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed" 300 mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed"
214 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null 301 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
215 base_src_configure "${econfargs[@]}" "$@" 302 econf "${econfargs[@]}" "$@"
216 popd > /dev/null 303 popd > /dev/null
217} 304}
218 305
219# @FUNCTION: autotools-utils_src_compile 306# @FUNCTION: autotools-utils_src_compile
220# @DESCRIPTION: 307# @DESCRIPTION:
222autotools-utils_src_compile() { 309autotools-utils_src_compile() {
223 debug-print-function ${FUNCNAME} "$@" 310 debug-print-function ${FUNCNAME} "$@"
224 311
225 _check_build_dir 312 _check_build_dir
226 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null 313 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
227 base_src_compile "$@" 314 emake "$@" || die 'emake failed'
228 popd > /dev/null 315 popd > /dev/null
229} 316}
230 317
231# @FUNCTION: autotools-utils_src_install 318# @FUNCTION: autotools-utils_src_install
232# @DESCRIPTION: 319# @DESCRIPTION:
239autotools-utils_src_install() { 326autotools-utils_src_install() {
240 debug-print-function ${FUNCNAME} "$@" 327 debug-print-function ${FUNCNAME} "$@"
241 328
242 _check_build_dir 329 _check_build_dir
243 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null 330 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
244 base_src_install "$@" 331 emake DESTDIR="${D}" "$@" install || die "emake install failed"
245 popd > /dev/null 332 popd > /dev/null
246 333
334 # XXX: support installing them from builddir as well?
335 if [[ ${DOCS} ]]; then
336 dodoc "${DOCS[@]}" || die "dodoc failed"
337 fi
338 if [[ ${HTML_DOCS} ]]; then
339 dohtml -r "${HTML_DOCS[@]}" || die "dohtml failed"
340 fi
341
247 # Remove libtool files and unnecessary static libs 342 # 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} 343 remove_libtool_files
251} 344}
252 345
253# @FUNCTION: autotools-utils_src_test 346# @FUNCTION: autotools-utils_src_test
254# @DESCRIPTION: 347# @DESCRIPTION:
255# The autotools src_test function. Runs emake check in build directory. 348# The autotools src_test function. Runs emake check in build directory.

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.31

  ViewVC Help
Powered by ViewVC 1.1.20