具体实验步骤:
(1)如果你当前用户是超级用户(root)则请登录成普通用户(在我们的试验中用farsight用户)
(2)创建工作目录并拷贝相关的软件包
$mkdir /home/farsight/downloads
把需要用的工具包拷贝到downloads目录中。用到的工具包如下(gcc-3.4.5-glibc-2.3.6.dat中有说明,如果您的linux环境可以上网,则后面用到的安装脚本会自动下载需要的数据包):
l gcc-3.4.5.tar.gz 在ftp://ftp.gnu.org/gnu/
l glibc-2.3.6.tar.gz 在ftp://ftp.gnu.org/gnu/
l linux-2.6.14.tar.gz 在ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.14.tar.gz
l crosstool-0.43.tar.gz 在http://www.kegel.com/crosstool/crosstool-0.43.tar.gz
l binutils-2.15.tar.gz 在ftp://ftp.gnu.org/gnu
l glibc-linuxthreads-2.3.6.tar.gz 在ftp://ftp.gnu.org/gnu/
l linux-libc-headers-2.6.12.0.tar.bz2 在网上搜一下就行
l gdb-6.5.tar.bz2 ftp://ftp.gnu.org/gnu/
在/home/farsight/labs/1stDay/addlabs/cross_toolchains目录下有这些包,把他们拷贝到 /home/farsight/downloads:
$ cp /home/farsight/labs/1stDay/addlabs/cross_toolchains/*.tar.* /home/farsight/downloads
(3)解压软件包,并进入该目录,查看重要的脚本文件。
$ cd downloads
$ tar –zxvf crosstool-0.43.tar.gz
$ cd crosstool-0.43
在此目录下可以看到有很多.sh脚本和.dat配置文件,每一个支持的处理器都有它所相应的脚本。假如选用demo-arm-softfloat.sh 就是建立目标为支持软浮点的arm交叉编译工具链。
(4)$vim demo-arm-softfloat.sh
#!/bin/sh
# This script has one line for each known working toolchain
# for this architecture. Uncomment the one you want.
# Generated by generate-demo.pl from buildlogs/all.dats.txt
set -ex
TARBALLS_DIR=/home/farsight/downloads //表示下载的源码的存放目录
RESULT_TOP=/opt/crosstool //表示生成的工具链的存放目录
export TARBALLS_DIR RESULT_TOP
GCC_LANGUAGES="c,c++" //表示将要生成的工具链支持的语言
export GCC_LANGUAGES
# Really, you should do the mkdir before running this,
# and chown /opt/crosstool to yourself so you don't need to run as root.
mkdir -p $RESULT_TOP
#eval `cat arm-softfloat.dat gcc-2.95.3-glibc-2.1.3.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-2.95.3-glibc-2.2.2.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-2.95.3-glibc-2.2.5.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.2.3-glibc-2.2.5.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.2.3-glibc-2.3.2.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.2.3-glibc-2.3.2-tls.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.3.6-glibc-2.2.2.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.3.6-glibc-2.2.5.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.3.6-glibc-2.3.2.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.3.6-glibc-2.3.2-tls.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.4.5-glibc-2.2.5.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.4.5-glibc-2.3.5.dat` sh all.sh --notest
eval `cat arm-softfloat.dat gcc-3.4.5-glibc-2.3.6.dat` sh all.sh --notest --gdb //本实验中选择本行,并注意在后面添加--gdb 使得能生产调试工具
echo Done.
//上面表示你要选工具链的版本号!"#"起注释功能!可以选择一行!
把TARBALLS_DIR改为TARBALLS_DIR=/home/farsight/downloads
把RESULT_TOP改为RESULT_TOP=/home/farsight/crosstool
最终修改后的文件是这样的:
#!/bin/sh
# This script has one line for each known working toolchain
# for this architecture. Uncomment the one you want.
# Generated by generate-demo.pl from buildlogs/all.dats.txt
set -ex
TARBALLS_DIR=/home/farsight/downloads
RESULT_TOP=/opt/crosstool
export TARBALLS_DIR RESULT_TOP
GCC_LANGUAGES="c,c++"
export GCC_LANGUAGES
# Really, you should do the mkdir before running this,
# and chown /opt/crosstool to yourself so you don't need to run as root.
mkdir -p $RESULT_TOP
#eval `cat arm-softfloat.dat gcc-2.95.3-glibc-2.1.3.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-2.95.3-glibc-2.2.2.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-2.95.3-glibc-2.2.5.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.2.3-glibc-2.2.5.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.2.3-glibc-2.3.2.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.2.3-glibc-2.3.2-tls.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.3.6-glibc-2.2.2.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.3.6-glibc-2.2.5.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.3.6-glibc-2.3.2.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.3.6-glibc-2.3.2-tls.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.4.5-glibc-2.2.5.dat` sh all.sh --notest
#eval `cat arm-softfloat.dat gcc-3.4.5-glibc-2.3.5.dat` sh all.sh --notest
eval `cat arm-softfloat.dat gcc-3.4.5-glibc-2.3.6.dat` sh all.sh --notest --gdb
echo Done.
另外, 由于我们要在/opt下面最后安装工具链,需要先让farsight具有/opt的可写权限,简单处理一下:
$ chmod 777 /opt
demo-arm-softfloat.sh这个脚本在执行的时候,是执行的eval `cat arm-softfloat.dat gcc-3.4.5-glibc-2.3.6.dat` sh all.sh –notest这个批处理文件。打开这个文件
(5)$ vim gcc-3.4.5-glibc-2.3.6.dat
BINUTILS_DIR=binutils-2.15
GCC_DIR=gcc-3.4.5
GLIBC_DIR=glibc-2.3.6
LINUX_DIR=linux-2.6.8
LINUX_SANITIZED_HEADER_DIR=linux-libc-headers-2.6.12.0
GLIBCTHREADS_FILENAME=glibc-linuxthreads-2.3.6
由于交叉编译器是编译2.6.14的内核,那么修改LINUX_DIR=linux-2.6.14
另外,我们需要增加GDB的调试功能,在LINUX_DIR这一行后面增加一行:
GDB_DIR=gdb-6.5
最终修改后是这样的:
BINUTILS_DIR=binutils-2.15
GCC_DIR=gcc-3.4.5
GLIBC_DIR=glibc-2.3.6
LINUX_DIR=linux-2.6.14
GDB_DIR=gdb-6.5
LINUX_SANITIZED_HEADER_DIR=linux-libc-headers-2.6.12.0
GLIBCTHREADS_FILENAME=glibc-linuxthreads-2.3.6
(6)vim arm-softfloat.dat
KERNELCONFIG=`pwd`/arm.config
TARGET=arm-softfloat-linux-gnu
TARGET_CFLAGS="-O"
GCC_EXTRA_CONFIG="--with-float=soft"
GLIBC_EXTRA_CONFIG="--without-fp"
将 TARGET修改arm-linux-gnu
最终修改后是这样的:
KERNELCONFIG=`pwd`/arm.config
TARGET=arm-linux-gnu
TARGET_CFLAGS="-O"
GCC_EXTRA_CONFIG="--with-float=soft"
GLIBC_EXTRA_CONFIG="--without-fp"
这个时候,就可以执行编译脚本了。
(7)$ ./ demo-arm-softfloat.sh
约1个多小时后,编译完毕。
注: 如果编译过程遇到问题,在改正问题前,请在eval `cat arm-softfloat.dat gcc-3.4.5-glibc-2.3.6.dat` sh all.sh --notest --gdb末尾处加--nounpack表示不重新解压安装包,目的是让安装过程继续进行,而不覆盖掉以前的编译结果。