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"
36 source "$@" || return 1
37 [[ $shopts != $(shopt) ]] &&
38 eqawarn "QA Notice: Global shell options changed and were not restored while sourcing '$*'"
39 [[ "$IFS" != "$OLDIFS" ]] &&
40 eqawarn "QA Notice: Global IFS changed and was not restored while sourcing '$*'"
45 local shopts=$(shopt) OLDIFS="$IFS"
47 [[ $shopts != $(shopt) ]] &&
48 eqawarn "QA Notice: Global shell options changed and were not restored while calling '$*'"
49 [[ "$IFS" != "$OLDIFS" ]] &&
50 eqawarn "QA Notice: Global IFS changed and was not restored while calling '$*'"
54 # subshell die support
62 # Prevent aliases from causing portage to act inappropriately.
63 # Make sure it's before everything so we don't mess aliases that follow.
66 # Unset some variables that break things.
67 unset GZIP BZIP BZIP2 CDPATH GREP_OPTIONS GREP_COLOR GLOBIGNORE
69 export PATH="/usr/local/sbin:/sbin:/usr/sbin:${PORTAGE_BIN_PATH}:/usr/local/bin:/bin:/usr/bin:${ROOTPATH}"
70 [ ! -z "$PREROOTPATH" ] && export PATH="${PREROOTPATH%%:}:$PATH"
72 source "${PORTAGE_BIN_PATH}/isolated-functions.sh" &>/dev/null
74 # Set IMAGE for minimal backward compatibility with
75 # overlays or user's bashrc, but don't export it.
76 [ "${EBUILD_PHASE}" == "preinst" ] && IMAGE=${D}
78 [[ $PORTAGE_QUIET != "" ]] && export PORTAGE_QUIET
80 # the sandbox is disabled by default except when overridden in the relevant stages
83 # sandbox support functions; defined prior to profile.bashrc srcing, since the profile might need to add a default exception (/usr/lib64/conftest fex)
85 [[ -z $1 || -n $2 ]] && die "Usage: addread <colon-delimited list of paths>"
86 export SANDBOX_READ="$SANDBOX_READ:$1"
90 [[ -z $1 || -n $2 ]] && die "Usage: addwrite <colon-delimited list of paths>"
91 export SANDBOX_WRITE="$SANDBOX_WRITE:$1"
95 [[ -z $1 || -n $2 ]] && die "Usage: adddeny <colon-delimited list of paths>"
96 export SANDBOX_DENY="$SANDBOX_DENY:$1"
100 [[ -z $1 || -n $2 ]] && die "Usage: addpredict <colon-delimited list of paths>"
101 export SANDBOX_PREDICT="$SANDBOX_PREDICT:$1"
113 # Custom version of esyslog() to take care of the "Red Star" bug.
114 # MUST follow functions.sh to override the "" parameter problem.
134 # if we got something like '!flag', then invert the return value
135 if [[ ${u:0:1} == "!" ]] ; then
140 # Make sure we have this USE flag in IUSE
141 if [[ -n ${PORTAGE_IUSE} ]] && \
142 [[ -n ${EBUILD_PHASE} ]] && \
143 ! hasq ${EBUILD_PHASE} config depend info prerm postrm postinst && \
144 [[ ${EMERGE_FROM} != binary ]] ; then
145 # TODO: Implement PORTAGE_IUSE for binary packages. Currently,
146 # it is only valid for build time phases.
147 echo "${u}" | egrep -q "${PORTAGE_IUSE}" || \
148 eqawarn "QA Notice: USE Flag '${u}' not" \
149 "in IUSE for ${CATEGORY}/${PF}"
152 if hasq ${u} ${USE} ; then
160 if [ "${EBUILD_PHASE}" == "depend" ]; then
161 die "portageq calls (has_version calls portageq) are not allowed in the global scope"
163 # return shell-true/shell-false if exists.
164 # Takes single depend-type atoms.
165 PYTHONPATH="${PORTAGE_PYM_PATH}:${PYTHONPATH}" \
166 "${PORTAGE_BIN_PATH}"/portageq has_version "${ROOT}" "$1"
176 die "unexpected portageq exit code: ${retval}"
182 if [ "${EBUILD_PHASE}" == "depend" ]; then
183 die "portageq calls are not allowed in the global scope"
185 PYTHONPATH="${PORTAGE_PYM_PATH}:${PYTHONPATH}" \
186 "${PORTAGE_BIN_PATH}/portageq" "$@"
190 # ----------------------------------------------------------------------------
191 # ----------------------------------------------------------------------------
192 # ----------------------------------------------------------------------------
196 if [ "${EBUILD_PHASE}" == "depend" ]; then
197 die "portageq calls (best_version calls portageq) are not allowed in the global scope"
199 # returns the best/most-current match.
200 # Takes single depend-type atoms.
201 PYTHONPATH="${PORTAGE_PYM_PATH}:${PYTHONPATH}" \
202 "${PORTAGE_BIN_PATH}/portageq" 'best_version' "${ROOT}" "$1"
207 echo "!!! use_with() called without a parameter." >&2
208 echo "!!! use_with <USEFLAG> [<flagname> [value]]" >&2
213 if [ ! -z "${3}" ]; then
218 if [ -z "${UWORD}" ]; then
223 echo "--with-${UWORD}${UW_SUFFIX}"
225 echo "--without-${UWORD}"
232 echo "!!! use_enable() called without a parameter." >&2
233 echo "!!! use_enable <USEFLAG> [<flagname> [value]]" >&2
238 if [ ! -z "${3}" ]; then
243 if [ -z "${UWORD}" ]; then
248 echo "--enable-${UWORD}${UE_SUFFIX}"
250 echo "--disable-${UWORD}"
255 register_die_hook() {
256 export EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} $*"
259 #if no perms are specified, dirs/files will have decent defaults
260 #(not secretive, but not stupid)
263 export INSDESTTREE=""
264 export _E_EXEDESTTREE_=""
265 export _E_DOCDESTTREE_=""
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"
965 ebuild_phase src_install
966 touch "${PORTAGE_BUILDDIR}/.installed"
967 vecho ">>> Completed installing ${PF} into ${D}"
969 cd ${PORTAGE_BUILDDIR}
970 [ "$(type -t post_src_install)" == "function" ] && qa_call post_src_install
972 cd "${PORTAGE_BUILDDIR}"/build-info
975 for f in ASFLAGS CATEGORY CBUILD CC CFLAGS CHOST CTARGET CXX \
976 CXXFLAGS DEPEND EXTRA_ECONF EXTRA_EINSTALL EXTRA_MAKE \
977 FEATURES INHERITED IUSE LDFLAGS LIBCFLAGS LIBCXXFLAGS \
978 LICENSE PDEPEND PF PKGUSE PROVIDE RDEPEND RESTRICT SLOT \
979 KEYWORDS HOMEPAGE SRC_URI DESCRIPTION; do
980 [ -n "${!f}" ] && echo $(echo "${!f}" | \
981 tr '\n,\r,\t' ' , , ' | sed s/' \+'/' '/g) > ${f}
984 echo "${EAPI:-0}" > EAPI
987 # local variables can leak into the saved environment.
991 # To avoid environment.bz2 bloat, cleanse variables that are
992 # are no longer needed after src_install(). Don't cleanse from
993 # the global environment though, in case the user wants to repeat
994 # this phase (like with FEATURES=noauto and the ebuild command).
995 unset S _E_DOCDESTTREE_ _E_EXEDESTTREE_
996 save_ebuild_env | filter_readonly_variables \
997 --filter-sandbox --allow-extra-vars > environment
999 bzip2 -f9 environment
1001 cp "${EBUILD}" "${PF}.ebuild"
1002 [ -n "${PORTAGE_REPO_NAME}" ] && echo "${PORTAGE_REPO_NAME}" > repository
1003 if hasq nostrip ${FEATURES} ${RESTRICT} || hasq strip ${RESTRICT}
1011 if [ -z "${D}" ]; then
1012 eerror "${FUNCNAME}: D is unset"
1015 ebuild_phase_with_hooks pkg_preinst
1021 echo "Copyright 1999-2006 Gentoo Foundation"
1023 echo "How to use the ebuild command:"
1025 echo "The first argument to ebuild should be an existing .ebuild file."
1027 echo "One or more of the following options can then be specified. If more"
1028 echo "than one option is specified, each will be executed in order."
1030 echo " help : show this help screen"
1031 echo " setup : execute package specific setup actions"
1032 echo " fetch : download source archive(s) and patches"
1033 echo " digest : create a digest and a manifest file for the package"
1034 echo " manifest : create a manifest file for the package"
1035 echo " unpack : unpack/patch sources (auto-fetch if needed)"
1036 echo " compile : compile sources (auto-fetch/unpack if needed)"
1037 echo " test : test package (auto-fetch/unpack/compile if needed)"
1038 echo " preinst : execute pre-install instructions"
1039 echo " postinst : execute post-install instructions"
1040 echo " install : install the package to the temporary install directory"
1041 echo " qmerge : merge image into live filesystem, recording files in db"
1042 echo " merge : do fetch, unpack, compile, install and qmerge"
1043 echo " prerm : execute pre-removal instructions"
1044 echo " postrm : execute post-removal instructions"
1045 echo " unmerge : remove package from live filesystem"
1046 echo " config : execute package specific configuration actions"
1047 echo " package : create a tarball package in ${PKGDIR}/All"
1048 echo " rpm : build a RedHat RPM package"
1049 echo " clean : clean up all source and temporary files"
1051 echo "The following settings will be used for the ebuild process:"
1053 echo " package : ${PF}"
1054 echo " slot : ${SLOT}"
1055 echo " category : ${CATEGORY}"
1056 echo " description : ${DESCRIPTION}"
1057 echo " system : ${CHOST}"
1058 echo " c flags : ${CFLAGS}"
1059 echo " c++ flags : ${CXXFLAGS}"
1060 echo " make flags : ${MAKEOPTS}"
1061 echo -n " build mode : "
1062 if hasq nostrip ${FEATURES} ${RESTRICT} || hasq strip ${RESTRICT} ;
1064 echo "debug (large)"
1066 echo "production (stripped)"
1068 echo " merge to : ${ROOT}"
1070 if [ -n "$USE" ]; then
1071 echo "Additionally, support for the following optional features will be enabled:"
1078 # debug-print() gets called from many places with verbose status information useful
1079 # for tracking down problems. The output is in $T/eclass-debug.log.
1080 # You can set ECLASS_DEBUG_OUTPUT to redirect the output somewhere else as well.
1081 # The special "on" setting echoes the information, mixing it with the rest of the
1083 # You can override the setting by exporting a new one from the console, or you can
1084 # set a new default in make.*. Here the default is "" or unset.
1086 # in the future might use e* from /etc/init.d/functions.sh if i feel like it
1088 # if $T isn't defined, we're in dep calculation mode and
1089 # shouldn't do anything
1090 [ ! -d "$T" ] && return 0
1094 # extra user-configurable targets
1095 if [ "$ECLASS_DEBUG_OUTPUT" == "on" ]; then
1097 elif [ -n "$ECLASS_DEBUG_OUTPUT" ]; then
1098 echo "debug: $1" >> $ECLASS_DEBUG_OUTPUT
1102 echo "$1" 2>/dev/null >> "${T}/eclass-debug.log"
1103 # let the portage user own/write to this file
1104 chmod g+w "${T}/eclass-debug.log" &>/dev/null
1110 # The following 2 functions are debug-print() wrappers
1112 debug-print-function() {
1113 str="$1: entering function"
1115 debug-print "$str, parameters: $*"
1118 debug-print-section() {
1119 debug-print "now in section $*"
1122 # Sources all eclasses in parameters
1123 declare -ix ECLASS_DEPTH=0
1125 ECLASS_DEPTH=$(($ECLASS_DEPTH + 1))
1126 if [[ ${ECLASS_DEPTH} > 1 ]]; then
1127 debug-print "*** Multiple Inheritence (Level: ${ECLASS_DEPTH})"
1139 location="${ECLASSDIR}/${1}.eclass"
1142 # PECLASS is used to restore the ECLASS var after recursion.
1146 if [ "${EBUILD_PHASE}" != "depend" ] && \
1147 [[ ${EBUILD_PHASE} != *rm ]] && \
1148 [[ ${EMERGE_FROM} != "binary" ]] ; then
1149 # This is disabled in the *rm phases because they frequently give
1150 # false alarms due to INHERITED in /var/db/pkg being outdated
1151 # in comparison the the eclasses from the portage tree.
1152 if ! hasq $ECLASS $INHERITED; then
1153 eqawarn "QA Notice: ECLASS '$ECLASS' inherited illegally in $CATEGORY/$PF"
1157 # any future resolution code goes here
1158 if [ -n "$PORTDIR_OVERLAY" ]; then
1160 for overlay in ${PORTDIR_OVERLAY}; do
1161 olocation="${overlay}/eclass/${1}.eclass"
1162 if [ -e "$olocation" ]; then
1163 location="${olocation}"
1164 debug-print " eclass exists: ${location}"
1168 debug-print "inherit: $1 -> $location"
1169 [ ! -e "$location" ] && die "${1}.eclass could not be found by inherit()"
1171 if [ "${location}" == "${olocation}" ] && \
1172 ! hasq "${location}" ${EBUILD_OVERLAY_ECLASSES} ; then
1173 EBUILD_OVERLAY_ECLASSES="${EBUILD_OVERLAY_ECLASSES} ${location}"
1176 #We need to back up the value of DEPEND and RDEPEND to B_DEPEND and B_RDEPEND
1177 #(if set).. and then restore them after the inherit call.
1179 #turn off glob expansion
1182 # Retain the old data and restore it later.
1183 unset B_IUSE B_DEPEND B_RDEPEND B_PDEPEND
1184 [ "${IUSE-unset}" != "unset" ] && B_IUSE="${IUSE}"
1185 [ "${DEPEND-unset}" != "unset" ] && B_DEPEND="${DEPEND}"
1186 [ "${RDEPEND-unset}" != "unset" ] && B_RDEPEND="${RDEPEND}"
1187 [ "${PDEPEND-unset}" != "unset" ] && B_PDEPEND="${PDEPEND}"
1188 unset IUSE DEPEND RDEPEND PDEPEND
1189 #turn on glob expansion
1192 qa_source "$location" || die "died sourcing $location in inherit()"
1194 #turn off glob expansion
1197 # If each var has a value, append it to the global variable E_* to
1198 # be applied after everything is finished. New incremental behavior.
1199 [ "${IUSE-unset}" != "unset" ] && export E_IUSE="${E_IUSE} ${IUSE}"
1200 [ "${DEPEND-unset}" != "unset" ] && export E_DEPEND="${E_DEPEND} ${DEPEND}"
1201 [ "${RDEPEND-unset}" != "unset" ] && export E_RDEPEND="${E_RDEPEND} ${RDEPEND}"
1202 [ "${PDEPEND-unset}" != "unset" ] && export E_PDEPEND="${E_PDEPEND} ${PDEPEND}"
1204 [ "${B_IUSE-unset}" != "unset" ] && IUSE="${B_IUSE}"
1205 [ "${B_IUSE-unset}" != "unset" ] || unset IUSE
1207 [ "${B_DEPEND-unset}" != "unset" ] && DEPEND="${B_DEPEND}"
1208 [ "${B_DEPEND-unset}" != "unset" ] || unset DEPEND
1210 [ "${B_RDEPEND-unset}" != "unset" ] && RDEPEND="${B_RDEPEND}"
1211 [ "${B_RDEPEND-unset}" != "unset" ] || unset RDEPEND
1213 [ "${B_PDEPEND-unset}" != "unset" ] && PDEPEND="${B_PDEPEND}"
1214 [ "${B_PDEPEND-unset}" != "unset" ] || unset PDEPEND
1216 #turn on glob expansion
1219 hasq $1 $INHERITED || export INHERITED="$INHERITED $1"
1221 export ECLASS="$PECLASS"
1225 ((--ECLASS_DEPTH)) # Returns 1 when ECLASS_DEPTH reaches 0.
1229 # Exports stub functions that call the eclass's functions, thereby making them default.
1230 # For example, if ECLASS="base" and you call "EXPORT_FUNCTIONS src_unpack", the following
1231 # code will be eval'd:
1232 # src_unpack() { base_src_unpack; }
1233 EXPORT_FUNCTIONS() {
1234 if [ -z "$ECLASS" ]; then
1235 echo "EXPORT_FUNCTIONS without a defined ECLASS" >&2
1239 debug-print "EXPORT_FUNCTIONS: ${1} -> ${ECLASS}_${1}"
1240 eval "$1() { ${ECLASS}_$1 "\$@" ; }" > /dev/null
1245 # adds all parameters to E_DEPEND and E_RDEPEND, which get added to DEPEND
1246 # and RDEPEND after the ebuild has been processed. This is important to
1247 # allow users to use DEPEND="foo" without frying dependencies added by an
1248 # earlier inherit. It also allows RDEPEND to work properly, since a lot
1249 # of ebuilds assume that an unset RDEPEND gets its value from DEPEND.
1250 # Without eclasses, this is true. But with them, the eclass may set
1251 # RDEPEND itself (or at least used to) which would prevent RDEPEND from
1252 # getting its value from DEPEND. This is a side-effect that made eclasses
1253 # have unreliable dependencies.
1256 debug-print-function newdepend $*
1257 debug-print "newdepend: E_DEPEND=$E_DEPEND E_RDEPEND=$E_RDEPEND"
1259 while [ -n "$1" ]; do
1262 do_newdepend DEPEND sys-devel/autoconf sys-devel/automake sys-devel/make
1265 do_newdepend DEPEND sys-devel/gcc virtual/libc
1266 do_newdepend RDEPEND virtual/libc
1269 do_newdepend DEPEND $1
1277 debug-print-function newrdepend $*
1278 do_newdepend RDEPEND $1
1282 debug-print-function newpdepend $*
1283 do_newdepend PDEPEND $1
1287 # This function does a generic change determining whether we're in an
1288 # eclass or not. If we are, we change the E_* variables for deps.
1289 debug-print-function do_newdepend $*
1290 [ -z "$1" ] && die "do_newdepend without arguments"
1292 # Grab what we're affecting... Figure out if we're affecting eclasses.
1293 [[ ${ECLASS_DEPTH} > 0 ]] && TARGET="E_$1"
1294 [[ ${ECLASS_DEPTH} > 0 ]] || TARGET="$1"
1295 shift # $1 was a variable name.
1297 while [ -n "$1" ]; do
1298 # This bit of evil takes TARGET and uses it to evaluate down to a
1299 # variable. This is a sneaky way to make this infinately expandable.
1300 # The normal translation of this would look something like this:
1301 # E_DEPEND="${E_DEPEND} $1" :::::: Cool, huh? :)
1302 eval export ${TARGET}=\"\${${TARGET}} \$1\"
1307 # this is a function for removing any directory matching a passed in pattern from
1309 remove_path_entry() {
1312 stripped_path="${PATH}"
1313 while [ -n "$1" ]; do
1315 for p in ${stripped_path}; do
1316 if [ "${p/${1}}" == "${p}" ]; then
1317 cur_path="${cur_path}:${p}"
1320 stripped_path="${cur_path#:*}"
1324 PATH="${stripped_path}"
1327 source_all_bashrcs() {
1328 local OCC="${CC}" OCXX="${CXX}"
1329 # source the existing profile.bashrc's.
1333 for x in ${PROFILE_PATHS}; do
1334 # Must unset it so that it doesn't mess up assumptions in the RCs.
1336 [ -f "${x}/profile.bashrc" ] && qa_source "${x}/profile.bashrc"
1340 # We assume if people are changing shopts in their bashrc they do so at their
1341 # own peril. This is the ONLY non-portage bit of code that can change shopts
1342 # without a QA violation.
1343 if [ -f "${PORTAGE_BASHRC}" ]; then
1344 # If $- contains x, then tracing has already enabled elsewhere for some
1345 # reason. We preserve it's state so as not to interfere.
1346 if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then
1347 source "${PORTAGE_BASHRC}"
1350 source "${PORTAGE_BASHRC}"
1354 [ ! -z "${OCC}" ] && export CC="${OCC}"
1355 [ ! -z "${OCXX}" ] && export CXX="${OCXX}"
1358 # Hardcoded bash lists are needed for backward compatibility with
1359 # <portage-2.1.4 since they assume that a newly installed version
1360 # of ebuild.sh will work for pkg_postinst, pkg_prerm, and pkg_postrm
1361 # when portage is upgrading itself.
1363 READONLY_EBUILD_METADATA="DEPEND DESCRIPTION
1364 EAPI HOMEPAGE INHERITED IUSE KEYWORDS LICENSE
1365 PDEPEND PROVIDE RDEPEND RESTRICT SLOT SRC_URI"
1367 READONLY_PORTAGE_VARS="D EBUILD EBUILD_PHASE \
1368 EBUILD_SH_ARGS EMERGE_FROM FILESDIR PORTAGE_BINPKG_FILE \
1369 PORTAGE_BIN_PATH PORTAGE_IUSE \
1370 PORTAGE_PYM_PATH PORTAGE_MUTABLE_FILTERED_VARS \
1371 PORTAGE_SAVED_READONLY_VARS PORTAGE_TMPDIR T WORKDIR"
1373 PORTAGE_SAVED_READONLY_VARS="A CATEGORY P PF PN PR PV PVR"
1375 # Variables that portage sets but doesn't mark readonly.
1376 # In order to prevent changed values from causing unexpected
1377 # interference, they are filtered out of the environment when
1378 # it is saved or loaded (any mutations do not persist).
1379 PORTAGE_MUTABLE_FILTERED_VARS="AA HOSTNAME"
1381 # @FUNCTION: filter_readonly_variables
1382 # @DESCRIPTION: [--filter-sandbox] [--allow-extra-vars]
1383 # Read an environment from stdin and echo to stdout while filtering readonly
1386 # --filter-sandbox causes all SANDBOX_* variables to be filtered, which
1387 # is only desired in certain cases, such as during preprocessing or when
1388 # saving environment.bz2 for a binary or installed package.
1390 # --filter-features causes the special FEATURES variable to be filtered.
1391 # Generally, we want it to persist between phases since the user might
1392 # want to modify it via bashrc to enable things like splitdebug and
1393 # installsources for specific packages. They should be able to modify it
1394 # in pre_pkg_setup() and have it persist all the way through the install
1395 # phase. However, if FEATURES exist inside environment.bz2 then they
1396 # should be overridden by current settings.
1398 # ---allow-extra-vars causes some extra vars to be allowd through, such
1399 # as ${PORTAGE_SAVED_READONLY_VARS} and ${PORTAGE_MUTABLE_FILTERED_VARS}.
1401 # In bash-3.2_p20+ an attempt to assign BASH_*, FUNCNAME, GROUPS or any
1402 # readonly variable cause the shell to exit while executing the "source"
1403 # builtin command. To avoid this problem, this function filters those
1404 # variables out and discards them. See bug #190128.
1405 filter_readonly_variables() {
1406 local x filtered_vars var_grep
1407 local readonly_bash_vars="DIRSTACK EUID FUNCNAME GROUPS
1408 PIPESTATUS PPID SHELLOPTS UID"
1409 local filtered_sandbox_vars="SANDBOX_ACTIVE SANDBOX_BASHRC
1410 SANDBOX_DEBUG_LOG SANDBOX_DISABLED SANDBOX_LIB
1411 SANDBOX_LOG SANDBOX_ON"
1412 filtered_vars="${readonly_bash_vars} ${READONLY_PORTAGE_VARS}
1413 BASH_[_[:alnum:]]* PATH"
1414 if hasq --filter-sandbox $* ; then
1415 filtered_vars="${filtered_vars} SANDBOX_[_[:alnum:]]*"
1417 filtered_vars="${filtered_vars} ${filtered_sandbox_vars}"
1419 if hasq --filter-features $* ; then
1420 filtered_vars="${filtered_vars} FEATURES"
1422 if ! hasq --allow-extra-vars $* ; then
1425 ${PORTAGE_SAVED_READONLY_VARS}
1426 ${PORTAGE_MUTABLE_FILTERED_VARS}
1430 for x in ${filtered_vars} ; do
1431 var_grep="${var_grep}|${x}"
1434 var_grep=${var_grep:1} # strip the first |
1435 var_grep="(^|^declare[[:space:]]+-[^[:space:]]+[[:space:]]+|^export[[:space:]]+)(${var_grep})=.*"
1436 # The sed is to remove the readonly attribute from variables such as those
1437 # listed in READONLY_EBUILD_METADATA, since having any readonly attributes
1438 # persisting in the saved environment can be inconvenient when it
1439 # eventually needs to be reloaded.
1440 "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${var_grep}" | sed -r \
1441 -e 's:^declare[[:space:]]+-r[[:space:]]+:declare :' \
1442 -e 's:^declare[[:space:]]+-([[:alnum:]]*)r([[:alnum:]]*)[[:space:]]+:declare -\1\2 :'
1445 # @FUNCTION: preprocess_ebuild_env
1447 # Filter any readonly variables from ${T}/environment, source it, and then
1448 # save it via save_ebuild_env(). This process should be sufficient to prevent
1449 # any stale variables or functions from an arbitrary environment from
1450 # interfering with the current environment. This is useful when an existing
1451 # environment needs to be loaded from a binary or installed package.
1452 preprocess_ebuild_env() {
1453 local filter_opts=""
1454 if [ -f "${T}/environment.raw" ] ; then
1455 # This is a signal from the python side, indicating that the
1456 # environment may contain stale SANDBOX_{DENY,PREDICT,READ,WRITE}
1457 # and FEATURES variables that should be filtered out. Between
1458 # phases, these variables are normally preserved.
1459 filter_opts="--filter-sandbox --filter-features ${filter_opts}"
1461 filter_readonly_variables ${filter_opts} < "${T}"/environment \
1462 > "${T}"/environment.filtered || return $?
1464 mv "${T}"/environment.filtered "${T}"/environment || return $?
1465 rm -f "${T}/environment.success" || return $?
1466 # WARNING: Code inside this subshell should avoid making assumptions
1467 # about variables or functions after source "${T}"/environment has been
1468 # called. Any variables that need to be relied upon should already be
1469 # filtered out above.
1472 source "${T}/environment" || exit $?
1473 # We have to temporarily disable sandbox since the
1474 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
1475 # may be unusable (triggering in spurious sandbox violations)
1476 # until we've merged them with our current values.
1479 # It's remotely possible that save_ebuild_env() has been overridden
1480 # by the above source command. To protect ourselves, we override it
1481 # here with our own version. ${PORTAGE_BIN_PATH} is safe to use here
1482 # because it's already filtered above.
1483 source "${PORTAGE_BIN_PATH}/isolated-functions.sh" || exit $?
1485 # Rely on save_ebuild_env() to filter out any remaining variables
1486 # and functions that could interfere with the current environment.
1487 save_ebuild_env || exit $?
1488 touch "${T}/environment.success" || exit $?
1489 ) > "${T}/environment.filtered"
1491 if [ -e "${T}/environment.success" ] ; then
1492 filter_readonly_variables < \
1493 "${T}/environment.filtered" > "${T}/environment"
1498 rm -f "${T}"/environment.{filtered,raw,success}
1502 # === === === === === === === === === === === === === === === === === ===
1503 # === === === === === functions end, main part begins === === === === ===
1504 # === === === === === functions end, main part begins === === === === ===
1505 # === === === === === functions end, main part begins === === === === ===
1506 # === === === === === === === === === === === === === === === === === ===
1508 if [ -n "${EBUILD_SH_ARGS}" ] && \
1509 ! hasq ${EBUILD_SH_ARGS} clean depend help info nofetch ; then
1511 if [ "$(id -nu)" == "portage" ] ; then
1515 if hasq distcc ${FEATURES} ; then
1516 if [ -d /usr/lib/distcc/bin ]; then
1517 #We can enable distributed compile support
1518 if [ -z "${PATH/*distcc*/}" ]; then
1519 # Remove the other reference.
1520 remove_path_entry "distcc"
1522 export PATH="/usr/lib/distcc/bin:${PATH}"
1523 [ ! -z "${DISTCC_LOG}" ] && addwrite "$(dirname ${DISTCC_LOG})"
1524 elif which distcc &>/dev/null; then
1525 if ! hasq distcc $CC; then
1526 export CC="distcc $CC"
1528 if ! hasq distcc $CXX; then
1529 export CXX="distcc $CXX"
1534 if hasq ccache ${FEATURES} ; then
1535 #We can enable compiler cache support
1536 if [ -z "${PATH/*ccache*/}" ]; then
1537 # Remove the other reference.
1538 remove_path_entry "ccache"
1541 if [ -d /usr/lib/ccache/bin ]; then
1542 export PATH="/usr/lib/ccache/bin:${PATH}"
1543 elif [ -d /usr/bin/ccache ]; then
1544 export PATH="/usr/bin/ccache:${PATH}"
1547 [ -z "${CCACHE_DIR}" ] && export CCACHE_DIR="/var/tmp/ccache"
1549 addread "${CCACHE_DIR}"
1550 addwrite "${CCACHE_DIR}"
1552 [ -n "${CCACHE_SIZE}" ] && ccache -M ${CCACHE_SIZE} &> /dev/null
1554 # Force configure scripts that automatically detect ccache to respect
1555 # FEATURES="-ccache"
1556 export CCACHE_DISABLE=1
1559 # XXX: Load up the helper functions.
1560 # for X in /usr/lib/portage/bin/functions/*.sh; do
1561 # source ${X} || die "Failed to source ${X}"
1568 kill ${PORTAGE_MASTER_PID}
1570 trap "killparent" INT
1572 fi # "$*"!="depend" && "$*"!="clean" && "$*" != "setup"
1574 export SANDBOX_ON="1"
1575 export S=${WORKDIR}/${P}
1577 unset E_IUSE E_DEPEND E_RDEPEND E_PDEPEND
1579 # Turn of extended glob matching so that g++ doesn't get incorrectly matched.
1582 QA_INTERCEPTORS="javac java-config python python-config perl grep egrep fgrep sed gcc g++ cc bash awk nawk gawk pkg-config"
1583 # level the QA interceptors if we're in depend
1584 if hasq "depend" "${EBUILD_SH_ARGS}"; then
1585 for BIN in ${QA_INTERCEPTORS}; do
1586 BIN_PATH=$(type -Pf ${BIN})
1587 if [ "$?" != "0" ]; then
1588 BODY="echo \"*** missing command: ${BIN}\" >&2; return 127"
1590 BODY="${BIN_PATH} \"\$@\"; return \$?"
1592 FUNC_SRC="${BIN}() {
1593 if [ \$ECLASS_DEPTH -gt 0 ]; then
1594 eqawarn \"QA Notice: '${BIN}' called in global scope: eclass \${ECLASS}\"
1596 eqawarn \"QA Notice: '${BIN}' called in global scope: \${CATEGORY}/\${PF}\"
1600 eval "$FUNC_SRC" || echo "error creating QA interceptor ${BIN}" >&2
1602 unset BIN_PATH BIN BODY FUNC_SRC
1605 if ! hasq ${EBUILD_PHASE} clean depend && \
1606 [ -f "${T}"/environment ] ; then
1607 # The environment may have been extracted from environment.bz2 or
1608 # may have come from another version of ebuild.sh or something.
1609 # In any case, preprocess it to prevent any potential interference.
1610 preprocess_ebuild_env || \
1611 die "error processing environment"
1612 # Colon separated SANDBOX_* variables need to be cumulative.
1613 for x in SANDBOX_DENY SANDBOX_READ SANDBOX_PREDICT SANDBOX_WRITE ; do
1614 eval PORTAGE_${x}=\${!x}
1616 PORTAGE_SANDBOX_ON=${SANDBOX_ON}
1618 source "${T}"/environment || \
1619 die "error sourcing environment"
1620 # We have to temporarily disable sandbox since the
1621 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
1622 # may be unusable (triggering in spurious sandbox violations)
1623 # until we've merged them with our current values.
1625 for x in SANDBOX_DENY SANDBOX_PREDICT SANDBOX_READ SANDBOX_WRITE ; do
1626 eval y=\${PORTAGE_${x}}
1627 if [ "${y}" != "${!x}" ] ; then
1628 eval export ${x}=\"$(echo -n "${y}:${!x}" | tr ":" "\0" | \
1629 sort -z -u | tr "\0" ":")\"
1634 export SANDBOX_ON=${PORTAGE_SANDBOX_ON}
1635 unset PORTAGE_SANDBOX_ON
1637 # After loading the environment, make sure the color variables
1638 # are in sync with the current NOCOLOR setting.
1639 case "${NOCOLOR:-false}" in
1651 if ! hasq ${EBUILD_PHASE} clean && \
1653 hasq ${EBUILD_PHASE} depend || \
1654 [ ! -f "${T}"/environment ] || \
1655 hasq noauto ${FEATURES}
1657 # The bashrcs get an opportunity here to set aliases that will be expanded
1658 # during sourcing of ebuilds and eclasses.
1661 # *DEPEND and IUSE will be set during the sourcing of the ebuild.
1662 # In order to ensure correct interaction between ebuilds and
1663 # eclasses, they need to be unset before this process of
1664 # interaction begins.
1665 unset DEPEND RDEPEND PDEPEND IUSE
1666 source "${EBUILD}" || die "error sourcing ebuild"
1668 if [ "${EBUILD_PHASE}" != "depend" ] ; then
1669 RESTRICT=${PORTAGE_RESTRICT}
1672 # This next line is not the same as export RDEPEND=${RDEPEND:-${DEPEND}}
1673 # That will test for unset *or* NULL (""). We want just to set for unset...
1674 # turn off glob expansion from here on in to prevent *'s and ? in the
1675 # DEPEND syntax from getting expanded :)
1677 if [ "${RDEPEND-unset}" == "unset" ] ; then
1678 export RDEPEND=${DEPEND}
1679 debug-print "RDEPEND: not set... Setting to: ${DEPEND}"
1682 # add in dependency info from eclasses
1683 IUSE="${IUSE} ${E_IUSE}"
1684 DEPEND="${DEPEND} ${E_DEPEND}"
1685 RDEPEND="${RDEPEND} ${E_RDEPEND}"
1686 PDEPEND="${PDEPEND} ${E_PDEPEND}"
1688 unset ECLASS E_IUSE E_DEPEND E_RDEPEND E_PDEPEND
1690 if [ "${EBUILD_PHASE}" != "depend" ] ; then
1691 # Make IUSE defaults backward compatible with all the old shell code.
1693 for x in ${IUSE} ; do
1694 if [[ ${x} == +* ]] || [[ ${x} == -* ]] ; then
1695 iuse_temp="${iuse_temp} ${x:1}"
1697 iuse_temp="${iuse_temp} ${x}"
1700 export IUSE=${iuse_temp}
1706 # unset USE_EXPAND variables that contain only the special "*" token
1707 for x in ${USE_EXPAND} ; do
1708 [ "${!x}" == "*" ] && unset ${x}
1712 if hasq nostrip ${FEATURES} ${RESTRICT} || hasq strip ${RESTRICT}
1717 #a reasonable default for $S
1718 [[ -z ${S} ]] && export S=${WORKDIR}/${P}
1720 #wipe the interceptors. we don't want saved.
1721 if hasq "depend" "${EBUILD_SH_ARGS}"; then
1722 unset -f $QA_INTERCEPTORS
1723 unset QA_INTERCEPTORS
1726 #some users have $TMP/$TMPDIR to a custom dir in their home ...
1727 #this will cause sandbox errors with some ./configure
1728 #scripts, so set it to $T.
1730 export TMPDIR="${T}"
1732 # Note: readonly variables interfere with preprocess_ebuild_env(), so
1733 # declare them only after it has already run.
1734 if [ "${EBUILD_PHASE}" != "depend" ] ; then
1735 declare -r ${READONLY_EBUILD_METADATA} ${READONLY_PORTAGE_VARS}
1738 if [ -n "${EBUILD_SH_ARGS}" ] ; then
1739 case ${EBUILD_SH_ARGS} in
1741 ebuild_phase_with_hooks pkg_nofetch
1744 prerm|postrm|postinst|config|info)
1745 if hasq ${EBUILD_SH_ARGS} config info && \
1746 [ "$(type -t pkg_${EBUILD_SH_ARGS})" != "function" ]; then
1747 ewarn "pkg_${EBUILD_SH_ARGS}() is not defined: '${EBUILD##*/}'"
1749 export SANDBOX_ON="0"
1750 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
1751 ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
1754 ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
1758 unpack|compile|test|clean|install)
1759 if [ "${SANDBOX_DISABLED="0"}" == "0" ]; then
1760 export SANDBOX_ON="1"
1762 export SANDBOX_ON="0"
1764 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
1765 dyn_${EBUILD_SH_ARGS}
1768 dyn_${EBUILD_SH_ARGS}
1771 export SANDBOX_ON="0"
1774 #pkg_setup needs to be out of the sandbox for tmp file creation;
1775 #for example, awking and piping a file in /tmp requires a temp file to be created
1776 #in /etc. If pkg_setup is in the sandbox, both our lilo and apache ebuilds break.
1777 export SANDBOX_ON="0"
1778 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
1779 dyn_${EBUILD_SH_ARGS}
1782 dyn_${EBUILD_SH_ARGS}
1787 export SANDBOX_ON="0"
1790 if [ -n "${dbkey}" ] ; then
1791 if [ ! -d "${dbkey%/*}" ]; then
1792 install -d -g ${PORTAGE_GID} -m2775 "${dbkey%/*}"
1794 # Make it group writable. 666&~002==664
1798 auxdbkeys="DEPEND RDEPEND SLOT SRC_URI RESTRICT HOMEPAGE LICENSE
1799 DESCRIPTION KEYWORDS INHERITED IUSE CDEPEND PDEPEND PROVIDE EAPI
1800 UNUSED_01 UNUSED_02 UNUSED_03 UNUSED_04 UNUSED_05 UNUSED_06
1803 #the extra $(echo) commands remove newlines
1805 [ -n "${EAPI}" ] || EAPI=0
1806 if [ -n "${dbkey}" ] ; then
1808 for f in ${auxdbkeys} ; do
1809 echo $(echo ${!f}) >> "${dbkey}" || exit $?
1812 for f in ${auxdbkeys} ; do
1813 echo $(echo ${!f}) 1>&9 || exit $?
1820 export SANDBOX_ON="1"
1821 echo "Unrecognized EBUILD_SH_ARGS: '${EBUILD_SH_ARGS}'"
1827 [ -n "${EBUILD_EXIT_STATUS_FILE}" ] && \
1828 touch "${EBUILD_EXIT_STATUS_FILE}" &>/dev/null
1831 # Save the env only for relevant phases.
1832 if [ -n "${EBUILD_SH_ARGS}" ] && \
1833 ! hasq ${EBUILD_SH_ARGS} clean depend help info nofetch ; then
1834 # Save current environment and touch a success file. (echo for success)
1836 save_ebuild_env | filter_readonly_variables > "${T}/environment"
1837 chown portage:portage "${T}/environment" &>/dev/null
1838 chmod g+w "${T}/environment" &>/dev/null
1841 # Do not exit when ebuild.sh is sourced by other scripts.