1.1 --- a/Makefile.in Mon Jan 26 18:36:02 2009 +0000
1.2 +++ b/Makefile.in Mon Jan 26 22:43:08 2009 +0000
1.3 @@ -1,7 +1,37 @@
1.4 # Makefile.in for building crosstool-NG
1.5 # This file serves as source for the ./configure operation
1.6
1.7 -MAKEFLAGS += --no-print-directory --no-builtin-rules
1.8 +# This series of test is here because GNU make 3.81 will *not* use MAKEFLAGS
1.9 +# to set additional flags in the current Makfile ( see:
1.10 +# http://savannah.gnu.org/bugs/?20501 ), although the make manual says it
1.11 +# should ( see: http://www.gnu.org/software/make/manual/make.html#Options_002fRecursion )
1.12 +# so we have to work it around by calling ourselves back if needed
1.13 +
1.14 +# So why do we need not to use the built rules and variables? Because we
1.15 +# need to generate scripts/crosstool-NG.sh from scripts/crosstool-NG.sh.in
1.16 +# and there is a built-in implicit rule '%.sh:' that has neither a pre-requisite
1.17 +# nor a command associated, and that built-in implicit rule takes precedence
1.18 +# over our non-built-in implicit rule '%: %.in', below.
1.19 +
1.20 +# CT_MAKEFLAGS will be used later, below...
1.21 +
1.22 +# Do not print directories as we descend into them
1.23 +ifeq ($(filter --no-print-directory,$(MAKEFLAGS)),)
1.24 +CT_MAKEFLAGS += --no-print-directory
1.25 +endif
1.26 +
1.27 +# Use neither builtin rules, nor builtin variables
1.28 +# Note: dual test, because if -R and -r are given on the command line
1.29 +# (who knows?), MAKEFLAGS contains 'Rr' instead of '-Rr', while adding
1.30 +# '-Rr' to MAKEFLAGS adds it literaly ( and does not add 'Rr' )
1.31 +ifeq ($(filter Rr,$(MAKEFLAGS)),)
1.32 +ifeq ($(filter -Rr,$(MAKEFLAGS)),)
1.33 +CT_MAKEFLAGS += -Rr
1.34 +endif # No -Rr
1.35 +endif # No Rr
1.36 +
1.37 +# Remove any suffix rules
1.38 +.SUFFIXES:
1.39
1.40 all: Makefile build
1.41
1.42 @@ -42,6 +72,17 @@
1.43 ###############################################################################
1.44 # Global make rules
1.45
1.46 +# If any extra MAKEFLAGS were added, re-run ourselves
1.47 +# See top of file for an explanation of why this is needed...
1.48 +ifneq ($(strip $(CT_MAKEFLAGS)),)
1.49 +
1.50 +MAKEFLAGS += $(CT_MAKEFLAGS)
1.51 +build install clean distclean uninstall:
1.52 + @$(MAKE) $@
1.53 +
1.54 +else
1.55 +# There were no additional MAKEFLAGS to add, do the job
1.56 +
1.57 TARGETS := bin lib doc man
1.58
1.59 build: $(patsubst %,build-%,$(TARGETS))
1.60 @@ -62,7 +103,7 @@
1.61 #--------------------------------------
1.62 # Build rules
1.63
1.64 -build-bin: ct-ng
1.65 +build-bin: ct-ng scripts/crosstool-NG.sh
1.66
1.67 build-lib: paths.mk
1.68
1.69 @@ -83,6 +124,7 @@
1.70 -e 's,@@CT_VERSION@@,$(VERSION),g;' \
1.71 -e 's,@@CT_DATE@@,$(DATE),g;' \
1.72 -e 's,@@CT_make@@,$(make),g;' \
1.73 + -e 's,@@CT_bash@@,$(bash),g;' \
1.74 $@.in >$@
1.75
1.76 # We create a script fragment that is parseable from inside a Makefile,
1.77 @@ -127,6 +169,8 @@
1.78 real-install:
1.79 @echo " CHMOD 'ct-ng'"
1.80 @chmod a+x ct-ng
1.81 + @echo " CHMOD 'scripts/crosstool-NG.sh'"
1.82 + @chmod a+x scripts/crosstool-NG.sh
1.83
1.84 real-uninstall:
1.85 @true
1.86 @@ -206,3 +250,5 @@
1.87 @rm -f "$(DESTDIR)$(MANDIR)/ct-ng.1"{,.gz}
1.88
1.89 endif # Not --local
1.90 +
1.91 +endif # No extra MAKEFLAGS were added
2.1 --- a/scripts/crosstool-NG.sh Mon Jan 26 18:36:02 2009 +0000
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,472 +0,0 @@
2.4 -#!/bin/bash
2.5 -# Copyright 2007 Yann E. MORIN
2.6 -# Licensed under the GPL v2. See COPYING in the root of this package.
2.7 -
2.8 -# This is the main entry point to crosstool
2.9 -# This will:
2.10 -# - download, extract and patch the toolchain components
2.11 -# - build and install each components in turn
2.12 -# - and eventually test the resulting toolchain
2.13 -
2.14 -# What this file does is prepare the environment, based upon the user-choosen
2.15 -# options. It also checks the existing environment for un-friendly variables,
2.16 -# and builds the tools.
2.17 -
2.18 -# Parse the common functions
2.19 -# Note: some initialisation and sanitizing is done while parsing this file,
2.20 -# most notably:
2.21 -# - set trap handler on errors,
2.22 -# - don't hash commands lookups,
2.23 -# - initialise logging.
2.24 -. "${CT_LIB_DIR}/scripts/functions"
2.25 -
2.26 -# Parse the configuration file
2.27 -# It has some info about the logging facility, so include it early
2.28 -. .config
2.29 -
2.30 -# Overide the locale early, in case we ever translate crosstool-NG messages
2.31 -[ -z "${CT_NO_OVERIDE_LC_MESSAGES}" ] && export LC_ALL=C
2.32 -
2.33 -# Start date. Can't be done until we know the locale
2.34 -CT_STAR_DATE=$(CT_DoDate +%s%N)
2.35 -CT_STAR_DATE_HUMAN=$(CT_DoDate +%Y%m%d.%H%M%S)
2.36 -
2.37 -# Yes! We can do full logging from now on!
2.38 -CT_DoLog INFO "Build started ${CT_STAR_DATE_HUMAN}"
2.39 -
2.40 -# renice oursleves
2.41 -CT_DoExecLog DEBUG renice ${CT_NICE} $$
2.42 -
2.43 -CT_DoStep DEBUG "Dumping user-supplied crosstool-NG configuration"
2.44 -CT_DoExecLog DEBUG egrep '^(# |)CT_' .config
2.45 -CT_EndStep
2.46 -
2.47 -# Some sanity checks in the environment and needed tools
2.48 -CT_DoLog INFO "Checking environment sanity"
2.49 -
2.50 -CT_DoLog DEBUG "Unsetting and unexporting MAKEFLAGS"
2.51 -unset MAKEFLAGS
2.52 -export MAKEFLAGS
2.53 -
2.54 -# Other environment sanity checks
2.55 -CT_TestAndAbort "Don't set LD_LIBRARY_PATH. It screws up the build." -n "${LD_LIBRARY_PATH}"
2.56 -CT_TestAndAbort "Don't set CFLAGS. It screws up the build." -n "${CFLAGS}"
2.57 -CT_TestAndAbort "Don't set CXXFLAGS. It screws up the build." -n "${CXXFLAGS}"
2.58 -CT_Test "GREP_OPTIONS screws up the build. Resetting." -n "${GREP_OPTIONS}"
2.59 -export GREP_OPTIONS=
2.60 -
2.61 -CT_DoLog INFO "Building environment variables"
2.62 -
2.63 -# Include sub-scripts instead of calling them: that way, we do not have to
2.64 -# export any variable, nor re-parse the configuration and functions files.
2.65 -. "${CT_LIB_DIR}/scripts/build/arch/${CT_ARCH}.sh"
2.66 -. "${CT_LIB_DIR}/scripts/build/kernel/${CT_KERNEL}.sh"
2.67 -. "${CT_LIB_DIR}/scripts/build/gmp.sh"
2.68 -. "${CT_LIB_DIR}/scripts/build/mpfr.sh"
2.69 -. "${CT_LIB_DIR}/scripts/build/binutils.sh"
2.70 -. "${CT_LIB_DIR}/scripts/build/libc/${CT_LIBC}.sh"
2.71 -. "${CT_LIB_DIR}/scripts/build/cc/${CT_CC}.sh"
2.72 -. "${CT_LIB_DIR}/scripts/build/tools.sh"
2.73 -. "${CT_LIB_DIR}/scripts/build/debug.sh"
2.74 -
2.75 -# Target tuple: CT_TARGET needs a little love:
2.76 -CT_DoBuildTargetTuple
2.77 -
2.78 -# Kludge: If any of the configured options needs CT_TARGET,
2.79 -# then rescan the options file now:
2.80 -. .config
2.81 -
2.82 -# Second kludge: merge user-supplied target CFLAGS with architecture-provided
2.83 -# target CFLAGS. Do the same for LDFLAGS in case it happens in the future.
2.84 -# Put user-supplied flags at the end, so that they take precedence.
2.85 -CT_TARGET_CFLAGS="${CT_ARCH_TARGET_CFLAGS} ${CT_TARGET_CFLAGS}"
2.86 -CT_TARGET_LDFLAGS="${CT_ARCH_TARGET_LDFLAGS} ${CT_TARGET_LDFLAGS}"
2.87 -CT_CC_CORE_EXTRA_CONFIG="${CT_ARCH_CC_CORE_EXTRA_CONFIG} ${CT_CC_CORE_EXTRA_CONFIG}"
2.88 -CT_CC_EXTRA_CONFIG="${CT_ARCH_CC_EXTRA_CONFIG} ${CT_CC_EXTRA_CONFIG}"
2.89 -
2.90 -# Where will we work?
2.91 -: "${CT_WORK_DIR:=${CT_TOP_DIR}/targets}"
2.92 -CT_TARBALLS_DIR="${CT_WORK_DIR}/tarballs"
2.93 -CT_SRC_DIR="${CT_WORK_DIR}/src"
2.94 -CT_BUILD_DIR="${CT_WORK_DIR}/${CT_TARGET}/build"
2.95 -CT_DEBUG_INSTALL_DIR="${CT_INSTALL_DIR}/${CT_TARGET}/debug-root"
2.96 -# Note: we'll always install the core compiler in its own directory, so as to
2.97 -# not mix the two builds: core and final.
2.98 -CT_CC_CORE_STATIC_PREFIX_DIR="${CT_BUILD_DIR}/${CT_CC}-core-static"
2.99 -CT_CC_CORE_SHARED_PREFIX_DIR="${CT_BUILD_DIR}/${CT_CC}-core-shared"
2.100 -CT_STATE_DIR="${CT_WORK_DIR}/${CT_TARGET}/state"
2.101 -
2.102 -# We must ensure that we can restart if asked for!
2.103 -if [ -n "${CT_RESTART}" -a ! -d "${CT_STATE_DIR}" ]; then
2.104 - CT_DoLog ERROR "You asked to restart a non-restartable build"
2.105 - CT_DoLog ERROR "This happened because you didn't set CT_DEBUG_CT_SAVE_STEPS"
2.106 - CT_DoLog ERROR "in the config options for the previous build, or the state"
2.107 - CT_DoLog ERROR "directory for the previous build was deleted."
2.108 - CT_Abort "I will stop here to avoid any carnage"
2.109 -fi
2.110 -
2.111 -# If the local tarball directory does not exist, say so, and don't try to save there!
2.112 -if [ ! -d "${CT_LOCAL_TARBALLS_DIR}" ]; then
2.113 - CT_DoLog WARN "Directory '${CT_LOCAL_TARBALLS_DIR}' does not exist. Will not save downloaded tarballs to local storage."
2.114 - CT_SAVE_TARBALLS=
2.115 -fi
2.116 -
2.117 -# Some more sanity checks now that we have all paths set up
2.118 -case "${CT_LOCAL_TARBALLS_DIR},${CT_TARBALLS_DIR},${CT_SRC_DIR},${CT_BUILD_DIR},${CT_PREFIX_DIR},${CT_INSTALL_DIR}" in
2.119 - *" "*) CT_Abort "Don't use spaces in paths, it breaks things.";;
2.120 -esac
2.121 -
2.122 -# Check now if we can write to the destination directory:
2.123 -if [ -d "${CT_INSTALL_DIR}" ]; then
2.124 - CT_TestAndAbort "Destination directory '${CT_INSTALL_DIR}' is not removable" ! -w $(dirname "${CT_INSTALL_DIR}")
2.125 -fi
2.126 -
2.127 -# Good, now grab a bit of informations on the system we're being run on,
2.128 -# just in case something goes awok, and it's not our fault:
2.129 -CT_SYS_USER=$(id -un)
2.130 -CT_SYS_HOSTNAME=$(hostname -f 2>/dev/null || true)
2.131 -# Hmmm. Some non-DHCP-enabled machines do not have an FQDN... Fall back to node name.
2.132 -CT_SYS_HOSTNAME="${CT_SYS_HOSTNAME:-$(uname -n)}"
2.133 -CT_SYS_KERNEL=$(uname -s)
2.134 -CT_SYS_REVISION=$(uname -r)
2.135 -# MacOS X lacks '-o' :
2.136 -CT_SYS_OS=$(uname -o || echo "Unknown (maybe MacOS-X)")
2.137 -CT_SYS_MACHINE=$(uname -m)
2.138 -CT_SYS_PROCESSOR=$(uname -p)
2.139 -CT_SYS_GCC=$(gcc -dumpversion)
2.140 -CT_SYS_TARGET=$(CT_DoConfigGuess)
2.141 -CT_TOOLCHAIN_ID="crosstool-${CT_VERSION} build ${CT_STAR_DATE_HUMAN} by ${CT_SYS_USER}@${CT_SYS_HOSTNAME}"
2.142 -
2.143 -CT_DoLog EXTRA "Preparing working directories"
2.144 -
2.145 -# Ah! The build directory shall be eradicated, even if we restart!
2.146 -if [ -d "${CT_BUILD_DIR}" ]; then
2.147 - CT_DoForceRmdir "${CT_BUILD_DIR}"
2.148 -fi
2.149 -
2.150 -# Don't eradicate directories if we need to restart
2.151 -if [ -z "${CT_RESTART}" ]; then
2.152 - # Get rid of pre-existing installed toolchain and previous build directories.
2.153 - # We need to do that _before_ we can safely log, because the log file will
2.154 - # most probably be in the toolchain directory.
2.155 - if [ "${CT_FORCE_DOWNLOAD}" = "y" -a -d "${CT_TARBALLS_DIR}" ]; then
2.156 - CT_DoForceRmdir "${CT_TARBALLS_DIR}"
2.157 - fi
2.158 - if [ "${CT_FORCE_EXTRACT}" = "y" -a -d "${CT_SRC_DIR}" ]; then
2.159 - CT_DoForceRmdir "${CT_SRC_DIR}"
2.160 - fi
2.161 - if [ -d "${CT_INSTALL_DIR}" ]; then
2.162 - CT_DoForceRmdir "${CT_INSTALL_DIR}"
2.163 - fi
2.164 - if [ -d "${CT_DEBUG_INSTALL_DIR}" ]; then
2.165 - CT_DoForceRmdir "${CT_DEBUG_INSTALL_DIR}"
2.166 - fi
2.167 - # In case we start anew, get rid of the previously saved state directory
2.168 - if [ -d "${CT_STATE_DIR}" ]; then
2.169 - CT_DoForceRmdir "${CT_STATE_DIR}"
2.170 - fi
2.171 -fi
2.172 -
2.173 -# Create the directories we'll use, even if restarting: it does no harm to
2.174 -# create already existent directories, and CT_BUILD_DIR needs to be created
2.175 -# anyway
2.176 -CT_DoExecLog ALL mkdir -p "${CT_TARBALLS_DIR}"
2.177 -CT_DoExecLog ALL mkdir -p "${CT_SRC_DIR}"
2.178 -CT_DoExecLog ALL mkdir -p "${CT_BUILD_DIR}"
2.179 -CT_DoExecLog ALL mkdir -p "${CT_INSTALL_DIR}"
2.180 -CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}"
2.181 -CT_DoExecLog ALL mkdir -p "${CT_DEBUG_INSTALL_DIR}"
2.182 -CT_DoExecLog ALL mkdir -p "${CT_CC_CORE_STATIC_PREFIX_DIR}"
2.183 -CT_DoExecLog ALL mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}"
2.184 -CT_DoExecLog ALL mkdir -p "${CT_STATE_DIR}"
2.185 -
2.186 -# Kludge: CT_INSTALL_DIR and CT_PREFIX_DIR might have grown read-only if
2.187 -# the previous build was successful. To be able to move the logfile there,
2.188 -# switch them back to read/write
2.189 -CT_DoExecLog ALL chmod -R u+w "${CT_INSTALL_DIR}" "${CT_PREFIX_DIR}"
2.190 -
2.191 -# Redirect log to the actual log file now we can
2.192 -# It's quite understandable that the log file will be installed in the install
2.193 -# directory, so we must first ensure it exists and is writeable (above) before
2.194 -# we can log there
2.195 -exec >/dev/null
2.196 -case "${CT_LOG_TO_FILE}" in
2.197 - y) CT_LOG_FILE="${CT_PREFIX_DIR}/build.log"
2.198 - cat "${tmp_log_file}" >>"${CT_LOG_FILE}"
2.199 - rm -f "${tmp_log_file}"
2.200 - exec >>"${CT_LOG_FILE}"
2.201 - ;;
2.202 - *) rm -f "${tmp_log_file}"
2.203 - ;;
2.204 -esac
2.205 -
2.206 -# Setting up the rest of the environment only if not restarting
2.207 -if [ -z "${CT_RESTART}" ]; then
2.208 - # What's our shell?
2.209 - # Will be plain /bin/sh on most systems, except if we have /bin/ash and we
2.210 - # _explictly_ required using it
2.211 - CT_SHELL="/bin/sh"
2.212 - [ "${CT_CONFIG_SHELL_ASH}" = "y" -a -x "/bin/ash" ] && CT_SHELL="/bin/ash"
2.213 -
2.214 - # Arrange paths depending on wether we use sys-root or not.
2.215 - if [ "${CT_USE_SYSROOT}" = "y" ]; then
2.216 - CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}/sys-root"
2.217 - CT_HEADERS_DIR="${CT_SYSROOT_DIR}/usr/include"
2.218 - BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
2.219 - CC_CORE_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
2.220 - CC_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
2.221 - LIBC_SYSROOT_ARG=""
2.222 - # glibc's prefix must be exactly /usr, else --with-sysroot'd gcc will get
2.223 - # confused when $sysroot/usr/include is not present.
2.224 - # Note: --prefix=/usr is magic!
2.225 - # See http://www.gnu.org/software/libc/FAQ.html#s-2.2
2.226 - else
2.227 - # plain old way. All libraries in prefix/target/lib
2.228 - CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}"
2.229 - CT_HEADERS_DIR="${CT_SYSROOT_DIR}/include"
2.230 - # hack! Always use --with-sysroot for binutils.
2.231 - # binutils 2.14 and later obey it, older binutils ignore it.
2.232 - # Lets you build a working 32->64 bit cross gcc
2.233 - BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
2.234 - # Use --with-headers, else final gcc will define disable_glibc while
2.235 - # building libgcc, and you'll have no profiling
2.236 - CC_CORE_SYSROOT_ARG="--without-headers"
2.237 - CC_SYSROOT_ARG="--with-headers=${CT_HEADERS_DIR}"
2.238 - LIBC_SYSROOT_ARG="prefix="
2.239 - fi
2.240 -
2.241 - # Prepare the 'lib' directories in sysroot, else the ../lib64 hack used by
2.242 - # 32 -> 64 bit crosscompilers won't work, and build of final gcc will fail with
2.243 - # "ld: cannot open crti.o: No such file or directory"
2.244 - CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/lib"
2.245 - CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/usr/lib"
2.246 -
2.247 - # Prevent gcc from installing its libraries outside of the sys-root
2.248 - CT_DoExecLog ALL ln -sf "sys-root/lib" "${CT_PREFIX_DIR}/${CT_TARGET}/lib"
2.249 -
2.250 - # Now, in case we're 64 bits, just have lib64/ be a symlink to lib/
2.251 - # so as to have all libraries in the same directory (we can do that
2.252 - # because we are *not* multilib).
2.253 - if [ "${CT_ARCH_64}" = "y" ]; then
2.254 - CT_DoExecLog ALL ln -sf "lib" "${CT_SYSROOT_DIR}/lib64"
2.255 - CT_DoExecLog ALL ln -sf "lib" "${CT_SYSROOT_DIR}/usr/lib64"
2.256 - CT_DoExecLog ALL ln -sf "sys-root/lib" "${CT_PREFIX_DIR}/${CT_TARGET}/lib64"
2.257 - fi
2.258 -
2.259 - # Determine build system if not set by the user
2.260 - CT_Test "You did not specify the build system. That's OK, I can guess..." -z "${CT_BUILD}"
2.261 - case "${CT_BUILD}" in
2.262 - "") CT_BUILD=$("${CT_BUILD_PREFIX}gcc${CT_BUILD_SUFFIX}" -dumpmachine);;
2.263 - esac
2.264 -
2.265 - # Prepare mangling patterns to later modify BUILD and HOST (see below)
2.266 - case "${CT_TOOLCHAIN_TYPE}" in
2.267 - cross)
2.268 - CT_HOST="${CT_BUILD}"
2.269 - build_mangle="build_"
2.270 - host_mangle="build_"
2.271 - ;;
2.272 - *) CT_Abort "No code for '${CT_TOOLCHAIN_TYPE}' toolchain type!"
2.273 - ;;
2.274 - esac
2.275 -
2.276 - # Save the real tuples to generate shell-wrappers to the real tools
2.277 - CT_REAL_BUILD="${CT_BUILD}"
2.278 - CT_REAL_HOST="${CT_HOST}"
2.279 -
2.280 - # Canonicalise CT_BUILD and CT_HOST
2.281 - # Not only will it give us full-qualified tuples, but it will also ensure
2.282 - # that they are valid tuples (in case of typo with user-provided tuples)
2.283 - # That's way better than trying to rewrite config.sub ourselves...
2.284 - CT_BUILD=$(CT_DoConfigSub "${CT_BUILD}")
2.285 - CT_HOST=$(CT_DoConfigSub "${CT_HOST}")
2.286 -
2.287 - # Modify BUILD and HOST so that gcc always generate a cross-compiler
2.288 - # even if any of the build, host or target machines are the same.
2.289 - # NOTE: we'll have to mangle the (BUILD|HOST)->TARGET x-compiler to
2.290 - # support canadain build, later...
2.291 - CT_BUILD="${CT_BUILD/-/-${build_mangle}}"
2.292 - CT_HOST="${CT_HOST/-/-${host_mangle}}"
2.293 -
2.294 - # Now we have mangled our BUILD and HOST tuples, we must fake the new
2.295 - # cross-tools for those mangled tuples.
2.296 - CT_DoLog DEBUG "Making build system tools available"
2.297 - CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/bin"
2.298 - for m in BUILD HOST; do
2.299 - r="CT_REAL_${m}"
2.300 - v="CT_${m}"
2.301 - p="CT_${m}_PREFIX"
2.302 - s="CT_${m}_SUFFIX"
2.303 - if [ -n "${!p}" ]; then
2.304 - t="${!p}"
2.305 - else
2.306 - t="${!r}-"
2.307 - fi
2.308 -
2.309 - for tool in ar as dlltool gcc g++ gcj gnatbind gnatmake ld nm objcopy objdump ranlib strip windres; do
2.310 - # First try with prefix + suffix
2.311 - # Then try with prefix only
2.312 - # Then try with suffix only, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
2.313 - # Finally try with neither prefix nor suffix, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
2.314 - # This is needed, because some tools have a prefix and
2.315 - # a suffix (eg. gcc), while others may have only one,
2.316 - # or even none (eg. binutils)
2.317 - where=$(CT_Which "${t}${tool}${!s}")
2.318 - [ -z "${where}" ] && where=$(CT_Which "${t}${tool}")
2.319 - if [ -z "${where}" \
2.320 - -a \( "${m}" = "BUILD" \
2.321 - -o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
2.322 - where=$(CT_Which "${tool}${!s}")
2.323 - fi
2.324 - if [ -z "${where}" \
2.325 - -a \( "${m}" = "BUILD" \
2.326 - -o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
2.327 - where=$(CT_Which "${tool}")
2.328 - fi
2.329 -
2.330 - # Not all tools are available for all platforms, but some are really,
2.331 - # bally needed
2.332 - if [ -n "${where}" ]; then
2.333 - CT_DoLog DEBUG " '${!v}-${tool}' -> '${where}'"
2.334 - printf "#${BANG}${CT_SHELL}\nexec '${where}' \"\${@}\"\n" >"${CT_PREFIX_DIR}/bin/${!v}-${tool}"
2.335 - CT_DoExecLog ALL chmod 700 "${CT_PREFIX_DIR}/bin/${!v}-${tool}"
2.336 - else
2.337 - # We'll at least need some of them...
2.338 - case "${tool}" in
2.339 - ar|as|gcc|ld|nm|objcopy|objdump|ranlib)
2.340 - CT_Abort "Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : either needed!"
2.341 - ;;
2.342 - *)
2.343 - # It does not deserve a WARN level.
2.344 - CT_DoLog DEBUG " Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : not required."
2.345 - ;;
2.346 - esac
2.347 - fi
2.348 - done
2.349 - done
2.350 -
2.351 - # Carefully add paths in the order we want them:
2.352 - # - first try in ${CT_PREFIX_DIR}/bin
2.353 - # - then try in ${CT_CC_CORE_SHARED_PREFIX_DIR}/bin
2.354 - # - then try in ${CT_CC_CORE_STATIC_PREFIX_DIR}/bin
2.355 - # - fall back to searching user's PATH
2.356 - # Of course, neither cross-native nor canadian can run on BUILD,
2.357 - # so don't add those PATHs in this case...
2.358 - case "${CT_TOOLCHAIN_TYPE}" in
2.359 - cross) export PATH="${CT_PREFIX_DIR}/bin:${CT_CC_CORE_SHARED_PREFIX_DIR}/bin:${CT_CC_CORE_STATIC_PREFIX_DIR}/bin:${PATH}";;
2.360 - *) ;;
2.361 - esac
2.362 -
2.363 - # Some makeinfo versions are a pain in [put your most sensible body part here].
2.364 - # Go ahead with those, by creating a wrapper that keeps partial files, and that
2.365 - # never fails:
2.366 - CT_DoLog DEBUG " 'makeinfo' -> '$(CT_Which makeinfo)'"
2.367 - printf "#${BANG}/bin/sh\n$(CT_Which makeinfo) --force \"\${@}\"\ntrue\n" >"${CT_PREFIX_DIR}/bin/makeinfo"
2.368 - CT_DoExecLog ALL chmod 700 "${CT_PREFIX_DIR}/bin/makeinfo"
2.369 -
2.370 - # Help gcc
2.371 - CT_CFLAGS_FOR_HOST=
2.372 - [ "${CT_USE_PIPES}" = "y" ] && CT_CFLAGS_FOR_HOST="${CT_CFLAGS_FOR_HOST} -pipe"
2.373 -
2.374 - # Override the configured jobs with what's been given on the command line
2.375 - [ -n "${CT_JOBS}" ] && CT_PARALLEL_JOBS="${CT_JOBS}"
2.376 -
2.377 - # Set the shell to be used by ./configure scripts and by Makefiles (those
2.378 - # that support it!).
2.379 - export CONFIG_SHELL="${CT_SHELL}"
2.380 -
2.381 - # And help make go faster
2.382 - PARALLELMFLAGS=
2.383 - [ ${CT_PARALLEL_JOBS} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -j${CT_PARALLEL_JOBS}"
2.384 - [ ${CT_LOAD} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -l${CT_LOAD}"
2.385 - export PARALLELMFLAGS
2.386 -
2.387 - CT_DoLog EXTRA "Installing user-supplied crosstool-NG configuration"
2.388 - CT_DoExecLog DEBUG install -m 0755 "${CT_LIB_DIR}/scripts/toolchain-config.in" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
2.389 - bzip2 -c -9 .config >>"${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
2.390 -
2.391 - CT_DoStep EXTRA "Dumping internal crosstool-NG configuration"
2.392 - CT_DoLog EXTRA "Building a toolchain for:"
2.393 - CT_DoLog EXTRA " build = ${CT_REAL_BUILD}"
2.394 - CT_DoLog EXTRA " host = ${CT_REAL_HOST}"
2.395 - CT_DoLog EXTRA " target = ${CT_TARGET}"
2.396 - set |egrep '^CT_.+=' |sort |CT_DoLog DEBUG
2.397 - CT_EndStep
2.398 -fi
2.399 -
2.400 -if [ -z "${CT_RESTART}" ]; then
2.401 - CT_DoStep INFO "Retrieving needed toolchain components' tarballs"
2.402 - do_kernel_get
2.403 - do_gmp_get
2.404 - do_mpfr_get
2.405 - do_binutils_get
2.406 - do_cc_get
2.407 - do_libc_get
2.408 - do_tools_get
2.409 - do_debug_get
2.410 - CT_EndStep
2.411 -
2.412 - if [ "${CT_ONLY_DOWNLOAD}" != "y" ]; then
2.413 - if [ "${CT_FORCE_EXTRACT}" = "y" ]; then
2.414 - CT_DoForceRmdir "${CT_SRC_DIR}"
2.415 - CT_DoExecLog ALL mkdir -p "${CT_SRC_DIR}"
2.416 - fi
2.417 - CT_DoStep INFO "Extracting and patching toolchain components"
2.418 - do_kernel_extract
2.419 - do_gmp_extract
2.420 - do_mpfr_extract
2.421 - do_binutils_extract
2.422 - do_cc_extract
2.423 - do_libc_extract
2.424 - do_tools_extract
2.425 - do_debug_extract
2.426 - CT_EndStep
2.427 - fi
2.428 -fi
2.429 -
2.430 -# Now for the job by itself. Go have a coffee!
2.431 -if [ "${CT_ONLY_DOWNLOAD}" != "y" -a "${CT_ONLY_EXTRACT}" != "y" ]; then
2.432 - # Because of CT_RESTART, this becomes quite complex
2.433 - do_stop=0
2.434 - prev_step=
2.435 - [ -n "${CT_RESTART}" ] && do_it=0 || do_it=1
2.436 - # Aha! CT_STEPS comes from steps.mk!
2.437 - for step in ${CT_STEPS}; do
2.438 - if [ ${do_it} -eq 0 ]; then
2.439 - if [ "${CT_RESTART}" = "${step}" ]; then
2.440 - CT_DoLoadState "${step}"
2.441 - do_it=1
2.442 - do_stop=0
2.443 - fi
2.444 - else
2.445 - CT_DoSaveState ${step}
2.446 - if [ ${do_stop} -eq 1 ]; then
2.447 - CT_DoLog ERROR "Stopping just after step '${prev_step}', as requested."
2.448 - exit 0
2.449 - fi
2.450 - fi
2.451 - if [ ${do_it} -eq 1 ]; then
2.452 - do_${step}
2.453 - if [ "${CT_STOP}" = "${step}" ]; then
2.454 - do_stop=1
2.455 - fi
2.456 - if [ "${CT_DEBUG_PAUSE_STEPS}" = "y" ]; then
2.457 - CT_DoPause "Step '${step}' finished"
2.458 - fi
2.459 - fi
2.460 - prev_step="${step}"
2.461 - done
2.462 -fi
2.463 -
2.464 -CT_DoEnd INFO
2.465 -
2.466 -# From now-on, it can become impossible to log any time, because
2.467 -# either we're compressing the log file, or it can become RO any
2.468 -# moment... Consign all ouptut to oblivion...
2.469 -CT_DoLog INFO "Finishing installation (may take a few seconds)..."
2.470 -exec >/dev/null 2>&1
2.471 -
2.472 -[ "${CT_LOG_FILE_COMPRESS}" = y ] && bzip2 -9 "${CT_LOG_FILE}"
2.473 -[ "${CT_INSTALL_DIR_RO}" = "y" ] && chmod -R a-w "${CT_INSTALL_DIR}"
2.474 -
2.475 -trap - EXIT
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/scripts/crosstool-NG.sh.in Mon Jan 26 22:43:08 2009 +0000
3.3 @@ -0,0 +1,491 @@
3.4 +#!@@CT_bash@@
3.5 +# Copyright 2007 Yann E. MORIN
3.6 +# Licensed under the GPL v2. See COPYING in the root of this package.
3.7 +
3.8 +# This is the main entry point to crosstool
3.9 +# This will:
3.10 +# - download, extract and patch the toolchain components
3.11 +# - build and install each components in turn
3.12 +# - and eventually test the resulting toolchain
3.13 +
3.14 +# What this file does is prepare the environment, based upon the user-choosen
3.15 +# options. It also checks the existing environment for un-friendly variables,
3.16 +# and builds the tools.
3.17 +
3.18 +# Parse the common functions
3.19 +# Note: some initialisation and sanitizing is done while parsing this file,
3.20 +# most notably:
3.21 +# - set trap handler on errors,
3.22 +# - don't hash commands lookups,
3.23 +# - initialise logging.
3.24 +. "${CT_LIB_DIR}/scripts/functions"
3.25 +
3.26 +# Parse the configuration file
3.27 +# It has some info about the logging facility, so include it early
3.28 +. .config
3.29 +# Yes! We can do full logging from now on!
3.30 +
3.31 +# Overide the locale early, in case we ever translate crosstool-NG messages
3.32 +[ -z "${CT_NO_OVERIDE_LC_MESSAGES}" ] && export LC_ALL=C
3.33 +
3.34 +# Where will we work?
3.35 +CT_WORK_DIR="${CT_WORK_DIR:-${CT_TOP_DIR}/targets}"
3.36 +
3.37 +# Create the bin-overide early
3.38 +# Contains symlinks to the tools found bu ./configure
3.39 +# Note: CT_DoLog and CT_DoExecLog do not use any of those tool, so
3.40 +# they can be safely used
3.41 +CT_BIN_OVERIDE_DIR="${CT_WORK_DIR}/bin"
3.42 +CT_DoLog DEBUG "Creating bin-overide for tools in '${CT_BIN_OVERIDE_DIR}'"
3.43 +CT_DoExecLog DEBUG mkdir -p "${CT_BIN_OVERIDE_DIR}"
3.44 +cat "${CT_LIB_DIR}/paths.mk" |while read trash line; do
3.45 + tool="${line%%=*}"
3.46 + path="${line#*=}"
3.47 + CT_DoLog DEBUG " '${tool}' -> '${path}'"
3.48 + printf "#${BANG}/bin/sh\nexec '${path}' \"\${@}\"\n" >"${CT_BIN_OVERIDE_DIR}/${tool}"
3.49 + CT_DoExecLog ALL chmod 700 "${CT_BIN_OVERIDE_DIR}/${tool}"
3.50 +done
3.51 +export PATH="${CT_BIN_OVERIDE_DIR}:${PATH}"
3.52 +
3.53 +# Start date. Can't be done until we know the locale
3.54 +CT_STAR_DATE=$(CT_DoDate +%s%N)
3.55 +CT_STAR_DATE_HUMAN=$(CT_DoDate +%Y%m%d.%H%M%S)
3.56 +
3.57 +# Log real begining of build, now
3.58 +CT_DoLog INFO "Build started ${CT_STAR_DATE_HUMAN}"
3.59 +
3.60 +# renice oursleves
3.61 +CT_DoExecLog DEBUG renice ${CT_NICE} $$
3.62 +
3.63 +CT_DoStep DEBUG "Dumping user-supplied crosstool-NG configuration"
3.64 +CT_DoExecLog DEBUG egrep '^(# |)CT_' .config
3.65 +CT_EndStep
3.66 +
3.67 +# Some sanity checks in the environment and needed tools
3.68 +CT_DoLog INFO "Checking environment sanity"
3.69 +
3.70 +CT_DoLog DEBUG "Unsetting and unexporting MAKEFLAGS"
3.71 +unset MAKEFLAGS
3.72 +export MAKEFLAGS
3.73 +
3.74 +# Other environment sanity checks
3.75 +CT_TestAndAbort "Don't set LD_LIBRARY_PATH. It screws up the build." -n "${LD_LIBRARY_PATH}"
3.76 +CT_TestAndAbort "Don't set CFLAGS. It screws up the build." -n "${CFLAGS}"
3.77 +CT_TestAndAbort "Don't set CXXFLAGS. It screws up the build." -n "${CXXFLAGS}"
3.78 +CT_Test "GREP_OPTIONS screws up the build. Resetting." -n "${GREP_OPTIONS}"
3.79 +export GREP_OPTIONS=
3.80 +
3.81 +CT_DoLog INFO "Building environment variables"
3.82 +
3.83 +# Include sub-scripts instead of calling them: that way, we do not have to
3.84 +# export any variable, nor re-parse the configuration and functions files.
3.85 +. "${CT_LIB_DIR}/scripts/build/arch/${CT_ARCH}.sh"
3.86 +. "${CT_LIB_DIR}/scripts/build/kernel/${CT_KERNEL}.sh"
3.87 +. "${CT_LIB_DIR}/scripts/build/gmp.sh"
3.88 +. "${CT_LIB_DIR}/scripts/build/mpfr.sh"
3.89 +. "${CT_LIB_DIR}/scripts/build/binutils.sh"
3.90 +. "${CT_LIB_DIR}/scripts/build/libc/${CT_LIBC}.sh"
3.91 +. "${CT_LIB_DIR}/scripts/build/cc/${CT_CC}.sh"
3.92 +. "${CT_LIB_DIR}/scripts/build/tools.sh"
3.93 +. "${CT_LIB_DIR}/scripts/build/debug.sh"
3.94 +
3.95 +# Target tuple: CT_TARGET needs a little love:
3.96 +CT_DoBuildTargetTuple
3.97 +
3.98 +# Kludge: If any of the configured options needs CT_TARGET,
3.99 +# then rescan the options file now:
3.100 +. .config
3.101 +
3.102 +# Second kludge: merge user-supplied target CFLAGS with architecture-provided
3.103 +# target CFLAGS. Do the same for LDFLAGS in case it happens in the future.
3.104 +# Put user-supplied flags at the end, so that they take precedence.
3.105 +CT_TARGET_CFLAGS="${CT_ARCH_TARGET_CFLAGS} ${CT_TARGET_CFLAGS}"
3.106 +CT_TARGET_LDFLAGS="${CT_ARCH_TARGET_LDFLAGS} ${CT_TARGET_LDFLAGS}"
3.107 +CT_CC_CORE_EXTRA_CONFIG="${CT_ARCH_CC_CORE_EXTRA_CONFIG} ${CT_CC_CORE_EXTRA_CONFIG}"
3.108 +CT_CC_EXTRA_CONFIG="${CT_ARCH_CC_EXTRA_CONFIG} ${CT_CC_EXTRA_CONFIG}"
3.109 +
3.110 +# Create the working directories
3.111 +CT_TARBALLS_DIR="${CT_WORK_DIR}/tarballs"
3.112 +CT_SRC_DIR="${CT_WORK_DIR}/src"
3.113 +CT_BUILD_DIR="${CT_WORK_DIR}/${CT_TARGET}/build"
3.114 +CT_DEBUG_INSTALL_DIR="${CT_INSTALL_DIR}/${CT_TARGET}/debug-root"
3.115 +# Note: we'll always install the core compiler in its own directory, so as to
3.116 +# not mix the two builds: core and final.
3.117 +CT_CC_CORE_STATIC_PREFIX_DIR="${CT_BUILD_DIR}/${CT_CC}-core-static"
3.118 +CT_CC_CORE_SHARED_PREFIX_DIR="${CT_BUILD_DIR}/${CT_CC}-core-shared"
3.119 +CT_STATE_DIR="${CT_WORK_DIR}/${CT_TARGET}/state"
3.120 +
3.121 +# We must ensure that we can restart if asked for!
3.122 +if [ -n "${CT_RESTART}" -a ! -d "${CT_STATE_DIR}" ]; then
3.123 + CT_DoLog ERROR "You asked to restart a non-restartable build"
3.124 + CT_DoLog ERROR "This happened because you didn't set CT_DEBUG_CT_SAVE_STEPS"
3.125 + CT_DoLog ERROR "in the config options for the previous build, or the state"
3.126 + CT_DoLog ERROR "directory for the previous build was deleted."
3.127 + CT_Abort "I will stop here to avoid any carnage"
3.128 +fi
3.129 +
3.130 +# If the local tarball directory does not exist, say so, and don't try to save there!
3.131 +if [ ! -d "${CT_LOCAL_TARBALLS_DIR}" ]; then
3.132 + CT_DoLog WARN "Directory '${CT_LOCAL_TARBALLS_DIR}' does not exist. Will not save downloaded tarballs to local storage."
3.133 + CT_SAVE_TARBALLS=
3.134 +fi
3.135 +
3.136 +# Some more sanity checks now that we have all paths set up
3.137 +case "${CT_LOCAL_TARBALLS_DIR},${CT_TARBALLS_DIR},${CT_SRC_DIR},${CT_BUILD_DIR},${CT_PREFIX_DIR},${CT_INSTALL_DIR}" in
3.138 + *" "*) CT_Abort "Don't use spaces in paths, it breaks things.";;
3.139 +esac
3.140 +
3.141 +# Check now if we can write to the destination directory:
3.142 +if [ -d "${CT_INSTALL_DIR}" ]; then
3.143 + CT_TestAndAbort "Destination directory '${CT_INSTALL_DIR}' is not removable" ! -w $(dirname "${CT_INSTALL_DIR}")
3.144 +fi
3.145 +
3.146 +# Good, now grab a bit of informations on the system we're being run on,
3.147 +# just in case something goes awok, and it's not our fault:
3.148 +CT_SYS_USER=$(id -un)
3.149 +CT_SYS_HOSTNAME=$(hostname -f 2>/dev/null || true)
3.150 +# Hmmm. Some non-DHCP-enabled machines do not have an FQDN... Fall back to node name.
3.151 +CT_SYS_HOSTNAME="${CT_SYS_HOSTNAME:-$(uname -n)}"
3.152 +CT_SYS_KERNEL=$(uname -s)
3.153 +CT_SYS_REVISION=$(uname -r)
3.154 +# MacOS X lacks '-o' :
3.155 +CT_SYS_OS=$(uname -o || echo "Unknown (maybe MacOS-X)")
3.156 +CT_SYS_MACHINE=$(uname -m)
3.157 +CT_SYS_PROCESSOR=$(uname -p)
3.158 +CT_SYS_GCC=$(gcc -dumpversion)
3.159 +CT_SYS_TARGET=$(CT_DoConfigGuess)
3.160 +CT_TOOLCHAIN_ID="crosstool-${CT_VERSION} build ${CT_STAR_DATE_HUMAN} by ${CT_SYS_USER}@${CT_SYS_HOSTNAME}"
3.161 +
3.162 +CT_DoLog EXTRA "Preparing working directories"
3.163 +
3.164 +# Ah! The build directory shall be eradicated, even if we restart!
3.165 +if [ -d "${CT_BUILD_DIR}" ]; then
3.166 + CT_DoForceRmdir "${CT_BUILD_DIR}"
3.167 +fi
3.168 +
3.169 +# Don't eradicate directories if we need to restart
3.170 +if [ -z "${CT_RESTART}" ]; then
3.171 + # Get rid of pre-existing installed toolchain and previous build directories.
3.172 + # We need to do that _before_ we can safely log, because the log file will
3.173 + # most probably be in the toolchain directory.
3.174 + if [ "${CT_FORCE_DOWNLOAD}" = "y" -a -d "${CT_TARBALLS_DIR}" ]; then
3.175 + CT_DoForceRmdir "${CT_TARBALLS_DIR}"
3.176 + fi
3.177 + if [ "${CT_FORCE_EXTRACT}" = "y" -a -d "${CT_SRC_DIR}" ]; then
3.178 + CT_DoForceRmdir "${CT_SRC_DIR}"
3.179 + fi
3.180 + if [ -d "${CT_INSTALL_DIR}" ]; then
3.181 + CT_DoForceRmdir "${CT_INSTALL_DIR}"
3.182 + fi
3.183 + if [ -d "${CT_DEBUG_INSTALL_DIR}" ]; then
3.184 + CT_DoForceRmdir "${CT_DEBUG_INSTALL_DIR}"
3.185 + fi
3.186 + # In case we start anew, get rid of the previously saved state directory
3.187 + if [ -d "${CT_STATE_DIR}" ]; then
3.188 + CT_DoForceRmdir "${CT_STATE_DIR}"
3.189 + fi
3.190 +fi
3.191 +
3.192 +# Create the directories we'll use, even if restarting: it does no harm to
3.193 +# create already existent directories, and CT_BUILD_DIR needs to be created
3.194 +# anyway
3.195 +CT_DoExecLog ALL mkdir -p "${CT_TARBALLS_DIR}"
3.196 +CT_DoExecLog ALL mkdir -p "${CT_SRC_DIR}"
3.197 +CT_DoExecLog ALL mkdir -p "${CT_BUILD_DIR}"
3.198 +CT_DoExecLog ALL mkdir -p "${CT_INSTALL_DIR}"
3.199 +CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}"
3.200 +CT_DoExecLog ALL mkdir -p "${CT_DEBUG_INSTALL_DIR}"
3.201 +CT_DoExecLog ALL mkdir -p "${CT_CC_CORE_STATIC_PREFIX_DIR}"
3.202 +CT_DoExecLog ALL mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}"
3.203 +CT_DoExecLog ALL mkdir -p "${CT_STATE_DIR}"
3.204 +
3.205 +# Kludge: CT_INSTALL_DIR and CT_PREFIX_DIR might have grown read-only if
3.206 +# the previous build was successful. To be able to move the logfile there,
3.207 +# switch them back to read/write
3.208 +CT_DoExecLog ALL chmod -R u+w "${CT_INSTALL_DIR}" "${CT_PREFIX_DIR}"
3.209 +
3.210 +# Redirect log to the actual log file now we can
3.211 +# It's quite understandable that the log file will be installed in the install
3.212 +# directory, so we must first ensure it exists and is writeable (above) before
3.213 +# we can log there
3.214 +exec >/dev/null
3.215 +case "${CT_LOG_TO_FILE}" in
3.216 + y) CT_LOG_FILE="${CT_PREFIX_DIR}/build.log"
3.217 + cat "${tmp_log_file}" >>"${CT_LOG_FILE}"
3.218 + rm -f "${tmp_log_file}"
3.219 + exec >>"${CT_LOG_FILE}"
3.220 + ;;
3.221 + *) rm -f "${tmp_log_file}"
3.222 + ;;
3.223 +esac
3.224 +
3.225 +# Setting up the rest of the environment only if not restarting
3.226 +if [ -z "${CT_RESTART}" ]; then
3.227 + # What's our shell?
3.228 + # Will be plain /bin/sh on most systems, except if we have /bin/ash and we
3.229 + # _explictly_ required using it
3.230 + CT_SHELL="/bin/sh"
3.231 + [ "${CT_CONFIG_SHELL_ASH}" = "y" -a -x "/bin/ash" ] && CT_SHELL="/bin/ash"
3.232 +
3.233 + # Arrange paths depending on wether we use sys-root or not.
3.234 + if [ "${CT_USE_SYSROOT}" = "y" ]; then
3.235 + CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}/sys-root"
3.236 + CT_HEADERS_DIR="${CT_SYSROOT_DIR}/usr/include"
3.237 + BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
3.238 + CC_CORE_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
3.239 + CC_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
3.240 + LIBC_SYSROOT_ARG=""
3.241 + # glibc's prefix must be exactly /usr, else --with-sysroot'd gcc will get
3.242 + # confused when $sysroot/usr/include is not present.
3.243 + # Note: --prefix=/usr is magic!
3.244 + # See http://www.gnu.org/software/libc/FAQ.html#s-2.2
3.245 + else
3.246 + # plain old way. All libraries in prefix/target/lib
3.247 + CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}"
3.248 + CT_HEADERS_DIR="${CT_SYSROOT_DIR}/include"
3.249 + # hack! Always use --with-sysroot for binutils.
3.250 + # binutils 2.14 and later obey it, older binutils ignore it.
3.251 + # Lets you build a working 32->64 bit cross gcc
3.252 + BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
3.253 + # Use --with-headers, else final gcc will define disable_glibc while
3.254 + # building libgcc, and you'll have no profiling
3.255 + CC_CORE_SYSROOT_ARG="--without-headers"
3.256 + CC_SYSROOT_ARG="--with-headers=${CT_HEADERS_DIR}"
3.257 + LIBC_SYSROOT_ARG="prefix="
3.258 + fi
3.259 +
3.260 + # Prepare the 'lib' directories in sysroot, else the ../lib64 hack used by
3.261 + # 32 -> 64 bit crosscompilers won't work, and build of final gcc will fail with
3.262 + # "ld: cannot open crti.o: No such file or directory"
3.263 + CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/lib"
3.264 + CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/usr/lib"
3.265 +
3.266 + # Prevent gcc from installing its libraries outside of the sys-root
3.267 + CT_DoExecLog ALL ln -sf "sys-root/lib" "${CT_PREFIX_DIR}/${CT_TARGET}/lib"
3.268 +
3.269 + # Now, in case we're 64 bits, just have lib64/ be a symlink to lib/
3.270 + # so as to have all libraries in the same directory (we can do that
3.271 + # because we are *not* multilib).
3.272 + if [ "${CT_ARCH_64}" = "y" ]; then
3.273 + CT_DoExecLog ALL ln -sf "lib" "${CT_SYSROOT_DIR}/lib64"
3.274 + CT_DoExecLog ALL ln -sf "lib" "${CT_SYSROOT_DIR}/usr/lib64"
3.275 + CT_DoExecLog ALL ln -sf "sys-root/lib" "${CT_PREFIX_DIR}/${CT_TARGET}/lib64"
3.276 + fi
3.277 +
3.278 + # Determine build system if not set by the user
3.279 + CT_Test "You did not specify the build system. That's OK, I can guess..." -z "${CT_BUILD}"
3.280 + case "${CT_BUILD}" in
3.281 + "") CT_BUILD=$("${CT_BUILD_PREFIX}gcc${CT_BUILD_SUFFIX}" -dumpmachine);;
3.282 + esac
3.283 +
3.284 + # Prepare mangling patterns to later modify BUILD and HOST (see below)
3.285 + case "${CT_TOOLCHAIN_TYPE}" in
3.286 + cross)
3.287 + CT_HOST="${CT_BUILD}"
3.288 + build_mangle="build_"
3.289 + host_mangle="build_"
3.290 + ;;
3.291 + *) CT_Abort "No code for '${CT_TOOLCHAIN_TYPE}' toolchain type!"
3.292 + ;;
3.293 + esac
3.294 +
3.295 + # Save the real tuples to generate shell-wrappers to the real tools
3.296 + CT_REAL_BUILD="${CT_BUILD}"
3.297 + CT_REAL_HOST="${CT_HOST}"
3.298 +
3.299 + # Canonicalise CT_BUILD and CT_HOST
3.300 + # Not only will it give us full-qualified tuples, but it will also ensure
3.301 + # that they are valid tuples (in case of typo with user-provided tuples)
3.302 + # That's way better than trying to rewrite config.sub ourselves...
3.303 + CT_BUILD=$(CT_DoConfigSub "${CT_BUILD}")
3.304 + CT_HOST=$(CT_DoConfigSub "${CT_HOST}")
3.305 +
3.306 + # Modify BUILD and HOST so that gcc always generate a cross-compiler
3.307 + # even if any of the build, host or target machines are the same.
3.308 + # NOTE: we'll have to mangle the (BUILD|HOST)->TARGET x-compiler to
3.309 + # support canadain build, later...
3.310 + CT_BUILD="${CT_BUILD/-/-${build_mangle}}"
3.311 + CT_HOST="${CT_HOST/-/-${host_mangle}}"
3.312 +
3.313 + # Now we have mangled our BUILD and HOST tuples, we must fake the new
3.314 + # cross-tools for those mangled tuples.
3.315 + CT_DoLog DEBUG "Making build system tools available"
3.316 + CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/bin"
3.317 + for m in BUILD HOST; do
3.318 + r="CT_REAL_${m}"
3.319 + v="CT_${m}"
3.320 + p="CT_${m}_PREFIX"
3.321 + s="CT_${m}_SUFFIX"
3.322 + if [ -n "${!p}" ]; then
3.323 + t="${!p}"
3.324 + else
3.325 + t="${!r}-"
3.326 + fi
3.327 +
3.328 + for tool in ar as dlltool gcc g++ gcj gnatbind gnatmake ld nm objcopy objdump ranlib strip windres; do
3.329 + # First try with prefix + suffix
3.330 + # Then try with prefix only
3.331 + # Then try with suffix only, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
3.332 + # Finally try with neither prefix nor suffix, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
3.333 + # This is needed, because some tools have a prefix and
3.334 + # a suffix (eg. gcc), while others may have only one,
3.335 + # or even none (eg. binutils)
3.336 + where=$(CT_Which "${t}${tool}${!s}")
3.337 + [ -z "${where}" ] && where=$(CT_Which "${t}${tool}")
3.338 + if [ -z "${where}" \
3.339 + -a \( "${m}" = "BUILD" \
3.340 + -o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
3.341 + where=$(CT_Which "${tool}${!s}")
3.342 + fi
3.343 + if [ -z "${where}" \
3.344 + -a \( "${m}" = "BUILD" \
3.345 + -o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
3.346 + where=$(CT_Which "${tool}")
3.347 + fi
3.348 +
3.349 + # Not all tools are available for all platforms, but some are really,
3.350 + # bally needed
3.351 + if [ -n "${where}" ]; then
3.352 + CT_DoLog DEBUG " '${!v}-${tool}' -> '${where}'"
3.353 + printf "#${BANG}${CT_SHELL}\nexec '${where}' \"\${@}\"\n" >"${CT_PREFIX_DIR}/bin/${!v}-${tool}"
3.354 + CT_DoExecLog ALL chmod 700 "${CT_PREFIX_DIR}/bin/${!v}-${tool}"
3.355 + else
3.356 + # We'll at least need some of them...
3.357 + case "${tool}" in
3.358 + ar|as|gcc|ld|nm|objcopy|objdump|ranlib)
3.359 + CT_Abort "Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : either needed!"
3.360 + ;;
3.361 + *)
3.362 + # It does not deserve a WARN level.
3.363 + CT_DoLog DEBUG " Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : not required."
3.364 + ;;
3.365 + esac
3.366 + fi
3.367 + done
3.368 + done
3.369 +
3.370 + # Carefully add paths in the order we want them:
3.371 + # - first try in ${CT_PREFIX_DIR}/bin
3.372 + # - then try in ${CT_CC_CORE_SHARED_PREFIX_DIR}/bin
3.373 + # - then try in ${CT_CC_CORE_STATIC_PREFIX_DIR}/bin
3.374 + # - fall back to searching user's PATH
3.375 + # Of course, neither cross-native nor canadian can run on BUILD,
3.376 + # so don't add those PATHs in this case...
3.377 + case "${CT_TOOLCHAIN_TYPE}" in
3.378 + cross) export PATH="${CT_PREFIX_DIR}/bin:${CT_CC_CORE_SHARED_PREFIX_DIR}/bin:${CT_CC_CORE_STATIC_PREFIX_DIR}/bin:${PATH}";;
3.379 + *) ;;
3.380 + esac
3.381 +
3.382 + # Some makeinfo versions are a pain in [put your most sensible body part here].
3.383 + # Go ahead with those, by creating a wrapper that keeps partial files, and that
3.384 + # never fails:
3.385 + CT_DoLog DEBUG " 'makeinfo' -> '$(CT_Which makeinfo)'"
3.386 + printf "#${BANG}/bin/sh\n$(CT_Which makeinfo) --force \"\${@}\"\ntrue\n" >"${CT_PREFIX_DIR}/bin/makeinfo"
3.387 + CT_DoExecLog ALL chmod 700 "${CT_PREFIX_DIR}/bin/makeinfo"
3.388 +
3.389 + # Help gcc
3.390 + CT_CFLAGS_FOR_HOST=
3.391 + [ "${CT_USE_PIPES}" = "y" ] && CT_CFLAGS_FOR_HOST="${CT_CFLAGS_FOR_HOST} -pipe"
3.392 +
3.393 + # Override the configured jobs with what's been given on the command line
3.394 + [ -n "${CT_JOBS}" ] && CT_PARALLEL_JOBS="${CT_JOBS}"
3.395 +
3.396 + # Set the shell to be used by ./configure scripts and by Makefiles (those
3.397 + # that support it!).
3.398 + export CONFIG_SHELL="${CT_SHELL}"
3.399 +
3.400 + # And help make go faster
3.401 + PARALLELMFLAGS=
3.402 + [ ${CT_PARALLEL_JOBS} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -j${CT_PARALLEL_JOBS}"
3.403 + [ ${CT_LOAD} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -l${CT_LOAD}"
3.404 + export PARALLELMFLAGS
3.405 +
3.406 + CT_DoLog EXTRA "Installing user-supplied crosstool-NG configuration"
3.407 + CT_DoExecLog DEBUG install -m 0755 "${CT_LIB_DIR}/scripts/toolchain-config.in" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
3.408 + bzip2 -c -9 .config >>"${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
3.409 +
3.410 + CT_DoStep EXTRA "Dumping internal crosstool-NG configuration"
3.411 + CT_DoLog EXTRA "Building a toolchain for:"
3.412 + CT_DoLog EXTRA " build = ${CT_REAL_BUILD}"
3.413 + CT_DoLog EXTRA " host = ${CT_REAL_HOST}"
3.414 + CT_DoLog EXTRA " target = ${CT_TARGET}"
3.415 + set |egrep '^CT_.+=' |sort |CT_DoLog DEBUG
3.416 + CT_EndStep
3.417 +fi
3.418 +
3.419 +if [ -z "${CT_RESTART}" ]; then
3.420 + CT_DoStep INFO "Retrieving needed toolchain components' tarballs"
3.421 + do_kernel_get
3.422 + do_gmp_get
3.423 + do_mpfr_get
3.424 + do_binutils_get
3.425 + do_cc_get
3.426 + do_libc_get
3.427 + do_tools_get
3.428 + do_debug_get
3.429 + CT_EndStep
3.430 +
3.431 + if [ "${CT_ONLY_DOWNLOAD}" != "y" ]; then
3.432 + if [ "${CT_FORCE_EXTRACT}" = "y" ]; then
3.433 + CT_DoForceRmdir "${CT_SRC_DIR}"
3.434 + CT_DoExecLog ALL mkdir -p "${CT_SRC_DIR}"
3.435 + fi
3.436 + CT_DoStep INFO "Extracting and patching toolchain components"
3.437 + do_kernel_extract
3.438 + do_gmp_extract
3.439 + do_mpfr_extract
3.440 + do_binutils_extract
3.441 + do_cc_extract
3.442 + do_libc_extract
3.443 + do_tools_extract
3.444 + do_debug_extract
3.445 + CT_EndStep
3.446 + fi
3.447 +fi
3.448 +
3.449 +# Now for the job by itself. Go have a coffee!
3.450 +if [ "${CT_ONLY_DOWNLOAD}" != "y" -a "${CT_ONLY_EXTRACT}" != "y" ]; then
3.451 + # Because of CT_RESTART, this becomes quite complex
3.452 + do_stop=0
3.453 + prev_step=
3.454 + [ -n "${CT_RESTART}" ] && do_it=0 || do_it=1
3.455 + # Aha! CT_STEPS comes from steps.mk!
3.456 + for step in ${CT_STEPS}; do
3.457 + if [ ${do_it} -eq 0 ]; then
3.458 + if [ "${CT_RESTART}" = "${step}" ]; then
3.459 + CT_DoLoadState "${step}"
3.460 + do_it=1
3.461 + do_stop=0
3.462 + fi
3.463 + else
3.464 + CT_DoSaveState ${step}
3.465 + if [ ${do_stop} -eq 1 ]; then
3.466 + CT_DoLog ERROR "Stopping just after step '${prev_step}', as requested."
3.467 + exit 0
3.468 + fi
3.469 + fi
3.470 + if [ ${do_it} -eq 1 ]; then
3.471 + do_${step}
3.472 + if [ "${CT_STOP}" = "${step}" ]; then
3.473 + do_stop=1
3.474 + fi
3.475 + if [ "${CT_DEBUG_PAUSE_STEPS}" = "y" ]; then
3.476 + CT_DoPause "Step '${step}' finished"
3.477 + fi
3.478 + fi
3.479 + prev_step="${step}"
3.480 + done
3.481 +fi
3.482 +
3.483 +CT_DoEnd INFO
3.484 +
3.485 +# From now-on, it can become impossible to log any time, because
3.486 +# either we're compressing the log file, or it can become RO any
3.487 +# moment... Consign all ouptut to oblivion...
3.488 +CT_DoLog INFO "Finishing installation (may take a few seconds)..."
3.489 +exec >/dev/null 2>&1
3.490 +
3.491 +[ "${CT_LOG_FILE_COMPRESS}" = y ] && bzip2 -9 "${CT_LOG_FILE}"
3.492 +[ "${CT_INSTALL_DIR_RO}" = "y" ] && chmod -R a-w "${CT_INSTALL_DIR}"
3.493 +
3.494 +trap - EXIT