make: Overriding

1 
1 9.5 Overriding Variables
1 ========================
1 
1 An argument that contains '=' specifies the value of a variable: 'V=X'
1 sets the value of the variable V to X.  If you specify a value in this
1 way, all ordinary assignments of the same variable in the makefile are
1 ignored; we say they have been "overridden" by the command line
1 argument.
1 
1    The most common way to use this facility is to pass extra flags to
1 compilers.  For example, in a properly written makefile, the variable
1 'CFLAGS' is included in each recipe that runs the C compiler, so a file
1 'foo.c' would be compiled something like this:
1 
1      cc -c $(CFLAGS) foo.c
1 
1    Thus, whatever value you set for 'CFLAGS' affects each compilation
1 that occurs.  The makefile probably specifies the usual value for
1 'CFLAGS', like this:
1 
1      CFLAGS=-g
1 
1    Each time you run 'make', you can override this value if you wish.
1 For example, if you say 'make CFLAGS='-g -O'', each C compilation will
1 be done with 'cc -c -g -O'.  (This also illustrates how you can use
1 quoting in the shell to enclose spaces and other special characters in
1 the value of a variable when you override it.)
1 
1    The variable 'CFLAGS' is only one of many standard variables that
11 exist just so that you can change them this way.  ⇒Variables Used
 by Implicit Rules Implicit Variables, for a complete list.
1 
1    You can also program the makefile to look at additional variables of
1 your own, giving the user the ability to control other aspects of how
1 the makefile works by changing the variables.
1 
1    When you override a variable with a command line argument, you can
1 define either a recursively-expanded variable or a simply-expanded
1 variable.  The examples shown above make a recursively-expanded
1 variable; to make a simply-expanded variable, write ':=' or '::='
1 instead of '='.  But, unless you want to include a variable reference or
1 function call in the _value_ that you specify, it makes no difference
1 which kind of variable you create.
1 
1    There is one way that the makefile can change a variable that you
1 have overridden.  This is to use the 'override' directive, which is a
11 line that looks like this: 'override VARIABLE = VALUE' (⇒The
 'override' Directive Override Directive.).
1