如何替换 Makefile 中单词列表中出现的所有模式?

how to substitute all the occurrences of a pattern in a word list in Makefile?

在 Makefile 的 $(patsubst pattern, replacement, text) 语句中,它在 text 的白色 space 分隔单词列表中搜索任何 pattern 并用替换替换它们。但是 manual

Only the first ‘%’ in the pattern and replacement is treated this way; any subsequent ‘%’ is unchanged.

假设我有 test_list := test1 test2 我想从中制作一个列表 build/test1/test1 build/test2/test2。因为 patsubst 只替换第一次出现,所以如果我做 $(patsubst %, build/%/%, $(test_list)),它会给我 build/test1/% build/test2/%。我怎样才能制作build/test1/test1 build/test2/test2?是否有 patsubst 的变体可以转换所有出现?

在这个相当简单的例子中 foreach 应该做你想做的事:

$(foreach t,$(test_list),build/$(t)/$(t))