This will not track dependencies on headers and other include files, so this will not properly rebuild when these files are updated. With not too much modification, we can ask gcc to output a dependency file next to each object file that is produced. We ask make to include these dependency files where available:

The options will generate dependency files alongside compilation (-MMD instead of -MM), and with phony targets (-MP) for dependencies. The rationale for doing this is described in Autodependencies with GNU make, although this article dates from a time when apparently only -MM was available. The options -MMD -MP are a modern way of implementing what is proposed in the article.

Besides GCC, also Clang 3.0 and ICC 12.1 seem to support these options.