【问题标题】:How to write Makefile that traverses files in a directory如何编写遍历目录中文件的Makefile
【发布时间】:2018-10-12 08:41:23
【问题描述】:

今天尝试写Makefile来遍历一个目录下的所有文件。我是这样写的Shell风格的,

for file in `find $(DEPLOY_PATH)/ -type l`; \
do \
  echo $(file); \
done

有9个链接文件,但是当我运行make时,它打印了9个空行,没有文件名

【问题讨论】:

  • 请编辑您的问题以显示完整的makefile
  • 您正在编写一个设置 shell 变量 $file 的 shell 脚本,但您引用的是 make 变量 $(file)。你应该说echo $$file
  • @MadScientist 是的,你是对的!

标签: shell makefile


【解决方案1】:

$(file) 指的是 Makefile 变量。你要的是$$file:

$ cd "$(mktemp --directory)"
$ cat Makefile 
all:
    for file in *; \
    do \
        echo "$$file" || exit 1; \
    done
$ make
for file in *; \
do \
    echo "$file" || exit 1; \
done
Makefile
with spaces

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-29
    • 2011-06-22
    • 2021-07-09
    • 2014-10-02
    • 2022-01-02
    相关资源
    最近更新 更多