2 # Copyright 1999-2011 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
5 # Hardcoded bash lists are needed for backward compatibility with
6 # <portage-2.1.4 since they assume that a newly installed version
7 # of ebuild.sh will work for pkg_postinst, pkg_prerm, and pkg_postrm
8 # when portage is upgrading itself.
10 PORTAGE_READONLY_METADATA="DEFINED_PHASES DEPEND DESCRIPTION
11 EAPI HOMEPAGE INHERITED IUSE REQUIRED_USE KEYWORDS LICENSE
12 PDEPEND PROVIDE RDEPEND RESTRICT SLOT SRC_URI"
14 PORTAGE_READONLY_VARS="D EBUILD EBUILD_PHASE \
15 EBUILD_SH_ARGS ECLASSDIR EMERGE_FROM FILESDIR MERGE_TYPE \
17 PORTAGE_ACTUAL_DISTDIR PORTAGE_ARCHLIST PORTAGE_BASHRC \
18 PORTAGE_BINPKG_FILE PORTAGE_BINPKG_TAR_OPTS PORTAGE_BINPKG_TMPFILE \
19 PORTAGE_BIN_PATH PORTAGE_BUILDDIR PORTAGE_BUNZIP2_COMMAND \
20 PORTAGE_BZIP2_COMMAND PORTAGE_COLORMAP PORTAGE_CONFIGROOT \
21 PORTAGE_DEBUG PORTAGE_DEPCACHEDIR PORTAGE_EBUILD_EXIT_FILE \
22 PORTAGE_GID PORTAGE_GRPNAME PORTAGE_INST_GID PORTAGE_INST_UID \
23 PORTAGE_IPC_DAEMON PORTAGE_IUSE PORTAGE_LOG_FILE \
24 PORTAGE_MUTABLE_FILTERED_VARS PORTAGE_PYM_PATH PORTAGE_PYTHON \
25 PORTAGE_READONLY_METADATA PORTAGE_READONLY_VARS \
26 PORTAGE_REPO_NAME PORTAGE_RESTRICT PORTAGE_SANDBOX_COMPAT_LEVEL \
27 PORTAGE_SAVED_READONLY_VARS PORTAGE_SIGPIPE_STATUS \
28 PORTAGE_TMPDIR PORTAGE_UPDATE_ENV PORTAGE_USERNAME \
29 PORTAGE_VERBOSE PORTAGE_WORKDIR_MODE PORTDIR PORTDIR_OVERLAY \
30 PROFILE_PATHS REPLACING_VERSIONS REPLACED_BY_VERSION T WORKDIR"
32 PORTAGE_SAVED_READONLY_VARS="A CATEGORY P PF PN PR PV PVR"
34 # Variables that portage sets but doesn't mark readonly.
35 # In order to prevent changed values from causing unexpected
36 # interference, they are filtered out of the environment when
37 # it is saved or loaded (any mutations do not persist).
38 PORTAGE_MUTABLE_FILTERED_VARS="AA HOSTNAME"
40 # @FUNCTION: filter_readonly_variables
41 # @DESCRIPTION: [--filter-sandbox] [--allow-extra-vars]
42 # Read an environment from stdin and echo to stdout while filtering variables
43 # with names that are known to cause interference:
45 # * some specific variables for which bash does not allow assignment
46 # * some specific variables that affect portage or sandbox behavior
47 # * variable names that begin with a digit or that contain any
48 # non-alphanumeric characters that are not be supported by bash
50 # --filter-sandbox causes all SANDBOX_* variables to be filtered, which
51 # is only desired in certain cases, such as during preprocessing or when
52 # saving environment.bz2 for a binary or installed package.
54 # --filter-features causes the special FEATURES variable to be filtered.
55 # Generally, we want it to persist between phases since the user might
56 # want to modify it via bashrc to enable things like splitdebug and
57 # installsources for specific packages. They should be able to modify it
58 # in pre_pkg_setup() and have it persist all the way through the install
59 # phase. However, if FEATURES exist inside environment.bz2 then they
60 # should be overridden by current settings.
62 # --filter-locale causes locale related variables such as LANG and LC_*
63 # variables to be filtered. These variables should persist between phases,
64 # in case they are modified by the ebuild. However, the current user
65 # settings should be used when loading the environment from a binary or
68 # --filter-path causes the PATH variable to be filtered. This variable
69 # should persist between phases, in case it is modified by the ebuild.
70 # However, old settings should be overridden when loading the
71 # environment from a binary or installed package.
73 # ---allow-extra-vars causes some extra vars to be allowd through, such
74 # as ${PORTAGE_SAVED_READONLY_VARS} and ${PORTAGE_MUTABLE_FILTERED_VARS}.
76 # In bash-3.2_p20+ an attempt to assign BASH_*, FUNCNAME, GROUPS or any
77 # readonly variable cause the shell to exit while executing the "source"
78 # builtin command. To avoid this problem, this function filters those
79 # variables out and discards them. See bug #190128.
80 filter_readonly_variables() {
82 local readonly_bash_vars="BASHOPTS BASHPID DIRSTACK EUID
83 FUNCNAME GROUPS PIPESTATUS PPID SHELLOPTS UID"
84 local bash_misc_vars="BASH BASH_.* COMP_WORDBREAKS HISTCMD
85 HISTFILE HOSTNAME HOSTTYPE IFS LINENO MACHTYPE OLDPWD
86 OPTERR OPTIND OSTYPE POSIXLY_CORRECT PS4 PWD RANDOM
87 SECONDS SHELL SHLVL _"
88 local filtered_sandbox_vars="SANDBOX_ACTIVE SANDBOX_BASHRC
89 SANDBOX_DEBUG_LOG SANDBOX_DISABLED SANDBOX_LIB
90 SANDBOX_LOG SANDBOX_ON"
91 local misc_garbage_vars="_portage_filter_opts"
92 filtered_vars="$readonly_bash_vars $bash_misc_vars
93 $PORTAGE_READONLY_VARS $misc_garbage_vars"
95 # Don't filter/interfere with prefix variables unless they are
96 # supported by the current EAPI.
99 [[ " ${USE} " == *" prefix "* ]] && \
100 filtered_vars+=" ED EPREFIX EROOT"
103 filtered_vars+=" ED EPREFIX EROOT"
107 if has --filter-sandbox $* ; then
108 filtered_vars="${filtered_vars} SANDBOX_.*"
110 filtered_vars="${filtered_vars} ${filtered_sandbox_vars}"
112 if has --filter-features $* ; then
113 filtered_vars="${filtered_vars} FEATURES PORTAGE_FEATURES"
115 if has --filter-path $* ; then
116 filtered_vars+=" PATH"
118 if has --filter-locale $* ; then
119 filtered_vars+=" LANG LC_ALL LC_COLLATE
120 LC_CTYPE LC_MESSAGES LC_MONETARY
121 LC_NUMERIC LC_PAPER LC_TIME"
123 if ! has --allow-extra-vars $* ; then
126 ${PORTAGE_SAVED_READONLY_VARS}
127 ${PORTAGE_MUTABLE_FILTERED_VARS}
131 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}" || die "filter-bash-environment.py failed"
134 # @FUNCTION: preprocess_ebuild_env
136 # Filter any readonly variables from ${T}/environment, source it, and then
137 # save it via save_ebuild_env(). This process should be sufficient to prevent
138 # any stale variables or functions from an arbitrary environment from
139 # interfering with the current environment. This is useful when an existing
140 # environment needs to be loaded from a binary or installed package.
141 preprocess_ebuild_env() {
142 local _portage_filter_opts="--filter-features --filter-locale --filter-path --filter-sandbox"
144 # If environment.raw is present, this is a signal from the python side,
145 # indicating that the environment may contain stale FEATURES and
146 # SANDBOX_{DENY,PREDICT,READ,WRITE} variables that should be filtered out.
147 # Otherwise, we don't need to filter the environment.
148 [ -f "${T}/environment.raw" ] || return 0
150 filter_readonly_variables $_portage_filter_opts < "${T}"/environment \
151 >> "$T/environment.filtered" || return $?
152 unset _portage_filter_opts
153 mv "${T}"/environment.filtered "${T}"/environment || return $?
154 rm -f "${T}/environment.success" || return $?
155 # WARNING: Code inside this subshell should avoid making assumptions
156 # about variables or functions after source "${T}"/environment has been
157 # called. Any variables that need to be relied upon should already be
158 # filtered out above.
161 source "${T}/environment" || exit $?
162 # We have to temporarily disable sandbox since the
163 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
164 # may be unusable (triggering in spurious sandbox violations)
165 # until we've merged them with our current values.
168 # It's remotely possible that save_ebuild_env() has been overridden
169 # by the above source command. To protect ourselves, we override it
170 # here with our own version. ${PORTAGE_BIN_PATH} is safe to use here
171 # because it's already filtered above.
172 source "${PORTAGE_BIN_PATH}/save-ebuild-env.sh" || exit $?
174 # Rely on save_ebuild_env() to filter out any remaining variables
175 # and functions that could interfere with the current environment.
176 save_ebuild_env || exit $?
177 >> "$T/environment.success" || exit $?
178 ) > "${T}/environment.filtered"
180 if [ -e "${T}/environment.success" ] ; then
181 filter_readonly_variables --filter-features < \
182 "${T}/environment.filtered" > "${T}/environment"
187 rm -f "${T}"/environment.{filtered,raw,success}
192 declare -F "$1" >/dev/null && qa_call $1
195 ebuild_phase_with_hooks() {
196 local x phase_name=${1}
197 for x in {pre_,,post_}${phase_name} ; do
203 if [[ -e $PORTAGE_BUILDDIR/.pretended ]] ; then
204 vecho ">>> It appears that '$PF' is already pretended; skipping."
205 vecho ">>> Remove '$PORTAGE_BUILDDIR/.pretended' to force pretend."
208 ebuild_phase pre_pkg_pretend
209 ebuild_phase pkg_pretend
210 >> "$PORTAGE_BUILDDIR/.pretended" || \
211 die "Failed to create $PORTAGE_BUILDDIR/.pretended"
212 ebuild_phase post_pkg_pretend
216 if [[ -e $PORTAGE_BUILDDIR/.setuped ]] ; then
217 vecho ">>> It appears that '$PF' is already setup; skipping."
218 vecho ">>> Remove '$PORTAGE_BUILDDIR/.setuped' to force setup."
221 ebuild_phase pre_pkg_setup
222 ebuild_phase pkg_setup
223 >> "$PORTAGE_BUILDDIR/.setuped" || \
224 die "Failed to create $PORTAGE_BUILDDIR/.setuped"
225 ebuild_phase post_pkg_setup
229 if [[ -f ${PORTAGE_BUILDDIR}/.unpacked ]] ; then
230 vecho ">>> WORKDIR is up-to-date, keeping..."
233 if [ ! -d "${WORKDIR}" ]; then
234 install -m${PORTAGE_WORKDIR_MODE:-0700} -d "${WORKDIR}" || die "Failed to create dir '${WORKDIR}'"
236 cd "${WORKDIR}" || die "Directory change failed: \`cd '${WORKDIR}'\`"
237 ebuild_phase pre_src_unpack
238 vecho ">>> Unpacking source..."
239 ebuild_phase src_unpack
240 >> "$PORTAGE_BUILDDIR/.unpacked" || \
241 die "Failed to create $PORTAGE_BUILDDIR/.unpacked"
242 vecho ">>> Source unpacked in ${WORKDIR}"
243 ebuild_phase post_src_unpack
247 if [ -z "${PORTAGE_BUILDDIR}" ]; then
248 echo "Aborting clean phase because PORTAGE_BUILDDIR is unset!"
250 elif [ ! -d "${PORTAGE_BUILDDIR}" ] ; then
253 if has chflags $FEATURES ; then
254 chflags -R noschg,nouchg,nosappnd,nouappnd "${PORTAGE_BUILDDIR}"
255 chflags -R nosunlnk,nouunlnk "${PORTAGE_BUILDDIR}" 2>/dev/null
258 rm -rf "${PORTAGE_BUILDDIR}/image" "${PORTAGE_BUILDDIR}/homedir"
259 rm -f "${PORTAGE_BUILDDIR}/.installed"
261 if [[ $EMERGE_FROM = binary ]] || \
262 ! has keeptemp $FEATURES && ! has keepwork $FEATURES ; then
266 if [[ $EMERGE_FROM = binary ]] || ! has keepwork $FEATURES; then
267 rm -f "$PORTAGE_BUILDDIR"/.{ebuild_changed,logid,pretended,setuped,unpacked,prepared} \
268 "$PORTAGE_BUILDDIR"/.{configured,compiled,tested,packaged} \
269 "$PORTAGE_BUILDDIR"/.die_hooks \
270 "$PORTAGE_BUILDDIR"/.ipc_{in,out,lock} \
271 "$PORTAGE_BUILDDIR"/.exit_status
273 rm -rf "${PORTAGE_BUILDDIR}/build-info"
277 if [ -f "${PORTAGE_BUILDDIR}/.unpacked" ]; then
278 find "${PORTAGE_BUILDDIR}" -type d ! -regex "^${WORKDIR}" | sort -r | tr "\n" "\0" | $XARGS -0 rmdir &>/dev/null
281 # do not bind this to doebuild defined DISTDIR; don't trust doebuild, and if mistakes are made it'll
282 # result in it wiping the users distfiles directory (bad).
283 rm -rf "${PORTAGE_BUILDDIR}/distdir"
285 # Some kernels, such as Solaris, return EINVAL when an attempt
286 # is made to remove the current working directory.
287 cd "$PORTAGE_BUILDDIR"/../..
288 rmdir "$PORTAGE_BUILDDIR" 2>/dev/null
295 if [ "$2" != "fail" ]; then
296 msg="${EBUILD}: ${1} aborted; exiting."
298 msg="${EBUILD}: ${1} failed; exiting."
304 #unset signal handler
305 trap - SIGINT SIGQUIT
309 abort_handler src_prepare $1
310 rm -f "$PORTAGE_BUILDDIR/.prepared"
315 abort_handler src_configure $1
316 rm -f "$PORTAGE_BUILDDIR/.configured"
321 abort_handler "src_compile" $1
322 rm -f "${PORTAGE_BUILDDIR}/.compiled"
327 abort_handler "dyn_test" $1
328 rm -f "${PORTAGE_BUILDDIR}/.tested"
333 abort_handler "src_install" $1
334 rm -rf "${PORTAGE_BUILDDIR}/image"
338 has_phase_defined_up_to() {
340 for phase in unpack prepare configure compile install; do
341 has ${phase} ${DEFINED_PHASES} && return 0
342 [[ ${phase} == $1 ]] && return 1
344 # We shouldn't actually get here
350 if [[ -e $PORTAGE_BUILDDIR/.prepared ]] ; then
351 vecho ">>> It appears that '$PF' is already prepared; skipping."
352 vecho ">>> Remove '$PORTAGE_BUILDDIR/.prepared' to force prepare."
356 if [[ -d $S ]] ; then
358 elif has $EAPI 0 1 2 3 3_pre2 ; then
360 elif [[ -z ${A} ]] && ! has_phase_defined_up_to prepare; then
363 die "The source directory '${S}' doesn't exist"
366 trap abort_prepare SIGINT SIGQUIT
368 ebuild_phase pre_src_prepare
369 vecho ">>> Preparing source in $PWD ..."
370 ebuild_phase src_prepare
371 >> "$PORTAGE_BUILDDIR/.prepared" || \
372 die "Failed to create $PORTAGE_BUILDDIR/.prepared"
373 vecho ">>> Source prepared."
374 ebuild_phase post_src_prepare
376 trap - SIGINT SIGQUIT
381 if [[ -e $PORTAGE_BUILDDIR/.configured ]] ; then
382 vecho ">>> It appears that '$PF' is already configured; skipping."
383 vecho ">>> Remove '$PORTAGE_BUILDDIR/.configured' to force configuration."
387 if [[ -d $S ]] ; then
389 elif has $EAPI 0 1 2 3 3_pre2 ; then
391 elif [[ -z ${A} ]] && ! has_phase_defined_up_to configure; then
394 die "The source directory '${S}' doesn't exist"
397 trap abort_configure SIGINT SIGQUIT
399 ebuild_phase pre_src_configure
401 vecho ">>> Configuring source in $PWD ..."
402 ebuild_phase src_configure
403 >> "$PORTAGE_BUILDDIR/.configured" || \
404 die "Failed to create $PORTAGE_BUILDDIR/.configured"
405 vecho ">>> Source configured."
407 ebuild_phase post_src_configure
409 trap - SIGINT SIGQUIT
414 if [[ -e $PORTAGE_BUILDDIR/.compiled ]] ; then
415 vecho ">>> It appears that '${PF}' is already compiled; skipping."
416 vecho ">>> Remove '$PORTAGE_BUILDDIR/.compiled' to force compilation."
420 if [[ -d $S ]] ; then
422 elif has $EAPI 0 1 2 3 3_pre2 ; then
424 elif [[ -z ${A} ]] && ! has_phase_defined_up_to compile; then
427 die "The source directory '${S}' doesn't exist"
430 trap abort_compile SIGINT SIGQUIT
432 if has distcc $FEATURES && has distcc-pump $FEATURES ; then
433 if [[ -z $INCLUDE_SERVER_PORT ]] || [[ ! -w $INCLUDE_SERVER_PORT ]] ; then
434 eval $(pump --startup)
435 trap "pump --shutdown" EXIT
439 ebuild_phase pre_src_compile
441 vecho ">>> Compiling source in $PWD ..."
442 ebuild_phase src_compile
443 >> "$PORTAGE_BUILDDIR/.compiled" || \
444 die "Failed to create $PORTAGE_BUILDDIR/.compiled"
445 vecho ">>> Source compiled."
447 ebuild_phase post_src_compile
449 trap - SIGINT SIGQUIT
454 if [[ -e $PORTAGE_BUILDDIR/.tested ]] ; then
455 vecho ">>> It appears that ${PN} has already been tested; skipping."
456 vecho ">>> Remove '${PORTAGE_BUILDDIR}/.tested' to force test."
460 if [ "${EBUILD_FORCE_TEST}" == "1" ] ; then
461 # If USE came from ${T}/environment then it might not have USE=test
462 # like it's supposed to here.
463 ! has test ${USE} && export USE="${USE} test"
466 trap "abort_test" SIGINT SIGQUIT
467 if [ -d "${S}" ]; then
473 if ! has test $FEATURES && [ "${EBUILD_FORCE_TEST}" != "1" ]; then
474 vecho ">>> Test phase [not enabled]: ${CATEGORY}/${PF}"
475 elif has test $RESTRICT; then
476 einfo "Skipping make test/check due to ebuild restriction."
477 vecho ">>> Test phase [explicitly disabled]: ${CATEGORY}/${PF}"
479 local save_sp=${SANDBOX_PREDICT}
481 ebuild_phase pre_src_test
482 ebuild_phase src_test
483 >> "$PORTAGE_BUILDDIR/.tested" || \
484 die "Failed to create $PORTAGE_BUILDDIR/.tested"
485 ebuild_phase post_src_test
486 SANDBOX_PREDICT=${save_sp}
489 trap - SIGINT SIGQUIT
493 [ -z "$PORTAGE_BUILDDIR" ] && die "${FUNCNAME}: PORTAGE_BUILDDIR is unset"
494 if has noauto $FEATURES ; then
495 rm -f "${PORTAGE_BUILDDIR}/.installed"
496 elif [[ -e $PORTAGE_BUILDDIR/.installed ]] ; then
497 vecho ">>> It appears that '${PF}' is already installed; skipping."
498 vecho ">>> Remove '${PORTAGE_BUILDDIR}/.installed' to force install."
501 trap "abort_install" SIGINT SIGQUIT
502 ebuild_phase pre_src_install
505 [[ " ${USE} " == *" prefix "* ]] || \
506 case "$EAPI" in 0|1|2) _x=${D} ;; esac
511 if [[ -d $S ]] ; then
513 elif has $EAPI 0 1 2 3 3_pre2 ; then
515 elif [[ -z ${A} ]] && ! has_phase_defined_up_to install; then
518 die "The source directory '${S}' doesn't exist"
522 vecho ">>> Install ${PF} into ${D} category ${CATEGORY}"
523 #our custom version of libtool uses $S and $D to fix
524 #invalid paths in .la files
527 # Reset exeinto(), docinto(), insinto(), and into() state variables
528 # in case the user is running the install phase multiple times
529 # consecutively via the ebuild command.
531 export INSDESTTREE=""
532 export _E_EXEDESTTREE_=""
533 export _E_DOCDESTTREE_=""
535 ebuild_phase src_install
536 >> "$PORTAGE_BUILDDIR/.installed" || \
537 die "Failed to create $PORTAGE_BUILDDIR/.installed"
538 vecho ">>> Completed installing ${PF} into ${D}"
540 ebuild_phase post_src_install
542 cd "${PORTAGE_BUILDDIR}"/build-info
546 for f in CATEGORY DEFINED_PHASES FEATURES INHERITED IUSE \
547 PF PKGUSE SLOT KEYWORDS HOMEPAGE DESCRIPTION ; do
549 [[ -n $x ]] && echo "$x" > $f
551 if [[ $CATEGORY != virtual ]] ; then
552 for f in ASFLAGS CBUILD CC CFLAGS CHOST CTARGET CXX \
553 CXXFLAGS EXTRA_ECONF EXTRA_EINSTALL EXTRA_MAKE \
554 LDFLAGS LIBCFLAGS LIBCXXFLAGS ; do
556 [[ -n $x ]] && echo "$x" > $f
560 echo "${EAPI:-0}" > EAPI
562 # Save EPREFIX, since it makes it easy to use chpathtool to
563 # adjust the content of a binary package so that it will
564 # work in a different EPREFIX from the one is was built for.
567 [[ " ${USE} " == *" prefix "* ]] && \
568 [ -n "${EPREFIX}" ] && echo "${EPREFIX}" > EPREFIX
571 [ -n "${EPREFIX}" ] && echo "${EPREFIX}" > EPREFIX
577 # local variables can leak into the saved environment.
580 save_ebuild_env --exclude-init-phases | filter_readonly_variables \
581 --filter-path --filter-sandbox --allow-extra-vars > environment
582 assert "save_ebuild_env failed"
584 ${PORTAGE_BZIP2_COMMAND} -f9 environment
586 cp "${EBUILD}" "${PF}.ebuild"
587 [ -n "${PORTAGE_REPO_NAME}" ] && echo "${PORTAGE_REPO_NAME}" > repository
588 if has nostrip ${FEATURES} ${RESTRICT} || has strip ${RESTRICT}
592 trap - SIGINT SIGQUIT
596 if [ -z "${D}" ]; then
597 eerror "${FUNCNAME}: D is unset"
600 ebuild_phase_with_hooks pkg_preinst
606 echo "Copyright 1999-2010 Gentoo Foundation"
608 echo "How to use the ebuild command:"
610 echo "The first argument to ebuild should be an existing .ebuild file."
612 echo "One or more of the following options can then be specified. If more"
613 echo "than one option is specified, each will be executed in order."
615 echo " help : show this help screen"
616 echo " pretend : execute package specific pretend actions"
617 echo " setup : execute package specific setup actions"
618 echo " fetch : download source archive(s) and patches"
619 echo " digest : create a manifest file for the package"
620 echo " manifest : create a manifest file for the package"
621 echo " unpack : unpack sources (auto-dependencies if needed)"
622 echo " prepare : prepare sources (auto-dependencies if needed)"
623 echo " configure : configure sources (auto-fetch/unpack if needed)"
624 echo " compile : compile sources (auto-fetch/unpack/configure if needed)"
625 echo " test : test package (auto-fetch/unpack/configure/compile if needed)"
626 echo " preinst : execute pre-install instructions"
627 echo " postinst : execute post-install instructions"
628 echo " install : install the package to the temporary install directory"
629 echo " qmerge : merge image into live filesystem, recording files in db"
630 echo " merge : do fetch, unpack, compile, install and qmerge"
631 echo " prerm : execute pre-removal instructions"
632 echo " postrm : execute post-removal instructions"
633 echo " unmerge : remove package from live filesystem"
634 echo " config : execute package specific configuration actions"
635 echo " package : create a tarball package in ${PKGDIR}/All"
636 echo " rpm : build a RedHat RPM package"
637 echo " clean : clean up all source and temporary files"
639 echo "The following settings will be used for the ebuild process:"
641 echo " package : ${PF}"
642 echo " slot : ${SLOT}"
643 echo " category : ${CATEGORY}"
644 echo " description : ${DESCRIPTION}"
645 echo " system : ${CHOST}"
646 echo " c flags : ${CFLAGS}"
647 echo " c++ flags : ${CXXFLAGS}"
648 echo " make flags : ${MAKEOPTS}"
649 echo -n " build mode : "
650 if has nostrip ${FEATURES} ${RESTRICT} || has strip ${RESTRICT} ;
654 echo "production (stripped)"
656 echo " merge to : ${ROOT}"
658 if [ -n "$USE" ]; then
659 echo "Additionally, support for the following optional features will be enabled:"
666 # @FUNCTION: _ebuild_arg_to_phase
668 # Translate a known ebuild(1) argument into the precise
669 # name of it's corresponding ebuild phase.
670 _ebuild_arg_to_phase() {
671 [ $# -ne 2 ] && die "expected exactly 2 args, got $#: $*"
678 ! has $eapi 0 1 2 3 3_pre2 && \
679 phase_func=pkg_pretend
685 phase_func=pkg_nofetch
688 phase_func=src_unpack
692 phase_func=src_prepare
696 phase_func=src_configure
699 phase_func=src_compile
705 phase_func=src_install
708 phase_func=pkg_preinst
711 phase_func=pkg_postinst
717 phase_func=pkg_postrm
721 [[ -z $phase_func ]] && return 1
726 _ebuild_phase_funcs() {
727 [ $# -ne 2 ] && die "expected exactly 2 args, got $#: $*"
730 local default_phases="pkg_nofetch src_unpack src_prepare src_configure
731 src_compile src_install src_test"
732 local x y default_func=""
734 for x in pkg_nofetch src_unpack src_test ; do
735 declare -F $x >/dev/null || \
736 eval "$x() { _eapi0_$x \"\$@\" ; }"
743 if ! declare -F src_compile >/dev/null ; then
746 src_compile() { _eapi0_src_compile "$@" ; }
749 src_compile() { _eapi1_src_compile "$@" ; }
754 for x in $default_phases ; do
756 die \"default_$x() is not supported with EAPI='$eapi' during phase $phase_func\"
761 die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
768 declare -F src_configure >/dev/null || \
769 src_configure() { _eapi2_src_configure "$@" ; }
771 declare -F src_compile >/dev/null || \
772 src_compile() { _eapi2_src_compile "$@" ; }
774 has $eapi 2 3 3_pre2 || declare -F src_install >/dev/null || \
775 src_install() { _eapi4_src_install "$@" ; }
777 if has $phase_func $default_phases ; then
779 _eapi2_pkg_nofetch () { _eapi0_pkg_nofetch "$@" ; }
780 _eapi2_src_unpack () { _eapi0_src_unpack "$@" ; }
781 _eapi2_src_prepare () { true ; }
782 _eapi2_src_test () { _eapi0_src_test "$@" ; }
783 _eapi2_src_install () { die "$FUNCNAME is not supported" ; }
785 for x in $default_phases ; do
786 eval "default_$x() { _eapi2_$x \"\$@\" ; }"
789 eval "default() { _eapi2_$phase_func \"\$@\" ; }"
795 eval "default_src_install() { _eapi4_src_install \"\$@\" ; }"
796 [[ $phase_func = src_install ]] && \
797 eval "default() { _eapi4_$phase_func \"\$@\" ; }"
803 for x in $default_phases ; do
805 die \"default_$x() is not supported in phase $default_func\"
810 die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
821 # Subshell/helper die support (must export for the die helper).
822 # Since this function is typically executed in a subshell,
823 # setup EBUILD_MASTER_PID to refer to the current $BASHPID,
824 # which seems to give the best results when further
825 # nested subshells call die.
826 export EBUILD_MASTER_PID=$BASHPID
827 trap 'exit 1' SIGTERM
829 #a reasonable default for $S
830 [[ -z ${S} ]] && export S=${WORKDIR}/${P}
832 if [[ -s $SANDBOX_LOG ]] ; then
833 # We use SANDBOX_LOG to check for sandbox violations,
834 # so we ensure that there can't be a stale log to
835 # interfere with our logic.
837 if [[ -n SANDBOX_ON ]] ; then
842 rm -f "$SANDBOX_LOG" || \
843 die "failed to remove stale sandbox log: '$SANDBOX_LOG'"
845 if [[ -n $x ]] ; then
851 # Force configure scripts that automatically detect ccache to
852 # respect FEATURES="-ccache".
853 has ccache $FEATURES || export CCACHE_DISABLE=1
855 local phase_func=$(_ebuild_arg_to_phase "$EAPI" "$EBUILD_PHASE")
856 [[ -n $phase_func ]] && _ebuild_phase_funcs "$EAPI" "$phase_func"
863 ebuild_phase_with_hooks pkg_nofetch
865 prerm|postrm|postinst|config|info)
866 if has "${1}" config info && \
867 ! declare -F "pkg_${1}" >/dev/null ; then
868 ewarn "pkg_${1}() is not defined: '${EBUILD##*/}'"
870 export SANDBOX_ON="0"
871 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
872 ebuild_phase_with_hooks pkg_${1}
875 ebuild_phase_with_hooks pkg_${1}
878 if [[ $EBUILD_PHASE == postinst ]] && [[ -n $PORTAGE_UPDATE_ENV ]]; then
879 # Update environment.bz2 in case installation phases
880 # need to pass some variables to uninstallation phases.
881 save_ebuild_env --exclude-init-phases | \
882 filter_readonly_variables --filter-path \
883 --filter-sandbox --allow-extra-vars \
884 | ${PORTAGE_BZIP2_COMMAND} -c -f9 > "$PORTAGE_UPDATE_ENV"
885 assert "save_ebuild_env failed"
888 unpack|prepare|configure|compile|test|clean|install)
889 if [[ ${SANDBOX_DISABLED:-0} = 0 ]] ; then
890 export SANDBOX_ON="1"
892 export SANDBOX_ON="0"
899 for x in ASFLAGS CCACHE_DIR CCACHE_SIZE \
900 CFLAGS CXXFLAGS LDFLAGS LIBCFLAGS LIBCXXFLAGS ; do
901 [[ ${!x+set} = set ]] && export $x
905 has distcc $FEATURES && [[ -n $DISTCC_DIR ]] && \
906 [[ ${SANDBOX_WRITE/$DISTCC_DIR} = $SANDBOX_WRITE ]] && \
907 addwrite "$DISTCC_DIR"
910 [ -z "$PKG_CONFIG_PATH" -a -n "$ABI" -a -n "${!x}" ] && \
911 export PKG_CONFIG_PATH=/usr/${!x}/pkgconfig
913 if has noauto $FEATURES && \
914 [[ ! -f $PORTAGE_BUILDDIR/.unpacked ]] ; then
916 echo "!!! We apparently haven't unpacked..." \
917 "This is probably not what you"
918 echo "!!! want to be doing... You are using" \
919 "FEATURES=noauto so I'll assume"
920 echo "!!! that you know what you are doing..." \
921 "You have 5 seconds to abort..."
925 for x in 1 2 3 4 5 6 7 8; do
932 cd "$PORTAGE_BUILDDIR"
933 if [ ! -d build-info ] ; then
935 cp "$EBUILD" "build-info/$PF.ebuild"
938 #our custom version of libtool uses $S and $D to fix
939 #invalid paths in .la files
945 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
952 export SANDBOX_ON="0"
954 help|pretend|setup|preinst)
955 #pkg_setup needs to be out of the sandbox for tmp file creation;
956 #for example, awking and piping a file in /tmp requires a temp file to be created
957 #in /etc. If pkg_setup is in the sandbox, both our lilo and apache ebuilds break.
958 export SANDBOX_ON="0"
959 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
970 export SANDBOX_ON="1"
971 echo "Unrecognized arg '${1}'"
978 # Save the env only for relevant phases.
979 if ! has "${1}" clean help info nofetch ; then
981 save_ebuild_env | filter_readonly_variables \
982 --filter-features > "$T/environment"
983 assert "save_ebuild_env failed"
984 chown portage:portage "$T/environment" &>/dev/null
985 chmod g+w "$T/environment" &>/dev/null
987 [[ -n $PORTAGE_EBUILD_EXIT_FILE ]] && > "$PORTAGE_EBUILD_EXIT_FILE"
988 if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
989 [[ ! -s $SANDBOX_LOG ]]
990 "$PORTAGE_BIN_PATH"/ebuild-ipc exit $?