2012-03-30 62 views
0

运行它后,我有以下makefile,我对makefile进行了一些更改,现在当我运行它时,我得到一个“make:无法为`default'完成”。我如何强制它重建?我执行“make”并且“make clean”,当我输入“make”时我仍然收到错误消息。为Java/Linux生成文件

另外,如何获取src目录中的log4.properties文件以复制到目标目录(在make文件和命令行中:javac -classpath src:lib/log4j-1.2 .16.jar src/*。java -d bin)?

 
# 
# define compiler and compiler flag variables 
# 

JFLAGS = -g -cp .:src:lib/log4j-1.2.16.jar 
JC = javac 


# 
# Clear any default targets for building .class files from .java files; we 
# will provide our own target entry to do this in this makefile. 
# make has a set of default targets for different suffixes (like .c.o) 
# Currently, clearing the default for .java.class is not necessary since 
# make does not have a definition for this target, but later versions of 
# make may, so it doesn't hurt to make sure that we clear any default 
# definitions for these 
# 

.SUFFIXES: .java .class 


# 
# Here is our target entry for creating .class files from .java files 
# This is a target entry that uses the suffix rule syntax: 
# DSTS: 
#  rule 
# 'TS' is the suffix of the target file, 'DS' is the suffix of the dependency 
# file, and 'rule' is the rule for building a target 
# '$*' is a built-in macro that gets the basename of the current target 
# Remember that there must be a before the command line ('rule') 
# 

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


# 
# CLASSES is a macro consisting of 4 words (one for each java source file) 
# 

CLASSES = \ 
    src/MatrixDriver.java \ 
    src/ConcreteMatrix.java \ 
    src/Matrix.java \ 
    src/Submatrix.java 


# 
# the default make target entry 
# 

default: classes 


# 
# This target entry uses Suffix Replacement within a macro: 
# $(name:string1=string2) 
# In the words in the macro named 'name' replace 'string1' with 'string2' 
# Below we are replacing the suffix .java of all words in the macro CLASSES 
# with the .class suffix 
# 

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


# 
# RM is a predefined macro in make (RM = rm -f) 
# 

clean: FORCE 
    $(RM) *.class 

FORCE: 

+0

你改变了什么? – surfen 2012-03-30 00:51:32

+0

我为输出目录添加了-d bin,但只是拿出来了。我仍然得到了make:'default'没有什么可做的。 – user994165 2012-03-30 01:05:56

+2

有点偏离主题,但您可能需要查看更多针对Java的构建工具,例如Ant或Maven。能够在类路径中放置'**/*。jar'变得非常方便,一旦你获得了更多的依赖关系。 – Bruno 2012-03-30 01:23:16

回答

2

的问题是这样的:

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

没有做什么,你认为它。也许你的意思是这样的?

%.class: %.java 
    $(JC) $(JFLAGS) $^ 
+0

当我做出改变时,我得到这个:“makefile:34:***目标模式不包含'%'。停止。” – user994165 2012-03-31 05:50:35

0

我没仔细看过你的Makefile,我不认为自己是一个化妆专家 但

  1. 似乎没有要在Makefile文件本身
  2. 任何依赖你改变的是Makefile

使我认为正确的行为正是你所描述的。也许你可以添加一个依赖到Makefile。

0

确保没有文件或目录称为类。然后,Make可以假设没有更多的事情要做。