/[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.28
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.28 2011/11/27 09:17:35 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 base 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
96# @DESCRIPTION: 101# @DESCRIPTION:
130 fi 135 fi
131 echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\"" 136 echo ">>> Working in BUILD_DIR: \"$AUTOTOOLS_BUILD_DIR\""
132} 137}
133 138
134# @FUNCTION: remove_libtool_files 139# @FUNCTION: remove_libtool_files
135# @USAGE: [all|none] 140# @USAGE: [all]
136# @DESCRIPTION: 141# @DESCRIPTION:
137# Determines unnecessary libtool files (.la) and libtool static archives (.a) 142# Determines unnecessary libtool files (.la) and libtool static archives (.a)
138# and removes them from installation image. 143# and removes them from installation image.
144#
139# To unconditionally remove all libtool files, pass 'all' as argument. 145# To unconditionally remove all libtool files, pass 'all' as argument.
140# To leave all libtool files alone, pass 'none' as argument. 146# Otherwise, libtool archives required for static linking will be preserved.
141# Unnecessary static archives are removed in any case.
142# 147#
143# 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.
144# See autotools-utils_src_install for reference. 149# See autotools-utils_src_install for reference.
145remove_libtool_files() { 150remove_libtool_files() {
146 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
147 172
148 local f 173 local f
149 for f in $(find "${D}" -type f -name '*.la'); do 174 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}") 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.
152 if [[ "$1" == 'all' || -z ${shouldnotlink} ]]; then 180 if [[ ${shouldnotlink} ]]; then
153 if [[ "$1" != 'none' ]]; then 181 einfo "Removing unnecessary ${archivefile#${D%/}}"
154 echo "Removing unnecessary ${f}" 182 rm -f "${archivefile}" || die
155 rm -f "${f}" 183 # The .la file may be used by a module loader, so avoid removing it
156 fi 184 # unless explicitly requested.
185 [[ ${removing_all} ]] || continue
157 fi 186 fi
158 # Remove static libs we're not supposed to link against 187
159 if [[ -n ${shouldnotlink} ]]; then 188 # Remove .la files when:
160 local remove=${f/%.la/.a} 189 # - user explicitly wants us to remove all .la files,
161 [[ "${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
162 echo "Removing unnecessary ${remove}" 204 einfo "Removing unnecessary ${f#${D%/}} (${removing})"
163 rm -f "${remove}" 205 rm -f "${f}" || die
164 fi 206 fi
165 done 207 done
166} 208}
167 209
168# @FUNCTION: autotools-utils_src_prepare 210# @FUNCTION: autotools-utils_src_prepare
172# Supporting PATCHES array and user patches. See base.eclass(5) for reference. 214# Supporting PATCHES array and user patches. See base.eclass(5) for reference.
173autotools-utils_src_prepare() { 215autotools-utils_src_prepare() {
174 debug-print-function ${FUNCNAME} "$@" 216 debug-print-function ${FUNCNAME} "$@"
175 217
176 base_src_prepare 218 base_src_prepare
219 elibtoolize --patch-only
177} 220}
178 221
179# @FUNCTION: autotools-utils_src_configure 222# @FUNCTION: autotools-utils_src_configure
180# @DESCRIPTION: 223# @DESCRIPTION:
181# The src_configure function. For out of source build it creates build 224# The src_configure function. For out of source build it creates build
182# directory and runs econf there. Configuration parameters defined 225# directory and runs econf there. Configuration parameters defined
183# in myeconfargs are passed here to econf. Additionally following USE 226# in myeconfargs are passed here to econf. Additionally following USE
184# flags are known: 227# flags are known:
185# 228#
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 229# IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static
189# to econf respectively. 230# to econf respectively.
190autotools-utils_src_configure() { 231autotools-utils_src_configure() {
191 debug-print-function ${FUNCNAME} "$@" 232 debug-print-function ${FUNCNAME} "$@"
192 233
234 [[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \
235 || die 'autotools-utils.eclass: myeconfargs has to be an array.'
236
193 # Common args 237 # Common args
194 local econfargs=() 238 local econfargs=()
195 239
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 240 # Handle static-libs found in IUSE, disable them by default
202 if has static-libs ${IUSE//+}; then 241 if in_iuse static-libs; then
203 econfargs+=( 242 econfargs+=(
204 --enable-shared 243 --enable-shared
205 $(use_enable static-libs static) 244 $(use_enable static-libs static)
206 ) 245 )
207 fi 246 fi
209 # Append user args 248 # Append user args
210 econfargs+=("${myeconfargs[@]}") 249 econfargs+=("${myeconfargs[@]}")
211 250
212 _check_build_dir 251 _check_build_dir
213 mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed" 252 mkdir -p "${AUTOTOOLS_BUILD_DIR}" || die "mkdir '${AUTOTOOLS_BUILD_DIR}' failed"
214 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null 253 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null || die
215 base_src_configure "${econfargs[@]}" "$@" 254 base_src_configure "${econfargs[@]}" "$@"
216 popd > /dev/null 255 popd > /dev/null || die
217} 256}
218 257
219# @FUNCTION: autotools-utils_src_compile 258# @FUNCTION: autotools-utils_src_compile
220# @DESCRIPTION: 259# @DESCRIPTION:
221# The autotools src_compile function, invokes emake in specified AUTOTOOLS_BUILD_DIR. 260# The autotools src_compile function, invokes emake in specified AUTOTOOLS_BUILD_DIR.
222autotools-utils_src_compile() { 261autotools-utils_src_compile() {
223 debug-print-function ${FUNCNAME} "$@" 262 debug-print-function ${FUNCNAME} "$@"
224 263
225 _check_build_dir 264 _check_build_dir
226 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null 265 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null || die
227 base_src_compile "$@" 266 base_src_compile "$@"
228 popd > /dev/null 267 popd > /dev/null || die
229} 268}
230 269
231# @FUNCTION: autotools-utils_src_install 270# @FUNCTION: autotools-utils_src_install
232# @DESCRIPTION: 271# @DESCRIPTION:
233# The autotools src_install function. Runs emake install, unconditionally 272# The autotools src_install function. Runs emake install, unconditionally
238# DOCS and HTML_DOCS arrays are supported. See base.eclass(5) for reference. 277# DOCS and HTML_DOCS arrays are supported. See base.eclass(5) for reference.
239autotools-utils_src_install() { 278autotools-utils_src_install() {
240 debug-print-function ${FUNCNAME} "$@" 279 debug-print-function ${FUNCNAME} "$@"
241 280
242 _check_build_dir 281 _check_build_dir
243 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null 282 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null || die
244 base_src_install "$@" 283 base_src_install "$@"
245 popd > /dev/null 284 popd > /dev/null || die
246 285
247 # Remove libtool files and unnecessary static libs 286 # 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} 287 remove_libtool_files
251} 288}
252 289
253# @FUNCTION: autotools-utils_src_test 290# @FUNCTION: autotools-utils_src_test
254# @DESCRIPTION: 291# @DESCRIPTION:
255# The autotools src_test function. Runs emake check in build directory. 292# The autotools src_test function. Runs emake check in build directory.
256autotools-utils_src_test() { 293autotools-utils_src_test() {
257 debug-print-function ${FUNCNAME} "$@" 294 debug-print-function ${FUNCNAME} "$@"
258 295
259 _check_build_dir 296 _check_build_dir
260 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null 297 pushd "${AUTOTOOLS_BUILD_DIR}" > /dev/null || die
261 # Run default src_test as defined in ebuild.sh 298 # Run default src_test as defined in ebuild.sh
262 default_src_test 299 default_src_test
263 popd > /dev/null 300 popd > /dev/null || die
264} 301}

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

  ViewVC Help
Powered by ViewVC 1.1.20