如何创建一个 make 文件来独立运行其他 make 文件?

发布于 2025-01-15 05:58:30 字数 582 浏览 3 评论 0原文

我希望能够在位于文件夹根目录的 make 文件中运行类似于 make subdir 的命令,该命令将依次运行位于当前文件子目录中的另一个 make 文件。

从官方的 GNU make 文件文档中,我能够找到下面的代码并测试它,它做了我需要做的事情,

subsystem:
     $(MAKE) -C ./subdir/

我将代码放在根目录中的 make 文件中,当我运行 make 时root,它运行 subdir 文件夹中的 make 文件。

但举例来说,我有几个子文件夹,每个子文件夹都有自己的 make 文件,该文件执行与每个文件夹中的内容相关的操作。我的目的是让根 make 文件作为一个地方,我可以在整个文件夹中的其他子文件夹中启动 make 文件,但独立执行此操作,而不是一次运行所有文件。

因此,如果我在根目录中说 make subfolder1,则 subfolder1 中的 make 文件将运行,如果我说 make subfolder2,则 subfolder2 中的 make 文件将运行,等等。这是可以实现的吗?

I want to be able to run a command like make subdir in a make file located in the root of a folder which will in turn run another make file that is located in a sub directory of the current one.

From the official GNU make file documents, I was able to find the code below and test it which did what I needed to do

subsystem:
     $(MAKE) -C ./subdir/

I placed the code in a make file in the root and when I run make in the root, it runs the make file in the subdir folder.

But say for example, I have several sub folders each with their own make file that does something pertaining to the contents in each respective folder. My intention is to have the root make file serve as a place where I can launch make files in other sub folders throughout the folder but do so independently, not run all of them at once.

So if I was to say make subfolder1 in the root, the make file in subfolder1 will run, and if I was to say make subfolder2, the make file in subfolder2 will run, and so on and so forth. Is this achievable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

绅刃 2025-01-22 05:58:30

通过使用原始问题中的代码并重命名它们以满足我的需要,我能够实现我所需要的。

name1:
     $(MAKE) -C ./subdir1/

name2:
     $(MAKE) -C ./subdir2/

也感谢@MadScientist 指出我已经弄清楚如何做我需要的事情,我肯定想得太多了。

我确实遇到了一个问题,当我运行带有 name1 或 name2 的 make 文件时,系统提示我一条消息,说该目录是最新的。即使我进入子文件夹并由于调用各自的 make 文件而删除了任何填充的文件,问题仍然存在。

我可以通过将下面的代码添加到我的根 make 文件的底部来绕过它。

.PHONY: name1 name2...

因此,现在当我调用 make name1make name2 时,这些子文件夹中的 make 文件将正常工作并执行其应有的功能!

I was able to achieve what I needed by using the code in my original question and just renaming them to fit my needs.

name1:
     $(MAKE) -C ./subdir1/

name2:
     $(MAKE) -C ./subdir2/

Thanks to @MadScientist as well for pointing out that I had figured out how to do what I needed, I was overthinking it for sure.

I did run into an issue in which when I ran the make file with name1 or name2, I was prompted with a message saying that the directory was up to date. Even if I went into the sub folders and deleted any populated files as a result of calling their respective make files, the issue still persisted.

I was able to bypass it by adding the code below to the bottom of my root make file.

.PHONY: name1 name2...

So now when I call make name1 or make name2, the make files in those sub folders work and do what they are supposed to!

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