Can I compile ANTLR to a binary executable (with GCJ?)?
- get & install gcj and libgcj. Both can be found at:
gcj is part of the GNU compiler (gcc 2.95.1) and libgcj is a separate library containing the Java runtime system.
- delete AWT dependend code (antlr/debug/misc directory)
- goto antlr root directory
- make the libantlr.so library
Note that you should compile class files, ICE's may occur when compiling the .java source files (I suppose because of Java 1.1 language features)
gcj -shared -fPIC -o libantlr.so --CLASSPATH=".:/usr/local/share/libgcj.zip" `find antlr -name "*.class"`
This generates a lot of output which can be ignored and hopefully a libantlr.so which can be copied into the LD_LIBRARY_PATH, eg to /usr/local/lib.
On my Linux host the result is a 2MB shared library which can be stripped ('strip libantlr.so') down to 1.1MB. It may be further reduced by selective compilation of only necessary classes ...
- make the cantlr binary
gcj --main=antlr.Tool antlr/Tool.class --CLASSPATH=".:/usr/local/share/libgcj.zip" -o cantlr -L/usr/local/lib -lantlr
This should result in a small binary (56K on my host) which just loads the libantlr.so. You can copy the binary to /usr/local/bin.
- go to examples/java and test cantlr
cd examples/java ../../cantlr java.g
it should take less than 1s on a P3 host
How to compile antlr generated source with gcj
- make libantlr.so as described above
- generate your Java stuff as usual, then compile using gcj and
cantlr Grammar.g gcj -c -o Lexer.o Lexer.java gcj -c -o Parser.o Parser.java gcj -c -o Tokens.o Tokens.java gcj -c -o Main.o Main.java gcj --main=Main -o Main Main.o Lexer.o Parser.o Tokens.o -lantlr