PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 19, 2022

[FIXED] How to access a variable in a nmake conditional?

 August 19, 2022     environment-variables, nmake, visual-studio     No comments   

Issue

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"


Answered By - qxg
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,209,990

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing