Passing arguments to "make run"
I use Makefiles.
I have a target called run
which runs the build target. Simplified, it looks like the following:
prog: ....
...
run: prog
./prog
Is there any way to pass arguments? So that
make run asdf --> ./prog asdf
make run the dog kicked the cat --> ./prog the dog kicked the cat
I don't know a way to do what you want exactly, but a workaround might be:
run: ./prog
./prog $(ARGS)
Then:
make ARGS="asdf" run
# or
make run ARGS="asdf"
This question is almost three years old, but anyway...
If you're using GNU make, this is easy to do. The only problem is that make
will interpret non-option arguments in the command line as targets. The solution is to turn them into do-nothing targets, so make
won't complain:
# If the first argument is "run"...
ifeq (run,$(firstword $(MAKECMDGOALS)))
# use the rest as arguments for "run"
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets
$(eval $(RUN_ARGS):;@:)
endif
prog: # ...
# ...
.PHONY: run
run : prog
@echo prog $(RUN_ARGS)
Running this gives:
$ make run foo bar baz
prog foo bar baz