Java的makefile [英] makefile for java

查看:126
本文介绍了Java的makefile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白我的Makefile做错了什么:

i don't understand what i did wrong with my makefile :


JAVA_SRCS:=$(wildcard tasks/src/*.java)
JAVA_CLASSES=$(subst /src/,/build/,$(JAVA_SRCS:.java=.class))
JFLAGS=-cp jar/octobot.jar -d tasks/build
JC=javac

.SUFFIXES: .java .class

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

default: build

build: $(JAVA_CLASSES)

clean:
 $(RM) tasks/build/*.class

我收到此错误:


make: *** No rule to make target `tasks/build/ClickTask.class', needed by `classes'.  Stop.
zsh: exit 2     make

但是奇怪的是,当我像这样重新编写规则 build 时:

But strangely, when i re-write the rule build like this :


build: $(JAVA_SRCS:.java=.class)

没有错误,该规则已启动,但每次都会执行(并且不正确)

no error, the rule is launched but does it every time (and it's not correct)

推荐答案

@Dean Povey是正确的:您不能使用后缀规则来执行此操作,因为它们与源代码位于同一目录中.但是,您可以使用GNU Make模式规则来执行此操作(并且您已经在Makefile中使用了GNUMake-isms,等等):

@Dean Povey is correct: you can't do this with suffix rules, because they look in the same directory as the source. You can, however, do this with a GNU Make pattern rule (and you're already using GNUMake-isms in your Makefile, so whatever):

tasks/build/%.class: tasks/src/%.java
        $(JC) $(JFLAGS) $<

但是,请注意,make不适合构建Java源,因为一个.java文件可能会导致许多.class文件(例如内部类). Automake解决此问题的方法是通过一次调用javac编译所有内容,并写出一个时间戳文件(例如echo timestamp > classnoinst.stamp).然后,需要构建的Java源代码的所有内容都取决于该标记文件,并且make clean会将.stamp.class文件一起删除.

Note, however, that make is ill-suited to building java source as one .java file can result in many .class files (inner classes, for instance). Automake's approach to this problem is to compile everything in a single call to javac and write out a timestamp file (echo timestamp > classnoinst.stamp, for example). Then anything that needs the java sources built depends on that stamp file and make clean removes the .stamp along with the .class files.

这篇关于Java的makefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆