如何不为目标参数获取 "get make: *** No rule to make target"

How not to get "get make: *** No rule to make target" for goal parameters

我有以下目标:

.PHONY: echo
echo:
    @echo "parameters:" $(filter-out $@,$(MAKECMDGOALS))

当我执行它时,我不仅得到了我指定的目标,而且当 Make 尝试 运行 make hello:

时也会出错
$ make echo hello world
parameters: hello world
make: *** No rule to make target `hello'.  Stop.

如何修复或抑制最后一行中的错误?

错误的发生是因为 Make 不知道如何处理 helloworld 等目标。你想让它什么也不做,但它不知道。

所以添加一个什么都不做的"match anything" rule:

%:
    @: