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