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