/[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.422
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.422 2013/06/21 23:52:50 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
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]
218 local s 216 local s
219 estack_pop eumask s || die "${FUNCNAME}: unbalanced push" 217 estack_pop eumask s || die "${FUNCNAME}: unbalanced push"
220 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}" 218 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
221} 219}
222 220
221# @FUNCTION: isdigit
222# @USAGE: <number> [more numbers]
223# @DESCRIPTION:
224# Return true if all arguments are numbers.
225isdigit() {
226 local d
227 for d ; do
228 [[ ${d:-bad} == *[!0-9]* ]] && return 1
229 done
230 return 0
231}
232
223# @VARIABLE: EPATCH_SOURCE 233# @VARIABLE: EPATCH_SOURCE
224# @DESCRIPTION: 234# @DESCRIPTION:
225# Default directory to search for patches. 235# Default directory to search for patches.
226EPATCH_SOURCE="${WORKDIR}/patch" 236EPATCH_SOURCE="${WORKDIR}/patch"
227# @VARIABLE: EPATCH_SUFFIX 237# @VARIABLE: EPATCH_SUFFIX
228# @DESCRIPTION: 238# @DESCRIPTION:
229# Default extension for patches (do not prefix the period yourself). 239# Default extension for patches (do not prefix the period yourself).
230EPATCH_SUFFIX="patch.bz2" 240EPATCH_SUFFIX="patch.bz2"
231# @VARIABLE: EPATCH_OPTS 241# @VARIABLE: EPATCH_OPTS
232# @DESCRIPTION: 242# @DESCRIPTION:
233# Default options for patch: 243# Options to pass to patch. Meant for ebuild/package-specific tweaking
244# such as forcing the patch level (-p#) or fuzz (-F#) factor. Note that
245# for single patch tweaking, you can also pass flags directly to epatch.
246EPATCH_OPTS=""
247# @VARIABLE: EPATCH_COMMON_OPTS
248# @DESCRIPTION:
249# Common options to pass to `patch`. You probably should never need to
250# change these. If you do, please discuss it with base-system first to
251# be sure.
234# @CODE 252# @CODE
235# -g0 - keep RCS, ClearCase, Perforce and SCCS happy #24571 253# -g0 - keep RCS, ClearCase, Perforce and SCCS happy #24571
236# --no-backup-if-mismatch - do not leave .orig files behind 254# --no-backup-if-mismatch - do not leave .orig files behind
237# -E - automatically remove empty files 255# -E - automatically remove empty files
238# @CODE 256# @CODE
239EPATCH_OPTS="-g0 -E --no-backup-if-mismatch" 257EPATCH_COMMON_OPTS="-g0 -E --no-backup-if-mismatch"
240# @VARIABLE: EPATCH_EXCLUDE 258# @VARIABLE: EPATCH_EXCLUDE
241# @DESCRIPTION: 259# @DESCRIPTION:
242# List of patches not to apply. Note this is only file names, 260# List of patches not to apply. Note this is only file names,
243# and not the full path. Globs accepted. 261# and not the full path. Globs accepted.
244EPATCH_EXCLUDE="" 262EPATCH_EXCLUDE=""
253# @VARIABLE: EPATCH_FORCE 271# @VARIABLE: EPATCH_FORCE
254# @DESCRIPTION: 272# @DESCRIPTION:
255# Only require patches to match EPATCH_SUFFIX rather than the extended 273# Only require patches to match EPATCH_SUFFIX rather than the extended
256# arch naming style. 274# arch naming style.
257EPATCH_FORCE="no" 275EPATCH_FORCE="no"
276# @VARIABLE: EPATCH_USER_EXCLUDE
277# @DEFAULT_UNSET
278# @DESCRIPTION:
279# List of patches not to apply. Note this is only file names,
280# and not the full path. Globs accepted.
258 281
259# @FUNCTION: epatch 282# @FUNCTION: epatch
260# @USAGE: [patches] [dirs of patches] 283# @USAGE: [options] [patches] [dirs of patches]
261# @DESCRIPTION: 284# @DESCRIPTION:
262# epatch is designed to greatly simplify the application of patches. It can 285# 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 286# 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 287# 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 288# the -p option as epatch will automatically attempt -p0 to -p5 until things
266# apply successfully. 289# apply successfully.
267# 290#
268# If you do not specify any options, then epatch will default to the directory 291# If you do not specify any patches/dirs, then epatch will default to the
269# specified by EPATCH_SOURCE. 292# directory specified by EPATCH_SOURCE.
293#
294# Any options specified that start with a dash will be passed down to patch
295# for this specific invocation. As soon as an arg w/out a dash is found, then
296# arg processing stops.
270# 297#
271# When processing directories, epatch will apply all patches that match: 298# When processing directories, epatch will apply all patches that match:
272# @CODE 299# @CODE
273# if ${EPATCH_FORCE} != "yes" 300# if ${EPATCH_FORCE} != "yes"
274# ??_${ARCH}_foo.${EPATCH_SUFFIX} 301# ??_${ARCH}_foo.${EPATCH_SUFFIX}
292 echo "${1//?/=}" 319 echo "${1//?/=}"
293 } 320 }
294 321
295 unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402 322 unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402
296 323
324 # First process options. We localize the EPATCH_OPTS setting
325 # from above so that we can pass it on in the loop below with
326 # any additional values the user has specified.
327 local EPATCH_OPTS=( ${EPATCH_OPTS[*]} )
328 while [[ $# -gt 0 ]] ; do
329 case $1 in
330 -*) EPATCH_OPTS+=( "$1" ) ;;
331 *) break ;;
332 esac
333 shift
334 done
335
297 # Let the rest of the code process one user arg at a time -- 336 # 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 337 # each arg may expand into multiple patches, and each arg may
299 # need to start off with the default global EPATCH_xxx values 338 # need to start off with the default global EPATCH_xxx values
300 if [[ $# -gt 1 ]] ; then 339 if [[ $# -gt 1 ]] ; then
301 local m 340 local m
334 eerror " ${EPATCH_SOURCE}" 373 eerror " ${EPATCH_SOURCE}"
335 eerror " ( ${EPATCH_SOURCE##*/} )" 374 eerror " ( ${EPATCH_SOURCE##*/} )"
336 echo 375 echo
337 die "Cannot find \$EPATCH_SOURCE!" 376 die "Cannot find \$EPATCH_SOURCE!"
338 fi 377 fi
378
379 # Now that we know we're actually going to apply something, merge
380 # all of the patch options back in to a single variable for below.
381 EPATCH_OPTS="${EPATCH_COMMON_OPTS} ${EPATCH_OPTS[*]}"
339 382
340 local PIPE_CMD 383 local PIPE_CMD
341 case ${EPATCH_SUFFIX##*\.} in 384 case ${EPATCH_SUFFIX##*\.} in
342 xz) PIPE_CMD="xz -dc" ;; 385 xz) PIPE_CMD="xz -dc" ;;
343 lzma) PIPE_CMD="lzma -dc" ;; 386 lzma) PIPE_CMD="lzma -dc" ;;
377 eshopts_push -o noglob 420 eshopts_push -o noglob
378 421
379 local ex 422 local ex
380 for ex in ${EPATCH_EXCLUDE} ; do 423 for ex in ${EPATCH_EXCLUDE} ; do
381 if [[ ${patchname} == ${ex} ]] ; then 424 if [[ ${patchname} == ${ex} ]] ; then
425 einfo " Skipping ${patchname} due to EPATCH_EXCLUDE ..."
426 eshopts_pop
427 continue 2
428 fi
429 done
430
431 for ex in ${EPATCH_USER_EXCLUDE} ; do
432 if [[ ${patchname} == ${ex} ]] ; then
433 einfo " Skipping ${patchname} due to EPATCH_USER_EXCLUDE ..."
382 eshopts_pop 434 eshopts_pop
383 continue 2 435 continue 2
384 fi 436 fi
385 done 437 done
386 438
434 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}" 486 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}"
435 fi 487 fi
436 # Similar reason, but with relative paths. 488 # Similar reason, but with relative paths.
437 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}") 489 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}")
438 if [[ -n ${rel_paths} ]] ; then 490 if [[ -n ${rel_paths} ]] ; then
491 echo
492 eerror "Rejected Patch: ${patchname} !"
493 eerror " ( ${PATCH_TARGET} )"
494 eerror
439 eqawarn "QA Notice: Your patch uses relative paths '../'." 495 eerror "Your patch uses relative paths '../':"
440 eqawarn " In the future this will cause a failure."
441 eqawarn "${rel_paths}" 496 eerror "${rel_paths}"
497 echo
498 die "you need to fix the relative paths in patch"
442 fi 499 fi
443 500
444 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/ 501 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/
445 local patch_cmd 502 local patch_cmd
503 # Handle aliased patch command #404447 #461568
504 local patch="patch"
505 eval $(alias patch 2>/dev/null | sed 's:^alias ::')
446 while [[ ${count} -lt 5 ]] ; do 506 while [[ ${count} -lt 5 ]] ; do
447 patch_cmd="${BASH_ALIASES[patch]:-patch} -p${count} ${EPATCH_OPTS}" 507 patch_cmd="${patch} -p${count} ${EPATCH_OPTS}"
448 508
449 # Generate some useful debug info ... 509 # Generate some useful debug info ...
450 ( 510 (
451 _epatch_draw_line "***** ${patchname} *****" 511 _epatch_draw_line "***** ${patchname} *****"
452 echo 512 echo
523 583
524# @FUNCTION: epatch_user 584# @FUNCTION: epatch_user
525# @USAGE: 585# @USAGE:
526# @DESCRIPTION: 586# @DESCRIPTION:
527# Applies user-provided patches to the source tree. The patches are 587# Applies user-provided patches to the source tree. The patches are
528# taken from /etc/portage/patches/<CATEGORY>/<PF|P|PN>/, where the first 588# 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 589# of these three directories to exist will be the one to use, ignoring
530# any more general directories which might exist as well. 590# any more general directories which might exist as well. They must end
591# in ".patch" to be applied.
531# 592#
532# User patches are intended for quick testing of patches without ebuild 593# User patches are intended for quick testing of patches without ebuild
533# modifications, as well as for permanent customizations a user might 594# modifications, as well as for permanent customizations a user might
534# desire. Obviously, there can be no official support for arbitrarily 595# desire. Obviously, there can be no official support for arbitrarily
535# patched ebuilds. So whenever a build log in a bug report mentions that 596# patched ebuilds. So whenever a build log in a bug report mentions that
554 local applied="${T}/epatch_user.log" 615 local applied="${T}/epatch_user.log"
555 [[ -e ${applied} ]] && return 2 616 [[ -e ${applied} ]] && return 2
556 617
557 # don't clobber any EPATCH vars that the parent might want 618 # don't clobber any EPATCH vars that the parent might want
558 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches 619 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
559 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}; do 620 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}{,:${SLOT}}; do
560 EPATCH_SOURCE=${base}/${CTARGET}/${check} 621 EPATCH_SOURCE=${base}/${CTARGET}/${check}
561 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check} 622 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check}
562 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check} 623 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check}
563 if [[ -d ${EPATCH_SOURCE} ]] ; then 624 if [[ -d ${EPATCH_SOURCE} ]] ; then
564 EPATCH_SOURCE=${EPATCH_SOURCE} \ 625 EPATCH_SOURCE=${EPATCH_SOURCE} \
627# Make a .desktop file. 688# Make a .desktop file.
628# 689#
629# @CODE 690# @CODE
630# binary: what command does the app run with ? 691# binary: what command does the app run with ?
631# name: the name that will show up in the menu 692# name: the name that will show up in the menu
632# icon: give your little like a pretty little icon ... 693# icon: the icon to use in the menu entry
633# this can be relative (to /usr/share/pixmaps) or 694# this can be relative (to /usr/share/pixmaps) or
634# a full path to an icon 695# a full path to an icon
635# type: what kind of application is this? 696# type: what kind of application is this?
636# for categories: 697# for categories:
637# http://standards.freedesktop.org/menu-spec/latest/apa.html 698# http://standards.freedesktop.org/menu-spec/latest/apa.html
913 insinto /usr/share/applications 974 insinto /usr/share/applications
914 newins "$@" 975 newins "$@"
915 ) 976 )
916} 977}
917 978
918# @FUNCTION: doicon 979# @FUNCTION: _iconins
919# @USAGE: <list of icons> 980# @INTERNAL
920# @DESCRIPTION: 981# @DESCRIPTION:
921# Install the list of icons into the icon directory (/usr/share/pixmaps). 982# function for use in doicon and newicon
922# This is useful in conjunction with creating desktop/menu files. 983_iconins() {
923doicon() {
924 ( 984 (
925 # wrap the env here so that the 'insinto' call 985 # wrap the env here so that the 'insinto' call
926 # doesn't corrupt the env of the caller 986 # doesn't corrupt the env of the caller
927 local i j ret 987 local funcname=$1; shift
988 local size dir
989 local context=apps
990 local theme=hicolor
991
992 while [[ $# -gt 0 ]] ; do
993 case $1 in
994 -s|--size)
995 if [[ ${2%%x*}x${2%%x*} == "$2" ]] ; then
996 size=${2%%x*}
997 else
998 size=${2}
999 fi
1000 case ${size} in
1001 16|22|24|32|36|48|64|72|96|128|192|256)
1002 size=${size}x${size};;
1003 scalable)
1004 ;;
1005 *)
1006 eerror "${size} is an unsupported icon size!"
1007 exit 1;;
1008 esac
1009 shift 2;;
1010 -t|--theme)
1011 theme=${2}
1012 shift 2;;
1013 -c|--context)
1014 context=${2}
1015 shift 2;;
1016 *)
1017 if [[ -z ${size} ]] ; then
928 insinto /usr/share/pixmaps 1018 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 1019 else
939 ((++ret)) 1020 insinto /usr/share/icons/${theme}/${size}/${context}
940 fi 1021 fi
1022
1023 if [[ ${funcname} == doicon ]] ; then
1024 if [[ -f $1 ]] ; then
1025 doins "${1}"
1026 elif [[ -d $1 ]] ; then
1027 shopt -s nullglob
1028 doins "${1}"/*.{png,svg}
1029 shopt -u nullglob
1030 else
1031 eerror "${1} is not a valid file/directory!"
1032 exit 1
1033 fi
1034 else
1035 break
1036 fi
1037 shift 1;;
1038 esac
941 done 1039 done
942 exit ${ret} 1040 if [[ ${funcname} == newicon ]] ; then
943 ) 1041 newins "$@"
1042 fi
1043 ) || die
1044}
1045
1046# @FUNCTION: doicon
1047# @USAGE: [options] <icons>
1048# @DESCRIPTION:
1049# Install icon into the icon directory /usr/share/icons or into
1050# /usr/share/pixmaps if "--size" is not set.
1051# This is useful in conjunction with creating desktop/menu files.
1052#
1053# @CODE
1054# options:
1055# -s, --size
1056# !!! must specify to install into /usr/share/icons/... !!!
1057# size of the icon, like 48 or 48x48
1058# supported icon sizes are:
1059# 16 22 24 32 36 48 64 72 96 128 192 256 scalable
1060# -c, --context
1061# defaults to "apps"
1062# -t, --theme
1063# defaults to "hicolor"
1064#
1065# icons: list of icons
1066#
1067# example 1: doicon foobar.png fuqbar.svg suckbar.png
1068# results in: insinto /usr/share/pixmaps
1069# doins foobar.png fuqbar.svg suckbar.png
1070#
1071# example 2: doicon -s 48 foobar.png fuqbar.png blobbar.png
1072# results in: insinto /usr/share/icons/hicolor/48x48/apps
1073# doins foobar.png fuqbar.png blobbar.png
1074# @CODE
1075doicon() {
1076 _iconins ${FUNCNAME} "$@"
944} 1077}
945 1078
946# @FUNCTION: newicon 1079# @FUNCTION: newicon
947# @USAGE: <icon> <newname> 1080# @USAGE: [options] <icon> <newname>
948# @DESCRIPTION: 1081# @DESCRIPTION:
949# Like all other new* functions, install the specified icon as newname. 1082# Like doicon, install the specified icon as newname.
1083#
1084# @CODE
1085# example 1: newicon foobar.png NEWNAME.png
1086# results in: insinto /usr/share/pixmaps
1087# newins foobar.png NEWNAME.png
1088#
1089# example 2: newicon -s 48 foobar.png NEWNAME.png
1090# results in: insinto /usr/share/icons/hicolor/48x48/apps
1091# newins foobar.png NEWNAME.png
1092# @CODE
950newicon() { 1093newicon() {
951 ( 1094 _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} 1095}
958 1096
959# @FUNCTION: strip-linguas 1097# @FUNCTION: strip-linguas
960# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>] 1098# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>]
961# @DESCRIPTION: 1099# @DESCRIPTION:
999 else 1137 else
1000 nols="${nols} ${f}" 1138 nols="${nols} ${f}"
1001 fi 1139 fi
1002 done 1140 done
1003 [[ -n ${nols} ]] \ 1141 [[ -n ${nols} ]] \
1004 && ewarn "Sorry, but ${PN} does not support the LINGUAS:" ${nols} 1142 && einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
1005 export LINGUAS=${newls:1} 1143 export LINGUAS=${newls:1}
1006} 1144}
1007 1145
1008# @FUNCTION: preserve_old_lib 1146# @FUNCTION: preserve_old_lib
1009# @USAGE: <libs to preserve> [more libs] 1147# @USAGE: <libs to preserve> [more libs]
1057 ewarn "the libraries are not being removed. You need to run revdep-rebuild" 1195 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" 1196 ewarn "in order to remove these old dependencies. If you do not have this"
1059 ewarn "helper program, simply emerge the 'gentoolkit' package." 1197 ewarn "helper program, simply emerge the 'gentoolkit' package."
1060 ewarn 1198 ewarn
1061 fi 1199 fi
1062 # temp hack for #348634 #357225
1063 [[ ${PN} == "mpfr" ]] && lib=${lib##*/}
1064 ewarn " # revdep-rebuild --library '${lib}'" 1200 ewarn " # revdep-rebuild --library '${lib}' && rm '${lib}'"
1065 done 1201 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} 1202}
1075 1203
1076# @FUNCTION: built_with_use 1204# @FUNCTION: built_with_use
1077# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags> 1205# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags>
1078# @DESCRIPTION: 1206# @DESCRIPTION:
1173# http://bugs.gentoo.org/73450 1301# http://bugs.gentoo.org/73450
1174epunt_cxx() { 1302epunt_cxx() {
1175 local dir=$1 1303 local dir=$1
1176 [[ -z ${dir} ]] && dir=${S} 1304 [[ -z ${dir} ]] && dir=${S}
1177 ebegin "Removing useless C++ checks" 1305 ebegin "Removing useless C++ checks"
1178 local f 1306 local f p any_found
1179 find "${dir}" -name configure | while read f ; do 1307 while IFS= read -r -d '' f; do
1180 patch --no-backup-if-mismatch -p0 "${f}" "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null 1308 for p in "${PORTDIR}"/eclass/ELT-patches/nocxx/*.patch ; do
1309 if patch --no-backup-if-mismatch -p1 "${f}" "${p}" >/dev/null ; then
1310 any_found=1
1311 break
1312 fi
1181 done 1313 done
1314 done < <(find "${dir}" -name configure -print0)
1315
1316 if [[ -z ${any_found} ]]; then
1317 eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt)."
1318 fi
1182 eend 0 1319 eend 0
1183} 1320}
1184 1321
1185# @FUNCTION: make_wrapper 1322# @FUNCTION: make_wrapper
1186# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath] 1323# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
1190# first optionally setting LD_LIBRARY_PATH to the colon-delimited 1327# first optionally setting LD_LIBRARY_PATH to the colon-delimited
1191# libpaths followed by optionally changing directory to chdir. 1328# libpaths followed by optionally changing directory to chdir.
1192make_wrapper() { 1329make_wrapper() {
1193 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5 1330 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
1194 local tmpwrapper=$(emktemp) 1331 local tmpwrapper=$(emktemp)
1332
1333 (
1334 echo '#!/bin/sh'
1335 [[ -n ${chdir} ]] && printf 'cd "%s"\n' "${chdir}"
1336 if [[ -n ${libdir} ]] ; then
1337 cat <<-EOF
1338 if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
1339 export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
1340 else
1341 export LD_LIBRARY_PATH="${libdir}"
1342 fi
1343 EOF
1344 fi
1195 # We don't want to quote ${bin} so that people can pass complex 1345 # We don't want to quote ${bin} so that people can pass complex
1196 # things as $bin ... "./someprog --args" 1346 # things as ${bin} ... "./someprog --args"
1347 printf 'exec %s "$@"\n' "${bin}"
1197 cat << EOF > "${tmpwrapper}" 1348 ) > "${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}" 1349 chmod go+rx "${tmpwrapper}"
1350
1210 if [[ -n ${path} ]] ; then 1351 if [[ -n ${path} ]] ; then
1211 ( 1352 (
1212 exeinto "${path}" 1353 exeinto "${path}"
1213 newexe "${tmpwrapper}" "${wrapper}" 1354 newexe "${tmpwrapper}" "${wrapper}"
1214 ) || die 1355 ) || die
1275} 1416}
1276 1417
1277# @FUNCTION: usex 1418# @FUNCTION: usex
1278# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix] 1419# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix]
1279# @DESCRIPTION: 1420# @DESCRIPTION:
1421# Proxy to declare usex for package managers or EAPIs that do not provide it
1422# 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"), 1423# If USE flag is set, echo [true output][true suffix] (defaults to "yes"),
1281# otherwise echo [false output][false suffix] (defaults to "no"). 1424# otherwise echo [false output][false suffix] (defaults to "no").
1425if has "${EAPI:-0}" 0 1 2 3 4; then
1282usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963 1426 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
1427fi
1428
1429# @FUNCTION: prune_libtool_files
1430# @USAGE: [--all|--modules]
1431# @DESCRIPTION:
1432# Locate unnecessary libtool files (.la) and libtool static archives
1433# (.a) and remove them from installation image.
1434#
1435# By default, .la files are removed whenever the static linkage can
1436# either be performed using pkg-config or doesn't introduce additional
1437# flags.
1438#
1439# If '--modules' argument is passed, .la files for modules (plugins) are
1440# removed as well. This is usually useful when the package installs
1441# plugins and the plugin loader does not use .la files.
1442#
1443# If '--all' argument is passed, all .la files are removed without
1444# performing any heuristic on them. You shouldn't ever use that,
1445# and instead report a bug in the algorithm instead.
1446#
1447# The .a files are only removed whenever corresponding .la files state
1448# that they should not be linked to, i.e. whenever these files
1449# correspond to plugins.
1450#
1451# Note: if your package installs both static libraries and .pc files
1452# which use variable substitution for -l flags, you need to add
1453# pkg-config to your DEPEND.
1454prune_libtool_files() {
1455 debug-print-function ${FUNCNAME} "$@"
1456
1457 local removing_all removing_modules opt
1458 for opt; do
1459 case "${opt}" in
1460 --all)
1461 removing_all=1
1462 removing_modules=1
1463 ;;
1464 --modules)
1465 removing_modules=1
1466 ;;
1467 *)
1468 die "Invalid argument to ${FUNCNAME}(): ${opt}"
1469 esac
1470 done
1471
1472 local f
1473 local queue=()
1474 while IFS= read -r -d '' f; do # for all .la files
1475 local archivefile=${f/%.la/.a}
1476
1477 # The following check is done by libtool itself.
1478 # It helps us avoid removing random files which match '*.la',
1479 # see bug #468380.
1480 if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
1481 continue
1482 fi
1483
1484 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1485 local reason pkgconfig_scanned
1486 local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
1487
1488 if [[ ${snotlink} == yes ]]; then
1489
1490 # Remove static libs we're not supposed to link against.
1491 if [[ -f ${archivefile} ]]; then
1492 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1493 queue+=( "${archivefile}" )
1494 fi
1495
1496 # The .la file may be used by a module loader, so avoid removing it
1497 # unless explicitly requested.
1498 if [[ ${removing_modules} ]]; then
1499 reason='module'
1500 fi
1501
1502 else
1503
1504 # Remove .la files when:
1505 # - user explicitly wants us to remove all .la files,
1506 # - respective static archive doesn't exist,
1507 # - they are covered by a .pc file already,
1508 # - they don't provide any new information (no libs & no flags).
1509
1510 if [[ ${removing_all} ]]; then
1511 reason='requested'
1512 elif [[ ! -f ${archivefile} ]]; then
1513 reason='no static archive'
1514 elif [[ ! $(sed -nre \
1515 "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
1516 "${f}") ]]; then
1517 reason='no libs & flags'
1518 else
1519 if [[ ! ${pkgconfig_scanned} ]]; then
1520 # Create a list of all .pc-covered libs.
1521 local pc_libs=()
1522 if [[ ! ${removing_all} ]]; then
1523 local pc
1524 local tf=${T}/prune-lt-files.pc
1525 local pkgconf=$(tc-getPKG_CONFIG)
1526
1527 while IFS= read -r -d '' pc; do # for all .pc files
1528 local arg libs
1529
1530 # Use pkg-config if available (and works),
1531 # fallback to sed.
1532 if ${pkgconf} --exists "${pc}" &>/dev/null; then
1533 sed -e '/^Requires:/d' "${pc}" > "${tf}"
1534 libs=$(${pkgconf} --libs "${tf}")
1535 else
1536 libs=$(sed -ne 's/^Libs://p' "${pc}")
1537 fi
1538
1539 for arg in ${libs}; do
1540 if [[ ${arg} == -l* ]]; then
1541 if [[ ${arg} == '*$*' ]]; then
1542 eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
1543 eqawarn "(arg: ${arg})"
1544 eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
1545 fi
1546
1547 pc_libs+=( lib${arg#-l}.la )
1548 fi
1549 done
1550 done < <(find "${D}" -type f -name '*.pc' -print0)
1551
1552 rm -f "${tf}"
1553 fi
1554
1555 pkgconfig_scanned=1
1556 fi # pkgconfig_scanned
1557
1558 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1559 fi # removal due to .pc
1560
1561 fi # shouldnotlink==no
1562
1563 if [[ ${reason} ]]; then
1564 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1565 queue+=( "${f}" )
1566 fi
1567 done < <(find "${D}" -xtype f -name '*.la' -print0)
1568
1569 if [[ ${queue[@]} ]]; then
1570 rm -f "${queue[@]}"
1571 fi
1572}
1283 1573
1284check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; } 1574check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; }
1285 1575
1286fi 1576fi

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

  ViewVC Help
Powered by ViewVC 1.1.20