交叉工具链制作至尊宝典

zz : http://blog.csdn.net/turui/article/details/6596093

zz : http://blog.csdn.net/turui/article/details/6620951

交叉工具链制作至尊宝典(一)


一些必须知道的基础知识

  • Debian 操作系统 以及 aptitude 命令
  • autoconf and automake
  • 什么是交叉编译,configure 的几个参数 build host target

    build:
    编译代码的机器,的CPU指令集

    host:
    编译生成的东西,的CPU指令集(目标板上的CPU的指令集)

    target:
    编译生成的东西,他编译生成的的东西,的指令集(所以此选项一般不用,大多只有在做交叉工具链时使用)

    0、以Expert mode 安装Debian

    不要升级,确保环境是一个纯净的环境

    1、声明环境变量 

    [sql]  view plain copy
    1. export IS_TARGET=arm-linux  
    2. export DIR_SRC=/root/cross_toolchains/src  
    3. export PREFIX=/opt/cross_toolchains/arm  
    4. export CONFIGURE_BASE="../configure --prefix=$PREFIX --with-sysroot=$PREFIX"  

    2、下载制作交叉工具链所必须的的代码

    [plain]  view plain copy
    1. binutils  
    2. ftp://ftp.gnu.org/gnu/binutils/binutils-2.21.tar.gz  
    [plain]  view plain copy
    1. gcc  
    2. ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.2.tar.gz  
    3. ftp://ftp.gnu.org/gnu/mpfr/mpfr-3.0.1.tar.gz  
    4. http://www.multiprecision.org/mpc/download/mpc-0.9.tar.gz  
    5. ftp://ftp.gnu.org/gnu/gcc/gcc-4.6.1/gcc-4.6.1.tar.gz  
    [plain]  view plain copy
    1. glibc  
    2. ftp://ftp.gnu.org/gnu/glibc/glibc-2.14.tar.gz  
    3. ftp://ftp.gnu.org/gnu/glibc/glibc-ports-2.13.tar.gz  
    [plain]  view plain copy
    1. linux kernel  
    2. http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.2.tar.bz2  

    3、安装(卸载)必要的的软件包

    [plain]  view plain copy
    1. aptitude install build-essential automake bison flex texinfo gawk g\+\+  
    2. aptitude remove mawk  

    4、解压、归档软件包

    [plain]  view plain copy
    1. cd $DIR_SRC  
    2. tar -xf binutils-2.21.tar.gz  
    3. tar -xf gmp-5.0.2.tar.gz  
    4. tar -xf mpc-0.9.tar.gz  
    5. tar -xf mpfr-3.0.1.tar.gz  
    6. tar -xf gcc-4.6.1.tar.bz2  
    7. tar -xf glibc-2.14.tar.gz  
    8. tar -xf glibc-ports-2.13.tar.gz  
    9. tar -xf linux-2.6.39.2.tar.bz2  
    [plain]  view plain copy
    1. mv gmp-5.0.2 gcc-4.6.1/gmp  
    2. mv mpc-0.9 gcc-4.6.1/mpc  
    3. mv mpfr-3.0.1 gcc-4.6.1/mpfr  
    4. mv glibc-ports-2.13 glibc-2.14/ports  

    5、编译 BINUTILS

    [plain]  view plain copy
    1. cd $DIR_SRC  
    2. cd binutils-2.21  
    3. mkdir build  
    4. cd build  
    5. $CONFIGURE_BASE --target=$IS_TARGET --disable-nls --enable-shared --disable-multilib  
    [plain]  view plain copy
    1. make configure-host  
    2. make  
    3. make install  
    [plain]  view plain copy
    1. export PATH=$PATH:$PREFIX/bin  

    问题:
    编译binutils一般不会遇到什么问题,但是,如果前面步骤3中安装的软件不全会出现问题

    6、建立用于编译C库的GCC

    [plain]  view plain copy
    1. cd $DIR_SRC  
    2. cd gcc-4.6.1  
    3. mkdir build   
    4. cd build  
    5. $CONFIGURE_BASE \  
    6. --target=$IS_TARGET \  
    7. --disable-nls \  
    8. --disable-shared \  
    9. --without-headers \  
    10. --with-newlib \  
    11. --enable-languages=c \  
    12. --disable-threads \  
    13. --disable-multilib \  
    14. --disable-decimal-float \  
    15. --disable-libgomp \  
    16. --disable-libmudflap \  
    17. --disable-libssp  
    [plain]  view plain copy
    1. make all-gcc all-target-libgcc  
    2. make install-gcc install-target-libgcc  
    [plain]  view plain copy
    1. 值得注意的几个configure选项  
    2. --target  
    3. --disable-shared  
    4. --without-headers  
    5. --with-newlib  
    6. --enable-language-c  
    7. --disable-thread  
    [plain]  view plain copy
    1. cd $PREFIX/lib/gcc/$IS_TARGET/4.6.1  
    2. ln -s libgcc.a libgcc_eh.a  
    [plain]  view plain copy
    1. 有建议修改 gcc/config/t-linux 这个文件  
    2. 增加 -D__gthr_posix_h -Dinhibit_libc 两个宏,但我这里没这样做,是因为:  
    3. 在configure后,编译使用的命令并不是 make 或者是 make all 而是 make all-gcc 和 make all-target-libgcc,所以很多问题不会出现  
    4. -with-newlib,这个选项不会迫使我们必须使用newlib  
    [plain]  view plain copy
    1. libgcc.mvars: No such file or directory  
    2. 不能在 GCC 的源代码目录进行configure,必须在另外的目录进行configure make 等工作  
    3. 所以这里在代码所在目录下 mkdir build 并 cd build 再进行 ../configure 等工作  
    [plain]  view plain copy
    1. configure: error: C compiler cannot create executables  
    2. 如果使用 make 或 make all 会出现这样的问题,因为我们还未编译出目标指令集的 C 库  
    3. 所以只能先使用 make all-gcc make all-target-libgcc  
    [plain]  view plain copy
    1. ../../../../arm-linux/bin/ld: cannot find -lgcc  
    2. ../../../../arm-linux/bin/ld: cannot find -lgcc_eh  
    3. 很多资料都只写了 make all-gcc 而没有写 make all-target-libgcc 这样只建立了gcc,没有建立libgcc.a会出现以上第一个错误  
    4. 如果没手工建立链接文件 libgcc_eh.a 则会出现第二个错误  

    7、配置内核生成必要的头文件

    [plain]  view plain copy
    1. cd $DIR_SRC  
    2. cd linux-2.6.39.2  
    3. make ARCH=arm CROSS_COMPILE=$IS_TARGET- menuconfig  
    4. make ARCH=arm CROSS_COMPILE=$IS_TARGET-  
    [plain]  view plain copy
    1. mkdir -p $PREFIX/include  
    2. cd $PREFIX/include  
    3. ln -s $DIR_SRC/linux-2.6.39.2/arch/arm/include/asm asm  
    4. ln -s $DIR_SRC/linux-2.6.39.2/include/linux linux  
    5. ln -s $DIR_SRC/linux-2.6.39.2/include/asm-generic asm-generic  
    [plain]  view plain copy
    1. 这里并没有将内核的头文件复制到交叉工具链的安装目录  
    2. 编译C库的时候,需要对应的CPU指令集的汇编代码所以做了链接处理  
    [plain]  view plain copy
    1. 编译内核在执行 make ARCH=arm CROSS_COMPILE=$IS_TARGET- 时如果出错,是没有关系的,这里只要生成了对应的 version.h autoconf.h就可以了  

    8、编译C库

    [plain]  view plain copy
    1. cd $DIR_SRC  
    2. cd glibc-2.9  
    3. mkdir build  
    4. cd build  
    [plain]  view plain copy
    1. vi ../configure  
    2. vi ../ports/sysdeps/unix/sysv/linux/arm/sigrestorer.S  
    3. vi ../sysdeps/unix/syscall-template.S   
    4. vi ../nptl/allocatestack.c   
    5. vi ../elf/dl-tls.c  
    6. vi ../sysdeps/ieee754/dbl-64/s_fma.c  
    7. vi ../sysdeps/ieee754/dbl-64/s_fmaf.c  
    8.   
    9. 具体的修改,我写在下面(觉得还是要说清楚为什么修改,所以就没用sed命令或是做一些patch文件了,请向下看)  
    [plain]  view plain copy
    1. CC=$IS_TARGET-gcc \  
    2. $CONFIGURE_BASE \  
    3. --host=$IS_TARGET \  
    4. -enable-add-ons \  
    5. --with-binutils=$PREFIX/bin \  
    6. --with-headers=$PREFIX/include \  
    7. libc_cv_forced_unwind=yes \  
    8. libc_cv_c_cleanup=yes  
    [plain]  view plain copy
    1. 值得注意的几个configure选项  
    2. --host  
    3. --with-headers  
    4. lib_cv_forced_unwind  
    5. lib_cv_c_cleanup  
    [plain]  view plain copy
    1. make  
    2. make install   
    [plain]  view plain copy
    1. 这里编译的时候并有选择TARGET为EABI,所以在制作交叉工具链时会有很多问题需要修改  
    [plain]  view plain copy
    1. *** These critical programs are missing or too old: as ld  
    2. *** Check the INSTALL file for required versions.  
    3. vi ../configure   
    4. 查找  "$AS --version" 将 2.1[3-9] 修改为 2.[1-2][0-9]  
    5. 查询  "$LD --version" 将 2.1[3-9] 修改为 2.[1-2][0-9]  
    [plain]  view plain copy
    1. Error: previous CFI entry not closed (missing .cfi_endproc)  
    2. vi ../ports/sysdeps/unix/sysv/linux/arm/sigrestorer.S  
    3. ENTRY(__default_sa_restorer) 下增加  
    4. END(__default_sa_restorer)  
    5. ENTRY(__default_rt_sa_restorer) 下增加  
    6. END(__default_rt_sa_restorer)  
    [plain]  view plain copy
    1. syscall-template.S:82: Error: CFI instruction used without previous .cfi_startproc  
    2. vi ../sysdeps/unix/syscall-template.S   
    3. 这个问题的修改我也不是十分确定,我是这样来思考的  
    4. 看到 syscall-template.S 中 有 #include <sysdep.h>  
    5. 去查看 ports/sysdeps/unix/sysv/linux/arm/sysdep.h  
    6. 看到如下代码  
    7. #ifdef __ASSEMBLER__  
    8. #undef  PSEUDO  
    9.   
    10. #define PSEUDO(name, syscall_name, args)                                      \  
    11.   .text;                                                                      \  
    12.   ENTRY (name);                                                               \  
    13.     DO_CALL (syscall_name, args);                                             \  
    14.     cmn r0, $4096;  
    15.   
    16. 猜测是__ASSEMBLER__宏未打开,以至于未能找到PSEUD0函数的声明,则将  
    17.   
    18. #define PSEUDO(name, syscall_name, args)                                      \  
    19.   .text;                                                                      \  
    20.   ENTRY (name);                                                               \  
    21.     DO_CALL (syscall_name, args);                                             \  
    22.     cmn r0, $4096;  
    23.   
    24. 这段代码 添加至 ../sysdeps/unix/syscall-template.S 中  
    [plain]  view plain copy
    1. LS_DTV_UNALLOCATED  undeclared (first use in this function)  
    2. vi ../nptl/allocatestack.c  
    3. vi ../elf/dl-tls.c   
    4. 这个错误会出现在编译以上两个文件的时候,这个宏的定义我grep了整个glibc的所有代码,没找到ARM相关的声明及定义,按照其他指令集的定义猜测着修改如下  
    5. 在以上两个C文件中增加相应的定义  
    6.   
    7. #define TLS_DTV_UNALLOCATED      ((void *) -1l)  
    [plain]  view plain copy
    1. E_TOWARDZERO undeclared (first use in this function)  
    2. E_INEXACT undeclared (first use in this function)  
    3. 以上两个错误会出现在以下两个文件的的编译过程中  
    4. vi ../sysdeps/ieee754/dbl-64/s_fma.c  
    5. vi ../sysdeps/ieee754/dbl-64/s_fmaf.c  
    6. 参考 ports/sysdeps/arm/eabi/bits/fenv.h中的定义  
    7. 在两个文件中添加  
    8. #define FE_TOWARDZERO 0xc00000  
    9. #define FE_INEXACT 16  
    [plain]  view plain copy
    1. mawk: scripts/gen-sorted.awk: line 19: regular expression compile failed   
    2. 所以要 aptitude install gawk 所以也顺带着 aptitude remove mawk  
    [plain]  view plain copy
    1. configure: error: forced unwind support is required   
    2. configure 中增加配置参数 libc_cv_forced_unwind=yes   
    [plain]  view plain copy
    1. error: the compiler must support C cleanup handlin  
    2. configure 中增加配置参数libc_cv_c_cleanup=yes   
    [plain]  view plain copy
    1. --enable-add-ons 为 C 库 增加 thread 支持,目前默认使用的是 nptl 所以这里没有去下载 glibc-threads 相关的代码  
    [plain]  view plain copy
    1. --with-headers 指定内核头文件所在的目录  

    9、编译完整的 gcc 工具链

    [plain]  view plain copy
    1. mkdir -p $PREFIX/usr  
    2. cd $PREFIX/usr  
    3. ln -s ../include include  
    [plain]  view plain copy
    1. cd $PREFIX  
    2. mkdir -p opt/cross_toolchains  
    3. cd opt/cross_toolchains/  
    4. ln -s ../../../arm arm  
    [plain]  view plain copy
    1. cd $DIR_SRC  
    2. cd gcc-4.6.1  
    3. cd build  
    4. make clean  
    5. make distclean  
    6. rm * -rf  
    [plain]  view plain copy
    1. $CONFIGURE_BASE \  
    2. --target=arm-linux \  
    3. --enable-languages=c,c++ \  
    4. --enable-shared \  
    5. --disable-nls \  
    6. --enable-c99 \  
    7. --enable-long-long \  
    8. --disable-multilib \  
    9. --enable-__cxa_atexit  
    [plain]  view plain copy
    1. 几个值得注意的configure 选项  
    2. --target  
    3. --enable-shared  
    [plain]  view plain copy
    1. make  
    2. make install  
    [plain]  view plain copy
    1. The directory that should contain system headers does not exist:  
    2. 这个问题我没具体的去跟踪了,从表面上看出来是一些路径上的问题,并且经过验证,这个问题是在configure时使用了--with-sysroot选项时产生的  
    3. 为了尝试不通过建立链接的方式去解决这个问题  
    4. 在指明了 --includedir --libdir --sysconfdir 等等一系列参数后编译,依然会出现此问题  
    5. 所以不再跟踪,暂且是当做GCC编译环境上的一个 BUG好了  
    [plain]  view plain copy
    1. /opt/cross_toolchains/arm/arm-linux/bin/ld: cannot find /opt/cross_toolchains/arm/lib/libc.so.6 inside /opt/cross_toolchains/arm  
    2. 这个问题更是有点神经病了,所以这里也不跟踪了,也是由于使用了 --with-sysroot选项产生的问题,建立了第二个链接文件  
    3. 目的是让 /opt/cross_toolchains/arm 这个被当做是根目录的目录里面能有一个跟 --prefix 指定的 /opt/cross_toolchains/arm 一样的目录结构(说起来真别扭)  
    参考资料
    https://www.ibm.com/developerworks/cn/linux/l-embcmpl/
    http://cross-lfs.org/view/clfs-embedded/arm/cross-tools/introduction.html
    http://www.linuxsir.org/bbs/showthread.php?t=267672(这个文章虽然有点老,也有点神,把一些能看懂的说的让人看不懂,那个图更是让人觉得,汗,但原理还是说的很清楚的,这里强调的--with-sysroot的3次出现的问题,还是值得仔细想想的,这也是我为什么将 --with-sysroot 选项 做到$CONFIGURE_BASE 这个环境变量中的原因)


    交叉工具链制作至尊宝典(二)

    本文在前章的基础上,继续深入研究,如何能正确的编译出交叉工具链

    关于 --with-sysroot 这个参数,真是一个让人觉得可恨的参数,这个参数会引起一系列的问题,前章中,不得已的在 /opt/cross_toolchains/arm 中建立了两个连接文件

    [plain]  view plain copy
    1. mkdir usr  
    2. cd usr  
    3. ln -s ../include include  

    [plain]  view plain copy
    1. mkdir -p opt/cross_toolchains  
    2. cd opt/cross_toolchains  
    3. ln -s ../../../arm arm  

    还记得这两段脚本吗?让我觉得极其不爽,不得已才用这种办法去解决遇到的问题,而这两个问题都是因为使用了 --with-sysroot 这个 configure 参数而导致的,关键是我不知道如何解决!!

    下面的脚本中我们将不再使用 --with-sysroot 这个configure 参数

    下面的脚本将编译 arm eabi 的交叉工具链

    值得注意的地方是,在编译完 glibc 后的一些处理

    [plain]  view plain copy
    1. cd $PREFIX/arm-none-linux-gnueabi  
    2. rm lib include -rf  
    3. ln -s ../lib lib  
    4. ln -s ../include include  
    上面这段会解决一些看起来很难理解的问题,但我觉得这样做是正确的,因为在最后编译gcc时,需要使用到binutil的一些工具,而binutils的命令安装在bin目录下

    与这个bin 同一层的 lib 和 include 目录并不存在,所以会引起编译gcc 中  pthread.h 头文件找不到,链接需要的 c 库 开工代码 ctri.o ctxxx几个 o文件找不到等问题

    通过这样处理,可以解决这个问题,并且避免了使用 --with-sysroot 这个恶心的参数(autoconf 做的不够好啊,要么就是 gcc 的 autoconf脚本没写好)

    比如这种问题:

    [plain]  view plain copy
    1. arm-none-linux-gnueabi/bin/ld: cannot find crti.o: No such file or directory  

    自动化脚本如下,使用方法:将脚本保存为 makecross.sh,并且设置权限 chmod a+x makecross.sh,然后执行脚本./makecross.sh,可以看到帮助

    后续我会补充上 targe的选择以及检测方法,cpu指令集的选择,uclibc 编译,等相关内容

    [plain]  view plain copy
    1. #!/bin/sh  
    2. # the newer four-part form:  
    3. #       CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM  
    4.   
    5.   
    6.   
    7. unset CPU  
    8. unset MFR  
    9. unset KERNEL  
    10. unset OS  
    11. unset VER_GCC  
    12. unset DIR_OPT  
    13. unset DIR_SRC  
    14. unset PREFIX  
    15. unset TARGET  
    16.   
    17. export CPU=arm  
    18. export MFR=none  
    19. export KERNEL=linux  
    20. #export OS=uclibceabi  
    21. export OS=gnueabi  
    22. export VER_GCC=4.6.1  
    23.   
    24. export DIR_OPT=/opt/cross_toolchains  
    25. export DIR_SRC=/root/cross_toolchains/src    
    26. export PREFIX=$DIR_OPT/$CPU/$VER_GCC  
    27. export CONFIGURE_BASE="../configure --prefix=$PREFIX"  
    28. export TARGET=$CPU-$MFR-$KERNEL-$OS  
    29. export PATH=$PATH:$PREFIX/bin  
    30.   
    31. function do_unzip_single()  
    32. {  
    33.     cd $DIR_SRC  
    34.     if [ "$1" = "binutils" ];then  
    35.         tar -xf binutils-2.21.tar.gz  
    36.     elif [ "$1" = "gcc" ];then  
    37.         tar -xf gcc-4.6.1.tar.gz  
    38.         tar -xf mpfr-3.0.1.tar.gz  
    39.         tar -xf mpc-0.9.tar.gz  
    40.         tar -xf gmp-5.0.2.tar.gz  
    41.           
    42.         mv gmp-5.0.2  gcc-4.6.1/gmp  
    43.         mv mpc-0.9    gcc-4.6.1/mpc  
    44.         mv mpfr-3.0.1 gcc-4.6.1/mpfr          
    45.     elif [ "$1" = "glibc" ];then  
    46.         tar -xf glibc-2.13.tar.gz  
    47.         tar -xf glibc-ports-2.13.tar.gz  
    48.   
    49.         mv glibc-ports-2.13 glibc-2.13/ports  
    50.     elif [ "$1" = "kernel" ];then  
    51.         tar -xf linux-2.6.39.2.tar.bz2        
    52.     fi  
    53. }  
    54.   
    55. function do_download_single_do()  
    56. {  
    57.     cd $DIR_SRC  
    58.     if [ ! -e $DIR_SRC/$1 ];then  
    59.          wget $2  
    60.     fi  
    61. }  
    62.   
    63. function do_download_single()  
    64. {  
    65.     FILE_NAME=""  
    66.     URL=""  
    67.     if [ "$1" = "binutils" ];then  
    68.         set FILE_NAME=binutils-2.21.tar.gz  
    69.         set URL=ftp://ftp.gnu.org/gnu/binutils/binutils-2.21.tar.gz  
    70.           
    71.         do_download_single_do $FILE_NAME $URL  
    72.     elif [ "$1" = "gcc" ];then  
    73.         set FILE_NAME=gcc-4.6.1.tar.gz  
    74.         set URL=ftp://ftp.gnu.org/gnu/gcc/gcc-4.6.1/gcc-4.6.1.tar.gz  
    75.         do_download_single_do $FILE_NAME $URL  
    76.           
    77.         set FILE_NAME=mpfr-3.0.1.tar.gz  
    78.         set URL=ftp://ftp.gnu.org/gnu/mpfr/mpfr-3.0.1.tar.gz  
    79.         do_download_single_do $FILE_NAME $URL  
    80.           
    81.         set FILE_NAME=mpc-0.9.tar.gz  
    82.         set URL=http://www.multiprecision.org/mpc/download/mpc-0.9.tar.gz  
    83.         do_download_single_do $FILE_NAME $URL  
    84.           
    85.         set FILE_NAME=gmp-5.0.2.tar.gz  
    86.         set URL=ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.2.tar.gz  
    87.         do_download_single_do $FILE_NAME $URL  
    88.     elif [ "$1" = "glibc" ];then  
    89.         set FILE_NAME=glibc-2.13.tar.gz  
    90.         set URL=ftp://ftp.gnu.org/gnu/glibc/glibc-2.13.tar.gz  
    91.         do_download_single_do $FILE_NAME $URL  
    92.           
    93.         set FILE_NAME=glibc-ports-2.13.tar.gz  
    94.         set URL=ftp://ftp.gnu.org/gnu/glibc/glibc-ports-2.13.tar.gz  
    95.         do_download_single_do $FILE_NAME $URL  
    96.     elif [ "$1" = "kernel" ];then  
    97.         set FILE_NAME=linux-2.6.39.2.tar.bz2  
    98.         set URL=http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.2.tar.bz2  
    99.         do_download_single_do $FILE_NAME $URL  
    100.     fi  
    101. }  
    102.   
    103. function do_remove_single()  
    104. {  
    105.     cd $DIR_SRC  
    106.     # only remove the directory,but not the zip file.  
    107.     if [ "$1" = "binutils" ];then  
    108.         rm -rf binutils-2.21  
    109.     elif [ "$1" = "gcc" ];then  
    110.         rm -rf gcc-4.6.1   
    111.         rm -rf mpfr-3.0.1  
    112.         rm -rf mpc-0.9  
    113.         rm -rf gmp-5.0.2          
    114.     elif [ "$1" = "glibc" ];then  
    115.         rm -rf glibc-2.13  
    116.         rm -rf glibc-ports-2.13  
    117.     elif [ "$1" = "kernel" ];then  
    118.         rm -rf linux-2.6.39.2  
    119.     fi  
    120. }  
    121.   
    122. function do_reconstruction_single()  
    123. {  
    124.     echo "reconstruction single package $1"  
    125.     cd $DIR_SRC  
    126.     do_remove_single $1;  
    127.     do_download_single $1  
    128.     do_unzip_single $1    
    129. }  
    130.   
    131. function do_reconstruction()  
    132. {  
    133.     cd $DIR_SRC   
    134.     if [ "$1" = "all" ]  
    135.     then  
    136.         do_reconstruction_single binutils  
    137.         do_reconstruction_single gcc  
    138.         do_reconstruction_single glibc        
    139.     else  
    140.         do_reconstruction_single $1       
    141.     fi    
    142. }  
    143.   
    144. function do_build_single_pre()  
    145. {  
    146.     if [ "$1" = "binutils" ];then  
    147.         cd binutils-2.21      
    148.     elif [ "$1" = "gcc_first" ];then  
    149.         # glibc need kernel's .h file  
    150.         mkdir -p $PREFIX/include  
    151.         cd $PREFIX/include  
    152.           
    153.         rm -f asm  
    154.         rm -f linux  
    155.         rm -f asm-generic     
    156.   
    157.         ln -s $DIR_SRC/linux-2.6.39.2/arch/arm/include/asm asm  
    158.         ln -s $DIR_SRC/linux-2.6.39.2/include/linux linux  
    159.         ln -s $DIR_SRC/linux-2.6.39.2/include/asm-generic asm-generic  
    160.           
    161.         cd $DIR_SRC  
    162.   
    163.         cd gcc-4.6.1      
    164.     elif [ "$1" = "glibc" ];then  
    165.         cd glibc-2.13     
    166.         echo "/* Value used for dtv entries for which the allocation is delayed.  */" >> ports/sysdeps/arm/dl-tls.h  
    167.         echo "#define TLS_DTV_UNALLOCATED     ((void *) -1l)"  >> ports/sysdeps/arm/dl-tls.h  
    168.     elif [ "$1" = "gcc" ];then  
    169.         cd gcc-4.6.1      
    170.     elif [ "$1" = "kernel" ];then  
    171.         cd linux-2.6.39.2     
    172.     fi  
    173.       
    174.     # create build directory  
    175.     rm -rf build  
    176.     mkdir -p build  
    177.       
    178.     if [ "$1" = "kernel" ];then  
    179.         rm -rf build      
    180.     fi  
    181. }  
    182.   
    183. function do_build_single_config  
    184. {  
    185.     # configure  
    186.     if [ "$1" = "binutils" ];then  
    187.         $CONFIGURE_BASE \  
    188.         --target=$TARGET \  
    189.         --enable-shared       
    190.     elif [ "$1" = "gcc_first" ];then  
    191.         $CONFIGURE_BASE \  
    192.         --target=$TARGET \  
    193.         --disable-shared \  
    194.         --without-headers \  
    195.         --with-newlib \  
    196.         --enable-languages=c \  
    197.         --disable-threads         
    198.     elif [ "$1" = "glibc" ];then  
    199.         CC=$PREFIX/bin/$TARGET-gcc \  
    200.         $CONFIGURE_BASE \  
    201.         --host=$TARGET \  
    202.         -enable-add-ons \  
    203.         --with-headers=$PREFIX/include \  
    204.         --with-binutils=$PREFIX/bin \  
    205.         libc_cv_forced_unwind=yes \  
    206.         libc_cv_c_cleanup=yes         
    207.     elif [ "$1" = "gcc" ];then  
    208.         $CONFIGURE_BASE \  
    209.         --target=$TARGET \  
    210.         --enable-shared \  
    211.         --enable-languages=c,c++ \  
    212.         --enable-c99 \  
    213.         --enable-long-long \  
    214.         --enable-__cxa_atexit  
    215.     elif [ "$1" = "kernel" ];then  
    216.         make menuconfig   
    217.     fi  
    218. }  
    219.   
    220. function do_build_single_make()  
    221. {  
    222.     # make and make install  
    223.     if [ "$1" = "gcc_first" ];then  
    224.         make -j4 all-gcc all-target-libgcc  
    225.         make -j4 install-gcc install-target-libgcc  
    226.         cd $PREFIX/lib/gcc/$TARGET/$VER_GCC  
    227.         rm libgcc_eh.a  
    228.         ln -s libgcc.a libgcc_eh.a  
    229.     elif [ "$1" = "glibc" ];then  
    230.         make -j4  
    231.         make -j4 install          
    232.         cd $PREFIX/arm-none-linux-gnueabi  
    233.         rm lib include -rf  
    234.         ln -s ../lib lib  
    235.         ln -s ../include include  
    236.     else  
    237.         make -j4  
    238.         make -j4 install  
    239.     fi  
    240. }  
    241.   
    242. function do_build_single()  
    243. {  
    244.     cd $DIR_SRC  
    245.     echo "build single package $1"  
    246.     if [ "$1" = "kernel" ];then  
    247.         do_build_single_pre $1  
    248.         do_build_single_config $1  
    249.     else  
    250.         do_build_single_pre $1  
    251.         cd build  
    252.         do_build_single_config $1  
    253.         do_build_single_make $1  
    254.     fi  
    255. }  
    256.   
    257. function do_build()  
    258. {  
    259.     if [ "$1" = "all" ]  
    260.     then  
    261.         do_build_single binutils  
    262.         do_build_single gcc_first  
    263.         do_build_single glibc     
    264.         do_build_single gcc  
    265.     else  
    266.         do_build_single $1  
    267.                   
    268.     fi  
    269. }  
    270.   
    271. function do_rebuild()  
    272. {  
    273.     rm -rf $PREFIX/*  
    274.     do_reconstruction $1  
    275.     do_build $1  
    276. }  
    277.   
    278. function do_help()  
    279. {  
    280.     echo "usage:"  
    281.     echo "  ./makecross reconstruction binutils"  
    282.     echo "  ./makecross reconstruction gcc"  
    283.     echo "  ./makecross reconstruction glibc"  
    284.     echo "  ./makecross reconstruction all"  
    285.     echo "  ./makecross build binutils"  
    286.     echo "  ./makecross build gcc_first"  
    287.     echo "  ./makecross build glibc"  
    288.     echo "  ./makecross build gcc"  
    289.     echo "  ./makecross build all"    
    290.     echo "  ./makecross rebuild all"  
    291. }  
    292.   
    293. # main entery  
    294.   
    295. # to install necessary package  
    296. # aptitude install build-essential automake bison flex texinfo gawk g\+\+ zip  
    297. # aptitude remove mawk  
    298.   
    299.   
    300. SOME=`aptitude show build-essential automake bison flex texinfo gawk g\+\+ zip|grep "State: not install"`   
    301. #echo $SOME  
    302. if [ ! "$SOME" = "" ];then  
    303.     echo "aptitude install"  
    304.     aptitude install build-essential automake bison flex texinfo gawk g\+\+ zip  
    305. fi  
    306.   
    307. SOME=`aptitude show mawk | grep "State: installed"`  
    308. if [ ! "$SOME" = "" ];then  
    309.     echo "aptitude remove mawk"  
    310.     aptitude remove mawk  
    311. fi  
    312.   
    313. # about kernel  
    314. # if there is no kernel headers,then rebuild kernel  
    315. # include/linux/version.h and include/generated/autoconf.h  
    316. if [ ! -e $DIR_SRC/linux-2.6.39.2/include/linux/version.h ];then  
    317.     #echo "version"  
    318.     if [ ! -e $DIR_SRC/linux-2.6.39.2/include/generated/autoconf.h ];then  
    319.           echo "reconstruction kernel"  
    320.           do_reconstruction_single $1  
    321.     fi  
    322. fi  
    323. echo "check and rebuild env done."  
    324.   
    325. # do command  
    326. if [ "$1" = "reconstruction" ];then  
    327.     do_reconstruction $2  
    328. elif [ "$1" = "build" ];then  
    329.     echo "build"  
    330.     do_build $2  
    331. elif [ "$1" = "rebuild" ];then  
    332.     do_rebuild $2  
    333. else  
    334.     do_help  
    335. fi  
    336.   
    337.    



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值