/[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.421
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.421 2013/05/22 05:10:29 mgorny 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
259# @VARIABLE: EPATCH_FORCE 259# @VARIABLE: EPATCH_FORCE
260# @DESCRIPTION: 260# @DESCRIPTION:
261# Only require patches to match EPATCH_SUFFIX rather than the extended 261# Only require patches to match EPATCH_SUFFIX rather than the extended
262# arch naming style. 262# arch naming style.
263EPATCH_FORCE="no" 263EPATCH_FORCE="no"
264# @VARIABLE: EPATCH_USER_EXCLUDE
265# @DEFAULT_UNSET
266# @DESCRIPTION:
267# List of patches not to apply. Note this is only file names,
268# and not the full path. Globs accepted.
264 269
265# @FUNCTION: epatch 270# @FUNCTION: epatch
266# @USAGE: [options] [patches] [dirs of patches] 271# @USAGE: [options] [patches] [dirs of patches]
267# @DESCRIPTION: 272# @DESCRIPTION:
268# epatch is designed to greatly simplify the application of patches. It can 273# epatch is designed to greatly simplify the application of patches. It can
403 eshopts_push -o noglob 408 eshopts_push -o noglob
404 409
405 local ex 410 local ex
406 for ex in ${EPATCH_EXCLUDE} ; do 411 for ex in ${EPATCH_EXCLUDE} ; do
407 if [[ ${patchname} == ${ex} ]] ; then 412 if [[ ${patchname} == ${ex} ]] ; then
413 einfo " Skipping ${patchname} due to EPATCH_EXCLUDE ..."
414 eshopts_pop
415 continue 2
416 fi
417 done
418
419 for ex in ${EPATCH_USER_EXCLUDE} ; do
420 if [[ ${patchname} == ${ex} ]] ; then
421 einfo " Skipping ${patchname} due to EPATCH_USER_EXCLUDE ..."
408 eshopts_pop 422 eshopts_pop
409 continue 2 423 continue 2
410 fi 424 fi
411 done 425 done
412 426
460 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}" 474 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}"
461 fi 475 fi
462 # Similar reason, but with relative paths. 476 # Similar reason, but with relative paths.
463 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}") 477 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}")
464 if [[ -n ${rel_paths} ]] ; then 478 if [[ -n ${rel_paths} ]] ; then
479 echo
480 eerror "Rejected Patch: ${patchname} !"
481 eerror " ( ${PATCH_TARGET} )"
482 eerror
465 eqawarn "QA Notice: Your patch uses relative paths '../'." 483 eerror "Your patch uses relative paths '../':"
466 eqawarn " In the future this will cause a failure."
467 eqawarn "${rel_paths}" 484 eerror "${rel_paths}"
485 echo
486 die "you need to fix the relative paths in patch"
468 fi 487 fi
469 488
470 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/ 489 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/
471 local patch_cmd 490 local patch_cmd
491 # Handle aliased patch command #404447 #461568
492 local patch="patch"
493 eval $(alias patch 2>/dev/null | sed 's:^alias ::')
472 while [[ ${count} -lt 5 ]] ; do 494 while [[ ${count} -lt 5 ]] ; do
473 patch_cmd="${BASH_ALIASES[patch]:-patch} -p${count} ${EPATCH_OPTS}" 495 patch_cmd="${patch} -p${count} ${EPATCH_OPTS}"
474 496
475 # Generate some useful debug info ... 497 # Generate some useful debug info ...
476 ( 498 (
477 _epatch_draw_line "***** ${patchname} *****" 499 _epatch_draw_line "***** ${patchname} *****"
478 echo 500 echo
1267# http://bugs.gentoo.org/73450 1289# http://bugs.gentoo.org/73450
1268epunt_cxx() { 1290epunt_cxx() {
1269 local dir=$1 1291 local dir=$1
1270 [[ -z ${dir} ]] && dir=${S} 1292 [[ -z ${dir} ]] && dir=${S}
1271 ebegin "Removing useless C++ checks" 1293 ebegin "Removing useless C++ checks"
1272 local f 1294 local f p any_found
1273 find "${dir}" -name configure | while read f ; do 1295 while IFS= read -r -d '' f; do
1274 patch --no-backup-if-mismatch -p0 "${f}" "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null 1296 for p in "${PORTDIR}"/eclass/ELT-patches/nocxx/*.patch ; do
1297 if patch --no-backup-if-mismatch -p1 "${f}" "${p}" >/dev/null ; then
1298 any_found=1
1299 break
1300 fi
1275 done 1301 done
1302 done < <(find "${dir}" -name configure -print0)
1303
1304 if [[ -z ${any_found} ]]; then
1305 eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt)."
1306 fi
1276 eend 0 1307 eend 0
1277} 1308}
1278 1309
1279# @FUNCTION: make_wrapper 1310# @FUNCTION: make_wrapper
1280# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath] 1311# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
1284# first optionally setting LD_LIBRARY_PATH to the colon-delimited 1315# first optionally setting LD_LIBRARY_PATH to the colon-delimited
1285# libpaths followed by optionally changing directory to chdir. 1316# libpaths followed by optionally changing directory to chdir.
1286make_wrapper() { 1317make_wrapper() {
1287 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5 1318 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
1288 local tmpwrapper=$(emktemp) 1319 local tmpwrapper=$(emktemp)
1320
1321 (
1322 echo '#!/bin/sh'
1323 [[ -n ${chdir} ]] && printf 'cd "%s"\n' "${chdir}"
1324 if [[ -n ${libdir} ]] ; then
1325 cat <<-EOF
1326 if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
1327 export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
1328 else
1329 export LD_LIBRARY_PATH="${libdir}"
1330 fi
1331 EOF
1332 fi
1289 # We don't want to quote ${bin} so that people can pass complex 1333 # We don't want to quote ${bin} so that people can pass complex
1290 # things as $bin ... "./someprog --args" 1334 # things as ${bin} ... "./someprog --args"
1335 printf 'exec %s "$@"\n' "${bin}"
1291 cat << EOF > "${tmpwrapper}" 1336 ) > "${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}" 1337 chmod go+rx "${tmpwrapper}"
1338
1304 if [[ -n ${path} ]] ; then 1339 if [[ -n ${path} ]] ; then
1305 ( 1340 (
1306 exeinto "${path}" 1341 exeinto "${path}"
1307 newexe "${tmpwrapper}" "${wrapper}" 1342 newexe "${tmpwrapper}" "${wrapper}"
1308 ) || die 1343 ) || die
1378if has "${EAPI:-0}" 0 1 2 3 4; then 1413if has "${EAPI:-0}" 0 1 2 3 4; then
1379 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963 1414 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
1380fi 1415fi
1381 1416
1382# @FUNCTION: prune_libtool_files 1417# @FUNCTION: prune_libtool_files
1383# @USAGE: [--all] 1418# @USAGE: [--all|--modules]
1384# @DESCRIPTION: 1419# @DESCRIPTION:
1385# Locate unnecessary libtool files (.la) and libtool static archives 1420# Locate unnecessary libtool files (.la) and libtool static archives
1386# (.a) and remove them from installation image. 1421# (.a) and remove them from installation image.
1387# 1422#
1388# By default, .la files are removed whenever the static linkage can 1423# By default, .la files are removed whenever the static linkage can
1389# either be performed using pkg-config or doesn't introduce additional 1424# either be performed using pkg-config or doesn't introduce additional
1390# flags. 1425# flags.
1391# 1426#
1427# If '--modules' argument is passed, .la files for modules (plugins) are
1428# removed as well. This is usually useful when the package installs
1429# plugins and the plugin loader does not use .la files.
1430#
1392# If '--all' argument is passed, all .la files are removed. This is 1431# If '--all' argument is passed, all .la files are removed without
1393# usually useful when the package installs plugins and does not use .la 1432# performing any heuristic on them. You shouldn't ever use that,
1394# files for loading them. 1433# and instead report a bug in the algorithm instead.
1395# 1434#
1396# The .a files are only removed whenever corresponding .la files state 1435# The .a files are only removed whenever corresponding .la files state
1397# that they should not be linked to, i.e. whenever these files 1436# that they should not be linked to, i.e. whenever these files
1398# correspond to plugins. 1437# correspond to plugins.
1399# 1438#
1400# Note: if your package installs both static libraries and .pc files, 1439# Note: if your package installs both static libraries and .pc files
1440# which use variable substitution for -l flags, you need to add
1401# you need to add pkg-config to your DEPEND. 1441# pkg-config to your DEPEND.
1402prune_libtool_files() { 1442prune_libtool_files() {
1403 debug-print-function ${FUNCNAME} "$@" 1443 debug-print-function ${FUNCNAME} "$@"
1404 1444
1405 local removing_all opt 1445 local removing_all removing_modules opt
1406 for opt; do 1446 for opt; do
1407 case "${opt}" in 1447 case "${opt}" in
1408 --all) 1448 --all)
1409 removing_all=1 1449 removing_all=1
1450 removing_modules=1
1451 ;;
1452 --modules)
1453 removing_modules=1
1410 ;; 1454 ;;
1411 *) 1455 *)
1412 die "Invalid argument to ${FUNCNAME}(): ${opt}" 1456 die "Invalid argument to ${FUNCNAME}(): ${opt}"
1413 esac 1457 esac
1414 done 1458 done
1416 local f 1460 local f
1417 local queue=() 1461 local queue=()
1418 while IFS= read -r -d '' f; do # for all .la files 1462 while IFS= read -r -d '' f; do # for all .la files
1419 local archivefile=${f/%.la/.a} 1463 local archivefile=${f/%.la/.a}
1420 1464
1465 # The following check is done by libtool itself.
1466 # It helps us avoid removing random files which match '*.la',
1467 # see bug #468380.
1468 if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
1469 continue
1470 fi
1471
1421 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed' 1472 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1473 local reason pkgconfig_scanned
1474 local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
1422 1475
1476 if [[ ${snotlink} == yes ]]; then
1477
1423 # Remove static libs we're not supposed to link against. 1478 # Remove static libs we're not supposed to link against.
1424 if grep -q '^shouldnotlink=yes$' "${f}"; then
1425 if [[ -f ${archivefile} ]]; then 1479 if [[ -f ${archivefile} ]]; then
1426 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)" 1480 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1427 queue+=( "${archivefile}" ) 1481 queue+=( "${archivefile}" )
1428 fi 1482 fi
1429 1483
1430 # The .la file may be used by a module loader, so avoid removing it 1484 # The .la file may be used by a module loader, so avoid removing it
1431 # unless explicitly requested. 1485 # unless explicitly requested.
1432 [[ ${removing_all} ]] || continue 1486 if [[ ${removing_modules} ]]; then
1487 reason='module'
1433 fi 1488 fi
1434 1489
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 1490 else
1491
1492 # Remove .la files when:
1493 # - user explicitly wants us to remove all .la files,
1494 # - respective static archive doesn't exist,
1495 # - they are covered by a .pc file already,
1496 # - they don't provide any new information (no libs & no flags).
1497
1498 if [[ ${removing_all} ]]; then
1499 reason='requested'
1500 elif [[ ! -f ${archivefile} ]]; then
1501 reason='no static archive'
1502 elif [[ ! $(sed -nre \
1503 "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
1504 "${f}") ]]; then
1505 reason='no libs & flags'
1506 else
1450 if [[ ! ${pkgconfig_scanned} ]]; then 1507 if [[ ! ${pkgconfig_scanned} ]]; then
1451 # Create a list of all .pc-covered libs. 1508 # Create a list of all .pc-covered libs.
1452 local pc_libs=() 1509 local pc_libs=()
1453 if [[ ! ${removing_all} ]]; then 1510 if [[ ! ${removing_all} ]]; then
1454 local f 1511 local pc
1455 local tf=${T}/prune-lt-files.pc 1512 local tf=${T}/prune-lt-files.pc
1456 local pkgconf=$(tc-getPKG_CONFIG) 1513 local pkgconf=$(tc-getPKG_CONFIG)
1457 1514
1458 while IFS= read -r -d '' f; do # for all .pc files 1515 while IFS= read -r -d '' pc; do # for all .pc files
1459 local arg 1516 local arg libs
1460 1517
1518 # Use pkg-config if available (and works),
1519 # fallback to sed.
1520 if ${pkgconf} --exists "${pc}" &>/dev/null; then
1461 sed -e '/^Requires:/d' "${f}" > "${tf}" 1521 sed -e '/^Requires:/d' "${pc}" > "${tf}"
1462 for arg in $("${pkgconf}" --libs "${tf}"); do 1522 libs=$(${pkgconf} --libs "${tf}")
1463 [[ ${arg} == -l* ]] && pc_libs+=( lib${arg#-l}.la ) 1523 else
1524 libs=$(sed -ne 's/^Libs://p' "${pc}")
1525 fi
1526
1527 for arg in ${libs}; do
1528 if [[ ${arg} == -l* ]]; then
1529 if [[ ${arg} == '*$*' ]]; then
1530 eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
1531 eqawarn "(arg: ${arg})"
1532 eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
1533 fi
1534
1535 pc_libs+=( lib${arg#-l}.la )
1536 fi
1464 done 1537 done
1465 done < <(find "${D}" -type f -name '*.pc' -print0) 1538 done < <(find "${D}" -type f -name '*.pc' -print0)
1466 1539
1467 rm -f "${tf}" 1540 rm -f "${tf}"
1468 fi 1541 fi
1469 1542
1470 pkgconfig_scanned=1 1543 pkgconfig_scanned=1
1471 fi 1544 fi # pkgconfig_scanned
1472 1545
1473 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc' 1546 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1474 fi 1547 fi # removal due to .pc
1548
1549 fi # shouldnotlink==no
1475 1550
1476 if [[ ${reason} ]]; then 1551 if [[ ${reason} ]]; then
1477 einfo "Removing unnecessary ${f#${D%/}} (${reason})" 1552 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1478 queue+=( "${f}" ) 1553 queue+=( "${f}" )
1479 fi 1554 fi

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

  ViewVC Help
Powered by ViewVC 1.1.20