2 # Copyright 1999-2011 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" \
330 while read -r -d $'\0' ; do
332 die "Failed to recursively create .keep files"
336 >> "${D}${x}/.keep_${CATEGORY}_${PN}-${SLOT}" || \
337 die "Failed to create .keep in ${D}${x}"
347 local eapi=${EAPI:-0}
348 [ -z "$*" ] && die "Nothing passed to the 'unpack' command"
351 vecho ">>> Unpacking ${x} to ${PWD}"
355 if [[ ${x} == "./"* ]] ; then
357 elif [[ ${x} == ${DISTDIR%/}/* ]] ; then
358 die "Arguments to unpack() cannot begin with \${DISTDIR}."
359 elif [[ ${x} == "/"* ]] ; then
360 die "Arguments to unpack() cannot be absolute"
364 [[ ! -s ${srcdir}${x} ]] && die "${x} does not exist"
367 if [ "${y}" == "tar" ]; then
368 $1 -c -- "$srcdir$x" | tar xof -
369 assert_sigpipe_ok "$myfail"
371 $1 -c -- "${srcdir}${x}" > ${x%.*} || die "$myfail"
375 myfail="failure unpacking ${x}"
378 tar xof "$srcdir$x" || die "$myfail"
381 tar xozf "$srcdir$x" || die "$myfail"
384 ${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- "$srcdir$x" | tar xof -
385 assert_sigpipe_ok "$myfail"
388 # unzip will interactively prompt under some error conditions,
389 # as reported in bug #336285
390 ( while true ; do echo n || break ; done ) | \
391 unzip -qo "${srcdir}${x}" || die "$myfail"
394 _unpack_tar "gzip -d"
397 _unpack_tar "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}"
401 my_output="$(7z x -y "${srcdir}${x}")"
402 if [ $? -ne 0 ]; then
403 echo "${my_output}" >&2
408 unrar x -idq -o+ "${srcdir}${x}" || die "$myfail"
411 lha xfq "${srcdir}${x}" || die "$myfail"
414 ar x "${srcdir}${x}" || die "$myfail"
417 # Unpacking .deb archives can not always be done with
418 # `ar`. For instance on AIX this doesn't work out. If
419 # we have `deb2targz` installed, prefer it over `ar` for
420 # that reason. We just make sure on AIX `deb2targz` is
422 if type -P deb2targz > /dev/null; then
424 local created_symlink=0
425 if [ ! "$srcdir$x" -ef "$y" ] ; then
426 # deb2targz always extracts into the same directory as
427 # the source file, so create a symlink in the current
428 # working directory if necessary.
429 ln -sf "$srcdir$x" "$y" || die "$myfail"
432 deb2targz "$y" || die "$myfail"
433 if [ $created_symlink = 1 ] ; then
434 # Clean up the symlink so the ebuild
435 # doesn't inadvertently install it.
438 mv -f "${y%.deb}".tar.gz data.tar.gz || die "$myfail"
440 ar x "$srcdir$x" || die "$myfail"
444 _unpack_tar "lzma -d"
447 if hasq $eapi 0 1 2 ; then
448 vecho "unpack ${x}: file format not recognized. Ignoring."
454 vecho "unpack ${x}: file format not recognized. Ignoring."
458 # Do not chmod '.' since it's probably ${WORKDIR} and PORTAGE_WORKDIR_MODE
459 # should be preserved.
460 find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \
461 ${XARGS} -0 chmod -fR a+rX,u+w,g-w,o-w
464 strip_duplicate_slashes() {
465 if [[ -n $1 ]] ; then
467 while [[ ${removed} == *//* ]] ; do
468 removed=${removed//\/\///}
477 for x ; do [[ ${x} == ${s} ]] && echo "${x}" && return 0 ; done
480 hasgq() { hasg "$@" >/dev/null ; }
484 local phase_func=$(_ebuild_arg_to_phase "$EAPI" "$EBUILD_PHASE")
485 if [[ -n $phase_func ]] ; then
486 if hasq "$EAPI" 0 1 ; then
487 [[ $phase_func != src_compile ]] && \
488 eqawarn "QA Notice: econf called in" \
489 "$phase_func instead of src_compile"
491 [[ $phase_func != src_configure ]] && \
492 eqawarn "QA Notice: econf called in" \
493 "$phase_func instead of src_configure"
498 if [ -x "${ECONF_SOURCE}/configure" ]; then
499 if [[ -n $CONFIG_SHELL && \
500 "$(head -n1 "$ECONF_SOURCE/configure")" =~ ^'#!'[[:space:]]*/bin/sh([[:space:]]|$) ]] ; then
501 sed -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" -i "$ECONF_SOURCE/configure" || \
502 die "Substition of shebang in '$ECONF_SOURCE/configure' failed"
504 if [ -e /usr/share/gnuconfig/ ]; then
505 find "${WORKDIR}" -type f '(' \
506 -name config.guess -o -name config.sub ')' -print0 | \
507 while read -r -d $'\0' x ; do
508 vecho " * econf: updating ${x/${WORKDIR}\/} with /usr/share/gnuconfig/${x##*/}"
509 cp -f /usr/share/gnuconfig/"${x##*/}" "${x}"
513 # EAPI=4 adds --disable-dependency-tracking to econf
514 if ! hasq "$EAPI" 0 1 2 3 3_pre2 && \
515 "${ECONF_SOURCE}/configure" --help 2>/dev/null | \
516 grep -q disable-dependency-tracking ; then
517 set -- --disable-dependency-tracking "$@"
520 # if the profile defines a location to install libs to aside from default, pass it on.
521 # if the ebuild passes in --libdir, they're responsible for the conf_libdir fun.
522 local CONF_LIBDIR LIBDIR_VAR="LIBDIR_${ABI}"
523 if [[ -n ${ABI} && -n ${!LIBDIR_VAR} ]] ; then
524 CONF_LIBDIR=${!LIBDIR_VAR}
526 if [[ -n ${CONF_LIBDIR} ]] && ! hasgq --libdir=\* "$@" ; then
527 export CONF_PREFIX=$(hasg --exec-prefix=\* "$@")
528 [[ -z ${CONF_PREFIX} ]] && CONF_PREFIX=$(hasg --prefix=\* "$@")
529 : ${CONF_PREFIX:=/usr}
530 CONF_PREFIX=${CONF_PREFIX#*=}
531 [[ ${CONF_PREFIX} != /* ]] && CONF_PREFIX="/${CONF_PREFIX}"
532 [[ ${CONF_LIBDIR} != /* ]] && CONF_LIBDIR="/${CONF_LIBDIR}"
533 set -- --libdir="$(strip_duplicate_slashes ${CONF_PREFIX}${CONF_LIBDIR})" "$@"
538 ${CBUILD:+--build=${CBUILD}} \
540 ${CTARGET:+--target=${CTARGET}} \
541 --mandir=/usr/share/man \
542 --infodir=/usr/share/info \
543 --datadir=/usr/share \
545 --localstatedir=/var/lib \
548 vecho "${ECONF_SOURCE}/configure" "$@"
550 if ! "${ECONF_SOURCE}/configure" "$@" ; then
552 if [ -s config.log ]; then
554 echo "!!! Please attach the following file when seeking support:"
555 echo "!!! ${PWD}/config.log"
559 elif [ -f "${ECONF_SOURCE}/configure" ]; then
560 die "configure is not executable"
562 die "no configure script found"
567 # CONF_PREFIX is only set if they didn't pass in libdir above.
568 local LOCAL_EXTRA_EINSTALL="${EXTRA_EINSTALL}"
569 LIBDIR_VAR="LIBDIR_${ABI}"
570 if [ -n "${ABI}" -a -n "${!LIBDIR_VAR}" ]; then
571 CONF_LIBDIR="${!LIBDIR_VAR}"
574 if [ -n "${CONF_LIBDIR}" ] && [ "${CONF_PREFIX:+set}" = set ]; then
575 EI_DESTLIBDIR="${D}/${CONF_PREFIX}/${CONF_LIBDIR}"
576 EI_DESTLIBDIR="$(strip_duplicate_slashes ${EI_DESTLIBDIR})"
577 LOCAL_EXTRA_EINSTALL="libdir=${EI_DESTLIBDIR} ${LOCAL_EXTRA_EINSTALL}"
581 if [ -f ./[mM]akefile -o -f ./GNUmakefile ] ; then
582 if [ "${PORTAGE_DEBUG}" == "1" ]; then
583 ${MAKE:-make} -n prefix="${D}usr" \
584 datadir="${D}usr/share" \
585 infodir="${D}usr/share/info" \
586 localstatedir="${D}var/lib" \
587 mandir="${D}usr/share/man" \
588 sysconfdir="${D}etc" \
589 ${LOCAL_EXTRA_EINSTALL} \
590 ${MAKEOPTS} ${EXTRA_EMAKE} -j1 \
593 ${MAKE:-make} prefix="${D}usr" \
594 datadir="${D}usr/share" \
595 infodir="${D}usr/share/info" \
596 localstatedir="${D}var/lib" \
597 mandir="${D}usr/share/man" \
598 sysconfdir="${D}etc" \
599 ${LOCAL_EXTRA_EINSTALL} \
600 ${MAKEOPTS} ${EXTRA_EMAKE} -j1 \
601 "$@" install || die "einstall failed"
603 die "no Makefile found"
607 _eapi0_pkg_nofetch() {
608 [ -z "${SRC_URI}" ] && return
610 elog "The following are listed in SRC_URI for ${PN}:"
612 for x in $(echo ${SRC_URI}); do
617 _eapi0_src_unpack() {
618 [[ -n ${A} ]] && unpack ${A}
621 _eapi0_src_compile() {
622 if [ -x ./configure ] ; then
629 # Since we don't want emake's automatic die
630 # support (EAPI 4 and later), and we also don't
631 # want the warning messages that it produces if
632 # we call it in 'nonfatal' mode, we use emake_cmd
633 # to emulate the desired parts of emake behavior.
634 local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}"
635 if $emake_cmd -j1 check -n &> /dev/null; then
636 vecho ">>> Test phase [check]: ${CATEGORY}/${PF}"
637 if ! $emake_cmd -j1 check; then
638 hasq test $FEATURES && die "Make check failed. See above for details."
639 hasq test $FEATURES || eerror "Make check failed. See above for details."
641 elif $emake_cmd -j1 test -n &> /dev/null; then
642 vecho ">>> Test phase [test]: ${CATEGORY}/${PF}"
643 if ! $emake_cmd -j1 test; then
644 hasq test $FEATURES && die "Make test failed. See above for details."
645 hasq test $FEATURES || eerror "Make test failed. See above for details."
648 vecho ">>> Test phase [none]: ${CATEGORY}/${PF}"
652 _eapi1_src_compile() {
657 _eapi2_src_configure() {
658 if [[ -x ${ECONF_SOURCE:-.}/configure ]] ; then
663 _eapi2_src_compile() {
664 if [ -f Makefile ] || [ -f GNUmakefile ] || [ -f makefile ]; then
665 emake || die "emake failed"
669 _eapi4_src_install() {
670 if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
671 emake DESTDIR="${D}" install
674 if ! declare -p DOCS &>/dev/null ; then
676 for d in README* ChangeLog AUTHORS NEWS TODO CHANGES \
677 THANKS BUGS FAQ CREDITS CHANGELOG ; do
678 [[ -s "${d}" ]] && dodoc "${d}"
680 elif [[ $(declare -p DOCS) == "declare -a "* ]] ; then
688 declare -F "$1" >/dev/null && qa_call $1
691 ebuild_phase_with_hooks() {
692 local x phase_name=${1}
693 for x in {pre_,,post_}${phase_name} ; do
699 if [[ -e $PORTAGE_BUILDDIR/.pretended ]] ; then
700 vecho ">>> It appears that '$PF' is already pretended; skipping."
701 vecho ">>> Remove '$PORTAGE_BUILDDIR/.pretended' to force pretend."
704 ebuild_phase pre_pkg_pretend
705 ebuild_phase pkg_pretend
706 >> "$PORTAGE_BUILDDIR/.pretended" || \
707 die "Failed to create $PORTAGE_BUILDDIR/.pretended"
708 ebuild_phase post_pkg_pretend
712 if [[ -e $PORTAGE_BUILDDIR/.setuped ]] ; then
713 vecho ">>> It appears that '$PF' is already setup; skipping."
714 vecho ">>> Remove '$PORTAGE_BUILDDIR/.setuped' to force setup."
717 ebuild_phase pre_pkg_setup
718 ebuild_phase pkg_setup
719 >> "$PORTAGE_BUILDDIR/.setuped" || \
720 die "Failed to create $PORTAGE_BUILDDIR/.setuped"
721 ebuild_phase post_pkg_setup
726 if [ -e "${WORKDIR}" ]; then
730 vecho ">>> Checking ${x}'s mtime..."
731 if [ "${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/${x}" -nt "${WORKDIR}" ]; then
732 vecho ">>> ${x} has been updated; recreating WORKDIR..."
737 if [ ! -f "${PORTAGE_BUILDDIR}/.unpacked" ] ; then
738 vecho ">>> Not marked as unpacked; recreating WORKDIR..."
742 if [ "${newstuff}" == "yes" ]; then
743 # We don't necessarily have privileges to do a full dyn_clean here.
744 rm -rf "${PORTAGE_BUILDDIR}"/{.setuped,.unpacked,.prepared,.configured,.compiled,.tested,.installed,.packaged,build-info}
745 if ! hasq keepwork $FEATURES ; then
748 if [ -d "${T}" ] && \
749 ! hasq keeptemp $FEATURES ; then
750 rm -rf "${T}" && mkdir "${T}"
753 if [ -e "${WORKDIR}" ]; then
754 if [ "$newstuff" == "no" ]; then
755 vecho ">>> WORKDIR is up-to-date, keeping..."
760 if [ ! -d "${WORKDIR}" ]; then
761 install -m${PORTAGE_WORKDIR_MODE:-0700} -d "${WORKDIR}" || die "Failed to create dir '${WORKDIR}'"
763 cd "${WORKDIR}" || die "Directory change failed: \`cd '${WORKDIR}'\`"
764 ebuild_phase pre_src_unpack
765 vecho ">>> Unpacking source..."
766 ebuild_phase src_unpack
767 >> "$PORTAGE_BUILDDIR/.unpacked" || \
768 die "Failed to create $PORTAGE_BUILDDIR/.unpacked"
769 vecho ">>> Source unpacked in ${WORKDIR}"
770 ebuild_phase post_src_unpack
774 if [ -z "${PORTAGE_BUILDDIR}" ]; then
775 echo "Aborting clean phase because PORTAGE_BUILDDIR is unset!"
777 elif [ ! -d "${PORTAGE_BUILDDIR}" ] ; then
780 if hasq chflags $FEATURES ; then
781 chflags -R noschg,nouchg,nosappnd,nouappnd "${PORTAGE_BUILDDIR}"
782 chflags -R nosunlnk,nouunlnk "${PORTAGE_BUILDDIR}" 2>/dev/null
785 rm -rf "${PORTAGE_BUILDDIR}/image" "${PORTAGE_BUILDDIR}/homedir"
786 rm -f "${PORTAGE_BUILDDIR}/.installed"
788 if [[ $EMERGE_FROM = binary ]] || \
789 ! hasq keeptemp $FEATURES && ! hasq keepwork $FEATURES ; then
793 if [[ $EMERGE_FROM = binary ]] || ! hasq keepwork $FEATURES; then
794 rm -f "$PORTAGE_BUILDDIR"/.{ebuild_changed,logid,pretended,setuped,unpacked,prepared} \
795 "$PORTAGE_BUILDDIR"/.{configured,compiled,tested,packaged} \
796 "$PORTAGE_BUILDDIR"/.die_hooks \
797 "$PORTAGE_BUILDDIR"/.ipc_{in,out,lock} \
798 "$PORTAGE_BUILDDIR"/.exit_status
800 rm -rf "${PORTAGE_BUILDDIR}/build-info"
804 if [ -f "${PORTAGE_BUILDDIR}/.unpacked" ]; then
805 find "${PORTAGE_BUILDDIR}" -type d ! -regex "^${WORKDIR}" | sort -r | tr "\n" "\0" | $XARGS -0 rmdir &>/dev/null
808 # do not bind this to doebuild defined DISTDIR; don't trust doebuild, and if mistakes are made it'll
809 # result in it wiping the users distfiles directory (bad).
810 rm -rf "${PORTAGE_BUILDDIR}/distdir"
812 # Some kernels, such as Solaris, return EINVAL when an attempt
813 # is made to remove the current working directory.
814 cd "$PORTAGE_BUILDDIR"/../..
815 rmdir "$PORTAGE_BUILDDIR" 2>/dev/null
821 if [ "$1" == "/" ]; then
825 if [ ! -d "${D}${DESTTREE}" ]; then
826 install -d "${D}${DESTTREE}"
828 if [[ $ret -ne 0 ]] ; then
829 helpers_die "${FUNCNAME[0]} failed"
837 if [ "$1" == "/" ]; then
838 export INSDESTTREE=""
840 export INSDESTTREE=$1
841 if [ ! -d "${D}${INSDESTTREE}" ]; then
842 install -d "${D}${INSDESTTREE}"
844 if [[ $ret -ne 0 ]] ; then
845 helpers_die "${FUNCNAME[0]} failed"
853 if [ "$1" == "/" ]; then
854 export _E_EXEDESTTREE_=""
856 export _E_EXEDESTTREE_="$1"
857 if [ ! -d "${D}${_E_EXEDESTTREE_}" ]; then
858 install -d "${D}${_E_EXEDESTTREE_}"
860 if [[ $ret -ne 0 ]] ; then
861 helpers_die "${FUNCNAME[0]} failed"
869 if [ "$1" == "/" ]; then
870 export _E_DOCDESTTREE_=""
872 export _E_DOCDESTTREE_="$1"
873 if [ ! -d "${D}usr/share/doc/${PF}/${_E_DOCDESTTREE_}" ]; then
874 install -d "${D}usr/share/doc/${PF}/${_E_DOCDESTTREE_}"
876 if [[ $ret -ne 0 ]] ; then
877 helpers_die "${FUNCNAME[0]} failed"
885 export INSOPTIONS="$@"
887 # `install` should never be called with '-s' ...
888 hasq -s ${INSOPTIONS} && die "Never call insopts() with -s"
892 export DIROPTIONS="$@"
896 export EXEOPTIONS="$@"
898 # `install` should never be called with '-s' ...
899 hasq -s ${EXEOPTIONS} && die "Never call exeopts() with -s"
903 export LIBOPTIONS="$@"
905 # `install` should never be called with '-s' ...
906 hasq -s ${LIBOPTIONS} && die "Never call libopts() with -s"
910 hasq "${EAPI}" 0 1 2 3 && die "'docompress' not supported in this EAPI"
913 if [[ $1 = "-x" ]]; then
916 f=$(strip_duplicate_slashes "${f}"); f=${f%/}
917 [[ ${f:0:1} = / ]] || f="/${f}"
918 for g in "${PORTAGE_DOCOMPRESS_SKIP[@]}"; do
919 [[ ${f} = "${g}" ]] && continue 2
921 PORTAGE_DOCOMPRESS_SKIP[${#PORTAGE_DOCOMPRESS_SKIP[@]}]=${f}
925 f=$(strip_duplicate_slashes "${f}"); f=${f%/}
926 [[ ${f:0:1} = / ]] || f="/${f}"
927 for g in "${PORTAGE_DOCOMPRESS[@]}"; do
928 [[ ${f} = "${g}" ]] && continue 2
930 PORTAGE_DOCOMPRESS[${#PORTAGE_DOCOMPRESS[@]}]=${f}
937 if [ "$2" != "fail" ]; then
938 msg="${EBUILD}: ${1} aborted; exiting."
940 msg="${EBUILD}: ${1} failed; exiting."
946 #unset signal handler
947 trap - SIGINT SIGQUIT
951 abort_handler src_prepare $1
952 rm -f "$PORTAGE_BUILDDIR/.prepared"
957 abort_handler src_configure $1
958 rm -f "$PORTAGE_BUILDDIR/.configured"
963 abort_handler "src_compile" $1
964 rm -f "${PORTAGE_BUILDDIR}/.compiled"
969 abort_handler "dyn_test" $1
970 rm -f "${PORTAGE_BUILDDIR}/.tested"
975 abort_handler "src_install" $1
976 rm -rf "${PORTAGE_BUILDDIR}/image"
980 has_phase_defined_up_to() {
982 for phase in unpack prepare configure compile install; do
983 has ${phase} ${DEFINED_PHASES} && return 0
984 [[ ${phase} == $1 ]] && return 1
986 # We shouldn't actually get here
992 if [[ -e $PORTAGE_BUILDDIR/.prepared ]] ; then
993 vecho ">>> It appears that '$PF' is already prepared; skipping."
994 vecho ">>> Remove '$PORTAGE_BUILDDIR/.prepared' to force prepare."
998 if [[ -d $S ]] ; then
1000 elif hasq $EAPI 0 1 2 3 3_pre2 ; then
1002 elif [[ -z ${A} ]] && ! has_phase_defined_up_to prepare; then
1005 die "The source directory '${S}' doesn't exist"
1008 trap abort_prepare SIGINT SIGQUIT
1010 ebuild_phase pre_src_prepare
1011 vecho ">>> Preparing source in $PWD ..."
1012 ebuild_phase src_prepare
1013 >> "$PORTAGE_BUILDDIR/.prepared" || \
1014 die "Failed to create $PORTAGE_BUILDDIR/.prepared"
1015 vecho ">>> Source prepared."
1016 ebuild_phase post_src_prepare
1018 trap - SIGINT SIGQUIT
1023 if [[ -e $PORTAGE_BUILDDIR/.configured ]] ; then
1024 vecho ">>> It appears that '$PF' is already configured; skipping."
1025 vecho ">>> Remove '$PORTAGE_BUILDDIR/.configured' to force configuration."
1029 if [[ -d $S ]] ; then
1031 elif hasq $EAPI 0 1 2 3 3_pre2 ; then
1033 elif [[ -z ${A} ]] && ! has_phase_defined_up_to configure; then
1036 die "The source directory '${S}' doesn't exist"
1039 trap abort_configure SIGINT SIGQUIT
1041 ebuild_phase pre_src_configure
1043 vecho ">>> Configuring source in $PWD ..."
1044 ebuild_phase src_configure
1045 >> "$PORTAGE_BUILDDIR/.configured" || \
1046 die "Failed to create $PORTAGE_BUILDDIR/.configured"
1047 vecho ">>> Source configured."
1049 ebuild_phase post_src_configure
1051 trap - SIGINT SIGQUIT
1056 if [[ -e $PORTAGE_BUILDDIR/.compiled ]] ; then
1057 vecho ">>> It appears that '${PF}' is already compiled; skipping."
1058 vecho ">>> Remove '$PORTAGE_BUILDDIR/.compiled' to force compilation."
1062 if [[ -d $S ]] ; then
1064 elif hasq $EAPI 0 1 2 3 3_pre2 ; then
1066 elif [[ -z ${A} ]] && ! has_phase_defined_up_to compile; then
1069 die "The source directory '${S}' doesn't exist"
1072 trap abort_compile SIGINT SIGQUIT
1074 if hasq distcc $FEATURES && hasq distcc-pump $FEATURES ; then
1075 if [[ -z $INCLUDE_SERVER_PORT ]] || [[ ! -w $INCLUDE_SERVER_PORT ]] ; then
1076 eval $(/usr/bin/pump --startup)
1077 trap "/usr/bin/pump --shutdown" EXIT
1081 ebuild_phase pre_src_compile
1083 vecho ">>> Compiling source in $PWD ..."
1084 ebuild_phase src_compile
1085 >> "$PORTAGE_BUILDDIR/.compiled" || \
1086 die "Failed to create $PORTAGE_BUILDDIR/.compiled"
1087 vecho ">>> Source compiled."
1089 ebuild_phase post_src_compile
1091 trap - SIGINT SIGQUIT
1096 if [[ -e $PORTAGE_BUILDDIR/.tested ]] ; then
1097 vecho ">>> It appears that ${PN} has already been tested; skipping."
1098 vecho ">>> Remove '${PORTAGE_BUILDDIR}/.tested' to force test."
1102 if [ "${EBUILD_FORCE_TEST}" == "1" ] ; then
1103 # If USE came from ${T}/environment then it might not have USE=test
1104 # like it's supposed to here.
1105 ! hasq test ${USE} && export USE="${USE} test"
1108 trap "abort_test" SIGINT SIGQUIT
1109 if [ -d "${S}" ]; then
1115 if ! hasq test $FEATURES && [ "${EBUILD_FORCE_TEST}" != "1" ]; then
1116 vecho ">>> Test phase [not enabled]: ${CATEGORY}/${PF}"
1117 elif hasq test $RESTRICT; then
1118 einfo "Skipping make test/check due to ebuild restriction."
1119 vecho ">>> Test phase [explicitly disabled]: ${CATEGORY}/${PF}"
1121 local save_sp=${SANDBOX_PREDICT}
1123 ebuild_phase pre_src_test
1124 ebuild_phase src_test
1125 >> "$PORTAGE_BUILDDIR/.tested" || \
1126 die "Failed to create $PORTAGE_BUILDDIR/.tested"
1127 ebuild_phase post_src_test
1128 SANDBOX_PREDICT=${save_sp}
1131 trap - SIGINT SIGQUIT
1135 [ -z "$PORTAGE_BUILDDIR" ] && die "${FUNCNAME}: PORTAGE_BUILDDIR is unset"
1136 if hasq noauto $FEATURES ; then
1137 rm -f "${PORTAGE_BUILDDIR}/.installed"
1138 elif [[ -e $PORTAGE_BUILDDIR/.installed ]] ; then
1139 vecho ">>> It appears that '${PF}' is already installed; skipping."
1140 vecho ">>> Remove '${PORTAGE_BUILDDIR}/.installed' to force install."
1143 trap "abort_install" SIGINT SIGQUIT
1144 ebuild_phase pre_src_install
1145 rm -rf "${PORTAGE_BUILDDIR}/image"
1146 mkdir "${PORTAGE_BUILDDIR}/image"
1147 if [[ -d $S ]] ; then
1149 elif hasq $EAPI 0 1 2 3 3_pre2 ; then
1151 elif [[ -z ${A} ]] && ! has_phase_defined_up_to install; then
1154 die "The source directory '${S}' doesn't exist"
1158 vecho ">>> Install ${PF} into ${D} category ${CATEGORY}"
1159 #our custom version of libtool uses $S and $D to fix
1160 #invalid paths in .la files
1163 # Reset exeinto(), docinto(), insinto(), and into() state variables
1164 # in case the user is running the install phase multiple times
1165 # consecutively via the ebuild command.
1166 export DESTTREE=/usr
1167 export INSDESTTREE=""
1168 export _E_EXEDESTTREE_=""
1169 export _E_DOCDESTTREE_=""
1171 ebuild_phase src_install
1172 >> "$PORTAGE_BUILDDIR/.installed" || \
1173 die "Failed to create $PORTAGE_BUILDDIR/.installed"
1174 vecho ">>> Completed installing ${PF} into ${D}"
1176 ebuild_phase post_src_install
1178 cd "${PORTAGE_BUILDDIR}"/build-info
1182 for f in CATEGORY DEFINED_PHASES FEATURES INHERITED IUSE REQUIRED_USE \
1183 PF PKGUSE SLOT KEYWORDS HOMEPAGE DESCRIPTION ; do
1185 [[ -n $x ]] && echo "$x" > $f
1187 if [[ $CATEGORY != virtual ]] ; then
1188 for f in ASFLAGS CBUILD CC CFLAGS CHOST CTARGET CXX \
1189 CXXFLAGS EXTRA_ECONF EXTRA_EINSTALL EXTRA_MAKE \
1190 LDFLAGS LIBCFLAGS LIBCXXFLAGS ; do
1192 [[ -n $x ]] && echo "$x" > $f
1196 echo "${EAPI:-0}" > EAPI
1199 # local variables can leak into the saved environment.
1202 save_ebuild_env --exclude-init-phases | filter_readonly_variables \
1203 --filter-path --filter-sandbox --allow-extra-vars > environment
1204 assert "save_ebuild_env failed"
1206 ${PORTAGE_BZIP2_COMMAND} -f9 environment
1208 cp "${EBUILD}" "${PF}.ebuild"
1209 [ -n "${PORTAGE_REPO_NAME}" ] && echo "${PORTAGE_REPO_NAME}" > repository
1210 if hasq nostrip ${FEATURES} ${RESTRICT} || hasq strip ${RESTRICT}
1214 trap - SIGINT SIGQUIT
1218 if [ -z "${D}" ]; then
1219 eerror "${FUNCNAME}: D is unset"
1222 ebuild_phase_with_hooks pkg_preinst
1228 echo "Copyright 1999-2010 Gentoo Foundation"
1230 echo "How to use the ebuild command:"
1232 echo "The first argument to ebuild should be an existing .ebuild file."
1234 echo "One or more of the following options can then be specified. If more"
1235 echo "than one option is specified, each will be executed in order."
1237 echo " help : show this help screen"
1238 echo " pretend : execute package specific pretend actions"
1239 echo " setup : execute package specific setup actions"
1240 echo " fetch : download source archive(s) and patches"
1241 echo " digest : create a manifest file for the package"
1242 echo " manifest : create a manifest file for the package"
1243 echo " unpack : unpack sources (auto-dependencies if needed)"
1244 echo " prepare : prepare sources (auto-dependencies if needed)"
1245 echo " configure : configure sources (auto-fetch/unpack if needed)"
1246 echo " compile : compile sources (auto-fetch/unpack/configure if needed)"
1247 echo " test : test package (auto-fetch/unpack/configure/compile if needed)"
1248 echo " preinst : execute pre-install instructions"
1249 echo " postinst : execute post-install instructions"
1250 echo " install : install the package to the temporary install directory"
1251 echo " qmerge : merge image into live filesystem, recording files in db"
1252 echo " merge : do fetch, unpack, compile, install and qmerge"
1253 echo " prerm : execute pre-removal instructions"
1254 echo " postrm : execute post-removal instructions"
1255 echo " unmerge : remove package from live filesystem"
1256 echo " config : execute package specific configuration actions"
1257 echo " package : create a tarball package in ${PKGDIR}/All"
1258 echo " rpm : build a RedHat RPM package"
1259 echo " clean : clean up all source and temporary files"
1261 echo "The following settings will be used for the ebuild process:"
1263 echo " package : ${PF}"
1264 echo " slot : ${SLOT}"
1265 echo " category : ${CATEGORY}"
1266 echo " description : ${DESCRIPTION}"
1267 echo " system : ${CHOST}"
1268 echo " c flags : ${CFLAGS}"
1269 echo " c++ flags : ${CXXFLAGS}"
1270 echo " make flags : ${MAKEOPTS}"
1271 echo -n " build mode : "
1272 if hasq nostrip ${FEATURES} ${RESTRICT} || hasq strip ${RESTRICT} ;
1274 echo "debug (large)"
1276 echo "production (stripped)"
1278 echo " merge to : ${ROOT}"
1280 if [ -n "$USE" ]; then
1281 echo "Additionally, support for the following optional features will be enabled:"
1288 # debug-print() gets called from many places with verbose status information useful
1289 # for tracking down problems. The output is in $T/eclass-debug.log.
1290 # You can set ECLASS_DEBUG_OUTPUT to redirect the output somewhere else as well.
1291 # The special "on" setting echoes the information, mixing it with the rest of the
1293 # You can override the setting by exporting a new one from the console, or you can
1294 # set a new default in make.*. Here the default is "" or unset.
1296 # in the future might use e* from /etc/init.d/functions.sh if i feel like it
1298 # if $T isn't defined, we're in dep calculation mode and
1299 # shouldn't do anything
1300 [[ $EBUILD_PHASE = depend || ! -d ${T} || ${#} -eq 0 ]] && return 0
1302 if [[ ${ECLASS_DEBUG_OUTPUT} == on ]]; then
1303 printf 'debug: %s\n' "${@}" >&2
1304 elif [[ -n ${ECLASS_DEBUG_OUTPUT} ]]; then
1305 printf 'debug: %s\n' "${@}" >> "${ECLASS_DEBUG_OUTPUT}"
1308 if [[ -w $T ]] ; then
1310 printf '%s\n' "${@}" >> "${T}/eclass-debug.log"
1311 # let the portage user own/write to this file
1312 chgrp portage "${T}/eclass-debug.log" &>/dev/null
1313 chmod g+w "${T}/eclass-debug.log" &>/dev/null
1317 # The following 2 functions are debug-print() wrappers
1319 debug-print-function() {
1320 debug-print "${1}: entering function, parameters: ${*:2}"
1323 debug-print-section() {
1324 debug-print "now in section ${*}"
1327 # Sources all eclasses in parameters
1328 declare -ix ECLASS_DEPTH=0
1330 ECLASS_DEPTH=$(($ECLASS_DEPTH + 1))
1331 if [[ ${ECLASS_DEPTH} > 1 ]]; then
1332 debug-print "*** Multiple Inheritence (Level: ${ECLASS_DEPTH})"
1335 if [[ -n $ECLASS && -n ${!__export_funcs_var} ]] ; then
1336 echo "QA Notice: EXPORT_FUNCTIONS is called before inherit in" \
1337 "$ECLASS.eclass. For compatibility with <=portage-2.1.6.7," \
1338 "only call EXPORT_FUNCTIONS after inherit(s)." \
1339 | fmt -w 75 | while read -r ; do eqawarn "$REPLY" ; done
1346 # These variables must be restored before returning.
1347 local PECLASS=$ECLASS
1348 local prev_export_funcs_var=$__export_funcs_var
1351 local B_REQUIRED_USE
1356 location="${ECLASSDIR}/${1}.eclass"
1360 __export_funcs_var=__export_functions_$ECLASS_DEPTH
1361 unset $__export_funcs_var
1363 if [ "${EBUILD_PHASE}" != "depend" ] && \
1364 [[ ${EBUILD_PHASE} != *rm ]] && \
1365 [[ ${EMERGE_FROM} != "binary" ]] ; then
1366 # This is disabled in the *rm phases because they frequently give
1367 # false alarms due to INHERITED in /var/db/pkg being outdated
1368 # in comparison the the eclasses from the portage tree.
1369 if ! hasq $ECLASS $INHERITED $__INHERITED_QA_CACHE ; then
1370 eqawarn "QA Notice: ECLASS '$ECLASS' inherited illegally in $CATEGORY/$PF $EBUILD_PHASE"
1374 # any future resolution code goes here
1375 if [ -n "$PORTDIR_OVERLAY" ]; then
1377 for overlay in ${PORTDIR_OVERLAY}; do
1378 olocation="${overlay}/eclass/${1}.eclass"
1379 if [ -e "$olocation" ]; then
1380 location="${olocation}"
1381 debug-print " eclass exists: ${location}"
1385 debug-print "inherit: $1 -> $location"
1386 [ ! -e "$location" ] && die "${1}.eclass could not be found by inherit()"
1388 if [ "${location}" == "${olocation}" ] && \
1389 ! hasq "${location}" ${EBUILD_OVERLAY_ECLASSES} ; then
1390 EBUILD_OVERLAY_ECLASSES="${EBUILD_OVERLAY_ECLASSES} ${location}"
1393 #We need to back up the value of DEPEND and RDEPEND to B_DEPEND and B_RDEPEND
1394 #(if set).. and then restore them after the inherit call.
1396 #turn off glob expansion
1399 # Retain the old data and restore it later.
1400 unset B_IUSE B_REQUIRED_USE B_DEPEND B_RDEPEND B_PDEPEND
1401 [ "${IUSE+set}" = set ] && B_IUSE="${IUSE}"
1402 [ "${REQUIRED_USE+set}" = set ] && B_REQUIRED_USE="${REQUIRED_USE}"
1403 [ "${DEPEND+set}" = set ] && B_DEPEND="${DEPEND}"
1404 [ "${RDEPEND+set}" = set ] && B_RDEPEND="${RDEPEND}"
1405 [ "${PDEPEND+set}" = set ] && B_PDEPEND="${PDEPEND}"
1406 unset IUSE REQUIRED_USE DEPEND RDEPEND PDEPEND
1407 #turn on glob expansion
1410 qa_source "$location" || die "died sourcing $location in inherit()"
1412 #turn off glob expansion
1415 # If each var has a value, append it to the global variable E_* to
1416 # be applied after everything is finished. New incremental behavior.
1417 [ "${IUSE+set}" = set ] && export E_IUSE="${E_IUSE} ${IUSE}"
1418 [ "${REQUIRED_USE+set}" = set ] && export E_REQUIRED_USE="${E_REQUIRED_USE} ${REQUIRED_USE}"
1419 [ "${DEPEND+set}" = set ] && export E_DEPEND="${E_DEPEND} ${DEPEND}"
1420 [ "${RDEPEND+set}" = set ] && export E_RDEPEND="${E_RDEPEND} ${RDEPEND}"
1421 [ "${PDEPEND+set}" = set ] && export E_PDEPEND="${E_PDEPEND} ${PDEPEND}"
1423 [ "${B_IUSE+set}" = set ] && IUSE="${B_IUSE}"
1424 [ "${B_IUSE+set}" = set ] || unset IUSE
1426 [ "${B_REQUIRED_USE+set}" = set ] && REQUIRED_USE="${B_REQUIRED_USE}"
1427 [ "${B_REQUIRED_USE+set}" = set ] || unset REQUIRED_USE
1429 [ "${B_DEPEND+set}" = set ] && DEPEND="${B_DEPEND}"
1430 [ "${B_DEPEND+set}" = set ] || unset DEPEND
1432 [ "${B_RDEPEND+set}" = set ] && RDEPEND="${B_RDEPEND}"
1433 [ "${B_RDEPEND+set}" = set ] || unset RDEPEND
1435 [ "${B_PDEPEND+set}" = set ] && PDEPEND="${B_PDEPEND}"
1436 [ "${B_PDEPEND+set}" = set ] || unset PDEPEND
1438 #turn on glob expansion
1441 if [[ -n ${!__export_funcs_var} ]] ; then
1442 for x in ${!__export_funcs_var} ; do
1443 debug-print "EXPORT_FUNCTIONS: $x -> ${ECLASS}_$x"
1444 declare -F "${ECLASS}_$x" >/dev/null || \
1445 die "EXPORT_FUNCTIONS: ${ECLASS}_$x is not defined"
1446 eval "$x() { ${ECLASS}_$x \"\$@\" ; }" > /dev/null
1449 unset $__export_funcs_var
1451 hasq $1 $INHERITED || export INHERITED="$INHERITED $1"
1455 ((--ECLASS_DEPTH)) # Returns 1 when ECLASS_DEPTH reaches 0.
1456 if (( ECLASS_DEPTH > 0 )) ; then
1457 export ECLASS=$PECLASS
1458 __export_funcs_var=$prev_export_funcs_var
1460 unset ECLASS __export_funcs_var
1465 # Exports stub functions that call the eclass's functions, thereby making them default.
1466 # For example, if ECLASS="base" and you call "EXPORT_FUNCTIONS src_unpack", the following
1467 # code will be eval'd:
1468 # src_unpack() { base_src_unpack; }
1469 EXPORT_FUNCTIONS() {
1470 if [ -z "$ECLASS" ]; then
1471 die "EXPORT_FUNCTIONS without a defined ECLASS"
1473 eval $__export_funcs_var+=\" $*\"
1476 # this is a function for removing any directory matching a passed in pattern from
1478 remove_path_entry() {
1481 stripped_path="${PATH}"
1482 while [ -n "$1" ]; do
1484 for p in ${stripped_path}; do
1485 if [ "${p/${1}}" == "${p}" ]; then
1486 cur_path="${cur_path}:${p}"
1489 stripped_path="${cur_path#:*}"
1493 PATH="${stripped_path}"
1496 # @FUNCTION: _ebuild_arg_to_phase
1498 # Translate a known ebuild(1) argument into the precise
1499 # name of it's corresponding ebuild phase.
1500 _ebuild_arg_to_phase() {
1501 [ $# -ne 2 ] && die "expected exactly 2 args, got $#: $*"
1508 ! hasq $eapi 0 1 2 3 3_pre2 && \
1509 phase_func=pkg_pretend
1512 phase_func=pkg_setup
1515 phase_func=pkg_nofetch
1518 phase_func=src_unpack
1521 ! hasq $eapi 0 1 && \
1522 phase_func=src_prepare
1525 ! hasq $eapi 0 1 && \
1526 phase_func=src_configure
1529 phase_func=src_compile
1535 phase_func=src_install
1538 phase_func=pkg_preinst
1541 phase_func=pkg_postinst
1544 phase_func=pkg_prerm
1547 phase_func=pkg_postrm
1551 [[ -z $phase_func ]] && return 1
1556 _ebuild_phase_funcs() {
1557 [ $# -ne 2 ] && die "expected exactly 2 args, got $#: $*"
1560 local default_phases="pkg_nofetch src_unpack src_prepare src_configure
1561 src_compile src_install src_test"
1562 local x y default_func=""
1564 for x in pkg_nofetch src_unpack src_test ; do
1565 declare -F $x >/dev/null || \
1566 eval "$x() { _eapi0_$x \"\$@\" ; }"
1573 if ! declare -F src_compile >/dev/null ; then
1576 src_compile() { _eapi0_src_compile "$@" ; }
1579 src_compile() { _eapi1_src_compile "$@" ; }
1584 for x in $default_phases ; do
1585 eval "default_$x() {
1586 die \"default_$x() is not supported with EAPI='$eapi' during phase $phase_func\"
1591 die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
1598 declare -F src_configure >/dev/null || \
1599 src_configure() { _eapi2_src_configure "$@" ; }
1601 declare -F src_compile >/dev/null || \
1602 src_compile() { _eapi2_src_compile "$@" ; }
1604 has $eapi 2 3 3_pre2 || declare -F src_install >/dev/null || \
1605 src_install() { _eapi4_src_install "$@" ; }
1607 if hasq $phase_func $default_phases ; then
1609 _eapi2_pkg_nofetch () { _eapi0_pkg_nofetch "$@" ; }
1610 _eapi2_src_unpack () { _eapi0_src_unpack "$@" ; }
1611 _eapi2_src_prepare () { true ; }
1612 _eapi2_src_test () { _eapi0_src_test "$@" ; }
1613 _eapi2_src_install () { die "$FUNCNAME is not supported" ; }
1615 for x in $default_phases ; do
1616 eval "default_$x() { _eapi2_$x \"\$@\" ; }"
1619 eval "default() { _eapi2_$phase_func \"\$@\" ; }"
1625 eval "default_src_install() { _eapi4_src_install \"\$@\" ; }"
1626 [[ $phase_func = src_install ]] && \
1627 eval "default() { _eapi4_$phase_func \"\$@\" ; }"
1633 for x in $default_phases ; do
1634 eval "default_$x() {
1635 die \"default_$x() is not supported in phase $default_func\"
1640 die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
1649 # Set given variables unless these variable have been already set (e.g. during emerge
1650 # invocation) to values different than values set in make.conf.
1651 set_unless_changed() {
1652 if [[ $# -lt 1 ]]; then
1653 die "${FUNCNAME}() requires at least 1 argument: VARIABLE=VALUE"
1656 local argument value variable
1657 for argument in "$@"; do
1658 if [[ ${argument} != *=* ]]; then
1659 die "${FUNCNAME}(): Argument '${argument}' has incorrect syntax"
1661 variable="${argument%%=*}"
1662 value="${argument#*=}"
1663 if eval "[[ \${${variable}} == \$(env -u ${variable} portageq envvar ${variable}) ]]"; then
1664 eval "${variable}=\"\${value}\""
1669 # Unset given variables unless these variable have been set (e.g. during emerge
1670 # invocation) to values different than values set in make.conf.
1671 unset_unless_changed() {
1672 if [[ $# -lt 1 ]]; then
1673 die "${FUNCNAME}() requires at least 1 argument: VARIABLE"
1677 for variable in "$@"; do
1678 if eval "[[ \${${variable}} == \$(env -u ${variable} portageq envvar ${variable}) ]]"; then
1684 PORTAGE_BASHRCS_SOURCED=0
1686 # @FUNCTION: source_all_bashrcs
1688 # Source a relevant bashrc files and perform other miscellaneous
1689 # environment initialization when appropriate.
1691 # If EAPI is set then define functions provided by the current EAPI:
1693 # * default_* aliases for the current EAPI phase functions
1694 # * A "default" function which is an alias for the default phase
1695 # function for the current phase.
1697 source_all_bashrcs() {
1698 [[ $PORTAGE_BASHRCS_SOURCED = 1 ]] && return 0
1699 PORTAGE_BASHRCS_SOURCED=1
1702 local OCC="${CC}" OCXX="${CXX}"
1704 if [[ $EBUILD_PHASE != depend ]] ; then
1705 # source the existing profile.bashrcs.
1708 local path_array=($PROFILE_PATHS)
1710 for x in "${path_array[@]}" ; do
1711 [ -f "$x/profile.bashrc" ] && qa_source "$x/profile.bashrc"
1715 # We assume if people are changing shopts in their bashrc they do so at their
1716 # own peril. This is the ONLY non-portage bit of code that can change shopts
1717 # without a QA violation.
1718 for x in "${PORTAGE_BASHRC}" "${PM_EBUILD_HOOK_DIR}"/${CATEGORY}/{${PN},${PN}:${SLOT},${P},${PF}}; do
1719 if [ -r "${x}" ]; then
1720 # If $- contains x, then tracing has already enabled elsewhere for some
1721 # reason. We preserve it's state so as not to interfere.
1722 if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then
1732 [ ! -z "${OCC}" ] && export CC="${OCC}"
1733 [ ! -z "${OCXX}" ] && export CXX="${OCXX}"
1736 # Hardcoded bash lists are needed for backward compatibility with
1737 # <portage-2.1.4 since they assume that a newly installed version
1738 # of ebuild.sh will work for pkg_postinst, pkg_prerm, and pkg_postrm
1739 # when portage is upgrading itself.
1741 PORTAGE_READONLY_METADATA="DEFINED_PHASES DEPEND DESCRIPTION
1742 EAPI HOMEPAGE INHERITED IUSE REQUIRED_USE KEYWORDS LICENSE
1743 PDEPEND PROVIDE RDEPEND RESTRICT SLOT SRC_URI"
1745 PORTAGE_READONLY_VARS="D EBUILD EBUILD_PHASE \
1746 EBUILD_SH_ARGS ECLASSDIR EMERGE_FROM FILESDIR MERGE_TYPE \
1747 PM_EBUILD_HOOK_DIR \
1748 PORTAGE_ACTUAL_DISTDIR PORTAGE_ARCHLIST PORTAGE_BASHRC \
1749 PORTAGE_BINPKG_FILE PORTAGE_BINPKG_TAR_OPTS PORTAGE_BINPKG_TMPFILE \
1750 PORTAGE_BIN_PATH PORTAGE_BUILDDIR PORTAGE_BUNZIP2_COMMAND \
1751 PORTAGE_BZIP2_COMMAND PORTAGE_COLORMAP PORTAGE_CONFIGROOT \
1752 PORTAGE_DEBUG PORTAGE_DEPCACHEDIR PORTAGE_EBUILD_EXIT_FILE \
1753 PORTAGE_GID PORTAGE_GRPNAME PORTAGE_INST_GID PORTAGE_INST_UID \
1754 PORTAGE_IPC_DAEMON PORTAGE_IUSE PORTAGE_LOG_FILE \
1755 PORTAGE_MUTABLE_FILTERED_VARS PORTAGE_PYM_PATH PORTAGE_PYTHON \
1756 PORTAGE_READONLY_METADATA PORTAGE_READONLY_VARS \
1757 PORTAGE_REPO_NAME PORTAGE_RESTRICT PORTAGE_SANDBOX_COMPAT_LEVEL \
1758 PORTAGE_SAVED_READONLY_VARS PORTAGE_SIGPIPE_STATUS \
1759 PORTAGE_TMPDIR PORTAGE_UPDATE_ENV PORTAGE_USERNAME \
1760 PORTAGE_VERBOSE PORTAGE_WORKDIR_MODE PORTDIR PORTDIR_OVERLAY \
1761 PROFILE_PATHS REPLACING_VERSIONS REPLACED_BY_VERSION T WORKDIR"
1763 PORTAGE_SAVED_READONLY_VARS="A CATEGORY P PF PN PR PV PVR"
1765 # Variables that portage sets but doesn't mark readonly.
1766 # In order to prevent changed values from causing unexpected
1767 # interference, they are filtered out of the environment when
1768 # it is saved or loaded (any mutations do not persist).
1769 PORTAGE_MUTABLE_FILTERED_VARS="AA HOSTNAME"
1771 # @FUNCTION: filter_readonly_variables
1772 # @DESCRIPTION: [--filter-sandbox] [--allow-extra-vars]
1773 # Read an environment from stdin and echo to stdout while filtering variables
1774 # with names that are known to cause interference:
1776 # * some specific variables for which bash does not allow assignment
1777 # * some specific variables that affect portage or sandbox behavior
1778 # * variable names that begin with a digit or that contain any
1779 # non-alphanumeric characters that are not be supported by bash
1781 # --filter-sandbox causes all SANDBOX_* variables to be filtered, which
1782 # is only desired in certain cases, such as during preprocessing or when
1783 # saving environment.bz2 for a binary or installed package.
1785 # --filter-features causes the special FEATURES variable to be filtered.
1786 # Generally, we want it to persist between phases since the user might
1787 # want to modify it via bashrc to enable things like splitdebug and
1788 # installsources for specific packages. They should be able to modify it
1789 # in pre_pkg_setup() and have it persist all the way through the install
1790 # phase. However, if FEATURES exist inside environment.bz2 then they
1791 # should be overridden by current settings.
1793 # --filter-locale causes locale related variables such as LANG and LC_*
1794 # variables to be filtered. These variables should persist between phases,
1795 # in case they are modified by the ebuild. However, the current user
1796 # settings should be used when loading the environment from a binary or
1797 # installed package.
1799 # --filter-path causes the PATH variable to be filtered. This variable
1800 # should persist between phases, in case it is modified by the ebuild.
1801 # However, old settings should be overridden when loading the
1802 # environment from a binary or installed package.
1804 # ---allow-extra-vars causes some extra vars to be allowd through, such
1805 # as ${PORTAGE_SAVED_READONLY_VARS} and ${PORTAGE_MUTABLE_FILTERED_VARS}.
1807 # In bash-3.2_p20+ an attempt to assign BASH_*, FUNCNAME, GROUPS or any
1808 # readonly variable cause the shell to exit while executing the "source"
1809 # builtin command. To avoid this problem, this function filters those
1810 # variables out and discards them. See bug #190128.
1811 filter_readonly_variables() {
1812 local x filtered_vars
1813 local readonly_bash_vars="BASHOPTS BASHPID DIRSTACK EUID
1814 FUNCNAME GROUPS PIPESTATUS PPID SHELLOPTS UID"
1815 local bash_misc_vars="BASH BASH_.* COMP_WORDBREAKS HISTCMD
1816 HISTFILE HOSTNAME HOSTTYPE IFS LINENO MACHTYPE OLDPWD
1817 OPTERR OPTIND OSTYPE POSIXLY_CORRECT PS4 PWD RANDOM
1818 SECONDS SHELL SHLVL"
1819 local filtered_sandbox_vars="SANDBOX_ACTIVE SANDBOX_BASHRC
1820 SANDBOX_DEBUG_LOG SANDBOX_DISABLED SANDBOX_LIB
1821 SANDBOX_LOG SANDBOX_ON"
1822 local misc_garbage_vars="_portage_filter_opts"
1823 filtered_vars="$readonly_bash_vars $bash_misc_vars
1824 $PORTAGE_READONLY_VARS $misc_garbage_vars"
1826 # Don't filter/interfere with prefix variables unless they are
1827 # supported by the current EAPI.
1828 case "${EAPI:-0}" in
1832 filtered_vars+=" ED EPREFIX EROOT"
1836 if hasq --filter-sandbox $* ; then
1837 filtered_vars="${filtered_vars} SANDBOX_.*"
1839 filtered_vars="${filtered_vars} ${filtered_sandbox_vars}"
1841 if hasq --filter-features $* ; then
1842 filtered_vars="${filtered_vars} FEATURES PORTAGE_FEATURES"
1844 if hasq --filter-path $* ; then
1845 filtered_vars+=" PATH"
1847 if hasq --filter-locale $* ; then
1848 filtered_vars+=" LANG LC_ALL LC_COLLATE
1849 LC_CTYPE LC_MESSAGES LC_MONETARY
1850 LC_NUMERIC LC_PAPER LC_TIME"
1852 if ! hasq --allow-extra-vars $* ; then
1855 ${PORTAGE_SAVED_READONLY_VARS}
1856 ${PORTAGE_MUTABLE_FILTERED_VARS}
1860 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}" || die "filter-bash-environment.py failed"
1863 # @FUNCTION: preprocess_ebuild_env
1865 # Filter any readonly variables from ${T}/environment, source it, and then
1866 # save it via save_ebuild_env(). This process should be sufficient to prevent
1867 # any stale variables or functions from an arbitrary environment from
1868 # interfering with the current environment. This is useful when an existing
1869 # environment needs to be loaded from a binary or installed package.
1870 preprocess_ebuild_env() {
1871 local _portage_filter_opts="--filter-features --filter-locale --filter-path --filter-sandbox"
1873 # If environment.raw is present, this is a signal from the python side,
1874 # indicating that the environment may contain stale FEATURES and
1875 # SANDBOX_{DENY,PREDICT,READ,WRITE} variables that should be filtered out.
1876 # Otherwise, we don't need to filter the environment.
1877 [ -f "${T}/environment.raw" ] || return 0
1879 filter_readonly_variables $_portage_filter_opts < "${T}"/environment \
1880 >> "$T/environment.filtered" || return $?
1881 unset _portage_filter_opts
1882 mv "${T}"/environment.filtered "${T}"/environment || return $?
1883 rm -f "${T}/environment.success" || return $?
1884 # WARNING: Code inside this subshell should avoid making assumptions
1885 # about variables or functions after source "${T}"/environment has been
1886 # called. Any variables that need to be relied upon should already be
1887 # filtered out above.
1890 source "${T}/environment" || exit $?
1891 # We have to temporarily disable sandbox since the
1892 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
1893 # may be unusable (triggering in spurious sandbox violations)
1894 # until we've merged them with our current values.
1897 # It's remotely possible that save_ebuild_env() has been overridden
1898 # by the above source command. To protect ourselves, we override it
1899 # here with our own version. ${PORTAGE_BIN_PATH} is safe to use here
1900 # because it's already filtered above.
1901 source "${PORTAGE_BIN_PATH}/isolated-functions.sh" || exit $?
1903 # Rely on save_ebuild_env() to filter out any remaining variables
1904 # and functions that could interfere with the current environment.
1905 save_ebuild_env || exit $?
1906 >> "$T/environment.success" || exit $?
1907 ) > "${T}/environment.filtered"
1909 if [ -e "${T}/environment.success" ] ; then
1910 filter_readonly_variables --filter-features < \
1911 "${T}/environment.filtered" > "${T}/environment"
1916 rm -f "${T}"/environment.{filtered,raw,success}
1920 # === === === === === === === === === === === === === === === === === ===
1921 # === === === === === functions end, main part begins === === === === ===
1922 # === === === === === functions end, main part begins === === === === ===
1923 # === === === === === functions end, main part begins === === === === ===
1924 # === === === === === === === === === === === === === === === === === ===
1926 export SANDBOX_ON="1"
1927 export S=${WORKDIR}/${P}
1929 unset E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND
1931 # Turn of extended glob matching so that g++ doesn't get incorrectly matched.
1934 if [[ ${EBUILD_PHASE} == depend ]] ; then
1935 QA_INTERCEPTORS="awk bash cc egrep equery fgrep g++
1936 gawk gcc grep javac java-config nawk perl
1937 pkg-config python python-config sed"
1938 elif [[ ${EBUILD_PHASE} == clean* ]] ; then
1939 unset QA_INTERCEPTORS
1941 QA_INTERCEPTORS="autoconf automake aclocal libtoolize"
1943 # level the QA interceptors if we're in depend
1944 if [[ -n ${QA_INTERCEPTORS} ]] ; then
1945 for BIN in ${QA_INTERCEPTORS}; do
1946 BIN_PATH=$(type -Pf ${BIN})
1947 if [ "$?" != "0" ]; then
1948 BODY="echo \"*** missing command: ${BIN}\" >&2; return 127"
1950 BODY="${BIN_PATH} \"\$@\"; return \$?"
1952 if [[ ${EBUILD_PHASE} == depend ]] ; then
1953 FUNC_SRC="${BIN}() {
1954 if [ \$ECLASS_DEPTH -gt 0 ]; then
1955 eqawarn \"QA Notice: '${BIN}' called in global scope: eclass \${ECLASS}\"
1957 eqawarn \"QA Notice: '${BIN}' called in global scope: \${CATEGORY}/\${PF}\"
1961 elif hasq ${BIN} autoconf automake aclocal libtoolize ; then
1962 FUNC_SRC="${BIN}() {
1963 if ! hasq \${FUNCNAME[1]} eautoreconf eaclocal _elibtoolize \\
1964 eautoheader eautoconf eautomake autotools_run_tool \\
1965 autotools_check_macro autotools_get_subdirs \\
1966 autotools_get_auxdir ; then
1967 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
1968 eqawarn \"Use autotools.eclass instead of calling '${BIN}' directly.\"
1973 FUNC_SRC="${BIN}() {
1974 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
1978 eval "$FUNC_SRC" || echo "error creating QA interceptor ${BIN}" >&2
1980 unset BIN_PATH BIN BODY FUNC_SRC
1983 # Subshell/helper die support (must export for the die helper).
1984 export EBUILD_MASTER_PID=$BASHPID
1985 trap 'exit 1' SIGTERM
1987 if ! hasq "$EBUILD_PHASE" clean cleanrm depend && \
1988 [ -f "${T}"/environment ] ; then
1989 # The environment may have been extracted from environment.bz2 or
1990 # may have come from another version of ebuild.sh or something.
1991 # In any case, preprocess it to prevent any potential interference.
1992 preprocess_ebuild_env || \
1993 die "error processing environment"
1994 # Colon separated SANDBOX_* variables need to be cumulative.
1995 for x in SANDBOX_DENY SANDBOX_READ SANDBOX_PREDICT SANDBOX_WRITE ; do
1996 export PORTAGE_${x}=${!x}
1998 PORTAGE_SANDBOX_ON=${SANDBOX_ON}
2000 source "${T}"/environment || \
2001 die "error sourcing environment"
2002 # We have to temporarily disable sandbox since the
2003 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
2004 # may be unusable (triggering in spurious sandbox violations)
2005 # until we've merged them with our current values.
2007 for x in SANDBOX_DENY SANDBOX_PREDICT SANDBOX_READ SANDBOX_WRITE ; do
2009 if [ -z "${!x}" ] ; then
2011 elif [ -n "${!y}" ] && [ "${!y}" != "${!x}" ] ; then
2013 export ${x}=$(printf "${!y}:${!x}" | tr ":" "\0" | \
2014 sort -z -u | tr "\0" ":")
2020 export SANDBOX_ON=${PORTAGE_SANDBOX_ON}
2021 unset PORTAGE_SANDBOX_ON
2022 [[ -n $EAPI ]] || EAPI=0
2025 if ! hasq "$EBUILD_PHASE" clean cleanrm ; then
2026 if [[ $EBUILD_PHASE = depend || ! -f $T/environment || \
2027 -f $PORTAGE_BUILDDIR/.ebuild_changed ]] || \
2028 hasq noauto $FEATURES ; then
2029 # The bashrcs get an opportunity here to set aliases that will be expanded
2030 # during sourcing of ebuilds and eclasses.
2033 # When EBUILD_PHASE != depend, INHERITED comes pre-initialized
2034 # from cache. In order to make INHERITED content independent of
2035 # EBUILD_PHASE during inherit() calls, we unset INHERITED after
2036 # we make a backup copy for QA checks.
2037 __INHERITED_QA_CACHE=$INHERITED
2039 # *DEPEND and IUSE will be set during the sourcing of the ebuild.
2040 # In order to ensure correct interaction between ebuilds and
2041 # eclasses, they need to be unset before this process of
2042 # interaction begins.
2043 unset DEPEND RDEPEND PDEPEND INHERITED IUSE REQUIRED_USE \
2044 ECLASS E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND
2046 if [[ $PORTAGE_DEBUG != 1 || ${-/x/} != $- ]] ; then
2047 source "$EBUILD" || die "error sourcing ebuild"
2050 source "$EBUILD" || die "error sourcing ebuild"
2054 if [[ "${EBUILD_PHASE}" != "depend" ]] ; then
2055 RESTRICT=${PORTAGE_RESTRICT}
2056 [[ -e $PORTAGE_BUILDDIR/.ebuild_changed ]] && \
2057 rm "$PORTAGE_BUILDDIR/.ebuild_changed"
2060 [[ -n $EAPI ]] || EAPI=0
2062 if has "$EAPI" 0 1 2 3 3_pre2 ; then
2063 export RDEPEND=${RDEPEND-${DEPEND}}
2064 debug-print "RDEPEND: not set... Setting to: ${DEPEND}"
2067 # add in dependency info from eclasses
2068 IUSE="${IUSE} ${E_IUSE}"
2069 DEPEND="${DEPEND} ${E_DEPEND}"
2070 RDEPEND="${RDEPEND} ${E_RDEPEND}"
2071 PDEPEND="${PDEPEND} ${E_PDEPEND}"
2072 REQUIRED_USE="${REQUIRED_USE} ${E_REQUIRED_USE}"
2074 unset ECLASS E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND \
2075 __INHERITED_QA_CACHE
2077 # alphabetically ordered by $EBUILD_PHASE value
2080 _valid_phases="src_compile pkg_config pkg_info src_install
2081 pkg_nofetch pkg_postinst pkg_postrm pkg_preinst pkg_prerm
2082 pkg_setup src_test src_unpack"
2085 _valid_phases="src_compile pkg_config src_configure pkg_info
2086 src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst
2087 src_prepare pkg_prerm pkg_setup src_test src_unpack"
2090 _valid_phases="src_compile pkg_config src_configure pkg_info
2091 src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst
2092 src_prepare pkg_prerm pkg_pretend pkg_setup src_test src_unpack"
2097 for _f in $_valid_phases ; do
2098 if declare -F $_f >/dev/null ; then
2100 DEFINED_PHASES+=" ${_f#src_}"
2103 [[ -n $DEFINED_PHASES ]] || DEFINED_PHASES=-
2105 unset _f _valid_phases
2107 if [[ $EBUILD_PHASE != depend ]] ; then
2111 _ebuild_helpers_path="$PORTAGE_BIN_PATH/ebuild-helpers"
2114 _ebuild_helpers_path="$PORTAGE_BIN_PATH/ebuild-helpers/4:$PORTAGE_BIN_PATH/ebuild-helpers"
2118 PATH=$_ebuild_helpers_path:$PREROOTPATH${PREROOTPATH:+:}/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin${ROOTPATH:+:}$ROOTPATH
2119 unset _ebuild_helpers_path
2121 if hasq distcc $FEATURES ; then
2122 PATH="/usr/lib/distcc/bin:$PATH"
2123 [[ -n $DISTCC_LOG ]] && addwrite "${DISTCC_LOG%/*}"
2126 if hasq ccache $FEATURES ; then
2127 PATH="/usr/lib/ccache/bin:$PATH"
2129 if [[ -n $CCACHE_DIR ]] ; then
2130 addread "$CCACHE_DIR"
2131 addwrite "$CCACHE_DIR"
2134 [[ -n $CCACHE_SIZE ]] && ccache -M $CCACHE_SIZE &> /dev/null
2137 if [[ -n $QA_PREBUILT ]] ; then
2139 # these ones support fnmatch patterns
2140 QA_EXECSTACK+=" $QA_PREBUILT"
2141 QA_TEXTRELS+=" $QA_PREBUILT"
2142 QA_WX_LOAD+=" $QA_PREBUILT"
2144 # these ones support regular expressions, so translate
2145 # fnmatch patterns to regular expressions
2146 for x in QA_DT_HASH QA_DT_NEEDED QA_PRESTRIPPED QA_SONAME ; do
2147 if [[ $(declare -p $x 2>/dev/null) = declare\ -a* ]] ; then
2148 eval "$x=(\"\${$x[@]}\" ${QA_PREBUILT//\*/.*})"
2150 eval "$x+=\" ${QA_PREBUILT//\*/.*}\""
2157 # This needs to be exported since prepstrip is a separate shell script.
2158 [[ -n $QA_PRESTRIPPED ]] && export QA_PRESTRIPPED
2159 eval "[[ -n \$QA_PRESTRIPPED_${ARCH/-/_} ]] && \
2160 export QA_PRESTRIPPED_${ARCH/-/_}"
2165 # unset USE_EXPAND variables that contain only the special "*" token
2166 for x in ${USE_EXPAND} ; do
2167 [ "${!x}" == "*" ] && unset ${x}
2171 if hasq nostrip ${FEATURES} ${RESTRICT} || hasq strip ${RESTRICT}
2176 #a reasonable default for $S
2177 [[ -z ${S} ]] && export S=${WORKDIR}/${P}
2179 # Note: readonly variables interfere with preprocess_ebuild_env(), so
2180 # declare them only after it has already run.
2181 if [ "${EBUILD_PHASE}" != "depend" ] ; then
2182 declare -r $PORTAGE_READONLY_METADATA $PORTAGE_READONLY_VARS
2187 declare -r ED EPREFIX EROOT
2194 # Subshell/helper die support (must export for the die helper).
2195 # Since this function is typically executed in a subshell,
2196 # setup EBUILD_MASTER_PID to refer to the current $BASHPID,
2197 # which seems to give the best results when further
2198 # nested subshells call die.
2199 export EBUILD_MASTER_PID=$BASHPID
2200 trap 'exit 1' SIGTERM
2202 if [[ $EBUILD_PHASE != depend ]] ; then
2203 # Force configure scripts that automatically detect ccache to
2204 # respect FEATURES="-ccache".
2205 hasq ccache $FEATURES || export CCACHE_DISABLE=1
2207 local phase_func=$(_ebuild_arg_to_phase "$EAPI" "$EBUILD_PHASE")
2208 [[ -n $phase_func ]] && _ebuild_phase_funcs "$EAPI" "$phase_func"
2214 case ${EBUILD_SH_ARGS} in
2216 ebuild_phase_with_hooks pkg_nofetch
2218 prerm|postrm|postinst|config|info)
2219 if hasq "$EBUILD_SH_ARGS" config info && \
2220 ! declare -F "pkg_$EBUILD_SH_ARGS" >/dev/null ; then
2221 ewarn "pkg_${EBUILD_SH_ARGS}() is not defined: '${EBUILD##*/}'"
2223 export SANDBOX_ON="0"
2224 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
2225 ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
2228 ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
2231 if [[ $EBUILD_PHASE == postinst ]] && [[ -n $PORTAGE_UPDATE_ENV ]]; then
2232 # Update environment.bz2 in case installation phases
2233 # need to pass some variables to uninstallation phases.
2234 save_ebuild_env --exclude-init-phases | \
2235 filter_readonly_variables --filter-path \
2236 --filter-sandbox --allow-extra-vars \
2237 | ${PORTAGE_BZIP2_COMMAND} -c -f9 > "$PORTAGE_UPDATE_ENV"
2238 assert "save_ebuild_env failed"
2241 unpack|prepare|configure|compile|test|clean|install)
2242 if [[ ${SANDBOX_DISABLED:-0} = 0 ]] ; then
2243 export SANDBOX_ON="1"
2245 export SANDBOX_ON="0"
2248 case "$EBUILD_SH_ARGS" in
2252 for x in ASFLAGS CCACHE_DIR CCACHE_SIZE \
2253 CFLAGS CXXFLAGS LDFLAGS LIBCFLAGS LIBCXXFLAGS ; do
2254 [[ ${!x+set} = set ]] && export $x
2258 hasq distcc $FEATURES && [[ -n $DISTCC_DIR ]] && \
2259 [[ ${SANDBOX_WRITE/$DISTCC_DIR} = $SANDBOX_WRITE ]] && \
2260 addwrite "$DISTCC_DIR"
2263 [ -z "$PKG_CONFIG_PATH" -a -n "$ABI" -a -n "${!x}" ] && \
2264 export PKG_CONFIG_PATH=/usr/${!x}/pkgconfig
2266 if hasq noauto $FEATURES && \
2267 [[ ! -f $PORTAGE_BUILDDIR/.unpacked ]] ; then
2269 echo "!!! We apparently haven't unpacked..." \
2270 "This is probably not what you"
2271 echo "!!! want to be doing... You are using" \
2272 "FEATURES=noauto so I'll assume"
2273 echo "!!! that you know what you are doing..." \
2274 "You have 5 seconds to abort..."
2278 for x in 1 2 3 4 5 6 7 8; do
2285 cd "$PORTAGE_BUILDDIR"
2286 if [ ! -d build-info ] ; then
2288 cp "$EBUILD" "build-info/$PF.ebuild"
2291 #our custom version of libtool uses $S and $D to fix
2292 #invalid paths in .la files
2298 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
2299 dyn_${EBUILD_SH_ARGS}
2302 dyn_${EBUILD_SH_ARGS}
2305 export SANDBOX_ON="0"
2307 help|pretend|setup|preinst)
2308 #pkg_setup needs to be out of the sandbox for tmp file creation;
2309 #for example, awking and piping a file in /tmp requires a temp file to be created
2310 #in /etc. If pkg_setup is in the sandbox, both our lilo and apache ebuilds break.
2311 export SANDBOX_ON="0"
2312 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
2313 dyn_${EBUILD_SH_ARGS}
2316 dyn_${EBUILD_SH_ARGS}
2321 export SANDBOX_ON="0"
2324 if [ -n "${dbkey}" ] ; then
2325 if [ ! -d "${dbkey%/*}" ]; then
2326 install -d -g ${PORTAGE_GID} -m2775 "${dbkey%/*}"
2328 # Make it group writable. 666&~002==664
2332 auxdbkeys="DEPEND RDEPEND SLOT SRC_URI RESTRICT HOMEPAGE LICENSE
2333 DESCRIPTION KEYWORDS INHERITED IUSE REQUIRED_USE PDEPEND PROVIDE EAPI
2334 PROPERTIES DEFINED_PHASES UNUSED_05 UNUSED_04
2335 UNUSED_03 UNUSED_02 UNUSED_01"
2337 #the extra $(echo) commands remove newlines
2338 [ -n "${EAPI}" ] || EAPI=0
2340 if [ -n "${dbkey}" ] ; then
2342 for f in ${auxdbkeys} ; do
2343 echo $(echo ${!f}) >> "${dbkey}" || exit $?
2346 for f in ${auxdbkeys} ; do
2347 echo $(echo ${!f}) 1>&9 || exit $?
2356 export SANDBOX_ON="1"
2357 echo "Unrecognized EBUILD_SH_ARGS: '${EBUILD_SH_ARGS}'"
2365 if [[ -s $SANDBOX_LOG ]] ; then
2366 # We use SANDBOX_LOG to check for sandbox violations,
2367 # so we ensure that there can't be a stale log to
2368 # interfere with our logic.
2370 if [[ -n SANDBOX_ON ]] ; then
2375 rm -f "$SANDBOX_LOG" || \
2376 die "failed to remove stale sandbox log: '$SANDBOX_LOG'"
2378 if [[ -n $x ]] ; then
2379 export SANDBOX_ON=$x
2384 if [[ $EBUILD_PHASE = depend ]] ; then
2386 elif [[ -n $EBUILD_SH_ARGS ]] ; then
2388 # Don't allow subprocesses to inherit the pipe which
2389 # emerge uses to monitor ebuild.sh.
2394 # Save the env only for relevant phases.
2395 if ! hasq "$EBUILD_SH_ARGS" clean help info nofetch ; then
2397 save_ebuild_env | filter_readonly_variables \
2398 --filter-features > "$T/environment"
2399 assert "save_ebuild_env failed"
2400 chown portage:portage "$T/environment" &>/dev/null
2401 chmod g+w "$T/environment" &>/dev/null
2403 [[ -n $PORTAGE_EBUILD_EXIT_FILE ]] && > "$PORTAGE_EBUILD_EXIT_FILE"
2404 if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
2405 [[ ! -s $SANDBOX_LOG ]]
2406 "$PORTAGE_BIN_PATH"/ebuild-ipc exit $?
2413 # Do not exit when ebuild.sh is sourced by other scripts.