Make/index
GNU make
Short Table of Contents
- 1 Overview of
make
- 2 An Introduction to Makefiles
- 3 Writing Makefiles
- 4 Writing Rules
- 5 Writing Recipes in Rules
- 6 How to Use Variables
- 7 Conditional Parts of Makefiles
- 8 Functions for Transforming Text
- 9 How to Run
make
- 10 Using Implicit Rules
- 11 Using
make
to Update Archive Files - 12 Extending GNU
make
- 13 Integrating GNU
make
- 14 Features of GNU
make
- 15 Incompatibilities and Missing Features
- 16 Makefile Conventions
- Appendix A Quick Reference
- Appendix B Errors Generated by Make
- Appendix C Complex Makefile Example
- Appendix D GNU Free Documentation License
- Index of Concepts
- Index of Functions, Variables, & Directives
Table of Contents
- 1 Overview of
make
- 2 An Introduction to Makefiles
- 3 Writing Makefiles
- 4 Writing Rules
- 4.1 Rule Example
- 4.2 Rule Syntax
- 4.3 Types of Prerequisites
- 4.4 Using Wildcard Characters in File Names
- 4.5 Searching Directories for Prerequisites
- 4.6 Phony Targets
- 4.7 Rules without Recipes or Prerequisites
- 4.8 Empty Target Files to Record Events
- 4.9 Special Built-in Target Names
- 4.10 Multiple Targets in a Rule
- 4.11 Multiple Rules for One Target
- 4.12 Static Pattern Rules
- 4.13 Double-Colon Rules
- 4.14 Generating Prerequisites Automatically
- 5 Writing Recipes in Rules
- 6 How to Use Variables
- 6.1 Basics of Variable References
- 6.2 The Two Flavors of Variables
- 6.3 Advanced Features for Reference to Variables
- 6.4 How Variables Get Their Values
- 6.5 Setting Variables
- 6.6 Appending More Text to Variables
- 6.7 The
override
Directive - 6.8 Defining Multi-Line Variables
- 6.9 Undefining Variables
- 6.10 Variables from the Environment
- 6.11 Target-specific Variable Values
- 6.12 Pattern-specific Variable Values
- 6.13 Suppressing Inheritance
- 6.14 Other Special Variables
- 7 Conditional Parts of Makefiles
- 8 Functions for Transforming Text
- 8.1 Function Call Syntax
- 8.2 Functions for String Substitution and Analysis
- 8.3 Functions for File Names
- 8.4 Functions for Conditionals
- 8.5 The
foreach
Function - 8.6 The
file
Function - 8.7 The
call
Function - 8.8 The
value
Function - 8.9 The
eval
Function - 8.10 The
origin
Function - 8.11 The
flavor
Function - 8.12 Functions That Control Make
- 8.13 The
shell
Function - 8.14 The
guile
Function
- 9 How to Run
make
- 10 Using Implicit Rules
- 11 Using
make
to Update Archive Files - 12 Extending GNU
make
- 13 Integrating GNU
make
- 14 Features of GNU
make
- 15 Incompatibilities and Missing Features
- 16 Makefile Conventions
- Appendix A Quick Reference
- Appendix B Errors Generated by Make
- Appendix C Complex Makefile Example
- Appendix D GNU Free Documentation License
- Index of Concepts
- Index of Functions, Variables, & Directives
GNU make
This file documents the GNU make
utility, which determines
automatically which pieces of a large program need to be recompiled,
and issues the commands to recompile them.
This is Edition 0.75, last updated 17 January 2020,
of The GNU Make Manual, for GNU make
version 4.3.
Copyright © 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover Texts being “A GNU Manual,” and with the Back-Cover Texts as in (a) below. A copy of the license is included in the section entitled “GNU Free Documentation License.”
(a) The FSF’s Back-Cover Text is: “You have the freedom to copy and modify this GNU manual. Buying copies from the FSF supports it in developing GNU and promoting software freedom.”
• Overview
Overview of make
.
An introduction to make
.
Makefiles tell make
what to do.
• Rules
Rules describe when a file must be remade.
• Recipes
Recipes say how to remake a file.
You can use variables to avoid repetition.
Use or ignore parts of the makefile based on the values of variables.
Many powerful ways to manipulate text.
How to invoke make
on the command line.
Use implicit rules to treat many files alike, based on their file names.
• Archives
How make
can update library archives.
Using extensions to make
.
Integrating make
with other tools.
• Features
Features GNU make
has over other make
s.
• Missing
What GNU make
lacks from other make
s.
Conventions for writing makefiles for GNU programs.
A quick reference for experienced users.
A list of common errors generated by make
.
A real example of a straightforward, but nontrivial, makefile.
• GNU Free Documentation License
License for copying this manual.
Index of Concepts.
Index of Functions, Variables, & Directives.
— The Detailed Node Listing — Overview of make
Preparing and running make
.
• Reading
On reading this text.
• Bugs
Problems and bugs.
An Introduction to Makefiles
What a rule looks like.
A simple makefile.
How make
processes this makefile.
Variables make makefiles simpler.
Letting make
deduce the recipes.
Another style of makefile.
• Cleanup
Rules for cleaning the directory.
Writing Makefiles
What makefiles contain.
How to name your makefile.
• Include
How one makefile can use another makefile.
The environment can specify extra makefiles.
How makefiles get remade.
How to override part of one makefile with another makefile.
How makefiles are read in.
How makefiles are parsed.
How and when secondary expansion is performed.
What Makefiles Contain
Splitting long lines in makefiles
Writing Rules
An example explained.
General syntax explained.
There are two types of prerequisites.
Using wildcard characters such as ‘*’.
Searching other directories for source files.
Using a target that is not a real file’s name.
You can use a target without a recipe or prerequisites to mark other targets as phony.
When only the date matters and the files are empty.
Targets with special built-in meanings.
When to make use of several targets in a rule.
How to use several rules with the same target.
Static pattern rules apply to multiple targets and can vary the prerequisites according to the target name.
How to use a special kind of rule to allow several independent rules for one target.
How to automatically generate rules giving prerequisites from source files themselves.
Using Wildcard Characters in File Names
Several examples.
Problems to avoid.
How to cause wildcard expansion where it does not normally take place.
Searching Directories for Prerequisites
Specifying a search path that applies to every prerequisite.
Specifying a search path for a specified class of names.
When and how search paths are applied.
How to write recipes that work together with search paths.
How search paths affect implicit rules.
Directory search for link libraries.
Static Pattern Rules
The syntax of static pattern rules.
When are they better than implicit rules?
Writing Recipes in Rules
Recipe syntax features and pitfalls.
• Echoing
How to control when recipes are echoed.
How recipes are executed.
• Parallel
How recipes can be executed in parallel.
• Errors
What happens after a recipe execution error.
What happens when a recipe is interrupted.
Invoking make
from makefiles.
Defining canned recipes.
Defining useful, do-nothing recipes.
Recipe Syntax
Breaking long recipe lines for readability.
Using make
variables in recipes.
Recipe Execution
One shell for all lines in a recipe.
How make
chooses the shell used
to run recipes.
Parallel Execution
Handling output during parallel execution
Handling input during parallel execution
Recursive Use of make
The special effects of using ‘$(MAKE)
’.
How to communicate variables to a sub-make
.
How to communicate options to a sub-make
.
How the ‘-w
’ or ‘--print-directory
’ option
helps debug use of recursive make
commands.
How to Use Variables
How to use the value of a variable.
• Flavors
Variables come in two flavors.
• Advanced
Advanced features for referencing a variable.
• Values
All the ways variables get their values.
• Setting
How to set a variable in the makefile.
How to append more text to the old value of a variable.
How to set a variable in the makefile even if the user has set it with a command argument.
An alternate way to set a variable to a multi-line string.
How to undefine a variable so that it appears as if it was never set.
Variable values can come from the environment.
Variable values can be defined on a per-target basis.
Target-specific variable values can be applied to a group of targets that match a pattern.
Suppress inheritance of variables.
Variables with special meaning or behavior.
Advanced Features for Reference to Variables
Referencing a variable with substitutions on the value.
Computing the name of the variable to refer to.
Conditional Parts of Makefiles
Example of a conditional
The syntax of conditionals.
Conditionals that test flags.
Functions for Transforming Text
How to write a function call.
General-purpose text manipulation functions.
Functions for manipulating file names.
Functions that implement conditions.
Repeat some text with controlled variation.
Write text to a file.
Expand a user-defined function.
Return the un-expanded value of a variable.
Evaluate the arguments as makefile syntax.
Find where a variable got its value.
Find out the flavor of a variable.
Functions that control how make runs.
Substitute the output of a shell command.
Use GNU Guile embedded scripting language.
How to Run make
How to specify which makefile to use.
• Goals
How to use goal arguments to specify which parts of the makefile to use.
How to use mode flags to specify what kind of thing to do with the recipes in the makefile other than simply execute them.
How to avoid recompiling certain files.
How to override a variable to specify an alternate compiler and other things.
• Testing
How to proceed past some errors, to test compilation.
Summary of Options
Using Implicit Rules
How to use an existing implicit rule to get the recipes for updating a file.
A list of built-in rules.
How to change what predefined rules do.
How to use a chain of implicit rules.
How to define new implicit rules.
How to define a recipe for rules which cannot find any.
The old-fashioned style of implicit rule.
The precise algorithm for applying implicit rules.
Defining and Redefining Pattern Rules
An introduction to pattern rules.
Examples of pattern rules.
How to use automatic variables in the recipe of implicit rules.
How patterns match.
Precautions you should take prior to defining rules that can match any target file whatever.
How to override or cancel built-in rules.
Using make to Update Archive Files
Archive members as targets.
The implicit rule for archive member targets.
Dangers to watch out for when using archives.
You can write a special kind of suffix rule for updating archives.
Implicit Rule for Archive Member Targets
How to update archive symbol directories.
Extending GNU make
Using Guile as an embedded scripting language.
Loading dynamic objects as extensions.
GNU Guile Integration
Converting Guile types to make
strings.
Invoking make
functions from Guile.
Example using Guile in make
.
Loading Dynamic Objects
Loading dynamic objects as extensions.
How loaded objects get remade.
Programmatic interface for loaded objects.
Example of a loaded object
Integrating GNU make
Share job slots with GNU make
.
Control output to terminals.
Sharing Job Slots with GNU make
Using the jobserver on POSIX systems.
Using the jobserver on Windows systems.