EAPI 4: Support MERGE_TYPE (bug #347351)
[portage.git] / bin / ebuild.sh
1 #!/bin/bash
2 # Copyright 1999-2010 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 PORTAGE_BIN_PATH="${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"
6 PORTAGE_PYM_PATH="${PORTAGE_PYM_PATH:-/usr/lib/portage/pym}"
7
8 if [[ $PORTAGE_SANDBOX_COMPAT_LEVEL -lt 22 ]] ; then
9         # Ensure that /dev/std* streams have appropriate sandbox permission for
10         # bug #288863. This can be removed after sandbox is fixed and portage
11         # depends on the fixed version (sandbox-2.2 has the fix but it is
12         # currently unstable).
13         export SANDBOX_WRITE="${SANDBOX_WRITE:+${SANDBOX_WRITE}:}/dev/stdout:/dev/stderr"
14         export SANDBOX_READ="${SANDBOX_READ:+${SANDBOX_READ}:}/dev/stdin"
15 fi
16
17 # Don't use sandbox's BASH_ENV for new shells because it does
18 # 'source /etc/profile' which can interfere with the build
19 # environment by modifying our PATH.
20 unset BASH_ENV
21
22 ROOTPATH=${ROOTPATH##:}
23 ROOTPATH=${ROOTPATH%%:}
24 PREROOTPATH=${PREROOTPATH##:}
25 PREROOTPATH=${PREROOTPATH%%:}
26 PATH=$PORTAGE_BIN_PATH/ebuild-helpers:$PREROOTPATH${PREROOTPATH:+:}/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin${ROOTPATH:+:}$ROOTPATH
27 export PATH
28
29 # This is just a temporary workaround for portage-9999 users since
30 # earlier portage versions do not detect a version change in this case
31 # (9999 to 9999) and therefore they try execute an incompatible version of
32 # ebuild.sh during the upgrade.
33 export PORTAGE_BZIP2_COMMAND=${PORTAGE_BZIP2_COMMAND:-bzip2} 
34
35 # These two functions wrap sourcing and calling respectively.  At present they
36 # perform a qa check to make sure eclasses and ebuilds and profiles don't mess
37 # with shell opts (shopts).  Ebuilds/eclasses changing shopts should reset them 
38 # when they are done.
39
40 qa_source() {
41         local shopts=$(shopt) OLDIFS="$IFS"
42         local retval
43         source "$@"
44         retval=$?
45         set +e
46         [[ $shopts != $(shopt) ]] &&
47                 eqawarn "QA Notice: Global shell options changed and were not restored while sourcing '$*'"
48         [[ "$IFS" != "$OLDIFS" ]] &&
49                 eqawarn "QA Notice: Global IFS changed and was not restored while sourcing '$*'"
50         return $retval
51 }
52
53 qa_call() {
54         local shopts=$(shopt) OLDIFS="$IFS"
55         local retval
56         "$@"
57         retval=$?
58         set +e
59         [[ $shopts != $(shopt) ]] &&
60                 eqawarn "QA Notice: Global shell options changed and were not restored while calling '$*'"
61         [[ "$IFS" != "$OLDIFS" ]] &&
62                 eqawarn "QA Notice: Global IFS changed and was not restored while calling '$*'"
63         return $retval
64 }
65
66 EBUILD_SH_ARGS="$*"
67
68 shift $#
69
70 # Prevent aliases from causing portage to act inappropriately.
71 # Make sure it's before everything so we don't mess aliases that follow.
72 unalias -a
73
74 # Unset some variables that break things.
75 unset GZIP BZIP BZIP2 CDPATH GREP_OPTIONS GREP_COLOR GLOBIGNORE
76
77 source "${PORTAGE_BIN_PATH}/isolated-functions.sh"  &>/dev/null
78
79 [[ $PORTAGE_QUIET != "" ]] && export PORTAGE_QUIET
80
81 # sandbox support functions; defined prior to profile.bashrc srcing, since the profile might need to add a default exception (/usr/lib64/conftest fex)
82 _sb_append_var() {
83         local _v=$1 ; shift
84         local var="SANDBOX_${_v}"
85         [[ -z $1 || -n $2 ]] && die "Usage: add$(echo ${_v} | \
86                 LC_ALL=C tr [:upper:] [:lower:]) <colon-delimited list of paths>"
87         export ${var}="${!var:+${!var}:}$1"
88 }
89 # bash-4 version:
90 # local var="SANDBOX_${1^^}"
91 # addread() { _sb_append_var ${0#add} "$@" ; }
92 addread()    { _sb_append_var READ    "$@" ; }
93 addwrite()   { _sb_append_var WRITE   "$@" ; }
94 adddeny()    { _sb_append_var DENY    "$@" ; }
95 addpredict() { _sb_append_var PREDICT "$@" ; }
96
97 addwrite "${PORTAGE_TMPDIR}"
98 addread "/:${PORTAGE_TMPDIR}"
99 [[ -n ${PORTAGE_GPG_DIR} ]] && addpredict "${PORTAGE_GPG_DIR}"
100
101 # Avoid sandbox violations in temporary directories.
102 if [[ -w $T ]] ; then
103         export TEMP=$T
104         export TMP=$T
105         export TMPDIR=$T
106 elif [[ $SANDBOX_ON = 1 ]] ; then
107         for x in TEMP TMP TMPDIR ; do
108                 [[ -n ${!x} ]] && addwrite "${!x}"
109         done
110         unset x
111 fi
112
113 # the sandbox is disabled by default except when overridden in the relevant stages
114 export SANDBOX_ON=0
115
116 lchown() {
117         chown -h "$@"
118 }
119
120 lchgrp() {
121         chgrp -h "$@"
122 }
123
124 esyslog() {
125         # Custom version of esyslog() to take care of the "Red Star" bug.
126         # MUST follow functions.sh to override the "" parameter problem.
127         return 0
128 }
129
130 use() {
131         useq ${1}
132 }
133
134 usev() {
135         if useq ${1}; then
136                 echo "${1#!}"
137                 return 0
138         fi
139         return 1
140 }
141
142 useq() {
143         local u=$1
144         local found=0
145
146         # if we got something like '!flag', then invert the return value
147         if [[ ${u:0:1} == "!" ]] ; then
148                 u=${u:1}
149                 found=1
150         fi
151
152         if [[ $EBUILD_PHASE = depend ]] ; then
153                 # TODO: Add a registration interface for eclasses to register
154                 # any number of phase hooks, so that global scope eclass
155                 # initialization can by migrated to phase hooks in new EAPIs.
156                 # Example: add_phase_hook before pkg_setup $ECLASS_pre_pkg_setup
157                 #if [[ -n $EAPI ]] && ! hasq "$EAPI" 0 1 2 3 ; then
158                 #       die "use() called during invalid phase: $EBUILD_PHASE"
159                 #fi
160                 true
161
162         # Make sure we have this USE flag in IUSE
163         elif [[ -n $PORTAGE_IUSE && -n $EBUILD_PHASE ]] ; then
164                 [[ $u =~ $PORTAGE_IUSE ]] || \
165                         eqawarn "QA Notice: USE Flag '${u}' not" \
166                                 "in IUSE for ${CATEGORY}/${PF}"
167         fi
168
169         if hasq ${u} ${USE} ; then
170                 return ${found}
171         else
172                 return $((!found))
173         fi
174 }
175
176 # Return true if given package is installed. Otherwise return false.
177 # Takes single depend-type atoms.
178 has_version() {
179         if [ "${EBUILD_PHASE}" == "depend" ]; then
180                 die "portageq calls (has_version calls portageq) are not allowed in the global scope"
181         fi
182
183         if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
184                 "$PORTAGE_BIN_PATH"/ebuild-ipc has_version "$ROOT" "$1"
185         else
186                 PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
187                 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" has_version "${ROOT}" "$1"
188         fi
189         local retval=$?
190         case "${retval}" in
191                 0|1)
192                         return ${retval}
193                         ;;
194                 *)
195                         die "unexpected portageq exit code: ${retval}"
196                         ;;
197         esac
198 }
199
200 portageq() {
201         if [ "${EBUILD_PHASE}" == "depend" ]; then
202                 die "portageq calls are not allowed in the global scope"
203         fi
204
205         PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
206         "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" "$@"
207 }
208
209
210 # ----------------------------------------------------------------------------
211 # ----------------------------------------------------------------------------
212 # ----------------------------------------------------------------------------
213
214
215 # Returns the best/most-current match.
216 # Takes single depend-type atoms.
217 best_version() {
218         if [ "${EBUILD_PHASE}" == "depend" ]; then
219                 die "portageq calls (best_version calls portageq) are not allowed in the global scope"
220         fi
221
222         if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
223                 "$PORTAGE_BIN_PATH"/ebuild-ipc best_version "$ROOT" "$1"
224         else
225                 PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
226                 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" 'best_version' "${ROOT}" "$1"
227         fi
228         local retval=$?
229         case "${retval}" in
230                 0|1)
231                         return ${retval}
232                         ;;
233                 *)
234                         die "unexpected portageq exit code: ${retval}"
235                         ;;
236         esac
237 }
238
239 use_with() {
240         if [ -z "$1" ]; then
241                 echo "!!! use_with() called without a parameter." >&2
242                 echo "!!! use_with <USEFLAG> [<flagname> [value]]" >&2
243                 return 1
244         fi
245
246         if ! has "${EAPI:-0}" 0 1 2 3 ; then
247                 local UW_SUFFIX=${3+=$3}
248         else
249                 local UW_SUFFIX=${3:+=$3}
250         fi
251         local UWORD=${2:-$1}
252
253         if useq $1; then
254                 echo "--with-${UWORD}${UW_SUFFIX}"
255         else
256                 echo "--without-${UWORD}"
257         fi
258         return 0
259 }
260
261 use_enable() {
262         if [ -z "$1" ]; then
263                 echo "!!! use_enable() called without a parameter." >&2
264                 echo "!!! use_enable <USEFLAG> [<flagname> [value]]" >&2
265                 return 1
266         fi
267
268         if ! has "${EAPI:-0}" 0 1 2 3 ; then
269                 local UE_SUFFIX=${3+=$3}
270         else
271                 local UE_SUFFIX=${3:+=$3}
272         fi
273         local UWORD=${2:-$1}
274
275         if useq $1; then
276                 echo "--enable-${UWORD}${UE_SUFFIX}"
277         else
278                 echo "--disable-${UWORD}"
279         fi
280         return 0
281 }
282
283 register_die_hook() {
284         local x
285         for x in $* ; do
286                 hasq $x $EBUILD_DEATH_HOOKS || \
287                         export EBUILD_DEATH_HOOKS="$EBUILD_DEATH_HOOKS $x"
288         done
289 }
290
291 register_success_hook() {
292         local x
293         for x in $* ; do
294                 hasq $x $EBUILD_SUCCESS_HOOKS || \
295                         export EBUILD_SUCCESS_HOOKS="$EBUILD_SUCCESS_HOOKS $x"
296         done
297 }
298
299 # Ensure that $PWD is sane whenever possible, to protect against
300 # exploitation of insecure search path for python -c in ebuilds.
301 # See bug #239560.
302 if ! hasq "$EBUILD_PHASE" clean cleanrm depend help ; then
303         cd "$PORTAGE_BUILDDIR" || \
304                 die "PORTAGE_BUILDDIR does not exist: '$PORTAGE_BUILDDIR'"
305 fi
306
307 #if no perms are specified, dirs/files will have decent defaults
308 #(not secretive, but not stupid)
309 umask 022
310 export DESTTREE=/usr
311 export INSDESTTREE=""
312 export _E_EXEDESTTREE_=""
313 export _E_DOCDESTTREE_=""
314 export INSOPTIONS="-m0644"
315 export EXEOPTIONS="-m0755"
316 export LIBOPTIONS="-m0644"
317 export DIROPTIONS="-m0755"
318 export MOPREFIX=${PN}
319 declare -a PORTAGE_DOCOMPRESS=( /usr/share/{doc,info,man} )
320 declare -a PORTAGE_DOCOMPRESS_SKIP=( /usr/share/doc/${PF}/html )
321
322 # adds ".keep" files so that dirs aren't auto-cleaned
323 keepdir() {
324         dodir "$@"
325         local x
326         if [ "$1" == "-R" ] || [ "$1" == "-r" ]; then
327                 shift
328                 find "$@" -type d -printf "${D}%p/.keep_${CATEGORY}_${PN}-${SLOT}\n" \
329                         | tr "\n" "\0" | ${XARGS} -0 -n100 touch || \
330                         die "Failed to recursively create .keep files"
331         else
332                 for x in "$@"; do
333                         touch "${D}${x}/.keep_${CATEGORY}_${PN}-${SLOT}" || \
334                                 die "Failed to create .keep in ${D}${x}"
335                 done
336         fi
337 }
338
339 unpack() {
340         local srcdir
341         local x
342         local y
343         local myfail
344         local eapi=${EAPI:-0}
345         [ -z "$*" ] && die "Nothing passed to the 'unpack' command"
346
347         for x in "$@"; do
348                 vecho ">>> Unpacking ${x} to ${PWD}"
349                 y=${x%.*}
350                 y=${y##*.}
351
352                 if [[ ${x} == "./"* ]] ; then
353                         srcdir=""
354                 elif [[ ${x} == ${DISTDIR%/}/* ]] ; then
355                         die "Arguments to unpack() cannot begin with \${DISTDIR}."
356                 elif [[ ${x} == "/"* ]] ; then
357                         die "Arguments to unpack() cannot be absolute"
358                 else
359                         srcdir="${DISTDIR}/"
360                 fi
361                 [[ ! -s ${srcdir}${x} ]] && die "${x} does not exist"
362
363                 _unpack_tar() {
364                         if [ "${y}" == "tar" ]; then
365                                 $1 -c -- "$srcdir$x" | tar xof -
366                                 assert_sigpipe_ok "$myfail"
367                         else
368                                 $1 -c -- "${srcdir}${x}" > ${x%.*} || die "$myfail"
369                         fi
370                 }
371
372                 myfail="failure unpacking ${x}"
373                 case "${x##*.}" in
374                         tar)
375                                 tar xof "$srcdir$x" || die "$myfail"
376                                 ;;
377                         tgz)
378                                 tar xozf "$srcdir$x" || die "$myfail"
379                                 ;;
380                         tbz|tbz2)
381                                 ${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- "$srcdir$x" | tar xof -
382                                 assert_sigpipe_ok "$myfail"
383                                 ;;
384                         ZIP|zip|jar)
385                                 # unzip will interactively prompt under some error conditions,
386                                 # as reported in bug #336285
387                                 ( while true ; do echo n ; done ) | \
388                                 unzip -qo "${srcdir}${x}" || die "$myfail"
389                                 ;;
390                         gz|Z|z)
391                                 _unpack_tar "gzip -d"
392                                 ;;
393                         bz2|bz)
394                                 _unpack_tar "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}"
395                                 ;;
396                         7Z|7z)
397                                 local my_output
398                                 my_output="$(7z x -y "${srcdir}${x}")"
399                                 if [ $? -ne 0 ]; then
400                                         echo "${my_output}" >&2
401                                         die "$myfail"
402                                 fi
403                                 ;;
404                         RAR|rar)
405                                 unrar x -idq -o+ "${srcdir}${x}" || die "$myfail"
406                                 ;;
407                         LHa|LHA|lha|lzh)
408                                 lha xfq "${srcdir}${x}" || die "$myfail"
409                                 ;;
410                         a)
411                                 ar x "${srcdir}${x}" || die "$myfail"
412                                 ;;
413                         deb)
414                                 # Unpacking .deb archives can not always be done with
415                                 # `ar`.  For instance on AIX this doesn't work out.  If
416                                 # we have `deb2targz` installed, prefer it over `ar` for
417                                 # that reason.  We just make sure on AIX `deb2targz` is
418                                 # installed.
419                                 if type -P deb2targz > /dev/null; then
420                                         y=${x##*/}
421                                         local created_symlink=0
422                                         if [ ! "$srcdir$x" -ef "$y" ] ; then
423                                                 # deb2targz always extracts into the same directory as
424                                                 # the source file, so create a symlink in the current
425                                                 # working directory if necessary.
426                                                 ln -sf "$srcdir$x" "$y" || die "$myfail"
427                                                 created_symlink=1
428                                         fi
429                                         deb2targz "$y" || die "$myfail"
430                                         if [ $created_symlink = 1 ] ; then
431                                                 # Clean up the symlink so the ebuild
432                                                 # doesn't inadvertently install it.
433                                                 rm -f "$y"
434                                         fi
435                                         mv -f "${y%.deb}".tar.gz data.tar.gz || die "$myfail"
436                                 else
437                                         ar x "$srcdir$x" || die "$myfail"
438                                 fi
439                                 ;;
440                         lzma)
441                                 _unpack_tar "lzma -d"
442                                 ;;
443                         xz)
444                                 if hasq $eapi 0 1 2 ; then
445                                         vecho "unpack ${x}: file format not recognized. Ignoring."
446                                 else
447                                         _unpack_tar "xz -d"
448                                 fi
449                                 ;;
450                         *)
451                                 vecho "unpack ${x}: file format not recognized. Ignoring."
452                                 ;;
453                 esac
454         done
455         # Do not chmod '.' since it's probably ${WORKDIR} and PORTAGE_WORKDIR_MODE
456         # should be preserved.
457         find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \
458                 ${XARGS} -0 chmod -fR a+rX,u+w,g-w,o-w
459 }
460
461 strip_duplicate_slashes() {
462         if [[ -n $1 ]] ; then
463                 local removed=$1
464                 while [[ ${removed} == *//* ]] ; do
465                         removed=${removed//\/\///}
466                 done
467                 echo ${removed}
468         fi
469 }
470
471 hasg() {
472     local x s=$1
473     shift
474     for x ; do [[ ${x} == ${s} ]] && echo "${x}" && return 0 ; done
475     return 1
476 }
477 hasgq() { hasg "$@" >/dev/null ; }
478 econf() {
479         local x
480
481         local phase_func=$(_ebuild_arg_to_phase "$EAPI" "$EBUILD_PHASE")
482         if [[ -n $phase_func ]] ; then
483                 if hasq "$EAPI" 0 1 ; then
484                         [[ $phase_func != src_compile ]] && \
485                                 eqawarn "QA Notice: econf called in" \
486                                         "$phase_func instead of src_compile"
487                 else
488                         [[ $phase_func != src_configure ]] && \
489                                 eqawarn "QA Notice: econf called in" \
490                                         "$phase_func instead of src_configure"
491                 fi
492         fi
493
494         : ${ECONF_SOURCE:=.}
495         if [ -x "${ECONF_SOURCE}/configure" ]; then
496                 if [[ -n $CONFIG_SHELL && \
497                         "$(head -n1 "$ECONF_SOURCE/configure")" =~ ^'#!'[[:space:]]*/bin/sh([[:space:]]|$) ]] ; then
498                         sed -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" -i "$ECONF_SOURCE/configure" || \
499                                 die "Substition of shebang in '$ECONF_SOURCE/configure' failed"
500                 fi
501                 if [ -e /usr/share/gnuconfig/ ]; then
502                         find "${WORKDIR}" -type f '(' \
503                         -name config.guess -o -name config.sub ')' -print0 | \
504                         while read -d $'\0' x ; do
505                                 vecho " * econf: updating ${x/${WORKDIR}\/} with /usr/share/gnuconfig/${x##*/}"
506                                 cp -f /usr/share/gnuconfig/"${x##*/}" "${x}"
507                         done
508                 fi
509
510                 # EAPI=4 adds --disable-dependency-tracking to econf
511                 if ! hasq "$EAPI" 0 1 2 3 3_pre2 ; then
512                         set -- --disable-dependency-tracking "$@"
513                 fi
514
515                 # if the profile defines a location to install libs to aside from default, pass it on.
516                 # if the ebuild passes in --libdir, they're responsible for the conf_libdir fun.
517                 local CONF_LIBDIR LIBDIR_VAR="LIBDIR_${ABI}"
518                 if [[ -n ${ABI} && -n ${!LIBDIR_VAR} ]] ; then
519                         CONF_LIBDIR=${!LIBDIR_VAR}
520                 fi
521                 if [[ -n ${CONF_LIBDIR} ]] && ! hasgq --libdir=\* "$@" ; then
522                         export CONF_PREFIX=$(hasg --exec-prefix=\* "$@")
523                         [[ -z ${CONF_PREFIX} ]] && CONF_PREFIX=$(hasg --prefix=\* "$@")
524                         : ${CONF_PREFIX:=/usr}
525                         CONF_PREFIX=${CONF_PREFIX#*=}
526                         [[ ${CONF_PREFIX} != /* ]] && CONF_PREFIX="/${CONF_PREFIX}"
527                         [[ ${CONF_LIBDIR} != /* ]] && CONF_LIBDIR="/${CONF_LIBDIR}"
528                         set -- --libdir="$(strip_duplicate_slashes ${CONF_PREFIX}${CONF_LIBDIR})" "$@"
529                 fi
530
531                 set -- \
532                         --prefix=/usr \
533                         ${CBUILD:+--build=${CBUILD}} \
534                         --host=${CHOST} \
535                         ${CTARGET:+--target=${CTARGET}} \
536                         --mandir=/usr/share/man \
537                         --infodir=/usr/share/info \
538                         --datadir=/usr/share \
539                         --sysconfdir=/etc \
540                         --localstatedir=/var/lib \
541                         "$@" \
542                         ${EXTRA_ECONF}
543                 vecho "${ECONF_SOURCE}/configure" "$@"
544
545                 if ! "${ECONF_SOURCE}/configure" "$@" ; then
546
547                         if [ -s config.log ]; then
548                                 echo
549                                 echo "!!! Please attach the following file when seeking support:"
550                                 echo "!!! ${PWD}/config.log"
551                         fi
552                         die "econf failed"
553                 fi
554         elif [ -f "${ECONF_SOURCE}/configure" ]; then
555                 die "configure is not executable"
556         else
557                 die "no configure script found"
558         fi
559 }
560
561 einstall() {
562         # CONF_PREFIX is only set if they didn't pass in libdir above.
563         local LOCAL_EXTRA_EINSTALL="${EXTRA_EINSTALL}"
564         LIBDIR_VAR="LIBDIR_${ABI}"
565         if [ -n "${ABI}" -a -n "${!LIBDIR_VAR}" ]; then
566                 CONF_LIBDIR="${!LIBDIR_VAR}"
567         fi
568         unset LIBDIR_VAR
569         if [ -n "${CONF_LIBDIR}" ] && [ "${CONF_PREFIX:+set}" = set ]; then
570                 EI_DESTLIBDIR="${D}/${CONF_PREFIX}/${CONF_LIBDIR}"
571                 EI_DESTLIBDIR="$(strip_duplicate_slashes ${EI_DESTLIBDIR})"
572                 LOCAL_EXTRA_EINSTALL="libdir=${EI_DESTLIBDIR} ${LOCAL_EXTRA_EINSTALL}"
573                 unset EI_DESTLIBDIR
574         fi
575
576         if [ -f ./[mM]akefile -o -f ./GNUmakefile ] ; then
577                 if [ "${PORTAGE_DEBUG}" == "1" ]; then
578                         ${MAKE:-make} -n prefix="${D}usr" \
579                                 datadir="${D}usr/share" \
580                                 infodir="${D}usr/share/info" \
581                                 localstatedir="${D}var/lib" \
582                                 mandir="${D}usr/share/man" \
583                                 sysconfdir="${D}etc" \
584                                 ${LOCAL_EXTRA_EINSTALL} \
585                                 ${MAKEOPTS} ${EXTRA_EMAKE} -j1 \
586                                 "$@" install
587                 fi
588                 ${MAKE:-make} prefix="${D}usr" \
589                         datadir="${D}usr/share" \
590                         infodir="${D}usr/share/info" \
591                         localstatedir="${D}var/lib" \
592                         mandir="${D}usr/share/man" \
593                         sysconfdir="${D}etc" \
594                         ${LOCAL_EXTRA_EINSTALL} \
595                         ${MAKEOPTS} ${EXTRA_EMAKE} -j1 \
596                         "$@" install || die "einstall failed"
597         else
598                 die "no Makefile found"
599         fi
600 }
601
602 _eapi0_pkg_nofetch() {
603         [ -z "${SRC_URI}" ] && return
604
605         elog "The following are listed in SRC_URI for ${PN}:"
606         local x
607         for x in $(echo ${SRC_URI}); do
608                 elog "   ${x}"
609         done
610 }
611
612 _eapi0_src_unpack() {
613         [[ -n ${A} ]] && unpack ${A}
614 }
615
616 _eapi0_src_compile() {
617         if [ -x ./configure ] ; then
618                 econf
619         fi
620         _eapi2_src_compile
621 }
622
623 _eapi0_src_test() {
624         if emake -j1 check -n &> /dev/null; then
625                 vecho ">>> Test phase [check]: ${CATEGORY}/${PF}"
626                 if ! emake -j1 check; then
627                         hasq test $FEATURES && die "Make check failed. See above for details."
628                         hasq test $FEATURES || eerror "Make check failed. See above for details."
629                 fi
630         elif emake -j1 test -n &> /dev/null; then
631                 vecho ">>> Test phase [test]: ${CATEGORY}/${PF}"
632                 if ! emake -j1 test; then
633                         hasq test $FEATURES && die "Make test failed. See above for details."
634                         hasq test $FEATURES || eerror "Make test failed. See above for details."
635                 fi
636         else
637                 vecho ">>> Test phase [none]: ${CATEGORY}/${PF}"
638         fi
639 }
640
641 _eapi1_src_compile() {
642         _eapi2_src_configure
643         _eapi2_src_compile
644 }
645
646 _eapi2_src_configure() {
647         if [[ -x ${ECONF_SOURCE:-.}/configure ]] ; then
648                 econf
649         fi
650 }
651
652 _eapi2_src_compile() {
653         if [ -f Makefile ] || [ -f GNUmakefile ] || [ -f makefile ]; then
654                 emake || die "emake failed"
655         fi
656 }
657
658 _eapi4_src_install() {
659         if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
660                 emake DESTDIR="${D}" install
661         fi
662
663         if [[ -z $DOCS ]] ; then
664                 local d
665                 for d in README* ChangeLog AUTHORS NEWS TODO CHANGES \
666                                 THANKS BUGS FAQ CREDITS CHANGELOG ; do
667                         [[ -s "${d}" ]] && dodoc "${d}"
668                 done
669         elif [[ $(declare -p DOCS) == "declare -a "* ]] ; then
670                 dodoc "${DOCS[@]}"
671         else
672                 dodoc ${DOCS}
673         fi
674 }
675
676 ebuild_phase() {
677         declare -F "$1" >/dev/null && qa_call $1
678 }
679
680 ebuild_phase_with_hooks() {
681         local x phase_name=${1}
682         for x in {pre_,,post_}${phase_name} ; do
683                 ebuild_phase ${x}
684         done
685 }
686
687 dyn_pretend() {
688         ebuild_phase_with_hooks pkg_pretend
689 }
690
691 dyn_setup() {
692         if [[ -e $PORTAGE_BUILDDIR/.setuped ]] ; then
693                 vecho ">>> It appears that '$PF' is already setup; skipping."
694                 vecho ">>> Remove '$PORTAGE_BUILDDIR/.setuped' to force setup."
695                 return 0
696         fi
697         ebuild_phase pre_pkg_setup
698         ebuild_phase pkg_setup
699         > "$PORTAGE_BUILDDIR"/.setuped
700         ebuild_phase post_pkg_setup
701 }
702
703 dyn_unpack() {
704         local newstuff="no"
705         if [ -e "${WORKDIR}" ]; then
706                 local x
707                 local checkme
708                 for x in $A ; do
709                         vecho ">>> Checking ${x}'s mtime..."
710                         if [ "${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/${x}" -nt "${WORKDIR}" ]; then
711                                 vecho ">>> ${x} has been updated; recreating WORKDIR..."
712                                 newstuff="yes"
713                                 break
714                         fi
715                 done
716                 if [ ! -f "${PORTAGE_BUILDDIR}/.unpacked" ] ; then
717                         vecho ">>> Not marked as unpacked; recreating WORKDIR..."
718                         newstuff="yes"
719                 fi
720         fi
721         if [ "${newstuff}" == "yes" ]; then
722                 # We don't necessarily have privileges to do a full dyn_clean here.
723                 rm -rf "${PORTAGE_BUILDDIR}"/{.setuped,.unpacked,.prepared,.configured,.compiled,.tested,.installed,.packaged,build-info}
724                 if ! hasq keepwork $FEATURES ; then
725                         rm -rf "${WORKDIR}"
726                 fi
727                 if [ -d "${T}" ] && \
728                         ! hasq keeptemp $FEATURES ; then
729                         rm -rf "${T}" && mkdir "${T}"
730                 fi
731         fi
732         if [ -e "${WORKDIR}" ]; then
733                 if [ "$newstuff" == "no" ]; then
734                         vecho ">>> WORKDIR is up-to-date, keeping..."
735                         return 0
736                 fi
737         fi
738
739         if [ ! -d "${WORKDIR}" ]; then
740                 install -m${PORTAGE_WORKDIR_MODE:-0700} -d "${WORKDIR}" || die "Failed to create dir '${WORKDIR}'"
741         fi
742         cd "${WORKDIR}" || die "Directory change failed: \`cd '${WORKDIR}'\`"
743         ebuild_phase pre_src_unpack
744         vecho ">>> Unpacking source..."
745         ebuild_phase src_unpack
746         touch "${PORTAGE_BUILDDIR}/.unpacked" || die "IO Failure -- Failed 'touch .unpacked' in ${PORTAGE_BUILDDIR}"
747         vecho ">>> Source unpacked in ${WORKDIR}"
748         ebuild_phase post_src_unpack
749 }
750
751 dyn_clean() {
752         if [ -z "${PORTAGE_BUILDDIR}" ]; then
753                 echo "Aborting clean phase because PORTAGE_BUILDDIR is unset!"
754                 return 1
755         elif [ ! -d "${PORTAGE_BUILDDIR}" ] ; then
756                 return 0
757         fi
758         if hasq chflags $FEATURES ; then
759                 chflags -R noschg,nouchg,nosappnd,nouappnd "${PORTAGE_BUILDDIR}"
760                 chflags -R nosunlnk,nouunlnk "${PORTAGE_BUILDDIR}" 2>/dev/null
761         fi
762
763         rm -rf "${PORTAGE_BUILDDIR}/image" "${PORTAGE_BUILDDIR}/homedir"
764         rm -f "${PORTAGE_BUILDDIR}/.installed"
765
766         if [[ $EMERGE_FROM = binary ]] || \
767                 ! hasq keeptemp $FEATURES && ! hasq keepwork $FEATURES ; then
768                 rm -rf "${T}"
769         fi
770
771         if [[ $EMERGE_FROM = binary ]] || ! hasq keepwork $FEATURES; then
772                 rm -f "$PORTAGE_BUILDDIR"/.{ebuild_changed,logid,setuped,unpacked,prepared} \
773                         "$PORTAGE_BUILDDIR"/.{configured,compiled,tested,packaged} \
774                         "$PORTAGE_BUILDDIR"/.die_hooks \
775                         "$PORTAGE_BUILDDIR"/.ipc_{in,out,lock} \
776                         "$PORTAGE_BUILDDIR"/.exit_status
777
778                 rm -rf "${PORTAGE_BUILDDIR}/build-info"
779                 rm -rf "${WORKDIR}"
780         fi
781
782         if [ -f "${PORTAGE_BUILDDIR}/.unpacked" ]; then
783                 find "${PORTAGE_BUILDDIR}" -type d ! -regex "^${WORKDIR}" | sort -r | tr "\n" "\0" | $XARGS -0 rmdir &>/dev/null
784         fi
785
786         # do not bind this to doebuild defined DISTDIR; don't trust doebuild, and if mistakes are made it'll
787         # result in it wiping the users distfiles directory (bad).
788         rm -rf "${PORTAGE_BUILDDIR}/distdir"
789
790         # Some kernels, such as Solaris, return EINVAL when an attempt
791         # is made to remove the current working directory.
792         cd "$PORTAGE_BUILDDIR"/../..
793         rmdir "$PORTAGE_BUILDDIR" "${PORTAGE_BUILDDIR%/*}" 2>/dev/null
794
795         true
796 }
797
798 into() {
799         if [ "$1" == "/" ]; then
800                 export DESTTREE=""
801         else
802                 export DESTTREE=$1
803                 if [ ! -d "${D}${DESTTREE}" ]; then
804                         install -d "${D}${DESTTREE}"
805                         local ret=$?
806                         if [[ $ret -ne 0 ]] ; then
807                                 helpers_die "${FUNCNAME[0]} failed"
808                                 return $ret
809                         fi
810                 fi
811         fi
812 }
813
814 insinto() {
815         if [ "$1" == "/" ]; then
816                 export INSDESTTREE=""
817         else
818                 export INSDESTTREE=$1
819                 if [ ! -d "${D}${INSDESTTREE}" ]; then
820                         install -d "${D}${INSDESTTREE}"
821                         local ret=$?
822                         if [[ $ret -ne 0 ]] ; then
823                                 helpers_die "${FUNCNAME[0]} failed"
824                                 return $ret
825                         fi
826                 fi
827         fi
828 }
829
830 exeinto() {
831         if [ "$1" == "/" ]; then
832                 export _E_EXEDESTTREE_=""
833         else
834                 export _E_EXEDESTTREE_="$1"
835                 if [ ! -d "${D}${_E_EXEDESTTREE_}" ]; then
836                         install -d "${D}${_E_EXEDESTTREE_}"
837                         local ret=$?
838                         if [[ $ret -ne 0 ]] ; then
839                                 helpers_die "${FUNCNAME[0]} failed"
840                                 return $ret
841                         fi
842                 fi
843         fi
844 }
845
846 docinto() {
847         if [ "$1" == "/" ]; then
848                 export _E_DOCDESTTREE_=""
849         else
850                 export _E_DOCDESTTREE_="$1"
851                 if [ ! -d "${D}usr/share/doc/${PF}/${_E_DOCDESTTREE_}" ]; then
852                         install -d "${D}usr/share/doc/${PF}/${_E_DOCDESTTREE_}"
853                         local ret=$?
854                         if [[ $ret -ne 0 ]] ; then
855                                 helpers_die "${FUNCNAME[0]} failed"
856                                 return $ret
857                         fi
858                 fi
859         fi
860 }
861
862 insopts() {
863         export INSOPTIONS="$@"
864
865         # `install` should never be called with '-s' ...
866         hasq -s ${INSOPTIONS} && die "Never call insopts() with -s"
867 }
868
869 diropts() {
870         export DIROPTIONS="$@"
871 }
872
873 exeopts() {
874         export EXEOPTIONS="$@"
875
876         # `install` should never be called with '-s' ...
877         hasq -s ${EXEOPTIONS} && die "Never call exeopts() with -s"
878 }
879
880 libopts() {
881         export LIBOPTIONS="$@"
882
883         # `install` should never be called with '-s' ...
884         hasq -s ${LIBOPTIONS} && die "Never call libopts() with -s"
885 }
886
887 docompress() {
888         hasq "${EAPI}" 0 1 2 3 && die "'docompress' not supported in this EAPI"
889
890         local f g
891         if [[ $1 = "-x" ]]; then
892                 shift
893                 for f; do
894                         f=$(strip_duplicate_slashes "${f}"); f=${f%/}
895                         [[ ${f:0:1} = / ]] || f="/${f}"
896                         for g in "${PORTAGE_DOCOMPRESS_SKIP[@]}"; do
897                                 [[ ${f} = ${g} ]] && continue 2
898                         done
899                         PORTAGE_DOCOMPRESS_SKIP[${#PORTAGE_DOCOMPRESS_SKIP[@]}]=${f}
900                 done
901         else
902                 for f; do
903                         f=$(strip_duplicate_slashes "${f}"); f=${f%/}
904                         [[ ${f:0:1} = / ]] || f="/${f}"
905                         for g in "${PORTAGE_DOCOMPRESS[@]}"; do
906                                 [[ ${f} = ${g} ]] && continue 2
907                         done
908                         PORTAGE_DOCOMPRESS[${#PORTAGE_DOCOMPRESS[@]}]=${f}
909                 done
910         fi
911 }
912
913 abort_handler() {
914         local msg
915         if [ "$2" != "fail" ]; then
916                 msg="${EBUILD}: ${1} aborted; exiting."
917         else
918                 msg="${EBUILD}: ${1} failed; exiting."
919         fi
920         echo
921         echo "$msg"
922         echo
923         eval ${3}
924         #unset signal handler
925         trap - SIGINT SIGQUIT
926 }
927
928 abort_prepare() {
929         abort_handler src_prepare $1
930         rm -f "$PORTAGE_BUILDDIR/.prepared"
931         exit 1
932 }
933
934 abort_configure() {
935         abort_handler src_configure $1
936         rm -f "$PORTAGE_BUILDDIR/.configured"
937         exit 1
938 }
939
940 abort_compile() {
941         abort_handler "src_compile" $1
942         rm -f "${PORTAGE_BUILDDIR}/.compiled"
943         exit 1
944 }
945
946 abort_test() {
947         abort_handler "dyn_test" $1
948         rm -f "${PORTAGE_BUILDDIR}/.tested"
949         exit 1
950 }
951
952 abort_install() {
953         abort_handler "src_install" $1
954         rm -rf "${PORTAGE_BUILDDIR}/image"
955         exit 1
956 }
957
958 has_phase_defined_up_to() {
959         local phase
960         for phase in unpack prepare configure compile install; do
961                 has ${phase} ${DEFINED_PHASES} && return 0
962                 [[ ${phase} == $1 ]] && return 1
963         done
964         # We shouldn't actually get here
965         return 1
966 }
967
968 dyn_prepare() {
969
970         if [[ -e $PORTAGE_BUILDDIR/.prepared ]] ; then
971                 vecho ">>> It appears that '$PF' is already prepared; skipping."
972                 vecho ">>> Remove '$PORTAGE_BUILDDIR/.prepared' to force prepare."
973                 return 0
974         fi
975
976         if [[ -d $S ]] ; then
977                 cd "${S}"
978         elif hasq $EAPI 0 1 2 3 3_pre2 ; then
979                 cd "${WORKDIR}"
980         elif [[ -z ${A} ]] && ! has_phase_defined_up_to prepare; then
981                 cd "${WORKDIR}"
982         else
983                 die "The source directory '${S}' doesn't exist"
984         fi
985
986         trap abort_prepare SIGINT SIGQUIT
987
988         ebuild_phase pre_src_prepare
989         vecho ">>> Preparing source in $PWD ..."
990         ebuild_phase src_prepare
991         touch "$PORTAGE_BUILDDIR"/.prepared
992         vecho ">>> Source prepared."
993         ebuild_phase post_src_prepare
994
995         trap - SIGINT SIGQUIT
996 }
997
998 dyn_configure() {
999
1000         if [[ -e $PORTAGE_BUILDDIR/.configured ]] ; then
1001                 vecho ">>> It appears that '$PF' is already configured; skipping."
1002                 vecho ">>> Remove '$PORTAGE_BUILDDIR/.configured' to force configuration."
1003                 return 0
1004         fi
1005
1006         if [[ -d $S ]] ; then
1007                 cd "${S}"
1008         elif hasq $EAPI 0 1 2 3 3_pre2 ; then
1009                 cd "${WORKDIR}"
1010         elif [[ -z ${A} ]] && ! has_phase_defined_up_to configure; then
1011                 cd "${WORKDIR}"
1012         else
1013                 die "The source directory '${S}' doesn't exist"
1014         fi
1015
1016         trap abort_configure SIGINT SIGQUIT
1017
1018         ebuild_phase pre_src_configure
1019
1020         vecho ">>> Configuring source in $PWD ..."
1021         ebuild_phase src_configure
1022         touch "$PORTAGE_BUILDDIR"/.configured
1023         vecho ">>> Source configured."
1024
1025         ebuild_phase post_src_configure
1026
1027         trap - SIGINT SIGQUIT
1028 }
1029
1030 dyn_compile() {
1031
1032         if [[ -e $PORTAGE_BUILDDIR/.compiled ]] ; then
1033                 vecho ">>> It appears that '${PF}' is already compiled; skipping."
1034                 vecho ">>> Remove '$PORTAGE_BUILDDIR/.compiled' to force compilation."
1035                 return 0
1036         fi
1037
1038         if [[ -d $S ]] ; then
1039                 cd "${S}"
1040         elif hasq $EAPI 0 1 2 3 3_pre2 ; then
1041                 cd "${WORKDIR}"
1042         elif [[ -z ${A} ]] && ! has_phase_defined_up_to compile; then
1043                 cd "${WORKDIR}"
1044         else
1045                 die "The source directory '${S}' doesn't exist"
1046         fi
1047
1048         trap abort_compile SIGINT SIGQUIT
1049
1050         ebuild_phase pre_src_compile
1051
1052         vecho ">>> Compiling source in $PWD ..."
1053         ebuild_phase src_compile
1054         touch "$PORTAGE_BUILDDIR"/.compiled
1055         vecho ">>> Source compiled."
1056
1057         ebuild_phase post_src_compile
1058
1059         trap - SIGINT SIGQUIT
1060 }
1061
1062 dyn_test() {
1063
1064         if [[ -e $PORTAGE_BUILDDIR/.tested ]] ; then
1065                 vecho ">>> It appears that ${PN} has already been tested; skipping."
1066                 vecho ">>> Remove '${PORTAGE_BUILDDIR}/.tested' to force test."
1067                 return
1068         fi
1069
1070         if [ "${EBUILD_FORCE_TEST}" == "1" ] ; then
1071                 # If USE came from ${T}/environment then it might not have USE=test
1072                 # like it's supposed to here.
1073                 ! hasq test ${USE} && export USE="${USE} test"
1074         fi
1075
1076         trap "abort_test" SIGINT SIGQUIT
1077         if [ -d "${S}" ]; then
1078                 cd "${S}"
1079         else
1080                 cd "${WORKDIR}"
1081         fi
1082
1083         if ! hasq test $FEATURES && [ "${EBUILD_FORCE_TEST}" != "1" ]; then
1084                 vecho ">>> Test phase [not enabled]: ${CATEGORY}/${PF}"
1085         elif hasq test $RESTRICT; then
1086                 einfo "Skipping make test/check due to ebuild restriction."
1087                 vecho ">>> Test phase [explicitly disabled]: ${CATEGORY}/${PF}"
1088         else
1089                 local save_sp=${SANDBOX_PREDICT}
1090                 addpredict /
1091                 ebuild_phase pre_src_test
1092                 ebuild_phase src_test
1093                 touch "$PORTAGE_BUILDDIR/.tested" || \
1094                         die "Failed to 'touch .tested' in $PORTAGE_BUILDDIR"
1095                 ebuild_phase post_src_test
1096                 SANDBOX_PREDICT=${save_sp}
1097         fi
1098
1099         trap - SIGINT SIGQUIT
1100 }
1101
1102 dyn_install() {
1103         [ -z "$PORTAGE_BUILDDIR" ] && die "${FUNCNAME}: PORTAGE_BUILDDIR is unset"
1104         if hasq noauto $FEATURES ; then
1105                 rm -f "${PORTAGE_BUILDDIR}/.installed"
1106         elif [[ -e $PORTAGE_BUILDDIR/.installed ]] ; then
1107                 vecho ">>> It appears that '${PF}' is already installed; skipping."
1108                 vecho ">>> Remove '${PORTAGE_BUILDDIR}/.installed' to force install."
1109                 return 0
1110         fi
1111         trap "abort_install" SIGINT SIGQUIT
1112         ebuild_phase pre_src_install
1113         rm -rf "${PORTAGE_BUILDDIR}/image"
1114         mkdir "${PORTAGE_BUILDDIR}/image"
1115         if [[ -d $S ]] ; then
1116                 cd "${S}"
1117         elif hasq $EAPI 0 1 2 3 3_pre2 ; then
1118                 cd "${WORKDIR}"
1119         elif [[ -z ${A} ]] && ! has_phase_defined_up_to install; then
1120                 cd "${WORKDIR}"
1121         else
1122                 die "The source directory '${S}' doesn't exist"
1123         fi
1124
1125         vecho
1126         vecho ">>> Install ${PF} into ${D} category ${CATEGORY}"
1127         #our custom version of libtool uses $S and $D to fix
1128         #invalid paths in .la files
1129         export S D
1130         #some packages uses an alternative to $S to build in, cause
1131         #our libtool to create problematic .la files
1132         export PWORKDIR="$WORKDIR"
1133
1134         # Reset exeinto(), docinto(), insinto(), and into() state variables
1135         # in case the user is running the install phase multiple times
1136         # consecutively via the ebuild command.
1137         export DESTTREE=/usr
1138         export INSDESTTREE=""
1139         export _E_EXEDESTTREE_=""
1140         export _E_DOCDESTTREE_=""
1141
1142         ebuild_phase src_install
1143         touch "${PORTAGE_BUILDDIR}/.installed"
1144         vecho ">>> Completed installing ${PF} into ${D}"
1145         vecho
1146         ebuild_phase post_src_install
1147
1148         cd "${PORTAGE_BUILDDIR}"/build-info
1149         set -f
1150         local f x
1151         IFS=$' \t\n\r'
1152         for f in CATEGORY DEFINED_PHASES FEATURES INHERITED IUSE REQUIRED_USE \
1153                 PF PKGUSE SLOT KEYWORDS HOMEPAGE DESCRIPTION ; do
1154                 x=$(echo -n ${!f})
1155                 [[ -n $x ]] && echo "$x" > $f
1156         done
1157         if [[ $CATEGORY != virtual ]] ; then
1158                 for f in ASFLAGS CBUILD CC CFLAGS CHOST CTARGET CXX \
1159                         CXXFLAGS EXTRA_ECONF EXTRA_EINSTALL EXTRA_MAKE \
1160                         LDFLAGS LIBCFLAGS LIBCXXFLAGS ; do
1161                         x=$(echo -n ${!f})
1162                         [[ -n $x ]] && echo "$x" > $f
1163                 done
1164         fi
1165         echo "${USE}"       > USE
1166         echo "${EAPI:-0}"   > EAPI
1167         set +f
1168
1169         # local variables can leak into the saved environment.
1170         unset f
1171
1172         save_ebuild_env --exclude-init-phases | filter_readonly_variables \
1173                 --filter-path --filter-sandbox --allow-extra-vars > environment
1174         assert "save_ebuild_env failed"
1175
1176         ${PORTAGE_BZIP2_COMMAND} -f9 environment
1177
1178         cp "${EBUILD}" "${PF}.ebuild"
1179         [ -n "${PORTAGE_REPO_NAME}" ]  && echo "${PORTAGE_REPO_NAME}" > repository
1180         if hasq nostrip ${FEATURES} ${RESTRICT} || hasq strip ${RESTRICT}
1181         then
1182                 touch DEBUGBUILD
1183         fi
1184         trap - SIGINT SIGQUIT
1185 }
1186
1187 dyn_preinst() {
1188         if [ -z "${D}" ]; then
1189                 eerror "${FUNCNAME}: D is unset"
1190                 return 1
1191         fi
1192         ebuild_phase_with_hooks pkg_preinst
1193 }
1194
1195 dyn_help() {
1196         echo
1197         echo "Portage"
1198         echo "Copyright 1999-2010 Gentoo Foundation"
1199         echo
1200         echo "How to use the ebuild command:"
1201         echo
1202         echo "The first argument to ebuild should be an existing .ebuild file."
1203         echo
1204         echo "One or more of the following options can then be specified.  If more"
1205         echo "than one option is specified, each will be executed in order."
1206         echo
1207         echo "  help        : show this help screen"
1208         echo "  pretend     : execute package specific pretend actions"
1209         echo "  setup       : execute package specific setup actions"
1210         echo "  fetch       : download source archive(s) and patches"
1211         echo "  digest      : create a manifest file for the package"
1212         echo "  manifest    : create a manifest file for the package"
1213         echo "  unpack      : unpack sources (auto-dependencies if needed)"
1214         echo "  prepare     : prepare sources (auto-dependencies if needed)"
1215         echo "  configure   : configure sources (auto-fetch/unpack if needed)"
1216         echo "  compile     : compile sources (auto-fetch/unpack/configure if needed)"
1217         echo "  test        : test package (auto-fetch/unpack/configure/compile if needed)"
1218         echo "  preinst     : execute pre-install instructions"
1219         echo "  postinst    : execute post-install instructions"
1220         echo "  install     : install the package to the temporary install directory"
1221         echo "  qmerge      : merge image into live filesystem, recording files in db"
1222         echo "  merge       : do fetch, unpack, compile, install and qmerge"
1223         echo "  prerm       : execute pre-removal instructions"
1224         echo "  postrm      : execute post-removal instructions"
1225         echo "  unmerge     : remove package from live filesystem"
1226         echo "  config      : execute package specific configuration actions"
1227         echo "  package     : create a tarball package in ${PKGDIR}/All"
1228         echo "  rpm         : build a RedHat RPM package"
1229         echo "  clean       : clean up all source and temporary files"
1230         echo
1231         echo "The following settings will be used for the ebuild process:"
1232         echo
1233         echo "  package     : ${PF}"
1234         echo "  slot        : ${SLOT}"
1235         echo "  category    : ${CATEGORY}"
1236         echo "  description : ${DESCRIPTION}"
1237         echo "  system      : ${CHOST}"
1238         echo "  c flags     : ${CFLAGS}"
1239         echo "  c++ flags   : ${CXXFLAGS}"
1240         echo "  make flags  : ${MAKEOPTS}"
1241         echo -n "  build mode  : "
1242         if hasq nostrip ${FEATURES} ${RESTRICT} || hasq strip ${RESTRICT} ;
1243         then
1244                 echo "debug (large)"
1245         else
1246                 echo "production (stripped)"
1247         fi
1248         echo "  merge to    : ${ROOT}"
1249         echo
1250         if [ -n "$USE" ]; then
1251                 echo "Additionally, support for the following optional features will be enabled:"
1252                 echo
1253                 echo "  ${USE}"
1254         fi
1255         echo
1256 }
1257
1258 # debug-print() gets called from many places with verbose status information useful
1259 # for tracking down problems. The output is in $T/eclass-debug.log.
1260 # You can set ECLASS_DEBUG_OUTPUT to redirect the output somewhere else as well.
1261 # The special "on" setting echoes the information, mixing it with the rest of the
1262 # emerge output.
1263 # You can override the setting by exporting a new one from the console, or you can
1264 # set a new default in make.*. Here the default is "" or unset.
1265
1266 # in the future might use e* from /etc/init.d/functions.sh if i feel like it
1267 debug-print() {
1268         # if $T isn't defined, we're in dep calculation mode and
1269         # shouldn't do anything
1270         [[ $EBUILD_PHASE = depend || ! -d ${T} || ${#} -eq 0 ]] && return 0
1271
1272         if [[ ${ECLASS_DEBUG_OUTPUT} == on ]]; then
1273                 printf 'debug: %s\n' "${@}" >&2
1274         elif [[ -n ${ECLASS_DEBUG_OUTPUT} ]]; then
1275                 printf 'debug: %s\n' "${@}" >> "${ECLASS_DEBUG_OUTPUT}"
1276         fi
1277
1278         if [[ -w $T ]] ; then
1279                 # default target
1280                 printf '%s\n' "${@}" >> "${T}/eclass-debug.log"
1281                 # let the portage user own/write to this file
1282                 chgrp portage "${T}/eclass-debug.log" &>/dev/null
1283                 chmod g+w "${T}/eclass-debug.log" &>/dev/null
1284         fi
1285 }
1286
1287 # The following 2 functions are debug-print() wrappers
1288
1289 debug-print-function() {
1290         debug-print "${1}: entering function, parameters: ${*:2}"
1291 }
1292
1293 debug-print-section() {
1294         debug-print "now in section ${*}"
1295 }
1296
1297 # Sources all eclasses in parameters
1298 declare -ix ECLASS_DEPTH=0
1299 inherit() {
1300         ECLASS_DEPTH=$(($ECLASS_DEPTH + 1))
1301         if [[ ${ECLASS_DEPTH} > 1 ]]; then
1302                 debug-print "*** Multiple Inheritence (Level: ${ECLASS_DEPTH})"
1303         fi
1304
1305         if [[ -n $ECLASS && -n ${!__export_funcs_var} ]] ; then
1306                 echo "QA Notice: EXPORT_FUNCTIONS is called before inherit in" \
1307                         "$ECLASS.eclass. For compatibility with <=portage-2.1.6.7," \
1308                         "only call EXPORT_FUNCTIONS after inherit(s)." \
1309                         | fmt -w 75 | while read ; do eqawarn "$REPLY" ; done
1310         fi
1311
1312         local location
1313         local olocation
1314         local x
1315
1316         # These variables must be restored before returning.
1317         local PECLASS=$ECLASS
1318         local prev_export_funcs_var=$__export_funcs_var
1319
1320         local B_IUSE
1321         local B_REQUIRED_USE
1322         local B_DEPEND
1323         local B_RDEPEND
1324         local B_PDEPEND
1325         while [ "$1" ]; do
1326                 location="${ECLASSDIR}/${1}.eclass"
1327                 olocation=""
1328
1329                 export ECLASS="$1"
1330                 __export_funcs_var=__export_functions_$ECLASS_DEPTH
1331                 unset $__export_funcs_var
1332
1333                 if [ "${EBUILD_PHASE}" != "depend" ] && \
1334                         [[ ${EBUILD_PHASE} != *rm ]] && \
1335                         [[ ${EMERGE_FROM} != "binary" ]] ; then
1336                         # This is disabled in the *rm phases because they frequently give
1337                         # false alarms due to INHERITED in /var/db/pkg being outdated
1338                         # in comparison the the eclasses from the portage tree.
1339                         if ! hasq $ECLASS $INHERITED; then
1340                                 eqawarn "QA Notice: ECLASS '$ECLASS' inherited illegally in $CATEGORY/$PF $EBUILD_PHASE"
1341                         fi
1342                 fi
1343
1344                 # any future resolution code goes here
1345                 if [ -n "$PORTDIR_OVERLAY" ]; then
1346                         local overlay
1347                         for overlay in ${PORTDIR_OVERLAY}; do
1348                                 olocation="${overlay}/eclass/${1}.eclass"
1349                                 if [ -e "$olocation" ]; then
1350                                         location="${olocation}"
1351                                         debug-print "  eclass exists: ${location}"
1352                                 fi
1353                         done
1354                 fi
1355                 debug-print "inherit: $1 -> $location"
1356                 [ ! -e "$location" ] && die "${1}.eclass could not be found by inherit()"
1357
1358                 if [ "${location}" == "${olocation}" ] && \
1359                         ! hasq "${location}" ${EBUILD_OVERLAY_ECLASSES} ; then
1360                                 EBUILD_OVERLAY_ECLASSES="${EBUILD_OVERLAY_ECLASSES} ${location}"
1361                 fi
1362
1363                 #We need to back up the value of DEPEND and RDEPEND to B_DEPEND and B_RDEPEND
1364                 #(if set).. and then restore them after the inherit call.
1365
1366                 #turn off glob expansion
1367                 set -f
1368
1369                 # Retain the old data and restore it later.
1370                 unset B_IUSE B_REQUIRED_USE B_DEPEND B_RDEPEND B_PDEPEND
1371                 [ "${IUSE+set}"       = set ] && B_IUSE="${IUSE}"
1372                 [ "${REQUIRED_USE+set}" = set ] && B_REQUIRED_USE="${REQUIRED_USE}"
1373                 [ "${DEPEND+set}"     = set ] && B_DEPEND="${DEPEND}"
1374                 [ "${RDEPEND+set}"    = set ] && B_RDEPEND="${RDEPEND}"
1375                 [ "${PDEPEND+set}"    = set ] && B_PDEPEND="${PDEPEND}"
1376                 unset IUSE REQUIRED_USE DEPEND RDEPEND PDEPEND
1377                 #turn on glob expansion
1378                 set +f
1379
1380                 qa_source "$location" || die "died sourcing $location in inherit()"
1381                 
1382                 #turn off glob expansion
1383                 set -f
1384
1385                 # If each var has a value, append it to the global variable E_* to
1386                 # be applied after everything is finished. New incremental behavior.
1387                 [ "${IUSE+set}"       = set ] && export E_IUSE="${E_IUSE} ${IUSE}"
1388                 [ "${REQUIRED_USE+set}"       = set ] && export E_REQUIRED_USE="${E_REQUIRED_USE} ${REQUIRED_USE}"
1389                 [ "${DEPEND+set}"     = set ] && export E_DEPEND="${E_DEPEND} ${DEPEND}"
1390                 [ "${RDEPEND+set}"    = set ] && export E_RDEPEND="${E_RDEPEND} ${RDEPEND}"
1391                 [ "${PDEPEND+set}"    = set ] && export E_PDEPEND="${E_PDEPEND} ${PDEPEND}"
1392
1393                 [ "${B_IUSE+set}"     = set ] && IUSE="${B_IUSE}"
1394                 [ "${B_IUSE+set}"     = set ] || unset IUSE
1395                 
1396                 [ "${B_REQUIRED_USE+set}"     = set ] && REQUIRED_USE="${B_REQUIRED_USE}"
1397                 [ "${B_REQUIRED_USE+set}"     = set ] || unset REQUIRED_USE
1398
1399                 [ "${B_DEPEND+set}"   = set ] && DEPEND="${B_DEPEND}"
1400                 [ "${B_DEPEND+set}"   = set ] || unset DEPEND
1401
1402                 [ "${B_RDEPEND+set}"  = set ] && RDEPEND="${B_RDEPEND}"
1403                 [ "${B_RDEPEND+set}"  = set ] || unset RDEPEND
1404
1405                 [ "${B_PDEPEND+set}"  = set ] && PDEPEND="${B_PDEPEND}"
1406                 [ "${B_PDEPEND+set}"  = set ] || unset PDEPEND
1407
1408                 #turn on glob expansion
1409                 set +f
1410
1411                 if [[ -n ${!__export_funcs_var} ]] ; then
1412                         for x in ${!__export_funcs_var} ; do
1413                                 debug-print "EXPORT_FUNCTIONS: $x -> ${ECLASS}_$x"
1414                                 declare -F "${ECLASS}_$x" >/dev/null || \
1415                                         die "EXPORT_FUNCTIONS: ${ECLASS}_$x is not defined"
1416                                 eval "$x() { ${ECLASS}_$x \"\$@\" ; }" > /dev/null
1417                         done
1418                 fi
1419                 unset $__export_funcs_var
1420
1421                 hasq $1 $INHERITED || export INHERITED="$INHERITED $1"
1422
1423                 shift
1424         done
1425         ((--ECLASS_DEPTH)) # Returns 1 when ECLASS_DEPTH reaches 0.
1426         if (( ECLASS_DEPTH > 0 )) ; then
1427                 export ECLASS=$PECLASS
1428                 __export_funcs_var=$prev_export_funcs_var
1429         else
1430                 unset ECLASS __export_funcs_var
1431         fi
1432         return 0
1433 }
1434
1435 # Exports stub functions that call the eclass's functions, thereby making them default.
1436 # For example, if ECLASS="base" and you call "EXPORT_FUNCTIONS src_unpack", the following
1437 # code will be eval'd:
1438 # src_unpack() { base_src_unpack; }
1439 EXPORT_FUNCTIONS() {
1440         if [ -z "$ECLASS" ]; then
1441                 die "EXPORT_FUNCTIONS without a defined ECLASS"
1442         fi
1443         eval $__export_funcs_var+=\" $*\"
1444 }
1445
1446 # this is a function for removing any directory matching a passed in pattern from
1447 # PATH
1448 remove_path_entry() {
1449         save_IFS
1450         IFS=":"
1451         stripped_path="${PATH}"
1452         while [ -n "$1" ]; do
1453                 cur_path=""
1454                 for p in ${stripped_path}; do
1455                         if [ "${p/${1}}" == "${p}" ]; then
1456                                 cur_path="${cur_path}:${p}"
1457                         fi
1458                 done
1459                 stripped_path="${cur_path#:*}"
1460                 shift
1461         done
1462         restore_IFS
1463         PATH="${stripped_path}"
1464 }
1465
1466 # @FUNCTION: _ebuild_arg_to_phase
1467 # @DESCRIPTION:
1468 # Translate a known ebuild(1) argument into the precise
1469 # name of it's corresponding ebuild phase.
1470 _ebuild_arg_to_phase() {
1471         [ $# -ne 2 ] && die "expected exactly 2 args, got $#: $*"
1472         local eapi=$1
1473         local arg=$2
1474         local phase_func=""
1475
1476         case "$arg" in
1477                 pretend)
1478                         ! hasq $eapi 0 1 2 3 3_pre2 && \
1479                                 phase_func=pkg_pretend
1480                         ;;
1481                 setup)
1482                         phase_func=pkg_setup
1483                         ;;
1484                 nofetch)
1485                         phase_func=pkg_nofetch
1486                         ;;
1487                 unpack)
1488                         phase_func=src_unpack
1489                         ;;
1490                 prepare)
1491                         ! hasq $eapi 0 1 && \
1492                                 phase_func=src_prepare
1493                         ;;
1494                 configure)
1495                         ! hasq $eapi 0 1 && \
1496                                 phase_func=src_configure
1497                         ;;
1498                 compile)
1499                         phase_func=src_compile
1500                         ;;
1501                 test)
1502                         phase_func=src_test
1503                         ;;
1504                 install)
1505                         phase_func=src_install
1506                         ;;
1507                 preinst)
1508                         phase_func=pkg_preinst
1509                         ;;
1510                 postinst)
1511                         phase_func=pkg_postinst
1512                         ;;
1513                 prerm)
1514                         phase_func=pkg_prerm
1515                         ;;
1516                 postrm)
1517                         phase_func=pkg_postrm
1518                         ;;
1519         esac
1520
1521         [[ -z $phase_func ]] && return 1
1522         echo "$phase_func"
1523         return 0
1524 }
1525
1526 _ebuild_phase_funcs() {
1527         [ $# -ne 2 ] && die "expected exactly 2 args, got $#: $*"
1528         local eapi=$1
1529         local phase_func=$2
1530         local default_phases="pkg_nofetch src_unpack src_prepare src_configure
1531                 src_compile src_install src_test"
1532         local x y default_func=""
1533
1534         for x in pkg_nofetch src_unpack src_test ; do
1535                 declare -F $x >/dev/null || \
1536                         eval "$x() { _eapi0_$x \"\$@\" ; }"
1537         done
1538
1539         case $eapi in
1540
1541                 0|1)
1542
1543                         if ! declare -F src_compile >/dev/null ; then
1544                                 case $eapi in
1545                                         0)
1546                                                 src_compile() { _eapi0_src_compile "$@" ; }
1547                                                 ;;
1548                                         *)
1549                                                 src_compile() { _eapi1_src_compile "$@" ; }
1550                                                 ;;
1551                                 esac
1552                         fi
1553
1554                         for x in $default_phases ; do
1555                                 eval "default_$x() {
1556                                         die \"default_$x() is not supported with EAPI='$eapi' during phase $phase_func\"
1557                                 }"
1558                         done
1559
1560                         eval "default() {
1561                                 die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
1562                         }"
1563
1564                         ;;
1565
1566                 *)
1567
1568                         declare -F src_configure >/dev/null || \
1569                                 src_configure() { _eapi2_src_configure "$@" ; }
1570
1571                         declare -F src_compile >/dev/null || \
1572                                 src_compile() { _eapi2_src_compile "$@" ; }
1573
1574                         has $eapi 2 3 3_pre2 || declare -F src_install >/dev/null || \
1575                                 src_install() { _eapi4_src_install "$@" ; }
1576
1577                         if hasq $phase_func $default_phases ; then
1578
1579                                 _eapi2_pkg_nofetch   () { _eapi0_pkg_nofetch          "$@" ; }
1580                                 _eapi2_src_unpack    () { _eapi0_src_unpack           "$@" ; }
1581                                 _eapi2_src_prepare   () { true                             ; }
1582                                 _eapi2_src_test      () { _eapi0_src_test             "$@" ; }
1583                                 _eapi2_src_install   () { die "$FUNCNAME is not supported" ; }
1584
1585                                 for x in $default_phases ; do
1586                                         eval "default_$x() { _eapi2_$x \"\$@\" ; }"
1587                                 done
1588
1589                                 eval "default() { _eapi2_$phase_func \"\$@\" ; }"
1590
1591                                 case $eapi in
1592                                         2|3)
1593                                                 ;;
1594                                         *)
1595                                                 eval "default_src_install() { _eapi4_src_install \"\$@\" ; }"
1596                                                 [[ $phase_func = src_install ]] && \
1597                                                         eval "default() { _eapi4_$phase_func \"\$@\" ; }"
1598                                                 ;;
1599                                 esac
1600
1601                         else
1602
1603                                 for x in $default_phases ; do
1604                                         eval "default_$x() {
1605                                                 die \"default_$x() is not supported in phase $default_func\"
1606                                         }"
1607                                 done
1608
1609                                 eval "default() {
1610                                         die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
1611                                 }"
1612
1613                         fi
1614
1615                         ;;
1616         esac
1617 }
1618
1619 PORTAGE_BASHRCS_SOURCED=0
1620
1621 # @FUNCTION: source_all_bashrcs
1622 # @DESCRIPTION:
1623 # Source a relevant bashrc files and perform other miscellaneous
1624 # environment initialization when appropriate.
1625 #
1626 # If EAPI is set then define functions provided by the current EAPI:
1627 #
1628 #  * default_* aliases for the current EAPI phase functions
1629 #  * A "default" function which is an alias for the default phase
1630 #    function for the current phase.
1631 #
1632 source_all_bashrcs() {
1633         [[ $PORTAGE_BASHRCS_SOURCED = 1 ]] && return 0
1634         PORTAGE_BASHRCS_SOURCED=1
1635         local x
1636
1637         local OCC="${CC}" OCXX="${CXX}"
1638
1639         if [[ $EBUILD_PHASE != depend ]] ; then
1640                 # source the existing profile.bashrcs.
1641                 save_IFS
1642                 IFS=$'\n'
1643                 local path_array=($PROFILE_PATHS)
1644                 restore_IFS
1645                 for x in "${path_array[@]}" ; do
1646                         [ -f "$x/profile.bashrc" ] && qa_source "$x/profile.bashrc"
1647                 done
1648         fi
1649
1650         # We assume if people are changing shopts in their bashrc they do so at their
1651         # own peril.  This is the ONLY non-portage bit of code that can change shopts
1652         # without a QA violation.
1653         for x in "${PORTAGE_BASHRC}" "${PM_EBUILD_HOOK_DIR}"/${CATEGORY}/{${PN},${PN}:${SLOT},${P},${PF}}; do
1654                 if [ -r "${x}" ]; then
1655                         # If $- contains x, then tracing has already enabled elsewhere for some
1656                         # reason.  We preserve it's state so as not to interfere.
1657                         if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then
1658                                 source "${x}"
1659                         else
1660                                 set -x
1661                                 source "${x}"
1662                                 set +x
1663                         fi
1664                 fi
1665         done
1666
1667         [ ! -z "${OCC}" ] && export CC="${OCC}"
1668         [ ! -z "${OCXX}" ] && export CXX="${OCXX}"
1669 }
1670
1671 # Hardcoded bash lists are needed for backward compatibility with
1672 # <portage-2.1.4 since they assume that a newly installed version
1673 # of ebuild.sh will work for pkg_postinst, pkg_prerm, and pkg_postrm
1674 # when portage is upgrading itself.
1675
1676 PORTAGE_READONLY_METADATA="DEFINED_PHASES DEPEND DESCRIPTION
1677         EAPI HOMEPAGE INHERITED IUSE REQUIRED_USE KEYWORDS LICENSE
1678         PDEPEND PROVIDE RDEPEND RESTRICT SLOT SRC_URI"
1679
1680 PORTAGE_READONLY_VARS="D EBUILD EBUILD_PHASE \
1681         EBUILD_SH_ARGS ECLASSDIR EMERGE_FROM FILESDIR MERGE_TYPE \
1682         PM_EBUILD_HOOK_DIR \
1683         PORTAGE_ACTUAL_DISTDIR PORTAGE_ARCHLIST PORTAGE_BASHRC  \
1684         PORTAGE_BINPKG_FILE PORTAGE_BINPKG_TAR_OPTS PORTAGE_BINPKG_TMPFILE \
1685         PORTAGE_BIN_PATH PORTAGE_BUILDDIR PORTAGE_BUNZIP2_COMMAND \
1686         PORTAGE_BZIP2_COMMAND PORTAGE_COLORMAP PORTAGE_CONFIGROOT \
1687         PORTAGE_DEBUG PORTAGE_DEPCACHEDIR PORTAGE_EBUILD_EXIT_FILE \
1688         PORTAGE_GID PORTAGE_GRPNAME PORTAGE_INST_GID PORTAGE_INST_UID \
1689         PORTAGE_IPC_DAEMON PORTAGE_IUSE PORTAGE_LOG_FILE \
1690         PORTAGE_MUTABLE_FILTERED_VARS PORTAGE_PYM_PATH PORTAGE_PYTHON \
1691         PORTAGE_READONLY_METADATA PORTAGE_READONLY_VARS \
1692         PORTAGE_REPO_NAME PORTAGE_RESTRICT PORTAGE_SANDBOX_COMPAT_LEVEL \
1693         PORTAGE_SAVED_READONLY_VARS PORTAGE_SIGPIPE_STATUS \
1694         PORTAGE_TMPDIR PORTAGE_UPDATE_ENV PORTAGE_USERNAME \
1695         PORTAGE_VERBOSE PORTAGE_WORKDIR_MODE PORTDIR PORTDIR_OVERLAY \
1696         PROFILE_PATHS REPLACING_VERSIONS REPLACED_BY_VERSION T WORKDIR"
1697
1698 PORTAGE_SAVED_READONLY_VARS="A CATEGORY P PF PN PR PV PVR"
1699
1700 # Variables that portage sets but doesn't mark readonly.
1701 # In order to prevent changed values from causing unexpected
1702 # interference, they are filtered out of the environment when
1703 # it is saved or loaded (any mutations do not persist).
1704 PORTAGE_MUTABLE_FILTERED_VARS="AA HOSTNAME"
1705
1706 # @FUNCTION: filter_readonly_variables
1707 # @DESCRIPTION: [--filter-sandbox] [--allow-extra-vars]
1708 # Read an environment from stdin and echo to stdout while filtering variables
1709 # with names that are known to cause interference:
1710 #
1711 #   * some specific variables for which bash does not allow assignment
1712 #   * some specific variables that affect portage or sandbox behavior
1713 #   * variable names that begin with a digit or that contain any
1714 #     non-alphanumeric characters that are not be supported by bash
1715 #
1716 # --filter-sandbox causes all SANDBOX_* variables to be filtered, which
1717 # is only desired in certain cases, such as during preprocessing or when
1718 # saving environment.bz2 for a binary or installed package.
1719 #
1720 # --filter-features causes the special FEATURES variable to be filtered.
1721 # Generally, we want it to persist between phases since the user might
1722 # want to modify it via bashrc to enable things like splitdebug and
1723 # installsources for specific packages. They should be able to modify it
1724 # in pre_pkg_setup() and have it persist all the way through the install
1725 # phase. However, if FEATURES exist inside environment.bz2 then they
1726 # should be overridden by current settings.
1727 #
1728 # --filter-locale causes locale related variables such as LANG and LC_*
1729 # variables to be filtered. These variables should persist between phases,
1730 # in case they are modified by the ebuild. However, the current user
1731 # settings should be used when loading the environment from a binary or
1732 # installed package.
1733 #
1734 # --filter-path causes the PATH variable to be filtered. This variable
1735 # should persist between phases, in case it is modified by the ebuild.
1736 # However, old settings should be overridden when loading the
1737 # environment from a binary or installed package.
1738 #
1739 # ---allow-extra-vars causes some extra vars to be allowd through, such
1740 # as ${PORTAGE_SAVED_READONLY_VARS} and ${PORTAGE_MUTABLE_FILTERED_VARS}.
1741 #
1742 # In bash-3.2_p20+ an attempt to assign BASH_*, FUNCNAME, GROUPS or any
1743 # readonly variable cause the shell to exit while executing the "source"
1744 # builtin command. To avoid this problem, this function filters those
1745 # variables out and discards them. See bug #190128.
1746 filter_readonly_variables() {
1747         local x filtered_vars
1748         local readonly_bash_vars="BASHOPTS BASHPID DIRSTACK EUID
1749                 FUNCNAME GROUPS PIPESTATUS PPID SHELLOPTS UID"
1750         local bash_misc_vars="BASH BASH_.* COMP_WORDBREAKS HISTCMD
1751                 HISTFILE HOSTNAME HOSTTYPE IFS LINENO MACHTYPE OLDPWD
1752                 OPTERR OPTIND OSTYPE POSIXLY_CORRECT PS4 PWD RANDOM
1753                 SECONDS SHELL SHLVL"
1754         local filtered_sandbox_vars="SANDBOX_ACTIVE SANDBOX_BASHRC
1755                 SANDBOX_DEBUG_LOG SANDBOX_DISABLED SANDBOX_LIB
1756                 SANDBOX_LOG SANDBOX_ON"
1757         local misc_garbage_vars="_portage_filter_opts"
1758         filtered_vars="$readonly_bash_vars $bash_misc_vars
1759                 $PORTAGE_READONLY_VARS $misc_garbage_vars"
1760
1761         # Don't filter/interfere with prefix variables unless they are
1762         # supported by the current EAPI.
1763         case "${EAPI:-0}" in
1764                 0|1|2)
1765                         ;;
1766                 *)
1767                         filtered_vars+=" ED EPREFIX EROOT"
1768                         ;;
1769         esac
1770
1771         if hasq --filter-sandbox $* ; then
1772                 filtered_vars="${filtered_vars} SANDBOX_.*"
1773         else
1774                 filtered_vars="${filtered_vars} ${filtered_sandbox_vars}"
1775         fi
1776         if hasq --filter-features $* ; then
1777                 filtered_vars="${filtered_vars} FEATURES PORTAGE_FEATURES"
1778         fi
1779         if hasq --filter-path $* ; then
1780                 filtered_vars+=" PATH"
1781         fi
1782         if hasq --filter-locale $* ; then
1783                 filtered_vars+=" LANG LC_ALL LC_COLLATE
1784                         LC_CTYPE LC_MESSAGES LC_MONETARY
1785                         LC_NUMERIC LC_PAPER LC_TIME"
1786         fi
1787         if ! hasq --allow-extra-vars $* ; then
1788                 filtered_vars="
1789                         ${filtered_vars}
1790                         ${PORTAGE_SAVED_READONLY_VARS}
1791                         ${PORTAGE_MUTABLE_FILTERED_VARS}
1792                 "
1793         fi
1794
1795         "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}" || die "filter-bash-environment.py failed"
1796 }
1797
1798 # @FUNCTION: preprocess_ebuild_env
1799 # @DESCRIPTION:
1800 # Filter any readonly variables from ${T}/environment, source it, and then
1801 # save it via save_ebuild_env(). This process should be sufficient to prevent
1802 # any stale variables or functions from an arbitrary environment from
1803 # interfering with the current environment. This is useful when an existing
1804 # environment needs to be loaded from a binary or installed package.
1805 preprocess_ebuild_env() {
1806         local _portage_filter_opts=""
1807         if [ -f "${T}/environment.raw" ] ; then
1808                 # This is a signal from the python side, indicating that the
1809                 # environment may contain stale SANDBOX_{DENY,PREDICT,READ,WRITE}
1810                 # and FEATURES variables that should be filtered out. Between
1811                 # phases, these variables are normally preserved.
1812                 _portage_filter_opts+=" --filter-features --filter-locale --filter-path --filter-sandbox"
1813         fi
1814         filter_readonly_variables $_portage_filter_opts < "${T}"/environment \
1815                 > "${T}"/environment.filtered || return $?
1816         unset _portage_filter_opts
1817         mv "${T}"/environment.filtered "${T}"/environment || return $?
1818         rm -f "${T}/environment.success" || return $?
1819         # WARNING: Code inside this subshell should avoid making assumptions
1820         # about variables or functions after source "${T}"/environment has been
1821         # called. Any variables that need to be relied upon should already be
1822         # filtered out above.
1823         (
1824                 export SANDBOX_ON=1
1825                 source "${T}/environment" || exit $?
1826                 # We have to temporarily disable sandbox since the
1827                 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
1828                 # may be unusable (triggering in spurious sandbox violations)
1829                 # until we've merged them with our current values.
1830                 export SANDBOX_ON=0
1831
1832                 # It's remotely possible that save_ebuild_env() has been overridden
1833                 # by the above source command. To protect ourselves, we override it
1834                 # here with our own version. ${PORTAGE_BIN_PATH} is safe to use here
1835                 # because it's already filtered above.
1836                 source "${PORTAGE_BIN_PATH}/isolated-functions.sh" || exit $?
1837
1838                 # Rely on save_ebuild_env() to filter out any remaining variables
1839                 # and functions that could interfere with the current environment.
1840                 save_ebuild_env || exit $?
1841                 touch "${T}/environment.success" || exit $?
1842         ) > "${T}/environment.filtered"
1843         local retval
1844         if [ -e "${T}/environment.success" ] ; then
1845                 filter_readonly_variables --filter-features < \
1846                         "${T}/environment.filtered" > "${T}/environment"
1847                 retval=$?
1848         else
1849                 retval=1
1850         fi
1851         rm -f "${T}"/environment.{filtered,raw,success}
1852         return ${retval}
1853 }
1854
1855 # === === === === === === === === === === === === === === === === === ===
1856 # === === === === === functions end, main part begins === === === === ===
1857 # === === === === === functions end, main part begins === === === === ===
1858 # === === === === === functions end, main part begins === === === === ===
1859 # === === === === === === === === === === === === === === === === === ===
1860
1861 export SANDBOX_ON="1"
1862 export S=${WORKDIR}/${P}
1863
1864 unset E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND
1865
1866 # Turn of extended glob matching so that g++ doesn't get incorrectly matched.
1867 shopt -u extglob
1868
1869 if [[ ${EBUILD_PHASE} == depend ]] ; then
1870         QA_INTERCEPTORS="awk bash cc egrep equery fgrep g++
1871                 gawk gcc grep javac java-config nawk perl
1872                 pkg-config python python-config sed"
1873 elif [[ ${EBUILD_PHASE} == clean* ]] ; then
1874         unset QA_INTERCEPTORS
1875 else
1876         QA_INTERCEPTORS="autoconf automake aclocal libtoolize"
1877 fi
1878 # level the QA interceptors if we're in depend
1879 if [[ -n ${QA_INTERCEPTORS} ]] ; then
1880         for BIN in ${QA_INTERCEPTORS}; do
1881                 BIN_PATH=$(type -Pf ${BIN})
1882                 if [ "$?" != "0" ]; then
1883                         BODY="echo \"*** missing command: ${BIN}\" >&2; return 127"
1884                 else
1885                         BODY="${BIN_PATH} \"\$@\"; return \$?"
1886                 fi
1887                 if [[ ${EBUILD_PHASE} == depend ]] ; then
1888                         FUNC_SRC="${BIN}() {
1889                                 if [ \$ECLASS_DEPTH -gt 0 ]; then
1890                                         eqawarn \"QA Notice: '${BIN}' called in global scope: eclass \${ECLASS}\"
1891                                 else
1892                                         eqawarn \"QA Notice: '${BIN}' called in global scope: \${CATEGORY}/\${PF}\"
1893                                 fi
1894                         ${BODY}
1895                         }"
1896                 elif hasq ${BIN} autoconf automake aclocal libtoolize ; then
1897                         FUNC_SRC="${BIN}() {
1898                                 if ! hasq \${FUNCNAME[1]} eautoreconf eaclocal _elibtoolize \\
1899                                         eautoheader eautoconf eautomake autotools_run_tool \\
1900                                         autotools_check_macro autotools_get_subdirs \\
1901                                         autotools_get_auxdir ; then
1902                                         eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
1903                                         eqawarn \"Use autotools.eclass instead of calling '${BIN}' directly.\"
1904                                 fi
1905                         ${BODY}
1906                         }"
1907                 else
1908                         FUNC_SRC="${BIN}() {
1909                                 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
1910                         ${BODY}
1911                         }"
1912                 fi
1913                 eval "$FUNC_SRC" || echo "error creating QA interceptor ${BIN}" >&2
1914         done
1915         unset BIN_PATH BIN BODY FUNC_SRC
1916 fi
1917
1918 # Subshell/helper die support (must export for the die helper).
1919 export EBUILD_MASTER_PID=$BASHPID
1920 trap 'exit 1' SIGTERM
1921
1922 if ! hasq "$EBUILD_PHASE" clean cleanrm depend && \
1923         [ -f "${T}"/environment ] ; then
1924         # The environment may have been extracted from environment.bz2 or
1925         # may have come from another version of ebuild.sh or something.
1926         # In any case, preprocess it to prevent any potential interference.
1927         preprocess_ebuild_env || \
1928                 die "error processing environment"
1929         # Colon separated SANDBOX_* variables need to be cumulative.
1930         for x in SANDBOX_DENY SANDBOX_READ SANDBOX_PREDICT SANDBOX_WRITE ; do
1931                 export PORTAGE_${x}=${!x}
1932         done
1933         PORTAGE_SANDBOX_ON=${SANDBOX_ON}
1934         export SANDBOX_ON=1
1935         source "${T}"/environment || \
1936                 die "error sourcing environment"
1937         # We have to temporarily disable sandbox since the
1938         # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
1939         # may be unusable (triggering in spurious sandbox violations)
1940         # until we've merged them with our current values.
1941         export SANDBOX_ON=0
1942         for x in SANDBOX_DENY SANDBOX_PREDICT SANDBOX_READ SANDBOX_WRITE ; do
1943                 y="PORTAGE_${x}"
1944                 if [ -z "${!x}" ] ; then
1945                         export ${x}=${!y}
1946                 elif [ -n "${!y}" ] && [ "${!y}" != "${!x}" ] ; then
1947                         # filter out dupes
1948                         export ${x}=$(printf "${!y}:${!x}" | tr ":" "\0" | \
1949                                 sort -z -u | tr "\0" ":")
1950                 fi
1951                 export ${x}=${!x%:}
1952                 unset PORTAGE_${x}
1953         done
1954         unset x y
1955         export SANDBOX_ON=${PORTAGE_SANDBOX_ON}
1956         unset PORTAGE_SANDBOX_ON
1957         [[ -n $EAPI ]] || EAPI=0
1958 fi
1959
1960 if ! hasq "$EBUILD_PHASE" clean cleanrm ; then
1961         if [[ $EBUILD_PHASE = depend || ! -f $T/environment || \
1962                 -f $PORTAGE_BUILDDIR/.ebuild_changed ]] || \
1963                 hasq noauto $FEATURES ; then
1964                 # The bashrcs get an opportunity here to set aliases that will be expanded
1965                 # during sourcing of ebuilds and eclasses.
1966                 source_all_bashrcs
1967
1968                 # *DEPEND and IUSE will be set during the sourcing of the ebuild.
1969                 # In order to ensure correct interaction between ebuilds and
1970                 # eclasses, they need to be unset before this process of
1971                 # interaction begins.
1972                 unset DEPEND RDEPEND PDEPEND IUSE REQUIRED_USE
1973
1974                 if [[ $PORTAGE_DEBUG != 1 || ${-/x/} != $- ]] ; then
1975                         source "$EBUILD" || die "error sourcing ebuild"
1976                 else
1977                         set -x
1978                         source "$EBUILD" || die "error sourcing ebuild"
1979                         set +x
1980                 fi
1981
1982                 if [[ "${EBUILD_PHASE}" != "depend" ]] ; then
1983                         RESTRICT=${PORTAGE_RESTRICT}
1984                         [[ -e $PORTAGE_BUILDDIR/.ebuild_changed ]] && \
1985                         rm "$PORTAGE_BUILDDIR/.ebuild_changed"
1986                 fi
1987
1988                 [[ -n $EAPI ]] || EAPI=0
1989
1990                 if has "$EAPI" 0 1 2 3 3_pre2 ; then
1991                         export RDEPEND=${RDEPEND-${DEPEND}}
1992                         debug-print "RDEPEND: not set... Setting to: ${DEPEND}"
1993                 fi
1994
1995                 # add in dependency info from eclasses
1996                 IUSE="${IUSE} ${E_IUSE}"
1997                 DEPEND="${DEPEND} ${E_DEPEND}"
1998                 RDEPEND="${RDEPEND} ${E_RDEPEND}"
1999                 PDEPEND="${PDEPEND} ${E_PDEPEND}"
2000                 REQUIRED_USE="${REQUIRED_USE} ${E_REQUIRED_USE}"
2001                 
2002                 unset ECLASS E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND 
2003
2004                 # alphabetically ordered by $EBUILD_PHASE value
2005                 case "$EAPI" in
2006                         0|1)
2007                                 _valid_phases="src_compile pkg_config pkg_info src_install
2008                                         pkg_nofetch pkg_postinst pkg_postrm pkg_preinst pkg_prerm
2009                                         pkg_setup src_test src_unpack"
2010                                 ;;
2011                         2|3|3_pre2)
2012                                 _valid_phases="src_compile pkg_config src_configure pkg_info
2013                                         src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst
2014                                         src_prepare pkg_prerm pkg_setup src_test src_unpack"
2015                                 ;;
2016                         *)
2017                                 _valid_phases="src_compile pkg_config src_configure pkg_info
2018                                         src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst
2019                                         src_prepare pkg_prerm pkg_pretend pkg_setup src_test src_unpack"
2020                                 ;;
2021                 esac
2022
2023                 DEFINED_PHASES=
2024                 for _f in $_valid_phases ; do
2025                         if declare -F $_f >/dev/null ; then
2026                                 _f=${_f#pkg_}
2027                                 DEFINED_PHASES+=" ${_f#src_}"
2028                         fi
2029                 done
2030                 [[ -n $DEFINED_PHASES ]] || DEFINED_PHASES=-
2031
2032                 unset _f _valid_phases
2033
2034                 if [[ $EBUILD_PHASE != depend ]] ; then
2035
2036                         case "$EAPI" in
2037                                 0|1|2|3)
2038                                         _ebuild_helpers_path="$PORTAGE_BIN_PATH/ebuild-helpers"
2039                                         ;;
2040                                 *)
2041                                         _ebuild_helpers_path="$PORTAGE_BIN_PATH/ebuild-helpers/4:$PORTAGE_BIN_PATH/ebuild-helpers"
2042                                         ;;
2043                         esac
2044
2045                         PATH=$_ebuild_helpers_path:$PREROOTPATH${PREROOTPATH:+:}/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin${ROOTPATH:+:}$ROOTPATH
2046                         unset _ebuild_helpers_path
2047
2048                         if hasq distcc $FEATURES ; then
2049                                 PATH="/usr/lib/distcc/bin:$PATH"
2050                                 [[ -n $DISTCC_LOG ]] && addwrite "${DISTCC_LOG%/*}"
2051                         fi
2052
2053                         if hasq ccache $FEATURES ; then
2054                                 PATH="/usr/lib/ccache/bin:$PATH"
2055
2056                                 if [[ -n $CCACHE_DIR ]] ; then
2057                                         addread "$CCACHE_DIR"
2058                                         addwrite "$CCACHE_DIR"
2059                                 fi
2060
2061                                 [[ -n $CCACHE_SIZE ]] && ccache -M $CCACHE_SIZE &> /dev/null
2062                         fi
2063                 fi
2064
2065                 if [[ -n $QA_PREBUILT ]] ; then
2066
2067                         # these ones support fnmatch patterns
2068                         QA_EXECSTACK+=" $QA_PREBUILT"
2069                         QA_TEXTRELS+=" $QA_PREBUILT"
2070                         QA_WX_LOAD+=" $QA_PREBUILT"
2071
2072                         # these ones support regular expressions, so translate
2073                         # fnmatch patterns to regular expressions
2074                         for x in QA_DT_HASH QA_DT_NEEDED QA_PRESTRIPPED QA_SONAME ; do
2075                                 if [[ $(declare -p $x 2>/dev/null) = declare\ -a* ]] ; then
2076                                         eval "$x=(\"\${$x[@]}\" ${QA_PREBUILT//\*/.*})"
2077                                 else
2078                                         eval "$x+=\" ${QA_PREBUILT//\*/.*}\""
2079                                 fi
2080                         done
2081
2082                         unset x
2083                 fi
2084
2085                 # This needs to be exported since prepstrip is a separate shell script.
2086                 [[ -n $QA_PRESTRIPPED ]] && export QA_PRESTRIPPED
2087                 eval "[[ -n \$QA_PRESTRIPPED_${ARCH/-/_} ]] && export QA_PRESTRIPPED_${ARCH/-/_}"
2088         fi
2089 fi
2090
2091 # unset USE_EXPAND variables that contain only the special "*" token
2092 for x in ${USE_EXPAND} ; do
2093         [ "${!x}" == "*" ] && unset ${x}
2094 done
2095 unset x
2096
2097 if hasq nostrip ${FEATURES} ${RESTRICT} || hasq strip ${RESTRICT}
2098 then
2099         export DEBUGBUILD=1
2100 fi
2101
2102 #a reasonable default for $S
2103 [[ -z ${S} ]] && export S=${WORKDIR}/${P}
2104
2105 # Note: readonly variables interfere with preprocess_ebuild_env(), so
2106 # declare them only after it has already run.
2107 if [ "${EBUILD_PHASE}" != "depend" ] ; then
2108         declare -r $PORTAGE_READONLY_METADATA $PORTAGE_READONLY_VARS
2109         case "$EAPI" in
2110                 0|1|2)
2111                         ;;
2112                 *)
2113                         declare -r ED EPREFIX EROOT
2114                         ;;
2115         esac
2116 fi
2117
2118 ebuild_main() {
2119
2120         # Subshell/helper die support (must export for the die helper).
2121         # Since this function is typically executed in a subshell,
2122         # setup EBUILD_MASTER_PID to refer to the current $BASHPID,
2123         # which seems to give the best results when further
2124         # nested subshells call die.
2125         export EBUILD_MASTER_PID=$BASHPID
2126         trap 'exit 1' SIGTERM
2127
2128         if [[ $EBUILD_PHASE != depend ]] ; then
2129                 # Force configure scripts that automatically detect ccache to
2130                 # respect FEATURES="-ccache".
2131                 hasq ccache $FEATURES || export CCACHE_DISABLE=1
2132
2133                 local phase_func=$(_ebuild_arg_to_phase "$EAPI" "$EBUILD_PHASE")
2134                 [[ -n $phase_func ]] && _ebuild_phase_funcs "$EAPI" "$phase_func"
2135                 unset phase_func
2136         fi
2137
2138         source_all_bashrcs
2139
2140         case ${EBUILD_SH_ARGS} in
2141         nofetch)
2142                 ebuild_phase_with_hooks pkg_nofetch
2143                 ;;
2144         prerm|postrm|postinst|config|info)
2145                 if hasq "$EBUILD_SH_ARGS" config info && \
2146                         ! declare -F "pkg_$EBUILD_SH_ARGS" >/dev/null ; then
2147                         ewarn  "pkg_${EBUILD_SH_ARGS}() is not defined: '${EBUILD##*/}'"
2148                 fi
2149                 export SANDBOX_ON="0"
2150                 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
2151                         ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
2152                 else
2153                         set -x
2154                         ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
2155                         set +x
2156                 fi
2157                 if [[ $EBUILD_PHASE == postinst ]] && [[ -n $PORTAGE_UPDATE_ENV ]]; then
2158                         # Update environment.bz2 in case installation phases
2159                         # need to pass some variables to uninstallation phases.
2160                         save_ebuild_env --exclude-init-phases | \
2161                                 filter_readonly_variables --filter-path \
2162                                 --filter-sandbox --allow-extra-vars \
2163                                 | ${PORTAGE_BZIP2_COMMAND} -c -f9 > "$PORTAGE_UPDATE_ENV"
2164                         assert "save_ebuild_env failed"
2165                 fi
2166                 ;;
2167         unpack|prepare|configure|compile|test|clean|install)
2168                 if [[ ${SANDBOX_DISABLED:-0} = 0 ]] ; then
2169                         export SANDBOX_ON="1"
2170                 else
2171                         export SANDBOX_ON="0"
2172                 fi
2173
2174                 case "$EBUILD_SH_ARGS" in
2175                 configure|compile)
2176
2177                         local x
2178                         for x in ASFLAGS CCACHE_DIR CCACHE_SIZE \
2179                                 CFLAGS CXXFLAGS LDFLAGS LIBCFLAGS LIBCXXFLAGS ; do
2180                                 [[ ${!x+set} = set ]] && export $x
2181                         done
2182                         unset x
2183
2184                         hasq distcc $FEATURES && [[ -n $DISTCC_DIR ]] && \
2185                                 [[ ${SANDBOX_WRITE/$DISTCC_DIR} = $SANDBOX_WRITE ]] && \
2186                                 addwrite "$DISTCC_DIR"
2187
2188                         x=LIBDIR_$ABI
2189                         [ -z "$PKG_CONFIG_PATH" -a -n "$ABI" -a -n "${!x}" ] && \
2190                                 export PKG_CONFIG_PATH=/usr/${!x}/pkgconfig
2191
2192                         if hasq noauto $FEATURES && \
2193                                 [[ ! -f $PORTAGE_BUILDDIR/.unpacked ]] ; then
2194                                 echo
2195                                 echo "!!! We apparently haven't unpacked..." \
2196                                         "This is probably not what you"
2197                                 echo "!!! want to be doing... You are using" \
2198                                         "FEATURES=noauto so I'll assume"
2199                                 echo "!!! that you know what you are doing..." \
2200                                         "You have 5 seconds to abort..."
2201                                 echo
2202
2203                                 local x
2204                                 for x in 1 2 3 4 5 6 7 8; do
2205                                         LC_ALL=C sleep 0.25
2206                                 done
2207
2208                                 sleep 3
2209                         fi
2210
2211                         cd "$PORTAGE_BUILDDIR"
2212                         if [ ! -d build-info ] ; then
2213                                 mkdir build-info
2214                                 cp "$EBUILD" "build-info/$PF.ebuild"
2215                         fi
2216
2217                         #our custom version of libtool uses $S and $D to fix
2218                         #invalid paths in .la files
2219                         export S D
2220                         #some packages use an alternative to $S to build in, cause
2221                         #our libtool to create problematic .la files
2222                         export PWORKDIR=$WORKDIR
2223
2224                         ;;
2225                 esac
2226
2227                 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
2228                         dyn_${EBUILD_SH_ARGS}
2229                 else
2230                         set -x
2231                         dyn_${EBUILD_SH_ARGS}
2232                         set +x
2233                 fi
2234                 export SANDBOX_ON="0"
2235                 ;;
2236         help|pretend|setup|preinst)
2237                 #pkg_setup needs to be out of the sandbox for tmp file creation;
2238                 #for example, awking and piping a file in /tmp requires a temp file to be created
2239                 #in /etc.  If pkg_setup is in the sandbox, both our lilo and apache ebuilds break.
2240                 export SANDBOX_ON="0"
2241                 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
2242                         dyn_${EBUILD_SH_ARGS}
2243                 else
2244                         set -x
2245                         dyn_${EBUILD_SH_ARGS}
2246                         set +x
2247                 fi
2248                 ;;
2249         depend)
2250                 export SANDBOX_ON="0"
2251                 set -f
2252
2253                 if [ -n "${dbkey}" ] ; then
2254                         if [ ! -d "${dbkey%/*}" ]; then
2255                                 install -d -g ${PORTAGE_GID} -m2775 "${dbkey%/*}"
2256                         fi
2257                         # Make it group writable. 666&~002==664
2258                         umask 002
2259                 fi
2260
2261                 auxdbkeys="DEPEND RDEPEND SLOT SRC_URI RESTRICT HOMEPAGE LICENSE
2262                         DESCRIPTION KEYWORDS INHERITED IUSE REQUIRED_USE PDEPEND PROVIDE EAPI
2263                         PROPERTIES DEFINED_PHASES UNUSED_05 UNUSED_04
2264                         UNUSED_03 UNUSED_02 UNUSED_01"
2265
2266                 #the extra $(echo) commands remove newlines
2267                 [ -n "${EAPI}" ] || EAPI=0
2268
2269                 if [ -n "${dbkey}" ] ; then
2270                         > "${dbkey}"
2271                         for f in ${auxdbkeys} ; do
2272                                 echo $(echo ${!f}) >> "${dbkey}" || exit $?
2273                         done
2274                 else
2275                         for f in ${auxdbkeys} ; do
2276                                 echo $(echo ${!f}) 1>&9 || exit $?
2277                         done
2278                         exec 9>&-
2279                 fi
2280                 set +f
2281                 ;;
2282         _internal_test)
2283                 ;;
2284         *)
2285                 export SANDBOX_ON="1"
2286                 echo "Unrecognized EBUILD_SH_ARGS: '${EBUILD_SH_ARGS}'"
2287                 echo
2288                 dyn_help
2289                 exit 1
2290                 ;;
2291         esac
2292 }
2293
2294 if [[ -s $SANDBOX_LOG ]] ; then
2295         # We use SANDBOX_LOG to check for sandbox violations,
2296         # so we ensure that there can't be a stale log to
2297         # interfere with our logic.
2298         x=
2299         if [[ -n SANDBOX_ON ]] ; then
2300                 x=$SANDBOX_ON
2301                 export SANDBOX_ON=0
2302         fi
2303
2304         rm -f "$SANDBOX_LOG" || \
2305                 die "failed to remove stale sandbox log: '$SANDBOX_LOG'"
2306
2307         if [[ -n $x ]] ; then
2308                 export SANDBOX_ON=$x
2309         fi
2310         unset x
2311 fi
2312
2313 if [[ $EBUILD_PHASE = depend ]] ; then
2314         ebuild_main
2315 elif [[ -n $EBUILD_SH_ARGS ]] ; then
2316         (
2317                 # Don't allow subprocesses to inherit the pipe which
2318                 # emerge uses to monitor ebuild.sh.
2319                 exec 9>&-
2320
2321                 ebuild_main
2322
2323                 # Save the env only for relevant phases.
2324                 if ! hasq "$EBUILD_SH_ARGS" clean help info nofetch ; then
2325                         umask 002
2326                         save_ebuild_env | filter_readonly_variables \
2327                                 --filter-features > "$T/environment"
2328                         assert "save_ebuild_env failed"
2329                         chown portage:portage "$T/environment" &>/dev/null
2330                         chmod g+w "$T/environment" &>/dev/null
2331                 fi
2332                 [[ -n $PORTAGE_EBUILD_EXIT_FILE ]] && > "$PORTAGE_EBUILD_EXIT_FILE"
2333                 if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
2334                         [[ ! -s $SANDBOX_LOG ]]
2335                         "$PORTAGE_BIN_PATH"/ebuild-ipc exit $?
2336                 fi
2337                 exit 0
2338         )
2339         exit $?
2340 fi
2341
2342 # Do not exit when ebuild.sh is sourced by other scripts.
2343 true