filter_out GNUmake 变量内容中不需要的东西
filter_out unwanted stuff from variable content in GNUmake
我有如下所示的变量:
TEMP_VARIABLE := proj1 proj2 proj3 proj4
PROJ := proj2
我想从 TEMP_VARIABLE 中删除所有项目,即 (proj1,proj3,proj4)。为此,我的 Makefile 中有以下解析技术。
TEMP_VARIABLE := $(foreach dir,$(TEMP_VARIABLE), $(ifneq $(,$(findstring $(dir),$(PROJ))) $(filter-out $(dir),$(TEMP_VARIABLE))))
当我 运行 我的 make 文件并尝试显示 TEMP_VARIABLE
时,它没有打印任何内容。并注意那个变量。
我上面的foreach
解析有什么问题吗?
问题
$(,$(findstring $(dir),$(PROJ)))
您不太可能有一个名为 ,
或 ,proj2
的宏。要检查此类错误,请始终使用 运行 make 和 --warn-undefined-variables
。我得到了:
$ make -f a --warn
a:3: warning: undefined variable ','
a:3: warning: undefined variable 'ifneq proj2 proj3 proj4'
a:3: warning: undefined variable ',proj2'
a:3: warning: undefined variable 'ifneq proj1 proj3 proj4'
a:3: warning: undefined variable ','
a:3: warning: undefined variable 'ifneq proj1 proj2 proj4'
a:3: warning: undefined variable ','
a:3: warning: undefined variable 'ifneq proj1 proj2 proj3'
你真正想要的
生活通常比较简单。使用 $(filter …)
怎么样?
$ cat a
TEMP_VARIABLE := proj1 proj2 proj3 proj4
PROJ := proj2
TEMP_VARIABLE := $(filter ${PROJ},${TEMP_VARIABLE})
$(error [${TEMP_VARIABLE}])
给予
$ make -f a --warn
a:4: *** [proj2]. Stop.
我有如下所示的变量:
TEMP_VARIABLE := proj1 proj2 proj3 proj4
PROJ := proj2
我想从 TEMP_VARIABLE 中删除所有项目,即 (proj1,proj3,proj4)。为此,我的 Makefile 中有以下解析技术。
TEMP_VARIABLE := $(foreach dir,$(TEMP_VARIABLE), $(ifneq $(,$(findstring $(dir),$(PROJ))) $(filter-out $(dir),$(TEMP_VARIABLE))))
当我 运行 我的 make 文件并尝试显示 TEMP_VARIABLE
时,它没有打印任何内容。并注意那个变量。
我上面的foreach
解析有什么问题吗?
问题
$(,$(findstring $(dir),$(PROJ)))
您不太可能有一个名为 ,
或 ,proj2
的宏。要检查此类错误,请始终使用 运行 make 和 --warn-undefined-variables
。我得到了:
$ make -f a --warn
a:3: warning: undefined variable ','
a:3: warning: undefined variable 'ifneq proj2 proj3 proj4'
a:3: warning: undefined variable ',proj2'
a:3: warning: undefined variable 'ifneq proj1 proj3 proj4'
a:3: warning: undefined variable ','
a:3: warning: undefined variable 'ifneq proj1 proj2 proj4'
a:3: warning: undefined variable ','
a:3: warning: undefined variable 'ifneq proj1 proj2 proj3'
你真正想要的
生活通常比较简单。使用 $(filter …)
怎么样?
$ cat a
TEMP_VARIABLE := proj1 proj2 proj3 proj4
PROJ := proj2
TEMP_VARIABLE := $(filter ${PROJ},${TEMP_VARIABLE})
$(error [${TEMP_VARIABLE}])
给予
$ make -f a --warn
a:4: *** [proj2]. Stop.