GNU make 3.79.1 的 makefile 中二次扩展的替代方案
我一直在研究一个使用二次扩展的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需在源代码树中添加
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 compilemake-3.81
using whatever make is available and then usemake-3.81
for compiling everything else.函数/宏怎么样?使用eval会达到与二次扩展相同的结果。当然不如所有明确的规则干净,但打字更少。
也许您可以在原始代码中用 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.
Maybe you can wrap $$(%_ofiles) with eval in your original code and omit the foreach. Not sure...
没有
$(eval)
?,呸!您必须编写一些 shell 将特定的 make 语法发出到file.mk
(比如说),然后将其include
到 Makefile 中。您可以通过告诉 make Makefile 依赖于file.mk
来引导该过程。 Make 首先必须先更新 Makefile,然后再进行其他操作。因此它将创建file.mk
,包含它,然后重新启动。对于您的情况,它看起来像
file.mk
将仅包含依赖项而没有配方。一个简短的草图:No
$(eval)
?, bah! You will have to write some shell to emit the specific make syntax intofile.mk
(say), and theninclude
that into the Makefile. You bootstrap the process by telling make that the Makefile depends onfile.mk
. Make first has to update Makefile before anything else. So it will createfile.mk
, include it, and restart itself.For your case it looks like
file.mk
will just contain dependencies and no recipes. A brief sketch: