2013年04月15日

折腾了一个星期,过程整理下放上来,希望能有些帮助。本来这事关意义就在于享受麻烦的过程, 要不直接找个线程的下载下来不就行了。

环境:

Fedora18 gcc4.7.2 glibc2.17 binutils2.23 linux2.6.38

在fedora上先要安装几个包,还要删除一个:

yum erase audit

yum install gcc

yum install mpc

yum install mpfr-devel

yum install ncurses-devel

yum install autoconf

yum install textinfo

然后下载这几个源码包:

mpc-0.8.1.tar.gz

gcc-4.7.2.tar.bz2

glibc-2.17.tar.bz2

binutils-2.23.tar.gz

linux-2.6.38.tar.gz

Gcc貌似4.x的版本编译gcc需要用到mpc mpfr gmp这些。Fedora单单没有mpc-devel这个包,所以要头文件还是要自己编译。

$tar zxvf mpc-0.8.1.tar.gz

$cd mpc-0.8

$mkdir mpc_install

$cd mpc_install

$../configure –prefix=/usr –with-gmp=/usr –with-mpfr=/usr

$make

$make install

 

现在开始编译toolchain,先要创建几个编译时放生成文件的目录,还要设置些环境变量。

 

crosstoolchain4.7.2

crosstoolchain4.7.2/build-tools

crosstoolchain4.7.2/kernel

crosstoolchain4.7.2/tools

crosstoolchain4.7.2/build-tools/build-binutils

crosstoolchain4.7.2/build-tools/build-boot-gcc

crosstoolchain4.7.2/build-tools/build-gcc

crosstoolchain4.7.2/build-tools/bulid-glibc

 

[uty@localhost crosstoolchain4.7.2]$ export PROJECT=crosstoolchain4.7.2

[uty@localhost crosstoolchain4.7.2]$ export PRJROOT=/home/uty/workplace/$PROJECT

[uty@localhost crosstoolchain4.7.2]$ export TARGET=arm-none-linux-gnueabi

[uty@localhost crosstoolchain4.7.2]$ export PREFIX=${PRJROOT}/tools

[uty@localhost crosstoolchain4.7.2]$ export TARGET_PREFIX=${PREFIX}/${TARGET}

[uty@localhost crosstoolchain4.7.2]$ export PATH=${PREFIX}/bin:${PATH}

这些事情还是挺重要的,目录一定要放对,要不编译的时候经常找不到.h .o lib什么的

 

编译binutils

Copy binutils-2.23.tar.gz to built-tools directory

[uty@localhost build-tools]$ tar zxvf binutils-2.23.tar.gz

[uty@localhost build-tools]$ cd build-binutils

[uty@localhost build-binutils]$ ../binutils-2.23/configure –target=$TARGET –prefix=$PREFIX

[uty@localhost build-binutils]$ make

[uty@localhost build-binutils]$ make install

设置内核头文件

Copy linux-2.6.38.tar.gz to kernel direcotry.

[uty@localhost kernel]$ tar zxvf linux-2.6.38.tar.gz

[uty@localhost kernel]$ cd linux-2.6.38/

[uty@localhost linux-2.6.38]$ make ARCH=arm CROSS_COMPILE=arm-linux- menuconfig

Select Exit and say YES to generate kernel headers.

[uty@localhost linux-2.6.38]$ make include/linux/version.h

CHK include/linux/version.h

UPD include/linux/version.h

[uty@localhost linux-2.6.38]$ mkdir -p $TARGET_PREFIX/include

[uty@localhost linux-2.6.38]$ cp -r include/linux/ $TARGET_PREFIX/include

[uty@localhost linux-2.6.38]$ cp -r arch/arm/include/asm/ $TARGET_PREFIX/include/asm

[uty@localhost linux-2.6.38]$ cp -r include/asm-generic/ $TARGET_PREFIX/include

编译bootstrap gcc

Copy glibc-2.17.tar.bz2 to build-tools directory.

[uty@localhost build-tools]$ tar jxvf gcc-4.7.2.tar.bz2

[uty@localhost build-tools]$ cd build-boot-gcc/

[uty@localhost build-boot-gcc]$ ../gcc-4.7.2/configure –target=$TARGET –prefix=$PREFIX –without-headers –with-newlib –enable-languages=c,c++ –with-gmp=/usr –with-mpfr=/usr –with-mpc=/usr –disable-libmudflap –disable-libssp –disable-libstdcxx-pch –disable-nls –disable-shared –disable-threads –disable-libgomp –disable-decimal-float –disable-libffi

[uty@localhost build-boot-gcc]$ make all-gcc

[uty@localhost build-boot-gcc]$ make install-gcc

[uty@localhost build-boot-gcc]$ make all-target-libgcc

[uty@localhost build-boot-gcc]$ make install-target-libgcc

编译glibc

Copy glibc-2.17.tar.bz2 to build-tools directory.

[uty@localhost build-tools]$ tar jxvf glibc-2.17.tar.bz2

[uty@localhost build-tools]$ cd build-glibc

[uty@localhost build-glibc]$ CC=arm-none-linux-gnueabi-gcc ../glibc-2.17/configure –host=$TARGET –prefix=$TARGET_PREFIX –enable-add-ons –with-headers=$TARGET_PREFIX/include

[uty@localhost build-glibc]$ make

[uty@localhost build-glibc]$ make install

编译完整的gcc

[uty@localhost build-tools]$ cd build-gcc

[uty@localhost build-gcc]$ ../gcc-4.7.2/configure –target=$TARGET –prefix=$PREFIX –enable-languages=c,c++

[uty@localhost build-gcc]$ make

[uty@localhost build-gcc]$ make install

 

应该说只有指定的这几个版本的配置这样编译才能通过。。。。。