Installation of GCC
We won't be needing a C++ compiler until the next chapter. So, only
the gcc-core tarball needs to be unpacked at this time.
This package is known to behave badly when you have changed its
default optimization flags (including the -march and -mcpu options).
Therefore, if you have defined any environment variables that override
default optimizations, such as CFLAGS and CXXFLAGS, we recommend unsetting
or modifying them when building GCC.
patch -Np1 -i ../gcc-&gcc-version;-mmap_test.patch
patch -Np1 -i ../gcc-&gcc-version;-no_fixincludes.patch
It is recommended by the GCC installation documentation to build
GCC outside of the source directory in a dedicated directory:
mkdir ../gcc-build
cd ../gcc-build
Prepare GCC to be compiled:
../gcc-&gcc-version;/configure --prefix=/stage1 \
--with-local-prefix=/stage1 \
--disable-nls --enable-shared \
--enable-languages=c
The meaning of the new configure options is:
--with-local-prefix=/stage1: The
purpose of this switch is to remove /usr/local/include
from gcc's include search path. This is not absolutely
essential, but we want to try and minimize the influence from the host system,
so this seems a logical thing to do.
--enable-shared: This switch may
seem counter-intuitive at first. But using it allows the building of
libgcc_s.so.1 and libgcc_eh.a, and
having libgcc_eh.a available ensures that the configure
script for Glibc (the next package we compile) produces the proper results.
Please note that the gcc binaries will still be linked
statically, as this is controlled by the -static
value of BOOT_LDFLAGS further on.
--enable-languages=c: This will build
only the C compiler from the GCC package. We won't be needing anything else
during this chapter.
Continue with compiling the package:
make BOOT_LDFLAGS="-static" bootstrap
The meaning of the make parameters is:
BOOT_LDFLAGS="-static": This tells
GCC to link its programs statically.
bootstrap: This target doesn't just
compile GCC, but compiles it several times. It uses the programs compiled in
a first round to compile itself a second time, and then again a third time.
It then compares these second and third compiles to make sure it can
reproduce itself flawlessly, which most probably means that it was
compiled correctly.
And install the package:
make install
As a finishing touch we'll create the /stage1/bin/cc symlink. Many programs and
scripts run cc instead of gcc,
a thing meant to keep programs generic and therefore usable on all kinds of
Unix systems. Not everybody has the GNU C compiler installed. Simply running
cc leaves the system administrator free to decide what
C compiler to install, as long as there's a symlink pointing to it:
ln -sf gcc /stage1/bin/cc