2009-01-26 22:43:08 +00:00
|
|
|
#!@@CT_bash@@
|
2007-02-24 11:00:05 +00:00
|
|
|
# Copyright 2007 Yann E. MORIN
|
|
|
|
# Licensed under the GPL v2. See COPYING in the root of this package.
|
|
|
|
|
|
|
|
# This is the main entry point to crosstool
|
|
|
|
# This will:
|
|
|
|
# - download, extract and patch the toolchain components
|
|
|
|
# - build and install each components in turn
|
|
|
|
# - and eventually test the resulting toolchain
|
|
|
|
|
|
|
|
# What this file does is prepare the environment, based upon the user-choosen
|
|
|
|
# options. It also checks the existing environment for un-friendly variables,
|
2007-05-17 16:22:51 +00:00
|
|
|
# and builds the tools.
|
2007-02-24 11:00:05 +00:00
|
|
|
|
|
|
|
# Parse the common functions
|
2008-05-14 17:56:33 +00:00
|
|
|
# Note: some initialisation and sanitizing is done while parsing this file,
|
|
|
|
# most notably:
|
|
|
|
# - set trap handler on errors,
|
|
|
|
# - don't hash commands lookups,
|
|
|
|
# - initialise logging.
|
2007-07-01 19:04:20 +00:00
|
|
|
. "${CT_LIB_DIR}/scripts/functions"
|
2007-02-24 11:00:05 +00:00
|
|
|
|
2007-05-17 16:22:51 +00:00
|
|
|
# Parse the configuration file
|
|
|
|
# It has some info about the logging facility, so include it early
|
2008-10-23 13:45:48 +00:00
|
|
|
. .config
|
2009-01-26 22:43:08 +00:00
|
|
|
# Yes! We can do full logging from now on!
|
2007-02-24 11:00:05 +00:00
|
|
|
|
2008-11-20 17:48:10 +00:00
|
|
|
# Overide the locale early, in case we ever translate crosstool-NG messages
|
|
|
|
[ -z "${CT_NO_OVERIDE_LC_MESSAGES}" ] && export LC_ALL=C
|
|
|
|
|
2009-01-26 22:43:08 +00:00
|
|
|
# Where will we work?
|
|
|
|
CT_WORK_DIR="${CT_WORK_DIR:-${CT_TOP_DIR}/targets}"
|
2009-03-27 18:53:54 +00:00
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_WORK_DIR}"
|
|
|
|
|
|
|
|
# Check build file system case-sensitiveness
|
2009-03-29 21:05:13 +00:00
|
|
|
CT_DoExecLog DEBUG touch "${CT_WORK_DIR}/foo"
|
2009-03-27 18:53:54 +00:00
|
|
|
CT_TestAndAbort "Your file system in '${CT_WORK_DIR}' is *not* case-sensitive!" -f "${CT_WORK_DIR}/FOO"
|
2009-03-29 21:05:13 +00:00
|
|
|
CT_DoExecLog DEBUG rm -f "${CT_WORK_DIR}/foo"
|
2009-01-26 22:43:08 +00:00
|
|
|
|
|
|
|
# Create the bin-overide early
|
2009-03-03 17:41:59 +00:00
|
|
|
# Contains symlinks to the tools found by ./configure
|
2009-01-26 22:43:08 +00:00
|
|
|
# Note: CT_DoLog and CT_DoExecLog do not use any of those tool, so
|
|
|
|
# they can be safely used
|
|
|
|
CT_BIN_OVERIDE_DIR="${CT_WORK_DIR}/bin"
|
|
|
|
CT_DoLog DEBUG "Creating bin-overide for tools in '${CT_BIN_OVERIDE_DIR}'"
|
|
|
|
CT_DoExecLog DEBUG mkdir -p "${CT_BIN_OVERIDE_DIR}"
|
|
|
|
cat "${CT_LIB_DIR}/paths.mk" |while read trash line; do
|
|
|
|
tool="${line%%=*}"
|
|
|
|
path="${line#*=}"
|
|
|
|
CT_DoLog DEBUG " '${tool}' -> '${path}'"
|
|
|
|
printf "#${BANG}/bin/sh\nexec '${path}' \"\${@}\"\n" >"${CT_BIN_OVERIDE_DIR}/${tool}"
|
|
|
|
CT_DoExecLog ALL chmod 700 "${CT_BIN_OVERIDE_DIR}/${tool}"
|
|
|
|
done
|
|
|
|
export PATH="${CT_BIN_OVERIDE_DIR}:${PATH}"
|
|
|
|
|
2008-11-20 17:48:10 +00:00
|
|
|
# Start date. Can't be done until we know the locale
|
|
|
|
CT_STAR_DATE=$(CT_DoDate +%s%N)
|
|
|
|
CT_STAR_DATE_HUMAN=$(CT_DoDate +%Y%m%d.%H%M%S)
|
|
|
|
|
2009-01-26 22:43:08 +00:00
|
|
|
# Log real begining of build, now
|
2007-02-24 11:00:05 +00:00
|
|
|
CT_DoLog INFO "Build started ${CT_STAR_DATE_HUMAN}"
|
|
|
|
|
2007-09-14 17:29:39 +00:00
|
|
|
# renice oursleves
|
2008-08-07 07:52:09 +00:00
|
|
|
CT_DoExecLog DEBUG renice ${CT_NICE} $$
|
2007-09-14 17:29:39 +00:00
|
|
|
|
2008-10-01 18:10:40 +00:00
|
|
|
CT_DoStep DEBUG "Dumping user-supplied crosstool-NG configuration"
|
2009-03-08 17:09:39 +00:00
|
|
|
CT_DoExecLog DEBUG grep -E '^(# |)CT_' .config
|
2007-05-17 16:22:51 +00:00
|
|
|
CT_EndStep
|
2007-05-07 09:04:02 +00:00
|
|
|
|
2007-02-24 11:00:05 +00:00
|
|
|
# Some sanity checks in the environment and needed tools
|
|
|
|
CT_DoLog INFO "Checking environment sanity"
|
|
|
|
|
2007-07-23 19:49:35 +00:00
|
|
|
CT_DoLog DEBUG "Unsetting and unexporting MAKEFLAGS"
|
|
|
|
unset MAKEFLAGS
|
|
|
|
export MAKEFLAGS
|
|
|
|
|
2007-02-24 11:00:05 +00:00
|
|
|
# Other environment sanity checks
|
|
|
|
CT_TestAndAbort "Don't set LD_LIBRARY_PATH. It screws up the build." -n "${LD_LIBRARY_PATH}"
|
|
|
|
CT_TestAndAbort "Don't set CFLAGS. It screws up the build." -n "${CFLAGS}"
|
|
|
|
CT_TestAndAbort "Don't set CXXFLAGS. It screws up the build." -n "${CXXFLAGS}"
|
|
|
|
CT_Test "GREP_OPTIONS screws up the build. Resetting." -n "${GREP_OPTIONS}"
|
2008-10-23 13:45:48 +00:00
|
|
|
export GREP_OPTIONS=
|
2007-02-24 11:00:05 +00:00
|
|
|
|
|
|
|
CT_DoLog INFO "Building environment variables"
|
|
|
|
|
2008-10-23 13:45:48 +00:00
|
|
|
# Include sub-scripts instead of calling them: that way, we do not have to
|
|
|
|
# export any variable, nor re-parse the configuration and functions files.
|
2009-03-04 17:59:35 +00:00
|
|
|
. "${CT_LIB_DIR}/scripts/build/internals.sh"
|
2008-10-05 15:32:00 +00:00
|
|
|
. "${CT_LIB_DIR}/scripts/build/arch/${CT_ARCH}.sh"
|
2008-10-23 13:45:48 +00:00
|
|
|
. "${CT_LIB_DIR}/scripts/build/kernel/${CT_KERNEL}.sh"
|
2009-05-03 21:10:15 +00:00
|
|
|
. "${CT_LIB_DIR}/scripts/build/companion_libs/gmp.sh"
|
|
|
|
. "${CT_LIB_DIR}/scripts/build/companion_libs/mpfr.sh"
|
2008-10-23 13:45:48 +00:00
|
|
|
. "${CT_LIB_DIR}/scripts/build/binutils.sh"
|
|
|
|
. "${CT_LIB_DIR}/scripts/build/libc/${CT_LIBC}.sh"
|
|
|
|
. "${CT_LIB_DIR}/scripts/build/cc/${CT_CC}.sh"
|
|
|
|
. "${CT_LIB_DIR}/scripts/build/tools.sh"
|
|
|
|
. "${CT_LIB_DIR}/scripts/build/debug.sh"
|
2007-09-14 17:43:16 +00:00
|
|
|
|
2007-08-15 16:18:35 +00:00
|
|
|
# Target tuple: CT_TARGET needs a little love:
|
|
|
|
CT_DoBuildTargetTuple
|
2007-02-24 11:00:05 +00:00
|
|
|
|
2007-05-17 16:22:51 +00:00
|
|
|
# Kludge: If any of the configured options needs CT_TARGET,
|
|
|
|
# then rescan the options file now:
|
2008-12-09 21:25:29 +00:00
|
|
|
. .config
|
2007-05-17 16:22:51 +00:00
|
|
|
|
2007-09-16 17:59:18 +00:00
|
|
|
# Second kludge: merge user-supplied target CFLAGS with architecture-provided
|
2008-05-24 22:38:07 +00:00
|
|
|
# target CFLAGS. Do the same for LDFLAGS in case it happens in the future.
|
|
|
|
# Put user-supplied flags at the end, so that they take precedence.
|
2007-09-16 17:59:18 +00:00
|
|
|
CT_TARGET_CFLAGS="${CT_ARCH_TARGET_CFLAGS} ${CT_TARGET_CFLAGS}"
|
2008-05-24 22:38:07 +00:00
|
|
|
CT_TARGET_LDFLAGS="${CT_ARCH_TARGET_LDFLAGS} ${CT_TARGET_LDFLAGS}"
|
2008-08-07 15:18:18 +00:00
|
|
|
CT_CC_CORE_EXTRA_CONFIG="${CT_ARCH_CC_CORE_EXTRA_CONFIG} ${CT_CC_CORE_EXTRA_CONFIG}"
|
|
|
|
CT_CC_EXTRA_CONFIG="${CT_ARCH_CC_EXTRA_CONFIG} ${CT_CC_EXTRA_CONFIG}"
|
2007-09-16 17:59:18 +00:00
|
|
|
|
2009-01-26 22:43:08 +00:00
|
|
|
# Create the working directories
|
2008-06-24 16:19:45 +00:00
|
|
|
CT_TARBALLS_DIR="${CT_WORK_DIR}/tarballs"
|
|
|
|
CT_SRC_DIR="${CT_WORK_DIR}/src"
|
|
|
|
CT_BUILD_DIR="${CT_WORK_DIR}/${CT_TARGET}/build"
|
2009-03-27 23:40:07 +00:00
|
|
|
CT_STATE_DIR="${CT_WORK_DIR}/${CT_TARGET}/state"
|
|
|
|
CT_CONFIG_DIR="${CT_BUILD_DIR}/configs"
|
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
# Note: we'll always install the core compiler in its own directory, so as to
|
2007-08-15 10:14:43 +00:00
|
|
|
# not mix the two builds: core and final.
|
2007-05-27 20:22:06 +00:00
|
|
|
CT_CC_CORE_STATIC_PREFIX_DIR="${CT_BUILD_DIR}/${CT_CC}-core-static"
|
|
|
|
CT_CC_CORE_SHARED_PREFIX_DIR="${CT_BUILD_DIR}/${CT_CC}-core-shared"
|
2007-05-10 21:33:35 +00:00
|
|
|
|
2007-05-28 21:33:35 +00:00
|
|
|
# We must ensure that we can restart if asked for!
|
|
|
|
if [ -n "${CT_RESTART}" -a ! -d "${CT_STATE_DIR}" ]; then
|
|
|
|
CT_DoLog ERROR "You asked to restart a non-restartable build"
|
|
|
|
CT_DoLog ERROR "This happened because you didn't set CT_DEBUG_CT_SAVE_STEPS"
|
2007-06-02 15:50:45 +00:00
|
|
|
CT_DoLog ERROR "in the config options for the previous build, or the state"
|
2008-02-14 22:44:34 +00:00
|
|
|
CT_DoLog ERROR "directory for the previous build was deleted."
|
2007-05-28 21:33:35 +00:00
|
|
|
CT_Abort "I will stop here to avoid any carnage"
|
|
|
|
fi
|
|
|
|
|
2007-09-23 17:18:18 +00:00
|
|
|
# If the local tarball directory does not exist, say so, and don't try to save there!
|
|
|
|
if [ ! -d "${CT_LOCAL_TARBALLS_DIR}" ]; then
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog WARN "Directory '${CT_LOCAL_TARBALLS_DIR}' does not exist. Will not save downloaded tarballs to local storage."
|
|
|
|
CT_SAVE_TARBALLS=
|
2007-09-23 17:18:18 +00:00
|
|
|
fi
|
|
|
|
|
2007-05-07 09:04:02 +00:00
|
|
|
# Some more sanity checks now that we have all paths set up
|
2007-09-23 17:18:18 +00:00
|
|
|
case "${CT_LOCAL_TARBALLS_DIR},${CT_TARBALLS_DIR},${CT_SRC_DIR},${CT_BUILD_DIR},${CT_PREFIX_DIR},${CT_INSTALL_DIR}" in
|
2007-05-07 09:04:02 +00:00
|
|
|
*" "*) CT_Abort "Don't use spaces in paths, it breaks things.";;
|
|
|
|
esac
|
|
|
|
|
2007-05-10 21:33:35 +00:00
|
|
|
# Check now if we can write to the destination directory:
|
|
|
|
if [ -d "${CT_INSTALL_DIR}" ]; then
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_TestAndAbort "Destination directory '${CT_INSTALL_DIR}' is not removable" ! -w $(dirname "${CT_INSTALL_DIR}")
|
2007-05-10 21:33:35 +00:00
|
|
|
fi
|
|
|
|
|
2007-05-17 16:22:51 +00:00
|
|
|
# Good, now grab a bit of informations on the system we're being run on,
|
|
|
|
# just in case something goes awok, and it's not our fault:
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_SYS_USER=$(id -un)
|
|
|
|
CT_SYS_HOSTNAME=$(hostname -f 2>/dev/null || true)
|
2007-05-17 16:22:51 +00:00
|
|
|
# Hmmm. Some non-DHCP-enabled machines do not have an FQDN... Fall back to node name.
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_SYS_HOSTNAME="${CT_SYS_HOSTNAME:-$(uname -n)}"
|
|
|
|
CT_SYS_KERNEL=$(uname -s)
|
|
|
|
CT_SYS_REVISION=$(uname -r)
|
2007-05-17 16:22:51 +00:00
|
|
|
# MacOS X lacks '-o' :
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_SYS_OS=$(uname -o || echo "Unknown (maybe MacOS-X)")
|
|
|
|
CT_SYS_MACHINE=$(uname -m)
|
|
|
|
CT_SYS_PROCESSOR=$(uname -p)
|
|
|
|
CT_SYS_GCC=$(gcc -dumpversion)
|
|
|
|
CT_SYS_TARGET=$(CT_DoConfigGuess)
|
2007-05-17 16:22:51 +00:00
|
|
|
CT_TOOLCHAIN_ID="crosstool-${CT_VERSION} build ${CT_STAR_DATE_HUMAN} by ${CT_SYS_USER}@${CT_SYS_HOSTNAME}"
|
|
|
|
|
|
|
|
CT_DoLog EXTRA "Preparing working directories"
|
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
# Ah! The build directory shall be eradicated, even if we restart!
|
2007-05-10 21:33:35 +00:00
|
|
|
if [ -d "${CT_BUILD_DIR}" ]; then
|
2009-01-12 21:35:23 +00:00
|
|
|
CT_DoForceRmdir "${CT_BUILD_DIR}"
|
2007-05-10 21:33:35 +00:00
|
|
|
fi
|
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
# Don't eradicate directories if we need to restart
|
|
|
|
if [ -z "${CT_RESTART}" ]; then
|
|
|
|
# Get rid of pre-existing installed toolchain and previous build directories.
|
|
|
|
# We need to do that _before_ we can safely log, because the log file will
|
|
|
|
# most probably be in the toolchain directory.
|
|
|
|
if [ "${CT_FORCE_DOWNLOAD}" = "y" -a -d "${CT_TARBALLS_DIR}" ]; then
|
2009-01-12 21:35:23 +00:00
|
|
|
CT_DoForceRmdir "${CT_TARBALLS_DIR}"
|
2007-05-22 20:46:07 +00:00
|
|
|
fi
|
|
|
|
if [ "${CT_FORCE_EXTRACT}" = "y" -a -d "${CT_SRC_DIR}" ]; then
|
2009-01-12 21:35:23 +00:00
|
|
|
CT_DoForceRmdir "${CT_SRC_DIR}"
|
2007-05-22 20:46:07 +00:00
|
|
|
fi
|
|
|
|
if [ -d "${CT_INSTALL_DIR}" ]; then
|
2009-01-12 21:35:23 +00:00
|
|
|
CT_DoForceRmdir "${CT_INSTALL_DIR}"
|
2007-05-22 20:46:07 +00:00
|
|
|
fi
|
|
|
|
# In case we start anew, get rid of the previously saved state directory
|
|
|
|
if [ -d "${CT_STATE_DIR}" ]; then
|
2009-01-12 21:35:23 +00:00
|
|
|
CT_DoForceRmdir "${CT_STATE_DIR}"
|
2007-05-22 20:46:07 +00:00
|
|
|
fi
|
|
|
|
fi
|
2007-05-07 09:04:02 +00:00
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
# Create the directories we'll use, even if restarting: it does no harm to
|
|
|
|
# create already existent directories, and CT_BUILD_DIR needs to be created
|
|
|
|
# anyway
|
2009-01-12 18:57:45 +00:00
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_TARBALLS_DIR}"
|
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_SRC_DIR}"
|
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_BUILD_DIR}"
|
2009-03-27 23:40:07 +00:00
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_CONFIG_DIR}"
|
2009-01-12 18:57:45 +00:00
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_INSTALL_DIR}"
|
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}"
|
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_CC_CORE_STATIC_PREFIX_DIR}"
|
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_CC_CORE_SHARED_PREFIX_DIR}"
|
2009-03-27 23:40:07 +00:00
|
|
|
|
|
|
|
# Only create the state dir if asked for a restartable build
|
|
|
|
[ -n "${CT_DEBUG_CT_SAVE_STEPS}" ] && CT_DoExecLog ALL mkdir -p "${CT_STATE_DIR}"
|
2007-05-22 20:46:07 +00:00
|
|
|
|
2009-03-27 18:53:54 +00:00
|
|
|
# Check install file system case-sensitiveness
|
2009-03-29 21:05:13 +00:00
|
|
|
CT_DoExecLog DEBUG touch "${CT_PREFIX_DIR}/foo"
|
2009-03-27 18:53:54 +00:00
|
|
|
CT_TestAndAbort "Your file system in '${CT_PREFIX_DIR}' is *not* case-sensitive!" -f "${CT_PREFIX_DIR}/FOO"
|
2009-03-29 21:05:13 +00:00
|
|
|
CT_DoExecLog DEBUG rm -f "${CT_PREFIX_DIR}/foo"
|
2009-03-27 18:53:54 +00:00
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
# Kludge: CT_INSTALL_DIR and CT_PREFIX_DIR might have grown read-only if
|
2008-02-14 22:44:34 +00:00
|
|
|
# the previous build was successful. To be able to move the logfile there,
|
2007-05-22 20:46:07 +00:00
|
|
|
# switch them back to read/write
|
2009-01-12 18:57:45 +00:00
|
|
|
CT_DoExecLog ALL chmod -R u+w "${CT_INSTALL_DIR}" "${CT_PREFIX_DIR}"
|
2007-05-10 21:33:35 +00:00
|
|
|
|
2007-02-24 11:00:05 +00:00
|
|
|
# Redirect log to the actual log file now we can
|
2007-05-07 09:04:02 +00:00
|
|
|
# It's quite understandable that the log file will be installed in the install
|
|
|
|
# directory, so we must first ensure it exists and is writeable (above) before
|
|
|
|
# we can log there
|
2007-05-20 13:48:26 +00:00
|
|
|
exec >/dev/null
|
2007-06-17 14:51:37 +00:00
|
|
|
case "${CT_LOG_TO_FILE}" in
|
|
|
|
y) CT_LOG_FILE="${CT_PREFIX_DIR}/build.log"
|
|
|
|
cat "${tmp_log_file}" >>"${CT_LOG_FILE}"
|
|
|
|
rm -f "${tmp_log_file}"
|
|
|
|
exec >>"${CT_LOG_FILE}"
|
|
|
|
;;
|
|
|
|
*) rm -f "${tmp_log_file}"
|
|
|
|
;;
|
2007-02-24 11:00:05 +00:00
|
|
|
esac
|
|
|
|
|
2007-09-16 17:59:18 +00:00
|
|
|
# Setting up the rest of the environment only if not restarting
|
2007-05-22 20:46:07 +00:00
|
|
|
if [ -z "${CT_RESTART}" ]; then
|
2008-11-13 18:22:23 +00:00
|
|
|
# What's our shell?
|
|
|
|
# Will be plain /bin/sh on most systems, except if we have /bin/ash and we
|
|
|
|
# _explictly_ required using it
|
|
|
|
CT_SHELL="/bin/sh"
|
|
|
|
[ "${CT_CONFIG_SHELL_ASH}" = "y" -a -x "/bin/ash" ] && CT_SHELL="/bin/ash"
|
2007-05-22 20:46:07 +00:00
|
|
|
|
|
|
|
# Arrange paths depending on wether we use sys-root or not.
|
|
|
|
if [ "${CT_USE_SYSROOT}" = "y" ]; then
|
2009-03-03 17:41:59 +00:00
|
|
|
CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}/${CT_SYSROOT_DIR_PREFIX}/sys-root"
|
|
|
|
CT_DEBUGROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}/${CT_SYSROOT_DIR_PREFIX}/debug-root"
|
2007-05-22 20:46:07 +00:00
|
|
|
CT_HEADERS_DIR="${CT_SYSROOT_DIR}/usr/include"
|
|
|
|
BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
|
|
|
|
CC_CORE_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
|
|
|
|
CC_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
|
|
|
|
LIBC_SYSROOT_ARG=""
|
|
|
|
# glibc's prefix must be exactly /usr, else --with-sysroot'd gcc will get
|
|
|
|
# confused when $sysroot/usr/include is not present.
|
|
|
|
# Note: --prefix=/usr is magic!
|
|
|
|
# See http://www.gnu.org/software/libc/FAQ.html#s-2.2
|
|
|
|
else
|
|
|
|
# plain old way. All libraries in prefix/target/lib
|
|
|
|
CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}"
|
|
|
|
CT_HEADERS_DIR="${CT_SYSROOT_DIR}/include"
|
|
|
|
# hack! Always use --with-sysroot for binutils.
|
|
|
|
# binutils 2.14 and later obey it, older binutils ignore it.
|
|
|
|
# Lets you build a working 32->64 bit cross gcc
|
|
|
|
BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
|
|
|
|
# Use --with-headers, else final gcc will define disable_glibc while
|
|
|
|
# building libgcc, and you'll have no profiling
|
|
|
|
CC_CORE_SYSROOT_ARG="--without-headers"
|
|
|
|
CC_SYSROOT_ARG="--with-headers=${CT_HEADERS_DIR}"
|
|
|
|
LIBC_SYSROOT_ARG="prefix="
|
|
|
|
fi
|
2009-03-03 17:41:59 +00:00
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}"
|
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_DEBUGROOT_DIR}"
|
2007-05-07 09:04:02 +00:00
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
# Prepare the 'lib' directories in sysroot, else the ../lib64 hack used by
|
2009-01-31 17:38:26 +00:00
|
|
|
# 32 -> 64 bit crosscompilers won't work, and build of final gcc will fail
|
|
|
|
# with: "ld: cannot open crti.o: No such file or directory"
|
|
|
|
# Also prepare the lib directory in the install dir, else some 64 bit archs
|
|
|
|
# won't build
|
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/lib"
|
2009-01-12 18:57:45 +00:00
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/lib"
|
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/usr/lib"
|
2007-05-22 20:46:07 +00:00
|
|
|
|
2008-07-27 16:35:37 +00:00
|
|
|
# Prevent gcc from installing its libraries outside of the sys-root
|
2009-03-03 17:41:59 +00:00
|
|
|
CT_DoExecLog ALL ln -sf "./${CT_SYSROOT_DIR_PREFIX}/sys-root/lib" "${CT_PREFIX_DIR}/${CT_TARGET}/lib"
|
2008-07-27 16:35:37 +00:00
|
|
|
|
|
|
|
# Now, in case we're 64 bits, just have lib64/ be a symlink to lib/
|
|
|
|
# so as to have all libraries in the same directory (we can do that
|
|
|
|
# because we are *not* multilib).
|
2008-11-07 08:09:42 +00:00
|
|
|
if [ "${CT_ARCH_64}" = "y" ]; then
|
2009-01-31 17:38:26 +00:00
|
|
|
CT_DoExecLog ALL ln -sf "lib" "${CT_PREFIX_DIR}/lib64"
|
2009-01-12 18:57:45 +00:00
|
|
|
CT_DoExecLog ALL ln -sf "lib" "${CT_SYSROOT_DIR}/lib64"
|
|
|
|
CT_DoExecLog ALL ln -sf "lib" "${CT_SYSROOT_DIR}/usr/lib64"
|
2009-03-03 17:41:59 +00:00
|
|
|
CT_DoExecLog ALL ln -sf "lib" "${CT_PREFIX_DIR}/${CT_TARGET}/lib64"
|
2008-11-07 08:09:42 +00:00
|
|
|
fi
|
2008-07-27 16:35:37 +00:00
|
|
|
|
2008-11-13 18:22:23 +00:00
|
|
|
# Determine build system if not set by the user
|
|
|
|
CT_Test "You did not specify the build system. That's OK, I can guess..." -z "${CT_BUILD}"
|
|
|
|
case "${CT_BUILD}" in
|
2008-11-28 23:31:02 +00:00
|
|
|
"") CT_BUILD=$("${CT_BUILD_PREFIX}gcc${CT_BUILD_SUFFIX}" -dumpmachine);;
|
2008-11-13 18:22:23 +00:00
|
|
|
esac
|
2007-02-24 11:00:05 +00:00
|
|
|
|
2008-11-28 23:33:04 +00:00
|
|
|
# Prepare mangling patterns to later modify BUILD and HOST (see below)
|
2008-11-13 18:22:23 +00:00
|
|
|
case "${CT_TOOLCHAIN_TYPE}" in
|
|
|
|
cross)
|
|
|
|
CT_HOST="${CT_BUILD}"
|
|
|
|
build_mangle="build_"
|
|
|
|
host_mangle="build_"
|
|
|
|
;;
|
|
|
|
*) CT_Abort "No code for '${CT_TOOLCHAIN_TYPE}' toolchain type!"
|
|
|
|
;;
|
2007-05-17 16:22:51 +00:00
|
|
|
esac
|
2007-02-24 11:00:05 +00:00
|
|
|
|
2008-11-13 18:22:23 +00:00
|
|
|
# Save the real tuples to generate shell-wrappers to the real tools
|
|
|
|
CT_REAL_BUILD="${CT_BUILD}"
|
|
|
|
CT_REAL_HOST="${CT_HOST}"
|
|
|
|
|
2008-11-28 23:31:02 +00:00
|
|
|
# Canonicalise CT_BUILD and CT_HOST
|
|
|
|
# Not only will it give us full-qualified tuples, but it will also ensure
|
|
|
|
# that they are valid tuples (in case of typo with user-provided tuples)
|
|
|
|
# That's way better than trying to rewrite config.sub ourselves...
|
2008-12-03 22:35:52 +00:00
|
|
|
CT_BUILD=$(CT_DoConfigSub "${CT_BUILD}")
|
|
|
|
CT_HOST=$(CT_DoConfigSub "${CT_HOST}")
|
2008-11-04 16:30:11 +00:00
|
|
|
|
2008-11-13 18:22:23 +00:00
|
|
|
# Modify BUILD and HOST so that gcc always generate a cross-compiler
|
|
|
|
# even if any of the build, host or target machines are the same.
|
|
|
|
# NOTE: we'll have to mangle the (BUILD|HOST)->TARGET x-compiler to
|
|
|
|
# support canadain build, later...
|
|
|
|
CT_BUILD="${CT_BUILD/-/-${build_mangle}}"
|
|
|
|
CT_HOST="${CT_HOST/-/-${host_mangle}}"
|
|
|
|
|
|
|
|
# Now we have mangled our BUILD and HOST tuples, we must fake the new
|
|
|
|
# cross-tools for those mangled tuples.
|
2007-06-17 14:51:37 +00:00
|
|
|
CT_DoLog DEBUG "Making build system tools available"
|
2009-01-12 18:57:45 +00:00
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/bin"
|
2008-11-13 18:22:23 +00:00
|
|
|
for m in BUILD HOST; do
|
|
|
|
r="CT_REAL_${m}"
|
|
|
|
v="CT_${m}"
|
|
|
|
p="CT_${m}_PREFIX"
|
|
|
|
s="CT_${m}_SUFFIX"
|
|
|
|
if [ -n "${!p}" ]; then
|
|
|
|
t="${!p}"
|
|
|
|
else
|
|
|
|
t="${!r}-"
|
|
|
|
fi
|
|
|
|
|
2009-01-06 22:10:17 +00:00
|
|
|
for tool in ar as dlltool gcc g++ gcj gnatbind gnatmake ld nm objcopy objdump ranlib strip windres; do
|
2008-11-13 18:22:23 +00:00
|
|
|
# First try with prefix + suffix
|
|
|
|
# Then try with prefix only
|
|
|
|
# Then try with suffix only, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
|
|
|
|
# Finally try with neither prefix nor suffix, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
|
|
|
|
# This is needed, because some tools have a prefix and
|
|
|
|
# a suffix (eg. gcc), while others may have only one,
|
|
|
|
# or even none (eg. binutils)
|
|
|
|
where=$(CT_Which "${t}${tool}${!s}")
|
|
|
|
[ -z "${where}" ] && where=$(CT_Which "${t}${tool}")
|
|
|
|
if [ -z "${where}" \
|
|
|
|
-a \( "${m}" = "BUILD" \
|
|
|
|
-o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
|
|
|
|
where=$(CT_Which "${tool}${!s}")
|
|
|
|
fi
|
|
|
|
if [ -z "${where}" \
|
|
|
|
-a \( "${m}" = "BUILD" \
|
|
|
|
-o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
|
|
|
|
where=$(CT_Which "${tool}")
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Not all tools are available for all platforms, but some are really,
|
|
|
|
# bally needed
|
|
|
|
if [ -n "${where}" ]; then
|
|
|
|
CT_DoLog DEBUG " '${!v}-${tool}' -> '${where}'"
|
|
|
|
printf "#${BANG}${CT_SHELL}\nexec '${where}' \"\${@}\"\n" >"${CT_PREFIX_DIR}/bin/${!v}-${tool}"
|
2009-01-12 18:57:45 +00:00
|
|
|
CT_DoExecLog ALL chmod 700 "${CT_PREFIX_DIR}/bin/${!v}-${tool}"
|
2008-11-13 18:22:23 +00:00
|
|
|
else
|
|
|
|
case "${tool}" in
|
2009-01-29 22:09:55 +00:00
|
|
|
# We'll at least need some of them...
|
2008-11-13 18:22:23 +00:00
|
|
|
ar|as|gcc|ld|nm|objcopy|objdump|ranlib)
|
|
|
|
CT_Abort "Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : either needed!"
|
|
|
|
;;
|
2009-01-29 22:09:55 +00:00
|
|
|
# Some are conditionnally required
|
|
|
|
# Add them in alphabetical (C locale) ordering
|
|
|
|
gcj)
|
|
|
|
CT_TestAndAbort "Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : either needed!" "${CT_CC_LANG_JAVA}" = "y"
|
|
|
|
;;
|
|
|
|
# If any other is missing, only warn at low level
|
2008-11-13 18:22:23 +00:00
|
|
|
*)
|
|
|
|
# It does not deserve a WARN level.
|
|
|
|
CT_DoLog DEBUG " Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : not required."
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
done
|
2007-05-22 20:46:07 +00:00
|
|
|
done
|
2007-02-24 11:00:05 +00:00
|
|
|
|
2008-11-13 18:22:23 +00:00
|
|
|
# Carefully add paths in the order we want them:
|
|
|
|
# - first try in ${CT_PREFIX_DIR}/bin
|
|
|
|
# - then try in ${CT_CC_CORE_SHARED_PREFIX_DIR}/bin
|
|
|
|
# - then try in ${CT_CC_CORE_STATIC_PREFIX_DIR}/bin
|
|
|
|
# - fall back to searching user's PATH
|
|
|
|
# Of course, neither cross-native nor canadian can run on BUILD,
|
|
|
|
# so don't add those PATHs in this case...
|
|
|
|
case "${CT_TOOLCHAIN_TYPE}" in
|
|
|
|
cross) export PATH="${CT_PREFIX_DIR}/bin:${CT_CC_CORE_SHARED_PREFIX_DIR}/bin:${CT_CC_CORE_STATIC_PREFIX_DIR}/bin:${PATH}";;
|
|
|
|
*) ;;
|
|
|
|
esac
|
|
|
|
|
2008-06-15 22:02:45 +00:00
|
|
|
# Some makeinfo versions are a pain in [put your most sensible body part here].
|
|
|
|
# Go ahead with those, by creating a wrapper that keeps partial files, and that
|
|
|
|
# never fails:
|
2009-01-12 18:57:45 +00:00
|
|
|
CT_DoLog DEBUG " 'makeinfo' -> '$(CT_Which makeinfo)'"
|
2008-11-28 23:33:04 +00:00
|
|
|
printf "#${BANG}/bin/sh\n$(CT_Which makeinfo) --force \"\${@}\"\ntrue\n" >"${CT_PREFIX_DIR}/bin/makeinfo"
|
2009-01-12 18:57:45 +00:00
|
|
|
CT_DoExecLog ALL chmod 700 "${CT_PREFIX_DIR}/bin/makeinfo"
|
2008-06-15 22:02:45 +00:00
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
# Help gcc
|
|
|
|
CT_CFLAGS_FOR_HOST=
|
|
|
|
[ "${CT_USE_PIPES}" = "y" ] && CT_CFLAGS_FOR_HOST="${CT_CFLAGS_FOR_HOST} -pipe"
|
|
|
|
|
2007-08-15 14:59:37 +00:00
|
|
|
# Override the configured jobs with what's been given on the command line
|
|
|
|
[ -n "${CT_JOBS}" ] && CT_PARALLEL_JOBS="${CT_JOBS}"
|
|
|
|
|
2008-11-04 16:30:11 +00:00
|
|
|
# Set the shell to be used by ./configure scripts and by Makefiles (those
|
|
|
|
# that support it!).
|
|
|
|
export CONFIG_SHELL="${CT_SHELL}"
|
2008-08-25 19:44:39 +00:00
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
# And help make go faster
|
|
|
|
PARALLELMFLAGS=
|
|
|
|
[ ${CT_PARALLEL_JOBS} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -j${CT_PARALLEL_JOBS}"
|
|
|
|
[ ${CT_LOAD} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -l${CT_LOAD}"
|
2008-06-17 11:30:36 +00:00
|
|
|
export PARALLELMFLAGS
|
2007-05-22 20:46:07 +00:00
|
|
|
|
2008-10-01 18:10:40 +00:00
|
|
|
CT_DoLog EXTRA "Installing user-supplied crosstool-NG configuration"
|
2008-12-11 18:21:18 +00:00
|
|
|
CT_DoExecLog DEBUG install -m 0755 "${CT_LIB_DIR}/scripts/toolchain-config.in" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
|
2009-02-01 18:51:19 +00:00
|
|
|
CT_DoExecLog DEBUG sed -r -i -e 's,@@grep@@,"'"${grep}"'",;' "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
|
2008-10-06 21:23:31 +00:00
|
|
|
bzip2 -c -9 .config >>"${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
|
2008-10-01 18:10:40 +00:00
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
CT_DoStep EXTRA "Dumping internal crosstool-NG configuration"
|
|
|
|
CT_DoLog EXTRA "Building a toolchain for:"
|
2008-11-13 18:22:23 +00:00
|
|
|
CT_DoLog EXTRA " build = ${CT_REAL_BUILD}"
|
|
|
|
CT_DoLog EXTRA " host = ${CT_REAL_HOST}"
|
2007-05-22 20:46:07 +00:00
|
|
|
CT_DoLog EXTRA " target = ${CT_TARGET}"
|
2009-03-08 17:09:39 +00:00
|
|
|
set |grep -E '^CT_.+=' |sort |CT_DoLog DEBUG
|
2007-05-22 20:46:07 +00:00
|
|
|
CT_EndStep
|
|
|
|
fi
|
2007-02-24 11:00:05 +00:00
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
if [ -z "${CT_RESTART}" ]; then
|
|
|
|
CT_DoStep INFO "Retrieving needed toolchain components' tarballs"
|
|
|
|
do_kernel_get
|
2008-04-30 10:43:41 +00:00
|
|
|
do_gmp_get
|
|
|
|
do_mpfr_get
|
2007-05-22 20:46:07 +00:00
|
|
|
do_binutils_get
|
|
|
|
do_cc_get
|
2007-08-15 10:14:43 +00:00
|
|
|
do_libc_get
|
2007-06-01 16:55:33 +00:00
|
|
|
do_tools_get
|
2007-05-22 20:46:07 +00:00
|
|
|
do_debug_get
|
2007-05-07 09:04:02 +00:00
|
|
|
CT_EndStep
|
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
if [ "${CT_ONLY_DOWNLOAD}" != "y" ]; then
|
|
|
|
if [ "${CT_FORCE_EXTRACT}" = "y" ]; then
|
2009-01-12 21:35:23 +00:00
|
|
|
CT_DoForceRmdir "${CT_SRC_DIR}"
|
2009-01-12 18:57:45 +00:00
|
|
|
CT_DoExecLog ALL mkdir -p "${CT_SRC_DIR}"
|
2007-05-10 21:33:35 +00:00
|
|
|
fi
|
2007-05-22 20:46:07 +00:00
|
|
|
CT_DoStep INFO "Extracting and patching toolchain components"
|
|
|
|
do_kernel_extract
|
2008-04-30 10:43:41 +00:00
|
|
|
do_gmp_extract
|
|
|
|
do_mpfr_extract
|
2007-05-22 20:46:07 +00:00
|
|
|
do_binutils_extract
|
|
|
|
do_cc_extract
|
2007-08-15 10:14:43 +00:00
|
|
|
do_libc_extract
|
2007-06-01 16:55:33 +00:00
|
|
|
do_tools_extract
|
2007-05-22 20:46:07 +00:00
|
|
|
do_debug_extract
|
|
|
|
CT_EndStep
|
|
|
|
fi
|
|
|
|
fi
|
2007-05-10 21:33:35 +00:00
|
|
|
|
2007-05-22 20:46:07 +00:00
|
|
|
# Now for the job by itself. Go have a coffee!
|
|
|
|
if [ "${CT_ONLY_DOWNLOAD}" != "y" -a "${CT_ONLY_EXTRACT}" != "y" ]; then
|
|
|
|
# Because of CT_RESTART, this becomes quite complex
|
2007-05-28 21:33:35 +00:00
|
|
|
do_stop=0
|
|
|
|
prev_step=
|
2007-05-22 20:46:07 +00:00
|
|
|
[ -n "${CT_RESTART}" ] && do_it=0 || do_it=1
|
2008-04-30 10:43:41 +00:00
|
|
|
# Aha! CT_STEPS comes from steps.mk!
|
2008-04-28 07:38:36 +00:00
|
|
|
for step in ${CT_STEPS}; do
|
2007-05-22 20:46:07 +00:00
|
|
|
if [ ${do_it} -eq 0 ]; then
|
|
|
|
if [ "${CT_RESTART}" = "${step}" ]; then
|
|
|
|
CT_DoLoadState "${step}"
|
|
|
|
do_it=1
|
2007-05-28 21:33:35 +00:00
|
|
|
do_stop=0
|
2007-05-22 20:46:07 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
CT_DoSaveState ${step}
|
2007-05-28 21:33:35 +00:00
|
|
|
if [ ${do_stop} -eq 1 ]; then
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoLog ERROR "Stopping just after step '${prev_step}', as requested."
|
2007-05-28 21:33:35 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
2007-05-10 21:33:35 +00:00
|
|
|
fi
|
2007-05-22 20:46:07 +00:00
|
|
|
if [ ${do_it} -eq 1 ]; then
|
|
|
|
do_${step}
|
2007-05-25 19:30:42 +00:00
|
|
|
if [ "${CT_STOP}" = "${step}" ]; then
|
2007-05-28 21:33:35 +00:00
|
|
|
do_stop=1
|
2007-05-25 19:30:42 +00:00
|
|
|
fi
|
2008-07-25 22:57:35 +00:00
|
|
|
if [ "${CT_DEBUG_PAUSE_STEPS}" = "y" ]; then
|
2008-05-20 21:32:39 +00:00
|
|
|
CT_DoPause "Step '${step}' finished"
|
2007-05-22 20:46:07 +00:00
|
|
|
fi
|
|
|
|
fi
|
2007-05-28 21:33:35 +00:00
|
|
|
prev_step="${step}"
|
2007-05-22 20:46:07 +00:00
|
|
|
done
|
2007-03-07 19:00:10 +00:00
|
|
|
fi
|
|
|
|
|
2007-05-17 16:22:51 +00:00
|
|
|
CT_DoEnd INFO
|
|
|
|
|
2009-01-12 18:57:45 +00:00
|
|
|
# From now-on, it can become impossible to log any time, because
|
|
|
|
# either we're compressing the log file, or it can become RO any
|
|
|
|
# moment... Consign all ouptut to oblivion...
|
|
|
|
CT_DoLog INFO "Finishing installation (may take a few seconds)..."
|
|
|
|
exec >/dev/null 2>&1
|
2007-06-17 14:51:37 +00:00
|
|
|
|
2009-01-12 18:57:45 +00:00
|
|
|
[ "${CT_LOG_FILE_COMPRESS}" = y ] && bzip2 -9 "${CT_LOG_FILE}"
|
|
|
|
[ "${CT_INSTALL_DIR_RO}" = "y" ] && chmod -R a-w "${CT_INSTALL_DIR}"
|
2007-02-24 11:00:05 +00:00
|
|
|
|
|
|
|
trap - EXIT
|