Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

defining default values in makefile

Tags:

My makefile has line like this

   CFLAGS = -c -g -D OPT1 -D OPT2 

I want to pass this arguments through command line like this

 make ARG1= OPT1 ARG2 =OPT2     

If I dont pass these arguments through command line I want makefile to use take default values defined in makefile. How do I do that ?

like image 307
user1377944 Avatar asked May 22 '12 09:05

user1377944


People also ask

What is := in makefile?

Expanded assignment = defines a recursively-expanded variable. := defines a simply-expanded variable.

How do I override a variable in makefile?

There is one way that the makefile can change a variable that you have overridden. This is to use the override directive, which is a line that looks like this: ' override variable = value ' (see The override Directive).


1 Answers

Just do something like this in the makefile:

OPT1 = MY_OPT_1 # defaults OPT2 = MY_OPT_2  CFLAGS = -c -g -D $(OPT1) -D $(OPT2) 

Then on the command line:

$ make -e OPT1=SOME_OTHER_OPT1 OPT2=SOME_OTHER_OPT2 

When you specify falues for OPT1 and/or OPT2 on the command line these will override the default values in the makefile.

Note that you probably want the -e option with make in most cases to force everything to be re-built with the new OPT1, OPT2 values.

like image 54
Paul R Avatar answered Sep 19 '22 17:09

Paul R