make Command Purpose Maintains up-to-date versions of programs. Syntax make [ -d ] [ -e ] [ -i ] [ -k ] [ -n ] [ -p ] [ -q ] [ -r ] [ -S ] [ -s ] [ -t ] [ -f MakeFile ... ] [ TargetFile ... ] Description The make command reads MakeFile for information about the speci- fied TargetFiles and for the commands necessary to update them. The make command does not change the TargetFile if you have not changed any of the source files since you last built it. It con- siders a missing file to be a changed file (out-of-date). You can also include macro definitions on the command line after all of the flags. Macro definitions have the form: macro-name = string The make command considers all entries on the command line that follow the flags and that do not contain an equal sign to be tar- get file names. The default shell is determined by: * The MAKESHELL environment variable, if defined. (BSD users should set this to /usr/bin/sh.) * If MAKESHELL is undefined, the program uses the value of SHELL that you set from the description file or the command line. Note that a SHELL set from the environment is always ignored. * If MAKESHELL and SHELL are undefined, the program uses the de- fault value /usr/bin/sh. The make command stores its default rules in the external file /usr/ccs/lib/make.cfg. The /usr/ccs/lib/make.cfg file is a con- figuration file that contains default rules for the make command. These defaults may be overriden in the user Makefile. You may substitute your own rules file by setting the MAKERULES variable to your own file name from the command line. The fol- lowing lines show how to change the rules file from the command line: make MAKERULES=/pathname/filename For more information, see the make Command Overview in AIX Ver- sion 3.2 General Programming Concepts. Description File The make command searches the current directory for the first description file it finds that is named makefile, Makefile, s.makefile, or s.Makefile, in that order. The -f option may be used to override this naming convention. The description file contains a sequence of entries specifying the files that the target files depend on. The general form of an entry is: target [target] . . . :[:] [File] . . . [`shell command expression`]. . . [;Command] [(tab)Command] The first line of an entry (called the dependency line), contains a list of targets followed by a : (colon) and an optional list of prerequisite files or dependencies or shell command expressions, which are commands enclosed in single backquotes (`) whose output is treated as dependencies. If you put shell commands on the dependency line, they must be preceded by a ; (semicolon). All commands that follow the semicolon and all following lines that begin with a tab contain shell commands that the make command uses to build the target. The VPATH variable is set with a list of directory path names separated by a : (colon). The make command uses VPATH to search for a dependency-related file within these directories. If this macro is defined, then these directories are searched. If this macro is not defined or just defined with a . (dot), only the current directory is searched. The default for VPATH is not de- fined. To specify more than one set of commands for a TargetFile, you must enter more than one dependency definition. In this case, each definition must have the TargetFile name followed by two colons (::), a dependency list, and a command list. A # (pound sign) is used to put comments in a description file. All characters following a # and continuing to the end of the line are considered to be part of the comment. Comments may be specified on individual lines as well as on dependency lines and command lines in the description file. The description file can contain blank lines, which will be ignored by the make program. However, no blank lines are allowed in a continued list. The first line that does not begin with a tab or # (pound sign) begins a new dependency or a macro definition. Command lines are performed one at time, each by its own subshell. Thus, the ef- fect of some shell commands, such as cd, does not extend across new-line characters. You can, however, put a \ (backslash) at the end of a line to continue it on the next physical line. Commands are executed by passing the command line to the command interpreter. If commands are executed in the background, the make command does not wait for the termination of the background processes before it exits. The first one through three characters in a command can be one of the following special characters: - Ignores errors returned by the command on this line. @ Does not display this command line. + Executes this command line even if -n, -q or -t is specified. Suffix Rules The make command has default rules that govern the building of most standard files. These rules depend on the standard suffixes used by the system utility programs to identify file types. These rules define the starting and ending file types so that, for example, given a specified .o file, the make command can infer the existence of a corresponding .c file and knows to com- pile it using the cc -c command. A rule with only one suffix (that is, .c:) defines the building of prog from all its source files. Use a \~ (tilde) in the suf- fix to indicate an SCCS file. For example, the .c\~.o rule governs changing an SCCS C source file into an object file. You can define rules within the description file. The make command recognizes as a rule any target that contains no slashes and starts with a dot. You can also add suffixes to the list of suffixes recognized by the make command and add to the default dependency rules. Use the target name .SUFFIXES followed by the suffixes you want to add. Be careful of the order in which you list the suffixes. The make command uses the first possible name for which both a file and a rule exist. The default list is: .SUFFIXES: .o .c .c\~ .f .f\~ .y .y\~ .l .l\~ .s .s\~ .sh .sh\~ .h .h\~ .a You can clear the list of suffixes by including .SUFFIXES: with no following list. Special Target Names You can use some special target names in the description file to tell the make command to process the file in a different manner. These are: .DEFAULT The commands that appear after this name in the descrip- tion file tell the make command what to do if it can find no com- mands or default rules to tell it how to create a specific file. .IGNORE If this name appears on a line by itself, the make command does not stop when errors occur. If this has prere- quisites, the make command ignores errors associated with them. Using a - (minus) as the first character on a command line in the description file tells the make command to ignore errors for the command on that line only. .POSIX The make command processes the makefile as specified by the POSIX standard. .PRECIOUS The files named on the same line as this special name are not removed when the make command is interrupted. If no file names are specified, all files are treated as if specified with .PRECIOUS. .SILENT If this name appears on a line by itself, the make command does not display any of the commands that it performs to build a file. If this has prerequisites, the make command does not display any of the commands associated with them. .SUFFIXES Use this name to add more suffixes to the list of file suffixes that make recognizes. Environment When you run the make command, it reads the environment and treats all variables as macro definitions. The make command processes macro definitions in the following order: 1. The make command's own default rules 2. Environment variables 3. Description files 4. Command line. Therefore, macro assignments in a description file normally over- ride duplicate environment variables. The -e flag instructs the make command to use the environment variables instead of the description file macro assignments. The make command recognizes the MAKEFLAGS and MFLAGS environment macros, which the user can set only as environment variable mac- ros that can be assigned any make flag value except -f, -p, and -d. The make command uses the value of MFLAGS only if the MAKEFLAGS macro is not defined. When the make program starts, it invokes itself with the options specified with these environment variables, if defined, in addition to those specified on the com- mand line. It passes these options to any command it invokes, including additional invocations of the make command itself. Thus you can perform a make -n recursively on a software system to see what would have been performed. The -n is passed to further copies of the shell that runs the next level of make com- mands. In this way, you can check all of the description files for a software project without actually compiling the project. Macros Entries of the form String1 = String2 are macro definitions. String2 consists of all characters that occur on a line before a comment character (#) or before a new-line character that is not a continuation line. After this macro definition, the make com- mand replaces each $(String1) in the file with String2. The make command also handles nested macro names, in the form of $($(String1)). Where the innermost macro name is expanded, then its value is taken as another macro name that must also be ex- panded. Ten levels of nesting for macro expansion is supported. You do not have to use the parentheses around the macro name if the macro name is only one character long and there is no substi- tute sequence (see the next paragraph). If you use the following form, you can also replace characters in the macro string with other characters for one time that you use the macro: $(String1[:Substitute1=[Substitute2]]) The optional :Substitute1 = Substitute2 specifies a substitute sequence. If you specify a substitute sequence, the make program replaces each Substitute1 pattern in the named macro with Substi- tute2 (if Substitute1 is a suffix in String1). Strings in a substitute sequence begin and end with any of the following: a blank, tab, new-line character, or beginning of line. Note: Because the make command uses the dollar sign symbol ($) to designate a macro, do not use that symbol in filenames of targets and parents, or in commands in the description file unless you are using a defined make macro. Internal Macros The make command has five internal macros. It assigns values to these macros under one or more of the following conditions: * When it uses an internal rule to build a file * When it uses a .DEFAULT rule to build a file * When it uses rules in the description file to build a file * When the file is a library member. The five internal macors are defined as follows: $* The file name (without the suffix) of the source file. $@ The full target name of the current target. $< The source files of an out-of-date module. The make command evaluates this macro when applying inference rules or the .DEFAULT rule. For example: .c.o: cc -c $< Here, $< refers to the .c file of any out-of-date .o file. $? The list of out-of-date files. The make command evaluates this macro when it evaluates explicit rules from MakeFile. $% The name of an archive library member. The make command evaluates this macro only if 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. You can add an uppercase D or F to indicate "directory part" or "file part", respectively, to all internal macros except for $?. Thus, $(@D) refers to the directory part of the name $@. If there is no directory part, the make command uses ./. The $$ symbol is the dollar sign in a description file. A single $ is interpreted by the make command as a macro to be evaluated, as in the above definitions. Libraries If a target name contains parentheses, the make command considers it an archive library. The string within parentheses refers to a library member. Thus, lib(File.o) and $(LIB)(File.o) both see an archive library which contains File.o. (You must have already defined the LIB macro.) The expression $(LIB) + (File1.o File2.o) is not legal. Rules that apply to archive libraries have the form .x.a, where .x is the suffix of the file you want to add to an archive li- brary. For example, .c.a indicates a rule that changes any C source file to a library file member. For the following descrip- tion file entry: lib: lib(file1.o) lib(file2.o) lib(file3.o) @echo lib is now up to date. The default rule used by the make command is: .c.a: $(CC) -c $(CFLAGS) $< ar rv $@ $*.o rm -f $*.o Note: The .x suffix must be different from the suffix of the ar- chive member. Another, but more limited, example of an archive library mainte- nance rule follows: lib: lib(file1.o) lib(file2.o) lib(file3.o) $(CC) -c $(CFLAGS) $(?:.o=.c) ar rv lib $? rm $? @echo lib is now up to date .c.a:; This example rule uses a substitute sequence (.o=.c) to replace with .c files all .o files generated by the $? macro. The $? list is the set of object file names (inside lib)with C source files that are out of date. The macro substitution translates .o to .c. If this rule appears in your description file, it disables the default .c.a: rule, which creates each object file one by one. This type of organization speeds up archive library maintenance, but becomes hard to use if the archive library contains a variety of source programs, for example, assembly and C programs. Flags -d Displays detailed information about the files and times that make examines (debug mode). -e Uses environment variables in place of any assignments made within description files. These assignments normally replace en- vironment variables. -f MakeFile Reads MakeFile for a description of how to build the target file. If you give only a - (minus sign) for MakeFile, the make command reads standard input. If you do not use the -f flag, the make command searches the current directory for the first description file named makefile, Makefile, s.makefile, or s.Makefile, in that order. You can specify more than one description file by entering the -f flag more than once (with its associated MakeFile parameter). -i Ignores error codes returned by commands. The make command normally stops if a command returns a nonzero code. Use this flag to compile several modules only if you want the make command to continue when an error occurs in one of the modules. -k Stops processing the current target if an error occurs, but continues with other branches that do not depend on that target. -n Displays commands, but does not run them. However, lines be- ginning with a + (plus sign) are executed. Displays lines begin- ning with an @ (at sign). If the special target .POSIX is not specified and the command in the description file contains the string $(MAKE), perform another call to the make command. Use this flag to preview the performance of the make command. -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 lines with the + (plus sign) prefix will be executed. -r Does not use the default rules. Uses only rules specified in the description file. -S Terminates the make command if an error occurs. This is the default and the opposite of -k flag. If the -k and -S flags are both specified, the last one evaluated works. -s Does not display commands or touch messages on the screen as they are performed. -t Changes only the date of the files, rather than performing the listed commands. Use this flag if you have made only minor changes to a source file that do not affect anything outside of that file. This flag changes the date of all target files that appear on the command line or in the description file. However, command lines beginning with a + (plus sign) are executed. Exit Status 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. >0 An error occurred. Examples 1. To make the file specified by the first entry in the descrip- tion file: make 2. To display, but not run, the commands that the make command would use to make a file: make -n search.o You may want to do this to verify that a new description file is correct before using it. Files makefile Contains make command description rules. Makefile Contains make command description rules. s.makefile Contains make command description rules. s.Makefile Contains make command description rules. /usr/ccs/lib/make.cfg Contains make command default rules. These defaults can be overridden in the user Makefile. Implementation Specifics This command is part of Application Development Toolkit in Base Application Development Toolkit. The make command works with any interactive language, but re- quires the installation of the desired language-specific transla- tors and interpreters. Related Information The sh command. The make Command Overview in AIX Version 3.2 General Programming Concepts. The Commands Overview in AIX Version 3.2 System User's Guide: Base and Devices.