<< Back to man.ChinaUnix.net

5.5. GCC-3.4.1 - Pass 1

The GCC package contains the GNU compiler collection, which includes the C and C++ compilers.

Approximate build time: 4.4 SBU

Required disk space: 300 MB

GCC installation depends on: Bash, Binutils, Coreutils, Diffutils, Findutils, Gawk, Gettext, Glibc, Grep, Make, Perl, Sed, and Texinfo

5.5.1. Installation of GCC

Unpack only the gcc-core tarball because neither the C++ compiler nor the test suite will be needed here.

This package is known to have issues when its default optimization flags (including the -march and -mcpu options) are changed. If any environment variables that override default optimizations have been defined, such as CFLAGS and CXXFLAGS, unset them when building GCC.

The GCC documentation recommends building GCC outside of the source directory in a dedicated build directory:

mkdir ../gcc-build
cd ../gcc-build

Prepare GCC for compilation:

../gcc-3.4.1/configure --prefix=/tools \
    --libexecdir=/tools/lib --with-local-prefix=/tools \
    --disable-nls --enable-shared --enable-languages=c

The meaning of the configure options:

--with-local-prefix=/tools

The purpose of this switch is to remove /usr/local/include from gcc's include search path. This is not absolutely essential, however, it helps to minimize the influence of the host system.

--enable-shared

This switch may seem counter-intuitive at first. However, this switch 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. Note that the GCC binaries will still be linked statically because this is controlled by the -static value of the BOOT_LDFLAGS variable in the next step.

--enable-languages=c

This option ensures that only the C compiler is built. This option is only needed when you have downloaded and unpacked the full GCC tarball, as opposed to just the gcc-core tarball.

Continue with compiling the package:

make BOOT_LDFLAGS="-static" bootstrap

The meaning of the make parameters:

BOOT_LDFLAGS="-static"

This tells GCC to link its programs statically.

bootstrap

This target does not 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. This also implies that it was compiled correctly.

Compilation is now complete. At this point, the test suite would normally be run, but, as mentioned before, the test suite framework is not in place yet. The benefits of running the tests at this point are minimal since the programs from this first pass will soon be replaced.

Install the package:

make install

As a finishing touch, create a symlink. Many programs and scripts run cc instead of gcc, which is used to keep programs generic and therefore usable on all kinds of UNIX systems where the GNU C compiler is not always installed. Running cc leaves the system administrator free to decide which C compiler to install.

ln -s gcc /tools/bin/cc

Details on this package are located in Section 6.14.2, “Contents of GCC.”