<?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-java-download-http  "http://ftp.gnu.org/gnu/gcc/gcc-&gcc-version;/gcc-&gcc-version;.tar.bz2">
  <!ENTITY gcc-java-download-ftp   "ftp://ftp.gnu.org/gnu/gcc/gcc-&gcc-version;/gcc-&gcc-version;.tar.bz2">
  <!ENTITY gcc-java-md5sum         "4df8ee253b7f3863ad0b86359cd39c43">
  <!ENTITY gcc-java-size           "86 MB">
  <!ENTITY gcc-java-buildsize      "3.0 GB">
  <!ENTITY gcc-java-time           "84 SBU (including 70 SBU for tests)">

  <!ENTITY ecj-download-ftp    "ftp://sourceware.org/pub/java/ecj-latest.jar">

  <!ENTITY antlr-version       "4.2.2">
  <!ENTITY antlr-download-http "http://www.antlr.org/download/antlr-&antlr-version;-complete.jar">
]>

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

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

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

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

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

    <para>See the introduction to the Java language and system at
    <xref linkend="java"/>. The GNU Compiler Collection (GCC) contains
    a Java compiler to native code. Together with the
    <application>ecj</application> Java compiler from Eclipse (to bytecode),
    it provides a way to build an acceptable JVM from source. However, since
    the release of <application>OpenJDK</application>, the development
    of GCC-Java has almost stopped, and the built JVM is an old version.
    One reason to build
    this system is that it can be used to bootstrap <xref linkend="openjdk"/>,
    without the need for downloading a Java binary.</para>

    &lfs77_checked;

    <caution>
      <para>Using the instructions on this page will have the effect that
      the C and C++ compiler and libraries will be reinstalled, overwriting
      the ones on your system. This may lead to some issues. Please read the
      note and caution on the <xref linkend="gcc"/> page.</para>
    </caution>

    <bridgehead renderas="sect3">Package Information</bridgehead>
    <itemizedlist spacing="compact">
      <listitem>
        <para>Download (HTTP): <ulink url="&gcc-java-download-http;"/></para>
      </listitem>
      <listitem>
        <para>Download (FTP): <ulink url="&gcc-java-download-ftp;"/></para>
      </listitem>
      <listitem>
        <para>Download MD5 sum: &gcc-java-md5sum;</para>
      </listitem>
      <listitem>
        <para>Download size: &gcc-java-size;</para>
      </listitem>
      <listitem>
        <para>Estimated disk space required: &gcc-java-buildsize;</para>
      </listitem>
      <listitem>
        <para>Estimated build time: &gcc-java-time;</para>
      </listitem>
    </itemizedlist>

    <bridgehead renderas="sect3">Additional Downloads</bridgehead>
    <itemizedlist spacing="compact">
      <listitem>
        <para>
          Eclipse Java compiler:
          <ulink url="&ecj-download-ftp;"/>
        </para>
      </listitem>
      <listitem>
        <para>
          ANTLR binary, for building <command>gjdoc</command> (optional):
          <ulink url="&antlr-download-http;"/>
        </para>
      </listitem>
<!--      <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">Required</bridgehead>
    <para role="required">
      <xref linkend="zip"/>,
      <xref linkend="unzip"/>, and
      <xref linkend="which"/>
    </para>

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

    <bridgehead renderas="sect4">Optional</bridgehead>
    <para role="optional">
      <xref linkend="gtk2"/> and
      <ulink url="https://download.gnome.org/sources/libart_lgpl/">
        Libart
      </ulink> for building the AWT peer
    </para>

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

  </sect2>

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

    <para>The instructions below assume that the C and C++ compilers have
    the same version as the one you are installing, so that a
    <quote>bootstrap</quote> is not necessary. If you are upgrading
    the GCC version, then remove the <option>--disable-bootstrap</option> from
    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 Java</application> by running the
    following commands:</para>

<screen><userinput>sed -i 's/\(install.*:\) install-.*recursive/\1/' libffi/Makefile.in         &amp;&amp;
sed -i 's/\(install-data-am:\).*/\1/'             libffi/include/Makefile.in &amp;&amp;
<!--
patch -Np1 -i ../gcc-&gcc-version;-upstream_fixes-1.patch &amp;&amp;
-->

cp ../ecj-latest.jar ./ecj.jar &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           \
    --disable-bootstrap          \
    --enable-cloog-backend=isl   \
    --enable-java-home           \
    --with-jvm-root-dir=/opt/gcj \
    --with-antlr-jar=$(pwd)/../antlr-&antlr-version;-complete.jar \
    --enable-languages=java &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 job control 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} &amp;&amp;

gcj -o ecj ../ecj-latest.jar \
    --main=org.eclipse.jdt.internal.compiler.batch.Main &amp;&amp;
mv ecj /usr/bin &amp;&amp;
ln -sfv ../../../usr/bin/ecj /opt/gcj/bin/javac</userinput></screen>

  </sect2>

  <sect2 role="commands">
    <title>Command Explanations</title>

    <para>The two <command>sed</command> commands prevent the
    installation of the <application>libffi</application> library bundled
    with <application>GCC</application>, since it is outdated compared to
    <xref linkend="libffi"/>.</para>
<!--
    <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.
    </para>

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

    <para>
      <parameter>--disable-bootstrap</parameter>: Prevents the C and C++
      compilers to recompile themselves. You should use this switch only
      if the installed C and C++ compilers are the same version as the
      ones you install.
    </para>

    <para>
      <parameter>--enable-java-home</parameter>: Creates a directory
      layout similar to that of a JVM.
    </para>

    <para>
      <parameter>--with-jvm-root-dir=/opt/gcj</parameter>: Installs
      the JVM in the specified location.
    </para>

    <para>
      <parameter>--with-antlr-jar=...</parameter>: Specifies the location of
      <application>ANTLR</application>, which is needed to build
      <command>gjdoc</command>. Remove if you have not downloaded antlr.
    </para>

    <para>
    <parameter>--enable-languages=java</parameter>:
    This command identifies which language to build. Note it is unavoidable
    that the <application>C</application> and <application>C++</application>
    compilers be built too.</para>

    <para>
      <option>--enable-java-awt=gtk</option>: Allows to build the Java AWT
      <application>GTK+2</application> peer. Needed to have a fully functional
      JVM.
    </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>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 commands changes the ownership to the
    <systemitem class="username">root</systemitem> user and group.</para>

    <para>
      <command>gcj -o ecj ...</command>: compiles the eclipse compiler to
      native code, which is much faster than bytecode. This compiler is
      then used as a <command>javac</command> replacement in the JVM.
    </para>

  </sect2>

  <sect2 role="configuration">
    <title>Configuring GCC-Java</title>

    <sect3>
      <title>Configuration Information</title>

      <para>
        The configuration is the same as for <xref linkend="openjdk"/>,
        replacing <filename class="directory">/opt/jdk</filename> with
        <filename class="directory">/opt/gcj</filename>.
      </para>

    </sect3>

  </sect2>

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

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

      <seglistitem>
        <seg>
          aot-compile, ecj, gappletviewer, gc-analyze, gcj, gcj-dbtool,
          gcjh, gij, gjar, gjarsigner, gjavah, gjdoc, gkeytool, gnative2ascii,
          gorbd, grmic, grmid, grmiregistry, gserialver, gtnameserv, jcf-dump,
          jv-convert, rebuild-gcj-db. Symbolic links to these files are located
          in <filename class="directory">/opt/gcj/bin</filename>
        </seg>
        <seg>
          libgcj_bc.so, libgcj.so, libgcj-tools.so
          libgij.so, and numerous other
          run-time libraries and executables in
          <filename class="directory">/usr/lib/gcc</filename> and
          <filename class="directory">/usr/libexec/gcc</filename>
        </seg>
        <seg>
          /usr/include/c++/&gcc-version;/{gcj,gnu,java,javax,org,sun},
          /usr/lib/gcj-&gcc-version;-15,
          /usr/lib/security, /opt/gcj/{bin,jre,include,lib} and
          /usr/share/java
        </seg>
      </seglistitem>
    </segmentedlist>

    <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>

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

      <varlistentry id="aot-compile">
        <term><command>aot-compile</command></term>
        <listitem>
          <para>searches a directory for Java bytecode and uses
          <command>gcj</command> to compile it to native code.</para>
          <indexterm zone="gcc aot-compile">
            <primary sortas="b-aot-compile">aot-compile</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="ecj">
        <term><command>ecj</command></term>
        <listitem>
          <para>is the eclipse compiler.</para>
          <indexterm zone="gcc ecj">
            <primary sortas="b-ecj">ecj</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gappletviewer">
        <term><command>gappletviewer</command></term>
        <listitem>
          <para>loads and run a <application>Java</application> applet.</para>
          <indexterm zone="gcc gappletviewer">
            <primary sortas="b-gappletviewer">gappletviewer</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gc-analyze">
        <term><command>gc-analyze</command></term>
        <listitem>
          <para>analyzes garbage collector (GC) memory dumps from
          <application>Java</application> code.</para>
          <indexterm zone="gcc gc-analyze">
            <primary sortas="b-gc-analyze">gc-analyze</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gcj">
        <term><command>gcj</command></term>
        <listitem>
          <para>is an ahead-of-time compiler for the
          <application>Java</application> language.</para>
          <indexterm zone="gcc gcj">
            <primary sortas="b-gcj">gcj</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gcj-dbtool">
        <term><command>gcj-dbtool</command></term>
        <listitem>
          <para>is a tool for creating and manipulating class file mapping
          databases.</para>
          <indexterm zone="gcc gcj-dbtool">
            <primary sortas="b-gcj-dbtool">gcj-dbtool</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gcjh">
        <term><command>gcjh</command></term>
        <listitem>
          <para>generates header files from <application>Java</application>
          class files.</para>
          <indexterm zone="gcc gcjh">
            <primary sortas="b-gcjh">gcjh</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gij">
        <term><command>gij</command></term>
        <listitem>
          <para>is the GNU interpreter for <application>Java</application>
          bytecode.</para>
          <indexterm zone="gcc gij">
            <primary sortas="b-gij">gij</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gjar">
        <term><command>gjar</command></term>
        <listitem>
          <para>is an (partial) implementation of the <command>jar</command>
          utility that comes with Sun's JDK.</para>
          <indexterm zone="gcc gjar">
            <primary sortas="b-gjar">gjar</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gjarsigner">
        <term><command>gjarsigner</command></term>
        <listitem>
          <para>is a Java ARchive (JAR) file signing and verification
          tool.</para>
          <indexterm zone="gcc gjarsigner">
            <primary sortas="b-gjarsigner">gjarsigner</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gjavah">
        <term><command>gjavah</command></term>
        <listitem>
          <para>generates header files from Java class files.</para>
          <indexterm zone="gcc gjavah">
            <primary sortas="b-gjavah">gjavah</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gjdoc">
        <term><command>gjdoc</command></term>
        <listitem>
          <para>is a documentation tool similar to <command>javadoc</command>.
          </para>
          <indexterm zone="gcc gjdoc">
            <primary sortas="b-gjdoc">gjdoc</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gkeytool">
        <term><command>gkeytool</command></term>
        <listitem>
          <para>manages private keys and public certificates in a
          <application>Java</application> environment.</para>
          <indexterm zone="gcc gkeytool">
            <primary sortas="b-gkeytool">gkeytool</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gnative2ascii">
        <term><command>gnative2ascii</command></term>
        <listitem>
          <para>is an encoding converter for <application>Java</application>.</para>
          <indexterm zone="gcc gnative2ascii">
            <primary sortas="b-gnative2ascii">gnative2ascii</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gorbd">
        <term><command>gorbd</command></term>
        <listitem>
          <para>is an object request broker daemon.</para>
          <indexterm zone="gcc gorbd">
            <primary sortas="b-gorbd">gorbd</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="grmic-gcc">
        <term><command>grmic</command></term>
        <listitem>
          <para>generates stubs for Remote Method Invocation.</para>
          <indexterm zone="gcc grmic-gcc">
            <primary sortas="b-grmic">grmic</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="grmid-gcc">
        <term><command>grmid</command></term>
        <listitem>
          <para>RMI activation system daemon.</para>
          <indexterm zone="gcc grmid-gcc">
            <primary sortas="b-grmid">grmid</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="grmiregistry-gcc">
        <term><command>grmiregistry</command></term>
        <listitem>
          <para> starts a remote object registry on the current host.</para>
          <indexterm zone="gcc grmiregistry-gcc">
            <primary sortas="b-grmiregistry">grmiregistry</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gserialver">
        <term><command>gserialver</command></term>
        <listitem>
          <para> prints the serialVersionUID of the specified class.</para>
          <indexterm zone="gcc gserialver">
            <primary sortas="b-gserialver">gserialver</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="gtnameserv">
        <term><command>gtnameserv</command></term>
        <listitem>
          <para> starts a naming service.</para>
          <indexterm zone="gcc gtnameserv">
            <primary sortas="b-gtnameserv">gtnameserv</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="jcf-dump">
        <term><command>jcf-dump</command></term>
        <listitem>
          <para>prints information about <application>Java</application>
          class files.</para>
          <indexterm zone="gcc jcf-dump">
            <primary sortas="b-jcf-dump">jcf-dump</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="jv-convert">
        <term><command>jv-convert</command></term>
        <listitem>
          <para>converts files from one encoding to another.</para>
          <indexterm zone="gcc jv-convert">
            <primary sortas="b-jv-convert">jv-convert</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="rebuild-gcj-db">
        <term><command>rebuild-gcj-db</command></term>
        <listitem>
          <para>Merge the per-solib databases made by
          <application>aot-compile</application> into one system-wide
          database.</para>
          <indexterm zone="gcc rebuild-gcj-db">
            <primary sortas="b-rebuild-gcj-db">rebuild-gcj-db</primary>
          </indexterm>
        </listitem>
      </varlistentry>

    </variablelist>

  </sect2>

</sect1>
