defining default values in makefile
16,552
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.
Related videos on Youtube
Comments
-
user1377944 over 1 year
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 ?
-
Paul R almost 12 yearspossible duplicate of Passing additional variables from command line to make
-
-
Ian Hickman almost 10 yearsUse #ifdef OPT2 #endif in your c/cpp file