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

Diff of /eclass/eutils.eclass

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

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

Legend:
Removed from v.1.373  
changed lines
  Added in v.1.399

  ViewVC Help
Powered by ViewVC 1.1.20