scripts/crosstool.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jan 04 14:21:00 2009 +0000 (2009-01-04)
changeset 1117 f70e9b41339b
parent 1116 46f6f7f9f37d
child 1119 4e7562023f3e
permissions -rwxr-xr-x
Get rid of CT_BINUTILS_FILE.

/trunk/scripts/build/binutils.sh | 56 28 28 0 +++++++++++++++++++++++-----------------------
/trunk/scripts/crosstool.sh | 1 0 1 0 -
2 files changed, 28 insertions(+), 29 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 # Now, build up the variables from the user-configured options.
    88 CT_GMP_FILE="gmp-${CT_GMP_VERSION}"
    89 CT_MPFR_FILE="mpfr-${CT_MPFR_VERSION}"
    90 CT_CC_FILE="${CT_CC}-${CT_CC_VERSION}"
    91 CT_LIBC_FILE="${CT_LIBC}-${CT_LIBC_VERSION}"
    92 
    93 # Where will we work?
    94 : "${CT_WORK_DIR:=${CT_TOP_DIR}/targets}"
    95 CT_TARBALLS_DIR="${CT_WORK_DIR}/tarballs"
    96 CT_SRC_DIR="${CT_WORK_DIR}/src"
    97 CT_BUILD_DIR="${CT_WORK_DIR}/${CT_TARGET}/build"
    98 CT_DEBUG_INSTALL_DIR="${CT_INSTALL_DIR}/${CT_TARGET}/debug-root"
    99 # Note: we'll always install the core compiler in its own directory, so as to
   100 # not mix the two builds: core and final.
   101 CT_CC_CORE_STATIC_PREFIX_DIR="${CT_BUILD_DIR}/${CT_CC}-core-static"
   102 CT_CC_CORE_SHARED_PREFIX_DIR="${CT_BUILD_DIR}/${CT_CC}-core-shared"
   103 CT_STATE_DIR="${CT_WORK_DIR}/${CT_TARGET}/state"
   104 
   105 # We must ensure that we can restart if asked for!
   106 if [ -n "${CT_RESTART}" -a ! -d "${CT_STATE_DIR}"  ]; then
   107     CT_DoLog ERROR "You asked to restart a non-restartable build"
   108     CT_DoLog ERROR "This happened because you didn't set CT_DEBUG_CT_SAVE_STEPS"
   109     CT_DoLog ERROR "in the config options for the previous build, or the state"
   110     CT_DoLog ERROR "directory for the previous build was deleted."
   111     CT_Abort "I will stop here to avoid any carnage"
   112 fi
   113 
   114 if [ -n "${CT_LOCAL_TARBALLS_DIR}" ]; then
   115     # Make absolute path, it so much easier!
   116     CT_LOCAL_TARBALLS_DIR=$(CT_MakeAbsolutePath "${CT_LOCAL_TARBALLS_DIR}")
   117 fi
   118 
   119 # If the local tarball directory does not exist, say so, and don't try to save there!
   120 if [ ! -d "${CT_LOCAL_TARBALLS_DIR}" ]; then
   121     CT_DoLog WARN "Directory '${CT_LOCAL_TARBALLS_DIR}' does not exist. Will not save downloaded tarballs to local storage."
   122     CT_SAVE_TARBALLS=
   123 fi
   124 
   125 # Some more sanity checks now that we have all paths set up
   126 case "${CT_LOCAL_TARBALLS_DIR},${CT_TARBALLS_DIR},${CT_SRC_DIR},${CT_BUILD_DIR},${CT_PREFIX_DIR},${CT_INSTALL_DIR}" in
   127     *" "*) CT_Abort "Don't use spaces in paths, it breaks things.";;
   128 esac
   129 
   130 # Check now if we can write to the destination directory:
   131 if [ -d "${CT_INSTALL_DIR}" ]; then
   132     CT_TestAndAbort "Destination directory '${CT_INSTALL_DIR}' is not removable" ! -w $(dirname "${CT_INSTALL_DIR}")
   133 fi
   134 
   135 # Good, now grab a bit of informations on the system we're being run on,
   136 # just in case something goes awok, and it's not our fault:
   137 CT_SYS_USER=$(id -un)
   138 CT_SYS_HOSTNAME=$(hostname -f 2>/dev/null || true)
   139 # Hmmm. Some non-DHCP-enabled machines do not have an FQDN... Fall back to node name.
   140 CT_SYS_HOSTNAME="${CT_SYS_HOSTNAME:-$(uname -n)}"
   141 CT_SYS_KERNEL=$(uname -s)
   142 CT_SYS_REVISION=$(uname -r)
   143 # MacOS X lacks '-o' :
   144 CT_SYS_OS=$(uname -o || echo "Unknown (maybe MacOS-X)")
   145 CT_SYS_MACHINE=$(uname -m)
   146 CT_SYS_PROCESSOR=$(uname -p)
   147 CT_SYS_GCC=$(gcc -dumpversion)
   148 CT_SYS_TARGET=$(CT_DoConfigGuess)
   149 CT_TOOLCHAIN_ID="crosstool-${CT_VERSION} build ${CT_STAR_DATE_HUMAN} by ${CT_SYS_USER}@${CT_SYS_HOSTNAME}"
   150 
   151 CT_DoLog EXTRA "Preparing working directories"
   152 
   153 # Ah! The build directory shall be eradicated, even if we restart!
   154 if [ -d "${CT_BUILD_DIR}" ]; then
   155     mv "${CT_BUILD_DIR}" "${CT_BUILD_DIR}.$$"
   156     chmod -R u+w "${CT_BUILD_DIR}.$$"
   157     setsid nohup rm -rf "${CT_BUILD_DIR}.$$" >/dev/null 2>&1 &
   158 fi
   159 
   160 # Don't eradicate directories if we need to restart
   161 if [ -z "${CT_RESTART}" ]; then
   162     # Get rid of pre-existing installed toolchain and previous build directories.
   163     # We need to do that _before_ we can safely log, because the log file will
   164     # most probably be in the toolchain directory.
   165     if [ "${CT_FORCE_DOWNLOAD}" = "y" -a -d "${CT_TARBALLS_DIR}" ]; then
   166         mv "${CT_TARBALLS_DIR}" "${CT_TARBALLS_DIR}.$$"
   167         chmod -R u+w "${CT_TARBALLS_DIR}.$$"
   168         setsid nohup rm -rf "${CT_TARBALLS_DIR}.$$" >/dev/null 2>&1 &
   169     fi
   170     if [ "${CT_FORCE_EXTRACT}" = "y" -a -d "${CT_SRC_DIR}" ]; then
   171         mv "${CT_SRC_DIR}" "${CT_SRC_DIR}.$$"
   172         chmod -R u+w "${CT_SRC_DIR}.$$"
   173         setsid nohup rm -rf "${CT_SRC_DIR}.$$" >/dev/null 2>&1 &
   174     fi
   175     if [ -d "${CT_INSTALL_DIR}" ]; then
   176         mv "${CT_INSTALL_DIR}" "${CT_INSTALL_DIR}.$$"
   177         chmod -R u+w "${CT_INSTALL_DIR}.$$"
   178         setsid nohup rm -rf "${CT_INSTALL_DIR}.$$" >/dev/null 2>&1 &
   179     fi
   180     if [ -d "${CT_DEBUG_INSTALL_DIR}" ]; then
   181         mv "${CT_DEBUG_INSTALL_DIR}" "${CT_DEBUG_INSTALL_DIR}.$$"
   182         chmod -R u+w "${CT_DEBUG_INSTALL_DIR}.$$"
   183         setsid nohup rm -rf "${CT_DEBUG_INSTALL_DIR}.$$" >/dev/null 2>&1 &
   184     fi
   185     # In case we start anew, get rid of the previously saved state directory
   186     if [ -d "${CT_STATE_DIR}" ]; then
   187         mv "${CT_STATE_DIR}" "${CT_STATE_DIR}.$$"
   188         chmod -R u+w "${CT_STATE_DIR}.$$"
   189         setsid nohup rm -rf "${CT_STATE_DIR}.$$" >/dev/null 2>&1 &
   190     fi
   191 fi
   192 
   193 # Create the directories we'll use, even if restarting: it does no harm to
   194 # create already existent directories, and CT_BUILD_DIR needs to be created
   195 # anyway
   196 mkdir -p "${CT_TARBALLS_DIR}"
   197 mkdir -p "${CT_SRC_DIR}"
   198 mkdir -p "${CT_BUILD_DIR}"
   199 mkdir -p "${CT_INSTALL_DIR}"
   200 mkdir -p "${CT_PREFIX_DIR}"
   201 mkdir -p "${CT_DEBUG_INSTALL_DIR}"
   202 mkdir -p "${CT_CC_CORE_STATIC_PREFIX_DIR}"
   203 mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}"
   204 mkdir -p "${CT_STATE_DIR}"
   205 
   206 # Kludge: CT_INSTALL_DIR and CT_PREFIX_DIR might have grown read-only if
   207 # the previous build was successful. To be able to move the logfile there,
   208 # switch them back to read/write
   209 chmod -R u+w "${CT_INSTALL_DIR}" "${CT_PREFIX_DIR}"
   210 
   211 # Redirect log to the actual log file now we can
   212 # It's quite understandable that the log file will be installed in the install
   213 # directory, so we must first ensure it exists and is writeable (above) before
   214 # we can log there
   215 exec >/dev/null
   216 case "${CT_LOG_TO_FILE}" in
   217     y)  CT_LOG_FILE="${CT_PREFIX_DIR}/build.log"
   218         cat "${tmp_log_file}" >>"${CT_LOG_FILE}"
   219         rm -f "${tmp_log_file}"
   220         exec >>"${CT_LOG_FILE}"
   221         ;;
   222     *)  rm -f "${tmp_log_file}"
   223         ;;
   224 esac
   225 
   226 # Setting up the rest of the environment only if not restarting
   227 if [ -z "${CT_RESTART}" ]; then
   228     # What's our shell?
   229     # Will be plain /bin/sh on most systems, except if we have /bin/ash and we
   230     # _explictly_ required using it
   231     CT_SHELL="/bin/sh"
   232     [ "${CT_CONFIG_SHELL_ASH}" = "y" -a -x "/bin/ash" ] && CT_SHELL="/bin/ash"
   233 
   234     # Arrange paths depending on wether we use sys-root or not.
   235     if [ "${CT_USE_SYSROOT}" = "y" ]; then
   236         CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}/sys-root"
   237         CT_HEADERS_DIR="${CT_SYSROOT_DIR}/usr/include"
   238         BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   239         CC_CORE_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   240         CC_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   241         LIBC_SYSROOT_ARG=""
   242         # glibc's prefix must be exactly /usr, else --with-sysroot'd gcc will get
   243         # confused when $sysroot/usr/include is not present.
   244         # Note: --prefix=/usr is magic!
   245         # See http://www.gnu.org/software/libc/FAQ.html#s-2.2
   246     else
   247         # plain old way. All libraries in prefix/target/lib
   248         CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}"
   249         CT_HEADERS_DIR="${CT_SYSROOT_DIR}/include"
   250         # hack!  Always use --with-sysroot for binutils.
   251         # binutils 2.14 and later obey it, older binutils ignore it.
   252         # Lets you build a working 32->64 bit cross gcc
   253         BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   254         # Use --with-headers, else final gcc will define disable_glibc while
   255         # building libgcc, and you'll have no profiling
   256         CC_CORE_SYSROOT_ARG="--without-headers"
   257         CC_SYSROOT_ARG="--with-headers=${CT_HEADERS_DIR}"
   258         LIBC_SYSROOT_ARG="prefix="
   259     fi
   260 
   261     # Prepare the 'lib' directories in sysroot, else the ../lib64 hack used by
   262     # 32 -> 64 bit crosscompilers won't work, and build of final gcc will fail with
   263     #  "ld: cannot open crti.o: No such file or directory"
   264     mkdir -p "${CT_SYSROOT_DIR}/lib"
   265     mkdir -p "${CT_SYSROOT_DIR}/usr/lib"
   266 
   267     # Prevent gcc from installing its libraries outside of the sys-root
   268     ln -sf "sys-root/lib" "${CT_PREFIX_DIR}/${CT_TARGET}/lib"
   269 
   270     # Now, in case we're 64 bits, just have lib64/ be a symlink to lib/
   271     # so as to have all libraries in the same directory (we can do that
   272     # because we are *not* multilib).
   273     if [ "${CT_ARCH_64}" = "y" ]; then
   274         ln -sf "lib" "${CT_SYSROOT_DIR}/lib64"
   275         ln -sf "lib" "${CT_SYSROOT_DIR}/usr/lib64"
   276         ln -sf "sys-root/lib" "${CT_PREFIX_DIR}/${CT_TARGET}/lib64"
   277     fi
   278 
   279     # Determine build system if not set by the user
   280     CT_Test "You did not specify the build system. That's OK, I can guess..." -z "${CT_BUILD}"
   281     case "${CT_BUILD}" in
   282         "") CT_BUILD=$("${CT_BUILD_PREFIX}gcc${CT_BUILD_SUFFIX}" -dumpmachine);;
   283     esac
   284 
   285     # Prepare mangling patterns to later modify BUILD and HOST (see below)
   286     case "${CT_TOOLCHAIN_TYPE}" in
   287         cross)
   288             CT_HOST="${CT_BUILD}"
   289             build_mangle="build_"
   290             host_mangle="build_"
   291             ;;
   292         *)  CT_Abort "No code for '${CT_TOOLCHAIN_TYPE}' toolchain type!"
   293             ;;
   294     esac
   295 
   296     # Save the real tuples to generate shell-wrappers to the real tools
   297     CT_REAL_BUILD="${CT_BUILD}"
   298     CT_REAL_HOST="${CT_HOST}"
   299 
   300     # Canonicalise CT_BUILD and CT_HOST
   301     # Not only will it give us full-qualified tuples, but it will also ensure
   302     # that they are valid tuples (in case of typo with user-provided tuples)
   303     # That's way better than trying to rewrite config.sub ourselves...
   304     CT_BUILD=$(CT_DoConfigSub "${CT_BUILD}")
   305     CT_HOST=$(CT_DoConfigSub "${CT_HOST}")
   306 
   307     # Modify BUILD and HOST so that gcc always generate a cross-compiler
   308     # even if any of the build, host or target machines are the same.
   309     # NOTE: we'll have to mangle the (BUILD|HOST)->TARGET x-compiler to
   310     #       support canadain build, later...
   311     CT_BUILD="${CT_BUILD/-/-${build_mangle}}"
   312     CT_HOST="${CT_HOST/-/-${host_mangle}}"
   313 
   314     # Now we have mangled our BUILD and HOST tuples, we must fake the new
   315     # cross-tools for those mangled tuples.
   316     CT_DoLog DEBUG "Making build system tools available"
   317     mkdir -p "${CT_PREFIX_DIR}/bin"
   318     for m in BUILD HOST; do
   319         r="CT_REAL_${m}"
   320         v="CT_${m}"
   321         p="CT_${m}_PREFIX"
   322         s="CT_${m}_SUFFIX"
   323         if [ -n "${!p}" ]; then
   324             t="${!p}"
   325         else
   326             t="${!r}-"
   327         fi
   328 
   329         for tool in ar as dlltool gcc g++ gnatbind gnatmake ld nm objcopy objdump ranlib strip windres; do
   330             # First try with prefix + suffix
   331             # Then try with prefix only
   332             # Then try with suffix only, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
   333             # Finally try with neither prefix nor suffix, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
   334             # This is needed, because some tools have a prefix and
   335             # a suffix (eg. gcc), while others may have only one,
   336             # or even none (eg. binutils)
   337             where=$(CT_Which "${t}${tool}${!s}")
   338             [ -z "${where}" ] && where=$(CT_Which "${t}${tool}")
   339             if [    -z "${where}"                         \
   340                  -a \(    "${m}" = "BUILD"                \
   341                        -o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
   342                 where=$(CT_Which "${tool}${!s}")
   343             fi
   344             if [ -z "${where}"                            \
   345                  -a \(    "${m}" = "BUILD"                \
   346                        -o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
   347                 where=$(CT_Which "${tool}")
   348             fi
   349 
   350             # Not all tools are available for all platforms, but some are really,
   351             # bally needed
   352             if [ -n "${where}" ]; then
   353                 CT_DoLog DEBUG "  '${!v}-${tool}' -> '${where}'"
   354                 printf "#${BANG}${CT_SHELL}\nexec '${where}' \"\${@}\"\n" >"${CT_PREFIX_DIR}/bin/${!v}-${tool}"
   355                 chmod 700 "${CT_PREFIX_DIR}/bin/${!v}-${tool}"
   356             else
   357                 # We'll at least need some of them...
   358                 case "${tool}" in
   359                     ar|as|gcc|ld|nm|objcopy|objdump|ranlib)
   360                         CT_Abort "Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : either needed!"
   361                         ;;
   362                     *)
   363                         # It does not deserve a WARN level.
   364                         CT_DoLog DEBUG "  Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : not required."
   365                         ;;
   366                 esac
   367             fi
   368         done
   369     done
   370 
   371     # Carefully add paths in the order we want them:
   372     #  - first try in ${CT_PREFIX_DIR}/bin
   373     #  - then try in ${CT_CC_CORE_SHARED_PREFIX_DIR}/bin
   374     #  - then try in ${CT_CC_CORE_STATIC_PREFIX_DIR}/bin
   375     #  - fall back to searching user's PATH
   376     # Of course, neither cross-native nor canadian can run on BUILD,
   377     # so don't add those PATHs in this case...
   378     case "${CT_TOOLCHAIN_TYPE}" in
   379         cross)  export PATH="${CT_PREFIX_DIR}/bin:${CT_CC_CORE_SHARED_PREFIX_DIR}/bin:${CT_CC_CORE_STATIC_PREFIX_DIR}/bin:${PATH}";;
   380         *)  ;;
   381     esac
   382 
   383     # Some makeinfo versions are a pain in [put your most sensible body part here].
   384     # Go ahead with those, by creating a wrapper that keeps partial files, and that
   385     # never fails:
   386     printf "#${BANG}/bin/sh\n$(CT_Which makeinfo) --force \"\${@}\"\ntrue\n" >"${CT_PREFIX_DIR}/bin/makeinfo"
   387     chmod 700 "${CT_PREFIX_DIR}/bin/makeinfo"
   388 
   389     # Help gcc
   390     CT_CFLAGS_FOR_HOST=
   391     [ "${CT_USE_PIPES}" = "y" ] && CT_CFLAGS_FOR_HOST="${CT_CFLAGS_FOR_HOST} -pipe"
   392 
   393     # Override the configured jobs with what's been given on the command line
   394     [ -n "${CT_JOBS}" ] && CT_PARALLEL_JOBS="${CT_JOBS}"
   395 
   396     # Set the shell to be used by ./configure scripts and by Makefiles (those
   397     # that support it!).
   398     export CONFIG_SHELL="${CT_SHELL}"
   399 
   400     # And help make go faster
   401     PARALLELMFLAGS=
   402     [ ${CT_PARALLEL_JOBS} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -j${CT_PARALLEL_JOBS}"
   403     [ ${CT_LOAD} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -l${CT_LOAD}"
   404     export PARALLELMFLAGS
   405 
   406     CT_DoLog EXTRA "Installing user-supplied crosstool-NG configuration"
   407     CT_DoExecLog DEBUG install -m 0755 "${CT_LIB_DIR}/scripts/toolchain-config.in" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
   408     bzip2 -c -9 .config >>"${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
   409 
   410     CT_DoStep EXTRA "Dumping internal crosstool-NG configuration"
   411     CT_DoLog EXTRA "Building a toolchain for:"
   412     CT_DoLog EXTRA "  build  = ${CT_REAL_BUILD}"
   413     CT_DoLog EXTRA "  host   = ${CT_REAL_HOST}"
   414     CT_DoLog EXTRA "  target = ${CT_TARGET}"
   415     set |egrep '^CT_.+=' |sort |CT_DoLog DEBUG
   416     CT_EndStep
   417 fi
   418 
   419 if [ -z "${CT_RESTART}" ]; then
   420     CT_DoStep INFO "Retrieving needed toolchain components' tarballs"
   421     do_kernel_get
   422     do_gmp_get
   423     do_mpfr_get
   424     do_binutils_get
   425     do_cc_get
   426     do_libc_get
   427     do_tools_get
   428     do_debug_get
   429     CT_EndStep
   430 
   431     if [ "${CT_ONLY_DOWNLOAD}" != "y" ]; then
   432         if [ "${CT_FORCE_EXTRACT}" = "y" ]; then
   433             mv "${CT_SRC_DIR}" "${CT_SRC_DIR}.force.$$"
   434             setsid nohup rm -rf "${CT_SRC_DIR}.force.$$" >/dev/null 2>&1
   435             mkdir -p "${CT_SRC_DIR}"
   436         fi
   437         CT_DoStep INFO "Extracting and patching toolchain components"
   438         do_kernel_extract
   439         do_gmp_extract
   440         do_mpfr_extract
   441         do_binutils_extract
   442         do_cc_extract
   443         do_libc_extract
   444         do_tools_extract
   445         do_debug_extract
   446         CT_EndStep
   447     fi
   448 fi
   449 
   450 # Now for the job by itself. Go have a coffee!
   451 if [ "${CT_ONLY_DOWNLOAD}" != "y" -a "${CT_ONLY_EXTRACT}" != "y" ]; then
   452     # Because of CT_RESTART, this becomes quite complex
   453     do_stop=0
   454     prev_step=
   455     [ -n "${CT_RESTART}" ] && do_it=0 || do_it=1
   456     # Aha! CT_STEPS comes from steps.mk!
   457     for step in ${CT_STEPS}; do
   458         if [ ${do_it} -eq 0 ]; then
   459             if [ "${CT_RESTART}" = "${step}" ]; then
   460                 CT_DoLoadState "${step}"
   461                 do_it=1
   462                 do_stop=0
   463             fi
   464         else
   465             CT_DoSaveState ${step}
   466             if [ ${do_stop} -eq 1 ]; then
   467                 CT_DoLog ERROR "Stopping just after step '${prev_step}', as requested."
   468                 exit 0
   469             fi
   470         fi
   471         if [ ${do_it} -eq 1 ]; then
   472             do_${step}
   473             if [ "${CT_STOP}" = "${step}" ]; then
   474                 do_stop=1
   475             fi
   476             if [ "${CT_DEBUG_PAUSE_STEPS}" = "y" ]; then
   477                 CT_DoPause "Step '${step}' finished"
   478             fi
   479         fi
   480         prev_step="${step}"
   481     done
   482 
   483     CT_DoLog INFO "================================================================="
   484 
   485     CT_DoLog DEBUG "Removing access to the build system tools"
   486     find "${CT_PREFIX_DIR}/bin" -name "${CT_BUILD}-"'*' -exec rm -fv {} \; |CT_DoLog DEBUG
   487     find "${CT_PREFIX_DIR}/bin" -name "${CT_HOST}-"'*' -exec rm -fv {} \; |CT_DoLog DEBUG
   488     rm -fv "${CT_PREFIX_DIR}/bin/makeinfo" |CT_DoLog DEBUG
   489 
   490     if [ "${CT_BARE_METAL}" != "y" ]; then
   491         CT_DoLog EXTRA "Installing the populate helper"
   492         sed -r -e 's|@@CT_TARGET@@|'"${CT_TARGET}"'|g;' \
   493             "${CT_LIB_DIR}/scripts/populate.in"           \
   494             >"${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
   495         chmod 755 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
   496     fi
   497 
   498     # Create the aliases to the target tools
   499     CT_DoLog EXTRA "Creating toolchain aliases"
   500     CT_Pushd "${CT_PREFIX_DIR}/bin"
   501     for t in "${CT_TARGET}-"*; do
   502         if [ -n "${CT_TARGET_ALIAS}" ]; then
   503             _t=$(echo "$t" |sed -r -e 's/^'"${CT_TARGET}"'-/'"${CT_TARGET_ALIAS}"'-/;')
   504             ln -sv "${t}" "${_t}" 2>&1
   505         fi
   506         if [ -n "${CT_TARGET_ALIAS_SED_EXPR}" ]; then
   507             _t=$(echo "$t" |sed -r -e "${CT_TARGET_ALIAS_SED_EXPR}")
   508             ln -sv "${t}" "${_t}" 2>&1
   509         fi
   510     done |CT_DoLog ALL
   511     CT_Popd
   512 
   513     # Remove the generated documentation files
   514     if [ "${CT_REMOVE_DOCS}" = "y" ]; then
   515     	CT_DoLog INFO "Removing installed documentation"
   516         rm -rf "${CT_PREFIX_DIR}/"{,usr/}{man,info}
   517         rm -rf "${CT_SYSROOT_DIR}/"{,usr/}{man,info}
   518         rm -rf "${CT_DEBUG_INSTALL_DIR}/"{,usr/}{man,info}
   519     fi
   520 fi
   521 
   522 CT_DoEnd INFO
   523 
   524 if [ "${CT_LOG_FILE_COMPRESS}" = y ]; then
   525     CT_DoLog EXTRA "Compressing log file"
   526     exec >/dev/null
   527     bzip2 -9 "${CT_LOG_FILE}"
   528 fi
   529 
   530 if [ "${CT_INSTALL_DIR_RO}" = "y" ]; then
   531     # OK, now we're done, set the toolchain read-only
   532     # Don't log, the log file may become read-only any moment...
   533     chmod -R a-w "${CT_INSTALL_DIR}" >/dev/null 2>&1
   534 fi
   535 
   536 trap - EXIT