scripts/crosstool.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Fri Nov 07 08:09:42 2008 +0000 (2008-11-07)
changeset 1038 33f695f7773a
parent 1033 1dd56375ff9e
child 1041 2573519c00d6
permissions -rwxr-xr-x
Do not autodetect 64-bit archs, have them tell be 'select'-ing ARCH_64 in the configuration.

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