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.
The makefile looks like this
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 $<
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
make: *** No rule to make target `blue.cpp', needed by `build/Release/blue.o'. Stop.
Its like VPATH is not working at all. I tried
vpath %.cpp src/elements
but that does not work either.
Amazingly enough, renaming blue.cpp to blue.c and editing the makefile back to the %.c usage does work, it compiles just fine.
Am I going crazy here?