⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crosstool-newlib.sh

📁 在linux下建立交叉编译环境的she
💻 SH
字号:
#!/bin/shabort() {    echo $@    exec /bin/false}## crosstool.sh# Build a GNU/Linux toolchain## Copyright (c) 2001 by Bill Gatliff, bgat@billgatliff.com # Copyright (c) 2003 by Dan Kegel, dkegel@ixiacom.com, Ixia Communications, # All rights reserved.  This script is provided under the terms of the GPL.# For questions, comments or improvements see the crossgcc mailing# list at http://sources.redhat.com/ml/crossgcc, or contact the# authors, but do your homework first.  As Bill says, "THINK!"# 17-Sep-03: Modified for Newlib by Nicolas Moreau ngbmoreau@yahoo.com.au## Meant to be invoked from another shell script.# Usage: seven environment variables must be set, namely:test -z "${PREFIX}"           && abort "Please set PREFIX to where you want the toolchain installed."test -z "${BINUTILS_DIR}"     && abort "Please set BINUTILS_DIR to the bare filename of the binutils tarball or directory"test -z "${GCC_DIR}"          && abort "Please set GCC_DIR to the bare filename of the gcc tarball or directory"test -z "${NEWLIB_DIR}"       && abort "Please set NEWLIB_DIR to the bare filename of the newlib tarball or directory"test -z "${TARGET}"           && abort "Please set TARGET to the Gnu target identifier (e.g. pentium-linux)"test -z "${TARGET_CFLAGS}"    && abort "Please set TARGET_CFLAGS to any compiler flags needed when building newlib (-O recommended)"# Four environment variables are optional, namely:test -z "${GCC_EXTRA_CONFIG}" && echo  "GCC_EXTRA_CONFIG not set, so not passing any extra options to gcc's configure script"set -ex# map TARGET to Linux equivalentcase $TARGET in    alpha*)   ARCH=alpha ;;    arm*)     ARCH=arm ;;    cris*)    ARCH=cris ;;    hppa*)    ARCH=parisc ;;    i*86*)    ARCH=i386 ;;    ia64*)    ARCH=ia64 ;;    mips*)    ARCH=mips ;;    m68k*)    ARCH=m68k ;;    powerpc*) ARCH=ppc ;;    ppc*)     abort "Target $TARGET incompatible with binutils and gcc regression tests; use target powerpc-* instead";;    s390*)    ARCH=s390 ;;    sh*)      ARCH=sh ;;    sparc64*) ARCH=sparc64 ;;    sparc*)   ARCH=sparc ;;    x86_64*)  ARCH=x86_64 ;;    *) abort "Bad target $TARGET"esac# Make all paths absolute (it's so confusing otherwise)PREFIX=`cd $PREFIX; pwd`BINUTILS_DIR=`cd $BINUTILS_DIR; pwd`GCC_DIR=`cd $GCC_DIR; pwd`NEWLIB_DIR=`cd $NEWLIB_DIR; pwd`# make sure the build product's binaries are in the search pathPATH="${PREFIX}/bin:${PATH}"export PATH# test that we have write permissions to the install dirmkdir -p ${PREFIX}/${TARGET}touch ${PREFIX}/${TARGET}/test-if-writetest -f ${PREFIX}/${TARGET}/test-if-write || abort "You don't appear to have write permissions to ${PREFIX}/${TARGET}."echoecho Building for:echo "    --target=$TARGET"echo "    --prefix=$PREFIX"# Set HOST to something almost, but not completely, identical to BUILD# This strange operation causes gcc to always generate a cross-compiler# even if the build machine is the same kind as the host.BUILD=`$GCC_DIR/config.guess`HOST=`echo $BUILD | sed s/-/-host_/`#---------------------------------------------------------echo Build binutilsmkdir -p build-binutils; cd build-binutilsif test '!' -f Makefile; then    ${BINUTILS_DIR}/configure --target=$TARGET --prefix=$PREFIX --with-gnu-as --with-gnu-ldfimake all make install cd ..# test to see if this step passedtest -x ${PREFIX}/bin/${TARGET}-ld || abort Build failed during binutils #---------------------------------------------------------echo "Build gcc-core (just enough to build newlib)"mkdir -p build-gcc-core; cd build-gcc-coreif test '!' -f Makefile; then    ${GCC_DIR}/configure --target=$TARGET --host=$HOST --prefix=$PREFIX \	--with-local-prefix=${PREFIX}/${TARGET} \	--disable-multilib \	--with-newlib \        ${GCC_EXTRA_CONFIG} \        --without-headers \	--disable-nls \	--enable-threads=no \	--enable-symvers=gnu \        --enable-languages=c \	--disable-shared \	--with-gnu-as \	--with-gnu-ldfimake all-gcc install-gcc cd ..test -x ${PREFIX}/bin/${TARGET}-gcc || abort Build failed during gcc-core #---------------------------------------------------------echo Build Newlibmkdir -p build-newlib; cd build-newlibif test '!' -f Makefile; then        ${NEWLIB_DIR}/configure --target=$TARGET --prefix=$PREFIX --with-gnu-as --with-gnu-ldfimakemake install cd ..test -f ${PREFIX}/${TARGET}/lib/libc.a || abort Building libc failed#---------------------------------------------------------echo Build final gccmkdir -p build-gcc; cd build-gccif test '!' -f Makefile; then    # --enable-symvers=gnu really only needed for sh4 to work around a detection problem    # only matters for gcc-3.2.x and later, I think    # --disable-nls to work around crash bug on ppc405, but also because embedded    # systems don't really need message catalogs...    # Use --with-headers, else it will define disable_glibc while building libgcc, and you'll have no profiling    ${GCC_DIR}/configure --target=$TARGET --host=$HOST --prefix=$PREFIX \        ${GCC_EXTRA_CONFIG} \        --with-headers=${PREFIX}/${TARGET}/include \	--disable-nls \	--enable-symvers=gnu \        --enable-languages=c,c++ \	--disable-shared \	--enable-c99 \        --enable-long-long \        --with-gnu-as \        --with-gnu-ld        fimake all make install esaccd ..cd ..test -x ${PREFIX}/bin/${TARGET}-gcc || Build failed during final gcc #---------------------------------------------------------echo Cross-toolchain build complete.exit 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -