Quick Reference (GNU make)
Next: Error Messages, Previous: Makefile Conventions, Up: Top [Contents][Index]
Appendix A Quick Reference
This appendix summarizes the directives, text manipulation functions, and special variables which GNU make understands. See Special Targets, Catalogue of Built-In Rules, and Summary of Options, for other summaries.
Here is a summary of the directives GNU make recognizes:
define variable
define variable =
define variable :=
define variable ::=
define variable +=
define variable ?=
endef
- Define multi-line variables.
See Multi-Line.
undefine variable- Undefining variables.
See Undefine Directive.
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 Conditionals.
include file
-include file
sinclude file
- Include another makefile.
See Including Other Makefiles.
override variable-assignment- Define a variable, overriding any previous definition, even one from the command line.
export- Tell
maketo export all variables to child processes by default.
See Communicating Variables to a Sub-make.
export variable
export variable-assignment
unexport variable
- Tell
makewhether or not to export a particular variable to child processes.
See Communicating Variables to a Sub-make.
private variable-assignment- Do not allow this variable assignment to be inherited by prerequisites.
vpath pattern path- Specify a search path for files matching a ‘
%’ pattern.
See The vpath Directive.
vpath pattern- Remove all search paths previously specified for
pattern. vpath- Remove all search paths previously specified in any
vpathdirective.
Here is a summary of the built-in functions (see Functions):
$(subst from,to,text)- Replace
fromwithtointext.
See Functions for String Substitution and Analysis.
$(patsubst pattern,replacement,text)- Replace words matching
patternwithreplacementintext.
See Functions for String Substitution and Analysis.
$(strip string)- Remove excess whitespace characters from
string.
See Functions for String Substitution and Analysis.
$(findstring find,text)- Locate
findintext.
See Functions for String Substitution and Analysis.
$(filter pattern…,text)- Select words in
textthat match one of thepatternwords.
See Functions for String Substitution and Analysis.
$(filter-out pattern…,text)- Select words in
textthat do not match any of thepatternwords.
See Functions for String Substitution and Analysis.
$(sort list)- Sort the words in
listlexicographically, removing duplicates.
See Functions for String Substitution and Analysis.
$(word n,text)- Extract the
nth word (one-origin) oftext.
See Functions for String Substitution and Analysis.
$(words text)- Count the number of words in
text.
See Functions for String Substitution and Analysis.
$(wordlist s,e,text)- Returns the list of words in
textfromstoe.
See Functions for String Substitution and Analysis.
$(firstword names…)- Extract the first word of
names.
See Functions for String Substitution and Analysis.
$(lastword names…)- Extract the last word of
names.
See Functions for String Substitution and Analysis.
$(dir names…)- Extract the directory part of each file name.
$(notdir names…)- Extract the non-directory part of each file name.
$(suffix names…)- Extract the suffix (the last ‘
.’ and following characters) of each file name.
$(basename names…)- Extract the base name (name without suffix) of each file name.
$(addsuffix suffix,names…)- Append
suffixto each word innames.
$(addprefix prefix,names…)- Prepend
prefixto each word innames.
$(join list1,list2)- Join two parallel lists of words.
$(wildcard pattern…)- Find file names matching a shell file name pattern (not a ‘
%’ pattern).
$(realpath names…)- For each file name in
names, expand to an absolute name that does not contain any.,.., nor symlinks.
$(abspath names…)- For each file name in
names, expand to an absolute name that does not contain any.or..components, but preserves symlinks.
$(error text…)- When this function is evaluated,
makegenerates a fatal error with the messagetext.
See Functions That Control Make.
$(warning text…)- When this function is evaluated,
makegenerates a warning with the messagetext.
See Functions That Control Make.
$(shell command)- Execute a shell command and return its output.
See The shell Function.
$(origin variable)- Return a string describing how the
makevariablevariablewas defined.
See The origin Function.
$(flavor variable)- Return a string describing the flavor of the
makevariablevariable.
See The flavor Function.
$(foreach var,words,text)- Evaluate
textwithvarbound to each word inwords, and concatenate the results.
See The foreach Function.
$(if condition,then-part[,else-part])- Evaluate the condition
condition; if it’s non-empty substitute the expansion of thethen-partotherwise substitute the expansion of theelse-part.
See Functions for Conditionals.
$(or condition1[,condition2[,condition3…]])- Evaluate each condition
conditionNone at a time; substitute the first non-empty expansion. If all expansions are empty, substitute the empty string.
See Functions for Conditionals.
$(and condition1[,condition2[,condition3…]])- Evaluate each condition
conditionNone at a time; if any expansion results in the empty string substitute the empty string. If all expansions result in a non-empty string, substitute the expansion of the lastcondition.
See Functions for Conditionals.
$(call var,param,…)- Evaluate the variable
varreplacing any references to$(1),$(2)with the first, second, etc.paramvalues.
See The call Function.
$(eval text)- Evaluate
textthen read the results as makefile commands. Expands to the empty string.
See The eval Function.
$(file op filename,text)- Expand the arguments, then open the file
filenameusing modeopand writetextto that file.
See The file Function.
$(value var)- Evaluates to the contents of the variable
var, with no expansion performed on it.
See The value Function.
Here is a summary of the automatic variables. See Automatic Variables, 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 named member is used (see Archives).
$^
$+
- The names of all the prerequisites, with spaces between them. For prerequisites which are archive members, only the named member is used (see Archives). The value of
$^omits duplicate prerequisites, while$+retains them and preserves their order. $*- The stem with which an implicit rule matches (see How Patterns Match).
$(@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
$?.
These variables are used specially by GNU make:
MAKEFILESMakefiles to be read on every invocation of
make.
See The Variable MAKEFILES.VPATHDirectory search path for files not found in the current directory.
See VPATH Search Path for All Prerequisites.SHELLThe name of the system default command interpreter, usually
/bin/sh. You can setSHELLin the makefile to change the shell used to run recipes. See Recipe Execution. TheSHELLvariable is handled specially when importing from and exporting to the environment. See Choosing the Shell.MAKESHELLOn MS-DOS only, the name of the command interpreter that is to be used by
make. This value takes precedence over the value ofSHELL. See MAKESHELL variable.MAKEThe name with which
makewas invoked. Using this variable in recipes has special meaning. See How the MAKE Variable Works.MAKE_VERSIONThe built-in variable ‘
MAKE_VERSION’ expands to the version number of the GNUmakeprogram.MAKE_HOSTThe built-in variable ‘
MAKE_HOST’ expands to a string representing the host that GNUmakewas built to run on.MAKELEVELThe number of levels of recursion (sub-
makes).
See Variables/Recursion.MAKEFLAGSThe flags given to
make. You can set this in the environment or a makefile to set flags.
See Communicating Options to a Sub-make.It is never appropriate to use
MAKEFLAGSdirectly in a recipe line: its contents may not be quoted correctly for use in the shell. Always allow recursivemake’s to obtain these values through the environment from its parent.GNUMAKEFLAGSOther flags parsed by
make. You can set this in the environment or a makefile to setmakecommand-line flags. GNUmakenever sets this variable itself. This variable is only needed if you’d like to set GNUmake-specific flags in a POSIX-compliant makefile. This variable will be seen by GNUmakeand ignored by othermakeimplementations. It’s not needed if you only use GNUmake; just useMAKEFLAGSdirectly. See Communicating Options to a Sub-make.MAKECMDGOALSThe targets given to
makeon the command line. Setting this variable has no effect on the operation ofmake.
See Arguments to Specify the Goals.CURDIRSet to the absolute pathname of the current working directory (after all
-Coptions are processed, if any). Setting this variable has no effect on the operation ofmake.
See Recursive Use of make.SUFFIXESThe default list of suffixes before
makereads any makefiles..LIBPATTERNSDefines the naming of the libraries
makesearches for, and their order.
See Directory Search for Link Libraries.
Next: Error Messages, Previous: Makefile Conventions, Up: Top [Contents][Index]