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

Diff of /eclass/eutils.eclass

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

Revision 1.407 Revision 1.429
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2013 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.407 2012/10/11 16:50:53 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.429 2013/12/27 09:28:42 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
142 142
143 if [[ -n ${__estack_retvar} ]] ; then 143 if [[ -n ${__estack_retvar} ]] ; then
144 eval ${__estack_retvar}=\"\${${__estack_name}\[${__estack_i}\]}\" 144 eval ${__estack_retvar}=\"\${${__estack_name}\[${__estack_i}\]}\"
145 fi 145 fi
146 eval unset ${__estack_name}\[${__estack_i}\] 146 eval unset ${__estack_name}\[${__estack_i}\]
147}
148
149# @FUNCTION: evar_push
150# @USAGE: <variable to save> [more vars to save]
151# @DESCRIPTION:
152# This let's you temporarily modify a variable and then restore it (including
153# set vs unset semantics). Arrays are not supported at this time.
154#
155# This is meant for variables where using `local` does not work (such as
156# exported variables, or only temporarily changing things in a func).
157#
158# For example:
159# @CODE
160# evar_push LC_ALL
161# export LC_ALL=C
162# ... do some stuff that needs LC_ALL=C set ...
163# evar_pop
164#
165# # You can also save/restore more than one var at a time
166# evar_push BUTTERFLY IN THE SKY
167# ... do stuff with the vars ...
168# evar_pop # This restores just one var, SKY
169# ... do more stuff ...
170# evar_pop 3 # This pops the remaining 3 vars
171# @CODE
172evar_push() {
173 local var val
174 for var ; do
175 [[ ${!var+set} == "set" ]] \
176 && val=${!var} \
177 || val="${___ECLASS_ONCE_EUTILS}"
178 estack_push evar "${var}" "${val}"
179 done
180}
181
182# @FUNCTION: evar_push_set
183# @USAGE: <variable to save> [new value to store]
184# @DESCRIPTION:
185# This is a handy shortcut to save and temporarily set a variable. If a value
186# is not specified, the var will be unset.
187evar_push_set() {
188 local var=$1
189 evar_push ${var}
190 case $# in
191 1) unset ${var} ;;
192 2) printf -v "${var}" '%s' "$2" ;;
193 *) die "${FUNCNAME}: incorrect # of args: $*" ;;
194 esac
195}
196
197# @FUNCTION: evar_pop
198# @USAGE: [number of vars to restore]
199# @DESCRIPTION:
200# Restore the variables to the state saved with the corresponding
201# evar_push call. See that function for more details.
202evar_pop() {
203 local cnt=${1:-bad}
204 case $# in
205 0) cnt=1 ;;
206 1) isdigit "${cnt}" || die "${FUNCNAME}: first arg must be a number: $*" ;;
207 *) die "${FUNCNAME}: only accepts one arg: $*" ;;
208 esac
209
210 local var val
211 while (( cnt-- )) ; do
212 estack_pop evar val || die "${FUNCNAME}: unbalanced push"
213 estack_pop evar var || die "${FUNCNAME}: unbalanced push"
214 [[ ${val} == "${___ECLASS_ONCE_EUTILS}" ]] \
215 && unset ${var} \
216 || printf -v "${var}" '%s' "${val}"
217 done
147} 218}
148 219
149# @FUNCTION: eshopts_push 220# @FUNCTION: eshopts_push
150# @USAGE: [options to `set` or `shopt`] 221# @USAGE: [options to `set` or `shopt`]
151# @DESCRIPTION: 222# @DESCRIPTION:
216 local s 287 local s
217 estack_pop eumask s || die "${FUNCNAME}: unbalanced push" 288 estack_pop eumask s || die "${FUNCNAME}: unbalanced push"
218 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}" 289 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
219} 290}
220 291
292# @FUNCTION: isdigit
293# @USAGE: <number> [more numbers]
294# @DESCRIPTION:
295# Return true if all arguments are numbers.
296isdigit() {
297 local d
298 for d ; do
299 [[ ${d:-bad} == *[!0-9]* ]] && return 1
300 done
301 return 0
302}
303
221# @VARIABLE: EPATCH_SOURCE 304# @VARIABLE: EPATCH_SOURCE
222# @DESCRIPTION: 305# @DESCRIPTION:
223# Default directory to search for patches. 306# Default directory to search for patches.
224EPATCH_SOURCE="${WORKDIR}/patch" 307EPATCH_SOURCE="${WORKDIR}/patch"
225# @VARIABLE: EPATCH_SUFFIX 308# @VARIABLE: EPATCH_SUFFIX
259# @VARIABLE: EPATCH_FORCE 342# @VARIABLE: EPATCH_FORCE
260# @DESCRIPTION: 343# @DESCRIPTION:
261# Only require patches to match EPATCH_SUFFIX rather than the extended 344# Only require patches to match EPATCH_SUFFIX rather than the extended
262# arch naming style. 345# arch naming style.
263EPATCH_FORCE="no" 346EPATCH_FORCE="no"
347# @VARIABLE: EPATCH_USER_EXCLUDE
348# @DEFAULT_UNSET
349# @DESCRIPTION:
350# List of patches not to apply. Note this is only file names,
351# and not the full path. Globs accepted.
264 352
265# @FUNCTION: epatch 353# @FUNCTION: epatch
266# @USAGE: [options] [patches] [dirs of patches] 354# @USAGE: [options] [patches] [dirs of patches]
267# @DESCRIPTION: 355# @DESCRIPTION:
268# epatch is designed to greatly simplify the application of patches. It can 356# epatch is designed to greatly simplify the application of patches. It can
269# process patch files directly, or directories of patches. The patches may be 357# process patch files directly, or directories of patches. The patches may be
270# compressed (bzip/gzip/etc...) or plain text. You generally need not specify 358# compressed (bzip/gzip/etc...) or plain text. You generally need not specify
271# the -p option as epatch will automatically attempt -p0 to -p5 until things 359# the -p option as epatch will automatically attempt -p0 to -p4 until things
272# apply successfully. 360# apply successfully.
273# 361#
274# If you do not specify any patches/dirs, then epatch will default to the 362# If you do not specify any patches/dirs, then epatch will default to the
275# directory specified by EPATCH_SOURCE. 363# directory specified by EPATCH_SOURCE.
276# 364#
337 # Use the suffix from the single patch (localize it); the code 425 # Use the suffix from the single patch (localize it); the code
338 # below will find the suffix for us 426 # below will find the suffix for us
339 local EPATCH_SUFFIX=$1 427 local EPATCH_SUFFIX=$1
340 428
341 elif [[ -d $1 ]] ; then 429 elif [[ -d $1 ]] ; then
430 # We have to force sorting to C so that the wildcard expansion is consistent #471666.
431 evar_push_set LC_COLLATE C
342 # Some people like to make dirs of patches w/out suffixes (vim) 432 # Some people like to make dirs of patches w/out suffixes (vim).
343 set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"} 433 set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"}
434 evar_pop
344 435
345 elif [[ -f ${EPATCH_SOURCE}/$1 ]] ; then 436 elif [[ -f ${EPATCH_SOURCE}/$1 ]] ; then
346 # Re-use EPATCH_SOURCE as a search dir 437 # Re-use EPATCH_SOURCE as a search dir
347 epatch "${EPATCH_SOURCE}/$1" 438 epatch "${EPATCH_SOURCE}/$1"
348 return $? 439 return $?
403 eshopts_push -o noglob 494 eshopts_push -o noglob
404 495
405 local ex 496 local ex
406 for ex in ${EPATCH_EXCLUDE} ; do 497 for ex in ${EPATCH_EXCLUDE} ; do
407 if [[ ${patchname} == ${ex} ]] ; then 498 if [[ ${patchname} == ${ex} ]] ; then
499 einfo " Skipping ${patchname} due to EPATCH_EXCLUDE ..."
500 eshopts_pop
501 continue 2
502 fi
503 done
504
505 for ex in ${EPATCH_USER_EXCLUDE} ; do
506 if [[ ${patchname} == ${ex} ]] ; then
507 einfo " Skipping ${patchname} due to EPATCH_USER_EXCLUDE ..."
408 eshopts_pop 508 eshopts_pop
409 continue 2 509 continue 2
410 fi 510 fi
411 done 511 done
412 512
460 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}" 560 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}"
461 fi 561 fi
462 # Similar reason, but with relative paths. 562 # Similar reason, but with relative paths.
463 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}") 563 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}")
464 if [[ -n ${rel_paths} ]] ; then 564 if [[ -n ${rel_paths} ]] ; then
565 echo
566 eerror "Rejected Patch: ${patchname} !"
567 eerror " ( ${PATCH_TARGET} )"
568 eerror
465 eqawarn "QA Notice: Your patch uses relative paths '../'." 569 eerror "Your patch uses relative paths '../':"
466 eqawarn " In the future this will cause a failure."
467 eqawarn "${rel_paths}" 570 eerror "${rel_paths}"
571 echo
572 die "you need to fix the relative paths in patch"
468 fi 573 fi
469 574
470 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/ 575 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/
471 local patch_cmd 576 local patch_cmd
577 # Handle aliased patch command #404447 #461568
578 local patch="patch"
579 eval $(alias patch 2>/dev/null | sed 's:^alias ::')
472 while [[ ${count} -lt 5 ]] ; do 580 while [[ ${count} -lt 5 ]] ; do
473 patch_cmd="${BASH_ALIASES[patch]:-patch} -p${count} ${EPATCH_OPTS}" 581 patch_cmd="${patch} -p${count} ${EPATCH_OPTS}"
474 582
475 # Generate some useful debug info ... 583 # Generate some useful debug info ...
476 ( 584 (
477 _epatch_draw_line "***** ${patchname} *****" 585 _epatch_draw_line "***** ${patchname} *****"
478 echo 586 echo
838 insinto /usr/share/applications 946 insinto /usr/share/applications
839 doins "${desktop}" 947 doins "${desktop}"
840 ) || die "installing desktop file failed" 948 ) || die "installing desktop file failed"
841} 949}
842 950
951# @FUNCTION: _eutils_eprefix_init
952# @INTERNAL
953# @DESCRIPTION:
954# Initialized prefix variables for EAPI<3.
955_eutils_eprefix_init() {
956 has "${EAPI:-0}" 0 1 2 && : ${ED:=${D}} ${EPREFIX:=} ${EROOT:=${ROOT}}
957}
958
843# @FUNCTION: validate_desktop_entries 959# @FUNCTION: validate_desktop_entries
844# @USAGE: [directories] 960# @USAGE: [directories]
845# @MAINTAINER: 961# @MAINTAINER:
846# Carsten Lohrke <carlo@gentoo.org> 962# Carsten Lohrke <carlo@gentoo.org>
847# @DESCRIPTION: 963# @DESCRIPTION:
848# Validate desktop entries using desktop-file-utils 964# Validate desktop entries using desktop-file-utils
849validate_desktop_entries() { 965validate_desktop_entries() {
966 _eutils_eprefix_init
850 if [[ -x /usr/bin/desktop-file-validate ]] ; then 967 if [[ -x "${EPREFIX}"/usr/bin/desktop-file-validate ]] ; then
851 einfo "Checking desktop entry validity" 968 einfo "Checking desktop entry validity"
852 local directories="" 969 local directories=""
853 for d in /usr/share/applications $@ ; do 970 for d in /usr/share/applications $@ ; do
854 [[ -d ${D}${d} ]] && directories="${directories} ${D}${d}" 971 [[ -d ${ED}${d} ]] && directories="${directories} ${ED}${d}"
855 done 972 done
856 if [[ -n ${directories} ]] ; then 973 if [[ -n ${directories} ]] ; then
857 for FILE in $(find ${directories} -name "*\.desktop" \ 974 for FILE in $(find ${directories} -name "*\.desktop" \
858 -not -path '*.hidden*' | sort -u 2>/dev/null) 975 -not -path '*.hidden*' | sort -u 2>/dev/null)
859 do 976 do
860 local temp=$(desktop-file-validate ${FILE} | grep -v "warning:" | \ 977 local temp=$(desktop-file-validate ${FILE} | grep -v "warning:" | \
861 sed -e "s|error: ||" -e "s|${FILE}:|--|g" ) 978 sed -e "s|error: ||" -e "s|${FILE}:|--|g" )
862 [[ -n $temp ]] && elog ${temp/--/${FILE/${D}/}:} 979 [[ -n $temp ]] && elog ${temp/--/${FILE/${ED}/}:}
863 done 980 done
864 fi 981 fi
865 echo "" 982 echo ""
866 else 983 else
867 einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo." 984 einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo."
1117# would break packages that link against it. Most people get around this 1234# would break packages that link against it. Most people get around this
1118# by using the portage SLOT mechanism, but that is not always a relevant 1235# by using the portage SLOT mechanism, but that is not always a relevant
1119# solution, so instead you can call this from pkg_preinst. See also the 1236# solution, so instead you can call this from pkg_preinst. See also the
1120# preserve_old_lib_notify function. 1237# preserve_old_lib_notify function.
1121preserve_old_lib() { 1238preserve_old_lib() {
1239 _eutils_eprefix_init
1122 if [[ ${EBUILD_PHASE} != "preinst" ]] ; then 1240 if [[ ${EBUILD_PHASE} != "preinst" ]] ; then
1123 eerror "preserve_old_lib() must be called from pkg_preinst() only" 1241 eerror "preserve_old_lib() must be called from pkg_preinst() only"
1124 die "Invalid preserve_old_lib() usage" 1242 die "Invalid preserve_old_lib() usage"
1125 fi 1243 fi
1126 [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]" 1244 [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]"
1128 # let portage worry about it 1246 # let portage worry about it
1129 has preserve-libs ${FEATURES} && return 0 1247 has preserve-libs ${FEATURES} && return 0
1130 1248
1131 local lib dir 1249 local lib dir
1132 for lib in "$@" ; do 1250 for lib in "$@" ; do
1133 [[ -e ${ROOT}/${lib} ]] || continue 1251 [[ -e ${EROOT}/${lib} ]] || continue
1134 dir=${lib%/*} 1252 dir=${lib%/*}
1135 dodir ${dir} || die "dodir ${dir} failed" 1253 dodir ${dir} || die "dodir ${dir} failed"
1136 cp "${ROOT}"/${lib} "${D}"/${lib} || die "cp ${lib} failed" 1254 cp "${EROOT}"/${lib} "${ED}"/${lib} || die "cp ${lib} failed"
1137 touch "${D}"/${lib} 1255 touch "${ED}"/${lib}
1138 done 1256 done
1139} 1257}
1140 1258
1141# @FUNCTION: preserve_old_lib_notify 1259# @FUNCTION: preserve_old_lib_notify
1142# @USAGE: <libs to notify> [more libs] 1260# @USAGE: <libs to notify> [more libs]
1149 fi 1267 fi
1150 1268
1151 # let portage worry about it 1269 # let portage worry about it
1152 has preserve-libs ${FEATURES} && return 0 1270 has preserve-libs ${FEATURES} && return 0
1153 1271
1272 _eutils_eprefix_init
1273
1154 local lib notice=0 1274 local lib notice=0
1155 for lib in "$@" ; do 1275 for lib in "$@" ; do
1156 [[ -e ${ROOT}/${lib} ]] || continue 1276 [[ -e ${EROOT}/${lib} ]] || continue
1157 if [[ ${notice} -eq 0 ]] ; then 1277 if [[ ${notice} -eq 0 ]] ; then
1158 notice=1 1278 notice=1
1159 ewarn "Old versions of installed libraries were detected on your system." 1279 ewarn "Old versions of installed libraries were detected on your system."
1160 ewarn "In order to avoid breaking packages that depend on these old libs," 1280 ewarn "In order to avoid breaking packages that depend on these old libs,"
1161 ewarn "the libraries are not being removed. You need to run revdep-rebuild" 1281 ewarn "the libraries are not being removed. You need to run revdep-rebuild"
1187# in IUSE like normal USE flags. 1307# in IUSE like normal USE flags.
1188# 1308#
1189# Remember that this function isn't terribly intelligent so order of optional 1309# Remember that this function isn't terribly intelligent so order of optional
1190# flags matter. 1310# flags matter.
1191built_with_use() { 1311built_with_use() {
1312 _eutils_eprefix_init
1192 local hidden="no" 1313 local hidden="no"
1193 if [[ $1 == "--hidden" ]] ; then 1314 if [[ $1 == "--hidden" ]] ; then
1194 hidden="yes" 1315 hidden="yes"
1195 shift 1316 shift
1196 fi 1317 fi
1210 1331
1211 local PKG=$(best_version $1) 1332 local PKG=$(best_version $1)
1212 [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package" 1333 [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package"
1213 shift 1334 shift
1214 1335
1215 local USEFILE=${ROOT}/var/db/pkg/${PKG}/USE 1336 local USEFILE=${EROOT}/var/db/pkg/${PKG}/USE
1216 local IUSEFILE=${ROOT}/var/db/pkg/${PKG}/IUSE 1337 local IUSEFILE=${EROOT}/var/db/pkg/${PKG}/IUSE
1217 1338
1218 # if the IUSE file doesn't exist, the read will error out, we need to handle 1339 # if the IUSE file doesn't exist, the read will error out, we need to handle
1219 # this gracefully 1340 # this gracefully
1220 if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]] ; then 1341 if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]] ; then
1221 case ${missing_action} in 1342 case ${missing_action} in
1267# http://bugs.gentoo.org/73450 1388# http://bugs.gentoo.org/73450
1268epunt_cxx() { 1389epunt_cxx() {
1269 local dir=$1 1390 local dir=$1
1270 [[ -z ${dir} ]] && dir=${S} 1391 [[ -z ${dir} ]] && dir=${S}
1271 ebegin "Removing useless C++ checks" 1392 ebegin "Removing useless C++ checks"
1272 local f 1393 local f p any_found
1273 find "${dir}" -name configure | while read f ; do 1394 while IFS= read -r -d '' f; do
1274 patch --no-backup-if-mismatch -p0 "${f}" "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null 1395 for p in "${PORTDIR}"/eclass/ELT-patches/nocxx/*.patch ; do
1396 if patch --no-backup-if-mismatch -p1 "${f}" "${p}" >/dev/null ; then
1397 any_found=1
1398 break
1399 fi
1275 done 1400 done
1401 done < <(find "${dir}" -name configure -print0)
1402
1403 if [[ -z ${any_found} ]]; then
1404 eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt)."
1405 fi
1276 eend 0 1406 eend 0
1277} 1407}
1278 1408
1279# @FUNCTION: make_wrapper 1409# @FUNCTION: make_wrapper
1280# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath] 1410# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
1282# Create a shell wrapper script named wrapper in installpath 1412# Create a shell wrapper script named wrapper in installpath
1283# (defaults to the bindir) to execute target (default of wrapper) by 1413# (defaults to the bindir) to execute target (default of wrapper) by
1284# first optionally setting LD_LIBRARY_PATH to the colon-delimited 1414# first optionally setting LD_LIBRARY_PATH to the colon-delimited
1285# libpaths followed by optionally changing directory to chdir. 1415# libpaths followed by optionally changing directory to chdir.
1286make_wrapper() { 1416make_wrapper() {
1417 _eutils_eprefix_init
1287 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5 1418 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
1288 local tmpwrapper=$(emktemp) 1419 local tmpwrapper=$(emktemp)
1420
1421 (
1422 echo '#!/bin/sh'
1423 [[ -n ${chdir} ]] && printf 'cd "%s"\n' "${EPREFIX}${chdir}"
1424 if [[ -n ${libdir} ]] ; then
1425 local var
1426 if [[ ${CHOST} == *-darwin* ]] ; then
1427 var=DYLD_LIBRARY_PATH
1428 else
1429 var=LD_LIBRARY_PATH
1430 fi
1431 cat <<-EOF
1432 if [ "\${${var}+set}" = "set" ] ; then
1433 export ${var}="\${${var}}:${EPREFIX}${libdir}"
1434 else
1435 export ${var}="${EPREFIX}${libdir}"
1436 fi
1437 EOF
1438 fi
1289 # We don't want to quote ${bin} so that people can pass complex 1439 # We don't want to quote ${bin} so that people can pass complex
1290 # things as $bin ... "./someprog --args" 1440 # things as ${bin} ... "./someprog --args"
1441 printf 'exec %s "$@"\n' "${bin/#\//${EPREFIX}\/}"
1291 cat << EOF > "${tmpwrapper}" 1442 ) > "${tmpwrapper}"
1292#!/bin/sh
1293cd "${chdir:-.}"
1294if [ -n "${libdir}" ] ; then
1295 if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
1296 export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
1297 else
1298 export LD_LIBRARY_PATH="${libdir}"
1299 fi
1300fi
1301exec ${bin} "\$@"
1302EOF
1303 chmod go+rx "${tmpwrapper}" 1443 chmod go+rx "${tmpwrapper}"
1444
1304 if [[ -n ${path} ]] ; then 1445 if [[ -n ${path} ]] ; then
1305 ( 1446 (
1306 exeinto "${path}" 1447 exeinto "${path}"
1307 newexe "${tmpwrapper}" "${wrapper}" 1448 newexe "${tmpwrapper}" "${wrapper}"
1308 ) || die 1449 ) || die
1378if has "${EAPI:-0}" 0 1 2 3 4; then 1519if has "${EAPI:-0}" 0 1 2 3 4; then
1379 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963 1520 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
1380fi 1521fi
1381 1522
1382# @FUNCTION: prune_libtool_files 1523# @FUNCTION: prune_libtool_files
1383# @USAGE: [--all] 1524# @USAGE: [--all|--modules]
1384# @DESCRIPTION: 1525# @DESCRIPTION:
1385# Locate unnecessary libtool files (.la) and libtool static archives 1526# Locate unnecessary libtool files (.la) and libtool static archives
1386# (.a) and remove them from installation image. 1527# (.a) and remove them from installation image.
1387# 1528#
1388# By default, .la files are removed whenever the static linkage can 1529# By default, .la files are removed whenever the static linkage can
1389# either be performed using pkg-config or doesn't introduce additional 1530# either be performed using pkg-config or doesn't introduce additional
1390# flags. 1531# flags.
1391# 1532#
1533# If '--modules' argument is passed, .la files for modules (plugins) are
1534# removed as well. This is usually useful when the package installs
1535# plugins and the plugin loader does not use .la files.
1536#
1392# If '--all' argument is passed, all .la files are removed. This is 1537# If '--all' argument is passed, all .la files are removed without
1393# usually useful when the package installs plugins and does not use .la 1538# performing any heuristic on them. You shouldn't ever use that,
1394# files for loading them. 1539# and instead report a bug in the algorithm instead.
1395# 1540#
1396# The .a files are only removed whenever corresponding .la files state 1541# The .a files are only removed whenever corresponding .la files state
1397# that they should not be linked to, i.e. whenever these files 1542# that they should not be linked to, i.e. whenever these files
1398# correspond to plugins. 1543# correspond to plugins.
1399# 1544#
1400# Note: if your package installs both static libraries and .pc files, 1545# Note: if your package installs both static libraries and .pc files
1546# which use variable substitution for -l flags, you need to add
1401# you need to add pkg-config to your DEPEND. 1547# pkg-config to your DEPEND.
1402prune_libtool_files() { 1548prune_libtool_files() {
1403 debug-print-function ${FUNCNAME} "$@" 1549 debug-print-function ${FUNCNAME} "$@"
1404 1550
1405 local removing_all opt 1551 local removing_all removing_modules opt
1552 _eutils_eprefix_init
1406 for opt; do 1553 for opt; do
1407 case "${opt}" in 1554 case "${opt}" in
1408 --all) 1555 --all)
1409 removing_all=1 1556 removing_all=1
1557 removing_modules=1
1558 ;;
1559 --modules)
1560 removing_modules=1
1410 ;; 1561 ;;
1411 *) 1562 *)
1412 die "Invalid argument to ${FUNCNAME}(): ${opt}" 1563 die "Invalid argument to ${FUNCNAME}(): ${opt}"
1413 esac 1564 esac
1414 done 1565 done
1416 local f 1567 local f
1417 local queue=() 1568 local queue=()
1418 while IFS= read -r -d '' f; do # for all .la files 1569 while IFS= read -r -d '' f; do # for all .la files
1419 local archivefile=${f/%.la/.a} 1570 local archivefile=${f/%.la/.a}
1420 1571
1572 # The following check is done by libtool itself.
1573 # It helps us avoid removing random files which match '*.la',
1574 # see bug #468380.
1575 if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
1576 continue
1577 fi
1578
1421 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed' 1579 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1580 local reason pkgconfig_scanned
1581 local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
1422 1582
1583 if [[ ${snotlink} == yes ]]; then
1584
1423 # Remove static libs we're not supposed to link against. 1585 # Remove static libs we're not supposed to link against.
1424 if grep -q '^shouldnotlink=yes$' "${f}"; then
1425 if [[ -f ${archivefile} ]]; then 1586 if [[ -f ${archivefile} ]]; then
1426 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)" 1587 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1427 queue+=( "${archivefile}" ) 1588 queue+=( "${archivefile}" )
1428 fi 1589 fi
1429 1590
1430 # The .la file may be used by a module loader, so avoid removing it 1591 # The .la file may be used by a module loader, so avoid removing it
1431 # unless explicitly requested. 1592 # unless explicitly requested.
1432 [[ ${removing_all} ]] || continue 1593 if [[ ${removing_modules} ]]; then
1594 reason='module'
1433 fi 1595 fi
1434 1596
1435 # Remove .la files when:
1436 # - user explicitly wants us to remove all .la files,
1437 # - respective static archive doesn't exist,
1438 # - they are covered by a .pc file already,
1439 # - they don't provide any new information (no libs & no flags).
1440 local reason pkgconfig_scanned
1441 if [[ ${removing_all} ]]; then
1442 reason='requested'
1443 elif [[ ! -f ${archivefile} ]]; then
1444 reason='no static archive'
1445 elif [[ ! $(sed -nre \
1446 "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
1447 "${f}") ]]; then
1448 reason='no libs & flags'
1449 else 1597 else
1598
1599 # Remove .la files when:
1600 # - user explicitly wants us to remove all .la files,
1601 # - respective static archive doesn't exist,
1602 # - they are covered by a .pc file already,
1603 # - they don't provide any new information (no libs & no flags).
1604
1605 if [[ ${removing_all} ]]; then
1606 reason='requested'
1607 elif [[ ! -f ${archivefile} ]]; then
1608 reason='no static archive'
1609 elif [[ ! $(sed -nre \
1610 "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
1611 "${f}") ]]; then
1612 reason='no libs & flags'
1613 else
1450 if [[ ! ${pkgconfig_scanned} ]]; then 1614 if [[ ! ${pkgconfig_scanned} ]]; then
1451 # Create a list of all .pc-covered libs. 1615 # Create a list of all .pc-covered libs.
1452 local pc_libs=() 1616 local pc_libs=()
1453 if [[ ! ${removing_all} ]]; then 1617 if [[ ! ${removing_all} ]]; then
1454 local f 1618 local pc
1455 local tf=${T}/prune-lt-files.pc 1619 local tf=${T}/prune-lt-files.pc
1456 local pkgconf=$(tc-getPKG_CONFIG) 1620 local pkgconf=$(tc-getPKG_CONFIG)
1457 1621
1458 while IFS= read -r -d '' f; do # for all .pc files 1622 while IFS= read -r -d '' pc; do # for all .pc files
1459 local arg 1623 local arg libs
1460 1624
1625 # Use pkg-config if available (and works),
1626 # fallback to sed.
1627 if ${pkgconf} --exists "${pc}" &>/dev/null; then
1461 sed -e '/^Requires:/d' "${f}" > "${tf}" 1628 sed -e '/^Requires:/d' "${pc}" > "${tf}"
1462 for arg in $("${pkgconf}" --libs "${tf}"); do 1629 libs=$(${pkgconf} --libs "${tf}")
1463 [[ ${arg} == -l* ]] && pc_libs+=( lib${arg#-l}.la ) 1630 else
1631 libs=$(sed -ne 's/^Libs://p' "${pc}")
1632 fi
1633
1634 for arg in ${libs}; do
1635 if [[ ${arg} == -l* ]]; then
1636 if [[ ${arg} == '*$*' ]]; then
1637 eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
1638 eqawarn "(arg: ${arg})"
1639 eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
1640 fi
1641
1642 pc_libs+=( lib${arg#-l}.la )
1643 fi
1464 done 1644 done
1465 done < <(find "${D}" -type f -name '*.pc' -print0) 1645 done < <(find "${D}" -type f -name '*.pc' -print0)
1466 1646
1467 rm -f "${tf}" 1647 rm -f "${tf}"
1468 fi 1648 fi
1469 1649
1470 pkgconfig_scanned=1 1650 pkgconfig_scanned=1
1471 fi 1651 fi # pkgconfig_scanned
1472 1652
1473 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc' 1653 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1474 fi 1654 fi # removal due to .pc
1655
1656 fi # shouldnotlink==no
1475 1657
1476 if [[ ${reason} ]]; then 1658 if [[ ${reason} ]]; then
1477 einfo "Removing unnecessary ${f#${D%/}} (${reason})" 1659 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1478 queue+=( "${f}" ) 1660 queue+=( "${f}" )
1479 fi 1661 fi
1480 done < <(find "${D}" -xtype f -name '*.la' -print0) 1662 done < <(find "${ED}" -xtype f -name '*.la' -print0)
1481 1663
1482 if [[ ${queue[@]} ]]; then 1664 if [[ ${queue[@]} ]]; then
1483 rm -f "${queue[@]}" 1665 rm -f "${queue[@]}"
1484 fi 1666 fi
1485} 1667}
1486 1668
1669# @FUNCTION: prune_libtool_files
1670# @DESCRIPTION:
1671# Install documentation using DOCS and HTML_DOCS.
1672#
1673# If DOCS is declared and non-empty, all files listed in it are
1674# installed. The files must exist, otherwise the function will fail.
1675# In EAPI 4 and subsequent EAPIs DOCS may specify directories as well,
1676# in other EAPIs using directories is unsupported.
1677#
1678# If DOCS is not declared, the files matching patterns given
1679# in the default EAPI implementation of src_install will be installed.
1680# If this is undesired, DOCS can be set to empty value to prevent any
1681# documentation from being installed.
1682#
1683# If HTML_DOCS is declared and non-empty, all files and/or directories
1684# listed in it are installed as HTML docs (using dohtml).
1685#
1686# Both DOCS and HTML_DOCS can either be an array or a whitespace-
1687# separated list. Whenever directories are allowed, '<directory>/.' may
1688# be specified in order to install all files within the directory
1689# without creating a sub-directory in docdir.
1690#
1691# Passing additional options to dodoc and dohtml is not supported.
1692# If you needed such a thing, you need to call those helpers explicitly.
1693einstalldocs() {
1694 debug-print-function ${FUNCNAME} "${@}"
1695
1696 local dodoc_opts=-r
1697 has ${EAPI} 0 1 2 3 && dodoc_opts=
1698
1699 if ! declare -p DOCS &>/dev/null ; then
1700 local d
1701 for d in README* ChangeLog AUTHORS NEWS TODO CHANGES \
1702 THANKS BUGS FAQ CREDITS CHANGELOG ; do
1703 if [[ -s ${d} ]] ; then
1704 dodoc "${d}" || die
1705 fi
1706 done
1707 elif [[ $(declare -p DOCS) == "declare -a"* ]] ; then
1708 if [[ ${DOCS[@]} ]] ; then
1709 dodoc ${dodoc_opts} "${DOCS[@]}" || die
1710 fi
1711 else
1712 if [[ ${DOCS} ]] ; then
1713 dodoc ${dodoc_opts} ${DOCS} || die
1714 fi
1715 fi
1716
1717 if [[ $(declare -p HTML_DOCS 2>/dev/null) == "declare -a"* ]] ; then
1718 if [[ ${HTML_DOCS[@]} ]] ; then
1719 dohtml -r "${HTML_DOCS[@]}" || die
1720 fi
1721 else
1722 if [[ ${HTML_DOCS} ]] ; then
1723 dohtml -r ${HTML_DOCS} || die
1724 fi
1725 fi
1726
1727 return 0
1728}
1729
1487check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; } 1730check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; }
1488 1731
1489fi 1732fi

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

  ViewVC Help
Powered by ViewVC 1.1.20