The GNU Make Book

Book description

GNU Make Book is a practical, thorough guide to GNU Make basics, solutions, and advanced uses.

Publisher resources

View/Submit Errata

Table of contents

  1. The GNU Make Book
  2. About the Author
  3. About the Technical Reviewer
  4. Preface
  5. 1. The Basics Revisited
    1. Getting Environment Variables into GNU make
    2. Setting Variables from Outside the Makefile
    3. The Environment Used by Commands
    4. The $(shell) Environment
    5. Target-Specific and Pattern-Specific Variables
      1. Target-Specific Variables
      2. Pattern-Specific Variables
    6. Version Checking
      1. MAKE_VERSION
      2. .FEATURES
      3. Detecting $(eval)
    7. Using Boolean Values
      1. Undefined Variables in Conditionals
      2. Consistent Truth Values
    8. Logical Operations Using Boolean Values
      1. User-Defined Logical Operators
      2. Built-in Logical Operators (GNU make 3.81 and Later)
    9. Command Detection
    10. Delayed Variable Assignment
    11. Simple List Manipulation
    12. User-Defined Functions
      1. The Basics
      2. Argument-Handling Gotchas
      3. Calling Built-in Functions
    13. Recent GNU make Versions: 3.81, 3.82, and 4.0
      1. What’s New in GNU make 3.81
        1. .SECONDEXPANSION
          1. else
          2. The -L Command Line Option
        2. .INCLUDE_DIRS
        3. .FEATURES
        4. .DEFAULT_GOAL
        5. MAKE_RESTARTS
          1. New Functions
      2. What’s New in GNU make 3.82
        1. Backward Incompatibilities
        2. New Command Line Option: --eval
        3. New Special Variables: .RECIPEPREFIX and .SHELLFLAGS
        4. The .ONESHELL Target
        5. Changing Variables with the private and undefine Keywords
      3. What’s New in GNU make 4.0
        1. GNU Guile
        2. Loading Dynamic Objects
        3. Syncing Output with --output-sync
        4. The --trace Command Line Option
        5. New Assignment Operators: != and ::=
        6. The $(file) Function
      4. What’s New in GNU make 4.1
  6. 2. Makefile Debugging
    1. Printing the Value of a Makefile Variable
    2. Dumping Every Makefile Variable
    3. Tracing Variable Values
      1. Tracing Variable Use
      2. How the Variable Tracer Works
    4. Tracing Rule Execution
      1. An Example
      2. The SHELL Hack
      3. An Even Smarter SHELL Hack
      4. GNU make 4.0 Tracing
    5. Makefile Assertions
      1. assert
      2. assert_exists
      3. assert_target_directory
    6. An Interactive GNU make Debugger
      1. The Debugger in Action
      2. Breakpoints in Patterns
      3. Breakpoints in Makefiles
      4. Debugger Internals
    7. Dynamic Breakpoints in the GNU make Debugger
      1. Dynamic Breakpoints in Action
      2. The Easy Part
      3. The Trick
      4. Rocket Science
    8. An Introduction to remake
      1. Just Print and Trace
      2. Debugging
      3. Targets, Macro Values, and Expansion
  7. 3. Building and Rebuilding
    1. Rebuilding When CPPFLAGS Changes
      1. An Example Makefile
      2. Changing Our Example Makefile
      3. How Signature Works
      4. Limitations
    2. Rebuilding When a File’s Checksum Changes
      1. An Example Makefile
      2. Digesting File Contents
      3. The Modified Makefile
      4. The Hack in Action
      5. Improving the Code
    3. Automatic Dependency Generation
      1. An Example Makefile
      2. makedepend and make depend
      3. Automating makedepend and Removing make depend
      4. Making Deleted Files Disappear from Dependencies
      5. Doing Away with makedepend
      6. Using gcc -MP
    4. Atomic Rules in GNU make
      1. What Not to Do
      2. Using Pattern Rules
      3. Using a Sentinel File
    5. Painless Non-recursive make
      1. A Simple Recursive Make
      2. A Flexible Non-recursive make System
      3. Using the Non-recursive make System
      4. What About Submodules?
  8. 4. Pitfalls and Problems
    1. GNU make Gotcha: ifndef and ?=
      1. What ?= Does
      2. What ifndef Does
    2. $(shell) and := Go Together
      1. $(shell) Explained
      2. The Difference Between = and :=
      3. The Hidden Cost of =
    3. $(eval) and Variable Caching
      1. About $(eval)
      2. An $(eval) Side Effect
      3. Caching Variable Values
      4. Speed Improvements with Caching
      5. A Caching Function
      6. Wrapping Up
    4. The Trouble with Hidden Targets
      1. An Unexpected Error if the Hidden Target Is Missing
      2. The -n Option Fails
      3. You Can’t Parallelize make
      4. make Does the Wrong Work if the Hidden Target Is Updated
      5. You Can’t Direct make to Build foo.o
    5. GNU make’s Escaping Rules
      1. Dealing with $
      2. Playing with %
      3. Wildcards and Paths
      4. Continuations
      5. Comments
      6. I Just Want a Newline!
      7. Function Arguments: Spaces and Commas
      8. The Twilight Zone
    6. The Trouble with $(wildcard)
      1. $(wildcard) Explained
      2. Unexpected Results
      3. Unexpected Results Explained
    7. Making Directories
      1. An Example Makefile
      2. What Not to Do
      3. Solution 1: Build the Directory When the Makefile Is Parsed
      4. Solution 2: Build the Directory When all Is Built
      5. Solution 3: Use a Directory Marker File
      6. Solution 4: Use an Order-Only Prerequisite to Build the Directory
      7. Solution 5: Use Pattern Rules, Second Expansion, and a Marker File
      8. Solution 6: Make the Directory in Line
    8. GNU make Meets Filenames with Spaces
      1. An Example Makefile
      2. Escape Spaces with \
      3. Turn Spaces into Question Marks
      4. My Advice
    9. Path Handling
      1. Target Name Matching
      2. Working with Path Lists
      3. Lists of Paths in VPATH and vpath
      4. Using / or \
      5. Windows Oddity: Case Insensitive but Case Preserving
      6. Built-in Path Functions and Variables
      7. Useful Functions in 3.81: abspath and realpath
    10. Usman’s Law
      1. The Human Factor
      2. Poor Naming
      3. Silent Failure
      4. Recursive Clean
    11. Pitfalls and Benefits of GNU make Parallelization
      1. Using -j (or -jobs)
      2. Missing Dependencies
      3. The Hidden Temporary File Problem
      4. The Right Way to Do Recursive make
      5. Amdahl’s Law and the Limits of Parallelization
    12. Making $(wildcard) Recursive
    13. Which Makefile Am I In?
  9. 5. Pushing the Envelope
    1. Doing Arithmetic
      1. Addition and Subtraction
      2. Multiplication and Division
      3. Using Our Arithmetic Library: A Calculator
    2. Making an XML Bill of Materials
      1. An Example Makefile and BOM
      2. How It Works
      3. Gotchas
    3. Advanced User-Defined Functions
      1. Getting Started Modifying GNU make
      2. Anatomy of a Built-In Function
      3. Reverse a String
    4. GNU make 4.0 Loadable Objects
    5. Using Guile in GNU make
    6. Self-Documenting Makefiles
      1. Documenting Makefiles with print-help
      2. The Complete help-system.mak
  10. 6. The GNU Make Standard Library
    1. Importing the GMSL
    2. Calling a GMSL Function
    3. Checking the GMSL Version
    4. Example Real-World GMSL Use
      1. Case-Insensitive Comparison
      2. Finding a Program on the Path
      3. Using Assertions to Check Inputs
      4. Is DEBUG Set to Y?
      5. Is DEBUG Set to Y or N?
      6. Using Logical Operators in the Preprocessor
      7. Removing Duplicates from a List
      8. Automatically Incrementing a Version Number
    5. GMSL Reference
      1. Logical Operators
        1. not
        2. and
        3. or
        4. xor
        5. nand
        6. nor
        7. xnor
      2. Integer Arithmetic Functions
        1. int_decode
        2. int_encode
        3. int_plus
        4. plus
        5. int_subtract
        6. subtract
        7. int_multiply
        8. multiply
        9. int_divide
        10. divide
        11. int_max and int_min
        12. max and min
        13. int_inc
        14. inc
        15. int_dec
        16. dec
        17. int_double
        18. double
        19. int_halve
        20. halve
      3. Integer Comparison Functions
      4. Miscellaneous Integer Functions
        1. sequence
        2. dec2hex, dec2bin, and dec2oct
      5. List Manipulation Functions
        1. Applying a Function to a List with map
        2. Making a reduce Function
        3. Summing a List of Numbers Using reduce
        4. Mapping a Function Across a Pair of Lists
        5. first
        6. last
        7. rest
        8. chop
        9. map
        10. pairmap
        11. leq
        12. lne
        13. reverse
        14. uniq
        15. length
      6. String Manipulation Functions
        1. Splitting CSV Data into a GNU make List
        2. Making a PATH from a List of Directories
        3. Translating Characters Using tr
        4. seq
        5. sne
        6. streln
        7. substr
        8. split
        9. merge
        10. tr
        11. uc
        12. lc
      7. Set Manipulation Functions
        1. set_create
        2. set_insert
        3. set_remove
        4. set_is_member
        5. set_union
        6. set_intersection
        7. set_is_subset
        8. set_equal
      8. Associative Arrays
        1. set
        2. get
        3. keys
        4. defined
      9. Named Stacks
        1. traverse-tree
        2. dump-tree
        3. push
        4. pop
        5. peek
        6. depth
      10. Function Memoization
      11. Miscellaneous and Debugging Facilities
        1. gmsl_compatible
        2. gmsl-print-%
        3. assert
        4. assert_exists
      12. Environment Variables
  11. A. Updates
  12. Index
  13. Copyright

Product information

  • Title: The GNU Make Book
  • Author(s):
  • Release date: April 2015
  • Publisher(s): No Starch Press
  • ISBN: 9781593276492