scripts/crosstool-NG.sh.in
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Dec 14 19:17:37 2009 +0100 (2009-12-14)
changeset 1662 ea3490d46f4e
parent 1517 9a2838d971d4
child 1663 e94f4ffddd1d
permissions -rw-r--r--
scripts: correctly warn when the local tarballs directory does not exist

Warn about a missing local tarball directory, only if it was configured.
Avoid the spurious message:
Directory '${CT_LOCAL_TARBALLS_DIR}' does not exist.
Will not save downloaded tarballs to local storage.

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