如何让这个Makefile更加简洁呢?
我知道有一些方法可以删除 Makefile 中的重复 $(CC) $(CFLAGS) $@ $^
。你能告诉我如何让下面的Makefile更简洁吗?
CC=gcc
CFLAGS=-pthread -g -o
all: p1 p2
p1: p1.c
$(CC) $(CFLAGS) $@ $^
p2: p2.c
$(CC) $(CFLAGS) $@ $^
I know there are ways to remove duplicates $(CC) $(CFLAGS) $@ $^
in Makefile. Can you tell me how to make the Makefile below more concise?
CC=gcc
CFLAGS=-pthread -g -o
all: p1 p2
p1: p1.c
$(CC) $(CFLAGS) $@ $^
p2: p2.c
$(CC) $(CFLAGS) $@ $^
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了让你的Makefile更加简洁,你可以这样写。
然后您可以在
all:
行添加任意数量的 p。只要你提供pN.c,make就会将它们编译成相应的pN。To make your Makefile more concise, you can write it as follows.
Then you can add as many p's as you want on the
all:
line. As long as you provide pN.c, make will compile them into the corresponding pN.是的,您可以“按先决条件”组合命令。例如:
或类似的东西——您需要仔细检查细节并确保这些库等确实有意义。
请注意,短语
$(OBJS): dotprod.h
表示$(OBJS):
取决于dotprod.h
是否存在。您需要阅读手册以获取所有详细信息,特别是:
至于自动化这些东西的工具,您需要 automake 和 autoconf: http://sourceware.org /自动预订/
Yes, you can combine commands "by prerequisite". For example:
or somesuch -- you'll need to go through the details and make sure those libraries and so on actually make sense.
Note that the phrase
$(OBJS): dotprod.h
means that$(OBJS):
depends on the presence ofdotprod.h
.You will want to read the manual to get all the gory details, in particular:
As for tools to automate this stuff, you want automake and autoconf: http://sourceware.org/autobook/