logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

make.1p (71589B)


  1. '\" et
  2. .TH MAKE "1P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. make
  12. \(em maintain, update, and regenerate groups of programs
  13. (\fBDEVELOPMENT\fP)
  14. .SH SYNOPSIS
  15. .LP
  16. .nf
  17. make \fB[\fR-einpqrst\fB] [\fR-f \fImakefile\fB]\fR... \fB[\fR-k|-S\fB] [\fImacro\fR=\fIvalue\fR...\fB]
  18. \fB[\fItarget_name\fR...\fB]\fR
  19. .fi
  20. .SH DESCRIPTION
  21. The
  22. .IR make
  23. utility shall update files that are derived from other files. A typical
  24. case is one where object files are derived from the corresponding
  25. source files. The
  26. .IR make
  27. utility examines time relationships and shall update those derived files
  28. (called targets) that have modified times earlier than the modified
  29. times of the files (called prerequisites) from which they are derived.
  30. A description file (makefile) contains a description of the
  31. relationships between files, and the commands that need to be executed
  32. to update the targets to reflect changes in their prerequisites. Each
  33. specification, or rule, shall consist of a target, optional
  34. prerequisites, and optional commands to be executed when a prerequisite
  35. is newer than the target. There are two types of rule:
  36. .IP " 1." 4
  37. \fIInference rules\fP,
  38. which have one target name with at least one
  39. <period>
  40. (\c
  41. .BR '.' )
  42. and no
  43. <slash>
  44. (\c
  45. .BR '/' )
  46. .IP " 2." 4
  47. \fITarget rules\fP,
  48. which can have more than one target name
  49. .P
  50. In addition,
  51. .IR make
  52. shall have a collection of built-in macros and inference rules that
  53. infer prerequisite relationships to simplify maintenance of programs.
  54. .P
  55. To receive exactly the behavior described in this section, the
  56. user shall ensure that a portable makefile shall:
  57. .IP " *" 4
  58. Include the special target
  59. .BR .POSIX
  60. .IP " *" 4
  61. Omit any special target reserved for implementations (a leading period
  62. followed by uppercase letters) that has not been specified by this
  63. section
  64. .P
  65. The behavior of
  66. .IR make
  67. is unspecified if either or both of these conditions are not met.
  68. .SH OPTIONS
  69. The
  70. .IR make
  71. utility shall conform to the Base Definitions volume of POSIX.1\(hy2017,
  72. .IR "Section 12.2" ", " "Utility Syntax Guidelines",
  73. except for Guideline 9.
  74. .P
  75. The following options shall be supported:
  76. .IP "\fB\-e\fP" 10
  77. Cause environment variables, including those with null values, to
  78. override macro assignments within makefiles.
  79. .IP "\fB\-f\ \fImakefile\fR" 10
  80. Specify a different makefile. The argument
  81. .IR makefile
  82. is a pathname of a description file, which is also referred to as the
  83. .IR makefile .
  84. A pathname of
  85. .BR '\-'
  86. shall denote the standard input. There can be multiple instances of
  87. this option, and they shall be processed in the order specified. The
  88. effect of specifying the same option-argument more than once is
  89. unspecified.
  90. .IP "\fB\-i\fP" 10
  91. Ignore error codes returned by invoked commands. This mode is the same
  92. as if the special target
  93. .BR .IGNORE
  94. were specified without prerequisites.
  95. .IP "\fB\-k\fP" 10
  96. Continue to update other targets that do not depend on the current
  97. target if a non-ignored error occurs while executing the commands to
  98. bring a target up-to-date.
  99. .IP "\fB\-n\fP" 10
  100. Write commands that would be executed on standard output, but do not
  101. execute them. However, lines with a
  102. <plus-sign>
  103. (\c
  104. .BR '\(pl' )
  105. prefix shall be executed. In this mode, lines with an at-sign (\c
  106. .BR '@' )
  107. character prefix shall be written to standard output.
  108. .IP "\fB\-p\fP" 10
  109. Write to standard output the complete set of macro definitions and
  110. target descriptions. The output format is unspecified.
  111. .IP "\fB\-q\fP" 10
  112. Return a zero exit value if the target file is up-to-date; otherwise,
  113. return an exit value of 1. Targets shall not be updated if this option
  114. is specified. However, a makefile command line (associated with the
  115. targets) with a
  116. <plus-sign>
  117. (\c
  118. .BR '\(pl' )
  119. prefix shall be executed.
  120. .IP "\fB\-r\fP" 10
  121. Clear the suffix list and do not use the built-in rules.
  122. .IP "\fB\-S\fP" 10
  123. Terminate
  124. .IR make
  125. if an error occurs while executing the commands to bring a target
  126. up-to-date. This shall be the default and the opposite of
  127. .BR \-k .
  128. .IP "\fB\-s\fP" 10
  129. Do not write makefile command lines or touch messages (see
  130. .BR \-t )
  131. to standard output before executing. This mode shall be the same as if
  132. the special target
  133. .BR .SILENT
  134. were specified without prerequisites.
  135. .IP "\fB\-t\fP" 10
  136. Update the modification time of each target as though a
  137. .IR touch
  138. .IR target
  139. had been executed. Targets that have prerequisites but no commands (see
  140. .IR "Target Rules"),
  141. or that are already up-to-date, shall not be touched in this manner.
  142. Write messages to standard output for each target file indicating the
  143. name of the file and that it was touched. Normally, the
  144. .IR makefile
  145. command lines associated with each target are not executed. However, a
  146. command line with a
  147. <plus-sign>
  148. (\c
  149. .BR '\(pl' )
  150. prefix shall be executed.
  151. .P
  152. Any options specified in the
  153. .IR MAKEFLAGS
  154. environment variable shall be evaluated before any options specified on
  155. the
  156. .IR make
  157. utility command line. If the
  158. .BR \-k
  159. and
  160. .BR \-S
  161. options are both specified on the
  162. .IR make
  163. utility command line or by the
  164. .IR MAKEFLAGS
  165. environment variable, the last option specified shall take precedence.
  166. If the
  167. .BR \-f
  168. or
  169. .BR \-p
  170. options appear in the
  171. .IR MAKEFLAGS
  172. environment variable, the result is undefined.
  173. .SH OPERANDS
  174. The following operands shall be supported:
  175. .IP "\fItarget_name\fR" 10
  176. Target names, as defined in the EXTENDED DESCRIPTION section. If no
  177. target is specified, while
  178. .IR make
  179. is processing the makefiles, the first target that
  180. .IR make
  181. encounters that is not a special target or an inference rule shall be
  182. used.
  183. .IP "\fImacro\fR=\fIvalue\fR" 10
  184. Macro definitions, as defined in
  185. .IR "Macros".
  186. .P
  187. If the
  188. .IR target_name
  189. and
  190. .IR macro =\c
  191. .IR value
  192. operands are intermixed on the
  193. .IR make
  194. utility command line, the results are unspecified.
  195. .SH STDIN
  196. The standard input shall be used only if the
  197. .IR makefile
  198. option-argument is
  199. .BR '\-' .
  200. See the INPUT FILES section.
  201. .SH "INPUT FILES"
  202. The input file, otherwise known as the makefile, is a text file
  203. containing rules, macro definitions, include lines, and comments.
  204. See the EXTENDED DESCRIPTION section.
  205. .SH "ENVIRONMENT VARIABLES"
  206. The following environment variables shall affect the execution of
  207. .IR make :
  208. .IP "\fILANG\fP" 10
  209. Provide a default value for the internationalization variables that are
  210. unset or null. (See the Base Definitions volume of POSIX.1\(hy2017,
  211. .IR "Section 8.2" ", " "Internationalization Variables"
  212. for the precedence of internationalization variables used to determine
  213. the values of locale categories.)
  214. .IP "\fILC_ALL\fP" 10
  215. If set to a non-empty string value, override the values of all the
  216. other internationalization variables.
  217. .IP "\fILC_CTYPE\fP" 10
  218. Determine the locale for the interpretation of sequences of bytes of
  219. text data as characters (for example, single-byte as opposed to
  220. multi-byte characters in arguments and input files).
  221. .IP "\fILC_MESSAGES\fP" 10
  222. .br
  223. Determine the locale that should be used to affect the format and
  224. contents of diagnostic messages written to standard error.
  225. .IP "\fIMAKEFLAGS\fP" 10
  226. .br
  227. This variable shall be interpreted as a character string representing a
  228. series of option characters to be used as the default options. The
  229. implementation shall accept both of the following formats (but need not
  230. accept them when intermixed):
  231. .RS 10
  232. .IP " *" 4
  233. The characters are option letters without the leading
  234. <hyphen-minus>
  235. characters or
  236. <blank>
  237. separation used on a
  238. .IR make
  239. utility command line.
  240. .IP " *" 4
  241. The characters are formatted in a manner similar to a portion of the
  242. .IR make
  243. utility command line: options are preceded by
  244. <hyphen-minus>
  245. characters and
  246. <blank>-separated
  247. as described in the Base Definitions volume of POSIX.1\(hy2017,
  248. .IR "Section 12.2" ", " "Utility Syntax Guidelines".
  249. The
  250. .IR macro =\c
  251. .IR value
  252. macro definition operands can also be included. The difference between
  253. the contents of
  254. .IR MAKEFLAGS
  255. and the
  256. .IR make
  257. utility command line is that the contents of the variable shall not be
  258. subjected to the word expansions (see
  259. .IR "Section 2.6" ", " "Word Expansions")
  260. associated with parsing the command line values.
  261. .RE
  262. .IP "\fINLSPATH\fP" 10
  263. Determine the location of message catalogs for the processing of
  264. .IR LC_MESSAGES .
  265. .IP "\fIPROJECTDIR\fP" 10
  266. .br
  267. Provide a directory to be used to search for SCCS files not found in
  268. the current directory. In all of the following cases, the search for
  269. SCCS files is made in the directory
  270. .BR SCCS
  271. in the identified directory. If the value of
  272. .IR PROJECTDIR
  273. begins with a
  274. <slash>,
  275. it shall be considered an absolute pathname; otherwise, the value of
  276. .IR PROJECTDIR
  277. is treated as a user name and that user's initial working directory
  278. shall be examined for a subdirectory
  279. .BR src
  280. or
  281. .BR source .
  282. If such a directory is found, it shall be used. Otherwise, the value
  283. is used as a relative pathname.
  284. .RS 10
  285. .P
  286. If
  287. .IR PROJECTDIR
  288. is not set or has a null value, the search for SCCS files shall be made
  289. in the directory
  290. .BR SCCS
  291. in the current directory.
  292. .P
  293. The setting of
  294. .IR PROJECTDIR
  295. affects all files listed in the remainder of this utility description
  296. for files with a component named
  297. .BR SCCS .
  298. .RE
  299. .P
  300. The value of the
  301. .IR SHELL
  302. environment variable shall not be used as a macro and shall not be
  303. modified by defining the
  304. .BR SHELL
  305. macro in a makefile or on the command line. All other environment
  306. variables, including those with null values, shall be used as macros,
  307. as defined in
  308. .IR "Macros".
  309. .SH "ASYNCHRONOUS EVENTS"
  310. If not already ignored,
  311. .IR make
  312. shall trap SIGHUP, SIGTERM, SIGINT, and SIGQUIT and remove the current
  313. target unless the target is a directory or the target is a prerequisite
  314. of the special target
  315. .BR .PRECIOUS
  316. or unless one of the
  317. .BR \-n ,
  318. .BR \-p ,
  319. or
  320. .BR \-q
  321. options was specified. Any targets removed in this manner shall be
  322. reported in diagnostic messages of unspecified format, written to
  323. standard error. After this cleanup process, if any,
  324. .IR make
  325. shall take the standard action for all other signals.
  326. .SH STDOUT
  327. The
  328. .IR make
  329. utility shall write all commands to be executed to standard output
  330. unless the
  331. .BR \-s
  332. option was specified, the command is prefixed with an at-sign, or the
  333. special target
  334. .BR .SILENT
  335. has either the current target as a prerequisite or has no
  336. prerequisites. If
  337. .IR make
  338. is invoked without any work needing to be done, it shall write a
  339. message to standard output indicating that no action was taken. If the
  340. .BR \-t
  341. option is present and a file is touched,
  342. .IR make
  343. shall write to standard output a message of unspecified format
  344. indicating that the file was touched, including the filename of the
  345. file.
  346. .SH STDERR
  347. The standard error shall be used only for diagnostic messages.
  348. .SH "OUTPUT FILES"
  349. Files can be created when the
  350. .BR \-t
  351. option is present. Additional files can also be created by the
  352. utilities invoked by
  353. .IR make .
  354. .SH "EXTENDED DESCRIPTION"
  355. The
  356. .IR make
  357. utility attempts to perform the actions required to ensure that the
  358. specified targets are up-to-date. A target shall be considered
  359. up-to-date if it exists and is newer than all of its dependencies, or
  360. if it has already been made up-to-date by the current invocation of
  361. .IR make
  362. (regardless of the target's existence or age). A target may also be
  363. considered up-to-date if it exists, is the same age as one or more of
  364. its prerequisites, and is newer than the remaining prerequisites (if any).
  365. The
  366. .IR make
  367. utility shall treat all prerequisites as targets themselves and
  368. recursively ensure that they are up-to-date, processing them in the
  369. order in which they appear in the rule. The
  370. .IR make
  371. utility shall use the modification times of files to determine whether
  372. the corresponding targets are out-of-date.
  373. .P
  374. To ensure that a target is up-to-date,
  375. .IR make
  376. shall ensure that all of the prerequisites of a target are up-to-date,
  377. then check to see if the target itself is up-to-date. If the target
  378. is not up-to-date, the target shall be made up-to-date by executing
  379. the rule's commands (if any). If the target does not exist after the
  380. target has been successfully made up-to-date, the target shall be
  381. treated as being newer than any target for which it is a prerequisite.
  382. .P
  383. If a target exists and there is neither a target rule nor an inference
  384. rule for the target, the target shall be considered up-to-date. It
  385. shall be an error if
  386. .IR make
  387. attempts to ensure that a target is up-to-date but the target does not
  388. exist and there is neither a target rule nor an inference rule for the
  389. target.
  390. .SS "Makefile Syntax"
  391. .P
  392. A makefile can contain rules, macro definitions (see
  393. .IR "Macros"),
  394. include lines, and comments. There are two kinds of rules:
  395. .IR "inference rules"
  396. and
  397. .IR "target rules" .
  398. The
  399. .IR make
  400. utility shall contain a set of built-in inference rules. If the
  401. .BR \-r
  402. option is present, the built-in rules shall not be used and the suffix
  403. list shall be cleared. Additional rules of both types can be specified
  404. in a makefile. If a rule is defined more than once, the value of the
  405. rule shall be that of the last one specified. Macros can also be
  406. defined more than once, and the value of the macro is specified in
  407. .IR "Macros".
  408. There are three kinds of comments: blank lines, empty lines, and a
  409. <number-sign>
  410. (\c
  411. .BR '#' )
  412. and all following characters up to the first unescaped
  413. <newline>
  414. character. Blank lines, empty lines, and lines with
  415. <number-sign>
  416. (\c
  417. .BR '#' )
  418. as the first character on the line are also known as comment lines.
  419. .P
  420. By default, the following files shall be tried in sequence:
  421. .BR ./makefile
  422. and
  423. .BR ./Makefile .
  424. If neither
  425. .BR ./makefile
  426. or
  427. .BR ./Makefile
  428. are found, other implementation-defined files may also be tried.
  429. On XSI-conformant systems, the additional files
  430. .BR ./s.makefile ,
  431. .BR SCCS/s.makefile ,
  432. .BR ./s.Makefile ,
  433. and
  434. .BR SCCS/s.Makefile
  435. shall also be tried.
  436. .P
  437. The
  438. .BR \-f
  439. option shall direct
  440. .IR make
  441. to ignore any of these default files and use the specified argument as
  442. a makefile instead. If the
  443. .BR '\-'
  444. argument is specified, standard input shall be used.
  445. .P
  446. The term
  447. .IR makefile
  448. is used to refer to any rules provided by the user, whether in
  449. .BR ./makefile
  450. or its variants, or specified by the
  451. .BR \-f
  452. option.
  453. .P
  454. The rules in makefiles shall consist of the following types of lines:
  455. target rules, including special targets (see
  456. .IR "Target Rules"),
  457. inference rules (see
  458. .IR "Inference Rules"),
  459. macro definitions (see
  460. .IR "Macros"),
  461. and comments.
  462. .P
  463. Target and Inference Rules may contain
  464. .IR "command lines" .
  465. Command lines can have a prefix that shall be removed before
  466. execution (see
  467. .IR "Makefile Execution").
  468. .P
  469. When an escaped
  470. <newline>
  471. (one preceded by a
  472. <backslash>)
  473. is found anywhere in the makefile except in a command line, an include
  474. line, or a line immediately preceding an include line, it shall be
  475. replaced, along with any leading white space on the following line,
  476. with a single
  477. <space>.
  478. When an escaped
  479. <newline>
  480. is found in a command line in a makefile, the command line shall
  481. contain the
  482. <backslash>,
  483. the
  484. <newline>,
  485. and the next line, except that the first character of the next line
  486. shall not be included if it is a
  487. <tab>.
  488. When an escaped
  489. <newline>
  490. is found in an include line or in a line immediately preceding an
  491. include line, the behavior is unspecified.
  492. .SS "Include Lines"
  493. .P
  494. If the word
  495. .BR include
  496. appears at the beginning of a line and is followed by one or more
  497. <blank>
  498. characters, the string formed by the remainder of the line shall be
  499. processed as follows to produce a pathname:
  500. .IP " *" 4
  501. The trailing
  502. <newline>,
  503. any
  504. <blank>
  505. characters immediately preceding a comment,
  506. and any comment shall be discarded. If the resulting string contains
  507. any double-quote characters (\c
  508. .BR '\&"' )
  509. the behavior is unspecified.
  510. .IP " *" 4
  511. The resulting string shall be processed for macro expansion (see
  512. .IR "Macros").
  513. .IP " *" 4
  514. Any
  515. <blank>
  516. characters that appear after the first non-\c
  517. <blank>
  518. shall be used as separators to divide the macro-expanded string into
  519. fields. It is unspecified whether any other white-space characters
  520. are also used as separators. It is unspecified whether pathname
  521. expansion (see
  522. .IR "Section 2.13" ", " "Pattern Matching Notation")
  523. is also performed.
  524. .IP " *" 4
  525. If the processing of separators and optional pathname expansion
  526. results in either zero or two or more non-empty fields, the
  527. behavior is unspecified. If it results in one non-empty field,
  528. that field is taken as the pathname.
  529. .P
  530. If the pathname does not begin with a
  531. .BR '/'
  532. it shall be treated as relative to the current working directory
  533. of the process, not relative to the directory containing the makefile.
  534. If the file does not exist in this location, it is unspecified whether
  535. additional directories are searched.
  536. .P
  537. The contents of the file specified by the pathname shall be read
  538. and processed as if they appeared in the makefile in place of the
  539. include line. If the file ends with an escaped
  540. <newline>
  541. the behavior is unspecified.
  542. .P
  543. The file may itself contain further include lines. Implementations
  544. shall support nesting of include files up to a depth of at least 16.
  545. .SS "Makefile Execution"
  546. .P
  547. Makefile command lines shall be processed one at a time.
  548. .P
  549. Makefile command lines can have one or more of the following prefixes: a
  550. <hyphen-minus>
  551. (\c
  552. .BR '-' ),
  553. an at-sign (\c
  554. .BR '@' ),
  555. or a
  556. <plus-sign>
  557. (\c
  558. .BR '+' ).
  559. These shall modify the way in which
  560. .IR make
  561. processes the command.
  562. .IP "\fR\-\fR" 6
  563. If the command prefix contains a
  564. <hyphen-minus>,
  565. or the
  566. .BR \-i
  567. option is present, or the special target
  568. .BR .IGNORE
  569. has either the current target as a prerequisite or has no prerequisites,
  570. any error found while executing the command shall be ignored.
  571. .IP "\fR@\fR" 6
  572. If the command prefix contains an at-sign and the
  573. .IR make
  574. utility command line
  575. .BR \-n
  576. option is not specified, or the
  577. .BR \-s
  578. option is present, or the special target
  579. .BR .SILENT
  580. has either the current target as a prerequisite or has no prerequisites,
  581. the command shall not be written to standard output before it is executed.
  582. .IP "\fR+\fR" 6
  583. If the command prefix contains a
  584. <plus-sign>,
  585. this indicates a makefile command line that shall be executed even if
  586. .BR \-n ,
  587. .BR \-q ,
  588. or
  589. .BR \-t
  590. is specified.
  591. .P
  592. An
  593. .IR "execution line"
  594. is built from the command line by removing any prefix characters. Except
  595. as described under the at-sign prefix, the execution line shall be
  596. written to the standard output, optionally preceded by a
  597. <tab>.
  598. The execution line shall then be executed by a shell as if it were passed
  599. as the argument to the
  600. \fIsystem\fR()
  601. interface, except that if errors are not being ignored then the shell
  602. .BR \-e
  603. option shall also be in effect. If errors are being ignored for the
  604. command (as a result of the
  605. .BR \-i
  606. option, a
  607. .BR '\-'
  608. command prefix, or a
  609. .BR .IGNORE
  610. special target), the shell
  611. .BR \-e
  612. option shall not be in effect. The environment for the command being
  613. executed shall contain all of the variables in the environment of
  614. .IR make .
  615. .P
  616. By default, when
  617. .IR make
  618. receives a non-zero status from the execution of a command, it shall
  619. terminate with an error message to standard error.
  620. .SS "Target Rules"
  621. .P
  622. Target rules are formatted as follows:
  623. .sp
  624. .RS 4
  625. .nf
  626. \fItarget \fB[\fItarget\fR...\fB]\fR: \fB[\fIprerequisite\fR...\fB][;\fIcommand\fB]
  627. [\fR<tab>\fIcommand\fR
  628. <tab>\fIcommand\fR
  629. \&...\fB]\fR
  630. .P
  631. \fIline that does not begin with \fR<tab>
  632. .fi
  633. .P
  634. .RE
  635. .P
  636. Target entries are specified by a
  637. <blank>-separated,
  638. non-null list of targets, then a
  639. <colon>,
  640. then a
  641. <blank>-separated,
  642. possibly empty list of prerequisites. Text following a
  643. <semicolon>,
  644. if any, and all following lines that begin with a
  645. <tab>,
  646. are makefile command lines to be executed to update the target. The
  647. first non-empty line that does not begin with a
  648. <tab>
  649. or
  650. .BR '#'
  651. shall begin a new entry. Any comment line may begin a new entry.
  652. .P
  653. Applications shall select target names from the set of characters
  654. consisting solely of periods, underscores, digits, and alphabetics from
  655. the portable character set (see the Base Definitions volume of POSIX.1\(hy2017,
  656. .IR "Section 6.1" ", " "Portable Character Set").
  657. Implementations may allow other characters in target names as
  658. extensions. The interpretation of targets containing the characters
  659. .BR '%'
  660. and
  661. .BR '\&"'
  662. is implementation-defined.
  663. .P
  664. A target that has prerequisites, but does not have any commands, can be
  665. used to add to the prerequisite list for that target. Only one target
  666. rule for any given target can contain commands.
  667. .P
  668. Lines that begin with one of the following are called
  669. .IR "special targets"
  670. and control the operation of
  671. .IR make :
  672. .IP "\&\fB.DEFAULT\fR" 10
  673. If the makefile uses this special target, the application shall ensure
  674. that it is specified with commands, but without prerequisites. The
  675. commands shall be used by
  676. .IR make
  677. if there are no other rules available to build a target.
  678. .IP "\&\fB.IGNORE\fR" 10
  679. Prerequisites of this special target are targets themselves; this shall
  680. cause errors from commands associated with them to be ignored in the
  681. same manner as specified by the
  682. .BR \-i
  683. option. Subsequent occurrences of
  684. .BR .IGNORE
  685. shall add to the list of targets ignoring command errors. If no
  686. prerequisites are specified,
  687. .IR make
  688. shall behave as if the
  689. .BR \-i
  690. option had been specified and errors from all commands associated with
  691. all targets shall be ignored.
  692. .IP "\&\fB.POSIX\fR" 10
  693. The application shall ensure that this special target is specified
  694. without prerequisites or commands. If it appears as the first
  695. non-comment line in the makefile,
  696. .IR make
  697. shall process the makefile as specified by this section; otherwise, the
  698. behavior of
  699. .IR make
  700. is unspecified.
  701. .IP "\&\fB.PRECIOUS\fR" 10
  702. Prerequisites of this special target shall not be removed if
  703. .IR make
  704. receives one of the asynchronous events explicitly described in the
  705. ASYNCHRONOUS EVENTS section. Subsequent occurrences of
  706. .BR .PRECIOUS
  707. shall add to the list of precious files. If no prerequisites are
  708. specified, all targets in the makefile shall be treated as if specified
  709. with
  710. .BR .PRECIOUS .
  711. .IP "\fB.SCCS_GET\fR" 10
  712. The application shall ensure that this special target is specified
  713. without prerequisites. If this special target is included in a
  714. makefile, the commands specified with this target shall replace the
  715. default commands associated with this special target (see
  716. .IR "Default Rules").
  717. The commands specified with this target are used to get all SCCS files
  718. that are not found in the current directory.
  719. .RS 10
  720. .P
  721. When source files are named in a dependency list,
  722. .IR make
  723. shall treat them just like any other target. Because the source file is
  724. presumed to be present in the directory, there is no need to add an
  725. entry for it to the makefile. When a target has no dependencies, but is
  726. present in the directory,
  727. .IR make
  728. shall assume that that file is up-to-date. If, however, an SCCS file
  729. named
  730. .BR SCCS/s. \c
  731. .IR source_file
  732. is found for a target
  733. .IR source_file ,
  734. .IR make
  735. compares the timestamp of the target file with that of the
  736. .BR SCCS/s.source_file
  737. to ensure the target is up-to-date. If the target is missing, or if the
  738. SCCS file is newer,
  739. .IR make
  740. shall automatically issue the commands specified for the
  741. .BR .SCCS_GET
  742. special target to retrieve the most recent version. However, if the
  743. target is writable by anyone,
  744. .IR make
  745. shall not retrieve a new version.
  746. .RE
  747. .IP "\&\fB.SILENT\fR" 10
  748. Prerequisites of this special target are targets themselves; this shall
  749. cause commands associated with them not to be written to the standard
  750. output before they are executed. Subsequent occurrences of
  751. .BR .SILENT
  752. shall add to the list of targets with silent commands. If no
  753. prerequisites are specified,
  754. .IR make
  755. shall behave as if the
  756. .BR \-s
  757. option had been specified and no commands or touch messages associated
  758. with any target shall be written to standard output.
  759. .IP "\&\fB.SUFFIXES\fR" 10
  760. Prerequisites of
  761. .BR .SUFFIXES
  762. shall be appended to the list of known suffixes and are used in
  763. conjunction with the inference rules (see
  764. .IR "Inference Rules").
  765. If
  766. .BR .SUFFIXES
  767. does not have any prerequisites, the list of known suffixes shall be
  768. cleared.
  769. .P
  770. The special targets
  771. .BR .IGNORE ,
  772. .BR .POSIX ,
  773. .BR .PRECIOUS ,
  774. .BR .SILENT ,
  775. and
  776. .BR .SUFFIXES
  777. shall be specified without commands.
  778. .P
  779. Targets with names consisting of a leading
  780. <period>
  781. followed by the uppercase letters
  782. .BR \(dqPOSIX\(dq
  783. and then any other characters are reserved for future standardization.
  784. Targets with names consisting of a leading
  785. <period>
  786. followed by one or more uppercase letters are reserved for implementation
  787. extensions.
  788. .SS "Macros"
  789. .P
  790. Macro definitions are in the form:
  791. .sp
  792. .RS 4
  793. .nf
  794. \fIstring1\fR = \fB[\fIstring2\fB]\fR
  795. .fi
  796. .P
  797. .RE
  798. .P
  799. The macro named
  800. .IR string1
  801. is defined as having the value of
  802. .IR string2 ,
  803. where
  804. .IR string2
  805. is defined as all characters, if any, after the
  806. <equals-sign>,
  807. up to a comment character (\c
  808. .BR '#' )
  809. or an unescaped
  810. <newline>.
  811. Any
  812. <blank>
  813. characters immediately before or after the
  814. <equals-sign>
  815. shall be ignored.
  816. .P
  817. Applications shall select macro names from the set of characters
  818. consisting solely of periods, underscores, digits, and alphabetics from
  819. the portable character set (see the Base Definitions volume of POSIX.1\(hy2017,
  820. .IR "Section 6.1" ", " "Portable Character Set").
  821. A macro name shall not contain an
  822. <equals-sign>.
  823. Implementations may allow other characters in macro names as extensions.
  824. .P
  825. Macros can appear anywhere in the makefile. Macro expansions using
  826. the forms $(\c
  827. .IR string1 )
  828. or ${\c
  829. .IR string1 }
  830. shall be replaced by
  831. .IR string2 ,
  832. as follows:
  833. .IP " *" 4
  834. Macros in target lines shall be evaluated when the target line is read.
  835. .IP " *" 4
  836. Macros in makefile command lines shall be evaluated when the command is
  837. executed.
  838. .IP " *" 4
  839. Macros in the string before the
  840. <equals-sign>
  841. in a macro definition shall be evaluated when the macro assignment
  842. is made.
  843. .IP " *" 4
  844. Macros after the
  845. <equals-sign>
  846. in a macro definition shall not be evaluated until the defined macro
  847. is used in a rule or command, or before the
  848. <equals-sign>
  849. in a macro definition.
  850. .P
  851. The parentheses or braces are optional if
  852. .IR string1
  853. is a single character. The macro $$ shall be replaced by the single
  854. character
  855. .BR '$' .
  856. If
  857. .IR string1
  858. in a macro expansion contains a macro expansion, the results are
  859. unspecified.
  860. .P
  861. Macro expansions using the forms $(\c
  862. .IR string1 \c
  863. .BR [: \c
  864. .IR subst1 \c
  865. .BR =[ \c
  866. .IR subst2 \c
  867. .BR ]] )
  868. or ${\c
  869. .IR string1 \c
  870. .BR [: \c
  871. .IR subst1 \c
  872. .BR =[ \c
  873. .IR subst2 \c
  874. .BR ]] }
  875. can be used to replace all occurrences of
  876. .IR subst1
  877. with
  878. .IR subst2
  879. when the macro substitution is performed. The
  880. .IR subst1
  881. to be replaced shall be recognized when it is a suffix at the end of a
  882. word in
  883. .IR string1
  884. (where a
  885. .IR word ,
  886. in this context, is defined to be a string delimited by the beginning
  887. of the line, a
  888. <blank>,
  889. or a
  890. <newline>).
  891. If
  892. .IR string1
  893. in a macro expansion contains a macro expansion, the results are
  894. unspecified. If a
  895. <percent-sign>
  896. character appears as part of
  897. .IR subst1
  898. or
  899. .IR subst2
  900. after any macros have been recursively expanded, the results are
  901. unspecified.
  902. .P
  903. Macro expansions in
  904. .IR string1
  905. of macro definition lines shall be evaluated when read. Macro
  906. expansions in
  907. .IR string2
  908. of macro definition lines shall be performed when the macro identified
  909. by
  910. .IR string1
  911. is expanded in a rule or command.
  912. .P
  913. Macro definitions shall be taken from the following sources, in the
  914. following logical order, before the makefile(s) are read.
  915. .IP " 1." 4
  916. Macros specified on the
  917. .IR make
  918. utility command line, in the order specified on the command line. It is
  919. unspecified whether the internal macros defined in
  920. .IR "Internal Macros"
  921. are accepted from this source.
  922. .IP " 2." 4
  923. Macros defined by the
  924. .IR MAKEFLAGS
  925. environment variable, in the order specified in the environment
  926. variable. It is unspecified whether the internal macros defined in
  927. .IR "Internal Macros"
  928. are accepted from this source.
  929. .IP " 3." 4
  930. The contents of the environment, excluding the
  931. .IR MAKEFLAGS
  932. and
  933. .IR SHELL
  934. variables and including the variables with null values.
  935. .IP " 4." 4
  936. Macros defined in the inference rules built into
  937. .IR make .
  938. .P
  939. Macro definitions from these sources shall not override macro
  940. definitions from a lower-numbered source. Macro definitions from a
  941. single source (for example, the
  942. .IR make
  943. utility command line, the
  944. .IR MAKEFLAGS
  945. environment variable, or the other environment variables) shall
  946. override previous macro definitions from the same source.
  947. .P
  948. Macros defined in the makefile(s) shall override macro definitions that
  949. occur before them in the makefile(s) and macro definitions from source
  950. 4. If the
  951. .BR \-e
  952. option is not specified, macros defined in the makefile(s) shall
  953. override macro definitions from source 3. Macros defined in the
  954. makefile(s) shall not override macro definitions from source 1 or
  955. source 2.
  956. .P
  957. Before the makefile(s) are read, all of the
  958. .IR make
  959. utility command line options (except
  960. .BR \-f
  961. and
  962. .BR \-p )
  963. and
  964. .IR make
  965. utility command line macro definitions (except any for the
  966. .IR MAKEFLAGS
  967. macro), not already included in the
  968. .IR MAKEFLAGS
  969. macro, shall be added to the
  970. .IR MAKEFLAGS
  971. macro, quoted in an implementation-defined manner such that when
  972. .IR MAKEFLAGS
  973. is read by another instance of the
  974. .IR make
  975. command, the original macro's value is recovered. Other
  976. implementation-defined options and macros may also be added to the
  977. .IR MAKEFLAGS
  978. macro. If this modifies the value of the
  979. .IR MAKEFLAGS
  980. macro, or, if the
  981. .IR MAKEFLAGS
  982. macro is modified at any subsequent time, the
  983. .IR MAKEFLAGS
  984. environment variable shall be modified to match the new value of the
  985. .IR MAKEFLAGS
  986. macro. The result of setting
  987. .IR MAKEFLAGS
  988. in the Makefile is unspecified.
  989. .P
  990. Before the makefile(s) are read, all of the
  991. .IR make
  992. utility command line macro definitions (except the
  993. .IR MAKEFLAGS
  994. macro or the
  995. .IR SHELL
  996. macro) shall be added to the environment of
  997. .IR make .
  998. Other implementation-defined variables may also be added to the
  999. environment of
  1000. .IR make .
  1001. Macros defined by the
  1002. .IR MAKEFLAGS
  1003. environment variable and macros defined in the makefile(s) shall not
  1004. be added to the environment of
  1005. .IR make
  1006. if they are not already in its environment. With the exception of
  1007. .IR SHELL
  1008. (see below), it is unspecified whether macros defined in these ways
  1009. update the value of an environment variable that already exists in the
  1010. environment of
  1011. .IR make .
  1012. .P
  1013. The
  1014. .BR SHELL
  1015. macro shall be treated specially. It shall be provided by
  1016. .IR make
  1017. and set to the pathname of the shell command language interpreter (see
  1018. .IR "\fIsh\fR\^").
  1019. The
  1020. .IR SHELL
  1021. environment variable shall not affect the value of the
  1022. .BR SHELL
  1023. macro. If
  1024. .BR SHELL
  1025. is defined in the makefile or is specified on the command line, it
  1026. shall replace the original value of the
  1027. .BR SHELL
  1028. macro, but shall not affect the
  1029. .IR SHELL
  1030. environment variable. Other effects of defining
  1031. .BR SHELL
  1032. in the makefile or on the command line are implementation-defined.
  1033. .SS "Inference Rules"
  1034. .P
  1035. Inference rules are formatted as follows:
  1036. .sp
  1037. .RS 4
  1038. .nf
  1039. \fItarget\fR:
  1040. <tab>\fIcommand
  1041. \fB[\fR<tab>\fIcommand\fB]\fR
  1042. \&...
  1043. .P
  1044. \fIline that does not begin with \fR<tab>\fI or \fR#
  1045. .fi
  1046. .P
  1047. .RE
  1048. .P
  1049. The application shall ensure that the
  1050. .IR target
  1051. portion is a valid target name (see
  1052. .IR "Target Rules")
  1053. of the form
  1054. .BR .s2
  1055. or
  1056. .BR .s1.s2
  1057. (where
  1058. .BR .s1
  1059. and
  1060. .BR .s2
  1061. are suffixes that have been given as prerequisites of the
  1062. .BR .SUFFIXES
  1063. special target and
  1064. .IR s1
  1065. and
  1066. .IR s2
  1067. do not contain any
  1068. <slash>
  1069. or
  1070. <period>
  1071. characters.) If there is only one
  1072. <period>
  1073. in the target, it is a single-suffix inference rule. Targets with two
  1074. periods are double-suffix inference rules. Inference rules can have
  1075. only one target before the
  1076. <colon>.
  1077. .P
  1078. The application shall ensure that the makefile does not specify
  1079. prerequisites for inference rules; no characters other than white space
  1080. shall follow the
  1081. <colon>
  1082. in the first line, except when creating the
  1083. .IR "empty rule,"
  1084. described below. Prerequisites are inferred, as described below.
  1085. .P
  1086. Inference rules can be redefined. A target that matches an existing
  1087. inference rule shall overwrite the old inference rule. An empty rule
  1088. can be created with a command consisting of simply a
  1089. <semicolon>
  1090. (that is, the rule still exists and is found during inference rule search,
  1091. but since it is empty, execution has no effect). The empty rule can also
  1092. be formatted as follows:
  1093. .sp
  1094. .RS 4
  1095. .nf
  1096. \fIrule\fR: ;
  1097. .fi
  1098. .P
  1099. .RE
  1100. .P
  1101. where zero or more
  1102. <blank>
  1103. characters separate the
  1104. <colon>
  1105. and
  1106. <semicolon>.
  1107. .P
  1108. The
  1109. .IR make
  1110. utility uses the suffixes of targets and their prerequisites to infer
  1111. how a target can be made up-to-date. A list of inference rules defines
  1112. the commands to be executed. By default,
  1113. .IR make
  1114. contains a built-in set of inference rules. Additional rules can be
  1115. specified in the makefile.
  1116. .P
  1117. The special target
  1118. .BR .SUFFIXES
  1119. contains as its prerequisites a list of suffixes that shall be used by
  1120. the inference rules. The order in which the suffixes are specified
  1121. defines the order in which the inference rules for the suffixes are
  1122. used. New suffixes shall be appended to the current list by specifying
  1123. a
  1124. .BR .SUFFIXES
  1125. special target in the makefile. A
  1126. .BR .SUFFIXES
  1127. target with no prerequisites shall clear the list of suffixes. An
  1128. empty
  1129. .BR .SUFFIXES
  1130. target followed by a new
  1131. .BR .SUFFIXES
  1132. list is required to change the order of the suffixes.
  1133. .P
  1134. Normally, the user would provide an inference rule for each suffix.
  1135. The inference rule to update a target with a suffix
  1136. .BR .s1
  1137. from a prerequisite with a suffix
  1138. .BR .s2
  1139. is specified as a target
  1140. .BR .s2.s1 .
  1141. The internal macros provide the means to specify general inference
  1142. rules (see
  1143. .IR "Internal Macros").
  1144. .P
  1145. When no target rule is found to update a target, the inference rules
  1146. shall be checked. The suffix of the target (\c
  1147. .BR .s1 )
  1148. to be built is compared to the list of suffixes specified by the
  1149. .BR .SUFFIXES
  1150. special targets. If the
  1151. .BR .s1
  1152. suffix is found in
  1153. .BR .SUFFIXES ,
  1154. the inference rules shall be searched in the order defined for the
  1155. first
  1156. .BR .s2.s1
  1157. rule whose prerequisite file (\c
  1158. .BR $*.s2 )
  1159. exists. If the target is out-of-date with respect to this
  1160. prerequisite, the commands for that inference rule shall be executed.
  1161. .P
  1162. If the target to be built does not contain a suffix and there is no
  1163. rule for the target, the single suffix inference rules shall be
  1164. checked. The single-suffix inference rules define how to build a
  1165. target if a file is found with a name that matches the target name with
  1166. one of the single suffixes appended. A rule with one suffix
  1167. .BR .s2
  1168. is the definition of how to build
  1169. .IR target
  1170. from
  1171. .BR target.s2 .
  1172. The other suffix (\c
  1173. .BR .s1 )
  1174. is treated as null.
  1175. .P
  1176. A
  1177. <tilde>
  1178. (\c
  1179. .BR '\(ti' )
  1180. in the above rules refers to an SCCS file in the current directory.
  1181. Thus, the rule
  1182. .BR .c~.o
  1183. would transform an SCCS C-language source file into an object file (\c
  1184. .BR .o ).
  1185. Because the
  1186. .BR s.
  1187. of the SCCS files is a prefix, it is incompatible with
  1188. .IR make 's
  1189. suffix point of view. Hence, the
  1190. .BR '\(ti'
  1191. is a way of changing any file reference into an SCCS file reference.
  1192. .SS "Libraries"
  1193. .P
  1194. If a target or prerequisite contains parentheses, it shall be treated
  1195. as a member of an archive library. For the
  1196. .IR lib (\c
  1197. .IR member \c
  1198. .BR .o )
  1199. expression
  1200. .IR lib
  1201. refers to the name of the archive library and
  1202. .IR member \c
  1203. .BR .o
  1204. to the member name. The application shall ensure that the member is an
  1205. object file with the
  1206. .BR .o
  1207. suffix. The modification time of the expression is the modification
  1208. time for the member as kept in the archive library; see
  1209. .IR "\fIar\fR\^".
  1210. The
  1211. .BR .a
  1212. suffix shall refer to an archive library. The
  1213. .BR .s2.a
  1214. rule shall be used to update a member in the library from a file
  1215. with a suffix
  1216. .BR .s2 .
  1217. .SS "Internal Macros"
  1218. .P
  1219. The
  1220. .IR make
  1221. utility shall maintain five internal macros that can be used in target
  1222. and inference rules. In order to clearly define the meaning of these
  1223. macros, some clarification of the terms
  1224. .IR "target rule" ,
  1225. .IR "inference rule" ,
  1226. .IR target ,
  1227. and
  1228. .IR prerequisite
  1229. is necessary.
  1230. .P
  1231. Target rules are specified by the user in a makefile for a particular
  1232. target. Inference rules are user-specified or
  1233. .IR make -specified
  1234. rules for a particular class of target name. Explicit prerequisites
  1235. are those prerequisites specified in a makefile on target lines.
  1236. Implicit prerequisites are those prerequisites that are generated when
  1237. inference rules are used. Inference rules are applied to implicit
  1238. prerequisites or to explicit prerequisites that do not have target
  1239. rules defined for them in the makefile. Target rules are applied to
  1240. targets specified in the makefile.
  1241. .P
  1242. Before any target in the makefile is updated, each of its prerequisites
  1243. (both explicit and implicit) shall be updated. This shall be
  1244. accomplished by recursively processing each prerequisite. Upon
  1245. recursion, each prerequisite shall become a target itself. Its
  1246. prerequisites in turn shall be processed recursively until a target is
  1247. found that has no prerequisites, or further recursion would
  1248. require applying two inference rules one immediately after the other,
  1249. at which point the recursion shall stop. As an extension,
  1250. implementations may continue recursion when two or more successive
  1251. inference rules need to be applied; however, if there are multiple
  1252. different chains of such rules that could be used to create the
  1253. target, it is unspecified which chain is used. The recursion shall
  1254. then back up, updating each target as it goes.
  1255. .P
  1256. In the definitions that follow, the word
  1257. .IR target
  1258. refers to one of:
  1259. .IP " *" 4
  1260. A target specified in the makefile
  1261. .IP " *" 4
  1262. An explicit prerequisite specified in the makefile that becomes the
  1263. target when
  1264. .IR make
  1265. processes it during recursion
  1266. .IP " *" 4
  1267. An implicit prerequisite that becomes a target when
  1268. .IR make
  1269. processes it during recursion
  1270. .P
  1271. In the definitions that follow, the word
  1272. .IR prerequisite
  1273. refers to one of the following:
  1274. .IP " *" 4
  1275. An explicit prerequisite specified in the makefile for a particular
  1276. target
  1277. .IP " *" 4
  1278. An implicit prerequisite generated as a result of locating an
  1279. appropriate inference rule and corresponding file that matches the
  1280. suffix of the target
  1281. .P
  1282. The five internal macros are:
  1283. .IP $@ 8
  1284. The $@ shall evaluate to the full target name of the current target, or
  1285. the archive filename part of a library archive target. It shall be
  1286. evaluated for both target and inference rules.
  1287. .RS 8
  1288. .P
  1289. For example, in the
  1290. .BR .c.a
  1291. inference rule, $@ represents the out-of-date
  1292. .BR .a
  1293. file to be built. Similarly, in a makefile target rule to build
  1294. .BR lib.a
  1295. from
  1296. .BR file.c ,
  1297. $@ represents the out-of-date
  1298. .BR lib.a .
  1299. .RE
  1300. .IP $% 8
  1301. The $% macro shall be evaluated only when the current target is an
  1302. archive library member of the form
  1303. .IR libname (\c
  1304. .IR member \c
  1305. .BR .o ).
  1306. In these cases, $@ shall evaluate to
  1307. .IR libname
  1308. and $% shall evaluate to
  1309. .IR member \c
  1310. .BR .o .
  1311. The $% macro shall be evaluated for both target and inference rules.
  1312. .RS 8
  1313. .P
  1314. For example, in a makefile target rule to build
  1315. .BR lib.a (\c
  1316. .BR file.o ),
  1317. $% represents
  1318. .BR file.o ,
  1319. as opposed to $@, which represents
  1320. .BR lib.a .
  1321. .RE
  1322. .IP $? 8
  1323. The $? macro shall evaluate to the list of prerequisites that are
  1324. newer than the current target. It shall be evaluated for both target
  1325. and inference rules.
  1326. .RS 8
  1327. .P
  1328. For example, in a makefile target rule to build
  1329. .IR prog
  1330. from
  1331. .BR file1.o ,
  1332. .BR file2.o ,
  1333. and
  1334. .BR file3.o ,
  1335. and where
  1336. .IR prog
  1337. is not out-of-date with respect to
  1338. .BR file1.o ,
  1339. but is out-of-date with respect to
  1340. .BR file2.o
  1341. and
  1342. .BR file3.o ,
  1343. $? represents
  1344. .BR file2.o
  1345. and
  1346. .BR file3.o .
  1347. .RE
  1348. .IP $< 8
  1349. In an inference rule, the $< macro shall evaluate to the filename
  1350. whose existence allowed the inference rule to be chosen for the target.
  1351. In the
  1352. .BR .DEFAULT
  1353. rule, the $< macro shall evaluate to the current target name. The
  1354. meaning of the $< macro shall be otherwise unspecified.
  1355. .RS 8
  1356. .P
  1357. For example, in the
  1358. .BR .c.a
  1359. inference rule, $< represents the prerequisite
  1360. .BR .c
  1361. file.
  1362. .RE
  1363. .IP $* 8
  1364. The $* macro shall evaluate to the current target name with its suffix
  1365. deleted. It shall be evaluated at least for inference rules.
  1366. .RS 8
  1367. .P
  1368. For example, in the
  1369. .BR .c.a
  1370. inference rule, $*.o represents the out-of-date
  1371. .BR .o
  1372. file that corresponds to the prerequisite
  1373. .BR .c
  1374. file.
  1375. .RE
  1376. .P
  1377. Each of the internal macros has an alternative form. When an uppercase
  1378. .BR 'D'
  1379. or
  1380. .BR 'F'
  1381. is appended to any of the macros, the meaning shall be changed to the
  1382. .IR "directory part"
  1383. for
  1384. .BR 'D'
  1385. and
  1386. .IR "filename part"
  1387. for
  1388. .BR 'F' .
  1389. The directory part is the path prefix of the file without a trailing
  1390. <slash>;
  1391. for the current directory, the directory part is
  1392. .BR '.' .
  1393. When the $? macro contains more than one prerequisite filename, the
  1394. $(?D) and $(?F) (or ${?D} and ${?F}) macros expand to a list of
  1395. directory name parts and filename parts respectively.
  1396. .P
  1397. For the target
  1398. .IR lib (\c
  1399. .IR member \c
  1400. .BR .o )
  1401. and the
  1402. .BR s2.a
  1403. rule, the internal macros shall be defined as:
  1404. .IP $< 8
  1405. .IR member \c
  1406. .BR .s2
  1407. .IP $* 8
  1408. .IR member
  1409. .IP $@ 8
  1410. .IR lib
  1411. .IP $? 8
  1412. .IR member \c
  1413. .BR .s2
  1414. .IP $% 8
  1415. .IR member \c
  1416. .BR .o
  1417. .SS "Default Rules"
  1418. .P
  1419. The default rules for
  1420. .IR make
  1421. shall achieve results that are the same as if the following were used.
  1422. Implementations that do not support the C-Language Development
  1423. Utilities option may omit
  1424. .BR CC ,
  1425. .BR CFLAGS ,
  1426. .BR YACC ,
  1427. .BR YFLAGS ,
  1428. .BR LEX ,
  1429. .BR LFLAGS ,
  1430. .BR LDFLAGS ,
  1431. and the
  1432. .BR .c ,
  1433. .BR .y ,
  1434. and
  1435. .BR .l
  1436. inference rules. Implementations that do not support FORTRAN may omit
  1437. .BR FC ,
  1438. .BR FFLAGS ,
  1439. and the
  1440. .BR .f
  1441. inference rules. Implementations may provide additional macros and
  1442. rules.
  1443. .sp
  1444. .RS 4
  1445. .nf
  1446. \fISPECIAL TARGETS\fP
  1447. .P
  1448. \&.SCCS_GET: sccs $(SCCSFLAGS) get $(SCCSGETFLAGS) $@
  1449. .P
  1450. \&.SUFFIXES: .o .c .y .l .a .sh .f .c\(ti .y\(ti .l\(ti .sh\(ti .f\(ti
  1451. .P
  1452. .IR MACROS
  1453. .P
  1454. MAKE=make
  1455. AR=ar
  1456. ARFLAGS=-rv
  1457. YACC=yacc
  1458. YFLAGS=
  1459. LEX=lex
  1460. LFLAGS=
  1461. LDFLAGS=
  1462. CC=c99
  1463. CFLAGS=-O 1
  1464. FC=fort77
  1465. FFLAGS=-O 1
  1466. GET=get
  1467. GFLAGS=
  1468. SCCSFLAGS=
  1469. SCCSGETFLAGS=-s
  1470. .P
  1471. \fISINGLE SUFFIX RULES\fP
  1472. .P
  1473. \&.c:
  1474. $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
  1475. .P
  1476. \&.f:
  1477. $(FC) $(FFLAGS) $(LDFLAGS) -o $@ $<
  1478. .P
  1479. \&.sh:
  1480. cp $< $@
  1481. chmod a+x $@
  1482. .P
  1483. \&.c\(ti:
  1484. $(GET) $(GFLAGS) -p $< > $*.c
  1485. $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $*.c
  1486. .P
  1487. \&.f\(ti:
  1488. $(GET) $(GFLAGS) -p $< > $*.f
  1489. $(FC) $(FFLAGS) $(LDFLAGS) -o $@ $*.f
  1490. .P
  1491. \&.sh\(ti:
  1492. $(GET) $(GFLAGS) -p $< > $*.sh
  1493. cp $*.sh $@
  1494. chmod a+x $@
  1495. .P
  1496. \fIDOUBLE SUFFIX RULES\fP
  1497. .P
  1498. \&.c.o:
  1499. $(CC) $(CFLAGS) -c $<
  1500. .P
  1501. \&.f.o:
  1502. $(FC) $(FFLAGS) -c $<
  1503. .P
  1504. \&.y.o:
  1505. $(YACC) $(YFLAGS) $<
  1506. $(CC) $(CFLAGS) -c y.tab.c
  1507. rm -f y.tab.c
  1508. mv y.tab.o $@
  1509. .P
  1510. \&.l.o:
  1511. $(LEX) $(LFLAGS) $<
  1512. $(CC) $(CFLAGS) -c lex.yy.c
  1513. rm -f lex.yy.c
  1514. mv lex.yy.o $@
  1515. .P
  1516. \&.y.c:
  1517. $(YACC) $(YFLAGS) $<
  1518. mv y.tab.c $@
  1519. .P
  1520. \&.l.c:
  1521. $(LEX) $(LFLAGS) $<
  1522. mv lex.yy.c $@
  1523. .P
  1524. \&.c\(ti.o:
  1525. $(GET) $(GFLAGS) -p $< > $*.c
  1526. $(CC) $(CFLAGS) -c $*.c
  1527. .P
  1528. \&.f\(ti.o:
  1529. $(GET) $(GFLAGS) -p $< > $*.f
  1530. $(FC) $(FFLAGS) -c $*.f
  1531. .P
  1532. \&.y\(ti.o:
  1533. $(GET) $(GFLAGS) -p $< > $*.y
  1534. $(YACC) $(YFLAGS) $*.y
  1535. $(CC) $(CFLAGS) -c y.tab.c
  1536. rm -f y.tab.c
  1537. mv y.tab.o $@
  1538. .P
  1539. \&.l\(ti.o:
  1540. $(GET) $(GFLAGS) -p $< > $*.l
  1541. $(LEX) $(LFLAGS) $*.l
  1542. $(CC) $(CFLAGS) -c lex.yy.c
  1543. rm -f lex.yy.c
  1544. mv lex.yy.o $@
  1545. .P
  1546. \&.y\(ti.c:
  1547. $(GET) $(GFLAGS) -p $< > $*.y
  1548. $(YACC) $(YFLAGS) $*.y
  1549. mv y.tab.c $@
  1550. .P
  1551. \&.l\(ti.c:
  1552. $(GET) $(GFLAGS) -p $< > $*.l
  1553. $(LEX) $(LFLAGS) $*.l
  1554. mv lex.yy.c $@
  1555. .P
  1556. \&.c.a:
  1557. $(CC) -c $(CFLAGS) $<
  1558. $(AR) $(ARFLAGS) $@ $*.o
  1559. rm -f $*.o
  1560. .P
  1561. \&.f.a:
  1562. $(FC) -c $(FFLAGS) $<
  1563. $(AR) $(ARFLAGS) $@ $*.o
  1564. rm -f $*.o
  1565. .fi
  1566. .P
  1567. .RE
  1568. .SH "EXIT STATUS"
  1569. When the
  1570. .BR \-q
  1571. option is specified, the
  1572. .IR make
  1573. utility shall exit with one of the following values:
  1574. .IP "\00" 6
  1575. Successful completion.
  1576. .IP "\01" 6
  1577. The target was not up-to-date.
  1578. .IP >1 6
  1579. An error occurred.
  1580. .P
  1581. When the
  1582. .BR \-q
  1583. option is not specified, the
  1584. .IR make
  1585. utility shall exit with one of the following values:
  1586. .IP "\00" 6
  1587. Successful completion.
  1588. .IP >0 6
  1589. An error occurred.
  1590. .SH "CONSEQUENCES OF ERRORS"
  1591. Default.
  1592. .LP
  1593. .IR "The following sections are informative."
  1594. .SH "APPLICATION USAGE"
  1595. If there is a source file (such as
  1596. .BR ./source.c )
  1597. and there are two SCCS files corresponding to it (\c
  1598. .BR ./s.source.c
  1599. and
  1600. .BR ./SCCS/s.source.c ),
  1601. on XSI-conformant systems
  1602. .IR make
  1603. uses the SCCS file in the current directory. However, users are
  1604. advised to use the underlying SCCS utilities (\c
  1605. .IR admin ,
  1606. .IR delta ,
  1607. .IR get ,
  1608. and so on) or the
  1609. .IR sccs
  1610. utility for all source files in a given directory. If both forms are
  1611. used for a given source file, future developers are very likely to be
  1612. confused.
  1613. .P
  1614. It is incumbent upon portable makefiles to specify the
  1615. .BR .POSIX
  1616. special target in order to guarantee that they are not affected by
  1617. local extensions.
  1618. .P
  1619. The
  1620. .BR \-k
  1621. and
  1622. .BR \-S
  1623. options are both present so that the relationship between the command
  1624. line, the
  1625. .IR MAKEFLAGS
  1626. variable, and the makefile can be controlled precisely. If the
  1627. .BR k
  1628. flag is passed in
  1629. .IR MAKEFLAGS
  1630. and a command is of the form:
  1631. .sp
  1632. .RS 4
  1633. .nf
  1634. $(MAKE) -S foo
  1635. .fi
  1636. .P
  1637. .RE
  1638. .P
  1639. then the default behavior is restored for the child
  1640. .IR make .
  1641. .P
  1642. When the
  1643. .BR \-n
  1644. option is specified, it is always added to
  1645. .IR MAKEFLAGS .
  1646. This allows a recursive
  1647. .IR make
  1648. .BR \-n
  1649. .IR target
  1650. to be used to see all of the action that would be taken to update
  1651. .IR target .
  1652. .P
  1653. Because of widespread historical practice, interpreting a
  1654. <number-sign>
  1655. (\c
  1656. .BR '#' )
  1657. inside a variable as the start of a comment has the unfortunate
  1658. side-effect of making it impossible to place a
  1659. <number-sign>
  1660. in a variable, thus forbidding something like:
  1661. .sp
  1662. .RS 4
  1663. .nf
  1664. CFLAGS = "-D COMMENT_CHAR=\(aq#\(aq"
  1665. .fi
  1666. .P
  1667. .RE
  1668. .P
  1669. Many historical
  1670. .IR make
  1671. utilities stop chaining together inference rules when an intermediate
  1672. target is nonexistent. For example, it might be possible for a
  1673. .IR make
  1674. to determine that both
  1675. .BR .y.c
  1676. and
  1677. .BR .c.o
  1678. could be used to convert a
  1679. .BR .y
  1680. to a
  1681. .BR .o .
  1682. Instead, in this case,
  1683. .IR make
  1684. requires the use of a
  1685. .BR .y.o
  1686. rule.
  1687. .P
  1688. The best way to provide portable makefiles is to include all of the
  1689. rules needed in the makefile itself. The rules provided use only
  1690. features provided by other parts of this volume of POSIX.1\(hy2017. The default rules include
  1691. rules for optional commands in this volume of POSIX.1\(hy2017. Only rules pertaining to commands
  1692. that are provided are needed in an implementation's default set.
  1693. .P
  1694. Macros used within other macros are evaluated when the new macro is
  1695. used rather than when the new macro is defined. Therefore:
  1696. .sp
  1697. .RS 4
  1698. .nf
  1699. MACRO = \fIvalue1\fP
  1700. NEW = $(MACRO)
  1701. MACRO = \fIvalue2\fP
  1702. .P
  1703. target:
  1704. echo $(NEW)
  1705. .fi
  1706. .P
  1707. .RE
  1708. .P
  1709. would produce
  1710. .IR value2
  1711. and not
  1712. .IR value1
  1713. since
  1714. .BR NEW
  1715. was not expanded until it was needed in the
  1716. .IR echo
  1717. command line.
  1718. .P
  1719. Some historical applications have been known to intermix
  1720. .IR target_name
  1721. and
  1722. .IR macro=name
  1723. operands on the command line, expecting that all of the macros are
  1724. processed before any of the targets are dealt with. Conforming
  1725. applications do not do this, although some backwards-compatibility
  1726. support may be included in some implementations.
  1727. .P
  1728. The following characters in filenames may give trouble:
  1729. .BR '=' ,
  1730. .BR ':' ,
  1731. .BR '`' ,
  1732. single-quote, and
  1733. .BR '@' .
  1734. In include filenames, pattern matching characters and
  1735. .BR '\&"'
  1736. should also be avoided, as they may be treated as special by some
  1737. implementations.
  1738. .P
  1739. For inference rules, the description of $< and $? seem similar. However,
  1740. an example shows the minor difference. In a makefile containing:
  1741. .sp
  1742. .RS 4
  1743. .nf
  1744. foo.o: foo.h
  1745. .fi
  1746. .P
  1747. .RE
  1748. .P
  1749. if
  1750. .BR foo.h
  1751. is newer than
  1752. .BR foo.o ,
  1753. yet
  1754. .BR foo.c
  1755. is older than
  1756. .BR foo.o ,
  1757. the built-in rule to make
  1758. .BR foo.o
  1759. from
  1760. .BR foo.c
  1761. is used, with $< equal to
  1762. .BR foo.c
  1763. and $? equal to
  1764. .BR foo.h .
  1765. If
  1766. .BR foo.c
  1767. is also newer than
  1768. .BR foo.o ,
  1769. $< is equal to
  1770. .BR foo.c
  1771. and $? is equal to
  1772. .BR "foo.h foo.c" .
  1773. .P
  1774. As a consequence of the general rules for target updating, a useful
  1775. special case is that if a target has no prerequisites and no commands,
  1776. and the target of the rule is a nonexistent file, then
  1777. .IR make
  1778. acts as if this target has been updated whenever its rule is run.
  1779. .TP 10
  1780. .BR Note:
  1781. This implies that all targets depending on this one will always
  1782. have their commands run.
  1783. .P
  1784. .P
  1785. Shell command sequences like
  1786. .IR "make;\ cp\ original\ copy;\ make"
  1787. may have problems on filesystems where the timestamp resolution is the
  1788. minimum (1 second) required by the standard and where
  1789. .IR make
  1790. considers identical timestamps to be up-to-date. Conversely, rules like
  1791. .IR "copy:\ original;\ cp\ -p\ original\ copy"
  1792. will result in redundant work on
  1793. .IR make
  1794. implementations that consider identical timestamps to be out-of-date.
  1795. .P
  1796. This standard does not specify precedence between macro definition and
  1797. include directives. Thus, the behavior of:
  1798. .sp
  1799. .RS 4
  1800. .nf
  1801. include =foo.mk
  1802. .fi
  1803. .P
  1804. .RE
  1805. .P
  1806. is unspecified. To define a variable named include, either the white
  1807. space before the
  1808. <equal-sign>
  1809. should be removed, or another macro should be used, as in:
  1810. .sp
  1811. .RS 4
  1812. .nf
  1813. INCLUDE_NAME = include
  1814. $(INCLUDE_NAME) =foo.mk
  1815. .fi
  1816. .P
  1817. .RE
  1818. .P
  1819. On the other hand, if the intent is to include a file which starts with an
  1820. <equal-sign>,
  1821. either the filename should be changed to
  1822. .IR "./=foo.mk" ,
  1823. or the makefile should be written as:
  1824. .sp
  1825. .RS 4
  1826. .nf
  1827. INCLUDE_FILE = =foo.mk
  1828. include $(INCLUDE_FILE)
  1829. .fi
  1830. .P
  1831. .RE
  1832. .SH EXAMPLES
  1833. .IP " 1." 4
  1834. The following command:
  1835. .RS 4
  1836. .sp
  1837. .RS 4
  1838. .nf
  1839. make
  1840. .fi
  1841. .P
  1842. .RE
  1843. .P
  1844. makes the first target found in the makefile.
  1845. .RE
  1846. .IP " 2." 4
  1847. The following command:
  1848. .RS 4
  1849. .sp
  1850. .RS 4
  1851. .nf
  1852. make junk
  1853. .fi
  1854. .P
  1855. .RE
  1856. .P
  1857. makes the target
  1858. .BR junk .
  1859. .RE
  1860. .IP " 3." 4
  1861. The following makefile says that
  1862. .BR pgm
  1863. depends on two files,
  1864. .BR a.o
  1865. and
  1866. .BR b.o ,
  1867. and that they in turn depend on their corresponding source files (\c
  1868. .BR a.c
  1869. and
  1870. .BR b.c ),
  1871. and a common file
  1872. .BR incl.h :
  1873. .RS 4
  1874. .sp
  1875. .RS 4
  1876. .nf
  1877. \&.POSIX:
  1878. pgm: a.o b.o
  1879. c99 a.o b.o -o pgm
  1880. a.o: incl.h a.c
  1881. c99 -c a.c
  1882. b.o: incl.h b.c
  1883. c99 -c b.c
  1884. .fi
  1885. .P
  1886. .RE
  1887. .RE
  1888. .IP " 4." 4
  1889. An example for making optimized
  1890. .BR .o
  1891. files from
  1892. .BR .c
  1893. files is:
  1894. .RS 4
  1895. .sp
  1896. .RS 4
  1897. .nf
  1898. \&.c.o:
  1899. c99 -c -O 1 $*.c
  1900. .fi
  1901. .P
  1902. .RE
  1903. .P
  1904. or:
  1905. .sp
  1906. .RS 4
  1907. .nf
  1908. \&.c.o:
  1909. c99 -c -O 1 $<
  1910. .fi
  1911. .P
  1912. .RE
  1913. .RE
  1914. .IP " 5." 4
  1915. The most common use of the archive interface follows. Here, it is
  1916. assumed that the source files are all C-language source:
  1917. .RS 4
  1918. .sp
  1919. .RS 4
  1920. .nf
  1921. lib: lib(file1.o) lib(file2.o) lib(file3.o)
  1922. @echo lib is now up-to-date
  1923. .fi
  1924. .P
  1925. .RE
  1926. .P
  1927. The
  1928. .BR .c.a
  1929. rule is used to make
  1930. .BR file1.o ,
  1931. .BR file2.o ,
  1932. and
  1933. .BR file3.o
  1934. and insert them into
  1935. .BR lib .
  1936. .P
  1937. The treatment of escaped
  1938. <newline>
  1939. characters throughout the makefile is historical practice. For example,
  1940. the inference rule:
  1941. .sp
  1942. .RS 4
  1943. .nf
  1944. \&.c.o\e
  1945. :
  1946. .fi
  1947. .P
  1948. .RE
  1949. .P
  1950. works, and the macro:
  1951. .sp
  1952. .RS 4
  1953. .nf
  1954. f= bar baz\e
  1955. biz
  1956. a:
  1957. echo ==$f==
  1958. .fi
  1959. .P
  1960. .RE
  1961. .P
  1962. echoes
  1963. .BR \(dq==bar\ baz\ biz==\(dq .
  1964. .P
  1965. If $? were:
  1966. .sp
  1967. .RS 4
  1968. .nf
  1969. /usr/include/stdio.h /usr/include/unistd.h foo.h
  1970. .fi
  1971. .P
  1972. .RE
  1973. .P
  1974. then $(?D) would be:
  1975. .sp
  1976. .RS 4
  1977. .nf
  1978. /usr/include /usr/include .
  1979. .fi
  1980. .P
  1981. .RE
  1982. .P
  1983. and $(?F) would be:
  1984. .sp
  1985. .RS 4
  1986. .nf
  1987. stdio.h unistd.h foo.h
  1988. .fi
  1989. .P
  1990. .RE
  1991. .RE
  1992. .IP " 6." 4
  1993. The contents of the built-in rules can be viewed by running:
  1994. .RS 4
  1995. .sp
  1996. .RS 4
  1997. .nf
  1998. make -p -f /dev/null 2>/dev/null
  1999. .fi
  2000. .P
  2001. .RE
  2002. .RE
  2003. .SH RATIONALE
  2004. The
  2005. .IR make
  2006. utility described in this volume of POSIX.1\(hy2017 is intended to provide the means for
  2007. changing portable source code into executables that can be run on an
  2008. POSIX.1\(hy2008-conforming system. It reflects the most common features present
  2009. in System V and BSD
  2010. .IR make s.
  2011. .P
  2012. Historically, the
  2013. .IR make
  2014. utility has been an especially fertile ground for vendor and research
  2015. organization-specific syntax modifications and extensions. Examples
  2016. include:
  2017. .IP " *" 4
  2018. Syntax supporting parallel execution (such as from various
  2019. multi-processor vendors, GNU, and others)
  2020. .IP " *" 4
  2021. Additional ``operators'' separating targets and their prerequisites
  2022. (System V, BSD, and others)
  2023. .IP " *" 4
  2024. Specifying that command lines containing the strings
  2025. .BR \(dq${MAKE}\(dq
  2026. and
  2027. .BR \(dq$(MAKE)\(dq
  2028. are executed when the
  2029. .BR \-n
  2030. option is specified (GNU and System V)
  2031. .IP " *" 4
  2032. Modifications of the meaning of internal macros when referencing
  2033. libraries (BSD and others)
  2034. .IP " *" 4
  2035. Using a single instance of the shell for all of the command lines of
  2036. the target (BSD and others)
  2037. .IP " *" 4
  2038. Allowing
  2039. <space>
  2040. characters as well as
  2041. <tab>
  2042. characters to delimit command lines (BSD)
  2043. .IP " *" 4
  2044. Adding C preprocessor-style ``include'' and ``ifdef'' constructs
  2045. (System V, GNU, BSD, and others)
  2046. .IP " *" 4
  2047. Remote execution of command lines (Sprite and others)
  2048. .IP " *" 4
  2049. Specifying additional special targets (BSD, System V, and most others)
  2050. .IP " *" 4
  2051. Specifying an alternate shell to use to process commands.
  2052. .P
  2053. Additionally, many vendors and research organizations have rethought
  2054. the basic concepts of
  2055. .IR make ,
  2056. creating vastly extended, as well as completely new, syntaxes. Each of
  2057. these versions of
  2058. .IR make
  2059. fulfills the needs of a different community of users; it is
  2060. unreasonable for this volume of POSIX.1\(hy2017 to require behavior that would be incompatible
  2061. (and probably inferior) to historical practice for such a community.
  2062. .P
  2063. In similar circumstances, when the industry has enough sufficiently
  2064. incompatible formats as to make them irreconcilable, this volume of POSIX.1\(hy2017 has followed
  2065. one or both of two courses of action. Commands have been renamed (\c
  2066. .IR cksum ,
  2067. .IR echo ,
  2068. and
  2069. .IR pax )
  2070. and/or command line options have been provided to select the desired
  2071. behavior (\c
  2072. .IR grep ,
  2073. .IR od ,
  2074. and
  2075. .IR pax ).
  2076. .P
  2077. Because the syntax specified for the
  2078. .IR make
  2079. utility is, by and large, a subset of the syntaxes accepted by almost
  2080. all versions of
  2081. .IR make ,
  2082. it was decided that it would be counter-productive to change the name.
  2083. And since the makefile itself is a basic unit of portability, it would
  2084. not be completely effective to reserve a new option letter, such as
  2085. .IR make
  2086. .BR \-P ,
  2087. to achieve the portable behavior. Therefore, the special target
  2088. .BR .POSIX
  2089. was added to the makefile, allowing users to specify ``standard''
  2090. behavior. This special target does not preclude extensions in the
  2091. .IR make
  2092. utility, nor does it preclude such extensions being used by the
  2093. makefile specifying the target; it does, however, preclude any
  2094. extensions from being applied that could alter the behavior of
  2095. previously valid syntax; such extensions must be controlled via
  2096. command line options or new special targets. It is incumbent upon
  2097. portable makefiles to specify the
  2098. .BR .POSIX
  2099. special target in order to guarantee that they are not affected by
  2100. local extensions.
  2101. .P
  2102. The portable version of
  2103. .IR make
  2104. described in this reference page is not intended to be the
  2105. state-of-the-art software generation tool and, as such, some newer and
  2106. more leading-edge features have not been included. An attempt has been
  2107. made to describe the portable makefile in a manner that does not
  2108. preclude such extensions as long as they do not disturb the portable
  2109. behavior described here.
  2110. .P
  2111. When the
  2112. .BR \-n
  2113. option is specified, it is always added to
  2114. .IR MAKEFLAGS .
  2115. This allows a recursive
  2116. .IR make
  2117. .BR \-n
  2118. .IR target
  2119. to be used to see all of the action that would be taken to update
  2120. .IR target .
  2121. .P
  2122. The definition of
  2123. .IR MAKEFLAGS
  2124. allows both the System V letter string and the BSD command line
  2125. formats. The two formats are sufficiently different to allow
  2126. implementations to support both without ambiguity.
  2127. .P
  2128. Early proposals stated that an ``unquoted''
  2129. <number-sign>
  2130. was treated as the start of a comment. The
  2131. .IR make
  2132. utility does not pay any attention to quotes. A
  2133. <number-sign>
  2134. starts a comment regardless of its surroundings.
  2135. .P
  2136. The text about ``other implementation-defined pathnames may also be
  2137. tried'' in addition to
  2138. .BR ./makefile
  2139. and
  2140. .BR ./Makefile
  2141. is to allow such extensions as
  2142. .BR SCCS/s.Makefile
  2143. and other variations. It was made an implementation-defined
  2144. requirement (as opposed to unspecified behavior) to highlight
  2145. surprising implementations that might select something unexpected like
  2146. .BR /etc/Makefile .
  2147. XSI-conformant systems also try
  2148. .BR ./s.makefile ,
  2149. .BR SCCS/s.makefile ,
  2150. .BR ./s.Makefile ,
  2151. and
  2152. .BR SCCS/s.Makefile .
  2153. .P
  2154. Early proposals contained the macro
  2155. .BR NPROC
  2156. as a means of specifying that
  2157. .IR make
  2158. should use
  2159. .IR n
  2160. processes to do the work required. While this feature is a valuable
  2161. extension for many systems, it is not common usage and could require
  2162. other non-trivial extensions to makefile syntax. This extension is not
  2163. required by this volume of POSIX.1\(hy2017, but could be provided as a compatible extension. The
  2164. macro
  2165. .BR PARALLEL
  2166. is used by some historical systems with essentially the same meaning
  2167. (but without using a name that is a common system limit value). It is
  2168. suggested that implementors recognize the existing use of
  2169. .BR NPROC
  2170. and/or
  2171. .BR PARALLEL
  2172. as extensions to
  2173. .IR make .
  2174. .P
  2175. The default rules are based on System V. The default
  2176. .BR CC=
  2177. value is
  2178. .IR c99
  2179. instead of
  2180. .IR cc
  2181. because this volume of POSIX.1\(hy2017 does not standardize the utility named
  2182. .IR cc .
  2183. Thus, every conforming application would be required to define
  2184. .BR CC= \c
  2185. .IR c99
  2186. to expect to run. There is no advantage conferred by the hope that the
  2187. makefile might hit the ``preferred'' compiler because this cannot be
  2188. guaranteed to work. Also, since the portable makescript can only use
  2189. the
  2190. .IR c99
  2191. options, no advantage is conferred in terms of what the script can do.
  2192. It is a quality-of-implementation issue as to whether
  2193. .IR c99
  2194. is as valuable as
  2195. .IR cc .
  2196. .P
  2197. The
  2198. .BR \-d
  2199. option to
  2200. .IR make
  2201. is frequently used to produce debugging information, but is too
  2202. implementation-defined to add to this volume of POSIX.1\(hy2017.
  2203. .P
  2204. The
  2205. .BR \-p
  2206. option is not passed in
  2207. .IR MAKEFLAGS
  2208. on most historical implementations and to change this would cause many
  2209. implementations to break without sufficiently increased portability.
  2210. .P
  2211. Commands that begin with a
  2212. <plus-sign>
  2213. (\c
  2214. .BR '\(pl' )
  2215. are executed even if the
  2216. .BR \-n
  2217. option is present. Based on the GNU version of
  2218. .IR make ,
  2219. the behavior of
  2220. .BR \-n
  2221. when the
  2222. <plus-sign>
  2223. prefix is encountered has been extended to apply to
  2224. .BR \-q
  2225. and
  2226. .BR \-t
  2227. as well. However, the System V convention of forcing command execution
  2228. with
  2229. .BR \-n
  2230. when the command line of a target contains either of the strings
  2231. .BR \(dq$(MAKE)\(dq
  2232. or
  2233. .BR \(dq${MAKE}\(dq
  2234. has not been adopted. This functionality appeared in early proposals,
  2235. but the danger of this approach was pointed out with the following
  2236. example of a portion of a makefile:
  2237. .sp
  2238. .RS 4
  2239. .nf
  2240. subdir:
  2241. cd subdir; rm all_the_files; $(MAKE)
  2242. .fi
  2243. .P
  2244. .RE
  2245. .P
  2246. The loss of the System V behavior in this case is well-balanced by the
  2247. safety afforded to other makefiles that were not aware of this
  2248. situation. In any event, the command line
  2249. <plus-sign>
  2250. prefix can provide the desired functionality.
  2251. .P
  2252. The double
  2253. <colon>
  2254. in the target rule format is supported in BSD systems to allow more
  2255. than one target line containing the same target name to have commands
  2256. associated with it. Since this is not functionality described in the
  2257. SVID or XPG3 it has been allowed as an extension, but not mandated.
  2258. .P
  2259. The default rules are provided with text specifying that the built-in
  2260. rules shall be the same as if the listed set were used. The intent is
  2261. that implementations should be able to use the rules without change,
  2262. but will be allowed to alter them in ways that do not affect the
  2263. primary behavior.
  2264. .P
  2265. One point of discussion was whether to drop the default rules list from
  2266. \&this volume of POSIX.1\(hy2017. They provide convenience, but do not enhance portability of
  2267. applications. The prime benefit is in portability of users who wish to
  2268. type
  2269. .IR make
  2270. .IR command
  2271. and have the command build from a
  2272. .BR command.c
  2273. file.
  2274. .P
  2275. The historical
  2276. .IR MAKESHELL
  2277. feature, and related features provided by other
  2278. .IR make
  2279. implementations, were omitted. In some implementations it is used
  2280. to let a user override the shell to be used to run
  2281. .IR make
  2282. commands. This was confusing; for a portable
  2283. .IR make ,
  2284. the shell should be chosen by the makefile writer. Further, a makefile
  2285. writer cannot require an alternate shell to be used and still consider
  2286. the makefile portable. While it would be possible to standardize a
  2287. mechanism for specifying an alternate shell, existing implementations
  2288. do not agree on such a mechanism, and makefile writers can already
  2289. invoke an alternate shell by specifying the shell name in the rule
  2290. for a target; for example:
  2291. .sp
  2292. .RS 4
  2293. .nf
  2294. python -c "foo"
  2295. .fi
  2296. .P
  2297. .RE
  2298. .P
  2299. The
  2300. .IR make
  2301. utilities in most historical implementations process the prerequisites
  2302. of a target in left-to-right order, and the makefile format
  2303. requires this. It supports the standard idiom used in many makefiles
  2304. that produce
  2305. .IR yacc
  2306. programs; for example:
  2307. .sp
  2308. .RS 4
  2309. .nf
  2310. foo: y.tab.o lex.o main.o
  2311. $(CC) $(CFLAGS) -o $\fR@\fP t.tab.o lex.o main.o
  2312. .fi
  2313. .P
  2314. .RE
  2315. .P
  2316. In this example, if
  2317. .IR make
  2318. chose any arbitrary order, the
  2319. .BR lex.o
  2320. might not be made with the correct
  2321. .BR y.tab.h .
  2322. Although there may be better ways to express this relationship, it is
  2323. widely used historically. Implementations that desire to update
  2324. prerequisites in parallel should require an explicit extension to
  2325. .IR make
  2326. or the makefile format to accomplish it, as described previously.
  2327. .P
  2328. The algorithm for determining a new entry for target rules is partially
  2329. unspecified. Some historical
  2330. .IR make s
  2331. allow comment lines (including blank and empty lines) within the
  2332. collection of commands marked by leading
  2333. <tab>
  2334. characters. A conforming makefile must ensure that each command starts
  2335. with a
  2336. <tab>,
  2337. but implementations are free to ignore comments without triggering
  2338. the start of a new entry.
  2339. .P
  2340. The ASYNCHRONOUS EVENTS section includes having SIGTERM and SIGHUP,
  2341. along with the more traditional SIGINT and SIGQUIT, remove the current
  2342. target unless directed not to do so. SIGTERM and SIGHUP were added to
  2343. parallel other utilities that have historically cleaned up their work
  2344. as a result of these signals. When
  2345. .IR make
  2346. receives any signal other than SIGQUIT, it is required to resend itself
  2347. the signal it received so that it exits with a status that reflects the
  2348. signal. The results from SIGQUIT are partially unspecified because, on
  2349. systems that create
  2350. .BR core
  2351. files upon receipt of SIGQUIT, the
  2352. .BR core
  2353. from
  2354. .IR make
  2355. would conflict with a
  2356. .BR core
  2357. file from the command that was running when the SIGQUIT arrived. The
  2358. main concern was to prevent damaged files from appearing up-to-date when
  2359. .IR make
  2360. is rerun.
  2361. .P
  2362. The
  2363. .BR .PRECIOUS
  2364. special target was extended to affect all targets globally (by
  2365. specifying no prerequisites). The
  2366. .BR .IGNORE
  2367. and
  2368. .BR .SILENT
  2369. special targets were extended to allow prerequisites; it was judged to
  2370. be more useful in some cases to be able to turn off errors or echoing
  2371. for a list of targets than for the entire makefile. These extensions
  2372. to
  2373. .IR make
  2374. in System V were made to match historical practice from the BSD
  2375. .IR make .
  2376. .P
  2377. Macros are not exported to the environment of commands to be run. This
  2378. was never the case in any historical
  2379. .IR make
  2380. and would have serious consequences. The environment is the same as
  2381. the environment to
  2382. .IR make
  2383. except that
  2384. .IR MAKEFLAGS
  2385. and macros defined on the
  2386. .IR make
  2387. command line are added, and except that macros defined by the
  2388. .IR MAKEFLAGS
  2389. environment variable and macros defined in the makefile(s) may update the
  2390. value of an existing environment variable (other than
  2391. .IR SHELL ).
  2392. .P
  2393. Some implementations do not use
  2394. \fIsystem\fR()
  2395. for all command lines, as required by the portable makefile
  2396. format; as a performance enhancement, they select lines without shell
  2397. metacharacters for direct execution by
  2398. \fIexecve\fR().
  2399. There is no requirement that
  2400. \fIsystem\fR()
  2401. be used specifically, but merely that the same results be achieved.
  2402. The metacharacters typically used to bypass the direct
  2403. \fIexecve\fR()
  2404. execution have been any of:
  2405. .sp
  2406. .RS 4
  2407. .nf
  2408. = | \(ha ( ) ; & < > * ? [ ] : $ ` \(aq " \e \en
  2409. .fi
  2410. .P
  2411. .RE
  2412. .P
  2413. The default in some advanced versions of
  2414. .IR make
  2415. is to group all the command lines for a target and execute them using a
  2416. single shell invocation; the System V method is to pass each line
  2417. individually to a separate shell. The single-shell method has the
  2418. advantages in performance and the lack of a requirement for many
  2419. continued lines. However, converting to this newer method has caused
  2420. portability problems with many historical makefiles, so the behavior
  2421. with the POSIX makefile is specified to be the same as that of System
  2422. V. It is suggested that the special target
  2423. .BR .ONESHELL
  2424. be used as an implementation extension to achieve the single-shell
  2425. grouping for a target or group of targets.
  2426. .P
  2427. Novice users of
  2428. .IR make
  2429. have had difficulty with the historical need to start commands with a
  2430. <tab>.
  2431. Since it is often difficult to discern differences between
  2432. <tab>
  2433. and
  2434. <space>
  2435. characters on terminals or printed listings, confusing bugs can arise. In
  2436. early proposals, an attempt was made to correct this problem by allowing
  2437. leading
  2438. <blank>
  2439. characters instead of
  2440. <tab>
  2441. characters. However, implementors reported many makefiles that failed
  2442. in subtle ways following this change, and it is difficult to implement a
  2443. .IR make
  2444. that unambiguously can differentiate between macro and command lines.
  2445. There is extensive historical practice of allowing leading
  2446. <space>
  2447. characters before macro definitions. Forcing macro lines into column 1
  2448. would be a significant backwards-compatibility problem for some makefiles.
  2449. Therefore, historical practice was restored.
  2450. .P
  2451. There is substantial variation in the handling of include lines by
  2452. different implementations. However, there is enough commonality for the
  2453. standard to be able to specify a minimum set of requirements that allow
  2454. the feature to be used portably. Known variations have been explicitly
  2455. called out as unspecified behavior in the description.
  2456. .P
  2457. The System V dynamic dependency feature was not included. It would
  2458. support:
  2459. .sp
  2460. .RS 4
  2461. .nf
  2462. cat: $$@.c
  2463. .fi
  2464. .P
  2465. .RE
  2466. .P
  2467. that would expand to;
  2468. .sp
  2469. .RS 4
  2470. .nf
  2471. cat: cat.c
  2472. .fi
  2473. .P
  2474. .RE
  2475. .P
  2476. This feature exists only in the new version of System V
  2477. .IR make
  2478. and, while useful, is not in wide usage. This means that macros are
  2479. expanded twice for prerequisites: once at makefile parse time and once
  2480. at target update time.
  2481. .P
  2482. Consideration was given to adding metarules to the POSIX
  2483. .IR make .
  2484. This would make
  2485. .BR "%.o:\ %.c"
  2486. the same as
  2487. .BR .c.o: .
  2488. This is quite useful and available from some vendors, but it would
  2489. cause too many changes to this
  2490. .IR make
  2491. to support. It would have introduced rule chaining and new substitution
  2492. rules. However, the rules for target names have been set to reserve the
  2493. .BR '%'
  2494. and
  2495. .BR '\&"'
  2496. characters. These are traditionally used to implement metarules and
  2497. quoting of target names, respectively. Implementors are strongly
  2498. encouraged to use these characters only for these purposes.
  2499. .P
  2500. A request was made to extend the suffix delimiter character from a
  2501. <period>
  2502. to any character. The metarules feature in newer
  2503. .IR make s
  2504. solves this problem in a more general way. This volume of POSIX.1\(hy2017 is staying with the
  2505. more conservative historical definition.
  2506. .P
  2507. The standard output format for the
  2508. .BR \-p
  2509. option is not described because it is primarily a debugging option and
  2510. because the format is not generally useful to programs. In historical
  2511. implementations the output is not suitable for use in generating
  2512. makefiles. The
  2513. .BR \-p
  2514. format has been variable across historical implementations. Therefore,
  2515. the definition of
  2516. .BR \-p
  2517. was only to provide a consistently named option for obtaining
  2518. .IR make
  2519. script debugging information.
  2520. .P
  2521. Some historical implementations have not cleared the suffix list with
  2522. .BR \-r .
  2523. .P
  2524. Implementations should be aware that some historical applications have
  2525. intermixed
  2526. .IR target_name
  2527. and
  2528. .IR macro =\c
  2529. .IR value
  2530. operands on the command line, expecting that all of the macros are
  2531. processed before any of the targets are dealt with. Conforming
  2532. applications do not do this, but some backwards-compatibility support
  2533. may be warranted.
  2534. .P
  2535. Empty inference rules are specified with a
  2536. <semicolon>
  2537. command rather than omitting all commands, as described in an early
  2538. proposal. The latter case has no traditional meaning and is reserved
  2539. for implementation extensions, such as in GNU
  2540. .IR make .
  2541. .P
  2542. Earlier versions of this standard defined comment lines only as lines with
  2543. .BR '#'
  2544. as the first character. Many places then talked about comments, blank
  2545. lines, and empty lines; but some places inadvertently only mentioned
  2546. comments when blank lines and empty lines had also been accepted in
  2547. all known implementations. The standard now defines comment lines to
  2548. be blank lines, empty lines, and lines starting with a
  2549. .BR '#'
  2550. character and explictily lists cases where blank lines and empty lines
  2551. are not acceptable.
  2552. .P
  2553. On most historic systems, the
  2554. .IR make
  2555. utility considered a target with a prerequisite that had an identical
  2556. timestamp as up-to-date. The HP-UX implementation of
  2557. .IR make
  2558. treated it as out-of-date. The standard now allows either behavior,
  2559. but implementations are encouraged to follow the example set by HP-UX.
  2560. This is especially important on file systems where the timestamp
  2561. resolution is the minimum (1 second) required by the standard. All
  2562. implementations of
  2563. .IR make
  2564. should make full use of the finest timestamp resolution available on
  2565. the file systems holding targets and prerequisites to ensure that
  2566. targets are up-to-date even for prerequisite files with timestamps
  2567. that were updated within the same second. However, if the timestamp
  2568. resolutions of the file systems containing a target and a prerequisite
  2569. are different, the timestamp with the more precise resolution should
  2570. be rounded down to the resolution of the less precise timestamp for
  2571. the comparison.
  2572. .SH "FUTURE DIRECTIONS"
  2573. Some implementations of
  2574. .IR make
  2575. include an
  2576. .IR export
  2577. directive to add specified
  2578. .IR make
  2579. variables to the environment. This may be considered for
  2580. standardization in a future version.
  2581. .P
  2582. A future version of this standard may require that macro expansions
  2583. using the forms $(\c
  2584. .IR string1 \c
  2585. .BR :[ \c
  2586. .IR op \c
  2587. .BR ]%[ \c
  2588. .IR os \c
  2589. .BR ]=[ \c
  2590. .IR np \c
  2591. .BR ][%][ \c
  2592. .IR ns \c
  2593. .BR ] )
  2594. or ${\c
  2595. .IR string1 \c
  2596. .BR :[ \c
  2597. .IR op \c
  2598. .BR ]%[ \c
  2599. .IR os \c
  2600. .BR ]=[ \c
  2601. .IR np \c
  2602. .BR ][%][ \c
  2603. .IR ns \c
  2604. .BR ] }
  2605. are treated as pattern macro expansions.
  2606. .SH "SEE ALSO"
  2607. .IR "Chapter 2" ", " "Shell Command Language",
  2608. .IR "\fIar\fR\^",
  2609. .IR "\fIc99\fR\^",
  2610. .IR "\fIget\fR\^",
  2611. .IR "\fIlex\fR\^",
  2612. .IR "\fIsccs\fR\^",
  2613. .IR "\fIsh\fR\^",
  2614. .IR "\fIyacc\fR\^"
  2615. .P
  2616. The Base Definitions volume of POSIX.1\(hy2017,
  2617. .IR "Section 6.1" ", " "Portable Character Set",
  2618. .IR "Chapter 8" ", " "Environment Variables",
  2619. .IR "Section 12.2" ", " "Utility Syntax Guidelines"
  2620. .P
  2621. The System Interfaces volume of POSIX.1\(hy2017,
  2622. .IR "\fIexec\fR\^",
  2623. .IR "\fIsystem\fR\^(\|)"
  2624. .\"
  2625. .SH COPYRIGHT
  2626. Portions of this text are reprinted and reproduced in electronic form
  2627. from IEEE Std 1003.1-2017, Standard for Information Technology
  2628. -- Portable Operating System Interface (POSIX), The Open Group Base
  2629. Specifications Issue 7, 2018 Edition,
  2630. Copyright (C) 2018 by the Institute of
  2631. Electrical and Electronics Engineers, Inc and The Open Group.
  2632. In the event of any discrepancy between this version and the original IEEE and
  2633. The Open Group Standard, the original IEEE and The Open Group Standard
  2634. is the referee document. The original Standard can be obtained online at
  2635. http://www.opengroup.org/unix/online.html .
  2636. .PP
  2637. Any typographical or formatting errors that appear
  2638. in this page are most likely
  2639. to have been introduced during the conversion of the source files to
  2640. man page format. To report such errors, see
  2641. https://www.kernel.org/doc/man-pages/reporting_bugs.html .