/[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.383
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.383 2012/02/16 00:27:17 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
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
441 eqawarn " In the future this will cause a failure." 440 eqawarn " In the future this will cause a failure."
442 eqawarn "${rel_paths}" 441 eqawarn "${rel_paths}"
443 fi 442 fi
444 443
445 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/ 444 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/
445 local patch_cmd
446 while [[ ${count} -lt 5 ]] ; do 446 while [[ ${count} -lt 5 ]] ; do
447 patch_cmd="patch -p${count} ${EPATCH_OPTS}"
448
447 # Generate some useful debug info ... 449 # Generate some useful debug info ...
448 ( 450 (
449 _epatch_draw_line "***** ${patchname} *****" 451 _epatch_draw_line "***** ${patchname} *****"
450 echo 452 echo
451 echo "PATCH COMMAND: patch -p${count} ${EPATCH_OPTS} < '${PATCH_TARGET}'" 453 echo "PATCH COMMAND: ${patch_cmd} < '${PATCH_TARGET}'"
452 echo 454 echo
453 _epatch_draw_line "***** ${patchname} *****" 455 _epatch_draw_line "***** ${patchname} *****"
454 patch -p${count} ${EPATCH_OPTS} --dry-run -f < "${PATCH_TARGET}" 2>&1 456 ${patch_cmd} --dry-run -f < "${PATCH_TARGET}" 2>&1
455 ret=$? 457 ret=$?
456 echo 458 echo
457 echo "patch program exited with status ${ret}" 459 echo "patch program exited with status ${ret}"
458 exit ${ret} 460 exit ${ret}
459 ) >> "${STDERR_TARGET}" 461 ) >> "${STDERR_TARGET}"
463 _epatch_draw_line "***** ${patchname} *****" 465 _epatch_draw_line "***** ${patchname} *****"
464 echo 466 echo
465 echo "ACTUALLY APPLYING ${patchname} ..." 467 echo "ACTUALLY APPLYING ${patchname} ..."
466 echo 468 echo
467 _epatch_draw_line "***** ${patchname} *****" 469 _epatch_draw_line "***** ${patchname} *****"
468 patch -p${count} ${EPATCH_OPTS} < "${PATCH_TARGET}" 2>&1 470 ${patch_cmd} < "${PATCH_TARGET}" 2>&1
469 ret=$? 471 ret=$?
470 echo 472 echo
471 echo "patch program exited with status ${ret}" 473 echo "patch program exited with status ${ret}"
472 exit ${ret} 474 exit ${ret}
473 ) >> "${STDERR_TARGET}" 475 ) >> "${STDERR_TARGET}"
500 eerror " ${STDERR_TARGET}" 502 eerror " ${STDERR_TARGET}"
501 echo 503 echo
502 die "Failed Patch: ${patchname}!" 504 die "Failed Patch: ${patchname}!"
503 fi 505 fi
504 506
505 # if everything worked, delete the patch log 507 # if everything worked, delete the full debug patch log
506 rm -f "${STDERR_TARGET}" 508 rm -f "${STDERR_TARGET}"
509
510 # then log away the exact stuff for people to review later
511 cat <<-EOF >> "${T}/epatch.log"
512 PATCH: ${x}
513 CMD: ${patch_cmd}
514 PWD: ${PWD}
515
516 EOF
507 eend 0 517 eend 0
508 done 518 done
509 519
510 [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching" 520 [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching"
511 : # everything worked 521 : # everything worked
539# autotool input files as well. 549# autotool input files as well.
540epatch_user() { 550epatch_user() {
541 [[ $# -ne 0 ]] && die "epatch_user takes no options" 551 [[ $# -ne 0 ]] && die "epatch_user takes no options"
542 552
543 # Allow multiple calls to this function; ignore all but the first 553 # Allow multiple calls to this function; ignore all but the first
544 local applied="${T}/epatch_user.applied" 554 local applied="${T}/epatch_user.log"
545 [[ -e ${applied} ]] && return 2 555 [[ -e ${applied} ]] && return 2
546 556
547 # don't clobber any EPATCH vars that the parent might want 557 # don't clobber any EPATCH vars that the parent might want
548 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches 558 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
549 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do 559 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}; do
550 EPATCH_SOURCE=${base}/${CTARGET}/${check} 560 EPATCH_SOURCE=${base}/${CTARGET}/${check}
551 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check} 561 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check}
552 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check} 562 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check}
553 if [[ -d ${EPATCH_SOURCE} ]] ; then 563 if [[ -d ${EPATCH_SOURCE} ]] ; then
554 EPATCH_SOURCE=${EPATCH_SOURCE} \ 564 EPATCH_SOURCE=${EPATCH_SOURCE} \
609edos2unix() { 619edos2unix() {
610 [[ $# -eq 0 ]] && return 0 620 [[ $# -eq 0 ]] && return 0
611 sed -i 's/\r$//' -- "$@" || die 621 sed -i 's/\r$//' -- "$@" || die
612} 622}
613 623
614# Make a desktop file ! 624# @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]) 625# @USAGE: make_desktop_entry(<command>, [name], [icon], [type], [fields])
626# @DESCRIPTION:
627# Make a .desktop file.
619# 628#
629# @CODE
620# binary: what command does the app run with ? 630# binary: what command does the app run with ?
621# name: the name that will show up in the menu 631# name: the name that will show up in the menu
622# icon: give your little like a pretty little icon ... 632# icon: give your little like a pretty little icon ...
623# this can be relative (to /usr/share/pixmaps) or 633# this can be relative (to /usr/share/pixmaps) or
624# a full path to an icon 634# a full path to an icon
625# type: what kind of application is this ? for categories: 635# type: what kind of application is this?
636# for categories:
626# http://standards.freedesktop.org/menu-spec/latest/apa.html 637# http://standards.freedesktop.org/menu-spec/latest/apa.html
638# if unset, function tries to guess from package's category
627# fields: extra fields to append to the desktop file; a printf string 639# fields: extra fields to append to the desktop file; a printf string
640# @CODE
628make_desktop_entry() { 641make_desktop_entry() {
629 [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable" 642 [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable"
630 643
631 local exec=${1} 644 local exec=${1}
632 local name=${2:-${PN}} 645 local name=${2:-${PN}}
939 # wrap the env here so that the 'insinto' call 952 # wrap the env here so that the 'insinto' call
940 # doesn't corrupt the env of the caller 953 # doesn't corrupt the env of the caller
941 insinto /usr/share/pixmaps 954 insinto /usr/share/pixmaps
942 newins "$@" 955 newins "$@"
943 ) 956 )
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
1093 1.5.*|1.6.0-nv) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same
1094 skip=$(grep -a ^skip= "${src}" | cut -d= -f2)
1095 ;;
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 ;;
1116 *)
1117 eerror "I'm sorry, but I was unable to support the Makeself file."
1118 eerror "The version I detected was '${ver}'."
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
1124 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset"
1125 fi
1126 case ${exe} in
1127 tail) exe="tail -n +${skip} '${src}'";;
1128 dd) exe="dd ibs=${skip} skip=1 if='${src}'";;
1129 *) die "makeself cant handle exe '${exe}'"
1130 esac
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 *)
1150 eerror "Unknown filetype \"${filetype}\" ?"
1151 false
1152 ;;
1153 esac
1154 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
1155} 957}
1156 958
1157# @FUNCTION: cdrom_get_cds 959# @FUNCTION: cdrom_get_cds
1158# @USAGE: <file on cd1> [file on cd2] [file on cd3] [...] 960# @USAGE: <file on cd1> [file on cd2] [file on cd3] [...]
1159# @DESCRIPTION: 961# @DESCRIPTION:

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

  ViewVC Help
Powered by ViewVC 1.1.20