我怎样才能让 make 将二进制文件放在不同的位置?
简短而简单的问题,但我似乎在这里遇到了写作障碍:
假设我在与用于构建程序的 makefile 相同的目录中有一个源代码文件:
confus@confusion:~/prog$ ls
binaries includes main.c Makefile
How do I get make to put the binaries for my main.c
在 binaries
目录中?然后,在第二次运行时, make 应该像平常一样查看二进制文件是否是最新的(并且不要再次编译它)。
我的想法是这样的:
# Makefile
.PHONY: all
SOURCES := $(wildcard *.c)
TARGETS := $(subst %.c,binaries/%.o,$(SOURCES))
all:$(TARGETS)
$(TARGETS):$(SOURCES)
./compile "$(subst .o,.c,$(@F))" -o "$@"
Short and easy question, but I seem to have a writer's block here:
Suppose I have a source code file in the same directory as the makefile I use to build the program:
confus@confusion:~/prog$ ls
binaries includes main.c Makefile
How do I get make to put the binaries for my main.c
in the binaries
dir? Afterwards on a second run make should see if the binary file there is up to date (and don't compile it again) just like normal.
My thought was something like this:
# Makefile
.PHONY: all
SOURCES := $(wildcard *.c)
TARGETS := $(subst %.c,binaries/%.o,$(SOURCES))
all:$(TARGETS)
$(TARGETS):$(SOURCES)
./compile "$(subst .o,.c,$(@F))" -o "$@"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要说所有目标都依赖于所有源,而是有一个模式规则,
您可能还需要使用 vpath
修订:
你的替代品也有问题...
这个测试有效(只是为了编译单独的 .o 文件,您仍然需要链接它们,这将是一个非常简单的规则)
Don't say all targets depend on all sources, instead have a pattern rule
you may also need to use a vpath
Revised:
You also had a problem with your subst ...
this test worked (just for compiling individual .o files, you still need to link them, which would be a very simple rule)