2 # Copyright 1999-2013 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 HDEPEND HOMEPAGE INHERITED IUSE REQUIRED_USE KEYWORDS LICENSE
12 PDEPEND PROVIDE RDEPEND REPOSITORY RESTRICT SLOT SRC_URI"
14 PORTAGE_READONLY_VARS="D EBUILD EBUILD_PHASE EBUILD_PHASE_FUNC \
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_BUILD_GROUP \
20 PORTAGE_BUILD_USER PORTAGE_BUNZIP2_COMMAND \
21 PORTAGE_BZIP2_COMMAND PORTAGE_COLORMAP PORTAGE_CONFIGROOT \
22 PORTAGE_DEBUG PORTAGE_DEPCACHEDIR PORTAGE_EBUILD_EXIT_FILE \
23 PORTAGE_ECLASS_LOCATIONS \
24 PORTAGE_GID PORTAGE_GRPNAME PORTAGE_INST_GID PORTAGE_INST_UID \
25 PORTAGE_INTERNAL_CALLER PORTAGE_IPC_DAEMON PORTAGE_IUSE PORTAGE_LOG_FILE \
26 PORTAGE_MUTABLE_FILTERED_VARS PORTAGE_OVERRIDE_EPREFIX \
27 PORTAGE_PYM_PATH PORTAGE_PYTHON PORTAGE_PYTHONPATH \
28 PORTAGE_READONLY_METADATA PORTAGE_READONLY_VARS \
29 PORTAGE_REPO_NAME PORTAGE_REPOSITORIES PORTAGE_RESTRICT \
30 PORTAGE_SAVED_READONLY_VARS PORTAGE_SIGPIPE_STATUS \
31 PORTAGE_TMPDIR PORTAGE_UPDATE_ENV PORTAGE_USERNAME \
32 PORTAGE_VERBOSE PORTAGE_WORKDIR_MODE PORTAGE_XATTR_EXCLUDE \
34 PROFILE_PATHS REPLACING_VERSIONS REPLACED_BY_VERSION T WORKDIR \
35 __PORTAGE_HELPER __PORTAGE_TEST_HARDLINK_LOCKS"
37 PORTAGE_SAVED_READONLY_VARS="A CATEGORY P PF PN PR PV PVR"
39 # Variables that portage sets but doesn't mark readonly.
40 # In order to prevent changed values from causing unexpected
41 # interference, they are filtered out of the environment when
42 # it is saved or loaded (any mutations do not persist).
43 PORTAGE_MUTABLE_FILTERED_VARS="AA HOSTNAME"
45 # @FUNCTION: __filter_readonly_variables
46 # @DESCRIPTION: [--filter-sandbox] [--allow-extra-vars]
47 # Read an environment from stdin and echo to stdout while filtering variables
48 # with names that are known to cause interference:
50 # * some specific variables for which bash does not allow assignment
51 # * some specific variables that affect portage or sandbox behavior
52 # * variable names that begin with a digit or that contain any
53 # non-alphanumeric characters that are not be supported by bash
55 # --filter-sandbox causes all SANDBOX_* variables to be filtered, which
56 # is only desired in certain cases, such as during preprocessing or when
57 # saving environment.bz2 for a binary or installed package.
59 # --filter-features causes the special FEATURES variable to be filtered.
60 # Generally, we want it to persist between phases since the user might
61 # want to modify it via bashrc to enable things like splitdebug and
62 # installsources for specific packages. They should be able to modify it
63 # in pre_pkg_setup() and have it persist all the way through the install
64 # phase. However, if FEATURES exist inside environment.bz2 then they
65 # should be overridden by current settings.
67 # --filter-locale causes locale related variables such as LANG and LC_*
68 # variables to be filtered. These variables should persist between phases,
69 # in case they are modified by the ebuild. However, the current user
70 # settings should be used when loading the environment from a binary or
73 # --filter-path causes the PATH variable to be filtered. This variable
74 # should persist between phases, in case it is modified by the ebuild.
75 # However, old settings should be overridden when loading the
76 # environment from a binary or installed package.
78 # ---allow-extra-vars causes some extra vars to be allowd through, such
79 # as ${PORTAGE_SAVED_READONLY_VARS} and ${PORTAGE_MUTABLE_FILTERED_VARS}.
80 # This is enabled automatically if EMERGE_FROM=binary, since it preserves
81 # variables from when the package was originally built.
83 # In bash-3.2_p20+ an attempt to assign BASH_*, FUNCNAME, GROUPS or any
84 # readonly variable cause the shell to exit while executing the "source"
85 # builtin command. To avoid this problem, this function filters those
86 # variables out and discards them. See bug #190128.
87 __filter_readonly_variables() {
89 local readonly_bash_vars="BASHOPTS BASHPID DIRSTACK EUID
90 FUNCNAME GROUPS PIPESTATUS PPID SHELLOPTS UID"
91 local bash_misc_vars="BASH BASH_.* COLUMNS COMP_WORDBREAKS HISTCMD
92 HISTFILE HOSTNAME HOSTTYPE IFS LINENO MACHTYPE OLDPWD
93 OPTERR OPTIND OSTYPE POSIXLY_CORRECT PS4 PWD RANDOM
95 local filtered_sandbox_vars="SANDBOX_ACTIVE SANDBOX_BASHRC
96 SANDBOX_DEBUG_LOG SANDBOX_DISABLED SANDBOX_LIB
97 SANDBOX_LOG SANDBOX_ON"
98 # Untrusted due to possible application of package renames to binpkgs
99 local binpkg_untrusted_vars="CATEGORY P PF PN PR PV PVR"
100 local misc_garbage_vars="_portage_filter_opts"
101 filtered_vars="$readonly_bash_vars $bash_misc_vars
102 $PORTAGE_READONLY_VARS $misc_garbage_vars"
104 # Don't filter/interfere with prefix variables unless they are
105 # supported by the current EAPI.
106 if ___eapi_has_prefix_variables; then
107 filtered_vars+=" ED EPREFIX EROOT"
110 if has --filter-sandbox $* ; then
111 filtered_vars="${filtered_vars} SANDBOX_.*"
113 filtered_vars="${filtered_vars} ${filtered_sandbox_vars}"
115 if has --filter-features $* ; then
116 filtered_vars="${filtered_vars} FEATURES PORTAGE_FEATURES"
118 if has --filter-path $* ; then
119 filtered_vars+=" PATH"
121 if has --filter-locale $* ; then
122 filtered_vars+=" LANG LC_ALL LC_COLLATE
123 LC_CTYPE LC_MESSAGES LC_MONETARY
124 LC_NUMERIC LC_PAPER LC_TIME"
126 if ! has --allow-extra-vars $* ; then
127 if [ "${EMERGE_FROM}" = binary ] ; then
128 # preserve additional variables from build time,
129 # while excluding untrusted variables
130 filtered_vars+=" ${binpkg_untrusted_vars}"
132 filtered_vars+=" ${PORTAGE_SAVED_READONLY_VARS}"
133 filtered_vars+=" ${PORTAGE_MUTABLE_FILTERED_VARS}"
137 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}" || die "filter-bash-environment.py failed"
140 # @FUNCTION: __preprocess_ebuild_env
142 # Filter any readonly variables from ${T}/environment, source it, and then
143 # save it via __save_ebuild_env(). This process should be sufficient to prevent
144 # any stale variables or functions from an arbitrary environment from
145 # interfering with the current environment. This is useful when an existing
146 # environment needs to be loaded from a binary or installed package.
147 __preprocess_ebuild_env() {
148 local _portage_filter_opts="--filter-features --filter-locale --filter-path --filter-sandbox"
150 # If environment.raw is present, this is a signal from the python side,
151 # indicating that the environment may contain stale FEATURES and
152 # SANDBOX_{DENY,PREDICT,READ,WRITE} variables that should be filtered out.
153 # Otherwise, we don't need to filter the environment.
154 [ -f "${T}/environment.raw" ] || return 0
156 __filter_readonly_variables $_portage_filter_opts < "${T}"/environment \
157 >> "$T/environment.filtered" || return $?
158 unset _portage_filter_opts
159 mv "${T}"/environment.filtered "${T}"/environment || return $?
160 rm -f "${T}/environment.success" || return $?
161 # WARNING: Code inside this subshell should avoid making assumptions
162 # about variables or functions after source "${T}"/environment has been
163 # called. Any variables that need to be relied upon should already be
164 # filtered out above.
167 source "${T}/environment" || exit $?
168 # We have to temporarily disable sandbox since the
169 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
170 # may be unusable (triggering in spurious sandbox violations)
171 # until we've merged them with our current values.
174 # It's remotely possible that __save_ebuild_env() has been overridden
175 # by the above source command. To protect ourselves, we override it
176 # here with our own version. ${PORTAGE_BIN_PATH} is safe to use here
177 # because it's already filtered above.
178 source "${PORTAGE_BIN_PATH}/save-ebuild-env.sh" || exit $?
180 # Rely on __save_ebuild_env() to filter out any remaining variables
181 # and functions that could interfere with the current environment.
182 __save_ebuild_env || exit $?
183 >> "$T/environment.success" || exit $?
184 ) > "${T}/environment.filtered"
186 if [ -e "${T}/environment.success" ] ; then
187 __filter_readonly_variables --filter-features < \
188 "${T}/environment.filtered" > "${T}/environment"
193 rm -f "${T}"/environment.{filtered,raw,success}
198 declare -F "$1" >/dev/null && __qa_call $1
201 __ebuild_phase_with_hooks() {
202 local x phase_name=${1}
203 for x in {pre_,,post_}${phase_name} ; do
209 if [[ -e $PORTAGE_BUILDDIR/.pretended ]] ; then
210 __vecho ">>> It appears that '$PF' is already pretended; skipping."
211 __vecho ">>> Remove '$PORTAGE_BUILDDIR/.pretended' to force pretend."
214 __ebuild_phase pre_pkg_pretend
215 __ebuild_phase pkg_pretend
216 >> "$PORTAGE_BUILDDIR/.pretended" || \
217 die "Failed to create $PORTAGE_BUILDDIR/.pretended"
218 __ebuild_phase post_pkg_pretend
222 if [[ -e $PORTAGE_BUILDDIR/.setuped ]] ; then
223 __vecho ">>> It appears that '$PF' is already setup; skipping."
224 __vecho ">>> Remove '$PORTAGE_BUILDDIR/.setuped' to force setup."
227 __ebuild_phase pre_pkg_setup
228 __ebuild_phase pkg_setup
229 >> "$PORTAGE_BUILDDIR/.setuped" || \
230 die "Failed to create $PORTAGE_BUILDDIR/.setuped"
231 __ebuild_phase post_pkg_setup
235 if [[ -f ${PORTAGE_BUILDDIR}/.unpacked ]] ; then
236 __vecho ">>> WORKDIR is up-to-date, keeping..."
239 if [ ! -d "${WORKDIR}" ]; then
240 install -m${PORTAGE_WORKDIR_MODE:-0700} -d "${WORKDIR}" || die "Failed to create dir '${WORKDIR}'"
242 cd "${WORKDIR}" || die "Directory change failed: \`cd '${WORKDIR}'\`"
243 __ebuild_phase pre_src_unpack
244 __vecho ">>> Unpacking source..."
245 __ebuild_phase src_unpack
246 >> "$PORTAGE_BUILDDIR/.unpacked" || \
247 die "Failed to create $PORTAGE_BUILDDIR/.unpacked"
248 __vecho ">>> Source unpacked in ${WORKDIR}"
249 __ebuild_phase post_src_unpack
253 if [ -z "${PORTAGE_BUILDDIR}" ]; then
254 echo "Aborting clean phase because PORTAGE_BUILDDIR is unset!"
256 elif [ ! -d "${PORTAGE_BUILDDIR}" ] ; then
259 if has chflags $FEATURES ; then
260 chflags -R noschg,nouchg,nosappnd,nouappnd "${PORTAGE_BUILDDIR}"
261 chflags -R nosunlnk,nouunlnk "${PORTAGE_BUILDDIR}" 2>/dev/null
264 rm -rf "${PORTAGE_BUILDDIR}/image" "${PORTAGE_BUILDDIR}/homedir"
265 rm -f "${PORTAGE_BUILDDIR}/.installed"
267 if [[ $EMERGE_FROM = binary ]] || \
268 ! has keeptemp $FEATURES && ! has keepwork $FEATURES ; then
272 if [[ $EMERGE_FROM = binary ]] || ! has keepwork $FEATURES; then
273 rm -f "$PORTAGE_BUILDDIR"/.{ebuild_changed,logid,pretended,setuped,unpacked,prepared} \
274 "$PORTAGE_BUILDDIR"/.{configured,compiled,tested,packaged} \
275 "$PORTAGE_BUILDDIR"/.die_hooks \
276 "$PORTAGE_BUILDDIR"/.ipc_{in,out,lock} \
277 "$PORTAGE_BUILDDIR"/.exit_status
279 rm -rf "${PORTAGE_BUILDDIR}/build-info"
283 if [ -f "${PORTAGE_BUILDDIR}/.unpacked" ]; then
284 find "${PORTAGE_BUILDDIR}" -type d ! -regex "^${WORKDIR}" | sort -r | tr "\n" "\0" | $XARGS -0 rmdir &>/dev/null
287 # do not bind this to doebuild defined DISTDIR; don't trust doebuild, and if mistakes are made it'll
288 # result in it wiping the users distfiles directory (bad).
289 rm -rf "${PORTAGE_BUILDDIR}/distdir"
291 # Some kernels, such as Solaris, return EINVAL when an attempt
292 # is made to remove the current working directory.
293 cd "$PORTAGE_BUILDDIR"/../..
294 rmdir "$PORTAGE_BUILDDIR" 2>/dev/null
301 if [ "$2" != "fail" ]; then
302 msg="${EBUILD}: ${1} aborted; exiting."
304 msg="${EBUILD}: ${1} failed; exiting."
310 #unset signal handler
311 trap - SIGINT SIGQUIT
315 __abort_handler src_prepare $1
316 rm -f "$PORTAGE_BUILDDIR/.prepared"
320 __abort_configure() {
321 __abort_handler src_configure $1
322 rm -f "$PORTAGE_BUILDDIR/.configured"
327 __abort_handler "src_compile" $1
328 rm -f "${PORTAGE_BUILDDIR}/.compiled"
333 __abort_handler "__dyn_test" $1
334 rm -f "${PORTAGE_BUILDDIR}/.tested"
339 __abort_handler "src_install" $1
340 rm -rf "${PORTAGE_BUILDDIR}/image"
344 __has_phase_defined_up_to() {
346 for phase in unpack prepare configure compile install; do
347 has ${phase} ${DEFINED_PHASES} && return 0
348 [[ ${phase} == $1 ]] && return 1
350 # We shouldn't actually get here
356 if [[ -e $PORTAGE_BUILDDIR/.prepared ]] ; then
357 __vecho ">>> It appears that '$PF' is already prepared; skipping."
358 __vecho ">>> Remove '$PORTAGE_BUILDDIR/.prepared' to force prepare."
362 if [[ -d $S ]] ; then
364 elif ___eapi_has_S_WORKDIR_fallback; then
366 elif [[ -z ${A} ]] && ! __has_phase_defined_up_to prepare; then
369 die "The source directory '${S}' doesn't exist"
372 trap __abort_prepare SIGINT SIGQUIT
374 __ebuild_phase pre_src_prepare
375 __vecho ">>> Preparing source in $PWD ..."
376 __ebuild_phase src_prepare
377 >> "$PORTAGE_BUILDDIR/.prepared" || \
378 die "Failed to create $PORTAGE_BUILDDIR/.prepared"
379 __vecho ">>> Source prepared."
380 __ebuild_phase post_src_prepare
382 trap - SIGINT SIGQUIT
387 if [[ -e $PORTAGE_BUILDDIR/.configured ]] ; then
388 __vecho ">>> It appears that '$PF' is already configured; skipping."
389 __vecho ">>> Remove '$PORTAGE_BUILDDIR/.configured' to force configuration."
393 if [[ -d $S ]] ; then
395 elif ___eapi_has_S_WORKDIR_fallback; then
397 elif [[ -z ${A} ]] && ! __has_phase_defined_up_to configure; then
400 die "The source directory '${S}' doesn't exist"
403 trap __abort_configure SIGINT SIGQUIT
405 __ebuild_phase pre_src_configure
407 __vecho ">>> Configuring source in $PWD ..."
408 __ebuild_phase src_configure
409 >> "$PORTAGE_BUILDDIR/.configured" || \
410 die "Failed to create $PORTAGE_BUILDDIR/.configured"
411 __vecho ">>> Source configured."
413 __ebuild_phase post_src_configure
415 trap - SIGINT SIGQUIT
420 if [[ -e $PORTAGE_BUILDDIR/.compiled ]] ; then
421 __vecho ">>> It appears that '${PF}' is already compiled; skipping."
422 __vecho ">>> Remove '$PORTAGE_BUILDDIR/.compiled' to force compilation."
426 if [[ -d $S ]] ; then
428 elif ___eapi_has_S_WORKDIR_fallback; then
430 elif [[ -z ${A} ]] && ! __has_phase_defined_up_to compile; then
433 die "The source directory '${S}' doesn't exist"
436 trap __abort_compile SIGINT SIGQUIT
438 if has distcc $FEATURES && has distcc-pump $FEATURES ; then
439 if [[ -z $INCLUDE_SERVER_PORT ]] || [[ ! -w $INCLUDE_SERVER_PORT ]] ; then
440 eval $(pump --startup)
441 trap "pump --shutdown" EXIT
445 __ebuild_phase pre_src_compile
447 __vecho ">>> Compiling source in $PWD ..."
448 __ebuild_phase src_compile
449 >> "$PORTAGE_BUILDDIR/.compiled" || \
450 die "Failed to create $PORTAGE_BUILDDIR/.compiled"
451 __vecho ">>> Source compiled."
453 __ebuild_phase post_src_compile
455 trap - SIGINT SIGQUIT
460 if [[ -e $PORTAGE_BUILDDIR/.tested ]] ; then
461 __vecho ">>> It appears that ${PN} has already been tested; skipping."
462 __vecho ">>> Remove '${PORTAGE_BUILDDIR}/.tested' to force test."
466 trap "__abort_test" SIGINT SIGQUIT
467 if [ -d "${S}" ]; then
473 if has test ${RESTRICT} ; then
474 einfo "Skipping make test/check due to ebuild restriction."
475 __vecho ">>> Test phase [disabled because of RESTRICT=test]: ${CATEGORY}/${PF}"
477 # If ${EBUILD_FORCE_TEST} == 1 and FEATURES came from ${T}/environment
478 # then it might not have FEATURES=test like it's supposed to here.
479 elif [[ ${EBUILD_FORCE_TEST} != 1 ]] && ! has test ${FEATURES} ; then
480 __vecho ">>> Test phase [not enabled]: ${CATEGORY}/${PF}"
482 # If ${EBUILD_FORCE_TEST} == 1 and USE came from ${T}/environment
483 # then it might not have USE=test like it's supposed to here.
484 if [[ ${EBUILD_FORCE_TEST} == 1 && test =~ ${PORTAGE_IUSE} ]] && \
485 ! has test ${USE} ; then
486 export USE="${USE} test"
489 local save_sp=${SANDBOX_PREDICT}
491 __ebuild_phase pre_src_test
492 __ebuild_phase src_test
493 >> "$PORTAGE_BUILDDIR/.tested" || \
494 die "Failed to create $PORTAGE_BUILDDIR/.tested"
495 __ebuild_phase post_src_test
496 SANDBOX_PREDICT=${save_sp}
499 trap - SIGINT SIGQUIT
503 [ -z "$PORTAGE_BUILDDIR" ] && die "${FUNCNAME}: PORTAGE_BUILDDIR is unset"
504 if has noauto $FEATURES ; then
505 rm -f "${PORTAGE_BUILDDIR}/.installed"
506 elif [[ -e $PORTAGE_BUILDDIR/.installed ]] ; then
507 __vecho ">>> It appears that '${PF}' is already installed; skipping."
508 __vecho ">>> Remove '${PORTAGE_BUILDDIR}/.installed' to force install."
511 trap "__abort_install" SIGINT SIGQUIT
512 __ebuild_phase pre_src_install
514 if ___eapi_has_prefix_variables; then
523 if [[ -d $S ]] ; then
525 elif ___eapi_has_S_WORKDIR_fallback; then
527 elif [[ -z ${A} ]] && ! __has_phase_defined_up_to install; then
530 die "The source directory '${S}' doesn't exist"
534 __vecho ">>> Install ${PF} into ${D} category ${CATEGORY}"
535 #our custom version of libtool uses $S and $D to fix
536 #invalid paths in .la files
539 # Reset exeinto(), docinto(), insinto(), and into() state variables
540 # in case the user is running the install phase multiple times
541 # consecutively via the ebuild command.
543 export INSDESTTREE=""
544 export _E_EXEDESTTREE_=""
545 export _E_DOCDESTTREE_=""
547 __ebuild_phase src_install
548 >> "$PORTAGE_BUILDDIR/.installed" || \
549 die "Failed to create $PORTAGE_BUILDDIR/.installed"
550 __vecho ">>> Completed installing ${PF} into ${D}"
552 __ebuild_phase post_src_install
554 cd "${PORTAGE_BUILDDIR}"/build-info
558 for f in CATEGORY DEFINED_PHASES FEATURES INHERITED IUSE \
559 PF PKGUSE SLOT KEYWORDS HOMEPAGE DESCRIPTION ; do
561 [[ -n $x ]] && echo "$x" > $f
563 if [[ $CATEGORY != virtual ]] ; then
564 for f in ASFLAGS CBUILD CC CFLAGS CHOST CTARGET CXX \
565 CXXFLAGS EXTRA_ECONF EXTRA_EINSTALL EXTRA_MAKE \
566 LDFLAGS LIBCFLAGS LIBCXXFLAGS QA_CONFIGURE_OPTIONS \
569 [[ -n $x ]] && echo "$x" > $f
571 # whitespace preserved
572 for f in QA_AM_MAINTAINER_MODE ; do
573 [[ -n ${!f} ]] && echo "${!f}" > $f
577 echo "${EAPI:-0}" > EAPI
579 # Save EPREFIX, since it makes it easy to use chpathtool to
580 # adjust the content of a binary package so that it will
581 # work in a different EPREFIX from the one is was built for.
582 if ___eapi_has_prefix_variables && [[ -n ${EPREFIX} ]]; then
583 echo "${EPREFIX}" > EPREFIX
588 # local variables can leak into the saved environment.
591 # Use safe cwd, avoiding unsafe import for bug #469338.
592 cd "${PORTAGE_PYM_PATH}"
593 __save_ebuild_env --exclude-init-phases | __filter_readonly_variables \
594 --filter-path --filter-sandbox --allow-extra-vars > \
595 "${PORTAGE_BUILDDIR}"/build-info/environment
596 assert "__save_ebuild_env failed"
597 cd "${PORTAGE_BUILDDIR}"/build-info || die
599 ${PORTAGE_BZIP2_COMMAND} -f9 environment
601 cp "${EBUILD}" "${PF}.ebuild"
602 [ -n "${PORTAGE_REPO_NAME}" ] && echo "${PORTAGE_REPO_NAME}" > repository
603 if has nostrip ${FEATURES} ${RESTRICT} || has strip ${RESTRICT}
607 trap - SIGINT SIGQUIT
613 echo "Copyright 1999-2010 Gentoo Foundation"
615 echo "How to use the ebuild command:"
617 echo "The first argument to ebuild should be an existing .ebuild file."
619 echo "One or more of the following options can then be specified. If more"
620 echo "than one option is specified, each will be executed in order."
622 echo " help : show this help screen"
623 echo " pretend : execute package specific pretend actions"
624 echo " setup : execute package specific setup actions"
625 echo " fetch : download source archive(s) and patches"
626 echo " nofetch : display special fetch instructions"
627 echo " digest : create a manifest file for the package"
628 echo " manifest : create a manifest file for the package"
629 echo " unpack : unpack sources (auto-dependencies if needed)"
630 echo " prepare : prepare sources (auto-dependencies if needed)"
631 echo " configure : configure sources (auto-fetch/unpack if needed)"
632 echo " compile : compile sources (auto-fetch/unpack/configure if needed)"
633 echo " test : test package (auto-fetch/unpack/configure/compile if needed)"
634 echo " preinst : execute pre-install instructions"
635 echo " postinst : execute post-install instructions"
636 echo " install : install the package to the temporary install directory"
637 echo " qmerge : merge image into live filesystem, recording files in db"
638 echo " merge : do fetch, unpack, compile, install and qmerge"
639 echo " prerm : execute pre-removal instructions"
640 echo " postrm : execute post-removal instructions"
641 echo " unmerge : remove package from live filesystem"
642 echo " config : execute package specific configuration actions"
643 echo " package : create a tarball package in ${PKGDIR}/All"
644 echo " rpm : build a RedHat RPM package"
645 echo " clean : clean up all source and temporary files"
647 echo "The following settings will be used for the ebuild process:"
649 echo " package : ${PF}"
650 echo " slot : ${SLOT}"
651 echo " category : ${CATEGORY}"
652 echo " description : ${DESCRIPTION}"
653 echo " system : ${CHOST}"
654 echo " c flags : ${CFLAGS}"
655 echo " c++ flags : ${CXXFLAGS}"
656 echo " make flags : ${MAKEOPTS}"
657 echo -n " build mode : "
658 if has nostrip ${FEATURES} ${RESTRICT} || has strip ${RESTRICT} ;
662 echo "production (stripped)"
664 echo " merge to : ${ROOT}"
666 if [ -n "$USE" ]; then
667 echo "Additionally, support for the following optional features will be enabled:"
674 # @FUNCTION: __ebuild_arg_to_phase
676 # Translate a known ebuild(1) argument into the precise
677 # name of it's corresponding ebuild phase.
678 __ebuild_arg_to_phase() {
679 [ $# -ne 1 ] && die "expected exactly 1 arg, got $#: $*"
685 ___eapi_has_pkg_pretend && \
686 phase_func=pkg_pretend
692 phase_func=pkg_nofetch
695 phase_func=src_unpack
698 ___eapi_has_src_prepare && \
699 phase_func=src_prepare
702 ___eapi_has_src_configure && \
703 phase_func=src_configure
706 phase_func=src_compile
712 phase_func=src_install
715 phase_func=pkg_preinst
718 phase_func=pkg_postinst
724 phase_func=pkg_postrm
728 [[ -z $phase_func ]] && return 1
733 __ebuild_phase_funcs() {
734 [ $# -ne 2 ] && die "expected exactly 2 args, got $#: $*"
737 local default_phases="pkg_nofetch src_unpack src_prepare src_configure
738 src_compile src_install src_test"
739 local x y default_func=""
741 for x in pkg_nofetch src_unpack src_test ; do
742 declare -F $x >/dev/null || \
743 eval "$x() { __eapi0_$x \"\$@\" ; }"
750 if ! declare -F src_compile >/dev/null ; then
753 src_compile() { __eapi0_src_compile "$@" ; }
756 src_compile() { __eapi1_src_compile "$@" ; }
761 for x in $default_phases ; do
763 die \"default_$x() is not supported with EAPI='$eapi' during phase $phase_func\"
768 die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
775 declare -F src_configure >/dev/null || \
776 src_configure() { __eapi2_src_configure "$@" ; }
778 declare -F src_compile >/dev/null || \
779 src_compile() { __eapi2_src_compile "$@" ; }
781 has $eapi 2 3 || declare -F src_install >/dev/null || \
782 src_install() { __eapi4_src_install "$@" ; }
784 if has $phase_func $default_phases ; then
786 __eapi2_pkg_nofetch () { __eapi0_pkg_nofetch "$@" ; }
787 __eapi2_src_unpack () { __eapi0_src_unpack "$@" ; }
788 __eapi2_src_prepare () { true ; }
789 __eapi2_src_test () { __eapi0_src_test "$@" ; }
790 __eapi2_src_install () { die "$FUNCNAME is not supported" ; }
792 for x in $default_phases ; do
793 eval "default_$x() { __eapi2_$x \"\$@\" ; }"
796 eval "default() { __eapi2_$phase_func \"\$@\" ; }"
802 eval "default_src_install() { __eapi4_src_install \"\$@\" ; }"
803 [[ $phase_func = src_install ]] && \
804 eval "default() { __eapi4_$phase_func \"\$@\" ; }"
810 for x in $default_phases ; do
812 die \"default_$x() is not supported in phase $default_func\"
817 die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
828 # Subshell/helper die support (must export for the die helper).
829 # Since this function is typically executed in a subshell,
830 # setup EBUILD_MASTER_PID to refer to the current $BASHPID,
831 # which seems to give the best results when further
832 # nested subshells call die.
833 export EBUILD_MASTER_PID=$BASHPID
834 trap 'exit 1' SIGTERM
836 #a reasonable default for $S
837 [[ -z ${S} ]] && export S=${WORKDIR}/${P}
839 if [[ -s $SANDBOX_LOG ]] ; then
840 # We use SANDBOX_LOG to check for sandbox violations,
841 # so we ensure that there can't be a stale log to
842 # interfere with our logic.
844 if [[ -n SANDBOX_ON ]] ; then
849 rm -f "$SANDBOX_LOG" || \
850 die "failed to remove stale sandbox log: '$SANDBOX_LOG'"
852 if [[ -n $x ]] ; then
858 # Force configure scripts that automatically detect ccache to
859 # respect FEATURES="-ccache".
860 has ccache $FEATURES || export CCACHE_DISABLE=1
862 local phase_func=$(__ebuild_arg_to_phase "$EBUILD_PHASE")
863 [[ -n $phase_func ]] && __ebuild_phase_funcs "$EAPI" "$phase_func"
870 __ebuild_phase_with_hooks pkg_nofetch
872 prerm|postrm|preinst|postinst|config|info)
873 if has "${1}" config info && \
874 ! declare -F "pkg_${1}" >/dev/null ; then
875 ewarn "pkg_${1}() is not defined: '${EBUILD##*/}'"
877 export SANDBOX_ON="0"
878 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
879 __ebuild_phase_with_hooks pkg_${1}
882 __ebuild_phase_with_hooks pkg_${1}
885 if [[ -n $PORTAGE_UPDATE_ENV ]] ; then
886 # Update environment.bz2 in case installation phases
887 # need to pass some variables to uninstallation phases.
888 # Use safe cwd, avoiding unsafe import for bug #469338.
889 cd "${PORTAGE_PYM_PATH}"
890 __save_ebuild_env --exclude-init-phases | \
891 __filter_readonly_variables --filter-path \
892 --filter-sandbox --allow-extra-vars \
893 | ${PORTAGE_BZIP2_COMMAND} -c -f9 > "$PORTAGE_UPDATE_ENV"
894 assert "__save_ebuild_env failed"
897 unpack|prepare|configure|compile|test|clean|install)
898 if [[ ${SANDBOX_DISABLED:-0} = 0 ]] ; then
899 export SANDBOX_ON="1"
901 export SANDBOX_ON="0"
908 for x in ASFLAGS CCACHE_DIR CCACHE_SIZE \
909 CFLAGS CXXFLAGS LDFLAGS LIBCFLAGS LIBCXXFLAGS ; do
910 [[ ${!x+set} = set ]] && export $x
914 has distcc $FEATURES && [[ -n $DISTCC_DIR ]] && \
915 [[ ${SANDBOX_WRITE/$DISTCC_DIR} = $SANDBOX_WRITE ]] && \
916 addwrite "$DISTCC_DIR"
919 [ -z "$PKG_CONFIG_PATH" -a -n "$ABI" -a -n "${!x}" ] && \
920 export PKG_CONFIG_PATH=/usr/${!x}/pkgconfig
922 if has noauto $FEATURES && \
923 [[ ! -f $PORTAGE_BUILDDIR/.unpacked ]] ; then
925 echo "!!! We apparently haven't unpacked..." \
926 "This is probably not what you"
927 echo "!!! want to be doing... You are using" \
928 "FEATURES=noauto so I'll assume"
929 echo "!!! that you know what you are doing..." \
930 "You have 5 seconds to abort..."
934 for x in 1 2 3 4 5 6 7 8; do
941 cd "$PORTAGE_BUILDDIR"
942 if [ ! -d build-info ] ; then
944 cp "$EBUILD" "build-info/$PF.ebuild"
947 #our custom version of libtool uses $S and $D to fix
948 #invalid paths in .la files
954 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
961 export SANDBOX_ON="0"
964 #pkg_setup needs to be out of the sandbox for tmp file creation;
965 #for example, awking and piping a file in /tmp requires a temp file to be created
966 #in /etc. If pkg_setup is in the sandbox, both our lilo and apache ebuilds break.
967 export SANDBOX_ON="0"
968 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
979 export SANDBOX_ON="1"
980 echo "Unrecognized arg '${1}'"
987 # Save the env only for relevant phases.
988 if ! has "${1}" clean help info nofetch ; then
990 # Use safe cwd, avoiding unsafe import for bug #469338.
991 cd "${PORTAGE_PYM_PATH}"
992 __save_ebuild_env | __filter_readonly_variables \
993 --filter-features > "$T/environment"
994 assert "__save_ebuild_env failed"
995 chgrp "${PORTAGE_GRPNAME:-portage}" "$T/environment"
996 chmod g+w "$T/environment"
998 [[ -n $PORTAGE_EBUILD_EXIT_FILE ]] && > "$PORTAGE_EBUILD_EXIT_FILE"
999 if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
1000 [[ ! -s $SANDBOX_LOG ]]
1001 "$PORTAGE_BIN_PATH"/ebuild-ipc exit $?