I am trying to create a makefile for my java program that incorporates multiple files. Previously, I had success creating a makefile for a single file using this:
QuickSort.class: QuickSort.java
javac -g QuickSort.java
clean: rm -f QuickSort.class
Since I need to it compile multiple files, I updated it like this:
Dijkstra.class:
Dijkstra3.java\
DirGraph.java
FibDijkstra.java\
FibHeap.java\
MinDijkstra.java\
MinHeap.java\
javac -g Dijkstra3.java
javac -g DirGraph.java
javac -g FibDijkstra.java
javac -g FibHeap.java
javac -g MinDijkstra.java
javac -g MinHeap.java
clean:
rm -f Dijkstra.class
When I try to run make on this, it produces the error "No rule to make target javac needed by Dijkstra.class". Am I close in what I have? How would I go about editing it to make it work correctly? Thanks!
EDIT: When retrying it, I must have changed something from the original variation. Now it produces a list of all the files with no break in between saying command doesn't exist. Obviously then, I am not correctly trying to read all the files.
EDIT 2: I know have
JFLAGS = -g
JC = javac
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSES = \
Dijkstra3.java\
DirGraph.java\
FibDijkstra.java\
FibHeap.java\
MinDijkstra.java\
MinHeap.java
default: classes
classes: $(CLASSES:.java=.class)
clean:
$(RM) *.class
When I run this, it doesn't produce any errors for the makefile. Instead it produces errors for the included files themselves. What is odd about this is, that in NetBeans, when I have them pulled up there are no errors? What could be the cause of this?
Here is the final solution I came up with:
JFLAGS = -g
JC = javac
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSES = \
Dijkstra3.java\
DirGraph.java\
FibDijkstra.java\
FibHeap.java\
MinDijkstra.java\
MinHeap.java
default: classes
classes: $(CLASSES:.java=.class)
clean:
$(RM) *.class