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

Diff of /eclass/eutils.eclass

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

Revision 1.386 Revision 1.439
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.386 2012/03/01 22:10:50 naota Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.439 2014/11/13 04:55:06 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 user 21inherit multilib toolchain-funcs
22
23DESCRIPTION="Based on the ${ECLASS} eclass"
24 22
25if has "${EAPI:-0}" 0 1 2; then 23if has "${EAPI:-0}" 0 1 2; then
26 24
27# @FUNCTION: epause 25# @FUNCTION: epause
28# @USAGE: [seconds] 26# @USAGE: [seconds]
114# echo "${i}" 112# echo "${i}"
115# done 113# done
116# @CODE 114# @CODE
117estack_push() { 115estack_push() {
118 [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments" 116 [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments"
119 local stack_name="__ESTACK_$1__" ; shift 117 local stack_name="_ESTACK_$1_" ; shift
120 eval ${stack_name}+=\( \"\$@\" \) 118 eval ${stack_name}+=\( \"\$@\" \)
121} 119}
122 120
123# @FUNCTION: estack_pop 121# @FUNCTION: estack_pop
124# @USAGE: <stack> [variable] 122# @USAGE: <stack> [variable]
127# 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
128# 1, else return 0. See estack_push for more info. 126# 1, else return 0. See estack_push for more info.
129estack_pop() { 127estack_pop() {
130 [[ $# -eq 0 || $# -gt 2 ]] && die "estack_pop: incorrect # of arguments" 128 [[ $# -eq 0 || $# -gt 2 ]] && die "estack_pop: incorrect # of arguments"
131 129
132 # 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
133 # 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
134 # 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
135 # 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
136 # 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
137 # bit harder to read. 135 # bit harder to read.
138 local __estack_name="__ESTACK_$1__" ; shift 136 local _estack_name="_ESTACK_$1_" ; shift
139 local __estack_retvar=$1 ; shift 137 local _estack_retvar=$1 ; shift
140 eval local __estack_i=\${#${__estack_name}\[@\]} 138 eval local _estack_i=\${#${_estack_name}\[@\]}
141 # Don't warn -- let the caller interpret this as a failure 139 # Don't warn -- let the caller interpret this as a failure
142 # or as normal behavior (akin to `shift`) 140 # or as normal behavior (akin to `shift`)
143 [[ $(( --__estack_i )) -eq -1 ]] && return 1 141 [[ $(( --_estack_i )) -eq -1 ]] && return 1
144 142
145 if [[ -n ${__estack_retvar} ]] ; then 143 if [[ -n ${_estack_retvar} ]] ; then
146 eval ${__estack_retvar}=\"\${${__estack_name}\[${__estack_i}\]}\" 144 eval ${_estack_retvar}=\"\${${_estack_name}\[${_estack_i}\]}\"
147 fi 145 fi
148 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
149} 218}
150 219
151# @FUNCTION: eshopts_push 220# @FUNCTION: eshopts_push
152# @USAGE: [options to `set` or `shopt`] 221# @USAGE: [options to `set` or `shopt`]
153# @DESCRIPTION: 222# @DESCRIPTION:
160# 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.
161# 230#
162# 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
163# 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:
164# @CODE 233# @CODE
165# eshopts_push -s noglob 234# eshopts_push -o noglob
166# for x in ${foo} ; do 235# for x in ${foo} ; do
167# if ...some check... ; then 236# if ...some check... ; then
168# eshopts_pop 237# eshopts_pop
169# return 0 238# return 0
170# fi 239# fi
218 local s 287 local s
219 estack_pop eumask s || die "${FUNCNAME}: unbalanced push" 288 estack_pop eumask s || die "${FUNCNAME}: unbalanced push"
220 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}" 289 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
221} 290}
222 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
223# @VARIABLE: EPATCH_SOURCE 304# @VARIABLE: EPATCH_SOURCE
224# @DESCRIPTION: 305# @DESCRIPTION:
225# Default directory to search for patches. 306# Default directory to search for patches.
226EPATCH_SOURCE="${WORKDIR}/patch" 307EPATCH_SOURCE="${WORKDIR}/patch"
227# @VARIABLE: EPATCH_SUFFIX 308# @VARIABLE: EPATCH_SUFFIX
228# @DESCRIPTION: 309# @DESCRIPTION:
229# Default extension for patches (do not prefix the period yourself). 310# Default extension for patches (do not prefix the period yourself).
230EPATCH_SUFFIX="patch.bz2" 311EPATCH_SUFFIX="patch.bz2"
231# @VARIABLE: EPATCH_OPTS 312# @VARIABLE: EPATCH_OPTS
232# @DESCRIPTION: 313# @DESCRIPTION:
233# Default options for patch: 314# Options to pass to patch. Meant for ebuild/package-specific tweaking
315# such as forcing the patch level (-p#) or fuzz (-F#) factor. Note that
316# for single patch tweaking, you can also pass flags directly to epatch.
317EPATCH_OPTS=""
318# @VARIABLE: EPATCH_COMMON_OPTS
319# @DESCRIPTION:
320# Common options to pass to `patch`. You probably should never need to
321# change these. If you do, please discuss it with base-system first to
322# be sure.
234# @CODE 323# @CODE
235# -g0 - keep RCS, ClearCase, Perforce and SCCS happy #24571 324# -g0 - keep RCS, ClearCase, Perforce and SCCS happy #24571
236# --no-backup-if-mismatch - do not leave .orig files behind 325# --no-backup-if-mismatch - do not leave .orig files behind
237# -E - automatically remove empty files 326# -E - automatically remove empty files
238# @CODE 327# @CODE
239EPATCH_OPTS="-g0 -E --no-backup-if-mismatch" 328EPATCH_COMMON_OPTS="-g0 -E --no-backup-if-mismatch"
240# @VARIABLE: EPATCH_EXCLUDE 329# @VARIABLE: EPATCH_EXCLUDE
241# @DESCRIPTION: 330# @DESCRIPTION:
242# List of patches not to apply. Note this is only file names, 331# List of patches not to apply. Note this is only file names,
243# and not the full path. Globs accepted. 332# and not the full path. Globs accepted.
244EPATCH_EXCLUDE="" 333EPATCH_EXCLUDE=""
253# @VARIABLE: EPATCH_FORCE 342# @VARIABLE: EPATCH_FORCE
254# @DESCRIPTION: 343# @DESCRIPTION:
255# Only require patches to match EPATCH_SUFFIX rather than the extended 344# Only require patches to match EPATCH_SUFFIX rather than the extended
256# arch naming style. 345# arch naming style.
257EPATCH_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.
258 352
259# @FUNCTION: epatch 353# @FUNCTION: epatch
260# @USAGE: [patches] [dirs of patches] 354# @USAGE: [options] [patches] [dirs of patches]
261# @DESCRIPTION: 355# @DESCRIPTION:
262# 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
263# 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
264# 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
265# 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
266# apply successfully. 360# apply successfully.
267# 361#
268# If you do not specify any options, then epatch will default to the directory 362# If you do not specify any patches/dirs, then epatch will default to the
269# specified by EPATCH_SOURCE. 363# directory specified by EPATCH_SOURCE.
364#
365# Any options specified that start with a dash will be passed down to patch
366# for this specific invocation. As soon as an arg w/out a dash is found, then
367# arg processing stops.
270# 368#
271# When processing directories, epatch will apply all patches that match: 369# When processing directories, epatch will apply all patches that match:
272# @CODE 370# @CODE
273# if ${EPATCH_FORCE} != "yes" 371# if ${EPATCH_FORCE} != "yes"
274# ??_${ARCH}_foo.${EPATCH_SUFFIX} 372# ??_${ARCH}_foo.${EPATCH_SUFFIX}
292 echo "${1//?/=}" 390 echo "${1//?/=}"
293 } 391 }
294 392
295 unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402 393 unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402
296 394
395 # First process options. We localize the EPATCH_OPTS setting
396 # from above so that we can pass it on in the loop below with
397 # any additional values the user has specified.
398 local EPATCH_OPTS=( ${EPATCH_OPTS[*]} )
399 while [[ $# -gt 0 ]] ; do
400 case $1 in
401 -*) EPATCH_OPTS+=( "$1" ) ;;
402 *) break ;;
403 esac
404 shift
405 done
406
297 # Let the rest of the code process one user arg at a time -- 407 # Let the rest of the code process one user arg at a time --
298 # each arg may expand into multiple patches, and each arg may 408 # each arg may expand into multiple patches, and each arg may
299 # need to start off with the default global EPATCH_xxx values 409 # need to start off with the default global EPATCH_xxx values
300 if [[ $# -gt 1 ]] ; then 410 if [[ $# -gt 1 ]] ; then
301 local m 411 local m
315 # Use the suffix from the single patch (localize it); the code 425 # Use the suffix from the single patch (localize it); the code
316 # below will find the suffix for us 426 # below will find the suffix for us
317 local EPATCH_SUFFIX=$1 427 local EPATCH_SUFFIX=$1
318 428
319 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
320 # 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).
321 set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"} 433 set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"}
434 evar_pop
322 435
323 elif [[ -f ${EPATCH_SOURCE}/$1 ]] ; then 436 elif [[ -f ${EPATCH_SOURCE}/$1 ]] ; then
324 # Re-use EPATCH_SOURCE as a search dir 437 # Re-use EPATCH_SOURCE as a search dir
325 epatch "${EPATCH_SOURCE}/$1" 438 epatch "${EPATCH_SOURCE}/$1"
326 return $? 439 return $?
334 eerror " ${EPATCH_SOURCE}" 447 eerror " ${EPATCH_SOURCE}"
335 eerror " ( ${EPATCH_SOURCE##*/} )" 448 eerror " ( ${EPATCH_SOURCE##*/} )"
336 echo 449 echo
337 die "Cannot find \$EPATCH_SOURCE!" 450 die "Cannot find \$EPATCH_SOURCE!"
338 fi 451 fi
452
453 # Now that we know we're actually going to apply something, merge
454 # all of the patch options back in to a single variable for below.
455 EPATCH_OPTS="${EPATCH_COMMON_OPTS} ${EPATCH_OPTS[*]}"
339 456
340 local PIPE_CMD 457 local PIPE_CMD
341 case ${EPATCH_SUFFIX##*\.} in 458 case ${EPATCH_SUFFIX##*\.} in
342 xz) PIPE_CMD="xz -dc" ;; 459 xz) PIPE_CMD="xz -dc" ;;
343 lzma) PIPE_CMD="lzma -dc" ;; 460 lzma) PIPE_CMD="lzma -dc" ;;
370 then 487 then
371 continue 488 continue
372 fi 489 fi
373 490
374 # Let people filter things dynamically 491 # Let people filter things dynamically
375 if [[ -n ${EPATCH_EXCLUDE} ]] ; then 492 if [[ -n ${EPATCH_EXCLUDE}${EPATCH_USER_EXCLUDE} ]] ; then
376 # let people use globs in the exclude 493 # let people use globs in the exclude
377 eshopts_push -o noglob 494 eshopts_push -o noglob
378 495
379 local ex 496 local ex
380 for ex in ${EPATCH_EXCLUDE} ; do 497 for ex in ${EPATCH_EXCLUDE} ; do
381 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 ..."
382 eshopts_pop 508 eshopts_pop
383 continue 2 509 continue 2
384 fi 510 fi
385 done 511 done
386 512
434 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}"
435 fi 561 fi
436 # Similar reason, but with relative paths. 562 # Similar reason, but with relative paths.
437 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}") 563 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}")
438 if [[ -n ${rel_paths} ]] ; then 564 if [[ -n ${rel_paths} ]] ; then
565 echo
566 eerror "Rejected Patch: ${patchname} !"
567 eerror " ( ${PATCH_TARGET} )"
568 eerror
439 eqawarn "QA Notice: Your patch uses relative paths '../'." 569 eerror "Your patch uses relative paths '../':"
440 eqawarn " In the future this will cause a failure."
441 eqawarn "${rel_paths}" 570 eerror "${rel_paths}"
571 echo
572 die "you need to fix the relative paths in patch"
442 fi 573 fi
443 574
444 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/ 575 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/
445 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 ::')
446 while [[ ${count} -lt 5 ]] ; do 580 while [[ ${count} -lt 5 ]] ; do
447 patch_cmd="${BASH_ALIASES[patch]:-patch} -p${count} ${EPATCH_OPTS}" 581 patch_cmd="${patch} -p${count} ${EPATCH_OPTS}"
448 582
449 # Generate some useful debug info ... 583 # Generate some useful debug info ...
450 ( 584 (
451 _epatch_draw_line "***** ${patchname} *****" 585 _epatch_draw_line "***** ${patchname} *****"
452 echo 586 echo
523 657
524# @FUNCTION: epatch_user 658# @FUNCTION: epatch_user
525# @USAGE: 659# @USAGE:
526# @DESCRIPTION: 660# @DESCRIPTION:
527# Applies user-provided patches to the source tree. The patches are 661# Applies user-provided patches to the source tree. The patches are
528# taken from /etc/portage/patches/<CATEGORY>/<PF|P|PN>/, where the first 662# taken from /etc/portage/patches/<CATEGORY>/<P-PR|P|PN>[:SLOT]/, where the first
529# 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
530# any more general directories which might exist as well. 664# any more general directories which might exist as well. They must end
665# in ".patch" to be applied.
531# 666#
532# User patches are intended for quick testing of patches without ebuild 667# User patches are intended for quick testing of patches without ebuild
533# modifications, as well as for permanent customizations a user might 668# modifications, as well as for permanent customizations a user might
534# desire. Obviously, there can be no official support for arbitrarily 669# desire. Obviously, there can be no official support for arbitrarily
535# patched ebuilds. So whenever a build log in a bug report mentions that 670# patched ebuilds. So whenever a build log in a bug report mentions that
554 local applied="${T}/epatch_user.log" 689 local applied="${T}/epatch_user.log"
555 [[ -e ${applied} ]] && return 2 690 [[ -e ${applied} ]] && return 2
556 691
557 # don't clobber any EPATCH vars that the parent might want 692 # don't clobber any EPATCH vars that the parent might want
558 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches 693 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
559 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}; do 694 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}{,:${SLOT}}; do
560 EPATCH_SOURCE=${base}/${CTARGET}/${check} 695 EPATCH_SOURCE=${base}/${CTARGET}/${check}
561 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check} 696 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check}
562 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check} 697 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check}
563 if [[ -d ${EPATCH_SOURCE} ]] ; then 698 if [[ -d ${EPATCH_SOURCE} ]] ; then
564 EPATCH_SOURCE=${EPATCH_SOURCE} \ 699 EPATCH_SOURCE=${EPATCH_SOURCE} \
627# Make a .desktop file. 762# Make a .desktop file.
628# 763#
629# @CODE 764# @CODE
630# binary: what command does the app run with ? 765# binary: what command does the app run with ?
631# name: the name that will show up in the menu 766# name: the name that will show up in the menu
632# icon: give your little like a pretty little icon ... 767# icon: the icon to use in the menu entry
633# this can be relative (to /usr/share/pixmaps) or 768# this can be relative (to /usr/share/pixmaps) or
634# a full path to an icon 769# a full path to an icon
635# type: what kind of application is this? 770# type: what kind of application is this?
636# for categories: 771# for categories:
637# http://standards.freedesktop.org/menu-spec/latest/apa.html 772# http://standards.freedesktop.org/menu-spec/latest/apa.html
811 insinto /usr/share/applications 946 insinto /usr/share/applications
812 doins "${desktop}" 947 doins "${desktop}"
813 ) || die "installing desktop file failed" 948 ) || die "installing desktop file failed"
814} 949}
815 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
816# @FUNCTION: validate_desktop_entries 959# @FUNCTION: validate_desktop_entries
817# @USAGE: [directories] 960# @USAGE: [directories]
818# @MAINTAINER: 961# @MAINTAINER:
819# Carsten Lohrke <carlo@gentoo.org> 962# Carsten Lohrke <carlo@gentoo.org>
820# @DESCRIPTION: 963# @DESCRIPTION:
821# Validate desktop entries using desktop-file-utils 964# Validate desktop entries using desktop-file-utils
822validate_desktop_entries() { 965validate_desktop_entries() {
966 _eutils_eprefix_init
823 if [[ -x /usr/bin/desktop-file-validate ]] ; then 967 if [[ -x "${EPREFIX}"/usr/bin/desktop-file-validate ]] ; then
824 einfo "Checking desktop entry validity" 968 einfo "Checking desktop entry validity"
825 local directories="" 969 local directories=""
826 for d in /usr/share/applications $@ ; do 970 for d in /usr/share/applications $@ ; do
827 [[ -d ${D}${d} ]] && directories="${directories} ${D}${d}" 971 [[ -d ${ED}${d} ]] && directories="${directories} ${ED}${d}"
828 done 972 done
829 if [[ -n ${directories} ]] ; then 973 if [[ -n ${directories} ]] ; then
830 for FILE in $(find ${directories} -name "*\.desktop" \ 974 for FILE in $(find ${directories} -name "*\.desktop" \
831 -not -path '*.hidden*' | sort -u 2>/dev/null) 975 -not -path '*.hidden*' | sort -u 2>/dev/null)
832 do 976 do
833 local temp=$(desktop-file-validate ${FILE} | grep -v "warning:" | \ 977 local temp=$(desktop-file-validate ${FILE} | grep -v "warning:" | \
834 sed -e "s|error: ||" -e "s|${FILE}:|--|g" ) 978 sed -e "s|error: ||" -e "s|${FILE}:|--|g" )
835 [[ -n $temp ]] && elog ${temp/--/${FILE/${D}/}:} 979 [[ -n $temp ]] && elog ${temp/--/${FILE/${ED}/}:}
836 done 980 done
837 fi 981 fi
838 echo "" 982 echo ""
839 else 983 else
840 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."
913 insinto /usr/share/applications 1057 insinto /usr/share/applications
914 newins "$@" 1058 newins "$@"
915 ) 1059 )
916} 1060}
917 1061
918# @FUNCTION: doicon 1062# @FUNCTION: _iconins
919# @USAGE: <list of icons> 1063# @INTERNAL
920# @DESCRIPTION: 1064# @DESCRIPTION:
921# Install the list of icons into the icon directory (/usr/share/pixmaps). 1065# function for use in doicon and newicon
922# This is useful in conjunction with creating desktop/menu files. 1066_iconins() {
923doicon() {
924 ( 1067 (
925 # wrap the env here so that the 'insinto' call 1068 # wrap the env here so that the 'insinto' call
926 # doesn't corrupt the env of the caller 1069 # doesn't corrupt the env of the caller
927 local i j ret 1070 local funcname=$1; shift
1071 local size dir
1072 local context=apps
1073 local theme=hicolor
1074
1075 while [[ $# -gt 0 ]] ; do
1076 case $1 in
1077 -s|--size)
1078 if [[ ${2%%x*}x${2%%x*} == "$2" ]] ; then
1079 size=${2%%x*}
1080 else
1081 size=${2}
1082 fi
1083 case ${size} in
1084 16|22|24|32|36|48|64|72|96|128|192|256)
1085 size=${size}x${size};;
1086 scalable)
1087 ;;
1088 *)
1089 eerror "${size} is an unsupported icon size!"
1090 exit 1;;
1091 esac
1092 shift 2;;
1093 -t|--theme)
1094 theme=${2}
1095 shift 2;;
1096 -c|--context)
1097 context=${2}
1098 shift 2;;
1099 *)
1100 if [[ -z ${size} ]] ; then
928 insinto /usr/share/pixmaps 1101 insinto /usr/share/pixmaps
929 for i in "$@" ; do
930 if [[ -f ${i} ]] ; then
931 doins "${i}"
932 ((ret+=$?))
933 elif [[ -d ${i} ]] ; then
934 for j in "${i}"/*.png ; do
935 doins "${j}"
936 ((ret+=$?))
937 done
938 else 1102 else
939 ((++ret)) 1103 insinto /usr/share/icons/${theme}/${size}/${context}
940 fi 1104 fi
1105
1106 if [[ ${funcname} == doicon ]] ; then
1107 if [[ -f $1 ]] ; then
1108 doins "${1}"
1109 elif [[ -d $1 ]] ; then
1110 shopt -s nullglob
1111 doins "${1}"/*.{png,svg}
1112 shopt -u nullglob
1113 else
1114 eerror "${1} is not a valid file/directory!"
1115 exit 1
1116 fi
1117 else
1118 break
1119 fi
1120 shift 1;;
1121 esac
941 done 1122 done
942 exit ${ret} 1123 if [[ ${funcname} == newicon ]] ; then
943 ) 1124 newins "$@"
1125 fi
1126 ) || die
1127}
1128
1129# @FUNCTION: doicon
1130# @USAGE: [options] <icons>
1131# @DESCRIPTION:
1132# Install icon into the icon directory /usr/share/icons or into
1133# /usr/share/pixmaps if "--size" is not set.
1134# This is useful in conjunction with creating desktop/menu files.
1135#
1136# @CODE
1137# options:
1138# -s, --size
1139# !!! must specify to install into /usr/share/icons/... !!!
1140# size of the icon, like 48 or 48x48
1141# supported icon sizes are:
1142# 16 22 24 32 36 48 64 72 96 128 192 256 scalable
1143# -c, --context
1144# defaults to "apps"
1145# -t, --theme
1146# defaults to "hicolor"
1147#
1148# icons: list of icons
1149#
1150# example 1: doicon foobar.png fuqbar.svg suckbar.png
1151# results in: insinto /usr/share/pixmaps
1152# doins foobar.png fuqbar.svg suckbar.png
1153#
1154# example 2: doicon -s 48 foobar.png fuqbar.png blobbar.png
1155# results in: insinto /usr/share/icons/hicolor/48x48/apps
1156# doins foobar.png fuqbar.png blobbar.png
1157# @CODE
1158doicon() {
1159 _iconins ${FUNCNAME} "$@"
944} 1160}
945 1161
946# @FUNCTION: newicon 1162# @FUNCTION: newicon
947# @USAGE: <icon> <newname> 1163# @USAGE: [options] <icon> <newname>
948# @DESCRIPTION: 1164# @DESCRIPTION:
949# Like all other new* functions, install the specified icon as newname. 1165# Like doicon, install the specified icon as newname.
1166#
1167# @CODE
1168# example 1: newicon foobar.png NEWNAME.png
1169# results in: insinto /usr/share/pixmaps
1170# newins foobar.png NEWNAME.png
1171#
1172# example 2: newicon -s 48 foobar.png NEWNAME.png
1173# results in: insinto /usr/share/icons/hicolor/48x48/apps
1174# newins foobar.png NEWNAME.png
1175# @CODE
950newicon() { 1176newicon() {
951 ( 1177 _iconins ${FUNCNAME} "$@"
952 # wrap the env here so that the 'insinto' call
953 # doesn't corrupt the env of the caller
954 insinto /usr/share/pixmaps
955 newins "$@"
956 )
957} 1178}
958 1179
959# @FUNCTION: strip-linguas 1180# @FUNCTION: strip-linguas
960# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>] 1181# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>]
961# @DESCRIPTION: 1182# @DESCRIPTION:
999 else 1220 else
1000 nols="${nols} ${f}" 1221 nols="${nols} ${f}"
1001 fi 1222 fi
1002 done 1223 done
1003 [[ -n ${nols} ]] \ 1224 [[ -n ${nols} ]] \
1004 && ewarn "Sorry, but ${PN} does not support the LINGUAS:" ${nols} 1225 && einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
1005 export LINGUAS=${newls:1} 1226 export LINGUAS=${newls:1}
1006} 1227}
1007 1228
1008# @FUNCTION: preserve_old_lib 1229# @FUNCTION: preserve_old_lib
1009# @USAGE: <libs to preserve> [more libs] 1230# @USAGE: <libs to preserve> [more libs]
1013# 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
1014# 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
1015# 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
1016# preserve_old_lib_notify function. 1237# preserve_old_lib_notify function.
1017preserve_old_lib() { 1238preserve_old_lib() {
1239 _eutils_eprefix_init
1018 if [[ ${EBUILD_PHASE} != "preinst" ]] ; then 1240 if [[ ${EBUILD_PHASE} != "preinst" ]] ; then
1019 eerror "preserve_old_lib() must be called from pkg_preinst() only" 1241 eerror "preserve_old_lib() must be called from pkg_preinst() only"
1020 die "Invalid preserve_old_lib() usage" 1242 die "Invalid preserve_old_lib() usage"
1021 fi 1243 fi
1022 [[ -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]"
1024 # let portage worry about it 1246 # let portage worry about it
1025 has preserve-libs ${FEATURES} && return 0 1247 has preserve-libs ${FEATURES} && return 0
1026 1248
1027 local lib dir 1249 local lib dir
1028 for lib in "$@" ; do 1250 for lib in "$@" ; do
1029 [[ -e ${ROOT}/${lib} ]] || continue 1251 [[ -e ${EROOT}/${lib} ]] || continue
1030 dir=${lib%/*} 1252 dir=${lib%/*}
1031 dodir ${dir} || die "dodir ${dir} failed" 1253 dodir ${dir} || die "dodir ${dir} failed"
1032 cp "${ROOT}"/${lib} "${D}"/${lib} || die "cp ${lib} failed" 1254 cp "${EROOT}"/${lib} "${ED}"/${lib} || die "cp ${lib} failed"
1033 touch "${D}"/${lib} 1255 touch "${ED}"/${lib}
1034 done 1256 done
1035} 1257}
1036 1258
1037# @FUNCTION: preserve_old_lib_notify 1259# @FUNCTION: preserve_old_lib_notify
1038# @USAGE: <libs to notify> [more libs] 1260# @USAGE: <libs to notify> [more libs]
1045 fi 1267 fi
1046 1268
1047 # let portage worry about it 1269 # let portage worry about it
1048 has preserve-libs ${FEATURES} && return 0 1270 has preserve-libs ${FEATURES} && return 0
1049 1271
1272 _eutils_eprefix_init
1273
1050 local lib notice=0 1274 local lib notice=0
1051 for lib in "$@" ; do 1275 for lib in "$@" ; do
1052 [[ -e ${ROOT}/${lib} ]] || continue 1276 [[ -e ${EROOT}/${lib} ]] || continue
1053 if [[ ${notice} -eq 0 ]] ; then 1277 if [[ ${notice} -eq 0 ]] ; then
1054 notice=1 1278 notice=1
1055 ewarn "Old versions of installed libraries were detected on your system." 1279 ewarn "Old versions of installed libraries were detected on your system."
1056 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,"
1057 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"
1058 ewarn "in order to remove these old dependencies. If you do not have this" 1282 ewarn "in order to remove these old dependencies. If you do not have this"
1059 ewarn "helper program, simply emerge the 'gentoolkit' package." 1283 ewarn "helper program, simply emerge the 'gentoolkit' package."
1060 ewarn 1284 ewarn
1061 fi 1285 fi
1062 # temp hack for #348634 #357225
1063 [[ ${PN} == "mpfr" ]] && lib=${lib##*/}
1064 ewarn " # revdep-rebuild --library '${lib}'" 1286 ewarn " # revdep-rebuild --library '${lib}' && rm '${lib}'"
1065 done 1287 done
1066 if [[ ${notice} -eq 1 ]] ; then
1067 ewarn
1068 ewarn "Once you've finished running revdep-rebuild, it should be safe to"
1069 ewarn "delete the old libraries. Here is a copy & paste for the lazy:"
1070 for lib in "$@" ; do
1071 ewarn " # rm '${lib}'"
1072 done
1073 fi
1074} 1288}
1075 1289
1076# @FUNCTION: built_with_use 1290# @FUNCTION: built_with_use
1077# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags> 1291# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags>
1078# @DESCRIPTION: 1292# @DESCRIPTION:
1093# in IUSE like normal USE flags. 1307# in IUSE like normal USE flags.
1094# 1308#
1095# 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
1096# flags matter. 1310# flags matter.
1097built_with_use() { 1311built_with_use() {
1312 _eutils_eprefix_init
1098 local hidden="no" 1313 local hidden="no"
1099 if [[ $1 == "--hidden" ]] ; then 1314 if [[ $1 == "--hidden" ]] ; then
1100 hidden="yes" 1315 hidden="yes"
1101 shift 1316 shift
1102 fi 1317 fi
1116 1331
1117 local PKG=$(best_version $1) 1332 local PKG=$(best_version $1)
1118 [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package" 1333 [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package"
1119 shift 1334 shift
1120 1335
1121 local USEFILE=${ROOT}/var/db/pkg/${PKG}/USE 1336 local USEFILE=${EROOT}/var/db/pkg/${PKG}/USE
1122 local IUSEFILE=${ROOT}/var/db/pkg/${PKG}/IUSE 1337 local IUSEFILE=${EROOT}/var/db/pkg/${PKG}/IUSE
1123 1338
1124 # 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
1125 # this gracefully 1340 # this gracefully
1126 if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]] ; then 1341 if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]] ; then
1127 case ${missing_action} in 1342 case ${missing_action} in
1173# http://bugs.gentoo.org/73450 1388# http://bugs.gentoo.org/73450
1174epunt_cxx() { 1389epunt_cxx() {
1175 local dir=$1 1390 local dir=$1
1176 [[ -z ${dir} ]] && dir=${S} 1391 [[ -z ${dir} ]] && dir=${S}
1177 ebegin "Removing useless C++ checks" 1392 ebegin "Removing useless C++ checks"
1178 local f 1393 local f p any_found
1179 find "${dir}" -name configure | while read f ; do 1394 while IFS= read -r -d '' f; do
1180 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
1181 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
1182 eend 0 1406 eend 0
1183} 1407}
1184 1408
1185# @FUNCTION: make_wrapper 1409# @FUNCTION: make_wrapper
1186# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath] 1410# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
1188# Create a shell wrapper script named wrapper in installpath 1412# Create a shell wrapper script named wrapper in installpath
1189# (defaults to the bindir) to execute target (default of wrapper) by 1413# (defaults to the bindir) to execute target (default of wrapper) by
1190# first optionally setting LD_LIBRARY_PATH to the colon-delimited 1414# first optionally setting LD_LIBRARY_PATH to the colon-delimited
1191# libpaths followed by optionally changing directory to chdir. 1415# libpaths followed by optionally changing directory to chdir.
1192make_wrapper() { 1416make_wrapper() {
1417 _eutils_eprefix_init
1193 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5 1418 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
1194 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
1195 # 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
1196 # things as $bin ... "./someprog --args" 1440 # things as ${bin} ... "./someprog --args"
1441 printf 'exec %s "$@"\n' "${bin/#\//${EPREFIX}/}"
1197 cat << EOF > "${tmpwrapper}" 1442 ) > "${tmpwrapper}"
1198#!/bin/sh
1199cd "${chdir:-.}"
1200if [ -n "${libdir}" ] ; then
1201 if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
1202 export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
1203 else
1204 export LD_LIBRARY_PATH="${libdir}"
1205 fi
1206fi
1207exec ${bin} "\$@"
1208EOF
1209 chmod go+rx "${tmpwrapper}" 1443 chmod go+rx "${tmpwrapper}"
1444
1210 if [[ -n ${path} ]] ; then 1445 if [[ -n ${path} ]] ; then
1211 ( 1446 (
1212 exeinto "${path}" 1447 exeinto "${path}"
1213 newexe "${tmpwrapper}" "${wrapper}" 1448 newexe "${tmpwrapper}" "${wrapper}"
1214 ) || die 1449 ) || die
1275} 1510}
1276 1511
1277# @FUNCTION: usex 1512# @FUNCTION: usex
1278# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix] 1513# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix]
1279# @DESCRIPTION: 1514# @DESCRIPTION:
1515# Proxy to declare usex for package managers or EAPIs that do not provide it
1516# and use the package manager implementation when available (i.e. EAPI >= 5).
1280# If USE flag is set, echo [true output][true suffix] (defaults to "yes"), 1517# If USE flag is set, echo [true output][true suffix] (defaults to "yes"),
1281# otherwise echo [false output][false suffix] (defaults to "no"). 1518# otherwise echo [false output][false suffix] (defaults to "no").
1519if has "${EAPI:-0}" 0 1 2 3 4; then
1282usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963 1520 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
1521fi
1522
1523# @FUNCTION: prune_libtool_files
1524# @USAGE: [--all|--modules]
1525# @DESCRIPTION:
1526# Locate unnecessary libtool files (.la) and libtool static archives
1527# (.a) and remove them from installation image.
1528#
1529# By default, .la files are removed whenever the static linkage can
1530# either be performed using pkg-config or doesn't introduce additional
1531# flags.
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#
1537# If '--all' argument is passed, all .la files are removed without
1538# performing any heuristic on them. You shouldn't ever use that,
1539# and instead report a bug in the algorithm instead.
1540#
1541# The .a files are only removed whenever corresponding .la files state
1542# that they should not be linked to, i.e. whenever these files
1543# correspond to plugins.
1544#
1545# Note: if your package installs both static libraries and .pc files
1546# which use variable substitution for -l flags, you need to add
1547# pkg-config to your DEPEND.
1548prune_libtool_files() {
1549 debug-print-function ${FUNCNAME} "$@"
1550
1551 local removing_all removing_modules opt
1552 _eutils_eprefix_init
1553 for opt; do
1554 case "${opt}" in
1555 --all)
1556 removing_all=1
1557 removing_modules=1
1558 ;;
1559 --modules)
1560 removing_modules=1
1561 ;;
1562 *)
1563 die "Invalid argument to ${FUNCNAME}(): ${opt}"
1564 esac
1565 done
1566
1567 local f
1568 local queue=()
1569 while IFS= read -r -d '' f; do # for all .la files
1570 local archivefile=${f/%.la/.a}
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
1579 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1580 local reason pkgconfig_scanned
1581 local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
1582
1583 if [[ ${snotlink} == yes ]]; then
1584
1585 # Remove static libs we're not supposed to link against.
1586 if [[ -f ${archivefile} ]]; then
1587 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1588 queue+=( "${archivefile}" )
1589 fi
1590
1591 # The .la file may be used by a module loader, so avoid removing it
1592 # unless explicitly requested.
1593 if [[ ${removing_modules} ]]; then
1594 reason='module'
1595 fi
1596
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
1614 if [[ ! ${pkgconfig_scanned} ]]; then
1615 # Create a list of all .pc-covered libs.
1616 local pc_libs=()
1617 if [[ ! ${removing_all} ]]; then
1618 local pc
1619 local tf=${T}/prune-lt-files.pc
1620 local pkgconf=$(tc-getPKG_CONFIG)
1621
1622 while IFS= read -r -d '' pc; do # for all .pc files
1623 local arg libs
1624
1625 # Use pkg-config if available (and works),
1626 # fallback to sed.
1627 if ${pkgconf} --exists "${pc}" &>/dev/null; then
1628 sed -e '/^Requires:/d' "${pc}" > "${tf}"
1629 libs=$(${pkgconf} --libs "${tf}")
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
1644 done
1645 done < <(find "${D}" -type f -name '*.pc' -print0)
1646
1647 rm -f "${tf}"
1648 fi
1649
1650 pkgconfig_scanned=1
1651 fi # pkgconfig_scanned
1652
1653 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1654 fi # removal due to .pc
1655
1656 fi # shouldnotlink==no
1657
1658 if [[ ${reason} ]]; then
1659 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1660 queue+=( "${f}" )
1661 fi
1662 done < <(find "${ED}" -xtype f -name '*.la' -print0)
1663
1664 if [[ ${queue[@]} ]]; then
1665 rm -f "${queue[@]}"
1666 fi
1667}
1668
1669# @FUNCTION: einstalldocs
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}
1283 1729
1284check_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"; }
1285 1731
1732# @FUNCTION: optfeature
1733# @USAGE: <short description> <package atom to match> [other atoms]
1734# @DESCRIPTION:
1735# Print out a message suggesting an optional package (or packages) which
1736# provide the described functionality
1737#
1738# The following snippet would suggest app-misc/foo for optional foo support,
1739# app-misc/bar or app-misc/baz[bar] for optional bar support
1740# and either both app-misc/a and app-misc/b or app-misc/c for alphabet support.
1741# @CODE
1742# optfeature "foo support" app-misc/foo
1743# optfeature "bar support" app-misc/bar app-misc/baz[bar]
1744# optfeature "alphabet support" "app-misc/a app-misc/b" app-misc/c
1745# @CODE
1746optfeature() {
1747 debug-print-function ${FUNCNAME} "$@"
1748 local i j msg
1749 local desc=$1
1750 local flag=0
1751 shift
1752 for i; do
1753 for j in ${i}; do
1754 if has_version "${j}"; then
1755 flag=1
1756 else
1757 flag=0
1758 break
1759 fi
1760 done
1761 if [[ ${flag} -eq 1 ]]; then
1762 break
1763 fi
1764 done
1765 if [[ ${flag} -eq 0 ]]; then
1766 for i; do
1767 msg=" "
1768 for j in ${i}; do
1769 msg+=" ${j} and"
1770 done
1771 msg="${msg:0: -4} for ${desc}"
1772 elog "${msg}"
1773 done
1774 fi
1775}
1776
1286fi 1777fi

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

  ViewVC Help
Powered by ViewVC 1.1.20