内部带有变量的 Makefile 通配符

Makefile wildcard with variable inside

我正在尝试使用 Makefile 获取每个文件夹中的所有文件:

Test = $(wildcard */)

install: all
  @for dir in $(TEST); do \
    echo $$dir; \
    echo $(wildcard $$dir); \
  done

第一个 echo 输出正确:folder1/ folder2/ folder3/ 但是当在第二个 echo 中使用通配符时,我得到空输出(每个文件夹包含许多文件)。 为什么这不起作用以及如何存档有什么建议吗?

$(wildcard)make 函数,在解析 makefile 时计算一次。

dir 是一个 shell 变量,它仅在 收据计算 时存在(使用 shell).

因为 make 不知道 shell 变量,$(wildcard $$dir) 中的模式由 [=24 解释=]make 字面意思:$$dir.

如果你想输出 dir 变量指向的目录中的文件列表,你应该使用 shell 实用程序。例如。 ls $$dir.