title: How do I make an easy-to-update makefile?
body: <p>My makefile looks something like this:</p>
  
  <pre><code>FOO_OBJECT_FILES := $(OBJDIR)/Foo.cpp.o
  BAR_OBJECT_FILES := $(OBJDIR)/Bar.cpp.o $(OBJDIR)Bar.c.o
  ALL_OBJECT_FILES := $(FOO_OBJECT_FILES) $(BAR_OBJECT_FILES)
  
  $(BINDIR)/Foo.a: $(FOO_OBJECT_FILES)
      # Rules for making a static library out of Foo's object files go here.
  
  $(BINDIR)/Bar.a: $(BAR_OBJECT_FILES)
      # This uses the exact same command sequence as the previous rule.
  
  $(BINDIR)/All.a: $(ALL_OBJECT_FILES)
         # Ditto.
  
  # ...
  </code></pre>
  
  <p>When (not <em>if</em>) more targets are added to the project, the developer will have to update at least three things:</p>
  
  <ol>
  <li>The list of the new target's object files</li>
  <li>The list of all object files</li>
  <li>Targets for making the new target, even if it uses the same rules as the others</li>
  </ol>
  
  <p>Is there a way to simplify this process, or am I stuck with it?</p>
  
  <p>I tried using wildcard rules, but it doesn't look like they work with macros.</p>
  
  <pre><code>$(BINDIR)/%.a: $(%_OBJECT_FILES)
      # ...
  </code></pre>
  
  <p>You could treat the lists of object files as rules, but then the final target rules can't access them directly.</p>
  
  <pre><code>OBJECT_FILES_Foo: $(OBJDIR)/Foo.cpp.o
  OBJECT_FILES_Bar: $(OBJDIR)/Bar.cpp.o $(OBJDIR)Bar.c.o
  OBJECT_FILES_All: FOO_OBJECT_FILES BAR_OBJECT_FILES
  
  $(BINDIR)/%.a: OBJECT_FILES_%
      # This rule can't see into the object file lists to use them to build.
  </code></pre>
  
  <p>Is there no better way?</p>