문제

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 = %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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top