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.
131 eqawarn "QA Notice: The 'useq' function is deprecated (replaced by 'use')"
147 # if we got something like '!flag', then invert the return value
148 if [[ ${u:0:1} == "!" ]] ; then
153 if [[ $EBUILD_PHASE = depend ]] ; then
154 # TODO: Add a registration interface for eclasses to register
155 # any number of phase hooks, so that global scope eclass
156 # initialization can by migrated to phase hooks in new EAPIs.
157 # Example: add_phase_hook before pkg_setup $ECLASS_pre_pkg_setup
158 #if [[ -n $EAPI ]] && ! has "$EAPI" 0 1 2 3 ; then
159 # die "use() called during invalid phase: $EBUILD_PHASE"
163 # Make sure we have this USE flag in IUSE
164 elif [[ -n $PORTAGE_IUSE && -n $EBUILD_PHASE ]] ; then
165 [[ $u =~ $PORTAGE_IUSE ]] || \
166 eqawarn "QA Notice: USE Flag '${u}' not" \
167 "in IUSE for ${CATEGORY}/${PF}"
170 if has ${u} ${USE} ; then
177 # Return true if given package is installed. Otherwise return false.
178 # Takes single depend-type atoms.
180 if [ "${EBUILD_PHASE}" == "depend" ]; then
181 die "portageq calls (has_version calls portageq) are not allowed in the global scope"
184 if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
185 "$PORTAGE_BIN_PATH"/ebuild-ipc has_version "$ROOT" "$1"
187 PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
188 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" has_version "${ROOT}" "$1"
196 die "unexpected portageq exit code: ${retval}"
202 if [ "${EBUILD_PHASE}" == "depend" ]; then
203 die "portageq calls are not allowed in the global scope"
206 PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
207 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" "$@"
211 # ----------------------------------------------------------------------------
212 # ----------------------------------------------------------------------------
213 # ----------------------------------------------------------------------------
216 # Returns the best/most-current match.
217 # Takes single depend-type atoms.
219 if [ "${EBUILD_PHASE}" == "depend" ]; then
220 die "portageq calls (best_version calls portageq) are not allowed in the global scope"
223 if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
224 "$PORTAGE_BIN_PATH"/ebuild-ipc best_version "$ROOT" "$1"
226 PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
227 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" 'best_version' "${ROOT}" "$1"
235 die "unexpected portageq exit code: ${retval}"
242 echo "!!! use_with() called without a parameter." >&2
243 echo "!!! use_with <USEFLAG> [<flagname> [value]]" >&2
247 if ! has "${EAPI:-0}" 0 1 2 3 ; then
248 local UW_SUFFIX=${3+=$3}
250 local UW_SUFFIX=${3:+=$3}
255 echo "--with-${UWORD}${UW_SUFFIX}"
257 echo "--without-${UWORD}"
264 echo "!!! use_enable() called without a parameter." >&2
265 echo "!!! use_enable <USEFLAG> [<flagname> [value]]" >&2
269 if ! has "${EAPI:-0}" 0 1 2 3 ; then
270 local UE_SUFFIX=${3+=$3}
272 local UE_SUFFIX=${3:+=$3}
277 echo "--enable-${UWORD}${UE_SUFFIX}"
279 echo "--disable-${UWORD}"
284 register_die_hook() {
287 has $x $EBUILD_DEATH_HOOKS || \
288 export EBUILD_DEATH_HOOKS="$EBUILD_DEATH_HOOKS $x"
292 register_success_hook() {
295 has $x $EBUILD_SUCCESS_HOOKS || \
296 export EBUILD_SUCCESS_HOOKS="$EBUILD_SUCCESS_HOOKS $x"
300 # Ensure that $PWD is sane whenever possible, to protect against
301 # exploitation of insecure search path for python -c in ebuilds.
303 if ! has "$EBUILD_PHASE" clean cleanrm depend help ; then
304 cd "$PORTAGE_BUILDDIR" || \
305 die "PORTAGE_BUILDDIR does not exist: '$PORTAGE_BUILDDIR'"
308 #if no perms are specified, dirs/files will have decent defaults
309 #(not secretive, but not stupid)
312 export INSDESTTREE=""
313 export _E_EXEDESTTREE_=""
314 export _E_DOCDESTTREE_=""
315 export INSOPTIONS="-m0644"
316 export EXEOPTIONS="-m0755"
317 export LIBOPTIONS="-m0644"
318 export DIROPTIONS="-m0755"
319 export MOPREFIX=${PN}
320 declare -a PORTAGE_DOCOMPRESS=( /usr/share/{doc,info,man} )
321 declare -a PORTAGE_DOCOMPRESS_SKIP=( /usr/share/doc/${PF}/html )
323 # adds ".keep" files so that dirs aren't auto-cleaned
327 if [ "$1" == "-R" ] || [ "$1" == "-r" ]; then
329 find "$@" -type d -printf "${D}%p/.keep_${CATEGORY}_${PN}-${SLOT}\n" \
331 while read -r -d $'\0' ; do
333 die "Failed to recursively create .keep files"
337 >> "${D}${x}/.keep_${CATEGORY}_${PN}-${SLOT}" || \
338 die "Failed to create .keep in ${D}${x}"
348 local eapi=${EAPI:-0}
349 [ -z "$*" ] && die "Nothing passed to the 'unpack' command"
352 vecho ">>> Unpacking ${x} to ${PWD}"
356 if [[ ${x} == "./"* ]] ; then
358 elif [[ ${x} == ${DISTDIR%/}/* ]] ; then
359 die "Arguments to unpack() cannot begin with \${DISTDIR}."
360 elif [[ ${x} == "/"* ]] ; then
361 die "Arguments to unpack() cannot be absolute"
365 [[ ! -s ${srcdir}${x} ]] && die "${x} does not exist"
368 if [ "${y}" == "tar" ]; then
369 $1 -c -- "$srcdir$x" | tar xof -
370 assert_sigpipe_ok "$myfail"
372 $1 -c -- "${srcdir}${x}" > ${x%.*} || die "$myfail"
376 myfail="failure unpacking ${x}"
379 tar xof "$srcdir$x" || die "$myfail"
382 tar xozf "$srcdir$x" || die "$myfail"
385 ${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- "$srcdir$x" | tar xof -
386 assert_sigpipe_ok "$myfail"
389 # unzip will interactively prompt under some error conditions,
390 # as reported in bug #336285
391 ( while true ; do echo n || break ; done ) | \
392 unzip -qo "${srcdir}${x}" || die "$myfail"
395 _unpack_tar "gzip -d"
398 _unpack_tar "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}"
402 my_output="$(7z x -y "${srcdir}${x}")"
403 if [ $? -ne 0 ]; then
404 echo "${my_output}" >&2
409 unrar x -idq -o+ "${srcdir}${x}" || die "$myfail"
412 lha xfq "${srcdir}${x}" || die "$myfail"
415 ar x "${srcdir}${x}" || die "$myfail"
418 # Unpacking .deb archives can not always be done with
419 # `ar`. For instance on AIX this doesn't work out. If
420 # we have `deb2targz` installed, prefer it over `ar` for
421 # that reason. We just make sure on AIX `deb2targz` is
423 if type -P deb2targz > /dev/null; then
425 local created_symlink=0
426 if [ ! "$srcdir$x" -ef "$y" ] ; then
427 # deb2targz always extracts into the same directory as
428 # the source file, so create a symlink in the current
429 # working directory if necessary.
430 ln -sf "$srcdir$x" "$y" || die "$myfail"
433 deb2targz "$y" || die "$myfail"
434 if [ $created_symlink = 1 ] ; then
435 # Clean up the symlink so the ebuild
436 # doesn't inadvertently install it.
439 mv -f "${y%.deb}".tar.gz data.tar.gz || die "$myfail"
441 ar x "$srcdir$x" || die "$myfail"
445 _unpack_tar "lzma -d"
448 if has $eapi 0 1 2 ; then
449 vecho "unpack ${x}: file format not recognized. Ignoring."
455 vecho "unpack ${x}: file format not recognized. Ignoring."
459 # Do not chmod '.' since it's probably ${WORKDIR} and PORTAGE_WORKDIR_MODE
460 # should be preserved.
461 find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \
462 ${XARGS} -0 chmod -fR a+rX,u+w,g-w,o-w
465 strip_duplicate_slashes() {
466 if [[ -n $1 ]] ; then
468 while [[ ${removed} == *//* ]] ; do
469 removed=${removed//\/\///}
478 for x ; do [[ ${x} == ${s} ]] && echo "${x}" && return 0 ; done
481 hasgq() { hasg "$@" >/dev/null ; }
485 local phase_func=$(_ebuild_arg_to_phase "$EAPI" "$EBUILD_PHASE")
486 if [[ -n $phase_func ]] ; then
487 if has "$EAPI" 0 1 ; then
488 [[ $phase_func != src_compile ]] && \
489 eqawarn "QA Notice: econf called in" \
490 "$phase_func instead of src_compile"
492 [[ $phase_func != src_configure ]] && \
493 eqawarn "QA Notice: econf called in" \
494 "$phase_func instead of src_configure"
499 if [ -x "${ECONF_SOURCE}/configure" ]; then
500 if [[ -n $CONFIG_SHELL && \
501 "$(head -n1 "$ECONF_SOURCE/configure")" =~ ^'#!'[[:space:]]*/bin/sh([[:space:]]|$) ]] ; then
502 sed -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" -i "$ECONF_SOURCE/configure" || \
503 die "Substition of shebang in '$ECONF_SOURCE/configure' failed"
505 if [ -e /usr/share/gnuconfig/ ]; then
506 find "${WORKDIR}" -type f '(' \
507 -name config.guess -o -name config.sub ')' -print0 | \
508 while read -r -d $'\0' x ; do
509 vecho " * econf: updating ${x/${WORKDIR}\/} with /usr/share/gnuconfig/${x##*/}"
510 cp -f /usr/share/gnuconfig/"${x##*/}" "${x}"
514 # EAPI=4 adds --disable-dependency-tracking to econf
515 if ! has "$EAPI" 0 1 2 3 3_pre2 && \
516 "${ECONF_SOURCE}/configure" --help 2>/dev/null | \
517 grep -q disable-dependency-tracking ; then
518 set -- --disable-dependency-tracking "$@"
521 # if the profile defines a location to install libs to aside from default, pass it on.
522 # if the ebuild passes in --libdir, they're responsible for the conf_libdir fun.
523 local CONF_LIBDIR LIBDIR_VAR="LIBDIR_${ABI}"
524 if [[ -n ${ABI} && -n ${!LIBDIR_VAR} ]] ; then
525 CONF_LIBDIR=${!LIBDIR_VAR}
527 if [[ -n ${CONF_LIBDIR} ]] && ! hasgq --libdir=\* "$@" ; then
528 export CONF_PREFIX=$(hasg --exec-prefix=\* "$@")
529 [[ -z ${CONF_PREFIX} ]] && CONF_PREFIX=$(hasg --prefix=\* "$@")
530 : ${CONF_PREFIX:=/usr}
531 CONF_PREFIX=${CONF_PREFIX#*=}
532 [[ ${CONF_PREFIX} != /* ]] && CONF_PREFIX="/${CONF_PREFIX}"
533 [[ ${CONF_LIBDIR} != /* ]] && CONF_LIBDIR="/${CONF_LIBDIR}"
534 set -- --libdir="$(strip_duplicate_slashes ${CONF_PREFIX}${CONF_LIBDIR})" "$@"
539 ${CBUILD:+--build=${CBUILD}} \
541 ${CTARGET:+--target=${CTARGET}} \
542 --mandir=/usr/share/man \
543 --infodir=/usr/share/info \
544 --datadir=/usr/share \
546 --localstatedir=/var/lib \
549 vecho "${ECONF_SOURCE}/configure" "$@"
551 if ! "${ECONF_SOURCE}/configure" "$@" ; then
553 if [ -s config.log ]; then
555 echo "!!! Please attach the following file when seeking support:"
556 echo "!!! ${PWD}/config.log"
560 elif [ -f "${ECONF_SOURCE}/configure" ]; then
561 die "configure is not executable"
563 die "no configure script found"
568 # CONF_PREFIX is only set if they didn't pass in libdir above.
569 local LOCAL_EXTRA_EINSTALL="${EXTRA_EINSTALL}"
570 LIBDIR_VAR="LIBDIR_${ABI}"
571 if [ -n "${ABI}" -a -n "${!LIBDIR_VAR}" ]; then
572 CONF_LIBDIR="${!LIBDIR_VAR}"
575 if [ -n "${CONF_LIBDIR}" ] && [ "${CONF_PREFIX:+set}" = set ]; then
576 EI_DESTLIBDIR="${D}/${CONF_PREFIX}/${CONF_LIBDIR}"
577 EI_DESTLIBDIR="$(strip_duplicate_slashes ${EI_DESTLIBDIR})"
578 LOCAL_EXTRA_EINSTALL="libdir=${EI_DESTLIBDIR} ${LOCAL_EXTRA_EINSTALL}"
582 if [ -f ./[mM]akefile -o -f ./GNUmakefile ] ; then
583 if [ "${PORTAGE_DEBUG}" == "1" ]; then
584 ${MAKE:-make} -n prefix="${D}usr" \
585 datadir="${D}usr/share" \
586 infodir="${D}usr/share/info" \
587 localstatedir="${D}var/lib" \
588 mandir="${D}usr/share/man" \
589 sysconfdir="${D}etc" \
590 ${LOCAL_EXTRA_EINSTALL} \
591 ${MAKEOPTS} ${EXTRA_EMAKE} -j1 \
594 ${MAKE:-make} prefix="${D}usr" \
595 datadir="${D}usr/share" \
596 infodir="${D}usr/share/info" \
597 localstatedir="${D}var/lib" \
598 mandir="${D}usr/share/man" \
599 sysconfdir="${D}etc" \
600 ${LOCAL_EXTRA_EINSTALL} \
601 ${MAKEOPTS} ${EXTRA_EMAKE} -j1 \
602 "$@" install || die "einstall failed"
604 die "no Makefile found"
608 _eapi0_pkg_nofetch() {
609 [ -z "${SRC_URI}" ] && return
611 elog "The following are listed in SRC_URI for ${PN}:"
613 for x in $(echo ${SRC_URI}); do
618 _eapi0_src_unpack() {
619 [[ -n ${A} ]] && unpack ${A}
622 _eapi0_src_compile() {
623 if [ -x ./configure ] ; then
630 # Since we don't want emake's automatic die
631 # support (EAPI 4 and later), and we also don't
632 # want the warning messages that it produces if
633 # we call it in 'nonfatal' mode, we use emake_cmd
634 # to emulate the desired parts of emake behavior.
635 local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}"
636 if $emake_cmd -j1 check -n &> /dev/null; then
637 vecho ">>> Test phase [check]: ${CATEGORY}/${PF}"
638 if ! $emake_cmd -j1 check; then
639 has test $FEATURES && die "Make check failed. See above for details."
640 has test $FEATURES || eerror "Make check failed. See above for details."
642 elif $emake_cmd -j1 test -n &> /dev/null; then
643 vecho ">>> Test phase [test]: ${CATEGORY}/${PF}"
644 if ! $emake_cmd -j1 test; then
645 has test $FEATURES && die "Make test failed. See above for details."
646 has test $FEATURES || eerror "Make test failed. See above for details."
649 vecho ">>> Test phase [none]: ${CATEGORY}/${PF}"
653 _eapi1_src_compile() {
658 _eapi2_src_configure() {
659 if [[ -x ${ECONF_SOURCE:-.}/configure ]] ; then
664 _eapi2_src_compile() {
665 if [ -f Makefile ] || [ -f GNUmakefile ] || [ -f makefile ]; then
666 emake || die "emake failed"
670 _eapi4_src_install() {
671 if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
672 emake DESTDIR="${D}" install
675 if ! declare -p DOCS &>/dev/null ; then
677 for d in README* ChangeLog AUTHORS NEWS TODO CHANGES \
678 THANKS BUGS FAQ CREDITS CHANGELOG ; do
679 [[ -s "${d}" ]] && dodoc "${d}"
681 elif [[ $(declare -p DOCS) == "declare -a "* ]] ; then
689 declare -F "$1" >/dev/null && qa_call $1
692 ebuild_phase_with_hooks() {
693 local x phase_name=${1}
694 for x in {pre_,,post_}${phase_name} ; do
700 if [[ -e $PORTAGE_BUILDDIR/.pretended ]] ; then
701 vecho ">>> It appears that '$PF' is already pretended; skipping."
702 vecho ">>> Remove '$PORTAGE_BUILDDIR/.pretended' to force pretend."
705 ebuild_phase pre_pkg_pretend
706 ebuild_phase pkg_pretend
707 >> "$PORTAGE_BUILDDIR/.pretended" || \
708 die "Failed to create $PORTAGE_BUILDDIR/.pretended"
709 ebuild_phase post_pkg_pretend
713 if [[ -e $PORTAGE_BUILDDIR/.setuped ]] ; then
714 vecho ">>> It appears that '$PF' is already setup; skipping."
715 vecho ">>> Remove '$PORTAGE_BUILDDIR/.setuped' to force setup."
718 ebuild_phase pre_pkg_setup
719 ebuild_phase pkg_setup
720 >> "$PORTAGE_BUILDDIR/.setuped" || \
721 die "Failed to create $PORTAGE_BUILDDIR/.setuped"
722 ebuild_phase post_pkg_setup
727 if [ -e "${WORKDIR}" ]; then
731 vecho ">>> Checking ${x}'s mtime..."
732 if [ "${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/${x}" -nt "${WORKDIR}" ]; then
733 vecho ">>> ${x} has been updated; recreating WORKDIR..."
738 if [ ! -f "${PORTAGE_BUILDDIR}/.unpacked" ] ; then
739 vecho ">>> Not marked as unpacked; recreating WORKDIR..."
743 if [ "${newstuff}" == "yes" ]; then
744 # We don't necessarily have privileges to do a full dyn_clean here.
745 rm -rf "${PORTAGE_BUILDDIR}"/{.setuped,.unpacked,.prepared,.configured,.compiled,.tested,.installed,.packaged,build-info}
746 if ! has keepwork $FEATURES ; then
749 if [ -d "${T}" ] && \
750 ! has keeptemp $FEATURES ; then
751 rm -rf "${T}" && mkdir "${T}"
754 if [ -e "${WORKDIR}" ]; then
755 if [ "$newstuff" == "no" ]; then
756 vecho ">>> WORKDIR is up-to-date, keeping..."
761 if [ ! -d "${WORKDIR}" ]; then
762 install -m${PORTAGE_WORKDIR_MODE:-0700} -d "${WORKDIR}" || die "Failed to create dir '${WORKDIR}'"
764 cd "${WORKDIR}" || die "Directory change failed: \`cd '${WORKDIR}'\`"
765 ebuild_phase pre_src_unpack
766 vecho ">>> Unpacking source..."
767 ebuild_phase src_unpack
768 >> "$PORTAGE_BUILDDIR/.unpacked" || \
769 die "Failed to create $PORTAGE_BUILDDIR/.unpacked"
770 vecho ">>> Source unpacked in ${WORKDIR}"
771 ebuild_phase post_src_unpack
775 if [ -z "${PORTAGE_BUILDDIR}" ]; then
776 echo "Aborting clean phase because PORTAGE_BUILDDIR is unset!"
778 elif [ ! -d "${PORTAGE_BUILDDIR}" ] ; then
781 if has chflags $FEATURES ; then
782 chflags -R noschg,nouchg,nosappnd,nouappnd "${PORTAGE_BUILDDIR}"
783 chflags -R nosunlnk,nouunlnk "${PORTAGE_BUILDDIR}" 2>/dev/null
786 rm -rf "${PORTAGE_BUILDDIR}/image" "${PORTAGE_BUILDDIR}/homedir"
787 rm -f "${PORTAGE_BUILDDIR}/.installed"
789 if [[ $EMERGE_FROM = binary ]] || \
790 ! has keeptemp $FEATURES && ! has keepwork $FEATURES ; then
794 if [[ $EMERGE_FROM = binary ]] || ! has keepwork $FEATURES; then
795 rm -f "$PORTAGE_BUILDDIR"/.{ebuild_changed,logid,pretended,setuped,unpacked,prepared} \
796 "$PORTAGE_BUILDDIR"/.{configured,compiled,tested,packaged} \
797 "$PORTAGE_BUILDDIR"/.die_hooks \
798 "$PORTAGE_BUILDDIR"/.ipc_{in,out,lock} \
799 "$PORTAGE_BUILDDIR"/.exit_status
801 rm -rf "${PORTAGE_BUILDDIR}/build-info"
805 if [ -f "${PORTAGE_BUILDDIR}/.unpacked" ]; then
806 find "${PORTAGE_BUILDDIR}" -type d ! -regex "^${WORKDIR}" | sort -r | tr "\n" "\0" | $XARGS -0 rmdir &>/dev/null
809 # do not bind this to doebuild defined DISTDIR; don't trust doebuild, and if mistakes are made it'll
810 # result in it wiping the users distfiles directory (bad).
811 rm -rf "${PORTAGE_BUILDDIR}/distdir"
813 # Some kernels, such as Solaris, return EINVAL when an attempt
814 # is made to remove the current working directory.
815 cd "$PORTAGE_BUILDDIR"/../..
816 rmdir "$PORTAGE_BUILDDIR" 2>/dev/null
822 if [ "$1" == "/" ]; then
826 if [ ! -d "${D}${DESTTREE}" ]; then
827 install -d "${D}${DESTTREE}"
829 if [[ $ret -ne 0 ]] ; then
830 helpers_die "${FUNCNAME[0]} failed"
838 if [ "$1" == "/" ]; then
839 export INSDESTTREE=""
841 export INSDESTTREE=$1
842 if [ ! -d "${D}${INSDESTTREE}" ]; then
843 install -d "${D}${INSDESTTREE}"
845 if [[ $ret -ne 0 ]] ; then
846 helpers_die "${FUNCNAME[0]} failed"
854 if [ "$1" == "/" ]; then
855 export _E_EXEDESTTREE_=""
857 export _E_EXEDESTTREE_="$1"
858 if [ ! -d "${D}${_E_EXEDESTTREE_}" ]; then
859 install -d "${D}${_E_EXEDESTTREE_}"
861 if [[ $ret -ne 0 ]] ; then
862 helpers_die "${FUNCNAME[0]} failed"
870 if [ "$1" == "/" ]; then
871 export _E_DOCDESTTREE_=""
873 export _E_DOCDESTTREE_="$1"
874 if [ ! -d "${D}usr/share/doc/${PF}/${_E_DOCDESTTREE_}" ]; then
875 install -d "${D}usr/share/doc/${PF}/${_E_DOCDESTTREE_}"
877 if [[ $ret -ne 0 ]] ; then
878 helpers_die "${FUNCNAME[0]} failed"
886 export INSOPTIONS="$@"
888 # `install` should never be called with '-s' ...
889 has -s ${INSOPTIONS} && die "Never call insopts() with -s"
893 export DIROPTIONS="$@"
897 export EXEOPTIONS="$@"
899 # `install` should never be called with '-s' ...
900 has -s ${EXEOPTIONS} && die "Never call exeopts() with -s"
904 export LIBOPTIONS="$@"
906 # `install` should never be called with '-s' ...
907 has -s ${LIBOPTIONS} && die "Never call libopts() with -s"
911 has "${EAPI}" 0 1 2 3 && die "'docompress' not supported in this EAPI"
914 if [[ $1 = "-x" ]]; then
917 f=$(strip_duplicate_slashes "${f}"); f=${f%/}
918 [[ ${f:0:1} = / ]] || f="/${f}"
919 for g in "${PORTAGE_DOCOMPRESS_SKIP[@]}"; do
920 [[ ${f} = "${g}" ]] && continue 2
922 PORTAGE_DOCOMPRESS_SKIP[${#PORTAGE_DOCOMPRESS_SKIP[@]}]=${f}
926 f=$(strip_duplicate_slashes "${f}"); f=${f%/}
927 [[ ${f:0:1} = / ]] || f="/${f}"
928 for g in "${PORTAGE_DOCOMPRESS[@]}"; do
929 [[ ${f} = "${g}" ]] && continue 2
931 PORTAGE_DOCOMPRESS[${#PORTAGE_DOCOMPRESS[@]}]=${f}
938 if [ "$2" != "fail" ]; then
939 msg="${EBUILD}: ${1} aborted; exiting."
941 msg="${EBUILD}: ${1} failed; exiting."
947 #unset signal handler
948 trap - SIGINT SIGQUIT
952 abort_handler src_prepare $1
953 rm -f "$PORTAGE_BUILDDIR/.prepared"
958 abort_handler src_configure $1
959 rm -f "$PORTAGE_BUILDDIR/.configured"
964 abort_handler "src_compile" $1
965 rm -f "${PORTAGE_BUILDDIR}/.compiled"
970 abort_handler "dyn_test" $1
971 rm -f "${PORTAGE_BUILDDIR}/.tested"
976 abort_handler "src_install" $1
977 rm -rf "${PORTAGE_BUILDDIR}/image"
981 has_phase_defined_up_to() {
983 for phase in unpack prepare configure compile install; do
984 has ${phase} ${DEFINED_PHASES} && return 0
985 [[ ${phase} == $1 ]] && return 1
987 # We shouldn't actually get here
993 if [[ -e $PORTAGE_BUILDDIR/.prepared ]] ; then
994 vecho ">>> It appears that '$PF' is already prepared; skipping."
995 vecho ">>> Remove '$PORTAGE_BUILDDIR/.prepared' to force prepare."
999 if [[ -d $S ]] ; then
1001 elif has $EAPI 0 1 2 3 3_pre2 ; then
1003 elif [[ -z ${A} ]] && ! has_phase_defined_up_to prepare; then
1006 die "The source directory '${S}' doesn't exist"
1009 trap abort_prepare SIGINT SIGQUIT
1011 ebuild_phase pre_src_prepare
1012 vecho ">>> Preparing source in $PWD ..."
1013 ebuild_phase src_prepare
1014 >> "$PORTAGE_BUILDDIR/.prepared" || \
1015 die "Failed to create $PORTAGE_BUILDDIR/.prepared"
1016 vecho ">>> Source prepared."
1017 ebuild_phase post_src_prepare
1019 trap - SIGINT SIGQUIT
1024 if [[ -e $PORTAGE_BUILDDIR/.configured ]] ; then
1025 vecho ">>> It appears that '$PF' is already configured; skipping."
1026 vecho ">>> Remove '$PORTAGE_BUILDDIR/.configured' to force configuration."
1030 if [[ -d $S ]] ; then
1032 elif has $EAPI 0 1 2 3 3_pre2 ; then
1034 elif [[ -z ${A} ]] && ! has_phase_defined_up_to configure; then
1037 die "The source directory '${S}' doesn't exist"
1040 trap abort_configure SIGINT SIGQUIT
1042 ebuild_phase pre_src_configure
1044 vecho ">>> Configuring source in $PWD ..."
1045 ebuild_phase src_configure
1046 >> "$PORTAGE_BUILDDIR/.configured" || \
1047 die "Failed to create $PORTAGE_BUILDDIR/.configured"
1048 vecho ">>> Source configured."
1050 ebuild_phase post_src_configure
1052 trap - SIGINT SIGQUIT
1057 if [[ -e $PORTAGE_BUILDDIR/.compiled ]] ; then
1058 vecho ">>> It appears that '${PF}' is already compiled; skipping."
1059 vecho ">>> Remove '$PORTAGE_BUILDDIR/.compiled' to force compilation."
1063 if [[ -d $S ]] ; then
1065 elif has $EAPI 0 1 2 3 3_pre2 ; then
1067 elif [[ -z ${A} ]] && ! has_phase_defined_up_to compile; then
1070 die "The source directory '${S}' doesn't exist"
1073 trap abort_compile SIGINT SIGQUIT
1075 if has distcc $FEATURES && has distcc-pump $FEATURES ; then
1076 if [[ -z $INCLUDE_SERVER_PORT ]] || [[ ! -w $INCLUDE_SERVER_PORT ]] ; then
1077 eval $(pump --startup)
1078 trap "pump --shutdown" EXIT
1082 ebuild_phase pre_src_compile
1084 vecho ">>> Compiling source in $PWD ..."
1085 ebuild_phase src_compile
1086 >> "$PORTAGE_BUILDDIR/.compiled" || \
1087 die "Failed to create $PORTAGE_BUILDDIR/.compiled"
1088 vecho ">>> Source compiled."
1090 ebuild_phase post_src_compile
1092 trap - SIGINT SIGQUIT
1097 if [[ -e $PORTAGE_BUILDDIR/.tested ]] ; then
1098 vecho ">>> It appears that ${PN} has already been tested; skipping."
1099 vecho ">>> Remove '${PORTAGE_BUILDDIR}/.tested' to force test."
1103 if [ "${EBUILD_FORCE_TEST}" == "1" ] ; then
1104 # If USE came from ${T}/environment then it might not have USE=test
1105 # like it's supposed to here.
1106 ! has test ${USE} && export USE="${USE} test"
1109 trap "abort_test" SIGINT SIGQUIT
1110 if [ -d "${S}" ]; then
1116 if ! has test $FEATURES && [ "${EBUILD_FORCE_TEST}" != "1" ]; then
1117 vecho ">>> Test phase [not enabled]: ${CATEGORY}/${PF}"
1118 elif has test $RESTRICT; then
1119 einfo "Skipping make test/check due to ebuild restriction."
1120 vecho ">>> Test phase [explicitly disabled]: ${CATEGORY}/${PF}"
1122 local save_sp=${SANDBOX_PREDICT}
1124 ebuild_phase pre_src_test
1125 ebuild_phase src_test
1126 >> "$PORTAGE_BUILDDIR/.tested" || \
1127 die "Failed to create $PORTAGE_BUILDDIR/.tested"
1128 ebuild_phase post_src_test
1129 SANDBOX_PREDICT=${save_sp}
1132 trap - SIGINT SIGQUIT
1136 [ -z "$PORTAGE_BUILDDIR" ] && die "${FUNCNAME}: PORTAGE_BUILDDIR is unset"
1137 if has noauto $FEATURES ; then
1138 rm -f "${PORTAGE_BUILDDIR}/.installed"
1139 elif [[ -e $PORTAGE_BUILDDIR/.installed ]] ; then
1140 vecho ">>> It appears that '${PF}' is already installed; skipping."
1141 vecho ">>> Remove '${PORTAGE_BUILDDIR}/.installed' to force install."
1144 trap "abort_install" SIGINT SIGQUIT
1145 ebuild_phase pre_src_install
1146 rm -rf "${PORTAGE_BUILDDIR}/image"
1147 mkdir "${PORTAGE_BUILDDIR}/image"
1148 if [[ -d $S ]] ; then
1150 elif has $EAPI 0 1 2 3 3_pre2 ; then
1152 elif [[ -z ${A} ]] && ! has_phase_defined_up_to install; then
1155 die "The source directory '${S}' doesn't exist"
1159 vecho ">>> Install ${PF} into ${D} category ${CATEGORY}"
1160 #our custom version of libtool uses $S and $D to fix
1161 #invalid paths in .la files
1164 # Reset exeinto(), docinto(), insinto(), and into() state variables
1165 # in case the user is running the install phase multiple times
1166 # consecutively via the ebuild command.
1167 export DESTTREE=/usr
1168 export INSDESTTREE=""
1169 export _E_EXEDESTTREE_=""
1170 export _E_DOCDESTTREE_=""
1172 ebuild_phase src_install
1173 >> "$PORTAGE_BUILDDIR/.installed" || \
1174 die "Failed to create $PORTAGE_BUILDDIR/.installed"
1175 vecho ">>> Completed installing ${PF} into ${D}"
1177 ebuild_phase post_src_install
1179 cd "${PORTAGE_BUILDDIR}"/build-info
1183 for f in CATEGORY DEFINED_PHASES FEATURES INHERITED IUSE REQUIRED_USE \
1184 PF PKGUSE SLOT KEYWORDS HOMEPAGE DESCRIPTION ; do
1186 [[ -n $x ]] && echo "$x" > $f
1188 if [[ $CATEGORY != virtual ]] ; then
1189 for f in ASFLAGS CBUILD CC CFLAGS CHOST CTARGET CXX \
1190 CXXFLAGS EXTRA_ECONF EXTRA_EINSTALL EXTRA_MAKE \
1191 LDFLAGS LIBCFLAGS LIBCXXFLAGS ; do
1193 [[ -n $x ]] && echo "$x" > $f
1197 echo "${EAPI:-0}" > EAPI
1200 # local variables can leak into the saved environment.
1203 save_ebuild_env --exclude-init-phases | filter_readonly_variables \
1204 --filter-path --filter-sandbox --allow-extra-vars > environment
1205 assert "save_ebuild_env failed"
1207 ${PORTAGE_BZIP2_COMMAND} -f9 environment
1209 cp "${EBUILD}" "${PF}.ebuild"
1210 [ -n "${PORTAGE_REPO_NAME}" ] && echo "${PORTAGE_REPO_NAME}" > repository
1211 if has nostrip ${FEATURES} ${RESTRICT} || has strip ${RESTRICT}
1215 trap - SIGINT SIGQUIT
1219 if [ -z "${D}" ]; then
1220 eerror "${FUNCNAME}: D is unset"
1223 ebuild_phase_with_hooks pkg_preinst
1229 echo "Copyright 1999-2010 Gentoo Foundation"
1231 echo "How to use the ebuild command:"
1233 echo "The first argument to ebuild should be an existing .ebuild file."
1235 echo "One or more of the following options can then be specified. If more"
1236 echo "than one option is specified, each will be executed in order."
1238 echo " help : show this help screen"
1239 echo " pretend : execute package specific pretend actions"
1240 echo " setup : execute package specific setup actions"
1241 echo " fetch : download source archive(s) and patches"
1242 echo " digest : create a manifest file for the package"
1243 echo " manifest : create a manifest file for the package"
1244 echo " unpack : unpack sources (auto-dependencies if needed)"
1245 echo " prepare : prepare sources (auto-dependencies if needed)"
1246 echo " configure : configure sources (auto-fetch/unpack if needed)"
1247 echo " compile : compile sources (auto-fetch/unpack/configure if needed)"
1248 echo " test : test package (auto-fetch/unpack/configure/compile if needed)"
1249 echo " preinst : execute pre-install instructions"
1250 echo " postinst : execute post-install instructions"
1251 echo " install : install the package to the temporary install directory"
1252 echo " qmerge : merge image into live filesystem, recording files in db"
1253 echo " merge : do fetch, unpack, compile, install and qmerge"
1254 echo " prerm : execute pre-removal instructions"
1255 echo " postrm : execute post-removal instructions"
1256 echo " unmerge : remove package from live filesystem"
1257 echo " config : execute package specific configuration actions"
1258 echo " package : create a tarball package in ${PKGDIR}/All"
1259 echo " rpm : build a RedHat RPM package"
1260 echo " clean : clean up all source and temporary files"
1262 echo "The following settings will be used for the ebuild process:"
1264 echo " package : ${PF}"
1265 echo " slot : ${SLOT}"
1266 echo " category : ${CATEGORY}"
1267 echo " description : ${DESCRIPTION}"
1268 echo " system : ${CHOST}"
1269 echo " c flags : ${CFLAGS}"
1270 echo " c++ flags : ${CXXFLAGS}"
1271 echo " make flags : ${MAKEOPTS}"
1272 echo -n " build mode : "
1273 if has nostrip ${FEATURES} ${RESTRICT} || has strip ${RESTRICT} ;
1275 echo "debug (large)"
1277 echo "production (stripped)"
1279 echo " merge to : ${ROOT}"
1281 if [ -n "$USE" ]; then
1282 echo "Additionally, support for the following optional features will be enabled:"
1289 # debug-print() gets called from many places with verbose status information useful
1290 # for tracking down problems. The output is in $T/eclass-debug.log.
1291 # You can set ECLASS_DEBUG_OUTPUT to redirect the output somewhere else as well.
1292 # The special "on" setting echoes the information, mixing it with the rest of the
1294 # You can override the setting by exporting a new one from the console, or you can
1295 # set a new default in make.*. Here the default is "" or unset.
1297 # in the future might use e* from /etc/init.d/functions.sh if i feel like it
1299 # if $T isn't defined, we're in dep calculation mode and
1300 # shouldn't do anything
1301 [[ $EBUILD_PHASE = depend || ! -d ${T} || ${#} -eq 0 ]] && return 0
1303 if [[ ${ECLASS_DEBUG_OUTPUT} == on ]]; then
1304 printf 'debug: %s\n' "${@}" >&2
1305 elif [[ -n ${ECLASS_DEBUG_OUTPUT} ]]; then
1306 printf 'debug: %s\n' "${@}" >> "${ECLASS_DEBUG_OUTPUT}"
1309 if [[ -w $T ]] ; then
1311 printf '%s\n' "${@}" >> "${T}/eclass-debug.log"
1312 # let the portage user own/write to this file
1313 chgrp portage "${T}/eclass-debug.log" &>/dev/null
1314 chmod g+w "${T}/eclass-debug.log" &>/dev/null
1318 # The following 2 functions are debug-print() wrappers
1320 debug-print-function() {
1321 debug-print "${1}: entering function, parameters: ${*:2}"
1324 debug-print-section() {
1325 debug-print "now in section ${*}"
1328 # Sources all eclasses in parameters
1329 declare -ix ECLASS_DEPTH=0
1331 ECLASS_DEPTH=$(($ECLASS_DEPTH + 1))
1332 if [[ ${ECLASS_DEPTH} > 1 ]]; then
1333 debug-print "*** Multiple Inheritence (Level: ${ECLASS_DEPTH})"
1336 if [[ -n $ECLASS && -n ${!__export_funcs_var} ]] ; then
1337 echo "QA Notice: EXPORT_FUNCTIONS is called before inherit in" \
1338 "$ECLASS.eclass. For compatibility with <=portage-2.1.6.7," \
1339 "only call EXPORT_FUNCTIONS after inherit(s)." \
1340 | fmt -w 75 | while read -r ; do eqawarn "$REPLY" ; done
1347 # These variables must be restored before returning.
1348 local PECLASS=$ECLASS
1349 local prev_export_funcs_var=$__export_funcs_var
1352 local B_REQUIRED_USE
1357 location="${ECLASSDIR}/${1}.eclass"
1361 __export_funcs_var=__export_functions_$ECLASS_DEPTH
1362 unset $__export_funcs_var
1364 if [ "${EBUILD_PHASE}" != "depend" ] && \
1365 [[ ${EBUILD_PHASE} != *rm ]] && \
1366 [[ ${EMERGE_FROM} != "binary" ]] ; then
1367 # This is disabled in the *rm phases because they frequently give
1368 # false alarms due to INHERITED in /var/db/pkg being outdated
1369 # in comparison the the eclasses from the portage tree.
1370 if ! has $ECLASS $INHERITED $__INHERITED_QA_CACHE ; then
1371 eqawarn "QA Notice: ECLASS '$ECLASS' inherited illegally in $CATEGORY/$PF $EBUILD_PHASE"
1375 # any future resolution code goes here
1376 if [ -n "$PORTDIR_OVERLAY" ]; then
1378 for overlay in ${PORTDIR_OVERLAY}; do
1379 olocation="${overlay}/eclass/${1}.eclass"
1380 if [ -e "$olocation" ]; then
1381 location="${olocation}"
1382 debug-print " eclass exists: ${location}"
1386 debug-print "inherit: $1 -> $location"
1387 [ ! -e "$location" ] && die "${1}.eclass could not be found by inherit()"
1389 if [ "${location}" == "${olocation}" ] && \
1390 ! has "${location}" ${EBUILD_OVERLAY_ECLASSES} ; then
1391 EBUILD_OVERLAY_ECLASSES="${EBUILD_OVERLAY_ECLASSES} ${location}"
1394 #We need to back up the value of DEPEND and RDEPEND to B_DEPEND and B_RDEPEND
1395 #(if set).. and then restore them after the inherit call.
1397 #turn off glob expansion
1400 # Retain the old data and restore it later.
1401 unset B_IUSE B_REQUIRED_USE B_DEPEND B_RDEPEND B_PDEPEND
1402 [ "${IUSE+set}" = set ] && B_IUSE="${IUSE}"
1403 [ "${REQUIRED_USE+set}" = set ] && B_REQUIRED_USE="${REQUIRED_USE}"
1404 [ "${DEPEND+set}" = set ] && B_DEPEND="${DEPEND}"
1405 [ "${RDEPEND+set}" = set ] && B_RDEPEND="${RDEPEND}"
1406 [ "${PDEPEND+set}" = set ] && B_PDEPEND="${PDEPEND}"
1407 unset IUSE REQUIRED_USE DEPEND RDEPEND PDEPEND
1408 #turn on glob expansion
1411 qa_source "$location" || die "died sourcing $location in inherit()"
1413 #turn off glob expansion
1416 # If each var has a value, append it to the global variable E_* to
1417 # be applied after everything is finished. New incremental behavior.
1418 [ "${IUSE+set}" = set ] && export E_IUSE="${E_IUSE} ${IUSE}"
1419 [ "${REQUIRED_USE+set}" = set ] && export E_REQUIRED_USE="${E_REQUIRED_USE} ${REQUIRED_USE}"
1420 [ "${DEPEND+set}" = set ] && export E_DEPEND="${E_DEPEND} ${DEPEND}"
1421 [ "${RDEPEND+set}" = set ] && export E_RDEPEND="${E_RDEPEND} ${RDEPEND}"
1422 [ "${PDEPEND+set}" = set ] && export E_PDEPEND="${E_PDEPEND} ${PDEPEND}"
1424 [ "${B_IUSE+set}" = set ] && IUSE="${B_IUSE}"
1425 [ "${B_IUSE+set}" = set ] || unset IUSE
1427 [ "${B_REQUIRED_USE+set}" = set ] && REQUIRED_USE="${B_REQUIRED_USE}"
1428 [ "${B_REQUIRED_USE+set}" = set ] || unset REQUIRED_USE
1430 [ "${B_DEPEND+set}" = set ] && DEPEND="${B_DEPEND}"
1431 [ "${B_DEPEND+set}" = set ] || unset DEPEND
1433 [ "${B_RDEPEND+set}" = set ] && RDEPEND="${B_RDEPEND}"
1434 [ "${B_RDEPEND+set}" = set ] || unset RDEPEND
1436 [ "${B_PDEPEND+set}" = set ] && PDEPEND="${B_PDEPEND}"
1437 [ "${B_PDEPEND+set}" = set ] || unset PDEPEND
1439 #turn on glob expansion
1442 if [[ -n ${!__export_funcs_var} ]] ; then
1443 for x in ${!__export_funcs_var} ; do
1444 debug-print "EXPORT_FUNCTIONS: $x -> ${ECLASS}_$x"
1445 declare -F "${ECLASS}_$x" >/dev/null || \
1446 die "EXPORT_FUNCTIONS: ${ECLASS}_$x is not defined"
1447 eval "$x() { ${ECLASS}_$x \"\$@\" ; }" > /dev/null
1450 unset $__export_funcs_var
1452 has $1 $INHERITED || export INHERITED="$INHERITED $1"
1456 ((--ECLASS_DEPTH)) # Returns 1 when ECLASS_DEPTH reaches 0.
1457 if (( ECLASS_DEPTH > 0 )) ; then
1458 export ECLASS=$PECLASS
1459 __export_funcs_var=$prev_export_funcs_var
1461 unset ECLASS __export_funcs_var
1466 # Exports stub functions that call the eclass's functions, thereby making them default.
1467 # For example, if ECLASS="base" and you call "EXPORT_FUNCTIONS src_unpack", the following
1468 # code will be eval'd:
1469 # src_unpack() { base_src_unpack; }
1470 EXPORT_FUNCTIONS() {
1471 if [ -z "$ECLASS" ]; then
1472 die "EXPORT_FUNCTIONS without a defined ECLASS"
1474 eval $__export_funcs_var+=\" $*\"
1477 # this is a function for removing any directory matching a passed in pattern from
1479 remove_path_entry() {
1482 stripped_path="${PATH}"
1483 while [ -n "$1" ]; do
1485 for p in ${stripped_path}; do
1486 if [ "${p/${1}}" == "${p}" ]; then
1487 cur_path="${cur_path}:${p}"
1490 stripped_path="${cur_path#:*}"
1494 PATH="${stripped_path}"
1497 # @FUNCTION: _ebuild_arg_to_phase
1499 # Translate a known ebuild(1) argument into the precise
1500 # name of it's corresponding ebuild phase.
1501 _ebuild_arg_to_phase() {
1502 [ $# -ne 2 ] && die "expected exactly 2 args, got $#: $*"
1509 ! has $eapi 0 1 2 3 3_pre2 && \
1510 phase_func=pkg_pretend
1513 phase_func=pkg_setup
1516 phase_func=pkg_nofetch
1519 phase_func=src_unpack
1522 ! has $eapi 0 1 && \
1523 phase_func=src_prepare
1526 ! has $eapi 0 1 && \
1527 phase_func=src_configure
1530 phase_func=src_compile
1536 phase_func=src_install
1539 phase_func=pkg_preinst
1542 phase_func=pkg_postinst
1545 phase_func=pkg_prerm
1548 phase_func=pkg_postrm
1552 [[ -z $phase_func ]] && return 1
1557 _ebuild_phase_funcs() {
1558 [ $# -ne 2 ] && die "expected exactly 2 args, got $#: $*"
1561 local default_phases="pkg_nofetch src_unpack src_prepare src_configure
1562 src_compile src_install src_test"
1563 local x y default_func=""
1565 for x in pkg_nofetch src_unpack src_test ; do
1566 declare -F $x >/dev/null || \
1567 eval "$x() { _eapi0_$x \"\$@\" ; }"
1574 if ! declare -F src_compile >/dev/null ; then
1577 src_compile() { _eapi0_src_compile "$@" ; }
1580 src_compile() { _eapi1_src_compile "$@" ; }
1585 for x in $default_phases ; do
1586 eval "default_$x() {
1587 die \"default_$x() is not supported with EAPI='$eapi' during phase $phase_func\"
1592 die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
1599 declare -F src_configure >/dev/null || \
1600 src_configure() { _eapi2_src_configure "$@" ; }
1602 declare -F src_compile >/dev/null || \
1603 src_compile() { _eapi2_src_compile "$@" ; }
1605 has $eapi 2 3 3_pre2 || declare -F src_install >/dev/null || \
1606 src_install() { _eapi4_src_install "$@" ; }
1608 if has $phase_func $default_phases ; then
1610 _eapi2_pkg_nofetch () { _eapi0_pkg_nofetch "$@" ; }
1611 _eapi2_src_unpack () { _eapi0_src_unpack "$@" ; }
1612 _eapi2_src_prepare () { true ; }
1613 _eapi2_src_test () { _eapi0_src_test "$@" ; }
1614 _eapi2_src_install () { die "$FUNCNAME is not supported" ; }
1616 for x in $default_phases ; do
1617 eval "default_$x() { _eapi2_$x \"\$@\" ; }"
1620 eval "default() { _eapi2_$phase_func \"\$@\" ; }"
1626 eval "default_src_install() { _eapi4_src_install \"\$@\" ; }"
1627 [[ $phase_func = src_install ]] && \
1628 eval "default() { _eapi4_$phase_func \"\$@\" ; }"
1634 for x in $default_phases ; do
1635 eval "default_$x() {
1636 die \"default_$x() is not supported in phase $default_func\"
1641 die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
1650 # Set given variables unless these variable have been already set (e.g. during emerge
1651 # invocation) to values different than values set in make.conf.
1652 set_unless_changed() {
1653 if [[ $# -lt 1 ]]; then
1654 die "${FUNCNAME}() requires at least 1 argument: VARIABLE=VALUE"
1657 local argument value variable
1658 for argument in "$@"; do
1659 if [[ ${argument} != *=* ]]; then
1660 die "${FUNCNAME}(): Argument '${argument}' has incorrect syntax"
1662 variable="${argument%%=*}"
1663 value="${argument#*=}"
1664 if eval "[[ \${${variable}} == \$(env -u ${variable} portageq envvar ${variable}) ]]"; then
1665 eval "${variable}=\"\${value}\""
1670 # Unset given variables unless these variable have been set (e.g. during emerge
1671 # invocation) to values different than values set in make.conf.
1672 unset_unless_changed() {
1673 if [[ $# -lt 1 ]]; then
1674 die "${FUNCNAME}() requires at least 1 argument: VARIABLE"
1678 for variable in "$@"; do
1679 if eval "[[ \${${variable}} == \$(env -u ${variable} portageq envvar ${variable}) ]]"; then
1685 PORTAGE_BASHRCS_SOURCED=0
1687 # @FUNCTION: source_all_bashrcs
1689 # Source a relevant bashrc files and perform other miscellaneous
1690 # environment initialization when appropriate.
1692 # If EAPI is set then define functions provided by the current EAPI:
1694 # * default_* aliases for the current EAPI phase functions
1695 # * A "default" function which is an alias for the default phase
1696 # function for the current phase.
1698 source_all_bashrcs() {
1699 [[ $PORTAGE_BASHRCS_SOURCED = 1 ]] && return 0
1700 PORTAGE_BASHRCS_SOURCED=1
1703 local OCC="${CC}" OCXX="${CXX}"
1705 if [[ $EBUILD_PHASE != depend ]] ; then
1706 # source the existing profile.bashrcs.
1709 local path_array=($PROFILE_PATHS)
1711 for x in "${path_array[@]}" ; do
1712 [ -f "$x/profile.bashrc" ] && qa_source "$x/profile.bashrc"
1716 # We assume if people are changing shopts in their bashrc they do so at their
1717 # own peril. This is the ONLY non-portage bit of code that can change shopts
1718 # without a QA violation.
1719 for x in "${PORTAGE_BASHRC}" "${PM_EBUILD_HOOK_DIR}"/${CATEGORY}/{${PN},${PN}:${SLOT},${P},${PF}}; do
1720 if [ -r "${x}" ]; then
1721 # If $- contains x, then tracing has already enabled elsewhere for some
1722 # reason. We preserve it's state so as not to interfere.
1723 if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then
1733 [ ! -z "${OCC}" ] && export CC="${OCC}"
1734 [ ! -z "${OCXX}" ] && export CXX="${OCXX}"
1737 # Hardcoded bash lists are needed for backward compatibility with
1738 # <portage-2.1.4 since they assume that a newly installed version
1739 # of ebuild.sh will work for pkg_postinst, pkg_prerm, and pkg_postrm
1740 # when portage is upgrading itself.
1742 PORTAGE_READONLY_METADATA="DEFINED_PHASES DEPEND DESCRIPTION
1743 EAPI HOMEPAGE INHERITED IUSE REQUIRED_USE KEYWORDS LICENSE
1744 PDEPEND PROVIDE RDEPEND RESTRICT SLOT SRC_URI"
1746 PORTAGE_READONLY_VARS="D EBUILD EBUILD_PHASE \
1747 EBUILD_SH_ARGS ECLASSDIR EMERGE_FROM FILESDIR MERGE_TYPE \
1748 PM_EBUILD_HOOK_DIR \
1749 PORTAGE_ACTUAL_DISTDIR PORTAGE_ARCHLIST PORTAGE_BASHRC \
1750 PORTAGE_BINPKG_FILE PORTAGE_BINPKG_TAR_OPTS PORTAGE_BINPKG_TMPFILE \
1751 PORTAGE_BIN_PATH PORTAGE_BUILDDIR PORTAGE_BUNZIP2_COMMAND \
1752 PORTAGE_BZIP2_COMMAND PORTAGE_COLORMAP PORTAGE_CONFIGROOT \
1753 PORTAGE_DEBUG PORTAGE_DEPCACHEDIR PORTAGE_EBUILD_EXIT_FILE \
1754 PORTAGE_GID PORTAGE_GRPNAME PORTAGE_INST_GID PORTAGE_INST_UID \
1755 PORTAGE_IPC_DAEMON PORTAGE_IUSE PORTAGE_LOG_FILE \
1756 PORTAGE_MUTABLE_FILTERED_VARS PORTAGE_PYM_PATH PORTAGE_PYTHON \
1757 PORTAGE_READONLY_METADATA PORTAGE_READONLY_VARS \
1758 PORTAGE_REPO_NAME PORTAGE_RESTRICT PORTAGE_SANDBOX_COMPAT_LEVEL \
1759 PORTAGE_SAVED_READONLY_VARS PORTAGE_SIGPIPE_STATUS \
1760 PORTAGE_TMPDIR PORTAGE_UPDATE_ENV PORTAGE_USERNAME \
1761 PORTAGE_VERBOSE PORTAGE_WORKDIR_MODE PORTDIR PORTDIR_OVERLAY \
1762 PROFILE_PATHS REPLACING_VERSIONS REPLACED_BY_VERSION T WORKDIR"
1764 PORTAGE_SAVED_READONLY_VARS="A CATEGORY P PF PN PR PV PVR"
1766 # Variables that portage sets but doesn't mark readonly.
1767 # In order to prevent changed values from causing unexpected
1768 # interference, they are filtered out of the environment when
1769 # it is saved or loaded (any mutations do not persist).
1770 PORTAGE_MUTABLE_FILTERED_VARS="AA HOSTNAME"
1772 # @FUNCTION: filter_readonly_variables
1773 # @DESCRIPTION: [--filter-sandbox] [--allow-extra-vars]
1774 # Read an environment from stdin and echo to stdout while filtering variables
1775 # with names that are known to cause interference:
1777 # * some specific variables for which bash does not allow assignment
1778 # * some specific variables that affect portage or sandbox behavior
1779 # * variable names that begin with a digit or that contain any
1780 # non-alphanumeric characters that are not be supported by bash
1782 # --filter-sandbox causes all SANDBOX_* variables to be filtered, which
1783 # is only desired in certain cases, such as during preprocessing or when
1784 # saving environment.bz2 for a binary or installed package.
1786 # --filter-features causes the special FEATURES variable to be filtered.
1787 # Generally, we want it to persist between phases since the user might
1788 # want to modify it via bashrc to enable things like splitdebug and
1789 # installsources for specific packages. They should be able to modify it
1790 # in pre_pkg_setup() and have it persist all the way through the install
1791 # phase. However, if FEATURES exist inside environment.bz2 then they
1792 # should be overridden by current settings.
1794 # --filter-locale causes locale related variables such as LANG and LC_*
1795 # variables to be filtered. These variables should persist between phases,
1796 # in case they are modified by the ebuild. However, the current user
1797 # settings should be used when loading the environment from a binary or
1798 # installed package.
1800 # --filter-path causes the PATH variable to be filtered. This variable
1801 # should persist between phases, in case it is modified by the ebuild.
1802 # However, old settings should be overridden when loading the
1803 # environment from a binary or installed package.
1805 # ---allow-extra-vars causes some extra vars to be allowd through, such
1806 # as ${PORTAGE_SAVED_READONLY_VARS} and ${PORTAGE_MUTABLE_FILTERED_VARS}.
1808 # In bash-3.2_p20+ an attempt to assign BASH_*, FUNCNAME, GROUPS or any
1809 # readonly variable cause the shell to exit while executing the "source"
1810 # builtin command. To avoid this problem, this function filters those
1811 # variables out and discards them. See bug #190128.
1812 filter_readonly_variables() {
1813 local x filtered_vars
1814 local readonly_bash_vars="BASHOPTS BASHPID DIRSTACK EUID
1815 FUNCNAME GROUPS PIPESTATUS PPID SHELLOPTS UID"
1816 local bash_misc_vars="BASH BASH_.* COMP_WORDBREAKS HISTCMD
1817 HISTFILE HOSTNAME HOSTTYPE IFS LINENO MACHTYPE OLDPWD
1818 OPTERR OPTIND OSTYPE POSIXLY_CORRECT PS4 PWD RANDOM
1819 SECONDS SHELL SHLVL"
1820 local filtered_sandbox_vars="SANDBOX_ACTIVE SANDBOX_BASHRC
1821 SANDBOX_DEBUG_LOG SANDBOX_DISABLED SANDBOX_LIB
1822 SANDBOX_LOG SANDBOX_ON"
1823 local misc_garbage_vars="_portage_filter_opts"
1824 filtered_vars="$readonly_bash_vars $bash_misc_vars
1825 $PORTAGE_READONLY_VARS $misc_garbage_vars"
1827 # Don't filter/interfere with prefix variables unless they are
1828 # supported by the current EAPI.
1829 case "${EAPI:-0}" in
1833 filtered_vars+=" ED EPREFIX EROOT"
1837 if has --filter-sandbox $* ; then
1838 filtered_vars="${filtered_vars} SANDBOX_.*"
1840 filtered_vars="${filtered_vars} ${filtered_sandbox_vars}"
1842 if has --filter-features $* ; then
1843 filtered_vars="${filtered_vars} FEATURES PORTAGE_FEATURES"
1845 if has --filter-path $* ; then
1846 filtered_vars+=" PATH"
1848 if has --filter-locale $* ; then
1849 filtered_vars+=" LANG LC_ALL LC_COLLATE
1850 LC_CTYPE LC_MESSAGES LC_MONETARY
1851 LC_NUMERIC LC_PAPER LC_TIME"
1853 if ! has --allow-extra-vars $* ; then
1856 ${PORTAGE_SAVED_READONLY_VARS}
1857 ${PORTAGE_MUTABLE_FILTERED_VARS}
1861 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}" || die "filter-bash-environment.py failed"
1864 # @FUNCTION: preprocess_ebuild_env
1866 # Filter any readonly variables from ${T}/environment, source it, and then
1867 # save it via save_ebuild_env(). This process should be sufficient to prevent
1868 # any stale variables or functions from an arbitrary environment from
1869 # interfering with the current environment. This is useful when an existing
1870 # environment needs to be loaded from a binary or installed package.
1871 preprocess_ebuild_env() {
1872 local _portage_filter_opts="--filter-features --filter-locale --filter-path --filter-sandbox"
1874 # If environment.raw is present, this is a signal from the python side,
1875 # indicating that the environment may contain stale FEATURES and
1876 # SANDBOX_{DENY,PREDICT,READ,WRITE} variables that should be filtered out.
1877 # Otherwise, we don't need to filter the environment.
1878 [ -f "${T}/environment.raw" ] || return 0
1880 filter_readonly_variables $_portage_filter_opts < "${T}"/environment \
1881 >> "$T/environment.filtered" || return $?
1882 unset _portage_filter_opts
1883 mv "${T}"/environment.filtered "${T}"/environment || return $?
1884 rm -f "${T}/environment.success" || return $?
1885 # WARNING: Code inside this subshell should avoid making assumptions
1886 # about variables or functions after source "${T}"/environment has been
1887 # called. Any variables that need to be relied upon should already be
1888 # filtered out above.
1891 source "${T}/environment" || exit $?
1892 # We have to temporarily disable sandbox since the
1893 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
1894 # may be unusable (triggering in spurious sandbox violations)
1895 # until we've merged them with our current values.
1898 # It's remotely possible that save_ebuild_env() has been overridden
1899 # by the above source command. To protect ourselves, we override it
1900 # here with our own version. ${PORTAGE_BIN_PATH} is safe to use here
1901 # because it's already filtered above.
1902 source "${PORTAGE_BIN_PATH}/isolated-functions.sh" || exit $?
1904 # Rely on save_ebuild_env() to filter out any remaining variables
1905 # and functions that could interfere with the current environment.
1906 save_ebuild_env || exit $?
1907 >> "$T/environment.success" || exit $?
1908 ) > "${T}/environment.filtered"
1910 if [ -e "${T}/environment.success" ] ; then
1911 filter_readonly_variables --filter-features < \
1912 "${T}/environment.filtered" > "${T}/environment"
1917 rm -f "${T}"/environment.{filtered,raw,success}
1921 # === === === === === === === === === === === === === === === === === ===
1922 # === === === === === functions end, main part begins === === === === ===
1923 # === === === === === functions end, main part begins === === === === ===
1924 # === === === === === functions end, main part begins === === === === ===
1925 # === === === === === === === === === === === === === === === === === ===
1927 export SANDBOX_ON="1"
1928 export S=${WORKDIR}/${P}
1930 unset E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND
1932 # Turn of extended glob matching so that g++ doesn't get incorrectly matched.
1935 if [[ ${EBUILD_PHASE} == depend ]] ; then
1936 QA_INTERCEPTORS="awk bash cc egrep equery fgrep g++
1937 gawk gcc grep javac java-config nawk perl
1938 pkg-config python python-config sed"
1939 elif [[ ${EBUILD_PHASE} == clean* ]] ; then
1940 unset QA_INTERCEPTORS
1942 QA_INTERCEPTORS="autoconf automake aclocal libtoolize"
1944 # level the QA interceptors if we're in depend
1945 if [[ -n ${QA_INTERCEPTORS} ]] ; then
1946 for BIN in ${QA_INTERCEPTORS}; do
1947 BIN_PATH=$(type -Pf ${BIN})
1948 if [ "$?" != "0" ]; then
1949 BODY="echo \"*** missing command: ${BIN}\" >&2; return 127"
1951 BODY="${BIN_PATH} \"\$@\"; return \$?"
1953 if [[ ${EBUILD_PHASE} == depend ]] ; then
1954 FUNC_SRC="${BIN}() {
1955 if [ \$ECLASS_DEPTH -gt 0 ]; then
1956 eqawarn \"QA Notice: '${BIN}' called in global scope: eclass \${ECLASS}\"
1958 eqawarn \"QA Notice: '${BIN}' called in global scope: \${CATEGORY}/\${PF}\"
1962 elif has ${BIN} autoconf automake aclocal libtoolize ; then
1963 FUNC_SRC="${BIN}() {
1964 if ! has \${FUNCNAME[1]} eautoreconf eaclocal _elibtoolize \\
1965 eautoheader eautoconf eautomake autotools_run_tool \\
1966 autotools_check_macro autotools_get_subdirs \\
1967 autotools_get_auxdir ; then
1968 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
1969 eqawarn \"Use autotools.eclass instead of calling '${BIN}' directly.\"
1974 FUNC_SRC="${BIN}() {
1975 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
1979 eval "$FUNC_SRC" || echo "error creating QA interceptor ${BIN}" >&2
1981 unset BIN_PATH BIN BODY FUNC_SRC
1984 # Subshell/helper die support (must export for the die helper).
1985 export EBUILD_MASTER_PID=$BASHPID
1986 trap 'exit 1' SIGTERM
1988 if ! has "$EBUILD_PHASE" clean cleanrm depend && \
1989 [ -f "${T}"/environment ] ; then
1990 # The environment may have been extracted from environment.bz2 or
1991 # may have come from another version of ebuild.sh or something.
1992 # In any case, preprocess it to prevent any potential interference.
1993 preprocess_ebuild_env || \
1994 die "error processing environment"
1995 # Colon separated SANDBOX_* variables need to be cumulative.
1996 for x in SANDBOX_DENY SANDBOX_READ SANDBOX_PREDICT SANDBOX_WRITE ; do
1997 export PORTAGE_${x}=${!x}
1999 PORTAGE_SANDBOX_ON=${SANDBOX_ON}
2001 source "${T}"/environment || \
2002 die "error sourcing environment"
2003 # We have to temporarily disable sandbox since the
2004 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
2005 # may be unusable (triggering in spurious sandbox violations)
2006 # until we've merged them with our current values.
2008 for x in SANDBOX_DENY SANDBOX_PREDICT SANDBOX_READ SANDBOX_WRITE ; do
2010 if [ -z "${!x}" ] ; then
2012 elif [ -n "${!y}" ] && [ "${!y}" != "${!x}" ] ; then
2014 export ${x}=$(printf "${!y}:${!x}" | tr ":" "\0" | \
2015 sort -z -u | tr "\0" ":")
2021 export SANDBOX_ON=${PORTAGE_SANDBOX_ON}
2022 unset PORTAGE_SANDBOX_ON
2023 [[ -n $EAPI ]] || EAPI=0
2026 if ! has "$EBUILD_PHASE" clean cleanrm ; then
2027 if [[ $EBUILD_PHASE = depend || ! -f $T/environment || \
2028 -f $PORTAGE_BUILDDIR/.ebuild_changed ]] || \
2029 has noauto $FEATURES ; then
2030 # The bashrcs get an opportunity here to set aliases that will be expanded
2031 # during sourcing of ebuilds and eclasses.
2034 # When EBUILD_PHASE != depend, INHERITED comes pre-initialized
2035 # from cache. In order to make INHERITED content independent of
2036 # EBUILD_PHASE during inherit() calls, we unset INHERITED after
2037 # we make a backup copy for QA checks.
2038 __INHERITED_QA_CACHE=$INHERITED
2040 # *DEPEND and IUSE will be set during the sourcing of the ebuild.
2041 # In order to ensure correct interaction between ebuilds and
2042 # eclasses, they need to be unset before this process of
2043 # interaction begins.
2044 unset DEPEND RDEPEND PDEPEND INHERITED IUSE REQUIRED_USE \
2045 ECLASS E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND
2047 if [[ $PORTAGE_DEBUG != 1 || ${-/x/} != $- ]] ; then
2048 source "$EBUILD" || die "error sourcing ebuild"
2051 source "$EBUILD" || die "error sourcing ebuild"
2055 if [[ "${EBUILD_PHASE}" != "depend" ]] ; then
2056 RESTRICT=${PORTAGE_RESTRICT}
2057 [[ -e $PORTAGE_BUILDDIR/.ebuild_changed ]] && \
2058 rm "$PORTAGE_BUILDDIR/.ebuild_changed"
2061 [[ -n $EAPI ]] || EAPI=0
2063 if has "$EAPI" 0 1 2 3 3_pre2 ; then
2064 export RDEPEND=${RDEPEND-${DEPEND}}
2065 debug-print "RDEPEND: not set... Setting to: ${DEPEND}"
2068 # add in dependency info from eclasses
2069 IUSE="${IUSE} ${E_IUSE}"
2070 DEPEND="${DEPEND} ${E_DEPEND}"
2071 RDEPEND="${RDEPEND} ${E_RDEPEND}"
2072 PDEPEND="${PDEPEND} ${E_PDEPEND}"
2073 REQUIRED_USE="${REQUIRED_USE} ${E_REQUIRED_USE}"
2075 unset ECLASS E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND \
2076 __INHERITED_QA_CACHE
2078 # alphabetically ordered by $EBUILD_PHASE value
2081 _valid_phases="src_compile pkg_config pkg_info src_install
2082 pkg_nofetch pkg_postinst pkg_postrm pkg_preinst pkg_prerm
2083 pkg_setup src_test src_unpack"
2086 _valid_phases="src_compile pkg_config src_configure pkg_info
2087 src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst
2088 src_prepare pkg_prerm pkg_setup src_test src_unpack"
2091 _valid_phases="src_compile pkg_config src_configure pkg_info
2092 src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst
2093 src_prepare pkg_prerm pkg_pretend pkg_setup src_test src_unpack"
2098 for _f in $_valid_phases ; do
2099 if declare -F $_f >/dev/null ; then
2101 DEFINED_PHASES+=" ${_f#src_}"
2104 [[ -n $DEFINED_PHASES ]] || DEFINED_PHASES=-
2106 unset _f _valid_phases
2108 if [[ $EBUILD_PHASE != depend ]] ; then
2112 _ebuild_helpers_path="$PORTAGE_BIN_PATH/ebuild-helpers"
2115 _ebuild_helpers_path="$PORTAGE_BIN_PATH/ebuild-helpers/4:$PORTAGE_BIN_PATH/ebuild-helpers"
2119 PATH=$_ebuild_helpers_path:$PREROOTPATH${PREROOTPATH:+:}/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin${ROOTPATH:+:}$ROOTPATH
2120 unset _ebuild_helpers_path
2122 # Use default ABI libdir in accordance with bug #355283.
2123 x=LIBDIR_${DEFAULT_ABI}
2124 [[ -n $DEFAULT_ABI && -n ${!x} ]] && x=${!x} || x=lib
2126 if has distcc $FEATURES ; then
2127 PATH="/usr/$x/distcc/bin:$PATH"
2128 [[ -n $DISTCC_LOG ]] && addwrite "${DISTCC_LOG%/*}"
2131 if has ccache $FEATURES ; then
2132 PATH="/usr/$x/ccache/bin:$PATH"
2134 if [[ -n $CCACHE_DIR ]] ; then
2135 addread "$CCACHE_DIR"
2136 addwrite "$CCACHE_DIR"
2139 [[ -n $CCACHE_SIZE ]] && ccache -M $CCACHE_SIZE &> /dev/null
2144 if [[ -n $QA_PREBUILT ]] ; then
2146 # these ones support fnmatch patterns
2147 QA_EXECSTACK+=" $QA_PREBUILT"
2148 QA_TEXTRELS+=" $QA_PREBUILT"
2149 QA_WX_LOAD+=" $QA_PREBUILT"
2151 # these ones support regular expressions, so translate
2152 # fnmatch patterns to regular expressions
2153 for x in QA_DT_HASH QA_DT_NEEDED QA_PRESTRIPPED QA_SONAME ; do
2154 if [[ $(declare -p $x 2>/dev/null) = declare\ -a* ]] ; then
2155 eval "$x=(\"\${$x[@]}\" ${QA_PREBUILT//\*/.*})"
2157 eval "$x+=\" ${QA_PREBUILT//\*/.*}\""
2164 # This needs to be exported since prepstrip is a separate shell script.
2165 [[ -n $QA_PRESTRIPPED ]] && export QA_PRESTRIPPED
2166 eval "[[ -n \$QA_PRESTRIPPED_${ARCH/-/_} ]] && \
2167 export QA_PRESTRIPPED_${ARCH/-/_}"
2172 # unset USE_EXPAND variables that contain only the special "*" token
2173 for x in ${USE_EXPAND} ; do
2174 [ "${!x}" == "*" ] && unset ${x}
2178 if has nostrip ${FEATURES} ${RESTRICT} || has strip ${RESTRICT}
2183 #a reasonable default for $S
2184 [[ -z ${S} ]] && export S=${WORKDIR}/${P}
2186 # Note: readonly variables interfere with preprocess_ebuild_env(), so
2187 # declare them only after it has already run.
2188 if [ "${EBUILD_PHASE}" != "depend" ] ; then
2189 declare -r $PORTAGE_READONLY_METADATA $PORTAGE_READONLY_VARS
2194 declare -r ED EPREFIX EROOT
2201 # Subshell/helper die support (must export for the die helper).
2202 # Since this function is typically executed in a subshell,
2203 # setup EBUILD_MASTER_PID to refer to the current $BASHPID,
2204 # which seems to give the best results when further
2205 # nested subshells call die.
2206 export EBUILD_MASTER_PID=$BASHPID
2207 trap 'exit 1' SIGTERM
2209 if [[ $EBUILD_PHASE != depend ]] ; then
2210 # Force configure scripts that automatically detect ccache to
2211 # respect FEATURES="-ccache".
2212 has ccache $FEATURES || export CCACHE_DISABLE=1
2214 local phase_func=$(_ebuild_arg_to_phase "$EAPI" "$EBUILD_PHASE")
2215 [[ -n $phase_func ]] && _ebuild_phase_funcs "$EAPI" "$phase_func"
2221 case ${EBUILD_SH_ARGS} in
2223 ebuild_phase_with_hooks pkg_nofetch
2225 prerm|postrm|postinst|config|info)
2226 if has "$EBUILD_SH_ARGS" config info && \
2227 ! declare -F "pkg_$EBUILD_SH_ARGS" >/dev/null ; then
2228 ewarn "pkg_${EBUILD_SH_ARGS}() is not defined: '${EBUILD##*/}'"
2230 export SANDBOX_ON="0"
2231 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
2232 ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
2235 ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
2238 if [[ $EBUILD_PHASE == postinst ]] && [[ -n $PORTAGE_UPDATE_ENV ]]; then
2239 # Update environment.bz2 in case installation phases
2240 # need to pass some variables to uninstallation phases.
2241 save_ebuild_env --exclude-init-phases | \
2242 filter_readonly_variables --filter-path \
2243 --filter-sandbox --allow-extra-vars \
2244 | ${PORTAGE_BZIP2_COMMAND} -c -f9 > "$PORTAGE_UPDATE_ENV"
2245 assert "save_ebuild_env failed"
2248 unpack|prepare|configure|compile|test|clean|install)
2249 if [[ ${SANDBOX_DISABLED:-0} = 0 ]] ; then
2250 export SANDBOX_ON="1"
2252 export SANDBOX_ON="0"
2255 case "$EBUILD_SH_ARGS" in
2259 for x in ASFLAGS CCACHE_DIR CCACHE_SIZE \
2260 CFLAGS CXXFLAGS LDFLAGS LIBCFLAGS LIBCXXFLAGS ; do
2261 [[ ${!x+set} = set ]] && export $x
2265 has distcc $FEATURES && [[ -n $DISTCC_DIR ]] && \
2266 [[ ${SANDBOX_WRITE/$DISTCC_DIR} = $SANDBOX_WRITE ]] && \
2267 addwrite "$DISTCC_DIR"
2270 [ -z "$PKG_CONFIG_PATH" -a -n "$ABI" -a -n "${!x}" ] && \
2271 export PKG_CONFIG_PATH=/usr/${!x}/pkgconfig
2273 if has noauto $FEATURES && \
2274 [[ ! -f $PORTAGE_BUILDDIR/.unpacked ]] ; then
2276 echo "!!! We apparently haven't unpacked..." \
2277 "This is probably not what you"
2278 echo "!!! want to be doing... You are using" \
2279 "FEATURES=noauto so I'll assume"
2280 echo "!!! that you know what you are doing..." \
2281 "You have 5 seconds to abort..."
2285 for x in 1 2 3 4 5 6 7 8; do
2292 cd "$PORTAGE_BUILDDIR"
2293 if [ ! -d build-info ] ; then
2295 cp "$EBUILD" "build-info/$PF.ebuild"
2298 #our custom version of libtool uses $S and $D to fix
2299 #invalid paths in .la files
2305 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
2306 dyn_${EBUILD_SH_ARGS}
2309 dyn_${EBUILD_SH_ARGS}
2312 export SANDBOX_ON="0"
2314 help|pretend|setup|preinst)
2315 #pkg_setup needs to be out of the sandbox for tmp file creation;
2316 #for example, awking and piping a file in /tmp requires a temp file to be created
2317 #in /etc. If pkg_setup is in the sandbox, both our lilo and apache ebuilds break.
2318 export SANDBOX_ON="0"
2319 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
2320 dyn_${EBUILD_SH_ARGS}
2323 dyn_${EBUILD_SH_ARGS}
2328 export SANDBOX_ON="0"
2331 if [ -n "${dbkey}" ] ; then
2332 if [ ! -d "${dbkey%/*}" ]; then
2333 install -d -g ${PORTAGE_GID} -m2775 "${dbkey%/*}"
2335 # Make it group writable. 666&~002==664
2339 auxdbkeys="DEPEND RDEPEND SLOT SRC_URI RESTRICT HOMEPAGE LICENSE
2340 DESCRIPTION KEYWORDS INHERITED IUSE REQUIRED_USE PDEPEND PROVIDE EAPI
2341 PROPERTIES DEFINED_PHASES UNUSED_05 UNUSED_04
2342 UNUSED_03 UNUSED_02 UNUSED_01"
2344 #the extra $(echo) commands remove newlines
2345 [ -n "${EAPI}" ] || EAPI=0
2347 if [ -n "${dbkey}" ] ; then
2349 for f in ${auxdbkeys} ; do
2350 echo $(echo ${!f}) >> "${dbkey}" || exit $?
2353 for f in ${auxdbkeys} ; do
2354 echo $(echo ${!f}) 1>&9 || exit $?
2363 export SANDBOX_ON="1"
2364 echo "Unrecognized EBUILD_SH_ARGS: '${EBUILD_SH_ARGS}'"
2372 if [[ -s $SANDBOX_LOG ]] ; then
2373 # We use SANDBOX_LOG to check for sandbox violations,
2374 # so we ensure that there can't be a stale log to
2375 # interfere with our logic.
2377 if [[ -n SANDBOX_ON ]] ; then
2382 rm -f "$SANDBOX_LOG" || \
2383 die "failed to remove stale sandbox log: '$SANDBOX_LOG'"
2385 if [[ -n $x ]] ; then
2386 export SANDBOX_ON=$x
2391 if [[ $EBUILD_PHASE = depend ]] ; then
2393 elif [[ -n $EBUILD_SH_ARGS ]] ; then
2395 # Don't allow subprocesses to inherit the pipe which
2396 # emerge uses to monitor ebuild.sh.
2401 # Save the env only for relevant phases.
2402 if ! has "$EBUILD_SH_ARGS" clean help info nofetch ; then
2404 save_ebuild_env | filter_readonly_variables \
2405 --filter-features > "$T/environment"
2406 assert "save_ebuild_env failed"
2407 chown portage:portage "$T/environment" &>/dev/null
2408 chmod g+w "$T/environment" &>/dev/null
2410 [[ -n $PORTAGE_EBUILD_EXIT_FILE ]] && > "$PORTAGE_EBUILD_EXIT_FILE"
2411 if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
2412 [[ ! -s $SANDBOX_LOG ]]
2413 "$PORTAGE_BIN_PATH"/ebuild-ipc exit $?
2420 # Do not exit when ebuild.sh is sourced by other scripts.