免费注册 查看新帖 |

Chinaunix

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

使用GCC 4.2建立Linux交叉编译器工具链 [复制链接]

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

                                                                                                                                GCC 4.2的MAKEFILE里多了个with-sysroot参数,使得建立交叉编译工具链的难度大大降低.
本文使用linux-2.6.25, binutils-2.18, gcc-4.2.3, uclibc-0.9.29来建立交叉工具链.
为了方便起见,我把所有命令COPY下来组织了一下,写了个很粗糙的脚本.此脚本的使用方法是,把linux-2.6.25, binutils-2.18, gcc-4.2.3, uclibc-0.9.29这4个源码包解开,将解出的4个子目录与此脚本放在同一目录下,运行脚本即可.
此交叉编译器今后将被用来编译BUSYBOX等应用软件乃至构造基于INITRD的I386平台嵌入式LINUX操作系统.
整个脚本代码如下:
#!/bin/sh
INSTALL_PATH=/opt/cross-tools
TARGET=i686-pc-linux-uclibc
KERNEL_VER=2.6.25
UCLIBC_VER=0.9.29
BINUTILS_VER=2.18
GCC_VER=4.2.3
# kernel_headers
cd linux-${KERNEL_VER}
make include/linux/version.h
mkdir -p ${INSTALL_PATH}/usr/include
cp -a include/{asm-generic,linux,mtd,scsi,sound} ${INSTALL_PATH}/usr/include
cp -a include/asm-x86 ${INSTALL_PATH}/usr/include/asm
# uclibc_headers
cd ../uclibc-${UCLIBC_VER}
cp Makefile{,.orig}
sed -e 's/$(LN) -fs/cp/g' Makefile.orig > Makefile
for file in `find libc/sysdeps/linux -name Makefile`; do
    cp $file{,.orig}
    sed -e 's/$(LN) -fs/cp/g' -e 's@../libc/@$(TOPDIR)libc/@g' \
    $file.orig > $file
done
make defconfig ARCH=i386
cp .config{,.orig}
sed -e "/^KERNEL_HEADERS/s:=.*:=\"${INSTALL_PATH}/usr/include\":" \
    -e "/^SHARED_LIB_LOADER_PREFIX/s:=.*:=\"/lib\":" \
    -e "/^DEVEL_PREFIX/s:=.*:=\"/usr\":" \
    -e "/^RUNTIME_PREFIX/s:=.*:=\"/usr\":" \
    .config.orig > .config
UCLIBC_OPTIONS="DO_C99_MATH UCLIBC_HAS_RPC UCLIBC_HAS_CTYPE_CHECKED
    UCLIBC_HAS_WCHAR UCLIBC_HAS_HEXADECIMAL_FLOATS LDSO_PRELOAD_FILE_SUPPORT
    UCLIBC_HAS_FOPEN_EXCLUSIVE_MODE UCLIBC_HAS_PRINTF_M_SPEC UCLIBC_HAS_IPV6
    UCLIBC_HAS_GLIBC_CUSTOM_PRINTF UCLIBC_USE_NETLINK UCLIBC_HAS_FTW"
for config in $UCLIBC_OPTIONS; do
    cp .config{,.orig}
    sed -e "s:# ${config} is not set:${config}=y:" .config.orig > .config
done
UCLIBC_OPTIONS="UCLIBC_HAS_CTYPE_UNSAFE"
for config in $UCLIBC_OPTIONS; do
    cp .config{,.orig}
    sed -e "s:${config}=y:# ${config} is not set:" .config.orig > .config
done
echo "UCLIBC_HAS_FULL_RPC=y" >> .config
echo "UCLIBC_HAS_REENTRANT_RPC=y" >> .config
make oldconfig
make headers
mkdir -p ${INSTALL_PATH}/usr/include/bits
make PREFIX=${INSTALL_PATH} install_headers
# binutils
mkdir -p ../binutils-build
cd ../binutils-build
../binutils-${BINUTILS_VER}/configure --prefix=${INSTALL_PATH} \
    --target=${TARGET} --with-sysroot=${INSTALL_PATH} \
    --disable-multilib --disable-nls --enable-shared
make configure-host
make
make install
# gcc for compiling uclibc only.
mkdir -p ../gcc-build
cd ../gcc-build
../gcc-${GCC_VER}/configure --prefix=${INSTALL_PATH} \
    --target=${TARGET} --with-sysroot=${INSTALL_PATH} \
    --disable-multilib --disable-nls --disable-shared --enable-languages=c
make all-gcc
make install-gcc
# uclibc
cd ../uclibc-${UCLIBC_VER}
sed -e "/^CROSS_COMPILER_PREFIX/s:=.*:=\"${TARGET}-\":" \
    .config.orig > .config
make CC="${TARGET}-gcc -m32"
make PREFIX=${INSTALL_PATH} install
# gcc with full feature
cd ../gcc-build
../gcc-${GCC_VER}/configure --prefix=${INSTALL_PATH} \
    --target=${TARGET} --with-sysroot=${INSTALL_PATH} \
    --disable-multilib --disable-nls --enable-shared --enable-languages=c \
    --enable-__cxa_atexit --enable-c99 --enable-long-long --enable-threads=posix
make
make install
(全文完)
参考链接:
Cross-Compiled Linux From Scratch - Sysroot
http://cross-lfs.org/view/clfs-sysroot/x86/
Cross-Compiled Linux From Scratch - Embedded
http://cross-lfs.org/view/clfs-embedded/x86/
               
               
               
               
               
               
               
               
               
               

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

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP