title: Makefile: run the same command with different arguments on different targets
body: <h1>Code</h1>
  
  <p>Consider the following makefile snippet:</p>
  
  <pre><code>COMMIT := $(shell git rev-parse HEAD)
  
  build:
      docker build -f Dockerfile --no-cache=false -t $(COMMIT) .
  rebuild:
      docker build -f Dockerfile --no-cache=true  -t $(COMMIT) .
  </code></pre>
  
  <h1>The problem</h1>
  
  <p>The only difference between <code>build</code> and <code>rebuild</code> is the value of the <code>--no-cache</code> parameter. Obviously, rewriting the same command with a slight change is a bad practice; it breaks the DRY principle, and if I ever need to change something else in the command - for example, the value of <code>-t</code> - I would have to change it across all relevant targets.</p>
  
  <p>I had something like this in mind:</p>
  
  <pre><code>COMMIT := $(shell git rev-parse HEAD)
  NO_CACHE := false
  
  build:
      docker build -f Dockerfile --no-cache=$(NO_CACHE) -t $(COMMIT) .
  rebuild:
      NO-CACHE = true
      make build
  </code></pre>
  
  <p>I tried playing with the variables, with no luck.</p>
  
  <h1>My question</h1>
  
  <p>What would be an elegant way to write the <code>docker build</code> command once, and have each target alter its parameter?</p>