/[gentoo-x86]/eclass/eutils.eclass
Gentoo

Diff of /eclass/eutils.eclass

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

Revision 1.407 Revision 1.423
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2013 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/eutils.eclass,v 1.407 2012/10/11 16:50:53 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.423 2013/06/21 23:56:06 vapier Exp $
4 4
5# @ECLASS: eutils.eclass 5# @ECLASS: eutils.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# base-system@gentoo.org 7# base-system@gentoo.org
8# @BLURB: many extra (but common) functions that are used in ebuilds 8# @BLURB: many extra (but common) functions that are used in ebuilds
142 142
143 if [[ -n ${__estack_retvar} ]] ; then 143 if [[ -n ${__estack_retvar} ]] ; then
144 eval ${__estack_retvar}=\"\${${__estack_name}\[${__estack_i}\]}\" 144 eval ${__estack_retvar}=\"\${${__estack_name}\[${__estack_i}\]}\"
145 fi 145 fi
146 eval unset ${__estack_name}\[${__estack_i}\] 146 eval unset ${__estack_name}\[${__estack_i}\]
147}
148
149# @FUNCTION: evar_push
150# @USAGE: <variable to save> [more vars to save]
151# @DESCRIPTION:
152# This let's you temporarily modify a variable and then restore it (including
153# set vs unset semantics). Arrays are not supported at this time.
154#
155# This is meant for variables where using `local` does not work (such as
156# exported variables, or only temporarily changing things in a func).
157#
158# For example:
159# @CODE
160# evar_push LC_ALL
161# export LC_ALL=C
162# ... do some stuff that needs LC_ALL=C set ...
163# evar_pop
164#
165# # You can also save/restore more than one var at a time
166# evar_push BUTTERFLY IN THE SKY
167# ... do stuff with the vars ...
168# evar_pop # This restores just one var, SKY
169# ... do more stuff ...
170# evar_pop 3 # This pops the remaining 3 vars
171# @CODE
172evar_push() {
173 local var val
174 for var ; do
175 [[ ${!var+set} == "set" ]] \
176 && val=${!var} \
177 || val="${___ECLASS_ONCE_EUTILS}"
178 estack_push evar "${var}" "${val}"
179 done
180}
181
182# @FUNCTION: evar_push_set
183# @USAGE: <variable to save> [new value to store]
184# @DESCRIPTION:
185# This is a handy shortcut to save and temporarily set a variable. If a value
186# is not specified, the var will be unset.
187evar_push_set() {
188 local var=$1
189 evar_push ${var}
190 case $# in
191 1) unset ${var} ;;
192 2) printf -v "${var}" '%s' "$2" ;;
193 *) die "${FUNCNAME}: incorrect # of args: $*" ;;
194 esac
195}
196
197# @FUNCTION: evar_pop
198# @USAGE: [number of vars to restore]
199# @DESCRIPTION:
200# Restore the variables to the state saved with the corresponding
201# evar_push call. See that function for more details.
202evar_pop() {
203 local cnt=${1:-bad}
204 case $# in
205 0) cnt=1 ;;
206 1) isdigit "${cnt}" || die "${FUNCNAME}: first arg must be a number: $*" ;;
207 *) die "${FUNCNAME}: only accepts one arg: $*" ;;
208 esac
209
210 local var val
211 while (( cnt-- )) ; do
212 estack_pop evar val || die "${FUNCNAME}: unbalanced push"
213 estack_pop evar var || die "${FUNCNAME}: unbalanced push"
214 [[ ${val} == "${___ECLASS_ONCE_EUTILS}" ]] \
215 && unset ${var} \
216 || printf -v "${var}" '%s' "${val}"
217 done
147} 218}
148 219
149# @FUNCTION: eshopts_push 220# @FUNCTION: eshopts_push
150# @USAGE: [options to `set` or `shopt`] 221# @USAGE: [options to `set` or `shopt`]
151# @DESCRIPTION: 222# @DESCRIPTION:
216 local s 287 local s
217 estack_pop eumask s || die "${FUNCNAME}: unbalanced push" 288 estack_pop eumask s || die "${FUNCNAME}: unbalanced push"
218 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}" 289 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
219} 290}
220 291
292# @FUNCTION: isdigit
293# @USAGE: <number> [more numbers]
294# @DESCRIPTION:
295# Return true if all arguments are numbers.
296isdigit() {
297 local d
298 for d ; do
299 [[ ${d:-bad} == *[!0-9]* ]] && return 1
300 done
301 return 0
302}
303
221# @VARIABLE: EPATCH_SOURCE 304# @VARIABLE: EPATCH_SOURCE
222# @DESCRIPTION: 305# @DESCRIPTION:
223# Default directory to search for patches. 306# Default directory to search for patches.
224EPATCH_SOURCE="${WORKDIR}/patch" 307EPATCH_SOURCE="${WORKDIR}/patch"
225# @VARIABLE: EPATCH_SUFFIX 308# @VARIABLE: EPATCH_SUFFIX
259# @VARIABLE: EPATCH_FORCE 342# @VARIABLE: EPATCH_FORCE
260# @DESCRIPTION: 343# @DESCRIPTION:
261# Only require patches to match EPATCH_SUFFIX rather than the extended 344# Only require patches to match EPATCH_SUFFIX rather than the extended
262# arch naming style. 345# arch naming style.
263EPATCH_FORCE="no" 346EPATCH_FORCE="no"
347# @VARIABLE: EPATCH_USER_EXCLUDE
348# @DEFAULT_UNSET
349# @DESCRIPTION:
350# List of patches not to apply. Note this is only file names,
351# and not the full path. Globs accepted.
264 352
265# @FUNCTION: epatch 353# @FUNCTION: epatch
266# @USAGE: [options] [patches] [dirs of patches] 354# @USAGE: [options] [patches] [dirs of patches]
267# @DESCRIPTION: 355# @DESCRIPTION:
268# epatch is designed to greatly simplify the application of patches. It can 356# epatch is designed to greatly simplify the application of patches. It can
403 eshopts_push -o noglob 491 eshopts_push -o noglob
404 492
405 local ex 493 local ex
406 for ex in ${EPATCH_EXCLUDE} ; do 494 for ex in ${EPATCH_EXCLUDE} ; do
407 if [[ ${patchname} == ${ex} ]] ; then 495 if [[ ${patchname} == ${ex} ]] ; then
496 einfo " Skipping ${patchname} due to EPATCH_EXCLUDE ..."
497 eshopts_pop
498 continue 2
499 fi
500 done
501
502 for ex in ${EPATCH_USER_EXCLUDE} ; do
503 if [[ ${patchname} == ${ex} ]] ; then
504 einfo " Skipping ${patchname} due to EPATCH_USER_EXCLUDE ..."
408 eshopts_pop 505 eshopts_pop
409 continue 2 506 continue 2
410 fi 507 fi
411 done 508 done
412 509
460 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}" 557 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}"
461 fi 558 fi
462 # Similar reason, but with relative paths. 559 # Similar reason, but with relative paths.
463 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}") 560 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}")
464 if [[ -n ${rel_paths} ]] ; then 561 if [[ -n ${rel_paths} ]] ; then
562 echo
563 eerror "Rejected Patch: ${patchname} !"
564 eerror " ( ${PATCH_TARGET} )"
565 eerror
465 eqawarn "QA Notice: Your patch uses relative paths '../'." 566 eerror "Your patch uses relative paths '../':"
466 eqawarn " In the future this will cause a failure."
467 eqawarn "${rel_paths}" 567 eerror "${rel_paths}"
568 echo
569 die "you need to fix the relative paths in patch"
468 fi 570 fi
469 571
470 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/ 572 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/
471 local patch_cmd 573 local patch_cmd
574 # Handle aliased patch command #404447 #461568
575 local patch="patch"
576 eval $(alias patch 2>/dev/null | sed 's:^alias ::')
472 while [[ ${count} -lt 5 ]] ; do 577 while [[ ${count} -lt 5 ]] ; do
473 patch_cmd="${BASH_ALIASES[patch]:-patch} -p${count} ${EPATCH_OPTS}" 578 patch_cmd="${patch} -p${count} ${EPATCH_OPTS}"
474 579
475 # Generate some useful debug info ... 580 # Generate some useful debug info ...
476 ( 581 (
477 _epatch_draw_line "***** ${patchname} *****" 582 _epatch_draw_line "***** ${patchname} *****"
478 echo 583 echo
1267# http://bugs.gentoo.org/73450 1372# http://bugs.gentoo.org/73450
1268epunt_cxx() { 1373epunt_cxx() {
1269 local dir=$1 1374 local dir=$1
1270 [[ -z ${dir} ]] && dir=${S} 1375 [[ -z ${dir} ]] && dir=${S}
1271 ebegin "Removing useless C++ checks" 1376 ebegin "Removing useless C++ checks"
1272 local f 1377 local f p any_found
1273 find "${dir}" -name configure | while read f ; do 1378 while IFS= read -r -d '' f; do
1274 patch --no-backup-if-mismatch -p0 "${f}" "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null 1379 for p in "${PORTDIR}"/eclass/ELT-patches/nocxx/*.patch ; do
1380 if patch --no-backup-if-mismatch -p1 "${f}" "${p}" >/dev/null ; then
1381 any_found=1
1382 break
1383 fi
1275 done 1384 done
1385 done < <(find "${dir}" -name configure -print0)
1386
1387 if [[ -z ${any_found} ]]; then
1388 eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt)."
1389 fi
1276 eend 0 1390 eend 0
1277} 1391}
1278 1392
1279# @FUNCTION: make_wrapper 1393# @FUNCTION: make_wrapper
1280# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath] 1394# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
1284# first optionally setting LD_LIBRARY_PATH to the colon-delimited 1398# first optionally setting LD_LIBRARY_PATH to the colon-delimited
1285# libpaths followed by optionally changing directory to chdir. 1399# libpaths followed by optionally changing directory to chdir.
1286make_wrapper() { 1400make_wrapper() {
1287 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5 1401 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
1288 local tmpwrapper=$(emktemp) 1402 local tmpwrapper=$(emktemp)
1403
1404 (
1405 echo '#!/bin/sh'
1406 [[ -n ${chdir} ]] && printf 'cd "%s"\n' "${chdir}"
1407 if [[ -n ${libdir} ]] ; then
1408 cat <<-EOF
1409 if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
1410 export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
1411 else
1412 export LD_LIBRARY_PATH="${libdir}"
1413 fi
1414 EOF
1415 fi
1289 # We don't want to quote ${bin} so that people can pass complex 1416 # We don't want to quote ${bin} so that people can pass complex
1290 # things as $bin ... "./someprog --args" 1417 # things as ${bin} ... "./someprog --args"
1418 printf 'exec %s "$@"\n' "${bin}"
1291 cat << EOF > "${tmpwrapper}" 1419 ) > "${tmpwrapper}"
1292#!/bin/sh
1293cd "${chdir:-.}"
1294if [ -n "${libdir}" ] ; then
1295 if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
1296 export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
1297 else
1298 export LD_LIBRARY_PATH="${libdir}"
1299 fi
1300fi
1301exec ${bin} "\$@"
1302EOF
1303 chmod go+rx "${tmpwrapper}" 1420 chmod go+rx "${tmpwrapper}"
1421
1304 if [[ -n ${path} ]] ; then 1422 if [[ -n ${path} ]] ; then
1305 ( 1423 (
1306 exeinto "${path}" 1424 exeinto "${path}"
1307 newexe "${tmpwrapper}" "${wrapper}" 1425 newexe "${tmpwrapper}" "${wrapper}"
1308 ) || die 1426 ) || die
1378if has "${EAPI:-0}" 0 1 2 3 4; then 1496if has "${EAPI:-0}" 0 1 2 3 4; then
1379 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963 1497 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
1380fi 1498fi
1381 1499
1382# @FUNCTION: prune_libtool_files 1500# @FUNCTION: prune_libtool_files
1383# @USAGE: [--all] 1501# @USAGE: [--all|--modules]
1384# @DESCRIPTION: 1502# @DESCRIPTION:
1385# Locate unnecessary libtool files (.la) and libtool static archives 1503# Locate unnecessary libtool files (.la) and libtool static archives
1386# (.a) and remove them from installation image. 1504# (.a) and remove them from installation image.
1387# 1505#
1388# By default, .la files are removed whenever the static linkage can 1506# By default, .la files are removed whenever the static linkage can
1389# either be performed using pkg-config or doesn't introduce additional 1507# either be performed using pkg-config or doesn't introduce additional
1390# flags. 1508# flags.
1391# 1509#
1510# If '--modules' argument is passed, .la files for modules (plugins) are
1511# removed as well. This is usually useful when the package installs
1512# plugins and the plugin loader does not use .la files.
1513#
1392# If '--all' argument is passed, all .la files are removed. This is 1514# If '--all' argument is passed, all .la files are removed without
1393# usually useful when the package installs plugins and does not use .la 1515# performing any heuristic on them. You shouldn't ever use that,
1394# files for loading them. 1516# and instead report a bug in the algorithm instead.
1395# 1517#
1396# The .a files are only removed whenever corresponding .la files state 1518# The .a files are only removed whenever corresponding .la files state
1397# that they should not be linked to, i.e. whenever these files 1519# that they should not be linked to, i.e. whenever these files
1398# correspond to plugins. 1520# correspond to plugins.
1399# 1521#
1400# Note: if your package installs both static libraries and .pc files, 1522# Note: if your package installs both static libraries and .pc files
1523# which use variable substitution for -l flags, you need to add
1401# you need to add pkg-config to your DEPEND. 1524# pkg-config to your DEPEND.
1402prune_libtool_files() { 1525prune_libtool_files() {
1403 debug-print-function ${FUNCNAME} "$@" 1526 debug-print-function ${FUNCNAME} "$@"
1404 1527
1405 local removing_all opt 1528 local removing_all removing_modules opt
1406 for opt; do 1529 for opt; do
1407 case "${opt}" in 1530 case "${opt}" in
1408 --all) 1531 --all)
1409 removing_all=1 1532 removing_all=1
1533 removing_modules=1
1534 ;;
1535 --modules)
1536 removing_modules=1
1410 ;; 1537 ;;
1411 *) 1538 *)
1412 die "Invalid argument to ${FUNCNAME}(): ${opt}" 1539 die "Invalid argument to ${FUNCNAME}(): ${opt}"
1413 esac 1540 esac
1414 done 1541 done
1416 local f 1543 local f
1417 local queue=() 1544 local queue=()
1418 while IFS= read -r -d '' f; do # for all .la files 1545 while IFS= read -r -d '' f; do # for all .la files
1419 local archivefile=${f/%.la/.a} 1546 local archivefile=${f/%.la/.a}
1420 1547
1548 # The following check is done by libtool itself.
1549 # It helps us avoid removing random files which match '*.la',
1550 # see bug #468380.
1551 if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
1552 continue
1553 fi
1554
1421 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed' 1555 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1556 local reason pkgconfig_scanned
1557 local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
1422 1558
1559 if [[ ${snotlink} == yes ]]; then
1560
1423 # Remove static libs we're not supposed to link against. 1561 # Remove static libs we're not supposed to link against.
1424 if grep -q '^shouldnotlink=yes$' "${f}"; then
1425 if [[ -f ${archivefile} ]]; then 1562 if [[ -f ${archivefile} ]]; then
1426 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)" 1563 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1427 queue+=( "${archivefile}" ) 1564 queue+=( "${archivefile}" )
1428 fi 1565 fi
1429 1566
1430 # The .la file may be used by a module loader, so avoid removing it 1567 # The .la file may be used by a module loader, so avoid removing it
1431 # unless explicitly requested. 1568 # unless explicitly requested.
1432 [[ ${removing_all} ]] || continue 1569 if [[ ${removing_modules} ]]; then
1570 reason='module'
1433 fi 1571 fi
1434 1572
1435 # Remove .la files when:
1436 # - user explicitly wants us to remove all .la files,
1437 # - respective static archive doesn't exist,
1438 # - they are covered by a .pc file already,
1439 # - they don't provide any new information (no libs & no flags).
1440 local reason pkgconfig_scanned
1441 if [[ ${removing_all} ]]; then
1442 reason='requested'
1443 elif [[ ! -f ${archivefile} ]]; then
1444 reason='no static archive'
1445 elif [[ ! $(sed -nre \
1446 "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
1447 "${f}") ]]; then
1448 reason='no libs & flags'
1449 else 1573 else
1574
1575 # Remove .la files when:
1576 # - user explicitly wants us to remove all .la files,
1577 # - respective static archive doesn't exist,
1578 # - they are covered by a .pc file already,
1579 # - they don't provide any new information (no libs & no flags).
1580
1581 if [[ ${removing_all} ]]; then
1582 reason='requested'
1583 elif [[ ! -f ${archivefile} ]]; then
1584 reason='no static archive'
1585 elif [[ ! $(sed -nre \
1586 "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
1587 "${f}") ]]; then
1588 reason='no libs & flags'
1589 else
1450 if [[ ! ${pkgconfig_scanned} ]]; then 1590 if [[ ! ${pkgconfig_scanned} ]]; then
1451 # Create a list of all .pc-covered libs. 1591 # Create a list of all .pc-covered libs.
1452 local pc_libs=() 1592 local pc_libs=()
1453 if [[ ! ${removing_all} ]]; then 1593 if [[ ! ${removing_all} ]]; then
1454 local f 1594 local pc
1455 local tf=${T}/prune-lt-files.pc 1595 local tf=${T}/prune-lt-files.pc
1456 local pkgconf=$(tc-getPKG_CONFIG) 1596 local pkgconf=$(tc-getPKG_CONFIG)
1457 1597
1458 while IFS= read -r -d '' f; do # for all .pc files 1598 while IFS= read -r -d '' pc; do # for all .pc files
1459 local arg 1599 local arg libs
1460 1600
1601 # Use pkg-config if available (and works),
1602 # fallback to sed.
1603 if ${pkgconf} --exists "${pc}" &>/dev/null; then
1461 sed -e '/^Requires:/d' "${f}" > "${tf}" 1604 sed -e '/^Requires:/d' "${pc}" > "${tf}"
1462 for arg in $("${pkgconf}" --libs "${tf}"); do 1605 libs=$(${pkgconf} --libs "${tf}")
1463 [[ ${arg} == -l* ]] && pc_libs+=( lib${arg#-l}.la ) 1606 else
1607 libs=$(sed -ne 's/^Libs://p' "${pc}")
1608 fi
1609
1610 for arg in ${libs}; do
1611 if [[ ${arg} == -l* ]]; then
1612 if [[ ${arg} == '*$*' ]]; then
1613 eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
1614 eqawarn "(arg: ${arg})"
1615 eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
1616 fi
1617
1618 pc_libs+=( lib${arg#-l}.la )
1619 fi
1464 done 1620 done
1465 done < <(find "${D}" -type f -name '*.pc' -print0) 1621 done < <(find "${D}" -type f -name '*.pc' -print0)
1466 1622
1467 rm -f "${tf}" 1623 rm -f "${tf}"
1468 fi 1624 fi
1469 1625
1470 pkgconfig_scanned=1 1626 pkgconfig_scanned=1
1471 fi 1627 fi # pkgconfig_scanned
1472 1628
1473 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc' 1629 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1474 fi 1630 fi # removal due to .pc
1631
1632 fi # shouldnotlink==no
1475 1633
1476 if [[ ${reason} ]]; then 1634 if [[ ${reason} ]]; then
1477 einfo "Removing unnecessary ${f#${D%/}} (${reason})" 1635 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1478 queue+=( "${f}" ) 1636 queue+=( "${f}" )
1479 fi 1637 fi

Legend:
Removed from v.1.407  
changed lines
  Added in v.1.423

  ViewVC Help
Powered by ViewVC 1.1.20