2 # Copyright 1999-2007 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
6 PORTAGE_BIN_PATH="${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"
7 PORTAGE_PYM_PATH="${PORTAGE_PYM_PATH:-/usr/lib/portage/pym}"
9 SANDBOX_PREDICT="${SANDBOX_PREDICT}:/proc/self/maps:/dev/console:/dev/random"
10 export SANDBOX_PREDICT="${SANDBOX_PREDICT}:${PORTAGE_PYM_PATH}:${PORTAGE_DEPCACHEDIR}"
11 export SANDBOX_WRITE="${SANDBOX_WRITE}:/dev/shm:/dev/stdout:/dev/stderr:${PORTAGE_TMPDIR}"
12 export SANDBOX_READ="${SANDBOX_READ}:/:/dev/shm:/dev/stdin:${PORTAGE_TMPDIR}"
13 # Don't use sandbox's BASH_ENV for new shells because it does
14 # 'source /etc/profile' which can interfere with the build
15 # environment by modifying our PATH.
18 # sandbox's bashrc sources /etc/profile which unsets ROOTPATH,
19 # so we have to back it up and restore it.
20 if [ -n "${PORTAGE_ROOTPATH}" ] ; then
21 export ROOTPATH=${PORTAGE_ROOTPATH}
22 unset PORTAGE_ROOTPATH
25 if [ ! -z "${PORTAGE_GPG_DIR}" ]; then
26 SANDBOX_PREDICT="${SANDBOX_PREDICT}:${PORTAGE_GPG_DIR}"
29 # These two functions wrap sourcing and calling respectively. At present they
30 # perform a qa check to make sure eclasses and ebuilds and profiles don't mess
31 # with shell opts (shopts). Ebuilds/eclasses changing shopts should reset them
32 # when they are done. Note: For now these shoudl always return success.
35 local shopts=$(shopt) OLDIFS="$IFS"
39 [[ $shopts != $(shopt) ]] &&
40 eqawarn "QA Notice: Global shell options changed and were not restored while sourcing '$*'"
41 [[ "$IFS" != "$OLDIFS" ]] &&
42 eqawarn "QA Notice: Global IFS changed and was not restored while sourcing '$*'"
47 local shopts=$(shopt) OLDIFS="$IFS"
51 [[ $shopts != $(shopt) ]] &&
52 eqawarn "QA Notice: Global shell options changed and were not restored while calling '$*'"
53 [[ "$IFS" != "$OLDIFS" ]] &&
54 eqawarn "QA Notice: Global IFS changed and was not restored while calling '$*'"
58 # subshell die support
66 # Prevent aliases from causing portage to act inappropriately.
67 # Make sure it's before everything so we don't mess aliases that follow.
70 # Unset some variables that break things.
71 unset GZIP BZIP BZIP2 CDPATH GREP_OPTIONS GREP_COLOR GLOBIGNORE
73 export PATH="/usr/local/sbin:/sbin:/usr/sbin:${PORTAGE_BIN_PATH}:/usr/local/bin:/bin:/usr/bin:${ROOTPATH}"
74 [ ! -z "$PREROOTPATH" ] && export PATH="${PREROOTPATH%%:}:$PATH"
76 source "${PORTAGE_BIN_PATH}/isolated-functions.sh" &>/dev/null
78 # Set IMAGE for minimal backward compatibility with
79 # overlays or user's bashrc, but don't export it.
80 [ "${EBUILD_PHASE}" == "preinst" ] && IMAGE=${D}
82 [[ $PORTAGE_QUIET != "" ]] && export PORTAGE_QUIET
84 # the sandbox is disabled by default except when overridden in the relevant stages
87 # sandbox support functions; defined prior to profile.bashrc srcing, since the profile might need to add a default exception (/usr/lib64/conftest fex)
89 [[ -z $1 || -n $2 ]] && die "Usage: addread <colon-delimited list of paths>"
90 export SANDBOX_READ="$SANDBOX_READ:$1"
94 [[ -z $1 || -n $2 ]] && die "Usage: addwrite <colon-delimited list of paths>"
95 export SANDBOX_WRITE="$SANDBOX_WRITE:$1"
99 [[ -z $1 || -n $2 ]] && die "Usage: adddeny <colon-delimited list of paths>"
100 export SANDBOX_DENY="$SANDBOX_DENY:$1"
104 [[ -z $1 || -n $2 ]] && die "Usage: addpredict <colon-delimited list of paths>"
105 export SANDBOX_PREDICT="$SANDBOX_PREDICT:$1"
117 # Custom version of esyslog() to take care of the "Red Star" bug.
118 # MUST follow functions.sh to override the "" parameter problem.
138 # if we got something like '!flag', then invert the return value
139 if [[ ${u:0:1} == "!" ]] ; then
144 # Make sure we have this USE flag in IUSE
145 if [[ -n ${PORTAGE_IUSE} ]] && \
146 [[ -n ${EBUILD_PHASE} ]] && \
147 ! hasq ${EBUILD_PHASE} config depend info prerm postrm postinst && \
148 [[ ${EMERGE_FROM} != binary ]] ; then
149 # TODO: Implement PORTAGE_IUSE for binary packages. Currently,
150 # it is only valid for build time phases.
151 [[ $u =~ $PORTAGE_IUSE ]] || \
152 eqawarn "QA Notice: USE Flag '${u}' not" \
153 "in IUSE for ${CATEGORY}/${PF}"
156 if hasq ${u} ${USE} ; then
164 if [ "${EBUILD_PHASE}" == "depend" ]; then
165 die "portageq calls (has_version calls portageq) are not allowed in the global scope"
167 # return shell-true/shell-false if exists.
168 # Takes single depend-type atoms.
169 PYTHONPATH="${PORTAGE_PYM_PATH}:${PYTHONPATH}" \
170 "${PORTAGE_BIN_PATH}"/portageq has_version "${ROOT}" "$1"
180 die "unexpected portageq exit code: ${retval}"
186 if [ "${EBUILD_PHASE}" == "depend" ]; then
187 die "portageq calls are not allowed in the global scope"
189 PYTHONPATH="${PORTAGE_PYM_PATH}:${PYTHONPATH}" \
190 "${PORTAGE_BIN_PATH}/portageq" "$@"
194 # ----------------------------------------------------------------------------
195 # ----------------------------------------------------------------------------
196 # ----------------------------------------------------------------------------
200 if [ "${EBUILD_PHASE}" == "depend" ]; then
201 die "portageq calls (best_version calls portageq) are not allowed in the global scope"
203 # returns the best/most-current match.
204 # Takes single depend-type atoms.
205 PYTHONPATH="${PORTAGE_PYM_PATH}:${PYTHONPATH}" \
206 "${PORTAGE_BIN_PATH}/portageq" 'best_version' "${ROOT}" "$1"
211 echo "!!! use_with() called without a parameter." >&2
212 echo "!!! use_with <USEFLAG> [<flagname> [value]]" >&2
217 if [ ! -z "${3}" ]; then
222 if [ -z "${UWORD}" ]; then
227 echo "--with-${UWORD}${UW_SUFFIX}"
229 echo "--without-${UWORD}"
236 echo "!!! use_enable() called without a parameter." >&2
237 echo "!!! use_enable <USEFLAG> [<flagname> [value]]" >&2
242 if [ ! -z "${3}" ]; then
247 if [ -z "${UWORD}" ]; then
252 echo "--enable-${UWORD}${UE_SUFFIX}"
254 echo "--disable-${UWORD}"
259 register_die_hook() {
260 export EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} $*"
263 #if no perms are specified, dirs/files will have decent defaults
264 #(not secretive, but not stupid)
266 export INSOPTIONS="-m0644"
267 export EXEOPTIONS="-m0755"
268 export LIBOPTIONS="-m0644"
269 export DIROPTIONS="-m0755"
270 export MOPREFIX=${PN}
273 if [ -z "${KV}" ]; then
275 eerror "Could not determine your kernel version."
276 eerror "Make sure that you have a /usr/src/linux symlink,"
277 eerror "and that the indicated kernel has been configured."
278 eerror "You can also simply run the following command"
279 eerror "in the directory referenced by /usr/src/linux:"
280 eerror " make include/linux/version.h"
286 # adds ".keep" files so that dirs aren't auto-cleaned
290 if [ "$1" == "-R" ] || [ "$1" == "-r" ]; then
292 find "$@" -type d -printf "${D}%p/.keep_${CATEGORY}_${PN}-${SLOT}\n" \
293 | tr "\n" "\0" | ${XARGS} -0 -n100 touch || \
294 die "Failed to recursively create .keep files"
297 touch "${D}${x}/.keep_${CATEGORY}_${PN}-${SLOT}" || \
298 die "Failed to create .keep in ${D}${x}"
309 [ -z "$*" ] && die "Nothing passed to the 'unpack' command"
312 vecho ">>> Unpacking ${x} to ${PWD}"
316 if [[ ${x} == "./"* ]] ; then
318 elif [[ ${x} == ${DISTDIR%/}/* ]] ; then
319 die "Arguments to unpack() cannot begin with \${DISTDIR}."
320 elif [[ ${x} == "/"* ]] ; then
321 die "Arguments to unpack() cannot be absolute"
325 [[ ! -s ${srcdir}${x} ]] && die "${x} does not exist"
327 myfail="failure unpacking ${x}"
330 tar xof "${srcdir}${x}" ${tar_opts} || die "$myfail"
333 tar xozf "${srcdir}${x}" ${tar_opts} || die "$myfail"
336 bzip2 -dc "${srcdir}${x}" | tar xof - ${tar_opts}
340 unzip -qo "${srcdir}${x}" || die "$myfail"
343 if [ "${y}" == "tar" ]; then
344 tar zoxf "${srcdir}${x}" ${tar_opts} || die "$myfail"
346 gzip -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
350 if [ "${y}" == "tar" ]; then
351 bzip2 -dc "${srcdir}${x}" | tar xof - ${tar_opts}
354 bzip2 -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
359 my_output="$(7z x -y "${srcdir}${x}")"
360 if [ $? -ne 0 ]; then
361 echo "${my_output}" >&2
366 unrar x -idq -o+ "${srcdir}${x}" || die "$myfail"
369 lha xfq "${srcdir}${x}" || die "$myfail"
372 ar x "${srcdir}${x}" || die "$myfail"
375 if [ "${y}" == "tar" ]; then
376 lzma -dc "${srcdir}${x}" | tar xof - ${tar_opts}
379 lzma -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
383 vecho "unpack ${x}: file format not recognized. Ignoring."
387 # Do not chmod '.' since it's probably ${WORKDIR} and PORTAGE_WORKDIR_MODE
388 # should be preserved.
389 find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \
390 ${XARGS} -0 chmod -fR a+rX,u+w,g-w,o-w
393 strip_duplicate_slashes() {
394 if [[ -n $1 ]] ; then
396 while [[ ${removed} == *//* ]] ; do
397 removed=${removed//\/\///}
405 local LOCAL_EXTRA_ECONF="${EXTRA_ECONF}"
407 if [ -z "${ECONF_SOURCE}" ]; then
410 if [ -x "${ECONF_SOURCE}/configure" ]; then
411 if [ -e /usr/share/gnuconfig/ ]; then
412 find "${WORKDIR}" -type f '(' \
413 -name config.guess -o -name config.sub ')' -print0 | \
414 while read -d $'\0' x ; do
415 vecho " * econf: updating ${x/${WORKDIR}\/} with /usr/share/gnuconfig/${x##*/}"
416 cp -f /usr/share/gnuconfig/"${x##*/}" "${x}"
420 if [ ! -z "${CBUILD}" ]; then
421 LOCAL_EXTRA_ECONF="--build=${CBUILD} ${LOCAL_EXTRA_ECONF}"
424 if [ ! -z "${CTARGET}" ]; then
425 LOCAL_EXTRA_ECONF="--target=${CTARGET} ${LOCAL_EXTRA_ECONF}"
428 # if the profile defines a location to install libs to aside from default, pass it on.
429 # if the ebuild passes in --libdir, they're responsible for the conf_libdir fun.
430 LIBDIR_VAR="LIBDIR_${ABI}"
431 if [ -n "${ABI}" -a -n "${!LIBDIR_VAR}" ]; then
432 CONF_LIBDIR="${!LIBDIR_VAR}"
435 if [ -n "${CONF_LIBDIR}" ] && [ "${*/--libdir}" == "$*" ]; then
436 if [ "${*/--exec-prefix}" != "$*" ]; then
437 local args="$(echo $*)"
438 local -a pref=($(echo ${args/*--exec-prefix[= ]}))
440 [ "${CONF_PREFIX:0:1}" != "/" ] && CONF_PREFIX="/${CONF_PREFIX}"
441 elif [ "${*/--prefix}" != "$*" ]; then
442 local args="$(echo $*)"
443 local -a pref=($(echo ${args/*--prefix[= ]}))
445 [ "${CONF_PREFIX:0:1}" != "/" ] && CONF_PREFIX="/${CONF_PREFIX}"
450 [ "${CONF_LIBDIR:0:1}" != "/" ] && CONF_LIBDIR="/${CONF_LIBDIR}"
452 CONF_LIBDIR_RESULT="$(strip_duplicate_slashes ${CONF_PREFIX}${CONF_LIBDIR})"
454 LOCAL_EXTRA_ECONF="--libdir=${CONF_LIBDIR_RESULT} ${LOCAL_EXTRA_ECONF}"
457 local TMP_CONFCACHE_DIR CONFCACHE_ARG
458 if hasq confcache $FEATURES && ! hasq confcache $RESTRICT; then
459 CONFCACHE="$(type -P confcache)"
460 if [ -z "${CONFCACHE}" ]; then
461 ewarn "disabling confcache, binary cannot be found"
463 CONFCACHE="${CONFCACHE/ /\ }"
464 TMP_CONFCACHE_DIR="${CONFCACHE:+${CONFCACHE_DIR:-${PORTAGE_TMPDIR}/confcache}}"
465 TMP_CONFCACHE_DIR="${TMP_CONFCACHE_DIR/ /\ }"
466 CONFCACHE_ARG="--confcache-dir"
468 if [ -n "$CCACHE_DIR" ]; then
471 if [ -n "$DISTCC_DIR" ]; then
472 s="${s:+${s}:}$DISTCC_DIR"
475 CONFCACHE_ARG="--confcache-ignore $s $CONFCACHE_ARG"
482 vecho ${CONFCACHE} ${CONFCACHE_ARG} ${TMP_CONFCACHE_DIR} "${ECONF_SOURCE}/configure" \
485 --mandir=/usr/share/man \
486 --infodir=/usr/share/info \
487 --datadir=/usr/share \
489 --localstatedir=/var/lib \
493 if ! ${CONFCACHE} ${CONFCACHE_ARG} ${TMP_CONFCACHE_DIR} "${ECONF_SOURCE}/configure" \
496 --mandir=/usr/share/man \
497 --infodir=/usr/share/info \
498 --datadir=/usr/share \
500 --localstatedir=/var/lib \
502 ${LOCAL_EXTRA_ECONF}; then
504 if [ -s config.log ]; then
506 echo "!!! Please attach the following file when seeking support:"
507 echo "!!! ${PWD}/config.log"
511 elif [ -f "${ECONF_SOURCE:-.}/configure" ]; then
512 die "configure is not executable"
514 die "no configure script found"
519 # CONF_PREFIX is only set if they didn't pass in libdir above.
520 local LOCAL_EXTRA_EINSTALL="${EXTRA_EINSTALL}"
521 LIBDIR_VAR="LIBDIR_${ABI}"
522 if [ -n "${ABI}" -a -n "${!LIBDIR_VAR}" ]; then
523 CONF_LIBDIR="${!LIBDIR_VAR}"
526 if [ -n "${CONF_LIBDIR}" ] && [ "${CONF_PREFIX:-unset}" != "unset" ]; then
527 EI_DESTLIBDIR="${D}/${CONF_PREFIX}/${CONF_LIBDIR}"
528 EI_DESTLIBDIR="$(strip_duplicate_slashes ${EI_DESTLIBDIR})"
529 LOCAL_EXTRA_EINSTALL="libdir=${EI_DESTLIBDIR} ${LOCAL_EXTRA_EINSTALL}"
533 if [ -f ./[mM]akefile -o -f ./GNUmakefile ] ; then
534 if [ "${PORTAGE_DEBUG}" == "1" ]; then
535 ${MAKE:-make} -n prefix="${D}usr" \
536 datadir="${D}usr/share" \
537 infodir="${D}usr/share/info" \
538 localstatedir="${D}var/lib" \
539 mandir="${D}usr/share/man" \
540 sysconfdir="${D}etc" \
541 ${LOCAL_EXTRA_EINSTALL} \
544 ${MAKE:-make} prefix="${D}usr" \
545 datadir="${D}usr/share" \
546 infodir="${D}usr/share/info" \
547 localstatedir="${D}var/lib" \
548 mandir="${D}usr/share/man" \
549 sysconfdir="${D}etc" \
550 ${LOCAL_EXTRA_EINSTALL} \
551 "$@" install || die "einstall failed"
553 die "no Makefile found"
558 [ -z "${SRC_URI}" ] && return
560 echo "!!! The following are listed in SRC_URI for ${PN}:"
562 for x in $(echo ${SRC_URI}); do
568 [[ -n ${A} ]] && unpack ${A}
572 if [ "${EAPI:-0}" == 0 ] ; then
573 [ -x ./configure ] && econf
574 elif [ -x "${ECONF_SOURCE:-.}/configure" ] ; then
577 if [ -f Makefile ] || [ -f GNUmakefile ] || [ -f makefile ]; then
578 emake || die "emake failed"
583 if emake -j1 check -n &> /dev/null; then
584 vecho ">>> Test phase [check]: ${CATEGORY}/${PF}"
585 if ! emake -j1 check; then
586 hasq test $FEATURES && die "Make check failed. See above for details."
587 hasq test $FEATURES || eerror "Make check failed. See above for details."
589 elif emake -j1 test -n &> /dev/null; then
590 vecho ">>> Test phase [test]: ${CATEGORY}/${PF}"
591 if ! emake -j1 test; then
592 hasq test $FEATURES && die "Make test failed. See above for details."
593 hasq test $FEATURES || eerror "Make test failed. See above for details."
596 vecho ">>> Test phase [none]: ${CATEGORY}/${PF}"
600 # Used to generate the /lib/cpp and /usr/bin/cc wrappers
610 [ "$(type -t ${1})" == "function" ] && qa_call ${1}
613 ebuild_phase_with_hooks() {
614 local x phase_name=${1}
615 for x in {pre_,,post_}${phase_name} ; do
621 ebuild_phase_with_hooks pkg_setup
625 [ "$(type -t pre_src_unpack)" == "function" ] && qa_call pre_src_unpack
627 if [ -e "${WORKDIR}" ]; then
631 vecho ">>> Checking ${x}'s mtime..."
632 if [ "${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/${x}" -nt "${WORKDIR}" ]; then
633 vecho ">>> ${x} has been updated; recreating WORKDIR..."
638 if [ "${EBUILD}" -nt "${WORKDIR}" ] && ! hasq keepwork ${FEATURES} ; then
639 vecho ">>> ${EBUILD} has been updated; recreating WORKDIR..."
641 elif [ ! -f "${PORTAGE_BUILDDIR}/.unpacked" ]; then
642 vecho ">>> Not marked as unpacked; recreating WORKDIR..."
646 if [ "${newstuff}" == "yes" ]; then
647 # We don't necessarily have privileges to do a full dyn_clean here.
649 if [ -d "${T}" ] && ! hasq keeptemp ${FEATURES} ; then
650 rm -rf "${T}" && mkdir "${T}"
652 [ -e "${T}/environment" ] && \
653 mv "${T}/environment" "${T}/environment.keeptemp"
656 if [ -e "${WORKDIR}" ]; then
657 if [ "$newstuff" == "no" ]; then
658 vecho ">>> WORKDIR is up-to-date, keeping..."
659 [ "$(type -t post_src_unpack)" == "function" ] && qa_call post_src_unpack
664 if [ ! -d "${WORKDIR}" ]; then
665 install -m${PORTAGE_WORKDIR_MODE:-0700} -d "${WORKDIR}" || die "Failed to create dir '${WORKDIR}'"
667 cd "${WORKDIR}" || die "Directory change failed: \`cd '${WORKDIR}'\`"
668 vecho ">>> Unpacking source..."
669 ebuild_phase src_unpack
670 touch "${PORTAGE_BUILDDIR}/.unpacked" || die "IO Failure -- Failed 'touch .unpacked' in ${PORTAGE_BUILDDIR}"
671 vecho ">>> Source unpacked."
672 cd "${PORTAGE_BUILDDIR}"
674 [ "$(type -t post_src_unpack)" == "function" ] && qa_call post_src_unpack
678 if [ -z "${PORTAGE_BUILDDIR}" ]; then
679 echo "Aborting clean phase because PORTAGE_BUILDDIR is unset!"
681 elif [ ! -d "${PORTAGE_BUILDDIR}" ] ; then
684 if type -P chflags > /dev/null ; then
685 chflags -R noschg,nouchg,nosappnd,nouappnd "${PORTAGE_BUILDDIR}"
686 chflags -R nosunlnk,nouunlnk "${PORTAGE_BUILDDIR}" 2>/dev/null
689 rm -rf "${PORTAGE_BUILDDIR}/image" "${PORTAGE_BUILDDIR}/homedir"
691 if ! hasq keeptemp $FEATURES; then
694 [ -e "${T}/environment" ] && mv "${T}/environment" "${T}/environment.keeptemp"
697 if ! hasq keepwork $FEATURES; then
698 rm -rf "${PORTAGE_BUILDDIR}/.exit_status"
699 rm -rf "${PORTAGE_BUILDDIR}/.logid"
700 rm -rf "${PORTAGE_BUILDDIR}/.unpacked"
701 rm -rf "${PORTAGE_BUILDDIR}/.compiled"
702 rm -rf "${PORTAGE_BUILDDIR}/.tested"
703 rm -rf "${PORTAGE_BUILDDIR}/.installed"
704 rm -rf "${PORTAGE_BUILDDIR}/.packaged"
705 rm -rf "${PORTAGE_BUILDDIR}/build-info"
709 if [ -f "${PORTAGE_BUILDDIR}/.unpacked" ]; then
710 find "${PORTAGE_BUILDDIR}" -type d ! -regex "^${WORKDIR}" | sort -r | tr "\n" "\0" | $XARGS -0 rmdir &>/dev/null
713 # do not bind this to doebuild defined DISTDIR; don't trust doebuild, and if mistakes are made it'll
714 # result in it wiping the users distfiles directory (bad).
715 rm -rf "${PORTAGE_BUILDDIR}/distdir"
717 if [ -z "$(find "${PORTAGE_BUILDDIR}" -mindepth 1 -maxdepth 1)" ]; then
718 rmdir "${PORTAGE_BUILDDIR}"
725 if [ "$1" == "/" ]; then
729 if [ ! -d "${D}${DESTTREE}" ]; then
730 install -d "${D}${DESTTREE}"
736 if [ "$1" == "/" ]; then
737 export INSDESTTREE=""
739 export INSDESTTREE=$1
740 if [ ! -d "${D}${INSDESTTREE}" ]; then
741 install -d "${D}${INSDESTTREE}"
747 if [ "$1" == "/" ]; then
748 export _E_EXEDESTTREE_=""
750 export _E_EXEDESTTREE_="$1"
751 if [ ! -d "${D}${_E_EXEDESTTREE_}" ]; then
752 install -d "${D}${_E_EXEDESTTREE_}"
758 if [ "$1" == "/" ]; then
759 export _E_DOCDESTTREE_=""
761 export _E_DOCDESTTREE_="$1"
762 if [ ! -d "${D}usr/share/doc/${PF}/${_E_DOCDESTTREE_}" ]; then
763 install -d "${D}usr/share/doc/${PF}/${_E_DOCDESTTREE_}"
769 export INSOPTIONS="$@"
771 # `install` should never be called with '-s' ...
772 hasq -s ${INSOPTIONS} && die "Never call insopts() with -s"
776 export DIROPTIONS="$@"
780 export EXEOPTIONS="$@"
782 # `install` should never be called with '-s' ...
783 hasq -s ${EXEOPTIONS} && die "Never call exeopts() with -s"
787 export LIBOPTIONS="$@"
789 # `install` should never be called with '-s' ...
790 hasq -s ${LIBOPTIONS} && die "Never call libopts() with -s"
795 if [ "$2" != "fail" ]; then
796 msg="${EBUILD}: ${1} aborted; exiting."
798 msg="${EBUILD}: ${1} failed; exiting."
804 #unset signal handler
809 abort_handler "src_compile" $1
810 rm -f "${PORTAGE_BUILDDIR}/.compiled"
815 abort_handler "dyn_test" $1
816 rm -f "${PORTAGE_BUILDDIR}/.tested"
821 abort_handler "src_install" $1
822 rm -rf "${PORTAGE_BUILDDIR}/image"
827 trap "abort_compile" SIGINT SIGQUIT
829 [ "$(type -t pre_src_compile)" == "function" ] && qa_call pre_src_compile
831 [ "${CFLAGS-unset}" != "unset" ] && export CFLAGS
832 [ "${CXXFLAGS-unset}" != "unset" ] && export CXXFLAGS
833 [ "${LIBCFLAGS-unset}" != "unset" ] && export LIBCFLAGS
834 [ "${LIBCXXFLAGS-unset}" != "unset" ] && export LIBCXXFLAGS
835 [ "${LDFLAGS-unset}" != "unset" ] && export LDFLAGS
836 [ "${ASFLAGS-unset}" != "unset" ] && export ASFLAGS
838 [ "${CCACHE_DIR-unset}" != "unset" ] && export CCACHE_DIR
839 [ "${CCACHE_SIZE-unset}" != "unset" ] && export CCACHE_SIZE
841 [ "${DISTCC_DIR-unset}" == "unset" ] && export DISTCC_DIR="${PORTAGE_TMPDIR}/.distcc"
842 [ ! -z "${DISTCC_DIR}" ] && addwrite "${DISTCC_DIR}"
844 LIBDIR_VAR="LIBDIR_${ABI}"
845 if [ -z "${PKG_CONFIG_PATH}" -a -n "${ABI}" -a -n "${!LIBDIR_VAR}" ]; then
846 export PKG_CONFIG_PATH="/usr/${!LIBDIR_VAR}/pkgconfig"
850 if hasq noauto $FEATURES && [ ! -f ${PORTAGE_BUILDDIR}/.unpacked ]; then
852 echo "!!! We apparently haven't unpacked... This is probably not what you"
853 echo "!!! want to be doing... You are using FEATURES=noauto so I'll assume"
854 echo "!!! that you know what you are doing... You have 5 seconds to abort..."
858 for x in 1 2 3 4 5 6 7 8; do
866 local srcdir=${PORTAGE_BUILDDIR}
867 cd "${PORTAGE_BUILDDIR}"
868 if [ ! -e "build-info" ]; then
871 cp "${EBUILD}" "build-info/${PF}.ebuild"
873 if [[ ${PORTAGE_BUILDDIR}/.compiled -nt ${WORKDIR} ]] ; then
874 vecho ">>> It appears that '${PF}' is already compiled; skipping."
875 vecho ">>> Remove '${PORTAGE_BUILDDIR}/.compiled' to force compilation."
877 [ "$(type -t post_src_compile)" == "function" ] && qa_call post_src_compile
880 if [ -d "${S}" ]; then
886 #our custom version of libtool uses $S and $D to fix
887 #invalid paths in .la files
889 #some packages use an alternative to $S to build in, cause
890 #our libtool to create problematic .la files
891 export PWORKDIR="$WORKDIR"
892 vecho ">>> Compiling source in ${srcdir} ..."
893 ebuild_phase src_compile
894 vecho ">>> Source compiled."
895 #|| abort_compile "fail"
896 cd "${PORTAGE_BUILDDIR}"
898 [ "$(type -t post_src_compile)" == "function" ] && qa_call post_src_compile
904 if [ "${EBUILD_FORCE_TEST}" == "1" ] ; then
905 rm -f "${PORTAGE_BUILDDIR}/.tested"
906 # If USE came from ${T}/environment then it might not have USE=test
907 # like it's supposed to here.
908 ! hasq test ${USE} && export USE="${USE} test"
910 [ "$(type -t pre_src_test)" == "function" ] && qa_call pre_src_test
911 if [ "${PORTAGE_BUILDDIR}/.tested" -nt "${WORKDIR}" ]; then
912 vecho ">>> It appears that ${PN} has already been tested; skipping."
913 [ "$(type -t post_src_test)" == "function" ] && qa_call post_src_test
916 trap "abort_test" SIGINT SIGQUIT
917 if [ -d "${S}" ]; then
922 if ! hasq test $FEATURES && [ "${EBUILD_FORCE_TEST}" != "1" ]; then
923 vecho ">>> Test phase [not enabled]: ${CATEGORY}/${PF}"
924 elif hasq test $RESTRICT; then
925 ewarn "Skipping make test/check due to ebuild restriction."
926 vecho ">>> Test phase [explicitly disabled]: ${CATEGORY}/${PF}"
929 ebuild_phase src_test
930 SANDBOX_PREDICT="${SANDBOX_PREDICT%:/}"
933 cd "${PORTAGE_BUILDDIR}"
934 touch .tested || die "Failed to 'touch .tested' in ${PORTAGE_BUILDDIR}"
935 [ "$(type -t post_src_test)" == "function" ] && qa_call post_src_test
940 [ -z "$PORTAGE_BUILDDIR" ] && die "${FUNCNAME}: PORTAGE_BUILDDIR is unset"
941 if hasq noauto $FEATURES ; then
942 rm -f "${PORTAGE_BUILDDIR}/.installed"
943 elif [[ ${PORTAGE_BUILDDIR}/.installed -nt ${WORKDIR} ]] ; then
944 vecho ">>> It appears that '${PF}' is already installed; skipping."
945 vecho ">>> Remove '${PORTAGE_BUILDDIR}/.installed' to force install."
948 trap "abort_install" SIGINT SIGQUIT
949 [ "$(type -t pre_src_install)" == "function" ] && qa_call pre_src_install
950 rm -rf "${PORTAGE_BUILDDIR}/image"
951 mkdir "${PORTAGE_BUILDDIR}/image"
952 if [ -d "${S}" ]; then
958 vecho ">>> Install ${PF} into ${D} category ${CATEGORY}"
959 #our custom version of libtool uses $S and $D to fix
960 #invalid paths in .la files
962 #some packages uses an alternative to $S to build in, cause
963 #our libtool to create problematic .la files
964 export PWORKDIR="$WORKDIR"
966 # Reset exeinto(), docinto(), insinto(), and into() state variables
967 # in case the user is running the install phase multiple times
968 # consecutively via the ebuild command.
970 export INSDESTTREE=""
971 export _E_EXEDESTTREE_=""
972 export _E_DOCDESTTREE_=""
974 ebuild_phase src_install
975 touch "${PORTAGE_BUILDDIR}/.installed"
976 vecho ">>> Completed installing ${PF} into ${D}"
978 cd ${PORTAGE_BUILDDIR}
979 [ "$(type -t post_src_install)" == "function" ] && qa_call post_src_install
981 cd "${PORTAGE_BUILDDIR}"/build-info
984 for f in ASFLAGS CATEGORY CBUILD CC CFLAGS CHOST CTARGET CXX \
985 CXXFLAGS DEPEND EXTRA_ECONF EXTRA_EINSTALL EXTRA_MAKE \
986 FEATURES INHERITED IUSE LDFLAGS LIBCFLAGS LIBCXXFLAGS \
987 LICENSE PDEPEND PF PKGUSE PROVIDE RDEPEND RESTRICT SLOT \
988 KEYWORDS HOMEPAGE SRC_URI DESCRIPTION; do
989 [ -n "${!f}" ] && echo $(echo "${!f}" | \
990 tr '\n,\r,\t' ' , , ' | sed s/' \+'/' '/g) > ${f}
993 echo "${EAPI:-0}" > EAPI
996 # local variables can leak into the saved environment.
1000 # To avoid environment.bz2 bloat, cleanse variables that are
1001 # are no longer needed after src_install(). Don't cleanse from
1002 # the global environment though, in case the user wants to repeat
1003 # this phase (like with FEATURES=noauto and the ebuild command).
1004 unset S _E_DOCDESTTREE_ _E_EXEDESTTREE_
1005 save_ebuild_env | filter_readonly_variables \
1006 --filter-sandbox --allow-extra-vars > environment
1008 bzip2 -f9 environment
1010 cp "${EBUILD}" "${PF}.ebuild"
1011 [ -n "${PORTAGE_REPO_NAME}" ] && echo "${PORTAGE_REPO_NAME}" > repository
1012 if hasq nostrip ${FEATURES} ${RESTRICT} || hasq strip ${RESTRICT}
1020 if [ -z "${D}" ]; then
1021 eerror "${FUNCNAME}: D is unset"
1024 ebuild_phase_with_hooks pkg_preinst
1030 echo "Copyright 1999-2006 Gentoo Foundation"
1032 echo "How to use the ebuild command:"
1034 echo "The first argument to ebuild should be an existing .ebuild file."
1036 echo "One or more of the following options can then be specified. If more"
1037 echo "than one option is specified, each will be executed in order."
1039 echo " help : show this help screen"
1040 echo " setup : execute package specific setup actions"
1041 echo " fetch : download source archive(s) and patches"
1042 echo " digest : create a digest and a manifest file for the package"
1043 echo " manifest : create a manifest file for the package"
1044 echo " unpack : unpack/patch sources (auto-fetch if needed)"
1045 echo " compile : compile sources (auto-fetch/unpack if needed)"
1046 echo " test : test package (auto-fetch/unpack/compile if needed)"
1047 echo " preinst : execute pre-install instructions"
1048 echo " postinst : execute post-install instructions"
1049 echo " install : install the package to the temporary install directory"
1050 echo " qmerge : merge image into live filesystem, recording files in db"
1051 echo " merge : do fetch, unpack, compile, install and qmerge"
1052 echo " prerm : execute pre-removal instructions"
1053 echo " postrm : execute post-removal instructions"
1054 echo " unmerge : remove package from live filesystem"
1055 echo " config : execute package specific configuration actions"
1056 echo " package : create a tarball package in ${PKGDIR}/All"
1057 echo " rpm : build a RedHat RPM package"
1058 echo " clean : clean up all source and temporary files"
1060 echo "The following settings will be used for the ebuild process:"
1062 echo " package : ${PF}"
1063 echo " slot : ${SLOT}"
1064 echo " category : ${CATEGORY}"
1065 echo " description : ${DESCRIPTION}"
1066 echo " system : ${CHOST}"
1067 echo " c flags : ${CFLAGS}"
1068 echo " c++ flags : ${CXXFLAGS}"
1069 echo " make flags : ${MAKEOPTS}"
1070 echo -n " build mode : "
1071 if hasq nostrip ${FEATURES} ${RESTRICT} || hasq strip ${RESTRICT} ;
1073 echo "debug (large)"
1075 echo "production (stripped)"
1077 echo " merge to : ${ROOT}"
1079 if [ -n "$USE" ]; then
1080 echo "Additionally, support for the following optional features will be enabled:"
1087 # debug-print() gets called from many places with verbose status information useful
1088 # for tracking down problems. The output is in $T/eclass-debug.log.
1089 # You can set ECLASS_DEBUG_OUTPUT to redirect the output somewhere else as well.
1090 # The special "on" setting echoes the information, mixing it with the rest of the
1092 # You can override the setting by exporting a new one from the console, or you can
1093 # set a new default in make.*. Here the default is "" or unset.
1095 # in the future might use e* from /etc/init.d/functions.sh if i feel like it
1097 # if $T isn't defined, we're in dep calculation mode and
1098 # shouldn't do anything
1099 [ ! -d "$T" ] && return 0
1103 # extra user-configurable targets
1104 if [ "$ECLASS_DEBUG_OUTPUT" == "on" ]; then
1106 elif [ -n "$ECLASS_DEBUG_OUTPUT" ]; then
1107 echo "debug: $1" >> $ECLASS_DEBUG_OUTPUT
1111 echo "$1" 2>/dev/null >> "${T}/eclass-debug.log"
1112 # let the portage user own/write to this file
1113 chmod g+w "${T}/eclass-debug.log" &>/dev/null
1119 # The following 2 functions are debug-print() wrappers
1121 debug-print-function() {
1122 str="$1: entering function"
1124 debug-print "$str, parameters: $*"
1127 debug-print-section() {
1128 debug-print "now in section $*"
1131 # Sources all eclasses in parameters
1132 declare -ix ECLASS_DEPTH=0
1134 ECLASS_DEPTH=$(($ECLASS_DEPTH + 1))
1135 if [[ ${ECLASS_DEPTH} > 1 ]]; then
1136 debug-print "*** Multiple Inheritence (Level: ${ECLASS_DEPTH})"
1148 location="${ECLASSDIR}/${1}.eclass"
1151 # PECLASS is used to restore the ECLASS var after recursion.
1155 if [ "${EBUILD_PHASE}" != "depend" ] && \
1156 [[ ${EBUILD_PHASE} != *rm ]] && \
1157 [[ ${EMERGE_FROM} != "binary" ]] ; then
1158 # This is disabled in the *rm phases because they frequently give
1159 # false alarms due to INHERITED in /var/db/pkg being outdated
1160 # in comparison the the eclasses from the portage tree.
1161 if ! hasq $ECLASS $INHERITED; then
1162 eqawarn "QA Notice: ECLASS '$ECLASS' inherited illegally in $CATEGORY/$PF"
1166 # any future resolution code goes here
1167 if [ -n "$PORTDIR_OVERLAY" ]; then
1169 for overlay in ${PORTDIR_OVERLAY}; do
1170 olocation="${overlay}/eclass/${1}.eclass"
1171 if [ -e "$olocation" ]; then
1172 location="${olocation}"
1173 debug-print " eclass exists: ${location}"
1177 debug-print "inherit: $1 -> $location"
1178 [ ! -e "$location" ] && die "${1}.eclass could not be found by inherit()"
1180 if [ "${location}" == "${olocation}" ] && \
1181 ! hasq "${location}" ${EBUILD_OVERLAY_ECLASSES} ; then
1182 EBUILD_OVERLAY_ECLASSES="${EBUILD_OVERLAY_ECLASSES} ${location}"
1185 #We need to back up the value of DEPEND and RDEPEND to B_DEPEND and B_RDEPEND
1186 #(if set).. and then restore them after the inherit call.
1188 #turn off glob expansion
1191 # Retain the old data and restore it later.
1192 unset B_IUSE B_DEPEND B_RDEPEND B_PDEPEND
1193 [ "${IUSE-unset}" != "unset" ] && B_IUSE="${IUSE}"
1194 [ "${DEPEND-unset}" != "unset" ] && B_DEPEND="${DEPEND}"
1195 [ "${RDEPEND-unset}" != "unset" ] && B_RDEPEND="${RDEPEND}"
1196 [ "${PDEPEND-unset}" != "unset" ] && B_PDEPEND="${PDEPEND}"
1197 unset IUSE DEPEND RDEPEND PDEPEND
1198 #turn on glob expansion
1201 qa_source "$location" || die "died sourcing $location in inherit()"
1203 #turn off glob expansion
1206 # If each var has a value, append it to the global variable E_* to
1207 # be applied after everything is finished. New incremental behavior.
1208 [ "${IUSE-unset}" != "unset" ] && export E_IUSE="${E_IUSE} ${IUSE}"
1209 [ "${DEPEND-unset}" != "unset" ] && export E_DEPEND="${E_DEPEND} ${DEPEND}"
1210 [ "${RDEPEND-unset}" != "unset" ] && export E_RDEPEND="${E_RDEPEND} ${RDEPEND}"
1211 [ "${PDEPEND-unset}" != "unset" ] && export E_PDEPEND="${E_PDEPEND} ${PDEPEND}"
1213 [ "${B_IUSE-unset}" != "unset" ] && IUSE="${B_IUSE}"
1214 [ "${B_IUSE-unset}" != "unset" ] || unset IUSE
1216 [ "${B_DEPEND-unset}" != "unset" ] && DEPEND="${B_DEPEND}"
1217 [ "${B_DEPEND-unset}" != "unset" ] || unset DEPEND
1219 [ "${B_RDEPEND-unset}" != "unset" ] && RDEPEND="${B_RDEPEND}"
1220 [ "${B_RDEPEND-unset}" != "unset" ] || unset RDEPEND
1222 [ "${B_PDEPEND-unset}" != "unset" ] && PDEPEND="${B_PDEPEND}"
1223 [ "${B_PDEPEND-unset}" != "unset" ] || unset PDEPEND
1225 #turn on glob expansion
1228 hasq $1 $INHERITED || export INHERITED="$INHERITED $1"
1230 export ECLASS="$PECLASS"
1234 ((--ECLASS_DEPTH)) # Returns 1 when ECLASS_DEPTH reaches 0.
1238 # Exports stub functions that call the eclass's functions, thereby making them default.
1239 # For example, if ECLASS="base" and you call "EXPORT_FUNCTIONS src_unpack", the following
1240 # code will be eval'd:
1241 # src_unpack() { base_src_unpack; }
1242 EXPORT_FUNCTIONS() {
1243 if [ -z "$ECLASS" ]; then
1244 echo "EXPORT_FUNCTIONS without a defined ECLASS" >&2
1248 debug-print "EXPORT_FUNCTIONS: ${1} -> ${ECLASS}_${1}"
1249 eval "$1() { ${ECLASS}_$1 "\$@" ; }" > /dev/null
1254 # adds all parameters to E_DEPEND and E_RDEPEND, which get added to DEPEND
1255 # and RDEPEND after the ebuild has been processed. This is important to
1256 # allow users to use DEPEND="foo" without frying dependencies added by an
1257 # earlier inherit. It also allows RDEPEND to work properly, since a lot
1258 # of ebuilds assume that an unset RDEPEND gets its value from DEPEND.
1259 # Without eclasses, this is true. But with them, the eclass may set
1260 # RDEPEND itself (or at least used to) which would prevent RDEPEND from
1261 # getting its value from DEPEND. This is a side-effect that made eclasses
1262 # have unreliable dependencies.
1265 debug-print-function newdepend $*
1266 debug-print "newdepend: E_DEPEND=$E_DEPEND E_RDEPEND=$E_RDEPEND"
1268 while [ -n "$1" ]; do
1271 do_newdepend DEPEND sys-devel/autoconf sys-devel/automake sys-devel/make
1274 do_newdepend DEPEND sys-devel/gcc virtual/libc
1275 do_newdepend RDEPEND virtual/libc
1278 do_newdepend DEPEND $1
1286 debug-print-function newrdepend $*
1287 do_newdepend RDEPEND $1
1291 debug-print-function newpdepend $*
1292 do_newdepend PDEPEND $1
1296 # This function does a generic change determining whether we're in an
1297 # eclass or not. If we are, we change the E_* variables for deps.
1298 debug-print-function do_newdepend $*
1299 [ -z "$1" ] && die "do_newdepend without arguments"
1301 # Grab what we're affecting... Figure out if we're affecting eclasses.
1302 [[ ${ECLASS_DEPTH} > 0 ]] && TARGET="E_$1"
1303 [[ ${ECLASS_DEPTH} > 0 ]] || TARGET="$1"
1304 shift # $1 was a variable name.
1306 while [ -n "$1" ]; do
1307 # This bit of evil takes TARGET and uses it to evaluate down to a
1308 # variable. This is a sneaky way to make this infinately expandable.
1309 # The normal translation of this would look something like this:
1310 # E_DEPEND="${E_DEPEND} $1" :::::: Cool, huh? :)
1311 eval export ${TARGET}=\"\${${TARGET}} \$1\"
1316 # this is a function for removing any directory matching a passed in pattern from
1318 remove_path_entry() {
1321 stripped_path="${PATH}"
1322 while [ -n "$1" ]; do
1324 for p in ${stripped_path}; do
1325 if [ "${p/${1}}" == "${p}" ]; then
1326 cur_path="${cur_path}:${p}"
1329 stripped_path="${cur_path#:*}"
1333 PATH="${stripped_path}"
1336 source_all_bashrcs() {
1337 local OCC="${CC}" OCXX="${CXX}"
1338 # source the existing profile.bashrc's.
1342 for x in ${PROFILE_PATHS}; do
1343 # Must unset it so that it doesn't mess up assumptions in the RCs.
1345 [ -f "${x}/profile.bashrc" ] && qa_source "${x}/profile.bashrc"
1349 # We assume if people are changing shopts in their bashrc they do so at their
1350 # own peril. This is the ONLY non-portage bit of code that can change shopts
1351 # without a QA violation.
1352 if [ -f "${PORTAGE_BASHRC}" ]; then
1353 # If $- contains x, then tracing has already enabled elsewhere for some
1354 # reason. We preserve it's state so as not to interfere.
1355 if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then
1356 source "${PORTAGE_BASHRC}"
1359 source "${PORTAGE_BASHRC}"
1363 [ ! -z "${OCC}" ] && export CC="${OCC}"
1364 [ ! -z "${OCXX}" ] && export CXX="${OCXX}"
1367 # Hardcoded bash lists are needed for backward compatibility with
1368 # <portage-2.1.4 since they assume that a newly installed version
1369 # of ebuild.sh will work for pkg_postinst, pkg_prerm, and pkg_postrm
1370 # when portage is upgrading itself.
1372 READONLY_EBUILD_METADATA="DEPEND DESCRIPTION
1373 EAPI HOMEPAGE INHERITED IUSE KEYWORDS LICENSE
1374 PDEPEND PROVIDE RDEPEND RESTRICT SLOT SRC_URI"
1376 READONLY_PORTAGE_VARS="D EBUILD EBUILD_PHASE \
1377 EBUILD_SH_ARGS EMERGE_FROM FILESDIR PORTAGE_BINPKG_FILE \
1378 PORTAGE_BIN_PATH PORTAGE_IUSE \
1379 PORTAGE_PYM_PATH PORTAGE_MUTABLE_FILTERED_VARS \
1380 PORTAGE_SAVED_READONLY_VARS PORTAGE_TMPDIR T WORKDIR"
1382 PORTAGE_SAVED_READONLY_VARS="A CATEGORY P PF PN PR PV PVR"
1384 # Variables that portage sets but doesn't mark readonly.
1385 # In order to prevent changed values from causing unexpected
1386 # interference, they are filtered out of the environment when
1387 # it is saved or loaded (any mutations do not persist).
1388 PORTAGE_MUTABLE_FILTERED_VARS="AA HOSTNAME"
1390 # @FUNCTION: filter_readonly_variables
1391 # @DESCRIPTION: [--filter-sandbox] [--allow-extra-vars]
1392 # Read an environment from stdin and echo to stdout while filtering variables
1393 # with names that are known to cause interference:
1395 # * some specific variables for which bash does not allow assignment
1396 # * some specific variables that affect portage or sandbox behavior
1397 # * variable names that begin with a digit or that contain any
1398 # non-alphanumeric characters that are not be supported by bash
1400 # --filter-sandbox causes all SANDBOX_* variables to be filtered, which
1401 # is only desired in certain cases, such as during preprocessing or when
1402 # saving environment.bz2 for a binary or installed package.
1404 # --filter-features causes the special FEATURES variable to be filtered.
1405 # Generally, we want it to persist between phases since the user might
1406 # want to modify it via bashrc to enable things like splitdebug and
1407 # installsources for specific packages. They should be able to modify it
1408 # in pre_pkg_setup() and have it persist all the way through the install
1409 # phase. However, if FEATURES exist inside environment.bz2 then they
1410 # should be overridden by current settings.
1412 # ---allow-extra-vars causes some extra vars to be allowd through, such
1413 # as ${PORTAGE_SAVED_READONLY_VARS} and ${PORTAGE_MUTABLE_FILTERED_VARS}.
1415 # In bash-3.2_p20+ an attempt to assign BASH_*, FUNCNAME, GROUPS or any
1416 # readonly variable cause the shell to exit while executing the "source"
1417 # builtin command. To avoid this problem, this function filters those
1418 # variables out and discards them. See bug #190128.
1419 filter_readonly_variables() {
1420 local x filtered_vars
1421 local readonly_bash_vars="DIRSTACK EUID FUNCNAME GROUPS
1422 PIPESTATUS PPID SHELLOPTS UID"
1423 local filtered_sandbox_vars="SANDBOX_ACTIVE SANDBOX_BASHRC
1424 SANDBOX_DEBUG_LOG SANDBOX_DISABLED SANDBOX_LIB
1425 SANDBOX_LOG SANDBOX_ON"
1426 filtered_vars="${readonly_bash_vars} ${READONLY_PORTAGE_VARS}
1427 BASH_[_[:alnum:]]* PATH
1428 [[:digit:]][_[:alnum:]]*
1430 # TODO: Take the above variable name validation and the below sed-based
1431 # declare -r filter and integrate them both directly into
1432 # filter-bash-environment.py.
1433 if hasq --filter-sandbox $* ; then
1434 filtered_vars="${filtered_vars} SANDBOX_[_[:alnum:]]*"
1436 filtered_vars="${filtered_vars} ${filtered_sandbox_vars}"
1438 if hasq --filter-features $* ; then
1439 filtered_vars="${filtered_vars} FEATURES"
1441 if ! hasq --allow-extra-vars $* ; then
1444 ${PORTAGE_SAVED_READONLY_VARS}
1445 ${PORTAGE_MUTABLE_FILTERED_VARS}
1449 # The sed is to remove the readonly attribute from variables such as those
1450 # listed in READONLY_EBUILD_METADATA, since having any readonly attributes
1451 # persisting in the saved environment can be inconvenient when it
1452 # eventually needs to be reloaded.
1453 "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}" | sed -r \
1454 -e 's:^declare[[:space:]]+-r[[:space:]]+:declare :' \
1455 -e 's:^declare[[:space:]]+-([[:alnum:]]*)r([[:alnum:]]*)[[:space:]]+:declare -\1\2 :'
1458 # @FUNCTION: preprocess_ebuild_env
1460 # Filter any readonly variables from ${T}/environment, source it, and then
1461 # save it via save_ebuild_env(). This process should be sufficient to prevent
1462 # any stale variables or functions from an arbitrary environment from
1463 # interfering with the current environment. This is useful when an existing
1464 # environment needs to be loaded from a binary or installed package.
1465 preprocess_ebuild_env() {
1466 local filter_opts=""
1467 if [ -f "${T}/environment.raw" ] ; then
1468 # This is a signal from the python side, indicating that the
1469 # environment may contain stale SANDBOX_{DENY,PREDICT,READ,WRITE}
1470 # and FEATURES variables that should be filtered out. Between
1471 # phases, these variables are normally preserved.
1472 filter_opts="--filter-sandbox --filter-features ${filter_opts}"
1474 filter_readonly_variables ${filter_opts} < "${T}"/environment \
1475 > "${T}"/environment.filtered || return $?
1477 mv "${T}"/environment.filtered "${T}"/environment || return $?
1478 rm -f "${T}/environment.success" || return $?
1479 # WARNING: Code inside this subshell should avoid making assumptions
1480 # about variables or functions after source "${T}"/environment has been
1481 # called. Any variables that need to be relied upon should already be
1482 # filtered out above.
1485 source "${T}/environment" || exit $?
1486 # We have to temporarily disable sandbox since the
1487 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
1488 # may be unusable (triggering in spurious sandbox violations)
1489 # until we've merged them with our current values.
1492 # It's remotely possible that save_ebuild_env() has been overridden
1493 # by the above source command. To protect ourselves, we override it
1494 # here with our own version. ${PORTAGE_BIN_PATH} is safe to use here
1495 # because it's already filtered above.
1496 source "${PORTAGE_BIN_PATH}/isolated-functions.sh" || exit $?
1498 # Rely on save_ebuild_env() to filter out any remaining variables
1499 # and functions that could interfere with the current environment.
1500 save_ebuild_env || exit $?
1501 touch "${T}/environment.success" || exit $?
1502 ) > "${T}/environment.filtered"
1504 if [ -e "${T}/environment.success" ] ; then
1505 filter_readonly_variables < \
1506 "${T}/environment.filtered" > "${T}/environment"
1511 rm -f "${T}"/environment.{filtered,raw,success}
1515 # === === === === === === === === === === === === === === === === === ===
1516 # === === === === === functions end, main part begins === === === === ===
1517 # === === === === === functions end, main part begins === === === === ===
1518 # === === === === === functions end, main part begins === === === === ===
1519 # === === === === === === === === === === === === === === === === === ===
1521 if [ -n "${EBUILD_SH_ARGS}" ] && \
1522 ! hasq ${EBUILD_SH_ARGS} clean depend help info nofetch ; then
1524 if [ "$(id -nu)" == "portage" ] ; then
1528 if hasq distcc ${FEATURES} ; then
1529 if [ -d /usr/lib/distcc/bin ]; then
1530 #We can enable distributed compile support
1531 if [ -z "${PATH/*distcc*/}" ]; then
1532 # Remove the other reference.
1533 remove_path_entry "distcc"
1535 export PATH="/usr/lib/distcc/bin:${PATH}"
1536 [ ! -z "${DISTCC_LOG}" ] && addwrite "$(dirname ${DISTCC_LOG})"
1537 elif which distcc &>/dev/null; then
1538 if ! hasq distcc $CC; then
1539 export CC="distcc $CC"
1541 if ! hasq distcc $CXX; then
1542 export CXX="distcc $CXX"
1547 if hasq ccache ${FEATURES} ; then
1548 #We can enable compiler cache support
1549 if [ -z "${PATH/*ccache*/}" ]; then
1550 # Remove the other reference.
1551 remove_path_entry "ccache"
1554 if [ -d /usr/lib/ccache/bin ]; then
1555 export PATH="/usr/lib/ccache/bin:${PATH}"
1556 elif [ -d /usr/bin/ccache ]; then
1557 export PATH="/usr/bin/ccache:${PATH}"
1560 [ -z "${CCACHE_DIR}" ] && export CCACHE_DIR="/var/tmp/ccache"
1562 addread "${CCACHE_DIR}"
1563 addwrite "${CCACHE_DIR}"
1565 [ -n "${CCACHE_SIZE}" ] && ccache -M ${CCACHE_SIZE} &> /dev/null
1567 # Force configure scripts that automatically detect ccache to respect
1568 # FEATURES="-ccache"
1569 export CCACHE_DISABLE=1
1572 # XXX: Load up the helper functions.
1573 # for X in /usr/lib/portage/bin/functions/*.sh; do
1574 # source ${X} || die "Failed to source ${X}"
1577 fi # "$*"!="depend" && "$*"!="clean" && "$*" != "setup"
1579 export SANDBOX_ON="1"
1580 export S=${WORKDIR}/${P}
1582 unset E_IUSE E_DEPEND E_RDEPEND E_PDEPEND
1584 # Turn of extended glob matching so that g++ doesn't get incorrectly matched.
1587 if [[ ${EBUILD_PHASE} == depend ]] ; then
1588 QA_INTERCEPTORS="awk bash cc egrep fgrep g++
1589 gawk gcc grep javac java-config nawk perl
1590 pkg-config python python-config sed"
1591 elif [[ ${EBUILD_PHASE} == clean* ]] ; then
1592 unset QA_INTERCEPTORS
1594 QA_INTERCEPTORS="autoconf automake aclocal libtoolize"
1596 # level the QA interceptors if we're in depend
1597 if [[ -n ${QA_INTERCEPTORS} ]] ; then
1598 for BIN in ${QA_INTERCEPTORS}; do
1599 BIN_PATH=$(type -Pf ${BIN})
1600 if [ "$?" != "0" ]; then
1601 BODY="echo \"*** missing command: ${BIN}\" >&2; return 127"
1603 BODY="${BIN_PATH} \"\$@\"; return \$?"
1605 if [[ ${EBUILD_PHASE} == depend ]] ; then
1606 FUNC_SRC="${BIN}() {
1607 if [ \$ECLASS_DEPTH -gt 0 ]; then
1608 eqawarn \"QA Notice: '${BIN}' called in global scope: eclass \${ECLASS}\"
1610 eqawarn \"QA Notice: '${BIN}' called in global scope: \${CATEGORY}/\${PF}\"
1614 elif hasq ${BIN} autoconf automake aclocal libtoolize ; then
1615 FUNC_SRC="${BIN}() {
1616 if ! hasq \${FUNCNAME[1]} eautoreconf eaclocal _elibtoolize \\
1617 eautoheader eautoconf eautomake autotools_run_tool \\
1618 autotools_check_macro autotools_get_subdirs \\
1619 autotools_get_auxdir ; then
1620 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
1621 eqawarn \"Use autotools.eclass instead of calling '${BIN}' directly.\"
1626 FUNC_SRC="${BIN}() {
1627 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
1631 eval "$FUNC_SRC" || echo "error creating QA interceptor ${BIN}" >&2
1633 unset BIN_PATH BIN BODY FUNC_SRC
1636 if ! hasq ${EBUILD_PHASE} clean depend && \
1637 [ -f "${T}"/environment ] ; then
1638 # The environment may have been extracted from environment.bz2 or
1639 # may have come from another version of ebuild.sh or something.
1640 # In any case, preprocess it to prevent any potential interference.
1641 preprocess_ebuild_env || \
1642 die "error processing environment"
1643 # Colon separated SANDBOX_* variables need to be cumulative.
1644 for x in SANDBOX_DENY SANDBOX_READ SANDBOX_PREDICT SANDBOX_WRITE ; do
1645 eval PORTAGE_${x}=\${!x}
1647 PORTAGE_SANDBOX_ON=${SANDBOX_ON}
1649 source "${T}"/environment || \
1650 die "error sourcing environment"
1651 # We have to temporarily disable sandbox since the
1652 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
1653 # may be unusable (triggering in spurious sandbox violations)
1654 # until we've merged them with our current values.
1656 for x in SANDBOX_DENY SANDBOX_PREDICT SANDBOX_READ SANDBOX_WRITE ; do
1657 eval y=\${PORTAGE_${x}}
1658 if [ "${y}" != "${!x}" ] ; then
1659 eval export ${x}=\"$(echo -n "${y}:${!x}" | tr ":" "\0" | \
1660 sort -z -u | tr "\0" ":")\"
1665 export SANDBOX_ON=${PORTAGE_SANDBOX_ON}
1666 unset PORTAGE_SANDBOX_ON
1668 # After loading the environment, make sure the color variables
1669 # are in sync with the current NOCOLOR setting.
1670 case "${NOCOLOR:-false}" in
1682 if ! hasq ${EBUILD_PHASE} clean && \
1684 hasq ${EBUILD_PHASE} depend || \
1685 [ ! -f "${T}"/environment ] || \
1686 hasq noauto ${FEATURES}
1688 # The bashrcs get an opportunity here to set aliases that will be expanded
1689 # during sourcing of ebuilds and eclasses.
1692 # *DEPEND and IUSE will be set during the sourcing of the ebuild.
1693 # In order to ensure correct interaction between ebuilds and
1694 # eclasses, they need to be unset before this process of
1695 # interaction begins.
1696 unset DEPEND RDEPEND PDEPEND IUSE
1697 source "${EBUILD}" || die "error sourcing ebuild"
1699 if [ "${EBUILD_PHASE}" != "depend" ] ; then
1700 RESTRICT=${PORTAGE_RESTRICT}
1703 # This next line is not the same as export RDEPEND=${RDEPEND:-${DEPEND}}
1704 # That will test for unset *or* NULL (""). We want just to set for unset...
1705 # turn off glob expansion from here on in to prevent *'s and ? in the
1706 # DEPEND syntax from getting expanded :)
1708 if [ "${RDEPEND-unset}" == "unset" ] ; then
1709 export RDEPEND=${DEPEND}
1710 debug-print "RDEPEND: not set... Setting to: ${DEPEND}"
1713 # add in dependency info from eclasses
1714 IUSE="${IUSE} ${E_IUSE}"
1715 DEPEND="${DEPEND} ${E_DEPEND}"
1716 RDEPEND="${RDEPEND} ${E_RDEPEND}"
1717 PDEPEND="${PDEPEND} ${E_PDEPEND}"
1719 unset ECLASS E_IUSE E_DEPEND E_RDEPEND E_PDEPEND
1721 if [ "${EBUILD_PHASE}" != "depend" ] ; then
1722 # Make IUSE defaults backward compatible with all the old shell code.
1724 for x in ${IUSE} ; do
1725 if [[ ${x} == +* ]] || [[ ${x} == -* ]] ; then
1726 iuse_temp="${iuse_temp} ${x:1}"
1728 iuse_temp="${iuse_temp} ${x}"
1731 export IUSE=${iuse_temp}
1737 # enable bashrc support for the clean phase
1738 [[ ${EBUILD_PHASE} == clean ]] && source_all_bashrcs
1740 # unset USE_EXPAND variables that contain only the special "*" token
1741 for x in ${USE_EXPAND} ; do
1742 [ "${!x}" == "*" ] && unset ${x}
1746 if hasq nostrip ${FEATURES} ${RESTRICT} || hasq strip ${RESTRICT}
1751 #a reasonable default for $S
1752 [[ -z ${S} ]] && export S=${WORKDIR}/${P}
1754 #some users have $TMP/$TMPDIR to a custom dir in their home ...
1755 #this will cause sandbox errors with some ./configure
1756 #scripts, so set it to $T.
1758 export TMPDIR="${T}"
1760 # Note: readonly variables interfere with preprocess_ebuild_env(), so
1761 # declare them only after it has already run.
1762 if [ "${EBUILD_PHASE}" != "depend" ] ; then
1763 declare -r ${READONLY_EBUILD_METADATA} ${READONLY_PORTAGE_VARS}
1766 if [ -n "${EBUILD_SH_ARGS}" ] ; then
1767 case ${EBUILD_SH_ARGS} in
1769 ebuild_phase_with_hooks pkg_nofetch
1772 prerm|postrm|postinst|config|info)
1773 if hasq ${EBUILD_SH_ARGS} config info && \
1774 [ "$(type -t pkg_${EBUILD_SH_ARGS})" != "function" ]; then
1775 ewarn "pkg_${EBUILD_SH_ARGS}() is not defined: '${EBUILD##*/}'"
1777 export SANDBOX_ON="0"
1778 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
1779 ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
1782 ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
1785 if [[ $EBUILD_PHASE == postinst ]] && [[ -n $PORTAGE_UPDATE_ENV ]]; then
1786 # Update environment.bz2 in case installation phases
1787 # need to pass some variables to uninstallation phases.
1789 unset S _E_DOCDESTTREE_ _E_EXEDESTTREE_
1790 save_ebuild_env | filter_readonly_variables \
1791 --filter-sandbox --allow-extra-vars | \
1792 bzip2 -c -f9 > "$PORTAGE_UPDATE_ENV"
1796 unpack|compile|test|clean|install)
1797 if [ "${SANDBOX_DISABLED="0"}" == "0" ]; then
1798 export SANDBOX_ON="1"
1800 export SANDBOX_ON="0"
1802 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
1803 dyn_${EBUILD_SH_ARGS}
1806 dyn_${EBUILD_SH_ARGS}
1809 export SANDBOX_ON="0"
1812 #pkg_setup needs to be out of the sandbox for tmp file creation;
1813 #for example, awking and piping a file in /tmp requires a temp file to be created
1814 #in /etc. If pkg_setup is in the sandbox, both our lilo and apache ebuilds break.
1815 export SANDBOX_ON="0"
1816 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
1817 dyn_${EBUILD_SH_ARGS}
1820 dyn_${EBUILD_SH_ARGS}
1825 export SANDBOX_ON="0"
1828 if [ -n "${dbkey}" ] ; then
1829 if [ ! -d "${dbkey%/*}" ]; then
1830 install -d -g ${PORTAGE_GID} -m2775 "${dbkey%/*}"
1832 # Make it group writable. 666&~002==664
1836 auxdbkeys="DEPEND RDEPEND SLOT SRC_URI RESTRICT HOMEPAGE LICENSE
1837 DESCRIPTION KEYWORDS INHERITED IUSE CDEPEND PDEPEND PROVIDE EAPI
1838 UNUSED_01 UNUSED_02 UNUSED_03 UNUSED_04 UNUSED_05 UNUSED_06
1841 #the extra $(echo) commands remove newlines
1843 [ -n "${EAPI}" ] || EAPI=0
1844 if [ -n "${dbkey}" ] ; then
1846 for f in ${auxdbkeys} ; do
1847 echo $(echo ${!f}) >> "${dbkey}" || exit $?
1850 for f in ${auxdbkeys} ; do
1851 echo $(echo ${!f}) 1>&9 || exit $?
1858 export SANDBOX_ON="1"
1859 echo "Unrecognized EBUILD_SH_ARGS: '${EBUILD_SH_ARGS}'"
1865 [ -n "${EBUILD_EXIT_STATUS_FILE}" ] && \
1866 touch "${EBUILD_EXIT_STATUS_FILE}" &>/dev/null
1869 # Save the env only for relevant phases.
1870 if [ -n "${EBUILD_SH_ARGS}" ] && \
1871 ! hasq ${EBUILD_SH_ARGS} clean depend help info nofetch ; then
1872 # Save current environment and touch a success file. (echo for success)
1874 save_ebuild_env | filter_readonly_variables > "${T}/environment"
1875 chown portage:portage "${T}/environment" &>/dev/null
1876 chmod g+w "${T}/environment" &>/dev/null
1879 # Do not exit when ebuild.sh is sourced by other scripts.