Donald Knuth once said that, given a choice between two languages, he'd choose the one with the better debugger. For that reason, he'd probably never choose to use Make. Its debugging facilities are virtually nonexistent.
In this article, I address this problem by providing practical debugging tips I've used to debug real-world Makefiles. To illustrate, I use GNU Make because of its wide platform support and rich language. Unfortunately, that rich language doesn't include much in the way of debugging. In fact, GNU Make's -d command-line flag seems to produce output more useful to the author of GNU Make than to someone facing Makefile problems.
The only GNU Make command-line option that's really useful for Makefile debugging is -p, and all it does is dump the contents of GNU Make's built-in rules and macros, and any rules or macros defined in the Makefile. Granted, that's an enormous amount of information that can be useful in debugging, but hardly counts as a debugger.
Broadly, Makefile debugging problems fall into three categories:
- What's the value of macro X and how did it get it?
- Why did file foo get built?
- How does Make log file output relate to the rules in the Makefile?