/[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.416
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.416 2013/03/31 02:17:12 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]
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
523 563
524# @FUNCTION: epatch_user 564# @FUNCTION: epatch_user
525# @USAGE: 565# @USAGE:
526# @DESCRIPTION: 566# @DESCRIPTION:
527# Applies user-provided patches to the source tree. The patches are 567# Applies user-provided patches to the source tree. The patches are
528# taken from /etc/portage/patches/<CATEGORY>/<PF|P|PN>/, where the first 568# 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 569# of these three directories to exist will be the one to use, ignoring
530# any more general directories which might exist as well. 570# any more general directories which might exist as well. They must end
571# in ".patch" to be applied.
531# 572#
532# User patches are intended for quick testing of patches without ebuild 573# User patches are intended for quick testing of patches without ebuild
533# modifications, as well as for permanent customizations a user might 574# modifications, as well as for permanent customizations a user might
534# desire. Obviously, there can be no official support for arbitrarily 575# desire. Obviously, there can be no official support for arbitrarily
535# patched ebuilds. So whenever a build log in a bug report mentions that 576# patched ebuilds. So whenever a build log in a bug report mentions that
554 local applied="${T}/epatch_user.log" 595 local applied="${T}/epatch_user.log"
555 [[ -e ${applied} ]] && return 2 596 [[ -e ${applied} ]] && return 2
556 597
557 # don't clobber any EPATCH vars that the parent might want 598 # don't clobber any EPATCH vars that the parent might want
558 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches 599 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
559 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}; do 600 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}{,:${SLOT}}; do
560 EPATCH_SOURCE=${base}/${CTARGET}/${check} 601 EPATCH_SOURCE=${base}/${CTARGET}/${check}
561 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check} 602 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check}
562 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check} 603 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check}
563 if [[ -d ${EPATCH_SOURCE} ]] ; then 604 if [[ -d ${EPATCH_SOURCE} ]] ; then
564 EPATCH_SOURCE=${EPATCH_SOURCE} \ 605 EPATCH_SOURCE=${EPATCH_SOURCE} \
627# Make a .desktop file. 668# Make a .desktop file.
628# 669#
629# @CODE 670# @CODE
630# binary: what command does the app run with ? 671# binary: what command does the app run with ?
631# name: the name that will show up in the menu 672# name: the name that will show up in the menu
632# icon: give your little like a pretty little icon ... 673# icon: the icon to use in the menu entry
633# this can be relative (to /usr/share/pixmaps) or 674# this can be relative (to /usr/share/pixmaps) or
634# a full path to an icon 675# a full path to an icon
635# type: what kind of application is this? 676# type: what kind of application is this?
636# for categories: 677# for categories:
637# http://standards.freedesktop.org/menu-spec/latest/apa.html 678# http://standards.freedesktop.org/menu-spec/latest/apa.html
913 insinto /usr/share/applications 954 insinto /usr/share/applications
914 newins "$@" 955 newins "$@"
915 ) 956 )
916} 957}
917 958
918# @FUNCTION: doicon 959# @FUNCTION: _iconins
919# @USAGE: <list of icons> 960# @INTERNAL
920# @DESCRIPTION: 961# @DESCRIPTION:
921# Install the list of icons into the icon directory (/usr/share/pixmaps). 962# function for use in doicon and newicon
922# This is useful in conjunction with creating desktop/menu files. 963_iconins() {
923doicon() {
924 ( 964 (
925 # wrap the env here so that the 'insinto' call 965 # wrap the env here so that the 'insinto' call
926 # doesn't corrupt the env of the caller 966 # doesn't corrupt the env of the caller
927 local i j ret 967 local funcname=$1; shift
968 local size dir
969 local context=apps
970 local theme=hicolor
971
972 while [[ $# -gt 0 ]] ; do
973 case $1 in
974 -s|--size)
975 if [[ ${2%%x*}x${2%%x*} == "$2" ]] ; then
976 size=${2%%x*}
977 else
978 size=${2}
979 fi
980 case ${size} in
981 16|22|24|32|36|48|64|72|96|128|192|256)
982 size=${size}x${size};;
983 scalable)
984 ;;
985 *)
986 eerror "${size} is an unsupported icon size!"
987 exit 1;;
988 esac
989 shift 2;;
990 -t|--theme)
991 theme=${2}
992 shift 2;;
993 -c|--context)
994 context=${2}
995 shift 2;;
996 *)
997 if [[ -z ${size} ]] ; then
928 insinto /usr/share/pixmaps 998 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 999 else
939 ((++ret)) 1000 insinto /usr/share/icons/${theme}/${size}/${context}
940 fi 1001 fi
1002
1003 if [[ ${funcname} == doicon ]] ; then
1004 if [[ -f $1 ]] ; then
1005 doins "${1}"
1006 elif [[ -d $1 ]] ; then
1007 shopt -s nullglob
1008 doins "${1}"/*.{png,svg}
1009 shopt -u nullglob
1010 else
1011 eerror "${1} is not a valid file/directory!"
1012 exit 1
1013 fi
1014 else
1015 break
1016 fi
1017 shift 1;;
1018 esac
941 done 1019 done
942 exit ${ret} 1020 if [[ ${funcname} == newicon ]] ; then
943 ) 1021 newins "$@"
1022 fi
1023 ) || die
1024}
1025
1026# @FUNCTION: doicon
1027# @USAGE: [options] <icons>
1028# @DESCRIPTION:
1029# Install icon into the icon directory /usr/share/icons or into
1030# /usr/share/pixmaps if "--size" is not set.
1031# This is useful in conjunction with creating desktop/menu files.
1032#
1033# @CODE
1034# options:
1035# -s, --size
1036# !!! must specify to install into /usr/share/icons/... !!!
1037# size of the icon, like 48 or 48x48
1038# supported icon sizes are:
1039# 16 22 24 32 36 48 64 72 96 128 192 256 scalable
1040# -c, --context
1041# defaults to "apps"
1042# -t, --theme
1043# defaults to "hicolor"
1044#
1045# icons: list of icons
1046#
1047# example 1: doicon foobar.png fuqbar.svg suckbar.png
1048# results in: insinto /usr/share/pixmaps
1049# doins foobar.png fuqbar.svg suckbar.png
1050#
1051# example 2: doicon -s 48 foobar.png fuqbar.png blobbar.png
1052# results in: insinto /usr/share/icons/hicolor/48x48/apps
1053# doins foobar.png fuqbar.png blobbar.png
1054# @CODE
1055doicon() {
1056 _iconins ${FUNCNAME} "$@"
944} 1057}
945 1058
946# @FUNCTION: newicon 1059# @FUNCTION: newicon
947# @USAGE: <icon> <newname> 1060# @USAGE: [options] <icon> <newname>
948# @DESCRIPTION: 1061# @DESCRIPTION:
949# Like all other new* functions, install the specified icon as newname. 1062# Like doicon, install the specified icon as newname.
1063#
1064# @CODE
1065# example 1: newicon foobar.png NEWNAME.png
1066# results in: insinto /usr/share/pixmaps
1067# newins foobar.png NEWNAME.png
1068#
1069# example 2: newicon -s 48 foobar.png NEWNAME.png
1070# results in: insinto /usr/share/icons/hicolor/48x48/apps
1071# newins foobar.png NEWNAME.png
1072# @CODE
950newicon() { 1073newicon() {
951 ( 1074 _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} 1075}
958 1076
959# @FUNCTION: strip-linguas 1077# @FUNCTION: strip-linguas
960# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>] 1078# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>]
961# @DESCRIPTION: 1079# @DESCRIPTION:
999 else 1117 else
1000 nols="${nols} ${f}" 1118 nols="${nols} ${f}"
1001 fi 1119 fi
1002 done 1120 done
1003 [[ -n ${nols} ]] \ 1121 [[ -n ${nols} ]] \
1004 && ewarn "Sorry, but ${PN} does not support the LINGUAS:" ${nols} 1122 && einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
1005 export LINGUAS=${newls:1} 1123 export LINGUAS=${newls:1}
1006} 1124}
1007 1125
1008# @FUNCTION: preserve_old_lib 1126# @FUNCTION: preserve_old_lib
1009# @USAGE: <libs to preserve> [more libs] 1127# @USAGE: <libs to preserve> [more libs]
1057 ewarn "the libraries are not being removed. You need to run revdep-rebuild" 1175 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" 1176 ewarn "in order to remove these old dependencies. If you do not have this"
1059 ewarn "helper program, simply emerge the 'gentoolkit' package." 1177 ewarn "helper program, simply emerge the 'gentoolkit' package."
1060 ewarn 1178 ewarn
1061 fi 1179 fi
1062 # temp hack for #348634 #357225
1063 [[ ${PN} == "mpfr" ]] && lib=${lib##*/}
1064 ewarn " # revdep-rebuild --library '${lib}'" 1180 ewarn " # revdep-rebuild --library '${lib}' && rm '${lib}'"
1065 done 1181 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} 1182}
1075 1183
1076# @FUNCTION: built_with_use 1184# @FUNCTION: built_with_use
1077# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags> 1185# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags>
1078# @DESCRIPTION: 1186# @DESCRIPTION:
1173# http://bugs.gentoo.org/73450 1281# http://bugs.gentoo.org/73450
1174epunt_cxx() { 1282epunt_cxx() {
1175 local dir=$1 1283 local dir=$1
1176 [[ -z ${dir} ]] && dir=${S} 1284 [[ -z ${dir} ]] && dir=${S}
1177 ebegin "Removing useless C++ checks" 1285 ebegin "Removing useless C++ checks"
1178 local f 1286 local f p any_found
1179 find "${dir}" -name configure | while read f ; do 1287 while IFS= read -r -d '' f; do
1180 patch --no-backup-if-mismatch -p0 "${f}" "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null 1288 for p in "${PORTDIR}"/eclass/ELT-patches/nocxx/*.patch ; do
1289 if patch --no-backup-if-mismatch -p1 "${f}" "${p}" >/dev/null ; then
1290 any_found=1
1291 break
1292 fi
1181 done 1293 done
1294 done < <(find "${dir}" -name configure -print0)
1295
1296 if [[ -z ${any_found} ]]; then
1297 eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt)."
1298 fi
1182 eend 0 1299 eend 0
1183} 1300}
1184 1301
1185# @FUNCTION: make_wrapper 1302# @FUNCTION: make_wrapper
1186# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath] 1303# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
1190# first optionally setting LD_LIBRARY_PATH to the colon-delimited 1307# first optionally setting LD_LIBRARY_PATH to the colon-delimited
1191# libpaths followed by optionally changing directory to chdir. 1308# libpaths followed by optionally changing directory to chdir.
1192make_wrapper() { 1309make_wrapper() {
1193 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5 1310 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
1194 local tmpwrapper=$(emktemp) 1311 local tmpwrapper=$(emktemp)
1312
1313 (
1314 echo '#!/bin/sh'
1315 [[ -n ${chdir} ]] && printf 'cd "%s"\n' "${chdir}"
1316 if [[ -n ${libdir} ]] ; then
1317 cat <<-EOF
1318 if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
1319 export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
1320 else
1321 export LD_LIBRARY_PATH="${libdir}"
1322 fi
1323 EOF
1324 fi
1195 # We don't want to quote ${bin} so that people can pass complex 1325 # We don't want to quote ${bin} so that people can pass complex
1196 # things as $bin ... "./someprog --args" 1326 # things as ${bin} ... "./someprog --args"
1327 printf 'exec %s "$@"\n' "${bin}"
1197 cat << EOF > "${tmpwrapper}" 1328 ) > "${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}" 1329 chmod go+rx "${tmpwrapper}"
1330
1210 if [[ -n ${path} ]] ; then 1331 if [[ -n ${path} ]] ; then
1211 ( 1332 (
1212 exeinto "${path}" 1333 exeinto "${path}"
1213 newexe "${tmpwrapper}" "${wrapper}" 1334 newexe "${tmpwrapper}" "${wrapper}"
1214 ) || die 1335 ) || die
1275} 1396}
1276 1397
1277# @FUNCTION: usex 1398# @FUNCTION: usex
1278# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix] 1399# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix]
1279# @DESCRIPTION: 1400# @DESCRIPTION:
1401# Proxy to declare usex for package managers or EAPIs that do not provide it
1402# 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"), 1403# If USE flag is set, echo [true output][true suffix] (defaults to "yes"),
1281# otherwise echo [false output][false suffix] (defaults to "no"). 1404# otherwise echo [false output][false suffix] (defaults to "no").
1405if has "${EAPI:-0}" 0 1 2 3 4; then
1282usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963 1406 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
1407fi
1408
1409# @FUNCTION: prune_libtool_files
1410# @USAGE: [--all|--modules]
1411# @DESCRIPTION:
1412# Locate unnecessary libtool files (.la) and libtool static archives
1413# (.a) and remove them from installation image.
1414#
1415# By default, .la files are removed whenever the static linkage can
1416# either be performed using pkg-config or doesn't introduce additional
1417# flags.
1418#
1419# If '--modules' argument is passed, .la files for modules (plugins) are
1420# removed as well. This is usually useful when the package installs
1421# plugins and the plugin loader does not use .la files.
1422#
1423# If '--all' argument is passed, all .la files are removed without
1424# performing any heuristic on them. You shouldn't ever use that,
1425# and instead report a bug in the algorithm instead.
1426#
1427# The .a files are only removed whenever corresponding .la files state
1428# that they should not be linked to, i.e. whenever these files
1429# correspond to plugins.
1430#
1431# Note: if your package installs both static libraries and .pc files
1432# which use variable substitution for -l flags, you need to add
1433# pkg-config to your DEPEND.
1434prune_libtool_files() {
1435 debug-print-function ${FUNCNAME} "$@"
1436
1437 local removing_all removing_modules opt
1438 for opt; do
1439 case "${opt}" in
1440 --all)
1441 removing_all=1
1442 removing_modules=1
1443 ;;
1444 --modules)
1445 removing_modules=1
1446 ;;
1447 *)
1448 die "Invalid argument to ${FUNCNAME}(): ${opt}"
1449 esac
1450 done
1451
1452 local f
1453 local queue=()
1454 while IFS= read -r -d '' f; do # for all .la files
1455 local archivefile=${f/%.la/.a}
1456
1457 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1458
1459 local reason pkgconfig_scanned
1460
1461 # Remove static libs we're not supposed to link against.
1462 if grep -q '^shouldnotlink=yes$' "${f}"; then
1463 if [[ -f ${archivefile} ]]; then
1464 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1465 queue+=( "${archivefile}" )
1466 fi
1467
1468 # The .la file may be used by a module loader, so avoid removing it
1469 # unless explicitly requested.
1470 if [[ ${removing_modules} ]]; then
1471 reason='module'
1472 fi
1473
1474 # Remove .la files when:
1475 # - user explicitly wants us to remove all .la files,
1476 # - respective static archive doesn't exist,
1477 # - they are covered by a .pc file already,
1478 # - they don't provide any new information (no libs & no flags).
1479
1480 elif [[ ${removing_all} ]]; then
1481 reason='requested'
1482 elif [[ ! -f ${archivefile} ]]; then
1483 reason='no static archive'
1484 elif [[ ! $(sed -nre \
1485 "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
1486 "${f}") ]]; then
1487 reason='no libs & flags'
1488 else
1489 if [[ ! ${pkgconfig_scanned} ]]; then
1490 # Create a list of all .pc-covered libs.
1491 local pc_libs=()
1492 if [[ ! ${removing_all} ]]; then
1493 local pc
1494 local tf=${T}/prune-lt-files.pc
1495 local pkgconf=$(tc-getPKG_CONFIG)
1496
1497 while IFS= read -r -d '' pc; do # for all .pc files
1498 local arg libs
1499
1500 # Use pkg-config if available (and works),
1501 # fallback to sed.
1502 if ${pkgconf} --exists "${pc}" &>/dev/null; then
1503 sed -e '/^Requires:/d' "${pc}" > "${tf}"
1504 libs=$(${pkgconf} --libs "${tf}")
1505 else
1506 libs=$(sed -ne 's/^Libs://p' "${pc}")
1507 fi
1508
1509 for arg in ${libs}; do
1510 if [[ ${arg} == -l* ]]; then
1511 if [[ ${arg} == '*$*' ]]; then
1512 eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
1513 eqawarn "(arg: ${arg})"
1514 eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
1515 fi
1516
1517 pc_libs+=( lib${arg#-l}.la )
1518 fi
1519 done
1520 done < <(find "${D}" -type f -name '*.pc' -print0)
1521
1522 rm -f "${tf}"
1523 fi
1524
1525 pkgconfig_scanned=1
1526 fi
1527
1528 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1529 fi
1530
1531 if [[ ${reason} ]]; then
1532 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1533 queue+=( "${f}" )
1534 fi
1535 done < <(find "${D}" -xtype f -name '*.la' -print0)
1536
1537 if [[ ${queue[@]} ]]; then
1538 rm -f "${queue[@]}"
1539 fi
1540}
1283 1541
1284check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; } 1542check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; }
1285 1543
1286fi 1544fi

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

  ViewVC Help
Powered by ViewVC 1.1.20