Here's an example of building the ObjectWeb ASM project into native code:
<target name="gcjlib" depends="compile"
description="Create native libraries for use with gcj" >
<taskdef name="gcjlib"
classname="org.spindazzle.ant.taskdefs.GcjLib" />
<gcjlib name="lib-org-objectweb-asm">
<classpath location="${out.build}" />
<fileset dir="${out.build}" />
</gcjlib>
</target>
Add this fragment to ASM's build.xml file and run "ant
gcjlib". On Linux, this will create a shared library called
lib-org-objectweb-asm.so. Once you install this library,
the gcj runtime's system classloader will pick up native
versions of these classes instead of interpreting any bytecode it
might find. This class loading feature is described in more detail in
the GCC
Manual.
Gcj is capable of compiling jar files directly into shared libraries. However this is often too demanding on memory and CPU for large jar files. gcjlib breaks the build process down into multiple steps - compiling groups of class files into a smaller number of intermediate object files before linking them together to create the final shared library. This has the added benefit of working around command line length limits on the build system.
In addition to automatic shared library construction, gcjlib will detect and attempt to resolve all library dependencies at link time. For instance, if you compile code that uses foo.bar.Zip, gcjlib will work with gcj to locate a shared library containing a native version of foo.bar.Zip and add that library to the final link line. gcjlib currently warns if it can't resolve dependencies. This will result in a shared library whose missing dependencies will have to be resolved at runtime.
To perform a simple test of gcjlib, run the following command once you extract the source:
$ ant gcjlibThis should eventually generate lib-org-spindazzle-ant-taskdefs.so.
http://www.spindazzle.org/gcjlib/gcjlib-0.7-1.src.rpm
http://www.spindazzle.org/gcjlib/gcjlib-0.7-1.noarch.rpm