make

NAME

make - maintain program dependencies

SYNOPSIS

make [-eiknqrSst ] [-D variable] [-d flags]
	 [-f makefile] [-I directory] [-m directory]
	 [-V variable] [variable=value] [target ... ]

DESCRIPTION

The make(1) program is designed to simplify the maintenance of other programs. Its input is a list of specifications that pertain to the files upon which programs and other files depend. If the file makefile exists, it is read for this list of specifications. If it does not exist, the file Makefile is read. If the file .depend exists, it is read.

The options are as follows:

-D variable
Define variable to be 1, in the global context.
-d flags
Turn on debugging, and specify which portions of make(1) are to print debugging information. The flags would be one or more of the following:
A
Print all possible debugging information; equivalent to specifying all of the debugging flags.
a
Print debugging information about archive searching and caching.
c
Print debugging information about conditional evaluation.
d
Print debugging information about directory searching and caching.
g1
Print the input graph before making anything.
g2
Print the input graph after making everything, or before exiting on error.
j
Print debugging information about running multiple shells.
m
Print debugging information about making targets, including modification dates.
s
Print debugging information about suffix-transformation rules.
t
Print debugging information about target list maintenance.
v
Print debugging information about variable assignment.
-e
Specify that environmental variables override macro assignments within makefiles.
-f makefile
Specify a makefile to read instead of the default makefile and Makefile. If makefile is -, standard input is read. Multiple makefiles can be specified, and are read in the order specified.
-I directory
Specify a directory to search for makefiles and included makefiles. The system makefile directory is automatically included as part of this list.
-i
Ignore non-zero exit of shell commands in the makefile. Equivalent to specifying - before each command line in the makefile.
-k
Continue processing after errors are encountered, but only on those targets that do not depend on the target whose creation caused the error.
-m directory
Specify a directory to search for sys.mk and makefiles included through the <...> style .include directive. Multiple directories can be added to form a search path. This path will override the default system include path (/usr/share/mk). Furthermore, the system include path will be appended to the search path used for "..."-style inclusions (see the -I option).
-n
Display the commands that would have been executed, but do not actually execute them. Note that some versions of make(1) (notably, the System V version and gmake(1)) recursively call make(1). This version does not do that. The POSIX standard does not require that behavior. Use the + operator or the .MAKE pseudo target to cause the execution of recursive makes.
-q
Do not execute any commands, but exit 0 if the specified targets are up-to-date and 1, otherwise. Note that some versions of make(1) (notably the System V version and gmake(1)) recursively call make(1). This version does not do that. The POSIX standard does not require that behavior. Use the + operator or the .MAKE pseudo target to cause the execution of recursive makes.
-r
Do not use the built-in rules specified in the system makefile.
-S
A synonym for -k.
-s
Do not echo any commands as they are executed. Equivalent to specifying @ before each command line in the makefile.
-t
Rather than rebuilding a target as specified in the makefile, create it or update its modification time to make it appear up-to-date. Note that some versions of make(1) (notably the System V version and gmake(1)) recursively call make(1). This version does not do that. The POSIX standard does not require that behavior. Use the + operator or the .MAKE pseudo target to cause the execution of recursive makes.
-V variable
Print the make(1) interpretation of the value of variable, in the global context. Do not build any targets. Multiple instances of this option may be specified. The variables will be printed one per line, with a blank line for each null or undefined variable.
variable=value
Set the value of the variable variable to value.

There are seven different types of lines in a makefile: file dependency specifications, shell commands, variable assignments, include statements, conditional directives, for loops, and comments.

In general, lines can be continued from one line to the next by ending them with a backslash (\). The trailing newline character and initial white space on the following line are compressed into a single space.

FILE DEPENDENCY SPECIFICATIONS

Dependency lines consist of one or more targets, an operator, and zero or more sources. This creates a relationship where the targets depend on the sources and are usually created from them. The exact relationship between the target and the source is determined by the operator that separates them. The three operators are as follows:

:
A target is considered out-of-date if its modification time is less than those of any of its sources. Sources for a target accumulate over dependency lines when this operator is used. The target is removed if make(1) is interrupted.
!
Targets are always recreated, but not until all sources have been examined and recreated as necessary. Sources for a target accumulate over dependency lines when this operator is used. The target is removed if make(1) is interrupted.
::
If no sources are specified, the target is always recreated. Otherwise, a target is considered out-of-date if any of its sources have been modified more recently than the target. Sources for a target do not accumulate over dependency lines when this operator is used. The target will not be removed if make(1) is interrupted.

Targets and sources can contain the shell wildcard values ?, *, () and {}. The values ?, * and [] can only be used as part of the final component of the target or source, and must be used to describe existing files. The value {} need not necessarily be used to describe existing files. Expansion is in directory order, not in alphabetical order as is done in the shell.

SHELL COMMANDS

Each target can have associated with it a series of shell commands that are normally used to create the target. Each of the commands in this script must be preceded by a tab. While any target can appear on a dependency line, only one of these dependencies can be followed by a creation script, unless the :: operator is used.

If the first or first two characters of the command line are @ and/or -, the command is treated specially. A @ causes the command not to be echoed before it is executed. A - causes any non-zero exit status of the command line to be ignored.

VARIABLE ASSIGNMENTS

Variables in make are much like variables in the shell, and, by tradition, consist of all uppercase letters. The five operators that can be used to assign values to variables are as follows:

=
Assign the value to the variable. Any previous value is overridden.
+=
Append the value to the current value of the variable.
?=
Assign the value to the variable if it is not already defined.
:=
Assign with expansion; that is, expand the value before assigning it to the variable. Normally, expansion is not done until the variable is referenced.
!=
Expand the value, pass it to the shell for execution, and assign the result to the variable. Any newlines in the result are replaced with spaces.

Any white space before the assigned value is removed. If the value is being appended, a single space is inserted between the previous contents of the variable and the appended value.

Variables are expanded by surrounding the variable name with either curly braces ({}) or parenthesis (()) and preceding it with a dollar sign ($). If the variable name contains only a single letter, the surrounding braces or parenthesis are not required. This shorter form is not recommended.

Variable substitution occurs at two distinct times, depending on where the variable is being used. Variables in dependency lines are expanded as the line is read. Variables in shell commands are expanded when the shell command is executed.

The four different classes of variables (in order of increasing precedence) are:

Environment variables
Variables defined as part of the make(1) environment.
Global variables
Variables defined in the makefile or in included makefiles.
Command-line variables
Variables defined as part of the command line.
Local variables
Variables that are defined specific to a certain target. There are seven local variables; they have the highest precedence. They are shown here with the $ prefix.

The seven local variables are as follows:

$>
The list of all sources for this target; also known as .ALLSRC.
.ARCHIVE
The name of the archive file.
$<
The name/path of the source from which the target is to be transformed (the implied source); also known as .IMPSRC. It is evaluated only for inference rules.
$%
The name of the archive member (also known as .MEMBER). This only applies when the current target is an archive library member of the form libname.
$?
The list of sources for this target that were deemed newer than the target; also known as .OODATE.
$*
The file prefix of the file, containing only the file portion, no suffix or preceding directory components; also known as .PREFIX.
$@
The name of the target; also known as .TARGET. When building a library, it evaluates to the name of the library; see $%.

The short forms (@, ?, >, and *) are the ones specified by POSIX; the use of the longer terms is a Berkeley Software Distribution (BSD) extension.

You can modify the @, < and * variables with the letters D or F: D refers to the directory portion of the target name, and F refers to the target portion. For example, for the target /bin/construct, ${@D} is /bin and ${@F} is construct.

Four of the local variables can be used in sources on dependency lines because they expand to the proper value for each target on the line. These variables are @ (or .TARGET), * (or .PREFIX), % (or .MEMBER), and .ARCHIVE.

In addition, make(1) sets or uses the following variables:

$
A single dollar sign $; that is, $$ expands to a single dollar sign.
.MAKE
The name used to execute make(1) (argv[0])
.CURDIR
A path to the directory where make(1) was executed.
.OBJDIR
A path to the directory where the targets are built. At startup, make(1) searches for an alternate directory to place target files and attempts to change into this special directory. In order, make(1) tries to change into the directory named by the environment variable MAKEOBJDIRPREFIX; if it is defined, make(1) tries to build in $(MAKEOBJDIRPREFIX)/cwd. If that is not defined, it tries MAKEOBJDIR; if that fails, it tries to change into the directory named obj.$MACHINE (if the environment variable MACHINE is not set, make(1) calls the uname(3) function to determine the type of the computer). If it still has found no special directory, it tries the directory named obj. Finally, if none of the above directories are available make(1) uses the current directory.
MAKEFLAGS
The environment variable MAKEFLAGS can contain anything that can be specified on make(1) command line. Anything specified on the make(1) command line is appended to the MAKEFLAGS variable, which is then entered into the environment for all programs that make(1) executes.
PWD
An alternate path to the current directory. The make(1) utility normally sets .CURDIR to the canonical path given by getcwd(3). If the environment variable PWD is set and gives a path to the current directory, however, make(1) sets .CURDIR to the value of PWD instead. Setting this variable is most useful on systems that have automounters, where the same directory might have different paths on different computers. The PWD variable is set to the value of .OBJDIR and exported for all programs that make(1) executes.

Variable expansion can be modified to select or modify each word of the variable (where a word is a white-space delimited sequence of characters). The general format of a variable expansion is as follows:

{variable[:modifier[:...]]}

Each modifier begins with a colon and one of the following special characters. The colon can be escaped with a backslash (\).

C/old_pattern/new_pattern/[g]
Modify the first occurrence of old_pattern in each word to be replaced with new_pattern. The old_pattern is a regular expression and the new_pattern is an ed(1)-style replacement string. Usually, the first occurrence of the pattern in each word of the value is changed. The 1 modifier causes substitution to apply to one word at most; the g modifier causes the substitution to apply to as many instances of the search pattern as occur in the word or words in which it is found. The 1 and g modifiers are orthogonal; 1 specifies whether multiple words are potentially affected; g specifies whether multiple substitutions can occur in an affected word. If old_pattern begins with a caret character (^), old_pattern is anchored at the beginning of each word. If old_pattern ends with a dollar sign ($), it is anchored at the end of each word. Any character can be used as a delimiter for the parts of the modifier string. The anchoring, ampersand (&), and delimiter characters can be escaped with a backslash (\).

Variable expansion occurs in the normal fashion inside both old_string and new_string.The single exception is that a backslash is used to prevent the expansion of a dollar sign ($) not a preceding dollar sign as is usual.

E
Replaces each word in the variable with its suffix.
H
Replaces each word in the variable with everything but the last component.
M pattern
Select only those words that match the rest of the modifier. The standard shell wildcard characters *, ?, and []) can be used. The wildcard characters can be escaped with a backslash (\).
N pattern
This is identical to -M, but selects all words that do not match the rest of the modifier.
Q
Quotes every shell metacharacter in the variable so that it can be passed safely through recursive invocations of make(1).
R
Replaces each word in the variable with everything but its suffix.
S/old_pattern/new_pattern/[g]
Modify the first occurrence of old_pattern in each word to be replaced with new_pattern. If a g is appended to the last forward slash(/ of the pattern, all occurrences in each word are replaced. If old_pattern begins with a caret (^), old_pattern is anchored at the beginning of each word. If old_pattern ends with a dollar sign ($), it is anchored at the end of each word. Inside new_string, an ampersand (&) is replaced by old_pattern. Any character can be used as a delimiter for the parts of the modifier string. The anchoring, ampersand (&), and delimiter characters can be escaped with a backslash (\).

Variable expansion occurs in the normal fashion inside both old_string and new_string; the single exception is that a backslash is used to prevent the expansion of a dollar sign ($) not a preceding dollar sign as is usual.

T
Replaces each word in the variable with its last component.
old_string=new_string
This is the AT&T System V-style variable substitution. It must be the last modifier specified. If old_string or new_string do not contain the pattern matching character %, it is assumed that they are anchored at the end of each word, so only suffixes or entire words can be replaced. Otherwise % is the substring of old_string to be replaced in new_string

INCLUDE STATEMENTS, CONDITIONALS, AND FOR LOOPS

Makefile inclusion, conditional structures and for loops similar to the C programming language are provided in make(1). All such structures are identified by a line beginning with a single dot (.) character. Files are included with either:

.include <file>
or
.include file
Variables between the angle brackets (<>) or double quotes (") are expanded to form the file name. If angle brackets (<>)are used, the included makefile is expected to be in the system makefile directory. If double quotes (") are used, the including makefile's directory and any directories specified using the -I option are searched before the system makefile directory.

Conditional expressions are also preceded by a single dot as the first character of a line. The possible conditionals are as follows:

.undef variable
Undefine the specified global variable. Only global variables can be undefined.
.if [!] expression [operator expression ...]
Test the value of an expression.
.ifdef [!] variable [operator variable ...]
Test the value of a variable.
.ifndef [!] variable [ operator variable ...]
Test the value of a variable.
.ifmake [!] target [operator target ...]
Test the target being built.
.ifnmake [!] target [ operator target ... ]
Test the target being built.
.else
Reverse the sense of the last conditional.
.elif [!] expression [ operator expression ...]
A combination of .else followed by .if.
.elifdef [!]variable [ operator variable ...]
A combination of .else followed by .ifdef.
.elifndef [!] variable [ operator variable ...]
A combination of .else followed by .ifndef.
.elifmake [!]target [ operator target ...]
A combination of .else followed by .ifmake.n
.elifnmake [!]target [ operator target ...]
A combination of .else followed by .ifnmake.
.endif
End the body of the conditional.

The operator can be any one of the following:

||
Logical OR.
&&
Logical AND; of higher precedence than "".

As in C, make(1) will only evaluate a conditional as far as is necessary to determine its value. Parentheses can be used to change the order of evaluation. The boolean operator ! can be used to logically negate an entire conditional. It is of higher precedence than &&.

The value of expression can be any of the following:

defined
Takes a variable name as an argument and evaluates to true if the variable has been defined.
make
Takes a target name as an argument and evaluates to true if the target was specified as part of the make(1) command line, or was declared the default target (either implicitly or explicitly, see .MAIN) before the line containing the conditional.
empty
Takes a variable, with possible modifiers, and evaluates to true if the expansion of the variable would result in an empty string.
exists
Takes a file name as an argument and evaluates to true if the file exists. The file is searched for on the system search path (see .PATH).
target
Takes a target name as an argument and evaluates to true if the target has been defined.

Expression can also be an arithmetic or string comparison. Variable expansion is performed on both sides of the comparison, after which the integral values are compared. A value is interpreted as hexadecimal if it is preceded by 0x; otherwise, it is decimal. Octal numbers are not supported. The standard C relational operators are all supported. If after variable expansion, either the left or right hand side of a == or != operator is not an integral value, string comparison is performed between the expanded variables. If no relational operator is given, it is assumed that the expanded variable is being compared against 0.

When make(1) is evaluating one of these conditional expressions, and it encounters a word it does not recognize, either the make or defined expression is applied to it, depending on the form of the conditional. If the form is .ifdef or .ifndef, the defined expression is applied. Similarly, if the form is .ifmake or .ifnmake, the make expression is applied.

If the conditional evaluates to true, the parsing of the makefile continues as before. If it evaluates to false, the following lines are skipped. In both cases this continues until a .else or .endif is found.

For loops are typically used to apply a set of rules to a list of files. The syntax of a for loop is:

.for variable in expression
<make-rules>
.endfor
After the for expression is evaluated, it is split into words. The iteration variable is successively set to each word, and substituted in the make-rules inside the body of the for loop.

COMMENTS

Comments begin with a hash character (#) anywhere but in a shell command line, and continue to the end of the line.

SPECIAL SOURCES

.IGNORE
Ignore any errors from the commands associated with this target, exactly as if they all were preceded by a dash (-)
.MADE
Mark all sources of this target as being up-to-date.
.MAKE
Execute the commands associated with this target even if the -n or -t options were specified. Usually used to mark recursive occurrences of make(1).
.NOTMAIN
Usually, make(1) selects the first target it encounters as the default target to be built if no target was specified. This source prevents this target from being selected.
.OPTIONAL
If a target is marked with this attribute and make(1) cannot figure out how to create it, it will ignore this fact and assume the file either is not needed or already exists.
.PRECIOUS
When make(1) is interrupted, it removes any partially made targets. This source prevents the target from being removed.
.SILENT
Do not echo any of the commands associated with this target, exactly as if they all were preceded by an at sign (@).
.USE
Turn the target into the make(1) version of a macro. When the target is used as a source for another target, the other target acquires the commands, sources, and attributes (except for .USE) of the source. If the target already has commands, the .USE target's commands are appended to them.
.WAIT
If special .WAIT source appears in a dependency line, the sources that precede it are made before the sources that succeed it in the line. Loops are not detected except that targets that form loops are silently ignored.

SPECIAL TARGETS

Special targets cannot be included with other targets; that is, they must be the only target specified.

.BEGIN
Any command lines attached to this target are executed before anything else is done.
.DEFAULT
This is sort of a .USE rule for any target (that was used only as a source) that make(1) cannot figure out any other way to create. Only the shell script is used. The .IMPSRC variable of a target that inherits the .DEFAULT commands is set to the target's own name.
.END
Any command lines attached to this target are executed after everything else is done.
.IGNORE
Mark each of the sources with the .IGNORE attribute. If no sources are specified, this is the equivalent of specifying the -i option.
.INTERRUPT
If make(1) is interrupted, the commands for this target will be executed.
.MAIN
If no target is specified when make(1) is invoked, this target will be built.
.MAKEFLAGS
This target provides a way to specify flags for make(1) when the makefile is used. The flags are as if typed to the shell, though the -f option will have no effect.
.ORDER
The named targets are made in sequence.
.PATH
The sources are directories that are to be searched for files not found in the current directory. If no sources are specified, any previously specified directories are deleted.
.PHONY
Named sources have the .PHONY attribute. These targets are always considered to be out of date.
.PRECIOUS
Apply the .PRECIOUS attribute to any specified sources. If no sources are specified, the .PRECIOUS attribute is applied to every target in the file.
.SILENT
Apply the .SILENT attribute to any specified sources. If no sources are specified, the .SILENT attribute is applied to every command in the file.
.SUFFIXES
Each source specifies a suffix to make(1). If no sources are specified, any previous specified suffices are deleted.

ENVIRONMENT VARIABLES

The make(1) program utilizes the following environment variables, if they exist:

MACHINE
The name of the machine. Used by the .OBJDIR variable. If not specified, the machine type returned by uname(3) is used.
MAKE
Can contain command-line options. This is historical for the Berkeley Software Distribution (BSD) make, and does not exist in the POSIX-conformant version of the utility.
MAKEFLAGS
Can contain anything that can be specified on the make(1) command line. Anything specified on the make(1) command line is appended to the MAKEFLAGS variable, which is then entered into the environment for all programs that make(1) executes.

There are two possible formats for the string stored in MAKEFLAGS: The first is identical to the command-line (options preceded by hyphens and separated by blank characters). The second is useful only if there are no arguments to the options, and consists of option letters without leading hyphens or blank character separators.

The difference between the command line and the MAKEFLAGS variable is that the contents of the environment variable are not expanded by the shell.

MAKEOBJDIR
A path to the directory where the targets are built.
MAKEOBJDIRPREFIX
A path to the directory where the targets are built. The directory $(MAKEOBJDIRPREFIX)/csd is the first directory in which make(1) tries to build.
MAKESTARTUP
A path to a startup file that is used instead of the system startup file, /usr/share/mk/sys.mk.
PWD
An alternate path to the current directory. If set, this value will be used to define the value of the .CURDIR variable.

FILES

The make(1) utility uses the following files:

.depend
List of dependencies; created by the mkdep utility (not included in the Interix Software Development Kit). If this file exists, it is read.
Makefile
List of dependencies and recipes; this is read only if makefile does not exist in the current directory.
makefile
List of dependencies and recipes; used in preference to Makefile.
sys.mk
System makefile; not read if -r is specified. The directory containing the system makefile can be specified with the -I option.
/usr/share/mk
System makefile directory. The root of the path depends upon where the Interix distribution is installed. The directory containing the system makefile can be specified with the -I option.