6.18. GCC-10.2.0 - Pass 2

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

Approximate build time: 11 SBU
Required disk space: 3.7 GB

6.18.1. Installation of GCC

As in the first build of GCC, the GMP, MPFR, and MPC packages are required. Unpack the tarballs and move them into the required directory names:

tar -xf ../mpfr-4.1.0.tar.xz
mv -v mpfr-4.1.0 mpfr
tar -xf ../gmp-6.2.1.tar.xz
mv -v gmp-6.2.1 gmp
tar -xf ../mpc-1.2.1.tar.gz
mv -v mpc-1.2.1 mpc

On 64-bit hosts, set the default directory name for 64-bit libraries to lib:

sed -e 's/lib64/lib/g' \
       -i.orig $(find gcc/config -name t-linux64)

On 64-bit MIPS, set the default directory name for core C runtime objects to lib:

sed -e 's/lib64/lib/g' \
       -i.orig gcc/config/mips/mips.h

Fix an issue on MIPS:

sed -e '2384 s/MSA/mode != MAX_MACHINE_MODE \&\& &/' \
     -i gcc/config/mips/mips.c

Create a separate build directory again:

mkdir -v build
cd       build

Create a symlink that allows libgcc to be built with posix threads support:

mkdir -pv $LFS_TGT/libgcc
ln -s ../../../libgcc/gthr-posix.h $LFS_TGT/libgcc/gthr-default.h

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

Now prepare GCC for compilation:

../configure                                       \
    --build=$(../config.guess)                     \
    --host=$LFS_TGT                                \
    --prefix=/usr                                  \
    CC_FOR_TARGET=$LFS_TGT-gcc                     \
    --with-build-sysroot=$LFS                      \
    --enable-initfini-array                        \
    --disable-nls                                  \
    --disable-multilib                             \
    --disable-decimal-float                        \
    --disable-libatomic                            \
    --disable-libgomp                              \
    --disable-libquadmath                          \
    --disable-libssp                               \
    --disable-libvtv                               \
    --disable-libstdcxx                            \
    --enable-languages=c,c++                       \
    --with-abi=64                                  \
    $LFS_MIPS_GCC_EXTRA_OPTIONS

The meaning of the new configure options:

-with-build-sysroot=$LFS

Normally, using --host ensures that a cross-compiler is used for building GCC, and that compiler knows that it has to look for headers and libraries in $LFS. But the build system of GCC uses other tools, which are not aware of this location. This switch is needed to have them find the needed files in $LFS, and not on the host.

--enable-initfini-array

This option is automatically enabled when building a native compiler with a native compiler on Linux. But here, we build with a cross compiler, so we need to explicitly set this option.

Compile the package:

make

Install the package:

make DESTDIR=$LFS install

As a finishing touch, create a utility 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 -sv gcc $LFS/usr/bin/cc

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