1MAKE(1P) POSIX Programmer's Manual MAKE(1P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 make — maintain, update, and regenerate groups of programs (DEVELOP‐
14 MENT)
15
17 make [−einpqrst] [−f makefile]... [−k|−S] [macro=value...]
18 [target_name...]
19
21 The make utility shall update files that are derived from other files.
22 A typical case is one where object files are derived from the corre‐
23 sponding source files. The make utility examines time relationships and
24 shall update those derived files (called targets) that have modified
25 times earlier than the modified times of the files (called prerequi‐
26 sites) from which they are derived. A description file (makefile) con‐
27 tains a description of the relationships between files, and the com‐
28 mands that need to be executed to update the targets to reflect changes
29 in their prerequisites. Each specification, or rule, shall consist of a
30 target, optional prerequisites, and optional commands to be executed
31 when a prerequisite is newer than the target. There are two types of
32 rule:
33
34 1. Inference rules, which have one target name with at least one
35 <period> ('.') and no <slash> ('/')
36
37 2. Target rules, which can have more than one target name
38
39 In addition, make shall have a collection of built-in macros and infer‐
40 ence rules that infer prerequisite relationships to simplify mainte‐
41 nance of programs.
42
43 To receive exactly the behavior described in this section, the user
44 shall ensure that a portable makefile shall:
45
46 * Include the special target .POSIX
47
48 * Omit any special target reserved for implementations (a leading
49 period followed by uppercase letters) that has not been specified
50 by this section
51
52 The behavior of make is unspecified if either or both of these condi‐
53 tions are not met.
54
56 The make utility shall conform to the Base Definitions volume of
57 POSIX.1‐2008, Section 12.2, Utility Syntax Guidelines, except for
58 Guideline 9.
59
60 The following options shall be supported:
61
62 −e Cause environment variables, including those with null val‐
63 ues, to override macro assignments within makefiles.
64
65 −f makefile
66 Specify a different makefile. The argument makefile is a
67 pathname of a description file, which is also referred to as
68 the makefile. A pathname of '−' shall denote the standard
69 input. There can be multiple instances of this option, and
70 they shall be processed in the order specified. The effect of
71 specifying the same option-argument more than once is unspec‐
72 ified.
73
74 −i Ignore error codes returned by invoked commands. This mode is
75 the same as if the special target .IGNORE were specified
76 without prerequisites.
77
78 −k Continue to update other targets that do not depend on the
79 current target if a non-ignored error occurs while executing
80 the commands to bring a target up-to-date.
81
82 −n Write commands that would be executed on standard output, but
83 do not execute them. However, lines with a <plus-sign> ('+')
84 prefix shall be executed. In this mode, lines with an at-sign
85 ('@') character prefix shall be written to standard output.
86
87 −p Write to standard output the complete set of macro defini‐
88 tions and target descriptions. The output format is unspeci‐
89 fied.
90
91 −q Return a zero exit value if the target file is up-to-date;
92 otherwise, return an exit value of 1. Targets shall not be
93 updated if this option is specified. However, a makefile com‐
94 mand line (associated with the targets) with a <plus-sign>
95 ('+') prefix shall be executed.
96
97 −r Clear the suffix list and do not use the built-in rules.
98
99 −S Terminate make if an error occurs while executing the com‐
100 mands to bring a target up-to-date. This shall be the default
101 and the opposite of −k.
102
103 −s Do not write makefile command lines or touch messages (see
104 −t) to standard output before executing. This mode shall be
105 the same as if the special target .SILENT were specified
106 without prerequisites.
107
108 −t Update the modification time of each target as though a touch
109 target had been executed. Targets that have prerequisites but
110 no commands (see Target Rules), or that are already up-to-
111 date, shall not be touched in this manner. Write messages to
112 standard output for each target file indicating the name of
113 the file and that it was touched. Normally, the makefile com‐
114 mand lines associated with each target are not executed. How‐
115 ever, a command line with a <plus-sign> ('+') prefix shall be
116 executed.
117
118 Any options specified in the MAKEFLAGS environment variable shall be
119 evaluated before any options specified on the make utility command
120 line. If the −k and −S options are both specified on the make utility
121 command line or by the MAKEFLAGS environment variable, the last option
122 specified shall take precedence. If the −f or −p options appear in the
123 MAKEFLAGS environment variable, the result is undefined.
124
126 The following operands shall be supported:
127
128 target_name
129 Target names, as defined in the EXTENDED DESCRIPTION section.
130 If no target is specified, while make is processing the make‐
131 files, the first target that make encounters that is not a
132 special target or an inference rule shall be used.
133
134 macro=value
135 Macro definitions, as defined in Macros.
136
137 If the target_name and macro=value operands are intermixed on the make
138 utility command line, the results are unspecified.
139
141 The standard input shall be used only if the makefile option-argument
142 is '−'. See the INPUT FILES section.
143
145 The input file, otherwise known as the makefile, is a text file con‐
146 taining rules, macro definitions, and comments. See the EXTENDED
147 DESCRIPTION section.
148
150 The following environment variables shall affect the execution of make:
151
152 LANG Provide a default value for the internationalization vari‐
153 ables that are unset or null. (See the Base Definitions vol‐
154 ume of POSIX.1‐2008, Section 8.2, Internationalization Vari‐
155 ables for the precedence of internationalization variables
156 used to determine the values of locale categories.)
157
158 LC_ALL If set to a non-empty string value, override the values of
159 all the other internationalization variables.
160
161 LC_CTYPE Determine the locale for the interpretation of sequences of
162 bytes of text data as characters (for example, single-byte as
163 opposed to multi-byte characters in arguments and input
164 files).
165
166 LC_MESSAGES
167 Determine the locale that should be used to affect the format
168 and contents of diagnostic messages written to standard
169 error.
170
171 MAKEFLAGS
172 This variable shall be interpreted as a character string rep‐
173 resenting a series of option characters to be used as the
174 default options. The implementation shall accept both of the
175 following formats (but need not accept them when intermixed):
176
177 * The characters are option letters without the leading
178 <hyphen> characters or <blank> separation used on a make
179 utility command line.
180
181 * The characters are formatted in a manner similar to a
182 portion of the make utility command line: options are
183 preceded by <hyphen> characters and <blank>-separated as
184 described in the Base Definitions volume of POSIX.1‐2008,
185 Section 12.2, Utility Syntax Guidelines. The macro=value
186 macro definition operands can also be included. The dif‐
187 ference between the contents of MAKEFLAGS and the make
188 utility command line is that the contents of the variable
189 shall not be subjected to the word expansions (see Sec‐
190 tion 2.6, Word Expansions) associated with parsing the
191 command line values.
192
193 NLSPATH Determine the location of message catalogs for the processing
194 of LC_MESSAGES.
195
196 PROJECTDIR
197 Provide a directory to be used to search for SCCS files not
198 found in the current directory. In all of the following
199 cases, the search for SCCS files is made in the directory
200 SCCS in the identified directory. If the value of PROJECTDIR
201 begins with a <slash>, it shall be considered an absolute
202 pathname; otherwise, the value of PROJECTDIR is treated as a
203 user name and that user's initial working directory shall be
204 examined for a subdirectory src or source. If such a direc‐
205 tory is found, it shall be used. Otherwise, the value is used
206 as a relative pathname.
207
208 If PROJECTDIR is not set or has a null value, the search for
209 SCCS files shall be made in the directory SCCS in the current
210 directory.
211
212 The setting of PROJECTDIR affects all files listed in the
213 remainder of this utility description for files with a compo‐
214 nent named SCCS.
215
216 The value of the SHELL environment variable shall not be used as a
217 macro and shall not be modified by defining the SHELL macro in a make‐
218 file or on the command line. All other environment variables, including
219 those with null values, shall be used as macros, as defined in Macros.
220
222 If not already ignored, make shall trap SIGHUP, SIGTERM, SIGINT, and
223 SIGQUIT and remove the current target unless the target is a directory
224 or the target is a prerequisite of the special target .PRECIOUS or
225 unless one of the −n, −p, or −q options was specified. Any targets
226 removed in this manner shall be reported in diagnostic messages of
227 unspecified format, written to standard error. After this cleanup
228 process, if any, make shall take the standard action for all other sig‐
229 nals.
230
232 The make utility shall write all commands to be executed to standard
233 output unless the −s option was specified, the command is prefixed with
234 an at-sign, or the special target .SILENT has either the current target
235 as a prerequisite or has no prerequisites. If make is invoked without
236 any work needing to be done, it shall write a message to standard out‐
237 put indicating that no action was taken. If the −t option is present
238 and a file is touched, make shall write to standard output a message of
239 unspecified format indicating that the file was touched, including the
240 filename of the file.
241
243 The standard error shall be used only for diagnostic messages.
244
246 Files can be created when the −t option is present. Additional files
247 can also be created by the utilities invoked by make.
248
250 The make utility attempts to perform the actions required to ensure
251 that the specified targets are up-to-date. A target is considered out-
252 of-date if it is older than any of its prerequisites or if it does not
253 exist. The make utility shall treat all prerequisites as targets them‐
254 selves and recursively ensure that they are up-to-date, processing them
255 in the order in which they appear in the rule. The make utility shall
256 use the modification times of files to determine whether the corre‐
257 sponding targets are out-of-date.
258
259 After make has ensured that all of the prerequisites of a target are
260 up-to-date and if the target is out-of-date, the commands associated
261 with the target entry shall be executed. If there are no commands
262 listed for the target, the target shall be treated as up-to-date.
263
264 Makefile Syntax
265 A makefile can contain rules, macro definitions (see Macros), include
266 lines, and comments. There are two kinds of rules: inference rules and
267 target rules. The make utility shall contain a set of built-in infer‐
268 ence rules. If the −r option is present, the built-in rules shall not
269 be used and the suffix list shall be cleared. Additional rules of both
270 types can be specified in a makefile. If a rule is defined more than
271 once, the value of the rule shall be that of the last one specified.
272 Macros can also be defined more than once, and the value of the macro
273 is specified in Macros. Comments start with a <number-sign> ('#') and
274 continue until an unescaped <newline> is reached.
275
276 By default, the following files shall be tried in sequence: ./makefile
277 and ./Makefile. If neither ./makefile or ./Makefile are found, other
278 implementation-defined files may also be tried. On XSI-conformant sys‐
279 tems, the additional files ./s.makefile, SCCS/s.makefile, ./s.Makefile,
280 and SCCS/s.Makefile shall also be tried.
281
282 The −f option shall direct make to ignore any of these default files
283 and use the specified argument as a makefile instead. If the '−' argu‐
284 ment is specified, standard input shall be used.
285
286 The term makefile is used to refer to any rules provided by the user,
287 whether in ./makefile or its variants, or specified by the −f option.
288
289 The rules in makefiles shall consist of the following types of lines:
290 target rules, including special targets (see Target Rules), inference
291 rules (see Inference Rules), macro definitions (see Macros), empty
292 lines, and comments.
293
294 Target and Inference Rules may contain command lines. Command lines
295 can have a prefix that shall be removed before execution (see Makefile
296 Execution).
297
298 When an escaped <newline> (one preceded by a <backslash>) is found any‐
299 where in the makefile except in a command line, an include line, or a
300 line immediately preceding an include line, it shall be replaced, along
301 with any leading white space on the following line, with a single
302 <space>. When an escaped <newline> is found in a command line in a
303 makefile, the command line shall contain the <backslash>, the <new‐
304 line>, and the next line, except that the first character of the next
305 line shall not be included if it is a <tab>. When an escaped <newline>
306 is found in an include line or in a line immediately preceding an
307 include line, the behavior is unspecified.
308
309 Include Lines
310 If the word include appears at the beginning of a line and is followed
311 by one or more <blank> characters, the string formed by the remainder
312 of the line shall be processed as follows to produce a pathname:
313
314 * The trailing <newline> and any comment shall be discarded. If the
315 resulting string contains any double-quote characters ('"') the
316 behavior is unspecified.
317
318 * The resulting string shall be processed for macro expansion (see
319 Macros.
320
321 * Any <blank> characters that appear after the first non-<blank>
322 shall be used as separators to divide the macro-expanded string
323 into fields. It is unspecified whether any other white-space char‐
324 acters are also used as separators. It is unspecified whether path‐
325 name expansion (see Section 2.13, Pattern Matching Notation) is
326 also performed.
327
328 * If the processing of separators and optional pathname expansion
329 results in either zero or two or more non-empty fields, the behav‐
330 ior is unspecified. If it results in one non-empty field, that
331 field is taken as the pathname.
332
333 If the pathname does not begin with a '/' it shall be treated as rela‐
334 tive to the current working directory of the process, not relative to
335 the directory containing the makefile. If the file does not exist in
336 this location, it is unspecified whether additional directories are
337 searched.
338
339 The contents of the file specified by the pathname shall be read and
340 processed as if they appeared in the makefile in place of the include
341 line. If the file ends with an escaped <newline> the behavior is
342 unspecified.
343
344 The file may itself contain further include lines. Implementations
345 shall support nesting of include files up to a depth of at least 16.
346
347 Makefile Execution
348 Makefile command lines shall be processed one at a time.
349
350 Makefile command lines can have one or more of the following prefixes:
351 a <hyphen> ('-'), an at-sign ('@'), or a <plus-sign> ('+'). These
352 shall modify the way in which make processes the command.
353
354 − If the command prefix contains a <hyphen>, or the −i option is
355 present, or the special target .IGNORE has either the current
356 target as a prerequisite or has no prerequisites, any error found
357 while executing the command shall be ignored.
358
359 @ If the command prefix contains an at-sign and the make utility
360 command line −n option is not specified, or the −s option is
361 present, or the special target .SILENT has either the current
362 target as a prerequisite or has no prerequisites, the command
363 shall not be written to standard output before it is executed.
364
365 + If the command prefix contains a <plus-sign>, this indicates a
366 makefile command line that shall be executed even if −n, −q, or
367 −t is specified.
368
369 An execution line is built from the command line by removing any prefix
370 characters. Except as described under the at-sign prefix, the execution
371 line shall be written to the standard output, optionally preceded by a
372 <tab>. The execution line shall then be executed by a shell as if it
373 were passed as the argument to the system() interface, except that if
374 errors are not being ignored then the shell −e option shall also be in
375 effect. If errors are being ignored for the command (as a result of the
376 −i option, a '−' command prefix, or a .IGNORE special target), the
377 shell −e option shall not be in effect. The environment for the command
378 being executed shall contain all of the variables in the environment of
379 make.
380
381 By default, when make receives a non-zero status from the execution of
382 a command, it shall terminate with an error message to standard error.
383
384 Target Rules
385 Target rules are formatted as follows:
386
387 target [target...]: [prerequisite...][;command]
388 [<tab>command
389 <tab>command
390 ...]
391
392 line that does not begin with <tab>
393
394 Target entries are specified by a <blank>-separated, non-null list of
395 targets, then a <colon>, then a <blank>-separated, possibly empty list
396 of prerequisites. Text following a <semicolon>, if any, and all follow‐
397 ing lines that begin with a <tab>, are makefile command lines to be
398 executed to update the target. The first non-empty line that does not
399 begin with a <tab> or '#' shall begin a new entry. An empty or blank
400 line, or a line beginning with '#', may begin a new entry.
401
402 Applications shall select target names from the set of characters con‐
403 sisting solely of periods, underscores, digits, and alphabetics from
404 the portable character set (see the Base Definitions volume of
405 POSIX.1‐2008, Section 6.1, Portable Character Set). Implementations
406 may allow other characters in target names as extensions. The interpre‐
407 tation of targets containing the characters '%' and '"' is implementa‐
408 tion-defined.
409
410 A target that has prerequisites, but does not have any commands, can be
411 used to add to the prerequisite list for that target. Only one target
412 rule for any given target can contain commands.
413
414 Lines that begin with one of the following are called special targets
415 and control the operation of make:
416
417 .DEFAULT If the makefile uses this special target, the application
418 shall ensure that it is specified with commands, but without
419 prerequisites. The commands shall be used by make if there
420 are no other rules available to build a target.
421
422 .IGNORE Prerequisites of this special target are targets themselves;
423 this shall cause errors from commands associated with them to
424 be ignored in the same manner as specified by the −i option.
425 Subsequent occurrences of .IGNORE shall add to the list of
426 targets ignoring command errors. If no prerequisites are
427 specified, make shall behave as if the −i option had been
428 specified and errors from all commands associated with all
429 targets shall be ignored.
430
431 .POSIX The application shall ensure that this special target is
432 specified without prerequisites or commands. If it appears as
433 the first non-comment line in the makefile, make shall
434 process the makefile as specified by this section; otherwise,
435 the behavior of make is unspecified.
436
437 .PRECIOUS Prerequisites of this special target shall not be removed if
438 make receives one of the asynchronous events explicitly
439 described in the ASYNCHRONOUS EVENTS section. Subsequent
440 occurrences of .PRECIOUS shall add to the list of precious
441 files. If no prerequisites are specified, all targets in the
442 makefile shall be treated as if specified with .PRECIOUS.
443
444 .SCCS_GET The application shall ensure that this special target is
445 specified without prerequisites. If this special target is
446 included in a makefile, the commands specified with this tar‐
447 get shall replace the default commands associated with this
448 special target (see Default Rules). The commands specified
449 with this target are used to get all SCCS files that are not
450 found in the current directory.
451
452 When source files are named in a dependency list, make shall
453 treat them just like any other target. Because the source
454 file is presumed to be present in the directory, there is no
455 need to add an entry for it to the makefile. When a target
456 has no dependencies, but is present in the directory, make
457 shall assume that that file is up-to-date. If, however, an
458 SCCS file named SCCS/s.source_file is found for a target
459 source_file, make compares the timestamp of the target file
460 with that of the SCCS/s.source_file to ensure the target is
461 up-to-date. If the target is missing, or if the SCCS file is
462 newer, make shall automatically issue the commands specified
463 for the .SCCS_GET special target to retrieve the most recent
464 version. However, if the target is writable by anyone, make
465 shall not retrieve a new version.
466
467 .SILENT Prerequisites of this special target are targets themselves;
468 this shall cause commands associated with them not to be
469 written to the standard output before they are executed. Sub‐
470 sequent occurrences of .SILENT shall add to the list of tar‐
471 gets with silent commands. If no prerequisites are specified,
472 make shall behave as if the −s option had been specified and
473 no commands or touch messages associated with any target
474 shall be written to standard output.
475
476 .SUFFIXES Prerequisites of .SUFFIXES shall be appended to the list of
477 known suffixes and are used in conjunction with the inference
478 rules (see Inference Rules). If .SUFFIXES does not have any
479 prerequisites, the list of known suffixes shall be cleared.
480
481 The special targets .IGNORE, .POSIX, .PRECIOUS, .SILENT, and .SUFFIXES
482 shall be specified without commands.
483
484 Targets with names consisting of a leading <period> followed by the
485 uppercase letters "POSIX" and then any other characters are reserved
486 for future standardization. Targets with names consisting of a leading
487 <period> followed by one or more uppercase letters are reserved for
488 implementation extensions.
489
490 Macros
491 Macro definitions are in the form:
492
493 string1 = [string2]
494
495 The macro named string1 is defined as having the value of string2,
496 where string2 is defined as all characters, if any, after the <equals-
497 sign>, up to a comment character ('#') or an unescaped <newline>. Any
498 <blank> characters immediately before or after the <equals-sign> shall
499 be ignored.
500
501 Applications shall select macro names from the set of characters con‐
502 sisting solely of periods, underscores, digits, and alphabetics from
503 the portable character set (see the Base Definitions volume of
504 POSIX.1‐2008, Section 6.1, Portable Character Set). A macro name shall
505 not contain an <equals-sign>. Implementations may allow other charac‐
506 ters in macro names as extensions.
507
508 Macros can appear anywhere in the makefile. Macro expansions using the
509 forms $(string1) or ${string1} shall be replaced by string2, as fol‐
510 lows:
511
512 * Macros in target lines shall be evaluated when the target line is
513 read.
514
515 * Macros in makefile command lines shall be evaluated when the com‐
516 mand is executed.
517
518 * Macros in the string before the <equals-sign> in a macro definition
519 shall be evaluated when the macro assignment is made.
520
521 * Macros after the <equals-sign> in a macro definition shall not be
522 evaluated until the defined macro is used in a rule or command, or
523 before the <equals-sign> in a macro definition.
524
525 The parentheses or braces are optional if string1 is a single charac‐
526 ter. The macro $$ shall be replaced by the single character '$'. If
527 string1 in a macro expansion contains a macro expansion, the results
528 are unspecified.
529
530 Macro expansions using the forms $(string1[:subst1=[subst2]]) or
531 ${string1[:subst1=[subst2]]} can be used to replace all occurrences of
532 subst1 with subst2 when the macro substitution is performed. The subst1
533 to be replaced shall be recognized when it is a suffix at the end of a
534 word in string1 (where a word, in this context, is defined to be a
535 string delimited by the beginning of the line, a <blank>, or a <new‐
536 line>). If string1 in a macro expansion contains a macro expansion,
537 the results are unspecified.
538
539 Macro expansions in string1 of macro definition lines shall be evalu‐
540 ated when read. Macro expansions in string2 of macro definition lines
541 shall be performed when the macro identified by string1 is expanded in
542 a rule or command.
543
544 Macro definitions shall be taken from the following sources, in the
545 following logical order, before the makefile(s) are read.
546
547 1. Macros specified on the make utility command line, in the order
548 specified on the command line. It is unspecified whether the inter‐
549 nal macros defined in Internal Macros are accepted from this
550 source.
551
552 2. Macros defined by the MAKEFLAGS environment variable, in the order
553 specified in the environment variable. It is unspecified whether
554 the internal macros defined in Internal Macros are accepted from
555 this source.
556
557 3. The contents of the environment, excluding the MAKEFLAGS and SHELL
558 variables and including the variables with null values.
559
560 4. Macros defined in the inference rules built into make.
561
562 Macro definitions from these sources shall not override macro defini‐
563 tions from a lower-numbered source. Macro definitions from a single
564 source (for example, the make utility command line, the MAKEFLAGS envi‐
565 ronment variable, or the other environment variables) shall override
566 previous macro definitions from the same source.
567
568 Macros defined in the makefile(s) shall override macro definitions that
569 occur before them in the makefile(s) and macro definitions from source
570 4. If the −e option is not specified, macros defined in the makefile(s)
571 shall override macro definitions from source 3. Macros defined in the
572 makefile(s) shall not override macro definitions from source 1 or
573 source 2.
574
575 Before the makefile(s) are read, all of the make utility command line
576 options (except −f and −p) and make utility command line macro defini‐
577 tions (except any for the MAKEFLAGS macro), not already included in the
578 MAKEFLAGS macro, shall be added to the MAKEFLAGS macro, quoted in an
579 implementation-defined manner such that when MAKEFLAGS is read by
580 another instance of the make command, the original macro's value is
581 recovered. Other implementation-defined options and macros may also be
582 added to the MAKEFLAGS macro. If this modifies the value of the MAKE‐
583 FLAGS macro, or, if the MAKEFLAGS macro is modified at any subsequent
584 time, the MAKEFLAGS environment variable shall be modified to match the
585 new value of the MAKEFLAGS macro. The result of setting MAKEFLAGS in
586 the Makefile is unspecified.
587
588 Before the makefile(s) are read, all of the make utility command line
589 macro definitions (except the MAKEFLAGS macro or the SHELL macro) shall
590 be added to the environment of make. Other implementation-defined
591 variables may also be added to the environment of make.
592
593 The SHELL macro shall be treated specially. It shall be provided by
594 make and set to the pathname of the shell command language interpreter
595 (see sh). The SHELL environment variable shall not affect the value of
596 the SHELL macro. If SHELL is defined in the makefile or is specified on
597 the command line, it shall replace the original value of the SHELL
598 macro, but shall not affect the SHELL environment variable. Other
599 effects of defining SHELL in the makefile or on the command line are
600 implementation-defined.
601
602 Inference Rules
603 Inference rules are formatted as follows:
604
605 target:
606 <tab>command
607 [<tab>command]
608 ...
609
610 line that does not begin with <tab> or #
611
612 The application shall ensure that the target portion is a valid target
613 name (see Target Rules) of the form .s2 or .s1.s2 (where .s1 and .s2
614 are suffixes that have been given as prerequisites of the .SUFFIXES
615 special target and s1 and s2 do not contain any <slash> or <period>
616 characters.) If there is only one <period> in the target, it is a sin‐
617 gle-suffix inference rule. Targets with two periods are double-suffix
618 inference rules. Inference rules can have only one target before the
619 <colon>.
620
621 The application shall ensure that the makefile does not specify prereq‐
622 uisites for inference rules; no characters other than white space shall
623 follow the <colon> in the first line, except when creating the empty
624 rule, described below. Prerequisites are inferred, as described below.
625
626 Inference rules can be redefined. A target that matches an existing
627 inference rule shall overwrite the old inference rule. An empty rule
628 can be created with a command consisting of simply a <semicolon> (that
629 is, the rule still exists and is found during inference rule search,
630 but since it is empty, execution has no effect). The empty rule can
631 also be formatted as follows:
632
633 rule: ;
634
635 where zero or more <blank> characters separate the <colon> and <semi‐
636 colon>.
637
638 The make utility uses the suffixes of targets and their prerequisites
639 to infer how a target can be made up-to-date. A list of inference rules
640 defines the commands to be executed. By default, make contains a built-
641 in set of inference rules. Additional rules can be specified in the
642 makefile.
643
644 The special target .SUFFIXES contains as its prerequisites a list of
645 suffixes that shall be used by the inference rules. The order in which
646 the suffixes are specified defines the order in which the inference
647 rules for the suffixes are used. New suffixes shall be appended to the
648 current list by specifying a .SUFFIXES special target in the makefile.
649 A .SUFFIXES target with no prerequisites shall clear the list of suf‐
650 fixes. An empty .SUFFIXES target followed by a new .SUFFIXES list is
651 required to change the order of the suffixes.
652
653 Normally, the user would provide an inference rule for each suffix.
654 The inference rule to update a target with a suffix .s1 from a prereq‐
655 uisite with a suffix .s2 is specified as a target .s2.s1. The internal
656 macros provide the means to specify general inference rules (see Inter‐
657 nal Macros).
658
659 When no target rule is found to update a target, the inference rules
660 shall be checked. The suffix of the target (.s1) to be built is com‐
661 pared to the list of suffixes specified by the .SUFFIXES special tar‐
662 gets. If the .s1 suffix is found in .SUFFIXES, the inference rules
663 shall be searched in the order defined for the first .s2.s1 rule whose
664 prerequisite file ($*.s2) exists. If the target is out-of-date with
665 respect to this prerequisite, the commands for that inference rule
666 shall be executed.
667
668 If the target to be built does not contain a suffix and there is no
669 rule for the target, the single suffix inference rules shall be
670 checked. The single-suffix inference rules define how to build a target
671 if a file is found with a name that matches the target name with one of
672 the single suffixes appended. A rule with one suffix .s2 is the defini‐
673 tion of how to build target from target.s2. The other suffix (.s1) is
674 treated as null.
675
676 A <tilde> ('~') in the above rules refers to an SCCS file in the cur‐
677 rent directory. Thus, the rule .c~.o would transform an SCCS C-lan‐
678 guage source file into an object file (.o). Because the s. of the
679 SCCS files is a prefix, it is incompatible with make's suffix point of
680 view. Hence, the '~' is a way of changing any file reference into an
681 SCCS file reference.
682
683 Libraries
684 If a target or prerequisite contains parentheses, it shall be treated
685 as a member of an archive library. For the lib(member.o) expression lib
686 refers to the name of the archive library and member.o to the member
687 name. The application shall ensure that the member is an object file
688 with the .o suffix. The modification time of the expression is the mod‐
689 ification time for the member as kept in the archive library; see ar.
690 The .a suffix shall refer to an archive library. The .s2.a rule shall
691 be used to update a member in the library from a file with a suffix
692 .s2.
693
694 Internal Macros
695 The make utility shall maintain five internal macros that can be used
696 in target and inference rules. In order to clearly define the meaning
697 of these macros, some clarification of the terms target rule, inference
698 rule, target, and prerequisite is necessary.
699
700 Target rules are specified by the user in a makefile for a particular
701 target. Inference rules are user-specified or make-specified rules for
702 a particular class of target name. Explicit prerequisites are those
703 prerequisites specified in a makefile on target lines. Implicit pre‐
704 requisites are those prerequisites that are generated when inference
705 rules are used. Inference rules are applied to implicit prerequisites
706 or to explicit prerequisites that do not have target rules defined for
707 them in the makefile. Target rules are applied to targets specified in
708 the makefile.
709
710 Before any target in the makefile is updated, each of its prerequisites
711 (both explicit and implicit) shall be updated. This shall be accom‐
712 plished by recursively processing each prerequisite. Upon recursion,
713 each prerequisite shall become a target itself. Its prerequisites in
714 turn shall be processed recursively until a target is found that has no
715 prerequisites, at which point the recursion stops. The recursion shall
716 then back up, updating each target as it goes.
717
718 In the definitions that follow, the word target refers to one of:
719
720 * A target specified in the makefile
721
722 * An explicit prerequisite specified in the makefile that becomes the
723 target when make processes it during recursion
724
725 * An implicit prerequisite that becomes a target when make processes
726 it during recursion
727
728 In the definitions that follow, the word prerequisite refers to one of
729 the following:
730
731 * An explicit prerequisite specified in the makefile for a particular
732 target
733
734 * An implicit prerequisite generated as a result of locating an
735 appropriate inference rule and corresponding file that matches the
736 suffix of the target
737
738 The five internal macros are:
739
740 $@ The $@ shall evaluate to the full target name of the current
741 target, or the archive filename part of a library archive tar‐
742 get. It shall be evaluated for both target and inference rules.
743
744 For example, in the .c.a inference rule, $@ represents the out-
745 of-date .a file to be built. Similarly, in a makefile target
746 rule to build lib.a from file.c, $@ represents the out-of-date
747 lib.a.
748
749 $% The $% macro shall be evaluated only when the current target is
750 an archive library member of the form libname(member.o). In
751 these cases, $@ shall evaluate to libname and $% shall evaluate
752 to member.o. The $% macro shall be evaluated for both target
753 and inference rules.
754
755 For example, in a makefile target rule to build lib.a(file.o),
756 $% represents file.o, as opposed to $@, which represents lib.a.
757
758 $? The $? macro shall evaluate to the list of prerequisites that
759 are newer than the current target. It shall be evaluated for
760 both target and inference rules.
761
762 For example, in a makefile target rule to build prog from
763 file1.o, file2.o, and file3.o, and where prog is not out-of-
764 date with respect to file1.o, but is out-of-date with respect
765 to file2.o and file3.o, $? represents file2.o and file3.o.
766
767 $< In an inference rule, the $< macro shall evaluate to the file‐
768 name whose existence allowed the inference rule to be chosen
769 for the target. In the .DEFAULT rule, the $< macro shall eval‐
770 uate to the current target name. The meaning of the $< macro
771 shall be otherwise unspecified.
772
773 For example, in the .c.a inference rule, $< represents the pre‐
774 requisite .c file.
775
776 $* The $* macro shall evaluate to the current target name with its
777 suffix deleted. It shall be evaluated at least for inference
778 rules.
779
780 For example, in the .c.a inference rule, $*.o represents the
781 out-of-date .o file that corresponds to the prerequisite .c
782 file.
783
784 Each of the internal macros has an alternative form. When an uppercase
785 'D' or 'F' is appended to any of the macros, the meaning shall be
786 changed to the directory part for 'D' and filename part for 'F'. The
787 directory part is the path prefix of the file without a trailing
788 <slash>; for the current directory, the directory part is '.'. When
789 the $? macro contains more than one prerequisite filename, the $(?D)
790 and $(?F) (or ${?D} and ${?F}) macros expand to a list of directory
791 name parts and filename parts respectively.
792
793 For the target lib(member.o) and the s2.a rule, the internal macros
794 shall be defined as:
795
796 $< member.s2
797
798 $* member
799
800 $@ lib
801
802 $? member.s2
803
804 $% member.o
805
806 Default Rules
807 The default rules for make shall achieve results that are the same as
808 if the following were used. Implementations that do not support the C-
809 Language Development Utilities option may omit CC, CFLAGS, YACC,
810 YFLAGS, LEX, LFLAGS, LDFLAGS, and the .c, .y, and .l inference rules.
811 Implementations that do not support FORTRAN may omit FC, FFLAGS, and
812 the .f inference rules. Implementations may provide additional macros
813 and rules.
814
815 SPECIAL TARGETS
816
817 .SCCS_GET: sccs $(SCCSFLAGS) get $(SCCSGETFLAGS) $@
818
819 .SUFFIXES: .o .c .y .l .a .sh .f .c~ .y~ .l~ .sh~ .f~
820
821 MACROS
822
823 MAKE=make
824 AR=ar
825 ARFLAGS=−rv
826 YACC=yacc
827 YFLAGS=
828 LEX=lex
829 LFLAGS=
830 LDFLAGS=
831 CC=c99
832 CFLAGS=−O
833 FC=fort77
834 FFLAGS=−O 1
835 GET=get
836 GFLAGS=
837 SCCSFLAGS=
838 SCCSGETFLAGS=−s
839
840 SINGLE SUFFIX RULES
841
842 .c:
843 $(CC) $(CFLAGS) $(LDFLAGS) −o $@ $<
844
845 .f:
846 $(FC) $(FFLAGS) $(LDFLAGS) −o $@ $<
847
848 .sh:
849 cp $< $@
850 chmod a+x $@
851
852 .c~:
853 $(GET) $(GFLAGS) −p $< > $*.c
854 $(CC) $(CFLAGS) $(LDFLAGS) −o $@ $*.c
855
856 .f~:
857 $(GET) $(GFLAGS) −p $< > $*.f
858 $(FC) $(FFLAGS) $(LDFLAGS) −o $@ $*.f
859
860 .sh~:
861 $(GET) $(GFLAGS) −p $< > $*.sh
862 cp $*.sh $@
863 chmod a+x $@
864
865 DOUBLE SUFFIX RULES
866
867 .c.o:
868 $(CC) $(CFLAGS) −c $<
869
870 .f.o:
871 $(FC) $(FFLAGS) −c $<
872
873 .y.o:
874 $(YACC) $(YFLAGS) $<
875 $(CC) $(CFLAGS) −c y.tab.c
876 rm −f y.tab.c
877 mv y.tab.o $@
878
879 .l.o:
880 $(LEX) $(LFLAGS) $<
881 $(CC) $(CFLAGS) −c lex.yy.c
882 rm −f lex.yy.c
883 mv lex.yy.o $@
884
885 .y.c:
886 $(YACC) $(YFLAGS) $<
887 mv y.tab.c $@
888
889 .l.c:
890 $(LEX) $(LFLAGS) $<
891 mv lex.yy.c $@
892
893 .c~.o:
894 $(GET) $(GFLAGS) −p $< > $*.c
895 $(CC) $(CFLAGS) −c $*.c
896
897 .f~.o:
898 $(GET) $(GFLAGS) −p $< > $*.f
899 $(FC) $(FFLAGS) −c $*.f
900
901 .y~.o:
902 $(GET) $(GFLAGS) −p $< > $*.y
903 $(YACC) $(YFLAGS) $*.y
904 $(CC) $(CFLAGS) −c y.tab.c
905 rm −f y.tab.c
906 mv y.tab.o $@
907
908 .l~.o:
909 $(GET) $(GFLAGS) −p $< > $*.l
910 $(LEX) $(LFLAGS) $*.l
911 $(CC) $(CFLAGS) −c lex.yy.c
912 rm −f lex.yy.c
913 mv lex.yy.o $@
914
915 .y~.c:
916 $(GET) $(GFLAGS) −p $< > $*.y
917 $(YACC) $(YFLAGS) $*.y
918 mv y.tab.c $@
919
920 .l~.c:
921 $(GET) $(GFLAGS) −p $< > $*.l
922 $(LEX) $(LFLAGS) $*.l
923 mv lex.yy.c $@
924
925 .c.a:
926 $(CC) −c $(CFLAGS) $<
927 $(AR) $(ARFLAGS) $@ $*.o
928 rm −f $*.o
929
930 .f.a:
931 $(FC) −c $(FFLAGS) $<
932 $(AR) $(ARFLAGS) $@ $*.o
933 rm −f $*.o
934
936 When the −q option is specified, the make utility shall exit with one
937 of the following values:
938
939 0 Successful completion.
940
941 1 The target was not up-to-date.
942
943 >1 An error occurred.
944
945 When the −q option is not specified, the make utility shall exit with
946 one of the following values:
947
948 0 Successful completion.
949
950 >0 An error occurred.
951
953 Default.
954
955 The following sections are informative.
956
958 If there is a source file (such as ./source.c) and there are two SCCS
959 files corresponding to it (./s.source.c and ./SCCS/s.source.c), on XSI-
960 conformant systems make uses the SCCS file in the current directory.
961 However, users are advised to use the underlying SCCS utilities (admin,
962 delta, get, and so on) or the sccs utility for all source files in a
963 given directory. If both forms are used for a given source file, future
964 developers are very likely to be confused.
965
966 It is incumbent upon portable makefiles to specify the .POSIX special
967 target in order to guarantee that they are not affected by local exten‐
968 sions.
969
970 The −k and −S options are both present so that the relationship between
971 the command line, the MAKEFLAGS variable, and the makefile can be con‐
972 trolled precisely. If the k flag is passed in MAKEFLAGS and a command
973 is of the form:
974
975 $(MAKE) −S foo
976
977 then the default behavior is restored for the child make.
978
979 When the −n option is specified, it is always added to MAKEFLAGS. This
980 allows a recursive make −n target to be used to see all of the action
981 that would be taken to update target.
982
983 Because of widespread historical practice, interpreting a <number-sign>
984 ('#') inside a variable as the start of a comment has the unfortunate
985 side-effect of making it impossible to place a <number-sign> in a vari‐
986 able, thus forbidding something like:
987
988 CFLAGS = "−D COMMENT_CHAR='#'"
989
990 Many historical make utilities stop chaining together inference rules
991 when an intermediate target is nonexistent. For example, it might be
992 possible for a make to determine that both .y.c and .c.o could be used
993 to convert a .y to a .o. Instead, in this case, make requires the use
994 of a .y.o rule.
995
996 The best way to provide portable makefiles is to include all of the
997 rules needed in the makefile itself. The rules provided use only fea‐
998 tures provided by other parts of this volume of POSIX.1‐2008. The
999 default rules include rules for optional commands in this volume of
1000 POSIX.1‐2008. Only rules pertaining to commands that are provided are
1001 needed in an implementation's default set.
1002
1003 Macros used within other macros are evaluated when the new macro is
1004 used rather than when the new macro is defined. Therefore:
1005
1006 MACRO = value1
1007 NEW = $(MACRO)
1008 MACRO = value2
1009
1010 target:
1011 echo $(NEW)
1012
1013 would produce value2 and not value1 since NEW was not expanded until it
1014 was needed in the echo command line.
1015
1016 Some historical applications have been known to intermix target_name
1017 and macro=name operands on the command line, expecting that all of the
1018 macros are processed before any of the targets are dealt with. Conform‐
1019 ing applications do not do this, although some backwards-compatibility
1020 support may be included in some implementations.
1021
1022 The following characters in filenames may give trouble: '=', ':', '`',
1023 single-quote, and '@'. In include filenames, pattern matching charac‐
1024 ters and '"' should also be avoided, as they may be treated as special
1025 by some implementations.
1026
1027 For inference rules, the description of $< and $? seem similar. How‐
1028 ever, an example shows the minor difference. In a makefile containing:
1029
1030 foo.o: foo.h
1031
1032 if foo.h is newer than foo.o, yet foo.c is older than foo.o, the built-
1033 in rule to make foo.o from foo.c is used, with $< equal to foo.c and $?
1034 equal to foo.h. If foo.c is also newer than foo.o, $< is equal to
1035 foo.c and $? is equal to foo.h foo.c.
1036
1038 1. The following command:
1039
1040 make
1041
1042 makes the first target found in the makefile.
1043
1044 2. The following command:
1045
1046 make junk
1047
1048 makes the target junk.
1049
1050 3. The following makefile says that pgm depends on two files, a.o and
1051 b.o, and that they in turn depend on their corresponding source
1052 files (a.c and b.c), and a common file incl.h:
1053
1054 pgm: a.o b.o
1055 c99 a.o b.o −o pgm
1056 a.o: incl.h a.c
1057 c99 −c a.c
1058 b.o: incl.h b.c
1059 c99 −c b.c
1060
1061 4. An example for making optimized .o files from .c files is:
1062
1063 .c.o:
1064 c99 −c −O $*.c
1065
1066 or:
1067
1068 .c.o:
1069 c99 −c −O $<
1070
1071 5. The most common use of the archive interface follows. Here, it is
1072 assumed that the source files are all C-language source:
1073
1074 lib: lib(file1.o) lib(file2.o) lib(file3.o)
1075 @echo lib is now up-to-date
1076
1077 The .c.a rule is used to make file1.o, file2.o, and file3.o and
1078 insert them into lib.
1079
1080 The treatment of escaped <newline> characters throughout the make‐
1081 file is historical practice. For example, the inference rule:
1082
1083 .c.o\
1084 :
1085
1086 works, and the macro:
1087
1088 f= bar baz\
1089 biz
1090 a:
1091 echo ==$f==
1092
1093 echoes "==bar baz biz==".
1094
1095 If $? were:
1096
1097 /usr/include/stdio.h /usr/include/unistd.h foo.h
1098
1099 then $(?D) would be:
1100
1101 /usr/include /usr/include .
1102
1103 and $(?F) would be:
1104
1105 stdio.h unistd.h foo.h
1106
1107 6. The contents of the built-in rules can be viewed by running:
1108
1109 make −p −f /dev/null 2>/dev/null
1110
1112 The make utility described in this volume of POSIX.1‐2008 is intended
1113 to provide the means for changing portable source code into executables
1114 that can be run on an POSIX.1‐2008-conforming system. It reflects the
1115 most common features present in System V and BSD makes.
1116
1117 Historically, the make utility has been an especially fertile ground
1118 for vendor and research organization-specific syntax modifications and
1119 extensions. Examples include:
1120
1121 * Syntax supporting parallel execution (such as from various multi-
1122 processor vendors, GNU, and others)
1123
1124 * Additional ``operators'' separating targets and their prerequisites
1125 (System V, BSD, and others)
1126
1127 * Specifying that command lines containing the strings "${MAKE}" and
1128 "$(MAKE)" are executed when the −n option is specified (GNU and
1129 System V)
1130
1131 * Modifications of the meaning of internal macros when referencing
1132 libraries (BSD and others)
1133
1134 * Using a single instance of the shell for all of the command lines
1135 of the target (BSD and others)
1136
1137 * Allowing <space> characters as well as <tab> characters to delimit
1138 command lines (BSD)
1139
1140 * Adding C preprocessor-style ``include'' and ``ifdef'' constructs
1141 (System V, GNU, BSD, and others)
1142
1143 * Remote execution of command lines (Sprite and others)
1144
1145 * Specifying additional special targets (BSD, System V, and most oth‐
1146 ers)
1147
1148 Additionally, many vendors and research organizations have rethought
1149 the basic concepts of make, creating vastly extended, as well as com‐
1150 pletely new, syntaxes. Each of these versions of make fulfills the
1151 needs of a different community of users; it is unreasonable for this
1152 volume of POSIX.1‐2008 to require behavior that would be incompatible
1153 (and probably inferior) to historical practice for such a community.
1154
1155 In similar circumstances, when the industry has enough sufficiently
1156 incompatible formats as to make them irreconcilable, this volume of
1157 POSIX.1‐2008 has followed one or both of two courses of action. Com‐
1158 mands have been renamed (cksum, echo, and pax) and/or command line
1159 options have been provided to select the desired behavior (grep, od,
1160 and pax).
1161
1162 Because the syntax specified for the make utility is, by and large, a
1163 subset of the syntaxes accepted by almost all versions of make, it was
1164 decided that it would be counter-productive to change the name. And
1165 since the makefile itself is a basic unit of portability, it would not
1166 be completely effective to reserve a new option letter, such as make
1167 −P, to achieve the portable behavior. Therefore, the special target
1168 .POSIX was added to the makefile, allowing users to specify ``stan‐
1169 dard'' behavior. This special target does not preclude extensions in
1170 the make utility, nor does it preclude such extensions being used by
1171 the makefile specifying the target; it does, however, preclude any
1172 extensions from being applied that could alter the behavior of previ‐
1173 ously valid syntax; such extensions must be controlled via command line
1174 options or new special targets. It is incumbent upon portable makefiles
1175 to specify the .POSIX special target in order to guarantee that they
1176 are not affected by local extensions.
1177
1178 The portable version of make described in this reference page is not
1179 intended to be the state-of-the-art software generation tool and, as
1180 such, some newer and more leading-edge features have not been included.
1181 An attempt has been made to describe the portable makefile in a manner
1182 that does not preclude such extensions as long as they do not disturb
1183 the portable behavior described here.
1184
1185 When the −n option is specified, it is always added to MAKEFLAGS. This
1186 allows a recursive make −n target to be used to see all of the action
1187 that would be taken to update target.
1188
1189 The definition of MAKEFLAGS allows both the System V letter string and
1190 the BSD command line formats. The two formats are sufficiently differ‐
1191 ent to allow implementations to support both without ambiguity.
1192
1193 Early proposals stated that an ``unquoted'' <number-sign> was treated
1194 as the start of a comment. The make utility does not pay any attention
1195 to quotes. A <number-sign> starts a comment regardless of its surround‐
1196 ings.
1197
1198 The text about ``other implementation-defined pathnames may also be
1199 tried'' in addition to ./makefile and ./Makefile is to allow such
1200 extensions as SCCS/s.Makefile and other variations. It was made an
1201 implementation-defined requirement (as opposed to unspecified behavior)
1202 to highlight surprising implementations that might select something
1203 unexpected like /etc/Makefile. XSI-conformant systems also try
1204 ./s.makefile, SCCS/s.makefile, ./s.Makefile, and SCCS/s.Makefile.
1205
1206 Early proposals contained the macro NPROC as a means of specifying that
1207 make should use n processes to do the work required. While this feature
1208 is a valuable extension for many systems, it is not common usage and
1209 could require other non-trivial extensions to makefile syntax. This
1210 extension is not required by this volume of POSIX.1‐2008, but could be
1211 provided as a compatible extension. The macro PARALLEL is used by some
1212 historical systems with essentially the same meaning (but without using
1213 a name that is a common system limit value). It is suggested that
1214 implementors recognize the existing use of NPROC and/or PARALLEL as
1215 extensions to make.
1216
1217 The default rules are based on System V. The default CC= value is c99
1218 instead of cc because this volume of POSIX.1‐2008 does not standardize
1219 the utility named cc. Thus, every conforming application would be
1220 required to define CC=c99 to expect to run. There is no advantage con‐
1221 ferred by the hope that the makefile might hit the ``preferred'' com‐
1222 piler because this cannot be guaranteed to work. Also, since the porta‐
1223 ble makescript can only use the c99 options, no advantage is conferred
1224 in terms of what the script can do. It is a quality-of-implementation
1225 issue as to whether c99 is as valuable as cc.
1226
1227 The −d option to make is frequently used to produce debugging informa‐
1228 tion, but is too implementation-defined to add to this volume of
1229 POSIX.1‐2008.
1230
1231 The −p option is not passed in MAKEFLAGS on most historical implementa‐
1232 tions and to change this would cause many implementations to break
1233 without sufficiently increased portability.
1234
1235 Commands that begin with a <plus-sign> ('+') are executed even if the
1236 −n option is present. Based on the GNU version of make, the behavior of
1237 −n when the <plus-sign> prefix is encountered has been extended to
1238 apply to −q and −t as well. However, the System V convention of forcing
1239 command execution with −n when the command line of a target contains
1240 either of the strings "$(MAKE)" or "${MAKE}" has not been adopted. This
1241 functionality appeared in early proposals, but the danger of this
1242 approach was pointed out with the following example of a portion of a
1243 makefile:
1244
1245 subdir:
1246 cd subdir; rm all_the_files; $(MAKE)
1247
1248 The loss of the System V behavior in this case is well-balanced by the
1249 safety afforded to other makefiles that were not aware of this situa‐
1250 tion. In any event, the command line <plus-sign> prefix can provide the
1251 desired functionality.
1252
1253 The double <colon> in the target rule format is supported in BSD sys‐
1254 tems to allow more than one target line containing the same target name
1255 to have commands associated with it. Since this is not functionality
1256 described in the SVID or XPG3 it has been allowed as an extension, but
1257 not mandated.
1258
1259 The default rules are provided with text specifying that the built-in
1260 rules shall be the same as if the listed set were used. The intent is
1261 that implementations should be able to use the rules without change,
1262 but will be allowed to alter them in ways that do not affect the pri‐
1263 mary behavior.
1264
1265 The best way to provide portable makefiles is to include all of the
1266 rules needed in the makefile itself. The rules provided use only fea‐
1267 tures provided by other portions of this volume of POSIX.1‐2008. The
1268 default rules include rules for optional commands in this volume of
1269 POSIX.1‐2008. Only rules pertaining to commands that are provided are
1270 needed in the default set of an implementation.
1271
1272 One point of discussion was whether to drop the default rules list from
1273 this volume of POSIX.1‐2008. They provide convenience, but do not
1274 enhance portability of applications. The prime benefit is in portabil‐
1275 ity of users who wish to type make command and have the command build
1276 from a command.c file.
1277
1278 The historical MAKESHELL feature was omitted. In some implementations
1279 it is used to let a user override the shell to be used to run make com‐
1280 mands. This was confusing; for a portable make, the shell should be
1281 chosen by the makefile writer or specified on the make command line and
1282 not by a user running make.
1283
1284 The make utilities in most historical implementations process the pre‐
1285 requisites of a target in left-to-right order, and the makefile format
1286 requires this. It supports the standard idiom used in many makefiles
1287 that produce yacc programs; for example:
1288
1289 foo: y.tab.o lex.o main.o
1290 $(CC) $(CFLAGS) −o $@ t.tab.o lex.o main.o
1291
1292 In this example, if make chose any arbitrary order, the lex.o might not
1293 be made with the correct y.tab.h. Although there may be better ways to
1294 express this relationship, it is widely used historically. Implementa‐
1295 tions that desire to update prerequisites in parallel should require an
1296 explicit extension to make or the makefile format to accomplish it, as
1297 described previously.
1298
1299 The algorithm for determining a new entry for target rules is partially
1300 unspecified. Some historical makes allow blank, empty, or comment lines
1301 within the collection of commands marked by leading <tab> characters. A
1302 conforming makefile must ensure that each command starts with a <tab>,
1303 but implementations are free to ignore blank, empty, and comment lines
1304 without triggering the start of a new entry.
1305
1306 The ASYNCHRONOUS EVENTS section includes having SIGTERM and SIGHUP,
1307 along with the more traditional SIGINT and SIGQUIT, remove the current
1308 target unless directed not to do so. SIGTERM and SIGHUP were added to
1309 parallel other utilities that have historically cleaned up their work
1310 as a result of these signals. When make receives any signal other than
1311 SIGQUIT, it is required to resend itself the signal it received so that
1312 it exits with a status that reflects the signal. The results from
1313 SIGQUIT are partially unspecified because, on systems that create core
1314 files upon receipt of SIGQUIT, the core from make would conflict with a
1315 core file from the command that was running when the SIGQUIT arrived.
1316 The main concern was to prevent damaged files from appearing up-to-date
1317 when make is rerun.
1318
1319 The .PRECIOUS special target was extended to affect all targets glob‐
1320 ally (by specifying no prerequisites). The .IGNORE and .SILENT special
1321 targets were extended to allow prerequisites; it was judged to be more
1322 useful in some cases to be able to turn off errors or echoing for a
1323 list of targets than for the entire makefile. These extensions to make
1324 in System V were made to match historical practice from the BSD make.
1325
1326 Macros are not exported to the environment of commands to be run. This
1327 was never the case in any historical make and would have serious conse‐
1328 quences. The environment is the same as the environment to make except
1329 that MAKEFLAGS and macros defined on the make command line are added.
1330
1331 Some implementations do not use system() for all command lines, as
1332 required by the portable makefile format; as a performance enhancement,
1333 they select lines without shell metacharacters for direct execution by
1334 execve(). There is no requirement that system() be used specifically,
1335 but merely that the same results be achieved. The metacharacters typi‐
1336 cally used to bypass the direct execve() execution have been any of:
1337
1338 = | ^ ( ) ; & < > * ? [ ] : $ ` ' " \ \n
1339
1340 The default in some advanced versions of make is to group all the com‐
1341 mand lines for a target and execute them using a single shell invoca‐
1342 tion; the System V method is to pass each line individually to a sepa‐
1343 rate shell. The single-shell method has the advantages in performance
1344 and the lack of a requirement for many continued lines. However, con‐
1345 verting to this newer method has caused portability problems with many
1346 historical makefiles, so the behavior with the POSIX makefile is speci‐
1347 fied to be the same as that of System V. It is suggested that the spe‐
1348 cial target .ONESHELL be used as an implementation extension to achieve
1349 the single-shell grouping for a target or group of targets.
1350
1351 Novice users of make have had difficulty with the historical need to
1352 start commands with a <tab>. Since it is often difficult to discern
1353 differences between <tab> and <space> characters on terminals or
1354 printed listings, confusing bugs can arise. In early proposals, an
1355 attempt was made to correct this problem by allowing leading <blank>
1356 characters instead of <tab> characters. However, implementors reported
1357 many makefiles that failed in subtle ways following this change, and it
1358 is difficult to implement a make that unambiguously can differentiate
1359 between macro and command lines. There is extensive historical prac‐
1360 tice of allowing leading <space> characters before macro definitions.
1361 Forcing macro lines into column 1 would be a significant backwards-com‐
1362 patibility problem for some makefiles. Therefore, historical practice
1363 was restored.
1364
1365 There is substantial variation in the handling of include lines by dif‐
1366 ferent implementations. However, there is enough commonality for the
1367 standard to be able to specify a minimum set of requirements that allow
1368 the feature to be used portably. Known variations have been explicitly
1369 called out as unspecified behavior in the description.
1370
1371 The System V dynamic dependency feature was not included. It would sup‐
1372 port:
1373
1374 cat: $$@.c
1375
1376 that would expand to;
1377
1378 cat: cat.c
1379
1380 This feature exists only in the new version of System V make and, while
1381 useful, is not in wide usage. This means that macros are expanded twice
1382 for prerequisites: once at makefile parse time and once at target
1383 update time.
1384
1385 Consideration was given to adding metarules to the POSIX make. This
1386 would make %.o: %.c the same as .c.o:. This is quite useful and avail‐
1387 able from some vendors, but it would cause too many changes to this
1388 make to support. It would have introduced rule chaining and new substi‐
1389 tution rules. However, the rules for target names have been set to
1390 reserve the '%' and '"' characters. These are traditionally used to
1391 implement metarules and quoting of target names, respectively. Imple‐
1392 mentors are strongly encouraged to use these characters only for these
1393 purposes.
1394
1395 A request was made to extend the suffix delimiter character from a
1396 <period> to any character. The metarules feature in newer makes solves
1397 this problem in a more general way. This volume of POSIX.1‐2008 is
1398 staying with the more conservative historical definition.
1399
1400 The standard output format for the −p option is not described because
1401 it is primarily a debugging option and because the format is not gener‐
1402 ally useful to programs. In historical implementations the output is
1403 not suitable for use in generating makefiles. The −p format has been
1404 variable across historical implementations. Therefore, the definition
1405 of −p was only to provide a consistently named option for obtaining
1406 make script debugging information.
1407
1408 Some historical implementations have not cleared the suffix list with
1409 −r.
1410
1411 Implementations should be aware that some historical applications have
1412 intermixed target_name and macro=value operands on the command line,
1413 expecting that all of the macros are processed before any of the tar‐
1414 gets are dealt with. Conforming applications do not do this, but some
1415 backwards-compatibility support may be warranted.
1416
1417 Empty inference rules are specified with a <semicolon> command rather
1418 than omitting all commands, as described in an early proposal. The lat‐
1419 ter case has no traditional meaning and is reserved for implementation
1420 extensions, such as in GNU make.
1421
1423 None.
1424
1426 Chapter 2, Shell Command Language, ar, c99, get, lex, sccs, sh, yacc
1427
1428 The Base Definitions volume of POSIX.1‐2008, Section 6.1, Portable
1429 Character Set, Chapter 8, Environment Variables, Section 12.2, Utility
1430 Syntax Guidelines
1431
1432 The System Interfaces volume of POSIX.1‐2008, exec, system()
1433
1435 Portions of this text are reprinted and reproduced in electronic form
1436 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
1437 -- Portable Operating System Interface (POSIX), The Open Group Base
1438 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
1439 cal and Electronics Engineers, Inc and The Open Group. (This is
1440 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
1441 event of any discrepancy between this version and the original IEEE and
1442 The Open Group Standard, the original IEEE and The Open Group Standard
1443 is the referee document. The original Standard can be obtained online
1444 at http://www.unix.org/online.html .
1445
1446 Any typographical or formatting errors that appear in this page are
1447 most likely to have been introduced during the conversion of the source
1448 files to man page format. To report such errors, see https://www.ker‐
1449 nel.org/doc/man-pages/reporting_bugs.html .
1450
1451
1452
1453IEEE/The Open Group 2013 MAKE(1P)