title: Iterating over a directory of files using GNU Make
body: <p>My project has a directory called <code>tests/</code> which contains an arbitrary number of C source files, each one is a self-contained program designed to test a library. For each of these sourcefiles, I want to create an executable of the same name in my <code>build/</code> directory. </p>
  
  <p>E.g. <code>tests/test_init.c</code> would compile to an executable file <code>build/test_init</code>.</p>
  
  <p>Currently, my Makefile snippet looks like the following:</p>
  
  <pre><code>BUILD_DIR = build
  TEST_DIR = tests
  
  test_sources:= $(TEST_DIR)/*.c
  test_executables:= $(patsubst %.c, %, $(test_sources))
  
  .PHONY: tests
  
  tests: $(test_executables)
      $(CC) $^ -o $@ -g
  </code></pre>
  
  <p>But this fails to produce to desired result. Any help would be much appreciated.</p>