GNU make 是否可以拥有依赖于其他 makefile 目标完成的目标?

发布于 2024-11-13 05:45:01 字数 965 浏览 1 评论 0原文

我有几个代表项目子部分的目录,每个目录都有自己的 Makefile。
我想创建一个主 Makefile,其中包含每个子部分的目标,每个目标满足以下条件:

  • 依赖于该子项目的 Makefile 中的某个目标。
    这是棘手的部分。
  • 将子项目生成的一些库/可执行文件复制到中央目录中(有点像“make install”)。
    我已经可以使用简单的命令实现这一点。

我只能找到有关 GNU make 的 include 指令的信息,但这对我没有多大帮助,因为它似乎没有封装包含的 makefile 的规则(和执行)位于其自己的目录中,但只是 #include 将它们视为 C 风格(而不是将它们视为具有单独作用域的包)。

INSTALLDIR := build
SRCDIR := src

TARGETS := projA projB
.PHONY: $(TARGETS)
TARGETS_PATH := $(addprefix $(SRCDIR)/, $(TARGETS))
MAKEFILES := $(addsuffix /osx.mak, $(TARGETS_PATH))
# include them somehow?

对于上面定义的这样的设置,我现在希望每个 $(TARGETS)依赖于其相应 Makefile 的 release 目标(某些东西)就像 projA 的 projA: $(SRCDIR)/projA/osx.mak @release 一样,用我自己的语言来说,这意味着目标 projA 取决于 release 目标的成功执行特定的 Makefile)。

有什么办法可以实现这一点吗?
您可以建议除 GNU make 之外的其他工具,但子项目 makefile 已编写为 makefile。

I have several directories representing subparts of a project, each with its own Makefile.
I want to create a master Makefile with targets for each of those subparts, each target satisfying the following:

  • depend on a certain target from that subproject's Makefile.
    This is the tricky part.
  • copy some resulting library/executable build by the subproject into a central directory (kind of like "make install"-ing it).
    This I can already achieve using simple commands.

I could only find information about the include directive of GNU make, but that doesn't help me much as it seems not to encapsulate the rules (and execution) of the included makefile in its own directory, but instead just #includes them C-style (rather that thinking of them as packages with separate scopes).

INSTALLDIR := build
SRCDIR := src

TARGETS := projA projB
.PHONY: $(TARGETS)
TARGETS_PATH := $(addprefix $(SRCDIR)/, $(TARGETS))
MAKEFILES := $(addsuffix /osx.mak, $(TARGETS_PATH))
# include them somehow?

For such a setup as defined above, I now want each of $(TARGETS) to depend on the release target of its corresponding Makefile (something like projA: $(SRCDIR)/projA/osx.mak @ release for projA, in my own language meaning that target projA depends on the successful execution of the release target in that specific Makefile).

Is there any way to achieve this?
You can suggest other tools apart from GNU make, but the subproject makefiles are already written as makefiles.

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

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

发布评论

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

评论(1

去了角落 2024-11-20 05:45:01

看看递归make

你可以做类似的事情,

SRCDIR := src
TARGETS := projA projB
.PHONY: $(TARGETS)

$(TARGETS):
    cd $(SRCDIR)/$@; $(MAKE) release

Have a look at recursive make.

You could do something like,

SRCDIR := src
TARGETS := projA projB
.PHONY: $(TARGETS)

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