如何在 nmake 调用之间转发宏?

发布于 2024-07-18 08:20:43 字数 326 浏览 14 评论 0原文

如何在 nmake 调用之间转发宏?

假设我们正在

--- a.mak ---

some_variable = value

all:
   nmake -f b.mak

--- END ---

--- b.mak ---

all:
   @echo some_variable = WHAT TO PUT HERE TO GET VALUE OF some_variable?

--- END ---

尝试不同的操作,例如使用 set 和 setx 命令,但父 makefile 中设置的变量值在从其中调用的 makefile 中不可见。

How can I forward macros between nmake invocations?

Let's say we have

--- a.mak ---

some_variable = value

all:
   nmake -f b.mak

--- END ---

--- b.mak ---

all:
   @echo some_variable = WHAT TO PUT HERE TO GET VALUE OF some_variable?

--- END ---

I was trying different things like using set and setx commands but value of variable set in parent makefile is not visible in makefiles being invoked from within it.

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

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

发布评论

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

评论(2

挽你眉间 2024-07-25 08:20:43

以下是来自 MSDN 的有关递归调用 nmake 的信息:

使用递归宏递归调用NMAKE。 递归会话继承命令行和环境变量宏以及 Tools.ini 信息。 它们不继承 makefile 定义的推理规则或 .SUFFIXES 和 .PRECIOUS 规范。 要将宏传递给递归 NMAKE 会话,请在递归调用之前使用 SET 设置环境变量,在递归调用的命令中定义宏,或者在 Tools.ini 中定义宏。

因此,您可以使 a.mak 看起来像:

# ---- a.mak ----
some_variable = value

all:   
    nmake -f b.mak some_variable=$(some_variable)
#--- END ---

另外,请注意,使用 set 命令将变量放入环境中也可以,但是 nmake 自动将环境变量名称大写(即使是像“windir”这样奇怪的名称,由于某种原因在系统中为小写),并且区分大小写,因此要使用环境变量,您必须使用大写的变量。

来自 MSDN

继承的名称将转换为大写。 继承发生在预处理之前

因此,如果您要使用环境而不是在命令行上显式传递变量,那么您的 b.mak 应该如下所示:

#--- b.mak ---
all:
   @echo some_variable is: $(SOME_VARIABLE)
#--- end ---

因此,它可能不是标准化 nmake 宏名称的全大写命名约定是个坏主意。

Here's the info from MSDN about calling nmake recursively:

Use recursion macros to call NMAKE recursively. Recursive sessions inherit command-line and environment-variable macros and Tools.ini information. They do not inherit makefile-defined inference rules or .SUFFIXES and .PRECIOUS specifications. To pass macros to a recursive NMAKE session, either set an environment variable with SET before the recursive call, define a macro in the command for the recursive call, or define a macro in Tools.ini.

So, you could make a.mak look like:

# ---- a.mak ----
some_variable = value

all:   
    nmake -f b.mak some_variable=$(some_variable)
#--- END ---

Also, note that using the set sommand to put the variable in the environment will work as well, but nmake automatically capitalizes environment variable names (even for weird ones like "windir" which is lowercase in the system for some reason), and is case-sensitive, so to use the environment variable, you must use the variable in uppercase.

From MSDN:

inherited names are converted to uppercase. Inheritance occurs before preprocessing

So, here's what your b.mak should look like if you're going to pass the variable using the environment instead of explicitly on the command line:

#--- b.mak ---
all:
   @echo some_variable is: $(SOME_VARIABLE)
#--- end ---

Because of this, it's probably not a bad idea to standardize on an all-caps naming convention for nmake macro names.

月竹挽风 2024-07-25 08:20:43

也许你应该考虑不要递归地调用make,请参阅论文Recursive Make Should Been Harmful。 您仍然可以拥有类似于已有的 makefile(由 make 包含)的模块化文件,只是规则仅在一个顶级 makefile 中定义。

Maybe you should consider not calling make recursively, see the paper Recursive Make Considered Harmful. You can still have modular files similar to the makefiles you already have (included by make), just that the rules are only defined in one top level makefile.

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