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