title: Obtaining directory makefile resides in
body: <p>What is the correct way to get the directory where the currently executing makefile resides?</p>
  
  <p>I'm currently using <code>export ROOT=$(realpath $(dir $(lastword $(MAKEFILE_LIST))))</code> and am running into some problems where when running make with the exact same options will result in different values for ROOT.  About 90%of the time it has the correct value, but in the remaining 10% there are a number of invalid paths.</p>