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

Diff of /eclass/eutils.eclass

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

Revision 1.386 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.386 2012/03/01 22:10:50 naota 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
16# different from the overall eclass! 16# different from the overall eclass!
17 17
18if [[ ${___ECLASS_ONCE_EUTILS} != "recur -_+^+_- spank" ]] ; then 18if [[ ${___ECLASS_ONCE_EUTILS} != "recur -_+^+_- spank" ]] ; then
19___ECLASS_ONCE_EUTILS="recur -_+^+_- spank" 19___ECLASS_ONCE_EUTILS="recur -_+^+_- spank"
20 20
21inherit multilib user 21inherit multilib toolchain-funcs user
22
23DESCRIPTION="Based on the ${ECLASS} eclass"
24 22
25if has "${EAPI:-0}" 0 1 2; then 23if has "${EAPI:-0}" 0 1 2; then
26 24
27# @FUNCTION: epause 25# @FUNCTION: epause
28# @USAGE: [seconds] 26# @USAGE: [seconds]
228# @DESCRIPTION: 226# @DESCRIPTION:
229# Default extension for patches (do not prefix the period yourself). 227# Default extension for patches (do not prefix the period yourself).
230EPATCH_SUFFIX="patch.bz2" 228EPATCH_SUFFIX="patch.bz2"
231# @VARIABLE: EPATCH_OPTS 229# @VARIABLE: EPATCH_OPTS
232# @DESCRIPTION: 230# @DESCRIPTION:
233# Default options for patch: 231# Options to pass to patch. Meant for ebuild/package-specific tweaking
232# such as forcing the patch level (-p#) or fuzz (-F#) factor. Note that
233# for single patch tweaking, you can also pass flags directly to epatch.
234EPATCH_OPTS=""
235# @VARIABLE: EPATCH_COMMON_OPTS
236# @DESCRIPTION:
237# Common options to pass to `patch`. You probably should never need to
238# change these. If you do, please discuss it with base-system first to
239# be sure.
234# @CODE 240# @CODE
235# -g0 - keep RCS, ClearCase, Perforce and SCCS happy #24571 241# -g0 - keep RCS, ClearCase, Perforce and SCCS happy #24571
236# --no-backup-if-mismatch - do not leave .orig files behind 242# --no-backup-if-mismatch - do not leave .orig files behind
237# -E - automatically remove empty files 243# -E - automatically remove empty files
238# @CODE 244# @CODE
239EPATCH_OPTS="-g0 -E --no-backup-if-mismatch" 245EPATCH_COMMON_OPTS="-g0 -E --no-backup-if-mismatch"
240# @VARIABLE: EPATCH_EXCLUDE 246# @VARIABLE: EPATCH_EXCLUDE
241# @DESCRIPTION: 247# @DESCRIPTION:
242# List of patches not to apply. Note this is only file names, 248# List of patches not to apply. Note this is only file names,
243# and not the full path. Globs accepted. 249# and not the full path. Globs accepted.
244EPATCH_EXCLUDE="" 250EPATCH_EXCLUDE=""
253# @VARIABLE: EPATCH_FORCE 259# @VARIABLE: EPATCH_FORCE
254# @DESCRIPTION: 260# @DESCRIPTION:
255# Only require patches to match EPATCH_SUFFIX rather than the extended 261# Only require patches to match EPATCH_SUFFIX rather than the extended
256# arch naming style. 262# arch naming style.
257EPATCH_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.
258 269
259# @FUNCTION: epatch 270# @FUNCTION: epatch
260# @USAGE: [patches] [dirs of patches] 271# @USAGE: [options] [patches] [dirs of patches]
261# @DESCRIPTION: 272# @DESCRIPTION:
262# 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
263# process patch files directly, or directories of patches. The patches may be 274# process patch files directly, or directories of patches. The patches may be
264# compressed (bzip/gzip/etc...) or plain text. You generally need not specify 275# compressed (bzip/gzip/etc...) or plain text. You generally need not specify
265# the -p option as epatch will automatically attempt -p0 to -p5 until things 276# the -p option as epatch will automatically attempt -p0 to -p5 until things
266# apply successfully. 277# apply successfully.
267# 278#
268# If you do not specify any options, then epatch will default to the directory 279# If you do not specify any patches/dirs, then epatch will default to the
269# specified by EPATCH_SOURCE. 280# directory specified by EPATCH_SOURCE.
281#
282# Any options specified that start with a dash will be passed down to patch
283# for this specific invocation. As soon as an arg w/out a dash is found, then
284# arg processing stops.
270# 285#
271# When processing directories, epatch will apply all patches that match: 286# When processing directories, epatch will apply all patches that match:
272# @CODE 287# @CODE
273# if ${EPATCH_FORCE} != "yes" 288# if ${EPATCH_FORCE} != "yes"
274# ??_${ARCH}_foo.${EPATCH_SUFFIX} 289# ??_${ARCH}_foo.${EPATCH_SUFFIX}
292 echo "${1//?/=}" 307 echo "${1//?/=}"
293 } 308 }
294 309
295 unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402 310 unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402
296 311
312 # First process options. We localize the EPATCH_OPTS setting
313 # from above so that we can pass it on in the loop below with
314 # any additional values the user has specified.
315 local EPATCH_OPTS=( ${EPATCH_OPTS[*]} )
316 while [[ $# -gt 0 ]] ; do
317 case $1 in
318 -*) EPATCH_OPTS+=( "$1" ) ;;
319 *) break ;;
320 esac
321 shift
322 done
323
297 # Let the rest of the code process one user arg at a time -- 324 # Let the rest of the code process one user arg at a time --
298 # each arg may expand into multiple patches, and each arg may 325 # each arg may expand into multiple patches, and each arg may
299 # need to start off with the default global EPATCH_xxx values 326 # need to start off with the default global EPATCH_xxx values
300 if [[ $# -gt 1 ]] ; then 327 if [[ $# -gt 1 ]] ; then
301 local m 328 local m
334 eerror " ${EPATCH_SOURCE}" 361 eerror " ${EPATCH_SOURCE}"
335 eerror " ( ${EPATCH_SOURCE##*/} )" 362 eerror " ( ${EPATCH_SOURCE##*/} )"
336 echo 363 echo
337 die "Cannot find \$EPATCH_SOURCE!" 364 die "Cannot find \$EPATCH_SOURCE!"
338 fi 365 fi
366
367 # Now that we know we're actually going to apply something, merge
368 # all of the patch options back in to a single variable for below.
369 EPATCH_OPTS="${EPATCH_COMMON_OPTS} ${EPATCH_OPTS[*]}"
339 370
340 local PIPE_CMD 371 local PIPE_CMD
341 case ${EPATCH_SUFFIX##*\.} in 372 case ${EPATCH_SUFFIX##*\.} in
342 xz) PIPE_CMD="xz -dc" ;; 373 xz) PIPE_CMD="xz -dc" ;;
343 lzma) PIPE_CMD="lzma -dc" ;; 374 lzma) PIPE_CMD="lzma -dc" ;;
377 eshopts_push -o noglob 408 eshopts_push -o noglob
378 409
379 local ex 410 local ex
380 for ex in ${EPATCH_EXCLUDE} ; do 411 for ex in ${EPATCH_EXCLUDE} ; do
381 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 ..."
382 eshopts_pop 422 eshopts_pop
383 continue 2 423 continue 2
384 fi 424 fi
385 done 425 done
386 426
434 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}"
435 fi 475 fi
436 # Similar reason, but with relative paths. 476 # Similar reason, but with relative paths.
437 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}") 477 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}")
438 if [[ -n ${rel_paths} ]] ; then 478 if [[ -n ${rel_paths} ]] ; then
479 echo
480 eerror "Rejected Patch: ${patchname} !"
481 eerror " ( ${PATCH_TARGET} )"
482 eerror
439 eqawarn "QA Notice: Your patch uses relative paths '../'." 483 eerror "Your patch uses relative paths '../':"
440 eqawarn " In the future this will cause a failure."
441 eqawarn "${rel_paths}" 484 eerror "${rel_paths}"
485 echo
486 die "you need to fix the relative paths in patch"
442 fi 487 fi
443 488
444 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/ 489 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/
445 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 ::')
446 while [[ ${count} -lt 5 ]] ; do 494 while [[ ${count} -lt 5 ]] ; do
447 patch_cmd="${BASH_ALIASES[patch]:-patch} -p${count} ${EPATCH_OPTS}" 495 patch_cmd="${patch} -p${count} ${EPATCH_OPTS}"
448 496
449 # Generate some useful debug info ... 497 # Generate some useful debug info ...
450 ( 498 (
451 _epatch_draw_line "***** ${patchname} *****" 499 _epatch_draw_line "***** ${patchname} *****"
452 echo 500 echo
523 571
524# @FUNCTION: epatch_user 572# @FUNCTION: epatch_user
525# @USAGE: 573# @USAGE:
526# @DESCRIPTION: 574# @DESCRIPTION:
527# Applies user-provided patches to the source tree. The patches are 575# Applies user-provided patches to the source tree. The patches are
528# taken from /etc/portage/patches/<CATEGORY>/<PF|P|PN>/, where the first 576# taken from /etc/portage/patches/<CATEGORY>/<PF|P|PN>[:SLOT]/, where the first
529# of these three directories to exist will be the one to use, ignoring 577# of these three directories to exist will be the one to use, ignoring
530# any more general directories which might exist as well. 578# any more general directories which might exist as well. They must end
579# in ".patch" to be applied.
531# 580#
532# User patches are intended for quick testing of patches without ebuild 581# User patches are intended for quick testing of patches without ebuild
533# modifications, as well as for permanent customizations a user might 582# modifications, as well as for permanent customizations a user might
534# desire. Obviously, there can be no official support for arbitrarily 583# desire. Obviously, there can be no official support for arbitrarily
535# patched ebuilds. So whenever a build log in a bug report mentions that 584# patched ebuilds. So whenever a build log in a bug report mentions that
554 local applied="${T}/epatch_user.log" 603 local applied="${T}/epatch_user.log"
555 [[ -e ${applied} ]] && return 2 604 [[ -e ${applied} ]] && return 2
556 605
557 # don't clobber any EPATCH vars that the parent might want 606 # don't clobber any EPATCH vars that the parent might want
558 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches 607 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
559 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}; do 608 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}{,:${SLOT}}; do
560 EPATCH_SOURCE=${base}/${CTARGET}/${check} 609 EPATCH_SOURCE=${base}/${CTARGET}/${check}
561 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check} 610 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check}
562 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check} 611 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check}
563 if [[ -d ${EPATCH_SOURCE} ]] ; then 612 if [[ -d ${EPATCH_SOURCE} ]] ; then
564 EPATCH_SOURCE=${EPATCH_SOURCE} \ 613 EPATCH_SOURCE=${EPATCH_SOURCE} \
627# Make a .desktop file. 676# Make a .desktop file.
628# 677#
629# @CODE 678# @CODE
630# binary: what command does the app run with ? 679# binary: what command does the app run with ?
631# name: the name that will show up in the menu 680# name: the name that will show up in the menu
632# icon: give your little like a pretty little icon ... 681# icon: the icon to use in the menu entry
633# this can be relative (to /usr/share/pixmaps) or 682# this can be relative (to /usr/share/pixmaps) or
634# a full path to an icon 683# a full path to an icon
635# type: what kind of application is this? 684# type: what kind of application is this?
636# for categories: 685# for categories:
637# http://standards.freedesktop.org/menu-spec/latest/apa.html 686# http://standards.freedesktop.org/menu-spec/latest/apa.html
913 insinto /usr/share/applications 962 insinto /usr/share/applications
914 newins "$@" 963 newins "$@"
915 ) 964 )
916} 965}
917 966
918# @FUNCTION: doicon 967# @FUNCTION: _iconins
919# @USAGE: <list of icons> 968# @INTERNAL
920# @DESCRIPTION: 969# @DESCRIPTION:
921# Install the list of icons into the icon directory (/usr/share/pixmaps). 970# function for use in doicon and newicon
922# This is useful in conjunction with creating desktop/menu files. 971_iconins() {
923doicon() {
924 ( 972 (
925 # wrap the env here so that the 'insinto' call 973 # wrap the env here so that the 'insinto' call
926 # doesn't corrupt the env of the caller 974 # doesn't corrupt the env of the caller
927 local i j ret 975 local funcname=$1; shift
976 local size dir
977 local context=apps
978 local theme=hicolor
979
980 while [[ $# -gt 0 ]] ; do
981 case $1 in
982 -s|--size)
983 if [[ ${2%%x*}x${2%%x*} == "$2" ]] ; then
984 size=${2%%x*}
985 else
986 size=${2}
987 fi
988 case ${size} in
989 16|22|24|32|36|48|64|72|96|128|192|256)
990 size=${size}x${size};;
991 scalable)
992 ;;
993 *)
994 eerror "${size} is an unsupported icon size!"
995 exit 1;;
996 esac
997 shift 2;;
998 -t|--theme)
999 theme=${2}
1000 shift 2;;
1001 -c|--context)
1002 context=${2}
1003 shift 2;;
1004 *)
1005 if [[ -z ${size} ]] ; then
928 insinto /usr/share/pixmaps 1006 insinto /usr/share/pixmaps
929 for i in "$@" ; do
930 if [[ -f ${i} ]] ; then
931 doins "${i}"
932 ((ret+=$?))
933 elif [[ -d ${i} ]] ; then
934 for j in "${i}"/*.png ; do
935 doins "${j}"
936 ((ret+=$?))
937 done
938 else 1007 else
939 ((++ret)) 1008 insinto /usr/share/icons/${theme}/${size}/${context}
940 fi 1009 fi
1010
1011 if [[ ${funcname} == doicon ]] ; then
1012 if [[ -f $1 ]] ; then
1013 doins "${1}"
1014 elif [[ -d $1 ]] ; then
1015 shopt -s nullglob
1016 doins "${1}"/*.{png,svg}
1017 shopt -u nullglob
1018 else
1019 eerror "${1} is not a valid file/directory!"
1020 exit 1
1021 fi
1022 else
1023 break
1024 fi
1025 shift 1;;
1026 esac
941 done 1027 done
942 exit ${ret} 1028 if [[ ${funcname} == newicon ]] ; then
943 ) 1029 newins "$@"
1030 fi
1031 ) || die
1032}
1033
1034# @FUNCTION: doicon
1035# @USAGE: [options] <icons>
1036# @DESCRIPTION:
1037# Install icon into the icon directory /usr/share/icons or into
1038# /usr/share/pixmaps if "--size" is not set.
1039# This is useful in conjunction with creating desktop/menu files.
1040#
1041# @CODE
1042# options:
1043# -s, --size
1044# !!! must specify to install into /usr/share/icons/... !!!
1045# size of the icon, like 48 or 48x48
1046# supported icon sizes are:
1047# 16 22 24 32 36 48 64 72 96 128 192 256 scalable
1048# -c, --context
1049# defaults to "apps"
1050# -t, --theme
1051# defaults to "hicolor"
1052#
1053# icons: list of icons
1054#
1055# example 1: doicon foobar.png fuqbar.svg suckbar.png
1056# results in: insinto /usr/share/pixmaps
1057# doins foobar.png fuqbar.svg suckbar.png
1058#
1059# example 2: doicon -s 48 foobar.png fuqbar.png blobbar.png
1060# results in: insinto /usr/share/icons/hicolor/48x48/apps
1061# doins foobar.png fuqbar.png blobbar.png
1062# @CODE
1063doicon() {
1064 _iconins ${FUNCNAME} "$@"
944} 1065}
945 1066
946# @FUNCTION: newicon 1067# @FUNCTION: newicon
947# @USAGE: <icon> <newname> 1068# @USAGE: [options] <icon> <newname>
948# @DESCRIPTION: 1069# @DESCRIPTION:
949# Like all other new* functions, install the specified icon as newname. 1070# Like doicon, install the specified icon as newname.
1071#
1072# @CODE
1073# example 1: newicon foobar.png NEWNAME.png
1074# results in: insinto /usr/share/pixmaps
1075# newins foobar.png NEWNAME.png
1076#
1077# example 2: newicon -s 48 foobar.png NEWNAME.png
1078# results in: insinto /usr/share/icons/hicolor/48x48/apps
1079# newins foobar.png NEWNAME.png
1080# @CODE
950newicon() { 1081newicon() {
951 ( 1082 _iconins ${FUNCNAME} "$@"
952 # wrap the env here so that the 'insinto' call
953 # doesn't corrupt the env of the caller
954 insinto /usr/share/pixmaps
955 newins "$@"
956 )
957} 1083}
958 1084
959# @FUNCTION: strip-linguas 1085# @FUNCTION: strip-linguas
960# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>] 1086# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>]
961# @DESCRIPTION: 1087# @DESCRIPTION:
999 else 1125 else
1000 nols="${nols} ${f}" 1126 nols="${nols} ${f}"
1001 fi 1127 fi
1002 done 1128 done
1003 [[ -n ${nols} ]] \ 1129 [[ -n ${nols} ]] \
1004 && ewarn "Sorry, but ${PN} does not support the LINGUAS:" ${nols} 1130 && einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
1005 export LINGUAS=${newls:1} 1131 export LINGUAS=${newls:1}
1006} 1132}
1007 1133
1008# @FUNCTION: preserve_old_lib 1134# @FUNCTION: preserve_old_lib
1009# @USAGE: <libs to preserve> [more libs] 1135# @USAGE: <libs to preserve> [more libs]
1057 ewarn "the libraries are not being removed. You need to run revdep-rebuild" 1183 ewarn "the libraries are not being removed. You need to run revdep-rebuild"
1058 ewarn "in order to remove these old dependencies. If you do not have this" 1184 ewarn "in order to remove these old dependencies. If you do not have this"
1059 ewarn "helper program, simply emerge the 'gentoolkit' package." 1185 ewarn "helper program, simply emerge the 'gentoolkit' package."
1060 ewarn 1186 ewarn
1061 fi 1187 fi
1062 # temp hack for #348634 #357225
1063 [[ ${PN} == "mpfr" ]] && lib=${lib##*/}
1064 ewarn " # revdep-rebuild --library '${lib}'" 1188 ewarn " # revdep-rebuild --library '${lib}' && rm '${lib}'"
1065 done 1189 done
1066 if [[ ${notice} -eq 1 ]] ; then
1067 ewarn
1068 ewarn "Once you've finished running revdep-rebuild, it should be safe to"
1069 ewarn "delete the old libraries. Here is a copy & paste for the lazy:"
1070 for lib in "$@" ; do
1071 ewarn " # rm '${lib}'"
1072 done
1073 fi
1074} 1190}
1075 1191
1076# @FUNCTION: built_with_use 1192# @FUNCTION: built_with_use
1077# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags> 1193# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags>
1078# @DESCRIPTION: 1194# @DESCRIPTION:
1173# http://bugs.gentoo.org/73450 1289# http://bugs.gentoo.org/73450
1174epunt_cxx() { 1290epunt_cxx() {
1175 local dir=$1 1291 local dir=$1
1176 [[ -z ${dir} ]] && dir=${S} 1292 [[ -z ${dir} ]] && dir=${S}
1177 ebegin "Removing useless C++ checks" 1293 ebegin "Removing useless C++ checks"
1178 local f 1294 local f p any_found
1179 find "${dir}" -name configure | while read f ; do 1295 while IFS= read -r -d '' f; do
1180 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
1181 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
1182 eend 0 1307 eend 0
1183} 1308}
1184 1309
1185# @FUNCTION: make_wrapper 1310# @FUNCTION: make_wrapper
1186# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath] 1311# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
1190# first optionally setting LD_LIBRARY_PATH to the colon-delimited 1315# first optionally setting LD_LIBRARY_PATH to the colon-delimited
1191# libpaths followed by optionally changing directory to chdir. 1316# libpaths followed by optionally changing directory to chdir.
1192make_wrapper() { 1317make_wrapper() {
1193 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5 1318 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
1194 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
1195 # 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
1196 # things as $bin ... "./someprog --args" 1334 # things as ${bin} ... "./someprog --args"
1335 printf 'exec %s "$@"\n' "${bin}"
1197 cat << EOF > "${tmpwrapper}" 1336 ) > "${tmpwrapper}"
1198#!/bin/sh
1199cd "${chdir:-.}"
1200if [ -n "${libdir}" ] ; then
1201 if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
1202 export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
1203 else
1204 export LD_LIBRARY_PATH="${libdir}"
1205 fi
1206fi
1207exec ${bin} "\$@"
1208EOF
1209 chmod go+rx "${tmpwrapper}" 1337 chmod go+rx "${tmpwrapper}"
1338
1210 if [[ -n ${path} ]] ; then 1339 if [[ -n ${path} ]] ; then
1211 ( 1340 (
1212 exeinto "${path}" 1341 exeinto "${path}"
1213 newexe "${tmpwrapper}" "${wrapper}" 1342 newexe "${tmpwrapper}" "${wrapper}"
1214 ) || die 1343 ) || die
1275} 1404}
1276 1405
1277# @FUNCTION: usex 1406# @FUNCTION: usex
1278# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix] 1407# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix]
1279# @DESCRIPTION: 1408# @DESCRIPTION:
1409# Proxy to declare usex for package managers or EAPIs that do not provide it
1410# and use the package manager implementation when available (i.e. EAPI >= 5).
1280# If USE flag is set, echo [true output][true suffix] (defaults to "yes"), 1411# If USE flag is set, echo [true output][true suffix] (defaults to "yes"),
1281# otherwise echo [false output][false suffix] (defaults to "no"). 1412# otherwise echo [false output][false suffix] (defaults to "no").
1413if has "${EAPI:-0}" 0 1 2 3 4; then
1282usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963 1414 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
1415fi
1416
1417# @FUNCTION: prune_libtool_files
1418# @USAGE: [--all|--modules]
1419# @DESCRIPTION:
1420# Locate unnecessary libtool files (.la) and libtool static archives
1421# (.a) and remove them from installation image.
1422#
1423# By default, .la files are removed whenever the static linkage can
1424# either be performed using pkg-config or doesn't introduce additional
1425# flags.
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#
1431# If '--all' argument is passed, all .la files are removed without
1432# performing any heuristic on them. You shouldn't ever use that,
1433# and instead report a bug in the algorithm instead.
1434#
1435# The .a files are only removed whenever corresponding .la files state
1436# that they should not be linked to, i.e. whenever these files
1437# correspond to plugins.
1438#
1439# Note: if your package installs both static libraries and .pc files
1440# which use variable substitution for -l flags, you need to add
1441# pkg-config to your DEPEND.
1442prune_libtool_files() {
1443 debug-print-function ${FUNCNAME} "$@"
1444
1445 local removing_all removing_modules opt
1446 for opt; do
1447 case "${opt}" in
1448 --all)
1449 removing_all=1
1450 removing_modules=1
1451 ;;
1452 --modules)
1453 removing_modules=1
1454 ;;
1455 *)
1456 die "Invalid argument to ${FUNCNAME}(): ${opt}"
1457 esac
1458 done
1459
1460 local f
1461 local queue=()
1462 while IFS= read -r -d '' f; do # for all .la files
1463 local archivefile=${f/%.la/.a}
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
1472 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1473 local reason pkgconfig_scanned
1474 local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
1475
1476 if [[ ${snotlink} == yes ]]; then
1477
1478 # Remove static libs we're not supposed to link against.
1479 if [[ -f ${archivefile} ]]; then
1480 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1481 queue+=( "${archivefile}" )
1482 fi
1483
1484 # The .la file may be used by a module loader, so avoid removing it
1485 # unless explicitly requested.
1486 if [[ ${removing_modules} ]]; then
1487 reason='module'
1488 fi
1489
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
1507 if [[ ! ${pkgconfig_scanned} ]]; then
1508 # Create a list of all .pc-covered libs.
1509 local pc_libs=()
1510 if [[ ! ${removing_all} ]]; then
1511 local pc
1512 local tf=${T}/prune-lt-files.pc
1513 local pkgconf=$(tc-getPKG_CONFIG)
1514
1515 while IFS= read -r -d '' pc; do # for all .pc files
1516 local arg libs
1517
1518 # Use pkg-config if available (and works),
1519 # fallback to sed.
1520 if ${pkgconf} --exists "${pc}" &>/dev/null; then
1521 sed -e '/^Requires:/d' "${pc}" > "${tf}"
1522 libs=$(${pkgconf} --libs "${tf}")
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
1537 done
1538 done < <(find "${D}" -type f -name '*.pc' -print0)
1539
1540 rm -f "${tf}"
1541 fi
1542
1543 pkgconfig_scanned=1
1544 fi # pkgconfig_scanned
1545
1546 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1547 fi # removal due to .pc
1548
1549 fi # shouldnotlink==no
1550
1551 if [[ ${reason} ]]; then
1552 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1553 queue+=( "${f}" )
1554 fi
1555 done < <(find "${D}" -xtype f -name '*.la' -print0)
1556
1557 if [[ ${queue[@]} ]]; then
1558 rm -f "${queue[@]}"
1559 fi
1560}
1283 1561
1284check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; } 1562check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; }
1285 1563
1286fi 1564fi

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

  ViewVC Help
Powered by ViewVC 1.1.20