Auto-Dependency Generation in GNU Make

I renovated some makefiles this week and found myself wanting to generate dependencies of a piece of code automatically from ‘gcc -M’. The existing Makefile had an explicit “make depends” step that would invoke ‘gcc -M’ for each of the source files. This is annoying because all generated Makefiles would have to be recreated if one file’s dependencies changed.

The GNU Make Manual has a section on automatically generating prerequisites, which only gets you part of the way.

I owe a good deal of gratitude to Tom Tromey and Paul D. Smith for creating and writing up instructions on how GNU Make can automatically generate dependencies for source files. They discuss even better ways of generating dependency files and build upon the GNU Make Manual method.

Slashdot poll: Most Useful UNIX Tool

In response to the current /. poll, Most Useful UNIX Tool: I have the following from my ~/.zhistory at work:

Which is interesting to me. I can explain some of the counts:

  • I run cat $file | (grep|sed|awk) | ... too often out of a good/bad habit.
  • exit is small because I’ve bound x to exit (which itself is a bad habit; I should have just started using Control-D.
  • ssh > telnet
  • I don’t have root, so init isn’t really used, and my regex isn’t careful enough to eliminate disk_init.
  • sed is mega-useful, but is usually the second command in a pipeline. I want to start using perl -pe more.