6.9. GCC-7.1.0

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

6.9.1. Installation of GCC

Make a couple of essential adjustments to GCC's specs to ensure GCC uses our build environment:

patch -Np1 -i ../gcc-7.1.0-specs-1.patch

Change the StartFile Spec so that GCC looks in /tools:

echo -en '\n#undef STANDARD_STARTFILE_PREFIX_1\n#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"\n' >> gcc/config/linux.h
echo -en '\n#undef STANDARD_STARTFILE_PREFIX_2\n#define STANDARD_STARTFILE_PREFIX_2 ""\n' >> gcc/config/linux.h

Apply a sed substitution that will suppress the execution of the fixincludes script:

cp -v gcc/Makefile.in{,.orig}
sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig > gcc/Makefile.in

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

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

Before starting to build GCC, remember to unset any environment variables that override the default optimization flags.

Prepare GCC for compilation:

../gcc-7.1.0/configure \
    --prefix=/tools \
    --libdir=/tools/lib64 \
    --build=${CLFS_HOST} \
    --host=${CLFS_TARGET} \
    --target=${CLFS_TARGET} \
    --with-local-prefix=/tools \
    --enable-languages=c,c++ \
    --with-system-zlib \
    --with-native-system-header-dir=/tools/include \
    --disable-libssp \
    --enable-install-libiberty

The meaning of the new configure option:

--enable-install-libiberty

Allows GCC to build and install libiberty.a and its associated headers. This library is needed for some packages to compile.

Compile the package:

make AS_FOR_TARGET="${AS}" \
    LD_FOR_TARGET="${LD}"

Install the package:

make install

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