Reputation: 178521
I need to make a Makefile, and it should have a run
rule. However, the run requires some parameters.
Does anyone have any idea how I can pass arguments in when running a rule in a Makefile? I want to be able to run the run
rule with arguments by typing make run foo bar
.
I tried this, but it didn’t work:
run:
make compile
./scripts/runTrips $1 $2 $PLACES $OUT $VERS
The parameters I want supplied are the first and the second.
Upvotes: 18
Views: 14103
Reputation: 71
Make itself doesn't provide passing arguments like for scripts. Usually make is used in the following way: you configure project than run just simple 'make'. Configuring can be done by running shell script 'configure'. This script is the one that you can pass parameters to. For example:
./configure param1 param2
make run
configure script must parse parameters and write them out to config.mk. config.mk must contain the following:
PARAM1 = val1
PARAM2 = val2
Your Makefile must include config.mk:
TOP = .
include $(TOP)/config.mk
run:
make compile
./scripts/runTrips $(PARAM1) $(PARAM2) $(PLACES) $(OUT) $(VERS)
In your 'configure' script you can also check parameters for correctness and make other checks and calculations.
Upvotes: 5
Reputation: 336
When passing parameters to a make command, reference them like you would other internal make variables.
If your makefile looks like:
run:
script $(param1) $(param2)
You can call it with the following syntax:
$> make run param1=20 param2=30
and make should call the script like:
script 20 30
Upvotes: 31