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

Diff of /eclass/eutils.eclass

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

Revision 1.385 Revision 1.414
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.385 2012/03/01 07:00:40 ulm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.414 2013/03/11 00:13:16 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=""
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"
258 264
259# @FUNCTION: epatch 265# @FUNCTION: epatch
260# @USAGE: [patches] [dirs of patches] 266# @USAGE: [options] [patches] [dirs of patches]
261# @DESCRIPTION: 267# @DESCRIPTION:
262# epatch is designed to greatly simplify the application of patches. It can 268# 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 269# 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 270# 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 271# the -p option as epatch will automatically attempt -p0 to -p5 until things
266# apply successfully. 272# apply successfully.
267# 273#
268# If you do not specify any options, then epatch will default to the directory 274# If you do not specify any patches/dirs, then epatch will default to the
269# specified by EPATCH_SOURCE. 275# directory specified by EPATCH_SOURCE.
276#
277# Any options specified that start with a dash will be passed down to patch
278# for this specific invocation. As soon as an arg w/out a dash is found, then
279# arg processing stops.
270# 280#
271# When processing directories, epatch will apply all patches that match: 281# When processing directories, epatch will apply all patches that match:
272# @CODE 282# @CODE
273# if ${EPATCH_FORCE} != "yes" 283# if ${EPATCH_FORCE} != "yes"
274# ??_${ARCH}_foo.${EPATCH_SUFFIX} 284# ??_${ARCH}_foo.${EPATCH_SUFFIX}
292 echo "${1//?/=}" 302 echo "${1//?/=}"
293 } 303 }
294 304
295 unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402 305 unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402
296 306
307 # First process options. We localize the EPATCH_OPTS setting
308 # from above so that we can pass it on in the loop below with
309 # any additional values the user has specified.
310 local EPATCH_OPTS=( ${EPATCH_OPTS[*]} )
311 while [[ $# -gt 0 ]] ; do
312 case $1 in
313 -*) EPATCH_OPTS+=( "$1" ) ;;
314 *) break ;;
315 esac
316 shift
317 done
318
297 # Let the rest of the code process one user arg at a time -- 319 # 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 320 # each arg may expand into multiple patches, and each arg may
299 # need to start off with the default global EPATCH_xxx values 321 # need to start off with the default global EPATCH_xxx values
300 if [[ $# -gt 1 ]] ; then 322 if [[ $# -gt 1 ]] ; then
301 local m 323 local m
334 eerror " ${EPATCH_SOURCE}" 356 eerror " ${EPATCH_SOURCE}"
335 eerror " ( ${EPATCH_SOURCE##*/} )" 357 eerror " ( ${EPATCH_SOURCE##*/} )"
336 echo 358 echo
337 die "Cannot find \$EPATCH_SOURCE!" 359 die "Cannot find \$EPATCH_SOURCE!"
338 fi 360 fi
361
362 # Now that we know we're actually going to apply something, merge
363 # all of the patch options back in to a single variable for below.
364 EPATCH_OPTS="${EPATCH_COMMON_OPTS} ${EPATCH_OPTS[*]}"
339 365
340 local PIPE_CMD 366 local PIPE_CMD
341 case ${EPATCH_SUFFIX##*\.} in 367 case ${EPATCH_SUFFIX##*\.} in
342 xz) PIPE_CMD="xz -dc" ;; 368 xz) PIPE_CMD="xz -dc" ;;
343 lzma) PIPE_CMD="lzma -dc" ;; 369 lzma) PIPE_CMD="lzma -dc" ;;
442 fi 468 fi
443 469
444 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/ 470 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/
445 local patch_cmd 471 local patch_cmd
446 while [[ ${count} -lt 5 ]] ; do 472 while [[ ${count} -lt 5 ]] ; do
447 patch_cmd="patch -p${count} ${EPATCH_OPTS}" 473 patch_cmd="${BASH_ALIASES[patch]:-patch} -p${count} ${EPATCH_OPTS}"
448 474
449 # Generate some useful debug info ... 475 # Generate some useful debug info ...
450 ( 476 (
451 _epatch_draw_line "***** ${patchname} *****" 477 _epatch_draw_line "***** ${patchname} *****"
452 echo 478 echo
523 549
524# @FUNCTION: epatch_user 550# @FUNCTION: epatch_user
525# @USAGE: 551# @USAGE:
526# @DESCRIPTION: 552# @DESCRIPTION:
527# Applies user-provided patches to the source tree. The patches are 553# Applies user-provided patches to the source tree. The patches are
528# taken from /etc/portage/patches/<CATEGORY>/<PF|P|PN>/, where the first 554# 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 555# of these three directories to exist will be the one to use, ignoring
530# any more general directories which might exist as well. 556# any more general directories which might exist as well. They must end
557# in ".patch" to be applied.
531# 558#
532# User patches are intended for quick testing of patches without ebuild 559# User patches are intended for quick testing of patches without ebuild
533# modifications, as well as for permanent customizations a user might 560# modifications, as well as for permanent customizations a user might
534# desire. Obviously, there can be no official support for arbitrarily 561# desire. Obviously, there can be no official support for arbitrarily
535# patched ebuilds. So whenever a build log in a bug report mentions that 562# patched ebuilds. So whenever a build log in a bug report mentions that
554 local applied="${T}/epatch_user.log" 581 local applied="${T}/epatch_user.log"
555 [[ -e ${applied} ]] && return 2 582 [[ -e ${applied} ]] && return 2
556 583
557 # don't clobber any EPATCH vars that the parent might want 584 # don't clobber any EPATCH vars that the parent might want
558 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches 585 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
559 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}; do 586 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}{,:${SLOT}}; do
560 EPATCH_SOURCE=${base}/${CTARGET}/${check} 587 EPATCH_SOURCE=${base}/${CTARGET}/${check}
561 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check} 588 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check}
562 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check} 589 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check}
563 if [[ -d ${EPATCH_SOURCE} ]] ; then 590 if [[ -d ${EPATCH_SOURCE} ]] ; then
564 EPATCH_SOURCE=${EPATCH_SOURCE} \ 591 EPATCH_SOURCE=${EPATCH_SOURCE} \
627# Make a .desktop file. 654# Make a .desktop file.
628# 655#
629# @CODE 656# @CODE
630# binary: what command does the app run with ? 657# binary: what command does the app run with ?
631# name: the name that will show up in the menu 658# name: the name that will show up in the menu
632# icon: give your little like a pretty little icon ... 659# icon: the icon to use in the menu entry
633# this can be relative (to /usr/share/pixmaps) or 660# this can be relative (to /usr/share/pixmaps) or
634# a full path to an icon 661# a full path to an icon
635# type: what kind of application is this? 662# type: what kind of application is this?
636# for categories: 663# for categories:
637# http://standards.freedesktop.org/menu-spec/latest/apa.html 664# http://standards.freedesktop.org/menu-spec/latest/apa.html
913 insinto /usr/share/applications 940 insinto /usr/share/applications
914 newins "$@" 941 newins "$@"
915 ) 942 )
916} 943}
917 944
918# @FUNCTION: doicon 945# @FUNCTION: _iconins
919# @USAGE: <list of icons> 946# @INTERNAL
920# @DESCRIPTION: 947# @DESCRIPTION:
921# Install the list of icons into the icon directory (/usr/share/pixmaps). 948# function for use in doicon and newicon
922# This is useful in conjunction with creating desktop/menu files. 949_iconins() {
923doicon() {
924 ( 950 (
925 # wrap the env here so that the 'insinto' call 951 # wrap the env here so that the 'insinto' call
926 # doesn't corrupt the env of the caller 952 # doesn't corrupt the env of the caller
927 local i j ret 953 local funcname=$1; shift
954 local size dir
955 local context=apps
956 local theme=hicolor
957
958 while [[ $# -gt 0 ]] ; do
959 case $1 in
960 -s|--size)
961 if [[ ${2%%x*}x${2%%x*} == "$2" ]] ; then
962 size=${2%%x*}
963 else
964 size=${2}
965 fi
966 case ${size} in
967 16|22|24|32|36|48|64|72|96|128|192|256)
968 size=${size}x${size};;
969 scalable)
970 ;;
971 *)
972 eerror "${size} is an unsupported icon size!"
973 exit 1;;
974 esac
975 shift 2;;
976 -t|--theme)
977 theme=${2}
978 shift 2;;
979 -c|--context)
980 context=${2}
981 shift 2;;
982 *)
983 if [[ -z ${size} ]] ; then
928 insinto /usr/share/pixmaps 984 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 985 else
939 ((++ret)) 986 insinto /usr/share/icons/${theme}/${size}/${context}
940 fi 987 fi
988
989 if [[ ${funcname} == doicon ]] ; then
990 if [[ -f $1 ]] ; then
991 doins "${1}"
992 elif [[ -d $1 ]] ; then
993 shopt -s nullglob
994 doins "${1}"/*.{png,svg}
995 shopt -u nullglob
996 else
997 eerror "${1} is not a valid file/directory!"
998 exit 1
999 fi
1000 else
1001 break
1002 fi
1003 shift 1;;
1004 esac
941 done 1005 done
942 exit ${ret} 1006 if [[ ${funcname} == newicon ]] ; then
943 ) 1007 newins "$@"
1008 fi
1009 ) || die
1010}
1011
1012# @FUNCTION: doicon
1013# @USAGE: [options] <icons>
1014# @DESCRIPTION:
1015# Install icon into the icon directory /usr/share/icons or into
1016# /usr/share/pixmaps if "--size" is not set.
1017# This is useful in conjunction with creating desktop/menu files.
1018#
1019# @CODE
1020# options:
1021# -s, --size
1022# !!! must specify to install into /usr/share/icons/... !!!
1023# size of the icon, like 48 or 48x48
1024# supported icon sizes are:
1025# 16 22 24 32 36 48 64 72 96 128 192 256 scalable
1026# -c, --context
1027# defaults to "apps"
1028# -t, --theme
1029# defaults to "hicolor"
1030#
1031# icons: list of icons
1032#
1033# example 1: doicon foobar.png fuqbar.svg suckbar.png
1034# results in: insinto /usr/share/pixmaps
1035# doins foobar.png fuqbar.svg suckbar.png
1036#
1037# example 2: doicon -s 48 foobar.png fuqbar.png blobbar.png
1038# results in: insinto /usr/share/icons/hicolor/48x48/apps
1039# doins foobar.png fuqbar.png blobbar.png
1040# @CODE
1041doicon() {
1042 _iconins ${FUNCNAME} "$@"
944} 1043}
945 1044
946# @FUNCTION: newicon 1045# @FUNCTION: newicon
947# @USAGE: <icon> <newname> 1046# @USAGE: [options] <icon> <newname>
948# @DESCRIPTION: 1047# @DESCRIPTION:
949# Like all other new* functions, install the specified icon as newname. 1048# Like doicon, install the specified icon as newname.
1049#
1050# @CODE
1051# example 1: newicon foobar.png NEWNAME.png
1052# results in: insinto /usr/share/pixmaps
1053# newins foobar.png NEWNAME.png
1054#
1055# example 2: newicon -s 48 foobar.png NEWNAME.png
1056# results in: insinto /usr/share/icons/hicolor/48x48/apps
1057# newins foobar.png NEWNAME.png
1058# @CODE
950newicon() { 1059newicon() {
951 ( 1060 _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} 1061}
958 1062
959# @FUNCTION: strip-linguas 1063# @FUNCTION: strip-linguas
960# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>] 1064# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>]
961# @DESCRIPTION: 1065# @DESCRIPTION:
999 else 1103 else
1000 nols="${nols} ${f}" 1104 nols="${nols} ${f}"
1001 fi 1105 fi
1002 done 1106 done
1003 [[ -n ${nols} ]] \ 1107 [[ -n ${nols} ]] \
1004 && ewarn "Sorry, but ${PN} does not support the LINGUAS:" ${nols} 1108 && einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
1005 export LINGUAS=${newls:1} 1109 export LINGUAS=${newls:1}
1006} 1110}
1007 1111
1008# @FUNCTION: preserve_old_lib 1112# @FUNCTION: preserve_old_lib
1009# @USAGE: <libs to preserve> [more libs] 1113# @USAGE: <libs to preserve> [more libs]
1057 ewarn "the libraries are not being removed. You need to run revdep-rebuild" 1161 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" 1162 ewarn "in order to remove these old dependencies. If you do not have this"
1059 ewarn "helper program, simply emerge the 'gentoolkit' package." 1163 ewarn "helper program, simply emerge the 'gentoolkit' package."
1060 ewarn 1164 ewarn
1061 fi 1165 fi
1062 # temp hack for #348634 #357225
1063 [[ ${PN} == "mpfr" ]] && lib=${lib##*/}
1064 ewarn " # revdep-rebuild --library '${lib}'" 1166 ewarn " # revdep-rebuild --library '${lib}' && rm '${lib}'"
1065 done 1167 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} 1168}
1075 1169
1076# @FUNCTION: built_with_use 1170# @FUNCTION: built_with_use
1077# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags> 1171# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags>
1078# @DESCRIPTION: 1172# @DESCRIPTION:
1173# http://bugs.gentoo.org/73450 1267# http://bugs.gentoo.org/73450
1174epunt_cxx() { 1268epunt_cxx() {
1175 local dir=$1 1269 local dir=$1
1176 [[ -z ${dir} ]] && dir=${S} 1270 [[ -z ${dir} ]] && dir=${S}
1177 ebegin "Removing useless C++ checks" 1271 ebegin "Removing useless C++ checks"
1178 local f 1272 local f any_found
1179 find "${dir}" -name configure | while read f ; do 1273 while IFS= read -r -d '' f; do
1180 patch --no-backup-if-mismatch -p0 "${f}" "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null 1274 patch --no-backup-if-mismatch -p0 "${f}" \
1181 done 1275 "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null \
1276 && any_found=1
1277 done < <(find "${dir}" -name configure -print0)
1278
1279# if [[ -z ${any_found} ]]; then
1280# eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt)."
1281# fi
1182 eend 0 1282 eend 0
1183} 1283}
1184 1284
1185# @FUNCTION: make_wrapper 1285# @FUNCTION: make_wrapper
1186# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath] 1286# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
1190# first optionally setting LD_LIBRARY_PATH to the colon-delimited 1290# first optionally setting LD_LIBRARY_PATH to the colon-delimited
1191# libpaths followed by optionally changing directory to chdir. 1291# libpaths followed by optionally changing directory to chdir.
1192make_wrapper() { 1292make_wrapper() {
1193 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5 1293 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
1194 local tmpwrapper=$(emktemp) 1294 local tmpwrapper=$(emktemp)
1295
1296 (
1297 echo '#!/bin/sh'
1298 [[ -n ${chdir} ]] && printf 'cd "%s"\n' "${chdir}"
1299 if [[ -n ${libdir} ]] ; then
1300 cat <<-EOF
1301 if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
1302 export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
1303 else
1304 export LD_LIBRARY_PATH="${libdir}"
1305 fi
1306 EOF
1307 fi
1195 # We don't want to quote ${bin} so that people can pass complex 1308 # We don't want to quote ${bin} so that people can pass complex
1196 # things as $bin ... "./someprog --args" 1309 # things as ${bin} ... "./someprog --args"
1310 printf 'exec %s "$@"\n' "${bin}"
1197 cat << EOF > "${tmpwrapper}" 1311 ) > "${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}" 1312 chmod go+rx "${tmpwrapper}"
1313
1210 if [[ -n ${path} ]] ; then 1314 if [[ -n ${path} ]] ; then
1211 ( 1315 (
1212 exeinto "${path}" 1316 exeinto "${path}"
1213 newexe "${tmpwrapper}" "${wrapper}" 1317 newexe "${tmpwrapper}" "${wrapper}"
1214 ) || die 1318 ) || die
1275} 1379}
1276 1380
1277# @FUNCTION: usex 1381# @FUNCTION: usex
1278# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix] 1382# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix]
1279# @DESCRIPTION: 1383# @DESCRIPTION:
1384# Proxy to declare usex for package managers or EAPIs that do not provide it
1385# 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"), 1386# If USE flag is set, echo [true output][true suffix] (defaults to "yes"),
1281# otherwise echo [false output][false suffix] (defaults to "no"). 1387# otherwise echo [false output][false suffix] (defaults to "no").
1388if has "${EAPI:-0}" 0 1 2 3 4; then
1282usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963 1389 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
1390fi
1391
1392# @FUNCTION: prune_libtool_files
1393# @USAGE: [--all|--modules]
1394# @DESCRIPTION:
1395# Locate unnecessary libtool files (.la) and libtool static archives
1396# (.a) and remove them from installation image.
1397#
1398# By default, .la files are removed whenever the static linkage can
1399# either be performed using pkg-config or doesn't introduce additional
1400# flags.
1401#
1402# If '--modules' argument is passed, .la files for modules (plugins) are
1403# removed as well. This is usually useful when the package installs
1404# plugins and the plugin loader does not use .la files.
1405#
1406# If '--all' argument is passed, all .la files are removed without
1407# performing any heuristic on them. You shouldn't ever use that,
1408# and instead report a bug in the algorithm instead.
1409#
1410# The .a files are only removed whenever corresponding .la files state
1411# that they should not be linked to, i.e. whenever these files
1412# correspond to plugins.
1413#
1414# Note: if your package installs both static libraries and .pc files
1415# which use variable substitution for -l flags, you need to add
1416# pkg-config to your DEPEND.
1417prune_libtool_files() {
1418 debug-print-function ${FUNCNAME} "$@"
1419
1420 local removing_all removing_modules opt
1421 for opt; do
1422 case "${opt}" in
1423 --all)
1424 removing_all=1
1425 removing_modules=1
1426 ;;
1427 --modules)
1428 removing_modules=1
1429 ;;
1430 *)
1431 die "Invalid argument to ${FUNCNAME}(): ${opt}"
1432 esac
1433 done
1434
1435 local f
1436 local queue=()
1437 while IFS= read -r -d '' f; do # for all .la files
1438 local archivefile=${f/%.la/.a}
1439
1440 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1441
1442 local reason pkgconfig_scanned
1443
1444 # Remove static libs we're not supposed to link against.
1445 if grep -q '^shouldnotlink=yes$' "${f}"; then
1446 if [[ -f ${archivefile} ]]; then
1447 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1448 queue+=( "${archivefile}" )
1449 fi
1450
1451 # The .la file may be used by a module loader, so avoid removing it
1452 # unless explicitly requested.
1453 if [[ ${removing_modules} ]]; then
1454 reason='module'
1455 fi
1456
1457 # Remove .la files when:
1458 # - user explicitly wants us to remove all .la files,
1459 # - respective static archive doesn't exist,
1460 # - they are covered by a .pc file already,
1461 # - they don't provide any new information (no libs & no flags).
1462
1463 elif [[ ${removing_all} ]]; then
1464 reason='requested'
1465 elif [[ ! -f ${archivefile} ]]; then
1466 reason='no static archive'
1467 elif [[ ! $(sed -nre \
1468 "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
1469 "${f}") ]]; then
1470 reason='no libs & flags'
1471 else
1472 if [[ ! ${pkgconfig_scanned} ]]; then
1473 # Create a list of all .pc-covered libs.
1474 local pc_libs=()
1475 if [[ ! ${removing_all} ]]; then
1476 local pc
1477 local tf=${T}/prune-lt-files.pc
1478 local pkgconf=$(tc-getPKG_CONFIG)
1479
1480 while IFS= read -r -d '' pc; do # for all .pc files
1481 local arg libs
1482
1483 # Use pkg-config if available (and works),
1484 # fallback to sed.
1485 if ${pkgconf} --exists "${pc}" &>/dev/null; then
1486 sed -e '/^Requires:/d' "${pc}" > "${tf}"
1487 libs=$(${pkgconf} --libs "${tf}")
1488 else
1489 libs=$(sed -ne 's/^Libs://p' "${pc}")
1490 fi
1491
1492 for arg in ${libs}; do
1493 if [[ ${arg} == -l* ]]; then
1494 if [[ ${arg} == '*$*' ]]; then
1495 eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
1496 eqawarn "(arg: ${arg})"
1497 eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
1498 fi
1499
1500 pc_libs+=( lib${arg#-l}.la )
1501 fi
1502 done
1503 done < <(find "${D}" -type f -name '*.pc' -print0)
1504
1505 rm -f "${tf}"
1506 fi
1507
1508 pkgconfig_scanned=1
1509 fi
1510
1511 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1512 fi
1513
1514 if [[ ${reason} ]]; then
1515 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1516 queue+=( "${f}" )
1517 fi
1518 done < <(find "${D}" -xtype f -name '*.la' -print0)
1519
1520 if [[ ${queue[@]} ]]; then
1521 rm -f "${queue[@]}"
1522 fi
1523}
1283 1524
1284check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; } 1525check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; }
1285 1526
1286fi 1527fi

Legend:
Removed from v.1.385  
changed lines
  Added in v.1.414

  ViewVC Help
Powered by ViewVC 1.1.20