免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 870 | 回复: 0
打印 上一主题 下一主题

编译交叉工具链 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-09-06 20:18 |只看该作者 |倒序浏览

                                首先是安装linux-Headers包,这个是linux的头文件。
linux-headers-2.6.20.1-02252007
               
               
                cd ~/sources
tar xf linux-headers-2.6.20.1-02252007.tar.bz2
cd linux-headers-2.6.20.1
install -dv /tools/include
cp -av include/{asm-generic,asm-i386,asm-x86_64,linux} \
/tools/include/
cp -av include/asm-x86_64-biarch /tools/include/asm   
cd ~/sources
rm -rf linux-headers-2.6.20.1
file-4.21
cd ~/sources
tar xf file-4.21.tar.gz
cd file-4.21
./configure --prefix=/cross-tools
make
make install
cd ~/sources
rm -rf file-4.21
binutils-2.18
一组开发,包括连接器,汇编器等工具。
cd ~/sources
tar xf binutils-2.18.tar.bz2
cd binutils-2.18
patch -Np1 -i ../binutils-2.18-posix-1.patch
patch -Np1 -i ../binutils-2.18-genscripts_multilib-1.patch
mkdir -v ../binutils-build
cd ../binutils-build
AR=ar AS=as ../binutils-2.18/configure --prefix=/cross-tools \
   --host=${CLFS_HOST} --target=${CLFS_TARGET} --with-lib-path=/tools/lib \
   --disable-nls --enable-shared --enable-64-bit-bfd
make configure-host
make
make install
cp -v ../binutils-2.18/include/libiberty.h /tools/include
cd ~/sources
rm -rf binutils-2.18 binutils-2.18
gcc-4.2.1 static
大名鼎鼎GCC编译,个人认为是GNU最大的贡献之一,现在要编译的是GCC的静态版本。
cd ~/sources
tar xf gcc-4.2.1.tar.bz2
cd gcc-4.2.1
patch -Np1 -i ../gcc-4.2.1-specs-1.patch
patch -Np1 -i ../gcc-4.2.1-posix-1.patch
patch -Np1 -i ../gcc-4.2.1-cross_search_paths-1.patch
echo "
#undef STARTFILE_PREFIX_SPEC
#define STARTFILE_PREFIX_SPEC \"/tools/lib/\"" >> gcc/config/linux.h
cp -v gcc/Makefile.in{,.orig}
    sed -e "s@\(^CROSS_SYSTEM_HEADER_DIR =\).*@\1 /tools/include@g" \
    gcc/Makefile.in.orig > gcc/Makefile.in
mkdir -v../gcc-build
cd ../gcc-build
../gcc-4.2.1/configure --prefix=/cross-tools \
    --host=${CLFS_HOST} --target=${CLFS_TARGET} \
    --with-local-prefix=/tools --disable-nls --disable-shared \
    --disable-threads --enable-languages=c
make all-gcc
make install-gcc
cd ~/sources
rm -rf gcc-4.2.1 gcc-build
Glibc-2.6.1 32 Bit
编译glibc的32位版本,编译基间会有警告,不用但心,这是因为现在还没有msgfmt。
msgfmt是用来产生二进制的翻译文件用的。
cd ~/sources
tar xf glibc-2.6.1.tar.bz2
cd glibc-2.6.1
patch -Np1 -i ../glibc-2.6.1-libgcc_eh-1.patch
patch -Np1 -i ../glibc-2.6.1-localedef_segfault-1.patch
mkdir -v ../glibc-build
cd ../glibc-build
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" >> config.cache
BUILD_CC="gcc" CC="${CLFS_TARGET}-gcc ${BUILD32}" \
    AR="${CLFS_TARGET}-ar" RANLIB="${CLFS_TARGET}-ranlib" \
    CFLAGS="-march=$(cut -d- -f1     ../glibc-2.6.1/configure --prefix=/tools \
    --host=${CLFS_TARGET32} --build=${CLFS_HOST} \
    --disable-profile --enable-add-ons \
    --with-tls --enable-kernel=2.6.0 --with-__thread \
    --with-binutils=/cross-tools/bin --with-headers=/tools/include \
        --cache-file=config.cache
make
make install
cd ~/sources
rm -rf glibc-2.6.1 glibc-build
Glibc-2.6.1 64-Bit
编译glibc的64位版本,同上面一样会有警告,跳过就行了。
cd ~/sources
tar xf glibc-2.6.1.tar.bz2
cd glibc-2.6.1
patch -Np1 -i ../glibc-2.6.1-libgcc_eh-1.patch
patch -Np1 -i ../glibc-2.6.1-localedef_segfault-1.patch
mkdir -v ../glibc-build
cd ../glibc-build
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" >> config.cache
echo "slibdir=/tools/lib64" >> configparms
BUILD_CC="gcc" CC="${CLFS_TARGET}-gcc ${BUILD64}" \
    AR="${CLFS_TARGET}-ar" RANLIB="${CLFS_TARGET}-ranlib" \
     ../glibc-2.6.1/configure --prefix=/tools \
    --host=${CLFS_TARGET} --build=${CLFS_HOST}         --libdir=/tools/lib64 \
    --disable-profile --enable-add-ons \
    --with-tls --enable-kernel=2.6.0 --with-__thread \
    --with-binutils=/cross-tools/bin --with-headers=/tools/include \
    --cache-file=config.cache
make
make install
cd ~/sources
rm -rf glibc-2.6.1 glibc-build
Gcc-4.2.1 交叉编译
cd ~/sources
tar xf gcc-4.2.1.tar.bz2
cd gcc-4.2.1
patch -Np1 -i ../gcc-4.2.1-specs-1.patch
patch -Np1 -i ../gcc-4.2.1-posix-1.patch
patch -Np1 -i ../gcc-4.2.1-cross_search_paths-1.patch
echo "
#undef STARTFILE_PREFIX_SPEC
#define STARTFILE_PREFIX_SPEC \"/tools/lib/\"" >> gcc/config/linux.h
cp -v gcc/Makefile.in{,.orig}
    sed -e "s@\(^CROSS_SYSTEM_HEADER_DIR =\).*@\1 /tools/include@g" \
    gcc/Makefile.in.orig > gcc/Makefile.in
cp -v configure{,.orig}
    sed -e  '/FLAGS_FOR_TARGET.*\/lib\//s@-B[^ ]*/lib/@@g' configure.orig > configure
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-4.2.1/configure --prefix=/cross-tools \
    --target=${CLFS_TARGET} --host=${CLFS_HOST} \
    --with-local-prefix=/tools --disable-nls --enable-shared \
    --enable-languages=c,c++ --enable-__cxa_atexit \
    --enable-c99 --enable-long-long --enable-threads=posix
make AS_FOR_TARGET="${CLFS_TARGET}-as" \
    LD_FOR_TARGET="${CLFS_TARGET}-ld"
make install
rm -rf gcc-4.2.1 gcc-build
ok,到目前为止,交叉工具完成,下一步开始构建临时系统。
编译以上工具花了大概两个多小时,算起来还是很快的。
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/43917/showart_375769.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP