您不能将make函数与shell操作混合搭配。 Make将首先完全展开所有的变量和函数,然后将扩展的结果传递给shell,shell将其作为脚本运行。
您正试图在shell循环中使用make函数,但make函数首先被扩展,然后循环将在结果上运行。基本名称和patsubst运行在字符串$f
上,该字符串没有任何路径名,并且与%.c
模式不匹配,所以这些函数不起作用。
如果你想这样做,这样,你必须使用100%的shell操作,否则修改变量的外壳变得像在此之前:
test_filenames := $(wildcard Test/src/test_*.c)
compile_tests:
@for f in $(basename $(patsubst %.c,%,$(test_filenames))); do \
echo ">>> $$f";\
done
埃塔:如果你想要做的这一切在外壳,您可以使用:
test_filenames := $(wildcard Test/src/test_*.c)
compile_tests:
@for f in $(test_filenames); do \
echo ">>> $$(basename $$f .c)";\
done
或者更明确:
test_filenames := $(wildcard Test/src/test_*.c)
compile_tests:
@for f in $(test_filenames); do \
echo ">>> `basename $$f .c`";\
done
请注意显示的例子,当以显示你实际尝试过的。在上面你正在使用'test_files'和'test_filenames',这可能会让人误解真正的错误。 – MadScientist
如果我们知道你真的想要做什么,这将有所帮助。 – Beta