title: Automake: how to handle global and local 'make check' effectively?
body: <p>In a larger project, I have set up <code>./tests/Makefile.am</code> to run a number of tests when I call <code>make check</code>. The file <code>global_wrapper.c</code> contains the setup / breakdown code, and it calls test functions implemented in several subdirectories.</p>
  
  <pre><code>TESTS = global_test
  
  check_PROGRAMS = global_test
  
  global_test_SOURCES = global_wrapper.c foo/foo_test.c bar/bar_test.c
  </code></pre>
  
  <p>Works great. But the tests take a long time, so I would like to be able to optionally execute only tests from a single subdir. This is how I did it at first.</p>
  
  <p>I added the subdirectories:</p>
  
  <pre><code>SUBDIRS = foo bar
  </code></pre>
  
  <p>In the subdirectories, I added local wrappers and <code>Makefile.am</code>'s:</p>
  
  <pre><code>TESTS = foo_test
  
  check_PROGRAMS = foo_test
  
  # the foo_test.c here is of course the same as in the global Makefile.am
  foo_test_SOURCES = foo_wrapper.c foo_test.c
  </code></pre>
  
  <p>This, too, works great - when I call <code>make check</code> in the subdirectory <code>foo</code>, only the foo tests are executed.</p>
  
  <p><strong>However</strong>, when I now call <code>make check</code> in <code>./tests</code>, <em>all tests are executed twice</em>. Once through <code>global_test</code>, and once through the local test programs.</p>
  
  <p>If I omit the <code>SUBDIRS</code> statement in the global <code>Makefile.am</code>, the subdirectory makefiles don't get build. If I omit <code>TESTS</code> from the local <code>Makefile.am</code>'s, <code>make check</code> doesn't do anything for the local directories.</p>
  
  <p>I'm not that familiar with automake, but I am pretty sure there is some way to solve this dilemma. Can anybody here give me a hint?</p>