scripts/crosstool.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Thu Nov 20 17:48:10 2008 +0000 (2008-11-20)
changeset 1064 492d939dbb19
parent 1062 a435f445d477
child 1082 cfdaef41cd77
permissions -rwxr-xr-x
Overide locale to C so as to have readable logs.
Offer a DEBUG & EXPERIMENTAL setting to not overide locale.

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