Let's get started with the actual compilation. First we need to
install the dependencies; you can peruse the prerequisites page for
more details. I'm normally lazy and go with GMP, MPFR and MPC. This
means we're not getting all the Graphite goodies which require
PPL.
The correct order of dependencies is as follows: GCC depends on MPC,
which depends on MPFR, which depends on GMP; so the order of
installation is:
So we start by installing GMP (replace the --jobs 2 flag with the
number of cores available on your machine):
wget ftp://ftp.gmplib.org/pub/gmp-5.0.4/gmp-5.0.4.tar.bz2
tar xjf gmp-5.0.4.tar.bz2
cd gmp-5.0.4
./configure --prefix=${HOME}/local
make --jobs 2
make install
cd ..
If you are on a recent version of Linux you can use the brand-spanking xaf incantation of tar, which unpacks any archive type; in the
interest of backwards compatibility we're sticking with the old
invocations here.
Now we can install MPFR:
wget http://www.mpfr.org/mpfr-current/mpfr-3.1.0.tar.bz2
tar xjf mpfr-3.1.0.tar.bz2
cd mpfr-3.1.0
./configure --prefix=${HOME}/local --with-gmp=${HOME}/local
make --jobs 2
make install
cd ..
Note that we are using --with-gmp instead of using the traditional
CFLAGS and LDFLAGS. This is a pattern followed through on GCC
configuration; I highly recommend you follow it as I'm sure a lot of
other things are happening on the background other than setting those
environment variables. In fact you may want to even make sure these
variables are not set to avoid any weird compilation problems.
MPC is installed next:
wget http://www.multiprecision.org/mpc/download/mpc-0.9.tar.gz
tar xf mpc-0.9.tar.gz
cd mpc-0.9
./configure --prefix=${HOME}/local --with-gmp=${HOME}/local \
--with-mpfr=${HOME}/local
make --jobs 2
make install
cd ..
Finally, we can now install GCC. Up til now we've been lazy and done
in-source builds. This is normally frowned upon, but doesn't have any
major consequences - that is, with the exception of GCC. The
documentation states explicitly that this is not a good idea:
First, we highly recommend that GCC be built into a separate directory
from the sources which does not reside within the source tree. This is
how we generally build GCC; building where srcdir == objdir should
still work, but doesn't get extensive testing; building where objdir
is a subdirectory of srcdir is unsupported.
We're not that brave so we'll follow the recommendation. We compile
GCC as follows:
wget http://ftp.gnu.org/gnu/gcc/gcc-4.7.0/gcc-4.7.0.tar.bz2
tar xjf gcc-4.7.0.tar.bz2
mkdir gcc-4.7.0_obj
cd gcc-4.7.0_obj
../gcc-4.7.0/configure --prefix=${HOME}/local \
--enable-ld=yes --disable-nls --with-gmp=${HOME}/local \
--with-mpfr=${HOME}/local --with-mpc=${HOME}/local \
--program-suffix=-4.7 --enable-checking=release --enable-languages=c,c++
make --jobs 2
make install
Lets see in detail the more important GCC configuration options:
- disable-nls: unless you are into internationalisation, you don't
really need NLS. This shaves off a bit of build time.
- enable-checking: lets make a few checks - no one wants a compiler
that generates broken code.
- enable-languages: we are only interested in C/C++, so no point in
building ADA, Java, etc.
- enable-ld: we're being old-school here and using traditional
ld
instead of gold, the new linker written in C++.
On the whole, these basic instructions are sufficient to build GCC on
Linux, MacOSX and Windows (MinGW). However, when you leave Linux there
is always a bit of platform-specific fiddling required. And to be
fair, Debian testing also had a couple of wrinkles.