iibull 发表于 2008-5-15 13:04:50

binutils-2.17|gcc-4.1.1|glibc-2.5 作交叉编译器记录要点

author: iibull email: [email protected] nick: 阿牛@FUZHOU 20080515
如需转载请注明作者出处。

折腾了一天,终于把arm-linux-gcc4.11搞定了。记录如下,哈哈 免得大家走弯路。顺便预祝女儿周岁生日快乐。

首页要准备好编译用的软件包:      
软件包
wget -c http://ftp.gnu.org/gnu/binutils/binutils-2.17.tar.bz2
wget -c http://ftp.gnu.org/gnu/gcc/gcc-4.1.1/gcc-4.1.1.tar.bz2
wget -c http://ftp.gnu.org/gnu/glibc/glibc-2.5.tar.bz2
wget -c http://ftp.gnu.org/gnu/glibc/glibc-ports-2.5.tar.bz2
wget -c http://ftp.gnu.org/gnu/gdb/gdb-6.6.tar.bz2
wget -c http://www.kernel.org/pub/linux/kernel/v2.6/源码文件及各项补丁

patches
wget http://svn.cross-lfs.org/svn/repos/patches/glibc/glibc-2.5-alpha_ioperm_fix-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/glibc/glibc-2.5-branch_update-3.patch
wget http://svn.cross-lfs.org/svn/repos/patches/glibc/glibc-2.5-cross_hacks-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/glibc/glibc-2.5-cross_hacks-2.patch
wget http://svn.cross-lfs.org/svn/repos/patches/glibc/glibc-2.5-hppa_nptl-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/glibc/glibc-2.5-libgcc_eh-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/glibc/glibc-2.5-libgcc_eh-2.patch
wget http://svn.cross-lfs.org/svn/repos/patches/glibc/glibc-2.5-localedef_segfault-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/glibc/glibc-2.5-mawk_fix-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/glibc/glibc-2.5-mips_fixes-1.patch

wget http://svn.cross-lfs.org/svn/repos/patches/gcc/gcc-4.1.1-32-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/gcc/gcc-4.1.1-PR20425-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/gcc/gcc-4.1.1-PR29114-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/gcc/gcc-4.1.1-cross_search_paths-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/gcc/gcc-4.1.1-n32-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/gcc/gcc-4.1.1-posix-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/gcc/gcc-4.1.1-pure64-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/gcc/gcc-4.1.1-pure64_specs-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/gcc/gcc-4.1.1-sparc_tls-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/gcc/gcc-4.1.1-specs-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/gcc/gcc-4.1.1-specs_n32-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/gcc/gcc-4.1.1-uclibc-1.patch

wget http://svn.cross-lfs.org/svn/repos/patches/binutils/binutils-2.17-branch_update-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/binutils/binutils-2.17-branch_update-2.patch
wget http://svn.cross-lfs.org/svn/repos/patches/binutils/binutils-2.17-branch_update-3.patch
wget http://svn.cross-lfs.org/svn/repos/patches/binutils/binutils-2.17-genscripts_multilib-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/binutils/binutils-2.17-hppa_tls-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/binutils/binutils-2.17-posix-1.patch
wget http://svn.cross-lfs.org/svn/repos/patches/binutils/binutils-2.17-uclibc-1.patch


安装一些可能需要的软件包:
sudo apt-get install bison flex texinfo gawk

整个编译过程的工作目录:
sudo mkdir /crosstool
sudo chmod a+rwx /crosstool
cd /crosstool
mkdir linux-2.6.20
mkdir -p src/patches

linux-2.6.20存放要用到的内核头文件,patches存放需要的补丁,src存放要用到的软件包 PS:编译完成后的文件将安装到 ~/arm-linux上

设置一些环境变量 (~/.bashrc)
export CLFS_HOST="$(echo $MACHTYPE | sed "s/$(echo ${MACHTYPE} | cut -d- -f2)/cross/")"
export CLFS_TARGET="arm-linux"
export CLFS=/crosstool/arm-linux
export PATH=$CLFS/bin:$CLFS/cross-tools/bin:$PATH
unset CFLAGS
unset CXXFLAGS

source ~/.bashrc 使之生效

新建头文件存放地址
install -dv $CLFS/include
install -dv $CLFS/usr
install -dv $CLFS/usr/include

安装内核头文件:
新建保存头文件的目录,并生成linux/version.h文件指示内核版本,如果缺少这个文件后面编译会出错
install -dv ${CLFS}/usr/include
cd linux-2.6.20
make include/linux/version.h

复制必要的头文件和与体系结构(arm)相关的头文件
install -dv ${CLFS}/usr/include
cp -av include/{asm-generic,linux,mtd,scsi,sound} ${CLFS}/usr/include
cp -av include/asm-arm ${CLFS}/usr/include/asm



编译binutils-2.17:
#打上必要的补丁
cd src
tar jxvf binutils-2.17.tar.bz2
cd binutils-2.17
patch -Np1 -i ../patches/binutils-2.17-posix-1.patch (不要乱打补丁,否则make不成功)


创建编译目录:
mkdir -v ../binutils-build
cd ../binutils-build

配置configure:
../binutils-2.17/configure --prefix=${CLFS}/cross-tools --host=${CLFS_HOST} --target=${CLFS_TARGET} --with-sysroot=${CLFS} --disable-nls --enable-shared --disable-multilib

编译binutils:
make configure-host
make

安装binutils到 ${CLFS}/cross-tools:
make install

打开${CLFS}/cross-tools/bin,就会发现生成了好多arm-linux-开头的文件

以后会用到下面这个头文件,所以安装到include:
cp -v ../binutils-2.17/include/libiberty.h ${CLFS}/usr/include

安装 glibc的头文件到内核头文件中
编译glibc的时候需要glibc的头文件,所以要复制到内核头文件夹中
cd src
tar jxvf glibc-2.5.tar.bz2
cd glibc-2.5

去处glibc的gcc 3.4.x依赖
cp configure{,.orig}
sed -e 's/3.4/3./g' configure.orig > configure

安装glibc的arm支持:
tar -jxvf ../glibc-ports-2.5.tar.bz2
mv -v glibc-ports-2.5 ports

新建编译目录:
mkdir -v ../glibc-build_1
cd ../glibc-build_1

添加NPTL线程库支持:
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" >> config.cache
echo "libc_cv_arm_tls=yes" >> config.cache

指定安装路径:
echo "install_root=${CLFS}" > configparms

配置configure
CC=gcc
../glibc-2.5/configure --prefix=/usr --host=${CLFS_TARGET} --build=${CLFS_HOST} --with-headers=${CLFS}/usr/include --cache-file=config.cache

安装glibc头文件:
make install-headers ##(vi ../glibc-2.5/scripts/gen-sorted.awk出现错误时19/59/65行修改代码把 \[^\] 改成 \[\^]) 或者装gawk工具

cp -v bits/stdio_lim.h ${CLFS}/usr/include/bits
touch ${CLFS}/usr/include/gnu/stubs.h
cp -v ../glibc-2.5/ports/sysdeps/unix/sysv/linux/arm/nptl/bits/pthreadtypes.h ${CLFS}/usr/include/bits

[ 本帖最后由 iibull 于 2008-5-15 13:10 编辑 ]

iibull 发表于 2008-5-15 13:10:54

more ...

编译静态的gcc(不带glibc),用来编译glibc
cd src
tar jxvf gcc-4.1.1.tar.bz2
cd gcc-4.1.1

打上补丁:
patch -Np1 -i ../patches/gcc-4.1.1-posix-1.patch
patch -Np1 -i ../patches/gcc-4.1.1-cross_search_paths-1.patch

新建编译目录:
mkdir -v ../gcc-build
cd ../gcc-build

配置configure:
../gcc-4.1.1/configure --prefix=${CLFS}/cross-tools --host=${CLFS_HOST} --target=${CLFS_TARGET} --disable-multilib --with-sysroot=${CLFS} --disable-nls --disable-shared --enable-languages=c

编译安装gcc-static
make all-gcc
make install-gcc

编译安装glibc:

解压补丁并打上补丁:
cd src
mkdir glibc_2.5
tar jxvf glibc-2.5.tar.bz2 -C glibc_2.5
cd glibc_2.5; mv glibc-2.5/* ./; rm -rf glibc-2.5/

去处glibc的gcc 3.4.x依赖
cp configure{,.orig}
sed -e 's/3.4/3./g' configure.orig > configure

tar -jxvf ../glibc-ports-2.5.tar.bz2
mv -v glibc-ports-2.5 ports

patch -Np1 -i ../patches/glibc-2.5-libgcc_eh-2.patch
patch -Np1 -i ../patches/glibc-2.5-localedef_segfault-1.patch
patch -Np1 -i ../patches/glibc-2.5-cross_hacks-2.patch

新建编译目录:
mkdir -v ../glibc-build_2
cd ../glibc-build_2

编译并安装:
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" >> config.cache
echo "libc_cv_arm_tls=yes" >> config.cache
echo "install_root=${CLFS}" > configparms

BUILD_CC="gcc"
CC="${CLFS_TARGET}-gcc"
AR="${CLFS_TARGET}-ar"
RANLIB="${CLFS_TARGET}-ranlib"
../glibc_2.5/configure --prefix=/usr --libexecdir=/usr/lib/glibc --host=${CLFS_TARGET} --build=${CLFS_HOST} --disable-profile --enable-add-ons --with-tls --enable-kernel=2.6.0 --with-__thread --with-binutils=${CLFS}/cross-tools/bin --with-headers=${CLFS}/usr/include --cache-file=config.cache

安装glibc头文件:
make install-headers ##(用mawk时会发送错误,清修改vi ../glibc-2.5/scripts/gen-sorted.awk出现错误时19/59/65行修改代码把 \[^\] 改成 \[\^]) 或者装gawk工具

cp -v bits/stdio_lim.h ${CLFS}/usr/include/bits
touch ${CLFS}/usr/include/gnu/stubs.h
cp -v ../glibc_2.5/ports/sysdeps/unix/sysv/linux/arm/nptl/bits/pthreadtypes.h ${CLFS}/usr/include/bits

make
make install

配置glibc
cat > ${CLFS}/etc/nsswitch.conf << "EOF"
# Begin /etc/nsswitch.conf

passwd: files
group: files
shadow: files

hosts: files dns
networks: files

protocols: files
services: files
ethers: files
rpc: files

# End /etc/nsswitch.conf
EOF(ctrl +D)

配置glibc的动态装载:
cat > ${CLFS}/etc/ld.so.conf << "EOF"
# Begin /etc/ld.so.conf

/usr/local/lib
/opt/lib

# End /etc/ld.so.conf
EOF(ctrl +D)

完全安装gcc

打上个GCC的补丁:
cd ../gcc-4.1.1
patch -Np1 -i ../patches/gcc-4.1.1-posix-1.patch
patch -Np1 -i ../patches/gcc-4.1.1-PR20425-1.patch
patch -Np1 -i ../patches/gcc-4.1.1-cross_search_paths-1.patch

配置Configure:
cd ../gcc-build

../gcc-4.1.1/configure --prefix=${CLFS}/cross-tools --host=${CLFS_HOST} --target=${CLFS_TARGET} --disable-multilib --with-sysroot=${CLFS} --disable-nls --enable-shared --enable-languages=c,c++ --enable-__cxa_atexit --enable-c99 --enable-long-long --enable-threads=posix

编译安装gcc:
make
make install

编译gdb
cd src
tar jxvf gdb-6.6.tar.bz2
mkdir gdb-build
cd gdb-build
../gdb-6.6/configure --prefix=${CLFS}/cross-tools --host=${CLFS_HOST} --target=${CLFS_TARGET} --with-sysroot=${CLFS} --enable-threads=posix --enable-long-long

make
make install


打包压缩arm-linux-toolchains

tar cvjf /tmp/arm-linux-toolchains.tar.bz2 \
cross-tools/arm-linux \
cross-tools/bin/arm-linux-* \
cross-tools/bin/genext2fs \
cross-tools/include/c++/4.1.1 \
cross-tools/lib/gcc/arm-linux/4.1.1\
cross-tools/libexec/gcc/arm-linux/4.1.1

jiangtao9999 发表于 2008-5-15 16:25:51

貌似一个在 google 干活的哥们写了一个交叉编译器搭建脚本……
页: [1]
查看完整版本: binutils-2.17|gcc-4.1.1|glibc-2.5 作交叉编译器记录要点