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 if hasq --filter-sandbox $* ; then
1429 filtered_vars="${filtered_vars} SANDBOX_[_[:alnum:]]*"
1431 filtered_vars="${filtered_vars} ${filtered_sandbox_vars}"
1433 if hasq --filter-features $* ; then
1434 filtered_vars="${filtered_vars} FEATURES"
1436 if ! hasq --allow-extra-vars $* ; then
1439 ${PORTAGE_SAVED_READONLY_VARS}
1440 ${PORTAGE_MUTABLE_FILTERED_VARS}
1444 # TODO: Take the the below sed-based declare -r filter and integrate it
1445 # directly into filter-bash-environment.py.
1446 # The sed is to remove the readonly attribute from variables such as those
1447 # listed in READONLY_EBUILD_METADATA, since having any readonly attributes
1448 # persisting in the saved environment can be inconvenient when it
1449 # eventually needs to be reloaded.
1450 "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}" | sed -r \
1451 -e 's:^declare[[:space:]]+-r[[:space:]]+:declare :' \
1452 -e 's:^declare[[:space:]]+-([[:alnum:]]*)r([[:alnum:]]*)[[:space:]]+:declare -\1\2 :'
1455 # @FUNCTION: preprocess_ebuild_env
1457 # Filter any readonly variables from ${T}/environment, source it, and then
1458 # save it via save_ebuild_env(). This process should be sufficient to prevent
1459 # any stale variables or functions from an arbitrary environment from
1460 # interfering with the current environment. This is useful when an existing
1461 # environment needs to be loaded from a binary or installed package.
1462 preprocess_ebuild_env() {
1463 local filter_opts=""
1464 if [ -f "${T}/environment.raw" ] ; then
1465 # This is a signal from the python side, indicating that the
1466 # environment may contain stale SANDBOX_{DENY,PREDICT,READ,WRITE}
1467 # and FEATURES variables that should be filtered out. Between
1468 # phases, these variables are normally preserved.
1469 filter_opts="--filter-sandbox --filter-features ${filter_opts}"
1471 filter_readonly_variables ${filter_opts} < "${T}"/environment \
1472 > "${T}"/environment.filtered || return $?
1474 mv "${T}"/environment.filtered "${T}"/environment || return $?
1475 rm -f "${T}/environment.success" || return $?
1476 # WARNING: Code inside this subshell should avoid making assumptions
1477 # about variables or functions after source "${T}"/environment has been
1478 # called. Any variables that need to be relied upon should already be
1479 # filtered out above.
1482 source "${T}/environment" || exit $?
1483 # We have to temporarily disable sandbox since the
1484 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
1485 # may be unusable (triggering in spurious sandbox violations)
1486 # until we've merged them with our current values.
1489 # It's remotely possible that save_ebuild_env() has been overridden
1490 # by the above source command. To protect ourselves, we override it
1491 # here with our own version. ${PORTAGE_BIN_PATH} is safe to use here
1492 # because it's already filtered above.
1493 source "${PORTAGE_BIN_PATH}/isolated-functions.sh" || exit $?
1495 # Rely on save_ebuild_env() to filter out any remaining variables
1496 # and functions that could interfere with the current environment.
1497 save_ebuild_env || exit $?
1498 touch "${T}/environment.success" || exit $?
1499 ) > "${T}/environment.filtered"
1501 if [ -e "${T}/environment.success" ] ; then
1502 filter_readonly_variables < \
1503 "${T}/environment.filtered" > "${T}/environment"
1508 rm -f "${T}"/environment.{filtered,raw,success}
1512 # === === === === === === === === === === === === === === === === === ===
1513 # === === === === === functions end, main part begins === === === === ===
1514 # === === === === === functions end, main part begins === === === === ===
1515 # === === === === === functions end, main part begins === === === === ===
1516 # === === === === === === === === === === === === === === === === === ===
1518 if [ -n "${EBUILD_SH_ARGS}" ] && \
1519 ! hasq ${EBUILD_SH_ARGS} clean depend help info nofetch ; then
1521 if [ "$(id -nu)" == "portage" ] ; then
1525 if hasq distcc ${FEATURES} ; then
1526 if [ -d /usr/lib/distcc/bin ]; then
1527 #We can enable distributed compile support
1528 if [ -z "${PATH/*distcc*/}" ]; then
1529 # Remove the other reference.
1530 remove_path_entry "distcc"
1532 export PATH="/usr/lib/distcc/bin:${PATH}"
1533 [ ! -z "${DISTCC_LOG}" ] && addwrite "$(dirname ${DISTCC_LOG})"
1534 elif which distcc &>/dev/null; then
1535 if ! hasq distcc $CC; then
1536 export CC="distcc $CC"
1538 if ! hasq distcc $CXX; then
1539 export CXX="distcc $CXX"
1544 if hasq ccache ${FEATURES} ; then
1545 #We can enable compiler cache support
1546 if [ -z "${PATH/*ccache*/}" ]; then
1547 # Remove the other reference.
1548 remove_path_entry "ccache"
1551 if [ -d /usr/lib/ccache/bin ]; then
1552 export PATH="/usr/lib/ccache/bin:${PATH}"
1553 elif [ -d /usr/bin/ccache ]; then
1554 export PATH="/usr/bin/ccache:${PATH}"
1557 [ -z "${CCACHE_DIR}" ] && export CCACHE_DIR="/var/tmp/ccache"
1559 addread "${CCACHE_DIR}"
1560 addwrite "${CCACHE_DIR}"
1562 [ -n "${CCACHE_SIZE}" ] && ccache -M ${CCACHE_SIZE} &> /dev/null
1564 # Force configure scripts that automatically detect ccache to respect
1565 # FEATURES="-ccache"
1566 export CCACHE_DISABLE=1
1569 # XXX: Load up the helper functions.
1570 # for X in /usr/lib/portage/bin/functions/*.sh; do
1571 # source ${X} || die "Failed to source ${X}"
1574 fi # "$*"!="depend" && "$*"!="clean" && "$*" != "setup"
1576 export SANDBOX_ON="1"
1577 export S=${WORKDIR}/${P}
1579 unset E_IUSE E_DEPEND E_RDEPEND E_PDEPEND
1581 # Turn of extended glob matching so that g++ doesn't get incorrectly matched.
1584 if [[ ${EBUILD_PHASE} == depend ]] ; then
1585 QA_INTERCEPTORS="awk bash cc egrep fgrep g++
1586 gawk gcc grep javac java-config nawk perl
1587 pkg-config python python-config sed"
1588 elif [[ ${EBUILD_PHASE} == clean* ]] ; then
1589 unset QA_INTERCEPTORS
1591 QA_INTERCEPTORS="autoconf automake aclocal libtoolize"
1593 # level the QA interceptors if we're in depend
1594 if [[ -n ${QA_INTERCEPTORS} ]] ; then
1595 for BIN in ${QA_INTERCEPTORS}; do
1596 BIN_PATH=$(type -Pf ${BIN})
1597 if [ "$?" != "0" ]; then
1598 BODY="echo \"*** missing command: ${BIN}\" >&2; return 127"
1600 BODY="${BIN_PATH} \"\$@\"; return \$?"
1602 if [[ ${EBUILD_PHASE} == depend ]] ; then
1603 FUNC_SRC="${BIN}() {
1604 if [ \$ECLASS_DEPTH -gt 0 ]; then
1605 eqawarn \"QA Notice: '${BIN}' called in global scope: eclass \${ECLASS}\"
1607 eqawarn \"QA Notice: '${BIN}' called in global scope: \${CATEGORY}/\${PF}\"
1611 elif hasq ${BIN} autoconf automake aclocal libtoolize ; then
1612 FUNC_SRC="${BIN}() {
1613 if ! hasq \${FUNCNAME[1]} eautoreconf eaclocal _elibtoolize \\
1614 eautoheader eautoconf eautomake autotools_run_tool \\
1615 autotools_check_macro autotools_get_subdirs \\
1616 autotools_get_auxdir ; then
1617 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
1618 eqawarn \"Use autotools.eclass instead of calling '${BIN}' directly.\"
1623 FUNC_SRC="${BIN}() {
1624 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
1628 eval "$FUNC_SRC" || echo "error creating QA interceptor ${BIN}" >&2
1630 unset BIN_PATH BIN BODY FUNC_SRC
1633 if ! hasq ${EBUILD_PHASE} clean depend && \
1634 [ -f "${T}"/environment ] ; then
1635 # The environment may have been extracted from environment.bz2 or
1636 # may have come from another version of ebuild.sh or something.
1637 # In any case, preprocess it to prevent any potential interference.
1638 preprocess_ebuild_env || \
1639 die "error processing environment"
1640 # Colon separated SANDBOX_* variables need to be cumulative.
1641 for x in SANDBOX_DENY SANDBOX_READ SANDBOX_PREDICT SANDBOX_WRITE ; do
1642 eval PORTAGE_${x}=\${!x}
1644 PORTAGE_SANDBOX_ON=${SANDBOX_ON}
1646 source "${T}"/environment || \
1647 die "error sourcing environment"
1648 # We have to temporarily disable sandbox since the
1649 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
1650 # may be unusable (triggering in spurious sandbox violations)
1651 # until we've merged them with our current values.
1653 for x in SANDBOX_DENY SANDBOX_PREDICT SANDBOX_READ SANDBOX_WRITE ; do
1654 eval y=\${PORTAGE_${x}}
1655 if [ "${y}" != "${!x}" ] ; then
1656 eval export ${x}=\"$(echo -n "${y}:${!x}" | tr ":" "\0" | \
1657 sort -z -u | tr "\0" ":")\"
1662 export SANDBOX_ON=${PORTAGE_SANDBOX_ON}
1663 unset PORTAGE_SANDBOX_ON
1665 # After loading the environment, make sure the color variables
1666 # are in sync with the current NOCOLOR setting.
1667 case "${NOCOLOR:-false}" in
1679 if ! hasq ${EBUILD_PHASE} clean && \
1681 hasq ${EBUILD_PHASE} depend || \
1682 [ ! -f "${T}"/environment ] || \
1683 hasq noauto ${FEATURES}
1685 # The bashrcs get an opportunity here to set aliases that will be expanded
1686 # during sourcing of ebuilds and eclasses.
1689 # *DEPEND and IUSE will be set during the sourcing of the ebuild.
1690 # In order to ensure correct interaction between ebuilds and
1691 # eclasses, they need to be unset before this process of
1692 # interaction begins.
1693 unset DEPEND RDEPEND PDEPEND IUSE
1694 source "${EBUILD}" || die "error sourcing ebuild"
1696 if [ "${EBUILD_PHASE}" != "depend" ] ; then
1697 RESTRICT=${PORTAGE_RESTRICT}
1700 # This next line is not the same as export RDEPEND=${RDEPEND:-${DEPEND}}
1701 # That will test for unset *or* NULL (""). We want just to set for unset...
1702 # turn off glob expansion from here on in to prevent *'s and ? in the
1703 # DEPEND syntax from getting expanded :)
1705 if [ "${RDEPEND-unset}" == "unset" ] ; then
1706 export RDEPEND=${DEPEND}
1707 debug-print "RDEPEND: not set... Setting to: ${DEPEND}"
1710 # add in dependency info from eclasses
1711 IUSE="${IUSE} ${E_IUSE}"
1712 DEPEND="${DEPEND} ${E_DEPEND}"
1713 RDEPEND="${RDEPEND} ${E_RDEPEND}"
1714 PDEPEND="${PDEPEND} ${E_PDEPEND}"
1716 unset ECLASS E_IUSE E_DEPEND E_RDEPEND E_PDEPEND
1718 if [ "${EBUILD_PHASE}" != "depend" ] ; then
1719 # Make IUSE defaults backward compatible with all the old shell code.
1721 for x in ${IUSE} ; do
1722 if [[ ${x} == +* ]] || [[ ${x} == -* ]] ; then
1723 iuse_temp="${iuse_temp} ${x:1}"
1725 iuse_temp="${iuse_temp} ${x}"
1728 export IUSE=${iuse_temp}
1734 # enable bashrc support for the clean phase
1735 [[ ${EBUILD_PHASE} == clean ]] && source_all_bashrcs
1737 # unset USE_EXPAND variables that contain only the special "*" token
1738 for x in ${USE_EXPAND} ; do
1739 [ "${!x}" == "*" ] && unset ${x}
1743 if hasq nostrip ${FEATURES} ${RESTRICT} || hasq strip ${RESTRICT}
1748 #a reasonable default for $S
1749 [[ -z ${S} ]] && export S=${WORKDIR}/${P}
1751 #some users have $TMP/$TMPDIR to a custom dir in their home ...
1752 #this will cause sandbox errors with some ./configure
1753 #scripts, so set it to $T.
1755 export TMPDIR="${T}"
1757 # Note: readonly variables interfere with preprocess_ebuild_env(), so
1758 # declare them only after it has already run.
1759 if [ "${EBUILD_PHASE}" != "depend" ] ; then
1760 declare -r ${READONLY_EBUILD_METADATA} ${READONLY_PORTAGE_VARS}
1763 if [ -n "${EBUILD_SH_ARGS}" ] ; then
1764 case ${EBUILD_SH_ARGS} in
1766 ebuild_phase_with_hooks pkg_nofetch
1769 prerm|postrm|postinst|config|info)
1770 if hasq ${EBUILD_SH_ARGS} config info && \
1771 [ "$(type -t pkg_${EBUILD_SH_ARGS})" != "function" ]; then
1772 ewarn "pkg_${EBUILD_SH_ARGS}() is not defined: '${EBUILD##*/}'"
1774 export SANDBOX_ON="0"
1775 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
1776 ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
1779 ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
1782 if [[ $EBUILD_PHASE == postinst ]] && [[ -n $PORTAGE_UPDATE_ENV ]]; then
1783 # Update environment.bz2 in case installation phases
1784 # need to pass some variables to uninstallation phases.
1786 unset S _E_DOCDESTTREE_ _E_EXEDESTTREE_
1787 save_ebuild_env | filter_readonly_variables \
1788 --filter-sandbox --allow-extra-vars | \
1789 bzip2 -c -f9 > "$PORTAGE_UPDATE_ENV"
1793 unpack|compile|test|clean|install)
1794 if [ "${SANDBOX_DISABLED="0"}" == "0" ]; then
1795 export SANDBOX_ON="1"
1797 export SANDBOX_ON="0"
1799 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
1800 dyn_${EBUILD_SH_ARGS}
1803 dyn_${EBUILD_SH_ARGS}
1806 export SANDBOX_ON="0"
1809 #pkg_setup needs to be out of the sandbox for tmp file creation;
1810 #for example, awking and piping a file in /tmp requires a temp file to be created
1811 #in /etc. If pkg_setup is in the sandbox, both our lilo and apache ebuilds break.
1812 export SANDBOX_ON="0"
1813 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
1814 dyn_${EBUILD_SH_ARGS}
1817 dyn_${EBUILD_SH_ARGS}
1822 export SANDBOX_ON="0"
1825 if [ -n "${dbkey}" ] ; then
1826 if [ ! -d "${dbkey%/*}" ]; then
1827 install -d -g ${PORTAGE_GID} -m2775 "${dbkey%/*}"
1829 # Make it group writable. 666&~002==664
1833 auxdbkeys="DEPEND RDEPEND SLOT SRC_URI RESTRICT HOMEPAGE LICENSE
1834 DESCRIPTION KEYWORDS INHERITED IUSE CDEPEND PDEPEND PROVIDE EAPI
1835 UNUSED_01 UNUSED_02 UNUSED_03 UNUSED_04 UNUSED_05 UNUSED_06
1838 #the extra $(echo) commands remove newlines
1840 [ -n "${EAPI}" ] || EAPI=0
1841 if [ -n "${dbkey}" ] ; then
1843 for f in ${auxdbkeys} ; do
1844 echo $(echo ${!f}) >> "${dbkey}" || exit $?
1847 for f in ${auxdbkeys} ; do
1848 echo $(echo ${!f}) 1>&9 || exit $?
1855 export SANDBOX_ON="1"
1856 echo "Unrecognized EBUILD_SH_ARGS: '${EBUILD_SH_ARGS}'"
1862 [ -n "${EBUILD_EXIT_STATUS_FILE}" ] && \
1863 touch "${EBUILD_EXIT_STATUS_FILE}" &>/dev/null
1866 # Save the env only for relevant phases.
1867 if [ -n "${EBUILD_SH_ARGS}" ] && \
1868 ! hasq ${EBUILD_SH_ARGS} clean depend help info nofetch ; then
1869 # Save current environment and touch a success file. (echo for success)
1871 save_ebuild_env | filter_readonly_variables > "${T}/environment"
1872 chown portage:portage "${T}/environment" &>/dev/null
1873 chmod g+w "${T}/environment" &>/dev/null
1876 # Do not exit when ebuild.sh is sourced by other scripts.