title: Better rules for gnu make with docker
body: <p>Suppose my source files are located in</p>
  
  <pre><code>~/dev/root
  </code></pre>
  
  <p>Inside <code>~/dev/root</code> are a number of projects.</p>
  
  <p>e.g.</p>
  
  <pre><code>~/dev/root/libraries/libx
  ~/dev/root/apps/app/appy
  ~/dev/root/docker/appy
  </code></pre>
  
  <p>The build tool I use is called tundra2 and is invoked from the root level.</p>
  
  <p>So if I run tundra2 production appy it'll produce it's output to</p>
  
  <pre><code>~/dev/root/t2-output/linux64-gcc-production-default
  </code></pre>
  
  <p>The binary is directly below that directory.  There are also intermediate files located within sub-directories in that directory.</p>
  
  <p>Now the annoying bit.  For whatever reason, docker build uses a daemon process that copies everything from the directory it's being run from to a temporary directory.  It then produces it's image from there.  I haven't yet spent the time to try and extend tundra2 to cope with docker so I've been using a Makefile.</p>
  
  <p>So inside the docker/appy directory I have my Dockerfile.  Alongside I have a makefile.  The idea is to cd into that directory and run make.
  If everything builds, it should copy the outputs from t2-output into the docker/appy directory and run docker build.</p>
  
  <p>So far, I've specified the build targets like:</p>
  
  <pre><code>T2OUT=../../t2-output/linux64-gcc-production-default
  TAG = "appy"
  all: $(T2OUT)/appy
  
  $(T2OUT)/appy: 
       cd $(T2OUT) &amp;&amp; tundra2 production appy
       cp $&lt; .
       docker build -t $(TAG) .
  </code></pre>
  
  <p>etc</p>
  
  <p>The above is very cumbersome.  So I tried experimenting below with VPATH but that doesn't work.  <code>make --debug=v</code> confirms it. Can you suggest an alternative?  (I might even consider another build tool provided it isn't npm based)</p>
  
  <p>VPATH=../../t2-output/linux64-gcc-production-default
  %.so: 
    ...</p>
  
  <p>Sometimes I run the tundra2 build directly from ~/dev/root</p>
  
  <p>So what I'm trying to get make to do is detect that appy and the copied appy are different.  </p>
  
  <p>i.e.  if <code>~/dev/root/t2-output/linux64-gcc-production-default/appy</code> is different to: <code>~/dev/root/cluster/docker/appy/appy</code></p>
  
  <p>Then copy <code>~/dev/root/t2-output/linux64-gcc-production-default/appy</code> to <code>~/dev/root/cluster/docker/appy/appy</code></p>
  
  <p>And if <code>~/dev/root/t2-output/linux64-gcc-production-default/appy</code> doesn't exist, even if <code>~/dev/root/cluster/docker/appy/appy</code> does exist, we should go to ../../.. run tundra2 and copy the output as above to the docker/appy directory so that we can run docker build</p>