Dependencies in the makefile can be generated with g++ -MM *.cpp >.depend and then include the .depend rule.