Americas

  • United States
sandra_henrystocker
Unix Dweeb

The GNU Make Book

Reviews
May 10, 20154 mins
Data CenterLinuxOpen Source

John Graham-Cumming no starch press, 2015

Here’s a book that could teach you more than you ever thought possible about make.

One of those Unix utilities that I took for granted all these years, make is actually a lot more versatile than I imagined and quite a bit more complicated. For decades I ran through the standard four steps required to install optional software tools on the Unix systems that I managed — configure, make, make install, and make clean — the software building litany of the Unix sysadmin. To be honest, the syntax of the makefiles looked a lot trickier than any of the scripts I’d ever built and I was always grateful that I didn’t have to modify them, never mind build them myself.

If at this point, you’re wondering what I’m talking about, this book isn’t for you. But just so you get some value out of this post, allow me to explain that the make utility allows developers to prepare instructions that make it possible for people to compile products from source code on a wide range of systems. The command is “make” and the file that contains the compilation instructions is called a “Makefile”. That’s probably all you need to know.

For those of you who need to build makefiles from scratch or troubleshoot them when the software build that they’re intended to perform just isn’t working, the story is altogether different. You might run into errors and spend a lot of time trying to figure out what’s wrong and how to fix it. GNU make has been called “difficult” and “cryptic” and probably a lot of other things as well, but if a book can be said to have a theme, this book’s theme is “It ain’t necessarily so”.

The book starts out with an assumption that you understand the very basics of make, but includes a chapter that revisits the elementary components such as environment variables, debugging variables, the make environment, target- and pattern-specific variables, logical operators, simple and recursive variables, built-in functions, etc.

Once you get past the basics, it treats you to an entire chapter on how to do debugging when working with make. There’s no built-in debugger, but there’s still a lot that you can do to track down problems that you run into and this chapter alone makes this book an essential read for anyone responsible for preparing makefiles. It details techniques such as dumping variables and tracing their use, tracing rule execution, making good use of the -d option, setting break points in rules and patterns, setting break points in makefiles, using pattern rules, non-recursive make, etc.

The remaining four chapters take you deeply into the building and rebuilding process, explain many of the problems that you could run into, provide advanced techniques that can be invaluable if and when you need them, and show you how to work with the GNU make standard library (GMSL).

You can expect to emerge from your reading of this book knowing how to avoid unnecessarily long build times, use some of the more advanced capabilities of make, avoid troublesome pitfalls — especially when you’re working with parallelization, manage automatic dependency generation along with rebuilding and non-recursive make, and do some very pragmatic troubleshooting when you run into problems.

I’d recommend it to anyone who needs to use make and wants to know how to avoid problems and use make most effectively. It’s not an easy read, but it’s amazingly thorough, extremely practical, and very well written.

Footnote:

An interesting side note on the author, John Graham-Cumming: Apparently, he is best known for successfully petitioning the British government to apologize for its treatment of Alan Turing. Having watched The Imitation Game, I was particularly pleased to see this noted on the back of the book.

sandra_henrystocker
Unix Dweeb

Sandra Henry-Stocker has been administering Unix systems for more than 30 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She lives in the mountains in Virginia where, when not working with or writing about Unix, she's chasing the bears away from her bird feeders.

The opinions expressed in this blog are those of Sandra Henry-Stocker and do not necessarily represent those of IDG Communications, Inc., its parent, subsidiary or affiliated companies.

More from this author