/[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.440
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2014 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.440 2014/11/15 09:49:10 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
13# home rather than having multiple ebuilds implementing the same thing. 13# home rather than having multiple ebuilds implementing the same thing.
14# 14#
15# Due to the nature of this eclass, some functions may have maintainers 15# Due to the nature of this eclass, some functions may have maintainers
16# different from the overall eclass! 16# different from the overall eclass!
17 17
18if [[ ${___ECLASS_ONCE_EUTILS} != "recur -_+^+_- spank" ]] ; then 18if [[ -z ${_EUTILS_ECLASS} ]]; then
19___ECLASS_ONCE_EUTILS="recur -_+^+_- spank" 19_EUTILS_ECLASS=1
20 20
21inherit multilib toolchain-funcs user 21inherit multilib toolchain-funcs
22 22
23if has "${EAPI:-0}" 0 1 2; then 23if has "${EAPI:-0}" 0 1 2; then
24 24
25# @FUNCTION: epause 25# @FUNCTION: epause
26# @USAGE: [seconds] 26# @USAGE: [seconds]
112# echo "${i}" 112# echo "${i}"
113# done 113# done
114# @CODE 114# @CODE
115estack_push() { 115estack_push() {
116 [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments" 116 [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments"
117 local stack_name="__ESTACK_$1__" ; shift 117 local stack_name="_ESTACK_$1_" ; shift
118 eval ${stack_name}+=\( \"\$@\" \) 118 eval ${stack_name}+=\( \"\$@\" \)
119} 119}
120 120
121# @FUNCTION: estack_pop 121# @FUNCTION: estack_pop
122# @USAGE: <stack> [variable] 122# @USAGE: <stack> [variable]
125# the popped item is stored there. If no more items are available, return 125# the popped item is stored there. If no more items are available, return
126# 1, else return 0. See estack_push for more info. 126# 1, else return 0. See estack_push for more info.
127estack_pop() { 127estack_pop() {
128 [[ $# -eq 0 || $# -gt 2 ]] && die "estack_pop: incorrect # of arguments" 128 [[ $# -eq 0 || $# -gt 2 ]] && die "estack_pop: incorrect # of arguments"
129 129
130 # We use the fugly __estack_xxx var names to avoid collision with 130 # We use the fugly _estack_xxx var names to avoid collision with
131 # passing back the return value. If we used "local i" and the 131 # passing back the return value. If we used "local i" and the
132 # caller ran `estack_pop ... i`, we'd end up setting the local 132 # caller ran `estack_pop ... i`, we'd end up setting the local
133 # copy of "i" rather than the caller's copy. The __estack_xxx 133 # copy of "i" rather than the caller's copy. The _estack_xxx
134 # garbage is preferable to using $1/$2 everywhere as that is a 134 # garbage is preferable to using $1/$2 everywhere as that is a
135 # bit harder to read. 135 # bit harder to read.
136 local __estack_name="__ESTACK_$1__" ; shift 136 local _estack_name="_ESTACK_$1_" ; shift
137 local __estack_retvar=$1 ; shift 137 local _estack_retvar=$1 ; shift
138 eval local __estack_i=\${#${__estack_name}\[@\]} 138 eval local _estack_i=\${#${_estack_name}\[@\]}
139 # Don't warn -- let the caller interpret this as a failure 139 # Don't warn -- let the caller interpret this as a failure
140 # or as normal behavior (akin to `shift`) 140 # or as normal behavior (akin to `shift`)
141 [[ $(( --__estack_i )) -eq -1 ]] && return 1 141 [[ $(( --_estack_i )) -eq -1 ]] && return 1
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="unset_76fc3c462065bb4ca959f939e6793f94"
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} == "unset_76fc3c462065bb4ca959f939e6793f94" ]] \
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:
158# rather than `set` as there are some options only available via that. 229# rather than `set` as there are some options only available via that.
159# 230#
160# A common example is to disable shell globbing so that special meaning/care 231# A common example is to disable shell globbing so that special meaning/care
161# may be used with variables/arguments to custom functions. That would be: 232# may be used with variables/arguments to custom functions. That would be:
162# @CODE 233# @CODE
163# eshopts_push -s noglob 234# eshopts_push -o noglob
164# for x in ${foo} ; do 235# for x in ${foo} ; do
165# if ...some check... ; then 236# if ...some check... ; then
166# eshopts_pop 237# eshopts_pop
167# return 0 238# return 0
168# fi 239# fi
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 $?
396 then 487 then
397 continue 488 continue
398 fi 489 fi
399 490
400 # Let people filter things dynamically 491 # Let people filter things dynamically
401 if [[ -n ${EPATCH_EXCLUDE} ]] ; then 492 if [[ -n ${EPATCH_EXCLUDE}${EPATCH_USER_EXCLUDE} ]] ; then
402 # let people use globs in the exclude 493 # let people use globs in the exclude
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
549 657
550# @FUNCTION: epatch_user 658# @FUNCTION: epatch_user
551# @USAGE: 659# @USAGE:
552# @DESCRIPTION: 660# @DESCRIPTION:
553# Applies user-provided patches to the source tree. The patches are 661# Applies user-provided patches to the source tree. The patches are
554# taken from /etc/portage/patches/<CATEGORY>/<PF|P|PN>[:SLOT]/, where the first 662# taken from /etc/portage/patches/<CATEGORY>/<P-PR|P|PN>[:SLOT]/, where the first
555# of these three directories to exist will be the one to use, ignoring 663# of these three directories to exist will be the one to use, ignoring
556# any more general directories which might exist as well. They must end 664# any more general directories which might exist as well. They must end
557# in ".patch" to be applied. 665# in ".patch" to be applied.
558# 666#
559# User patches are intended for quick testing of patches without ebuild 667# User patches are intended for quick testing of patches without ebuild
793 *) 901 *)
794 type= 902 type=
795 ;; 903 ;;
796 esac 904 esac
797 fi 905 fi
906 local slot=${SLOT%/*}
798 if [ "${SLOT}" == "0" ] ; then 907 if [[ ${slot} == "0" ]] ; then
799 local desktop_name="${PN}" 908 local desktop_name="${PN}"
800 else 909 else
801 local desktop_name="${PN}-${SLOT}" 910 local desktop_name="${PN}-${slot}"
802 fi 911 fi
803 local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop" 912 local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop"
804 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop 913 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop
805 914
806 # Don't append another ";" when a valid category value is provided. 915 # Don't append another ";" when a valid category value is provided.
838 insinto /usr/share/applications 947 insinto /usr/share/applications
839 doins "${desktop}" 948 doins "${desktop}"
840 ) || die "installing desktop file failed" 949 ) || die "installing desktop file failed"
841} 950}
842 951
952# @FUNCTION: _eutils_eprefix_init
953# @INTERNAL
954# @DESCRIPTION:
955# Initialized prefix variables for EAPI<3.
956_eutils_eprefix_init() {
957 has "${EAPI:-0}" 0 1 2 && : ${ED:=${D}} ${EPREFIX:=} ${EROOT:=${ROOT}}
958}
959
843# @FUNCTION: validate_desktop_entries 960# @FUNCTION: validate_desktop_entries
844# @USAGE: [directories] 961# @USAGE: [directories]
845# @MAINTAINER: 962# @MAINTAINER:
846# Carsten Lohrke <carlo@gentoo.org> 963# Carsten Lohrke <carlo@gentoo.org>
847# @DESCRIPTION: 964# @DESCRIPTION:
848# Validate desktop entries using desktop-file-utils 965# Validate desktop entries using desktop-file-utils
849validate_desktop_entries() { 966validate_desktop_entries() {
967 _eutils_eprefix_init
850 if [[ -x /usr/bin/desktop-file-validate ]] ; then 968 if [[ -x "${EPREFIX}"/usr/bin/desktop-file-validate ]] ; then
851 einfo "Checking desktop entry validity" 969 einfo "Checking desktop entry validity"
852 local directories="" 970 local directories=""
853 for d in /usr/share/applications $@ ; do 971 for d in /usr/share/applications $@ ; do
854 [[ -d ${D}${d} ]] && directories="${directories} ${D}${d}" 972 [[ -d ${ED}${d} ]] && directories="${directories} ${ED}${d}"
855 done 973 done
856 if [[ -n ${directories} ]] ; then 974 if [[ -n ${directories} ]] ; then
857 for FILE in $(find ${directories} -name "*\.desktop" \ 975 for FILE in $(find ${directories} -name "*\.desktop" \
858 -not -path '*.hidden*' | sort -u 2>/dev/null) 976 -not -path '*.hidden*' | sort -u 2>/dev/null)
859 do 977 do
860 local temp=$(desktop-file-validate ${FILE} | grep -v "warning:" | \ 978 local temp=$(desktop-file-validate ${FILE} | grep -v "warning:" | \
861 sed -e "s|error: ||" -e "s|${FILE}:|--|g" ) 979 sed -e "s|error: ||" -e "s|${FILE}:|--|g" )
862 [[ -n $temp ]] && elog ${temp/--/${FILE/${D}/}:} 980 [[ -n $temp ]] && elog ${temp/--/${FILE/${ED}/}:}
863 done 981 done
864 fi 982 fi
865 echo "" 983 echo ""
866 else 984 else
867 einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo." 985 einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo."
1050# @CODE 1168# @CODE
1051# example 1: newicon foobar.png NEWNAME.png 1169# example 1: newicon foobar.png NEWNAME.png
1052# results in: insinto /usr/share/pixmaps 1170# results in: insinto /usr/share/pixmaps
1053# newins foobar.png NEWNAME.png 1171# newins foobar.png NEWNAME.png
1054# 1172#
1055# example 2: newicon -s 48 foobar.png NEWNAME.png 1173# example 2: newicon -s 48 foobar.png NEWNAME.png
1056# results in: insinto /usr/share/icons/hicolor/48x48/apps 1174# results in: insinto /usr/share/icons/hicolor/48x48/apps
1057# newins foobar.png NEWNAME.png 1175# newins foobar.png NEWNAME.png
1058# @CODE 1176# @CODE
1059newicon() { 1177newicon() {
1060 _iconins ${FUNCNAME} "$@" 1178 _iconins ${FUNCNAME} "$@"
1117# would break packages that link against it. Most people get around this 1235# 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 1236# 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 1237# solution, so instead you can call this from pkg_preinst. See also the
1120# preserve_old_lib_notify function. 1238# preserve_old_lib_notify function.
1121preserve_old_lib() { 1239preserve_old_lib() {
1240 _eutils_eprefix_init
1122 if [[ ${EBUILD_PHASE} != "preinst" ]] ; then 1241 if [[ ${EBUILD_PHASE} != "preinst" ]] ; then
1123 eerror "preserve_old_lib() must be called from pkg_preinst() only" 1242 eerror "preserve_old_lib() must be called from pkg_preinst() only"
1124 die "Invalid preserve_old_lib() usage" 1243 die "Invalid preserve_old_lib() usage"
1125 fi 1244 fi
1126 [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]" 1245 [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]"
1128 # let portage worry about it 1247 # let portage worry about it
1129 has preserve-libs ${FEATURES} && return 0 1248 has preserve-libs ${FEATURES} && return 0
1130 1249
1131 local lib dir 1250 local lib dir
1132 for lib in "$@" ; do 1251 for lib in "$@" ; do
1133 [[ -e ${ROOT}/${lib} ]] || continue 1252 [[ -e ${EROOT}/${lib} ]] || continue
1134 dir=${lib%/*} 1253 dir=${lib%/*}
1135 dodir ${dir} || die "dodir ${dir} failed" 1254 dodir ${dir} || die "dodir ${dir} failed"
1136 cp "${ROOT}"/${lib} "${D}"/${lib} || die "cp ${lib} failed" 1255 cp "${EROOT}"/${lib} "${ED}"/${lib} || die "cp ${lib} failed"
1137 touch "${D}"/${lib} 1256 touch "${ED}"/${lib}
1138 done 1257 done
1139} 1258}
1140 1259
1141# @FUNCTION: preserve_old_lib_notify 1260# @FUNCTION: preserve_old_lib_notify
1142# @USAGE: <libs to notify> [more libs] 1261# @USAGE: <libs to notify> [more libs]
1149 fi 1268 fi
1150 1269
1151 # let portage worry about it 1270 # let portage worry about it
1152 has preserve-libs ${FEATURES} && return 0 1271 has preserve-libs ${FEATURES} && return 0
1153 1272
1273 _eutils_eprefix_init
1274
1154 local lib notice=0 1275 local lib notice=0
1155 for lib in "$@" ; do 1276 for lib in "$@" ; do
1156 [[ -e ${ROOT}/${lib} ]] || continue 1277 [[ -e ${EROOT}/${lib} ]] || continue
1157 if [[ ${notice} -eq 0 ]] ; then 1278 if [[ ${notice} -eq 0 ]] ; then
1158 notice=1 1279 notice=1
1159 ewarn "Old versions of installed libraries were detected on your system." 1280 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," 1281 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" 1282 ewarn "the libraries are not being removed. You need to run revdep-rebuild"
1187# in IUSE like normal USE flags. 1308# in IUSE like normal USE flags.
1188# 1309#
1189# Remember that this function isn't terribly intelligent so order of optional 1310# Remember that this function isn't terribly intelligent so order of optional
1190# flags matter. 1311# flags matter.
1191built_with_use() { 1312built_with_use() {
1313 _eutils_eprefix_init
1192 local hidden="no" 1314 local hidden="no"
1193 if [[ $1 == "--hidden" ]] ; then 1315 if [[ $1 == "--hidden" ]] ; then
1194 hidden="yes" 1316 hidden="yes"
1195 shift 1317 shift
1196 fi 1318 fi
1210 1332
1211 local PKG=$(best_version $1) 1333 local PKG=$(best_version $1)
1212 [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package" 1334 [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package"
1213 shift 1335 shift
1214 1336
1215 local USEFILE=${ROOT}/var/db/pkg/${PKG}/USE 1337 local USEFILE=${EROOT}/var/db/pkg/${PKG}/USE
1216 local IUSEFILE=${ROOT}/var/db/pkg/${PKG}/IUSE 1338 local IUSEFILE=${EROOT}/var/db/pkg/${PKG}/IUSE
1217 1339
1218 # if the IUSE file doesn't exist, the read will error out, we need to handle 1340 # if the IUSE file doesn't exist, the read will error out, we need to handle
1219 # this gracefully 1341 # this gracefully
1220 if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]] ; then 1342 if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]] ; then
1221 case ${missing_action} in 1343 case ${missing_action} in
1267# http://bugs.gentoo.org/73450 1389# http://bugs.gentoo.org/73450
1268epunt_cxx() { 1390epunt_cxx() {
1269 local dir=$1 1391 local dir=$1
1270 [[ -z ${dir} ]] && dir=${S} 1392 [[ -z ${dir} ]] && dir=${S}
1271 ebegin "Removing useless C++ checks" 1393 ebegin "Removing useless C++ checks"
1272 local f 1394 local f p any_found
1273 find "${dir}" -name configure | while read f ; do 1395 while IFS= read -r -d '' f; do
1274 patch --no-backup-if-mismatch -p0 "${f}" "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null 1396 for p in "${PORTDIR}"/eclass/ELT-patches/nocxx/*.patch ; do
1397 if patch --no-backup-if-mismatch -p1 "${f}" "${p}" >/dev/null ; then
1398 any_found=1
1399 break
1400 fi
1275 done 1401 done
1402 done < <(find "${dir}" -name configure -print0)
1403
1404 if [[ -z ${any_found} ]]; then
1405 eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt)."
1406 fi
1276 eend 0 1407 eend 0
1277} 1408}
1278 1409
1279# @FUNCTION: make_wrapper 1410# @FUNCTION: make_wrapper
1280# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath] 1411# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
1282# Create a shell wrapper script named wrapper in installpath 1413# Create a shell wrapper script named wrapper in installpath
1283# (defaults to the bindir) to execute target (default of wrapper) by 1414# (defaults to the bindir) to execute target (default of wrapper) by
1284# first optionally setting LD_LIBRARY_PATH to the colon-delimited 1415# first optionally setting LD_LIBRARY_PATH to the colon-delimited
1285# libpaths followed by optionally changing directory to chdir. 1416# libpaths followed by optionally changing directory to chdir.
1286make_wrapper() { 1417make_wrapper() {
1418 _eutils_eprefix_init
1287 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5 1419 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
1288 local tmpwrapper=$(emktemp) 1420 local tmpwrapper=$(emktemp)
1421
1422 (
1423 echo '#!/bin/sh'
1424 [[ -n ${chdir} ]] && printf 'cd "%s"\n' "${EPREFIX}${chdir}"
1425 if [[ -n ${libdir} ]] ; then
1426 local var
1427 if [[ ${CHOST} == *-darwin* ]] ; then
1428 var=DYLD_LIBRARY_PATH
1429 else
1430 var=LD_LIBRARY_PATH
1431 fi
1432 cat <<-EOF
1433 if [ "\${${var}+set}" = "set" ] ; then
1434 export ${var}="\${${var}}:${EPREFIX}${libdir}"
1435 else
1436 export ${var}="${EPREFIX}${libdir}"
1437 fi
1438 EOF
1439 fi
1289 # We don't want to quote ${bin} so that people can pass complex 1440 # We don't want to quote ${bin} so that people can pass complex
1290 # things as $bin ... "./someprog --args" 1441 # things as ${bin} ... "./someprog --args"
1442 printf 'exec %s "$@"\n' "${bin/#\//${EPREFIX}/}"
1291 cat << EOF > "${tmpwrapper}" 1443 ) > "${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}" 1444 chmod go+rx "${tmpwrapper}"
1445
1304 if [[ -n ${path} ]] ; then 1446 if [[ -n ${path} ]] ; then
1305 ( 1447 (
1306 exeinto "${path}" 1448 exeinto "${path}"
1307 newexe "${tmpwrapper}" "${wrapper}" 1449 newexe "${tmpwrapper}" "${wrapper}"
1308 ) || die 1450 ) || die
1378if has "${EAPI:-0}" 0 1 2 3 4; then 1520if has "${EAPI:-0}" 0 1 2 3 4; then
1379 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963 1521 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
1380fi 1522fi
1381 1523
1382# @FUNCTION: prune_libtool_files 1524# @FUNCTION: prune_libtool_files
1383# @USAGE: [--all] 1525# @USAGE: [--all|--modules]
1384# @DESCRIPTION: 1526# @DESCRIPTION:
1385# Locate unnecessary libtool files (.la) and libtool static archives 1527# Locate unnecessary libtool files (.la) and libtool static archives
1386# (.a) and remove them from installation image. 1528# (.a) and remove them from installation image.
1387# 1529#
1388# By default, .la files are removed whenever the static linkage can 1530# By default, .la files are removed whenever the static linkage can
1389# either be performed using pkg-config or doesn't introduce additional 1531# either be performed using pkg-config or doesn't introduce additional
1390# flags. 1532# flags.
1391# 1533#
1534# If '--modules' argument is passed, .la files for modules (plugins) are
1535# removed as well. This is usually useful when the package installs
1536# plugins and the plugin loader does not use .la files.
1537#
1392# If '--all' argument is passed, all .la files are removed. This is 1538# If '--all' argument is passed, all .la files are removed without
1393# usually useful when the package installs plugins and does not use .la 1539# performing any heuristic on them. You shouldn't ever use that,
1394# files for loading them. 1540# and instead report a bug in the algorithm instead.
1395# 1541#
1396# The .a files are only removed whenever corresponding .la files state 1542# The .a files are only removed whenever corresponding .la files state
1397# that they should not be linked to, i.e. whenever these files 1543# that they should not be linked to, i.e. whenever these files
1398# correspond to plugins. 1544# correspond to plugins.
1399# 1545#
1400# Note: if your package installs both static libraries and .pc files, 1546# Note: if your package installs both static libraries and .pc files
1547# which use variable substitution for -l flags, you need to add
1401# you need to add pkg-config to your DEPEND. 1548# pkg-config to your DEPEND.
1402prune_libtool_files() { 1549prune_libtool_files() {
1403 debug-print-function ${FUNCNAME} "$@" 1550 debug-print-function ${FUNCNAME} "$@"
1404 1551
1405 local removing_all opt 1552 local removing_all removing_modules opt
1553 _eutils_eprefix_init
1406 for opt; do 1554 for opt; do
1407 case "${opt}" in 1555 case "${opt}" in
1408 --all) 1556 --all)
1409 removing_all=1 1557 removing_all=1
1558 removing_modules=1
1559 ;;
1560 --modules)
1561 removing_modules=1
1410 ;; 1562 ;;
1411 *) 1563 *)
1412 die "Invalid argument to ${FUNCNAME}(): ${opt}" 1564 die "Invalid argument to ${FUNCNAME}(): ${opt}"
1413 esac 1565 esac
1414 done 1566 done
1416 local f 1568 local f
1417 local queue=() 1569 local queue=()
1418 while IFS= read -r -d '' f; do # for all .la files 1570 while IFS= read -r -d '' f; do # for all .la files
1419 local archivefile=${f/%.la/.a} 1571 local archivefile=${f/%.la/.a}
1420 1572
1573 # The following check is done by libtool itself.
1574 # It helps us avoid removing random files which match '*.la',
1575 # see bug #468380.
1576 if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
1577 continue
1578 fi
1579
1421 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed' 1580 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1581 local reason pkgconfig_scanned
1582 local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
1422 1583
1584 if [[ ${snotlink} == yes ]]; then
1585
1423 # Remove static libs we're not supposed to link against. 1586 # Remove static libs we're not supposed to link against.
1424 if grep -q '^shouldnotlink=yes$' "${f}"; then
1425 if [[ -f ${archivefile} ]]; then 1587 if [[ -f ${archivefile} ]]; then
1426 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)" 1588 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1427 queue+=( "${archivefile}" ) 1589 queue+=( "${archivefile}" )
1428 fi 1590 fi
1429 1591
1430 # The .la file may be used by a module loader, so avoid removing it 1592 # The .la file may be used by a module loader, so avoid removing it
1431 # unless explicitly requested. 1593 # unless explicitly requested.
1432 [[ ${removing_all} ]] || continue 1594 if [[ ${removing_modules} ]]; then
1595 reason='module'
1433 fi 1596 fi
1434 1597
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 1598 else
1599
1600 # Remove .la files when:
1601 # - user explicitly wants us to remove all .la files,
1602 # - respective static archive doesn't exist,
1603 # - they are covered by a .pc file already,
1604 # - they don't provide any new information (no libs & no flags).
1605
1606 if [[ ${removing_all} ]]; then
1607 reason='requested'
1608 elif [[ ! -f ${archivefile} ]]; then
1609 reason='no static archive'
1610 elif [[ ! $(sed -nre \
1611 "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
1612 "${f}") ]]; then
1613 reason='no libs & flags'
1614 else
1450 if [[ ! ${pkgconfig_scanned} ]]; then 1615 if [[ ! ${pkgconfig_scanned} ]]; then
1451 # Create a list of all .pc-covered libs. 1616 # Create a list of all .pc-covered libs.
1452 local pc_libs=() 1617 local pc_libs=()
1453 if [[ ! ${removing_all} ]]; then 1618 if [[ ! ${removing_all} ]]; then
1454 local f 1619 local pc
1455 local tf=${T}/prune-lt-files.pc 1620 local tf=${T}/prune-lt-files.pc
1456 local pkgconf=$(tc-getPKG_CONFIG) 1621 local pkgconf=$(tc-getPKG_CONFIG)
1457 1622
1458 while IFS= read -r -d '' f; do # for all .pc files 1623 while IFS= read -r -d '' pc; do # for all .pc files
1459 local arg 1624 local arg libs
1460 1625
1626 # Use pkg-config if available (and works),
1627 # fallback to sed.
1628 if ${pkgconf} --exists "${pc}" &>/dev/null; then
1461 sed -e '/^Requires:/d' "${f}" > "${tf}" 1629 sed -e '/^Requires:/d' "${pc}" > "${tf}"
1462 for arg in $("${pkgconf}" --libs "${tf}"); do 1630 libs=$(${pkgconf} --libs "${tf}")
1463 [[ ${arg} == -l* ]] && pc_libs+=( lib${arg#-l}.la ) 1631 else
1632 libs=$(sed -ne 's/^Libs://p' "${pc}")
1633 fi
1634
1635 for arg in ${libs}; do
1636 if [[ ${arg} == -l* ]]; then
1637 if [[ ${arg} == '*$*' ]]; then
1638 eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
1639 eqawarn "(arg: ${arg})"
1640 eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
1641 fi
1642
1643 pc_libs+=( lib${arg#-l}.la )
1644 fi
1464 done 1645 done
1465 done < <(find "${D}" -type f -name '*.pc' -print0) 1646 done < <(find "${D}" -type f -name '*.pc' -print0)
1466 1647
1467 rm -f "${tf}" 1648 rm -f "${tf}"
1468 fi 1649 fi
1469 1650
1470 pkgconfig_scanned=1 1651 pkgconfig_scanned=1
1471 fi 1652 fi # pkgconfig_scanned
1472 1653
1473 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc' 1654 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1474 fi 1655 fi # removal due to .pc
1656
1657 fi # shouldnotlink==no
1475 1658
1476 if [[ ${reason} ]]; then 1659 if [[ ${reason} ]]; then
1477 einfo "Removing unnecessary ${f#${D%/}} (${reason})" 1660 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1478 queue+=( "${f}" ) 1661 queue+=( "${f}" )
1479 fi 1662 fi
1480 done < <(find "${D}" -xtype f -name '*.la' -print0) 1663 done < <(find "${ED}" -xtype f -name '*.la' -print0)
1481 1664
1482 if [[ ${queue[@]} ]]; then 1665 if [[ ${queue[@]} ]]; then
1483 rm -f "${queue[@]}" 1666 rm -f "${queue[@]}"
1484 fi 1667 fi
1485} 1668}
1486 1669
1670# @FUNCTION: einstalldocs
1671# @DESCRIPTION:
1672# Install documentation using DOCS and HTML_DOCS.
1673#
1674# If DOCS is declared and non-empty, all files listed in it are
1675# installed. The files must exist, otherwise the function will fail.
1676# In EAPI 4 and subsequent EAPIs DOCS may specify directories as well,
1677# in other EAPIs using directories is unsupported.
1678#
1679# If DOCS is not declared, the files matching patterns given
1680# in the default EAPI implementation of src_install will be installed.
1681# If this is undesired, DOCS can be set to empty value to prevent any
1682# documentation from being installed.
1683#
1684# If HTML_DOCS is declared and non-empty, all files and/or directories
1685# listed in it are installed as HTML docs (using dohtml).
1686#
1687# Both DOCS and HTML_DOCS can either be an array or a whitespace-
1688# separated list. Whenever directories are allowed, '<directory>/.' may
1689# be specified in order to install all files within the directory
1690# without creating a sub-directory in docdir.
1691#
1692# Passing additional options to dodoc and dohtml is not supported.
1693# If you needed such a thing, you need to call those helpers explicitly.
1694einstalldocs() {
1695 debug-print-function ${FUNCNAME} "${@}"
1696
1697 local dodoc_opts=-r
1698 has ${EAPI} 0 1 2 3 && dodoc_opts=
1699
1700 if ! declare -p DOCS &>/dev/null ; then
1701 local d
1702 for d in README* ChangeLog AUTHORS NEWS TODO CHANGES \
1703 THANKS BUGS FAQ CREDITS CHANGELOG ; do
1704 if [[ -s ${d} ]] ; then
1705 dodoc "${d}" || die
1706 fi
1707 done
1708 elif [[ $(declare -p DOCS) == "declare -a"* ]] ; then
1709 if [[ ${DOCS[@]} ]] ; then
1710 dodoc ${dodoc_opts} "${DOCS[@]}" || die
1711 fi
1712 else
1713 if [[ ${DOCS} ]] ; then
1714 dodoc ${dodoc_opts} ${DOCS} || die
1715 fi
1716 fi
1717
1718 if [[ $(declare -p HTML_DOCS 2>/dev/null) == "declare -a"* ]] ; then
1719 if [[ ${HTML_DOCS[@]} ]] ; then
1720 dohtml -r "${HTML_DOCS[@]}" || die
1721 fi
1722 else
1723 if [[ ${HTML_DOCS} ]] ; then
1724 dohtml -r ${HTML_DOCS} || die
1725 fi
1726 fi
1727
1728 return 0
1729}
1730
1487check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; } 1731check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; }
1488 1732
1733# @FUNCTION: optfeature
1734# @USAGE: <short description> <package atom to match> [other atoms]
1735# @DESCRIPTION:
1736# Print out a message suggesting an optional package (or packages) which
1737# provide the described functionality
1738#
1739# The following snippet would suggest app-misc/foo for optional foo support,
1740# app-misc/bar or app-misc/baz[bar] for optional bar support
1741# and either both app-misc/a and app-misc/b or app-misc/c for alphabet support.
1742# @CODE
1743# optfeature "foo support" app-misc/foo
1744# optfeature "bar support" app-misc/bar app-misc/baz[bar]
1745# optfeature "alphabet support" "app-misc/a app-misc/b" app-misc/c
1746# @CODE
1747optfeature() {
1748 debug-print-function ${FUNCNAME} "$@"
1749 local i j msg
1750 local desc=$1
1751 local flag=0
1752 shift
1753 for i; do
1754 for j in ${i}; do
1755 if has_version "${j}"; then
1756 flag=1
1757 else
1758 flag=0
1759 break
1760 fi
1761 done
1762 if [[ ${flag} -eq 1 ]]; then
1763 break
1764 fi
1765 done
1766 if [[ ${flag} -eq 0 ]]; then
1767 for i; do
1768 msg=" "
1769 for j in ${i}; do
1770 msg+=" ${j} and"
1771 done
1772 msg="${msg:0: -4} for ${desc}"
1773 elog "${msg}"
1774 done
1775 fi
1776}
1777
1489fi 1778fi

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

  ViewVC Help
Powered by ViewVC 1.1.20