scripts/crosstool-NG.sh.in
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Fri Sep 04 17:27:16 2009 +0200 (2009-09-04)
changeset 1512 439a6b292917
parent 1446 0a44fc4d6bd0
parent 1433 f04c7879f3c2
child 1517 9a2838d971d4
permissions -rw-r--r--
TODO: update

Add TODO list for m4, autoconf, automake and libtool.
Building our own versions would remove burden from the users
who have older versions on their distributions, and are not
ready/able/allowed to upgrade.
     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 "  '${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 [ ! -d "${CT_LOCAL_TARBALLS_DIR}" ]; then
   172     CT_DoLog WARN "Directory '${CT_LOCAL_TARBALLS_DIR}' does not exist. Will not save downloaded tarballs to local storage."
   173     CT_SAVE_TARBALLS=
   174 fi
   175 
   176 # Check now if we can write to the destination directory:
   177 if [ -d "${CT_INSTALL_DIR}" ]; then
   178     CT_TestAndAbort "Destination directory '${CT_INSTALL_DIR}' is not removable" ! -w $(dirname "${CT_INSTALL_DIR}")
   179 fi
   180 
   181 # Good, now grab a bit of informations on the system we're being run on,
   182 # just in case something goes awok, and it's not our fault:
   183 CT_SYS_USER=$(id -un)
   184 CT_SYS_HOSTNAME=$(hostname -f 2>/dev/null || true)
   185 # Hmmm. Some non-DHCP-enabled machines do not have an FQDN... Fall back to node name.
   186 CT_SYS_HOSTNAME="${CT_SYS_HOSTNAME:-$(uname -n)}"
   187 CT_SYS_KERNEL=$(uname -s)
   188 CT_SYS_REVISION=$(uname -r)
   189 # MacOS X lacks '-o' :
   190 CT_SYS_OS=$(uname -o || echo "Unknown (maybe MacOS-X)")
   191 CT_SYS_MACHINE=$(uname -m)
   192 CT_SYS_PROCESSOR=$(uname -p)
   193 CT_SYS_GCC=$(gcc -dumpversion)
   194 CT_SYS_TARGET=$(CT_DoConfigGuess)
   195 CT_TOOLCHAIN_ID="crosstool-${CT_VERSION} build ${CT_STAR_DATE_HUMAN} by ${CT_SYS_USER}@${CT_SYS_HOSTNAME}"
   196 
   197 CT_DoLog EXTRA "Preparing working directories"
   198 
   199 # Ah! The build directory shall be eradicated, even if we restart!
   200 if [ -d "${CT_BUILD_DIR}" ]; then
   201     CT_DoForceRmdir "${CT_BUILD_DIR}"
   202 fi
   203 
   204 # Don't eradicate directories if we need to restart
   205 if [ -z "${CT_RESTART}" ]; then
   206     # Get rid of pre-existing installed toolchain and previous build directories.
   207     # We need to do that _before_ we can safely log, because the log file will
   208     # most probably be in the toolchain directory.
   209     if [ "${CT_FORCE_DOWNLOAD}" = "y" -a -d "${CT_TARBALLS_DIR}" ]; then
   210         CT_DoForceRmdir "${CT_TARBALLS_DIR}"
   211     fi
   212     if [ "${CT_FORCE_EXTRACT}" = "y" -a -d "${CT_SRC_DIR}" ]; then
   213         CT_DoForceRmdir "${CT_SRC_DIR}"
   214     fi
   215     if [ -d "${CT_INSTALL_DIR}" ]; then
   216         CT_DoForceRmdir "${CT_INSTALL_DIR}"
   217     fi
   218     # In case we start anew, get rid of the previously saved state directory
   219     if [ -d "${CT_STATE_DIR}" ]; then
   220         CT_DoForceRmdir "${CT_STATE_DIR}"
   221     fi
   222 fi
   223 
   224 # Create the directories we'll use, even if restarting: it does no harm to
   225 # create already existent directories, and CT_BUILD_DIR needs to be created
   226 # anyway
   227 CT_DoExecLog ALL mkdir -p "${CT_TARBALLS_DIR}"
   228 CT_DoExecLog ALL mkdir -p "${CT_SRC_DIR}"
   229 CT_DoExecLog ALL mkdir -p "${CT_BUILD_DIR}"
   230 CT_DoExecLog ALL mkdir -p "${CT_CONFIG_DIR}"
   231 CT_DoExecLog ALL mkdir -p "${CT_INSTALL_DIR}"
   232 CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}"
   233 if [ -z "${CT_CANADIAN}" ]; then
   234     CT_DoExecLog ALL mkdir -p "${CT_CC_CORE_STATIC_PREFIX_DIR}"
   235     CT_DoExecLog ALL mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}"
   236 fi
   237 
   238 # Only create the state dir if asked for a restartable build
   239 [ -n "${CT_DEBUG_CT_SAVE_STEPS}" ] && CT_DoExecLog ALL mkdir -p "${CT_STATE_DIR}"
   240 
   241 # Check install file system case-sensitiveness
   242 CT_DoExecLog DEBUG touch "${CT_PREFIX_DIR}/foo"
   243 CT_TestAndAbort "Your file system in '${CT_PREFIX_DIR}' is *not* case-sensitive!" -f "${CT_PREFIX_DIR}/FOO"
   244 CT_DoExecLog DEBUG rm -f "${CT_PREFIX_DIR}/foo"
   245 
   246 # Kludge: CT_INSTALL_DIR and CT_PREFIX_DIR might have grown read-only if
   247 # the previous build was successful. To be able to move the logfile there,
   248 # switch them back to read/write
   249 CT_DoExecLog ALL chmod -R u+w "${CT_INSTALL_DIR}" "${CT_PREFIX_DIR}"
   250 
   251 # Redirect log to the actual log file now we can
   252 # It's quite understandable that the log file will be installed in the install
   253 # directory, so we must first ensure it exists and is writeable (above) before
   254 # we can log there
   255 exec >/dev/null
   256 case "${CT_LOG_TO_FILE}" in
   257     y)  CT_LOG_FILE="${CT_PREFIX_DIR}/build.log"
   258         cat "${tmp_log_file}" >>"${CT_LOG_FILE}"
   259         rm -f "${tmp_log_file}"
   260         exec >>"${CT_LOG_FILE}"
   261         ;;
   262     *)  rm -f "${tmp_log_file}"
   263         ;;
   264 esac
   265 
   266 # Setting up the rest of the environment only if not restarting
   267 if [ -z "${CT_RESTART}" ]; then
   268     # Arrange paths depending on wether we use sys-root or not.
   269     if [ "${CT_USE_SYSROOT}" = "y" ]; then
   270         CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}/${CT_SYSROOT_DIR_PREFIX}/sys-root"
   271         CT_DEBUGROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}/${CT_SYSROOT_DIR_PREFIX}/debug-root"
   272         CT_HEADERS_DIR="${CT_SYSROOT_DIR}/usr/include"
   273         BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   274         CC_CORE_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   275         CC_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   276         LIBC_SYSROOT_ARG=""
   277         # glibc's prefix must be exactly /usr, else --with-sysroot'd gcc will get
   278         # confused when $sysroot/usr/include is not present.
   279         # Note: --prefix=/usr is magic!
   280         # See http://www.gnu.org/software/libc/FAQ.html#s-2.2
   281     else
   282         # plain old way. All libraries in prefix/target/lib
   283         CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}"
   284         CT_DEBUGROOT_DIR="${CT_SYSROOT_DIR}"
   285         CT_HEADERS_DIR="${CT_SYSROOT_DIR}/include"
   286         # hack!  Always use --with-sysroot for binutils.
   287         # binutils 2.14 and later obey it, older binutils ignore it.
   288         # Lets you build a working 32->64 bit cross gcc
   289         BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   290         # Use --with-headers, else final gcc will define disable_glibc while
   291         # building libgcc, and you'll have no profiling
   292         CC_CORE_SYSROOT_ARG="--without-headers"
   293         CC_SYSROOT_ARG="--with-headers=${CT_HEADERS_DIR}"
   294         LIBC_SYSROOT_ARG="prefix="
   295     fi
   296     CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}"
   297     CT_DoExecLog ALL mkdir -p "${CT_DEBUGROOT_DIR}"
   298 
   299     # Prepare the 'lib' directories in sysroot, else the ../lib64 hack used by
   300     # 32 -> 64 bit crosscompilers won't work, and build of final gcc will fail
   301     # with: "ld: cannot open crti.o: No such file or directory"
   302     # Also prepare the lib directory in the install dir, else some 64 bit archs
   303     # won't build
   304     CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/lib"
   305     CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/lib"
   306     CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/usr/lib"
   307 
   308     if [ "${CT_USE_SYSROOT}" = "y" ]; then
   309       # Prevent gcc from installing its libraries outside of the sys-root
   310       CT_DoExecLog ALL ln -sf "./${CT_SYSROOT_DIR_PREFIX}/sys-root/lib" "${CT_PREFIX_DIR}/${CT_TARGET}/lib"
   311     fi
   312 
   313     # Now, in case we're 64 bits, just have lib64/ be a symlink to lib/
   314     # so as to have all libraries in the same directory (we can do that
   315     # because we are *not* multilib).
   316     if [ "${CT_ARCH_64}" = "y" ]; then
   317         CT_DoExecLog ALL ln -sf "lib" "${CT_PREFIX_DIR}/lib64"
   318         CT_DoExecLog ALL ln -sf "lib" "${CT_SYSROOT_DIR}/lib64"
   319         CT_DoExecLog ALL ln -sf "lib" "${CT_SYSROOT_DIR}/usr/lib64"
   320         CT_DoExecLog ALL ln -sf "lib" "${CT_PREFIX_DIR}/${CT_TARGET}/lib64"
   321     fi
   322 
   323     # Determine build system if not set by the user
   324     CT_Test "You did not specify the build system. That's OK, I can guess..." -z "${CT_BUILD}"
   325     case "${CT_BUILD}" in
   326         "") CT_BUILD=$("${CT_BUILD_PREFIX}gcc${CT_BUILD_SUFFIX}" -dumpmachine);;
   327     esac
   328 
   329     # Prepare mangling patterns to later modify BUILD and HOST (see below)
   330     case "${CT_TOOLCHAIN_TYPE}" in
   331         cross)
   332             # A cross-compiler runs on the same machine it is built on
   333             CT_HOST="${CT_BUILD}"
   334             build_mangle="build_"
   335             host_mangle="build_"
   336             target_mangle=""
   337             install_build_tools_for="BUILD HOST"
   338             ;;
   339         canadian)
   340             build_mangle="build_"
   341             host_mangle="host_"
   342             target_mangle=""
   343             install_build_tools_for="BUILD HOST TARGET"
   344             ;;
   345         *)  CT_Abort "No code for '${CT_TOOLCHAIN_TYPE}' toolchain type!"
   346             ;;
   347     esac
   348 
   349     # Save the real tuples to generate shell-wrappers to the real tools
   350     CT_REAL_BUILD="${CT_BUILD}"
   351     CT_REAL_HOST="${CT_HOST}"
   352     CT_REAL_TARGET="${CT_TARGET}"
   353 
   354     # Canonicalise CT_BUILD and CT_HOST
   355     # Not only will it give us full-qualified tuples, but it will also ensure
   356     # that they are valid tuples (in case of typo with user-provided tuples)
   357     # That's way better than trying to rewrite config.sub ourselves...
   358     # CT_TARGET is already made canonical in CT_DoBuildTargetTuple
   359     CT_BUILD=$(CT_DoConfigSub "${CT_BUILD}")
   360     CT_HOST=$(CT_DoConfigSub "${CT_HOST}")
   361 
   362     # Modify BUILD and HOST so that gcc always generate a cross-compiler
   363     # even if any of the build, host or target machines are the same.
   364     # NOTE: we'll have to mangle the (BUILD|HOST)->TARGET x-compiler to
   365     #       support canadain build, later...
   366     CT_BUILD="${CT_BUILD/-/-${build_mangle}}"
   367     CT_HOST="${CT_HOST/-/-${host_mangle}}"
   368     CT_TARGET="${CT_TARGET/-/-${target_mangle}}"
   369 
   370     # Now we have mangled our BUILD and HOST tuples, we must fake the new
   371     # cross-tools for those mangled tuples.
   372     CT_DoLog DEBUG "Making build system tools available"
   373     CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/buildtools"
   374     for m in ${install_build_tools_for}; do
   375         r="CT_REAL_${m}"
   376         v="CT_${m}"
   377         p="CT_${m}_PREFIX"
   378         s="CT_${m}_SUFFIX"
   379         if [ -n "${!p}" ]; then
   380             t="${!p}"
   381         else
   382             t="${!r}-"
   383         fi
   384 
   385         for tool in ar as dlltool gcc g++ gcj gnatbind gnatmake ld nm objcopy objdump ranlib strip windres; do
   386             # First try with prefix + suffix
   387             # Then try with prefix only
   388             # Then try with suffix only, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
   389             # Finally try with neither prefix nor suffix, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
   390             # This is needed, because some tools have a prefix and
   391             # a suffix (eg. gcc), while others may have only one,
   392             # or even none (eg. binutils)
   393             where=$(CT_Which "${t}${tool}${!s}")
   394             [ -z "${where}" ] && where=$(CT_Which "${t}${tool}")
   395             if [    -z "${where}"                         \
   396                  -a \(    "${m}" = "BUILD"                \
   397                        -o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
   398                 where=$(CT_Which "${tool}${!s}")
   399             fi
   400             if [ -z "${where}"                            \
   401                  -a \(    "${m}" = "BUILD"                \
   402                        -o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
   403                 where=$(CT_Which "${tool}")
   404             fi
   405 
   406             # Not all tools are available for all platforms, but some are really,
   407             # bally needed
   408             if [ -n "${where}" ]; then
   409                 CT_DoLog DEBUG "  '${!v}-${tool}' -> '${where}'"
   410                 printf "#${BANG}${CT_SHELL}\nexec '${where}' \"\${@}\"\n" >"${CT_PREFIX_DIR}/buildtools/${!v}-${tool}"
   411                 CT_DoExecLog ALL chmod 700 "${CT_PREFIX_DIR}/buildtools/${!v}-${tool}"
   412             else
   413                 case "${tool}" in
   414                     # We'll at least need some of them...
   415                     ar|as|gcc|g++|ld|nm|objcopy|objdump|ranlib)
   416                         CT_Abort "Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : either needed!"
   417                         ;;
   418                     # Some are conditionnally required
   419                     # Add them in alphabetical (C locale) ordering
   420                     gcj)
   421                         CT_TestAndAbort "Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : either needed!" "${CT_CC_LANG_JAVA}" = "y"
   422                         ;;
   423                     # If any other is missing, only warn at low level
   424                     *)
   425                         # It does not deserve a WARN level.
   426                         CT_DoLog DEBUG "  Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : not required."
   427                         ;;
   428                 esac
   429             fi
   430         done
   431     done
   432 
   433     # Carefully add paths in the order we want them:
   434     #  - first try in ${CT_PREFIX_DIR}/bin
   435     #  - then try in ${CT_CC_CORE_SHARED_PREFIX_DIR}/bin
   436     #  - then try in ${CT_CC_CORE_STATIC_PREFIX_DIR}/bin
   437     #  - fall back to searching user's PATH
   438     # Of course, neither cross-native nor canadian can run on BUILD,
   439     # so don't add those PATHs in this case...
   440     case "${CT_TOOLCHAIN_TYPE}" in
   441         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}";;
   442         canadian) export PATH="${CT_PREFIX_DIR}/buildtools:${PATH}";;
   443         *)  ;;
   444     esac
   445 
   446     # Some makeinfo versions are a pain in [put your most sensible body part here].
   447     # Go ahead with those, by creating a wrapper that keeps partial files, and that
   448     # never fails:
   449     CT_DoLog DEBUG "  'makeinfo' -> '$(CT_Which makeinfo)'"
   450     printf "#${BANG}${CT_SHELL}\n$(CT_Which makeinfo) --force \"\${@}\"\ntrue\n" >"${CT_PREFIX_DIR}/buildtools/makeinfo"
   451     CT_DoExecLog ALL chmod 700 "${CT_PREFIX_DIR}/buildtools/makeinfo"
   452 
   453     # Help gcc
   454     CT_CFLAGS_FOR_HOST=
   455     [ "${CT_USE_PIPES}" = "y" ] && CT_CFLAGS_FOR_HOST="${CT_CFLAGS_FOR_HOST} -pipe"
   456 
   457     # Override the configured jobs with what's been given on the command line
   458     [ -n "${CT_JOBS}" ] && CT_PARALLEL_JOBS="${CT_JOBS}"
   459 
   460     # Set the shell to be used by ./configure scripts and by Makefiles (those
   461     # that support it!).
   462     export CONFIG_SHELL="${CT_SHELL}"   # for ./configure
   463     export SHELL="${CT_SHELL}"          # for Makefiles
   464 
   465     # And help make go faster
   466     PARALLELMFLAGS=
   467     [ ${CT_PARALLEL_JOBS} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -j${CT_PARALLEL_JOBS}"
   468     [ ${CT_LOAD} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -l${CT_LOAD}"
   469     export PARALLELMFLAGS
   470 
   471     CT_DoLog EXTRA "Installing user-supplied crosstool-NG configuration"
   472     CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/bin"
   473     CT_DoExecLog DEBUG install -m 0755 "${CT_LIB_DIR}/scripts/toolchain-config.in" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
   474     CT_DoExecLog DEBUG sed -r -i -e 's,@@grep@@,"'"${grep}"'",;' "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
   475     bzip2 -c -9 .config >>"${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
   476 
   477     CT_DoStep EXTRA "Dumping internal crosstool-NG configuration"
   478     CT_DoLog EXTRA "Building a toolchain for:"
   479     CT_DoLog EXTRA "  build  = ${CT_REAL_BUILD}"
   480     CT_DoLog EXTRA "  host   = ${CT_REAL_HOST}"
   481     CT_DoLog EXTRA "  target = ${CT_TARGET}"
   482     set |grep -E '^CT_.+=' |sort |CT_DoLog DEBUG
   483     CT_EndStep
   484 fi
   485 
   486 if [ -z "${CT_RESTART}" ]; then
   487     CT_DoStep INFO "Retrieving needed toolchain components' tarballs"
   488     do_kernel_get
   489     do_gmp_get
   490     do_mpfr_get
   491     do_ppl_get
   492     do_cloog_get
   493     do_mpc_get
   494     do_binutils_get
   495     do_cc_get
   496     do_libc_get
   497     do_tools_get
   498     do_debug_get
   499     CT_EndStep
   500 
   501     if [ "${CT_ONLY_DOWNLOAD}" != "y" ]; then
   502         if [ "${CT_FORCE_EXTRACT}" = "y" ]; then
   503             CT_DoForceRmdir "${CT_SRC_DIR}"
   504             CT_DoExecLog ALL mkdir -p "${CT_SRC_DIR}"
   505         fi
   506         CT_DoStep INFO "Extracting and patching toolchain components"
   507         do_kernel_extract
   508         do_gmp_extract
   509         do_mpfr_extract
   510         do_ppl_extract
   511         do_cloog_extract
   512         do_mpc_extract
   513         do_binutils_extract
   514         do_cc_extract
   515         do_libc_extract
   516         do_tools_extract
   517         do_debug_extract
   518         CT_EndStep
   519     fi
   520 fi
   521 
   522 # Now for the job by itself. Go have a coffee!
   523 if [ "${CT_ONLY_DOWNLOAD}" != "y" -a "${CT_ONLY_EXTRACT}" != "y" ]; then
   524     # Because of CT_RESTART, this becomes quite complex
   525     do_stop=0
   526     prev_step=
   527     [ -n "${CT_RESTART}" ] && do_it=0 || do_it=1
   528     # Aha! CT_STEPS comes from steps.mk!
   529     for step in ${CT_STEPS}; do
   530         if [ ${do_it} -eq 0 ]; then
   531             if [ "${CT_RESTART}" = "${step}" ]; then
   532                 CT_DoLoadState "${step}"
   533                 do_it=1
   534                 do_stop=0
   535             fi
   536         else
   537             CT_DoSaveState ${step}
   538             if [ ${do_stop} -eq 1 ]; then
   539                 CT_DoLog ERROR "Stopping just after step '${prev_step}', as requested."
   540                 exit 0
   541             fi
   542         fi
   543         if [ ${do_it} -eq 1 ]; then
   544             do_${step}
   545             if [ "${CT_STOP}" = "${step}" ]; then
   546                 do_stop=1
   547             fi
   548             if [ "${CT_DEBUG_PAUSE_STEPS}" = "y" ]; then
   549                 CT_DoPause "Step '${step}' finished"
   550             fi
   551         fi
   552         prev_step="${step}"
   553     done
   554 fi
   555 
   556 CT_DoEnd INFO
   557 
   558 # From now-on, it can become impossible to log any time, because
   559 # either we're compressing the log file, or it can become RO any
   560 # moment... Consign all ouptut to oblivion...
   561 CT_DoLog INFO "Finishing installation (may take a few seconds)..."
   562 exec >/dev/null 2>&1
   563 
   564 [ "${CT_LOG_FILE_COMPRESS}" = y ] && bzip2 -9 "${CT_LOG_FILE}"
   565 [ "${CT_INSTALL_DIR_RO}" = "y"  ] && chmod -R a-w "${CT_INSTALL_DIR}"
   566 
   567 trap - EXIT