title: Compiling C++ and C files in one makefile
body: <p>I have a makefile that looks like this:</p>
  
  <pre><code>CS := a.c b.c
  CPPS := foo.cpp bar.cpp
  SOURCES := $(CS) $(CPPS)
  OBJS := $(CS:%.c=$(OBJSDIR)/%.o) $(CPPS:%.cpp=$(OBJSDIR)/%.o)
  </code></pre>
  
  <p>I want to create a single rule to compile them all. But the only option I can think of is this:</p>
  
  <pre><code>$(OBJSDIR)/%.o: %.cpp
      $(GXX) $(GXXFLAGS) -c $&lt; -o $@
  </code></pre>
  
  <p>But of course it doesn't work because some of the object files don't have a matching C++ source file.</p>
  
  <p>Any idea?</p>