GNU Make: How to perform second expansion with suffix-changing substitution
<h1>What I'm going for (what's failing)</h1>

<p>I have a list of dependencies for each file:</p>

<pre><code>point_deps =
bounds_deps = point
triangle_deps = point bounds
Image_deps = types bounds triangle
main_deps = Image triangle bounds point types
</code></pre>

<p>I'd like to write a rule to include the relevant dependencies. Here's my best attempt:</p>

<pre><code>out/%.o: src/%.cpp src/%.h $$($$*_deps:%=src/%.h)
  g++ -o $@ -c $&lt;
</code></pre>

<p>I expect <code>$*</code> to evaluate to, for instance, "main". Then the <a href="https://stackoverflow.com/a/12071918/1433127">suffix-changing substitution</a> should change each entry in the dependency list to begin with "src/" and end with ".h".</p>

<p>When I try to run the code above, I get an error (on the <code>out/%.o</code> line):</p>

<pre><code>makefile:26: *** multiple target patterns.  Stop.
</code></pre>

<h1>What's working (non-optimal)</h1>

<p>For now I have to create a separate variable for each file's header dependencies:</p>

<pre><code>point_deps_h = $(point_deps:%=src/%.h)
bounds_deps_h = $(bounds_deps:%=src/%.h)
triangle_deps_h = $(triangle_deps:%=src/%.h)
Image_deps_h = $(Image_deps:%=src/%.h)
main_deps_h = $(main_deps:%=src/%.h)
</code></pre>

<p>Then I can use <a href="https://stackoverflow.com/a/10870114/1433127">secondary-expansion</a> to include the correct header files:</p>

<pre><code>out/%.o: src/%.cpp src/%.h $$($$*_deps_h)
    g++ -o $@ -c $&lt;
</code></pre>