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