【问题标题】:filter_out unwanted stuff from variable content in GNUmake从 GNU make 的可变内容中过滤掉不需要的东西
【发布时间】:2020-04-21 14:50:42
【问题描述】:

我有如下所示的变量:

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解析有什么问题吗?

【问题讨论】:

    标签: makefile gnu-make


    【解决方案1】:

    问题

    $(,$(findstring $(dir),$(PROJ)))
    

    您不太可能拥有名为,,proj2 的宏。要检查此类错误,请始终使用--warn-undefined-variables 运行make。我得到了:

    $ 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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 2018-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-27
      相关资源
      最近更新 更多