title: Overriding `CC` and `CXX` variables in makefiles
body: <p>I have a master makefile, which contains generic settings, and a child makefile that has project specific settings.</p>
  
  <p>From my other question about <a href="https://stackoverflow.com/q/18869628/24949">overriding variables in a makefile</a>, I learned that I can use the following code in my master makefile:</p>
  
  <pre><code>CC ?= avr-gcc
  CXX ?= avr-g++
  </code></pre>
  
  <p>In the child makefile, I use <a href="https://github.com/colorgcc/colorgcc" rel="nofollow noreferrer">colorgcc</a> and override these variables:</p>
  
  <pre><code>CC ?= color-avr-gcc
  CXX ?= color-avr-g++
  </code></pre>
  
  <p>Everything works.</p>
  
  <p>But, if I remove the above lines from my child makefile, make starts using <code>gcc</code> and <code>g++</code> instead of <code>avr-gcc</code> and <code>avr-g++</code>.</p>
  
  <p>I guess both <code>CC</code> and <code>CXX</code> are treated differently and they are provided with default values by make and I am not able to assign default values to them using the following statements:</p>
  
  <pre><code>CC ?= avr-gcc
  CXX ?= avr-g++
  </code></pre>
  
  <p>My questions:</p>
  
  <ul>
  <li>Is my assumption correct?</li>
  <li>If yes, is there any other way to provide default values to <code>CC</code> and <code>CXX</code> in the master makefile and let make use it, if I don't override them in the child makefile?</li>
  </ul>
  
  <p><strong>Edit</strong>:</p>
  
  <p>As per <a href="https://stackoverflow.com/users/539810/chrono-kitsune">Chrono Kitsune</a>'s suggestion I did the following</p>
  
  <p><strong>master makefile</strong></p>
  
  <pre><code>CC = avr-gcc
  CXX = avr-g++
  # Add other master macros here.
  # Add other master targets here.
  </code></pre>
  
  <p><strong>child makefile</strong></p>
  
  <pre><code>CC ?= color-avr-gcc
  CXX ?= color-avr-g++
  # There are no child macros or targets
  
  include master.mk
  </code></pre>
  
  <p>Unfortunately, even this didn't work. When I run <code>make child.mk</code> it is picking up the <code>CC</code> and <code>CXX</code> defined in master.</p>
  
  <p>PS: BTW, my master makefile is a makefile for Arduino and the full source code is available in <a href="https://github.com/sudar/Arduino-Makefile/blob/master/arduino-mk/Arduino.mk" rel="nofollow noreferrer">github</a>.</p>