arm-gcc脚本

原文地址:http://www.douban.com/note/283668023/?type=like


 arm-gcc脚本

#!/usr/local/bin/bash

#-------------------------------------------------------------------------------------------------
#
# 2012-06-07 finnel work version
# binutils: ln-81 add check texinfo.x86_64 package
# ln-89 configure add --with-sysroot=$TARGET_PREFIX --with-lib-path=$TARGET_PREFIX/lib
# arm-linux-ld could find the lib file such as libpthread.so.0 when use -lpthread
#
# gcc second: ln-248 ../gcc-4.5.2/configure add --disable-libgomp --enable-threads=posix
# --enable-__cxa_atexit --enable-threads=posix --enable-c99 --enable-long-long
# --disable-multilib
#
#-------------------------------------------------------------------------------------------------

TARGET=arm-linux
PWDPATH=`pwd`
PREFIX=`pwd`/4.5.2
TARGET_PREFIX=$PREFIX/$TARGET
LC_ALL=POSIX
BUILD_PATH=`pwd`/build_gcc
DOWNLOAD=`pwd`/Downloads

#-------------------------------------------------------------------------------------------------
function init()
{
        echo $BUILD_PATH

        [ -d $PREFIX ] && rm -rf $PREFIX
        [ ! -d $DOWNLOAD ] && mkdir $DOWNLOAD

        #build path
        [ ! -d $BUILD_PATH ] && mkdir $BUILD_PATH
        cd $BUILD_PATH
        rm -rf *
}

#-------------------------------------------------------------------------------------------------
#download binutils, gcc , gmp, mpc, mpfr
function download()
{
        cd $DOWNLOAD

        [ ! -f binutils-2.20.1.tar.bz2 ] && wget -c http://ftp.gnu.org/gnu/binutils/binutils-2.20.1.tar.bz2

        [ ! -f gcc-4.5.2.tar.bz2 ] && wget -c http://ftp.gnu.org/gnu/gcc/gcc-4.5.2/gcc-4.5.2.tar.bz2
        [ ! -f gcc-4.5.2-specs-1.patch ] && wget http://ftp.lfs-matrix.net/pub/clfs/conglomeration/gcc/gcc-4.5.2-specs-1.patch
        [ ! -f gmp-5.0.1.tar.bz2 ] && wget -c http://ftp.gnu.org/gnu/gmp/gmp-5.0.1.tar.bz2
        [ ! -f mpfr-3.0.0.tar.bz2 ] && wget -c http://ftp.gnu.org/gnu/mpfr/mpfr-3.0.0.tar.bz2
        [ ! -f mpc-0.8.2.tar.gz ] && wget -c http://www.multiprecision.org/mpc/download/mpc-0.8.2.tar.gz

        #glibc
# wget http://tinderbox.jolexa.net/arm-linux_armv7/sys-kernel/linux-headers-2.6.30-r1.tbz2
        [ ! -f linux-libc-headers-2.6.12.0.tar.bz2 ] && wget http://ep09.pld-linux.org/~mmazur/linux-libc-headers/linux-libc-headers-2.6.12.0.tar.bz2
        [ ! -f glibc-2.11.2.tar.bz2 ] && wget http://ftp.gnu.org/gnu/glibc/glibc-2.11.2.tar.bz2
        [ ! -f glibc-ports-2.11.tar.bz2 ] && wget http://ftp.gnu.org/gnu/glibc/glibc-ports-2.11.tar.bz2

# [ ! -f patch-2.6.35.1.bz2 ] && wget http://www.kernel.org/pub/linux/kernel/v2.6/patch-2.6.35.1.bz2
        [ -f patch-2.6.35.1.bz2 ] && bunzip2 patch-2.6.35.1.bz2

        [ ! -f glibc-2.11.2-gcc_fix-1.patch ] && wget http://www.linuxfromscratch.org/patches/downloads/glibc/glibc-2.11.2-gcc_fix-1.patch
#wget http://www.linuxfromscratch.org/patches/downloads/glibc/glibc-2.11.2-makefile_fix-1.patch

        #gdb
        [ ! -f gdb-7.0a.tar.bz2 ] && { wget http://ftp.gnu.org/gnu/gdb/gdb-7.0a.tar.bz2 || echo "gdb download faild"; exit; }
        [ ! -f termcap-1.3.1.tar.gz ] && wget http://ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gz
}
#Download over
#-------------------------------------------------------------------------------------------------

#build binutils
function build_binutils()
{
        cd $BUILD_PATH

        for dir in `ls -p | grep / | grep binutils`
        do
                rm -rf $dir
        done

# 2012-05-31 add check texinfo.x86_64 package
# [ `rpm -q texinfo` ] || { echo; echo "You MUST install texinfo.x86_64 package"; echo; exit; }
# [ `pkg_info | grep texinfo` ] || { echo; echo "You MUST install texinfo.x86_64 package"; echo; exit; }

        tar xvf $DOWNLOAD/binutils-2.20.1.tar.bz2

        mkdir build-binutils
        cd build-binutils

# 2011-02-10: add --with-sysroot=$TARGET_PREFIX --with-lib-path=$TARGET_PREFIX/lib
        [ $1 -eq 1 ] && ../binutils-2.20.1/configure --target=$TARGET --prefix=$PREFIX --disable-nls --disable-werror || ../binutils-2.20.1/configure --target=$TARGET --prefix=$PREFIX --with-sysroot=$TARGET_PREFIX --with-lib-path=$TARGET_PREFIX/lib --disable-nls --disable-multilib --enable-shared

# --disable-nls tells binutils not to include native language support.
# --with-sysroot=$TARGET_PREFIX : tell arm-linux-ld search lib path otherwise can not find lib file
# --with-lib-path=$TARGET_PREFIX/lib : same as up, but none not effect.

        make -j2 || exit
        make install

        cd -
}
#build binutils over
#-------------------------------------------------------------------------------------------------

#build gcc first
function build_gcc()
{
        cd $BUILD_PATH

        for dir in `ls -p | grep / | grep gcc`
        do
                rm -rf $dir
        done

        tar xvf $DOWNLOAD/gcc-4.5.2.tar.bz2

        cd gcc-4.5.2
        tar xvf $DOWNLOAD/gmp-5.0.1.tar.bz2
        mv gmp-5.0.1 gmp
        tar xvf $DOWNLOAD/mpfr-3.0.0.tar.bz2
        mv mpfr-3.0.0 mpfr
        tar xvf $DOWNLOAD/mpc-0.8.2.tar.gz
        mv mpc-0.8.2 mpc

        patch -Np1 -i $DOWNLOAD/gcc-4.5.2-specs-1.patch

        mkdir ../build-gcc
        cd ../build-gcc

        ../gcc-4.5.2/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c,c++ --with-gmp-include=$(pwd)/gmp --with-gmp-lib=$(pwd)/gmp/.libs --without-headers --disable-threads --disable-decimal-float --enable-bootstrap --disable-werror

        make -j2 all-gcc
        make -j2 install-gcc
        make -j2 all-target-libgcc
        make -j2 install-target-libgcc

        #ln -vs libgcc.a `$PREFIX/bin/arm-linux-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/'`
        cd ..
        echo gcc 1st done
}
#build gcc first over
#-------------------------------------------------------------------------------------------------

#-------------------------------------------------------------------------------------------------
#build glibc
function build_glibc()
{
        cd $BUILD_PATH

        for dir in `ls -p | grep / | grep linux-`
        do
                rm -rf $dir
        done

        for dir in `ls -p | grep / | grep glibc`
        do
                rm -rf $dir
        done

        [ -d $TARGET_PREFIX/include ] && rm -rf $TARGET_PREFIX/include
        mkdir $TARGET_PREFIX/include

        tar xvf $DOWNLOAD/linux-libc-headers-2.6.12.0.tar.bz2
        cd linux-libc-headers-2.6.12.0
        cp -rf include/linux $TARGET_PREFIX/include/
        cp -rf include/asm-arm $TARGET_PREFIX/include/asm
        cp -rf include/asm-generic $TARGET_PREFIX/include/

        cd -

        tar xvf $DOWNLOAD/glibc-2.11.2.tar.bz2
        cd glibc-2.11.2

        patch -Np1 -i $DOWNLOAD/glibc-2.11.2-gcc_fix-1.patch
        tar xvf $DOWNLOAD/glibc-ports-2.11.tar.bz2

        cd -

        mkdir build-glibc
        cd build-glibc

        export PATH=/sbin:/bin:/usr/bin:/usr/sbin:$PREFIX/bin

# BUILD_CC=gcc CC=arm-linux-gcc AR=arm-linux-ar AS=arm-linux-as LD=arm-linux-ld ../glibc-2.11.2/configure --host=arm-linux --prefix=$PREFIX --build=amd64-undermydesk-freebsd --without-cvs --disable-profile --without-gd --enable-add-ons libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes --disable-sanity-checks --enable-hacker-mode --with-headers=$BUILD_PATH/linux-libc-headers-2.6.12.0/include --disable-tls --without-gda libc_cv_gnu89_inline=yes
        ../glibc-2.11.2/configure --host=arm-linux --prefix=$PREFIX --build=amd64-undermydesk-freebsd --without-cvs --disable-profile --without-gd --enable-add-ons libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes --disable-sanity-checks --enable-hacker-mode --with-headers=$BUILD_PATH/linux-libc-headers-2.6.12.0/include --disable-tls --without-gda libc_cv_gnu89_inline=yes

        gmake -j2 || { echo "error build glibc"; exit; }
        gmake install_root=$TARGET_PREFIX prefix="" install

        cd $PWDPATH
        sed '/^GROUP/s/\/lib\///g' $TARGET_PREFIX/lib/libc.so > libc.so
        cp libc.so $TARGET_PREFIX/lib
        rm -f libc.so

        #cp t-linux $BUILD_PATH/gcc-4.5.2/gcc/config/arm
        cd $BUILD_PATH
        echo glibc done
}
#build glibc over
#-------------------------------------------------------------------------------------------------


#build binutils second
function build_binutils_2()
{
        cd $BUILD_PATH

        for dir in `ls -p | grep / | grep binutils`
        do
                rm -rf $dir
        done

        tar xvf $DOWNLOAD/binutils-2.20.1.tar.bz2

        mkdir build-binutils
        cd build-binutils

# ../binutils-2.20.1/configure --target=$TARGET --prefix=$PREFIX --disable-nls --disable-werror
# 2011-02-10: add --with-sysroot=$TARGET_PREFIX --with-lib-path=$TARGET_PREFIX/lib
        ../binutils-2.20.1/configure --target=$TARGET --prefix=$PREFIX --with-sysroot=$TARGET_PREFIX --with-lib-path=$TARGET_PREFIX/lib --disable-nls --disable-multilib --enable-shared

# --disable-nls tells binutils not to include native language support.
# --with-sysroot=$TARGET_PREFIX : tell arm-linux-ld search lib path otherwise can not find lib file
# --with-lib-path=$TARGET_PREFIX/lib : same as up, but none not effect.

        make -j2 || exit
        make install

        cd -
}
#build binutils over
#-------------------------------------------------------------------------------------------------

#-------------------------------------------------------------------------------------------------
#build gcc second
function build_gcc_second()
{
        cd $BUILD_PATH/gcc-4.5.2

        echo -en '#undef STANDARD_INCLUDE_DIR\n#define STANDARD_INCLUDE_DIR "$TARGET_PREFIX/include"\n\n' >> gcc/config/linux.h
        echo -en '\n#undef STANDARD_STARTFILE_PREFIX_1\n#define STANDARD_STARTFILE_PREFIX_1 "$TARGET_PREFIX/lib/"\n' >> gcc/config/linux.h
        echo -en '\n#undef STANDARD_STARTFILE_PREFIX_2\n#define STANDARD_STARTFILE_PREFIX_2 ""\n' >> gcc/config/linux.h
        
        cp -v gcc/Makefile.in{,.orig}
        sed -e "s@\(^CROSS_SYSTEM_HEADER_DIR =\).*@\1 $TARGET_PREFIX/include@g" gcc/Makefile.in.orig > gcc/Makefile.in
        
        cd $BUILD_PATH/build-gcc

# 2011-02-10 change to
        ../gcc-4.5.2/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c,c++ --enable-shared --with-gmp-include=$(pwd)/gmp --with-gmp-lib=$(pwd)/gmp/.libs --disable-libgomp --disable-multilib --enable-threads=posix --enable-__cxa_atexit --enable-threads=posix --enable-c99 --enable-long-long
        make -j2 AS_FOR_TARGET="${TARGET}-as" LD_FOR_TARGET="${TARGET}-ld" || { echo "error build gcc2"; exit; }
        make install

        cd $PWDPATH
        #rm -rf $BUILD_PATH
        echo gcc all Done
}
#build gcc second over
#-------------------------------------------------------------------------------------------------

#-------------------------------------------------------------------------------------------------
#build gdb
function build_gdb()
{
        cd $BUILD_PATH

        for dir in `ls -p | grep / | grep gdb`
        do
                rm -rf $dir
        done

        for dir in `ls -p | grep / | grep termcap`
        do
                rm -rf $dir
        done

        tar xvf $DOWNLOAD/termcap-1.3.1.tar.gz

        mkdir build-termcap
        cd build-termcap

        CC=arm-linux-gcc AR=arm-linux-ar AS=arm-linux-as LD=arm-linux-ld ../termcap-1.3.1/configure --prefix=$TARGET_PREFIX --host=arm-linux --target=arm-linux
        sed 's/oldincludedir = \/usr\/include/oldincludedir = $includedir/' Makefile > tmp
        mv tmp Makefile
        make -j2
        make install

        cd ..

        tar xvf $DOWNLOAD/gdb-7.0a.tar.bz2

        mkdir build-gdb
        cd build-gdb


# CC=arm-linux-gcc AR=arm-linux-ar AS=arm-linux-as LD=arm-linux-ld
        ../gdb-7.0/configure --prefix=$PREFIX --target=arm-linux --host=arm-linux

        sed '1i\\#define PATH_MAX 256' ../gdb-7.0/gdb/linux-thread-db.c > tmp
        mv tmp ../gdb-7.0/gdb/linux-thread-db.c
        sed '1i\\#define PATH_MAX 256' ../gdb-7.0/gdb/gdbserver/hostio.c > tmp
        mv tmp ../gdb-7.0/gdb/gdbserver/hostio.c

        make -j2 || exit
        make install || exit

        cd ..

        echo
        echo GDB done
        file $PREFIX/bin/gdbserver
}
#build gdb over
#-------------------------------------------------------------------------------------------------

#-------------------------------------------------------------------------------------------------
#build_cross
function build_cross()
{
        init
        download
        build_binutils 1
        build_gcc
        build_glibc
        build_binutils 2
        build_gcc_second
        build_gdb
}
#-------------------------------------------------------------------------------------------------

#-------------------------------------------------------------------------------------------------
#main
function main()
{
        startTM=`date`
        date_start=`date|awk -F"[ :]" '{print $4*3600 + $5*60 +$6}'`
        build_cross
        endTM=`date`
        date_end=`date|awk -F"[ :]" '{print $4*3600 + $5*60 +$6}'`
        buildTM=`expr "$date_end" - "$date_start"`

        echo -------------------------------------------------------------------------------------------------
        echo
        echo BUILD ALL DOWN Last change: 2012-05-31 08:00:23 binutils-2.20.1 gcc-4.5.2 glibc-2.11.2
        echo
        echo Start time : $startTM
        echo End time : $endTM
        echo Build time : $buildTM seconds

        echo crossTool : $PREFIX/bin
        echo 'BE SURE USE echo "$TARGET_PREFIX/lib" > /etc/ld.so.conf.d/arm-gcc.conf; then use /sbin/ldconfig'
        echo
        echo if change crosstool path, MUST do:
        echo "export LD_LIBRARY_PATH=$PREFIX/arm-linux/lib:$PREFIX/x86_64-unknown-linux-gnu/arm-linux/lib"
        echo
        echo -------------------------------------------------------------------------------------------------
}

#-------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------
#main shell program
main

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值