OK, I had a play with this using a little project I had sitting around. I reckon that this does the job for auto dependencies:
Code:
CPPFLAGS=-Wall -Wextra -pedantic -std=c++0x
OBJS=driver.o logger.o properties.o
driver: $(OBJS)
$(CXX) $(OBJS) -o driver
-include $(OBJS:.o=.d)
%.o: %.cpp
$(CXX) -c $*.cpp $(CPPFLAGS) -MMD -MP -o $*.o
clean:
rm -f driver *.o *.d
Adapt to your taste obviously. It seems to work, even without that nasty sed stuff in the links I gave you. They don't mention the -MP option but it generates the dummy targets they refer to and I was able to rename a header file and have it recompile without complaint.
EDIT: you can make it even shorter with implicit rules
Code:
CPPFLAGS=-Wall -Wextra -pedantic -std=c++0x -MMD -MP
CC=g++
OBJS=driver.o logger.o properties.o
driver: $(OBJS)
-include $(OBJS:.o=.d)
clean:
rm -f driver *.o *.d
Bookmarks