Makefile同时编译C和Java程序
我有三个程序需要同时编译,2个用C编写,1个用java编写。当它们在 C 中时,我让所有三个 Makefile 一起工作,但后来用 java 重写了其中一个......有没有一种方法可以使用相同的 makefile 一次编译所有 3 个?
这是我当前的 Makefile:
CC=gcc
JC=javac
JFLAGS= -g
CFLAGS= -Wall -g -std=c99
LDFLAGS= -lm
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSES = kasiski.java kentry.java
ALL= ic ftable kasiski
all: $(ALL)
ic: ic.o
kasiski: $(CLASSES:.java=.class)
ftable: ftable.o
ic.o: ic.c ic.h
ftable.o: ftable.c ftable.h
.PHONY: clean
clean:
rm -rf core* *.class *.o *.gch $(ALL)
I have three programs that need to be compiled at the same time, 2 written in C and 1 in java. I had all three working with the Makefile when they were in C, but then rewrote one of them in java... is there a way to compile all 3 at once with the same makefile?
Here is my current Makefile:
CC=gcc
JC=javac
JFLAGS= -g
CFLAGS= -Wall -g -std=c99
LDFLAGS= -lm
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSES = kasiski.java kentry.java
ALL= ic ftable kasiski
all: $(ALL)
ic: ic.o
kasiski: $(CLASSES:.java=.class)
ftable: ftable.o
ic.o: ic.c ic.h
ftable.o: ftable.c ftable.h
.PHONY: clean
clean:
rm -rf core* *.class *.o *.gch $(ALL)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以一次性编译它们。如果您的“all”目标依赖于所有三个应用程序,那么“make all”应该构建所有这些应用程序。您可以添加“-j3”以使用三个单独的线程和/或进程进行实际编译(不清楚“一次”的含义)。另外,这里还有一些批评:
有关更多说明,请参阅我的 Makefile 教程< /a>.也就是说,您可能需要考虑更现代的构建系统,例如 Bazel 或 Gradle。这些系统被设计为更易于使用、更不易出错、更便携(因为它们使便携做事变得更容易)并且速度更快。
Yes, you can compile them all at once. If your "all" target depends on all three applications, then "make all" should build all of them. You can throw in "-j3" to actually compile using three separate threads and/or processes (it isn't clear what you mean by "at once"). Also, a couple criticisms here:
For more explanation, please see my Makefile tutorial. That said, you may want to consider a more modern build system such as Bazel or Gradle. These systems are designed to be much simpler to use, less error prone, more portable (because they make it easier to do things portably), and faster.