主机环境:
[html] view plaincopy
-
ubuntu 12.04.1 64bit
-
gcc version 4.6.3
1. 下载最新源码包
[html] view plaincopy
-
binutils-2.22.tar.gz
-
-
gcc-4.7.2.tar.bz2
-
gmp-5.0.5.tar.xz
-
mpfr-3.1.1.tar.xz
-
mpc-1.0.1.tar.gz
-
-
glibc-2.16.0.tar.xz
-
glibc-linuxthreads-2.5.tar.bz2
-
glibc-ports-2.16.0.tar.xz
-
-
linux-3.5.4.tar.bz2
将以上源码包放入~/src目录中
1. 配置编译环境
[html] view plaincopy
-
vim /etc/profile
-
# 将以下内容写入profile文件中保存退出
-
TARGET=arm-linux-gnueabi
-
PREFIX=/opt/cross/gcc-4.7.2/$TARGET
-
PATH=$PREFIX/bin:$PATH
-
-
export TARGET PREFIX PATH
-
-
# 配置编译环境
-
重启使配置环境失效
2. 编译binutils
[html] view plaincopy
-
tar -xzf binutils-2.22.tar.gz
-
mkdir binutils-build
-
cd binutils-build
-
../binutils-2.22/configure --target=$TARGET --prefix=$PREFIX
-
make -j2
-
sudo make install
-
cd ..
3. 第一次编译gcc
[html] view plaincopy
-
tar -xjf gcc-4.7.2.tar.bz2
-
mkdir gcc-bootstrap-build
-
tar -xf gmp-5.0.5.tar.xz
-
tar -xf mpfr-3.1.1.tar.xz
-
tar -xf mpc-1.0.1.tar.gz
-
cd gcc-4.7.2
-
mv -v gmp-5.0.5 gmp
-
mv -v mpfr-3.1.1 mpfr
-
mv -v mpc-1.0.1 mpc
-
cd ../gcc-bootstrap-build
-
-
-
-
修改 gcc/gengtype.c 文件如下:
write_field_root (outf_p f, pair_p v, type_p type, const char *name,
int has_length, struct fileloc *line, const char *if_marked,
bool emit_pch, type_p field_type, const char *field_name)
{
+ struct pair newv;
/* If the field reference is relative to V, rather than to some
subcomponent of V, we can mark any subarrays with a single stride.
We're effectively treating the field as a global variable in its
own right. */
if (v && type == v->type)
{
- struct pair newv;
newv = *v;
newv.type = field_type;
-
-
-
../gcc-4.7.2/configure \
-
--target=$TARGET --host=x86_64-linux-gnu --build=x86_64-linux-gnu \
-
--enable-targets=all --prefix=$PREFIX \
-
--enable-languages=c --with-newlib --without-headers --disable-nls \
-
--disable-threads --disable-shared --disable-libmudflap --disable-libssp \
-
--disable-libgomp --disable-decimal-float --enable-checking=release \
-
--disable-bootstrap --disable-libquadmath \
-
--with-mpfr-include=$(pwd)/../gcc-4.7.2/mpfr/src \
-
--with-mpfr-lib=$(pwd)/mpfr/src/.libs
-
make -j2 all-gcc
-
make -j2 all-target-libgcc
-
sudo make install-gcc
-
sudo make install-target-libgcc
-
sudo cp -v libiberty/libiberty.a $PREFIX/lib
-
# 以下添加libgcc_eh.a,libgcc_s.a到libgcc.a的软链接,防止编译C库时出错
-
sudo ln -vs libgcc.a `arm-linux-gnueabi-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/'`
-
sudo ln -vs libgcc.a `arm-linux-gnueabi-gcc -print-libgcc-file-name | sed 's/libgcc/&_s/'`
-
cd ..
4. 安装内核头文件
[html] view plaincopy
-
tar -xjf linux-3.5.4.tar.bz2
-
cd linux-3.5.4
-
make ARCH=arm headers_check
-
make ARCH=arm INSTALL_HDR_PATH=dest headers_install
-
sudo cp -rv dest/include/* $PREFIX/$TARGET/include
-
注意:内核头文件的安装位置是$PREFIX/$TARGET/include,而不是$PREFIX
-
cd ..
5. 编译C库
[html] view plaincopy
-
tar -xf glibc-2.16.0.tar.xz
-
tar -xjf glibc-linuxthreads-2.5.tar.bz2 -C glibc-2.16.0
-
tar -xf glibc-ports-2.16.0.tar.xz
-
mv glibc-ports-2.16.0 glibc-2.16.0/ports
-
mkdir glibc-build
-
cd glibc-build
-
-
CC=$TARGET-gcc \
-
AR=$TARGET-ar \
-
RANLIB=$TARGET-ranlib \
-
../glibc-2.16.0/configure \
-
--host=$TARGET \
-
--prefix=$PREFIX/$TARGET \
-
--with-tls --disable-profile \
-
--enable-add-ons --with-headers=$PREFIX/$TARGET/include \
-
libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes libc_cv_arm_tls=yes
-
注意:C库的安装位置是$PREFIX/$TARGET,编译完整的gcc时链接使用
-
sudo make -j2
-
sudo -s
-
-
make install
-
exit
-
cd ..
6. 编译完整的gcc
[html] view plaincopy
-
-
../gcc-4.7.2/configure --target=$TARGET \
-
--host=x86_64-linux-gnu --build=x86_64-linux-gnu \
-
--prefix=$PREFIX \
-
--enable-languages=c,c++ --enable-shared
-
make -j2
-
sudo make install
-
cd ..
阅读(546) | 评论(0) | 转发(0) |