我需要为 Makefile 中的多个目录创建链接。
链接(对于 中的所有文件./topdir/
)应该从./anotherdir/<file>
到./topdir/<file>
。
我试过了:
create-links: ./topdir/*/
@for f in $^; do \
echo "this is my path: [$${f}]" && \
DIR=$(shell basename $${f}) && \
echo "make link from ./anotherdir/$(DIR)" ;\
done
./topdir 中有这些文件
dir1
dir2
file1
file2
f
使用 dirs 及其相对路径(例如./topdir/dir1
)正确分配。
我只需要没有路径的目录名。这是basename
应该做的。
但 DIR 始终为空。为什么?
$(shell basename $${f})
在运行配方之前由 Make 处理;它不在循环中处理。您需要使用 shell 运行所有内容:或者