开发者

How do you access variables using NMake?

开发者 https://www.devze.com 2023-01-04 01:13 出处:网络
I have a makefile with the following code. I\'m trying to set a variable in an if statement. It doesn\'t error, but %OPTION% just prints %OPTION (with only one percentage sign) and the $(OPTION) doesn

I have a makefile with the following code. I'm trying to set a variable in an if statement. It doesn't error, but %OPTION% just prints %OPTION (with only one percentage sign) and the $(OPTION) doesn't print anything. Please help

Makefile

RELEASE_OR_DEBUG=debug  
init:  
    SET OPTION=test  
    @echo test1 = %OPTION%  
        @echo test2 = $(OPTION)  
    if ".$(RELEASE_OR_DEBUG)" == ".debug" SET OPTION="-d"  
    @echo OPTION = %OPTION%  
    @echo OPTION = $(OPTION)  

Output

test1 = 开发者_JAVA技巧%OPTION  
test2 =   
if ".debug" == ".debug" SET OPTION="-d"  
OPTION = %OPTION  
OPTION = $(OPTION)


You cannot set variables inside dependency statements (such as "init" in this case). In fact, you can't use if statements there either. Variables can be set by external batch files prior to calling the makefile (and that batch file then can call the makefile) or outside of dependency statements like RELEASE_OR_DEBUG in this example.
To access variables inside dependency statements, use $(VARIABLE_NAME). Be aware that if the variable name is not found, it will simply use a blank string (such as in your "@echo test2 = $(OPTION)" test where the variable OPTION was not found).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号