【bash】一个crosstool自动安装和编译脚本

在论坛发现了这个脚本,不知道是哪位大侠写的,仔细看了一遍,从头到尾没有任何复杂的语法,但是可以实现功能。我想这应该是我以后努力的方向。是为记!

 

#!/bin/bash



# author: zengqiu

# description: The script for building crosstool automatically

# usage: chmod +x crosstool-4.8.0.sh && ./crosstool-4.8.0.sh



function set_sys

{

    apt-get update && apt-get install build-essential libncurses5-dev gawk libmpfr-dev -y

}



function set_env

{

    export PRJROOT=/opt/arm

    export TARGET=arm-unknown-linux-gnueabi

    export PREFIX=${PRJROOT}/tools

    export BUILD=${PRJROOT}/build-tools

    export TARGET_PREFIX=${PREFIX}/${TARGET}

    export PATH=${PREFIX}/bin:${PATH}

}



function create_dir

{

    if [ -d ${PRJROOT} ]; then

        DATE=`date +%y%m%d`

        mv ${PRJROOT} ${PRJROOT}_${DATE}

    fi



    mkdir -p ${PRJROOT}

    mkdir -p ${PRJROOT}/build-tools ${PRJROOT}/tools ${PRJROOT}/kernel

    mkdir -p ${BUILD}/build-binutils ${BUILD}/build-boot-gcc ${BUILD}/build-gcc ${BUILD}/build-glibc ${BUILD}/build-glibc-headers

    mkdir -p ${TARGET_PREFIX}

}



function install_linux_headers

{

    cd ${PRJROOT}/kernel

    wget http://www.embeddedsystem.org/crosstool/4.8.0/linux-2.6.34.14.tar.bz2

    tar xvf linux-2.6.34.14.tar.bz2

    cd linux-2.6.34.14

    cp arch/arm/configs/s3c6400_defconfig ./.config

    make ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi- s3c6400_defconfig

    make ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi-

    mkdir -p ${TARGET_PREFIX}/include

    cp -r include/linux/ ${TARGET_PREFIX}/include

    cp -r include/asm-generic/ ${TARGET_PREFIX}/include

    cp -r arch/arm/include/asm/ ${TARGET_PREFIX}/include

}



function install_cross_binutils

{

    cd ${BUILD}

    wget http://www.embeddedsystem.org/crosstool/4.8.0/binutils-2.23.2.tar.bz2

    tar xvf binutils-2.23.2.tar.bz2

    cd build-binutils

    ../binutils-2.23.2/configure --target=${TARGET} --prefix=${PREFIX}

    make

    make install

}



function install_glibc_headers

{

    cd ${BUILD}

    wget http://www.embeddedsystem.org/crosstool/4.8.0/glibc-2.17.tar.bz2

    wget http://www.embeddedsystem.org/crosstool/4.8.0/glibc-ports-2.16.0.tar.bz2

    tar xvf glibc-2.17.tar.bz2

    tar xvf glibc-ports-2.16.0.tar.bz2

    mv glibc-ports-2.16.0 ./glibc-2.17/ports

    cd build-glibc-headers

    echo "libc_cv_forced_unwind=yes" > config.cache

    echo "libc_cv_c_cleanup=yes" >> config.cache

    echo "libc_cv_arm_tls=yes" >> config.cache

    ../glibc-2.17/configure --host=${TARGET} --prefix="/usr" --enable-add-ons --with-headers=${TARGET_PREFIX}/include --cache-file=config.cache

    make cross-compiling=yes install_root=${TARGET_PREFIX} prefix="" install-headers

}



function install_cross_gcc

{

    cd ${BUILD}

    wget http://www.embeddedsystem.org/crosstool/4.8.0/gcc-4.8.0.tar.bz2

    wget http://www.embeddedsystem.org/crosstool/4.8.0/gmp-5.1.1.tar.bz2

    wget http://www.embeddedsystem.org/crosstool/4.8.0/mpfr-3.1.2.tar.bz2

    wget http://www.embeddedsystem.org/crosstool/4.8.0/mpc-1.0.1.tar.gz

    tar xvf gcc-4.8.0.tar.bz2

    tar xvf gmp-5.1.1.tar.bz2

    tar xvf mpfr-3.1.2.tar.bz2

    tar xvf mpc-1.0.1.tar.gz

    mv gmp-5.1.1 ./gcc-4.8.0/gmp

    mv mpfr-3.1.2 ./gcc-4.8.0/mpfr

    mv mpc-1.0.1 ./gcc-4.8.0/mpc

    cd build-boot-gcc

    mkdir -p ${TARGET_PREFIX}/include/gnu

    touch ${TARGET_PREFIX}/include/gnu/stubs.h

    ../gcc-4.8.0/configure --target=${TARGET} --prefix=${PREFIX} --disable-shared --without-headers --with-newlib --enable-languages=c,c++

    make all-gcc all-target-libgcc

    make install-gcc install-target-libgcc

}



function install_glibc

{

    cd ${BUILD}/build-glibc

    echo "libc_cv_forced_unwind=yes" > config.cache

    echo "libc_cv_c_cleanup=yes" >> config.cache

    CC=${TARGET}-gcc ../glibc-2.17/configure --host=${TARGET} --prefix="/usr" --enable-add-ons --with-headers=${TARGET_PREFIX}/include --cache-file=config.cache

    ln -s ${PREFIX}/lib/gcc/arm-unknown-linux-gnueabi/4.8.0/libgcc.a ${PREFIX}/lib/gcc/arm-unknown-linux-gnueabi/4.8.0/libgcc_s.a

    ln -s ${PREFIX}/lib/gcc/arm-unknown-linux-gnueabi/4.8.0/libgcc.a ${PREFIX}/lib/gcc/arm-unknown-linux-gnueabi/4.8.0/libgcc_eh.a

    make

    make install_root=${TARGET_PREFIX} prefix="" install

}



function install_gcc

{

    cd ${BUILD}/build-gcc

    ../gcc-4.8.0/configure --target=${TARGET} --prefix=${PREFIX} --enable-shared --enable-__cxa_atexit --disable-nls --enable-c99 --enable-long-long --enable-threads=posix --enable-languages=c,c++

    sed -i 's/\/lib\///g' ${TARGET_PREFIX}/lib/libc.so

    sed -i 's/\/lib\///g' ${TARGET_PREFIX}/lib/libpthread.so

    make all

    make install

}



function test

{

    cd

    echo "#include <stdio.h>" >> helloworld.c

    echo "int main() {" >> helloworld.c

    echo "printf(\"Hello World!\\n\");" >> helloworld.c

    echo "return 0;}" >> helloworld.c

    arm-unknown-linux-gnueabi-gcc -o helloworld helloworld.c

    if [ -e helloworld ]; then

        echo "Build crosstool successed!"

    else

        echo "Build crosstool failed!"

    fi

}



set_sys

set_env

create_dir

install_linux_headers

install_cross_binutils

install_glibc_headers

install_cross_gcc

install_glibc

install_gcc

test

 

你可能感兴趣的:(bash)