My Makefile is below, i used the .d files for auto-dependencies,but it does not work when i just modified some .h files, it's strange, but why.. thanks for you help
PROGRAM := a.out
SRCDIRS := ./src/access
INCLUDE := -I./include/access
SRCEXTS := .cpp
CPPFLAGS := -g -Wall
LDFLAGS :=
CXX = g++
RM = rm -f
SHELL = /bin/sh
SOURCES = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
OBJS = $(foreach x,$(SRCEXTS), \
$(patsubst %$(x),%.o,$(filter %$(x),$(SOURCES))))
DEPS = $(patsubst %.o,%.d,$(OBJS))
.PHONY : all objs clean cleanall rebuild
all : $(PROGRAM)
objs : $(OBJS)
%.o : %.cpp
$(CXX) -c $(CPPFLAGS) $< -o $@ $(INCLUDE)
$(PROGRAM) : $(OBJS)
$(CXX) -o $(PROGRAM) $(OBJS) $(LDFLAGS)
rebuild: clean all
clean :
@$(RM) $(OBJS) $(DEPS)
cleanall: clean
@$(RM) $(PROGRAM)
-include $(DEPS)
%.d : %.cpp
rm -f $@; $(CXX) -MM $< $(INCLUDE) > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$