title: capture git branch name in makefile variable
body: <p>I am writing a Makefile and would like to capture the current branch name in a variable to be passed into a --define. 
  Since the script sometimes but not always runs on travis the git repository might be in detached state.</p>
  
  <p>I can extract the branch name on the command line but unfortunately not capture it in a variable. It seems as if the print $$2 does not work within the Makefile environment.</p>
  
  <p>My current line is: </p>
  
  <pre><code>BRANCH := $(shell git for-each-ref --format='%(objectname) %(refname:short)' refs/heads | awk "/^$$(git rev-parse HEAD)/ {print $$2}")
  </code></pre>
  
  <p>and I get </p>
  
  <pre><code>dfd943a57015dbd2129ca7b7033c4e1749f18974 BRANCH_NAME 
  </code></pre>
  
  <p>instead of just </p>
  
  <pre><code> BRANCH_NAME
  </code></pre>