一、准备工作
1、准备文件
binutils-2.22.tar.bz2
gcc-4.6.3.tar.bz2
glibc-2.14.1.tar.xz
glibc-ports-2.14.1.tar.gz
glibc-linuxthreads-2.5.tar.bz2
gdb-7.4.1.tar.bz2
linux-2.6.38.8.tar.bz2
mpfr-3.1.1.tar.bz2
mpc-1.0.1.tar.gz
gmp-5.1.0.tar.bz2
2、建立以下变量,方便稍候的输入
#vim ~/.bashrc
export TARGET=arm-linux-gnueabi
export PREFIX=/usr/local/arm-linux-gcc/4.6.3export TARGET_PREFIX=$PREFIX/$TARGETexport PATH=$PATH:$PREFIX/bin
3、为宿主机安装mpfr、mpc、gmp
#tar -xvf gmp-5.1.0.tar.bz2
#cd gmp-5.1.0
#mkdir build
#cd build
#../configure
#make all -j4
#make install
#tar -xvf mpfr-3.1.1.tar.bz2
# cd mpfr-3.1.1
#mkdir build#cd build
#../configure
#make all -j4
#make install
#tar -xvf mpc-1.0.1.tar.gz
#cd mpc-1.0.1
#mkdir build
#cd build
#../configure
#make all -j4
#make install
4、复制linux-kernel-headers
#tar -xvf linux-2.6.38.8.tar.bz2
#cd linux-2.6.38.8
#make include/linux/version.h
CHK include/linux/version.h UPD include/linux/version.h#mkdir -p $TARGET_PREFIX/include
#cp -r ./include/linux/ $TARGET_PREFIX/include
#cp -r ./include/asm-generic/ $TARGET_PREFIX/include
#cp -r ./arch/arm/include/asm/ $TARGET_PREFIX/include
二、编译binutils
#tar -xvf binutils-2.22.tar.bz2
#cd binutils-2.22
#mkdir build
#cd build
#../configure --prefix=$PREFIX --target=$TARGET
#make all -j4
#make install
三、初步编译gcc(不带glibc支持)
#tar -xvf gcc-4.6.3.tar.bz2
重新解压mpfr-3.1.1.tar.bz2、mpc-1.0.1.tar.gz、gmp-5.1.0.tar.bz2,并改名复制至gcc-4.6.3中
#rm -rf mpfr-3.1.1 mpc-1.0.1 gmp-5.1.0
#tar -xvf gmp-5.1.0.tar.bz2
#mv gmp-5.1.0 gmp
#mv ./gmp ./gcc-4.6.3
#tar -xvf mpfr-3.1.1.tar.bz2
#mv mpfr-3.1.1 mpfr
#mv ./mpfr ./gcc-4.6.3
#tar -xvf mpc-1.0.1.tar.gz
#mv mpc-1.0.1 mpc
#mv ./mpc ./gcc-4.6.3
#cd gcc-4.6.3
#mkdir build
#cd build
#../configure --prefix=$PREFIX --target=$TARGET --without-headers --enable-languages=c --disable-threads --with-newlib --disable-shared --disable-libmudflap --disable-libssp --disable-decimal-float
#make all-gcc -j4#make install-gcc
#make all-target-libgcc -j4
#make install-target-libgcc
四、编译glibc
#tar -xvf glibc-2.14.1.tar.xz
#tar -xvf glibc-ports-2.14.1.tar.gz
#mv glibc-ports-2.14.1 ports
#mv ./ports/ ./glibc-2.14.1#tar -xvf glibc-linuxthreads-2.5.tar.bz2 --directory=./glibc-2.14.1
# cd glibc-2.14.1
# mkdir build
# cd build
# CC=$TARGET-gcc
# ln -s /usr/local/arm-linux-gcc/4.6.3/lib/gcc/arm-linux-gnueabi/4.6.3/libgcc.a /usr/local/arm-linux-gcc/4.6.3/lib/gcc/arm-linux-gnueabi/4.6.3/libgcc_eh.a
创建config.cache配置文件
# vim config.cache
libc_cv_forced_unwind=yes
libc_cv_c_cleanup=yes
libc_cv_arm_tls=yes
# ../configure --host=$TARGET --target=$TARGET --prefix=$TARGET_PREFIX --enable-add-ons --disable-profile --cache-file=config.cache --with-binutils=$PREFIX/bin --with-headers=$TARGET_PREFIX/include
#make all -j4
#make install
五、重新编译gcc
# cd gcc-4.6.3/build/
# rm -rf *
# ../configure --prefix=$PREFIX --target=$TARGET --enable-shared --enable-languages=c,c++
# make all -j4
# make install
六、编译gdb
# tar -xvf gdb-7.4.1.tar.bz2
# ../configure --prefix=$PREFIX --target=$TARGET# make all -j4
# make install
七、创建链接
# cd $PREFIX/bin
# ln -s arm-linux-gnueabi-addr2line arm-linux-addr2line
# ln -s arm-linux-gnueabi-ar arm-linux-ar# ln -s arm-linux-gnueabi-as arm-linux-as# ln -s arm-linux-gnueabi-c++ arm-linux-c++# ln -s arm-linux-gnueabi-c++filt arm-linux-c++filt# ln -s arm-linux-gnueabi-cpp arm-linux-cpp# ln -s arm-linux-gnueabi-elfedit arm-linux-elfedit# ln -s arm-linux-gnueabi-g++ arm-linux-g++# ln -s arm-linux-gnueabi-gcc arm-linux-gcc# ln -s arm-linux-gnueabi-gcc-4.6.3 arm-linux-gcc-4.6.3# ln -s arm-linux-gnueabi-gcov arm-linux-gcov# ln -s arm-linux-gnueabi-gdb arm-linux-gdb# ln -s arm-linux-gnueabi-gdbtui arm-linux-gdbtui# ln -s arm-linux-gnueabi-gprof arm-linux-gprof# ln -s arm-linux-gnueabi-ld arm-linux-ld# ln -s arm-linux-gnueabi-ld.bfd arm-linux-ld.bfd# ln -s arm-linux-gnueabi-nm arm-linux-nm# ln -s arm-linux-gnueabi-objcopy arm-linux-objcopy# ln -s arm-linux-gnueabi-objdump arm-linux-objdump# ln -s arm-linux-gnueabi-ranlib arm-linux-ranlib# ln -s arm-linux-gnueabi-readelf arm-linux-readelf# ln -s arm-linux-gnueabi-run arm-linux-run# ln -s arm-linux-gnueabi-size arm-linux-size# ln -s arm-linux-gnueabi-strings arm-linux-strings# ln -s arm-linux-gnueabi-strip arm-linux-strip
完成