Java Makefile Error

I had this error while trying to compile my Java project with the Makefile I created.

Error:

make: There is no rule for creating target classes src/edu/osu/lispinterpreter/output/*.class', needed by . Stop. *

Makefile Content:

 JFLAGS = -g JC = javac .SUFFIXES: .java .class .java.class: $(JC) $(JFLAGS) $*.java CLASSES = \ src/edu/osu/lispinterpreter/tokenizer/*.java \ src/edu/osu/lispinterpreter/core/*.java \ src/edu/osu/lispinterpreter/output/*.java \ src/edu/osu/lispinterpreter/exceptions/*.java \ src/edu/osu/lispinterpreter/input/InputParser.java \ src/edu/osu/lispinterpreter/input/ReadInputString.java default: classes classes: $(CLASSES:.java=.class) clean: $(RM) *.class 

Can someone give me a hand with a makefile, please?

I am using Eclipse btw.

+4
source share
3 answers

You either list all the source files separately, or use the wildcard directive in the Makefile to automatically match the files.

Also from your comments, it looks like the package names for java files are: edu.osu.lispinterpreter.* .

Therefore, I would suggest moving the Makefile to the src directory and making these changes to the Makefile.

 CLASSES := $(wildcard edu/osu/lispinterpreter/tokenizer/*.java) CLASSES += $(wildcard edu/osu/lispinterpreter/core/*.java) CLASSES += $(wildcard edu/osu/lispinterpreter/output/*.java) CLASSES += $(wildcard edu/osu/lispinterpreter/exceptions/*.java) CLASSES += edu/osu/lispinterpreter/input/InputParser.java CLASSES += edu/osu/lispinterpreter/input/ReadInputString.java 

The java compiler should be able to select class definitions from other packages if the package name matches the directory structure without writing explicit dependencies to the Makefile .

+1
source

From http://www.gnu.org/software/make/manual/html_node/Wildcard-Pitfall.html#Wildcard-Pitfall

If the wildcard does not match the files, it remains as

It seems src / edu / osu / lispinterpreter / output is empty, so src / edu / osu / lispinterpreter / output / *. java does not correspond to any file and remains as is, which is not what it is intended. Using a wildcard function , this can be avoided.

The solution would be to replace

 src/edu/osu/lispinterpreter/output/*.java 

by

 $(wildcard src/edu/osu/lispinterpreter/output/*.java) 

etc. for all other lines, I think

+2
source

I think the problem is that you are using * in the CLASSES variable. The way you wrote this variable is populated with a list of "file names" that contain * ... characters that will be distributed throughout the rest of the processing.

You need to either list the classes individually, or do something to tell Make for the "glob" list. If you are using GNU Make, the wildcard function should do the trick.

But note that it will not work in other versions of Make, so you have a portability issue with the Makefile. (Which brings me back to my comment that Ant is better.)


And as soon as you finish this, you have a problem: if you compile Java classes every time:

  • your build will be very slow ... 'cos every javac command launches a JVM (assuming you use the Hotspot or OpenJDK toolchains)
  • you need to build the classes in the correct order ... according to the dependencies inherent in the source code,
  • you need to add these dependencies to the Makefile (!!!) and
  • If you have dependency cycles, you have problems!

With enough patience, you can create a Makefile that can handle this, but it is really difficult, and the resulting Makefile will be fragile. Realistic alternatives are:

  • just create all the /.java files in one javac command, regardless of dependencies,
  • add a "make depend" rule that uses something to parse source code or bytecode files and create dependencies in the Makefile.

Or just use Ant.

Literature:

+1
source

All Articles