title: Perfect makefile
body: <p>I'd like to use <a href="http://en.wikipedia.org/wiki/Make_%28software%29" rel="nofollow noreferrer">make</a> to get a modular build in combination with <a href="http://en.wikipedia.org/wiki/Continuous_integration" rel="nofollow noreferrer">continuous integration</a>, <em>automatic unit testing</em> and <em>multi-platform builds</em>. Similar setups are common in Java and .NET, but I'm having a hard time putting this together for make and C/C++. How can it be achieved?</p>
  
  <p>My requirements:</p>
  
  <ul>
  <li>fast build;  non-recursive make (Stack Overflow question <em><a href="https://stackoverflow.com/questions/559216">What is your experience with non-recursive make?</a></em>)</li>
  <li>modular system (that is, minimal dependencies, makefile in subdirectory with components)</li>
  <li>multiplatform (typically PC for unit testing, embedded target for system integration/release)</li>
  <li>complete dependency checking</li>
  <li>ability to perform (automatic) unit tests (Agile engineering)</li>
  <li>hook into continuous integration system</li>
  <li>easy to use</li>
  </ul>
  
  <p>I've started with <a href="http://code.google.com/p/nonrec-make" rel="nofollow noreferrer">non-rec make</a>. I still find it a great place to start.</p>
  
  <p>Limitations so far:</p>
  
  <ul>
  <li>no integration of unit tests</li>
  <li>incompatibility of windows based ARM compilers with Cygwin paths</li>
  <li>incompatibility of makefile with Windows \ paths</li>
  <li>forward dependencies</li>
  </ul>
  
  <p>My structure looks like:</p>
  
  <blockquote>
  <pre><code>    project_root
         /algorithm
                   /src
                       /algo1.c
                       /algo2.c
                   /unit_test
                       /algo1_test.c
                       /algo2_test.c
                   /out
                       algo1_test.exe
                       algo1_test.xml
                       algo2_test.exe
                       algo2_test.xml
               headers.h
         /embunit
         /harnass
     makefile
     Rules.top
  </code></pre>
  </blockquote>
  
  <p>I'd like to keep things simple; here the unit tests (algo1_test.exe) depend on both the 'algorithm' component (ok) and the unit test framework (which may or may not be known at the time of building this). However, moving the build rules to the top make does not appeal to me as this would distribute local knowledge of components throughout the system.</p>
  
  <p>As for the Cygwin paths: I'm working on making the build using relative paths. This resolves the <code>/cygdrive/c</code> issue (as compilers can generally handle / paths) without bringing in C: (which make dislikes). Any other ideas?</p>