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