views:

26

answers:

1

I try to get the path to the ProgramFiles environmental variable, that is supposed to expand to C:\Program Files (x86) on a x64 machine and to C:\Program Files on a x86 machine.

The problems is that in the nmake file if I do:

 all:
      echo $(PROGRAMFILES)

This will expand to C:\Program Files everytime and this is wrong.

Environment details from a x64 machine:

ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files

:: this one is special, if will return different results based on current process x86/x64
ProgramFiles=C:\Program Files (x86) or C:\Program Files
PROCESSOR_ARCHITECTURE=x86 or x64

Now the updated question is how to get the location of x86 program files inside nmake, in a way this will work on both x86 and x64 machines?

A: 

If you're on an x64 machine it is totally legal that %ProgramFiles% points to C:\Program Files - from within a 64-bit program's environment. The variable you have to use to get the x86 counterpart is %ProgramFiles(x86)%.

Which one to use can be determined by evaluating the current OS's architecture that is set in the PROCESSOR_ARCHITECTURE environment variable (which is e.g. set to AMD64). Or simply try to get %ProgramFiles(x86)% and if it is empty get the content of %ProgramFiles%.

Another approach would be to start a 32-bit cmd.exe and run your make there. It is located in C:\Windows\SysWOW64.

Andreas
I updated the question to explain better the reasoning (mainly I need this value in order to properly locate include directories). Also if you know a way to read values from the registry, but I'm pretty sure nmake does not supports this.
Sorin Sbarnea