title: Getting parent directory's basename in makefile
body: <p>I need to automate a variable alignment in my Makefile. My Makefile's full file path is:</p>
  
  <pre><code>/home/e2/branchname/projectname/modulename/Makefile
  </code></pre>
  
  <p>In my Makefile, I have a variable <code>BUILD_DIR</code>, a part of which should be equal to the <code>branchname</code> in the full path.</p>
  
  <p>So I did this:</p>
  
  <pre><code>BRANCH_NAME= $(shell cd ../.. &amp;&amp; basename "$PWD" &amp;&amp; cd projectname/modulename)
  BUILD_DIR=$(HOME)/$(BRANCH_NAME)/build
  </code></pre>
  
  <p>Apparently I expected <code>BUILD_DIR</code> to be <code>~/branchname/build</code> here, but after <code>make</code> I got <code>~/WD/build</code> instead. I think it's most likely that I got a wrong <code>BRANCH_NAME</code>. Is there something wrong with what I did? And if yes I'd like to get some advice about how to do it correctly.</p>
  
  <p>Thanks.</p>