<?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;
]>

<sect1 id="ch-cross-tools-toolchain" role="wrap">
  <?dbhtml filename="toolchain.html"?>

  <title>Toolchain</title>

  <indexterm zone="ch-cross-tools-toolchain">
    <primary sortas="a-toolchain">ToolChain</primary>
    <secondary>cross tools</secondary>
  </indexterm>

  <sect2 role="package">
    <title/>

    <para>This section combines Binutils, GCC, GMP, and MPFR  packages
    to create a clean toolchain.</para>

  </sect2>

  <sect2 role="installation">
    <title>Installation of our Toolchain</title>

    <para os="na">We are going to extract all the files needed
   to create our toolchain:</para>

<screen os="nb"><userinput>tar -jxf ../gcc-&gcc-version;.tar.bz2
tar -jxf ../binutils-&binutils-version;.tar.bz2
tar -jxf ../mfpr-&mpfr-version;.tar.bz2
tar -jxf ../gmp-&gmp-version;.tar.bz2</userinput></screen>

    <para os="nc">We are going to create a combined directory for
   or build:</para>

<screen os="nd"><userinput>mkdir -pv sysroot-toolchain
cd gcc-&gcc-version;; tar -c * | \
  ( cd ../sysroot-toolchain ; tar xf - )
cd ../binutils-&binutils-version;; tar -c * | \
  ( cd ../sysroot-toolchain ; tar xf - )
cd ../sysroot-toolchain
mv ../mpfr-&mpfr-version; ./mpfr
mv ../gmp-&gmp-version; ./gmp</userinput></screen>

    <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
    href="../common/binutils.xml"
    xpointer="xpointer(//*[@os='ba'])"/>

    <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
    href="../common/binutils.xml"
    xpointer="xpointer(//*[@os='bb'])"/>

    <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
    href="../common/binutils.xml"
    xpointer="xpointer(//*[@os='p1'])"/>

    <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
    href="../common/binutils.xml"
    xpointer="xpointer(//*[@os='p2'])"/>

    <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
    href="../common/gcc-static.xml"
    xpointer="xpointer(//*[@os='p1'])"/>

    <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
    href="../common/gcc-static.xml"
    xpointer="xpointer(//*[@os='p2'])"/>

    <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
    href="../common/gcc-static.xml"
    xpointer="xpointer(//*[@os='aa'])"/>

    <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
    href="../common/gcc-static.xml"
    xpointer="xpointer(//*[@os='ab'])"/>

    <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
    href="../common/gcc-static.xml"
    xpointer="xpointer(//*[@os='ac'])"/>

    <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
    href="../common/gcc-static.xml"
    xpointer="xpointer(//*[@os='ad'])"/>

    <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
    href="../../temp-system/common/gmp.xml"
    xpointer="xpointer(//*[@os='p1'])"/>

    <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
    href="../../temp-system/common/gmp.xml"
    xpointer="xpointer(//*[@os='p2'])"/>

    <para os="ng">This ensures by default the compiler will look in
/tools/lib/../lib or /tools/lib/../lib64 as appropriate:</para>

<screen os="nh"><userinput>echo "
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_1 \"/tools/lib/\"
#define STANDARD_STARTFILE_PREFIX_2 \"\"" >> gcc/config/linux.h</userinput></screen>

    <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
    href="../common/gcc-static.xml"
    xpointer="xpointer(//*[@os='ai'])"/>

    <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
    href="../common/gcc-static.xml"
    xpointer="xpointer(//*[@os='aj'])"/>

    <para os="bd">Finally, disable <option>-B</option> in <filename>configure</filename>,
    so it doesn't pick up the host's header files:</para>

<screen os="be"><userinput>cp -v configure{,.orig}
sed -e  '/FLAGS_FOR_TARGET.*\/lib\//s@-B[^ ]*/lib/@@g' configure.orig > \
    configure</userinput></screen>

    <xi:include xmlns:xi="http://www.w3.org/2003/XInclude"
    href="../common/gcc-static.xml"
    xpointer="xpointer(//*[@os='f'])"/>

<screen os="bf"><userinput>AR=ar AS=as ../sysroot-toolchain/configure \
  --with-sysroot=${CLFS} --prefix=/cross-tools \
  --target=i686-pc-linux-gnu --with-local-prefix=/tools \
  --without-headers --with-newlib  --disable-nls \
  --disable-shared  --disable-decimal-float  --disable-libgomp \
  --disable-libmudflap --disable-libssp --disable-threads \
  --enable-languages=c --enable-64-bit-bfd --with-lib-path=/tools/lib</userinput></screen>

    <variablelist os="bg">
      <title>The meaning of the new configure options:</title>

      <varlistentry os="bg1">
        <term><parameter>--enable-languages=c,c++</parameter></term>
        <listitem>
          <para>This option ensures that only the C and C++ compilers are built.</para>
        </listitem>
      </varlistentry>

      <varlistentry os="bg2">
        <term><parameter>--enable-__cxa_atexit</parameter></term>
        <listitem>
          <para>This option allows use of __cxa_atexit, rather than atexit,
          to register C++ destructors for local statics and global objects
          and is essential for fully standards-compliant handling of destructors.
          It also affects the C++ ABI and therefore results in C++ shared libraries
          and C++ programs that are interoperable with other Linux distributions.</para>
        </listitem>
      </varlistentry>

      <varlistentry os="bg3">
        <term><parameter>--enable-c99</parameter></term>
        <listitem>
          <para>Enable C99 support for C programs.</para>
        </listitem>
      </varlistentry>

      <varlistentry os="bg4">
        <term><parameter>--enable-long-long</parameter></term>
        <listitem>
          <para>Enables long long support in the compiler.</para>
        </listitem>
      </varlistentry>

      <varlistentry os="bg5">
        <term><parameter>--enable-threads=posix</parameter></term>
        <listitem>
          <para>This enables C++ exception handling for multi-threaded code.</para>
        </listitem>
      </varlistentry>

    </variablelist>

    <para os="bh">Continue with compiling the package:</para>

<screen os="bi"><userinput>make</userinput></screen>

    <para os="bj">Install the package:</para>

<screen os="bk"><userinput>make install</userinput></screen>

  </sect2>

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

    <para>Details on this package are located in <xref
    linkend="contents-gcc" role="."/></para>

  </sect2>

</sect1>
