MAKE(1) COMMAND REFERENCE MAKE(1) NAME make - build files and programs SYNOPSIS make [ -B ] [ -N ] [ -R ] [ -S ] [ -Y ] [ -d ] [ -e ] [ -f makefile ] [ -g ] [ -i ] [ -k ] [ -l ] [ -m ] [ -n ] [ -p ] [ -q ] [ -r ] [ -s ] [ -t ] [ macro definitions ] [ target ... ] DESCRIPTION Make is a program for maintaining programs. It looks at the last modification date of files to determine the actions it is to perform in order to make sure that the target is up to date. This document briefly describes the syntax of the rules and how they work. A more detailed description is available in the document Using Make. Rules Make uses special rules in order to decide what commands it must execute. There are two types of rules that make uses: target rules and suffix rules. Target rules have the following form: target :[:] [dependents] <separator> [commands] The target and the dependents may each be one or more valid file names, except that spaces and tabs are not allowed. Target names beginning with '.' are treated specially and should not be used, since make thinks that they are special entries. The separator may either be a semicolon, or a newline and a tab. The rule itself specifies that the files in target may be made up to date by executing the commands. The dependents are the names of the files or targets that must be up to date before the commands are executed. The double colon (::) has a special meaning to make. There may be more than one rule for targets if this is used, and each rule is used in order. The first rule for the target must be finished before all others are checked. This is especially useful for maintaining archive files (again, see the document Using Make). Suffix rules have the following form: <suffix1><suffix2>: <separator> [commands] suffix1 is a non-null file name suffix, like .c or ,v which may begin with a period, but may not contain any other periods. suffix2 may be null (see CAVEATS), but must begin with a period if it is not. The separator may either be a Printed 4/6/89 1
MAKE(1) COMMAND REFERENCE MAKE(1) semicolon or a newline and a tab. See the next section for the description of command syntax. The rule itself specifies that if a file ending with suffix1 exists and has the same root (everything but the suffix) as a file or target name ending with suffix2, then the given commands will make the latter file up to date. Special Characters in Rules The dependency line has some constraints. The characters ':', '>', '&', '|', space, and tab may not appear in file names unless the characters are preceded by the character '\'. Because of this added ability to have special characters in file names, all default suffix rules put file names in quotes. It is a good idea to do this with suffix rules defined in the makefile as well. See the document Using Make for more information on this subject. Command Syntax The commands mentioned in the above section are commands executed by sh(1sh), unless the special entry .CSHELL is placed in the makefile. Before executing the commands, all words beginning with the character '$' are expanded as macros (see the Macros section). The commands are then executed by sh. If the command exits with a nonzero status, make will normally stop. This can be turned off globally by the -i flag or the .IGNORE entry (see the OPTIONS and Special Entries sections). Nonzero exit status can be ignored for a single command by preceding the command with the character '-'. Normally, make prints each command before it is executed. The -s option and the .SILENT entry turn this off globally. Commands preceded by the character '@' are not printed. In order to speed things up, make looks at the command line after macros have been expanded to see whether it can directly execute the command, instead of having the shell execute it. This means that shell commands like times and cd will be executed directly by make so that the shell built-in command is not executed. In most cases, this is not a problem, since each command line is executed separately. For example, the target rule: target : cd .. make all will cause the error message: Printed 4/6/89 2
MAKE(1) COMMAND REFERENCE MAKE(1) make : cd : No such file or directory to be printed. This error message is misleading, because the real error is that the second line should be cd ..;\ so that make executes the command 'sh -ce cd ..;make all'. It is not worth the effort to have make recognize all of the built-in shell commands. Rules Files Make reads rules from a file called a 'makefile'. The default makefiles are named makefile and Makefile. The -f option can be used to specify an alternate file. The first step make takes is to make sure that the default makefiles are up to date if they are being used. In order to do this, make has a special set of built-in rules. Also, the file /usr/lib/mfrules is read for system-wide rules. If the file $HOME/.mfilerc exists, it is read for additional rules. The environment variable MFRULES can be set to the name of a file to use instead of $HOME/.mfilerc. Because of this action, makefiles can be stored under RCS and do not have to be present when make is invoked. This action can be turned off with the -m option and is not performed if the -f option is given. The -n and -N flags are ignored during this step, so the makefile is always made up to date. There is a set of built-in rules which make uses. Because of these rules, there does not have to be a makefile available. In addition to these rules, the files /usr/lib/makerules and $HOME/.makerc (which can be changed by setting the MAKERULES environment variable) are read. The use of each of these files can be selectively turned off by the -r, -B, -Y, and -R options (see the OPTIONS section). The complete set of default rules and macro definitions is available by executing the command: make -pfn /dev/null 2>/dev/null (The 2>/dev/null sends the error message that is printed due to the absence of a target to /dev/null.) Invocation Make needs to know what it is supposed to be making. If there is no makefile, the target must be specified on the command line. In this case, only implicit rules are used. This is useful for creating programs from a single source file. If there is a makefile, the target may be specified on the command line. If no target is specified, the first target name found in the makefile that does not begin with a period is used. Many makefiles have a target rule for 'all' Printed 4/6/89 3
MAKE(1) COMMAND REFERENCE MAKE(1) as the first target rule. This target usually depends on the program or programs that the makefile is being used for. In this way, executing make with no arguments implies make all. More than one target may be specified. Each target is made up to date in the order they are given. If an error occurs while making a target, make stops, unless the -k option is given. Options are first taken from the command line and then from the environment variable MAKEFLAGS. If the -e option is given on the command line, the MAKEFLAGS variable is ignored. The flags -e and -f are not allowed in the MAKEFLAGS variable. The variable may contain spaces and '-' characters for readability, but these are ignored by make. All options given to make except for the -f are stored in the special macro MFLAGS. Because of this, the makefile can contain a command like: $(MAKE) $(MFLAGS) clean and flags given to the top level command will be given to lower level invocations. The maximum number of options which may be given to make is 100. If more are given, an error message is printed and execution terminates. Directory Searching Make always looks in the current directory for files. The special entry .DIRECTORIES contains a list of other directories to look in for files. This is especially useful when source files are kept in an RCS directory or when programs share source. The default list of directories contains only ./RCS. This, coupled with the default suffix rule for .c,v.c, means that the file file.c implicitly depends on the file ./RCS/file.c,v. Directory searching is not done in cases where explicit dependencies are specified or with names containing the slash character (/) or beginning with the character '.'. Macros Make has a form of macro substitution. A macro definition is of the form "NAME=text". These may be specified in any rules file or on the command line. Any occurence of $(NAME) or ${NAME} found in the makefile is expanded to the text. Single letter macro names do not need the parentheses or braces. If a macro is defined multiply in a file, the last definition is the only one that is stored. Printed 4/6/89 4
MAKE(1) COMMAND REFERENCE MAKE(1) Make also has a set of special macros. These are: Macro Expands to $$ the character '$' $MAKE the name of the make program being executed (this is normally make) $MFLAGS the flags given to this invocation of make $@ the full name of the current target $< the name of the file which caused the implicit rule to be used $? the list of dependencies which were out of date (explicit rules only) $* the root of the target name $% the name of the member of the current archive file (only set for archive dependencies) There are three modifiers for the last five special macros given. The form $(macroD) expands to the directory names of each element of the expanded macro, if there is one. The form $(macroF) expands to the basename of the file names in the expanded macro. The form $(macro:from=to) expands to the names of each element in the macro, replacing occurrences of the from text which appear at the end of words with the to string. For example, if $? has the value file1.o file2.o file3.o , $(?:.o=.c) will expand to file1.c file2.c file3.c. Special Entries There are some special entries which can be placed in the makefile to set options and specify data. The form of these entries is NAME : [data]. These entries are: Name Result .IGNORE Nonzero exit statuses are ignored. (Same as the -i option.) .SILENT Supresses printing of commands. (Same as the -s option.) .DEBUG Print debugging output. (Same as the -d option.) .GRAPH Print a dependency list graph. (Same as the -g Printed 4/6/89 5
MAKE(1) COMMAND REFERENCE MAKE(1) option.) .CONTINUE On nonzero status, stop processing the current target, but continue with targets that do not depend on the current target. (Same as the -k option.) .PRINT Print information about commands, targets, macros, and other makefile entries. (Same as the -p option.) .DEFAULT When a target can not be made up to date or made to exist, the commands described by the .DEFAULT entry are executed. A typical use of this entry is to get SCCS files, since this version of make does not support SCCS files. .PRECIOUS Don't delete the file being built if fatal error occurs. This entry requires a list of filenames as data. .SUFFIXES With no data, the suffix list is set to null. With a list of suffixes as data, the suffixes are added to the current suffix list. Unless the -l option is given, the special suffix .NULL is replaced in the list by the null string. This is used in suffix rules where the second suffix is null. .DIRECTORIES With no data, the directory list is set to null. With a list of directories as data, the directories are added to the directory list. .CSHELL Normally, commands that must be executed by a shell are executed by /bin/sh. If this entry is in the makefile, commands are executed by /bin/csh with the -f option (meaning that the file .cshrc is not read). This also causes the character `~' to be special. This should only be used by experts. Makefile Formats The makefiles may contain comments as well as rules and macro definitions. The character '#' denotes that the rest of the current line is a comment. All words separated by spaces are taken to be distinct words. For this reason, the entry "my file", which is a valid filename to sh is separated into the word my and the word " file" instead of being treated as a single name. Printed 4/6/89 6
MAKE(1) COMMAND REFERENCE MAKE(1) If a line ends with a backslash (\), the newline and all tabs, spaces, and newlines following it are ignored. This is useful for maintaining very long macros and for formatting commands for readability. This can also be dangerous, since this feature is not turned off inside of comments. OPTIONS -B Do not read the built-in default rules. -N Trace and print, but do not execute the commands needed to update the targets, unless the word '$(MAKE)' or '${MAKE}' appears in the command line. This enables the user to trace multi-level makefiles. -R Do not read the personal default rules file. -S Stop after any command fails. -Y Do not read the system default rules file. -d Print debugging output. See the document Using Make for an explanation of the output. -e Do not read the MAKEFLAGS environment variable. -f filename Specifies a different makefile than makefile or Makefile -g Print a dependency list. The dependencies for each file are indented over four spaces. -i Ignore nonzero exit status. This is equivalent to the special entry .IGNORE. -k When a command returns nonzero status, abandon work on the current entry, but continue on branches that do not depend on the current entry. -l Remove the null suffix from the suffix list. -m Do not try to make the makefiles up to date. -n Trace and print, but do not execute the commands needed to update the targets. -p Print a listing containing information about all rules, macros, special entries and dependencies. -q If the target is up to date, exit with status 0. Otherwise, exit with status -1. -r Don't use the built-in rules and don't read the system or Printed 4/6/89 7
MAKE(1) COMMAND REFERENCE MAKE(1) personal rules files. This is equivalent to the flags -BYR. -s Equivalent to the special entry `.SILENT:'. -t Touch, i.e. update the modified date of targets, without executing any commands. EXAMPLES This example builds a program called 'put' from the source file 'put.c'. No makefile exists. make put This example makes the program 'get' from the files 'get.c' and 'subs.c', both of which require the include file 'subs.h'. The makefile looks like: get : get.o subs.o $(CC) $(CFLAGS) -o $@ get.o subs.o get.o subs.o : subs.h The invocation: make get will cause get.c and subs.c to be compiled to create the object files. If either of these files, subs.h, or the makefile are stored under RCS and not present in the current directory, they will be checked out. Finally, the two object files will be compiled together to create the program get. This example reads rules from the file make.pgm and makes the programs docputand dprint. After finishing, it installs the programs and cleans up. make -f make.pgm docput dprint install clean (Typically, the install target moves the programs to the proper directory for execution, and the clean target removes all object files, temporary files, and sources, if the sources are maintained under RCS.) This example prints out a graph of the dependencies used by make when the command 'make' with no arguments is executed. make -mnsg Note the use of the -m to supress information about making the makefiles, -n so no commands are executed, and -s to supress printing of commands to be executed. Printed 4/6/89 8
MAKE(1) COMMAND REFERENCE MAKE(1) This example builds the programs 'docput' and 'dprint' as above, but if errors occur in building 'docput', processing is still done on make -k docput dprint FILES [mM]akefile The file makefile is used as the rules file if it exists. If not, the file Makefile is used if it exists. /usr/lib/mfrules Additions to the default rule set for making makefiles. Provided for users with no source code. $HOME/.mfilerc Personal makefile-making rules. /usr/lib/makerules Additions to the default rule set. Provided for users with no source code. $HOME/.makerc Personal default rules. VARIABLES HOME The user's home directory. MAKEFLAGS Flags to make. MFRULES The name of the personal makefile-making rules file, if $HOME/.mfilerc is not used." MAKERULES The name of the personal default rules file, if $HOME/.makerc is not used." RETURN VALUE [NO_ERRS] Command completed without error. [USAGE] Incorrect command line syntax. Execution terminated. [-1] When the -q option is given, a return value of -1 means that the target is not up to date. [NP_WARN] An error warranting a warning message occurred. Execution continues. [NP_ERR] An error occurred that was not a system error. Execution terminated. Printed 4/6/89 9
MAKE(1) COMMAND REFERENCE MAKE(1) [P_WARN] A system error occurred. Execution continues. See intro(2) for more information on system errors. [P_ERR] A system error occurred. Execution terminated. See intro(2) for more information on system errors. CAVEATS Some commands return nonzero status inappropriately. Use -i to overcome the difficulty. Commands that are directly executed by the shell, notably cd(1sh), are ineffectual across newlines in make. When using single-suffix rules (where the second suffix is null), the target may have no explicit dependencies or commands. There are cases in which makefiles which work with other versions of make which do not handle RCS directories will have problems with this version. This is almost always the result of incompletely specified dependents. See the EXAMPLES section for an example of a rule which has this property. By default, there exists on a rule for building archives (files with the suffix ``.a'') for C files (with the suffix ``.c''). When using other types of files to build archives, rules are required. The -t flag should be used with care. In cases where one or more of the targets processed is not supposed to be a file (as in a makefile with a mnemonic print target), an empty file will be created. When a line ends with a backslash, all spaces, tabs, and newlines on the following lines are ignored. For example, this block of text: prog : prog.c\ prog2 : prog2.c prog prog2.c | cc -c -o prog2 prog3 : prog3.c is interpreted as: prog : prog.c prog2 : prog2.c prog prog2.c | cc -c -o prog2 prog3 : prog3.c Printed 4/6/89 10
MAKE(1) COMMAND REFERENCE MAKE(1) which will result in a syntax error. When macro substitution causes a line in the makefile to expand to longer than 2500 characters, a memory fault may occur. Checking is done to try to prevent this, but it is not possible to guarantee that this gets caught before the damage is done. SEE ALSO cc(1), co(1rcs), f77(1), pc(1), sh(1sh), and touch(1). Printed 4/6/89 11
%%index%% na:240,83; sy:323,774; de:1097,2624;4033,3112;7457,3403;11172,3210;14694,2646;17652,2550;20514,314; op:20828,2002;23142,308; ex:23450,1784;25546,184; fi:25730,812; va:26542,513; rv:27055,663;28030,344; ca:28374,1759;30445,317; se:30762,235; %%index%%000000000274