title: How can I use macros to generate multiple Makefile targets/rules inside foreach? Mysterious behaviour
body: <p>I am using GNU make 3.81.  Here is a test makefile that demonstrates the problem:</p>
  
  <pre><code>define BOZO
  
  a$(1): b c
      touch a$(1)
  
  endef
  
  $(foreach i,1 2 3,$(call BOZO,$(i)))
  </code></pre>
  
  <p>The idea here is to use a macro template (BOZO) to generate rules that follow a predictable pattern.</p>
  
  <p>Problem: when I run make on this makefile I get an error saying:</p>
  
  <pre><code>Makefile.fake:10: *** multiple target patterns.  Stop.
  </code></pre>
  
  <p>(where line 10 is the line with the foreach).</p>
  
  <p>Now, I know what that error normally indicates.  Let's see what that line expands to by using the <code>info</code> function to send the expansion to standard out.  I change line 10 to be:</p>
  
  <pre><code>$(info $(foreach i,1 2 3,$(call BOZO,$(i))))
  </code></pre>
  
  <p>and I run:</p>
  
  <pre><code>$ make -n
  
  a1: b c
      touch a1
  
  a2: b c
      touch a2
  
  a3: b c
      touch a3
  
  make: *** No targets.  Stop.
  </code></pre>
  
  <p>Note that the "no targets" message is expected, since the $(info ...) function evaluates to empty but causes make to <em>print</em> the generated rules.</p>
  
  <p>Let's run those rules then shall we?</p>
  
  <pre><code>$make -n &gt; out.txt
  make: *** No targets.  Stop.
  $make -f out.txt a1 a2 a3
  touch a1
  touch a2
  touch a3
  $
  </code></pre>
  
  <p>AAARGH!  The rules work fine.  So... is the bug in make, or in my understanding?</p>
  
  <p>One final clue that might help diagnose: if I change the foreach line to:</p>
  
  <pre><code>$(foreach i,1,$(call BOZO,$(i)))
  </code></pre>
  
  <p>(so that foreach has only one iteration)</p>
  
  <p>and then do</p>
  
  <pre><code>$make a1
  </code></pre>
  
  <p>I get a different error:</p>
  
  <pre><code>make: *** No rule to make target `a1'.  Stop.
  </code></pre>
  
  <p>I don't know of any way to "see" the expansion of <code>$(foreach )</code> that make sees except for <code>$(info )</code>, and its output is legal, so I'm quite stumped.</p>