5.16. Cross GCC-7.1.0 - Final

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

5.16.1. Installation of GCC Cross Compiler

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

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

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

Prepare GCC for compilation:

AR=ar \
LDFLAGS="-Wl,-rpath,/cross-tools/lib" \
../gcc-7.1.0/configure \
    --prefix=/cross-tools \
    --build=${CLFS_HOST} \
    --target=${CLFS_TARGET} \
    --host=${CLFS_HOST} \
    --with-sysroot=${CLFS} \
    --with-local-prefix=/tools \
    --with-native-system-header-dir=/tools/include \
    --disable-static \
    --enable-languages=c,c++ \
    --with-mpc=/cross-tools \
    --with-mpfr=/cross-tools \
    --with-gmp=/cross-tools \
    --with-isl=/cross-tools

The meaning of the new configure options:

--enable-languages=c,c++

This option ensures that only the C and C++ compilers are built.

Continue with compiling the package:

make AS_FOR_TARGET="${CLFS_TARGET}-as" \
    LD_FOR_TARGET="${CLFS_TARGET}-ld"

Install the package:

make install

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