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

Diff of /eclass/eutils.eclass

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

Revision 1.372 Revision 1.407
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2012 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.372 2011/12/14 17:36:18 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.407 2012/10/11 16:50:53 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
16# different from the overall eclass! 16# different from the overall eclass!
17 17
18if [[ ${___ECLASS_ONCE_EUTILS} != "recur -_+^+_- spank" ]] ; then 18if [[ ${___ECLASS_ONCE_EUTILS} != "recur -_+^+_- spank" ]] ; then
19___ECLASS_ONCE_EUTILS="recur -_+^+_- spank" 19___ECLASS_ONCE_EUTILS="recur -_+^+_- spank"
20 20
21inherit multilib portability user 21inherit multilib toolchain-funcs user
22
23DESCRIPTION="Based on the ${ECLASS} eclass"
24 22
25if has "${EAPI:-0}" 0 1 2; then 23if has "${EAPI:-0}" 0 1 2; then
26 24
27# @FUNCTION: epause 25# @FUNCTION: epause
28# @USAGE: [seconds] 26# @USAGE: [seconds]
98esvn_clean() { 96esvn_clean() {
99 [[ -z $* ]] && set -- . 97 [[ -z $* ]] && set -- .
100 find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf 98 find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf
101} 99}
102 100
101# @FUNCTION: estack_push
102# @USAGE: <stack> [items to push]
103# @DESCRIPTION:
104# Push any number of items onto the specified stack. Pick a name that
105# is a valid variable (i.e. stick to alphanumerics), and push as many
106# items as you like onto the stack at once.
107#
108# The following code snippet will echo 5, then 4, then 3, then ...
109# @CODE
110# estack_push mystack 1 2 3 4 5
111# while estack_pop mystack i ; do
112# echo "${i}"
113# done
114# @CODE
115estack_push() {
116 [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments"
117 local stack_name="__ESTACK_$1__" ; shift
118 eval ${stack_name}+=\( \"\$@\" \)
119}
120
121# @FUNCTION: estack_pop
122# @USAGE: <stack> [variable]
123# @DESCRIPTION:
124# Pop a single item off the specified stack. If a variable is specified,
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.
127estack_pop() {
128 [[ $# -eq 0 || $# -gt 2 ]] && die "estack_pop: incorrect # of arguments"
129
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
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
134 # garbage is preferable to using $1/$2 everywhere as that is a
135 # bit harder to read.
136 local __estack_name="__ESTACK_$1__" ; shift
137 local __estack_retvar=$1 ; shift
138 eval local __estack_i=\${#${__estack_name}\[@\]}
139 # Don't warn -- let the caller interpret this as a failure
140 # or as normal behavior (akin to `shift`)
141 [[ $(( --__estack_i )) -eq -1 ]] && return 1
142
143 if [[ -n ${__estack_retvar} ]] ; then
144 eval ${__estack_retvar}=\"\${${__estack_name}\[${__estack_i}\]}\"
145 fi
146 eval unset ${__estack_name}\[${__estack_i}\]
147}
148
103# @FUNCTION: eshopts_push 149# @FUNCTION: eshopts_push
104# @USAGE: [options to `set` or `shopt`] 150# @USAGE: [options to `set` or `shopt`]
105# @DESCRIPTION: 151# @DESCRIPTION:
106# Often times code will want to enable a shell option to change code behavior. 152# Often times code will want to enable a shell option to change code behavior.
107# Since changing shell options can easily break other pieces of code (which 153# Since changing shell options can easily break other pieces of code (which
112# rather than `set` as there are some options only available via that. 158# rather than `set` as there are some options only available via that.
113# 159#
114# A common example is to disable shell globbing so that special meaning/care 160# A common example is to disable shell globbing so that special meaning/care
115# may be used with variables/arguments to custom functions. That would be: 161# may be used with variables/arguments to custom functions. That would be:
116# @CODE 162# @CODE
117# eshopts_push -o noglob 163# eshopts_push -s noglob
118# for x in ${foo} ; do 164# for x in ${foo} ; do
119# if ...some check... ; then 165# if ...some check... ; then
120# eshopts_pop 166# eshopts_pop
121# return 0 167# return 0
122# fi 168# fi
123# done 169# done
124# eshopts_pop 170# eshopts_pop
125# @CODE 171# @CODE
126eshopts_push() { 172eshopts_push() {
127 # have to assume __ESHOPTS_SAVE__ isn't screwed with
128 # as a `declare -a` here will reset its value
129 local i=${#__ESHOPTS_SAVE__[@]}
130 if [[ $1 == -[su] ]] ; then 173 if [[ $1 == -[su] ]] ; then
131 __ESHOPTS_SAVE__[$i]=$(shopt -p) 174 estack_push eshopts "$(shopt -p)"
132 [[ $# -eq 0 ]] && return 0 175 [[ $# -eq 0 ]] && return 0
133 shopt "$@" || die "eshopts_push: bad options to shopt: $*" 176 shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*"
134 else 177 else
135 __ESHOPTS_SAVE__[$i]=$- 178 estack_push eshopts $-
136 [[ $# -eq 0 ]] && return 0 179 [[ $# -eq 0 ]] && return 0
137 set "$@" || die "eshopts_push: bad options to set: $*" 180 set "$@" || die "${FUNCNAME}: bad options to set: $*"
138 fi 181 fi
139} 182}
140 183
141# @FUNCTION: eshopts_pop 184# @FUNCTION: eshopts_pop
142# @USAGE: 185# @USAGE:
143# @DESCRIPTION: 186# @DESCRIPTION:
144# Restore the shell options to the state saved with the corresponding 187# Restore the shell options to the state saved with the corresponding
145# eshopts_push call. See that function for more details. 188# eshopts_push call. See that function for more details.
146eshopts_pop() { 189eshopts_pop() {
147 [[ $# -ne 0 ]] && die "eshopts_pop takes no arguments" 190 local s
148 local i=$(( ${#__ESHOPTS_SAVE__[@]} - 1 )) 191 estack_pop eshopts s || die "${FUNCNAME}: unbalanced push"
149 [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair"
150 local s=${__ESHOPTS_SAVE__[$i]}
151 unset __ESHOPTS_SAVE__[$i]
152 if [[ ${s} == "shopt -"* ]] ; then 192 if [[ ${s} == "shopt -"* ]] ; then
153 eval "${s}" || die "eshopts_pop: sanity: invalid shopt options: ${s}" 193 eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}"
154 else 194 else
155 set +$- || die "eshopts_pop: sanity: invalid shell settings: $-" 195 set +$- || die "${FUNCNAME}: sanity: invalid shell settings: $-"
156 set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}" 196 set -${s} || die "${FUNCNAME}: sanity: unable to restore saved shell settings: ${s}"
157 fi 197 fi
198}
199
200# @FUNCTION: eumask_push
201# @USAGE: <new umask>
202# @DESCRIPTION:
203# Set the umask to the new value specified while saving the previous
204# value onto a stack. Useful for temporarily changing the umask.
205eumask_push() {
206 estack_push eumask "$(umask)"
207 umask "$@" || die "${FUNCNAME}: bad options to umask: $*"
208}
209
210# @FUNCTION: eumask_pop
211# @USAGE:
212# @DESCRIPTION:
213# Restore the previous umask state.
214eumask_pop() {
215 [[ $# -eq 0 ]] || die "${FUNCNAME}: we take no options"
216 local s
217 estack_pop eumask s || die "${FUNCNAME}: unbalanced push"
218 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
158} 219}
159 220
160# @VARIABLE: EPATCH_SOURCE 221# @VARIABLE: EPATCH_SOURCE
161# @DESCRIPTION: 222# @DESCRIPTION:
162# Default directory to search for patches. 223# Default directory to search for patches.
165# @DESCRIPTION: 226# @DESCRIPTION:
166# Default extension for patches (do not prefix the period yourself). 227# Default extension for patches (do not prefix the period yourself).
167EPATCH_SUFFIX="patch.bz2" 228EPATCH_SUFFIX="patch.bz2"
168# @VARIABLE: EPATCH_OPTS 229# @VARIABLE: EPATCH_OPTS
169# @DESCRIPTION: 230# @DESCRIPTION:
170# Default options for patch: 231# Options to pass to patch. Meant for ebuild/package-specific tweaking
232# such as forcing the patch level (-p#) or fuzz (-F#) factor. Note that
233# for single patch tweaking, you can also pass flags directly to epatch.
234EPATCH_OPTS=""
235# @VARIABLE: EPATCH_COMMON_OPTS
236# @DESCRIPTION:
237# Common options to pass to `patch`. You probably should never need to
238# change these. If you do, please discuss it with base-system first to
239# be sure.
171# @CODE 240# @CODE
172# -g0 - keep RCS, ClearCase, Perforce and SCCS happy #24571 241# -g0 - keep RCS, ClearCase, Perforce and SCCS happy #24571
173# --no-backup-if-mismatch - do not leave .orig files behind 242# --no-backup-if-mismatch - do not leave .orig files behind
174# -E - automatically remove empty files 243# -E - automatically remove empty files
175# @CODE 244# @CODE
176EPATCH_OPTS="-g0 -E --no-backup-if-mismatch" 245EPATCH_COMMON_OPTS="-g0 -E --no-backup-if-mismatch"
177# @VARIABLE: EPATCH_EXCLUDE 246# @VARIABLE: EPATCH_EXCLUDE
178# @DESCRIPTION: 247# @DESCRIPTION:
179# List of patches not to apply. Note this is only file names, 248# List of patches not to apply. Note this is only file names,
180# and not the full path. Globs accepted. 249# and not the full path. Globs accepted.
181EPATCH_EXCLUDE="" 250EPATCH_EXCLUDE=""
192# Only require patches to match EPATCH_SUFFIX rather than the extended 261# Only require patches to match EPATCH_SUFFIX rather than the extended
193# arch naming style. 262# arch naming style.
194EPATCH_FORCE="no" 263EPATCH_FORCE="no"
195 264
196# @FUNCTION: epatch 265# @FUNCTION: epatch
197# @USAGE: [patches] [dirs of patches] 266# @USAGE: [options] [patches] [dirs of patches]
198# @DESCRIPTION: 267# @DESCRIPTION:
199# epatch is designed to greatly simplify the application of patches. It can 268# epatch is designed to greatly simplify the application of patches. It can
200# process patch files directly, or directories of patches. The patches may be 269# process patch files directly, or directories of patches. The patches may be
201# compressed (bzip/gzip/etc...) or plain text. You generally need not specify 270# compressed (bzip/gzip/etc...) or plain text. You generally need not specify
202# the -p option as epatch will automatically attempt -p0 to -p5 until things 271# the -p option as epatch will automatically attempt -p0 to -p5 until things
203# apply successfully. 272# apply successfully.
204# 273#
205# If you do not specify any options, then epatch will default to the directory 274# If you do not specify any patches/dirs, then epatch will default to the
206# specified by EPATCH_SOURCE. 275# directory specified by EPATCH_SOURCE.
276#
277# Any options specified that start with a dash will be passed down to patch
278# for this specific invocation. As soon as an arg w/out a dash is found, then
279# arg processing stops.
207# 280#
208# When processing directories, epatch will apply all patches that match: 281# When processing directories, epatch will apply all patches that match:
209# @CODE 282# @CODE
210# if ${EPATCH_FORCE} != "yes" 283# if ${EPATCH_FORCE} != "yes"
211# ??_${ARCH}_foo.${EPATCH_SUFFIX} 284# ??_${ARCH}_foo.${EPATCH_SUFFIX}
229 echo "${1//?/=}" 302 echo "${1//?/=}"
230 } 303 }
231 304
232 unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402 305 unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402
233 306
307 # First process options. We localize the EPATCH_OPTS setting
308 # from above so that we can pass it on in the loop below with
309 # any additional values the user has specified.
310 local EPATCH_OPTS=( ${EPATCH_OPTS[*]} )
311 while [[ $# -gt 0 ]] ; do
312 case $1 in
313 -*) EPATCH_OPTS+=( "$1" ) ;;
314 *) break ;;
315 esac
316 shift
317 done
318
234 # Let the rest of the code process one user arg at a time -- 319 # Let the rest of the code process one user arg at a time --
235 # each arg may expand into multiple patches, and each arg may 320 # each arg may expand into multiple patches, and each arg may
236 # need to start off with the default global EPATCH_xxx values 321 # need to start off with the default global EPATCH_xxx values
237 if [[ $# -gt 1 ]] ; then 322 if [[ $# -gt 1 ]] ; then
238 local m 323 local m
271 eerror " ${EPATCH_SOURCE}" 356 eerror " ${EPATCH_SOURCE}"
272 eerror " ( ${EPATCH_SOURCE##*/} )" 357 eerror " ( ${EPATCH_SOURCE##*/} )"
273 echo 358 echo
274 die "Cannot find \$EPATCH_SOURCE!" 359 die "Cannot find \$EPATCH_SOURCE!"
275 fi 360 fi
361
362 # Now that we know we're actually going to apply something, merge
363 # all of the patch options back in to a single variable for below.
364 EPATCH_OPTS="${EPATCH_COMMON_OPTS} ${EPATCH_OPTS[*]}"
276 365
277 local PIPE_CMD 366 local PIPE_CMD
278 case ${EPATCH_SUFFIX##*\.} in 367 case ${EPATCH_SUFFIX##*\.} in
279 xz) PIPE_CMD="xz -dc" ;; 368 xz) PIPE_CMD="xz -dc" ;;
280 lzma) PIPE_CMD="lzma -dc" ;; 369 lzma) PIPE_CMD="lzma -dc" ;;
377 eqawarn " In the future this will cause a failure." 466 eqawarn " In the future this will cause a failure."
378 eqawarn "${rel_paths}" 467 eqawarn "${rel_paths}"
379 fi 468 fi
380 469
381 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/ 470 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/
471 local patch_cmd
382 while [[ ${count} -lt 5 ]] ; do 472 while [[ ${count} -lt 5 ]] ; do
473 patch_cmd="${BASH_ALIASES[patch]:-patch} -p${count} ${EPATCH_OPTS}"
474
383 # Generate some useful debug info ... 475 # Generate some useful debug info ...
384 ( 476 (
385 _epatch_draw_line "***** ${patchname} *****" 477 _epatch_draw_line "***** ${patchname} *****"
386 echo 478 echo
387 echo "PATCH COMMAND: patch -p${count} ${EPATCH_OPTS} < '${PATCH_TARGET}'" 479 echo "PATCH COMMAND: ${patch_cmd} < '${PATCH_TARGET}'"
388 echo 480 echo
389 _epatch_draw_line "***** ${patchname} *****" 481 _epatch_draw_line "***** ${patchname} *****"
390 patch -p${count} ${EPATCH_OPTS} --dry-run -f < "${PATCH_TARGET}" 2>&1 482 ${patch_cmd} --dry-run -f < "${PATCH_TARGET}" 2>&1
391 ret=$? 483 ret=$?
392 echo 484 echo
393 echo "patch program exited with status ${ret}" 485 echo "patch program exited with status ${ret}"
394 exit ${ret} 486 exit ${ret}
395 ) >> "${STDERR_TARGET}" 487 ) >> "${STDERR_TARGET}"
399 _epatch_draw_line "***** ${patchname} *****" 491 _epatch_draw_line "***** ${patchname} *****"
400 echo 492 echo
401 echo "ACTUALLY APPLYING ${patchname} ..." 493 echo "ACTUALLY APPLYING ${patchname} ..."
402 echo 494 echo
403 _epatch_draw_line "***** ${patchname} *****" 495 _epatch_draw_line "***** ${patchname} *****"
404 patch -p${count} ${EPATCH_OPTS} < "${PATCH_TARGET}" 2>&1 496 ${patch_cmd} < "${PATCH_TARGET}" 2>&1
405 ret=$? 497 ret=$?
406 echo 498 echo
407 echo "patch program exited with status ${ret}" 499 echo "patch program exited with status ${ret}"
408 exit ${ret} 500 exit ${ret}
409 ) >> "${STDERR_TARGET}" 501 ) >> "${STDERR_TARGET}"
436 eerror " ${STDERR_TARGET}" 528 eerror " ${STDERR_TARGET}"
437 echo 529 echo
438 die "Failed Patch: ${patchname}!" 530 die "Failed Patch: ${patchname}!"
439 fi 531 fi
440 532
441 # if everything worked, delete the patch log 533 # if everything worked, delete the full debug patch log
442 rm -f "${STDERR_TARGET}" 534 rm -f "${STDERR_TARGET}"
535
536 # then log away the exact stuff for people to review later
537 cat <<-EOF >> "${T}/epatch.log"
538 PATCH: ${x}
539 CMD: ${patch_cmd}
540 PWD: ${PWD}
541
542 EOF
443 eend 0 543 eend 0
444 done 544 done
445 545
446 [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching" 546 [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching"
447 : # everything worked 547 : # everything worked
449 549
450# @FUNCTION: epatch_user 550# @FUNCTION: epatch_user
451# @USAGE: 551# @USAGE:
452# @DESCRIPTION: 552# @DESCRIPTION:
453# Applies user-provided patches to the source tree. The patches are 553# Applies user-provided patches to the source tree. The patches are
454# taken from /etc/portage/patches/<CATEGORY>/<PF|P|PN>/, where the first 554# taken from /etc/portage/patches/<CATEGORY>/<PF|P|PN>[:SLOT]/, where the first
455# of these three directories to exist will be the one to use, ignoring 555# of these three directories to exist will be the one to use, ignoring
456# any more general directories which might exist as well. 556# any more general directories which might exist as well. They must end
557# in ".patch" to be applied.
457# 558#
458# User patches are intended for quick testing of patches without ebuild 559# User patches are intended for quick testing of patches without ebuild
459# modifications, as well as for permanent customizations a user might 560# modifications, as well as for permanent customizations a user might
460# desire. Obviously, there can be no official support for arbitrarily 561# desire. Obviously, there can be no official support for arbitrarily
461# patched ebuilds. So whenever a build log in a bug report mentions that 562# patched ebuilds. So whenever a build log in a bug report mentions that
475# autotool input files as well. 576# autotool input files as well.
476epatch_user() { 577epatch_user() {
477 [[ $# -ne 0 ]] && die "epatch_user takes no options" 578 [[ $# -ne 0 ]] && die "epatch_user takes no options"
478 579
479 # Allow multiple calls to this function; ignore all but the first 580 # Allow multiple calls to this function; ignore all but the first
480 local applied="${T}/epatch_user.applied" 581 local applied="${T}/epatch_user.log"
481 [[ -e ${applied} ]] && return 2 582 [[ -e ${applied} ]] && return 2
482 583
483 # don't clobber any EPATCH vars that the parent might want 584 # don't clobber any EPATCH vars that the parent might want
484 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches 585 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
485 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do 586 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}{,:${SLOT}}; do
486 EPATCH_SOURCE=${base}/${CTARGET}/${check} 587 EPATCH_SOURCE=${base}/${CTARGET}/${check}
487 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check} 588 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check}
488 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check} 589 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check}
489 if [[ -d ${EPATCH_SOURCE} ]] ; then 590 if [[ -d ${EPATCH_SOURCE} ]] ; then
490 EPATCH_SOURCE=${EPATCH_SOURCE} \ 591 EPATCH_SOURCE=${EPATCH_SOURCE} \
545edos2unix() { 646edos2unix() {
546 [[ $# -eq 0 ]] && return 0 647 [[ $# -eq 0 ]] && return 0
547 sed -i 's/\r$//' -- "$@" || die 648 sed -i 's/\r$//' -- "$@" || die
548} 649}
549 650
550# Make a desktop file ! 651# @FUNCTION: make_desktop_entry
551# Great for making those icons in kde/gnome startmenu !
552# Amaze your friends ! Get the women ! Join today !
553#
554# make_desktop_entry(<command>, [name], [icon], [type], [fields]) 652# @USAGE: make_desktop_entry(<command>, [name], [icon], [type], [fields])
653# @DESCRIPTION:
654# Make a .desktop file.
555# 655#
656# @CODE
556# binary: what command does the app run with ? 657# binary: what command does the app run with ?
557# name: the name that will show up in the menu 658# name: the name that will show up in the menu
558# icon: give your little like a pretty little icon ... 659# icon: the icon to use in the menu entry
559# this can be relative (to /usr/share/pixmaps) or 660# this can be relative (to /usr/share/pixmaps) or
560# a full path to an icon 661# a full path to an icon
561# type: what kind of application is this ? for categories: 662# type: what kind of application is this?
663# for categories:
562# http://standards.freedesktop.org/menu-spec/latest/apa.html 664# http://standards.freedesktop.org/menu-spec/latest/apa.html
665# if unset, function tries to guess from package's category
563# fields: extra fields to append to the desktop file; a printf string 666# fields: extra fields to append to the desktop file; a printf string
667# @CODE
564make_desktop_entry() { 668make_desktop_entry() {
565 [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable" 669 [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable"
566 670
567 local exec=${1} 671 local exec=${1}
568 local name=${2:-${PN}} 672 local name=${2:-${PN}}
574 local catmaj=${CATEGORY%%-*} 678 local catmaj=${CATEGORY%%-*}
575 local catmin=${CATEGORY##*-} 679 local catmin=${CATEGORY##*-}
576 case ${catmaj} in 680 case ${catmaj} in
577 app) 681 app)
578 case ${catmin} in 682 case ${catmin} in
579 accessibility) type=Accessibility;; 683 accessibility) type="Utility;Accessibility";;
580 admin) type=System;; 684 admin) type=System;;
581 antivirus) type=System;; 685 antivirus) type=System;;
582 arch) type=Archiving;; 686 arch) type="Utility;Archiving";;
583 backup) type=Archiving;; 687 backup) type="Utility;Archiving";;
584 cdr) type=DiscBurning;; 688 cdr) type="AudioVideo;DiscBurning";;
585 dicts) type=Dictionary;; 689 dicts) type="Office;Dictionary";;
586 doc) type=Documentation;; 690 doc) type=Documentation;;
587 editors) type=TextEditor;; 691 editors) type="Utility;TextEditor";;
588 emacs) type=TextEditor;; 692 emacs) type="Development;TextEditor";;
589 emulation) type=Emulator;; 693 emulation) type="System;Emulator";;
590 laptop) type=HardwareSettings;; 694 laptop) type="Settings;HardwareSettings";;
591 office) type=Office;; 695 office) type=Office;;
592 pda) type=PDA;; 696 pda) type="Office;PDA";;
593 vim) type=TextEditor;; 697 vim) type="Development;TextEditor";;
594 xemacs) type=TextEditor;; 698 xemacs) type="Development;TextEditor";;
595 esac 699 esac
596 ;; 700 ;;
597 701
598 dev) 702 dev)
599 type="Development" 703 type="Development"
836 insinto /usr/share/applications 940 insinto /usr/share/applications
837 newins "$@" 941 newins "$@"
838 ) 942 )
839} 943}
840 944
841# @FUNCTION: doicon 945# @FUNCTION: _iconins
842# @USAGE: <list of icons> 946# @INTERNAL
843# @DESCRIPTION: 947# @DESCRIPTION:
844# Install the list of icons into the icon directory (/usr/share/pixmaps). 948# function for use in doicon and newicon
845# This is useful in conjunction with creating desktop/menu files. 949_iconins() {
846doicon() {
847 ( 950 (
848 # wrap the env here so that the 'insinto' call 951 # wrap the env here so that the 'insinto' call
849 # doesn't corrupt the env of the caller 952 # doesn't corrupt the env of the caller
850 local i j ret 953 local funcname=$1; shift
851 insinto /usr/share/pixmaps 954 local size dir
852 for i in "$@" ; do 955 local context=apps
853 if [[ -f ${i} ]] ; then 956 local theme=hicolor
854 doins "${i}" 957
855 ((ret+=$?)) 958 while [[ $# -gt 0 ]] ; do
856 elif [[ -d ${i} ]] ; then 959 case $1 in
857 for j in "${i}"/*.png ; do 960 -s|--size)
858 doins "${j}" 961 if [[ ${2%%x*}x${2%%x*} == "$2" ]] ; then
859 ((ret+=$?)) 962 size=${2%%x*}
860 done
861 else 963 else
862 ((++ret)) 964 size=${2}
863 fi 965 fi
864 done
865 exit ${ret}
866 )
867}
868
869# @FUNCTION: newicon
870# @USAGE: <icon> <newname>
871# @DESCRIPTION:
872# Like all other new* functions, install the specified icon as newname.
873newicon() {
874 (
875 # wrap the env here so that the 'insinto' call
876 # doesn't corrupt the env of the caller
877 insinto /usr/share/pixmaps
878 newins "$@"
879 )
880}
881
882# for internal use only (unpack_pdv and unpack_makeself)
883find_unpackable_file() {
884 local src=$1
885 if [[ -z ${src} ]] ; then
886 src=${DISTDIR}/${A}
887 else
888 if [[ -e ${DISTDIR}/${src} ]] ; then
889 src=${DISTDIR}/${src}
890 elif [[ -e ${PWD}/${src} ]] ; then
891 src=${PWD}/${src}
892 elif [[ -e ${src} ]] ; then
893 src=${src}
894 fi
895 fi
896 [[ ! -e ${src} ]] && return 1
897 echo "${src}"
898}
899
900# @FUNCTION: unpack_pdv
901# @USAGE: <file to unpack> <size of off_t>
902# @DESCRIPTION:
903# Unpack those pesky pdv generated files ...
904# They're self-unpacking programs with the binary package stuffed in
905# the middle of the archive. Valve seems to use it a lot ... too bad
906# it seems to like to segfault a lot :(. So lets take it apart ourselves.
907#
908# You have to specify the off_t size ... I have no idea how to extract that
909# information out of the binary executable myself. Basically you pass in
910# the size of the off_t type (in bytes) on the machine that built the pdv
911# archive.
912#
913# One way to determine this is by running the following commands:
914#
915# @CODE
916# strings <pdv archive> | grep lseek
917# strace -elseek <pdv archive>
918# @CODE
919#
920# Basically look for the first lseek command (we do the strings/grep because
921# sometimes the function call is _llseek or something) and steal the 2nd
922# parameter. Here is an example:
923#
924# @CODE
925# vapier@vapier 0 pdv_unpack # strings hldsupdatetool.bin | grep lseek
926# lseek
927# vapier@vapier 0 pdv_unpack # strace -elseek ./hldsupdatetool.bin
928# lseek(3, -4, SEEK_END) = 2981250
929# @CODE
930#
931# Thus we would pass in the value of '4' as the second parameter.
932unpack_pdv() {
933 local src=$(find_unpackable_file "$1")
934 local sizeoff_t=$2
935
936 [[ -z ${src} ]] && die "Could not locate source for '$1'"
937 [[ -z ${sizeoff_t} ]] && die "No idea what off_t size was used for this pdv :("
938
939 local shrtsrc=$(basename "${src}")
940 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
941 local metaskip=$(tail -c ${sizeoff_t} "${src}" | hexdump -e \"%i\")
942 local tailskip=$(tail -c $((${sizeoff_t}*2)) "${src}" | head -c ${sizeoff_t} | hexdump -e \"%i\")
943
944 # grab metadata for debug reasons
945 local metafile=$(emktemp)
946 tail -c +$((${metaskip}+1)) "${src}" > "${metafile}"
947
948 # rip out the final file name from the metadata
949 local datafile=$(tail -c +$((${metaskip}+1)) "${src}" | strings | head -n 1)
950 datafile=$(basename "${datafile}")
951
952 # now lets uncompress/untar the file if need be
953 local tmpfile=$(emktemp)
954 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null | head -c 512 > ${tmpfile}
955
956 local iscompressed=$(file -b "${tmpfile}")
957 if [[ ${iscompressed:0:8} == "compress" ]] ; then
958 iscompressed=1
959 mv ${tmpfile}{,.Z}
960 gunzip ${tmpfile}
961 else
962 iscompressed=0
963 fi
964 local istar=$(file -b "${tmpfile}")
965 if [[ ${istar:0:9} == "POSIX tar" ]] ; then
966 istar=1
967 else
968 istar=0
969 fi
970
971 #for some reason gzip dies with this ... dd cant provide buffer fast enough ?
972 #dd if=${src} ibs=${metaskip} count=1 \
973 # | dd ibs=${tailskip} skip=1 \
974 # | gzip -dc \
975 # > ${datafile}
976 if [ ${iscompressed} -eq 1 ] ; then
977 if [ ${istar} -eq 1 ] ; then
978 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
979 | head -c $((${metaskip}-${tailskip})) \
980 | tar -xzf -
981 else
982 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
983 | head -c $((${metaskip}-${tailskip})) \
984 | gzip -dc \
985 > ${datafile}
986 fi
987 else
988 if [ ${istar} -eq 1 ] ; then
989 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
990 | head -c $((${metaskip}-${tailskip})) \
991 | tar --no-same-owner -xf -
992 else
993 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
994 | head -c $((${metaskip}-${tailskip})) \
995 > ${datafile}
996 fi
997 fi
998 true
999 #[ -s "${datafile}" ] || die "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')"
1000 #assert "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')"
1001}
1002
1003# @FUNCTION: unpack_makeself
1004# @USAGE: [file to unpack] [offset] [tail|dd]
1005# @DESCRIPTION:
1006# Unpack those pesky makeself generated files ...
1007# They're shell scripts with the binary package tagged onto
1008# the end of the archive. Loki utilized the format as does
1009# many other game companies.
1010#
1011# If the file is not specified, then ${A} is used. If the
1012# offset is not specified then we will attempt to extract
1013# the proper offset from the script itself.
1014unpack_makeself() {
1015 local src_input=${1:-${A}}
1016 local src=$(find_unpackable_file "${src_input}")
1017 local skip=$2
1018 local exe=$3
1019
1020 [[ -z ${src} ]] && die "Could not locate source for '${src_input}'"
1021
1022 local shrtsrc=$(basename "${src}")
1023 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
1024 if [[ -z ${skip} ]] ; then
1025 local ver=$(grep -m1 -a '#.*Makeself' "${src}" | awk '{print $NF}')
1026 local skip=0
1027 exe=tail
1028 case ${ver} in 966 case ${size} in
1029 1.5.*|1.6.0-nv) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same 967 16|22|24|32|36|48|64|72|96|128|192|256)
1030 skip=$(grep -a ^skip= "${src}" | cut -d= -f2) 968 size=${size}x${size};;
1031 ;; 969 scalable)
1032 2.0|2.0.1)
1033 skip=$(grep -a ^$'\t'tail "${src}" | awk '{print $2}' | cut -b2-)
1034 ;;
1035 2.1.1)
1036 skip=$(grep -a ^offset= "${src}" | awk '{print $2}' | cut -b2-)
1037 (( skip++ ))
1038 ;;
1039 2.1.2)
1040 skip=$(grep -a ^offset= "${src}" | awk '{print $3}' | head -n 1)
1041 (( skip++ ))
1042 ;;
1043 2.1.3)
1044 skip=`grep -a ^offset= "${src}" | awk '{print $3}'`
1045 (( skip++ ))
1046 ;;
1047 2.1.4|2.1.5)
1048 skip=$(grep -a offset=.*head.*wc "${src}" | awk '{print $3}' | head -n 1)
1049 skip=$(head -n ${skip} "${src}" | wc -c)
1050 exe="dd"
1051 ;; 970 ;;
1052 *) 971 *)
1053 eerror "I'm sorry, but I was unable to support the Makeself file." 972 eerror "${size} is an unsupported icon size!"
1054 eerror "The version I detected was '${ver}'." 973 exit 1;;
1055 eerror "Please file a bug about the file ${shrtsrc} at"
1056 eerror "http://bugs.gentoo.org/ so that support can be added."
1057 die "makeself version '${ver}' not supported"
1058 ;;
1059 esac 974 esac
1060 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset" 975 shift 2;;
1061 fi 976 -t|--theme)
1062 case ${exe} in 977 theme=${2}
1063 tail) exe="tail -n +${skip} '${src}'";; 978 shift 2;;
1064 dd) exe="dd ibs=${skip} skip=1 if='${src}'";; 979 -c|--context)
1065 *) die "makeself cant handle exe '${exe}'" 980 context=${2}
1066 esac 981 shift 2;;
1067
1068 # lets grab the first few bytes of the file to figure out what kind of archive it is
1069 local filetype tmpfile=$(emktemp)
1070 eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}"
1071 filetype=$(file -b "${tmpfile}") || die
1072 case ${filetype} in
1073 *tar\ archive*)
1074 eval ${exe} | tar --no-same-owner -xf -
1075 ;;
1076 bzip2*)
1077 eval ${exe} | bzip2 -dc | tar --no-same-owner -xf -
1078 ;;
1079 gzip*)
1080 eval ${exe} | tar --no-same-owner -xzf -
1081 ;;
1082 compress*)
1083 eval ${exe} | gunzip | tar --no-same-owner -xf -
1084 ;;
1085 *) 982 *)
1086 eerror "Unknown filetype \"${filetype}\" ?"
1087 false
1088 ;;
1089 esac
1090 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
1091}
1092
1093# @FUNCTION: cdrom_get_cds
1094# @USAGE: <file on cd1> [file on cd2] [file on cd3] [...]
1095# @DESCRIPTION:
1096# Aquire cd(s) for those lovely cd-based emerges. Yes, this violates
1097# the whole 'non-interactive' policy, but damnit I want CD support !
1098#
1099# With these cdrom functions we handle all the user interaction and
1100# standardize everything. All you have to do is call cdrom_get_cds()
1101# and when the function returns, you can assume that the cd has been
1102# found at CDROM_ROOT.
1103#
1104# The function will attempt to locate a cd based upon a file that is on
1105# the cd. The more files you give this function, the more cds
1106# the cdrom functions will handle.
1107#
1108# Normally the cdrom functions will refer to the cds as 'cd #1', 'cd #2',
1109# etc... If you want to give the cds better names, then just export
1110# the appropriate CDROM_NAME variable before calling cdrom_get_cds().
1111# Use CDROM_NAME for one cd, or CDROM_NAME_# for multiple cds. You can
1112# also use the CDROM_NAME_SET bash array.
1113#
1114# For those multi cd ebuilds, see the cdrom_load_next_cd() function.
1115cdrom_get_cds() {
1116 # first we figure out how many cds we're dealing with by
1117 # the # of files they gave us
1118 local cdcnt=0
1119 local f=
1120 for f in "$@" ; do
1121 ((++cdcnt))
1122 export CDROM_CHECK_${cdcnt}="$f"
1123 done
1124 export CDROM_TOTAL_CDS=${cdcnt}
1125 export CDROM_CURRENT_CD=1
1126
1127 # now we see if the user gave use CD_ROOT ...
1128 # if they did, let's just believe them that it's correct
1129 if [[ -n ${CD_ROOT}${CD_ROOT_1} ]] ; then
1130 local var=
1131 cdcnt=0
1132 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
1133 ((++cdcnt))
1134 var="CD_ROOT_${cdcnt}"
1135 [[ -z ${!var} ]] && var="CD_ROOT"
1136 if [[ -z ${!var} ]] ; then 983 if [[ -z ${size} ]] ; then
1137 eerror "You must either use just the CD_ROOT" 984 insinto /usr/share/pixmaps
1138 eerror "or specify ALL the CD_ROOT_X variables." 985 else
1139 eerror "In this case, you will need ${CDROM_TOTAL_CDS} CD_ROOT_X variables." 986 insinto /usr/share/icons/${theme}/${size}/${context}
1140 die "could not locate CD_ROOT_${cdcnt}"
1141 fi 987 fi
1142 done
1143 export CDROM_ROOT=${CD_ROOT_1:-${CD_ROOT}}
1144 einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
1145 export CDROM_SET=-1
1146 for f in ${CDROM_CHECK_1//:/ } ; do
1147 ((++CDROM_SET))
1148 [[ -e ${CDROM_ROOT}/${f} ]] && break
1149 done
1150 export CDROM_MATCH=${f}
1151 return
1152 fi
1153 988
1154 # User didn't help us out so lets make sure they know they can 989 if [[ ${funcname} == doicon ]] ; then
1155 # simplify the whole process ...
1156 if [[ ${CDROM_TOTAL_CDS} -eq 1 ]] ; then
1157 einfo "This ebuild will need the ${CDROM_NAME:-cdrom for ${PN}}"
1158 echo
1159 einfo "If you do not have the CD, but have the data files"
1160 einfo "mounted somewhere on your filesystem, just export"
1161 einfo "the variable CD_ROOT so that it points to the"
1162 einfo "directory containing the files."
1163 echo
1164 einfo "For example:"
1165 einfo "export CD_ROOT=/mnt/cdrom"
1166 echo
1167 else
1168 if [[ -n ${CDROM_NAME_SET} ]] ; then
1169 # Translate the CDROM_NAME_SET array into CDROM_NAME_#
1170 cdcnt=0
1171 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
1172 ((++cdcnt))
1173 export CDROM_NAME_${cdcnt}="${CDROM_NAME_SET[$((${cdcnt}-1))]}"
1174 done
1175 fi
1176
1177 einfo "This package will need access to ${CDROM_TOTAL_CDS} cds."
1178 cdcnt=0
1179 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
1180 ((++cdcnt))
1181 var="CDROM_NAME_${cdcnt}"
1182 [[ ! -z ${!var} ]] && einfo " CD ${cdcnt}: ${!var}"
1183 done
1184 echo
1185 einfo "If you do not have the CDs, but have the data files"
1186 einfo "mounted somewhere on your filesystem, just export"
1187 einfo "the following variables so they point to the right place:"
1188 einfon ""
1189 cdcnt=0
1190 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
1191 ((++cdcnt))
1192 echo -n " CD_ROOT_${cdcnt}"
1193 done
1194 echo
1195 einfo "Or, if you have all the files in the same place, or"
1196 einfo "you only have one cdrom, you can export CD_ROOT"
1197 einfo "and that place will be used as the same data source"
1198 einfo "for all the CDs."
1199 echo
1200 einfo "For example:"
1201 einfo "export CD_ROOT_1=/mnt/cdrom"
1202 echo
1203 fi
1204
1205 export CDROM_SET=""
1206 export CDROM_CURRENT_CD=0
1207 cdrom_load_next_cd
1208}
1209
1210# @FUNCTION: cdrom_load_next_cd
1211# @DESCRIPTION:
1212# Some packages are so big they come on multiple CDs. When you're done reading
1213# files off a CD and want access to the next one, just call this function.
1214# Again, all the messy details of user interaction are taken care of for you.
1215# Once this returns, just read the variable CDROM_ROOT for the location of the
1216# mounted CD. Note that you can only go forward in the CD list, so make sure
1217# you only call this function when you're done using the current CD.
1218cdrom_load_next_cd() {
1219 local var
1220 ((++CDROM_CURRENT_CD))
1221
1222 unset CDROM_ROOT
1223 var=CD_ROOT_${CDROM_CURRENT_CD}
1224 [[ -z ${!var} ]] && var="CD_ROOT"
1225 if [[ -z ${!var} ]] ; then 990 if [[ -f $1 ]] ; then
1226 var="CDROM_CHECK_${CDROM_CURRENT_CD}" 991 doins "${1}"
1227 _cdrom_locate_file_on_cd ${!var} 992 elif [[ -d $1 ]] ; then
1228 else 993 shopt -s nullglob
1229 export CDROM_ROOT=${!var} 994 doins "${1}"/*.{png,svg}
1230 fi 995 shopt -u nullglob
1231
1232 einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
1233}
1234
1235# this is used internally by the cdrom_get_cds() and cdrom_load_next_cd()
1236# functions. this should *never* be called from an ebuild.
1237# all it does is try to locate a give file on a cd ... if the cd isn't
1238# found, then a message asking for the user to insert the cdrom will be
1239# displayed and we'll hang out here until:
1240# (1) the file is found on a mounted cdrom
1241# (2) the user hits CTRL+C
1242_cdrom_locate_file_on_cd() {
1243 local mline=""
1244 local showedmsg=0 showjolietmsg=0
1245
1246 while [[ -z ${CDROM_ROOT} ]] ; do
1247 local i=0
1248 local -a cdset=(${*//:/ })
1249 if [[ -n ${CDROM_SET} ]] ; then
1250 cdset=(${cdset[${CDROM_SET}]})
1251 fi
1252
1253 while [[ -n ${cdset[${i}]} ]] ; do
1254 local dir=$(dirname ${cdset[${i}]})
1255 local file=$(basename ${cdset[${i}]})
1256
1257 local point= node= fs= foo=
1258 while read point node fs foo ; do
1259 [[ " cd9660 iso9660 udf " != *" ${fs} "* ]] && \
1260 ! [[ ${fs} == "subfs" && ",${opts}," == *",fs=cdfss,"* ]] \
1261 && continue
1262 point=${point//\040/ }
1263 [[ ! -d ${point}/${dir} ]] && continue
1264 [[ -z $(find "${point}/${dir}" -maxdepth 1 -iname "${file}") ]] && continue
1265 export CDROM_ROOT=${point}
1266 export CDROM_SET=${i}
1267 export CDROM_MATCH=${cdset[${i}]}
1268 return
1269 done <<< "$(get_mounts)"
1270
1271 ((++i))
1272 done
1273
1274 echo
1275 if [[ ${showedmsg} -eq 0 ]] ; then
1276 if [[ ${CDROM_TOTAL_CDS} -eq 1 ]] ; then
1277 if [[ -z ${CDROM_NAME} ]] ; then
1278 einfo "Please insert+mount the cdrom for ${PN} now !"
1279 else 996 else
1280 einfo "Please insert+mount the ${CDROM_NAME} cdrom now !" 997 eerror "${1} is not a valid file/directory!"
998 exit 1
1281 fi 999 fi
1282 else 1000 else
1283 if [[ -z ${CDROM_NAME_1} ]] ; then 1001 break
1284 einfo "Please insert+mount cd #${CDROM_CURRENT_CD} for ${PN} now !"
1285 else
1286 local var="CDROM_NAME_${CDROM_CURRENT_CD}"
1287 einfo "Please insert+mount the ${!var} cdrom now !"
1288 fi
1289 fi 1002 fi
1290 showedmsg=1 1003 shift 1;;
1291 fi 1004 esac
1292 einfo "Press return to scan for the cd again"
1293 einfo "or hit CTRL+C to abort the emerge."
1294 echo
1295 if [[ ${showjolietmsg} -eq 0 ]] ; then
1296 showjolietmsg=1
1297 else
1298 ewarn "If you are having trouble with the detection"
1299 ewarn "of your CD, it is possible that you do not have"
1300 ewarn "Joliet support enabled in your kernel. Please"
1301 ewarn "check that CONFIG_JOLIET is enabled in your kernel."
1302 ebeep 5
1303 fi
1304 read || die "something is screwed with your system"
1305 done 1005 done
1006 if [[ ${funcname} == newicon ]] ; then
1007 newins "$@"
1008 fi
1009 ) || die
1010}
1011
1012# @FUNCTION: doicon
1013# @USAGE: [options] <icons>
1014# @DESCRIPTION:
1015# Install icon into the icon directory /usr/share/icons or into
1016# /usr/share/pixmaps if "--size" is not set.
1017# This is useful in conjunction with creating desktop/menu files.
1018#
1019# @CODE
1020# options:
1021# -s, --size
1022# !!! must specify to install into /usr/share/icons/... !!!
1023# size of the icon, like 48 or 48x48
1024# supported icon sizes are:
1025# 16 22 24 32 36 48 64 72 96 128 192 256 scalable
1026# -c, --context
1027# defaults to "apps"
1028# -t, --theme
1029# defaults to "hicolor"
1030#
1031# icons: list of icons
1032#
1033# example 1: doicon foobar.png fuqbar.svg suckbar.png
1034# results in: insinto /usr/share/pixmaps
1035# doins foobar.png fuqbar.svg suckbar.png
1036#
1037# example 2: doicon -s 48 foobar.png fuqbar.png blobbar.png
1038# results in: insinto /usr/share/icons/hicolor/48x48/apps
1039# doins foobar.png fuqbar.png blobbar.png
1040# @CODE
1041doicon() {
1042 _iconins ${FUNCNAME} "$@"
1043}
1044
1045# @FUNCTION: newicon
1046# @USAGE: [options] <icon> <newname>
1047# @DESCRIPTION:
1048# Like doicon, install the specified icon as newname.
1049#
1050# @CODE
1051# example 1: newicon foobar.png NEWNAME.png
1052# results in: insinto /usr/share/pixmaps
1053# newins foobar.png NEWNAME.png
1054#
1055# example 2: newicon -s 48 foobar.png NEWNAME.png
1056# results in: insinto /usr/share/icons/hicolor/48x48/apps
1057# newins foobar.png NEWNAME.png
1058# @CODE
1059newicon() {
1060 _iconins ${FUNCNAME} "$@"
1306} 1061}
1307 1062
1308# @FUNCTION: strip-linguas 1063# @FUNCTION: strip-linguas
1309# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>] 1064# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>]
1310# @DESCRIPTION: 1065# @DESCRIPTION:
1348 else 1103 else
1349 nols="${nols} ${f}" 1104 nols="${nols} ${f}"
1350 fi 1105 fi
1351 done 1106 done
1352 [[ -n ${nols} ]] \ 1107 [[ -n ${nols} ]] \
1353 && ewarn "Sorry, but ${PN} does not support the LINGUAS:" ${nols} 1108 && einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
1354 export LINGUAS=${newls:1} 1109 export LINGUAS=${newls:1}
1355} 1110}
1356 1111
1357# @FUNCTION: preserve_old_lib 1112# @FUNCTION: preserve_old_lib
1358# @USAGE: <libs to preserve> [more libs] 1113# @USAGE: <libs to preserve> [more libs]
1406 ewarn "the libraries are not being removed. You need to run revdep-rebuild" 1161 ewarn "the libraries are not being removed. You need to run revdep-rebuild"
1407 ewarn "in order to remove these old dependencies. If you do not have this" 1162 ewarn "in order to remove these old dependencies. If you do not have this"
1408 ewarn "helper program, simply emerge the 'gentoolkit' package." 1163 ewarn "helper program, simply emerge the 'gentoolkit' package."
1409 ewarn 1164 ewarn
1410 fi 1165 fi
1411 # temp hack for #348634 #357225
1412 [[ ${PN} == "mpfr" ]] && lib=${lib##*/}
1413 ewarn " # revdep-rebuild --library '${lib}'" 1166 ewarn " # revdep-rebuild --library '${lib}' && rm '${lib}'"
1414 done 1167 done
1415 if [[ ${notice} -eq 1 ]] ; then
1416 ewarn
1417 ewarn "Once you've finished running revdep-rebuild, it should be safe to"
1418 ewarn "delete the old libraries. Here is a copy & paste for the lazy:"
1419 for lib in "$@" ; do
1420 ewarn " # rm '${lib}'"
1421 done
1422 fi
1423} 1168}
1424 1169
1425# @FUNCTION: built_with_use 1170# @FUNCTION: built_with_use
1426# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags> 1171# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags>
1427# @DESCRIPTION: 1172# @DESCRIPTION:
1624} 1369}
1625 1370
1626# @FUNCTION: usex 1371# @FUNCTION: usex
1627# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix] 1372# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix]
1628# @DESCRIPTION: 1373# @DESCRIPTION:
1374# Proxy to declare usex for package managers or EAPIs that do not provide it
1375# and use the package manager implementation when available (i.e. EAPI >= 5).
1629# If USE flag is set, echo [true output][true suffix] (defaults to "yes"), 1376# If USE flag is set, echo [true output][true suffix] (defaults to "yes"),
1630# otherwise echo [false output][false suffix] (defaults to "no"). 1377# otherwise echo [false output][false suffix] (defaults to "no").
1378if has "${EAPI:-0}" 0 1 2 3 4; then
1631usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963 1379 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
1380fi
1381
1382# @FUNCTION: prune_libtool_files
1383# @USAGE: [--all]
1384# @DESCRIPTION:
1385# Locate unnecessary libtool files (.la) and libtool static archives
1386# (.a) and remove them from installation image.
1387#
1388# By default, .la files are removed whenever the static linkage can
1389# either be performed using pkg-config or doesn't introduce additional
1390# flags.
1391#
1392# If '--all' argument is passed, all .la files are removed. This is
1393# usually useful when the package installs plugins and does not use .la
1394# files for loading them.
1395#
1396# The .a files are only removed whenever corresponding .la files state
1397# that they should not be linked to, i.e. whenever these files
1398# correspond to plugins.
1399#
1400# Note: if your package installs both static libraries and .pc files,
1401# you need to add pkg-config to your DEPEND.
1402prune_libtool_files() {
1403 debug-print-function ${FUNCNAME} "$@"
1404
1405 local removing_all opt
1406 for opt; do
1407 case "${opt}" in
1408 --all)
1409 removing_all=1
1410 ;;
1411 *)
1412 die "Invalid argument to ${FUNCNAME}(): ${opt}"
1413 esac
1414 done
1415
1416 local f
1417 local queue=()
1418 while IFS= read -r -d '' f; do # for all .la files
1419 local archivefile=${f/%.la/.a}
1420
1421 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1422
1423 # Remove static libs we're not supposed to link against.
1424 if grep -q '^shouldnotlink=yes$' "${f}"; then
1425 if [[ -f ${archivefile} ]]; then
1426 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1427 queue+=( "${archivefile}" )
1428 fi
1429
1430 # The .la file may be used by a module loader, so avoid removing it
1431 # unless explicitly requested.
1432 [[ ${removing_all} ]] || continue
1433 fi
1434
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
1450 if [[ ! ${pkgconfig_scanned} ]]; then
1451 # Create a list of all .pc-covered libs.
1452 local pc_libs=()
1453 if [[ ! ${removing_all} ]]; then
1454 local f
1455 local tf=${T}/prune-lt-files.pc
1456 local pkgconf=$(tc-getPKG_CONFIG)
1457
1458 while IFS= read -r -d '' f; do # for all .pc files
1459 local arg
1460
1461 sed -e '/^Requires:/d' "${f}" > "${tf}"
1462 for arg in $("${pkgconf}" --libs "${tf}"); do
1463 [[ ${arg} == -l* ]] && pc_libs+=( lib${arg#-l}.la )
1464 done
1465 done < <(find "${D}" -type f -name '*.pc' -print0)
1466
1467 rm -f "${tf}"
1468 fi
1469
1470 pkgconfig_scanned=1
1471 fi
1472
1473 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1474 fi
1475
1476 if [[ ${reason} ]]; then
1477 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1478 queue+=( "${f}" )
1479 fi
1480 done < <(find "${D}" -xtype f -name '*.la' -print0)
1481
1482 if [[ ${queue[@]} ]]; then
1483 rm -f "${queue[@]}"
1484 fi
1485}
1632 1486
1633check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; } 1487check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; }
1634 1488
1635fi 1489fi

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

  ViewVC Help
Powered by ViewVC 1.1.20