From GNU make manual for version 3.81
###############################################################################
Summary:
###############################################################################
Make processes makefiles. Makefiles consist of macro definitions and rules.
Standard names for makefiles are GMakefile, Makefile, and makefile located in
the same directory as where invoked.
Comments begin with a hash mark (#) and
extend to the end of the line
Tab characters (shown as <TAB> in this document)
are significant and required in make.
Rules are of the format:
TARGET(s):
PREREQUISITE(s)
<TAB>COMMAND(s)
Targets are either filenames (possibly
including a relative directory path prefix), pseudo-targets or special targets.
###############################################################################
EXAMPLE
###############################################################################
.PHONY: All Clean
All: program.exe
program.exe: program.c
<TAB>g++ -o $@ $<
Clean:
<TAB>rm -fr program.o program.exe
###############################################################################
Directives:
###############################################################################
define variable
endef
Defines a multi-line, recursively-expanded variable. See
Section 5.8 [Sequences], page 55.
ifdef variable
ifndef variable
ifeq (a,b )
ifeq "a " "b "
ifeq 'a ' 'b '
ifneq (a,b )
ifneq "a " "b "
ifneq 'a ' 'b '
else
endif
Conditionally evaluate part of the makefile.
See Chapter 7
[Conditionals], page 71.
include file
-include file
sinclude file
Include
another makefile.
See Section 3.3 [Including Other Makefiles], page 12.
override variable = value
override variable := value
override variable += value
override variable ?= value
override define variable
endef
Define a variable,
overriding any previous definition, even one from the command line.
See
Section 6.7 [The override Directive], page 65.
export
Tell make to export all
variables to child processes by default.
See Section 5.7.2 [Communicating
Variables to a Sub-make], page 51.
export variable
export variable = value
export variable := value
export variable += value
export variable ?= value
unexport variable
Tell make whether or not to export a particular variable to
child processes.
See Section 5.7.2 [Communicating Variables to a Sub-make],
page 51.
vpath pattern path
Specify a search path for files matching a '%'
pattern.
See Section 4.4.2 [The vpath Directive], page 27.
vpath pattern
Remove all search paths previously specified for pattern.
vpath
Remove all
search paths previously specified in any vpath directive.
###############################################################################
Built-in functions (see Chapter 8 [Functions], page 77):
###############################################################################
$(subst from,to,text )
Replace from with to in text. See Section 8.2
[Functions for String Substitution and Analysis], page 78.
$(patsubst
pattern,replacement,text )
Replace words matching pattern with replacement in
text. See Section 8.2 [Functions for String Substitution and Analysis], page
78.
$(strip string )
Remove excess whitespace characters from string. See
Section 8.2 [Functions for String Substitution and Analysis], page 78.
$(findstring find,text )
Locate find in text. See Section 8.2 [Functions for
String Substitution and Analysis], page 78.
$(filter pattern ...,text )
Select words in text that match one of the pattern words. See Section 8.2
[Functions for String Substitution and Analysis], page 78.
$(filter-out pattern
...,text )
Select words in text that do not match any of the pattern words.
See Section 8.2 [Functions for String Substitution and Analysis], page 78.
$(sort list )
Sort the words in list lexicographically, removing duplicates.
See Section 8.2 [Functions for String Substitution and Analysis], page 78.
$(word n,text )
Extract the nth word (one-origin) of text. See Section 8.2
[Functions for String Substitution and Analysis], page 78.
$(words text )
Count the number of words in text. See Section 8.2 [Functions for String
Substitution and Analysis], page 78.
$(wordlist s,e,text )
Returns the list
of words in text from s to e. See Section 8.2 [Functions for String
Substitution and Analysis], page 78.
$(firstword names ...)
Extract the first
word of names. See Section 8.2 [Functions for String Substitution and
Analysis], page 78.
$(lastword names ...)
Extract the last word of names.
See Section 8.2 [Functions for String Substitution and Analysis], page 78.
$(dir names ...)
Extract the directory part of each file name. See Section
8.3 [Functions for File Names], page 81.
$(notdir names ...)
Extract the
non-directory part of each file name. See Section 8.3 [Functions for File
Names], page 81.
$(suffix names ...)
Extract the suffix (the last '.' and
following characters) of each file name. See Section 8.3 [Functions for File
Names], page 81.
$(basename names ...)
Extract the base name (name without
suffix) of each file name. See Section 8.3 [Functions for File Names], page 81.
$(addsuffix suffix,names ...)
Append suffix to each word in names. See
Section 8.3 [Functions for File Names], page 81.
$(addprefix prefix,names ...)
Prepend prefix to each word in names. See Section 8.3 [Functions for File
Names], page 81.
$(join list1,list2 )
Join two parallel lists of words. See
Section 8.3 [Functions for File Names], page 81.
$(wildcard pattern ...)
Find
file names matching a shell file name pattern (not a '%' pattern). See Section
4.3.3 [The Function wildcard], page 26.
$(realpath names ...)
For each file
name in names, expand to an absolute name that does not contain any ., .., nor
symlinks. See Section 8.3 [Functions for File Names], page 81.
$(abspath names
...)
For each file name in names, expand to an absolute name that does not
contain any . or .. components, but preserves symlinks. See Section 8.3
[Functions for File Names], page 81.
$(error text ...)
When this function is
evaluated, make generates a fatal error with the message text. See Section 8.12
[Functions That Control Make], page 90.
$(warning text ...)
When this
function is evaluated, make generates a warning with the message text. See
Section 8.12 [Functions That Control Make], page 90.
$(shell command )
Execute a shell command and return its output. See Section 8.11 [The shell
Function], page 89.
$(origin variable )
Return a string describing how the
make variable variable was defined. See Section 8.9 [The origin Function], page
87.
$(flavor variable )
Return a string describing the flavor of the make
variable variable. See Section 8.10 [The flavor Function], page 89.
$(foreach
var,words,text )
Evaluate text with var bound to each word in words, and
concatenate the results. See Section 8.5 [The foreach Function], page 84.
$(call var,param,...)
Evaluate the variable var replacing any references to
$(1), $(2) with the first, second, etc. param values. See Section 8.6 [The call
Function], page 85.
$(eval text )
Evaluate text then read the results as
makefile commands. Expands to the empty string. See Section 8.8 [The eval
Function], page 86.
$(value var )
Evaluates to the contents of the variable
var, with no expansion performed on it. See Section 8.7 [The value Function],
page 86.
###############################################################################
Automatic variables. See Section 10.5.3 [Automatic Variables], page 110, for
full information.
###############################################################################
$@
The file name of the target.
$%
The target member name, when the target
is an archive member.
$<
The name of the first prerequisite.
$?
The names
of all the prerequisites that are newer than the target, with spaces between
them. For prerequisites which are archive members, only the member named is used
(see Chapter 11 [Archives], page 119).
$^
$+
The names of all the
prerequisites, with spaces between them. For prerequisites which are archive
members, only the member named is used (see Chapter 11 [Archives], page 119).
The value of $^ omits duplicate prerequisites, while $+ retains them and
preserves their order. The stem with which an implicit rule matches (see
Section 10.5.4 [How Patterns Match], page 112).
$*
$(@D)
$(@F)
The directory
part and the file-within-directory part of $@.
$(*D)
$(*F)
The directory part
and the file-within-directory part of $*.
$(%D)
$(%F)
The directory part and
the file-within-directory part of $%.
$(<D)
$(<F)
The directory part and the
file-within-directory part of $<.
$(^D)
$(^F)
The directory part and the
file-within-directory part of $^.
$(+D)
$(+F)
The directory part and the
file-within-directory part of $+.
$(?D)
$(?F)
The directory part and the
file-within-directory part of $?.
###############################################################################
Variables are used specially by GNU make:
###############################################################################
MAKEFILES
Makefiles to be read on every invocation of make. See Section 3.4
[The Variable MAKEFILES], page 13.
VPATH
Directory search path for files not
found in the current directory. See Section 4.4.1 [VPATH Search Path for All
Prerequisites], page 27.
SHELL
The name of the system default command
interpreter, usually '/bin/sh'. You can set SHELL in the makefile to change the
shell used to run commands. See Section 5.3 [Command Execution], page 46. The
SHELL variable is handled specially when importing from and exporting to the
environment. See Section 5.3.1 [Choosing the Shell], page 46.
MAKESHELL
On
MS-DOS only, the name of the command interpreter that is to be used by make.
This value takes precedence over the value of SHELL. See Section 5.3 [MAKESHELL
variable], page 46.
MAKE
The name with which make was invoked. Using this
variable in commands has special meaning. See Section 5.7.1 [How the MAKE
Variable Works], page 50.
MAKELEVEL
The number of levels of recursion
(sub-makes). See Section 5.7.2 [Variables/Recursion], page 51.
MAKEFLAGS
The
flags given to make. You can set this in the environment or a makefile to set
flags. See Section 5.7.3 [Communicating Options to a Sub-make], page 53. It is
never appropriate to use MAKEFLAGS directly on a command line: its contents may
not be quoted correctly for use in the shell. Always allow recursive make's to
obtain these values through the environment from its parent.
MAKECMDGOALS
The
targets given to make on the command line. Setting this variable has no effect
on the operation of make. See Section 9.2 [Arguments to Specify the Goals],
page 91.
CURDIR
Set to the pathname of the current working directory (after
all -C options are processed, if any). Setting this variable has no effect on
the operation of make. See Section 5.7 [Recursive Use of make], page 50.
SUFFIXES
The default list of suffixes before make reads any makefiles.
.LIBPATTERNS
Defines the naming of the libraries make searches for, and their
order. See Section 4.4.6 [Directory Search for Link Libraries], page 30.
###############################################################################
Built-in targets
###############################################################################
.SUFFIXES:
The list of suffixes to be used in checking for suffix rules. See
Section 10.7 [Old Fashioned Suffix Rules].
.DEFAULT_GOAL:
Sets the goal to be
used if no targets were specified on the command-line.
.DEFAULT:
Commands to
be used for a any target for which no rules are found.
.PHONY:
Specifies the
list of pseudo-targets.
.PRECIOUS:
If make is killed or interrupted during
execution, these prerequisites will not be deleted.
.INTERMEDIATE:
Lists
targets which are intermediate files and subject to deletion.
.SECONDARY:
List intermediate targets that are never deleted.
.SECONDEXPANSION:
All
prerequisite lists defined after this will be expanded a second time after all
makefiles have been read in.
.DELETE_ON_ERROR:
prerequisite files defined
after this whose target commands return an error will be deleted
.IGNORE:
cause all errors during command execution to be ignored
.LOW_RESOLUTION_TIME:
uses a lower resolution timestamp for determining when files are out-of-date
.SILENT:
suppresses printing commands before executing them
.EXPORT_ALL_VARIABLES:
Causes all make variables to be exported to child
processes (i.e. in commands)
.NOTPARALLEL:
Forces serial execution
even though -j is specified
###############################################################################
EOF