title: Dependency ordering error for multi-job make
body: <p>The Makefile below has to create (multiple) output directories, and generate output in those directories, from input in the directory above. So, on entry, dir<em>n</em> exists, and dir<em>n</em>/file.foo exists. The build has to create dir<em>n</em>/out/file.bar.</p>
  
  <p>This Makefile works when run as a single job (note that it creates the two required source directories and files in the <code>$(shell)</code>). It presumably works because <code>makedirs</code> is the first/leftmost prerequisite for <code>all</code>. However, it doesn't work for a multi-job make (ie. <code>make -j4</code>/whatever).</p>
  
  <p>Any ideas on how to fix the dependencies to ensure that the output directories are made before they're required?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I should have made it clear that I have tried various order-only prerequisite solutions, but I couldn't do this and guarantee that the target actually rebuilt (the point of order-only is generally to <em>prevent</em> rebuilding, not enforce dependency ordering). If you have an OO solution, please check it! Thanks.</p>
  
  <pre><code># expected output:
  # made directories
  # copying dir1/out/../file.foo to dir1/out/file.bar
  # copying dir2/out/../file.foo to dir2/out/file.bar
  # created all output files
  # done
  
      $(shell mkdir dir1 &gt;&amp; /dev/null; touch dir1/file.foo; \
              mkdir dir2 &gt;&amp; /dev/null; touch dir2/file.foo)
  
      OUTDIRS = dir1/out dir2/out
      OUTPUTS = dir1/out/file.bar dir2/out/file.bar 
  
      .DEFAULT_GOAL := all
  
      .PHONY: makedirs $(OUTDIRS)
  
      .SUFFIXES: .foo .bar
  
      %.bar : ../%.foo
          @echo "copying $&lt; to $@"
          @cp $&lt; $@
  
      all : makedirs outputs
          @echo "done"
  
      outputs : $(OUTPUTS)
          @echo "created all output files"
  
      makedirs : $(OUTDIRS)
          @mkdir -p $(OUTDIRS)
          @echo "made directories"
  
      clean :
          @rm -rf dir1 dir2
  </code></pre>