Maintains, updates, and regenerates groups of programs.
make [ -DVariable ] [ -d Option] ] [ -e ] [ -i ] [ -k ] [ -n ] [ -p ] [ -q ] [ -r ] [ -S ] [ -s ] [ -t ] [ -f MakeFile ... ] [ Target ... ]
The make command assists you in maintaining a set of programs. Input to the make command is a list of file dependency specifications.
There are four types of lines in a makefile: file dependency specifications, shell commands, variable assignments, 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.
Dependency lines consist of one or more targets, an operator, and zero or more prerequisites (sources). This creates a relationship where the targets depend on the prerequisites and are usually created from them. The exact relationship between the target and the prerequisite is determined by the operator that separates them. The operators are as follows:
File dependency specifications have two types of rules, inference and target. Inference rules specify how a target is to be made up-to-date. These rules have one target with no / (slash) and a minimum of one . (period). Target rules specify how to build the target. These rules can have more than one target.
The make command executes the commands in the makefile line by line. As make executes each command, it writes the command to standard output (unless otherwise directed, for example, using the -s flag). A makefile must have a tab in front of the commands on each line.
When a command is executed through the make command, it uses make's execution environment. This includes any macros from the command line to the make command and any environment variables specified in the MAKEFLAGS variable. The make command's environment variables overwrite any variables of the same name in the existing environment.
Note: When the make command encounters a line beginning with the word include followed by another word that is the name of a makefile (for example, include depend), the make command attempts to open that file and process its contents as if the contents appeared where the include line occurs. This behavior occurs only if the first noncomment line of the first makefile read by the make command is not the .POSIX target; otherwise, a syntax error occurs.Comments: Comments begin with a # (number sign), anywhere but in a shell command line, and continue to the end of the line.
Environment: The make command uses the MAKEFLAGS environment variable, if it exists.
Target rules have the following format:
target[target...] : [prerequisite...] [;command] <Tab>command
Multiple targets and prerequisites are separated by spaces. Any text that follows the ; (semicolon) and all of the subsequent lines that begin with a tab character are considered commands to be used to update the target. A new target entry is started when a new line does not begin with a tab character or # (number sign).
Note: The list of prerequisites can be empty.
Special targets cannot be included with other targets; that is, they must be the only target specified. These targets control the operation of the make command. These targets are:
The make command has a default set of inference rules, which you can supplement or overwrite with additional inference rules definitions in the makefile. The default rules are stored in the external file, /usr/ccs/lib/aix.mk. You can substitute your own rules file by setting the MAKERULES variable to your own file name from the command line. The following line shows how to change the rules file from the command line:
make MAKERULES=/pathname/filename
Inference rules consist of target suffixes and commands. From the suffixes, the make command determines the prerequisites, and from both the suffixes and their prerequisites, the make command determines how to make a target up-to-date. Inference rules have the following format:
rule: <Tab>command ...
where rule has one of the following forms:
The .s1 and .s2 suffixes are defined as prerequisites of the special target, .SUFFIXES. The suffixes .s1 and .s2 must be known suffixes at the time the inference rule appears in the makefile. The inference rules use the suffixes in the order in which they are specified in .SUFFIXES. A new inference rule is started when a new line does not begin with a <Tab> or # (number sign).
If rule is empty, for example:
rule: ;
execution has no effect, and the make command recognizes that the suffix exists, but takes no actions when targets are out-of-date.
A ~ (tilde) in the preceding rules refers to an SCCS file. Therefore, the rule, .c~.o, would transform an SCCS C language prerequisite file into an object file (.o). Because the s. of the SCCS file is a prefix, it is incompatible with the make command's suffix view. The ~ (tilde) is a way of changing any file reference into an SCCS file reference.
A target or prerequisite can also be a member of an archive library and is treated as such if there are parentheses in the name. For example, library(name) indicates that name is a member of the archive library library. To update a member of a library from a particular file, you can use the format .s1.a, where a file with the .s1 suffix is used to update a member of the archive library. The .a refers to an archive library.
In makefiles, macro definitions are defined in the format:
variable=value
Macros can appear throughout the makefile, as follows:
If a macro has no definition, it defaults to NULL. A new macro definition overwrites an existing macro of the same name. Macros assignments can come from the following, in the listed order:
Note: The -e flag causes environment variables to override those defined in the makefile.
The SHELL macro is special. It is set by the make command to the path name of the shell command interpreter (/usr/bin/sh). However, if it is redefined in the makefile or on the command line, this default setting is overridden.
Note: The SHELL macro does not affect, and is not affected by, the SHELL environment variable.
Each target can have associated with it a series of shell commands, 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 one or all of @, -, and +, the command is treated specially, as follows:
A command that has no metacharacters is directly executed by the make command. For example, the make command consigns the first command in the following example to the shell because it contains the > (greater than sign) shell metacharacter. The second command in the following example does not contain any shell metacharacters, so the make command executes it directly:
target: dependency cat dependency > target chmod a+x target
Bypassing the shell saves time, but it can cause problems. For example, attempting to execute a C shell script from within a makefile by setting the SHELL macro to /bin/csh will not work unless the command line also contains at least one shell metacharacter.
SHELL=/bin/csh target: dependency my_csh_script
This makefile fails because the make command attempts to run my_csh_script instead of consigning it to the C shell.
Variables in the make command are much like variables in the shell and consist of all uppercase letters. The = operator assigns values to variables. Any previous variable is then overridden.
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 expended by surrounding the variable name with either { } (braces) or ( ) (parentheses) and preceding it with a $ (dollar sign). If the variable name contains only a single letter, the surrounding braces or parentheses 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 classes of variables (in order of increasing precedence) are:
-DVariable | Sets the value of Variable to 1. | ||||||||||||||||
-dOption | Displays detailed information about the files and times that make examines (debug mode). The -d flag without any options or with the A option displays all the debug information available. Individually selectable debug options follow:
| ||||||||||||||||
-e | Specifies that environmental variables override macro assignments within makefiles. | ||||||||||||||||
-f MakeFile | Specifies a makefile to read instead of the default makefile. If MakeFile is - (dash), standard input is read. Multiple makefiles can be specified and are read in the order specified. | ||||||||||||||||
-i | Ignores nonzero exit of shell commands in the makefile. Equivalent to specifying - (dash) before each command line in the makefile. | ||||||||||||||||
-k | Continues processing after errors are encountered, but only on those targets that do not depend on the target whose creation caused the error. | ||||||||||||||||
-n | Displays commands, but does not run them. However, lines beginning with a + (plus sign) are executed. | ||||||||||||||||
-p | Displays the complete set of macro definitions and target descriptions before performing any commands. | ||||||||||||||||
-q | Returns a zero status code if the target file is up-to-date; returns a one status code if the target file is not up-to-date. However, a command line with the + (plus sign) prefix will be executed. | ||||||||||||||||
-r | Does not use the default rules. | ||||||||||||||||
-S | Terminates the make command if an error occurs. This is the default and the opposite of -k flag. | ||||||||||||||||
-s | Does not display commands on the screen as they are performed. | ||||||||||||||||
-t | Creates a target or updates its modification time to make it appear up-to-date. Executes command lines beginning with a + (plus) sign. | ||||||||||||||||
Target | Specifies a target name of the form Target or sets the value of variables. |
When the -q flag is specified, this command returns the following exit values:
0 | Successful completion. |
1 | The target was not up-to-date. |
>1 | An error occurred. |
Otherwise, this command returns the following exit values:
0 | Successful completion. |
>1 | An error occurred. |
make
make -n search.oYou may want to do this to verify that a new description file is correct before using it.
pgm: a.o b.o c89 a.o b.o -o pgm a.o: incl.h a.c c89 -c a.c b.o: incl.h b.c c89 -c b.c
.c.o: c89 -c -o $*.c or: .c.o: c89 -c -o $<
make -p -f /dev/null 2>/dev/null
makefile | Contains a list of dependencies. |
Makefile | Contains a list of dependencies. |
s.makefile | Contains a list of dependencies. It is an SCCS file. |
s.Makefile | Contains a list of dependencies. It is an SCCS file. |
/usr/ccs/lib/posix.mk | Contains default POSIX rules for the make command. |
/usr/ccs/lib/aix.mk | Contains default rules for the make command. |
The sh command.
The make Command Overview in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.
The Commands Overview in AIX Version 4.3 System User's Guide: Operating System and Devices.