微软nmake:是否可以从shell命令输出中定义宏

Microsoft nmake: Is it possible to define macros from shell command output?

本文关键字:输出 命令 定义 shell nmake 是否 微软      更新时间:2023-10-16

在使用Microsoft Visual Studio的nmake编写代码时,我正试图将SVN修订信息保存到宏中。

在GNU make中,我做了一些类似的事情:

SVN_REVISION=r$(shell svnversion -n)

所以我得到了例如:SVN_REVISION=r10001

这也可以在微软nmake中实现吗?

提前谢谢。

使用上面提到的技术和递归调用,可以通过以下方式完成:

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