scripts/crosstool.sh
changeset 63 89b41dbffe8d
parent 46 1c22b060eb4d
child 64 7dab8d1a2426
     1.1 --- a/scripts/crosstool.sh	Mon Apr 23 20:27:40 2007 +0000
     1.2 +++ b/scripts/crosstool.sh	Mon May 07 09:04:02 2007 +0000
     1.3 @@ -28,7 +28,7 @@
     1.4  CT_STAR_DATE_HUMAN=`CT_DoDate +%Y%m%d.%H%M%S`
     1.5  
     1.6  # Log to a temporary file until we have built our environment
     1.7 -CT_ACTUAL_LOG_FILE="`pwd`/$$.log"
     1.8 +CT_ACTUAL_LOG_FILE="${CT_TOP_DIR}/$$.log"
     1.9  
    1.10  # CT_TOP_DIR should be an absolute path.
    1.11  CT_TOP_DIR="`CT_MakeAbsolutePath \"${CT_TOP_DIR}\"`"
    1.12 @@ -73,6 +73,9 @@
    1.13  # Yes! We can do full logging from now on!
    1.14  CT_DoLog INFO "Build started ${CT_STAR_DATE_HUMAN}"
    1.15  
    1.16 +# renice oursleves
    1.17 +renice ${CT_NICE} $$ |CT_DoLog DEBUG
    1.18 +
    1.19  # Some sanity checks in the environment and needed tools
    1.20  CT_DoLog INFO "Checking environment sanity"
    1.21  
    1.22 @@ -109,50 +112,8 @@
    1.23  
    1.24  CT_DoLog INFO "Building environment variables"
    1.25  
    1.26 -# This should go in buildToolchain.sh, but we might need it because it could
    1.27 -# be used by the user in his/her paths definitions.
    1.28  # Target triplet: CT_TARGET needs a little love:
    1.29 -case "${CT_ARCH_BE},${CT_ARCH_LE}" in
    1.30 -    y,) target_endian_eb=eb; target_endian_el=;;
    1.31 -    ,y) target_endian_eb=; target_endian_el=el;;
    1.32 -esac
    1.33 -case "${CT_ARCH}" in
    1.34 -    arm)  CT_TARGET="${CT_ARCH}${target_endian_eb}";;
    1.35 -    mips) CT_TARGET="${CT_ARCH}${target_endian_el}";;
    1.36 -    x86*) # Much love for this one :-(
    1.37 -          # Ultimately, we should use config.sub to output the correct
    1.38 -          # procesor name. Work for later...
    1.39 -          arch="${CT_ARCH_ARCH}"
    1.40 -          [ -z "${arch}" ] && arch="${CT_ARCH_TUNE}"
    1.41 -          case "${CT_ARCH}" in
    1.42 -              x86_64)      CT_TARGET=x86_64;;
    1.43 -          	  *)  case "${arch}" in
    1.44 -                      "")                                       CT_TARGET=i386;;
    1.45 -                      i386|i486|i586|i686)                      CT_TARGET="${arch}";;
    1.46 -                      winchip*)                                 CT_TARGET=i486;;
    1.47 -                      pentium|pentium-mmx|c3*)                  CT_TARGET=i586;;
    1.48 -                      nocona|athlon*64|k8|athlon-fx|opteron)    CT_TARGET=x86_64;;
    1.49 -                      pentiumpro|pentium*|athlon*)              CT_TARGET=i686;;
    1.50 -                      *)                                        CT_TARGET=i586;;
    1.51 -                  esac;;
    1.52 -          esac;;
    1.53 -esac
    1.54 -case "${CT_TARGET_VENDOR}" in
    1.55 -    "") CT_TARGET="${CT_TARGET}-unknown";;
    1.56 -    *)  CT_TARGET="${CT_TARGET}-${CT_TARGET_VENDOR}";;
    1.57 -esac
    1.58 -case "${CT_KERNEL}" in
    1.59 -    linux*)  CT_TARGET="${CT_TARGET}-linux";;
    1.60 -    cygwin*) CT_TARGET="${CT_TARGET}-cygwin";;
    1.61 -esac
    1.62 -case "${CT_LIBC}" in
    1.63 -    glibc)  CT_TARGET="${CT_TARGET}-gnu";;
    1.64 -    uClibc) CT_TARGET="${CT_TARGET}-uclibc";;
    1.65 -esac
    1.66 -case "${CT_ARCH_ABI}" in
    1.67 -    eabi)   CT_TARGET="${CT_TARGET}eabi";;
    1.68 -esac
    1.69 -CT_TARGET="`${CT_TOP_DIR}/tools/config.sub ${CT_TARGET}`"
    1.70 +CT_DoBuildTargetTriplet
    1.71  
    1.72  # Now, build up the variables from the user-configured options.
    1.73  CT_KERNEL_FILE="${CT_KERNEL}-${CT_KERNEL_VERSION}"
    1.74 @@ -171,50 +132,6 @@
    1.75  # then rescan the options file now:
    1.76  . "${CT_TOP_DIR}/.config"
    1.77  
    1.78 -# Determine build system if not set by the user
    1.79 -CT_Test "You did not specify the build system. Guessing." -z "${CT_BUILD}"
    1.80 -CT_BUILD="`${CT_TOP_DIR}/tools/config.sub \"${CT_BUILD:-\`${CT_TOP_DIR}/tools/config.guess\`}\"`"
    1.81 -
    1.82 -# Get rid of pre-existing installed toolchain and previous build directories.
    1.83 -# We need to do that _before_ we can safely log, because the log file will
    1.84 -# most probably be in the toolchain directory.
    1.85 -if [ -d "${CT_PREFIX_DIR}" ]; then
    1.86 -    mv "${CT_PREFIX_DIR}" "${CT_PREFIX_DIR}.$$"
    1.87 -    nohup rm -rf "${CT_PREFIX_DIR}.$$" >/dev/null 2>&1 &
    1.88 -fi
    1.89 -mkdir -p "${CT_PREFIX_DIR}"
    1.90 -if [ -d "${CT_BUILD_DIR}" ]; then
    1.91 -    mv "${CT_BUILD_DIR}" "${CT_BUILD_DIR}.$$"
    1.92 -    nohup rm -rf "${CT_BUILD_DIR}.$$" >/dev/null 2>&1 &
    1.93 -fi
    1.94 -mkdir -p "${CT_BUILD_DIR}"
    1.95 -
    1.96 -# Check now if we can write to the destination directory:
    1.97 -if [ -d "${CT_PREFIX_DIR}" ]; then
    1.98 -    CT_TestAndAbort "Destination directory \"${CT_INSTALL_DIR}\" is not writeable" ! -w "${CT_PREFIX_DIR}"
    1.99 -else
   1.100 -    mkdir -p "${CT_PREFIX_DIR}" || CT_Abort "Could not create destination directory \"${CT_PREFIX_DIR}\""
   1.101 -fi
   1.102 -
   1.103 -# Redirect log to the actual log file now we can
   1.104 -# It's quite understandable that the log file will be installed in the
   1.105 -# install directory, so we must first ensure it exists and is writeable (above)
   1.106 -# before we can log there
   1.107 -t="${CT_ACTUAL_LOG_FILE}"
   1.108 -case "${CT_LOG_TO_FILE},${CT_LOG_FILE}" in
   1.109 -    ,*)   CT_ACTUAL_LOG_FILE=/dev/null
   1.110 -          rm -f "${t}"
   1.111 -          ;;
   1.112 -    y,/*) mkdir -p "`dirname \"${CT_LOG_FILE}\"`"
   1.113 -          CT_ACTUAL_LOG_FILE="${CT_LOG_FILE}"
   1.114 -          mv "${t}" "${CT_ACTUAL_LOG_FILE}"
   1.115 -          ;;
   1.116 -    y,*)  mkdir -p "`pwd`/`dirname \"${CT_LOG_FILE}\"`"
   1.117 -          CT_ACTUAL_LOG_FILE="`pwd`/${CT_LOG_FILE}"
   1.118 -          mv "${t}" "${CT_ACTUAL_LOG_FILE}"
   1.119 -          ;;
   1.120 -esac
   1.121 -
   1.122  # Some more sanity checks now that we have all paths set up
   1.123  case "${CT_TARBALLS_DIR},${CT_SRC_DIR},${CT_BUILD_DIR},${CT_PREFIX_DIR},${CT_INSTALL_DIR}" in
   1.124      *" "*) CT_Abort "Don't use spaces in paths, it breaks things.";;
   1.125 @@ -233,7 +150,7 @@
   1.126  CT_SYS_KERNEL=`uname -s`
   1.127  CT_SYS_REVISION=`uname -r`
   1.128  # MacOS X lacks '-o' :
   1.129 -CT_SYS_OS=`uname -o || echo Unkown`
   1.130 +CT_SYS_OS=`uname -o || echo "Unknown (maybe MacOS-X)"`
   1.131  CT_SYS_MACHINE=`uname -m`
   1.132  CT_SYS_PROCESSOR=`uname -p`
   1.133  CT_SYS_USER="`id -un`"
   1.134 @@ -241,14 +158,212 @@
   1.135  CT_SYS_GCC=`gcc -dumpversion`
   1.136  CT_TOOLCHAIN_ID="crosstool-${CT_VERSION} build ${CT_SYS_DATE} by ${CT_SYS_USER}@${CT_SYS_HOSTNAME} for ${CT_TARGET}"
   1.137  
   1.138 -# renice oursleves
   1.139 -renice ${CT_NICE} $$ |CT_DoLog DEBUG
   1.140 +# Check now if we can write to the destination directory:
   1.141 +if [ -d "${CT_INSTALL_DIR}" ]; then
   1.142 +    CT_TestAndAbort "Destination directory \"${CT_INSTALL_DIR}\" is not removable" ! -w `dirname "${CT_INSTALL_DIR}"`
   1.143 +fi
   1.144 +
   1.145 +# Get rid of pre-existing installed toolchain and previous build directories.
   1.146 +# We need to do that _before_ we can safely log, because the log file will
   1.147 +# most probably be in the toolchain directory.
   1.148 +if [ -d "${CT_INSTALL_DIR}" ]; then
   1.149 +    mv "${CT_INSTALL_DIR}" "${CT_INSTALL_DIR}.$$"
   1.150 +    nohup rm -rf "${CT_INSTALL_DIR}.$$" >/dev/null 2>&1 &
   1.151 +fi
   1.152 +if [ -d "${CT_BUILD_DIR}" ]; then
   1.153 +    mv "${CT_BUILD_DIR}" "${CT_BUILD_DIR}.$$"
   1.154 +    nohup rm -rf "${CT_BUILD_DIR}.$$" >/dev/null 2>&1 &
   1.155 +fi
   1.156 +if [ "${CT_FORCE_EXTRACT}" = "y" -a -d "${CT_SRC_DIR}" ]; then
   1.157 +    mv "${CT_SRC_DIR}" "${CT_SRC_DIR}.$$"
   1.158 +    nohup rm -rf "${CT_SRC_DIR}.$$" >/dev/null 2>&1 &
   1.159 +fi
   1.160 +mkdir -p "${CT_INSTALL_DIR}"
   1.161 +mkdir -p "${CT_BUILD_DIR}"
   1.162 +mkdir -p "${CT_TARBALLS_DIR}"
   1.163 +mkdir -p "${CT_SRC_DIR}"
   1.164 +
   1.165 +# Make all path absolute, it so much easier!
   1.166 +# Now we have had the directories created, we even will get rid of embedded .. in paths:
   1.167 +CT_SRC_DIR="`CT_MakeAbsolutePath \"${CT_SRC_DIR}\"`"
   1.168 +CT_TARBALLS_DIR="`CT_MakeAbsolutePath \"${CT_TARBALLS_DIR}\"`"
   1.169 +
   1.170 +# Redirect log to the actual log file now we can
   1.171 +# It's quite understandable that the log file will be installed in the install
   1.172 +# directory, so we must first ensure it exists and is writeable (above) before
   1.173 +# we can log there
   1.174 +case "${CT_LOG_TO_FILE},${CT_LOG_FILE}" in
   1.175 +    ,*)   rm -f "${CT_ACTUAL_LOG_FILE}"
   1.176 +          CT_ACTUAL_LOG_FILE=/dev/null
   1.177 +          ;;
   1.178 +    y,/*) mkdir -p "`dirname \"${CT_LOG_FILE}\"`"
   1.179 +          mv "${CT_ACTUAL_LOG_FILE}" "${CT_LOG_FILE}"
   1.180 +          CT_ACTUAL_LOG_FILE="${CT_LOG_FILE}"
   1.181 +          ;;
   1.182 +    y,*)  mkdir -p "`pwd`/`dirname \"${CT_LOG_FILE}\"`"
   1.183 +          mv "${CT_ACTUAL_LOG_FILE}" "`pwd`/${CT_LOG_FILE}"
   1.184 +          CT_ACTUAL_LOG_FILE="`pwd`/${CT_LOG_FILE}"
   1.185 +          ;;
   1.186 +esac
   1.187 +
   1.188 +# Determine build system if not set by the user
   1.189 +CT_Test "You did not specify the build system. Guessing." -z "${CT_BUILD}"
   1.190 +CT_BUILD="`${CT_TOP_DIR}/tools/config.sub \"${CT_BUILD:-\`${CT_TOP_DIR}/tools/config.guess\`}\"`"
   1.191 +
   1.192 +# Arrange paths depending on wether we use sys-root or not.
   1.193 +if [ "${CT_USE_SYSROOT}" = "y" ]; then
   1.194 +    CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}/sys-root"
   1.195 +    CT_HEADERS_DIR="${CT_SYSROOT_DIR}/usr/include"
   1.196 +    BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   1.197 +    CC_CORE_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   1.198 +    CC_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   1.199 +    LIBC_SYSROOT_ARG=""
   1.200 +    # glibc's prefix must be exactly /usr, else --with-sysroot'd gcc will get
   1.201 +    # confused when $sysroot/usr/include is not present.
   1.202 +    # Note: --prefix=/usr is magic!
   1.203 +    # See http://www.gnu.org/software/libc/FAQ.html#s-2.2
   1.204 +else
   1.205 +    # plain old way. All libraries in prefix/target/lib
   1.206 +    CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}"
   1.207 +    CT_HEADERS_DIR="${CT_SYSROOT_DIR}/include"
   1.208 +    # hack!  Always use --with-sysroot for binutils.
   1.209 +    # binutils 2.14 and later obey it, older binutils ignore it.
   1.210 +    # Lets you build a working 32->64 bit cross gcc
   1.211 +    BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
   1.212 +    # Use --with-headers, else final gcc will define disable_glibc while
   1.213 +    # building libgcc, and you'll have no profiling
   1.214 +    CC_CORE_SYSROOT_ARG="--without-headers"
   1.215 +    CC_SYSROOT_ARG="--with-headers=${CT_HEADERS_DIR}"
   1.216 +    LIBC_SYSROOT_ARG="prefix="
   1.217 +fi
   1.218 +
   1.219 +# Prepare the 'lib' directories in sysroot, else the ../lib64 hack used by
   1.220 +# 32 -> 64 bit crosscompilers won't work, and build of final gcc will fail with
   1.221 +#  "ld: cannot open crti.o: No such file or directory"
   1.222 +mkdir -p "${CT_SYSROOT_DIR}/lib"
   1.223 +mkdir -p "${CT_SYSROOT_DIR}/usr/lib"
   1.224 +
   1.225 +# Canadian-cross are really picky on the way they are built. Tweak the values.
   1.226 +if [ "${CT_CANADIAN}" = "y" ]; then
   1.227 +    # Arrange so that gcc never, ever think that build system == host system
   1.228 +    CT_CANADIAN_OPT="--build=`echo \"${CT_BUILD}\" |sed -r -e 's/-/-build_/'`"
   1.229 +    # We shall have a compiler for this target!
   1.230 +    # Do test here...
   1.231 +else
   1.232 +    CT_HOST="${CT_BUILD}"
   1.233 +    CT_CANADIAN_OPT=
   1.234 +    # Add the target toolchain in the path so that we can build the C library
   1.235 +    export PATH="${CT_PREFIX_DIR}/bin:${CT_CC_CORE_PREFIX_DIR}/bin:${PATH}"
   1.236 +fi
   1.237 +
   1.238 +# Modify GCC_HOST to never be equal to $BUILD or $TARGET
   1.239 +# This strange operation causes gcc to always generate a cross-compiler
   1.240 +# even if the build machine is the same kind as the host.
   1.241 +# This is why CC has to be set when doing a canadian cross; you can't find a
   1.242 +# host compiler by appending -gcc to our whacky $GCC_HOST
   1.243 +# Kludge: it is reported that the above causes canadian crosses with cygwin
   1.244 +# hosts to fail, so avoid it just in that one case.  It would be cleaner to
   1.245 +# just move this into the non-canadian case above, but I'm afraid that might
   1.246 +# cause some configure script somewhere to decide that since build==host, they
   1.247 +# could run host binaries.
   1.248 +# (Copied almost as-is from original crosstool):
   1.249 +case "${CT_KERNEL},${CT_CANADIAN}" in
   1.250 +    cygwin,y) ;;
   1.251 +    *)        CT_HOST="`echo \"${CT_HOST}\" |sed -r -e 's/-/-host_/;'`";;
   1.252 +esac
   1.253 +
   1.254 +# Ah! Recent versions of binutils need some of the build and/or host system
   1.255 +# (read CT_BUILD and CT_HOST) tools to be accessible (ar is but an example).
   1.256 +# Do that:
   1.257 +CT_DoLog EXTRA "Making build system tools available"
   1.258 +mkdir -p "${CT_PREFIX_DIR}/bin"
   1.259 +for tool in ar; do
   1.260 +    ln -s "`which ${tool}`" "${CT_PREFIX_DIR}/bin/${CT_BUILD}-${tool}"
   1.261 +    ln -s "`which ${tool}`" "${CT_PREFIX_DIR}/bin/${CT_HOST}-${tool}"
   1.262 +done
   1.263 +
   1.264 +# Ha. cygwin host have an .exe suffix (extension) for executables.
   1.265 +[ "${CT_KERNEL}" = "cygwin" ] && EXEEXT=".exe" || EXEEXT=""
   1.266 +
   1.267 +# Transform the ARCH into a kernel-understandable ARCH
   1.268 +case "${CT_ARCH}" in
   1.269 +    x86) CT_KERNEL_ARCH=i386;;
   1.270 +    ppc) CT_KERNEL_ARCH=powerpc;;
   1.271 +    *)   CT_KERNEL_ARCH="${CT_ARCH}";;
   1.272 +esac
   1.273 +
   1.274 +# Build up the TARGET_CFLAGS from user-provided options
   1.275 +# Override with user-specified CFLAGS
   1.276 +[ -n "${CT_ARCH_CPU}" ]  && CT_TARGET_CFLAGS="-mcpu=${CT_ARCH_CPU} ${CT_TARGET_CFLAGS}"
   1.277 +[ -n "${CT_ARCH_TUNE}" ] && CT_TARGET_CFLAGS="-mtune=${CT_ARCH_TUNE} ${CT_TARGET_CFLAGS}"
   1.278 +[ -n "${CT_ARCH_ARCH}" ] && CT_TARGET_CFLAGS="-march=${CT_ARCH_ARCH} ${CT_TARGET_CFLAGS}"
   1.279 +[ -n "${CT_ARCH_FPU}" ]  && CT_TARGET_CFLAGS="-mfpu=${CT_ARCH_FPU} ${CT_TARGET_CFLAGS}"
   1.280 +
   1.281 +# Help gcc
   1.282 +CT_CFLAGS_FOR_HOST=
   1.283 +[ "${CT_USE_PIPES}" = "y" ] && CT_CFLAGS_FOR_HOST="${CT_CFLAGS_FOR_HOST} -pipe"
   1.284 +
   1.285 +# And help make go faster
   1.286 +PARALLELMFLAGS=
   1.287 +[ ${CT_PARALLEL_JOBS} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -j${CT_PARALLEL_JOBS}"
   1.288 +[ ${CT_LOAD} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -l${CT_LOAD}"
   1.289 +
   1.290 +CT_DoStep EXTRA "Dumping internal crosstool-NG configuration"
   1.291 +CT_DoLog EXTRA "Building a toolchain for:"
   1.292 +CT_DoLog EXTRA "  build  = ${CT_BUILD}"
   1.293 +CT_DoLog EXTRA "  host   = ${CT_HOST}"
   1.294 +CT_DoLog EXTRA "  target = ${CT_TARGET}"
   1.295 +set |egrep '^CT_.+=' |sort |CT_DoLog DEBUG
   1.296 +CT_EndStep
   1.297  
   1.298  # Include sub-scripts instead of calling them: that way, we do not have to
   1.299  # export any variable, nor re-parse the configuration and functions files.
   1.300 -. "${CT_TOP_DIR}/scripts/getExtractPatch.sh"
   1.301 -. "${CT_TOP_DIR}/scripts/buildToolchain.sh"
   1.302 -#. "${CT_TOP_DIR}/scripts/testToolchain.sh"
   1.303 +. "${CT_TOP_DIR}/scripts/build/kernel_${CT_KERNEL}.sh"
   1.304 +. "${CT_TOP_DIR}/scripts/build/binutils.sh"
   1.305 +. "${CT_TOP_DIR}/scripts/build/libc_libfloat.sh"
   1.306 +. "${CT_TOP_DIR}/scripts/build/libc_${CT_LIBC}.sh"
   1.307 +. "${CT_TOP_DIR}/scripts/build/cc_core_${CT_CC_CORE}.sh"
   1.308 +. "${CT_TOP_DIR}/scripts/build/cc_${CT_CC}.sh"
   1.309 +
   1.310 +# Now for the job by itself. Go have a coffee!
   1.311 +if [ "${CT_NO_DOWNLOAD}" != "y" ]; then
   1.312 +	CT_DoStep INFO "Retrieving needed toolchain components' tarballs"
   1.313 +    do_kernel_get
   1.314 +    do_binutils_get
   1.315 +    do_libc_get
   1.316 +    do_libfloat_get
   1.317 +    do_cc_core_get
   1.318 +    do_cc_get
   1.319 +    CT_EndStep
   1.320 +fi
   1.321 +
   1.322 +if [ "${CT_ONLY_DOWNLOAD}" != "y" ]; then
   1.323 +    if [ "${CT_FORCE_EXTRACT}" = "y" ]; then
   1.324 +        mv "${CT_SRC_DIR}" "${CT_SRC_DIR}.$$"
   1.325 +        nohup rm -rf "${CT_SRC_DIR}.$$" >/dev/null 2>&1
   1.326 +    fi
   1.327 +    CT_DoStep INFO "Extracting and patching toolchain components"
   1.328 +    do_kernel_extract
   1.329 +    do_binutils_extract
   1.330 +    do_libc_extract
   1.331 +    do_libfloat_extract
   1.332 +    do_cc_core_extract
   1.333 +    do_cc_extract
   1.334 +    CT_EndStep
   1.335 +
   1.336 +    if [ "${CT_ONLY_EXTRACT}" != "y" ]; then
   1.337 +        do_libc_check_config
   1.338 +        do_kernel_check_config
   1.339 +        do_kernel_headers
   1.340 +        do_binutils
   1.341 +        do_libc_headers
   1.342 +        do_cc_core
   1.343 +        do_libfloat
   1.344 +        do_libc
   1.345 +        do_cc
   1.346 +        do_libc_finish
   1.347 +    fi
   1.348 +fi
   1.349  
   1.350  if [ -n "${CT_TARGET_ALIAS}" ]; then
   1.351      CT_DoLog EXTRA "Creating symlinks from \"${CT_TARGET}-*\" to \"${CT_TARGET_ALIAS}-*\""