title: Creating several precompiled header files using GNU make
body: <p>I use gcc (running as <code>g++</code>) and GNU make.
  I use gcc to precompile a header file <code>precompiled.h</code>, creating <code>precompiled.h.gch</code>; the following line in a Makefile does it:</p>
  
  <pre><code># MYCCFLAGS is a list of command-line parameters, e.g. -g -O2 -DNDEBUG
  precompiled.h.gch: precompiled.h
      g++ $(MYCCFLAGS) -c $&lt; -o $@
  </code></pre>
  
  <p>All was well until i had to run <code>g++</code> with different command-line parameters.
  In this case, even though <code>precompiled.h.gch</code> exists, it cannot be used, and the compilation will be much slower.
  In the gcc documentation i have read that to handle this situation,
  i have to make a directory called <code>precompiled.h.gch</code> and put
  the precompiled header files there,
  one file for each set of <code>g++</code> command-line parameters.</p>
  
  <p>So now i wonder how i should change my Makefile to tell <code>g++</code> to create
  the gch-files this way.
  Maybe i can run <code>g++</code> just to test whether it can use any existing file
  in the <code>precompiled.h.gch</code> directory,
  and if not, generate a new precompiled header with a unique file name.</p>
  
  <p>Does gcc have support for doing such a test?</p>
  
  <p>Maybe i can implement what i want in another way?</p>