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 try to execute also the remaining string so the error:
make: *** No rule to make target `my'. Stop.
How can I prevent this?
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"
You can probably achieve what you want with a match-anything rule. Example (using a dummy
printf
recipe instead of a real one):Demo:
You can ignore the
make: 'target' is up to date.
messages or use the--quiet
option (or--silent
or-s
):If your Makefile is more complex than this, the match-anything rule could be a problem because it could catch other targets that you do not want to be caught. In this case make conditionals are an option:
Finally, if the name of the first goal is not always the same, you can adapt this with:
Or:
Demo:
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:
...which will avoid printing an empty line.
It would be better to do this in Bash, though. Here's one way you could do it:
This seems easier and more extensible.
You can always pass / set ENV variables before executing make if you only want to pass variables to make or to a shell script.
OR using a subshell
You might also look at the bash-shell-special-parameters