If you look at automatic make file dependency rule generation for the g++ compiler, there are a lot of different solutions on the Internet. I’m not sure which one is the best, but it sure involved the -MM or -MMD switch to g++.

I found the following to work sufficiently at the end of my simple project Makefile:

.SUFFIXES: .d

.cpp.d:
    $(CXX) -MM -MT $@ -MT $(patsubst %.d,%.o,$@) $(CXXFLAGS) -o $@ $^

include $(patsubst %.cpp,%.d,$(SRC))

the include directive will make sure that the necessary name.d rule files are generated.

this requires the source files predefined in SRC, example:

SRC := $(wildcard *.cpp)