<?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-gcc-static" role="wrap">
  <?dbhtml filename="gcc-static.html"?>

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

  <indexterm zone="ch-cross-tools-gcc-static">
    <primary sortas="a-GCC">GCC</primary>
    <secondary>cross tools, static</secondary>
  </indexterm>

  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  href="../../final-system/common/gcc.xml"
  xpointer="xpointer(//*[@role='package'])"/>

  <sect2 role="installation">
    <title>Installation of Cross GCC Compiler with Static libgcc
    and no Threads</title>

    <para os="p1">The following patch contains a number of updates to the
    &gcc-version; branch by the GCC developers:</para>

    <screen os="p2"><userinput>patch -Np1 -i ../&gcc-branch_update-patch;</userinput></screen>

    <para os="aa">Make a couple of essential adjustments to the
    <filename>specs</filename> file to ensure GCC uses our build
    environment:</para>

<screen os="ab"><userinput>patch -Np1 -i ../&gcc-specs-patch;</userinput></screen>

    <para os="ag">Change the StartFile Spec and Standard Include Dir so that
    GCC looks in <filename class="directory">/tools</filename>:</para>

<screen os="ah"><userinput>echo -en '#undef STANDARD_INCLUDE_DIR\n#define STANDARD_INCLUDE_DIR "/tools/include/"\n\n' >> gcc/config/linux.h
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</userinput></screen>

    <para os="ai">Now alter <command>gcc</command>'s c preprocessor's default
    include search path to use <filename class="directory">/tools</filename> only:</para>

<screen os="aj"><userinput>cp -v gcc/Makefile.in{,.orig}
sed -e "s@\(^CROSS_SYSTEM_HEADER_DIR =\).*@\1 /tools/include@g" \
    gcc/Makefile.in.orig &gt; gcc/Makefile.in</userinput></screen>

    <para os="t1">We will create a dummy <filename>limits.h</filename> so
    the build will not use the one provided by the host distro:</para>

<screen os="t2"><userinput>touch /tools/include/limits.h</userinput></screen>

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

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

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

<screen os="al"><userinput>AR=ar LDFLAGS="-Wl,-rpath,/cross-tools/lib" \
  ../gcc-&gcc-version;/configure --prefix=/cross-tools \
  --build=${CLFS_HOST} --host=${CLFS_HOST} --target=${CLFS_TARGET} \
  --with-sysroot=${CLFS} --with-local-prefix=/tools --disable-nls \
  --disable-shared --disable-static --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 \
  --enable-cloog-backend=isl</userinput></screen>

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

      <varlistentry>
        <term><parameter>--prefix=/cross-tools</parameter></term>
        <listitem>
          <para>This tells the configure script to prepare to install the 
          package in the <filename class="directory">/cross-tools</filename>
          directory.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--host=${CLFS_HOST}</parameter></term>
        <listitem>
          <para>When used with --target, this creates a cross-architecture
          executable that creates files for ${CLFS_TARGET} but runs on ${CLFS_HOST}.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--target=${CLFS_TARGET}</parameter></term>
        <listitem>
          <para>When used with --host, this creates a cross-architecture
          executable that creates files for ${CLFS_TARGET} but runs on ${CLFS_HOST}.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--with-sysroot=${CLFS}</parameter></term>
        <listitem>
          <para>Tells GCC to concider ${CLFS} as the root file system.</para>
        </listitem>
      </varlistentry>

     <varlistentry>
        <term><parameter>--with-local-prefix=/tools</parameter></term>
        <listitem>
          <para>The purpose of this switch is to remove <filename
          class="directory">/usr/local/include</filename> from
          <command>gcc</command>'s include search path. This is not
          absolutely essential, however, it helps to minimize the
          influence of the host system.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--disable-nls</parameter></term>
        <listitem>
          <para>This disables internationalization as i18n is not needed for the 
          cross-compile tools.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--disable-shared</parameter></term>
        <listitem>
          <para>Disables the creation of the shared libraries.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--without-headers</parameter></term>
        <listitem>
          <para>Disables GCC from using the target's Libc when cross compiling.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--with-newlib</parameter></term>
        <listitem>
          <para>Tells GCC that the target libc will use 'newlib'.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--disable-decimal-float</parameter></term>
        <listitem>
          <para>Disables support for the C decimal floating point extension.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--disable-libgomp</parameter></term>
        <listitem>
          <para>Disables the creation of runtime libraries used by GOMP.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--disable-libmudflap</parameter></term>
        <listitem>
          <para>Disables the creation of runtime libaries used by libmudflap.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--disable-libssp</parameter></term>
        <listitem>
          <para>Disables the use of Stack Smashing Protection for runtime libraries.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--disable-threads</parameter></term>
        <listitem>
          <para>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.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--enable-languages=c</parameter></term>
        <listitem>
          <para>This option ensures that only the C compiler is built.</para>
        </listitem>
      </varlistentry>

    </variablelist>

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

<screen os="ao"><userinput>make all-gcc all-target-libgcc</userinput></screen>

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

<screen os="aq"><userinput>make install-gcc install-target-libgcc</userinput></screen>

  </sect2>

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

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

  </sect2>

</sect1>
