title: depending on directories in make
body: <p>This is a followup to my earlier question: <a href="https://stackoverflow.com/questions/4403861/error-in-makefile/">SO 4403861</a> because the suggested solutions broke the dependencies, making the makefile useless.  I can't figure out why.</p>
  
  <p>I am using gnu make 3.82
  I have a rule that works if the obj directory has been created:</p>
  
  <pre><code>objdir:=../obj
  $(objdir)/%.o: %.C
      $(COMPILE) -MM -MT$(objdir)/$(notdir $@) $&lt; -o $(DEPDIR)/$(notdir $(basename $&lt;).d )
      $(COMPILE) -o $(objdir)/$(notdir $@ ) -c $&lt;
  </code></pre>
  
  <p>However, if the obj directory isn't there, make fails.  I wanted make to automatically create ../obj on demand, so I added what I thought was very simple:</p>
  
  <pre><code>$(objdir)/%.o: %.C $(objdir)
      $(COMPILE) -MM -MT$(objdir)/$(notdir $@) $&lt; -o $(DEPDIR)/$(notdir $(basename $&lt;).d )
      $(COMPILE) -o $(objdir)/$(notdir $@ ) -c $&lt;
  
  $(objdir):
     if [ ! -d $(objdir) ] ; then mkdir $(objdir) ; fi
  </code></pre>
  
  <p>When I do so, make always forces the compile, every time.  Why?  The mkdir should not happen unless there is no directory?  Why are dependencies destroyed by this simple change?</p>