Add more sophisticated dependency tracking with -MMD.

Avoids full rebuilds when just one header is changed.