]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/make.1
Update to bmake-20201101
[FreeBSD/FreeBSD.git] / contrib / bmake / make.1
1 .\"     $NetBSD: make.1,v 1.290 2020/11/01 20:24:45 rillig Exp $
2 .\"
3 .\" Copyright (c) 1990, 1993
4 .\"     The Regents of the University of California.  All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in the
13 .\"    documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\"    may be used to endorse or promote products derived from this software
16 .\"    without specific prior written permission.
17 .\"
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" SUCH DAMAGE.
29 .\"
30 .\"     from: @(#)make.1        8.4 (Berkeley) 3/19/94
31 .\"
32 .Dd November 1, 2020
33 .Dt MAKE 1
34 .Os
35 .Sh NAME
36 .Nm make
37 .Nd maintain program dependencies
38 .Sh SYNOPSIS
39 .Nm
40 .Op Fl BeikNnqrstWwX
41 .Op Fl C Ar directory
42 .Op Fl D Ar variable
43 .Op Fl d Ar flags
44 .Op Fl f Ar makefile
45 .Op Fl I Ar directory
46 .Op Fl J Ar private
47 .Op Fl j Ar max_jobs
48 .Op Fl m Ar directory
49 .Op Fl T Ar file
50 .Op Fl V Ar variable
51 .Op Fl v Ar variable
52 .Op Ar variable=value
53 .Op Ar target ...
54 .Sh DESCRIPTION
55 .Nm
56 is a program designed to simplify the maintenance of other programs.
57 Its input is a list of specifications as to the files upon which programs
58 and other files depend.
59 If no
60 .Fl f Ar makefile
61 makefile option is given,
62 .Nm
63 will try to open
64 .Ql Pa makefile
65 then
66 .Ql Pa Makefile
67 in order to find the specifications.
68 If the file
69 .Ql Pa .depend
70 exists, it is read (see
71 .Xr mkdep 1 ) .
72 .Pp
73 This manual page is intended as a reference document only.
74 For a more thorough description of
75 .Nm
76 and makefiles, please refer to
77 .%T "PMake \- A Tutorial" .
78 .Pp
79 .Nm
80 will prepend the contents of the
81 .Va MAKEFLAGS
82 environment variable to the command line arguments before parsing them.
83 .Pp
84 The options are as follows:
85 .Bl -tag -width Ds
86 .It Fl B
87 Try to be backwards compatible by executing a single shell per command and
88 by executing the commands to make the sources of a dependency line in sequence.
89 .It Fl C Ar directory
90 Change to
91 .Ar directory
92 before reading the makefiles or doing anything else.
93 If multiple
94 .Fl C
95 options are specified, each is interpreted relative to the previous one:
96 .Fl C Pa / Fl C Pa etc
97 is equivalent to
98 .Fl C Pa /etc .
99 .It Fl D Ar variable
100 Define
101 .Ar variable
102 to be 1, in the global context.
103 .It Fl d Ar [-]flags
104 Turn on debugging, and specify which portions of
105 .Nm
106 are to print debugging information.
107 Unless the flags are preceded by
108 .Ql \-
109 they are added to the
110 .Va MAKEFLAGS
111 environment variable and will be processed by any child make processes.
112 By default, debugging information is printed to standard error,
113 but this can be changed using the
114 .Ar F
115 debugging flag.
116 The debugging output is always unbuffered; in addition, if debugging
117 is enabled but debugging output is not directed to standard output,
118 then the standard output is line buffered.
119 .Ar Flags
120 is one or more of the following:
121 .Bl -tag -width Ds
122 .It Ar A
123 Print all possible debugging information;
124 equivalent to specifying all of the debugging flags.
125 .It Ar a
126 Print debugging information about archive searching and caching.
127 .It Ar C
128 Print debugging information about current working directory.
129 .It Ar c
130 Print debugging information about conditional evaluation.
131 .It Ar d
132 Print debugging information about directory searching and caching.
133 .It Ar e
134 Print debugging information about failed commands and targets.
135 .It Ar F Ns Oo Sy \&+ Oc Ns Ar filename
136 Specify where debugging output is written.
137 This must be the last flag, because it consumes the remainder of
138 the argument.
139 If the character immediately after the
140 .Ql F
141 flag is
142 .Ql \&+ ,
143 then the file will be opened in append mode;
144 otherwise the file will be overwritten.
145 If the file name is
146 .Ql stdout
147 or
148 .Ql stderr
149 then debugging output will be written to the
150 standard output or standard error output file descriptors respectively
151 (and the
152 .Ql \&+
153 option has no effect).
154 Otherwise, the output will be written to the named file.
155 If the file name ends
156 .Ql .%d
157 then the
158 .Ql %d
159 is replaced by the pid.
160 .It Ar f
161 Print debugging information about loop evaluation.
162 .It Ar "g1"
163 Print the input graph before making anything.
164 .It Ar "g2"
165 Print the input graph after making everything, or before exiting
166 on error.
167 .It Ar "g3"
168 Print the input graph before exiting on error.
169 .It Ar h
170 Print debugging information about hash table operations.
171 .It Ar j
172 Print debugging information about running multiple shells.
173 .It Ar L
174 Turn on lint checks.
175 This will throw errors for variable assignments that do not parse
176 correctly, at the time of assignment so the file and line number
177 are available.
178 .It Ar l
179 Print commands in Makefiles regardless of whether or not they are prefixed by
180 .Ql @
181 or other "quiet" flags.
182 Also known as "loud" behavior.
183 .It Ar M
184 Print debugging information about "meta" mode decisions about targets.
185 .It Ar m
186 Print debugging information about making targets, including modification
187 dates.
188 .It Ar n
189 Don't delete the temporary command scripts created when running commands.
190 These temporary scripts are created in the directory
191 referred to by the
192 .Ev TMPDIR
193 environment variable, or in
194 .Pa /tmp
195 if
196 .Ev TMPDIR
197 is unset or set to the empty string.
198 The temporary scripts are created by
199 .Xr mkstemp 3 ,
200 and have names of the form
201 .Pa makeXXXXXX .
202 .Em NOTE :
203 This can create many files in
204 .Ev TMPDIR
205 or
206 .Pa /tmp ,
207 so use with care.
208 .It Ar p
209 Print debugging information about makefile parsing.
210 .It Ar s
211 Print debugging information about suffix-transformation rules.
212 .It Ar t
213 Print debugging information about target list maintenance.
214 .It Ar V
215 Force the
216 .Fl V
217 option to print raw values of variables, overriding the default behavior
218 set via
219 .Va .MAKE.EXPAND_VARIABLES .
220 .It Ar v
221 Print debugging information about variable assignment.
222 .It Ar x
223 Run shell commands with
224 .Fl x
225 so the actual commands are printed as they are executed.
226 .El
227 .It Fl e
228 Specify that environment variables override macro assignments within
229 makefiles.
230 .It Fl f Ar makefile
231 Specify a makefile to read instead of the default
232 .Ql Pa makefile .
233 If
234 .Ar makefile
235 is
236 .Ql Fl ,
237 standard input is read.
238 Multiple makefiles may be specified, and are read in the order specified.
239 .It Fl I Ar directory
240 Specify a directory in which to search for makefiles and included makefiles.
241 The system makefile directory (or directories, see the
242 .Fl m
243 option) is automatically included as part of this list.
244 .It Fl i
245 Ignore non-zero exit of shell commands in the makefile.
246 Equivalent to specifying
247 .Ql Fl
248 before each command line in the makefile.
249 .It Fl J Ar private
250 This option should
251 .Em not
252 be specified by the user.
253 .Pp
254 When the
255 .Ar j
256 option is in use in a recursive build, this option is passed by a make
257 to child makes to allow all the make processes in the build to
258 cooperate to avoid overloading the system.
259 .It Fl j Ar max_jobs
260 Specify the maximum number of jobs that
261 .Nm
262 may have running at any one time.
263 The value is saved in
264 .Va .MAKE.JOBS .
265 Turns compatibility mode off, unless the
266 .Ar B
267 flag is also specified.
268 When compatibility mode is off, all commands associated with a
269 target are executed in a single shell invocation as opposed to the
270 traditional one shell invocation per line.
271 This can break traditional scripts which change directories on each
272 command invocation and then expect to start with a fresh environment
273 on the next line.
274 It is more efficient to correct the scripts rather than turn backwards
275 compatibility on.
276 .It Fl k
277 Continue processing after errors are encountered, but only on those targets
278 that do not depend on the target whose creation caused the error.
279 .It Fl m Ar directory
280 Specify a directory in which to search for sys.mk and makefiles included
281 via the
282 .Li \&< Ns Ar file Ns Li \&> Ns -style
283 include statement.
284 The
285 .Fl m
286 option can be used multiple times to form a search path.
287 This path will override the default system include path: /usr/share/mk.
288 Furthermore the system include path will be appended to the search path used
289 for
290 .Li \*q Ns Ar file Ns Li \*q Ns -style
291 include statements (see the
292 .Fl I
293 option).
294 .Pp
295 If a file or directory name in the
296 .Fl m
297 argument (or the
298 .Ev MAKESYSPATH
299 environment variable) starts with the string
300 .Qq \&.../
301 then
302 .Nm
303 will search for the specified file or directory named in the remaining part
304 of the argument string.
305 The search starts with the current directory of
306 the Makefile and then works upward towards the root of the file system.
307 If the search is successful, then the resulting directory replaces the
308 .Qq \&.../
309 specification in the
310 .Fl m
311 argument.
312 If used, this feature allows
313 .Nm
314 to easily search in the current source tree for customized sys.mk files
315 (e.g., by using
316 .Qq \&.../mk/sys.mk
317 as an argument).
318 .It Fl n
319 Display the commands that would have been executed, but do not
320 actually execute them unless the target depends on the .MAKE special
321 source (see below) or the command is prefixed with
322 .Ql Ic + .
323 .It Fl N
324 Display the commands which would have been executed, but do not
325 actually execute any of them; useful for debugging top-level makefiles
326 without descending into subdirectories.
327 .It Fl q
328 Do not execute any commands, but exit 0 if the specified targets are
329 up-to-date and 1, otherwise.
330 .It Fl r
331 Do not use the built-in rules specified in the system makefile.
332 .It Fl s
333 Do not echo any commands as they are executed.
334 Equivalent to specifying
335 .Ql Ic @
336 before each command line in the makefile.
337 .It Fl T Ar tracefile
338 When used with the
339 .Fl j
340 flag,
341 append a trace record to
342 .Ar tracefile
343 for each job started and completed.
344 .It Fl t
345 Rather than re-building a target as specified in the makefile, create it
346 or update its modification time to make it appear up-to-date.
347 .It Fl V Ar variable
348 Print the value of
349 .Ar variable .
350 Do not build any targets.
351 Multiple instances of this option may be specified;
352 the variables will be printed one per line,
353 with a blank line for each null or undefined variable.
354 The value printed is extracted from the global context after all
355 makefiles have been read.
356 By default, the raw variable contents (which may
357 include additional unexpanded variable references) are shown.
358 If
359 .Ar variable
360 contains a
361 .Ql \&$
362 then the value will be recursively expanded to its complete resultant
363 text before printing.
364 The expanded value will also be printed if
365 .Va .MAKE.EXPAND_VARIABLES
366 is set to true and
367 the
368 .Fl dV
369 option has not been used to override it.
370 Note that loop-local and target-local variables, as well as values
371 taken temporarily by global variables during makefile processing, are
372 not accessible via this option.
373 The
374 .Fl dv
375 debug mode can be used to see these at the cost of generating
376 substantial extraneous output.
377 .It Fl v Ar variable
378 Like
379 .Fl V
380 but the variable is always expanded to its complete value.
381 .It Fl W
382 Treat any warnings during makefile parsing as errors.
383 .It Fl w
384 Print entering and leaving directory messages, pre and post processing.
385 .It Fl X
386 Don't export variables passed on the command line to the environment
387 individually.
388 Variables passed on the command line are still exported
389 via the
390 .Va MAKEFLAGS
391 environment variable.
392 This option may be useful on systems which have a small limit on the
393 size of command arguments.
394 .It Ar variable=value
395 Set the value of the variable
396 .Ar variable
397 to
398 .Ar value .
399 Normally, all values passed on the command line are also exported to
400 sub-makes in the environment.
401 The
402 .Fl X
403 flag disables this behavior.
404 Variable assignments should follow options for POSIX compatibility
405 but no ordering is enforced.
406 .El
407 .Pp
408 There are seven different types of lines in a makefile: file dependency
409 specifications, shell commands, variable assignments, include statements,
410 conditional directives, for loops, and comments.
411 .Pp
412 In general, lines may be continued from one line to the next by ending
413 them with a backslash
414 .Pq Ql \e .
415 The trailing newline character and initial whitespace on the following
416 line are compressed into a single space.
417 .Sh FILE DEPENDENCY SPECIFICATIONS
418 Dependency lines consist of one or more targets, an operator, and zero
419 or more sources.
420 This creates a relationship where the targets
421 .Dq depend
422 on the sources
423 and are customarily created from them.
424 A target is considered out-of-date if it does not exist, or if its
425 modification time is less than that of any of its sources.
426 An out-of-date target will be re-created, but not until all sources
427 have been examined and themselves re-created as needed.
428 Three operators may be used:
429 .Bl -tag -width flag
430 .It Ic \&:
431 Many dependency lines may name this target but only one may have
432 attached shell commands.
433 All sources named in all dependency lines are considered together,
434 and if needed the attached shell commands are run to create or
435 re-create the target.
436 If
437 .Nm
438 is interrupted, the target is removed.
439 .It Ic \&!
440 The same, but the target is always re-created whether or not it is out
441 of date.
442 .It Ic \&::
443 Any dependency line may have attached shell commands, but each one
444 is handled independently: its sources are considered and the attached
445 shell commands are run if the target is out of date with respect to
446 (only) those sources.
447 Thus, different groups of the attached shell commands may be run
448 depending on the circumstances.
449 Furthermore, unlike
450 .Ic \&:,
451 for dependency lines with no sources, the attached shell
452 commands are always run.
453 Also unlike
454 .Ic \&:,
455 the target will not be removed if
456 .Nm
457 is interrupted.
458 .El
459 All dependency lines mentioning a particular target must use the same
460 operator.
461 .Pp
462 Targets and sources may contain the shell wildcard values
463 .Ql \&? ,
464 .Ql * ,
465 .Ql [] ,
466 and
467 .Ql {} .
468 The values
469 .Ql \&? ,
470 .Ql * ,
471 and
472 .Ql []
473 may only be used as part of the final
474 component of the target or source, and must be used to describe existing
475 files.
476 The value
477 .Ql {}
478 need not necessarily be used to describe existing files.
479 Expansion is in directory order, not alphabetically as done in the shell.
480 .Sh SHELL COMMANDS
481 Each target may have associated with it one or more lines of shell
482 commands, normally
483 used to create the target.
484 Each of the lines in this script
485 .Em must
486 be preceded by a tab.
487 (For historical reasons, spaces are not accepted.)
488 While targets can appear in many dependency lines if desired, by
489 default only one of these rules may be followed by a creation
490 script.
491 If the
492 .Ql Ic \&::
493 operator is used, however, all rules may include scripts and the
494 scripts are executed in the order found.
495 .Pp
496 Each line is treated as a separate shell command, unless the end of
497 line is escaped with a backslash
498 .Pq Ql \e
499 in which case that line and the next are combined.
500 .\" The escaped newline is retained and passed to the shell, which
501 .\" normally ignores it.
502 .\" However, the tab at the beginning of the following line is removed.
503 If the first characters of the command are any combination of
504 .Ql Ic @ ,
505 .Ql Ic + ,
506 or
507 .Ql Ic \- ,
508 the command is treated specially.
509 A
510 .Ql Ic @
511 causes the command not to be echoed before it is executed.
512 A
513 .Ql Ic +
514 causes the command to be executed even when
515 .Fl n
516 is given.
517 This is similar to the effect of the .MAKE special source,
518 except that the effect can be limited to a single line of a script.
519 A
520 .Ql Ic \-
521 in compatibility mode
522 causes any non-zero exit status of the command line to be ignored.
523 .Pp
524 When
525 .Nm
526 is run in jobs mode with
527 .Fl j Ar max_jobs ,
528 the entire script for the target is fed to a
529 single instance of the shell.
530 In compatibility (non-jobs) mode, each command is run in a separate process.
531 If the command contains any shell meta characters
532 .Pq Ql #=|^(){};&<>*?[]:$`\e\en
533 it will be passed to the shell; otherwise
534 .Nm
535 will attempt direct execution.
536 If a line starts with
537 .Ql Ic \-
538 and the shell has ErrCtl enabled then failure of the command line
539 will be ignored as in compatibility mode.
540 Otherwise
541 .Ql Ic \-
542 affects the entire job;
543 the script will stop at the first command line that fails,
544 but the target will not be deemed to have failed.
545 .Pp
546 Makefiles should be written so that the mode of
547 .Nm
548 operation does not change their behavior.
549 For example, any command which needs to use
550 .Dq cd
551 or
552 .Dq chdir
553 without potentially changing the directory for subsequent commands
554 should be put in parentheses so it executes in a subshell.
555 To force the use of one shell, escape the line breaks so as to make
556 the whole script one command.
557 For example:
558 .Bd -literal -offset indent
559 avoid-chdir-side-effects:
560         @echo Building $@ in `pwd`
561         @(cd ${.CURDIR} && ${MAKE} $@)
562         @echo Back in `pwd`
563
564 ensure-one-shell-regardless-of-mode:
565         @echo Building $@ in `pwd`; \e
566         (cd ${.CURDIR} && ${MAKE} $@); \e
567         echo Back in `pwd`
568 .Ed
569 .Pp
570 Since
571 .Nm
572 will
573 .Xr chdir 2
574 to
575 .Ql Va .OBJDIR
576 before executing any targets, each child process
577 starts with that as its current working directory.
578 .Sh VARIABLE ASSIGNMENTS
579 Variables in make are much like variables in the shell, and, by tradition,
580 consist of all upper-case letters.
581 .Ss Variable assignment modifiers
582 The five operators that can be used to assign values to variables are as
583 follows:
584 .Bl -tag -width Ds
585 .It Ic \&=
586 Assign the value to the variable.
587 Any previous value is overridden.
588 .It Ic \&+=
589 Append the value to the current value of the variable.
590 .It Ic \&?=
591 Assign the value to the variable if it is not already defined.
592 .It Ic \&:=
593 Assign with expansion, i.e. expand the value before assigning it
594 to the variable.
595 Normally, expansion is not done until the variable is referenced.
596 .Em NOTE :
597 References to undefined variables are
598 .Em not
599 expanded.
600 This can cause problems when variable modifiers are used.
601 .It Ic \&!=
602 Expand the value and pass it to the shell for execution and assign
603 the result to the variable.
604 Any newlines in the result are replaced with spaces.
605 .El
606 .Pp
607 Any white-space before the assigned
608 .Ar value
609 is removed; if the value is being appended, a single space is inserted
610 between the previous contents of the variable and the appended value.
611 .Pp
612 Variables are expanded by surrounding the variable name with either
613 curly braces
614 .Pq Ql {}
615 or parentheses
616 .Pq Ql ()
617 and preceding it with
618 a dollar sign
619 .Pq Ql \&$ .
620 If the variable name contains only a single letter, the surrounding
621 braces or parentheses are not required.
622 This shorter form is not recommended.
623 .Pp
624 If the variable name contains a dollar, then the name itself is expanded first.
625 This allows almost arbitrary variable names, however names containing dollar,
626 braces, parentheses, or whitespace are really best avoided!
627 .Pp
628 If the result of expanding a variable contains a dollar sign
629 .Pq Ql \&$
630 the string is expanded again.
631 .Pp
632 Variable substitution occurs at three distinct times, depending on where
633 the variable is being used.
634 .Bl -enum
635 .It
636 Variables in dependency lines are expanded as the line is read.
637 .It
638 Variables in shell commands are expanded when the shell command is
639 executed.
640 .It
641 .Dq .for
642 loop index variables are expanded on each loop iteration.
643 Note that other variables are not expanded inside loops so
644 the following example code:
645 .Bd -literal -offset indent
646
647 .Dv .for i in 1 2 3
648 a+=     ${i}
649 j=      ${i}
650 b+=     ${j}
651 .Dv .endfor
652
653 all:
654         @echo ${a}
655         @echo ${b}
656
657 .Ed
658 will print:
659 .Bd -literal -offset indent
660 1 2 3
661 3 3 3
662
663 .Ed
664 Because while ${a} contains
665 .Dq 1 2 3
666 after the loop is executed, ${b}
667 contains
668 .Dq ${j} ${j} ${j}
669 which expands to
670 .Dq 3 3 3
671 since after the loop completes ${j} contains
672 .Dq 3 .
673 .El
674 .Ss Variable classes
675 The four different classes of variables (in order of increasing precedence)
676 are:
677 .Bl -tag -width Ds
678 .It Environment variables
679 Variables defined as part of
680 .Nm Ns 's
681 environment.
682 .It Global variables
683 Variables defined in the makefile or in included makefiles.
684 .It Command line variables
685 Variables defined as part of the command line.
686 .It Local variables
687 Variables that are defined specific to a certain target.
688 .El
689 .Pp
690 Local variables are all built in and their values vary magically from
691 target to target.
692 It is not currently possible to define new local variables.
693 The seven local variables are as follows:
694 .Bl -tag -width ".ARCHIVE" -offset indent
695 .It Va .ALLSRC
696 The list of all sources for this target; also known as
697 .Ql Va \&> .
698 .It Va .ARCHIVE
699 The name of the archive file; also known as
700 .Ql Va \&! .
701 .It Va .IMPSRC
702 In suffix-transformation rules, the name/path of the source from which the
703 target is to be transformed (the
704 .Dq implied
705 source); also known as
706 .Ql Va \&< .
707 It is not defined in explicit rules.
708 .It Va .MEMBER
709 The name of the archive member; also known as
710 .Ql Va % .
711 .It Va .OODATE
712 The list of sources for this target that were deemed out-of-date; also
713 known as
714 .Ql Va \&? .
715 .It Va .PREFIX
716 The file prefix of the target, containing only the file portion, no suffix
717 or preceding directory components; also known as
718 .Ql Va * .
719 The suffix must be one of the known suffixes declared with
720 .Ic .SUFFIXES
721 or it will not be recognized.
722 .It Va .TARGET
723 The name of the target; also known as
724 .Ql Va @ .
725 For compatibility with other makes this is an alias for
726 .Ic .ARCHIVE
727 in archive member rules.
728 .El
729 .Pp
730 The shorter forms
731 .Ql ( Va > ,
732 .Ql Va \&! ,
733 .Ql Va < ,
734 .Ql Va % ,
735 .Ql Va \&? ,
736 .Ql Va * ,
737 and
738 .Ql Va @ )
739 are permitted for backward
740 compatibility with historical makefiles and legacy POSIX make and are
741 not recommended.
742 .Pp
743 Variants of these variables with the punctuation followed immediately by
744 .Ql D
745 or
746 .Ql F ,
747 e.g.
748 .Ql Va $(@D) ,
749 are legacy forms equivalent to using the
750 .Ql :H
751 and
752 .Ql :T
753 modifiers.
754 These forms are accepted for compatibility with
755 .At V
756 makefiles and POSIX but are not recommended.
757 .Pp
758 Four of the local variables may be used in sources on dependency lines
759 because they expand to the proper value for each target on the line.
760 These variables are
761 .Ql Va .TARGET ,
762 .Ql Va .PREFIX ,
763 .Ql Va .ARCHIVE ,
764 and
765 .Ql Va .MEMBER .
766 .Ss Additional built-in variables
767 In addition,
768 .Nm
769 sets or knows about the following variables:
770 .Bl -tag -width .MAKEOVERRIDES
771 .It Va \&$
772 A single dollar sign
773 .Ql \&$ ,
774 i.e.
775 .Ql \&$$
776 expands to a single dollar
777 sign.
778 .It Va .ALLTARGETS
779 The list of all targets encountered in the Makefile.
780 If evaluated during
781 Makefile parsing, lists only those targets encountered thus far.
782 .It Va .CURDIR
783 A path to the directory where
784 .Nm
785 was executed.
786 Refer to the description of
787 .Ql Ev PWD
788 for more details.
789 .It Va .INCLUDEDFROMDIR
790 The directory of the file this Makefile was included from.
791 .It Va .INCLUDEDFROMFILE
792 The filename of the file this Makefile was included from.
793 .It Ev MAKE
794 The name that
795 .Nm
796 was executed with
797 .Pq Va argv[0] .
798 For compatibility
799 .Nm
800 also sets
801 .Va .MAKE
802 with the same value.
803 The preferred variable to use is the environment variable
804 .Ev MAKE
805 because it is more compatible with other versions of
806 .Nm
807 and cannot be confused with the special target with the same name.
808 .It Va .MAKE.ALWAYS_PASS_JOB_QUEUE
809 Tells
810 .Nm
811 whether to pass the descriptors of the job token queue
812 even if the target is not tagged with
813 .Ic .MAKE
814 The default is
815 .Ql Pa yes
816 for backwards compatability with
817 .Fx 9.0
818 and earlier.
819 .It Va .MAKE.DEPENDFILE
820 Names the makefile (default
821 .Ql Pa .depend )
822 from which generated dependencies are read.
823 .It Va .MAKE.EXPAND_VARIABLES
824 A boolean that controls the default behavior of the
825 .Fl V
826 option.
827 If true, variable values printed with
828 .Fl V
829 are fully expanded; if false, the raw variable contents (which may
830 include additional unexpanded variable references) are shown.
831 .It Va .MAKE.EXPORTED
832 The list of variables exported by
833 .Nm .
834 .It Va .MAKE.JOBS
835 The argument to the
836 .Fl j
837 option.
838 .It Va .MAKE.JOB.PREFIX
839 If
840 .Nm
841 is run with
842 .Ar j
843 then output for each target is prefixed with a token
844 .Ql --- target ---
845 the first part of which can be controlled via
846 .Va .MAKE.JOB.PREFIX .
847 If
848 .Va .MAKE.JOB.PREFIX
849 is empty, no token is printed.
850 .br
851 For example:
852 .Li .MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}]
853 would produce tokens like
854 .Ql ---make[1234] target ---
855 making it easier to track the degree of parallelism being achieved.
856 .It Ev MAKEFLAGS
857 The environment variable
858 .Ql Ev MAKEFLAGS
859 may contain anything that
860 may be specified on
861 .Nm Ns 's
862 command line.
863 Anything specified on
864 .Nm Ns 's
865 command line is appended to the
866 .Ql Ev MAKEFLAGS
867 variable which is then
868 entered into the environment for all programs which
869 .Nm
870 executes.
871 .It Va .MAKE.LEVEL
872 The recursion depth of
873 .Nm .
874 The initial instance of
875 .Nm
876 will be 0, and an incremented value is put into the environment
877 to be seen by the next generation.
878 This allows tests like:
879 .Li .if ${.MAKE.LEVEL} == 0
880 to protect things which should only be evaluated in the initial instance of
881 .Nm .
882 .It Va .MAKE.MAKEFILE_PREFERENCE
883 The ordered list of makefile names
884 (default
885 .Ql Pa makefile ,
886 .Ql Pa Makefile )
887 that
888 .Nm
889 will look for.
890 .It Va .MAKE.MAKEFILES
891 The list of makefiles read by
892 .Nm ,
893 which is useful for tracking dependencies.
894 Each makefile is recorded only once, regardless of the number of times read.
895 .It Va .MAKE.MODE
896 Processed after reading all makefiles.
897 Can affect the mode that
898 .Nm
899 runs in.
900 It can contain a number of keywords:
901 .Bl -hang -width missing-filemon=bf.
902 .It Pa compat
903 Like
904 .Fl B ,
905 puts
906 .Nm
907 into "compat" mode.
908 .It Pa meta
909 Puts
910 .Nm
911 into "meta" mode, where meta files are created for each target
912 to capture the command run, the output generated and if
913 .Xr filemon 4
914 is available, the system calls which are of interest to
915 .Nm .
916 The captured output can be very useful when diagnosing errors.
917 .It Pa curdirOk= Ar bf
918 Normally
919 .Nm
920 will not create .meta files in
921 .Ql Va .CURDIR .
922 This can be overridden by setting
923 .Va bf
924 to a value which represents True.
925 .It Pa missing-meta= Ar bf
926 If
927 .Va bf
928 is True, then a missing .meta file makes the target out-of-date.
929 .It Pa missing-filemon= Ar bf
930 If
931 .Va bf
932 is True, then missing filemon data makes the target out-of-date.
933 .It Pa nofilemon
934 Do not use
935 .Xr filemon 4 .
936 .It Pa env
937 For debugging, it can be useful to include the environment
938 in the .meta file.
939 .It Pa verbose
940 If in "meta" mode, print a clue about the target being built.
941 This is useful if the build is otherwise running silently.
942 The message printed the value of:
943 .Va .MAKE.META.PREFIX .
944 .It Pa ignore-cmd
945 Some makefiles have commands which are simply not stable.
946 This keyword causes them to be ignored for
947 determining whether a target is out of date in "meta" mode.
948 See also
949 .Ic .NOMETA_CMP .
950 .It Pa silent= Ar bf
951 If
952 .Va bf
953 is True, when a .meta file is created, mark the target
954 .Ic .SILENT .
955 .El
956 .It Va .MAKE.META.BAILIWICK
957 In "meta" mode, provides a list of prefixes which
958 match the directories controlled by
959 .Nm .
960 If a file that was generated outside of
961 .Va .OBJDIR
962 but within said bailiwick is missing,
963 the current target is considered out-of-date.
964 .It Va .MAKE.META.CREATED
965 In "meta" mode, this variable contains a list of all the meta files
966 updated.
967 If not empty, it can be used to trigger processing of
968 .Va .MAKE.META.FILES .
969 .It Va .MAKE.META.FILES
970 In "meta" mode, this variable contains a list of all the meta files
971 used (updated or not).
972 This list can be used to process the meta files to extract dependency
973 information.
974 .It Va .MAKE.META.IGNORE_PATHS
975 Provides a list of path prefixes that should be ignored;
976 because the contents are expected to change over time.
977 The default list includes:
978 .Ql Pa /dev /etc /proc /tmp /var/run /var/tmp
979 .It Va .MAKE.META.IGNORE_PATTERNS
980 Provides a list of patterns to match against pathnames.
981 Ignore any that match.
982 .It Va .MAKE.META.IGNORE_FILTER
983 Provides a list of variable modifiers to apply to each pathname.
984 Ignore if the expansion is an empty string.
985 .It Va .MAKE.META.PREFIX
986 Defines the message printed for each meta file updated in "meta verbose" mode.
987 The default value is:
988 .Dl Building ${.TARGET:H:tA}/${.TARGET:T}
989 .It Va .MAKEOVERRIDES
990 This variable is used to record the names of variables assigned to
991 on the command line, so that they may be exported as part of
992 .Ql Ev MAKEFLAGS .
993 This behavior can be disabled by assigning an empty value to
994 .Ql Va .MAKEOVERRIDES
995 within a makefile.
996 Extra variables can be exported from a makefile
997 by appending their names to
998 .Ql Va .MAKEOVERRIDES .
999 .Ql Ev MAKEFLAGS
1000 is re-exported whenever
1001 .Ql Va .MAKEOVERRIDES
1002 is modified.
1003 .It Va .MAKE.PATH_FILEMON
1004 If
1005 .Nm
1006 was built with
1007 .Xr filemon 4
1008 support, this is set to the path of the device node.
1009 This allows makefiles to test for this support.
1010 .It Va .MAKE.PID
1011 The process-id of
1012 .Nm .
1013 .It Va .MAKE.PPID
1014 The parent process-id of
1015 .Nm .
1016 .It Va .MAKE.SAVE_DOLLARS
1017 value should be a boolean that controls whether
1018 .Ql $$
1019 are preserved when doing
1020 .Ql :=
1021 assignments.
1022 The default is false, for backwards compatibility.
1023 Set to true for compatability with other makes.
1024 If set to false,
1025 .Ql $$
1026 becomes
1027 .Ql $
1028 per normal evaluation rules.
1029 .It Va MAKE_PRINT_VAR_ON_ERROR
1030 When
1031 .Nm
1032 stops due to an error, it sets
1033 .Ql Va .ERROR_TARGET
1034 to the name of the target that failed,
1035 .Ql Va .ERROR_CMD
1036 to the commands of the failed target,
1037 and in "meta" mode, it also sets
1038 .Ql Va .ERROR_CWD
1039 to the
1040 .Xr getcwd 3 ,
1041 and
1042 .Ql Va .ERROR_META_FILE
1043 to the path of the meta file (if any) describing the failed target.
1044 It then prints its name and the value of
1045 .Ql Va .CURDIR
1046 as well as the value of any variables named in
1047 .Ql Va MAKE_PRINT_VAR_ON_ERROR .
1048 .It Va .newline
1049 This variable is simply assigned a newline character as its value.
1050 This allows expansions using the
1051 .Cm \&:@
1052 modifier to put a newline between
1053 iterations of the loop rather than a space.
1054 For example, the printing of
1055 .Ql Va MAKE_PRINT_VAR_ON_ERROR
1056 could be done as ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}.
1057 .It Va .OBJDIR
1058 A path to the directory where the targets are built.
1059 Its value is determined by trying to
1060 .Xr chdir 2
1061 to the following directories in order and using the first match:
1062 .Bl -enum
1063 .It
1064 .Ev ${MAKEOBJDIRPREFIX}${.CURDIR}
1065 .Pp
1066 (Only if
1067 .Ql Ev MAKEOBJDIRPREFIX
1068 is set in the environment or on the command line.)
1069 .It
1070 .Ev ${MAKEOBJDIR}
1071 .Pp
1072 (Only if
1073 .Ql Ev MAKEOBJDIR
1074 is set in the environment or on the command line.)
1075 .It
1076 .Ev ${.CURDIR} Ns Pa /obj. Ns Ev ${MACHINE}
1077 .It
1078 .Ev ${.CURDIR} Ns Pa /obj
1079 .It
1080 .Pa /usr/obj/ Ns Ev ${.CURDIR}
1081 .It
1082 .Ev ${.CURDIR}
1083 .El
1084 .Pp
1085 Variable expansion is performed on the value before it's used,
1086 so expressions such as
1087 .Dl ${.CURDIR:S,^/usr/src,/var/obj,}
1088 may be used.
1089 This is especially useful with
1090 .Ql Ev MAKEOBJDIR .
1091 .Pp
1092 .Ql Va .OBJDIR
1093 may be modified in the makefile via the special target
1094 .Ql Ic .OBJDIR .
1095 In all cases,
1096 .Nm
1097 will
1098 .Xr chdir 2
1099 to the specified directory if it exists, and set
1100 .Ql Va .OBJDIR
1101 and
1102 .Ql Ev PWD
1103 to that directory before executing any targets.
1104 .
1105 .It Va .PARSEDIR
1106 A path to the directory of the current
1107 .Ql Pa Makefile
1108 being parsed.
1109 .It Va .PARSEFILE
1110 The basename of the current
1111 .Ql Pa Makefile
1112 being parsed.
1113 This variable and
1114 .Ql Va .PARSEDIR
1115 are both set only while the
1116 .Ql Pa Makefiles
1117 are being parsed.
1118 If you want to retain their current values, assign them to a variable
1119 using assignment with expansion:
1120 .Pq Ql Cm \&:= .
1121 .It Va .PATH
1122 A variable that represents the list of directories that
1123 .Nm
1124 will search for files.
1125 The search list should be updated using the target
1126 .Ql Va .PATH
1127 rather than the variable.
1128 .It Ev PWD
1129 Alternate path to the current directory.
1130 .Nm
1131 normally sets
1132 .Ql Va .CURDIR
1133 to the canonical path given by
1134 .Xr getcwd 3 .
1135 However, if the environment variable
1136 .Ql Ev PWD
1137 is set and gives a path to the current directory, then
1138 .Nm
1139 sets
1140 .Ql Va .CURDIR
1141 to the value of
1142 .Ql Ev PWD
1143 instead.
1144 This behavior is disabled if
1145 .Ql Ev MAKEOBJDIRPREFIX
1146 is set or
1147 .Ql Ev MAKEOBJDIR
1148 contains a variable transform.
1149 .Ql Ev PWD
1150 is set to the value of
1151 .Ql Va .OBJDIR
1152 for all programs which
1153 .Nm
1154 executes.
1155 .It Ev .SHELL
1156 The pathname of the shell used to run target scripts.
1157 It is read-only.
1158 .It Ev .TARGETS
1159 The list of targets explicitly specified on the command line, if any.
1160 .It Ev VPATH
1161 Colon-separated
1162 .Pq Dq \&:
1163 lists of directories that
1164 .Nm
1165 will search for files.
1166 The variable is supported for compatibility with old make programs only,
1167 use
1168 .Ql Va .PATH
1169 instead.
1170 .El
1171 .Ss Variable modifiers
1172 Variable expansion may be modified to select or modify each word of the
1173 variable (where a
1174 .Dq word
1175 is white-space delimited sequence of characters).
1176 The general format of a variable expansion is as follows:
1177 .Pp
1178 .Dl ${variable[:modifier[:...]]}
1179 .Pp
1180 Each modifier begins with a colon,
1181 which may be escaped with a backslash
1182 .Pq Ql \e .
1183 .Pp
1184 A set of modifiers can be specified via a variable, as follows:
1185 .Pp
1186 .Dl modifier_variable=modifier[:...]
1187 .Dl ${variable:${modifier_variable}[:...]}
1188 .Pp
1189 In this case the first modifier in the modifier_variable does not
1190 start with a colon, since that must appear in the referencing
1191 variable.
1192 If any of the modifiers in the modifier_variable contain a dollar sign
1193 .Pq Ql $ ,
1194 these must be doubled to avoid early expansion.
1195 .Pp
1196 The supported modifiers are:
1197 .Bl -tag -width EEE
1198 .It Cm \&:E
1199 Replaces each word in the variable with its suffix.
1200 .It Cm \&:H
1201 Replaces each word in the variable with everything but the last component.
1202 .It Cm \&:M Ns Ar pattern
1203 Selects only those words that match
1204 .Ar pattern .
1205 The standard shell wildcard characters
1206 .Pf ( Ql * ,
1207 .Ql \&? ,
1208 and
1209 .Ql Oo Oc )
1210 may
1211 be used.
1212 The wildcard characters may be escaped with a backslash
1213 .Pq Ql \e .
1214 As a consequence of the way values are split into words, matched,
1215 and then joined, a construct like
1216 .Dl ${VAR:M*}
1217 will normalize the inter-word spacing, removing all leading and
1218 trailing space, and converting multiple consecutive spaces
1219 to single spaces.
1220 .
1221 .It Cm \&:N Ns Ar pattern
1222 This is identical to
1223 .Ql Cm \&:M ,
1224 but selects all words which do not match
1225 .Ar pattern .
1226 .It Cm \&:O
1227 Orders every word in variable alphabetically.
1228 .It Cm \&:Or
1229 Orders every word in variable in reverse alphabetical order.
1230 .It Cm \&:Ox
1231 Shuffles the words in variable.
1232 The results will be different each time you are referring to the
1233 modified variable; use the assignment with expansion
1234 .Pq Ql Cm \&:=
1235 to prevent such behavior.
1236 For example,
1237 .Bd -literal -offset indent
1238 LIST=                   uno due tre quattro
1239 RANDOM_LIST=            ${LIST:Ox}
1240 STATIC_RANDOM_LIST:=    ${LIST:Ox}
1241
1242 all:
1243         @echo "${RANDOM_LIST}"
1244         @echo "${RANDOM_LIST}"
1245         @echo "${STATIC_RANDOM_LIST}"
1246         @echo "${STATIC_RANDOM_LIST}"
1247 .Ed
1248 may produce output similar to:
1249 .Bd -literal -offset indent
1250 quattro due tre uno
1251 tre due quattro uno
1252 due uno quattro tre
1253 due uno quattro tre
1254 .Ed
1255 .It Cm \&:Q
1256 Quotes every shell meta-character in the variable, so that it can be passed
1257 safely to the shell.
1258 .It Cm \&:q
1259 Quotes every shell meta-character in the variable, and also doubles
1260 .Sq $
1261 characters so that it can be passed
1262 safely through recursive invocations of
1263 .Nm .
1264 This is equivalent to:
1265 .Sq \&:S/\e\&$/&&/g:Q .
1266 .It Cm \&:R
1267 Replaces each word in the variable with everything but its suffix.
1268 .It Cm \&:range[=count]
1269 The value is an integer sequence representing the words of the original
1270 value, or the supplied
1271 .Va count .
1272 .It Cm \&:gmtime[=utc]
1273 The value is a format string for
1274 .Xr strftime 3 ,
1275 using
1276 .Xr gmtime 3 .
1277 If a
1278 .Va utc
1279 value is not provided or is 0, the current time is used.
1280 .It Cm \&:hash
1281 Computes a 32-bit hash of the value and encode it as hex digits.
1282 .It Cm \&:localtime[=utc]
1283 The value is a format string for
1284 .Xr strftime 3 ,
1285 using
1286 .Xr localtime 3 .
1287 If a
1288 .Va utc
1289 value is not provided or is 0, the current time is used.
1290 .It Cm \&:tA
1291 Attempts to convert variable to an absolute path using
1292 .Xr realpath 3 ,
1293 if that fails, the value is unchanged.
1294 .It Cm \&:tl
1295 Converts variable to lower-case letters.
1296 .It Cm \&:ts Ns Ar c
1297 Words in the variable are normally separated by a space on expansion.
1298 This modifier sets the separator to the character
1299 .Ar c .
1300 If
1301 .Ar c
1302 is omitted, then no separator is used.
1303 The common escapes (including octal numeric codes) work as expected.
1304 .It Cm \&:tu
1305 Converts variable to upper-case letters.
1306 .It Cm \&:tW
1307 Causes the value to be treated as a single word
1308 (possibly containing embedded white space).
1309 See also
1310 .Ql Cm \&:[*] .
1311 .It Cm \&:tw
1312 Causes the value to be treated as a sequence of
1313 words delimited by white space.
1314 See also
1315 .Ql Cm \&:[@] .
1316 .Sm off
1317 .It Cm \&:S No \&/ Ar old_string No \&/ Ar new_string No \&/ Op Cm 1gW
1318 .Sm on
1319 Modifies the first occurrence of
1320 .Ar old_string
1321 in each word of the variable's value, replacing it with
1322 .Ar new_string .
1323 If a
1324 .Ql g
1325 is appended to the last delimiter of the pattern, all occurrences
1326 in each word are replaced.
1327 If a
1328 .Ql 1
1329 is appended to the last delimiter of the pattern, only the first occurrence
1330 is affected.
1331 If a
1332 .Ql W
1333 is appended to the last delimiter of the pattern,
1334 then the value is treated as a single word
1335 (possibly containing embedded white space).
1336 If
1337 .Ar old_string
1338 begins with a caret
1339 .Pq Ql ^ ,
1340 .Ar old_string
1341 is anchored at the beginning of each word.
1342 If
1343 .Ar old_string
1344 ends with a dollar sign
1345 .Pq Ql \&$ ,
1346 it is anchored at the end of each word.
1347 Inside
1348 .Ar new_string ,
1349 an ampersand
1350 .Pq Ql &
1351 is replaced by
1352 .Ar old_string
1353 (without any
1354 .Ql ^
1355 or
1356 .Ql \&$ ) .
1357 Any character may be used as a delimiter for the parts of the modifier
1358 string.
1359 The anchoring, ampersand and delimiter characters may be escaped with a
1360 backslash
1361 .Pq Ql \e .
1362 .Pp
1363 Variable expansion occurs in the normal fashion inside both
1364 .Ar old_string
1365 and
1366 .Ar new_string
1367 with the single exception that a backslash is used to prevent the expansion
1368 of a dollar sign
1369 .Pq Ql \&$ ,
1370 not a preceding dollar sign as is usual.
1371 .Sm off
1372 .It Cm \&:C No \&/ Ar pattern No \&/ Ar replacement No \&/ Op Cm 1gW
1373 .Sm on
1374 The
1375 .Cm \&:C
1376 modifier is just like the
1377 .Cm \&:S
1378 modifier except that the old and new strings, instead of being
1379 simple strings, are an extended regular expression (see
1380 .Xr regex 3 )
1381 string
1382 .Ar pattern
1383 and an
1384 .Xr ed 1 Ns \-style
1385 string
1386 .Ar replacement .
1387 Normally, the first occurrence of the pattern
1388 .Ar pattern
1389 in each word of the value is substituted with
1390 .Ar replacement .
1391 The
1392 .Ql 1
1393 modifier causes the substitution to apply to at most one word; the
1394 .Ql g
1395 modifier causes the substitution to apply to as many instances of the
1396 search pattern
1397 .Ar pattern
1398 as occur in the word or words it is found in; the
1399 .Ql W
1400 modifier causes the value to be treated as a single word
1401 (possibly containing embedded white space).
1402 .Pp
1403 As for the
1404 .Cm \&:S
1405 modifier, the
1406 .Ar pattern
1407 and
1408 .Ar replacement
1409 are subjected to variable expansion before being parsed as
1410 regular expressions.
1411 .It Cm \&:T
1412 Replaces each word in the variable with its last path component.
1413 .It Cm \&:u
1414 Removes adjacent duplicate words (like
1415 .Xr uniq 1 ) .
1416 .Sm off
1417 .It Cm \&:\&? Ar true_string Cm \&: Ar false_string
1418 .Sm on
1419 If the variable name (not its value), when parsed as a .if conditional
1420 expression, evaluates to true, return as its value the
1421 .Ar true_string ,
1422 otherwise return the
1423 .Ar false_string .
1424 Since the variable name is used as the expression, \&:\&? must be the
1425 first modifier after the variable name itself - which will, of course,
1426 usually contain variable expansions.
1427 A common error is trying to use expressions like
1428 .Dl ${NUMBERS:M42:?match:no}
1429 which actually tests defined(NUMBERS),
1430 to determine if any words match "42" you need to use something like:
1431 .Dl ${"${NUMBERS:M42}" != \&"\&":?match:no} .
1432 .It Ar :old_string=new_string
1433 This is the
1434 .At V
1435 style variable substitution.
1436 It must be the last modifier specified.
1437 If
1438 .Ar old_string
1439 or
1440 .Ar new_string
1441 do not contain the pattern matching character
1442 .Ar %
1443 then it is assumed that they are
1444 anchored at the end of each word, so only suffixes or entire
1445 words may be replaced.
1446 Otherwise
1447 .Ar %
1448 is the substring of
1449 .Ar old_string
1450 to be replaced in
1451 .Ar new_string .
1452 If only
1453 .Ar old_string
1454 contains the pattern matching character
1455 .Ar % ,
1456 and
1457 .Ar old_string
1458 matches, then the result is the
1459 .Ar new_string .
1460 If only the
1461 .Ar new_string
1462 contains the pattern matching character
1463 .Ar % ,
1464 then it is not treated specially and it is printed as a literal
1465 .Ar %
1466 on match.
1467 If there is more than one pattern matching character
1468 .Ar ( % )
1469 in either the
1470 .Ar new_string
1471 or
1472 .Ar old_string ,
1473 only the first instance is treated specially (as the pattern character);
1474 all subsequent instances are treated as regular characters.
1475 .Pp
1476 Variable expansion occurs in the normal fashion inside both
1477 .Ar old_string
1478 and
1479 .Ar new_string
1480 with the single exception that a backslash is used to prevent the
1481 expansion of a dollar sign
1482 .Pq Ql \&$ ,
1483 not a preceding dollar sign as is usual.
1484 .Sm off
1485 .It Cm \&:@ Ar temp Cm @ Ar string Cm @
1486 .Sm on
1487 This is the loop expansion mechanism from the OSF Development
1488 Environment (ODE) make.
1489 Unlike
1490 .Cm \&.for
1491 loops, expansion occurs at the time of reference.
1492 Assigns
1493 .Ar temp
1494 to each word in the variable and evaluates
1495 .Ar string .
1496 The ODE convention is that
1497 .Ar temp
1498 should start and end with a period.
1499 For example.
1500 .Dl ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@}
1501 .Pp
1502 However a single character variable is often more readable:
1503 .Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}
1504 .It Cm \&:_[=var]
1505 Saves the current variable value in
1506 .Ql $_
1507 or the named
1508 .Va var
1509 for later reference.
1510 Example usage:
1511 .Bd -literal -offset indent
1512 M_cmpv.units = 1 1000 1000000
1513 M_cmpv = S,., ,g:_:range:@i@+ $${_:[-$$i]} \&\\
1514 \\* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh
1515
1516 .Dv .if ${VERSION:${M_cmpv}} < ${3.1.12:L:${M_cmpv}}
1517
1518 .Ed
1519 Here
1520 .Ql $_
1521 is used to save the result of the
1522 .Ql :S
1523 modifier which is later referenced using the index values from
1524 .Ql :range .
1525 .It Cm \&:U Ns Ar newval
1526 If the variable is undefined,
1527 .Ar newval
1528 is the value.
1529 If the variable is defined, the existing value is returned.
1530 This is another ODE make feature.
1531 It is handy for setting per-target CFLAGS for instance:
1532 .Dl ${_${.TARGET:T}_CFLAGS:U${DEF_CFLAGS}}
1533 If a value is only required if the variable is undefined, use:
1534 .Dl ${VAR:D:Unewval}
1535 .It Cm \&:D Ns Ar newval
1536 If the variable is defined,
1537 .Ar newval
1538 is the value.
1539 .It Cm \&:L
1540 The name of the variable is the value.
1541 .It Cm \&:P
1542 The path of the node which has the same name as the variable
1543 is the value.
1544 If no such node exists or its path is null, then the
1545 name of the variable is used.
1546 In order for this modifier to work, the name (node) must at least have
1547 appeared on the rhs of a dependency.
1548 .Sm off
1549 .It Cm \&:\&! Ar cmd Cm \&!
1550 .Sm on
1551 The output of running
1552 .Ar cmd
1553 is the value.
1554 .It Cm \&:sh
1555 If the variable is non-empty it is run as a command and the output
1556 becomes the new value.
1557 .It Cm \&::= Ns Ar str
1558 The variable is assigned the value
1559 .Ar str
1560 after substitution.
1561 This modifier and its variations are useful in
1562 obscure situations such as wanting to set a variable when shell commands
1563 are being parsed.
1564 These assignment modifiers always expand to
1565 nothing, so if appearing in a rule line by themselves should be
1566 preceded with something to keep
1567 .Nm
1568 happy.
1569 .Pp
1570 The
1571 .Ql Cm \&::
1572 helps avoid false matches with the
1573 .At V
1574 style
1575 .Cm \&:=
1576 modifier and since substitution always occurs the
1577 .Cm \&::=
1578 form is vaguely appropriate.
1579 .It Cm \&::?= Ns Ar str
1580 As for
1581 .Cm \&::=
1582 but only if the variable does not already have a value.
1583 .It Cm \&::+= Ns Ar str
1584 Append
1585 .Ar str
1586 to the variable.
1587 .It Cm \&::!= Ns Ar cmd
1588 Assign the output of
1589 .Ar cmd
1590 to the variable.
1591 .It Cm \&:\&[ Ns Ar range Ns Cm \&]
1592 Selects one or more words from the value,
1593 or performs other operations related to the way in which the
1594 value is divided into words.
1595 .Pp
1596 Ordinarily, a value is treated as a sequence of words
1597 delimited by white space.
1598 Some modifiers suppress this behavior,
1599 causing a value to be treated as a single word
1600 (possibly containing embedded white space).
1601 An empty value, or a value that consists entirely of white-space,
1602 is treated as a single word.
1603 For the purposes of the
1604 .Ql Cm \&:[]
1605 modifier, the words are indexed both forwards using positive integers
1606 (where index 1 represents the first word),
1607 and backwards using negative integers
1608 (where index \-1 represents the last word).
1609 .Pp
1610 The
1611 .Ar range
1612 is subjected to variable expansion, and the expanded result is
1613 then interpreted as follows:
1614 .Bl -tag -width index
1615 .\" :[n]
1616 .It Ar index
1617 Selects a single word from the value.
1618 .\" :[start..end]
1619 .It Ar start Ns Cm \&.. Ns Ar end
1620 Selects all words from
1621 .Ar start
1622 to
1623 .Ar end ,
1624 inclusive.
1625 For example,
1626 .Ql Cm \&:[2..-1]
1627 selects all words from the second word to the last word.
1628 If
1629 .Ar start
1630 is greater than
1631 .Ar end ,
1632 then the words are output in reverse order.
1633 For example,
1634 .Ql Cm \&:[-1..1]
1635 selects all the words from last to first.
1636 If the list is already ordered, then this effectively reverses
1637 the list, but it is more efficient to use
1638 .Ql Cm \&:Or
1639 instead of
1640 .Ql Cm \&:O:[-1..1] .
1641 .\" :[*]
1642 .It Cm \&*
1643 Causes subsequent modifiers to treat the value as a single word
1644 (possibly containing embedded white space).
1645 Analogous to the effect of
1646 \&"$*\&"
1647 in Bourne shell.
1648 .\" :[0]
1649 .It 0
1650 Means the same as
1651 .Ql Cm \&:[*] .
1652 .\" :[*]
1653 .It Cm \&@
1654 Causes subsequent modifiers to treat the value as a sequence of words
1655 delimited by white space.
1656 Analogous to the effect of
1657 \&"$@\&"
1658 in Bourne shell.
1659 .\" :[#]
1660 .It Cm \&#
1661 Returns the number of words in the value.
1662 .El \" :[range]
1663 .El
1664 .Sh INCLUDE STATEMENTS, CONDITIONALS AND FOR LOOPS
1665 Makefile inclusion, conditional structures and for loops reminiscent
1666 of the C programming language are provided in
1667 .Nm .
1668 All such structures are identified by a line beginning with a single
1669 dot
1670 .Pq Ql \&.
1671 character.
1672 Files are included with either
1673 .Cm \&.include \&< Ns Ar file Ns Cm \&>
1674 or
1675 .Cm \&.include \&\*q Ns Ar file Ns Cm \&\*q .
1676 Variables between the angle brackets or double quotes are expanded
1677 to form the file name.
1678 If angle brackets are used, the included makefile is expected to be in
1679 the system makefile directory.
1680 If double quotes are used, the including makefile's directory and any
1681 directories specified using the
1682 .Fl I
1683 option are searched before the system
1684 makefile directory.
1685 For compatibility with other versions of
1686 .Nm
1687 .Ql include file ...
1688 is also accepted.
1689 .Pp
1690 If the include statement is written as
1691 .Cm .-include
1692 or as
1693 .Cm .sinclude
1694 then errors locating and/or opening include files are ignored.
1695 .Pp
1696 If the include statement is written as
1697 .Cm .dinclude
1698 not only are errors locating and/or opening include files ignored,
1699 but stale dependencies within the included file will be ignored
1700 just like
1701 .Va .MAKE.DEPENDFILE .
1702 .Pp
1703 Conditional expressions are also preceded by a single dot as the first
1704 character of a line.
1705 The possible conditionals are as follows:
1706 .Bl -tag -width Ds
1707 .It Ic .error Ar message
1708 The message is printed along with the name of the makefile and line number,
1709 then
1710 .Nm
1711 will exit immediately.
1712 .It Ic .export Ar variable ...
1713 Export the specified global variable.
1714 If no variable list is provided, all globals are exported
1715 except for internal variables (those that start with
1716 .Ql \&. ) .
1717 This is not affected by the
1718 .Fl X
1719 flag, so should be used with caution.
1720 For compatibility with other
1721 .Nm
1722 programs
1723 .Ql export variable=value
1724 is also accepted.
1725 .Pp
1726 Appending a variable name to
1727 .Va .MAKE.EXPORTED
1728 is equivalent to exporting a variable.
1729 .It Ic .export-env Ar variable ...
1730 The same as
1731 .Ql .export ,
1732 except that the variable is not appended to
1733 .Va .MAKE.EXPORTED .
1734 This allows exporting a value to the environment which is different from that
1735 used by
1736 .Nm
1737 internally.
1738 .It Ic .export-literal Ar variable ...
1739 The same as
1740 .Ql .export-env ,
1741 except that variables in the value are not expanded.
1742 .It Ic .info Ar message
1743 The message is printed along with the name of the makefile and line number.
1744 .It Ic .undef Ar variable
1745 Un-define the specified global variable.
1746 Only global variables may be un-defined.
1747 .It Ic .unexport Ar variable ...
1748 The opposite of
1749 .Ql .export .
1750 The specified global
1751 .Va variable
1752 will be removed from
1753 .Va .MAKE.EXPORTED .
1754 If no variable list is provided, all globals are unexported,
1755 and
1756 .Va .MAKE.EXPORTED
1757 deleted.
1758 .It Ic .unexport-env
1759 Unexport all globals previously exported and
1760 clear the environment inherited from the parent.
1761 This operation will cause a memory leak of the original environment,
1762 so should be used sparingly.
1763 Testing for
1764 .Va .MAKE.LEVEL
1765 being 0, would make sense.
1766 Also note that any variables which originated in the parent environment
1767 should be explicitly preserved if desired.
1768 For example:
1769 .Bd -literal -offset indent
1770 .Li .if ${.MAKE.LEVEL} == 0
1771 PATH := ${PATH}
1772 .Li .unexport-env
1773 .Li .export PATH
1774 .Li .endif
1775 .Pp
1776 .Ed
1777 Would result in an environment containing only
1778 .Ql Ev PATH ,
1779 which is the minimal useful environment.
1780 Actually
1781 .Ql Ev .MAKE.LEVEL
1782 will also be pushed into the new environment.
1783 .It Ic .warning Ar message
1784 The message prefixed by
1785 .Ql Pa warning:
1786 is printed along with the name of the makefile and line number.
1787 .It Ic \&.if Oo \&! Oc Ns Ar expression Op Ar operator expression ...
1788 Test the value of an expression.
1789 .It Ic .ifdef Oo \&! Oc Ns Ar variable Op Ar operator variable ...
1790 Test the value of a variable.
1791 .It Ic .ifndef Oo \&! Oc Ns Ar variable Op Ar operator variable ...
1792 Test the value of a variable.
1793 .It Ic .ifmake Oo \&! Oc Ns Ar target Op Ar operator target ...
1794 Test the target being built.
1795 .It Ic .ifnmake Oo \&! Ns Oc Ar target Op Ar operator target ...
1796 Test the target being built.
1797 .It Ic .else
1798 Reverse the sense of the last conditional.
1799 .It Ic .elif Oo \&! Ns Oc Ar expression Op Ar operator expression ...
1800 A combination of
1801 .Ql Ic .else
1802 followed by
1803 .Ql Ic .if .
1804 .It Ic .elifdef Oo \&! Oc Ns Ar variable Op Ar operator variable ...
1805 A combination of
1806 .Ql Ic .else
1807 followed by
1808 .Ql Ic .ifdef .
1809 .It Ic .elifndef Oo \&! Oc Ns Ar variable Op Ar operator variable ...
1810 A combination of
1811 .Ql Ic .else
1812 followed by
1813 .Ql Ic .ifndef .
1814 .It Ic .elifmake Oo \&! Oc Ns Ar target Op Ar operator target ...
1815 A combination of
1816 .Ql Ic .else
1817 followed by
1818 .Ql Ic .ifmake .
1819 .It Ic .elifnmake Oo \&! Oc Ns Ar target Op Ar operator target ...
1820 A combination of
1821 .Ql Ic .else
1822 followed by
1823 .Ql Ic .ifnmake .
1824 .It Ic .endif
1825 End the body of the conditional.
1826 .El
1827 .Pp
1828 The
1829 .Ar operator
1830 may be any one of the following:
1831 .Bl -tag -width "Cm XX"
1832 .It Cm \&|\&|
1833 Logical OR.
1834 .It Cm \&&&
1835 Logical
1836 .Tn AND ;
1837 of higher precedence than
1838 .Dq \&|\&| .
1839 .El
1840 .Pp
1841 As in C,
1842 .Nm
1843 will only evaluate a conditional as far as is necessary to determine
1844 its value.
1845 Parentheses may be used to change the order of evaluation.
1846 The boolean operator
1847 .Ql Ic \&!
1848 may be used to logically negate an entire
1849 conditional.
1850 It is of higher precedence than
1851 .Ql Ic \&&& .
1852 .Pp
1853 The value of
1854 .Ar expression
1855 may be any of the following:
1856 .Bl -tag -width defined
1857 .It Ic defined
1858 Takes a variable name as an argument and evaluates to true if the variable
1859 has been defined.
1860 .It Ic make
1861 Takes a target name as an argument and evaluates to true if the target
1862 was specified as part of
1863 .Nm Ns 's
1864 command line or was declared the default target (either implicitly or
1865 explicitly, see
1866 .Va .MAIN )
1867 before the line containing the conditional.
1868 .It Ic empty
1869 Takes a variable, with possible modifiers, and evaluates to true if
1870 the expansion of the variable would result in an empty string.
1871 .It Ic exists
1872 Takes a file name as an argument and evaluates to true if the file exists.
1873 The file is searched for on the system search path (see
1874 .Va .PATH ) .
1875 .It Ic target
1876 Takes a target name as an argument and evaluates to true if the target
1877 has been defined.
1878 .It Ic commands
1879 Takes a target name as an argument and evaluates to true if the target
1880 has been defined and has commands associated with it.
1881 .El
1882 .Pp
1883 .Ar Expression
1884 may also be an arithmetic or string comparison.
1885 Variable expansion is
1886 performed on both sides of the comparison, after which the numerical
1887 values are compared.
1888 A value is interpreted as hexadecimal if it is
1889 preceded by 0x, otherwise it is decimal; octal numbers are not supported.
1890 The standard C relational operators are all supported.
1891 If after
1892 variable expansion, either the left or right hand side of a
1893 .Ql Ic ==
1894 or
1895 .Ql Ic "!="
1896 operator is not a numerical value, then
1897 string comparison is performed between the expanded
1898 variables.
1899 If no relational operator is given, it is assumed that the expanded
1900 variable is being compared against 0, or an empty string in the case
1901 of a string comparison.
1902 .Pp
1903 When
1904 .Nm
1905 is evaluating one of these conditional expressions, and it encounters
1906 a (white-space separated) word it doesn't recognize, either the
1907 .Dq make
1908 or
1909 .Dq defined
1910 expression is applied to it, depending on the form of the conditional.
1911 If the form is
1912 .Ql Ic .ifdef ,
1913 .Ql Ic .ifndef ,
1914 or
1915 .Ql Ic .if
1916 the
1917 .Dq defined
1918 expression is applied.
1919 Similarly, if the form is
1920 .Ql Ic .ifmake
1921 or
1922 .Ql Ic .ifnmake ,
1923 the
1924 .Dq make
1925 expression is applied.
1926 .Pp
1927 If the conditional evaluates to true the parsing of the makefile continues
1928 as before.
1929 If it evaluates to false, the following lines are skipped.
1930 In both cases this continues until a
1931 .Ql Ic .else
1932 or
1933 .Ql Ic .endif
1934 is found.
1935 .Pp
1936 For loops are typically used to apply a set of rules to a list of files.
1937 The syntax of a for loop is:
1938 .Pp
1939 .Bl -tag -compact -width Ds
1940 .It Ic \&.for Ar variable Oo Ar variable ... Oc Ic in Ar expression
1941 .It Aq make-lines
1942 .It Ic \&.endfor
1943 .El
1944 .Pp
1945 After the for
1946 .Ic expression
1947 is evaluated, it is split into words.
1948 On each iteration of the loop, one word is taken and assigned to each
1949 .Ic variable ,
1950 in order, and these
1951 .Ic variables
1952 are substituted into the
1953 .Ic make-lines
1954 inside the body of the for loop.
1955 The number of words must come out even; that is, if there are three
1956 iteration variables, the number of words provided must be a multiple
1957 of three.
1958 .Sh COMMENTS
1959 Comments begin with a hash
1960 .Pq Ql \&#
1961 character, anywhere but in a shell
1962 command line, and continue to the end of an unescaped new line.
1963 .Sh SPECIAL SOURCES (ATTRIBUTES)
1964 .Bl -tag -width .IGNOREx
1965 .It Ic .EXEC
1966 Target is never out of date, but always execute commands anyway.
1967 .It Ic .IGNORE
1968 Ignore any errors from the commands associated with this target, exactly
1969 as if they all were preceded by a dash
1970 .Pq Ql \- .
1971 .\" .It Ic .INVISIBLE
1972 .\" XXX
1973 .\" .It Ic .JOIN
1974 .\" XXX
1975 .It Ic .MADE
1976 Mark all sources of this target as being up-to-date.
1977 .It Ic .MAKE
1978 Execute the commands associated with this target even if the
1979 .Fl n
1980 or
1981 .Fl t
1982 options were specified.
1983 Normally used to mark recursive
1984 .Nm Ns s .
1985 .It Ic .META
1986 Create a meta file for the target, even if it is flagged as
1987 .Ic .PHONY ,
1988 .Ic .MAKE ,
1989 or
1990 .Ic .SPECIAL .
1991 Usage in conjunction with
1992 .Ic .MAKE
1993 is the most likely case.
1994 In "meta" mode, the target is out-of-date if the meta file is missing.
1995 .It Ic .NOMETA
1996 Do not create a meta file for the target.
1997 Meta files are also not created for
1998 .Ic .PHONY ,
1999 .Ic .MAKE ,
2000 or
2001 .Ic .SPECIAL
2002 targets.
2003 .It Ic .NOMETA_CMP
2004 Ignore differences in commands when deciding if target is out of date.
2005 This is useful if the command contains a value which always changes.
2006 If the number of commands change, though, the target will still be out of date.
2007 The same effect applies to any command line that uses the variable
2008 .Va .OODATE ,
2009 which can be used for that purpose even when not otherwise needed or desired:
2010 .Bd -literal -offset indent
2011
2012 skip-compare-for-some:
2013         @echo this will be compared
2014         @echo this will not ${.OODATE:M.NOMETA_CMP}
2015         @echo this will also be compared
2016
2017 .Ed
2018 The
2019 .Cm \&:M
2020 pattern suppresses any expansion of the unwanted variable.
2021 .It Ic .NOPATH
2022 Do not search for the target in the directories specified by
2023 .Ic .PATH .
2024 .It Ic .NOTMAIN
2025 Normally
2026 .Nm
2027 selects the first target it encounters as the default target to be built
2028 if no target was specified.
2029 This source prevents this target from being selected.
2030 .It Ic .OPTIONAL
2031 If a target is marked with this attribute and
2032 .Nm
2033 can't figure out how to create it, it will ignore this fact and assume
2034 the file isn't needed or already exists.
2035 .It Ic .PHONY
2036 The target does not
2037 correspond to an actual file; it is always considered to be out of date,
2038 and will not be created with the
2039 .Fl t
2040 option.
2041 Suffix-transformation rules are not applied to
2042 .Ic .PHONY
2043 targets.
2044 .It Ic .PRECIOUS
2045 When
2046 .Nm
2047 is interrupted, it normally removes any partially made targets.
2048 This source prevents the target from being removed.
2049 .It Ic .RECURSIVE
2050 Synonym for
2051 .Ic .MAKE .
2052 .It Ic .SILENT
2053 Do not echo any of the commands associated with this target, exactly
2054 as if they all were preceded by an at sign
2055 .Pq Ql @ .
2056 .It Ic .USE
2057 Turn the target into
2058 .Nm Ns 's
2059 version of a macro.
2060 When the target is used as a source for another target, the other target
2061 acquires the commands, sources, and attributes (except for
2062 .Ic .USE )
2063 of the
2064 source.
2065 If the target already has commands, the
2066 .Ic .USE
2067 target's commands are appended
2068 to them.
2069 .It Ic .USEBEFORE
2070 Exactly like
2071 .Ic .USE ,
2072 but prepend the
2073 .Ic .USEBEFORE
2074 target commands to the target.
2075 .It Ic .WAIT
2076 If
2077 .Ic .WAIT
2078 appears in a dependency line, the sources that precede it are
2079 made before the sources that succeed it in the line.
2080 Since the dependents of files are not made until the file itself
2081 could be made, this also stops the dependents being built unless they
2082 are needed for another branch of the dependency tree.
2083 So given:
2084 .Bd -literal
2085 x: a .WAIT b
2086         echo x
2087 a:
2088         echo a
2089 b: b1
2090         echo b
2091 b1:
2092         echo b1
2093
2094 .Ed
2095 the output is always
2096 .Ql a ,
2097 .Ql b1 ,
2098 .Ql b ,
2099 .Ql x .
2100 .br
2101 The ordering imposed by
2102 .Ic .WAIT
2103 is only relevant for parallel makes.
2104 .El
2105 .Sh SPECIAL TARGETS
2106 Special targets may not be included with other targets, i.e. they must be
2107 the only target specified.
2108 .Bl -tag -width .BEGINx
2109 .It Ic .BEGIN
2110 Any command lines attached to this target are executed before anything
2111 else is done.
2112 .It Ic .DEFAULT
2113 This is sort of a
2114 .Ic .USE
2115 rule for any target (that was used only as a
2116 source) that
2117 .Nm
2118 can't figure out any other way to create.
2119 Only the shell script is used.
2120 The
2121 .Ic .IMPSRC
2122 variable of a target that inherits
2123 .Ic .DEFAULT Ns 's
2124 commands is set
2125 to the target's own name.
2126 .It Ic .DELETE_ON_ERROR
2127 If this target is present in the makefile, it globally causes make to
2128 delete targets whose commands fail.
2129 (By default, only targets whose commands are interrupted during
2130 execution are deleted.
2131 This is the historical behavior.)
2132 This setting can be used to help prevent half-finished or malformed
2133 targets from being left around and corrupting future rebuilds.
2134 .It Ic .END
2135 Any command lines attached to this target are executed after everything
2136 else is done.
2137 .It Ic .ERROR
2138 Any command lines attached to this target are executed when another target fails.
2139 The
2140 .Ic .ERROR_TARGET
2141 variable is set to the target that failed.
2142 See also
2143 .Ic MAKE_PRINT_VAR_ON_ERROR .
2144 .It Ic .IGNORE
2145 Mark each of the sources with the
2146 .Ic .IGNORE
2147 attribute.
2148 If no sources are specified, this is the equivalent of specifying the
2149 .Fl i
2150 option.
2151 .It Ic .INTERRUPT
2152 If
2153 .Nm
2154 is interrupted, the commands for this target will be executed.
2155 .It Ic .MAIN
2156 If no target is specified when
2157 .Nm
2158 is invoked, this target will be built.
2159 .It Ic .MAKEFLAGS
2160 This target provides a way to specify flags for
2161 .Nm
2162 when the makefile is used.
2163 The flags are as if typed to the shell, though the
2164 .Fl f
2165 option will have
2166 no effect.
2167 .\" XXX: NOT YET!!!!
2168 .\" .It Ic .NOTPARALLEL
2169 .\" The named targets are executed in non parallel mode.
2170 .\" If no targets are
2171 .\" specified, then all targets are executed in non parallel mode.
2172 .It Ic .NOPATH
2173 Apply the
2174 .Ic .NOPATH
2175 attribute to any specified sources.
2176 .It Ic .NOTPARALLEL
2177 Disable parallel mode.
2178 .It Ic .NO_PARALLEL
2179 Synonym for
2180 .Ic .NOTPARALLEL ,
2181 for compatibility with other pmake variants.
2182 .It Ic .OBJDIR
2183 The source is a new value for
2184 .Ql Va .OBJDIR .
2185 If it exists,
2186 .Nm
2187 will
2188 .Xr chdir 2
2189 to it and update the value of
2190 .Ql Va .OBJDIR .
2191 .It Ic .ORDER
2192 The named targets are made in sequence.
2193 This ordering does not add targets to the list of targets to be made.
2194 Since the dependents of a target do not get built until the target itself
2195 could be built, unless
2196 .Ql a
2197 is built by another part of the dependency graph,
2198 the following is a dependency loop:
2199 .Bd -literal
2200 \&.ORDER: b a
2201 b: a
2202 .Ed
2203 .Pp
2204 The ordering imposed by
2205 .Ic .ORDER
2206 is only relevant for parallel makes.
2207 .\" XXX: NOT YET!!!!
2208 .\" .It Ic .PARALLEL
2209 .\" The named targets are executed in parallel mode.
2210 .\" If no targets are
2211 .\" specified, then all targets are executed in parallel mode.
2212 .It Ic .PATH
2213 The sources are directories which are to be searched for files not
2214 found in the current directory.
2215 If no sources are specified, any previously specified directories are
2216 deleted.
2217 If the source is the special
2218 .Ic .DOTLAST
2219 target, then the current working
2220 directory is searched last.
2221 .It Ic .PATH. Ns Va suffix
2222 Like
2223 .Ic .PATH
2224 but applies only to files with a particular suffix.
2225 The suffix must have been previously declared with
2226 .Ic .SUFFIXES .
2227 .It Ic .PHONY
2228 Apply the
2229 .Ic .PHONY
2230 attribute to any specified sources.
2231 .It Ic .PRECIOUS
2232 Apply the
2233 .Ic .PRECIOUS
2234 attribute to any specified sources.
2235 If no sources are specified, the
2236 .Ic .PRECIOUS
2237 attribute is applied to every
2238 target in the file.
2239 .It Ic .SHELL
2240 Sets the shell that
2241 .Nm
2242 will use to execute commands.
2243 The sources are a set of
2244 .Ar field=value
2245 pairs.
2246 .Bl -tag -width hasErrCtls
2247 .It Ar name
2248 This is the minimal specification, used to select one of the built-in
2249 shell specs;
2250 .Ar sh ,
2251 .Ar ksh ,
2252 and
2253 .Ar csh .
2254 .It Ar path
2255 Specifies the path to the shell.
2256 .It Ar hasErrCtl
2257 Indicates whether the shell supports exit on error.
2258 .It Ar check
2259 The command to turn on error checking.
2260 .It Ar ignore
2261 The command to disable error checking.
2262 .It Ar echo
2263 The command to turn on echoing of commands executed.
2264 .It Ar quiet
2265 The command to turn off echoing of commands executed.
2266 .It Ar filter
2267 The output to filter after issuing the
2268 .Ar quiet
2269 command.
2270 It is typically identical to
2271 .Ar quiet .
2272 .It Ar errFlag
2273 The flag to pass the shell to enable error checking.
2274 .It Ar echoFlag
2275 The flag to pass the shell to enable command echoing.
2276 .It Ar newline
2277 The string literal to pass the shell that results in a single newline
2278 character when used outside of any quoting characters.
2279 .El
2280 Example:
2281 .Bd -literal
2282 \&.SHELL: name=ksh path=/bin/ksh hasErrCtl=true \e
2283         check="set \-e" ignore="set +e" \e
2284         echo="set \-v" quiet="set +v" filter="set +v" \e
2285         echoFlag=v errFlag=e newline="'\en'"
2286 .Ed
2287 .It Ic .SILENT
2288 Apply the
2289 .Ic .SILENT
2290 attribute to any specified sources.
2291 If no sources are specified, the
2292 .Ic .SILENT
2293 attribute is applied to every
2294 command in the file.
2295 .It Ic .STALE
2296 This target gets run when a dependency file contains stale entries, having
2297 .Va .ALLSRC
2298 set to the name of that dependency file.
2299 .It Ic .SUFFIXES
2300 Each source specifies a suffix to
2301 .Nm .
2302 If no sources are specified, any previously specified suffixes are deleted.
2303 It allows the creation of suffix-transformation rules.
2304 .Pp
2305 Example:
2306 .Bd -literal
2307 \&.SUFFIXES: .o
2308 \&.c.o:
2309         cc \-o ${.TARGET} \-c ${.IMPSRC}
2310 .Ed
2311 .El
2312 .Sh ENVIRONMENT
2313 .Nm
2314 uses the following environment variables, if they exist:
2315 .Ev MACHINE ,
2316 .Ev MACHINE_ARCH ,
2317 .Ev MAKE ,
2318 .Ev MAKEFLAGS ,
2319 .Ev MAKEOBJDIR ,
2320 .Ev MAKEOBJDIRPREFIX ,
2321 .Ev MAKESYSPATH ,
2322 .Ev PWD ,
2323 and
2324 .Ev TMPDIR .
2325 .Pp
2326 .Ev MAKEOBJDIRPREFIX
2327 and
2328 .Ev MAKEOBJDIR
2329 may only be set in the environment or on the command line to
2330 .Nm
2331 and not as makefile variables;
2332 see the description of
2333 .Ql Va .OBJDIR
2334 for more details.
2335 .Sh FILES
2336 .Bl -tag -width /usr/share/mk -compact
2337 .It .depend
2338 list of dependencies
2339 .It Makefile
2340 list of dependencies
2341 .It makefile
2342 list of dependencies
2343 .It sys.mk
2344 system makefile
2345 .It /usr/share/mk
2346 system makefile directory
2347 .El
2348 .Sh COMPATIBILITY
2349 The basic make syntax is compatible between different versions of make;
2350 however the special variables, variable modifiers and conditionals are not.
2351 .Ss Older versions
2352 An incomplete list of changes in older versions of
2353 .Nm :
2354 .Pp
2355 The way that .for loop variables are substituted changed after
2356 .Nx 5.0
2357 so that they still appear to be variable expansions.
2358 In particular this stops them being treated as syntax, and removes some
2359 obscure problems using them in .if statements.
2360 .Pp
2361 The way that parallel makes are scheduled changed in
2362 .Nx 4.0
2363 so that .ORDER and .WAIT apply recursively to the dependent nodes.
2364 The algorithms used may change again in the future.
2365 .Ss Other make dialects
2366 Other make dialects (GNU make, SVR4 make, POSIX make, etc.) do not
2367 support most of the features of
2368 .Nm
2369 as described in this manual.
2370 Most notably:
2371 .Bl -bullet -offset indent
2372 .It
2373 The
2374 .Ic .WAIT
2375 and
2376 .Ic .ORDER
2377 declarations and most functionality pertaining to parallelization.
2378 (GNU make supports parallelization but lacks these features needed to
2379 control it effectively.)
2380 .It
2381 Directives, including for loops and conditionals and most of the
2382 forms of include files.
2383 (GNU make has its own incompatible and less powerful syntax for
2384 conditionals.)
2385 .It
2386 All built-in variables that begin with a dot.
2387 .It
2388 Most of the special sources and targets that begin with a dot,
2389 with the notable exception of
2390 .Ic .PHONY ,
2391 .Ic .PRECIOUS ,
2392 and
2393 .Ic .SUFFIXES .
2394 .It
2395 Variable modifiers, except for the
2396 .Dl :old=new
2397 string substitution, which does not portably support globbing with
2398 .Ql %
2399 and historically only works on declared suffixes.
2400 .It
2401 The
2402 .Ic $>
2403 variable even in its short form; most makes support this functionality
2404 but its name varies.
2405 .El
2406 .Pp
2407 Some features are somewhat more portable, such as assignment with
2408 .Ic += ,
2409 .Ic ?= ,
2410 and
2411 .Ic != .
2412 The
2413 .Ic .PATH
2414 functionality is based on an older feature
2415 .Ic VPATH
2416 found in GNU make and many versions of SVR4 make; however,
2417 historically its behavior is too ill-defined (and too buggy) to rely
2418 upon.
2419 .Pp
2420 The
2421 .Ic $@
2422 and
2423 .Ic $<
2424 variables are more or less universally portable, as is the
2425 .Ic $(MAKE)
2426 variable.
2427 Basic use of suffix rules (for files only in the current directory,
2428 not trying to chain transformations together, etc.) is also reasonably
2429 portable.
2430 .Sh SEE ALSO
2431 .Xr mkdep 1 ,
2432 .Xr style.Makefile 5
2433 .Sh HISTORY
2434 A
2435 .Nm
2436 command appeared in
2437 .At v7 .
2438 This
2439 .Nm
2440 implementation is based on Adam De Boor's pmake program which was written
2441 for Sprite at Berkeley.
2442 It was designed to be a parallel distributed make running jobs on different
2443 machines using a daemon called
2444 .Dq customs .
2445 .Pp
2446 Historically the target/dependency
2447 .Dq FRC
2448 has been used to FoRCe rebuilding (since the target/dependency
2449 does not exist... unless someone creates an
2450 .Dq FRC
2451 file).
2452 .Sh BUGS
2453 The
2454 .Nm
2455 syntax is difficult to parse without actually acting on the data.
2456 For instance, finding the end of a variable's use should involve scanning
2457 each of the modifiers, using the correct terminator for each field.
2458 In many places
2459 .Nm
2460 just counts {} and () in order to find the end of a variable expansion.
2461 .Pp
2462 There is no way of escaping a space character in a filename.