/[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.425
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.425 2013/09/13 00:51:46 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
269# process patch files directly, or directories of patches. The patches may be 357# process patch files directly, or directories of patches. The patches may be
270# compressed (bzip/gzip/etc...) or plain text. You generally need not specify 358# compressed (bzip/gzip/etc...) or plain text. You generally need not specify
271# the -p option as epatch will automatically attempt -p0 to -p5 until things 359# the -p option as epatch will automatically attempt -p0 to -p4 until things
272# apply successfully. 360# apply successfully.
273# 361#
274# If you do not specify any patches/dirs, then epatch will default to the 362# If you do not specify any patches/dirs, then epatch will default to the
275# directory specified by EPATCH_SOURCE. 363# directory specified by EPATCH_SOURCE.
276# 364#
337 # Use the suffix from the single patch (localize it); the code 425 # Use the suffix from the single patch (localize it); the code
338 # below will find the suffix for us 426 # below will find the suffix for us
339 local EPATCH_SUFFIX=$1 427 local EPATCH_SUFFIX=$1
340 428
341 elif [[ -d $1 ]] ; then 429 elif [[ -d $1 ]] ; then
430 # We have to force sorting to C so that the wildcard expansion is consistent #471666.
431 evar_push_set LC_COLLATE C
342 # Some people like to make dirs of patches w/out suffixes (vim) 432 # Some people like to make dirs of patches w/out suffixes (vim).
343 set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"} 433 set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"}
434 evar_pop
344 435
345 elif [[ -f ${EPATCH_SOURCE}/$1 ]] ; then 436 elif [[ -f ${EPATCH_SOURCE}/$1 ]] ; then
346 # Re-use EPATCH_SOURCE as a search dir 437 # Re-use EPATCH_SOURCE as a search dir
347 epatch "${EPATCH_SOURCE}/$1" 438 epatch "${EPATCH_SOURCE}/$1"
348 return $? 439 return $?
403 eshopts_push -o noglob 494 eshopts_push -o noglob
404 495
405 local ex 496 local ex
406 for ex in ${EPATCH_EXCLUDE} ; do 497 for ex in ${EPATCH_EXCLUDE} ; do
407 if [[ ${patchname} == ${ex} ]] ; then 498 if [[ ${patchname} == ${ex} ]] ; then
499 einfo " Skipping ${patchname} due to EPATCH_EXCLUDE ..."
500 eshopts_pop
501 continue 2
502 fi
503 done
504
505 for ex in ${EPATCH_USER_EXCLUDE} ; do
506 if [[ ${patchname} == ${ex} ]] ; then
507 einfo " Skipping ${patchname} due to EPATCH_USER_EXCLUDE ..."
408 eshopts_pop 508 eshopts_pop
409 continue 2 509 continue 2
410 fi 510 fi
411 done 511 done
412 512
460 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}" 560 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}"
461 fi 561 fi
462 # Similar reason, but with relative paths. 562 # Similar reason, but with relative paths.
463 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}") 563 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}")
464 if [[ -n ${rel_paths} ]] ; then 564 if [[ -n ${rel_paths} ]] ; then
565 echo
566 eerror "Rejected Patch: ${patchname} !"
567 eerror " ( ${PATCH_TARGET} )"
568 eerror
465 eqawarn "QA Notice: Your patch uses relative paths '../'." 569 eerror "Your patch uses relative paths '../':"
466 eqawarn " In the future this will cause a failure."
467 eqawarn "${rel_paths}" 570 eerror "${rel_paths}"
571 echo
572 die "you need to fix the relative paths in patch"
468 fi 573 fi
469 574
470 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/ 575 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/
471 local patch_cmd 576 local patch_cmd
577 # Handle aliased patch command #404447 #461568
578 local patch="patch"
579 eval $(alias patch 2>/dev/null | sed 's:^alias ::')
472 while [[ ${count} -lt 5 ]] ; do 580 while [[ ${count} -lt 5 ]] ; do
473 patch_cmd="${BASH_ALIASES[patch]:-patch} -p${count} ${EPATCH_OPTS}" 581 patch_cmd="${patch} -p${count} ${EPATCH_OPTS}"
474 582
475 # Generate some useful debug info ... 583 # Generate some useful debug info ...
476 ( 584 (
477 _epatch_draw_line "***** ${patchname} *****" 585 _epatch_draw_line "***** ${patchname} *****"
478 echo 586 echo
1267# http://bugs.gentoo.org/73450 1375# http://bugs.gentoo.org/73450
1268epunt_cxx() { 1376epunt_cxx() {
1269 local dir=$1 1377 local dir=$1
1270 [[ -z ${dir} ]] && dir=${S} 1378 [[ -z ${dir} ]] && dir=${S}
1271 ebegin "Removing useless C++ checks" 1379 ebegin "Removing useless C++ checks"
1272 local f 1380 local f p any_found
1273 find "${dir}" -name configure | while read f ; do 1381 while IFS= read -r -d '' f; do
1274 patch --no-backup-if-mismatch -p0 "${f}" "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null 1382 for p in "${PORTDIR}"/eclass/ELT-patches/nocxx/*.patch ; do
1383 if patch --no-backup-if-mismatch -p1 "${f}" "${p}" >/dev/null ; then
1384 any_found=1
1385 break
1386 fi
1275 done 1387 done
1388 done < <(find "${dir}" -name configure -print0)
1389
1390 if [[ -z ${any_found} ]]; then
1391 eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt)."
1392 fi
1276 eend 0 1393 eend 0
1277} 1394}
1278 1395
1279# @FUNCTION: make_wrapper 1396# @FUNCTION: make_wrapper
1280# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath] 1397# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
1284# first optionally setting LD_LIBRARY_PATH to the colon-delimited 1401# first optionally setting LD_LIBRARY_PATH to the colon-delimited
1285# libpaths followed by optionally changing directory to chdir. 1402# libpaths followed by optionally changing directory to chdir.
1286make_wrapper() { 1403make_wrapper() {
1287 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5 1404 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
1288 local tmpwrapper=$(emktemp) 1405 local tmpwrapper=$(emktemp)
1406
1407 (
1408 echo '#!/bin/sh'
1409 [[ -n ${chdir} ]] && printf 'cd "%s"\n' "${chdir}"
1410 if [[ -n ${libdir} ]] ; then
1411 cat <<-EOF
1412 if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
1413 export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
1414 else
1415 export LD_LIBRARY_PATH="${libdir}"
1416 fi
1417 EOF
1418 fi
1289 # We don't want to quote ${bin} so that people can pass complex 1419 # We don't want to quote ${bin} so that people can pass complex
1290 # things as $bin ... "./someprog --args" 1420 # things as ${bin} ... "./someprog --args"
1421 printf 'exec %s "$@"\n' "${bin}"
1291 cat << EOF > "${tmpwrapper}" 1422 ) > "${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}" 1423 chmod go+rx "${tmpwrapper}"
1424
1304 if [[ -n ${path} ]] ; then 1425 if [[ -n ${path} ]] ; then
1305 ( 1426 (
1306 exeinto "${path}" 1427 exeinto "${path}"
1307 newexe "${tmpwrapper}" "${wrapper}" 1428 newexe "${tmpwrapper}" "${wrapper}"
1308 ) || die 1429 ) || die
1378if has "${EAPI:-0}" 0 1 2 3 4; then 1499if has "${EAPI:-0}" 0 1 2 3 4; then
1379 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963 1500 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
1380fi 1501fi
1381 1502
1382# @FUNCTION: prune_libtool_files 1503# @FUNCTION: prune_libtool_files
1383# @USAGE: [--all] 1504# @USAGE: [--all|--modules]
1384# @DESCRIPTION: 1505# @DESCRIPTION:
1385# Locate unnecessary libtool files (.la) and libtool static archives 1506# Locate unnecessary libtool files (.la) and libtool static archives
1386# (.a) and remove them from installation image. 1507# (.a) and remove them from installation image.
1387# 1508#
1388# By default, .la files are removed whenever the static linkage can 1509# By default, .la files are removed whenever the static linkage can
1389# either be performed using pkg-config or doesn't introduce additional 1510# either be performed using pkg-config or doesn't introduce additional
1390# flags. 1511# flags.
1391# 1512#
1513# If '--modules' argument is passed, .la files for modules (plugins) are
1514# removed as well. This is usually useful when the package installs
1515# plugins and the plugin loader does not use .la files.
1516#
1392# If '--all' argument is passed, all .la files are removed. This is 1517# If '--all' argument is passed, all .la files are removed without
1393# usually useful when the package installs plugins and does not use .la 1518# performing any heuristic on them. You shouldn't ever use that,
1394# files for loading them. 1519# and instead report a bug in the algorithm instead.
1395# 1520#
1396# The .a files are only removed whenever corresponding .la files state 1521# The .a files are only removed whenever corresponding .la files state
1397# that they should not be linked to, i.e. whenever these files 1522# that they should not be linked to, i.e. whenever these files
1398# correspond to plugins. 1523# correspond to plugins.
1399# 1524#
1400# Note: if your package installs both static libraries and .pc files, 1525# Note: if your package installs both static libraries and .pc files
1526# which use variable substitution for -l flags, you need to add
1401# you need to add pkg-config to your DEPEND. 1527# pkg-config to your DEPEND.
1402prune_libtool_files() { 1528prune_libtool_files() {
1403 debug-print-function ${FUNCNAME} "$@" 1529 debug-print-function ${FUNCNAME} "$@"
1404 1530
1405 local removing_all opt 1531 local removing_all removing_modules opt
1406 for opt; do 1532 for opt; do
1407 case "${opt}" in 1533 case "${opt}" in
1408 --all) 1534 --all)
1409 removing_all=1 1535 removing_all=1
1536 removing_modules=1
1537 ;;
1538 --modules)
1539 removing_modules=1
1410 ;; 1540 ;;
1411 *) 1541 *)
1412 die "Invalid argument to ${FUNCNAME}(): ${opt}" 1542 die "Invalid argument to ${FUNCNAME}(): ${opt}"
1413 esac 1543 esac
1414 done 1544 done
1416 local f 1546 local f
1417 local queue=() 1547 local queue=()
1418 while IFS= read -r -d '' f; do # for all .la files 1548 while IFS= read -r -d '' f; do # for all .la files
1419 local archivefile=${f/%.la/.a} 1549 local archivefile=${f/%.la/.a}
1420 1550
1551 # The following check is done by libtool itself.
1552 # It helps us avoid removing random files which match '*.la',
1553 # see bug #468380.
1554 if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
1555 continue
1556 fi
1557
1421 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed' 1558 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1559 local reason pkgconfig_scanned
1560 local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
1422 1561
1562 if [[ ${snotlink} == yes ]]; then
1563
1423 # Remove static libs we're not supposed to link against. 1564 # Remove static libs we're not supposed to link against.
1424 if grep -q '^shouldnotlink=yes$' "${f}"; then
1425 if [[ -f ${archivefile} ]]; then 1565 if [[ -f ${archivefile} ]]; then
1426 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)" 1566 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1427 queue+=( "${archivefile}" ) 1567 queue+=( "${archivefile}" )
1428 fi 1568 fi
1429 1569
1430 # The .la file may be used by a module loader, so avoid removing it 1570 # The .la file may be used by a module loader, so avoid removing it
1431 # unless explicitly requested. 1571 # unless explicitly requested.
1432 [[ ${removing_all} ]] || continue 1572 if [[ ${removing_modules} ]]; then
1573 reason='module'
1433 fi 1574 fi
1434 1575
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 1576 else
1577
1578 # Remove .la files when:
1579 # - user explicitly wants us to remove all .la files,
1580 # - respective static archive doesn't exist,
1581 # - they are covered by a .pc file already,
1582 # - they don't provide any new information (no libs & no flags).
1583
1584 if [[ ${removing_all} ]]; then
1585 reason='requested'
1586 elif [[ ! -f ${archivefile} ]]; then
1587 reason='no static archive'
1588 elif [[ ! $(sed -nre \
1589 "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
1590 "${f}") ]]; then
1591 reason='no libs & flags'
1592 else
1450 if [[ ! ${pkgconfig_scanned} ]]; then 1593 if [[ ! ${pkgconfig_scanned} ]]; then
1451 # Create a list of all .pc-covered libs. 1594 # Create a list of all .pc-covered libs.
1452 local pc_libs=() 1595 local pc_libs=()
1453 if [[ ! ${removing_all} ]]; then 1596 if [[ ! ${removing_all} ]]; then
1454 local f 1597 local pc
1455 local tf=${T}/prune-lt-files.pc 1598 local tf=${T}/prune-lt-files.pc
1456 local pkgconf=$(tc-getPKG_CONFIG) 1599 local pkgconf=$(tc-getPKG_CONFIG)
1457 1600
1458 while IFS= read -r -d '' f; do # for all .pc files 1601 while IFS= read -r -d '' pc; do # for all .pc files
1459 local arg 1602 local arg libs
1460 1603
1604 # Use pkg-config if available (and works),
1605 # fallback to sed.
1606 if ${pkgconf} --exists "${pc}" &>/dev/null; then
1461 sed -e '/^Requires:/d' "${f}" > "${tf}" 1607 sed -e '/^Requires:/d' "${pc}" > "${tf}"
1462 for arg in $("${pkgconf}" --libs "${tf}"); do 1608 libs=$(${pkgconf} --libs "${tf}")
1463 [[ ${arg} == -l* ]] && pc_libs+=( lib${arg#-l}.la ) 1609 else
1610 libs=$(sed -ne 's/^Libs://p' "${pc}")
1611 fi
1612
1613 for arg in ${libs}; do
1614 if [[ ${arg} == -l* ]]; then
1615 if [[ ${arg} == '*$*' ]]; then
1616 eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
1617 eqawarn "(arg: ${arg})"
1618 eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
1619 fi
1620
1621 pc_libs+=( lib${arg#-l}.la )
1622 fi
1464 done 1623 done
1465 done < <(find "${D}" -type f -name '*.pc' -print0) 1624 done < <(find "${D}" -type f -name '*.pc' -print0)
1466 1625
1467 rm -f "${tf}" 1626 rm -f "${tf}"
1468 fi 1627 fi
1469 1628
1470 pkgconfig_scanned=1 1629 pkgconfig_scanned=1
1471 fi 1630 fi # pkgconfig_scanned
1472 1631
1473 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc' 1632 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1474 fi 1633 fi # removal due to .pc
1634
1635 fi # shouldnotlink==no
1475 1636
1476 if [[ ${reason} ]]; then 1637 if [[ ${reason} ]]; then
1477 einfo "Removing unnecessary ${f#${D%/}} (${reason})" 1638 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1478 queue+=( "${f}" ) 1639 queue+=( "${f}" )
1479 fi 1640 fi

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

  ViewVC Help
Powered by ViewVC 1.1.20