make (1p)
PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.NAME
make — maintain, update, and regenerate groups of programs ( DEVELOPMENT)SYNOPSIS
make [−einpqrst] [−f makefile]... [−k|−S] [macro=value...] [target_name...]
DESCRIPTION
The make utility shall update files that are derived from other files. A typical case is one where object files are derived from the corresponding source files. The make utility examines time relationships and shall update those derived files (called targets) that have modified times earlier than the modified times of the files (called prerequisites) from which they are derived. A description file (makefile) contains a description of the relationships between files, and the commands that need to be executed to update the targets to reflect changes in their prerequisites. Each specification, or rule, shall consist of a target, optional prerequisites, and optional commands to be executed when a prerequisite is newer than the target. There are two types of rule:- 1.
- Inference rules, which have one target name with at least one <period> ('.') and no <slash> ('/')
- 2.
- Target rules, which can have more than one target name
- *
- Include the special target .POSIX
- *
- Omit any special target reserved for implementations (a leading period followed by uppercase letters) that has not been specified by this section
OPTIONS
The make utility shall conform to the Base Definitions volume of POSIX.1‐2008, Section 12.2, Utility Syntax Guidelines, except for Guideline 9. The following options shall be supported:- −e
- Cause environment variables, including those with null values, to override macro assignments within makefiles.
- −f makefile
- Specify a different makefile. The argument makefile is a pathname of a description file, which is also referred to as the makefile. A pathname of '−' shall denote the standard input. There can be multiple instances of this option, and they shall be processed in the order specified. The effect of specifying the same option-argument more than once is unspecified.
- −i
- Ignore error codes returned by invoked commands. This mode is the same as if the special target .IGNORE were specified without prerequisites.
- −k
- Continue to update other targets that do not depend on the current target if a non-ignored error occurs while executing the commands to bring a target up-to-date.
- −n
- Write commands that would be executed on standard output, but do not execute them. However, lines with a <plus-sign> ('+') prefix shall be executed. In this mode, lines with an at-sign ('@') character prefix shall be written to standard output.
- −p
- Write to standard output the complete set of macro definitions and target descriptions. The output format is unspecified.
- −q
- Return a zero exit value if the target file is up-to-date; otherwise, return an exit value of 1. Targets shall not be updated if this option is specified. However, a makefile command line (associated with the targets) with a <plus-sign> ('+') prefix shall be executed.
- −r
- Clear the suffix list and do not use the built-in rules.
- −S
- Terminate make if an error occurs while executing the commands to bring a target up-to-date. This shall be the default and the opposite of −k.
- −s
- Do not write makefile command lines or touch messages (see −t) to standard output before executing. This mode shall be the same as if the special target .SILENT were specified without prerequisites.
- −t
- Update the modification time of each target as though a touch target had been executed. Targets that have prerequisites but no commands (see Target Rules), or that are already up-to-date, shall not be touched in this manner. Write messages to standard output for each target file indicating the name of the file and that it was touched. Normally, the makefile command lines associated with each target are not executed. However, a command line with a <plus-sign> ('+') prefix shall be executed.
OPERANDS
The following operands shall be supported:- target_name
- Target names, as defined in the EXTENDED DESCRIPTION section. If no target is specified, while make is processing the makefiles, the first target that make encounters that is not a special target or an inference rule shall be used.
- macro=value
- Macro definitions, as defined in Macros.
STDIN
The standard input shall be used only if the makefile option-argument is '−'. See the INPUT FILES section.INPUT FILES
The input file, otherwise known as the makefile, is a text file containing rules, macro definitions, and comments. See the EXTENDED DESCRIPTION section.ENVIRONMENT VARIABLES
The following environment variables shall affect the execution of make:- LANG
- Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1‐2008, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)
- LC_ALL
- If set to a non-empty string value, override the values of all the other internationalization variables.
- LC_CTYPE
- Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments and input files).
- LC_MESSAGES
-
- MAKEFLAGS
-
- *
- The characters are option letters without the leading <hyphen> characters or <blank> separation used on a make utility command line.
- *
- The characters are formatted in a manner similar to a portion of the make utility command line: options are preceded by <hyphen> characters and <blank>-separated as described in the Base Definitions volume of POSIX.1‐2008, Section 12.2, Utility Syntax Guidelines. The macro=value macro definition operands can also be included. The difference between the contents of MAKEFLAGS and the make utility command line is that the contents of the variable shall not be subjected to the word expansions (see Section 2.6, Word Expansions) associated with parsing the command line values.
- NLSPATH
- Determine the location of message catalogs for the processing of LC_MESSAGES.
- PROJECTDIR
-
If PROJECTDIR is not set or has a null value, the search for SCCS files shall be made in the directory SCCS in the current directory.
The setting of PROJECTDIR affects all files listed in the remainder of this utility description for files with a component named SCCS.
The value of the SHELL environment variable shall not be used as a macro and shall not be modified by defining the SHELL macro in a makefile or on the command line. All other environment variables, including those with null values, shall be used as macros, as defined in Macros.
ASYNCHRONOUS EVENTS
If not already ignored, make shall trap SIGHUP, SIGTERM, SIGINT, and SIGQUIT and remove the current target unless the target is a directory or the target is a prerequisite of the special target .PRECIOUS or unless one of the −n, −p, or −q options was specified. Any targets removed in this manner shall be reported in diagnostic messages of unspecified format, written to standard error. After this cleanup process, if any, make shall take the standard action for all other signals.STDOUT
The make utility shall write all commands to be executed to standard output unless the −s option was specified, the command is prefixed with an at-sign, or the special target .SILENT has either the current target as a prerequisite or has no prerequisites. If make is invoked without any work needing to be done, it shall write a message to standard output indicating that no action was taken. If the −t option is present and a file is touched, make shall write to standard output a message of unspecified format indicating that the file was touched, including the filename of the file.STDERR
The standard error shall be used only for diagnostic messages.OUTPUT FILES
Files can be created when the −t option is present. Additional files can also be created by the utilities invoked by make.EXTENDED DESCRIPTION
The make utility attempts to perform the actions required to ensure that the specified targets are up-to-date. A target is considered out-of-date if it is older than any of its prerequisites or if it does not exist. The make utility shall treat all prerequisites as targets themselves and recursively ensure that they are up-to-date, processing them in the order in which they appear in the rule. The make utility shall use the modification times of files to determine whether the corresponding targets are out-of-date. After make has ensured that all of the prerequisites of a target are up-to-date and if the target is out-of-date, the commands associated with the target entry shall be executed. If there are no commands listed for the target, the target shall be treated as up-to-date.Makefile Syntax
A makefile can contain rules, macro definitions (see Macros), include lines, and comments. There are two kinds of rules: inference rules and target rules. The make utility shall contain a set of built-in inference rules. If the −r option is present, the built-in rules shall not be used and the suffix list shall be cleared. Additional rules of both types can be specified in a makefile. If a rule is defined more than once, the value of the rule shall be that of the last one specified. Macros can also be defined more than once, and the value of the macro is specified in Macros. Comments start with a <number-sign> ('#') and continue until an unescaped <newline> is reached. By default, the following files shall be tried in sequence: ./makefile and ./Makefile. If neither ./makefile or ./Makefile are found, other implementation-defined files may also be tried. On XSI-conformant systems, the additional files ./s.makefile, SCCS/s.makefile, ./s.Makefile, and SCCS/s.Makefile shall also be tried. The −f option shall direct make to ignore any of these default files and use the specified argument as a makefile instead. If the '−' argument is specified, standard input shall be used. The term makefile is used to refer to any rules provided by the user, whether in ./makefile or its variants, or specified by the −f option. The rules in makefiles shall consist of the following types of lines: target rules, including special targets (see Target Rules), inference rules (see Inference Rules), macro definitions (see Macros), empty lines, and comments. Target and Inference Rules may contain command lines. Command lines can have a prefix that shall be removed before execution (see Makefile Execution). When an escaped <newline> (one preceded by a <backslash>) is found anywhere in the makefile except in a command line, an include line, or a line immediately preceding an include line, it shall be replaced, along with any leading white space on the following line, with a single <space>. When an escaped <newline> is found in a command line in a makefile, the command line shall contain the <backslash>, the <newline>, and the next line, except that the first character of the next line shall not be included if it is a <tab>. When an escaped <newline> is found in an include line or in a line immediately preceding an include line, the behavior is unspecified.Include Lines
If the word include appears at the beginning of a line and is followed by one or more <blank> characters, the string formed by the remainder of the line shall be processed as follows to produce a pathname:- *
- The trailing <newline> and any comment shall be discarded. If the resulting string contains any double-quote characters ('"') the behavior is unspecified.
- *
- The resulting string shall be processed for macro expansion (see Macros.
- *
- Any <blank> characters that appear after the first non-<blank> shall be used as separators to divide the macro-expanded string into fields. It is unspecified whether any other white-space characters are also used as separators. It is unspecified whether pathname expansion (see Section 2.13, Pattern Matching Notation) is also performed.
- *
- If the processing of separators and optional pathname expansion results in either zero or two or more non-empty fields, the behavior is unspecified. If it results in one non-empty field, that field is taken as the pathname.
Makefile Execution
Makefile command lines shall be processed one at a time. Makefile command lines can have one or more of the following prefixes: a <hyphen> ('-'), an at-sign ('@'), or a <plus-sign> ('+'). These shall modify the way in which make processes the command.- −
- If the command prefix contains a <hyphen>, or the −i option is present, or the special target .IGNORE has either the current target as a prerequisite or has no prerequisites, any error found while executing the command shall be ignored.
- @
- If the command prefix contains an at-sign and the make utility command line −n option is not specified, or the −s option is present, or the special target .SILENT has either the current target as a prerequisite or has no prerequisites, the command shall not be written to standard output before it is executed.
- +
- If the command prefix contains a <plus-sign>, this indicates a makefile command line that shall be executed even if −n, −q, or −t is specified.
Target Rules
Target rules are formatted as follows:target [target...]: [prerequisite...][;command] [<tab>command <tab> command ... ]
line that does not begin with <tab>
- .DEFAULT
- If the makefile uses this special target, the application shall ensure that it is specified with commands, but without prerequisites. The commands shall be used by make if there are no other rules available to build a target.
- .IGNORE
- Prerequisites of this special target are targets themselves; this shall cause errors from commands associated with them to be ignored in the same manner as specified by the −i option. Subsequent occurrences of .IGNORE shall add to the list of targets ignoring command errors. If no prerequisites are specified, make shall behave as if the −i option had been specified and errors from all commands associated with all targets shall be ignored.
- .POSIX
- The application shall ensure that this special target is specified without prerequisites or commands. If it appears as the first non-comment line in the makefile, make shall process the makefile as specified by this section; otherwise, the behavior of make is unspecified.
- .PRECIOUS
- Prerequisites of this special target shall not be removed if make receives one of the asynchronous events explicitly described in the ASYNCHRONOUS EVENTS section. Subsequent occurrences of .PRECIOUS shall add to the list of precious files. If no prerequisites are specified, all targets in the makefile shall be treated as if specified with .PRECIOUS.
- .SCCS_GET
- The application shall ensure that this special target is specified without prerequisites. If this special target is included in a makefile, the commands specified with this target shall replace the default commands associated with this special target (see Default Rules). The commands specified with this target are used to get all SCCS files that are not found in the current directory.
When source files are named in a dependency list, make shall treat them just like any other target. Because the source file is presumed to be present in the directory, there is no need to add an entry for it to the makefile. When a target has no dependencies, but is present in the directory, make shall assume that that file is up-to-date. If, however, an SCCS file named SCCS/s.source_file is found for a target source_file, make compares the timestamp of the target file with that of the SCCS/s.source_file to ensure the target is up-to-date. If the target is missing, or if the SCCS file is newer, make shall automatically issue the commands specified for the .SCCS_GET special target to retrieve the most recent version. However, if the target is writable by anyone, make shall not retrieve a new version.
- .SILENT
- Prerequisites of this special target are targets themselves; this shall cause commands associated with them not to be written to the standard output before they are executed. Subsequent occurrences of .SILENT shall add to the list of targets with silent commands. If no prerequisites are specified, make shall behave as if the −s option had been specified and no commands or touch messages associated with any target shall be written to standard output.
- .SUFFIXES
- Prerequisites of .SUFFIXES shall be appended to the list of known suffixes and are used in conjunction with the inference rules (see Inference Rules). If .SUFFIXES does not have any prerequisites, the list of known suffixes shall be cleared.
Macros
Macro definitions are in the form:string1 = [string2]
- *
- Macros in target lines shall be evaluated when the target line is read.
- *
- Macros in makefile command lines shall be evaluated when the command is executed.
- *
- Macros in the string before the <equals-sign> in a macro definition shall be evaluated when the macro assignment is made.
- *
- Macros after the <equals-sign> in a macro definition shall not be evaluated until the defined macro is used in a rule or command, or before the <equals-sign> in a macro definition.
- 1.
- Macros specified on the make utility command line, in the order specified on the command line. It is unspecified whether the internal macros defined in Internal Macros are accepted from this source.
- 2.
- Macros defined by the MAKEFLAGS environment variable, in the order specified in the environment variable. It is unspecified whether the internal macros defined in Internal Macros are accepted from this source.
- 3.
- The contents of the environment, excluding the MAKEFLAGS and SHELL variables and including the variables with null values.
- 4.
- Macros defined in the inference rules built into make.
Inference Rules
Inference rules are formatted as follows:target: <tab> command [<tab>command] ...
line that does not begin with <tab> or #
rule: ;
Libraries
If a target or prerequisite contains parentheses, it shall be treated as a member of an archive library. For the lib(member.o) expression lib refers to the name of the archive library and member.o to the member name. The application shall ensure that the member is an object file with the .o suffix. The modification time of the expression is the modification time for the member as kept in the archive library; see ar. The .a suffix shall refer to an archive library. The .s2.a rule shall be used to update a member in the library from a file with a suffix .s2.Internal Macros
The make utility shall maintain five internal macros that can be used in target and inference rules. In order to clearly define the meaning of these macros, some clarification of the terms target rule, inference rule, target, and prerequisite is necessary. Target rules are specified by the user in a makefile for a particular target. Inference rules are user-specified or make-specified rules for a particular class of target name. Explicit prerequisites are those prerequisites specified in a makefile on target lines. Implicit prerequisites are those prerequisites that are generated when inference rules are used. Inference rules are applied to implicit prerequisites or to explicit prerequisites that do not have target rules defined for them in the makefile. Target rules are applied to targets specified in the makefile. Before any target in the makefile is updated, each of its prerequisites (both explicit and implicit) shall be updated. This shall be accomplished by recursively processing each prerequisite. Upon recursion, each prerequisite shall become a target itself. Its prerequisites in turn shall be processed recursively until a target is found that has no prerequisites, at which point the recursion stops. The recursion shall then back up, updating each target as it goes. In the definitions that follow, the word target refers to one of:- *
- A target specified in the makefile
- *
- An explicit prerequisite specified in the makefile that becomes the target when make processes it during recursion
- *
- An implicit prerequisite that becomes a target when make processes it during recursion
- *
- An explicit prerequisite specified in the makefile for a particular target
- *
- An implicit prerequisite generated as a result of locating an appropriate inference rule and corresponding file that matches the suffix of the target
- $@
- The $@ shall evaluate to the full target name of the current target, or the archive filename part of a library archive target. It shall be evaluated for both target and inference rules.
For example, in the .c.a inference rule, $@ represents the out-of-date .a file to be built. Similarly, in a makefile target rule to build lib.a from file.c, $@ represents the out-of-date lib.a.
- $%
- The $% macro shall be evaluated only when the current target is an archive library member of the form libname(member.o). In these cases, $@ shall evaluate to libname and $% shall evaluate to member.o. The $% macro shall be evaluated for both target and inference rules.
For example, in a makefile target rule to build lib.a(file.o), $% represents file.o, as opposed to $@, which represents lib.a.
- $?
- The $? macro shall evaluate to the list of prerequisites that are newer than the current target. It shall be evaluated for both target and inference rules.
For example, in a makefile target rule to build prog from file1.o, file2.o, and file3.o, and where prog is not out-of-date with respect to file1.o, but is out-of-date with respect to file2.o and file3.o, $? represents file2.o and file3.o.
- $<
- In an inference rule, the $< macro shall evaluate to the filename whose existence allowed the inference rule to be chosen for the target. In the .DEFAULT rule, the $< macro shall evaluate to the current target name. The meaning of the $< macro shall be otherwise unspecified.
For example, in the .c.a inference rule, $< represents the prerequisite .c file.
- $*
- The $* macro shall evaluate to the current target name with its suffix deleted. It shall be evaluated at least for inference rules.
For example, in the .c.a inference rule, $*.o represents the out-of-date .o file that corresponds to the prerequisite .c file.
Each of the internal macros has an alternative form. When an uppercase 'D' or 'F' is appended to any of the macros, the meaning shall be changed to the directory part for 'D' and filename part for 'F'. The directory part is the path prefix of the file without a trailing <slash>; for the current directory, the directory part is '.'. When the $? macro contains more than one prerequisite filename, the $(?D) and $(?F) (or ${?D} and ${?F}) macros expand to a list of directory name parts and filename parts respectively.
For the target lib(member.o) and the s2.a rule, the internal macros shall be defined as:
- $<
- member.s2
- $*
- member
- $@
- lib
- $?
- member.s2
- $%
- member.o
Default Rules
The default rules for make shall achieve results that are the same as if the following were used. Implementations that do not support the C-Language Development Utilities option may omit CC, CFLAGS, YACC, YFLAGS, LEX, LFLAGS, LDFLAGS, and the .c, .y, and .l inference rules. Implementations that do not support FORTRAN may omit FC, FFLAGS, and the .f inference rules. Implementations may provide additional macros and rules.SPECIAL TARGETS
.SCCS_GET: sccs $(SCCSFLAGS) get $(SCCSGETFLAGS) $@
.SUFFIXES: .o .c .y .l .a .sh .f .c~ .y~ .l~ .sh~ .f~
MACROS
MAKE=make AR=ar ARFLAGS=−rv YACC=yacc YFLAGS= LEX=lex LFLAGS= LDFLAGS= CC=c99 CFLAGS=−O FC=fort77 FFLAGS=−O 1 GET=get GFLAGS= SCCSFLAGS= SCCSGETFLAGS=−s
SINGLE SUFFIX RULES
.c: $(CC) $(CFLAGS) $(LDFLAGS) −o $@ $<
.f: $(FC) $(FFLAGS) $(LDFLAGS) −o $@ $<
.sh: cp $< $@ chmod a+x $@
.c~: $(GET) $(GFLAGS) −p $< > $*.c $(CC) $(CFLAGS) $(LDFLAGS) −o $@ $*.c
.f~: $(GET) $(GFLAGS) −p $< > $*.f $(FC) $(FFLAGS) $(LDFLAGS) −o $@ $*.f
.sh~: $(GET) $(GFLAGS) −p $< > $*.sh cp $*.sh $@ chmod a+x $@
DOUBLE SUFFIX RULES
.c.o: $(CC) $(CFLAGS) −c $<
.f.o: $(FC) $(FFLAGS) −c $<
.y.o: $(YACC) $(YFLAGS) $< $(CC) $(CFLAGS) −c y.tab.c rm −f y.tab.c mv y.tab.o $@
.l.o: $(LEX) $(LFLAGS) $< $(CC) $(CFLAGS) −c lex.yy.c rm −f lex.yy.c mv lex.yy.o $@
.y.c: $(YACC) $(YFLAGS) $< mv y.tab.c $@
.l.c: $(LEX) $(LFLAGS) $< mv lex.yy.c $@
.c~.o: $(GET) $(GFLAGS) −p $< > $*.c $(CC) $(CFLAGS) −c $*.c
.f~.o: $(GET) $(GFLAGS) −p $< > $*.f $(FC) $(FFLAGS) −c $*.f
.y~.o: $(GET) $(GFLAGS) −p $< > $*.y $(YACC) $(YFLAGS) $*.y $(CC) $(CFLAGS) −c y.tab.c rm −f y.tab.c mv y.tab.o $@
.l~.o: $(GET) $(GFLAGS) −p $< > $*.l $(LEX) $(LFLAGS) $*.l $(CC) $(CFLAGS) −c lex.yy.c rm −f lex.yy.c mv lex.yy.o $@
.y~.c: $(GET) $(GFLAGS) −p $< > $*.y $(YACC) $(YFLAGS) $*.y mv y.tab.c $@
.l~.c: $(GET) $(GFLAGS) −p $< > $*.l $(LEX) $(LFLAGS) $*.l mv lex.yy.c $@
.c.a: $(CC) −c $(CFLAGS) $< $(AR) $(ARFLAGS) $@ $*.o rm −f $*.o
.f.a: $(FC) −c $(FFLAGS) $< $(AR) $(ARFLAGS) $@ $*.o rm −f $*.o
EXIT STATUS
When the −q option is specified, the make utility shall exit with one of the following values:- 0
- Successful completion.
- 1
- The target was not up-to-date.
- >1
- An error occurred.
- 0
- Successful completion.
- >0
- An error occurred.
CONSEQUENCES OF ERRORS
Default. The following sections are informative.APPLICATION USAGE
If there is a source file (such as ./source.c) and there are two SCCS files corresponding to it (./s.source.c and ./SCCS/s.source.c), on XSI-conformant systems make uses the SCCS file in the current directory. However, users are advised to use the underlying SCCS utilities (admin, delta, get, and so on) or the sccs utility for all source files in a given directory. If both forms are used for a given source file, future developers are very likely to be confused. It is incumbent upon portable makefiles to specify the .POSIX special target in order to guarantee that they are not affected by local extensions. The −k and −S options are both present so that the relationship between the command line, the MAKEFLAGS variable, and the makefile can be controlled precisely. If the k flag is passed in MAKEFLAGS and a command is of the form:$(MAKE) −S foo
CFLAGS = "−D COMMENT_CHAR='#'"
MACRO = value1 NEW = $(MACRO) MACRO = value2
target: echo $(NEW)
foo.o: foo.h
EXAMPLES
- 1.
- The following command:
make
- 2.
- The following command:
make junk
- 3.
- 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 c99 a.o b.o −o pgm a.o: incl.h a.c c99 −c a.c b.o: incl.h b.c c99 −c b.c
- 4.
- An example for making optimized .o files from .c files is:
.c.o: c99 −c −O $*.c
.c.o: c99 −c −O $<
- 5.
- The most common use of the archive interface follows. Here, it is assumed that the source files are all C-language source:
lib: lib(file1.o) lib(file2.o) lib(file3.o) @echo lib is now up-to-date
.c.o\ :
f= bar baz\ biz a: echo ==$f==
/usr/include/stdio.h /usr/include/unistd.h foo.h
/usr/include /usr/include .
stdio.h unistd.h foo.h
- 6.
- The contents of the built-in rules can be viewed by running:
make −p −f /dev/null 2>/dev/null
RATIONALE
The make utility described in this volume of POSIX.1‐2008 is intended to provide the means for changing portable source code into executables that can be run on an POSIX.1‐2008-conforming system. It reflects the most common features present in System V and BSD makes. Historically, the make utility has been an especially fertile ground for vendor and research organization-specific syntax modifications and extensions. Examples include:- *
- Syntax supporting parallel execution (such as from various multi-processor vendors, GNU, and others)
- *
- Additional ``operators'' separating targets and their prerequisites (System V, BSD, and others)
- *
- Specifying that command lines containing the strings "${MAKE}" and "$(MAKE)" are executed when the −n option is specified (GNU and System V)
- *
- Modifications of the meaning of internal macros when referencing libraries (BSD and others)
- *
- Using a single instance of the shell for all of the command lines of the target (BSD and others)
- *
- Allowing <space> characters as well as <tab> characters to delimit command lines (BSD)
- *
- Adding C preprocessor-style ``include'' and ``ifdef'' constructs (System V, GNU, BSD, and others)
- *
- Remote execution of command lines (Sprite and others)
- *
- Specifying additional special targets (BSD, System V, and most others)
subdir: cd subdir; rm all_the_files; $(MAKE)
foo: y.tab.o lex.o main.o $(CC) $(CFLAGS) −o $@ t.tab.o lex.o main.o
= | ^ ( ) ; & < > * ? [ ] : $ ` ' " \ \n
cat: $$@.c
cat: cat.c