scripts/crosstool.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jan 04 22:17:53 2009 +0000 (2009-01-04)
changeset 1123 8c5881324a79
parent 1122 796d1143a1dc
child 1129 cf598d70f6ea
permissions -rwxr-xr-x
Get rid of CT_LIBC_FILE, remove useless CT_MakeAbsolutePath.

CT_LIBC_FILE:
- that one was not easy, as it had sneaked into CT_ExtractAndPatch
- which in turn made CT_ExtractAndPatch have references to C library addons
- which in turn relieved the C library _extract functions from doing their own job
- which in turn imposed some nasty tricks in CT_ExtractAndPatch
- which in turn made life easier for the DUMA _get and _extract functions
- which unveiled some bizare behavior for pushd and popd:
- if using smthg ike: 'pushd foo |bar':
- the directory is *neither* changed
- *nor* is it pushed onto the stack
- which made popd fail

CT_MakeAbsolutePath:
- used only to make CT_LOCAL_TARBALLS_DIR canonical
- which is ((almost) useless:
- hopefully, the user entered a full path already
- if it's not the case, too bad...

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