当有更改时调用子 make 进行构建时,如何检查依赖关系?
如果我有一个调用另一个 makefile 的 makefile,如何让主 makefile 正确检查从属 makefile 的依赖项是否已更改?
例如,如果我有一条规则,
server:
@cd $(SERVERDIR) && $(MAKE)
该规则在我构建可执行“服务器”的子目录中调用 make 。 但是,如果我更改组成服务器的文件之一,则父 make 看不到更改并拒绝重建服务器 - “make:‘服务器’是最新的。”
如何让主 makefile 正确检测依赖文件之一(例如 $(SERVERDIR)/server.c 之类的文件)是否发生更改?
If I have a makefile that calls another makefile, how to I get the master makefile to correctly check if the dependencies of the subordinate makefile have changed?
For example, if I have the rule
server:
@cd $(SERVERDIR) && $(MAKE)
That invokes make in the subdirectory in which I build an executable "server". However, if I change one of the files that make up server, the parent make doesn't see the changes and refuses to rebuild server - "make: `server' is up to date."
How can I get the master makefile to correctly detect when there's a change in one of the dependent files (something like $(SERVERDIR)/server.c, for example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看来您想使用虚假目标
有虚假目标的详细描述 此处,但简短的描述是您告诉 makefile 永远不会有与此服务器目标对应的文件,因此如果有,它不会认为服务器是最新的是目录中名为 server 的文件。
It looks like you want to use a phony target
There's a detailed description of the Phony target here, but the short description is you're telling the makefile that there will never be a file that corresponds with this server target, and therefore it won't consider server up to date if there is a file named server in the directory.
您的目标名称与主
Makefile
目录中的文件或目录之一的名称相匹配。假设您需要在名为
server
的子目录中构建所有内容,则此规则:将不起作用,因为目标
server
是一个目录,没有源文件并且不需要届时将建成。这个:
只要没有名为
srv
的文件或目录,就可以工作。Your target name matches the name of one of the files or directories in your main
Makefile
directory.Assuming you need to build everything in a subdirectory called
server
, this rule:will not work, as the target
server
is a directory, has no source files and doesn't need to be built then.This one:
will work, as long as there is no file or directory called
srv
.你不:
但是,是的,如果你别无选择,例如因为你无法控制子 makefile 中,
.PHONY
目标就是您要查找的内容。You don't:
But yes, if you have no choice, e.g. because you don't control the sub-makefile, a
.PHONY
target is what you are looking for.