Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameter for rule in Makefile

Tags:

unix

makefile

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.

like image 631
amit Avatar asked Jan 24 '11 14:01

amit


People also ask

What is a rule in a makefile?

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.

Can you have multiple rules in a makefile?

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.

What is $* in makefile?

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.

What is Percent symbol in makefile?

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 % .


1 Answers

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
like image 151
buzzwang Avatar answered Sep 21 '22 11:09

buzzwang