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

Diff of /eclass/eutils.eclass

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

Revision 1.375 Revision 1.414
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2013 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.375 2011/12/17 04:55:41 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.414 2013/03/11 00:13:16 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
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]
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}\]
149} 147}
150 148
151# @FUNCTION: eshopts_push 149# @FUNCTION: eshopts_push
152# @USAGE: [options to `set` or `shopt`] 150# @USAGE: [options to `set` or `shopt`]
153# @DESCRIPTION: 151# @DESCRIPTION:
160# 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.
161# 159#
162# 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
163# 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:
164# @CODE 162# @CODE
165# eshopts_push -o noglob 163# eshopts_push -s noglob
166# for x in ${foo} ; do 164# for x in ${foo} ; do
167# if ...some check... ; then 165# if ...some check... ; then
168# eshopts_pop 166# eshopts_pop
169# return 0 167# return 0
170# fi 168# fi
171# done 169# done
172# eshopts_pop 170# eshopts_pop
173# @CODE 171# @CODE
174eshopts_push() { 172eshopts_push() {
175 # have to assume __ESHOPTS_SAVE__ isn't screwed with
176 # as a `declare -a` here will reset its value
177 local i=${#__ESHOPTS_SAVE__[@]}
178 if [[ $1 == -[su] ]] ; then 173 if [[ $1 == -[su] ]] ; then
179 __ESHOPTS_SAVE__[$i]=$(shopt -p) 174 estack_push eshopts "$(shopt -p)"
180 [[ $# -eq 0 ]] && return 0 175 [[ $# -eq 0 ]] && return 0
181 shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*" 176 shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*"
182 else 177 else
183 __ESHOPTS_SAVE__[$i]=$- 178 estack_push eshopts $-
184 [[ $# -eq 0 ]] && return 0 179 [[ $# -eq 0 ]] && return 0
185 set "$@" || die "${FUNCNAME}: bad options to set: $*" 180 set "$@" || die "${FUNCNAME}: bad options to set: $*"
186 fi 181 fi
187} 182}
188 183
190# @USAGE: 185# @USAGE:
191# @DESCRIPTION: 186# @DESCRIPTION:
192# Restore the shell options to the state saved with the corresponding 187# Restore the shell options to the state saved with the corresponding
193# eshopts_push call. See that function for more details. 188# eshopts_push call. See that function for more details.
194eshopts_pop() { 189eshopts_pop() {
195 [[ $# -ne 0 ]] && die "${FUNCNAME} takes no arguments" 190 local s
196 local i=$(( ${#__ESHOPTS_SAVE__[@]} - 1 )) 191 estack_pop eshopts s || die "${FUNCNAME}: unbalanced push"
197 [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair"
198 local s=${__ESHOPTS_SAVE__[$i]}
199 unset __ESHOPTS_SAVE__[$i]
200 if [[ ${s} == "shopt -"* ]] ; then 192 if [[ ${s} == "shopt -"* ]] ; then
201 eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}" 193 eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}"
202 else 194 else
203 set +$- || die "${FUNCNAME}: sanity: invalid shell settings: $-" 195 set +$- || die "${FUNCNAME}: sanity: invalid shell settings: $-"
204 set -${s} || die "${FUNCNAME}: sanity: unable to restore saved shell settings: ${s}" 196 set -${s} || die "${FUNCNAME}: sanity: unable to restore saved shell settings: ${s}"
218# @FUNCTION: eumask_pop 210# @FUNCTION: eumask_pop
219# @USAGE: 211# @USAGE:
220# @DESCRIPTION: 212# @DESCRIPTION:
221# Restore the previous umask state. 213# Restore the previous umask state.
222eumask_pop() { 214eumask_pop() {
215 [[ $# -eq 0 ]] || die "${FUNCNAME}: we take no options"
223 local s 216 local s
224 estack_pop eumask s || die "${FUNCNAME}: unbalanced push" 217 estack_pop eumask s || die "${FUNCNAME}: unbalanced push"
225 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}" 218 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
226} 219}
227 220
233# @DESCRIPTION: 226# @DESCRIPTION:
234# Default extension for patches (do not prefix the period yourself). 227# Default extension for patches (do not prefix the period yourself).
235EPATCH_SUFFIX="patch.bz2" 228EPATCH_SUFFIX="patch.bz2"
236# @VARIABLE: EPATCH_OPTS 229# @VARIABLE: EPATCH_OPTS
237# @DESCRIPTION: 230# @DESCRIPTION:
238# 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.
239# @CODE 240# @CODE
240# -g0 - keep RCS, ClearCase, Perforce and SCCS happy #24571 241# -g0 - keep RCS, ClearCase, Perforce and SCCS happy #24571
241# --no-backup-if-mismatch - do not leave .orig files behind 242# --no-backup-if-mismatch - do not leave .orig files behind
242# -E - automatically remove empty files 243# -E - automatically remove empty files
243# @CODE 244# @CODE
244EPATCH_OPTS="-g0 -E --no-backup-if-mismatch" 245EPATCH_COMMON_OPTS="-g0 -E --no-backup-if-mismatch"
245# @VARIABLE: EPATCH_EXCLUDE 246# @VARIABLE: EPATCH_EXCLUDE
246# @DESCRIPTION: 247# @DESCRIPTION:
247# 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,
248# and not the full path. Globs accepted. 249# and not the full path. Globs accepted.
249EPATCH_EXCLUDE="" 250EPATCH_EXCLUDE=""
260# Only require patches to match EPATCH_SUFFIX rather than the extended 261# Only require patches to match EPATCH_SUFFIX rather than the extended
261# arch naming style. 262# arch naming style.
262EPATCH_FORCE="no" 263EPATCH_FORCE="no"
263 264
264# @FUNCTION: epatch 265# @FUNCTION: epatch
265# @USAGE: [patches] [dirs of patches] 266# @USAGE: [options] [patches] [dirs of patches]
266# @DESCRIPTION: 267# @DESCRIPTION:
267# 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
268# 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
269# 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
270# 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
271# apply successfully. 272# apply successfully.
272# 273#
273# 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
274# 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.
275# 280#
276# When processing directories, epatch will apply all patches that match: 281# When processing directories, epatch will apply all patches that match:
277# @CODE 282# @CODE
278# if ${EPATCH_FORCE} != "yes" 283# if ${EPATCH_FORCE} != "yes"
279# ??_${ARCH}_foo.${EPATCH_SUFFIX} 284# ??_${ARCH}_foo.${EPATCH_SUFFIX}
297 echo "${1//?/=}" 302 echo "${1//?/=}"
298 } 303 }
299 304
300 unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402 305 unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402
301 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
302 # 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 --
303 # each arg may expand into multiple patches, and each arg may 320 # each arg may expand into multiple patches, and each arg may
304 # need to start off with the default global EPATCH_xxx values 321 # need to start off with the default global EPATCH_xxx values
305 if [[ $# -gt 1 ]] ; then 322 if [[ $# -gt 1 ]] ; then
306 local m 323 local m
339 eerror " ${EPATCH_SOURCE}" 356 eerror " ${EPATCH_SOURCE}"
340 eerror " ( ${EPATCH_SOURCE##*/} )" 357 eerror " ( ${EPATCH_SOURCE##*/} )"
341 echo 358 echo
342 die "Cannot find \$EPATCH_SOURCE!" 359 die "Cannot find \$EPATCH_SOURCE!"
343 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[*]}"
344 365
345 local PIPE_CMD 366 local PIPE_CMD
346 case ${EPATCH_SUFFIX##*\.} in 367 case ${EPATCH_SUFFIX##*\.} in
347 xz) PIPE_CMD="xz -dc" ;; 368 xz) PIPE_CMD="xz -dc" ;;
348 lzma) PIPE_CMD="lzma -dc" ;; 369 lzma) PIPE_CMD="lzma -dc" ;;
445 eqawarn " In the future this will cause a failure." 466 eqawarn " In the future this will cause a failure."
446 eqawarn "${rel_paths}" 467 eqawarn "${rel_paths}"
447 fi 468 fi
448 469
449 # 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
450 while [[ ${count} -lt 5 ]] ; do 472 while [[ ${count} -lt 5 ]] ; do
473 patch_cmd="${BASH_ALIASES[patch]:-patch} -p${count} ${EPATCH_OPTS}"
474
451 # Generate some useful debug info ... 475 # Generate some useful debug info ...
452 ( 476 (
453 _epatch_draw_line "***** ${patchname} *****" 477 _epatch_draw_line "***** ${patchname} *****"
454 echo 478 echo
455 echo "PATCH COMMAND: patch -p${count} ${EPATCH_OPTS} < '${PATCH_TARGET}'" 479 echo "PATCH COMMAND: ${patch_cmd} < '${PATCH_TARGET}'"
456 echo 480 echo
457 _epatch_draw_line "***** ${patchname} *****" 481 _epatch_draw_line "***** ${patchname} *****"
458 patch -p${count} ${EPATCH_OPTS} --dry-run -f < "${PATCH_TARGET}" 2>&1 482 ${patch_cmd} --dry-run -f < "${PATCH_TARGET}" 2>&1
459 ret=$? 483 ret=$?
460 echo 484 echo
461 echo "patch program exited with status ${ret}" 485 echo "patch program exited with status ${ret}"
462 exit ${ret} 486 exit ${ret}
463 ) >> "${STDERR_TARGET}" 487 ) >> "${STDERR_TARGET}"
467 _epatch_draw_line "***** ${patchname} *****" 491 _epatch_draw_line "***** ${patchname} *****"
468 echo 492 echo
469 echo "ACTUALLY APPLYING ${patchname} ..." 493 echo "ACTUALLY APPLYING ${patchname} ..."
470 echo 494 echo
471 _epatch_draw_line "***** ${patchname} *****" 495 _epatch_draw_line "***** ${patchname} *****"
472 patch -p${count} ${EPATCH_OPTS} < "${PATCH_TARGET}" 2>&1 496 ${patch_cmd} < "${PATCH_TARGET}" 2>&1
473 ret=$? 497 ret=$?
474 echo 498 echo
475 echo "patch program exited with status ${ret}" 499 echo "patch program exited with status ${ret}"
476 exit ${ret} 500 exit ${ret}
477 ) >> "${STDERR_TARGET}" 501 ) >> "${STDERR_TARGET}"
504 eerror " ${STDERR_TARGET}" 528 eerror " ${STDERR_TARGET}"
505 echo 529 echo
506 die "Failed Patch: ${patchname}!" 530 die "Failed Patch: ${patchname}!"
507 fi 531 fi
508 532
509 # if everything worked, delete the patch log 533 # if everything worked, delete the full debug patch log
510 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
511 eend 0 543 eend 0
512 done 544 done
513 545
514 [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching" 546 [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching"
515 : # everything worked 547 : # everything worked
517 549
518# @FUNCTION: epatch_user 550# @FUNCTION: epatch_user
519# @USAGE: 551# @USAGE:
520# @DESCRIPTION: 552# @DESCRIPTION:
521# Applies user-provided patches to the source tree. The patches are 553# Applies user-provided patches to the source tree. The patches are
522# 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
523# 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
524# 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.
525# 558#
526# User patches are intended for quick testing of patches without ebuild 559# User patches are intended for quick testing of patches without ebuild
527# modifications, as well as for permanent customizations a user might 560# modifications, as well as for permanent customizations a user might
528# desire. Obviously, there can be no official support for arbitrarily 561# desire. Obviously, there can be no official support for arbitrarily
529# 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
543# autotool input files as well. 576# autotool input files as well.
544epatch_user() { 577epatch_user() {
545 [[ $# -ne 0 ]] && die "epatch_user takes no options" 578 [[ $# -ne 0 ]] && die "epatch_user takes no options"
546 579
547 # Allow multiple calls to this function; ignore all but the first 580 # Allow multiple calls to this function; ignore all but the first
548 local applied="${T}/epatch_user.applied" 581 local applied="${T}/epatch_user.log"
549 [[ -e ${applied} ]] && return 2 582 [[ -e ${applied} ]] && return 2
550 583
551 # don't clobber any EPATCH vars that the parent might want 584 # don't clobber any EPATCH vars that the parent might want
552 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches 585 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
553 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do 586 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}{,:${SLOT}}; do
554 EPATCH_SOURCE=${base}/${CTARGET}/${check} 587 EPATCH_SOURCE=${base}/${CTARGET}/${check}
555 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check} 588 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check}
556 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check} 589 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check}
557 if [[ -d ${EPATCH_SOURCE} ]] ; then 590 if [[ -d ${EPATCH_SOURCE} ]] ; then
558 EPATCH_SOURCE=${EPATCH_SOURCE} \ 591 EPATCH_SOURCE=${EPATCH_SOURCE} \
613edos2unix() { 646edos2unix() {
614 [[ $# -eq 0 ]] && return 0 647 [[ $# -eq 0 ]] && return 0
615 sed -i 's/\r$//' -- "$@" || die 648 sed -i 's/\r$//' -- "$@" || die
616} 649}
617 650
618# Make a desktop file ! 651# @FUNCTION: make_desktop_entry
619# Great for making those icons in kde/gnome startmenu !
620# Amaze your friends ! Get the women ! Join today !
621#
622# 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.
623# 655#
656# @CODE
624# binary: what command does the app run with ? 657# binary: what command does the app run with ?
625# name: the name that will show up in the menu 658# name: the name that will show up in the menu
626# icon: give your little like a pretty little icon ... 659# icon: the icon to use in the menu entry
627# this can be relative (to /usr/share/pixmaps) or 660# this can be relative (to /usr/share/pixmaps) or
628# a full path to an icon 661# a full path to an icon
629# type: what kind of application is this ? for categories: 662# type: what kind of application is this?
663# for categories:
630# 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
631# 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
632make_desktop_entry() { 668make_desktop_entry() {
633 [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable" 669 [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable"
634 670
635 local exec=${1} 671 local exec=${1}
636 local name=${2:-${PN}} 672 local name=${2:-${PN}}
642 local catmaj=${CATEGORY%%-*} 678 local catmaj=${CATEGORY%%-*}
643 local catmin=${CATEGORY##*-} 679 local catmin=${CATEGORY##*-}
644 case ${catmaj} in 680 case ${catmaj} in
645 app) 681 app)
646 case ${catmin} in 682 case ${catmin} in
647 accessibility) type=Accessibility;; 683 accessibility) type="Utility;Accessibility";;
648 admin) type=System;; 684 admin) type=System;;
649 antivirus) type=System;; 685 antivirus) type=System;;
650 arch) type=Archiving;; 686 arch) type="Utility;Archiving";;
651 backup) type=Archiving;; 687 backup) type="Utility;Archiving";;
652 cdr) type=DiscBurning;; 688 cdr) type="AudioVideo;DiscBurning";;
653 dicts) type=Dictionary;; 689 dicts) type="Office;Dictionary";;
654 doc) type=Documentation;; 690 doc) type=Documentation;;
655 editors) type=TextEditor;; 691 editors) type="Utility;TextEditor";;
656 emacs) type=TextEditor;; 692 emacs) type="Development;TextEditor";;
657 emulation) type=Emulator;; 693 emulation) type="System;Emulator";;
658 laptop) type=HardwareSettings;; 694 laptop) type="Settings;HardwareSettings";;
659 office) type=Office;; 695 office) type=Office;;
660 pda) type=PDA;; 696 pda) type="Office;PDA";;
661 vim) type=TextEditor;; 697 vim) type="Development;TextEditor";;
662 xemacs) type=TextEditor;; 698 xemacs) type="Development;TextEditor";;
663 esac 699 esac
664 ;; 700 ;;
665 701
666 dev) 702 dev)
667 type="Development" 703 type="Development"
904 insinto /usr/share/applications 940 insinto /usr/share/applications
905 newins "$@" 941 newins "$@"
906 ) 942 )
907} 943}
908 944
909# @FUNCTION: doicon 945# @FUNCTION: _iconins
910# @USAGE: <list of icons> 946# @INTERNAL
911# @DESCRIPTION: 947# @DESCRIPTION:
912# Install the list of icons into the icon directory (/usr/share/pixmaps). 948# function for use in doicon and newicon
913# This is useful in conjunction with creating desktop/menu files. 949_iconins() {
914doicon() {
915 ( 950 (
916 # wrap the env here so that the 'insinto' call 951 # wrap the env here so that the 'insinto' call
917 # doesn't corrupt the env of the caller 952 # doesn't corrupt the env of the caller
918 local i j ret 953 local funcname=$1; shift
919 insinto /usr/share/pixmaps 954 local size dir
920 for i in "$@" ; do 955 local context=apps
921 if [[ -f ${i} ]] ; then 956 local theme=hicolor
922 doins "${i}" 957
923 ((ret+=$?)) 958 while [[ $# -gt 0 ]] ; do
924 elif [[ -d ${i} ]] ; then 959 case $1 in
925 for j in "${i}"/*.png ; do 960 -s|--size)
926 doins "${j}" 961 if [[ ${2%%x*}x${2%%x*} == "$2" ]] ; then
927 ((ret+=$?)) 962 size=${2%%x*}
928 done
929 else 963 else
930 ((++ret)) 964 size=${2}
931 fi 965 fi
932 done
933 exit ${ret}
934 )
935}
936
937# @FUNCTION: newicon
938# @USAGE: <icon> <newname>
939# @DESCRIPTION:
940# Like all other new* functions, install the specified icon as newname.
941newicon() {
942 (
943 # wrap the env here so that the 'insinto' call
944 # doesn't corrupt the env of the caller
945 insinto /usr/share/pixmaps
946 newins "$@"
947 )
948}
949
950# for internal use only (unpack_pdv and unpack_makeself)
951find_unpackable_file() {
952 local src=$1
953 if [[ -z ${src} ]] ; then
954 src=${DISTDIR}/${A}
955 else
956 if [[ -e ${DISTDIR}/${src} ]] ; then
957 src=${DISTDIR}/${src}
958 elif [[ -e ${PWD}/${src} ]] ; then
959 src=${PWD}/${src}
960 elif [[ -e ${src} ]] ; then
961 src=${src}
962 fi
963 fi
964 [[ ! -e ${src} ]] && return 1
965 echo "${src}"
966}
967
968# @FUNCTION: unpack_pdv
969# @USAGE: <file to unpack> <size of off_t>
970# @DESCRIPTION:
971# Unpack those pesky pdv generated files ...
972# They're self-unpacking programs with the binary package stuffed in
973# the middle of the archive. Valve seems to use it a lot ... too bad
974# it seems to like to segfault a lot :(. So lets take it apart ourselves.
975#
976# You have to specify the off_t size ... I have no idea how to extract that
977# information out of the binary executable myself. Basically you pass in
978# the size of the off_t type (in bytes) on the machine that built the pdv
979# archive.
980#
981# One way to determine this is by running the following commands:
982#
983# @CODE
984# strings <pdv archive> | grep lseek
985# strace -elseek <pdv archive>
986# @CODE
987#
988# Basically look for the first lseek command (we do the strings/grep because
989# sometimes the function call is _llseek or something) and steal the 2nd
990# parameter. Here is an example:
991#
992# @CODE
993# vapier@vapier 0 pdv_unpack # strings hldsupdatetool.bin | grep lseek
994# lseek
995# vapier@vapier 0 pdv_unpack # strace -elseek ./hldsupdatetool.bin
996# lseek(3, -4, SEEK_END) = 2981250
997# @CODE
998#
999# Thus we would pass in the value of '4' as the second parameter.
1000unpack_pdv() {
1001 local src=$(find_unpackable_file "$1")
1002 local sizeoff_t=$2
1003
1004 [[ -z ${src} ]] && die "Could not locate source for '$1'"
1005 [[ -z ${sizeoff_t} ]] && die "No idea what off_t size was used for this pdv :("
1006
1007 local shrtsrc=$(basename "${src}")
1008 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
1009 local metaskip=$(tail -c ${sizeoff_t} "${src}" | hexdump -e \"%i\")
1010 local tailskip=$(tail -c $((${sizeoff_t}*2)) "${src}" | head -c ${sizeoff_t} | hexdump -e \"%i\")
1011
1012 # grab metadata for debug reasons
1013 local metafile=$(emktemp)
1014 tail -c +$((${metaskip}+1)) "${src}" > "${metafile}"
1015
1016 # rip out the final file name from the metadata
1017 local datafile=$(tail -c +$((${metaskip}+1)) "${src}" | strings | head -n 1)
1018 datafile=$(basename "${datafile}")
1019
1020 # now lets uncompress/untar the file if need be
1021 local tmpfile=$(emktemp)
1022 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null | head -c 512 > ${tmpfile}
1023
1024 local iscompressed=$(file -b "${tmpfile}")
1025 if [[ ${iscompressed:0:8} == "compress" ]] ; then
1026 iscompressed=1
1027 mv ${tmpfile}{,.Z}
1028 gunzip ${tmpfile}
1029 else
1030 iscompressed=0
1031 fi
1032 local istar=$(file -b "${tmpfile}")
1033 if [[ ${istar:0:9} == "POSIX tar" ]] ; then
1034 istar=1
1035 else
1036 istar=0
1037 fi
1038
1039 #for some reason gzip dies with this ... dd cant provide buffer fast enough ?
1040 #dd if=${src} ibs=${metaskip} count=1 \
1041 # | dd ibs=${tailskip} skip=1 \
1042 # | gzip -dc \
1043 # > ${datafile}
1044 if [ ${iscompressed} -eq 1 ] ; then
1045 if [ ${istar} -eq 1 ] ; then
1046 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
1047 | head -c $((${metaskip}-${tailskip})) \
1048 | tar -xzf -
1049 else
1050 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
1051 | head -c $((${metaskip}-${tailskip})) \
1052 | gzip -dc \
1053 > ${datafile}
1054 fi
1055 else
1056 if [ ${istar} -eq 1 ] ; then
1057 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
1058 | head -c $((${metaskip}-${tailskip})) \
1059 | tar --no-same-owner -xf -
1060 else
1061 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
1062 | head -c $((${metaskip}-${tailskip})) \
1063 > ${datafile}
1064 fi
1065 fi
1066 true
1067 #[ -s "${datafile}" ] || die "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')"
1068 #assert "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')"
1069}
1070
1071# @FUNCTION: unpack_makeself
1072# @USAGE: [file to unpack] [offset] [tail|dd]
1073# @DESCRIPTION:
1074# Unpack those pesky makeself generated files ...
1075# They're shell scripts with the binary package tagged onto
1076# the end of the archive. Loki utilized the format as does
1077# many other game companies.
1078#
1079# If the file is not specified, then ${A} is used. If the
1080# offset is not specified then we will attempt to extract
1081# the proper offset from the script itself.
1082unpack_makeself() {
1083 local src_input=${1:-${A}}
1084 local src=$(find_unpackable_file "${src_input}")
1085 local skip=$2
1086 local exe=$3
1087
1088 [[ -z ${src} ]] && die "Could not locate source for '${src_input}'"
1089
1090 local shrtsrc=$(basename "${src}")
1091 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
1092 if [[ -z ${skip} ]] ; then
1093 local ver=$(grep -m1 -a '#.*Makeself' "${src}" | awk '{print $NF}')
1094 local skip=0
1095 exe=tail
1096 case ${ver} in 966 case ${size} in
1097 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)
1098 skip=$(grep -a ^skip= "${src}" | cut -d= -f2) 968 size=${size}x${size};;
1099 ;; 969 scalable)
1100 2.0|2.0.1)
1101 skip=$(grep -a ^$'\t'tail "${src}" | awk '{print $2}' | cut -b2-)
1102 ;;
1103 2.1.1)
1104 skip=$(grep -a ^offset= "${src}" | awk '{print $2}' | cut -b2-)
1105 (( skip++ ))
1106 ;;
1107 2.1.2)
1108 skip=$(grep -a ^offset= "${src}" | awk '{print $3}' | head -n 1)
1109 (( skip++ ))
1110 ;;
1111 2.1.3)
1112 skip=`grep -a ^offset= "${src}" | awk '{print $3}'`
1113 (( skip++ ))
1114 ;;
1115 2.1.4|2.1.5)
1116 skip=$(grep -a offset=.*head.*wc "${src}" | awk '{print $3}' | head -n 1)
1117 skip=$(head -n ${skip} "${src}" | wc -c)
1118 exe="dd"
1119 ;; 970 ;;
1120 *) 971 *)
1121 eerror "I'm sorry, but I was unable to support the Makeself file." 972 eerror "${size} is an unsupported icon size!"
1122 eerror "The version I detected was '${ver}'." 973 exit 1;;
1123 eerror "Please file a bug about the file ${shrtsrc} at"
1124 eerror "http://bugs.gentoo.org/ so that support can be added."
1125 die "makeself version '${ver}' not supported"
1126 ;;
1127 esac 974 esac
1128 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset" 975 shift 2;;
1129 fi 976 -t|--theme)
1130 case ${exe} in 977 theme=${2}
1131 tail) exe="tail -n +${skip} '${src}'";; 978 shift 2;;
1132 dd) exe="dd ibs=${skip} skip=1 if='${src}'";; 979 -c|--context)
1133 *) die "makeself cant handle exe '${exe}'" 980 context=${2}
1134 esac 981 shift 2;;
1135
1136 # lets grab the first few bytes of the file to figure out what kind of archive it is
1137 local filetype tmpfile=$(emktemp)
1138 eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}"
1139 filetype=$(file -b "${tmpfile}") || die
1140 case ${filetype} in
1141 *tar\ archive*)
1142 eval ${exe} | tar --no-same-owner -xf -
1143 ;;
1144 bzip2*)
1145 eval ${exe} | bzip2 -dc | tar --no-same-owner -xf -
1146 ;;
1147 gzip*)
1148 eval ${exe} | tar --no-same-owner -xzf -
1149 ;;
1150 compress*)
1151 eval ${exe} | gunzip | tar --no-same-owner -xf -
1152 ;;
1153 *) 982 *)
1154 eerror "Unknown filetype \"${filetype}\" ?"
1155 false
1156 ;;
1157 esac
1158 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
1159}
1160
1161# @FUNCTION: cdrom_get_cds
1162# @USAGE: <file on cd1> [file on cd2] [file on cd3] [...]
1163# @DESCRIPTION:
1164# Aquire cd(s) for those lovely cd-based emerges. Yes, this violates
1165# the whole 'non-interactive' policy, but damnit I want CD support !
1166#
1167# With these cdrom functions we handle all the user interaction and
1168# standardize everything. All you have to do is call cdrom_get_cds()
1169# and when the function returns, you can assume that the cd has been
1170# found at CDROM_ROOT.
1171#
1172# The function will attempt to locate a cd based upon a file that is on
1173# the cd. The more files you give this function, the more cds
1174# the cdrom functions will handle.
1175#
1176# Normally the cdrom functions will refer to the cds as 'cd #1', 'cd #2',
1177# etc... If you want to give the cds better names, then just export
1178# the appropriate CDROM_NAME variable before calling cdrom_get_cds().
1179# Use CDROM_NAME for one cd, or CDROM_NAME_# for multiple cds. You can
1180# also use the CDROM_NAME_SET bash array.
1181#
1182# For those multi cd ebuilds, see the cdrom_load_next_cd() function.
1183cdrom_get_cds() {
1184 # first we figure out how many cds we're dealing with by
1185 # the # of files they gave us
1186 local cdcnt=0
1187 local f=
1188 for f in "$@" ; do
1189 ((++cdcnt))
1190 export CDROM_CHECK_${cdcnt}="$f"
1191 done
1192 export CDROM_TOTAL_CDS=${cdcnt}
1193 export CDROM_CURRENT_CD=1
1194
1195 # now we see if the user gave use CD_ROOT ...
1196 # if they did, let's just believe them that it's correct
1197 if [[ -n ${CD_ROOT}${CD_ROOT_1} ]] ; then
1198 local var=
1199 cdcnt=0
1200 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
1201 ((++cdcnt))
1202 var="CD_ROOT_${cdcnt}"
1203 [[ -z ${!var} ]] && var="CD_ROOT"
1204 if [[ -z ${!var} ]] ; then 983 if [[ -z ${size} ]] ; then
1205 eerror "You must either use just the CD_ROOT" 984 insinto /usr/share/pixmaps
1206 eerror "or specify ALL the CD_ROOT_X variables." 985 else
1207 eerror "In this case, you will need ${CDROM_TOTAL_CDS} CD_ROOT_X variables." 986 insinto /usr/share/icons/${theme}/${size}/${context}
1208 die "could not locate CD_ROOT_${cdcnt}"
1209 fi 987 fi
1210 done
1211 export CDROM_ROOT=${CD_ROOT_1:-${CD_ROOT}}
1212 einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
1213 export CDROM_SET=-1
1214 for f in ${CDROM_CHECK_1//:/ } ; do
1215 ((++CDROM_SET))
1216 [[ -e ${CDROM_ROOT}/${f} ]] && break
1217 done
1218 export CDROM_MATCH=${f}
1219 return
1220 fi
1221 988
1222 # User didn't help us out so lets make sure they know they can 989 if [[ ${funcname} == doicon ]] ; then
1223 # simplify the whole process ...
1224 if [[ ${CDROM_TOTAL_CDS} -eq 1 ]] ; then
1225 einfo "This ebuild will need the ${CDROM_NAME:-cdrom for ${PN}}"
1226 echo
1227 einfo "If you do not have the CD, but have the data files"
1228 einfo "mounted somewhere on your filesystem, just export"
1229 einfo "the variable CD_ROOT so that it points to the"
1230 einfo "directory containing the files."
1231 echo
1232 einfo "For example:"
1233 einfo "export CD_ROOT=/mnt/cdrom"
1234 echo
1235 else
1236 if [[ -n ${CDROM_NAME_SET} ]] ; then
1237 # Translate the CDROM_NAME_SET array into CDROM_NAME_#
1238 cdcnt=0
1239 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
1240 ((++cdcnt))
1241 export CDROM_NAME_${cdcnt}="${CDROM_NAME_SET[$((${cdcnt}-1))]}"
1242 done
1243 fi
1244
1245 einfo "This package will need access to ${CDROM_TOTAL_CDS} cds."
1246 cdcnt=0
1247 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
1248 ((++cdcnt))
1249 var="CDROM_NAME_${cdcnt}"
1250 [[ ! -z ${!var} ]] && einfo " CD ${cdcnt}: ${!var}"
1251 done
1252 echo
1253 einfo "If you do not have the CDs, but have the data files"
1254 einfo "mounted somewhere on your filesystem, just export"
1255 einfo "the following variables so they point to the right place:"
1256 einfon ""
1257 cdcnt=0
1258 while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]] ; do
1259 ((++cdcnt))
1260 echo -n " CD_ROOT_${cdcnt}"
1261 done
1262 echo
1263 einfo "Or, if you have all the files in the same place, or"
1264 einfo "you only have one cdrom, you can export CD_ROOT"
1265 einfo "and that place will be used as the same data source"
1266 einfo "for all the CDs."
1267 echo
1268 einfo "For example:"
1269 einfo "export CD_ROOT_1=/mnt/cdrom"
1270 echo
1271 fi
1272
1273 export CDROM_SET=""
1274 export CDROM_CURRENT_CD=0
1275 cdrom_load_next_cd
1276}
1277
1278# @FUNCTION: cdrom_load_next_cd
1279# @DESCRIPTION:
1280# Some packages are so big they come on multiple CDs. When you're done reading
1281# files off a CD and want access to the next one, just call this function.
1282# Again, all the messy details of user interaction are taken care of for you.
1283# Once this returns, just read the variable CDROM_ROOT for the location of the
1284# mounted CD. Note that you can only go forward in the CD list, so make sure
1285# you only call this function when you're done using the current CD.
1286cdrom_load_next_cd() {
1287 local var
1288 ((++CDROM_CURRENT_CD))
1289
1290 unset CDROM_ROOT
1291 var=CD_ROOT_${CDROM_CURRENT_CD}
1292 [[ -z ${!var} ]] && var="CD_ROOT"
1293 if [[ -z ${!var} ]] ; then 990 if [[ -f $1 ]] ; then
1294 var="CDROM_CHECK_${CDROM_CURRENT_CD}" 991 doins "${1}"
1295 _cdrom_locate_file_on_cd ${!var} 992 elif [[ -d $1 ]] ; then
1296 else 993 shopt -s nullglob
1297 export CDROM_ROOT=${!var} 994 doins "${1}"/*.{png,svg}
1298 fi 995 shopt -u nullglob
1299
1300 einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
1301}
1302
1303# this is used internally by the cdrom_get_cds() and cdrom_load_next_cd()
1304# functions. this should *never* be called from an ebuild.
1305# all it does is try to locate a give file on a cd ... if the cd isn't
1306# found, then a message asking for the user to insert the cdrom will be
1307# displayed and we'll hang out here until:
1308# (1) the file is found on a mounted cdrom
1309# (2) the user hits CTRL+C
1310_cdrom_locate_file_on_cd() {
1311 local mline=""
1312 local showedmsg=0 showjolietmsg=0
1313
1314 while [[ -z ${CDROM_ROOT} ]] ; do
1315 local i=0
1316 local -a cdset=(${*//:/ })
1317 if [[ -n ${CDROM_SET} ]] ; then
1318 cdset=(${cdset[${CDROM_SET}]})
1319 fi
1320
1321 while [[ -n ${cdset[${i}]} ]] ; do
1322 local dir=$(dirname ${cdset[${i}]})
1323 local file=$(basename ${cdset[${i}]})
1324
1325 local point= node= fs= foo=
1326 while read point node fs foo ; do
1327 [[ " cd9660 iso9660 udf " != *" ${fs} "* ]] && \
1328 ! [[ ${fs} == "subfs" && ",${opts}," == *",fs=cdfss,"* ]] \
1329 && continue
1330 point=${point//\040/ }
1331 [[ ! -d ${point}/${dir} ]] && continue
1332 [[ -z $(find "${point}/${dir}" -maxdepth 1 -iname "${file}") ]] && continue
1333 export CDROM_ROOT=${point}
1334 export CDROM_SET=${i}
1335 export CDROM_MATCH=${cdset[${i}]}
1336 return
1337 done <<< "$(get_mounts)"
1338
1339 ((++i))
1340 done
1341
1342 echo
1343 if [[ ${showedmsg} -eq 0 ]] ; then
1344 if [[ ${CDROM_TOTAL_CDS} -eq 1 ]] ; then
1345 if [[ -z ${CDROM_NAME} ]] ; then
1346 einfo "Please insert+mount the cdrom for ${PN} now !"
1347 else 996 else
1348 einfo "Please insert+mount the ${CDROM_NAME} cdrom now !" 997 eerror "${1} is not a valid file/directory!"
998 exit 1
1349 fi 999 fi
1350 else 1000 else
1351 if [[ -z ${CDROM_NAME_1} ]] ; then 1001 break
1352 einfo "Please insert+mount cd #${CDROM_CURRENT_CD} for ${PN} now !"
1353 else
1354 local var="CDROM_NAME_${CDROM_CURRENT_CD}"
1355 einfo "Please insert+mount the ${!var} cdrom now !"
1356 fi
1357 fi 1002 fi
1358 showedmsg=1 1003 shift 1;;
1359 fi 1004 esac
1360 einfo "Press return to scan for the cd again"
1361 einfo "or hit CTRL+C to abort the emerge."
1362 echo
1363 if [[ ${showjolietmsg} -eq 0 ]] ; then
1364 showjolietmsg=1
1365 else
1366 ewarn "If you are having trouble with the detection"
1367 ewarn "of your CD, it is possible that you do not have"
1368 ewarn "Joliet support enabled in your kernel. Please"
1369 ewarn "check that CONFIG_JOLIET is enabled in your kernel."
1370 ebeep 5
1371 fi
1372 read || die "something is screwed with your system"
1373 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} "$@"
1374} 1061}
1375 1062
1376# @FUNCTION: strip-linguas 1063# @FUNCTION: strip-linguas
1377# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>] 1064# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>]
1378# @DESCRIPTION: 1065# @DESCRIPTION:
1416 else 1103 else
1417 nols="${nols} ${f}" 1104 nols="${nols} ${f}"
1418 fi 1105 fi
1419 done 1106 done
1420 [[ -n ${nols} ]] \ 1107 [[ -n ${nols} ]] \
1421 && ewarn "Sorry, but ${PN} does not support the LINGUAS:" ${nols} 1108 && einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
1422 export LINGUAS=${newls:1} 1109 export LINGUAS=${newls:1}
1423} 1110}
1424 1111
1425# @FUNCTION: preserve_old_lib 1112# @FUNCTION: preserve_old_lib
1426# @USAGE: <libs to preserve> [more libs] 1113# @USAGE: <libs to preserve> [more libs]
1474 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"
1475 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"
1476 ewarn "helper program, simply emerge the 'gentoolkit' package." 1163 ewarn "helper program, simply emerge the 'gentoolkit' package."
1477 ewarn 1164 ewarn
1478 fi 1165 fi
1479 # temp hack for #348634 #357225
1480 [[ ${PN} == "mpfr" ]] && lib=${lib##*/}
1481 ewarn " # revdep-rebuild --library '${lib}'" 1166 ewarn " # revdep-rebuild --library '${lib}' && rm '${lib}'"
1482 done 1167 done
1483 if [[ ${notice} -eq 1 ]] ; then
1484 ewarn
1485 ewarn "Once you've finished running revdep-rebuild, it should be safe to"
1486 ewarn "delete the old libraries. Here is a copy & paste for the lazy:"
1487 for lib in "$@" ; do
1488 ewarn " # rm '${lib}'"
1489 done
1490 fi
1491} 1168}
1492 1169
1493# @FUNCTION: built_with_use 1170# @FUNCTION: built_with_use
1494# @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>
1495# @DESCRIPTION: 1172# @DESCRIPTION:
1590# http://bugs.gentoo.org/73450 1267# http://bugs.gentoo.org/73450
1591epunt_cxx() { 1268epunt_cxx() {
1592 local dir=$1 1269 local dir=$1
1593 [[ -z ${dir} ]] && dir=${S} 1270 [[ -z ${dir} ]] && dir=${S}
1594 ebegin "Removing useless C++ checks" 1271 ebegin "Removing useless C++ checks"
1595 local f 1272 local f any_found
1596 find "${dir}" -name configure | while read f ; do 1273 while IFS= read -r -d '' f; do
1597 patch --no-backup-if-mismatch -p0 "${f}" "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null 1274 patch --no-backup-if-mismatch -p0 "${f}" \
1598 done 1275 "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null \
1276 && any_found=1
1277 done < <(find "${dir}" -name configure -print0)
1278
1279# if [[ -z ${any_found} ]]; then
1280# eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt)."
1281# fi
1599 eend 0 1282 eend 0
1600} 1283}
1601 1284
1602# @FUNCTION: make_wrapper 1285# @FUNCTION: make_wrapper
1603# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath] 1286# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
1607# first optionally setting LD_LIBRARY_PATH to the colon-delimited 1290# first optionally setting LD_LIBRARY_PATH to the colon-delimited
1608# libpaths followed by optionally changing directory to chdir. 1291# libpaths followed by optionally changing directory to chdir.
1609make_wrapper() { 1292make_wrapper() {
1610 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5 1293 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
1611 local tmpwrapper=$(emktemp) 1294 local tmpwrapper=$(emktemp)
1295
1296 (
1297 echo '#!/bin/sh'
1298 [[ -n ${chdir} ]] && printf 'cd "%s"\n' "${chdir}"
1299 if [[ -n ${libdir} ]] ; then
1300 cat <<-EOF
1301 if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
1302 export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
1303 else
1304 export LD_LIBRARY_PATH="${libdir}"
1305 fi
1306 EOF
1307 fi
1612 # We don't want to quote ${bin} so that people can pass complex 1308 # We don't want to quote ${bin} so that people can pass complex
1613 # things as $bin ... "./someprog --args" 1309 # things as ${bin} ... "./someprog --args"
1310 printf 'exec %s "$@"\n' "${bin}"
1614 cat << EOF > "${tmpwrapper}" 1311 ) > "${tmpwrapper}"
1615#!/bin/sh
1616cd "${chdir:-.}"
1617if [ -n "${libdir}" ] ; then
1618 if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
1619 export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
1620 else
1621 export LD_LIBRARY_PATH="${libdir}"
1622 fi
1623fi
1624exec ${bin} "\$@"
1625EOF
1626 chmod go+rx "${tmpwrapper}" 1312 chmod go+rx "${tmpwrapper}"
1313
1627 if [[ -n ${path} ]] ; then 1314 if [[ -n ${path} ]] ; then
1628 ( 1315 (
1629 exeinto "${path}" 1316 exeinto "${path}"
1630 newexe "${tmpwrapper}" "${wrapper}" 1317 newexe "${tmpwrapper}" "${wrapper}"
1631 ) || die 1318 ) || die
1692} 1379}
1693 1380
1694# @FUNCTION: usex 1381# @FUNCTION: usex
1695# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix] 1382# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix]
1696# @DESCRIPTION: 1383# @DESCRIPTION:
1384# Proxy to declare usex for package managers or EAPIs that do not provide it
1385# and use the package manager implementation when available (i.e. EAPI >= 5).
1697# If USE flag is set, echo [true output][true suffix] (defaults to "yes"), 1386# If USE flag is set, echo [true output][true suffix] (defaults to "yes"),
1698# otherwise echo [false output][false suffix] (defaults to "no"). 1387# otherwise echo [false output][false suffix] (defaults to "no").
1388if has "${EAPI:-0}" 0 1 2 3 4; then
1699usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963 1389 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
1390fi
1391
1392# @FUNCTION: prune_libtool_files
1393# @USAGE: [--all|--modules]
1394# @DESCRIPTION:
1395# Locate unnecessary libtool files (.la) and libtool static archives
1396# (.a) and remove them from installation image.
1397#
1398# By default, .la files are removed whenever the static linkage can
1399# either be performed using pkg-config or doesn't introduce additional
1400# flags.
1401#
1402# If '--modules' argument is passed, .la files for modules (plugins) are
1403# removed as well. This is usually useful when the package installs
1404# plugins and the plugin loader does not use .la files.
1405#
1406# If '--all' argument is passed, all .la files are removed without
1407# performing any heuristic on them. You shouldn't ever use that,
1408# and instead report a bug in the algorithm instead.
1409#
1410# The .a files are only removed whenever corresponding .la files state
1411# that they should not be linked to, i.e. whenever these files
1412# correspond to plugins.
1413#
1414# Note: if your package installs both static libraries and .pc files
1415# which use variable substitution for -l flags, you need to add
1416# pkg-config to your DEPEND.
1417prune_libtool_files() {
1418 debug-print-function ${FUNCNAME} "$@"
1419
1420 local removing_all removing_modules opt
1421 for opt; do
1422 case "${opt}" in
1423 --all)
1424 removing_all=1
1425 removing_modules=1
1426 ;;
1427 --modules)
1428 removing_modules=1
1429 ;;
1430 *)
1431 die "Invalid argument to ${FUNCNAME}(): ${opt}"
1432 esac
1433 done
1434
1435 local f
1436 local queue=()
1437 while IFS= read -r -d '' f; do # for all .la files
1438 local archivefile=${f/%.la/.a}
1439
1440 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1441
1442 local reason pkgconfig_scanned
1443
1444 # Remove static libs we're not supposed to link against.
1445 if grep -q '^shouldnotlink=yes$' "${f}"; then
1446 if [[ -f ${archivefile} ]]; then
1447 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1448 queue+=( "${archivefile}" )
1449 fi
1450
1451 # The .la file may be used by a module loader, so avoid removing it
1452 # unless explicitly requested.
1453 if [[ ${removing_modules} ]]; then
1454 reason='module'
1455 fi
1456
1457 # Remove .la files when:
1458 # - user explicitly wants us to remove all .la files,
1459 # - respective static archive doesn't exist,
1460 # - they are covered by a .pc file already,
1461 # - they don't provide any new information (no libs & no flags).
1462
1463 elif [[ ${removing_all} ]]; then
1464 reason='requested'
1465 elif [[ ! -f ${archivefile} ]]; then
1466 reason='no static archive'
1467 elif [[ ! $(sed -nre \
1468 "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
1469 "${f}") ]]; then
1470 reason='no libs & flags'
1471 else
1472 if [[ ! ${pkgconfig_scanned} ]]; then
1473 # Create a list of all .pc-covered libs.
1474 local pc_libs=()
1475 if [[ ! ${removing_all} ]]; then
1476 local pc
1477 local tf=${T}/prune-lt-files.pc
1478 local pkgconf=$(tc-getPKG_CONFIG)
1479
1480 while IFS= read -r -d '' pc; do # for all .pc files
1481 local arg libs
1482
1483 # Use pkg-config if available (and works),
1484 # fallback to sed.
1485 if ${pkgconf} --exists "${pc}" &>/dev/null; then
1486 sed -e '/^Requires:/d' "${pc}" > "${tf}"
1487 libs=$(${pkgconf} --libs "${tf}")
1488 else
1489 libs=$(sed -ne 's/^Libs://p' "${pc}")
1490 fi
1491
1492 for arg in ${libs}; do
1493 if [[ ${arg} == -l* ]]; then
1494 if [[ ${arg} == '*$*' ]]; then
1495 eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
1496 eqawarn "(arg: ${arg})"
1497 eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
1498 fi
1499
1500 pc_libs+=( lib${arg#-l}.la )
1501 fi
1502 done
1503 done < <(find "${D}" -type f -name '*.pc' -print0)
1504
1505 rm -f "${tf}"
1506 fi
1507
1508 pkgconfig_scanned=1
1509 fi
1510
1511 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1512 fi
1513
1514 if [[ ${reason} ]]; then
1515 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1516 queue+=( "${f}" )
1517 fi
1518 done < <(find "${D}" -xtype f -name '*.la' -print0)
1519
1520 if [[ ${queue[@]} ]]; then
1521 rm -f "${queue[@]}"
1522 fi
1523}
1700 1524
1701check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; } 1525check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; }
1702 1526
1703fi 1527fi

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

  ViewVC Help
Powered by ViewVC 1.1.20