title: Setting Makefile variable to result of command in rule
body: <p>I am trying to assign the result of a command to a variable in GNU make.  It works if I do it outside the rule:</p>
  
  <pre><code>$ cat stack.mk
  GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
  
  all:
      @echo Git branch is $(GIT_BRANCH)
  
  $ make -f stack.mk all
  Git branch is dev
  </code></pre>
  
  <p>But not if I put it in the rule body:</p>
  
  <pre><code>$ cat stack.mk
  all:
      export GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
      @echo Git branch is $(GIT_BRANCH)
  
  $ make -f stack.mk all
  export GIT_BRANCH=dev
  Git branch is
  </code></pre>
  
  <p>Is it possible to assign variables in a rule.  At this point I would like to assign the results of a couple of <code>git</code> commands to shell/<code>Makefile</code> variables.</p>