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.
A rule appears in the makefile and says when and how to remake certain files, called the rule's targets (most often only one per rule). It lists the other files that are the prerequisites of the target, and the recipe to use to create or update the target.
There can only be one recipe to be executed for a file. If more than one rule gives a recipe for the same file, make uses the last one given and prints an error message. (As a special case, if the file's name begins with a dot, no error message is printed.
Here, $* is an automatic variable which will expand to the stem of the target (the text matching the % in the pattern). So, if you invoke make foobar. xyz , this rule would invoke make foobar clean : it would run a sub-make, build the foobar target, then build the clean target.
Special characters in a makefile In commands, a percent symbol ( % ) is a file specifier. To represent % literally in a command, specify a double percent sign ( %% ) in place of a single one. In other situations, NMAKE interprets a single % literally, but it always interprets a double %% as a single % .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With