Click on any of the 687 commands below to get a description and list of available options. All links in the command summaries point to the online version of the book on Safari Bookshelf.
Update one or more targets according to dependency instructions in a description file in the current directory. By default, this file is called makefile or Makefile. Options, targets, and macro definitions can be in any order. Macro definitions are typed as:
name=string
For more information on make, see Managing Projects with GNU Make (O'Reilly).
Options
-d, --debug
Print detailed debugging information.
-e, --environment-overrides
Override Makefile macro definitions with environment variables.
-fMakefile, --file=Makefile, --makefile=Makefile
Use Makefile as the description file; a filename of - denotes standard input.
-h, --help
Print options to make command.
-i, --ignore-errors
Ignore command error codes (same as .IGNORE).
-j [jobs] , --jobs [=jobs]
Attempt to execute this many jobs simultaneously or, if no number is specified, as many jobs as possible.
-k, --keep-going
Abandon the current target when it fails, but keep working with unrelated targets.
Attempt to keep load below load, which should be a floating-point number. Used with -j.
-n, --just-print, --dry-run, --recon
Print commands but don't execute (used for testing).
-ofile, --old-file=file, --assume-old=file
Never remake file or cause other files to be remade on account of it.
-p, --print-data-base
Print rules and variables in addition to normal execution.
-q, --question
Query; return 0 if file is up to date, nonzero otherwise.
-r, --no-built-in-rules
Do not use default rules.
-s, --silent, --quiet
Do not display command lines (same as .SILENT).
-t, --touch
Touch the target files without remaking them.
-v, --version
Show version of make.
-w, --print-directory
Display the current working directory before and after execution.
--warn-undefined-variables
Print warning if a macro is used without being defined.
-Cdirectory, --directorydirectory
cd to directory before beginning make operations. A subsequent -C directive will cause make to attempt to cd into a directory relative to the current working directory.
-Idirectory, --include-dirdirectory
Include directory in list of directories containing included files.
-S, --no-keep-going, --stop
Cancel previous -k options. Useful in recursive makes.
Instructions in the description file are interpreted as single lines. If an instruction must span more than one input line, use a backslash (\) at the end of the line so that the next line is considered a continuation. The description file may contain any of the following types of lines:
Blank lines
Blank lines are ignored.
Comment lines
A pound sign (#) can be used at the beginning of a line or anywhere in the middle. make ignores everything after the #.
Dependency lines
Depending on one or more targets, certain commands that follow will be executed. Possible formats include:
Subsequent commands are executed if dependency files (the names of which may contain wildcards) do not exist or are newer than a target. If no prerequisites are supplied, then subsequent commands are always executed (whenever any of the targets are specified). No tab should precede any targets.
Conditionals
Conditionals are evaluated when the Makefile is first read and determine what make sees—i.e., which parts of the Makefile are obeyed and which parts are ignored. The general syntax for a conditional is:
conditionalText if true
else
Text if false
endif
ifeq (arg1, arg2), ifeq "arg1""arg2"
True if the two arguments are identical. The arguments should either be placed in parentheses and separated by a comma--(arg1, arg2)--or individually quoted with either single or double quotes.
ifneq (arg1, arg2), ifneq"arg1""arg2"
True if the two arguments are not identical. The arguments should either be placed in parentheses and separated by a comma, or individually quoted with either single or double quotes.
ifdefvariable
True if variable has a nonempty value.
ifndefvariable
True if variable has an empty value.
Suffix rules
These specify that files ending with the first suffix can be prerequisites for files ending with the second suffix (assuming the root filenames are the same). Either of these formats can be used:
.suffix.suffix:
.suffix:
The second form means that the root filename depends on the filename with the corresponding suffix.
Commands
Commands are grouped below the dependency line and are typed on lines that begin with a tab. If a command is preceded by a hyphen (-), make ignores any error returned. If a command is preceded by an at sign (@), the command line won't echo on the display (unless make is called with -n).
Macro definitions
These have the following form:
name = string
or:
define namestring
endef
Blank space is optional around the =.
Include statements
Similar to the C include directive, these have the form:
include files
Internal macros
$?
The list of prerequisites that have been changed more recently than the current target. Can be used only in normal description-file entries, not in suffix rules.
$@
The name of the current target, except in description-file entries for making libraries, where it becomes the library name. Can be used both in normal description-file entries and in suffix rules.
$<
The name of the current prerequisite that has been modified more recently than the current target.
$*
The name (without the suffix) of the current prerequisite that has been modified more recently than the current target. Can be used only in suffix rules.
$%
The name of the corresponding .o file when the current target is a library module. Can be used both in normal description-file entries and in suffix rules.
$^
A space-separated list of all dependencies with no duplications.
$+
A space-separated list of all dependencies, which includes duplications.
Pattern rules
These are a more general application of the idea behind suffix rules. If a target and a dependency both contain %, GNU make will substitute any part of an existing filename. For instance, the standard suffix rule:
$(cc) -o $@ $<
can be written as the following pattern rule:
%.o : %.c
$(cc) -o $@ $<
Macro modifiers
D
The directory portion of any internal macro name except $?. Valid uses are:
Replace all occurrences of from with to in string.
$(patsubstpattern,to,string)
Similar to subst, but treat % as a wildcard within pattern. Substitute to for any word in string that matches pattern.
$(stripstring)
Remove all extraneous whitespace.
$(findstringsubstring,mainstring)
Return substring if it exists within mainstring; otherwise, return null.
$(filterpattern,string)
Return those words in string that match at least one word in pattern. pattern may include the wildcard %.
$(filter-outpattern,string)
Remove those words in string that match at least one word in pattern. pattern may include the wildcard %.
$(sortlist)
Return list, sorted in lexical order.
$(dirlist)
Return the directory part (everything up to the last slash) of each filename in list.
$(notdirlist)
Return the nondirectory part (everything after the last slash) of each filename in list.
$(suffixlist)
Return the suffix part (everything after the last period) of each filename in list.
$(basenamelist)
Return everything but the suffix part (everything up to the last period) of each filename in list.
$(addsuffixsuffix,list)
Return each filename given in list with suffix appended.
$(addprefixprefix,list)
Return each filename given in list with prefix prepended.
$(joinlist1,list2)
Return a list formed by concatenating the two arguments word by word (e.g., $(join a b,.c .o) becomes a.c b.o).
$(wordn,string)
Return the nth word of string.
$(wordliststart,end,string)
Return words in string between word start and word end, inclusive.
$(wordsstring)
Return the number of words in string.
$(firstwordlist)
Return the first word in the list list.
$(wildcardpattern)
Return a list of existing files in the current directory that match pattern.
$(foreachvariable,list,string)
For each whitespace-separated word in list, expand its value and assign it to variable; then expand string, which usually contains a function referencing variable. Return the list of results.
$(ifcondition,then-string[,else-string] )
Expand string condition if it expands to a nonempty string, then expand the then-string. If condition expands to an empty string, return the empty string or, if specified, expand and return the else-string.
$(callvariable,parameters)
Expand each item in comma-separated list parameters and assign it to a temporary variable, $(n), where n is an incremented number beginning with 0. Then expand variable, a string referencing these temporary variables, and return the result.
$(originvariable)
Return one of the following strings that describes how variable was defined: undefined, default, environment, environment override, file, command line, override, or automatic.
$(shellcommand)
Return the results of command. Any newlines in the result are converted to spaces. This function works similarly to backquotes in most shells.
$(errorstring)
When evaluated, generate a fatal error with the message string.
$(warningstring)
When evaluated, generate a warning with the message string.
Macro string substitution
$(macro:s1=s2)
Evaluates to the current definition of $(macro), after substituting the string s2 for every occurrence of s1 that occurs either immediately before a blank or tab, or at the end of the macro definition.
Special target names
.DEFAULT:
Commands associated with this target are executed if make can't find any description-file entries or suffix rules with which to build a requested target.
.DELETE_ON_ERROR:
If this target exists in a Makefile, delete the target of any rule whose commands return a nonzero exit status.
.EXPORT_ALL_VARIABLES:
If this target exists, export all macros to all child processes.
.IGNORE:
Ignore error codes. Same as the -i option.
.INTERMEDIATE:
This target's dependencies should be treated as intermediate files.
.NOTPARALLEL:
If this target exists in a Makefile, run make serially, ignoring option -j.
.PHONY:
Always execute commands under a target, even if it is an existing, up-to-date file.
.PRECIOUS:
Files you specify for this target are not removed when you send a signal (such as an interrupt) that aborts make or when a command line in your description file returns an error.
.SECONDARY:
Like .INTERMEDIATE, this target's dependencies should be treated as intermediate files, but never automatically deleted.
.SILENT:
Execute commands, but do not echo them. Same as the -s option.
.SUFFIXES:
Suffixes associated with this target are meaningful in suffix rules. If no suffixes are listed, the existing list of suffix rules is effectively "turned off."