scripts/crosstool.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Thu Nov 13 18:22:23 2008 +0000 (2008-11-13)
changeset 1041 2573519c00d6
parent 1038 33f695f7773a
child 1062 a435f445d477
permissions -rwxr-xr-x
Merge #1195, #1196 and #1203 from /devel/YEM-build_host_target_cleanup:
- Get rid of CT_CC_NATIVE
- Get rid of CT_CANADIAN_OPT
- Sanitise CT_BUILD vs. CT_HOST

/trunk/scripts/build/tools/200-sstrip.sh | 4 2 2 0
/trunk/scripts/build/binutils.sh | 1 0 1 0 -
/trunk/scripts/build/cc/gcc.sh | 11 6 5 0 +-
/trunk/scripts/build/debug/200-duma.sh | 3 1 2 0 -
/trunk/scripts/build/libc/glibc.sh | 10 5 5 0 +-
/trunk/scripts/build/libc/eglibc.sh | 8 4 4 0 +-
/trunk/scripts/crosstool.sh | 168 113 55 0 ++++++++++++++++++++++++++------------
/trunk/config/toolchain.in | 160 137 23 0 +++++++++++++++++++++++++++++++-----
8 files changed, 268 insertions(+), 97 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     # What's our shell?
   227     # Will be plain /bin/sh on most systems, except if we have /bin/ash and we
   228     # _explictly_ required using it
   229     CT_SHELL="/bin/sh"
   230     [ "${CT_CONFIG_SHELL_ASH}" = "y" -a -x "/bin/ash" ] && CT_SHELL="/bin/ash"
   231 
   232     # Arrange paths depending on wether we use sys-root or not.
   233     if [ "${CT_USE_SYSROOT}" = "y" ]; then
   234         CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}/sys-root"
   235         CT_HEADERS_DIR="${CT_SYSROOT_DIR}/usr/include"
   236         BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   237         CC_CORE_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   238         CC_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   239         LIBC_SYSROOT_ARG=""
   240         # glibc's prefix must be exactly /usr, else --with-sysroot'd gcc will get
   241         # confused when $sysroot/usr/include is not present.
   242         # Note: --prefix=/usr is magic!
   243         # See http://www.gnu.org/software/libc/FAQ.html#s-2.2
   244     else
   245         # plain old way. All libraries in prefix/target/lib
   246         CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}"
   247         CT_HEADERS_DIR="${CT_SYSROOT_DIR}/include"
   248         # hack!  Always use --with-sysroot for binutils.
   249         # binutils 2.14 and later obey it, older binutils ignore it.
   250         # Lets you build a working 32->64 bit cross gcc
   251         BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   252         # Use --with-headers, else final gcc will define disable_glibc while
   253         # building libgcc, and you'll have no profiling
   254         CC_CORE_SYSROOT_ARG="--without-headers"
   255         CC_SYSROOT_ARG="--with-headers=${CT_HEADERS_DIR}"
   256         LIBC_SYSROOT_ARG="prefix="
   257     fi
   258 
   259     # Prepare the 'lib' directories in sysroot, else the ../lib64 hack used by
   260     # 32 -> 64 bit crosscompilers won't work, and build of final gcc will fail with
   261     #  "ld: cannot open crti.o: No such file or directory"
   262     mkdir -p "${CT_SYSROOT_DIR}/lib"
   263     mkdir -p "${CT_SYSROOT_DIR}/usr/lib"
   264 
   265     # Prevent gcc from installing its libraries outside of the sys-root
   266     ln -sf "sys-root/lib" "${CT_PREFIX_DIR}/${CT_TARGET}/lib"
   267 
   268     # Now, in case we're 64 bits, just have lib64/ be a symlink to lib/
   269     # so as to have all libraries in the same directory (we can do that
   270     # because we are *not* multilib).
   271     if [ "${CT_ARCH_64}" = "y" ]; then
   272         ln -sf "lib" "${CT_SYSROOT_DIR}/lib64"
   273         ln -sf "lib" "${CT_SYSROOT_DIR}/usr/lib64"
   274         ln -sf "sys-root/lib" "${CT_PREFIX_DIR}/${CT_TARGET}/lib64"
   275     fi
   276 
   277     # Determine build system if not set by the user
   278     CT_Test "You did not specify the build system. That's OK, I can guess..." -z "${CT_BUILD}"
   279     case "${CT_BUILD}" in
   280         "") CT_BUILD=$(gcc -dumpmachine);;
   281         *)  CT_BUILD=$(CT_DoConfigSub "${CT_BUILD}");;
   282     esac
   283 
   284     # Prepare mangling patterns to later modifyu BUILD and HOST (see below)
   285     case "${CT_TOOLCHAIN_TYPE}" in
   286         cross)
   287             CT_HOST="${CT_BUILD}"
   288             build_mangle="build_"
   289             host_mangle="build_"
   290             ;;
   291         *)  CT_Abort "No code for '${CT_TOOLCHAIN_TYPE}' toolchain type!"
   292             ;;
   293     esac
   294 
   295     # Save the real tuples to generate shell-wrappers to the real tools
   296     CT_REAL_BUILD="${CT_BUILD}"
   297     CT_REAL_HOST="${CT_HOST}"
   298 
   299     # Make BUILD and HOST full-fledge four-part tuples (gcc -dumpmachine
   300     # might be only three-part tuple, and I don't know wether config.guess
   301     # can return 3-part tuples...)
   302     case "${CT_BUILD}" in
   303         *-*-*-*-*)  CT_Abort "Unexpected 5-part (or more) build tuple: '${CT_BUILD}'";;
   304         *-*-*-*)    ;;
   305         *-*-*)      CT_BUILD="${CT_BUILD/-/-unknown-}";;
   306         *)          CT_Abort "Unepxected 1- or 2-part build tuple: '${CT_BUILD}'";;
   307     esac
   308     case "${CT_HOST}" in
   309         *-*-*-*-*)  CT_Abort "Unexpected 5-part (or more) host tuple: '${CT_HOST}'";;
   310         *-*-*-*)    ;;
   311         *-*-*)      CT_HOST="${CT_HOST/-/-unknown-}";;
   312         *)          CT_Abort "Unepxected 1- or 2-part host tuple: '${CT_HOST}'";;
   313     esac
   314 
   315     # Modify BUILD and HOST so that gcc always generate a cross-compiler
   316     # even if any of the build, host or target machines are the same.
   317     # NOTE: we'll have to mangle the (BUILD|HOST)->TARGET x-compiler to
   318     #       support canadain build, later...
   319     CT_BUILD="${CT_BUILD/-/-${build_mangle}}"
   320     CT_HOST="${CT_HOST/-/-${host_mangle}}"
   321 
   322     # Now we have mangled our BUILD and HOST tuples, we must fake the new
   323     # cross-tools for those mangled tuples.
   324     BANG='!'
   325     CT_DoLog DEBUG "Making build system tools available"
   326     mkdir -p "${CT_PREFIX_DIR}/bin"
   327     for m in BUILD HOST; do
   328         r="CT_REAL_${m}"
   329         v="CT_${m}"
   330         p="CT_${m}_PREFIX"
   331         s="CT_${m}_SUFFIX"
   332         if [ -n "${!p}" ]; then
   333             t="${!p}"
   334         else
   335             t="${!r}-"
   336         fi
   337 
   338         for tool in ar as dlltool gcc g++ gnatbind gnatmake ld nm objcopy objdump ranlib strip windres; do
   339             # First try with prefix + suffix
   340             # Then try with prefix only
   341             # Then try with suffix only, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
   342             # Finally try with neither prefix nor suffix, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
   343             # This is needed, because some tools have a prefix and
   344             # a suffix (eg. gcc), while others may have only one,
   345             # or even none (eg. binutils)
   346             where=$(CT_Which "${t}${tool}${!s}")
   347             [ -z "${where}" ] && where=$(CT_Which "${t}${tool}")
   348             if [    -z "${where}"                         \
   349                  -a \(    "${m}" = "BUILD"                \
   350                        -o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
   351                 where=$(CT_Which "${tool}${!s}")
   352             fi
   353             if [ -z "${where}"                            \
   354                  -a \(    "${m}" = "BUILD"                \
   355                        -o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
   356                 where=$(CT_Which "${tool}")
   357             fi
   358 
   359             # Not all tools are available for all platforms, but some are really,
   360             # bally needed
   361             if [ -n "${where}" ]; then
   362                 CT_DoLog DEBUG "  '${!v}-${tool}' -> '${where}'"
   363                 printf "#${BANG}${CT_SHELL}\nexec '${where}' \"\${@}\"\n" >"${CT_PREFIX_DIR}/bin/${!v}-${tool}"
   364                 chmod 700 "${CT_PREFIX_DIR}/bin/${!v}-${tool}"
   365             else
   366                 # We'll at least need some of them...
   367                 case "${tool}" in
   368                     ar|as|gcc|ld|nm|objcopy|objdump|ranlib)
   369                         CT_Abort "Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : either needed!"
   370                         ;;
   371                     *)
   372                         # It does not deserve a WARN level.
   373                         CT_DoLog DEBUG "  Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : not required."
   374                         ;;
   375                 esac
   376             fi
   377         done
   378     done
   379 
   380     # Carefully add paths in the order we want them:
   381     #  - first try in ${CT_PREFIX_DIR}/bin
   382     #  - then try in ${CT_CC_CORE_SHARED_PREFIX_DIR}/bin
   383     #  - then try in ${CT_CC_CORE_STATIC_PREFIX_DIR}/bin
   384     #  - fall back to searching user's PATH
   385     # Of course, neither cross-native nor canadian can run on BUILD,
   386     # so don't add those PATHs in this case...
   387     case "${CT_TOOLCHAIN_TYPE}" in
   388         cross)  export PATH="${CT_PREFIX_DIR}/bin:${CT_CC_CORE_SHARED_PREFIX_DIR}/bin:${CT_CC_CORE_STATIC_PREFIX_DIR}/bin:${PATH}";;
   389         *)  ;;
   390     esac
   391 
   392     # Some makeinfo versions are a pain in [put your most sensible body part here].
   393     # Go ahead with those, by creating a wrapper that keeps partial files, and that
   394     # never fails:
   395     echo -e "#!/bin/sh\n$(CT_Which makeinfo) --force \"\${@}\"\ntrue" >"${CT_PREFIX_DIR}/bin/makeinfo"
   396     chmod 700 "${CT_PREFIX_DIR}/bin/makeinfo"
   397 
   398     # Help gcc
   399     CT_CFLAGS_FOR_HOST=
   400     [ "${CT_USE_PIPES}" = "y" ] && CT_CFLAGS_FOR_HOST="${CT_CFLAGS_FOR_HOST} -pipe"
   401 
   402     # Override the configured jobs with what's been given on the command line
   403     [ -n "${CT_JOBS}" ] && CT_PARALLEL_JOBS="${CT_JOBS}"
   404 
   405     # Set the shell to be used by ./configure scripts and by Makefiles (those
   406     # that support it!).
   407     export CONFIG_SHELL="${CT_SHELL}"
   408 
   409     # And help make go faster
   410     PARALLELMFLAGS=
   411     [ ${CT_PARALLEL_JOBS} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -j${CT_PARALLEL_JOBS}"
   412     [ ${CT_LOAD} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -l${CT_LOAD}"
   413     export PARALLELMFLAGS
   414 
   415     CT_DoLog EXTRA "Installing user-supplied crosstool-NG configuration"
   416     CT_DoExecLog DEBUG install -m 0755 "${CT_LIB_DIR}/tools/toolchain-config.in" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
   417     bzip2 -c -9 .config >>"${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
   418 
   419     CT_DoStep EXTRA "Dumping internal crosstool-NG configuration"
   420     CT_DoLog EXTRA "Building a toolchain for:"
   421     CT_DoLog EXTRA "  build  = ${CT_REAL_BUILD}"
   422     CT_DoLog EXTRA "  host   = ${CT_REAL_HOST}"
   423     CT_DoLog EXTRA "  target = ${CT_TARGET}"
   424     set |egrep '^CT_.+=' |sort |CT_DoLog DEBUG
   425     CT_EndStep
   426 fi
   427 
   428 if [ -z "${CT_RESTART}" ]; then
   429     CT_DoStep INFO "Retrieving needed toolchain components' tarballs"
   430     do_kernel_get
   431     do_gmp_get
   432     do_mpfr_get
   433     do_binutils_get
   434     do_cc_get
   435     do_libc_get
   436     do_tools_get
   437     do_debug_get
   438     CT_EndStep
   439 
   440     if [ "${CT_ONLY_DOWNLOAD}" != "y" ]; then
   441         if [ "${CT_FORCE_EXTRACT}" = "y" ]; then
   442             mv "${CT_SRC_DIR}" "${CT_SRC_DIR}.force.$$"
   443             setsid nohup rm -rf "${CT_SRC_DIR}.force.$$" >/dev/null 2>&1
   444             mkdir -p "${CT_SRC_DIR}"
   445         fi
   446         CT_DoStep INFO "Extracting and patching toolchain components"
   447         do_kernel_extract
   448         do_gmp_extract
   449         do_mpfr_extract
   450         do_binutils_extract
   451         do_cc_extract
   452         do_libc_extract
   453         do_tools_extract
   454         do_debug_extract
   455         CT_EndStep
   456     fi
   457 fi
   458 
   459 # Now for the job by itself. Go have a coffee!
   460 if [ "${CT_ONLY_DOWNLOAD}" != "y" -a "${CT_ONLY_EXTRACT}" != "y" ]; then
   461     # Because of CT_RESTART, this becomes quite complex
   462     do_stop=0
   463     prev_step=
   464     [ -n "${CT_RESTART}" ] && do_it=0 || do_it=1
   465     # Aha! CT_STEPS comes from steps.mk!
   466     for step in ${CT_STEPS}; do
   467         if [ ${do_it} -eq 0 ]; then
   468             if [ "${CT_RESTART}" = "${step}" ]; then
   469                 CT_DoLoadState "${step}"
   470                 do_it=1
   471                 do_stop=0
   472             fi
   473         else
   474             CT_DoSaveState ${step}
   475             if [ ${do_stop} -eq 1 ]; then
   476                 CT_DoLog ERROR "Stopping just after step '${prev_step}', as requested."
   477                 exit 0
   478             fi
   479         fi
   480         if [ ${do_it} -eq 1 ]; then
   481             do_${step}
   482             if [ "${CT_STOP}" = "${step}" ]; then
   483                 do_stop=1
   484             fi
   485             if [ "${CT_DEBUG_PAUSE_STEPS}" = "y" ]; then
   486                 CT_DoPause "Step '${step}' finished"
   487             fi
   488         fi
   489         prev_step="${step}"
   490     done
   491 
   492     CT_DoLog INFO "================================================================="
   493 
   494     CT_DoLog DEBUG "Removing access to the build system tools"
   495     find "${CT_PREFIX_DIR}/bin" -name "${CT_BUILD}-"'*' -exec rm -fv {} \; |CT_DoLog DEBUG
   496     find "${CT_PREFIX_DIR}/bin" -name "${CT_HOST}-"'*' -exec rm -fv {} \; |CT_DoLog DEBUG
   497     rm -fv "${CT_PREFIX_DIR}/bin/makeinfo" |CT_DoLog DEBUG
   498 
   499     if [ "${CT_BARE_METAL}" != "y" ]; then
   500         CT_DoLog EXTRA "Installing the populate helper"
   501         sed -r -e 's|@@CT_TARGET@@|'"${CT_TARGET}"'|g;' \
   502             "${CT_LIB_DIR}/tools/populate.in"           \
   503             >"${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
   504         chmod 755 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-populate"
   505     fi
   506 
   507     # Create the aliases to the target tools
   508     CT_DoLog EXTRA "Creating toolchain aliases"
   509     CT_Pushd "${CT_PREFIX_DIR}/bin"
   510     for t in "${CT_TARGET}-"*; do
   511         if [ -n "${CT_TARGET_ALIAS}" ]; then
   512             _t=$(echo "$t" |sed -r -e 's/^'"${CT_TARGET}"'-/'"${CT_TARGET_ALIAS}"'-/;')
   513             ln -sv "${t}" "${_t}" 2>&1
   514         fi
   515         if [ -n "${CT_TARGET_ALIAS_SED_EXPR}" ]; then
   516             _t=$(echo "$t" |sed -r -e "${CT_TARGET_ALIAS_SED_EXPR}")
   517             ln -sv "${t}" "${_t}" 2>&1
   518         fi
   519     done |CT_DoLog ALL
   520     CT_Popd
   521 
   522     # Remove the generated documentation files
   523     if [ "${CT_REMOVE_DOCS}" = "y" ]; then
   524     	CT_DoLog INFO "Removing installed documentation"
   525         rm -rf "${CT_PREFIX_DIR}/"{,usr/}{man,info}
   526         rm -rf "${CT_SYSROOT_DIR}/"{,usr/}{man,info}
   527         rm -rf "${CT_DEBUG_INSTALL_DIR}/"{,usr/}{man,info}
   528     fi
   529 fi
   530 
   531 CT_DoEnd INFO
   532 
   533 if [ "${CT_LOG_FILE_COMPRESS}" = y ]; then
   534     CT_DoLog EXTRA "Compressing log file"
   535     exec >/dev/null
   536     bzip2 -9 "${CT_LOG_FILE}"
   537 fi
   538 
   539 if [ "${CT_INSTALL_DIR_RO}" = "y" ]; then
   540     # OK, now we're done, set the toolchain read-only
   541     # Don't log, the log file may become read-only any moment...
   542     chmod -R a-w "${CT_INSTALL_DIR}" >/dev/null 2>&1
   543 fi
   544 
   545 trap - EXIT