子项目的主 Makefile 不会编译子项目

发布于 2024-07-15 18:10:23 字数 919 浏览 3 评论 0原文

我有一个正在发布的项目,实际上包含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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜还是长夜 2024-07-22 18:10:23

您可能在顶层有一个名为“spidermonkey”的文件或目录。 Make认为这就是它应该创造的东西,并且由于它已经在那里,所以停下来。

编写 makefile 时要遵循的最重要规则之一是每个目标应创建一个与目标同名的文件。 换句话说,如果您有

 a:
       <some command>

该命令应该生成一个名为“a”的文件。

不生成文件而仅作为占位符存在的规则称为虚假目标,它们应该这样声明:

 .PHONY: 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

 a:
       <some command>

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:

 .PHONY: a

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"

可遇━不可求 2024-07-22 18:10:23

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文