title: gnu make : how to make conditional cflags
body: <p>I started a simple makefile for my project (MS-windows target, MinGW) with the following :</p>
  
  <pre><code>CFLAGS = -g -O0 -Wall -std=c99
  
  CC =    gcc
  CPP =   g++
  LIBS =
  
  PBDUMPER = pbdumper.exe
  
  all: $(PBDUMPER)
  
  $(PBDUMPER): pbdumper.c
      $(CC) $(CFLAGS) -o $@ $&lt; $(LIBS)
  
  clean:
      rm -f $(PBDUMPER)
  
  .PHONY: clean
  </code></pre>
  
  <p>Now I would like to choose between release and debug compilation.
  I have changed the variable definitions and implicit rule for debug : </p>
  
  <pre><code>CFLAGS_COMMON = -std=c99
  CFLAGS_DEBUG = -g -O0 -Wall
  CFLAGS_RELEASE = -O2 -Wall
  ...
  $(PBDUMPER): pbdumper.c
      $(CC) $(CFLAGS_COMMON) $(CFLAGS_DEBUG) -o $@ $&lt; $(LIBS)
  </code></pre>
  
  <p>But for release I would have to change the implicit rule to use the CFLAGS_RELEASE which is I suppose the wrong way to do.
  I have looked at the Gnu Make manual in the "implicit rules" and "automatic variables" sections but I did not found a better way.</p>
  
  <p>Could you show me the correct way, by either conditionally defining the CFLAGS, or maybe using a "if" in the implicit rules based on the flavour selected for compilation ? Or maybe another method.</p>