如何在 nmake 调用之间转发宏?
如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是来自 MSDN 的有关递归调用
nmake
的信息:因此,您可以使
a.mak
看起来像:另外,请注意,使用
set
命令将变量放入环境中也可以,但是nmake
自动将环境变量名称大写(即使是像“windir
”这样奇怪的名称,由于某种原因在系统中为小写),并且区分大小写,因此要使用环境变量,您必须使用大写的变量。来自 MSDN:
因此,如果您要使用环境而不是在命令行上显式传递变量,那么您的
b.mak
应该如下所示:因此,它可能不是标准化 nmake 宏名称的全大写命名约定是个坏主意。
Here's the info from MSDN about calling
nmake
recursively:So, you could make
a.mak
look like:Also, note that using the
set
sommand to put the variable in the environment will work as well, butnmake
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:
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:Because of this, it's probably not a bad idea to standardize on an all-caps naming convention for nmake macro names.
也许你应该考虑不要递归地调用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.