【问题标题】:Makefile, conditional and wildcard with variablesMakefile,条件和通配符与变量
【发布时间】:2020-01-28 17:02:53
【问题描述】:

我的 makefile 有问题。我想要一个“主”目标,它会自动处理各种目录并将它们复制到特定位置。但不知何故,带有通配符的 ifneq 条件无法正常工作,无论条件是否满足,都会给我相同的结果。

我正在尝试:

# Basically the same thing for all targets
% :
ifeq ($(wildcard $(TOP)/flow/$@),)
    $(error Directory $(TOP)/flow/$@ not found. Aborting. Debug: $(wildcard $(TOP)/flow/$@))
else
    $(error Directory $(TOP)/flow/$@ found!. Debug: $(wildcard $(TOP)/flow/$@))
endif

例如,在 $(TOP)/flow 中存在一个目录 core 但不存在 pwr。 Make 目标继续进行,就好像它们都存在一样。

➜  work ✗ make core
Makefile:20: *** Directory TOPFOLDER/flow/core found!. Debug: TOPFOLDER/flow/core.  Stop.
➜  work ✗ make pwr 
Makefile:20: *** Directory TOPFOLDER/flow/pwr found!. Debug: .  Stop.

为什么会这样?看不到我在这里做错了什么。

感谢您的帮助!

【问题讨论】:

  • 那是相当密集的。我想我知道错误的根源是什么,但是您能否更清楚地解释一下您希望此 makefile 做什么?
  • 我用一个更简单的用例重写​​了这个问题,但仍然失败了。感谢您的反馈!

标签: makefile conditional-statements wildcard


【解决方案1】:

在评估ifeq 时,变量$@ 为空。

可能改用运行时检查:

% :
    test -d $(TOP)/flow/$@/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-24
    • 1970-01-01
    • 2013-04-22
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    • 1970-01-01
    相关资源
    最近更新 更多