子项目的主 Makefile 不会编译子项目
我有一个正在发布的项目,实际上包含3个子项目,所有这些子项目都需要一次性编译。 我的 makefile 大致如下所示:
all: a b c
a:
@cd a && make
b:
@cd b && make
c:
@cd c && make
项目 A 和 B 都编译良好,但对于第三个项目,它告诉我没有什么可做的,尽管切换到 C 目录并运行 make 实际上会编译代码。
更具体一点:上例中的项目 C 实际上是 Mozilla 的 SpiderMonkey。 A 和 B 是我编写的代码/makefile,而 C 只是 Mozilla 网站上的 SpiderMonkey 的原始副本。 它的实际编译命令是:
make JS_DIST=/usr JS_THREADSAFE=1 JS_HAS_FILE_OBJECT=1
在我的主 Makefile 中,我有:
spidermonkey:
@cd spidermonkey/src && $(MAKE) JS_DIST=/usr JS_THREADSAFE=1 JS_HAS_FILE_OBJECT=1
运行“make Spidermonkey”输出“make:Nothing to be do for `spidermonkey”。 如何让 make 运行该命令?
编辑: 我尝试将以下几行添加到我的 makefile 中:
.PHONY: spidermonkey
以及将 Spidermonkey 规则重命名为 sm,但仍然没有任何变化。
编辑: 我的错! 当我应该有一个制表符时,我却有空格。 哦!
I have a project that I am working to release that actually contains 3 subprojects, all of which need to be compiled in one go. My makefile looks roughly like this:
all: a b c
a:
@cd a && make
b:
@cd b && make
c:
@cd c && make
Projects A and B both compile fine but for the 3rd project, it tells me there is nothing to be done although switching to the C directory and running make does in fact compile code.
To be a little more specific: Project C in the example above is actually Mozilla's SpiderMonkey. Whereas A and B are code/makefiles that I have written, C is just a raw copy of SpiderMonkey from the Mozilla website. The actually compile command for it is:
make JS_DIST=/usr JS_THREADSAFE=1 JS_HAS_FILE_OBJECT=1
In my master Makefile, I have:
spidermonkey:
@cd spidermonkey/src && $(MAKE) JS_DIST=/usr JS_THREADSAFE=1 JS_HAS_FILE_OBJECT=1
Running "make spidermonkey" outputs "make: Nothing to be done for `spidermonkey'." How do I get make to run the command?
EDIT:
I've tried adding the following lines to my makefile:
.PHONY: spidermonkey
As well as renaming the spidermonkey rule to sm, but still no change.
EDIT:
My bad! I had spaces when I should have had a tab. doh!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能在顶层有一个名为“spidermonkey”的文件或目录。 Make认为这就是它应该创造的东西,并且由于它已经在那里,所以停下来。
编写 makefile 时要遵循的最重要规则之一是每个目标应创建一个与目标同名的文件。 换句话说,如果您有
该命令应该生成一个名为“a”的文件。
不生成文件而仅作为占位符存在的规则称为虚假目标,它们应该这样声明:
然后Make将始终假设必须重新制作a。
另外,作为一般规则,不要使用“make”递归调用 make,而是使用 $(MAKE)。
编辑:将“伪”更改为“假”
You probably have a file or directory at the toplevel called "spidermonkey". Make thinks this is what its supposed to create, and since it is already there, make stops.
One of the most important rules to follow when writing makefiles is each target should create one file with the same name as the target. In other words, if you have
That command should produce a single file called "a".
Rules which do not produce files but are only there as placeholders are called phony targets, and they should be declared like this:
Make will then always assume that a has to be remade.
Also, as a general rule do not use "make" to invoke make recursively, use $(MAKE) instead.
EDIT: changed "pseudo" to "phony"
Make 只检查是否存在与规则目标同名的文件(或目录),如果存在(并且比依赖项更新),那么从 make 的角度来看,没有什么可做的。
所以你的问题是你有一个spidermonkey规则(没有依赖项)以及一个名为spidermonkey的目录,然后make认为“目标已经制定,我没什么可做的”。 要让 make 执行您想要的操作,请重命名 Spidermonkey 规则(或目录)。
顺便说一下递归 make,这不一定是个好主意,
请参阅被认为有害的递归。
Make only checks for the existance of a file (or directory) named the same as the rule target, and if there is (and it is newer than the dependencies) then from make's point of view there is nothing more to do.
So your problem is that you have a spidermonkey rule (with no dependencies) as well as a directory called spidermonkey, and then make thinks "the target is already made, nothing for me to do". To get make to do what you want, rename the spidermonkey rule (or the directory).
Speaking of recursive make by the way, this is not neccessarily a good idea,
see Recursive Make Considered Harmful.