make - Maintain program-generated and interdependent files
Format
- make [-EeinpqrstuVvx] [-k|-S] [-c dir] [-f file] ...
- [macro definition ...] [-D macro definition ...] [target ...]
Description
make helps you manage projects containing a set of interdependent files, such as a program with many source and object files, or a document built from source files, macro files, and so on. make keeps all such files up-to-date with one another. If one file changes, make updates all the other files that depend on the changed file.
.POSIX
special
target to provide maximum portability. When you specify this target, make processes
the makefile as specified in the POSIX standard. For details, see
the description of .POSIX
in Targets.In a double-byte locale, environment variable values, here-documents, and the command line can all contain environment values.
Options
- -c dir
- Attempts to change into the specified directory when make starts up. If make cannot change to the directory, an error message is printed. This option is useful for recursive makefiles when you are building in a different directory.
- -D macro definition
- Define macro on the command line before reading any
makefile. Use the same form as a normal macro definition
(macro=string). If you use this option, make
assigns the value to the macro before reading the makefile; any definition of the same macro
contained in the makefile supersedes this definition. Note: make uses any macros defined in this way before reading any makefile, including the startup file. This allows you to define a startup file by providing a value for MAKESTARTUP on the command line:
make -D MAKESTARTUP=$HOME/project/startup.mk
- -E
- Suppresses reading of the environment. If you do not specify either -E or -e, make reads the environment before reading the makefile.
- -e
- Reads the environment after reading the makefile. If neither -E nor -e are specified, make reads the environment before reading the makefile, except for the SHELL environment variable, which you must explicitly export. This option does not affect the value of MAKEFLAGS.
- -f file
- Uses file as the source for the makefile description.
make ignores the makefiles specified as prerequisites to the
.MAKEFILES
target. If you specify a minus sign (-) in place of file, make reads the standard input. (In other words, make expects you to enter the makefile from the terminal or to redirect it from a file.) You can use more than one -f option. - -i
- Tells make to ignore all errors and
continue making other targets. This is equivalent to the
.IGNORE
attribute or macro. - -k
- Makes all independent targets, even if an error occurs. Ordinarily, make stops after a command returns a nonzero status. Specifying -k tells make to ignore the error and continue to make other targets, as long as they are not related to the target that received the error. make does not attempt to update anything that depends on the target that was being made when the error occurred.
- -n
- Displays the commands that make would execute to update the chosen targets,
but does not actually execute any recipe lines unless they have a plus sign (+) command prefix.
make displays recipe lines with an at sign (@) command prefix on standard output
(stdout). For more information about recipe lines, see
Recipe lines in z/OS UNIX System Services Programming Tools. With group recipes, make displays the commands that it uses to update a given target, but it also executes the commands.Note: z/OS make supports group recipes, but traditional implementations of make do not. A group recipe signifies a collection of command lines fed as a unit to the command interpreter. By contrast, make executes commands in a normal recipe one by one. For more information about group recipes, see Group recipes in z/OS UNIX System Services Programming Tools.
If make finds the string
$ (MAKE)
in a recipe line, it expands it, adds -n to theMAKEFLAGS
, and then executes the recipe line. This enables you to see what happens when recursive calls are made to make. The output correctly shows line breaks in recipes that are divided into several lines of text using the \<newline> sequence. - -p
- Prints the makefile after it has been processed to include macro and target definitions. This display is in human-readable form useful for debugging, but you cannot use it as input to make.
- -q
- Checks whether the target is up-to-date. If it is up-to-date, make exits with
a status of
0
; otherwise, it exits with a status of1
(typically interpreted as an error by other software). No commands are run when -q is specified. - -r
- Does not read the startup file. Various control macros and default rules will not be defined.
- -S
- Ends make if an error occurs during operations to bring a target up-to-date (opposite of -k). This is the default.
- -s
- Specifies that recipe commands, warning messages, or touch messages (see the -t
option) not be displayed. This is equivalent to the
.SILENT
attribute or macro. - -t
- Touches the target to mark them as up-to-date, but only executes commands to change a target if the target has a plus sign (+) command prefix. make does not touch up-to-date targets or targets that have prerequisites but not recipes. make displays a message for each touched target file indicating the file name.
- -u
- Forces an unconditional update: make behaves as if all the prerequisites of the given target are out of date.
- -V
- Prints the version number of make and a list of built-in rules.
- -v
- Causes make to display a detailed account of its progress. This includes what files it reads, the definition and redefinition of each macro, metarule and suffix rule searches, and other information.
- -x
- Exports all macro definitions to the environment. This happens just before make begins making targets (but after it has read the entire makefile).
Targets
A target
is normally a file that you want to ensure is up-to-date with the
files on which it is dependent (the prerequisites). For example, you might want to check to see if
a
is based on the most recent version of the corresponding source code. If it is
not, then have the source code recompiled to get an up-to-date version. In this case, the compiled
program file is the target and the corresponding source files are prerequisites (that is, the files
on which a target is dependent).
make updates all targets that are specified on the command line. If you do not specify any target, make updates the targets in the first rule of the makefile. A target is out of date if it is older than any of its prerequisites (based on modification times) or if it does not exist. To update a target, make first recursively ensures that all the target's prerequisites are up-to-date, processing them in the order in which they appear in the rule. If the target itself is out of date, make then runs the recipe that is associated with the target. If the target has no associated recipe, make considers up-to-date.
make also supports another form of targets, known as special targets.
Special target directives are called targets because they appear in the target position of rules; however, they are really keywords, not targets. The rules they appear in are really directives that control the behavior of make.
The special target must be the only target in a special rule; you cannot list other normal or special targets.
.BRACEEXPAND
- This target cannot have any prerequisites and recipes that are associated with it. If set, the
target enables the outdated brace expansion feature used in older versions of
make. Older make commands would expand a construct of the
following form, beginning with each token in the token list:
Older make commands would append string1 to the front of each token in the list, and string2 to the end of each token in the list. A more productive means for achieving the same result with modern versions of make relies on macro expansion with prefix and suffix modifiers:string1{token_list}string2
The double quotation marks are required. Brace expansion is an outdated feature that is available in past versions of make.$ (TOKEN_BASE:^"prefix:+"suffix")
.CYCLECHECK
- This special target cannot have any prerequisite or recipes that are associated with it. If
set, it determines how make treats circular dependencies (see Circular dependencies). You can specify one of five attributes with this target. If you specify more than one attribute, an error message results. The five attributes are:
.SILENT
- make remains silent about any within-rule and between-rule circular dependencies, removes the offending dependency from the list of prerequisites, and continues.
.WARNTARG
- make issues warnings for named targets with circular dependencies. If
the name of the dependency is the same as the named target, it is removed from the list of
prerequisites and make continues. This is the default behavior if
.CYCLECHECK
is not specified or is specified with no attributes. .WARNALL
- make issues warnings for all within-rule circular dependencies regardless of whether the target is being built or not and for all between-rule circular dependencies for the named targets. The offending dependency is removed from the list of prerequisites and make continues.
.FATALTARG
- make treats all circular dependencies for named targets as fatal errors. It issues an error message and exits.
.FATALALL
- make treats all within-rule circular dependencies as fatal errors regardless of whether the target is being built or not. It also treats all between-rule circular dependencies for named targets as fatal errors. make issues an error message and exits.
.CYCLECHECK .WARNTARG:
.DEFAULT
- This target has no prerequisites, but it does have a recipe. If make can apply no other rule to produce a target, it uses this rule if it has been defined.
.ERROR
- make runs the recipe that is associated with this target whenever it detects an error condition.
.EXPORT
- All prerequisites associated with this target that correspond to macro names are exported to the environment at the point in the makefile at which this target appears.
.GROUPEPILOG
- make adds the recipe that is associated with this target after any
group recipe for a target that has the
.EPILOG
attribute. .GROUPPROLOG
- make adds the recipe associated with
this target after any group recipe for a target that has the
.PROLOG
attribute. .IMPORT
- make searches in the environment for prerequisite names specified for this
target and defines them as macros with their value taken from the environment. If the prerequisite
.EVERYTHING
is given, make reads in the entire environment (see -e and -E options). .INCLUDE
- make reads one or more additional makefiles
(specified in the prerequisite list), as if their contents had been
inserted at this point. If the prerequisite list contains more than
one file, make reads them in order from
left to right. make uses the following rules to search for extra makefiles:
- If a relative file name is enclosed in quotation marks, or is not enclosed with angle brackets
(< and >), make looks in the current directory. If the file isn't
present, make then looks for it in each directory specified by the
.INCLUDEDIRS
special target. - If a relative name is enclosed with angle brackets (< and >), make make
only searches in directories specified by the
.INCLUDEDIRS
special - If an absolute path name is given, make looks
for that file and ignores the list associated with the
.INCLUDEDIRS
special target.
- If a relative file name is enclosed in quotation marks, or is not enclosed with angle brackets
(< and >), make looks in the current directory. If the file isn't
present, make then looks for it in each directory specified by the
.INCLUDEDIRS
- The list of prerequisites specified for this target defines the set of directories to search when including a makefile.
.MAKEFILES
- The list of prerequisites is the set of files to try to read as the user makefile. These files are made in the order they are specified (from left to right) until one is found to be up-to-date. This is the file that is used.
.NOAUTODEPEND
- Disables the autodependency feature when building libraries. When this special target is used, only library members that have been explicitly given as dependents are considered prerequisites.
.POSIX
- make processes the makefile as specified in the POSIX.2POSIX.2 draft standard. This target may have no
prerequirementsthat are associated no recipes with it. This special target must appear before the
first non-comment line in the makefile. If this special target is present, the following facilities
are disabled:
- All recipe lines are run by the shell, one shell per line, regardless of the setting of SHELLMETAS.
- Metarule inferencing is disabled.
- Conditionals are disabled.
- Dynamic prerequisites are disabled.
- Group recipes are disabled.
- Disables brace expansion (set with the
special target)..BRACEEXPAND
- make does not check for the string $ (MAKE) when run with the -n options specified.
.REMOVE
- make uses the recipe of this target
to remove any intermediate files that it creates if an error is encountered
before the final target is created. This
.REMOVE
target only deletes files that satisfy all of the following criteria:- The file didn't exist when make began running.
- The file is named as an intermediate target, produced by invoking a metarule that was produced by transitive closure.
- The file is not explicitly named in the makefile.
- The generated target doesn't have the
.PRECIOUS
attribute. - The file is a prerequisite of a rule that is actually used.
.SOURCE
- The prerequisite list of this target defines a set of directories to check when trying to locate a target file name.make defaults to creating target files in the same directory that it finds the source file.
.SOURCE.x
- Same as
.SOURCE
, except that make searches the.SOURCE.x
list first when trying to locate a file matching a target with a name that ends in the suffix.x
. .SUFFIXES
- mk appends the prerequisite list of this target to the set of suffixes used when trying to infer a prerequisite for making a target using suffix rules. If you specify no prerequisites, make clears the list of suffixes, effectively disabling suffix rules from that point on.
A name of the form library(member) indicates
a member of a library. The library portion
is a target with the .LIBRARY
attribute, and the member portion
is a prerequisite of the library target.
A name of the form library((entry))
indicates
the library module that contains the given entry point. Once again,
the library portion is a target with the .LIBRARY
attribute. make regards
the library member that contains the entry point entry as
a prerequisite of the library target.
Makefiles
A makefile is a text file that describes the dependencies between various files. It normally contains a list of targets and identifies the prerequisites on which each depends. It also contains a series of instructions, called recipes, which describe the actions to be taken if a given target is out of date with its prerequisites.
By default, if you do not specify the -f option, make looks for a file in your current directory named makefile. If it does not find this file, it searches your current directory for a file named Makefile. If make finds either file, it uses this file as your makefile.
You can change the default makefiles with the .MAKEFILES
special target. This
target is already specified in the startup.mk file. See Targets for
more information.
Makefile contents
Comments begin with the pound (#) character and extend to the end of the line. make discards all comment text.
Inside
makefiles, you can split long lines over several lines of text. To
do this, put a backslash (\
) at the very end of the
line. You can use this technique to extend comments as well as recipe
lines and macro definitions, for example.
If a rule or macro
definition must contain a #
character, use \#
;
otherwise, make mistakes the #
for
the beginning of a comment. Also, if a macro definition must contain
a single $
character, use $$
.
"a:target" : "a:prereq"
-
, @
,
+
or all three. -
indicates that make is to ignore nonzero exit values when it runs this recipe line.@
indicates that make is not to display the recipe line before running it.+
tells make to always run this line, even when -n, -p, or -t is specified.
to
Group recipes begin with [
in the first non-white-space position of a line, and
end with ]
in the first non-white-space position of a line. Recipe lines in a group
recipe need not have a leading tab. make executes a group recipe by feeding it as
a single unit to a shell. If you immediately follow the [
at the beginning of a
group recipe with one of -
, @
or +
, they apply to
the entire group in the same way that they apply to single recipe lines.
Macro definitions
Macro
definitions can appear on the command line or in makefiles. Macro
definitions on the command line overrule definitions in makefiles;
makefile definitions never overrule command-line definitions. Macro
definitions on the command line may not have any white space between
the macro name and the =
character.
macro := string
expands macros inside string before assigning
a value to macro. macro += string
adds string to the previous value of macro.You can use any amount of white space on both sides of macro operators. make
defines the name macro to have the value string
and replaces it with that value whenever it is used as
$(
macro)
or
${
macro}
within the makefile. It is
possible to specify a $(
macro_name)
or
${
macro_name}
macro expansion, where
macro_name contains more $(....)
or
${...}
macro expansions itself.
Typically, make does not include white space at the beginning and end of string in the definition of macro; however, it never strips white space from macros imported from the environment.
If you want to include white space in a macro definition specified on the make command line, you must enclose the definition in quotes.
make resolves macro definitions in the following order:
- Macro definitions in the built-in rules.
- Macro definitions on the command line associated with the -D option.
- Macro definitions in the startup file.
- Contents of the environment.
- Macro definitions in the makefiles (in the order they appear).
- Macro definitions on the command line without the -D option.
If you specify the -e options, make reads the makefiles before reading the contents of the environment. If you specify the -E option, make does not read the contents of the environment.
If a macro is already defined when make encounters a new definition for it, the new definition replaces the old one. For example, a macro definition for name on the command line overrides a definition for name in the makefile. You can use the -v option to display macro assignments, as make performs them.
$(macro_name:modifier_list:modifier_list:...)
^"
string"- Prefix tokens
+"
string"- Suffix tokens
b
- File portion of all path names, without suffix
d
- Directory portion of all path names
f
- File portion of all path names, including suffix
l
- All characters mapped to lowercase
s/
pat/
string/
- Simple pattern substitution (you can use any character to separate the pattern from the substitution text)
suffix=
string- Suffix replacement
t"
separator"- Tokenization with given separator
u
- All characters mapped to uppercase
test = D1/D2/d3/a.out f.out d1/k.out
$@
- The full target name. When building a normal target, this macro evaluates to the full name of
the target. When building a library, it expands to the name of the archive library. For example, if
the target is:
mylib(member)
$@
expands to:mylib
$%
- The full target name. When building a normal target, this macro evaluates to the full name of
the target. When building a library, it expands to the name of the archive member. For example, if
the target is:
mylib(member)
$%
expands to:member
$&
- The list of all prerequisites.
$?
- The list of all prerequisites that are newer than the target.
$^
- The list of all prerequisites taken from the list specified on the rule line of the recipe where
the
$^
appears. $<
- In inference rules, it evaluates to the single prerequisite that caused the execution of the
rule. In normal rules it evaluates the same as
$?
. $>
- The name of the library if the current target is a library member.
$*
- The target name with no suffix (
$(%:db)
) or the value of the stem in a metarule.
$$@
, $$%
, $$>
,
and $$*
can appear in a prerequisite list as dynamic
prerequisites. $$@
stands for the target currently
being made. For example: fred : $$@.c
fred : fred.c
are equivalent. The construct can be modified,
as in: fred.o : $$(@:b).c
The runtime macros can be modified by the letters D
and F
to
indicate only the directory portion of the target name or only the file portion of the target name.
(The working directory is represented by a dot.) If define.h
is the only
prerequisite that is newer than the target, the macros $?D
and $?F
expand to dot ( .
) and to define.h
.
If
you are building a library, $$%
stands for the name
of the archive member being made. If you are building a normal target, $$%
stands
for the name of the target currently being made.
$$*
stands
for the name of the current target being made, but with no suffix.
If
you are building a library, $$>
stands for the name
of the archive library being made. If you are not building a library, $$>
is
not valid.
Rules
targets [attributes] ruleop [prerequisites]
[;recipe]
{<tab> recipe}
where the items enclosed in square
brackets are optional. (This is just a documentation convention; you
do not actually enter the square brackets.) The parts of the rule
are described as follows: - targets
- One or more target names.
- attributes
- A list, possibly empty, of attributes to apply to the list of targets.
- ruleop
- An operator token, usually a colon (
:
), that separates the target names from the prerequisite names and may also affect the processing of the specified targets. - prerequisites
- A list of zero or more names on which the specified targets depend.
- recipe
- A command to execute to update targets. May follow on the same line as the prerequisites, separated from them by a semicolon. If such a recipe is present, make takes it as the first in the list of recipe lines defining how to make the named targets. Additional recipe lines may follow the first line of the rule. Each subsequent recipe line must begin with a tab character.
targets : prereqs
- Is a simple rule definition. For explicit targets, at most one
simple rule may have a recipe, in contrast with the
::
rule operator, whose description follows. targets :! prereqs
- Executes the recipe for the associated targets once for each recently
changed prerequisite. In simple rules, the recipe is executed only
once, for all recently changed prerequisites at the same time. The
$<
macro expands to the current recently changed prerequisites if it appears in rules with this rule operator. targets :^ prereqs
- Inserts the specified prerequisites before any other prerequisites already associated with the specified targets.
targets :- prereqs
- Clears the previous list of prerequisites before adding the new prerequisites.
targets :: prereqs
- If no prerequisites are specified, the targets are always remade. Otherwise it is used for multiple rules applying to the same targets. Each rule can specify a different set of prerequisites with a different recipe for updating the target. Each rule is treated independently; the target is remade for each rule with recently changed prerequisites, using the corresponding recipe.
targets : | prereqs
- Can only be used in metarules. It tells make to treat each metadependency as
an independent rule. For example:
is equivalent to%$0 : | archive/%.c rcs/%.c /srcarc/RCS/%period.c recipe...
%$0 : archive/$.c recipe: %$0 : rcs/%.c recipe: %$0 : /srcarc/rcs/%.c recipe:
Circular dependencies
There are two types of circular dependencies: within-rule and between-rule.
c.o : a.o b.o c.o
is a
within-rule circular dependency. make detects a within-rule circular dependency
when it is parsing the makefile to build the dependency tree.a.o : b:o
b:o : a.o
is a
between-rules circular dependency. make detects a between-rule circular
dependency when it is processing the dependency tree built during the parse phase.Typically, make only
detects circular dependencies for those targets actually being built.
When a circular dependency is encountered, make issues
a warning message, removes the offending prerequisite from the list,
and continues parsing the makefile. You can use the .CYCLECHECK
special
target to alter. make's treatment of circular
dependencies.
Inference rules
With inference rules you can specify general rules for building files rather than creating a specific rule for each target.
make provides two forms of inference rules: suffix rules and metarules. It includes suffix rules to ensure compatibility with older makefiles. Metarules, however, provide a more general mechanism for specifying make's default behavior. They provide a superset of the functionality of suffix rules.
make searches all metarules before using suffix rules.
make uses the inference rules to infer how it can bring a target up-to-date. A list of inference rules defines the commands to be run. The default startup.mk file contains a set of inference rules for the most common targets. You can specify additional rules in the makefile.
When make finds
no explicit target rule to update a target, it checks the inference
rules. If make finds an applicable inference
rule with an out-of-date prerequisite, it runs on that rule's recipe.
See Targets for information about the .DEFAULT
special
target).
Metarules
Metarules have one target with
a single percent symbol that matches an arbitrary string called the
stem; The %
in a dependency stands for the stem.
%
s1, where
p1 and s1 are prefix and suffix strings of the
target, having a prerequisite
p2%
s2, where %
is the stem from the target, is specified as a rule:
p1%s1 : p2%s2 ; recipe....
Either the prefix or suffix string may be empty.
Transitive closure
Metarules provide a mechanism that allows several metarules to chain together to eventually create the target. This mechanism is called transitive closure. For example, if you have metarules:
%.o : %.c
... rule body...
and:
%.c : %.y
... rule body ...
make file.o
make uses the first metarule to look for file.c. If it can't find an explicit rule to build file.c, it again looks through the metarules and finds the rule that tells it to look for file.y.
% : %.c
... rule body ...
the command:
make file
causes make to look for file.c. If the metarules were not restricted and file.c did not exist, then make would look for file.c.c, and then file.c.c.c, and so on. Because each metarule is applied only once, this can't happen.)
% : %.o
recipe 1...
%.o : %c
recipe 2...
and you are making
file, this target matches successfully against %
causing
transitive closure to be computed for %
. As a result of this computation, a new
rule is created:
% : %.c
recipe 2... recipe from .REMOVE target for %.o, if not .PRECIOUS
recipe 1...
which
is executed if file.o doesn't exist. When the computation for the rule head has
been done, it is marked as transitive closure computed. Since all possible new rules have been added
to the rule set the first time the computation is done, it is not necessary to do it again: Nothing
new is added. The term transitive closure is adapted from the mathematical set theory. The best way to understand how this works is to experiment with little make files with the -v flag specified. This shows you in detail what rules are being searched, when transitive closure is calculated, and what rules are added.
Order of rule generation
Since transitive closure allows make to generate new rules, it is important to understand the order in which this is done:
- make searches for explicit rules in the order in which they appear, so explicit rules always take precedence.
- make reads metarules in the order in which they appear in the makefile. The first rule that appears in the makefile is the first one checked.
- New explicit metarules (as distinct from metarules generated by transitive closure) replace old
ones. In other words, if your makefile contains an explicit rule like this one, it replaces the
default rule in startup.mk:
If you use the -v option, make prints a warning when it replaces a metarule.%$O : %.c rule1
- When transitive closure is calculated, the new metarules generated are added to the end of the list of possible metarules. Thus, make always finds the explicit rules first, so they take precedence over generated rules. You can use the -v option to see what rules make generates and the order in which they appear.
- make performs two passes through the rules. On the first pass it tries to find a match with an explicit rule in the makefile; if this does not succeed, make performs a second pass to find a match with an existing file.
Suffix rules
make treats targets that begin with a period and contain no slashes or percent signs as suffix rules. If there is only one period in the target, it is a single suffix inference rule. Targets with two periods are double-suffix inference rules. Suffix rules do not have prerequisites but do have commands associated with them.
When make finds no explicit rule to update a target, it checks the suffix of the target (.s1) to be built against the suffix rules. make examines a prerequisite based on the basename of the target with the second suffix (.s2) appended, and if the target is out of date with respect to this prerequisite, make runs the recipe for that inference rule.
Metarules take precedence over suffix rules.
If the target to be built does not contain a suffix and there is no rule for the target, make checks the single suffix inference rules. The single suffix inference rules define how to build a target if make finds a rule with one of the single suffixes appended. A rule with one suffix .s2 defines how to build target from target.s2. make treats the other suffix (.s1) as null.
.SUFFIXES
special target. You can turn
off suffix rules by placing the following in your makefile: .SUFFIXES:
This
clears the prerequisites of the .SUFFIXES
target,
which prevents suffix rules from being enacted. The order that the
suffixes appear in the .SUFFIXES
rule determines
the order in which make checks the suffix
rules.The search algorithm used for suffix rules depends on
whether the .POSIX
special target is specified. When .POSIX
is
specified, the following steps describe the search algorithm for suffix
rules:
- Extract the suffix from the target. If that target does not have a suffix, go to step 6.
- Is it in the
.SUFFIXES
list? If not, quit the search. - If it is in the
.SUFFIXES
list, look for a double suffix rule that matches the target suffix. - If there is a match, extract the base name of the file, add on
the second suffix, and determine if the resulting file exists. If
the resulting file does not exist, keep searching the double suffix
rules.
If the resulting file does exist, use the recipe for this rule.
- If a successful match is not made, the inference has failed.
- If the target did not have a suffix, check the single suffix rules
in the order that the suffixes are specified in the
.SUFFIXES
target. - For each single suffix rule, add the suffix to the target name and determine if the resulting file name exists.
- If the file name exists, execute the recipe that is associated with that suffix rule. If the file name doesn't exist, continue trying the rest of the single suffix rules. If a successful match is not made, the inference has failed.
When the .POSIX
special target is not specified, make handles
suffix rules in the same manner as traditional implementations of make.
The following steps describe the search algorithm for suffix rules
in this situation.
- Extract the suffix from the target. If that target does not have a suffix, go to step 8.
- Is it in the
.SUFFIXES
list? If not, then quit the search. - If it is in the
.SUFFIXES
list, look for a double suffix rule that matches the target suffix. - If you find one, then extract the base name of the file, add on the second suffix and see if the resulting file exists. If it does, go to step 7. If not, continue with step 5.
- Is there an inference rule for the resulting file? If yes, run the recipe that is associated with that rule (which should describe how to make the file exist) and go to step 7.
- Search for the next double-suffix rule that matches the target suffix and return to step 4. If the double-suffix rules are exhausted, then the inference has failed.
- Use the recipe for the target rule.
- If the target did not have a suffix, then check the single-suffix
rules in the order that the suffixes are specified in the
.SUFFIXES
target. - For each single-suffix rule, add the suffix to the target name and see if the resulting file name exists.
- If the file exists, then run the recipe that is associated with that suffix rule. If it doesn't exist, continue trying the rest of the single-suffix rules.
- If a successful match is not made, then the inference has failed.
.suf.a:
recipe
the rule matches
any target having the LIBRARY
attribute set, regardless
of what the actual suffix was. For example, if your makefile contains
the rules: .SUFFIXES: .a .c
echo adding $< to library $@
then if mem$0
exists,
then the following command: make "mylib(mem.o)"
causes: adding mem.o to library mylib
to
be printed.Attributes
attribute_list : targets
This assigns the attributes in attribute_list to
the given targets. If you do not specify any targets, the attributes
apply to every target in the makefile. You can also put attributes
inside a normal rule, as in: targets attribute_list :
prerequisites
.EPILOG
- Insert shell epilog code when running a group recipe associated with any target having this attribute set.
.IGNORE
- Ignore an error when trying to make any target with this attribute set.
.LIBRARY
- Target is a library.
.PRECIOUS
- Do not remove this target under any circumstances. Any automatically inferred prerequisite inherits this attribute.
.PROLOG
- Insert shell prolog code when running a group recipe associated with any target having this attribute set.
.SETDIR
- Change the working directory to a specified directory when making
associated targets. The syntax of this attribute is
.SETDIR
=path, where path is the path name of desired working directory. If path contains any:
characters, the entire attribute string must be quoted, not just the path name. .SILENT
- Do not echo the recipe lines when making any target with this attribute set, and do not issue any warnings. You can use any attribute with any target, including special targets.
Control macros
make defines a number of control macros that control make's behavior. When there are several ways of doing the same thing, control macros are usually the best. A control macro that has the same function as a special target or attribute also has the same name.
Macros
that are said to be defined internally are automatically created
by make and can be used with the usual $(
name)
construct.
For example, $(PWD)
can be used to obtain the current
directory name.
DIRSEPSTR
- Contains the characters used to separate parts in a path name and can be set by the user. make uses the first character in this string to build path names when necessary.
.EPILOG
- If assigned a nonnull value, the
.EPILOG
attribute is given to every target. GROUPFLAGS
- Specifies option flags to pass to
GROUPSHELL
when make invokes it to run a group recipe. GROUPSHELL
- Gives the path name of the command interpreter (shell) that make calls to process group recipes.
GROUPSUFFIX
- Specifies a string for make to use as a suffix when creating group recipe files to be run by the command interpreter.
.IGNORE
- If this is assigned a nonnull value, make assigns
the
.IGNORE
attribute to every target. INCDEPTH
- This is the current depth of makefile inclusion. It is set internally.
MAKE
- This is set by the startup file and can be changed by the user. The standard startup file
defines it as:
$(MAKECMD) $(MFLAGS)
The
MAKE
macro is not used by make itself, but the string$(MAKE)
is recognized when using the -n option for single-line recipes. MAKECMD
- This is the name with which make was invoked.
MAKEDIR
- This is the full path name of the initial directory in which make began execution.
MAKEFLAGS
- The
MAKEFLAGS
macro contains all the options (flags) and macros specified in the MAKEFLAGS environment variable plus all of the options and macros specified on the command line, with the following exceptions.- Specifying -c, -f, or -p in the environment variable results in an error
- These same options specified on the command line do not appear in the
MAKEFLAGS
macro.
Options in the MAKEFLAGS environment variable may have optional leading dashes and spaces separating the options. These are stripped out when the MAKEFLAGS macro is constructed.Note: make always reads the MAKEFLAGS environment variable before reading the makefile. The -E and -e options do not affect this. MAKESTARTUP
- This has the default value:
/etc/startup.mk
To change this value, you can set the MAKESTARTUP environment variable before running make. You can also specify a value for this control macro on the command line if you use the -D option:make -DMAKESTARTUP=$HOME/project/startup.mk
Because make processes command-line macros after reading the startup file, setting this macro on the command line does not have the desired effect.
MFLAGS
- This is the same as
MAKEFLAGS
, except that it includes the leading switch character. NULL
- This is permanently defined to be the null string.
.PRECIOUS
- If this is assigned a nonnull value, make assigns
the
.PRECIOUS
attribute to every target. .PROLOG
- If this is assigned a nonnull value, make assigns
the
.PROLOG
attribute to every target. PWD
- This is the full path name of the working directory in which make is executing.
SHELL
- Specifies the full path name of the command interpreter that make calls
to process single-line recipes, when necessary. make passes
recipe lines to this shell only if they contain one or more of the
characters given in
SHELLMETAS
; otherwise, it runs them directly. By default, the value of the SHELL environment variable does not affect the value of this macro; however, you can use the.IMPORT
special target to assign the environment variable's value to this macro. You can also use the.EXPORT
special target to assign this macro's value to the SHELL environment variable. SHELLFLAGS
- Specifies option flags to pass to the shell when invoking it to runs a single-line recipe.
SHELLMETAS
- Specifies a list of metacharacters that can appear in single recipe
lines. If make finds any metacharacter,
it invokes the recipe using the shell specified by
SHELL
; otherwise, it runs the recipe without the shell. .SILENT
- If this is assigned a nonnull value, make assigns
the
.SILENT
attribute to every target.
Making libraries
A library is a file containing
a collection of object files. To make a library, you specify it as
a target with the .LIBRARY
attribute
and list its prerequisites. The prerequisites should be the object
members that are to go into the library.
make tries to handle the old library construct format in a sensible
way. When it finds lib(member)
, it declares the lib
portion as a target with the .LIBRARY
attribute and the
member portion as a prerequisite of the lib
target. To make the library properly, old makefile scripts using this format must name the
lib as a target and must try to bring it up-to-date. The same thing
happens for any target of the form lib((entry)). These targets have an
additional feature in that the entry target has the
.SYMBOL
attribute set automatically.
Conditional expressions
.IF expression
...
if text ...
.ELSE
... else text ...
.END
.IF expression
... if text ...
.ELSIF expression2
... else if text ...
.ELSE
... else text ...
.END
.ELSE
or .ELSIF
portion
is optional, and you can nest the conditionals (that is, the text
may contain another conditional). The .IF
, .ELSE
, .ELSIF
,
and .END
conditionals must start in the first column
of the line. expression or expression2 can
have one of three forms: string
is true
if the given string is nonnull, string == string
is true if the two strings are equal, and: string != string
is true if the two strings are not equal. Typically, one or both
strings contain macros, which make expands
before making comparisons. make also discards
white space at the start and end of the text portion before the comparison.
This means that a macro that expands to nothing but white space is
considered a null value for the purpose of the comparison. If a macro
expression needs to be compared with a null string, compare it to
the value of the macro $(NULL)
.The text enclosed in the conditional construct must have the same format that it would have outside the conditional. In particular, make assumes that anything that starts with a tab inside the conditional is a recipe line. This means that you cannot use tabs to indent text inside the conditional (except, of course, for recipe lines, which always begin with tabs).
Files
- /etc/startup.mk
- The default startup file containing default rules.
Environment variables
- MAKEFLAGS
- Contains a series of make options that are used as the default options for any make command. You can specify the options with or without leading minus signs (-) and blanks between them. It can also include macro definitions of the form usually found on the command line.
- MAKESTARTUP
- Contains the path name of the make stamp file. By default, make uses the file /etc/startup.mk as its startup file. To use a different file, set this environment variable before running make.
- SHELL
- Contains a name of a command interpreter. To assign this value to the
SHELL control macro, use the
.IMPORT
special target. You can also use the.EXPORT
special target to assign the value of the SHELL macro to the environment variable.
Localization
- LANG
- LC_ALL
- LC_CTYPE
- LC_MESSAGES
- LC_SYNTAX
- NLSPATH
Exit values
0
and 10
, make uses
exit status values below 10
only for failures that
do not run recipe lines. 0
- Successful completion
1
- Returned if you specified -q and file is not up-to-date
2
- Failure due to any of the following:
- Unknown command-line option.
- Missing argument to option, such as no file name for -f.
126
- Recipe command was not executable.
127
- Recipe command was not found.
129-254
- make was interrupted by a signal; the error code is the signal number ORed
with 128. For example,
SIGINT
is frequently signal 1; the return code from make is 128 or 129. 255
- Failure due to any of the following:
- Macro cannot be redefined
- Macro variables not assigned with
:=
- Special target cannot be a prerequisite
- Too many makefiles specified
- Configuration file not found
- No makefile present
- Missing
.END
for.IF
- No target
- Inability to return to directory
- Too many open files
- Open failed
- File not found
- Inability to change directory
- No more memory
- Line too long
- Circular macro detected
- Unterminated pattern string
- Unterminated replacement string
- Token separator string not quoted
- Unterminated separator string
- Expansion too long
- Suffix too long
- Unmatched quote
.IF
.ELSE ... END
nesting too deep.ELSE
without.IF
- Unmatched
.END
- Inference rules resulting in circular dependency
- No macro name
- Write error on temp file
- Target not found, and cannot be made
- Inability to make NAME
<+
diversion unterminated<+
diversion cannot be nested<+
missing before+>
- Incomplete rule recipe group detected
- Inability to mix single and group recipe lines
- Unmatched
]
found - Macro or rule definition expected but not found
- Name too long
- Inability to determine working directory
- Only one NAME attribute allowed in rule line
- Multiple targets not allowed in
%
rules - Special target must appear alone
- Duplicate entry in target list
- Syntax error in
%
rule, missing%
target - Duplicate entry in prerequisite list
- Missing targets or attributes in rule
- Multiply defined recipe for target
- Empty recipe for special target
- Imported macro NAME not found in environment
- No
.INCLUDE
files specified - Include file NAME, not found
- NAME ignored on special target
- Attributes possibly ignored
- Inability to find member defining
SYMBOL((
NAME))
- Incorrect library format
- Inability to touch library member
SHELL
macro not defined- Too many arguments
- Inability to export NAME
- Inability to open file
- Circular dependency detected
- Inability to stat
/
- Inability to stat
.
- Inability to open
..
- Read error in
..
- Metarule too long: "rule"
Usage notes
- The length of a single makefile script line cannot exceed 32768 characters.
- The length of an argument string cannot exceed 32768 characters.
- The length of a macro name is truncated after 256 characters.
- When the
.SETDIR
special target is used, make checks the file attributes of targets and prerequisites on every pass through a rule. This can significantly increase the number of system accesses. - In a double-byte environment, any character interpreted by make can be a double-byte character, including those in macro definitions and targets.
- In a double-byte locale, if make encounters an incorrect double-byte sequence, it ends with an error message.
Portability
POSIX.2, X/Open Portability Guide, UNIX systems.
- The options: -cdir, -D macro definition, -E, -u, -V, -v, and -x.
- The -n option has enhanced functionality not covered by the standard; for more
information, see the -n option and the
POSIX
special target for make. - The runtime macros: $&, $^ , $>.
- The dynamic prerequisites: $$%, $$>, $$*, $$@.
- All macro expansions.
- Macro assignments of the following form:
macroname := stringassigned macroname += stringassigned
- Brace expansion.
- Backslash continuation.
- The quoting mechanism, as in the following example:
"a:target" : "a:prerequisite"
- All rule operators except the colon (:).
- Conditionals.
- Metarules.
- All make attributes except
.IGNORE
,.PRECIOUS
,.SILENT
(referred to in POSIX.2 as special targets). - All make special targets except
.DEFAULT
,.POSIX
,.SUFFIXES
(referred to in POSIX.2 as special targets). - All make macros except SHELL (referred to in POSIX.2 as control macros).
Related information
c89, cc, c++, makedepend
S. I. Feldman, Make - Program for Maintaining Computer Programs, Software-Practice and Experience 9 (no. 4, April 1979):225-65 [Bell Labs, Murray Hill, NJ]