1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/scripts/crosstool.sh Sat Feb 24 11:00:05 2007 +0000
1.3 @@ -0,0 +1,273 @@
1.4 +#!/bin/bash
1.5 +# Copyright 2007 Yann E. MORIN
1.6 +# Licensed under the GPL v2. See COPYING in the root of this package.
1.7 +
1.8 +# This is the main entry point to crosstool
1.9 +# This will:
1.10 +# - download, extract and patch the toolchain components
1.11 +# - build and install each components in turn
1.12 +# - and eventually test the resulting toolchain
1.13 +
1.14 +# What this file does is prepare the environment, based upon the user-choosen
1.15 +# options. It also checks the existing environment for un-friendly variables,
1.16 +# and checks for needed tools. It eventually calls the main build script.
1.17 +
1.18 +# User must set CT_TOP_DIR in is environment!
1.19 +# Once we can build out-of-tree, then this will have to go.
1.20 +if [ -z "${CT_TOP_DIR}" -o ! -d "${CT_TOP_DIR}" ]; then
1.21 + # We don't have the functions right now, because we don't have CT_TOP_DIR.
1.22 + # Do the print stuff by hand:
1.23 + echo "CT_TOP_DIR not set. You must set CT_TOP_DIR to the top directory where crosstool is installed."
1.24 + exit 1
1.25 +fi
1.26 +
1.27 +# Parse the common functions
1.28 +. "${CT_TOP_DIR}/scripts/functions"
1.29 +
1.30 +CT_STAR_DATE=`CT_DoDate +%s%N`
1.31 +CT_STAR_DATE_HUMAN=`CT_DoDate +%Y%m%d.%H%M%S`
1.32 +
1.33 +# Log to a temporary file until we have built our environment
1.34 +CT_ACTUAL_LOG_FILE="`pwd`/$$.log"
1.35 +
1.36 +# CT_TOP_DIR should be an absolute path.
1.37 +CT_TOP_DIR="`CT_MakeAbsolutePath \"${CT_TOP_DIR}\"`"
1.38 +
1.39 +# Parse the configuration file
1.40 +CT_TestOrAbort "Configuration file not found. Please create one." -f "${CT_TOP_DIR}/.config"
1.41 +. "${CT_TOP_DIR}/.config"
1.42 +
1.43 +# The progress bar indicator is asked for
1.44 +if [ "${CT_LOG_PROGRESS_BAR}" = "y" ]; then
1.45 + _CT_PROG_BAR() {
1.46 + [ $((cpt/5)) -eq 0 ] && echo -en "/"
1.47 + [ $((cpt/5)) -eq 1 ] && echo -en "-"
1.48 + [ $((cpt/5)) -eq 2 ] && echo -en "\\"
1.49 + [ $((cpt/5)) -eq 3 ] && echo -en "|"
1.50 + echo -en "\r"
1.51 + cpt=$(((cpt+1)%20))
1.52 + }
1.53 + CT_PROG_BAR=_CT_PROG_BAR
1.54 + export -f _CT_PROG_BAR
1.55 +else
1.56 + CT_PROG_BAR=
1.57 +fi
1.58 +
1.59 +# Apply the color scheme if needed
1.60 +if [ "${CT_LOG_USE_COLORS}" = "y" ]; then
1.61 + CT_ERROR_COLOR="${_A_NOR}${_A_BRI}${_F_RED}"
1.62 + CT_WARN_COLOR="${_A_NOR}${_A_BRI}${_F_YEL}"
1.63 + CT_INFO_COLOR="${_A_NOR}${_A_BRI}${_F_GRN}"
1.64 + CT_EXTRA_COLOR="${_A_NOR}${_A_DIM}${_F_GRN}"
1.65 + CT_DEBUG_COLOR="${_A_NOR}${_A_DIM}${_F_WHI}"
1.66 + CT_NORMAL_COLOR="${_A_NOR}"
1.67 +else
1.68 + CT_ERROR_COLOR=
1.69 + CT_WARN_COLOR=
1.70 + CT_INFO_COLOR=
1.71 + CT_EXTRA_COLOR=
1.72 + CT_DEBUG_COLOR=
1.73 + CT_NORMAL_COLOR=
1.74 +fi
1.75 +
1.76 +# Yes! We can do full logging from now on!
1.77 +CT_DoLog INFO "Build started ${CT_STAR_DATE_HUMAN}"
1.78 +
1.79 +# Some sanity checks in the environment and needed tools
1.80 +CT_DoLog INFO "Checking environment sanity"
1.81 +
1.82 +# Enable known ordering of files in directory listings:
1.83 +CT_Test "Crosstool-NG might not work as expected with LANG=\"${LANG}\"" -n "${LANG}"
1.84 +case "${LC_COLLATE},${LC_ALL}" in
1.85 + # These four combinations are known to sort files in the correct order:
1.86 + fr_FR*,) ;;
1.87 + en_US*,) ;;
1.88 + *,fr_FR*) ;;
1.89 + *,en_US*) ;;
1.90 + # Anything else is destined to be borked if not gracefuly handled:
1.91 + *) CT_DoLog WARN "Either LC_COLLATE=\"${LC_COLLATE}\" or LC_ALL=\"${LC_ALL}\" is not supported."
1.92 + export LC_ALL=`locale -a |egrep "^(fr_FR|en_US)" |head -n 1`
1.93 + CT_TestOrAbort "Neither en_US* nor fr_FR* locales found on your system." -n "${LC_ALL}"
1.94 + CT_DoLog WARN "Forcing to known working LC_ALL=\"${LC_ALL}\"."
1.95 + ;;
1.96 +esac
1.97 +
1.98 +# Other environment sanity checks
1.99 +CT_TestAndAbort "Don't set LD_LIBRARY_PATH. It screws up the build." -n "${LD_LIBRARY_PATH}"
1.100 +CT_TestAndAbort "Don't set CFLAGS. It screws up the build." -n "${CFLAGS}"
1.101 +CT_TestAndAbort "Don't set CXXFLAGS. It screws up the build." -n "${CXXFLAGS}"
1.102 +CT_Test "GREP_OPTIONS screws up the build. Resetting." -n "${GREP_OPTIONS}"
1.103 +GREP_OPTIONS=
1.104 +CT_HasOrAbort awk
1.105 +CT_HasOrAbort sed
1.106 +CT_HasOrAbort bison
1.107 +CT_HasOrAbort flex
1.108 +
1.109 +CT_DoStep DEBUG "Dumping crosstool-NG configuration"
1.110 +cat ${CT_TOP_DIR}/.config |egrep '^(# |)CT_' |CT_DoLog DEBUG
1.111 +CT_EndStep
1.112 +
1.113 +CT_DoLog INFO "Building environment variables"
1.114 +
1.115 +# This should go in buildToolchain.sh, but we might need it because it could
1.116 +# be used by the user in his/her paths definitions.
1.117 +# Target triplet: CT_TARGET needs a little love:
1.118 +case "${CT_ARCH_BE},${CT_ARCH_LE}" in
1.119 + y,) target_endian_eb=eb; target_endian_el=;;
1.120 + ,y) target_endian_eb=; target_endian_el=el;;
1.121 +esac
1.122 +case "${CT_ARCH}" in
1.123 + arm) CT_TARGET="${CT_ARCH}${target_endian_eb}";;
1.124 + mips) CT_TARGET="${CT_ARCH}${target_endian_el}";;
1.125 + x86*) # Much love for this one :-(
1.126 + # Ultimately, we should use config.sub to output the correct
1.127 + # procesor name. Work for later...
1.128 + arch="${CT_ARCH_ARCH}"
1.129 + [ -z "${arch}" ] && arch="${CT_ARCH_TUNE}"
1.130 + case "${CT_ARCH}" in
1.131 + x86_64) CT_TARGET=x86_64;;
1.132 + *) case "${arch}" in
1.133 + "") CT_TARGET=i386;;
1.134 + i386|i486|i586|i686) CT_TARGET="${arch}";;
1.135 + winchip*) CT_TARGET=i486;;
1.136 + pentium|pentium-mmx|c3*) CT_TARGET=i586;;
1.137 + nocona|athlon*64|k8|athlon-fx|opteron) CT_TARGET=x86_64;;
1.138 + pentiumpro|pentium*|athlon*) CT_TARGET=i686;;
1.139 + *) CT_TARGET=i586;;
1.140 + esac;;
1.141 + esac;;
1.142 +esac
1.143 +case "${CT_TARGET_VENDOR}" in
1.144 + "") CT_TARGET="${CT_TARGET}-unknown";;
1.145 + *) CT_TARGET="${CT_TARGET}-${CT_TARGET_VENDOR}";;
1.146 +esac
1.147 +case "${CT_KERNEL}" in
1.148 + linux*) CT_TARGET="${CT_TARGET}-linux";;
1.149 + cygwin*) CT_TARGET="${CT_TARGET}-cygwin";;
1.150 +esac
1.151 +case "${CT_LIBC}" in
1.152 + glibc) CT_TARGET="${CT_TARGET}-gnu";;
1.153 + uClibc) CT_TARGET="${CT_TARGET}-uclibc";;
1.154 +esac
1.155 +CT_TARGET="`${CT_TOP_DIR}/tools/config.sub ${CT_TARGET}`"
1.156 +
1.157 +# Now, build up the variables from the user-configured options.
1.158 +CT_KERNEL_FILE="${CT_KERNEL}-${CT_KERNEL_VERSION}"
1.159 +CT_BINUTILS_FILE="binutils-${CT_BINUTILS_VERSION}"
1.160 +if [ "${CT_CC_USE_CORE}" != "y" ]; then
1.161 + CT_CC_CORE="${CT_CC}"
1.162 + CT_CC_CORE_VERSION="${CT_CC_VERSION}"
1.163 + CT_CC_CORE_EXTRA_CONFIG="${CT_CC_EXTRA_CONFIG}"
1.164 +fi
1.165 +CT_CC_CORE_FILE="${CT_CC_CORE}-${CT_CC_CORE_VERSION}"
1.166 +CT_CC_FILE="${CT_CC}-${CT_CC_VERSION}"
1.167 +CT_LIBC_FILE="${CT_LIBC}-${CT_LIBC_VERSION}"
1.168 +[ "${CT_ARCH_FLOAT_SW_LIBFLOAT}" = "y" ] && CT_LIBFLOAT_FILE="libfloat-990616"
1.169 +
1.170 +# Kludge: If any of the configured options needs CT_TARGET or CT_TOP_DIR,
1.171 +# then rescan the options file now:
1.172 +. "${CT_TOP_DIR}/.config"
1.173 +
1.174 +# Determine build system if not set by the user
1.175 +CT_Test "You did not specify the build system. Guessing." -z "${CT_BUILD}"
1.176 +CT_BUILD="`${CT_TOP_DIR}/tools/config.sub \"${CT_BUILD:-\`${CT_TOP_DIR}/tools/config.guess\`}\"`"
1.177 +
1.178 +# Get rid of pre-existing installed toolchain and previous build directories.
1.179 +# We need to do that _before_ we can safely log, because the log file will
1.180 +# most probably be in the toolchain directory.
1.181 +if [ -d "${CT_PREFIX_DIR}" ]; then
1.182 + mv "${CT_PREFIX_DIR}" "${CT_PREFIX_DIR}.$$"
1.183 + nohup rm -rf "${CT_PREFIX_DIR}.$$" >/dev/null 2>&1 &
1.184 +fi
1.185 +mkdir -p "${CT_PREFIX_DIR}"
1.186 +if [ -d "${CT_BUILD_DIR}" ]; then
1.187 + mv "${CT_BUILD_DIR}" "${CT_BUILD_DIR}.$$"
1.188 + nohup rm -rf "${CT_BUILD_DIR}.$$" >/dev/null 2>&1 &
1.189 +fi
1.190 +mkdir -p "${CT_BUILD_DIR}"
1.191 +
1.192 +# Check now if we can write to the destination directory:
1.193 +if [ -d "${CT_PREFIX_DIR}" ]; then
1.194 + CT_TestAndAbort "Destination directory \"${CT_INSTALL_DIR}\" is not writeable" ! -w "${CT_PREFIX_DIR}"
1.195 +else
1.196 + mkdir -p "${CT_PREFIX_DIR}" || CT_Abort "Could not create destination directory \"${CT_PREFIX_DIR}\""
1.197 +fi
1.198 +
1.199 +# Redirect log to the actual log file now we can
1.200 +# It's quite understandable that the log file will be installed in the
1.201 +# install directory, so we must first ensure it exists and is writeable (above)
1.202 +# before we can log there
1.203 +t="${CT_ACTUAL_LOG_FILE}"
1.204 +case "${CT_LOG_TO_FILE},${CT_LOG_FILE}" in
1.205 + ,*) CT_ACTUAL_LOG_FILE=/dev/null
1.206 + rm -f "${t}"
1.207 + ;;
1.208 + y,/*) mkdir -p "`dirname \"${CT_LOG_FILE}\"`"
1.209 + CT_ACTUAL_LOG_FILE="${CT_LOG_FILE}"
1.210 + mv "${t}" "${CT_ACTUAL_LOG_FILE}"
1.211 + ;;
1.212 + y,*) mkdir -p "`pwd`/`dirname \"${CT_LOG_FILE}\"`"
1.213 + CT_ACTUAL_LOG_FILE="`pwd`/${CT_LOG_FILE}"
1.214 + mv "${t}" "${CT_ACTUAL_LOG_FILE}"
1.215 + ;;
1.216 +esac
1.217 +
1.218 +# Some more sanity checks now that we have all paths set up
1.219 +case "${CT_TARBALLS_DIR},${CT_SRC_DIR},${CT_BUILD_DIR},${CT_PREFIX_DIR},${CT_INSTALL_DIR}" in
1.220 + *" "*) CT_Abort "Don't use spaces in paths, it breaks things.";;
1.221 +esac
1.222 +
1.223 +# Note: we'll always install the core compiler in its own directory, so as to
1.224 +# not mix the two builds: core and final. Anyway, its generic, wether we use
1.225 +# a different compiler as core, or not.
1.226 +CT_CC_CORE_PREFIX_DIR="${CT_BUILD_DIR}/${CT_CC}-core"
1.227 +
1.228 +# Good, now grab a bit of informations on the system we're being run,
1.229 +# just in case something goes awok, and it's not our fault:
1.230 +CT_SYS_HOSTNAME=`hostname -f 2>/dev/null || true`
1.231 +# Hmmm. Some non-DHCP-enabled machines do not have an FQDN... Fall back to node name.
1.232 +CT_SYS_HOSTNAME="${CT_SYS_HOSTNAME:-`uname -n`}"
1.233 +CT_SYS_KERNEL=`uname -s`
1.234 +CT_SYS_REVISION=`uname -r`
1.235 +# MacOS X lacks '-o' :
1.236 +CT_SYS_OS=`uname -o || echo Unkown`
1.237 +CT_SYS_MACHINE=`uname -m`
1.238 +CT_SYS_PROCESSOR=`uname -p`
1.239 +CT_SYS_USER="`id -un`"
1.240 +CT_SYS_DATE=`CT_DoDate +%Y%m%d.%H%M%S`
1.241 +CT_SYS_GCC=`gcc -dumpversion`
1.242 +CT_TOOLCHAIN_ID="crosstool-${CT_VERSION} build ${CT_SYS_DATE} by ${CT_SYS_USER}@${CT_SYS_HOSTNAME} for ${CT_TARGET}"
1.243 +
1.244 +# renice oursleves
1.245 +renice ${CT_NICE} $$ |CT_DoLog DEBUG
1.246 +
1.247 +# Include sub-scripts instead of calling them: that way, we do not have to
1.248 +# export any variable, nor re-parse the configuration and functions files.
1.249 +. "${CT_TOP_DIR}/scripts/getExtractPatch.sh"
1.250 +. "${CT_TOP_DIR}/scripts/buildToolchain.sh"
1.251 +#. "${CT_TOP_DIR}/scripts/testToolchain.sh"
1.252 +
1.253 +if [ -n "${CT_TARGET_ALIAS}" ]; then
1.254 + CT_DoLog EXTRA "Creating symlinks from \"${CT_TARGET}-*\" to \"${CT_TARGET_ALIAS}-*\""
1.255 + CT_Pushd "${CT_PREFIX_DIR}/bin"
1.256 + for t in "${CT_TARGET}-"*; do
1.257 + _t="`echo \"$t\" |sed -r -e 's/^'\"${CT_TARGET}\"'-/'\"${CT_TARGET_ALIAS}\"'-/;'`"
1.258 + CT_DoLog DEBUG "Linking \"${_t}\" -> \"${t}\""
1.259 + ln -s "${t}" "${_t}"
1.260 + done
1.261 + CT_Popd
1.262 +fi
1.263 +
1.264 +CT_STOP_DATE=`CT_DoDate +%s%N`
1.265 +CT_STOP_DATE_HUMAN=`CT_DoDate +%Y%m%d.%H%M%S`
1.266 +CT_DoLog INFO "Build completed at ${CT_STOP_DATE_HUMAN}"
1.267 +elapsed=$((CT_STOP_DATE-CT_STAR_DATE))
1.268 +elapsed_min=$((elapsed/(60*1000*1000*1000)))
1.269 +elapsed_sec=`printf "%02d" $(((elapsed%(60*1000*1000*1000))/(1000*1000*1000)))`
1.270 +elapsed_csec=`printf "%02d" $(((elapsed%(1000*1000*1000))/(10*1000*1000)))`
1.271 +CT_DoLog INFO "(elapsed: ${elapsed_min}:${elapsed_sec}.${elapsed_csec})"
1.272 +
1.273 +# Restore a 'normal' color setting
1.274 +echo -en "${CT_NORMAL_COLOR}"
1.275 +
1.276 +trap - EXIT