title: Makefile patsubst using value of shell variable
body: <p>As part of a make install rule for a testing suite, I'd like to move all binary executables in one directory (a src directory) to a bin directory.  I thought an easy way to do this would be to simply loop over each file in the <code>src</code> directory and then use <code>patsubst</code> to replace <code>src</code> with <code>bin</code> in each path.  Unfortunately, I can't get it to work because I can't get <code>make</code> to evaluate the name of the current FILE in each loop iteration.  All I have access to is the bash shell variable <code>$$FILE</code>, but when I use this with the <code>make</code> <code>patsubst</code> function, it doesn't actually <em>evaluate</em> the shell variable <code>$$FILE</code>... rather, the <code>patsubst</code> function seems to just see the string <code>"$FILE"</code>.</p>
  
  <p>So, here is what I'm trying:</p>
  
  <pre><code>install :
      -- irrelevant stuff snipped --
  
      for FILE in $(BINARY_TARGETS); do \
          if [ -f $$FILE ]; then mv -f $$FILE $(patsubst %/src/,%/bin/,$$FILE); fi \
      done 
  </code></pre>
  
  <p>This results in an error for each file:</p>
  
  <pre><code>mv: ‘./src/foo/bar’ and ‘./src/foo/bar’ are the same file
  </code></pre>
  
  <p>This error leads me to understand that the <code>patsubst</code> function in <code>make</code> is not actually evaluating shell variables, but just sees <code>$FILE</code>, and so the result is that it doesn't find the substitution pattern, and the final command passed to <code>mv</code> has the source and destination path as the same string.</p>
  
  <p>So, is there a way to get <code>patsubst</code> to evaluate the value of a shell variable?  Or is there a better way in general to accomplish what I'm trying to achieve here?</p>