GNU make 3.79.1 的 makefile 中二次扩展的替代方案

发布于 2024-10-18 14:13:10 字数 557 浏览 1 评论 0原文

我一直在研究一个使用二次扩展的 makefile,但不知道此功能仅自 GNU make 3.81 版本以来才存在。不幸的是,这里有一些旧机器只安装了 make 3.79.1,并且在这些机器上,makefile 当然不起作用。除了二次扩张还有其他选择吗?

我使用的 C++ 程序的规则如下所示:

.SECONDEXPANSION:

# Pattern rule for linking
%_$(SYSTEM) : $$(%_ofiles) $(EXEC)/%_$(SYSTEM).o
    $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)

# Example for an ofiles variable
prog1_ofiles = $(C1) $(C2)

C1 = $(OFILES)/C1.o

C2 = $(OFILES)/C2.o

我知道 - 最好的解决方案是安装当前的 make 版本。但我们的系统管理员对此并不热心;)所以我期待您的建议。

顺便说一句,有谁知道在哪里可以获得 GNU make 3.79.1 的文档 - 我在任何地方都找不到它。

I've been working on a makefile that uses secondary expansion not knowing that this feature only exists since version 3.81 of GNU make. Unfortunately, there are some old machines around here that only have make 3.79.1 installed and on these machines, the makefile doesn't work, of course. Is there an alternative to secondary expansion?

The rule for a C++ program where I use it looks like the following:

.SECONDEXPANSION:

# Pattern rule for linking
%_$(SYSTEM) : $(%_ofiles) $(EXEC)/%_$(SYSTEM).o
    $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)

# Example for an ofiles variable
prog1_ofiles = $(C1) $(C2)

C1 = $(OFILES)/C1.o

C2 = $(OFILES)/C2.o

I know - the best solution would be to install a current make version. But our system administrator was not enthusiastic about it ;) So I'm looking forward to your suggestions.

Btw, does anyone know where to get the documentation of GNU make 3.79.1 - I couldn't find it anywhere.

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

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

发布评论

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

评论(3

缱倦旧时光 2024-10-25 14:13:10

只需在源代码树中添加 make-3.81 源代码即可。您的主 Makefile 首先应使用任何可用的 make 编译 make-3.81,然后使用 make-3.81 编译其他所有内容。

Just add make-3.81 sources in your source tree. Your main Makefile first should compile make-3.81 using whatever make is available and then use make-3.81 for compiling everything else.

孤独岁月 2024-10-25 14:13:10

函数/宏怎么样?使用eval会达到与二次扩展相同的结果。当然不如所有明确的规则干净,但打字更少。

define PROGRAM_template
$(1)_$(SYSTEM) : $($(1)_ofiles) $(EXEC)/$(1)_$(SYSTEM).o
       $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
endef

$(foreach target, prog1 prog2 prog3, \
    $(eval $(call PROGRAM_template, $(target)))

也许您可以在原始代码中用 eval 包装 $$(%_ofiles) 并省略 foreach 。没有把握...

What about a function/macro? Using eval would achieve the same result as the secondary expansion. Certainly not as clean, but less typing than all the explicit rules.

define PROGRAM_template
$(1)_$(SYSTEM) : $($(1)_ofiles) $(EXEC)/$(1)_$(SYSTEM).o
       $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
endef

$(foreach target, prog1 prog2 prog3, \
    $(eval $(call PROGRAM_template, $(target)))

Maybe you can wrap $$(%_ofiles) with eval in your original code and omit the foreach. Not sure...

妄想挽回 2024-10-25 14:13:10

没有 $(eval)?,呸!您必须编写一些 shell 将特定的 make 语法发出到 file.mk (比如说),然后将其include 到 Makefile 中。您可以通过告诉 make Makefile 依赖于 file.mk 来引导该过程。 Make 首先必须先更新 Makefile,然后再进行其他操作。因此它将创建 file.mk,包含它,然后重新启动。

对于您的情况,它看起来像 file.mk 将仅包含依赖项而没有配方。一个简短的草图:

%_${SYSTEM}: ${EXEC}/%_${SYSTEM}.o
    $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)

file.mk:
    echo '%_${SYSTEM}: ${prog1_ofiles}' >$@

Makefile: file.mk

include file.mk

No $(eval)?, bah! You will have to write some shell to emit the specific make syntax into file.mk (say), and then include that into the Makefile. You bootstrap the process by telling make that the Makefile depends on file.mk. Make first has to update Makefile before anything else. So it will create file.mk, include it, and restart itself.

For your case it looks like file.mk will just contain dependencies and no recipes. A brief sketch:

%_${SYSTEM}: ${EXEC}/%_${SYSTEM}.o
    $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)

file.mk:
    echo '%_${SYSTEM}: ${prog1_ofiles}' >$@

Makefile: file.mk

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