使用 Microsoft nmake 时如何获取命令的输出?

发布于 2024-10-15 07:39:23 字数 306 浏览 6 评论 0原文

通过 Linux 上的 make,我们可以执行以下操作:

foo=$(shell /bin/bar)

运行命令 bar 并将输出分配给 foo。稍后可以通过引用 $(foo) 在 makefile 中使用它。

但现在我手上有一个 Microsoft 项目,它是用 Microsoft nmake.exe 编译和链接的。 nmake 是否有等效的东西可以让我运行命令并将输出分配给变量?

With make on linux, we can do things like:

foo=$(shell /bin/bar)

which runs the command bar and assigns the output to foo. This can later be used in the makefile by referencing $(foo).

But now I have a Microsoft project on my hands that is compiled and linked with the Microsoft nmake.exe. Is there an equivalent thing for nmake that would allow me to run a command and assign the output to a variable?

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

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

发布评论

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

评论(2

带刺的爱情 2024-10-22 07:39:23

虽然这是一个老问题,但有一种方法可以做到所要求的;它只是很复杂,就像批处理文件中的所有内容一样!

人们必须使用 make 导入环境变量和预处理器可以调用命令的组合机制,然后递归地调用 Makefile。它假设 Makefile 名为 Makefile(没有扩展名,这是默认的)。

!IFNDEF MAKE
MAKE=NMAKE
!ENDIF
!IFNDEF SHELLVALUE
!   IF [echo off && FOR /F "usebackq" %i IN (`hostname`) DO  SET SHELLVALUE=%i && $(MAKE)  /$(MAKEFLAGS) /nologo /f $(MAKEDIR)\Makefile && exit /b  ] == 0
!     MESSAGE Make completed
!   ELSE
!     ERROR Error in nmake
!   ENDIF
!ELSE
# $(SHELLVALUE) now contains the string returned from the command USERNAME
!MESSAGE Shellvalue is $(SHELLVALUE)
#      Put the parts of the makefile that depend on SHELLVALUE here
!ENDIF
#
# To be a valid makefile it must have some rules to perform
all:
     @echo;$(SHELLVALUE)

是的,我知道这很糟糕,但它确实演示了如何执行该技术,该技术可以使用任何 shell 命令来完成,而不仅仅是主机名

Although this is an old question, there is a method of doing what is asked; its just convoluted, like everything in batch files!

One has to use the combined mechanisms of the fact that make imports environmental variables and that the preprocessor can invoke commands, and then call the Makefile recursively. It assume the Makefile is called Makefile (with no extension, which is the default).

!IFNDEF MAKE
MAKE=NMAKE
!ENDIF
!IFNDEF SHELLVALUE
!   IF [echo off && FOR /F "usebackq" %i IN (`hostname`) DO  SET SHELLVALUE=%i && $(MAKE)  /$(MAKEFLAGS) /nologo /f $(MAKEDIR)\Makefile && exit /b  ] == 0
!     MESSAGE Make completed
!   ELSE
!     ERROR Error in nmake
!   ENDIF
!ELSE
# $(SHELLVALUE) now contains the string returned from the command USERNAME
!MESSAGE Shellvalue is $(SHELLVALUE)
#      Put the parts of the makefile that depend on SHELLVALUE here
!ENDIF
#
# To be a valid makefile it must have some rules to perform
all:
     @echo;$(SHELLVALUE)

Yes, I know its horrible, but it does demonstrate how to do the technique, which can be done with any shell command and not just hostname.

岁月染过的梦 2024-10-22 07:39:23

我认为答案是“不”。没有同等的。

如果可能的话,我建议您转换为 MSBuild。

I think the answer is "no." There is no equivalent.

I'd recommend that you convert to MSBuild if possible.

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