5.14. Cross GCC-4.6.0 - Static

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

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

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

patch -Np1 -i ../gcc-4.6.0-branch_update-1.patch

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

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

Change the StartFile Spec and Standard Include Dir so that GCC looks in /tools:

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

Now alter gcc's c preprocessor's default include search path to use /tools only:

cp -v gcc/Makefile.in{,.orig}
sed -e "s@\(^CROSS_SYSTEM_HEADER_DIR =\).*@\1 /tools/include@g" \
    gcc/Makefile.in.orig > gcc/Makefile.in

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.6.0/configure --prefix=/cross-tools \
  --build=${CLFS_HOST} --host=${CLFS_HOST} --target=${CLFS_TARGET} \
  --with-sysroot=${CLFS} --with-local-prefix=/tools --disable-nls \
  --disable-shared --with-mpfr=/cross-tools --with-gmp=/cross-tools \
  --with-ppl=/cross-tools --with-cloog=/cross-tools \
  --without-headers --with-newlib --disable-decimal-float \
  --disable-libgomp --disable-libmudflap --disable-libssp \
  --disable-threads --enable-languages=c --disable-multilib

The meaning of the configure options:


This tells the configure script to prepare to install the package in the /cross-tools directory.


When used with --target, this creates a cross-architecture executable that creates files for ${CLFS_TARGET} but runs on ${CLFS_HOST}.


When used with --host, this creates a cross-architecture executable that creates files for ${CLFS_TARGET} but runs on ${CLFS_HOST}.


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


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.


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


Disables the creation of the shared libraries.


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


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


Disables support for the C decimal floating point extension.


Disables the creation of runtime libraries used by GOMP.


Disables the creation of runtime libaries used by libmudflap.


Disables the use of Stack Smashing Protection for runtime libraries.


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.


This option ensures that only the C compiler is built.

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 10.16.2, “Contents of GCC.”