/[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.2 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.2 2010/07/19 16:15:14 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# @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
54# "${FILESDIR}/${P}-as-needed.patch" 59# "${FILESDIR}/${P}-as-needed.patch"
55# "${FILESDIR}/${P}-unbundle_libpng.patch" 60# "${FILESDIR}/${P}-unbundle_libpng.patch"
56# ) 61# )
57# 62#
58# src_configure() { 63# src_configure() {
59# 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
85case ${EAPI:-0} in 91case ${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" ;;
88esac 94esac
89 95
90inherit autotools base 96inherit autotools eutils libtool
91 97
92EXPORT_FUNCTIONS src_prepare src_configure src_compile src_install src_test 98EXPORT_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# myeconfargs=( 122# local myeconfargs=(
113# --disable-readline 123# --disable-readline
114# --with-confdir="/etc/nasty foo confdir/" 124# --with-confdir="/etc/nasty foo confdir/"
115# $(use_enable debug cnddebug) 125# $(use_enable debug cnddebug)
116# $(use_enable threads multithreading) 126# $(use_enable threads multithreading)
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.
144remove_libtool_files() { 184remove_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.
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.
172autotools-utils_src_prepare() { 261autotools-utils_src_prepare() {
173 debug-print-function ${FUNCNAME} "$@" 262 debug-print-function ${FUNCNAME} "$@"
174 263
175 base_src_prepare 264 [[ ${PATCHES} ]] && epatch "${PATCHES[@]}"
265 epatch_user
266
267 elibtoolize --patch-only
176} 268}
177 269
178# @FUNCTION: autotools-utils_src_configure 270# @FUNCTION: autotools-utils_src_configure
179# @DESCRIPTION: 271# @DESCRIPTION:
180# 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
181# directory and runs econf there. Configuration parameters defined 273# directory and runs econf there. Configuration parameters defined
182# in myeconfargs are passed here to econf. Additionally following USE 274# in myeconfargs are passed here to econf. Additionally following USE
183# flags are known: 275# flags are known:
184# 276#
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 277# IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static
188# to econf respectively. 278# to econf respectively.
189autotools-utils_src_configure() { 279autotools-utils_src_configure() {
190 debug-print-function ${FUNCNAME} "$@" 280 debug-print-function ${FUNCNAME} "$@"
191 281
282 [[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \
283 || die 'autotools-utils.eclass: myeconfargs has to be an array.'
284
192 # Common args 285 # Common args
193 local econfargs=() 286 local econfargs=()
194 287
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 288 # Handle static-libs found in IUSE, disable them by default
201 if has static-libs ${IUSE//+}; then 289 if in_iuse static-libs; then
202 econfargs+=( 290 econfargs+=(
203 --enable-shared 291 --enable-shared
204 $(use_enable static-libs static) 292 $(use_enable static-libs static)
205 ) 293 )
206 fi 294 fi
207 295
208 # Append user args 296 # Append user args
209 econfargs+=(${myeconfargs[@]}) 297 econfargs+=("${myeconfargs[@]}")
210 298
211 _check_build_dir 299 _check_build_dir
212 mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed" 300 mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed"
213 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null 301 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
214 base_src_configure "${econfargs[@]}" 302 econf "${econfargs[@]}" "$@"
215 popd > /dev/null 303 popd > /dev/null
216} 304}
217 305
218# @FUNCTION: autotools-utils_src_compile 306# @FUNCTION: autotools-utils_src_compile
219# @DESCRIPTION: 307# @DESCRIPTION:
221autotools-utils_src_compile() { 309autotools-utils_src_compile() {
222 debug-print-function ${FUNCNAME} "$@" 310 debug-print-function ${FUNCNAME} "$@"
223 311
224 _check_build_dir 312 _check_build_dir
225 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null 313 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
226 base_src_compile "$@" 314 emake "$@" || die 'emake failed'
227 popd > /dev/null 315 popd > /dev/null
228} 316}
229 317
230# @FUNCTION: autotools-utils_src_install 318# @FUNCTION: autotools-utils_src_install
231# @DESCRIPTION: 319# @DESCRIPTION:
238autotools-utils_src_install() { 326autotools-utils_src_install() {
239 debug-print-function ${FUNCNAME} "$@" 327 debug-print-function ${FUNCNAME} "$@"
240 328
241 _check_build_dir 329 _check_build_dir
242 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null 330 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
243 base_src_install 331 emake DESTDIR="${D}" "$@" install || die "emake install failed"
244 popd > /dev/null 332 popd > /dev/null
245 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
246 # Remove libtool files and unnecessary static libs 342 # 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} 343 remove_libtool_files
250} 344}
251 345
252# @FUNCTION: autotools-utils_src_test 346# @FUNCTION: autotools-utils_src_test
253# @DESCRIPTION: 347# @DESCRIPTION:
254# 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.2  
changed lines
  Added in v.1.31

  ViewVC Help
Powered by ViewVC 1.1.20