Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use GCJ with Ant?

Tags:

java

ant

gcj

I'm fairly new to both Apache Ant and GCJ, and I'm having a hard time trying to build with GCJ via Ant.

My app is in Scala, so I need to use GCJ to take .class files as source. No problem compiling .scala to .class with Ant.

First I figured out how to manually compile a .class file to .o (object), this way:

gcj --classpath=(...) -c (somepath)MouseClickListener.class -o (somepath)MouseClickListener.o

I see here that Ant supports GCJ compilation through the javac tag. So I figured this should work:

<target name="gcjCompile" depends="compile">
    <mkdir dir="${object.dir}" />
    <javac srcdir="${build.dir}"
           destdir="${object.dir}"
           compiler="gcj"
           executable="C:/gcc/gcc-4.3/bin/gcj.exe"
           classpathref="gcjProject.classpath">
        <include name="**/*.class"/>
    </javac>
</target>

But this javac task does nothing and I get no errors. Any clues? Thanks

like image 402
Germán Avatar asked Mar 08 '10 21:03

Germán


1 Answers

It sounds like you want to link your app into a native executable. That means that you've already compiled the source into JVM bytecode (as you've figured out to do by compiling .scala into .class files). You'll need to run the gcj command manually using the <exec> task to compile the bytecode into gcc object code files.

I'd recommend something like this:

<property name="main.class" value="Main" />
<property name="class.dir" value="${basedir}/classes" />
<target name="compile">
  <mkdir dir="${class.dir}" />
  <javac srcdir="${build.dir}"
         destdir="${class.dir}"
         compiler="gcj"
         executable="C:/gcc/gcc-4.3/bin/gcj.exe"
         classpathref="gcjProject.classpath">
    <include name="**/*.java"/>
  </javac>
</target>
<target name="link" depends="compile">
  <mkdir dir="${object.dir"} />
  <exec cmd="C:/gcc/gcc-4.3/bin/gcj.exe">
    <arg value="-classpath=${object.dir}" />
    <arg value="-c" />
    <arg value="*.class" />
  </exec>
</target>

Keep in mind that you need to define the build.dir and object.dir properties, and you may need to add a depends task before the javac in the compile target (or just recompile from scratch each time). I may have missed a lot of things, you should check the manual pages (for gcj, gcc, and ant) if it doesn't work at first.

like image 110
SEK Avatar answered Oct 19 '22 15:10

SEK