The GNU Make Book

GNU Make Book

by John Graham-Cumming
April 2015, 256 pp.
ISBN-13: 
978-1-59327-649-2

GNU make is the most widely used build automation tool, but it can be challenging to master and its terse language can be tough to parse for even experienced programmers. Those who run into difficulties face a long, involved struggle, often leaving unsolved problems behind and GNU make's vast potential untapped.

The GNU Make Book demystifies GNU make and shows you how to use its best features. You'll find a fast, thorough rundown of the basics of variables, rules, targets, and makefiles. Learn how to fix wastefully long build times and other common problems, and gain insight into more advanced capabilities, such as complex pattern rules. With this utterly pragmatic manual and cookbook, you'll make rapid progress toward becoming a more effective user.

You'll also learn how to:

  • Master user-defined functions, variables, and path handling
  • Weigh the pitfalls and advantages of GNU make parallelization
  • Handle automatic dependency generation, rebuilding, and non-recursive make
  • Modify the GNU make source and take advantage of the GNU Make Standard Library
  • Create makefile assertions and debug makefiles

GNU make is known for being tricky to use, but it doesn't have to be. If you’re looking for a deeper understanding of this indispensable tool, you'll find The GNU Make Book to be an indispensable guide.

Author Bio 

John Graham-Cumming is a longtime GNU make expert. He wrote the acclaimed machine learning–based POPFile email filter and successfully petitioned the British government to apologize for its treatment of Alan Turing. He holds a doctorate in computer security from Oxford University and works at CloudFlare.

Table of contents 

Chapter 1: The Basics Revisited
Chapter 2: Makefile Debugging
Chapter 3: Building and Rebuilding
Chapter 4: Pitfalls and Problems
Chapter 5: Pushing the Envelope
Chapter 6: The GNU Make Standard Library

View the detailed Table of Contents (PDF)
View the Index (PDF)

Reviews 

"An expert, detailed review of the features and facilities of make, together with superb advice on how to get the most benefits from it."
Computing Reviews

"Here's a book that could teach you more than you ever thought possible about make. Amazingly thorough, extremely practical, and very well written."
Sandra Henry-Stocker, IT World (Read More)

"Whether you habitually program in a compiled language or just need to resort to it from time to time, this book will help you use Make in a way that reduces errors, improves build times and enhances the quality of your code."
Steve Mansfield-Devine, editor of Elsevier's Network Security Newsletter

"I think this book is fantastic."
Matthew Helmke, author of Ubuntu Unleashed

Updates 

Page 22:

The paragraph: "Note that this makefile does define a variable called _, which you could access as $(_) or even $_. Using the underscore as a name is one way to indi- cate that the variable is just a placeholder, and its value should be ignored." should read "Note that this makefile defines a variable called _check, which you could access as $(_check). Putting an underscore at the start of a name is one way to indicate that the variable is just a placeholder, and its value should be ignored."

Page 47:

In Listing 2-4 the final two lines are:

11 $(YS): ; @echo $(Y) $(Y)
12 $(ZS): ; @echo $(Z) $(Z)

They should read:

11 $(YS):
12 -> @echo $(Y) $(Y)
13 $(ZS):
14 -> @echo $(Z) $(Z)

This makes the line numbers referenced in the text correct but does not change the functionality of the makefile.

Page 48:

The text "The output shows that S is first used twice on line 8 (the all target used XS and YS, which both use S). Then S appears again on line 4 (because YS
is used) and line 12 (because XS is used)." should read "The output shows that S is first used twice on line 8 (the all target used XS and YS, which both use S). Then S appears again on line 11 (because YS
 is used) and line 12 (because XS is used)"

Page 53:

The make output is shown as

$ make
make: Building foo.o
cc -c -o foo.o foo.c
Makefile:7: Building bar

But should be:

$ make
Makefile:2: Building foo.o
cc -c -o foo.o foo.c
Makefile:7: Building bar

and the line "Because no makefile or line number information gets printed, we know that a built-in rule was used here." removed.