具體實驗步驟:
(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表示不重新解壓安裝包,目的是讓安裝過程繼續進行,而不覆蓋掉以前的編譯結果。