停止执行makefile [英] Stop executing makefile
问题描述
我实现了一个配方,以便将所有剩余的字符串传递给命令,例如此脚本中的示例:
I implement a recipe in order to pass all the remaining string to the command, as example in this script:
Makefile
run:
# ./bin/run.sh $(filter-out $@,$(MAKECMDGOALS))
@echo $(filter-out $@,$(MAKECMDGOALS))
但是当我作为示例运行时:
But when I run as example:
>make run my custom input params
my custom input params
make: *** No rule to make target `my'. Stop.
makefile尝试也执行剩余的字符串,因此出现错误:
makefile try to execute also the remaining string so the error:
make: *** No rule to make target `my'. Stop.
如何防止这种情况?
注意:作为解决方法,我定义了一个虚拟配方:
NB: As workaround I define a dummy recipe:
%:
@echo
因此,这将打印一个空字符串而不是错误.
So this will print an empty string instead of the error.
我想避免做类似的事情:
I want to avoid to do something like:
make run-example param="my custom param"
推荐答案
我认为您不应该使用Makefile.您想对选项进行自己的解析,而在make中做起来比较麻烦.
I don't think you should use a Makefile. You want to do your own parsing of the options, and that's more trouble to do in make.
如果您对它不满意,可以执行以下操作:
If you're dead set on it, you could do this:
%:
@true
...这将避免打印空行.
...which will avoid printing an empty line.
不过,最好在Bash中执行此操作.这是您可以做到的一种方法:
It would be better to do this in Bash, though. Here's one way you could do it:
#!/usr/bin/env bash
if [ $# -lt 1 ]; then
echo Not enough args
exit 1
fi
case "$1" in
"run")
shift
./bin/run.sh $@
;;
*)
echo "Command $1 not recognized"
exit 1
;;
esac
这似乎更容易且可扩展.
This seems easier and more extensible.
这篇关于停止执行makefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!