如何在 nmake 条件中访问变量?

How to access a variable in a nmake conditional?

我无法访问 nmake conditional 中的环境变量。我尝试了以下方法,它们都会在 !IF 处导致某种语法错误。我还尝试了所有 == 变体:

!IF $(PROCESSOR_ARCHITECTURE) = "x86"
LIB_SRCS = $(LIB_SRCS) rdrand.cpp
!ENDIF

!IF %PROCESSOR_ARCHITECTURE% = "x86"
LIB_SRCS = $(LIB_SRCS) rdrand.cpp
!ENDIF

!IF [$(PROCESSOR_ARCHITECTURE) = "x86"]
LIB_SRCS = $(LIB_SRCS) rdrand.cpp
!ENDIF

!IF [%PROCESSOR_ARCHITECTURE% = "x86"]
LIB_SRCS = $(LIB_SRCS) rdrand.cpp
!ENDIF

例如,使用 !IF $(PROCESSOR_ARCHITECTURE) = "x86" 结果是 test.nmake(30) : fatal error U1023: syntax error in expression。第 30 行是 !IF.

MSDN 的 Makefile Preprocessing Directives 页面是一个预告片,它没有告诉我如何形成表达式(或者我没能找到它)。

如何在 nmake 条件中访问变量?


如果我按照qxg的建议,那么块中的代码不会被执行:

!IF "$(PROCESSOR_ARCHITECTURE)" = "x86"
LIB_SRCS = $(LIB_SRCS) rdrand.cpp
!ENDIF

事实上,打印 "$(PROCESSOR_ARCHITECTURE)"!MESSAGE 表明它应该匹配。并在块中放置一个 XXX 以导致失败不会产生错误。


下面是变量的转储:

C:\Users\Test>nmake /P

Microsoft (R) Program Maintenance Utility Version 11.00.61030.0
Copyright (C) Microsoft Corporation.  All rights reserved.

MACROS:
...
PROCESSOR_ARCHITECTURE = x86
           OS = Windows_NT
...

尝试

!IF "$(PROCESSOR_ARCHITECTURE)" == "x86"