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

Diff of /eclass/eutils.eclass

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

Revision 1.414 Revision 1.442
1# Copyright 1999-2013 Gentoo Foundation 1# Copyright 1999-2015 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.414 2013/03/11 00:13:16 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.442 2015/01/14 22:50:02 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
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."
962 size=${2%%x*} 1080 size=${2%%x*}
963 else 1081 else
964 size=${2} 1082 size=${2}
965 fi 1083 fi
966 case ${size} in 1084 case ${size} in
967 16|22|24|32|36|48|64|72|96|128|192|256) 1085 16|22|24|32|36|48|64|72|96|128|192|256|512)
968 size=${size}x${size};; 1086 size=${size}x${size};;
969 scalable) 1087 scalable)
970 ;; 1088 ;;
971 *) 1089 *)
972 eerror "${size} is an unsupported icon size!" 1090 eerror "${size} is an unsupported icon size!"
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 any_found 1394 local f p any_found
1273 while IFS= read -r -d '' f; do 1395 while IFS= read -r -d '' f; do
1274 patch --no-backup-if-mismatch -p0 "${f}" \ 1396 for p in "${PORTDIR}"/eclass/ELT-patches/nocxx/*.patch ; do
1275 "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null \ 1397 if patch --no-backup-if-mismatch -p1 "${f}" "${p}" >/dev/null ; then
1276 && any_found=1 1398 any_found=1
1399 break
1400 fi
1401 done
1277 done < <(find "${dir}" -name configure -print0) 1402 done < <(find "${dir}" -name configure -print0)
1278 1403
1279# if [[ -z ${any_found} ]]; then 1404 if [[ -z ${any_found} ]]; then
1280# eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt)." 1405 eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt)."
1281# fi 1406 fi
1282 eend 0 1407 eend 0
1283} 1408}
1284 1409
1285# @FUNCTION: make_wrapper 1410# @FUNCTION: make_wrapper
1286# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath] 1411# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
1288# Create a shell wrapper script named wrapper in installpath 1413# Create a shell wrapper script named wrapper in installpath
1289# (defaults to the bindir) to execute target (default of wrapper) by 1414# (defaults to the bindir) to execute target (default of wrapper) by
1290# first optionally setting LD_LIBRARY_PATH to the colon-delimited 1415# first optionally setting LD_LIBRARY_PATH to the colon-delimited
1291# libpaths followed by optionally changing directory to chdir. 1416# libpaths followed by optionally changing directory to chdir.
1292make_wrapper() { 1417make_wrapper() {
1418 _eutils_eprefix_init
1293 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5 1419 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
1294 local tmpwrapper=$(emktemp) 1420 local tmpwrapper=$(emktemp)
1295 1421
1296 ( 1422 (
1297 echo '#!/bin/sh' 1423 echo '#!/bin/sh'
1298 [[ -n ${chdir} ]] && printf 'cd "%s"\n' "${chdir}" 1424 [[ -n ${chdir} ]] && printf 'cd "%s"\n' "${EPREFIX}${chdir}"
1299 if [[ -n ${libdir} ]] ; then 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
1300 cat <<-EOF 1432 cat <<-EOF
1301 if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then 1433 if [ "\${${var}+set}" = "set" ] ; then
1302 export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}" 1434 export ${var}="\${${var}}:${EPREFIX}${libdir}"
1303 else 1435 else
1304 export LD_LIBRARY_PATH="${libdir}" 1436 export ${var}="${EPREFIX}${libdir}"
1305 fi 1437 fi
1306 EOF 1438 EOF
1307 fi 1439 fi
1308 # 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
1309 # things as ${bin} ... "./someprog --args" 1441 # things as ${bin} ... "./someprog --args"
1310 printf 'exec %s "$@"\n' "${bin}" 1442 printf 'exec %s "$@"\n' "${bin/#\//${EPREFIX}/}"
1311 ) > "${tmpwrapper}" 1443 ) > "${tmpwrapper}"
1312 chmod go+rx "${tmpwrapper}" 1444 chmod go+rx "${tmpwrapper}"
1313 1445
1314 if [[ -n ${path} ]] ; then 1446 if [[ -n ${path} ]] ; then
1315 ( 1447 (
1416# pkg-config to your DEPEND. 1548# pkg-config to your DEPEND.
1417prune_libtool_files() { 1549prune_libtool_files() {
1418 debug-print-function ${FUNCNAME} "$@" 1550 debug-print-function ${FUNCNAME} "$@"
1419 1551
1420 local removing_all removing_modules opt 1552 local removing_all removing_modules opt
1553 _eutils_eprefix_init
1421 for opt; do 1554 for opt; do
1422 case "${opt}" in 1555 case "${opt}" in
1423 --all) 1556 --all)
1424 removing_all=1 1557 removing_all=1
1425 removing_modules=1 1558 removing_modules=1
1435 local f 1568 local f
1436 local queue=() 1569 local queue=()
1437 while IFS= read -r -d '' f; do # for all .la files 1570 while IFS= read -r -d '' f; do # for all .la files
1438 local archivefile=${f/%.la/.a} 1571 local archivefile=${f/%.la/.a}
1439 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
1440 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed' 1580 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1441
1442 local reason pkgconfig_scanned 1581 local reason= pkgconfig_scanned=
1582 local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
1443 1583
1584 if [[ ${snotlink} == yes ]]; then
1585
1444 # Remove static libs we're not supposed to link against. 1586 # Remove static libs we're not supposed to link against.
1445 if grep -q '^shouldnotlink=yes$' "${f}"; then
1446 if [[ -f ${archivefile} ]]; then 1587 if [[ -f ${archivefile} ]]; then
1447 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)" 1588 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1448 queue+=( "${archivefile}" ) 1589 queue+=( "${archivefile}" )
1449 fi 1590 fi
1450 1591
1452 # unless explicitly requested. 1593 # unless explicitly requested.
1453 if [[ ${removing_modules} ]]; then 1594 if [[ ${removing_modules} ]]; then
1454 reason='module' 1595 reason='module'
1455 fi 1596 fi
1456 1597
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 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
1472 if [[ ! ${pkgconfig_scanned} ]]; then 1615 if [[ ! ${pkgconfig_scanned} ]]; then
1473 # Create a list of all .pc-covered libs. 1616 # Create a list of all .pc-covered libs.
1474 local pc_libs=() 1617 local pc_libs=()
1475 if [[ ! ${removing_all} ]]; then 1618 if [[ ! ${removing_all} ]]; then
1476 local pc 1619 local pc
1477 local tf=${T}/prune-lt-files.pc 1620 local tf=${T}/prune-lt-files.pc
1478 local pkgconf=$(tc-getPKG_CONFIG) 1621 local pkgconf=$(tc-getPKG_CONFIG)
1479 1622
1480 while IFS= read -r -d '' pc; do # for all .pc files 1623 while IFS= read -r -d '' pc; do # for all .pc files
1481 local arg libs 1624 local arg libs
1482 1625
1483 # Use pkg-config if available (and works), 1626 # Use pkg-config if available (and works),
1484 # fallback to sed. 1627 # fallback to sed.
1485 if ${pkgconf} --exists "${pc}" &>/dev/null; then 1628 if ${pkgconf} --exists "${pc}" &>/dev/null; then
1486 sed -e '/^Requires:/d' "${pc}" > "${tf}" 1629 sed -e '/^Requires:/d' "${pc}" > "${tf}"
1487 libs=$(${pkgconf} --libs "${tf}") 1630 libs=$(${pkgconf} --libs "${tf}")
1488 else 1631 else
1489 libs=$(sed -ne 's/^Libs://p' "${pc}") 1632 libs=$(sed -ne 's/^Libs://p' "${pc}")
1490 fi 1633 fi
1491 1634
1492 for arg in ${libs}; do 1635 for arg in ${libs}; do
1493 if [[ ${arg} == -l* ]]; then 1636 if [[ ${arg} == -l* ]]; then
1494 if [[ ${arg} == '*$*' ]]; then 1637 if [[ ${arg} == '*$*' ]]; then
1495 eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}" 1638 eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
1496 eqawarn "(arg: ${arg})" 1639 eqawarn "(arg: ${arg})"
1497 eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND." 1640 eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
1641 fi
1642
1643 pc_libs+=( lib${arg#-l}.la )
1498 fi 1644 fi
1499
1500 pc_libs+=( lib${arg#-l}.la )
1501 fi
1502 done 1645 done
1503 done < <(find "${D}" -type f -name '*.pc' -print0) 1646 done < <(find "${D}" -type f -name '*.pc' -print0)
1504 1647
1505 rm -f "${tf}" 1648 rm -f "${tf}"
1506 fi 1649 fi
1507 1650
1508 pkgconfig_scanned=1 1651 pkgconfig_scanned=1
1509 fi 1652 fi # pkgconfig_scanned
1510 1653
1511 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc' 1654 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1512 fi 1655 fi # removal due to .pc
1656
1657 fi # shouldnotlink==no
1513 1658
1514 if [[ ${reason} ]]; then 1659 if [[ ${reason} ]]; then
1515 einfo "Removing unnecessary ${f#${D%/}} (${reason})" 1660 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1516 queue+=( "${f}" ) 1661 queue+=( "${f}" )
1517 fi 1662 fi
1518 done < <(find "${D}" -xtype f -name '*.la' -print0) 1663 done < <(find "${ED}" -xtype f -name '*.la' -print0)
1519 1664
1520 if [[ ${queue[@]} ]]; then 1665 if [[ ${queue[@]} ]]; then
1521 rm -f "${queue[@]}" 1666 rm -f "${queue[@]}"
1522 fi 1667 fi
1523} 1668}
1524 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
1525check_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"; }
1526 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
1527fi 1778fi

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

  ViewVC Help
Powered by ViewVC 1.1.20