【问题标题】:Process list of files in makefile with $(notdir ...)使用 $(notdir ...) 处理 makefile 中的文件列表
【发布时间】:2015-12-09 18:34:06
【问题描述】:

我想将“notdir”函数应用于我从通配符匹配中获得的文件列表。虽然 '$(notdir $(wildcard dir/*.tst))' 有效,但我没有设法首先将列表存储在一个变量(下面的 Makefile 中的'FILES')中,然后由 $(notdir ... )。直接使用变量 ('$(notdir $(FILES))') 会导致返回通配符,使用 value ('$(notdir $(value $(FILES)))') 会产生空结果。

.PHONY: show

FILES := dir/*.tst
FILES2 := dir/a.tst dir/b.tst
#NAMES := $(notdir $(FILES))
NAMES1 := $(notdir $(value $(FILES)))
NAMES2 := $(notdir $(FILES2))
NAMES3 := $(notdir $(wildcard dir/*.tst))

show:
    @echo "FILES: " $(FILES)
    @echo "NAMES1: " $(NAMES1)
    @echo "NAMES2: " $(NAMES2)
    @echo "NAMES3: " $(NAMES3)

我也尝试过 $(notdir $(eval $$(FILES))),但这会导致“缺少分隔符”错误。

我在这里缺少什么?我本以为价值会完成这项工作......

【问题讨论】:

    标签: makefile gnu


    【解决方案1】:

    尝试以下方法:

    FILES := $(wildcard dir/*.tst)
    NAMES := $(notdir ${FILES})
    

    【讨论】:

    • 这也不起作用,我得到 '*.tst' 结果(NAMES3 是 a.tst b.tst,这是我想要的)
    • 其实可以,但是第二行可以简化为NAMES := $(notdir $(FILES))。因此问题是生成了FILES 的内容。
    • @user52366 你说得对,notdir 确实可以列出来。已更新。
    猜你喜欢
    • 2013-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多