<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
   "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  <!ENTITY % general-entities SYSTEM "../../general.ent">
  %general-entities;

  <!ENTITY gcc-download-http  "http://ftp.gnu.org/gnu/gcc/gcc-&gcc-version;/gcc-&gcc-version;.tar.bz2">
  <!ENTITY gcc-download-ftp   "ftp://ftp.gnu.org/gnu/gcc/gcc-&gcc-version;/gcc-&gcc-version;.tar.bz2">
  <!ENTITY gcc-md5sum         "4df8ee253b7f3863ad0b86359cd39c43">
  <!ENTITY gcc-size           "86 MB">
  <!ENTITY gcc-buildsize      "5.2 GB">
  <!ENTITY gcc-time           "138 SBU (including 95 SBU for tests)">
]>

<sect1 id="gcc" xreflabel="GCC-&gcc-version;">
  <?dbhtml filename="gcc.html" ?>

  <sect1info>
    <othername>$LastChangedBy: pierre $</othername>
    <date>$Date: 2015-02-23 16:51:12 -0500 (Mon, 23 Feb 2015) $</date>
  </sect1info>

  <title>GCC-&gcc-version;</title>

  <indexterm zone="gcc">
    <primary sortas="a-gcc-4-0">GCC-&gcc-version;</primary>
  </indexterm>

  <sect2 role="package">
    <title>Introduction to GCC</title>

    <para>The <application>GCC</application> package contains the GNU Compiler
    Collection. This page describes the installation of compilers for the
    following languages: C, C++, Fortran, Objective C, Objective C++, and Go.
    Two additional languages , Ada and Java are available in the collection.
    They have specific requirements, so they are described in separate pages
    (<xref linkend="gcc-ada"/> and <xref linkend="gcc-java"/>). Since C and
    C++ are installed in LFS, this page is either for upgrading C and C++,
    or for installing additional compilers.</para>

    &lfs77_checked;

    <caution>
      <para>If you are upgrading <application>GCC</application> from any other
      version prior to &gcc-version;, then you must be careful compiling 3rd
      party kernel modules. You should ensure that the kernel and all its
      native modules are also compiled using the same version of
      <application>GCC</application> that you use to build the 3rd party module.
      This issue does not affect native kernel (and kernel modules) updates,
      as the instructions below are a complete reinstallation of
      <application>GCC</application>. If you have existing 3rd party modules
      installed, ensure they are recompiled using the updated version of
      <application>GCC</application>. As always, never update the kernel
      headers from the ones used when <application>Glibc</application> was
      compiled during LFS.</para>
    </caution>

    <bridgehead renderas="sect3">Package Information</bridgehead>
    <itemizedlist spacing="compact">
      <listitem>
        <para>Download (HTTP): <ulink url="&gcc-download-http;"/></para>
      </listitem>
      <listitem>
        <para>Download (FTP): <ulink url="&gcc-download-ftp;"/></para>
      </listitem>
      <listitem>
        <para>Download MD5 sum: &gcc-md5sum;</para>
      </listitem>
      <listitem>
        <para>Download size: &gcc-size;</para>
      </listitem>
      <listitem>
        <para>Estimated disk space required: &gcc-buildsize;</para>
      </listitem>
      <listitem>
        <para>Estimated build time: &gcc-time;</para>
      </listitem>
    </itemizedlist>
    <bridgehead renderas="sect3">Additional Downloads</bridgehead>
    <itemizedlist spacing="compact">
      <listitem>
        <para>
          Optional D Language compiler:
          <ulink url="https://www.williamfeely.info/download/lfs-multilib/gdc-&gdc-version;.tar.xz"/>
        </para>
      </listitem>
    </itemizedlist>
<!--
    <bridgehead renderas="sect3">Additional Downloads</bridgehead>
    <itemizedlist spacing="compact">
      <listitem>
        <para>
          Required patch:
          <ulink url="&patch-root;/gcc-&gcc-version;-upstream_fixes-1.patch"/>
        </para>
      </listitem>
    </itemizedlist>
-->

    <bridgehead renderas="sect3">GCC Dependencies</bridgehead>

    <bridgehead renderas="sect4">Recommended</bridgehead>
    <para role="recommended">
      <xref linkend="dejagnu"/>, for tests
    </para>

    <para condition="html" role="usernotes">User Notes:
    <ulink url="&blfs-wiki;/gcc"/></para>

  </sect2>

  <sect2 role="installation">
    <title>Installation of GCC</title>

    <important>
      <para>Even if you specify only languages other than C and C++ to the
      <command>./configure</command> command below, the
      installation process will overwrite your existing
      <application>GCC</application> C and C++ compilers and libraries.
      Having the <application>Tcl</application>,
      <application>Expect</application> and <application>DejaGnu</application>
      packages installed before beginning the build is highly recommended so
      you can run the full suite of tests.</para>

      <para>Do not continue with the <command>make install</command> command
      until you are confident the build was successful. You can compare your
      test results with those found at <ulink
      url="http://gcc.gnu.org/ml/gcc-testresults/"/>.  You may also want to
      refer to the information found in the <application>GCC</application>
      section of Chapter 6 in the LFS book (<ulink
      url="&lfs-root;/chapter06/gcc.html"/>).</para>
    </important>
    
    <para>If you downloaded the optional D language compiler, add it to
    <application>GCC</application> by running the following commands:</para>
    
<screen><userinput>tar -xf ../gdc-&gdc-version;.tar.xz &amp;&amp;
cd gdc-&gdc-version; &amp;&amp;
./setup-gcc.sh .. &amp;&amp;
cd ..</userinput></screen>

    <para>The instructions below are intentionally performing a
    <quote>bootstrap</quote> process. Bootstrapping is needed for robustness
    and is highly recommended when upgrading the compilers version. To disable
    bootstrap anyways, add <parameter>--disable-bootstrap</parameter> to the
    <command>./configure</command> options below.</para>
<!--
    <para>As in LFS, fix a problem identified upstream:</para>

<screen><userinput>sed -i 's/if \((code.*))\)/if (\1 \&amp;\&amp; \!DEBUG_INSN_P (insn))/' gcc/sched-deps.c</userinput></screen>
-->

    <para>Install <application>GCC</application> by running the
    following commands:</para>

<screen><userinput><!--
patch -Np1 -i ../gcc-&gcc-version;-upstream_fixes-1.patch    &amp;&amp;
-->
sed -i -e 's@/libx32/ld-linux-x32.so.2@/tools/libx32/ld-linux-x32.so.2@g' gcc/config/i386/linux64.h
sed -i -e 's@/lib/ld-linux.so.2@/lib32/ld-linux.so.2@g' gcc/config/i386/linux64.h
sed -i -e '/MULTILIB_OSDIRNAMES/d' gcc/config/i386/t-linux64
echo "MULTILIB_OSDIRNAMES = m64=../lib m32=../lib32 mx32=../libx32" >> gcc/config/i386/t-linux64

mkdir ../gcc-build                                   &amp;&amp;
cd    ../gcc-build                                   &amp;&amp;

../gcc-&gcc-version;/configure                               \
    --prefix=/usr                                    \
    --libdir=/usr/lib                                \
    --enable-shared                                  \
    --enable-threads=posix                           \
    --enable-__cxa_atexit                            \
    --with-multilib-list=m32,m64,mx32                \
    --enable-clocale=gnu                             \
    --with-system-zlib                               \
    --enable-cloog-backend=isl                       \
    --enable-languages=c,c++,fortran,go,objc,obj-c++,d &amp;&amp;
make</userinput></screen>

    <para>If you have installed additional packages such as
    <application>Valgrind</application> and <application>GDB</application>,
    the <application>GCC</application> part of the testsuite will run more
    tests than in LFS. Some of those will report FAIL and others XPASS
    (pass when expected to FAIL). To run the tests, issue:</para>

<screen><userinput>ulimit -s 32768 &amp;&amp;
make -k check</userinput></screen>
<!-- The command above may error out, so using && may prevent the summary
to be run. -->

    <para>The tests are very long, and the results may be hard to find in the
    logs, specially if you use parallel jobs with make. You can get a summary
    of the tests with:</para>

<screen><userinput>../gcc-&gcc-version;/contrib/test_summary</userinput></screen>

    <para>Now, as the <systemitem class="username">root</systemitem> user:</para>

<screen role="root"><userinput>make install &amp;&amp;

mkdir -pv /usr/share/gdb/auto-load/usr/lib              &amp;&amp;
mv -v /usr/lib/*gdb.py /usr/share/gdb/auto-load/usr/lib &amp;&amp;

chown -v -R root:root \
    /usr/lib/gcc/*linux-gnu/&gcc-version;/include{,-fixed}</userinput></screen>

    <para>Some packages expect to find the C preprocessor in
    <filename class="directory">/lib</filename> or may refer to the C compiler
    under the name <command>cc</command>. The following symbolic links are not
    needed if you have followed the LFS instructions, since they
    have been already created. If you do not have them on your system, issue
    as the <systemitem class="username">root</systemitem> user:</para>

<screen role="root"><userinput>ln -v -sf ../usr/bin/cpp /lib &amp;&amp;
ln -v -sf gcc /usr/bin/cc</userinput></screen>

  </sect2>

  <sect2 role="commands">
    <title>Command Explanations</title>
<!--
    <para>
      <command>patch ... gcc-&gcc-version;-upstream_fixes-1.patch</command>:
      This patch corrects bugs in the C++ compiler, which lead to
      segmentation faults in some cases.
    </para>
-->

    <para>
      <command>mkdir ../gcc-build; cd ../gcc-build</command>: The
      <application>GCC</application> documentation recommends
      building the package in a dedicated build directory.
    </para>

    <para>
      <parameter>--enable-shared --enable-threads=posix
      --enable-__cxa_atexit</parameter>: These parameters are required to build
      the <application>C++</application> libraries to published standards.
    </para>

    <para>
      <parameter>--enable-clocale=gnu</parameter>: This parameter is a
    failsafe for incomplete locale data.</para>

    <para>
      <parameter>--with-multilib-list=m32,m64,mx32</parameter>: This
      parameter adds support for multilib compilation in 32-bit, 64-bit, and x32
      ABI formats.
    </para>

    <para>
      <parameter>--with-system-zlib</parameter>: Uses the system
      <application>zlib</application> instead of the bundled one.
      <application>zlib</application> is used for compressing
      and uncompressing <application>GCC</application>'s intermediate
      language in LTO (Link Time Optimization) object files.
    </para>

    <para>
      <parameter>--enable-cloog-backend=isl</parameter>: This parameter 
      enables the CLooG-ISL backend for Graphite Loop Optimizations.
    </para>

    <para>
      <parameter>--enable-languages=c,c++,fortran,go,objc,obj-c++</parameter>:
      This command identifies which languages to build. You may modify
      this command to remove undesired languages.  Omit <parameter>d</parameter>
      if you did not add the D language compiler.
    </para>

    <para>
      <command>ulimit -s 32768</command>: This command prevents several
      tests from running out of stack space.
    </para>

    <para>
      <command>make -k check</command>: This command runs the test suite
      without stopping if any errors are encountered.
    </para>

    <para>
      <command>../gcc-&gcc-version;/contrib/test_summary</command>: This
      command will produce a summary of the test suite results. You can append
      <command>| grep -A7 Summ</command> to the command to produce an even more
      condensed version of the summary. You may also wish to redirect the output
      to a file for review and comparison later on.
    </para>

    <para>
      <command>mv -v /usr/lib/*gdb.py ...</command>: The installation
      stage puts some files used by <application>gdb</application> under the
      <filename class="directory">/usr/lib</filename> directory. This generates
      spurious error messages when performing <command>ldconfig</command>. This
      command moves the files to another location.
    </para>

    <para>
      <command>chown -v -R root:root /usr/lib/gcc/*linux-gnu/...</command>:
      If the package is built by a user other than root, the ownership of the
      installed <filename class="directory">include</filename> directory (and
      its content) will be incorrect. This command changes the ownership to the
      <systemitem class="username">root</systemitem> user and group.
    </para>

  </sect2>

  <sect2 role="content">
    <title>Contents</title>

    <para>Some program and library names and descriptions are not listed here,
    but can be found at
    <ulink url="&lfs-root;/chapter06/gcc.html#contents-gcc"/> as they were
    initially installed during the building of LFS.</para>

    <segmentedlist>
      <segtitle>Installed Programs</segtitle>
      <segtitle>Installed Libraries</segtitle>
      <segtitle>Installed Directories</segtitle>

      <seglistitem>
        <seg>
          gccgo and gfortran,
          hard-linked to architecture specific names
        </seg>
        <seg>
          libgfortran.{so,a},
          libgo.{so,a}, libgobegin.a, libobjc.{so,a}, and numerous other
          run-time libraries and executables in <filename class="directory">
          /usr/lib/gcc</filename>, <filename class="directory">
          /usr/libexec/gcc</filename>, and <filename class="directory">
          /usr/lib/go</filename>
        </seg>
        <seg>
          /usr/lib/gcc/&lt;arch-triplet&gt;/&gcc-version;/include/objc and
          /usr/lib/go
        </seg>
      </seglistitem>
    </segmentedlist>

    <variablelist>
      <bridgehead renderas="sect3">Short Descriptions</bridgehead>
      <?dbfo list-presentation="list"?>
      <?dbhtml list-presentation="table"?>

      <varlistentry id="gccgo">
        <term><command>gccgo</command></term>
        <listitem>
          <para>is a GCC-based compiler for the
          <application>Go</application> language.</para>
          <indexterm zone="gcc gccgo">
            <primary sortas="b-gccgo">gccgo</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gfortran">
        <term><command>gfortran</command></term>
        <listitem>
          <para>is a GCC-based compiler for the
          <application>Fortran</application> language.</para>
          <indexterm zone="gcc gfortran">
            <primary sortas="b-gfortran">gfortran</primary>
          </indexterm>
        </listitem>
      </varlistentry>

    </variablelist>

  </sect2>

</sect1>
