5.16. Cross GCC-4.8.1 - Static

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

5.16.1. Installation of Cross GCC Compiler with Static libgcc and no Threads

The following patch contains a number of updates to the 4.8.1 branch by the GCC developers:

patch -Np1 -i ../gcc-4.8.1-branch_update-3.patch

Make a couple of essential adjustments to the specs file to ensure GCC uses our build environment:

patch -Np1 -i ../gcc-4.8.1-pure64_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

We will create a dummy limits.h so the build will not use the one provided by the host distro:

touch /tools/include/limits.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-4.8.1/configure --prefix=/cross-tools \
  --build=${CLFS_HOST} --host=${CLFS_HOST} --target=${CLFS_TARGET} \
  --with-sysroot=${CLFS} --with-local-prefix=/tools \
  --with-native-system-header-dir=/tools/include --disable-nls \
  --disable-shared --with-mpfr=/cross-tools --with-gmp=/cross-tools \
  --with-isl=/cross-tools --with-cloog=/cross-tools --with-mpc=/cross-tools \
  --without-headers --with-newlib --disable-decimal-float --disable-libgomp \
  --disable-libmudflap --disable-libssp --disable-threads --disable-multilib \
  --disable-libatomic --disable-libitm --disable-libsanitizer \
  --disable-libquadmath --disable-target-libiberty --disable-target-zlib \
  --with-system-zlib --enable-cloog-backend=isl --disable-isl-version-check \
  --enable-languages=c --enable-checking=release

The meaning of the new configure options:

--with-sysroot=${CLFS}

Tells GCC to consider ${CLFS} as the root file system.

--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.

--with-native-system-headers-dir=/tools/include

This switch ensures that GCC will search for the system headers in /tools/include and that host system headers will not be searched.

--disable-nls

This disables internationalization as i18n is not needed for the cross-compile tools.

--without-headers

Disables GCC from using the target's Libc when cross compiling.

--with-newlib

Tells GCC that the target libc will use 'newlib'.

--disable-decimal-float

Disables support for the C decimal floating point extension.

--disable-libgomp

Disables the creation of runtime libraries used by GOMP.

--disable-libmudflap

Disables the creation of runtime libaries used by libmudflap.

--disable-libssp

Disables the use of Stack Smashing Protection for runtime libraries.

--disable-threads

This 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.

--disable-libatomic

The atomic library isn't needed at this time.

--disable-libitm

The itm library isn't neeeded at this tiem.

--disable-libsanitizer

The sanitizer library isn't needed at this time.

--disable-libquadmath

The quadmath library isn't needed at this time.

--enable-languages=c

This option ensures that only the C compiler is built.

--enable-checking=release

This option selects the complexity of the internal consistency checks and adds error checking within the compiler.

Continue with compiling the package:

make all-gcc all-target-libgcc

The meaning of the new make options:

all-gcc all-target-libgcc

Compiles only the parts of GCC that are needed at this time, rather than the full package.

Install the package:

make install-gcc install-target-libgcc

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