scripts/crosstool-NG.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Jan 20 20:37:43 2009 +0000 (2009-01-20)
changeset 1149 df32ef8825f9
parent 1143 eee9e8de51e3
permissions -rwxr-xr-x
On 20090115.0012+0100, "Andy Johnson" <ajohnson@aecno.com> wrote:
... I added a step after
"debug" called "finish", and moved the code in crosstool.sh
after the loop that processes the steps from crosstool.sh
into a do_finish function in functions. Thus, it is now
possible to restart after the "debug" step to re-do the
final few things (clean and compress).

/trunk/scripts/crosstool-NG.sh | 38 0 38 0 --------------------------------------
/trunk/scripts/functions | 42 42 0 0 ++++++++++++++++++++++++++++++++++++++++++
/trunk/steps.mk | 3 2 1 0 ++-
3 files changed, 44 insertions(+), 39 deletions(-)
     1 #!/bin/bash
     2 # Copyright 2007 Yann E. MORIN
     3 # Licensed under the GPL v2. See COPYING in the root of this package.
     4 
     5 # This is the main entry point to crosstool
     6 # This will:
     7 #   - download, extract and patch the toolchain components
     8 #   - build and install each components in turn
     9 #   - and eventually test the resulting toolchain
    10 
    11 # What this file does is prepare the environment, based upon the user-choosen
    12 # options. It also checks the existing environment for un-friendly variables,
    13 # and builds the tools.
    14 
    15 # Parse the common functions
    16 # Note: some initialisation and sanitizing is done while parsing this file,
    17 # most notably:
    18 #  - set trap handler on errors,
    19 #  - don't hash commands lookups,
    20 #  - initialise logging.
    21 . "${CT_LIB_DIR}/scripts/functions"
    22 
    23 # Parse the configuration file
    24 # It has some info about the logging facility, so include it early
    25 . .config
    26 
    27 # Overide the locale early, in case we ever translate crosstool-NG messages
    28 [ -z "${CT_NO_OVERIDE_LC_MESSAGES}" ] && export LC_ALL=C
    29 
    30 # Start date. Can't be done until we know the locale
    31 CT_STAR_DATE=$(CT_DoDate +%s%N)
    32 CT_STAR_DATE_HUMAN=$(CT_DoDate +%Y%m%d.%H%M%S)
    33 
    34 # Yes! We can do full logging from now on!
    35 CT_DoLog INFO "Build started ${CT_STAR_DATE_HUMAN}"
    36 
    37 # renice oursleves
    38 CT_DoExecLog DEBUG renice ${CT_NICE} $$
    39 
    40 CT_DoStep DEBUG "Dumping user-supplied crosstool-NG configuration"
    41 CT_DoExecLog DEBUG egrep '^(# |)CT_' .config
    42 CT_EndStep
    43 
    44 # Some sanity checks in the environment and needed tools
    45 CT_DoLog INFO "Checking environment sanity"
    46 
    47 CT_DoLog DEBUG "Unsetting and unexporting MAKEFLAGS"
    48 unset MAKEFLAGS
    49 export MAKEFLAGS
    50 
    51 # Other environment sanity checks
    52 CT_TestAndAbort "Don't set LD_LIBRARY_PATH. It screws up the build." -n "${LD_LIBRARY_PATH}"
    53 CT_TestAndAbort "Don't set CFLAGS. It screws up the build." -n "${CFLAGS}"
    54 CT_TestAndAbort "Don't set CXXFLAGS. It screws up the build." -n "${CXXFLAGS}"
    55 CT_Test "GREP_OPTIONS screws up the build. Resetting." -n "${GREP_OPTIONS}"
    56 export GREP_OPTIONS=
    57 
    58 CT_DoLog INFO "Building environment variables"
    59 
    60 # Include sub-scripts instead of calling them: that way, we do not have to
    61 # export any variable, nor re-parse the configuration and functions files.
    62 . "${CT_LIB_DIR}/scripts/build/arch/${CT_ARCH}.sh"
    63 . "${CT_LIB_DIR}/scripts/build/kernel/${CT_KERNEL}.sh"
    64 . "${CT_LIB_DIR}/scripts/build/gmp.sh"
    65 . "${CT_LIB_DIR}/scripts/build/mpfr.sh"
    66 . "${CT_LIB_DIR}/scripts/build/binutils.sh"
    67 . "${CT_LIB_DIR}/scripts/build/libc/${CT_LIBC}.sh"
    68 . "${CT_LIB_DIR}/scripts/build/cc/${CT_CC}.sh"
    69 . "${CT_LIB_DIR}/scripts/build/tools.sh"
    70 . "${CT_LIB_DIR}/scripts/build/debug.sh"
    71 
    72 # Target tuple: CT_TARGET needs a little love:
    73 CT_DoBuildTargetTuple
    74 
    75 # Kludge: If any of the configured options needs CT_TARGET,
    76 # then rescan the options file now:
    77 . .config
    78 
    79 # Second kludge: merge user-supplied target CFLAGS with architecture-provided
    80 # target CFLAGS. Do the same for LDFLAGS in case it happens in the future.
    81 # Put user-supplied flags at the end, so that they take precedence.
    82 CT_TARGET_CFLAGS="${CT_ARCH_TARGET_CFLAGS} ${CT_TARGET_CFLAGS}"
    83 CT_TARGET_LDFLAGS="${CT_ARCH_TARGET_LDFLAGS} ${CT_TARGET_LDFLAGS}"
    84 CT_CC_CORE_EXTRA_CONFIG="${CT_ARCH_CC_CORE_EXTRA_CONFIG} ${CT_CC_CORE_EXTRA_CONFIG}"
    85 CT_CC_EXTRA_CONFIG="${CT_ARCH_CC_EXTRA_CONFIG} ${CT_CC_EXTRA_CONFIG}"
    86 
    87 # Where will we work?
    88 : "${CT_WORK_DIR:=${CT_TOP_DIR}/targets}"
    89 CT_TARBALLS_DIR="${CT_WORK_DIR}/tarballs"
    90 CT_SRC_DIR="${CT_WORK_DIR}/src"
    91 CT_BUILD_DIR="${CT_WORK_DIR}/${CT_TARGET}/build"
    92 CT_DEBUG_INSTALL_DIR="${CT_INSTALL_DIR}/${CT_TARGET}/debug-root"
    93 # Note: we'll always install the core compiler in its own directory, so as to
    94 # not mix the two builds: core and final.
    95 CT_CC_CORE_STATIC_PREFIX_DIR="${CT_BUILD_DIR}/${CT_CC}-core-static"
    96 CT_CC_CORE_SHARED_PREFIX_DIR="${CT_BUILD_DIR}/${CT_CC}-core-shared"
    97 CT_STATE_DIR="${CT_WORK_DIR}/${CT_TARGET}/state"
    98 
    99 # We must ensure that we can restart if asked for!
   100 if [ -n "${CT_RESTART}" -a ! -d "${CT_STATE_DIR}"  ]; then
   101     CT_DoLog ERROR "You asked to restart a non-restartable build"
   102     CT_DoLog ERROR "This happened because you didn't set CT_DEBUG_CT_SAVE_STEPS"
   103     CT_DoLog ERROR "in the config options for the previous build, or the state"
   104     CT_DoLog ERROR "directory for the previous build was deleted."
   105     CT_Abort "I will stop here to avoid any carnage"
   106 fi
   107 
   108 # If the local tarball directory does not exist, say so, and don't try to save there!
   109 if [ ! -d "${CT_LOCAL_TARBALLS_DIR}" ]; then
   110     CT_DoLog WARN "Directory '${CT_LOCAL_TARBALLS_DIR}' does not exist. Will not save downloaded tarballs to local storage."
   111     CT_SAVE_TARBALLS=
   112 fi
   113 
   114 # Some more sanity checks now that we have all paths set up
   115 case "${CT_LOCAL_TARBALLS_DIR},${CT_TARBALLS_DIR},${CT_SRC_DIR},${CT_BUILD_DIR},${CT_PREFIX_DIR},${CT_INSTALL_DIR}" in
   116     *" "*) CT_Abort "Don't use spaces in paths, it breaks things.";;
   117 esac
   118 
   119 # Check now if we can write to the destination directory:
   120 if [ -d "${CT_INSTALL_DIR}" ]; then
   121     CT_TestAndAbort "Destination directory '${CT_INSTALL_DIR}' is not removable" ! -w $(dirname "${CT_INSTALL_DIR}")
   122 fi
   123 
   124 # Good, now grab a bit of informations on the system we're being run on,
   125 # just in case something goes awok, and it's not our fault:
   126 CT_SYS_USER=$(id -un)
   127 CT_SYS_HOSTNAME=$(hostname -f 2>/dev/null || true)
   128 # Hmmm. Some non-DHCP-enabled machines do not have an FQDN... Fall back to node name.
   129 CT_SYS_HOSTNAME="${CT_SYS_HOSTNAME:-$(uname -n)}"
   130 CT_SYS_KERNEL=$(uname -s)
   131 CT_SYS_REVISION=$(uname -r)
   132 # MacOS X lacks '-o' :
   133 CT_SYS_OS=$(uname -o || echo "Unknown (maybe MacOS-X)")
   134 CT_SYS_MACHINE=$(uname -m)
   135 CT_SYS_PROCESSOR=$(uname -p)
   136 CT_SYS_GCC=$(gcc -dumpversion)
   137 CT_SYS_TARGET=$(CT_DoConfigGuess)
   138 CT_TOOLCHAIN_ID="crosstool-${CT_VERSION} build ${CT_STAR_DATE_HUMAN} by ${CT_SYS_USER}@${CT_SYS_HOSTNAME}"
   139 
   140 CT_DoLog EXTRA "Preparing working directories"
   141 
   142 # Ah! The build directory shall be eradicated, even if we restart!
   143 if [ -d "${CT_BUILD_DIR}" ]; then
   144     CT_DoForceRmdir "${CT_BUILD_DIR}"
   145 fi
   146 
   147 # Don't eradicate directories if we need to restart
   148 if [ -z "${CT_RESTART}" ]; then
   149     # Get rid of pre-existing installed toolchain and previous build directories.
   150     # We need to do that _before_ we can safely log, because the log file will
   151     # most probably be in the toolchain directory.
   152     if [ "${CT_FORCE_DOWNLOAD}" = "y" -a -d "${CT_TARBALLS_DIR}" ]; then
   153         CT_DoForceRmdir "${CT_TARBALLS_DIR}"
   154     fi
   155     if [ "${CT_FORCE_EXTRACT}" = "y" -a -d "${CT_SRC_DIR}" ]; then
   156         CT_DoForceRmdir "${CT_SRC_DIR}"
   157     fi
   158     if [ -d "${CT_INSTALL_DIR}" ]; then
   159         CT_DoForceRmdir "${CT_INSTALL_DIR}"
   160     fi
   161     if [ -d "${CT_DEBUG_INSTALL_DIR}" ]; then
   162         CT_DoForceRmdir "${CT_DEBUG_INSTALL_DIR}"
   163     fi
   164     # In case we start anew, get rid of the previously saved state directory
   165     if [ -d "${CT_STATE_DIR}" ]; then
   166         CT_DoForceRmdir "${CT_STATE_DIR}"
   167     fi
   168 fi
   169 
   170 # Create the directories we'll use, even if restarting: it does no harm to
   171 # create already existent directories, and CT_BUILD_DIR needs to be created
   172 # anyway
   173 CT_DoExecLog ALL mkdir -p "${CT_TARBALLS_DIR}"
   174 CT_DoExecLog ALL mkdir -p "${CT_SRC_DIR}"
   175 CT_DoExecLog ALL mkdir -p "${CT_BUILD_DIR}"
   176 CT_DoExecLog ALL mkdir -p "${CT_INSTALL_DIR}"
   177 CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}"
   178 CT_DoExecLog ALL mkdir -p "${CT_DEBUG_INSTALL_DIR}"
   179 CT_DoExecLog ALL mkdir -p "${CT_CC_CORE_STATIC_PREFIX_DIR}"
   180 CT_DoExecLog ALL mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}"
   181 CT_DoExecLog ALL mkdir -p "${CT_STATE_DIR}"
   182 
   183 # Kludge: CT_INSTALL_DIR and CT_PREFIX_DIR might have grown read-only if
   184 # the previous build was successful. To be able to move the logfile there,
   185 # switch them back to read/write
   186 CT_DoExecLog ALL chmod -R u+w "${CT_INSTALL_DIR}" "${CT_PREFIX_DIR}"
   187 
   188 # Redirect log to the actual log file now we can
   189 # It's quite understandable that the log file will be installed in the install
   190 # directory, so we must first ensure it exists and is writeable (above) before
   191 # we can log there
   192 exec >/dev/null
   193 case "${CT_LOG_TO_FILE}" in
   194     y)  CT_LOG_FILE="${CT_PREFIX_DIR}/build.log"
   195         cat "${tmp_log_file}" >>"${CT_LOG_FILE}"
   196         rm -f "${tmp_log_file}"
   197         exec >>"${CT_LOG_FILE}"
   198         ;;
   199     *)  rm -f "${tmp_log_file}"
   200         ;;
   201 esac
   202 
   203 # Setting up the rest of the environment only if not restarting
   204 if [ -z "${CT_RESTART}" ]; then
   205     # What's our shell?
   206     # Will be plain /bin/sh on most systems, except if we have /bin/ash and we
   207     # _explictly_ required using it
   208     CT_SHELL="/bin/sh"
   209     [ "${CT_CONFIG_SHELL_ASH}" = "y" -a -x "/bin/ash" ] && CT_SHELL="/bin/ash"
   210 
   211     # Arrange paths depending on wether we use sys-root or not.
   212     if [ "${CT_USE_SYSROOT}" = "y" ]; then
   213         CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}/sys-root"
   214         CT_HEADERS_DIR="${CT_SYSROOT_DIR}/usr/include"
   215         BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   216         CC_CORE_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   217         CC_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   218         LIBC_SYSROOT_ARG=""
   219         # glibc's prefix must be exactly /usr, else --with-sysroot'd gcc will get
   220         # confused when $sysroot/usr/include is not present.
   221         # Note: --prefix=/usr is magic!
   222         # See http://www.gnu.org/software/libc/FAQ.html#s-2.2
   223     else
   224         # plain old way. All libraries in prefix/target/lib
   225         CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}"
   226         CT_HEADERS_DIR="${CT_SYSROOT_DIR}/include"
   227         # hack!  Always use --with-sysroot for binutils.
   228         # binutils 2.14 and later obey it, older binutils ignore it.
   229         # Lets you build a working 32->64 bit cross gcc
   230         BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   231         # Use --with-headers, else final gcc will define disable_glibc while
   232         # building libgcc, and you'll have no profiling
   233         CC_CORE_SYSROOT_ARG="--without-headers"
   234         CC_SYSROOT_ARG="--with-headers=${CT_HEADERS_DIR}"
   235         LIBC_SYSROOT_ARG="prefix="
   236     fi
   237 
   238     # Prepare the 'lib' directories in sysroot, else the ../lib64 hack used by
   239     # 32 -> 64 bit crosscompilers won't work, and build of final gcc will fail with
   240     #  "ld: cannot open crti.o: No such file or directory"
   241     CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/lib"
   242     CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/usr/lib"
   243 
   244     # Prevent gcc from installing its libraries outside of the sys-root
   245     CT_DoExecLog ALL ln -sf "sys-root/lib" "${CT_PREFIX_DIR}/${CT_TARGET}/lib"
   246 
   247     # Now, in case we're 64 bits, just have lib64/ be a symlink to lib/
   248     # so as to have all libraries in the same directory (we can do that
   249     # because we are *not* multilib).
   250     if [ "${CT_ARCH_64}" = "y" ]; then
   251         CT_DoExecLog ALL ln -sf "lib" "${CT_SYSROOT_DIR}/lib64"
   252         CT_DoExecLog ALL ln -sf "lib" "${CT_SYSROOT_DIR}/usr/lib64"
   253         CT_DoExecLog ALL ln -sf "sys-root/lib" "${CT_PREFIX_DIR}/${CT_TARGET}/lib64"
   254     fi
   255 
   256     # Determine build system if not set by the user
   257     CT_Test "You did not specify the build system. That's OK, I can guess..." -z "${CT_BUILD}"
   258     case "${CT_BUILD}" in
   259         "") CT_BUILD=$("${CT_BUILD_PREFIX}gcc${CT_BUILD_SUFFIX}" -dumpmachine);;
   260     esac
   261 
   262     # Prepare mangling patterns to later modify BUILD and HOST (see below)
   263     case "${CT_TOOLCHAIN_TYPE}" in
   264         cross)
   265             CT_HOST="${CT_BUILD}"
   266             build_mangle="build_"
   267             host_mangle="build_"
   268             ;;
   269         *)  CT_Abort "No code for '${CT_TOOLCHAIN_TYPE}' toolchain type!"
   270             ;;
   271     esac
   272 
   273     # Save the real tuples to generate shell-wrappers to the real tools
   274     CT_REAL_BUILD="${CT_BUILD}"
   275     CT_REAL_HOST="${CT_HOST}"
   276 
   277     # Canonicalise CT_BUILD and CT_HOST
   278     # Not only will it give us full-qualified tuples, but it will also ensure
   279     # that they are valid tuples (in case of typo with user-provided tuples)
   280     # That's way better than trying to rewrite config.sub ourselves...
   281     CT_BUILD=$(CT_DoConfigSub "${CT_BUILD}")
   282     CT_HOST=$(CT_DoConfigSub "${CT_HOST}")
   283 
   284     # Modify BUILD and HOST so that gcc always generate a cross-compiler
   285     # even if any of the build, host or target machines are the same.
   286     # NOTE: we'll have to mangle the (BUILD|HOST)->TARGET x-compiler to
   287     #       support canadain build, later...
   288     CT_BUILD="${CT_BUILD/-/-${build_mangle}}"
   289     CT_HOST="${CT_HOST/-/-${host_mangle}}"
   290 
   291     # Now we have mangled our BUILD and HOST tuples, we must fake the new
   292     # cross-tools for those mangled tuples.
   293     CT_DoLog DEBUG "Making build system tools available"
   294     CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/bin"
   295     for m in BUILD HOST; do
   296         r="CT_REAL_${m}"
   297         v="CT_${m}"
   298         p="CT_${m}_PREFIX"
   299         s="CT_${m}_SUFFIX"
   300         if [ -n "${!p}" ]; then
   301             t="${!p}"
   302         else
   303             t="${!r}-"
   304         fi
   305 
   306         for tool in ar as dlltool gcc g++ gcj gnatbind gnatmake ld nm objcopy objdump ranlib strip windres; do
   307             # First try with prefix + suffix
   308             # Then try with prefix only
   309             # Then try with suffix only, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
   310             # Finally try with neither prefix nor suffix, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
   311             # This is needed, because some tools have a prefix and
   312             # a suffix (eg. gcc), while others may have only one,
   313             # or even none (eg. binutils)
   314             where=$(CT_Which "${t}${tool}${!s}")
   315             [ -z "${where}" ] && where=$(CT_Which "${t}${tool}")
   316             if [    -z "${where}"                         \
   317                  -a \(    "${m}" = "BUILD"                \
   318                        -o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
   319                 where=$(CT_Which "${tool}${!s}")
   320             fi
   321             if [ -z "${where}"                            \
   322                  -a \(    "${m}" = "BUILD"                \
   323                        -o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
   324                 where=$(CT_Which "${tool}")
   325             fi
   326 
   327             # Not all tools are available for all platforms, but some are really,
   328             # bally needed
   329             if [ -n "${where}" ]; then
   330                 CT_DoLog DEBUG "  '${!v}-${tool}' -> '${where}'"
   331                 printf "#${BANG}${CT_SHELL}\nexec '${where}' \"\${@}\"\n" >"${CT_PREFIX_DIR}/bin/${!v}-${tool}"
   332                 CT_DoExecLog ALL chmod 700 "${CT_PREFIX_DIR}/bin/${!v}-${tool}"
   333             else
   334                 # We'll at least need some of them...
   335                 case "${tool}" in
   336                     ar|as|gcc|ld|nm|objcopy|objdump|ranlib)
   337                         CT_Abort "Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : either needed!"
   338                         ;;
   339                     *)
   340                         # It does not deserve a WARN level.
   341                         CT_DoLog DEBUG "  Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : not required."
   342                         ;;
   343                 esac
   344             fi
   345         done
   346     done
   347 
   348     # Carefully add paths in the order we want them:
   349     #  - first try in ${CT_PREFIX_DIR}/bin
   350     #  - then try in ${CT_CC_CORE_SHARED_PREFIX_DIR}/bin
   351     #  - then try in ${CT_CC_CORE_STATIC_PREFIX_DIR}/bin
   352     #  - fall back to searching user's PATH
   353     # Of course, neither cross-native nor canadian can run on BUILD,
   354     # so don't add those PATHs in this case...
   355     case "${CT_TOOLCHAIN_TYPE}" in
   356         cross)  export PATH="${CT_PREFIX_DIR}/bin:${CT_CC_CORE_SHARED_PREFIX_DIR}/bin:${CT_CC_CORE_STATIC_PREFIX_DIR}/bin:${PATH}";;
   357         *)  ;;
   358     esac
   359 
   360     # Some makeinfo versions are a pain in [put your most sensible body part here].
   361     # Go ahead with those, by creating a wrapper that keeps partial files, and that
   362     # never fails:
   363     CT_DoLog DEBUG "  'makeinfo' -> '$(CT_Which makeinfo)'"
   364     printf "#${BANG}/bin/sh\n$(CT_Which makeinfo) --force \"\${@}\"\ntrue\n" >"${CT_PREFIX_DIR}/bin/makeinfo"
   365     CT_DoExecLog ALL chmod 700 "${CT_PREFIX_DIR}/bin/makeinfo"
   366 
   367     # Help gcc
   368     CT_CFLAGS_FOR_HOST=
   369     [ "${CT_USE_PIPES}" = "y" ] && CT_CFLAGS_FOR_HOST="${CT_CFLAGS_FOR_HOST} -pipe"
   370 
   371     # Override the configured jobs with what's been given on the command line
   372     [ -n "${CT_JOBS}" ] && CT_PARALLEL_JOBS="${CT_JOBS}"
   373 
   374     # Set the shell to be used by ./configure scripts and by Makefiles (those
   375     # that support it!).
   376     export CONFIG_SHELL="${CT_SHELL}"
   377 
   378     # And help make go faster
   379     PARALLELMFLAGS=
   380     [ ${CT_PARALLEL_JOBS} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -j${CT_PARALLEL_JOBS}"
   381     [ ${CT_LOAD} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -l${CT_LOAD}"
   382     export PARALLELMFLAGS
   383 
   384     CT_DoLog EXTRA "Installing user-supplied crosstool-NG configuration"
   385     CT_DoExecLog DEBUG install -m 0755 "${CT_LIB_DIR}/scripts/toolchain-config.in" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
   386     bzip2 -c -9 .config >>"${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
   387 
   388     CT_DoStep EXTRA "Dumping internal crosstool-NG configuration"
   389     CT_DoLog EXTRA "Building a toolchain for:"
   390     CT_DoLog EXTRA "  build  = ${CT_REAL_BUILD}"
   391     CT_DoLog EXTRA "  host   = ${CT_REAL_HOST}"
   392     CT_DoLog EXTRA "  target = ${CT_TARGET}"
   393     set |egrep '^CT_.+=' |sort |CT_DoLog DEBUG
   394     CT_EndStep
   395 fi
   396 
   397 if [ -z "${CT_RESTART}" ]; then
   398     CT_DoStep INFO "Retrieving needed toolchain components' tarballs"
   399     do_kernel_get
   400     do_gmp_get
   401     do_mpfr_get
   402     do_binutils_get
   403     do_cc_get
   404     do_libc_get
   405     do_tools_get
   406     do_debug_get
   407     CT_EndStep
   408 
   409     if [ "${CT_ONLY_DOWNLOAD}" != "y" ]; then
   410         if [ "${CT_FORCE_EXTRACT}" = "y" ]; then
   411             CT_DoForceRmdir "${CT_SRC_DIR}"
   412             CT_DoExecLog ALL mkdir -p "${CT_SRC_DIR}"
   413         fi
   414         CT_DoStep INFO "Extracting and patching toolchain components"
   415         do_kernel_extract
   416         do_gmp_extract
   417         do_mpfr_extract
   418         do_binutils_extract
   419         do_cc_extract
   420         do_libc_extract
   421         do_tools_extract
   422         do_debug_extract
   423         CT_EndStep
   424     fi
   425 fi
   426 
   427 # Now for the job by itself. Go have a coffee!
   428 if [ "${CT_ONLY_DOWNLOAD}" != "y" -a "${CT_ONLY_EXTRACT}" != "y" ]; then
   429     # Because of CT_RESTART, this becomes quite complex
   430     do_stop=0
   431     prev_step=
   432     [ -n "${CT_RESTART}" ] && do_it=0 || do_it=1
   433     # Aha! CT_STEPS comes from steps.mk!
   434     for step in ${CT_STEPS}; do
   435         if [ ${do_it} -eq 0 ]; then
   436             if [ "${CT_RESTART}" = "${step}" ]; then
   437                 CT_DoLoadState "${step}"
   438                 do_it=1
   439                 do_stop=0
   440             fi
   441         else
   442             CT_DoSaveState ${step}
   443             if [ ${do_stop} -eq 1 ]; then
   444                 CT_DoLog ERROR "Stopping just after step '${prev_step}', as requested."
   445                 exit 0
   446             fi
   447         fi
   448         if [ ${do_it} -eq 1 ]; then
   449             do_${step}
   450             if [ "${CT_STOP}" = "${step}" ]; then
   451                 do_stop=1
   452             fi
   453             if [ "${CT_DEBUG_PAUSE_STEPS}" = "y" ]; then
   454                 CT_DoPause "Step '${step}' finished"
   455             fi
   456         fi
   457         prev_step="${step}"
   458     done
   459 fi
   460 
   461 CT_DoEnd INFO
   462 
   463 # From now-on, it can become impossible to log any time, because
   464 # either we're compressing the log file, or it can become RO any
   465 # moment... Consign all ouptut to oblivion...
   466 CT_DoLog INFO "Finishing installation (may take a few seconds)..."
   467 exec >/dev/null 2>&1
   468 
   469 [ "${CT_LOG_FILE_COMPRESS}" = y ] && bzip2 -9 "${CT_LOG_FILE}"
   470 [ "${CT_INSTALL_DIR_RO}" = "y"  ] && chmod -R a-w "${CT_INSTALL_DIR}"
   471 
   472 trap - EXIT