title: Makefile works %.c, does not work %.cpp
body: <p>I have a set of makefiles I use to build a 'big' C project.  I am now trying to reuse some in my C++ project and have run into this headache that I just cannot figure out.</p>
  
  <p>The makefile looks like this</p>
  
  <pre><code>SOURCES = \
  elements/blue.cpp
  
  # Dont edit anything below here
  
  VPATH = $(addprefix $(SOURCE_DIR)/, $(dir $(SOURCES)))
  
  CXXFLAGS = $(OPT_FLAGS) -MMD -MF $(BUILD_DIR)/$*.d -D_LINUX -DNDEBUG -pipe
  DCXXFLAGS = $(DEBUG_FLAGS) -MMD -MF $(BUILD_DIR)/$*.d -v -D_LINUX -D_DEBUG -pipe
  
  OBJECTS := $(patsubst %.cpp, $(BUILD_DIR)/Release/%.o, $(notdir $(SOURCES)))
  DOBJECTS := $(patsubst %.cpp, $(BUILD_DIR)/Debug/%.o, $(notdir $(SOURCES)))
  
  $(OBJECTS): $(BUILD_DIR)/Release/%.o: %.cpp
      +@[ -d $(dir $@) ] || mkdir -p $(dir $@)
      $(CPP) $(INCLUDE) $(CXXFLAGS) $(DEFINES) -o $@ -c $&lt;
  </code></pre>
  
  <p>Its a little complicated but what it does in C is build all the %.c files defined in SOURCES and put the object files in BUILD_DIR.  It works great in c, but this does not work with cpp files.  I get</p>
  
  <pre><code>make: *** No rule to make target `blue.cpp', needed by `build/Release/blue.o'.  Stop.
  </code></pre>
  
  <p>Its like VPATH is not working at all.  I tried </p>
  
  <pre><code>vpath %.cpp src/elements
  </code></pre>
  
  <p>but that does not work either.  </p>
  
  <p>Amazingly enough, renaming blue.cpp to blue.c and editing the makefile back to the %.c usage does work, it compiles just fine.</p>
  
  <p>Am I going crazy here?</p>