/[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.379
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.379 2012/01/31 06:44:00 ulm 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 cdrom 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
544 local applied="${T}/epatch_user.applied" 542 local applied="${T}/epatch_user.applied"
545 [[ -e ${applied} ]] && return 2 543 [[ -e ${applied} ]] && return 2
546 544
547 # don't clobber any EPATCH vars that the parent might want 545 # don't clobber any EPATCH vars that the parent might want
548 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches 546 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
549 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do 547 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}; do
550 EPATCH_SOURCE=${base}/${CTARGET}/${check} 548 EPATCH_SOURCE=${base}/${CTARGET}/${check}
551 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check} 549 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check}
552 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check} 550 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check}
553 if [[ -d ${EPATCH_SOURCE} ]] ; then 551 if [[ -d ${EPATCH_SOURCE} ]] ; then
554 EPATCH_SOURCE=${EPATCH_SOURCE} \ 552 EPATCH_SOURCE=${EPATCH_SOURCE} \
609edos2unix() { 607edos2unix() {
610 [[ $# -eq 0 ]] && return 0 608 [[ $# -eq 0 ]] && return 0
611 sed -i 's/\r$//' -- "$@" || die 609 sed -i 's/\r$//' -- "$@" || die
612} 610}
613 611
614# Make a desktop file ! 612# @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]) 613# @USAGE: make_desktop_entry(<command>, [name], [icon], [type], [fields])
614# @DESCRIPTION:
615# Make a .desktop file.
619# 616#
617# @CODE
620# binary: what command does the app run with ? 618# binary: what command does the app run with ?
621# name: the name that will show up in the menu 619# name: the name that will show up in the menu
622# icon: give your little like a pretty little icon ... 620# icon: give your little like a pretty little icon ...
623# this can be relative (to /usr/share/pixmaps) or 621# this can be relative (to /usr/share/pixmaps) or
624# a full path to an icon 622# a full path to an icon
625# type: what kind of application is this ? for categories: 623# type: what kind of application is this?
624# for categories:
626# http://standards.freedesktop.org/menu-spec/latest/apa.html 625# http://standards.freedesktop.org/menu-spec/latest/apa.html
626# if unset, function tries to guess from package's category
627# fields: extra fields to append to the desktop file; a printf string 627# fields: extra fields to append to the desktop file; a printf string
628# @CODE
628make_desktop_entry() { 629make_desktop_entry() {
629 [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable" 630 [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable"
630 631
631 local exec=${1} 632 local exec=${1}
632 local name=${2:-${PN}} 633 local name=${2:-${PN}}
1150 eerror "Unknown filetype \"${filetype}\" ?" 1151 eerror "Unknown filetype \"${filetype}\" ?"
1151 false 1152 false
1152 ;; 1153 ;;
1153 esac 1154 esac
1154 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})" 1155 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
1201 eerror "You must either use just the CD_ROOT"
1202 eerror "or specify ALL the CD_ROOT_X variables."
1203 eerror "In this case, you will need ${CDROM_TOTAL_CDS} CD_ROOT_X variables."
1204 die "could not locate CD_ROOT_${cdcnt}"
1205 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
1218 # User didn't help us out so lets make sure they know they can
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
1290 var="CDROM_CHECK_${CDROM_CURRENT_CD}"
1291 _cdrom_locate_file_on_cd ${!var}
1292 else
1293 export CDROM_ROOT=${!var}
1294 fi
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
1344 einfo "Please insert+mount the ${CDROM_NAME} cdrom now !"
1345 fi
1346 else
1347 if [[ -z ${CDROM_NAME_1} ]] ; then
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
1354 showedmsg=1
1355 fi
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
1370} 1156}
1371 1157
1372# @FUNCTION: strip-linguas 1158# @FUNCTION: strip-linguas
1373# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>] 1159# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>]
1374# @DESCRIPTION: 1160# @DESCRIPTION:

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

  ViewVC Help
Powered by ViewVC 1.1.20