Makefile set if variable is empty

前端 未结 6 567
暖寄归人
暖寄归人 2021-01-31 01:37

I want to set a variable if it is empty. I tried in this way:

....
TEST := $(something)
...
TEST ?= $(something else)

The first $(somethi

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-31 02:03

    From GNU make, chapter 7.2, Syntax of Conditionals:

    "Often you want to test if a variable has a non-empty value. When the value results from complex expansions of variables and functions, expansions you would consider empty may actually contain whitespace characters and thus are not seen as empty. However, you can use the strip function to avoid interpreting whitespace as a non-empty value. For example:

    ifeq ($(strip $(foo)),)
    text-if-empty
    endif
    

    will evaluate text-if-empty even if the expansion of $(foo) contains whitespace characters."

提交回复
热议问题