6.4. GCC-4.1.1

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

6.4.1. Installation of GCC

The following patch fixes the searching of multilib dirs for specs file:

patch -Np1 -i ../gcc-4.1.1-PR20425-1.patch

The following patches fixes an TLS build issue. For More details go to http://gcc.gnu.org/ml/gcc-patches/2006-02/msg00177.html:

patch -Np1 -i ../gcc-4.1.1-sparc_tls-1.patch

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

patch -Np1 -i ../gcc-4.1.1-pure64_specs-1.patch

To make sure that a couple of tools use the proper syntax, apply the following patch:

patch -Np1 -i ../gcc-4.1.1-posix-1.patch

The following patch ensures that gcc does not search the /usr directory for libgcc_s.so when cross-compiling:

patch -Np1 -i ../gcc-4.1.1-cross_search_paths-1.patch

Now we will change cpp's search path not to look in /usr/include:

cp -v gcc/cppdefault.c{,.orig}
sed -e '/#define STANDARD_INCLUDE_DIR/s@"/usr/include"@0@g' \
    gcc/cppdefault.c.orig > gcc/cppdefault.c

Also, we need to set the directory searched by the fixincludes process for system headers, so it won't look at the host's headers:

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

When searching for the multilibs, force the build to use the results of --print-multi-lib from our cross-compiler, not the native compiler gcc builds now:

cp -v gcc/Makefile.in{,.orig2}
sed -e "/MULTILIBS/s@\$(GCC_FOR_TARGET)@/cross-tools/bin/${CC}@g" \
   gcc/Makefile.in.orig2 > gcc/Makefile.in
[Important]

Important

The above patches and sed's are critical in ensuring a successful overall build. Do not forget to apply them.

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

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

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

Prepare GCC for compilation:

CC="${CC} ${BUILD64}" CXX="${CXX} ${BUILD64}" \
    ../gcc-4.1.1/configure --prefix=/tools --disable-multilib \
    --build=${LFS_HOST} --host=${LFS_TARGET} --target=${LFS_TARGET} \
    --libexecdir=/tools/lib --with-local-prefix=/tools --enable-long-long \
    --enable-c99 --enable-shared --enable-threads=posix --enable-__cxa_atexit \
    --disable-nls --enable-languages=c,c++ --disable-libstdcxx-pch

The meaning of the new configure options:

CXX="${CXX} ${BUILD64}"

This forces the C++ compiler to use our Build 64 FLAGS.

--disable-libstdcxx-pch

Do not build the pre-compiled header (PCH) for libstdc++. It takes up a lot of space, and we have no use for it.

Compile the package:

make CFLAGS_FOR_TARGET="${GCCTARGET}" CXXFLAGS_FOR_TARGET="${GCCTARGET}" \
AS_FOR_TARGET="${AS}" LD_FOR_TARGET="${LD}"

Install the package:

make install

Now we copy the files that are placed in /tools/lib64 to /tools/lib. We also delete the /tools/lib64 directory:

cp -va /tools/lib64/* /tools/lib
rm -rvf /tools/lib64

Many packages use the name cc to call the C compiler. To satisfy those packages, create a symlink:

ln -sv gcc /tools/bin/cc

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