scripts/crosstool.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jan 04 14:39:39 2009 +0000 (2009-01-04)
changeset 1122 796d1143a1dc
parent 1119 4e7562023f3e
child 1123 8c5881324a79
permissions -rwxr-xr-x
Get rid of CT_CC_FILE.

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