make(1) make(1)
NAME
make - maintain groups of files
SYNOPSIS
make [option ...] [macro-definition ...] [target ...]
DESCRIPTION
When modular programming is used, programs generally consist of a
number of file. make offers a method of updating such programs.
make uses a makefile, in which the user can define targets, and can
specify how one target depends others. When a source file is altered,
make recreates the program by recompiling only those parts which are
directly or indirectly dependent on the amended file.
make recreates the target when the latter is older than at least one
of the files on which it depends. make takes into account the inter-
dependencies of the files, and supplies the date and time of the last
change to a file.
The makefile is normally called makefile, Makefile, s.makefile or
s.Makefile. If this naming convention is adhered to, make can be
called without specifying any arguments. make will search for the
makefile in the current directory or in the SCCS directory, and will
recreate the target file if at least one change has taken place.
Page 1 Reliant UNIX 5.44 Printed 11/98
make(1) make(1)
OPTIONS
-e Overwrites the definitions in makefiles by environment variables.
-f makefile
makefile is assumed to be the name of a description file.
-i Ignores error codes returned by commands which are part of a com-
mand sequence. make will continue processing even after an error.
.IGNORE in the makefile has the same effect.
-k Cancels the command sequence if an error occurs in one of the
makefiles entries. Processing is continued for all other targets
which do not depend on the defective target. -k overwrites
preceding -S options.
-n Serves as a debugging aid. All the commands will be output,
including those beginning with an @. Only commands preceded by a
plus sign + are executed.
-p Outputs a complete list of the macro definitions and target file
descriptions.
-q Returns a zero status if the target file is up-to-date. A nonzero
status indicates that the target file must be recreated. The tar-
get file is not changed, however, commands preceded by a plus
sign + are executed.
-r Ignores the built-in rules.
-s Suppresses the setting of a new timestamp output of the commands
which are executed. .SILENT as the target in the makefile has the
same effect.
-S Terminates if an error occurs in one of the makefiles entries.
This is the default setting. -S overwrites preceding -k options.
-t Gives a new timestamp to the targets of the makefiles and these
are then taken to be up-to-date. Only commands preceded by a plus
sign + are executed.
-- If the first filename begins with a dash (-), the end of the
command-line options must be marked with --.
Page 2 Reliant UNIX 5.44 Printed 11/98
make(1) make(1)
Creating a makefile
The makefile invoked with the -f option is a carefully structured file
of explicit instructions for updating and regenerating programs, and
contains a sequence of entries that specify dependencies. The first
line of an entry is a blank-separated, non-null list of targets, then
a :, then a (possibly null) list of prerequisite files or dependen-
cies. Text following a ; and all following lines that begin with a tab
are shell commands to be executed to update the target. The first
non-empty line that does not begin with a tab or # begins a new depen-
dency or macro definition. Shell commands may be continued across
lines with a backslash-newline (\ newline) sequence. Everything
printed by make (except the initial tab) is passed directly to the
shell as is. Thus,
echo a\
b
will produce
a b
exactly the same as the shell would.
Commands which are more than one line long must be a maximum of
LINEMAX lines long in total if the .POSIX command is used.
Comments are enclosed between # and the newline character.
The following makefile says that pgm depends on two files a.o and b.o,
and that they in turn depend on their corresponding source files (a.c
and b.c) and a common file incl.h:
pgm: a.o b.o
cc a.o b.o -o pgm
a.o: incl.h a.c
cc -c a.c
b.o: incl.h b.c
cc -c b.c
Executing a makefile
Command lines are executed in sequence from a separate shells. The
shell used by make to execute the commands can be specified using the
SHELL environment variable or the SHELL macro. The default is
/usr/bin/sh.
The following commands can be specified in a makefile to control the
execution of the commands:
Page 3 Reliant UNIX 5.44 Printed 11/98
make(1) make(1)
.POSIX
make fully supports the XPG4 specification. make deviates from
the description in some points to ensure that existing makefiles
can be executed.
.DEFAULT
If a file must be created, but there are no specific commands or
relevant inference rules available, the commands specified in
.DEFAULT are used.
.IGNORE
Error messages from commands are ignored for all files that
depend on this target. If no file is specified, it has the same
effect as -i.
.PRECIOUS
Files that depend on this target are not deleted if the quit sig-
nal or the interrupt signal is received. If no file is specified,
all files are retained.
.SILENT
Output of the executed commands is suppressed for all files
independent of this target. If no file is specified, it has the
same effect as -s.
The execution of individual commands can be controlled by preceding
them with @, - or +:
@ Command output is suppressed
- Errors are ignored
+ The command is always executed, even if one of the -n, -q or -t
options is set.
A line is output when it is executed if the -s option is present, the
.SILENT entry is valid for the file, or the initial string contains a
@. The -n option outputs the command without executing it, unless the
command line is preceded by + (in which case the line is always exe-
cuted). The -t option brings the altered date of a file up-to-date
without executing the command (unless a command is preceded by +).
make is normally terminated by commands (or when the -S option is set)
which return a non-zero status. The end status is ignored if the -i
option is present, the .IGNORE entry is valid for the file, or the
initial string of the command contains -. If the -k option is present,
work is terminated on the current entry but continued in other
branches which do not depend on this entry.
The target file is deleted by canceling and quitting, unless the .PRE-
CIOUS entry is valid for it.
Page 4 Reliant UNIX 5.44 Printed 11/98
make(1) make(1)
Environment
The environment is read by make. All variables are assumed to be macro
definitions and are processed as such - except the SHELL variable. The
value of the SHELL environment variable will not be used as a macro
and will not be modified by defining the SHELL macro in a makefile or
on the command line. The environment variables are processed before
any makefile and immediately after the internal rules; thus, macro
assignments in a makefile override environment variables. The -e
option causes the environment to override the macro assignments in a
makefile. Suffixes and their associated rules in the makefile will
override any identical suffixes in the built-in rules.
The MAKEFLAGS environment variable can contain macros and all input
options which are valid for the command line with the exception of -f
and -p. make evaluates the variable in front of the command line. The
MAKEFLAGS macro (and the variable if it is not defined) is automati-
cally assigned the current options and macros when make is called, and
is passed on when the commands are called. In this way, the MAKEFLAGS
macro always contains the current definitions. This feature proves
very useful for "super-makes". In fact, as noted above, when the -n
option is used, the command $(MAKE) is executed anyway; hence, one can
perform a make -n recursively on a whole software system to see what
would have been executed. This result is possible because the -n is
put in MAKEFLAGS and passed to further invocations of $(MAKE). This
usage is one way of debugging all of the makefiles for a software pro-
ject without actually doing anything.
The PROJECTDIR environment variable specifies in which directory the
SCCS files should be sought if they are not in the current directory.
SCCS files are searched for in a SCCS subdirectory. If a relative
pathname is specified, the HOME directory is searched first for the
src or source subdirectories. If these directories do not exist, the
path is set relative to the current directory.
Include files
If the string include appears as the first seven letters of a line in
a makefile, and is followed by a blank or a tab, the rest of the line
is assumed to be a filename and will be read by the current invoca-
tion, after substituting for any macros.
Macro definitions
Entries of the form string1 = string2 are macro definitions. string2
is defined as all characters up to a comment character or an unescaped
newline. Subsequent appearances of $(string1[:subst1=[subst2]]) are
replaced by string2. The parentheses are optional if a single-
character macro name is used and there is no substitute sequence. The
optional :subst1=subst2 is a substitute sequence. If it is specified,
all nonoverlapping occurrences of subst1 in the named macro are
replaced by subst2. Strings for this type of substitution are
Page 5 Reliant UNIX 5.44 Printed 11/98
make(1) make(1)
delimited by blanks, tabs, newline characters, and beginnings of
lines. An example of the use of the substitute sequence is shown in
the "Libraries" section below.
The SHELL macro is treated specially. It is provided and set to the
pathname of the shell command language interpreter sh(1). The SHELL
environment variable will not affect the value of the SHELL macro. If
SHELL is defined in the makefile or is specified on the command line,
it will replace the original value of the SHELL macro, but will not
affect the SHELL environment variable.
Internal macros
There are five internally maintained macros that are useful for writ-
ing rules for building targets.
$* stands for the filename part of the current dependent with the
suffix deleted. It is evaluated only for inference rules.
$@ stands for the full target name of the current target. It is
evaluated only for explicitly named dependencies.
$< is only evaluated for inference rules or the .DEFAULT rule. It is
the module that is outdated with respect to the target, i.e. the
"manufactured" dependent filename. Thus, in the .c.o rule, the $<
macro would evaluate to the .c file.
An example for making optimized .o files from .c files is:
.c.o:
cc -c -O $*.c
or:
.c.o:
cc -c -O $<
$%? is evaluated when explicit rules from the makefile are evaluated.
It is the list of prerequisites that are outdated with respect to
the target.
$% is only evaluated when the target is an archive library member of
the form lib(file.o). In this case, $@ evaluates to lib and $%
evaluates to the library member, file.o.
The macros can have alternative forms. When an upper case D or F is
appended, the meaning is changed to "directory part" for D and "file
part" for F. Thus, $(@D) refers to the directory part of the string
$@. If there is no directory part, ./ is generated. If the $? macro
contains more than one filename, the $(?D) and $(?F) macros (or ${?D}
and ${?F}) expand into a list of directory parts and file parts.
Page 6 Reliant UNIX 5.44 Printed 11/98
make(1) make(1)
Inference rules
Certain names, such as those ending with .o, have inferable prere-
quisites such as .c, .s, etc. If no update commands for such a file
appear in makefile, and if an inferable prerequisite exists, that
prerequisite is compiled to make the target. In this case, make has
inference rules that allow building files from other files by examin-
ing the suffixes and determining an appropriate inference rule to use.
The current default inference rules are:
.c .c~ .f .f~ .s .s~ .sh .sh~ .C .C~
.c.a .c.o .c~.a .c~.c .c~.o .f.a .f.o .f~.a .f~.f .f~.o
.h~.h .l.c .l.o .l~.c .l~.l .l~.o .s.a .s.o .s~.a .s~.o
.s~.s .sh~.sh .y.c .y.o .y~.c .y~.o .y~.y .C.a .C.o .C~.a
.C~.C .C~.o .L.C .L.o .L~.C .L~.L .L~.o .Y.C .Y.o .Y~.C
.Y~.o .Y~.Y
The user may add rules to this list by simply putting them in the
makefile.
The inference of prerequisites can be controlled. The rule to create a
file with suffix .o from a file with suffix .c is specified as an
entry with .c.o: as the target and no dependents. Shell commands asso-
ciated with the target define the rule for making a .o file from a .c
file. Any target that has no slashes in it and starts with a dot is
identified as a rule and not a true target.
The internal rules for make are contained in the source file rules.c
for the make program. These rules can be locally modified. To print
out the rules compiled into the make on any machine in a form suitable
for recompilation, the following command is used:
make -pf - 2>/dev/null </dev/null
A tilde in the above rules refers to an SCCS file [see sccsfile(4)].
Thus, the rule .c~.o would transform an SCCS C source file into an
object file (.o). Because the s. of the SCCS files is a prefix, it is
incompatible with the make suffix point of view. Hence, the tilde is a
way of changing any file reference into an SCCS file reference.
A rule with only one suffix (for example, .c:) is the definition of
how to build x from x.c. In effect, the other suffix is null. This
feature is useful for building targets from only one source file (for
example, shell procedures and simple C programs).
Additional suffixes are given as the dependency list for .SUFFIXES.
Order is significant; the first possible name for which both a file
and a rule exist is inferred as a prerequisite. The default list is:
.SUFFIXES .o .c .c~ .y .y~ .l .l~ .s .s~ .sh .sh~ .h .h~ .f .f~
.C .C~ .Y .Y~ .L .L~
Page 7 Reliant UNIX 5.44 Printed 11/98
make(1) make(1)
Here again, the above command for printing the internal rules will
display the list of suffixes implemented on the current machine. Mul-
tiple suffix lists accumulate; .SUFFIXES: with no dependencies clears
the list of suffixes.
The example given in "Creating a makefile" can be formulated shorter
using this:
pgm: a.o b.o
cc a.o b.o -o pgm
a.o b.o: incl.h
Certain macros are used by the default inference rules to permit the
inclusion of optional matter in any resulting commands. For example,
CFLAGS, LFLAGS, and YFLAGS are used for compiler options to cc(1),
lex(1), and yacc(1), respectively.
With the .SCCSGET command, the default commands for accessing SCCS
files which are not in the current directory, can be changed. The
inference rule is:
.SCCSGET: sccs $(SCCSFLAGS) get $(SCCSGETFLAGS) $@
Libraries
If a target or dependency name contains parentheses, it is assumed to
be an archive library, the string within parentheses referring to a
member within the library. Thus, lib(file.o) and $(LIB)(file.o) both
refer to an archive library that contains file.o. This example assumes
the LIB macro has been previously defined. The expression
$(LIB)(file1.o file2.o) is not legal. Rules pertaining to archive
libraries have the form .XX.a where the XX is the suffix from which
the archive member is to be made. An unfortunate by-product of the
current implementation requires the XX to be different from the suffix
of the archive member. Thus, one cannot have lib(file.o) depend upon
file.o explicitly.
The most common use of the archive interface follows. Here, we assume
the source files are all C type source:
lib: lib(file1.o) lib(file2.o) lib(file3.o)
@echo lib is now up-to-date
.c.a:
$(CC) -c $(CFLAGS) $<
$(AR) $(ARFLAGS) $@ $*.o
rm -f $*.o
In fact, the .c.a rule listed above is built into make and is unneces-
sary in this example. A more interesting, but more limited example of
an archive library maintenance construction follows:
Page 8 Reliant UNIX 5.44 Printed 11/98
make(1) make(1)
lib: lib(file1.o) lib(file2.o) lib(file3.o)
$(CC) -c $(CFLAGS) $(?:.o=.c)
$(AR) $(ARFLAGS) lib $?
rm $?
@echo lib is now up-to-date
.c.a:;
Here the substitution mode of the macro expansions is used. The $?
list is defined to be the set of object filenames (inside lib) whose C
source files are outdated. The substitution mode translates the .o to
.c. Unfortunately, one cannot as yet transform to Also note the disa-
bling of the .c.a: rule, which would have created each object file,
one by one. This particular construct speeds up archive library
maintenance considerably. This type of construct becomes very cumber-
some if the archive library contains a mix of assembly programs and C
programs.
DIAGNOSTICS
With the defective output of make an error message appears which con-
tains a contraction in the form (bucodeno). The help codeno command
can be used to assess this code. You then receive a detailed explana-
tion of the error. Example:
make: *** Error code 1 (bu21) (ignored)
$ help bu21
bu21:
"*** Error code '...' " OR "*** Termination code ' ' "
This error is reported but does not occur in make(1). It
is associated with the last command executed. See the UNIX manual for
additional information on the error codes for that command. If
"ignored" has been printed on the line immediately following the above
error message, this error is ignored by make(1). Errors
will be ignored if the -i option was set on execution, or if the dummy
target .IGNORE appears in the makefile, or if the particular command was
prefaced with a minus sign (-).
Note: The help command is not internationalized.
LOCALE
The language of the message texts is governed by the environment vari-
able LCALL, LCMESSAGES or LANG.
When the default is set, the system behaves as if it were not interna-
tionalized, i.e. the message texts are in English. You must change one
of these variables in order to change the language of the message
texts.
Page 9 Reliant UNIX 5.44 Printed 11/98
make(1) make(1)
Detailed information on the dependencies of the environment variables
and on internationalization in general can be found in the manual
"Programmer's Guide: Internationalization - Localization". Refer also
to environ(5) for information on setting the user environment.
NOTES
Some commands return non-zero status inappropriately; use -i or the -
command line prefix to overcome the difficulty.
Filenames with the characters = : @ will not work. Commands that are
directly executed by the shell, notably cd(1), are ineffectual across
newlines in make. The syntax lib(file1.o file2.o file3.o) is illegal.
You cannot build lib(file.o) from file.o.
FILES
[Mm]akefile and s.[Mm]akefile
/usr/bin/sh
SEE ALSO
cc(1), cd(1), lex(1), sh(1), yacc(1), printf(3S), sccsfile(4).
Chapter on "make" in the "Guide to Tools for Programming in C".
Page 10 Reliant UNIX 5.44 Printed 11/98