- 论坛徽章:
- 0
|
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 |
|