If you are porting code from C to Java it is often useful to be able to use the C pre-proccessor (cpp or cc -E). This tip shows you how to create a makefile that will allow you to run cpp on your java code. First you need to do: mkdir cpp, before you start. Assume you want to compile the classes file1.java and file2.java.
JCC=/usr/local/java/bin/javacJFLAGS=-gCPP=gcc -EDEST=/tmp/.SUFFIXES: .class .javaTARGETS= file1.class file2.class.java.class: /bin/rm -f dummy.c ln -s $ cpp/$
The other version allows you to just run cpp on selected files. The files that have the extension .javacpp will have the C Pre-processor run on them.
JCC=/usr/local/java/bin/javacJFLAGS=CPP=gcc -E.SUFFIXES : .class .java .javacpp.javacpp.java: cp $ $*.java chmod -w $*.java .java.class : $(JCC) $(JAVAFLAGS) $
Note that you need to add the dependences, otherwise when you change .javacpp, the file is still just built from the .java file.