title: Finding the appropriate executable in a Makefile
body: <p>I'm writing a Makefile that needs to execute the program <code>foo1</code>, which is usually provided by the operating system. Some operating systems provide this binary with a different name, <code>foo2</code>.</p>
  
  <p>I'm trying to figure out how to best test for the correct executable and exist if neither doesn't exist. I've had a few approaches but they all seem ugly and I figured there might be a more appropriate way to do this.</p>
  
  <p>I tried this:</p>
  
  <pre><code>FOO = $(shell which foo foo2)
  
  target:
     @which $(FOO) &gt; /dev/null
     $(FOO)
  </code></pre>
  
  <p>I don't find this very elegant because if both <code>foo</code> and <code>foo2</code> exist on the system, <code>which</code> will actually return two lines. It's also weird that I call <code>which</code> twice and that I rely on an error being emitted when I don't pass anything to the second <code>which</code>.</p>
  
  <p>In short, what's a better way?</p>