Makefile检查列表中是否存在变量

Makefile检查列表中是否存在变量,makefile,Makefile,我有一个生成文件: #Build Configurations CONFIGS = Debug Release Profile #Config flags Debug_Flags=dasd Release_Flags= .SECONDEXPANSION: #Debug_safety_check Release_safety_check Profile_safety_check targets $(addsuffix _safety_check,$(CONFIGS)): #Check exi

我有一个生成文件:

#Build Configurations
CONFIGS = Debug Release Profile

#Config flags
Debug_Flags=dasd
Release_Flags=

.SECONDEXPANSION:

#Debug_safety_check Release_safety_check Profile_safety_check targets
$(addsuffix _safety_check,$(CONFIGS)):
#Check existence of variable
ifeq '$(origin $(subst safety_check,FLAGS,$@))' 'undefined'
    $(error $(subst safety_check,FLAGS,$@) variable undefined)
endif 

#How to make our configurations (do corresponding safety_checks)
$(CONFIGS): $$@_safety_check
这行不正确:

ifeq '$(origin $(subst safety_check,FLAGS,$@))' 'undefined'
我想,这是因为调用相应的安全检查时发生了$@扩展。但如果EQ膨胀“立即”发生,那么,事实上,我们得到了这样一条线:

ifeq '$(origin ' ') 'undefined'
是否存在从列表中检查变量定义的方法?

Ufff,明白了

#Build Configurations
CONFIGS = Debug Release Profile

#Config flags
Debug_Flags=dasd
Release_Flags=
#Profile_Flags=

#Adds _flags suffix for each variable, 
#get it's origin ('undefined' for undefined variables).
#If $(findstring) a lookup for the word 'undefined' succeeds, 
#adds to the result variable
undef_flags = $(foreach c, $(CONFIGS), \
                $(if $(findstring undefined, $(origin $c_Flags)), $c))

#Count words for undefined configs, must be not '0'
ifneq ($(words $(undef_flags)),0)
#strip because if flag is undefined we'll get the trash spaces
$(error Flags ($(strip $(undef_flags))) must be defined)
endif

这它真的很混乱,您正在使用
SECONDEXPANSION
,而不需要它。要检查哪些变量?@Beta、.SECONDEXPANSION在第
$(配置):$$@\u safety\u check
行中使用。不是吗?我几个小时前就找到了解决办法。等一下,我会发布它。@Beta,我会检查变量
Release\u Flags
Debug\u Flags
。总之,
$(addsuffix\u标志,$(配置))