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.

Share:
16,552

Related videos on Youtube

user1377944
Author by

user1377944

s/w professional with one year of experience

Updated on September 16, 2022

Comments

  • user1377944
    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 ?

  • Ian Hickman
    Ian Hickman almost 10 years
    Use #ifdef OPT2 #endif in your c/cpp file