在Makefile中检查环境变量的值


21

我有一个Makefile目标,在其中必须检查环境变量的值。但是,我没有确切的语法。努力尝试,但找不到。任何帮助表示赞赏。

环境变量名称:TEST,其值:“ TRUE”

test_target: 
    ifeq ($(TEST),"TRUE")
            echo "Do something"
    endif

我收到以下错误:

/bin/sh: -c: line 0: syntax error near unexpected token `"TRUE","TRUE"'
/bin/sh: -c: line 0: `ifeq ("TRUE","TRUE")'

Answers:


26

ifeq()指令必须在第1列中,删除所有前导空格,即

test_target: 
ifeq ($(TEST),"TRUE")
        echo "Do something"
endif

^没有空格


14

您不得ifeq放任TAB。允许有空格。阅读GNU Make文档

test_target: 
ifeq ($(TEST),"TRUE")
    echo "Do something"
endif

另请注意,它$(TEST)"TRUE"原样进行比较:

$ make TEST=TRUE
make: Nothing to be done for 'test_target'.

$ make TEST='"TRUE"'
echo "Do something"
Do something

这一点特别有用-还要注意,它会将$(TEST)与“ TRUE”进行比较,如下所示:谢谢
kakoma
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.