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