make(1)make(1)NAMEmake - maintain, update, and regenerate groups of programs
SYNOPSIS
makefile] [macro_namevalue] [names]
DESCRIPTION
Makefile Structure
A makefile can contain four different kinds of lines: target lines,
shell command lines, macro definitions, and include lines. Target
lines consist of a blank-separated, nonnull list of targets, followed
by a colon or double colon followed by a (possibly null) list of pre‐
requisite files called Pattern Matching Notation (see regexp(5)) is
supported for the generation of file names as dependents. Text follow‐
ing a semicolon on a target line, and all following lines that begin
with a tab are shell commands to be executed to update the target (see
the subsection below about The first line that does not begin with a
tab or begins a new target definition, macro definition, or include
line. Shell commands can be continued across lines by using a <back‐
slash><newline> sequence.
Target lines with their associated command lines are called rules.
Lines of the form are macro definitions. Macros can be defined any‐
where in the makefile, but are usually grouped together at the begin‐
ning. string1 is the macro name; string2 is the macro value. string2
is defined as all characters up to a comment character or an unescaped
newline. Spaces and tabs immediately to the left and right of the are
ignored. Subsequent appearances of anywhere in the makefile (except in
comments) are replaced by string2. The parentheses are optional if a
single character macro name is used and there is no substitute
sequence. An optional substitute sequence, [subst2]]can be specified,
which causes all nonoverlapping occurrences of subst1 at the end of
substrings in the value of string1 to be replaced by subst2. Sub‐
strings in a macro value are delimited by blanks, tabs, newline charac‐
ters, and beginnings of lines. For example, if
then
evaluates to
Macro values can contain references to other macros (see the section):
The value of is set to but when it is used in a target, command, or
include line, it is expanded to If the value of is subsequently changed
by another definition further down in the makefile or on the command
line, any references to reflect this change.
Macro definitions can also be specified on the command line and over‐
ride any definitions in the makefile.
(UNIX Standard only, see standards(5). Macros on the command line are
added to the environment variable. Macros defined in the environment
variable, but without any command line macro, adds the macro to the
environment overwriting any existing environment variable of the same
name.)
Certain macros are automatically defined for (see Built-in Macros).
See the subsection for a discussion of the order in which macro defini‐
tions are treated.
The value assigned to a macro can be overridden by a conditional macro
definition. A conditional macro definition takes on the form When the
target line associated with target is being processed, the macro value
specified in the conditional macro definition is in effect. If string1
is previously defined, the new value of string1 will override the pre‐
vious definition. The new value of string1 takes effect when target or
any dependents of target are being processed. If the string appears as
the first seven letters of a line in a makefile, and is followed by one
or more space or tab characters, the rest of the line is assumed to be
a file name and is read and processed by the current invocation of as
another makefile after any macros in the file name have been expanded.
The default behaviour of is to use built-in target, if target does not
have explicit commands associated with it and target is defined. See
the subsection.
General Description
executes commands previously placed in a makefile to update one or more
target names. Target names are typically names of programs. If no
option is specified, the file names and are tried in that order. If is
specified, the standard input is used. More than one option can be
specified. The makefile arguments are processed in the order speci‐
fied. A space between the and the file name be present, and multiple
makefile names must each have their own option preceding them. The
contents of a makefile override the built-in rules and macros if they
are present.
If no target names are specified on the command line, updates the first
target in the (first) makefile that is not an inference rule. A target
is updated in two cases: firstly, if it depends on files that are newer
than the target; secondly, if it depends on files that have same modi‐
fication time as that of the target. Missing files are deemed to be
out-of-date. All dependents of a target are recursively updated, if
necessary, before the target is updated. This effects a depth-first
update of the dependency tree for the target.
If a target does not have any dependents specified after the separator
on the target line (explicit dependents), any shell commands associated
with that target are executed if the target does not exist.
A target line can have either a single or double colon between the tar‐
get name or names and any explicit dependent names. A target name can
appear on more than one target line, but all of those lines must be of
the same (single- or double-colon) type. For the usual single-colon
case, at most one of these target lines can have explicit commands
associated with it. If the target is out-of-date with any of its
dependents on any of the lines, the explicit commands are executed, if
they are specified, or else a default rule can be executed. For the
double-colon case, explicit commands can be associated with more than
one of the target lines containing the target name; if the target is
out-of-date with any of the dependents on a particular line, the com‐
mands for that line are executed. A built-in rule may also be exe‐
cuted.
Target lines and their associated shell command lines are also referred
to as Hash marks and newline characters surround comments anywhere in
the makefile except in rules. Comments in the rules depend on the set‐
ting of the macro.
The following makefile says that depends on two files: and and that
they in turn depend on their corresponding source files and and a com‐
mon file
Command lines are executed one at a time, each by its own shell. Each
command line can have one or more of the following prefixes: or These
prefixes are explained below.
Commands returning nonzero status normally terminate The option or the
presence of the special target in the makefile cause to continue exe‐
cuting the makefile regardless of how many command lines cause errors,
although the error messages are still printed on standard output. If
is present at the beginning of a command line, any error returned by
that line is printed to standard output but does not terminate. The
prefix can be used to selectively ignore errors in a makefile. If the
option is specified and a command line returns an error status, work is
abandoned on the current target, but continues on other branches that
do not depend on that target. If the option is present in the environ‐
ment variable, processing can be returned to the default by specifying
the option.
The option specifies printing of a command line without execution.
However, if the command line has the string or in it or as a prefix,
the line is always executed (see discussion of the macro under The
(touch) option updates the modified date of a file without executing
any commands.
A command line is normally printed before it is executed, but if the
line has a at the beginning, printing is suppressed. The option or the
presence of the special target in the makefile suppresses printing of
all command lines. The can be used to selectively turn off printing.
Everything printed by (except the initial tab) is passed directly to
the shell without alteration. Thus,
produces
just as the shell would.
The option allows old makefiles (those written for the old version of
to run without errors. The old version of assumed that if a target did
not have any explicit commands associated with it, the user intended
the command to be null, and would not execute any rule that might have
been defined. The current version of operates in this mode by default.
However, the current version of provides a option which turns this mode
off so that if a target does not have explicit commands associated with
it and a rule is defined, the rule is executed. Note that the and
options have no effect on the search and possible location and execu‐
tion of an appropriate inference rule for the target. The search for a
built-in inference rule other than is always performed.
The signals and (see signal(5)) cause the target to be deleted unless
the target depends on the special name
Options
The following is a brief description of all options and some special
names. Options can occur in any order. They can be specified sepa‐
rately, or together with one except for the option.
Compatibility mode for old (Version 7) makefiles.
This option is turned on by default.
Turn off compatibility mode for old (Version 7) makefiles.
Debug mode. Print out detailed information on files and times exam‐
ined. (This is very verbose and is intended for debug‐
ging the command itself.)
Environment variables override assignments within makefiles .
Description file name, referred to as the makefile.
A file name of denotes the standard input. The contents
of the makefile override the built-in rules and macros
if they are present. Note that the space between and
makefile be present. Multiple instances of this option
are allowable (except for and are processed in the order
specified.
Ignore error codes returned by invoked commands.
This mode is also entered if the special target name
appears in the makefile.
When a command returns nonzero status,
abandon work on the current entry, but continue on other
branches that do not depend on that target. This is the
opposite of If both and are specified, the last one
specified is used.
No execute mode.
Print commands, but do not execute them. Even lines
beginning with an are printed. However, lines that con‐
tain the string or or that have as a prefix to the com‐
mand are executed.
Write to standard output the complete set of macro definitions
and target descriptions.
Update in parallel more than one target at a time.
The number of targets updated concurrently is determined
by the environment variable and the presence of direc‐
tives in make file.
Question. The command returns a zero or nonzero status code,
depending on whether the target file is or is not up-to-
date. Targets are not updated with this option.
Clear suffix list and do not use the built-in rules.
Silent mode. Command lines are not printed to standard output before
their execution. This mode is also entered if the spe‐
cial target name appears in the makefile.
Terminate if an error occurs while executing the commands
to bring a target up-to-date. This is the default and
the opposite of If both and are specified, the last one
given is used. This enables overriding the presence of
the flag in the environment variable.
Touch the target files (causing them to be up-to-date)
rather than issue the usual commands.
Unconditionally
the target, ignoring all timestamps.
Suppress warning messages.
Fatal messages will not be affected.
Zero or more command line macro definitions can be specified.
See the subsection.
[names] Zero or more target names that appear in the makefile.
Each target so specified is updated by If no names are
specified, updates the first target in the makefile that
is not an inference rule.
Parallel Make
If is invoked with the option, it tries to build more than one target
at a time, in parallel. (This is done by using the standard UNIX sys‐
tem process mechanism which enables multiple processes to run simulta‐
neously.) For the makefile shown in the example in the previous sub‐
section, it would create processes to build and in parallel. After
these processes were complete, it would build
The number of targets will try to build in parallel is determined by
the value of the environment variable If is invoked, but is not set,
then will try to build no more than two targets in parallel.
You can use the directive to serialize the updating of some specified
targets. This is useful when two or more targets modify a common out‐
put file, such as when inserting modules into an archive or when creat‐
ing an intermediate file with the same name, as is done by and If the
makefile in the previous subsection contained a directive of the form
it would prevent make from building a.o and b.o in parallel.
Environment
All variables defined in the environment (see environ(5)) are read by
and are treated and processed as macro definitions, with the exception
of the environment variable which is always ignored. The value of the
environment variable will not be used as a macro and will not be modi‐
fied by defining the macro in a makefile or on the command line. Vari‐
ables with no definition or empty string definitions are included by
There are four possible sources of macro definitions which are read in
the following order: internal (default), current environment, the make‐
file(s), and command line. Because of this order of processing, macro
assignments in a makefile override environment variables. The option
allows the environment to override the macro assignments in a makefile.
Command-line macro definitions always override any other definitions.
The environment variable is processed by on the assumption that it con‐
tains any legal input option (except and defined for the command line.
The variable can also be specified in the makefile.
(UNIX Standard only, see standards(5). in the makefile replaces the
environment variable. Command line options have precedence over envi‐
ronment variable.)
If is not defined in either of these places, constructs the variable
for itself, puts the options specified on the command line and any
default options into it, and passes it on to invocations of commands.
Thus, always contains the current input options. This proves very use‐
ful for doing recursive commands. Even when the option is specified,
command lines containing the string or are executed; hence, one can
perform a recursively on an entire software system to see what would
have been executed. This is possible because the is put into and
passed to the recursive invocations of or This is one way of debugging
all of the makefiles for a software project without actually executing
any of the commands.
Each of the commands in the rules is given to a shell to be executed.
The shell used is the shell command interpreter (see sh(1)), or the one
specified in the makefile by the macro. To ensure the same shell is
used each time a makefile is executed, the line:
or a suitable equivalent should be put in the macro definition section
of the makefile.
Suffixes
Target and/or dependent names often have suffixes. Knowledge about
certain suffixes is built into and used to identify appropriate infer‐
ence rules to be applied to update a target (see the subsection on The
current default list of suffixes is:
These suffixes are defined as the dependents of the special built-in
target This is done automatically by
Additional suffixes can be specified in a makefile as the dependents
list for These additional values are added to the default values. Mul‐
tiple suffix lists accumulate. The order of the suffix list is signif‐
icant (see the subsection). If the user wishes to change the order of
the suffixes, he must first define with a null dependent list, which
clears the current value for and then define with the suffixes in the
desired order. The list of suffixes built into on any machine can be
displayed by:
The list of built-in suffixes incorporated with the definitions in a
given makefile called can be displayed by:
Inference Rules
Certain target or dependent names (such as those ending with have
inferable dependents such as and etc. If no update commands for such a
name appear in the makefile, and if an inferable dependent file exists,
that dependent file is compiled to update the target. In this case,
has inference rules that allow building files from other files by exam‐
ining the suffixes and determining an appropriate inference rule to
use. There are currently default inference rules defined for:
Single Suffix Rules
Double Suffix Rules
Double suffix inference rules define how to build from Single suffix
inference rules define how to build from In effect, the first suffix is
null. Single suffix rules are useful for building targets from only
one source file; e.g., shell procedures and simple C programs.
A tilde in the above rules refers to an SCCS file (see sccsfile(4)).
Thus, the rule would transform an SCCS C source file into an object
file Since the of the SCCS files is a prefix, it is incompatible with
the suffix point-of-view of the command. Hence, the tilde is a way of
changing any file reference into an SCCS file reference.
A rule to create a file with suffix from a file with suffix is speci‐
fied as an entry with as the target and no dependents. Shell commands
associated with the target define the rule for making a file from a
file. Any target name that has no slashes in it and starts with a dot
is identified as an inference (rule instead of a target (rule. Targets
with one dot are single suffix inference rules; targets with two dots
are double suffix inference rules. Users can, in a makefile, define
additional inference rules and either redefine or cancel default infer‐
ence rules.
The default inference rule for changing a file into a file might look
like this:
and the default inference rule for changing a file to a C object file
might look like this:
Certain macros are used in the default inference rules to permit the
inclusion of optional matter in any resulting commands. For example,
and are used for compiler options to cc(1), lex(1), and yacc(1),
respectively. is commonly used to designate linker/loader options.
These macros are automatically defined by but can be redefined by the
user in the makefile.
The macro is, by convention, used to specify the order of inclusion of
any special libraries during the linking phase of compilation. To
specify a particular order of inclusion for a particular set of
libraries, the existing single suffix rule for a file,
can be redefined as
as well as defining in the makefile.
There are also some special built-in macros used in the inference rules
See the subsection.
If a target does not have explicit dependents, or if a dependent does
not also have a target that matches it with associated explicit rules,
looks for the first inference rule that matches both the target's
(dependent's) suffix (which may be null) and a file which matches the
other suffix of the rule. Since it conducts this search by going
through the list of values front to back, the order in which is defined
is significant.
To print out the rules compiled into the on any machine, type:
Since defines an inference rule the example in the subsection can be
rewritten more simply:
Libraries
If a target or dependent name contains parentheses, it is assumed to be
an archive library, the string within parentheses referring to a member
within the library. Thus and both refer to an archive library that
contains (this assumes the macro has been previously defined). The
expression is not valid. Rules pertaining to archive libraries have
the form where xx is the suffix from which the archive member is to be
made. An unfortunate byproduct of the current implementation requires
the xx to be different from the suffix of the archive member. Thus,
one cannot have depend upon explicitly. The most common use of the ar‐
chive interface follows. Here, we assume the source files are all C
type source:
(See the subsection on for an explanation of the and symbols.) In
fact, the rule listed above is built into and is unnecessary in this
example. This rule is applied to each dependent of in turn. The fol‐
lowing example accomplishes this more efficiently:
Here substitution in the macros is used. The list is defined to be the
set of object file names (inside whose C source files are out-of-date.
The substitution sequence translates the to (Unfortunately, one cannot
as yet transform to however, this may become possible in the future.)
Note also, the disabling of the rule, which would have created and
archived each object file, one by one. This particular construct
speeds up archive library maintenance considerably, but becomes very
cumbersome if the archive library contains a mix of assembly programs
and C programs.
Archive members containing the definition of a symbol are designated by
double parentheses around the symbol name, but are otherwise handled as
described above.
Built-In Targets
has knowledge about some special targets. These must be specified in
the makefile to take effect (with the exception of which is automati‐
cally set by but can be changed by the user).
If a file must be made but there are no explicit commands
or relevant built-in rules for it, the commands
associated with the target name are used if has
been defined in the makefile. does not have any
explicit dependents.
Dependents of this target are not removed when
or are received.
Same effect as the
option. No dependents or explicit commands need
to be specified.
Same effect as the
option. No dependents or explicit commands need
to be specified.
The explicit dependents of
are added to the built-in list of known suffixes
and are used in conjunction with the inference
rules. If does not have any dependents, the list
of known suffixes is cleared. There are no com‐
mands associated with
Serialize the updating of specified targets (See the
Section).
Built-in Macros
There are five internally maintained macros that are useful for writing
rules for building targets. In order to clearly define the meaning of
these macros, some clarification of the terms and is necessary. When
updates a target, it may actually generate a series of targets to
update. Before any rule (either explicit or implicit) is applied to
the target to update it, recursion takes place on each dependent of the
target. The dependent, upon recursion, becomes a target itself, and
may have or generate its own dependents, which in turn are recursed
upon until a target is found that has no dependents, at which point the
recursion stops. Not all targets processed by appear as explicit tar‐
gets in the makefile; some of them are explicit dependents from the
makefile while others are implicit dependents generated as recursively
updates the target. For instance, when the following makefile is exe‐
cuted:
the following series of targets to be made is generated:
with two dependents and an explicit rule to follow
(recursively) with an implicit dependent of
which matches the implicit rule
(recursively) with no implicit dependents and no implicit rules.
This stops the recursion and simply returns the last
modification time of the file
(recursively) with an implicit dependent of
which matches the implicit rule
(recursively) with no implicit dependents and no implicit rules.
This stops the recursion and merely returns the last
modification time of the file
In the definitions below, the word target refers to a target specified
in the makefile, an explicit dependent specified in the makefile which
becomes the target when recurses on it, or an implicit dependent (gen‐
erated as a result of locating an inference rule and file that match
the suffix of the target) which becomes the target when recurses on it.
The word dependent refers to an explicit dependent specified in the
makefile for a particular target, or an implicit dependent generated as
a result of locating an appropriate inference rule and corresponding
file that matches the suffix of the target.
It may be helpful to think of target rules as user specified rules for
a particular target name, and inference rules as user or specified
rules for a particular class of target names. It may also be helpful
to remember that the value of the target name and its corresponding
dependent names change as recurses on both explicit and implicit depen‐
dents, and that inference rules are only applied to implicit dependents
or to explicit dependents which do not have target rules defined for
them in the makefile.
The macro is the full target name of the current target, or
the archive file name part of a library archive target.
It is evaluated for both target and inference rules.
The macro is only evaluated when the current target is an
archive library member of the form or In these cases,
evaluates to and evaluates to or the object file con‐
taining the symbol is evaluated for both target and
inference rules.
The macro is the list of dependents that are out-of-date
with respect to the current target; essentially, those
modules that have been rebuilt. It is evaluated for
both target and inference rules, but is usually only
used in target rules. evaluates to one name only in an
inference rule, but may evaluate to more than one name
in a target rule.
In an inference rule,
evaluates to the source file name that corresponds to
the implicit rule which matches the suffix of the target
being made. In other words, it is the file that is out-
of-date with respect to the target. In the rule, the
macro evaluates to the current target name. is evalu‐
ated only for inference rules. Thus, in the rule, the
macro would evaluate to the file. An example for making
optimized files from files is:
or:
The macro is the current target name with the suffix deleted. It
is evaluated only for inference rules.
These five macros can have alternative forms. When an uppercase or is
appended to any of the five macros, the meaning is changed to ``direc‐
tory part'' for and ``file part'' for Thus, refers to the directory
part of the string If there is no directory part, is generated. When
the macro contains more than one dependent name, the expands to a list
of directory name parts and the expands to a list of the file name
parts.
In addition to the built-in macros listed above, other commonly used
macros are defined by These macros are used in the default inference
rules, and can be displayed with the option. These macros can be used
in target rules in the makefile. They can also be redefined in the
makefile.
The macro has meaning on dependency lines. Macros of
this form are called because they are evaluated
at the time the dependency is actually processed.
evaluates to exactly the same thing as does on a
command line; that is, the current target name.
This macro is useful for building large numbers
of executable files, each of which has only one
source file. For instance, the following HP-UX
commands could all be built using the same rule:
CMDS = cat echo cmp chown
$(CMDS) : $$@.c
$(CC) -O $? -o $@
If this makefile is invoked with builds each tar‐
get in turn using the generic rule, with evaluat‐
ing to while is the target, to when the target is
and so forth.
The dynamic dependency macro can also take the F
form, which represents the file name part of This
is useful if the targets contain path names. For
example:
INCDIR = /usr/include
INCLUDES = $(INCDIR)/stdio.h \
$(INCDIR)/pwd.h \
$(INCDIR)/dir.h \
$(INCDIR)/a.out.h
$(INCLUDES) : $$(@F)
cp $? $@
chmod 0444 $@
Special Macros
The VPATH macro allows make to search a colon separated list of direc‐
tories for dependents. Lines of the form causes make to first search
the current directory for a dependent and if the dependent is not
found, make searches path1 and continues until the directories speci‐
fied in the VPATH macro are exhausted.
EXTERNAL INFLUENCES
For information about the UNIX standard environment, see standards(5).
Environment Variables
provides a default value for the internationalization variables that
are unset or null. If is unset or null, the default value of "C" (see
lang(5)) is used. If any of the internationalization variables con‐
tains an invalid setting, will behave as if all internationalization
variables are set to "C". See environ(5).
If set to a nonempty string value, overrides the values of all the
other internationalization variables.
determines the interpretation of text as single and/or multi-byte char‐
acters, the classification of characters as printable, and the charac‐
ters matched by character class expressions in regular expressions.
determines the locale that should be used to affect the format and con‐
tents of diagnostic messages written to standard error and informative
messages written to standard output.
determines the location of message catalogues for the processing of
provides a directory to be used to search for SCCS files not found in
the current directory. In all of the following cases, the search for
SCCS files will be made in the directory in the identified directory.
If the value of begins with a slash, it is considered an absolute path
name; otherwise, the home directory of a user of that name is examined
for a subdirectory or If such a directory is found, it is used. Other‐
wise, the value is used as a relative path name.
If is not set or has a null value, the current directory is searched
first, followed by a search in the directory in the current directory.
The setting of affects all files listed in the remainder of this util‐
ity description for files with a component named
International Code Set Support
Single and multi-byte character code sets are supported.
RETURN VALUE
returns a 0 upon successful completion or a value greater than 0 if an
error occurred. If the option is specified, returns 0 if the target
was up-to-date and a value greater than 0 if the target was not up-to-
date.
EXAMPLES
The following example creates an executable file from a C source code
file without a makefile, if program.c exists in the current directory:
The following example shows more than one makefile specified and some
command line macros defined, and updates the first target in module1:
The following example updates two targets in a default makefile cur‐
rently residing in the current directory:
The following example updates the prog target in a specified makefile,
allows environment variables to override any common variables in the
makefile, clears the built-in suffix list and ignore the built-in
rules, and outputs exhaustive debugging information:
WARNINGS
Be wary of any file (such as an include file) whose access, modifica‐
tion, and last change times cannot be altered by the process. For
example, if a program depends on an include file that in turn depends
on another include file, and if one or both of these files are out-of-
date, tries to update these files each time it is run, thus unnecessar‐
ily up-to-date files that are dependent on the include file. The solu‐
tion is to manually update these files with the command before running
(see touch(1)).
Some commands return nonzero status inappropriately; use to overcome
the difficulty.
File names with the characters and do not work.
Built-in commands that are directly executed by the shell such as (see
cd(1)), are ineffectual across newlines in
The syntax is illegal.
You cannot build from
The macro does not work.
Expanded target lines cannot contain more than 16384 characters,
including the terminating newline.
If no makefile exists in the current directory, typing
results in attempting to build from
If is invoked in a shell script with a quoted argument that evaluates
to NULL (such as fails.
DEPENDENCIES
NFS Warning
When comparing modification times of files located on different NFS
servers, behaves unpredictably if the clocks on the servers are not
synchronized.
FILES
SEE ALSO
cc_bundled(1), cd(1), lex(1), mkmf(1), sh(1), env‐
iron(5), lang(5), regexp(5), standards(5).
by Steve Talbot, Second Edition, O'Reilly & Associates,
Inc., 1986.
STANDARDS CONFORMANCEmake(1)