5

我需要能够编译我的程序,然后每次使用不同的 .txt 文件作为第一个命令行参数执行 3 次不同的时间,而这一切都需要使用单个“make”命令来完成。我希望我的 Makefile 执行的相应终端命令如下:

javac MainDriver.java FSA.java State.java Transition.java
java MainDriver test1.txt
java MainDriver test2.txt
java MainDriver test3.txt

这是我目前拥有的:

JC = javac
JCR = java

.SUFFIXES: .java .class
.java.class:
    $(JC) $*.java

CLASSES = \
    MainDriver.java \
    FSA.java \
    State.java \
    Transition.java 

default: classes

classes: $(CLASSES:.java=.class)

clean:
    $(RM) *.class *~
4

1 回答 1

2
JC = javac
JCR = java

.SUFFIXES: .java .class
.java.class:
    $(JC) $*.java

CLASSES = \
    MainDriver.java \
    FSA.java \
    State.java \
    Transition.java 

TXT_FILES = \
    test1.txt \
    test2.txt \
    test3.txt \

default: classes exec-tests

classes: $(CLASSES:.java=.class)

clean:
    $(RM) *.class *~

exec-tests: classes
    set -e; \
    for file in $(TXT_FILES); do $(JCR) MainDriver $$file; done;


.PHONY: default clean classes exec-tests
于 2013-02-28T02:30:38.827 回答