4.7. GCC-13.2.0 - Static¶
The GCC package contains the GNU compiler collection, which includes the C compiler. This build of GCC is mainly done so that the C library can be built next.
4.7.1. Installation of Cross GCC Compiler with Static libgcc and no Threads¶
GCC requires the GMP, MPFR, and MPC packages to either be present on the host or to be present in source form within the gcc source tree. Unpack these into the GCC directory after unpacking GCC:
tar xf ../mpfr-4.2.1.tar.xz
mv -v mpfr-4.2.1 mpfr
tar xf ../gmp-6.3.0.tar.xz
mv -v gmp-6.3.0 gmp
tar xf ../mpc-1.3.1.tar.gz
mv -v mpc-1.3.1 mpc
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:
../gcc-13.2.0/configure \
--prefix=${CLFS}/cross-tools \
--build=${CLFS_HOST} \
--host=${CLFS_HOST} \
--target=${CLFS_TARGET} \
--with-sysroot=${CLFS}/cross-tools/${CLFS_TARGET} \
--disable-nls \
--disable-shared \
--without-headers \
--with-newlib \
--disable-decimal-float \
--disable-libgomp \
--disable-libmudflap \
--disable-libssp \
--disable-libatomic \
--disable-libquadmath \
--disable-threads \
--enable-languages=c \
--disable-multilib \
--with-mpfr-include=$(pwd)/../gcc-13.2.0/mpfr/src \
--with-mpfr-lib=$(pwd)/mpfr/src/.libs \
--with-arch=${CLFS_CPU}
The meaning of the configure options:
--prefix=${CLFS}/cross-toolsThis tells the configure script to prepare to install the package in the
${CLFS}/cross-toolsdirectory.--build=${CLFS_HOST}This tells the configure script the triplet to use to build GCC. It will use ${CLFS_HOST} as that’s where it’s being built.
--host=${CLFS_HOST}This tells the configure script the triplet of the machine GCC will be executed on when actually cross compiling. It will use ${CLFS_HOST} as that’s where GCC will execute when cross compiling software later.
--target=${CLFS_TARGET}This tells the configure script the triplet of the machine GCC will build executables for. It will use ${CLFS_TARGET} so that software compiled with this version of GCC can be executed on the embedded machine target.
--with-sysroot=${CLFS}/cross-tools/${CLFS_TARGET}This tells configure that ${CLFS}/cross-tools/${CLFS_TARGET} is going to be the temporary root of our system. It will now use the specified sysroot as a prefix of the default search paths.
--disable-nlsThis disables internationalization as i18n is not needed for the cross-compile tools.
--disable-sharedDisables the creation of the shared libraries.
--without-headersTells configure to not use any headers from any C libraries. This is needed as we haven’t yet built the C library and to prevent influence from the host environment.
--with-newlibTells configure to build libgcc without needing any C libraries.
--disable-decimal-floatTells configure to disable IEEE 754-2008 decimal floating point support. Decimal floating point support isn’t needed yet.
--disable-libgompTells configure to not build the GOMP run-time libraries. GOMP is the GNU implementation of OpenMP, a API for shared-memory parallel programming.
--disable-libmudflapTells configure to not build libmudflap. Mudflap is a library that can be used to help check for proper pointer usage.
--disable-libsspTells configure not to build run-time libraries for stack smashing detection.
--disable-libatomicTells configure not to build atomic operations.
--disable-libquadmathTells configure not to build quad math operations.
--disable-threadsThis will prevent GCC from looking for the multi-thread include files, since they haven’t been created for this architecture yet. GCC will be able to find the multi-thread information after the glibc headers are created.
--enable-languages=cThis option ensures that only the C compiler is built.
--disable-multilibThis option specifies that multiple target libraries should not be built.
--with-mpfr-include=$(pwd)/../gcc-13.2.0/mpfr/srcTells configure how to find the mpfr headers.
--with-mpfr-lib=$(pwd)/mpfr/src/.libsTells configure to use the mpfr libraries built within the GCC build directory. This happens automatically but is needed to prevent GCC from searching the host’s normal library paths.
--with-arch=${CLFS_CPU}This option configures the cross compiler to only output instructions for our previously selected CPU.
Continue with compiling the package:
make all-gcc all-target-libgcc
Install the package:
make install-gcc install-target-libgcc
Details on this package are located in Section 4.9.2, “Contents of GCC.”