/[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.7 Revision 1.29
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.7 2011/01/22 20:28:53 reavertm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/autotools-utils.eclass,v 1.29 2011/11/27 09:57:20 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
81# @CODE 87# @CODE
82 88
83# Keep variable names synced with cmake-utils and the other way around! 89# Keep variable names synced with cmake-utils and the other way around!
84 90
85case ${EAPI:-0} in 91case ${EAPI:-0} in
86 2|3) ;; 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 base 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
95# @DESCRIPTION: 101# @DESCRIPTION:
129 fi 135 fi
130 echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\"" 136 echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\""
131} 137}
132 138
133# @FUNCTION: remove_libtool_files 139# @FUNCTION: remove_libtool_files
134# @USAGE: [all|none] 140# @USAGE: [all]
135# @DESCRIPTION: 141# @DESCRIPTION:
136# Determines unnecessary libtool files (.la) and libtool static archives (.a) 142# Determines unnecessary libtool files (.la) and libtool static archives (.a)
137# and removes them from installation image. 143# and removes them from installation image.
144#
138# To unconditionally remove all libtool files, pass 'all' as argument. 145# To unconditionally remove all libtool files, pass 'all' as argument.
139# To leave all libtool files alone, pass 'none' as argument. 146# Otherwise, libtool archives required for static linking will be preserved.
140# Unnecessary static archives are removed in any case.
141# 147#
142# In most cases it's not necessary to manually invoke this function. 148# In most cases it's not necessary to manually invoke this function.
143# See autotools-utils_src_install for reference. 149# See autotools-utils_src_install for reference.
144remove_libtool_files() { 150remove_libtool_files() {
145 debug-print-function ${FUNCNAME} "$@" 151 debug-print-function ${FUNCNAME} "$@"
152 local removing_all
153 [[ ${#} -le 1 ]] || die "Invalid number of args to ${FUNCNAME}()"
154 if [[ ${#} -eq 1 ]]; then
155 case "${1}" in
156 all)
157 removing_all=1
158 ;;
159 *)
160 die "Invalid argument to ${FUNCNAME}(): ${1}"
161 esac
162 fi
163
164 local pc_libs=()
165 if [[ ! ${removing_all} ]]; then
166 local arg
167 for arg in $(find "${D}" -name '*.pc' -exec \
168 sed -n -e 's;^Libs:;;p' {} +); do
169 [[ ${arg} == -l* ]] && pc_libs+=(lib${arg#-l}.la)
170 done
171 fi
146 172
147 local f 173 local f
148 for f in $(find "${D}" -type f -name '*.la'); do 174 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}") 175 local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}")
176 local archivefile=${f/%.la/.a}
177 [[ "${f}" != "${archivefile}" ]] || die 'regex sanity check failed'
178
179 # Remove static libs we're not supposed to link against.
151 if [[ "$1" == 'all' || -z ${shouldnotlink} ]]; then 180 if [[ ${shouldnotlink} ]]; then
152 if [[ "$1" != 'none' ]]; then 181 einfo "Removing unnecessary ${archivefile#${D%/}}"
153 echo "Removing unnecessary ${f}" 182 rm -f "${archivefile}" || die
154 rm -f "${f}" 183 # The .la file may be used by a module loader, so avoid removing it
155 fi 184 # unless explicitly requested.
185 [[ ${removing_all} ]] || continue
156 fi 186 fi
157 # Remove static libs we're not supposed to link against 187
158 if [[ -n ${shouldnotlink} ]]; then 188 # Remove .la files when:
159 local remove=${f/%.la/.a} 189 # - user explicitly wants us to remove all .la files,
160 [[ "${f}" != "${remove}" ]] || die 'regex sanity check failed' 190 # - respective static archive doesn't exist,
191 # - they are covered by a .pc file already,
192 # - they don't provide any new information (no libs & no flags).
193 local removing
194 if [[ ${removing_all} ]]; then removing='forced'
195 elif [[ ! -f ${archivefile} ]]; then removing='no static archive'
196 elif has "$(basename "${f}")" "${pc_libs[@]}"; then
197 removing='covered by .pc'
198 elif [[ ! $(sed -n -e \
199 "s/^\(dependency_libs\|inherited_linker_flags\)='\(.*\)'$/\2/p" \
200 "${f}") ]]; then removing='no libs & flags'
201 fi
202
203 if [[ ${removing} ]]; then
161 echo "Removing unnecessary ${remove}" 204 einfo "Removing unnecessary ${f#${D%/}} (${removing})"
162 rm -f "${remove}" 205 rm -f "${f}" || die
163 fi 206 fi
164 done 207 done
208
209 # check for invalid eclass use
210 # this is the most commonly used function, so do it here
211 _check_build_dir
212 if [[ ! -d "${AUTOTOOLS_BUILD_DIR}" ]]; then
213 eqawarn "autotools-utils used but autotools-utils_src_configure was never called."
214 eqawarn "This is not supported and never was. Please report a bug against"
215 eqawarn "the offending ebuild. This will become a fatal error in a near future."
216 fi
165} 217}
166 218
167# @FUNCTION: autotools-utils_src_prepare 219# @FUNCTION: autotools-utils_src_prepare
168# @DESCRIPTION: 220# @DESCRIPTION:
169# The src_prepare function. 221# The src_prepare function.
171# Supporting PATCHES array and user patches. See base.eclass(5) for reference. 223# Supporting PATCHES array and user patches. See base.eclass(5) for reference.
172autotools-utils_src_prepare() { 224autotools-utils_src_prepare() {
173 debug-print-function ${FUNCNAME} "$@" 225 debug-print-function ${FUNCNAME} "$@"
174 226
175 base_src_prepare 227 base_src_prepare
228 elibtoolize --patch-only
176} 229}
177 230
178# @FUNCTION: autotools-utils_src_configure 231# @FUNCTION: autotools-utils_src_configure
179# @DESCRIPTION: 232# @DESCRIPTION:
180# The src_configure function. For out of source build it creates build 233# The src_configure function. For out of source build it creates build
181# directory and runs econf there. Configuration parameters defined 234# directory and runs econf there. Configuration parameters defined
182# in myeconfargs are passed here to econf. Additionally following USE 235# in myeconfargs are passed here to econf. Additionally following USE
183# flags are known: 236# flags are known:
184# 237#
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 238# IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static
188# to econf respectively. 239# to econf respectively.
189autotools-utils_src_configure() { 240autotools-utils_src_configure() {
190 debug-print-function ${FUNCNAME} "$@" 241 debug-print-function ${FUNCNAME} "$@"
191 242
243 [[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \
244 || die 'autotools-utils.eclass: myeconfargs has to be an array.'
245
192 # Common args 246 # Common args
193 local econfargs=() 247 local econfargs=()
194 248
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 249 # Handle static-libs found in IUSE, disable them by default
201 if has static-libs ${IUSE//+}; then 250 if in_iuse static-libs; then
202 econfargs+=( 251 econfargs+=(
203 --enable-shared 252 --enable-shared
204 $(use_enable static-libs static) 253 $(use_enable static-libs static)
205 ) 254 )
206 fi 255 fi
238autotools-utils_src_install() { 287autotools-utils_src_install() {
239 debug-print-function ${FUNCNAME} "$@" 288 debug-print-function ${FUNCNAME} "$@"
240 289
241 _check_build_dir 290 _check_build_dir
242 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null 291 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null
243 base_src_install 292 base_src_install "$@"
244 popd > /dev/null 293 popd > /dev/null
245 294
246 # Remove libtool files and unnecessary static libs 295 # 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} 296 remove_libtool_files
250} 297}
251 298
252# @FUNCTION: autotools-utils_src_test 299# @FUNCTION: autotools-utils_src_test
253# @DESCRIPTION: 300# @DESCRIPTION:
254# The autotools src_test function. Runs emake check in build directory. 301# The autotools src_test function. Runs emake check in build directory.

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.29

  ViewVC Help
Powered by ViewVC 1.1.20