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/javacJFLAGS=-gCPP=gcc -EDEST=/tmp/.SUFFIXES: .class .javaTARGETS= 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/javacJFLAGS=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.javaCounter.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.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may