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 ?
Expanded assignment = defines a recursively-expanded variable. := defines a simply-expanded variable.
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).
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.
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