This SO post can help you:
make enable directive and create dependencies with -MM
Basically, make can generate a list of all the dependencies in a project. I use the following in all make files:
%.d: $(program_SRCS)
@ $(CC) $(CPPFLAGS) -MM $*.c | sed -e 's@^\(.*\)\.o:@\1.d \1.o:@' > $@
clean_list += ${program_SRCS:.c=.d}
ifneq "$(MAKECMDGOALS)" "clean"
-include ${program_SRCS:.c=.d}
endif
, . , foo.cpp, foo.h, bar.h, baz.h. foo.d make. foo.d :
foo.d foo.o: foo.cpp foo.h bar.h baz.h
, make .
, , , grep -l foo.h *.d, , foo.h.