自己电脑上试着编译mips的gcc cross compiler,好烦,一直没成功,编译binutils的时候就貌似出了问题,等到编译gcc的时候就更不对了。。。说缺少东西。好麻烦,先放一阵。看看有没有现成的包,自己编译有点麻烦阿。
You’re adverse to using someone else’s toolchains, and cannot remember how to build one yourself, no matter how hard you try. Fear not. Outlined here is the proceedure to build a bootstrap toolchain; one which is minus the C library and is just enough to build the kernel.
Prologue
What you’ll need:
Note that in general you want to use the latest versions released by the time a kernel was released. The versions listed here are known to be working well for recent kernels as of the time of writing. Using tools more recent than the kernel means that combination will not have been tested exhaustively so the likelihood of encountering incompatibilities increases. Sometimes tool compatibility versions are fixed in -stable but there is no guarantee that this also covers your favourite esoteric configuration.
Now, export a few environment variables for your convenience. If you’re building for big-endian MIPS, your TARGET should be mips-unknown-linux-gnu instead. If you wish to install to a different location other than /opt/cross/, substitute in your PREFIX accordingly. A common alternative is /usr/local/.
% export WDIR=/tmp
% export TARGET=mipsel-unknown-linux-gnu
% export PREFIX=/opt/cross
You’ll need to re-export your PATH with the new install location so when building a bootstrap gcc, it may locate the shiny new cross-binutils:
% export PATH="${PATH}":${PREFIX}/bin
Now change to the staging directory:
% cd $WDIR
% mkdir ${TARGET}-toolchain && cd ${TARGET}-toolchain
Binutils
Extract, configure, build and install:
% tar xjf binutils-2.16.1.tar.bz2
% mkdir build-binutils && cd build-binutils
% ../binutils-2.16.1/configure --target=$TARGET --prefix=$PREFIX
% make
% make install
% cd ..
You should now have the cross-binutils installed under ${PREFIX}/bin/ with names prefixed by mipsel-unknown-linux-gnu-* (or mips-unknown-linux-gnu-* if you’re building for big-endian MIPS).
GCC
Extract, configure, build and install a bootstrap GCC.
Enable any other language front-ends as you see fit. For building the kernel however, you can get away with just the C language front-end. Also, tell the configure script not to look for target libc headers — we don’t have them, and don’t need them at this point.
% tar xjf gcc-3.4.4.tar.bz2
% mkdir build-gcc-bootstrap && cd build-gcc-bootstrap
% ../gcc-3.4.4/configure --target=$TARGET --prefix=$PREFIX \
--enable-languages=c --without-headers \
--with-gnu-ld --with-gnu-as \
--disable-shared --disable-threads
% make -j2
% make install
% cd ..
GDB
You’ll need this for debugging either the kernel (with KGDB) or userspace (natively or with gdbserver). If this doesn’t apply in your case, you may safely skip this section.
Extract, configure, build and install:
% tar xjf gdb-6.3.tar.bz2
% mkdir build-gdb && cd build-gdb
% ../gdb-6.3/configure --target=$TARGET --prefix=$PREFIX
% make
% make install
% cd ..
Summary
Your shiny new toolchain should be in your PATH, given you re-exported it earlier. Otherwise, you’ll need to prefix your PATH with:
% ${PREFIX}/bin/mipsel-unknown-linux-gnu-
or for a big-endian target:
% ${PREFIX}/bin/mips-unknown-linux-gnu-
Enjoy.