Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Advanced
Mar 22, 2000

Using the C Pre-Processor

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/javac
JFLAGS=-g
CPP=gcc -E
DEST=/tmp/
.SUFFIXES: .class .java
TARGETS= file1.class file2.class
.java.class:
 /bin/rm -f dummy.c
 ln -s $< dummy.c
 $(CPP) dummy.c | grep -v '^#' > cpp/$<
 $(JCC) $(JFLAGS) cpp/$<
 cp cpp/*.class /home/cameron/xg/x/classes/
 cp cpp/*.class ./
all: $(TARGETS)
clean:
 /bin/rm -f *.class 
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/javac
JFLAGS=
CPP=gcc -E
.SUFFIXES : .class .java .javacpp
.javacpp.java:
 cp $< $*.c
 $(CPP) $*.c | grep -v '^#' > $*.java
 chmod -w $*.java
 .java.class :
 $(JCC) $(JAVAFLAGS) $<
 all: Counter.class Connect.class
 mv *class $(DEST)
Counter.class: Counter.java
Counter.java: Counter.javacpp
Note that you need to add the dependences, otherwise when you change .javacpp, the file is still just built from the .java file.
Manoj K.
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date