visual-studioenvironment-variablesnmake

How to access a variable in a nmake conditional?


I'm having trouble accessing an environmental variable in a nmake conditional. I've tried the following, and they all result in some sort of syntax error at the !IF. I've also tried all the == variants:

!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

For example, using !IF $(PROCESSOR_ARCHITECTURE) = "x86" results in test.nmake(30) : fatal error U1023: syntax error in expression. Line 30 is the !IF.

MSDN's Makefile Preprocessing Directives page is a teaser, and it does not tell me how to form the expression (or I have not been able to locate it).

How do I access a variable in a nmake conditional?


If I follow qxg's suggestion, then the code in the block is not executed:

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

In fact, printing "$(PROCESSOR_ARCHITECTURE)" with !MESSAGE shows it should match. And placing a XXX in the block to cause a failure does not produce an error.


And the following is the dump of the variables:

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
...

Solution

  • Try

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