2 # Copyright 1999-2010 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
5 PORTAGE_BIN_PATH="${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"
6 PORTAGE_PYM_PATH="${PORTAGE_PYM_PATH:-/usr/lib/portage/pym}"
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"
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.
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
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}
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
41 local shopts=$(shopt) OLDIFS="$IFS"
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 '$*'"
54 local shopts=$(shopt) OLDIFS="$IFS"
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 '$*'"
70 # Prevent aliases from causing portage to act inappropriately.
71 # Make sure it's before everything so we don't mess aliases that follow.
74 # Unset some variables that break things.
75 unset GZIP BZIP BZIP2 CDPATH GREP_OPTIONS GREP_COLOR GLOBIGNORE
77 source "${PORTAGE_BIN_PATH}/isolated-functions.sh" &>/dev/null
79 [[ $PORTAGE_QUIET != "" ]] && export PORTAGE_QUIET
81 # sandbox support functions; defined prior to profile.bashrc srcing, since the profile might need to add a default exception (/usr/lib64/conftest fex)
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"
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 "$@" ; }
97 addwrite "${PORTAGE_TMPDIR}"
98 addread "/:${PORTAGE_TMPDIR}"
99 [[ -n ${PORTAGE_GPG_DIR} ]] && addpredict "${PORTAGE_GPG_DIR}"
101 # Avoid sandbox violations in temporary directories.
102 if [[ -w $T ]] ; then
106 elif [[ $SANDBOX_ON = 1 ]] ; then
107 for x in TEMP TMP TMPDIR ; do
108 [[ -n ${!x} ]] && addwrite "${!x}"
113 # the sandbox is disabled by default except when overridden in the relevant stages
125 # Custom version of esyslog() to take care of the "Red Star" bug.
126 # MUST follow functions.sh to override the "" parameter problem.
146 # if we got something like '!flag', then invert the return value
147 if [[ ${u:0:1} == "!" ]] ; then
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"
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}"
169 if hasq ${u} ${USE} ; then
176 # Return true if given package is installed. Otherwise return false.
177 # Takes single depend-type atoms.
179 if [ "${EBUILD_PHASE}" == "depend" ]; then
180 die "portageq calls (has_version calls portageq) are not allowed in the global scope"
183 if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
184 "$PORTAGE_BIN_PATH"/ebuild-ipc has_version "$ROOT" "$1"
186 PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
187 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" has_version "${ROOT}" "$1"
195 die "unexpected portageq exit code: ${retval}"
201 if [ "${EBUILD_PHASE}" == "depend" ]; then
202 die "portageq calls are not allowed in the global scope"
205 PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
206 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" "$@"
210 # ----------------------------------------------------------------------------
211 # ----------------------------------------------------------------------------
212 # ----------------------------------------------------------------------------
215 # Returns the best/most-current match.
216 # Takes single depend-type atoms.
218 if [ "${EBUILD_PHASE}" == "depend" ]; then
219 die "portageq calls (best_version calls portageq) are not allowed in the global scope"
222 if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
223 "$PORTAGE_BIN_PATH"/ebuild-ipc best_version "$ROOT" "$1"
225 PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
226 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" 'best_version' "${ROOT}" "$1"
234 die "unexpected portageq exit code: ${retval}"
241 echo "!!! use_with() called without a parameter." >&2
242 echo "!!! use_with <USEFLAG> [<flagname> [value]]" >&2
246 if ! has "${EAPI:-0}" 0 1 2 3 ; then
247 local UW_SUFFIX=${3+=$3}
249 local UW_SUFFIX=${3:+=$3}
254 echo "--with-${UWORD}${UW_SUFFIX}"
256 echo "--without-${UWORD}"
263 echo "!!! use_enable() called without a parameter." >&2
264 echo "!!! use_enable <USEFLAG> [<flagname> [value]]" >&2
268 if ! has "${EAPI:-0}" 0 1 2 3 ; then
269 local UE_SUFFIX=${3+=$3}
271 local UE_SUFFIX=${3:+=$3}
276 echo "--enable-${UWORD}${UE_SUFFIX}"
278 echo "--disable-${UWORD}"
283 register_die_hook() {
286 hasq $x $EBUILD_DEATH_HOOKS || \
287 export EBUILD_DEATH_HOOKS="$EBUILD_DEATH_HOOKS $x"
291 register_success_hook() {
294 hasq $x $EBUILD_SUCCESS_HOOKS || \
295 export EBUILD_SUCCESS_HOOKS="$EBUILD_SUCCESS_HOOKS $x"
299 # Ensure that $PWD is sane whenever possible, to protect against
300 # exploitation of insecure search path for python -c in ebuilds.
302 if ! hasq "$EBUILD_PHASE" clean cleanrm depend help ; then
303 cd "$PORTAGE_BUILDDIR" || \
304 die "PORTAGE_BUILDDIR does not exist: '$PORTAGE_BUILDDIR'"
307 #if no perms are specified, dirs/files will have decent defaults
308 #(not secretive, but not stupid)
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 )
322 # adds ".keep" files so that dirs aren't auto-cleaned
326 if [ "$1" == "-R" ] || [ "$1" == "-r" ]; then
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"
333 touch "${D}${x}/.keep_${CATEGORY}_${PN}-${SLOT}" || \
334 die "Failed to create .keep in ${D}${x}"
344 local eapi=${EAPI:-0}
345 [ -z "$*" ] && die "Nothing passed to the 'unpack' command"
348 vecho ">>> Unpacking ${x} to ${PWD}"
352 if [[ ${x} == "./"* ]] ; then
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"
361 [[ ! -s ${srcdir}${x} ]] && die "${x} does not exist"
364 if [ "${y}" == "tar" ]; then
365 $1 -c -- "$srcdir$x" | tar xof -
366 assert_sigpipe_ok "$myfail"
368 $1 -c -- "${srcdir}${x}" > ${x%.*} || die "$myfail"
372 myfail="failure unpacking ${x}"
375 tar xof "$srcdir$x" || die "$myfail"
378 tar xozf "$srcdir$x" || die "$myfail"
381 ${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- "$srcdir$x" | tar xof -
382 assert_sigpipe_ok "$myfail"
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"
391 _unpack_tar "gzip -d"
394 _unpack_tar "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}"
398 my_output="$(7z x -y "${srcdir}${x}")"
399 if [ $? -ne 0 ]; then
400 echo "${my_output}" >&2
405 unrar x -idq -o+ "${srcdir}${x}" || die "$myfail"
408 lha xfq "${srcdir}${x}" || die "$myfail"
411 ar x "${srcdir}${x}" || die "$myfail"
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
419 if type -P deb2targz > /dev/null; then
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"
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.
435 mv -f "${y%.deb}".tar.gz data.tar.gz || die "$myfail"
437 ar x "$srcdir$x" || die "$myfail"
441 _unpack_tar "lzma -d"
444 if hasq $eapi 0 1 2 ; then
445 vecho "unpack ${x}: file format not recognized. Ignoring."
451 vecho "unpack ${x}: file format not recognized. Ignoring."
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
461 strip_duplicate_slashes() {
462 if [[ -n $1 ]] ; then
464 while [[ ${removed} == *//* ]] ; do
465 removed=${removed//\/\///}
474 for x ; do [[ ${x} == ${s} ]] && echo "${x}" && return 0 ; done
477 hasgq() { hasg "$@" >/dev/null ; }
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"
488 [[ $phase_func != src_configure ]] && \
489 eqawarn "QA Notice: econf called in" \
490 "$phase_func instead of src_configure"
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"
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}"
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 "$@"
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}
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})" "$@"
533 ${CBUILD:+--build=${CBUILD}} \
535 ${CTARGET:+--target=${CTARGET}} \
536 --mandir=/usr/share/man \
537 --infodir=/usr/share/info \
538 --datadir=/usr/share \
540 --localstatedir=/var/lib \
543 vecho "${ECONF_SOURCE}/configure" "$@"
545 if ! "${ECONF_SOURCE}/configure" "$@" ; then
547 if [ -s config.log ]; then
549 echo "!!! Please attach the following file when seeking support:"
550 echo "!!! ${PWD}/config.log"
554 elif [ -f "${ECONF_SOURCE}/configure" ]; then
555 die "configure is not executable"
557 die "no configure script found"
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}"
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}"
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 \
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"
598 die "no Makefile found"
602 _eapi0_pkg_nofetch() {
603 [ -z "${SRC_URI}" ] && return
605 elog "The following are listed in SRC_URI for ${PN}:"
607 for x in $(echo ${SRC_URI}); do
612 _eapi0_src_unpack() {
613 [[ -n ${A} ]] && unpack ${A}
616 _eapi0_src_compile() {
617 if [ -x ./configure ] ; then
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."
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."
637 vecho ">>> Test phase [none]: ${CATEGORY}/${PF}"
641 _eapi1_src_compile() {
646 _eapi2_src_configure() {
647 if [[ -x ${ECONF_SOURCE:-.}/configure ]] ; then
652 _eapi2_src_compile() {
653 if [ -f Makefile ] || [ -f GNUmakefile ] || [ -f makefile ]; then
654 emake || die "emake failed"
658 _eapi4_src_install() {
659 if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
660 emake DESTDIR="${D}" install
663 if [[ -z $DOCS ]] ; then
665 for d in README* ChangeLog AUTHORS NEWS TODO CHANGES \
666 THANKS BUGS FAQ CREDITS CHANGELOG ; do
667 [[ -s "${d}" ]] && dodoc "${d}"
669 elif [[ $(declare -p DOCS) == "declare -a "* ]] ; then
677 declare -F "$1" >/dev/null && qa_call $1
680 ebuild_phase_with_hooks() {
681 local x phase_name=${1}
682 for x in {pre_,,post_}${phase_name} ; do
688 ebuild_phase_with_hooks pkg_pretend
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."
697 ebuild_phase pre_pkg_setup
698 ebuild_phase pkg_setup
699 > "$PORTAGE_BUILDDIR"/.setuped
700 ebuild_phase post_pkg_setup
705 if [ -e "${WORKDIR}" ]; then
709 vecho ">>> Checking ${x}'s mtime..."
710 if [ "${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/${x}" -nt "${WORKDIR}" ]; then
711 vecho ">>> ${x} has been updated; recreating WORKDIR..."
716 if [ ! -f "${PORTAGE_BUILDDIR}/.unpacked" ] ; then
717 vecho ">>> Not marked as unpacked; recreating WORKDIR..."
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
727 if [ -d "${T}" ] && \
728 ! hasq keeptemp $FEATURES ; then
729 rm -rf "${T}" && mkdir "${T}"
732 if [ -e "${WORKDIR}" ]; then
733 if [ "$newstuff" == "no" ]; then
734 vecho ">>> WORKDIR is up-to-date, keeping..."
739 if [ ! -d "${WORKDIR}" ]; then
740 install -m${PORTAGE_WORKDIR_MODE:-0700} -d "${WORKDIR}" || die "Failed to create dir '${WORKDIR}'"
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
752 if [ -z "${PORTAGE_BUILDDIR}" ]; then
753 echo "Aborting clean phase because PORTAGE_BUILDDIR is unset!"
755 elif [ ! -d "${PORTAGE_BUILDDIR}" ] ; then
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
763 rm -rf "${PORTAGE_BUILDDIR}/image" "${PORTAGE_BUILDDIR}/homedir"
764 rm -f "${PORTAGE_BUILDDIR}/.installed"
766 if [[ $EMERGE_FROM = binary ]] || \
767 ! hasq keeptemp $FEATURES && ! hasq keepwork $FEATURES ; then
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
778 rm -rf "${PORTAGE_BUILDDIR}/build-info"
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
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"
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
799 if [ "$1" == "/" ]; then
803 if [ ! -d "${D}${DESTTREE}" ]; then
804 install -d "${D}${DESTTREE}"
806 if [[ $ret -ne 0 ]] ; then
807 helpers_die "${FUNCNAME[0]} failed"
815 if [ "$1" == "/" ]; then
816 export INSDESTTREE=""
818 export INSDESTTREE=$1
819 if [ ! -d "${D}${INSDESTTREE}" ]; then
820 install -d "${D}${INSDESTTREE}"
822 if [[ $ret -ne 0 ]] ; then
823 helpers_die "${FUNCNAME[0]} failed"
831 if [ "$1" == "/" ]; then
832 export _E_EXEDESTTREE_=""
834 export _E_EXEDESTTREE_="$1"
835 if [ ! -d "${D}${_E_EXEDESTTREE_}" ]; then
836 install -d "${D}${_E_EXEDESTTREE_}"
838 if [[ $ret -ne 0 ]] ; then
839 helpers_die "${FUNCNAME[0]} failed"
847 if [ "$1" == "/" ]; then
848 export _E_DOCDESTTREE_=""
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_}"
854 if [[ $ret -ne 0 ]] ; then
855 helpers_die "${FUNCNAME[0]} failed"
863 export INSOPTIONS="$@"
865 # `install` should never be called with '-s' ...
866 hasq -s ${INSOPTIONS} && die "Never call insopts() with -s"
870 export DIROPTIONS="$@"
874 export EXEOPTIONS="$@"
876 # `install` should never be called with '-s' ...
877 hasq -s ${EXEOPTIONS} && die "Never call exeopts() with -s"
881 export LIBOPTIONS="$@"
883 # `install` should never be called with '-s' ...
884 hasq -s ${LIBOPTIONS} && die "Never call libopts() with -s"
888 hasq "${EAPI}" 0 1 2 3 && die "'docompress' not supported in this EAPI"
891 if [[ $1 = "-x" ]]; then
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
899 PORTAGE_DOCOMPRESS_SKIP[${#PORTAGE_DOCOMPRESS_SKIP[@]}]=${f}
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
908 PORTAGE_DOCOMPRESS[${#PORTAGE_DOCOMPRESS[@]}]=${f}
915 if [ "$2" != "fail" ]; then
916 msg="${EBUILD}: ${1} aborted; exiting."
918 msg="${EBUILD}: ${1} failed; exiting."
924 #unset signal handler
925 trap - SIGINT SIGQUIT
929 abort_handler src_prepare $1
930 rm -f "$PORTAGE_BUILDDIR/.prepared"
935 abort_handler src_configure $1
936 rm -f "$PORTAGE_BUILDDIR/.configured"
941 abort_handler "src_compile" $1
942 rm -f "${PORTAGE_BUILDDIR}/.compiled"
947 abort_handler "dyn_test" $1
948 rm -f "${PORTAGE_BUILDDIR}/.tested"
953 abort_handler "src_install" $1
954 rm -rf "${PORTAGE_BUILDDIR}/image"
958 has_phase_defined_up_to() {
960 for phase in unpack prepare configure compile install; do
961 has ${phase} ${DEFINED_PHASES} && return 0
962 [[ ${phase} == $1 ]] && return 1
964 # We shouldn't actually get here
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."
976 if [[ -d $S ]] ; then
978 elif hasq $EAPI 0 1 2 3 3_pre2 ; then
980 elif [[ -z ${A} ]] && ! has_phase_defined_up_to prepare; then
983 die "The source directory '${S}' doesn't exist"
986 trap abort_prepare SIGINT SIGQUIT
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
995 trap - SIGINT SIGQUIT
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."
1006 if [[ -d $S ]] ; then
1008 elif hasq $EAPI 0 1 2 3 3_pre2 ; then
1010 elif [[ -z ${A} ]] && ! has_phase_defined_up_to configure; then
1013 die "The source directory '${S}' doesn't exist"
1016 trap abort_configure SIGINT SIGQUIT
1018 ebuild_phase pre_src_configure
1020 vecho ">>> Configuring source in $PWD ..."
1021 ebuild_phase src_configure
1022 touch "$PORTAGE_BUILDDIR"/.configured
1023 vecho ">>> Source configured."
1025 ebuild_phase post_src_configure
1027 trap - SIGINT SIGQUIT
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."
1038 if [[ -d $S ]] ; then
1040 elif hasq $EAPI 0 1 2 3 3_pre2 ; then
1042 elif [[ -z ${A} ]] && ! has_phase_defined_up_to compile; then
1045 die "The source directory '${S}' doesn't exist"
1048 trap abort_compile SIGINT SIGQUIT
1050 ebuild_phase pre_src_compile
1052 vecho ">>> Compiling source in $PWD ..."
1053 ebuild_phase src_compile
1054 touch "$PORTAGE_BUILDDIR"/.compiled
1055 vecho ">>> Source compiled."
1057 ebuild_phase post_src_compile
1059 trap - SIGINT SIGQUIT
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."
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"
1076 trap "abort_test" SIGINT SIGQUIT
1077 if [ -d "${S}" ]; then
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}"
1089 local save_sp=${SANDBOX_PREDICT}
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}
1099 trap - SIGINT SIGQUIT
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."
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
1117 elif hasq $EAPI 0 1 2 3 3_pre2 ; then
1119 elif [[ -z ${A} ]] && ! has_phase_defined_up_to install; then
1122 die "The source directory '${S}' doesn't exist"
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
1130 #some packages uses an alternative to $S to build in, cause
1131 #our libtool to create problematic .la files
1132 export PWORKDIR="$WORKDIR"
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_=""
1142 ebuild_phase src_install
1143 touch "${PORTAGE_BUILDDIR}/.installed"
1144 vecho ">>> Completed installing ${PF} into ${D}"
1146 ebuild_phase post_src_install
1148 cd "${PORTAGE_BUILDDIR}"/build-info
1152 for f in CATEGORY DEFINED_PHASES FEATURES INHERITED IUSE REQUIRED_USE \
1153 PF PKGUSE SLOT KEYWORDS HOMEPAGE DESCRIPTION ; do
1155 [[ -n $x ]] && echo "$x" > $f
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
1162 [[ -n $x ]] && echo "$x" > $f
1166 echo "${EAPI:-0}" > EAPI
1169 # local variables can leak into the saved environment.
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"
1176 ${PORTAGE_BZIP2_COMMAND} -f9 environment
1178 cp "${EBUILD}" "${PF}.ebuild"
1179 [ -n "${PORTAGE_REPO_NAME}" ] && echo "${PORTAGE_REPO_NAME}" > repository
1180 if hasq nostrip ${FEATURES} ${RESTRICT} || hasq strip ${RESTRICT}
1184 trap - SIGINT SIGQUIT
1188 if [ -z "${D}" ]; then
1189 eerror "${FUNCNAME}: D is unset"
1192 ebuild_phase_with_hooks pkg_preinst
1198 echo "Copyright 1999-2010 Gentoo Foundation"
1200 echo "How to use the ebuild command:"
1202 echo "The first argument to ebuild should be an existing .ebuild file."
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."
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"
1231 echo "The following settings will be used for the ebuild process:"
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} ;
1244 echo "debug (large)"
1246 echo "production (stripped)"
1248 echo " merge to : ${ROOT}"
1250 if [ -n "$USE" ]; then
1251 echo "Additionally, support for the following optional features will be enabled:"
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
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.
1266 # in the future might use e* from /etc/init.d/functions.sh if i feel like it
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
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}"
1278 if [[ -w $T ]] ; then
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
1287 # The following 2 functions are debug-print() wrappers
1289 debug-print-function() {
1290 debug-print "${1}: entering function, parameters: ${*:2}"
1293 debug-print-section() {
1294 debug-print "now in section ${*}"
1297 # Sources all eclasses in parameters
1298 declare -ix ECLASS_DEPTH=0
1300 ECLASS_DEPTH=$(($ECLASS_DEPTH + 1))
1301 if [[ ${ECLASS_DEPTH} > 1 ]]; then
1302 debug-print "*** Multiple Inheritence (Level: ${ECLASS_DEPTH})"
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
1316 # These variables must be restored before returning.
1317 local PECLASS=$ECLASS
1318 local prev_export_funcs_var=$__export_funcs_var
1321 local B_REQUIRED_USE
1326 location="${ECLASSDIR}/${1}.eclass"
1330 __export_funcs_var=__export_functions_$ECLASS_DEPTH
1331 unset $__export_funcs_var
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"
1344 # any future resolution code goes here
1345 if [ -n "$PORTDIR_OVERLAY" ]; then
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}"
1355 debug-print "inherit: $1 -> $location"
1356 [ ! -e "$location" ] && die "${1}.eclass could not be found by inherit()"
1358 if [ "${location}" == "${olocation}" ] && \
1359 ! hasq "${location}" ${EBUILD_OVERLAY_ECLASSES} ; then
1360 EBUILD_OVERLAY_ECLASSES="${EBUILD_OVERLAY_ECLASSES} ${location}"
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.
1366 #turn off glob expansion
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
1380 qa_source "$location" || die "died sourcing $location in inherit()"
1382 #turn off glob expansion
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}"
1393 [ "${B_IUSE+set}" = set ] && IUSE="${B_IUSE}"
1394 [ "${B_IUSE+set}" = set ] || unset IUSE
1396 [ "${B_REQUIRED_USE+set}" = set ] && REQUIRED_USE="${B_REQUIRED_USE}"
1397 [ "${B_REQUIRED_USE+set}" = set ] || unset REQUIRED_USE
1399 [ "${B_DEPEND+set}" = set ] && DEPEND="${B_DEPEND}"
1400 [ "${B_DEPEND+set}" = set ] || unset DEPEND
1402 [ "${B_RDEPEND+set}" = set ] && RDEPEND="${B_RDEPEND}"
1403 [ "${B_RDEPEND+set}" = set ] || unset RDEPEND
1405 [ "${B_PDEPEND+set}" = set ] && PDEPEND="${B_PDEPEND}"
1406 [ "${B_PDEPEND+set}" = set ] || unset PDEPEND
1408 #turn on glob expansion
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
1419 unset $__export_funcs_var
1421 hasq $1 $INHERITED || export INHERITED="$INHERITED $1"
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
1430 unset ECLASS __export_funcs_var
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"
1443 eval $__export_funcs_var+=\" $*\"
1446 # this is a function for removing any directory matching a passed in pattern from
1448 remove_path_entry() {
1451 stripped_path="${PATH}"
1452 while [ -n "$1" ]; do
1454 for p in ${stripped_path}; do
1455 if [ "${p/${1}}" == "${p}" ]; then
1456 cur_path="${cur_path}:${p}"
1459 stripped_path="${cur_path#:*}"
1463 PATH="${stripped_path}"
1466 # @FUNCTION: _ebuild_arg_to_phase
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 $#: $*"
1478 ! hasq $eapi 0 1 2 3 3_pre2 && \
1479 phase_func=pkg_pretend
1482 phase_func=pkg_setup
1485 phase_func=pkg_nofetch
1488 phase_func=src_unpack
1491 ! hasq $eapi 0 1 && \
1492 phase_func=src_prepare
1495 ! hasq $eapi 0 1 && \
1496 phase_func=src_configure
1499 phase_func=src_compile
1505 phase_func=src_install
1508 phase_func=pkg_preinst
1511 phase_func=pkg_postinst
1514 phase_func=pkg_prerm
1517 phase_func=pkg_postrm
1521 [[ -z $phase_func ]] && return 1
1526 _ebuild_phase_funcs() {
1527 [ $# -ne 2 ] && die "expected exactly 2 args, got $#: $*"
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=""
1534 for x in pkg_nofetch src_unpack src_test ; do
1535 declare -F $x >/dev/null || \
1536 eval "$x() { _eapi0_$x \"\$@\" ; }"
1543 if ! declare -F src_compile >/dev/null ; then
1546 src_compile() { _eapi0_src_compile "$@" ; }
1549 src_compile() { _eapi1_src_compile "$@" ; }
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\"
1561 die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
1568 declare -F src_configure >/dev/null || \
1569 src_configure() { _eapi2_src_configure "$@" ; }
1571 declare -F src_compile >/dev/null || \
1572 src_compile() { _eapi2_src_compile "$@" ; }
1574 has $eapi 2 3 3_pre2 || declare -F src_install >/dev/null || \
1575 src_install() { _eapi4_src_install "$@" ; }
1577 if hasq $phase_func $default_phases ; then
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" ; }
1585 for x in $default_phases ; do
1586 eval "default_$x() { _eapi2_$x \"\$@\" ; }"
1589 eval "default() { _eapi2_$phase_func \"\$@\" ; }"
1595 eval "default_src_install() { _eapi4_src_install \"\$@\" ; }"
1596 [[ $phase_func = src_install ]] && \
1597 eval "default() { _eapi4_$phase_func \"\$@\" ; }"
1603 for x in $default_phases ; do
1604 eval "default_$x() {
1605 die \"default_$x() is not supported in phase $default_func\"
1610 die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
1619 PORTAGE_BASHRCS_SOURCED=0
1621 # @FUNCTION: source_all_bashrcs
1623 # Source a relevant bashrc files and perform other miscellaneous
1624 # environment initialization when appropriate.
1626 # If EAPI is set then define functions provided by the current EAPI:
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.
1632 source_all_bashrcs() {
1633 [[ $PORTAGE_BASHRCS_SOURCED = 1 ]] && return 0
1634 PORTAGE_BASHRCS_SOURCED=1
1637 local OCC="${CC}" OCXX="${CXX}"
1639 if [[ $EBUILD_PHASE != depend ]] ; then
1640 # source the existing profile.bashrcs.
1643 local path_array=($PROFILE_PATHS)
1645 for x in "${path_array[@]}" ; do
1646 [ -f "$x/profile.bashrc" ] && qa_source "$x/profile.bashrc"
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
1667 [ ! -z "${OCC}" ] && export CC="${OCC}"
1668 [ ! -z "${OCXX}" ] && export CXX="${OCXX}"
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.
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"
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"
1698 PORTAGE_SAVED_READONLY_VARS="A CATEGORY P PF PN PR PV PVR"
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"
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:
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
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.
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.
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.
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.
1739 # ---allow-extra-vars causes some extra vars to be allowd through, such
1740 # as ${PORTAGE_SAVED_READONLY_VARS} and ${PORTAGE_MUTABLE_FILTERED_VARS}.
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"
1761 # Don't filter/interfere with prefix variables unless they are
1762 # supported by the current EAPI.
1763 case "${EAPI:-0}" in
1767 filtered_vars+=" ED EPREFIX EROOT"
1771 if hasq --filter-sandbox $* ; then
1772 filtered_vars="${filtered_vars} SANDBOX_.*"
1774 filtered_vars="${filtered_vars} ${filtered_sandbox_vars}"
1776 if hasq --filter-features $* ; then
1777 filtered_vars="${filtered_vars} FEATURES PORTAGE_FEATURES"
1779 if hasq --filter-path $* ; then
1780 filtered_vars+=" PATH"
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"
1787 if ! hasq --allow-extra-vars $* ; then
1790 ${PORTAGE_SAVED_READONLY_VARS}
1791 ${PORTAGE_MUTABLE_FILTERED_VARS}
1795 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}" || die "filter-bash-environment.py failed"
1798 # @FUNCTION: preprocess_ebuild_env
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"
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.
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.
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 $?
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"
1844 if [ -e "${T}/environment.success" ] ; then
1845 filter_readonly_variables --filter-features < \
1846 "${T}/environment.filtered" > "${T}/environment"
1851 rm -f "${T}"/environment.{filtered,raw,success}
1855 # === === === === === === === === === === === === === === === === === ===
1856 # === === === === === functions end, main part begins === === === === ===
1857 # === === === === === functions end, main part begins === === === === ===
1858 # === === === === === functions end, main part begins === === === === ===
1859 # === === === === === === === === === === === === === === === === === ===
1861 export SANDBOX_ON="1"
1862 export S=${WORKDIR}/${P}
1864 unset E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND
1866 # Turn of extended glob matching so that g++ doesn't get incorrectly matched.
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
1876 QA_INTERCEPTORS="autoconf automake aclocal libtoolize"
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"
1885 BODY="${BIN_PATH} \"\$@\"; return \$?"
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}\"
1892 eqawarn \"QA Notice: '${BIN}' called in global scope: \${CATEGORY}/\${PF}\"
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.\"
1908 FUNC_SRC="${BIN}() {
1909 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
1913 eval "$FUNC_SRC" || echo "error creating QA interceptor ${BIN}" >&2
1915 unset BIN_PATH BIN BODY FUNC_SRC
1918 # Subshell/helper die support (must export for the die helper).
1919 export EBUILD_MASTER_PID=$BASHPID
1920 trap 'exit 1' SIGTERM
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}
1933 PORTAGE_SANDBOX_ON=${SANDBOX_ON}
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.
1942 for x in SANDBOX_DENY SANDBOX_PREDICT SANDBOX_READ SANDBOX_WRITE ; do
1944 if [ -z "${!x}" ] ; then
1946 elif [ -n "${!y}" ] && [ "${!y}" != "${!x}" ] ; then
1948 export ${x}=$(printf "${!y}:${!x}" | tr ":" "\0" | \
1949 sort -z -u | tr "\0" ":")
1955 export SANDBOX_ON=${PORTAGE_SANDBOX_ON}
1956 unset PORTAGE_SANDBOX_ON
1957 [[ -n $EAPI ]] || EAPI=0
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.
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
1974 if [[ $PORTAGE_DEBUG != 1 || ${-/x/} != $- ]] ; then
1975 source "$EBUILD" || die "error sourcing ebuild"
1978 source "$EBUILD" || die "error sourcing ebuild"
1982 if [[ "${EBUILD_PHASE}" != "depend" ]] ; then
1983 RESTRICT=${PORTAGE_RESTRICT}
1984 [[ -e $PORTAGE_BUILDDIR/.ebuild_changed ]] && \
1985 rm "$PORTAGE_BUILDDIR/.ebuild_changed"
1988 [[ -n $EAPI ]] || EAPI=0
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}"
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}"
2002 unset ECLASS E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND
2004 # alphabetically ordered by $EBUILD_PHASE value
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"
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"
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"
2024 for _f in $_valid_phases ; do
2025 if declare -F $_f >/dev/null ; then
2027 DEFINED_PHASES+=" ${_f#src_}"
2030 [[ -n $DEFINED_PHASES ]] || DEFINED_PHASES=-
2032 unset _f _valid_phases
2034 if [[ $EBUILD_PHASE != depend ]] ; then
2038 _ebuild_helpers_path="$PORTAGE_BIN_PATH/ebuild-helpers"
2041 _ebuild_helpers_path="$PORTAGE_BIN_PATH/ebuild-helpers/4:$PORTAGE_BIN_PATH/ebuild-helpers"
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
2048 if hasq distcc $FEATURES ; then
2049 PATH="/usr/lib/distcc/bin:$PATH"
2050 [[ -n $DISTCC_LOG ]] && addwrite "${DISTCC_LOG%/*}"
2053 if hasq ccache $FEATURES ; then
2054 PATH="/usr/lib/ccache/bin:$PATH"
2056 if [[ -n $CCACHE_DIR ]] ; then
2057 addread "$CCACHE_DIR"
2058 addwrite "$CCACHE_DIR"
2061 [[ -n $CCACHE_SIZE ]] && ccache -M $CCACHE_SIZE &> /dev/null
2065 if [[ -n $QA_PREBUILT ]] ; then
2067 # these ones support fnmatch patterns
2068 QA_EXECSTACK+=" $QA_PREBUILT"
2069 QA_TEXTRELS+=" $QA_PREBUILT"
2070 QA_WX_LOAD+=" $QA_PREBUILT"
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//\*/.*})"
2078 eval "$x+=\" ${QA_PREBUILT//\*/.*}\""
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/-/_}"
2091 # unset USE_EXPAND variables that contain only the special "*" token
2092 for x in ${USE_EXPAND} ; do
2093 [ "${!x}" == "*" ] && unset ${x}
2097 if hasq nostrip ${FEATURES} ${RESTRICT} || hasq strip ${RESTRICT}
2102 #a reasonable default for $S
2103 [[ -z ${S} ]] && export S=${WORKDIR}/${P}
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
2113 declare -r ED EPREFIX EROOT
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
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
2133 local phase_func=$(_ebuild_arg_to_phase "$EAPI" "$EBUILD_PHASE")
2134 [[ -n $phase_func ]] && _ebuild_phase_funcs "$EAPI" "$phase_func"
2140 case ${EBUILD_SH_ARGS} in
2142 ebuild_phase_with_hooks pkg_nofetch
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##*/}'"
2149 export SANDBOX_ON="0"
2150 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
2151 ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
2154 ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
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"
2167 unpack|prepare|configure|compile|test|clean|install)
2168 if [[ ${SANDBOX_DISABLED:-0} = 0 ]] ; then
2169 export SANDBOX_ON="1"
2171 export SANDBOX_ON="0"
2174 case "$EBUILD_SH_ARGS" in
2178 for x in ASFLAGS CCACHE_DIR CCACHE_SIZE \
2179 CFLAGS CXXFLAGS LDFLAGS LIBCFLAGS LIBCXXFLAGS ; do
2180 [[ ${!x+set} = set ]] && export $x
2184 hasq distcc $FEATURES && [[ -n $DISTCC_DIR ]] && \
2185 [[ ${SANDBOX_WRITE/$DISTCC_DIR} = $SANDBOX_WRITE ]] && \
2186 addwrite "$DISTCC_DIR"
2189 [ -z "$PKG_CONFIG_PATH" -a -n "$ABI" -a -n "${!x}" ] && \
2190 export PKG_CONFIG_PATH=/usr/${!x}/pkgconfig
2192 if hasq noauto $FEATURES && \
2193 [[ ! -f $PORTAGE_BUILDDIR/.unpacked ]] ; then
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..."
2204 for x in 1 2 3 4 5 6 7 8; do
2211 cd "$PORTAGE_BUILDDIR"
2212 if [ ! -d build-info ] ; then
2214 cp "$EBUILD" "build-info/$PF.ebuild"
2217 #our custom version of libtool uses $S and $D to fix
2218 #invalid paths in .la files
2220 #some packages use an alternative to $S to build in, cause
2221 #our libtool to create problematic .la files
2222 export PWORKDIR=$WORKDIR
2227 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
2228 dyn_${EBUILD_SH_ARGS}
2231 dyn_${EBUILD_SH_ARGS}
2234 export SANDBOX_ON="0"
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}
2245 dyn_${EBUILD_SH_ARGS}
2250 export SANDBOX_ON="0"
2253 if [ -n "${dbkey}" ] ; then
2254 if [ ! -d "${dbkey%/*}" ]; then
2255 install -d -g ${PORTAGE_GID} -m2775 "${dbkey%/*}"
2257 # Make it group writable. 666&~002==664
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"
2266 #the extra $(echo) commands remove newlines
2267 [ -n "${EAPI}" ] || EAPI=0
2269 if [ -n "${dbkey}" ] ; then
2271 for f in ${auxdbkeys} ; do
2272 echo $(echo ${!f}) >> "${dbkey}" || exit $?
2275 for f in ${auxdbkeys} ; do
2276 echo $(echo ${!f}) 1>&9 || exit $?
2285 export SANDBOX_ON="1"
2286 echo "Unrecognized EBUILD_SH_ARGS: '${EBUILD_SH_ARGS}'"
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.
2299 if [[ -n SANDBOX_ON ]] ; then
2304 rm -f "$SANDBOX_LOG" || \
2305 die "failed to remove stale sandbox log: '$SANDBOX_LOG'"
2307 if [[ -n $x ]] ; then
2308 export SANDBOX_ON=$x
2313 if [[ $EBUILD_PHASE = depend ]] ; then
2315 elif [[ -n $EBUILD_SH_ARGS ]] ; then
2317 # Don't allow subprocesses to inherit the pipe which
2318 # emerge uses to monitor ebuild.sh.
2323 # Save the env only for relevant phases.
2324 if ! hasq "$EBUILD_SH_ARGS" clean help info nofetch ; then
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
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 $?
2342 # Do not exit when ebuild.sh is sourced by other scripts.