xref: /src/contrib/bmake/bmake.1 (revision 68ad2b0d7af2a3571c4abac9afa712f9b09b721c)
1.\"	$NetBSD: make.1,v 1.388 2025/11/12 22:14:07 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 November 11, 2025
33.Dt BMAKE 1
34.Os
35.Sh NAME
36.Nm bmake
37.Nd maintain program dependencies
38.Sh SYNOPSIS
39.Nm
40.Op Fl BeikNnqrSstWwX
41.Op Fl C Ar directory
42.Op Fl D Ar variable
43.Op Fl d Ar flags
44.Op Fl f Ar makefile
45.Op Fl I Ar directory
46.Op Fl J Ar private
47.Op Fl j Ar max_jobs
48.Op Fl m Ar directory
49.Op Fl T Ar file
50.Op Fl V Ar variable
51.Op Fl v Ar variable
52.Op Ar variable\| Ns Cm \&= Ns Ar value
53.Op Ar target No ...
54.Sh DESCRIPTION
55.Nm
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 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 \&>
793or
794.Sq Va \&^ .
795.It Va .ARCHIVE
796The name of the archive file; also known as
797.Sq Va \&! .
798.It Va .IMPSRC
799In suffix-transformation rules, the name/path of the source from which the
800target is to be transformed (the
801.Dq implied
802source); also known as
803.Sq Va \&< .
804It is not defined in explicit rules.
805.It Va .MEMBER
806The name of the archive member; also known as
807.Sq Va % .
808.It Va .OODATE
809The list of sources for this target that were deemed out-of-date; also
810known as
811.Sq Va \&? .
812.It Va .PREFIX
813The name of the target with suffix (if declared in
814.Ic .SUFFIXES )
815removed; also known as
816.Sq Va * .
817.It Va .TARGET
818The name of the target; also known as
819.Sq Va @ .
820For compatibility with other makes this is an alias for
821.Va .ARCHIVE
822in archive member rules.
823.El
824.Pp
825The shorter forms
826.Po
827.Sq Va \&> ,
828.Sq Va \&^ ,
829.Sq Va \&! ,
830.Sq Va \&< ,
831.Sq Va \&% ,
832.Sq Va \&? ,
833.Sq Va \&* ,
834and
835.Sq Va \&@
836.Pc
837are permitted for backward
838compatibility with historical makefiles and legacy POSIX make and are
839not recommended.
840.Pp
841Variants of these variables with the punctuation followed immediately by
842.Ql D
843or
844.Ql F ,
845e.g.\&
846.Ql $(@D) ,
847are legacy forms equivalent to using the
848.Ql :H
849and
850.Ql :T
851modifiers.
852These forms are accepted for compatibility with
853.At V
854makefiles and POSIX but are not recommended.
855.Pp
856Four of the local variables may be used in sources on dependency lines
857because they expand to the proper value for each target on the line.
858These variables are
859.Sq Va .TARGET ,
860.Sq Va .PREFIX ,
861.Sq Va .ARCHIVE ,
862and
863.Sq Va .MEMBER .
864.Ss Additional built-in variables
865In addition,
866.Nm
867sets or knows about the following variables:
868.Bl -tag
869.\" NB: This list is sorted case-insensitive, ignoring punctuation.
870.\" NB: To find all built-in variables in make's source code,
871.\" NB: search for Var_*, Global_*, SetVarObjdir, GetBooleanExpr,
872.\" NB: and the implementation of Var_SetWithFlags.
873.\" NB: Last synced on 2023-01-01.
874.It Va .ALLTARGETS
875The list of all targets encountered in the makefiles.
876If evaluated during makefile parsing,
877lists only those targets encountered thus far.
878.It Va .CURDIR
879A path to the directory where
880.Nm
881was executed.
882Refer to the description of
883.Sq Va PWD
884for more details.
885.It Va .ERROR_CMD
886Is used in error handling, see
887.Va MAKE_PRINT_VAR_ON_ERROR .
888.It Va .ERROR_CWD
889Is used in error handling, see
890.Va MAKE_PRINT_VAR_ON_ERROR .
891.It Va .ERROR_EXIT
892Is used in error handling, see
893.Va MAKE_PRINT_VAR_ON_ERROR .
894.It Va .ERROR_META_FILE
895Is used in error handling in
896.Dq meta
897mode, see
898.Va MAKE_PRINT_VAR_ON_ERROR .
899.It Va .ERROR_TARGET
900Is used in error handling, see
901.Va MAKE_PRINT_VAR_ON_ERROR .
902.It Va .INCLUDEDFROMDIR
903The directory of the file this makefile was included from.
904.It Va .INCLUDEDFROMFILE
905The filename of the file this makefile was included from.
906.\" .INCLUDES is intentionally undocumented, as it is obsolete.
907.\" .LIBS is intentionally undocumented, as it is obsolete.
908.It Va MACHINE
909The machine hardware name, see
910.Xr uname 1 .
911.It Va MACHINE_ARCH
912The machine processor architecture name, see
913.Xr uname 1 .
914.It Va MAKE
915The name that
916.Nm
917was executed with
918.Pq Va argv[0] .
919.It Va .MAKE
920The same as
921.Va MAKE ,
922for compatibility.
923The preferred variable to use is the environment variable
924.Ev MAKE
925because it is more compatible with other make variants
926and cannot be confused with the special target with the same name.
927.\" '.MAKE.cmd_filtered' is intentionally undocumented,
928.\" as it is an internal implementation detail.
929.It Va .MAKE.DEPENDFILE
930Names the makefile (default
931.Sq Pa .depend )
932from which generated dependencies are read.
933.It Va .MAKE.DIE_QUIETLY
934If set to
935.Ql true ,
936do not print error information at the end.
937.It Va .MAKE.EXPAND_VARIABLES
938A boolean that controls the default behavior of the
939.Fl V
940option.
941If true, variable values printed with
942.Fl V
943are fully expanded; if false, the raw variable contents (which may
944include additional unexpanded variable references) are shown.
945.It Va .MAKE.EXPORTED
946The list of variables exported by
947.Nm .
948.It Va MAKE_VERSION
949This variable indicates the version of
950.Nm .
951It is typically the date of last import from NetBSD.
952It is useful for checking whether certain features are available.
953.It Va MAKEFILE
954The top-level makefile that is currently read,
955as given in the command line.
956.It Va .MAKEFLAGS
957The environment variable
958.Sq Ev MAKEFLAGS
959may contain anything that
960may be specified on
961.Nm Ns 's
962command line.
963Anything specified on
964.Nm Ns 's
965command line is appended to the
966.Va .MAKEFLAGS
967variable, which is then added to the environment for all programs that
968.Nm
969executes.
970.It Va .MAKE.GID
971The numeric group ID of the user running
972.Nm .
973It is read-only.
974.It Va .MAKE.JOB.PREFIX
975If
976.Nm
977is run with
978.Fl j ,
979the output for each target is prefixed with a token
980.Dl --- Ar target Li ---
981the first part of which can be controlled via
982.Va .MAKE.JOB.PREFIX .
983If
984.Va .MAKE.JOB.PREFIX
985is empty, no token is printed.
986For example, setting
987.Va .MAKE.JOB.PREFIX
988to
989.Ql ${.newline}---${.MAKE:T}[${.MAKE.PID}]
990would produce tokens like
991.Dl ---make[1234] Ar target Li ---
992making it easier to track the degree of parallelism being achieved.
993.It Va .MAKE.JOBS
994The argument to the
995.Fl j
996option.
997.It Va .MAKE.JOBS.C
998A read-only boolean that indicates whether the
999.Fl j
1000option supports use of
1001.Ql C .
1002.It Va .MAKE.LEVEL
1003The recursion depth of
1004.Nm .
1005The top-level instance of
1006.Nm
1007has level 0, and each child make has its parent level plus 1.
1008This allows tests like:
1009.Li .if ${.MAKE.LEVEL} == 0
1010to protect things which should only be evaluated in the top-level instance of
1011.Nm .
1012.It Va .MAKE.LEVEL.ENV
1013The name of the environment variable that stores the level of nested calls to
1014.Nm .
1015.It Va .MAKE.MAKEFILE_PREFERENCE
1016The ordered list of makefile names
1017(default
1018.Sq Pa makefile ,
1019.Sq Pa Makefile )
1020that
1021.Nm
1022looks for.
1023.It Va .MAKE.MAKEFILES
1024The list of makefiles read by
1025.Nm ,
1026which is useful for tracking dependencies.
1027Each makefile is recorded only once, regardless of the number of times read.
1028.It Va .MAKE.META.BAILIWICK
1029In
1030.Dq meta
1031mode, provides a list of prefixes which
1032match the directories controlled by
1033.Nm .
1034If a file that was generated outside of
1035.Va .OBJDIR
1036but within said bailiwick is missing,
1037the current target is considered out-of-date.
1038.It Va .MAKE.META.CMP_FILTER
1039In
1040.Dq meta
1041mode, it can (very rarely!) be useful to filter command
1042lines before comparison.
1043This variable can be set to a set of modifiers that are applied to
1044each line of the old and new command that differ, if the filtered
1045commands still differ, the target is considered out-of-date.
1046.It Va .MAKE.META.CREATED
1047In
1048.Dq meta
1049mode, this variable contains a list of all the meta files
1050updated.
1051If not empty, it can be used to trigger processing of
1052.Va .MAKE.META.FILES .
1053.It Va .MAKE.META.FILES
1054In
1055.Dq meta
1056mode, this variable contains a list of all the meta files
1057used (updated or not).
1058This list can be used to process the meta files to extract dependency
1059information.
1060.It Va .MAKE.META.IGNORE_FILTER
1061Provides a list of variable modifiers to apply to each pathname.
1062Ignore if the expansion is an empty string.
1063.It Va .MAKE.META.IGNORE_PATHS
1064Provides a list of path prefixes that should be ignored;
1065because the contents are expected to change over time.
1066The default list includes:
1067.Sq Pa /dev /etc /proc /tmp /var/run /var/tmp
1068.It Va .MAKE.META.IGNORE_PATTERNS
1069Provides a list of patterns to match against pathnames.
1070Ignore any that match.
1071.It Va .MAKE.META.PREFIX
1072Defines the message printed for each meta file updated in
1073.Dq meta verbose
1074mode.
1075The default value is:
1076.Dl Building ${.TARGET:H:tA}/${.TARGET:T}
1077.It Va .MAKE.MODE
1078Processed after reading all makefiles.
1079Affects the mode that
1080.Nm
1081runs in.
1082It can contain these keywords:
1083.Bl -tag -width indent
1084.It Cm compat
1085Like
1086.Fl B ,
1087puts
1088.Nm
1089into
1090.Dq compat
1091mode.
1092.It Cm meta
1093Puts
1094.Nm
1095into
1096.Dq meta
1097mode, where meta files are created for each target
1098to capture the commands run, the output generated, and if
1099.Xr filemon 4
1100is available, the system calls which are of interest to
1101.Nm .
1102The captured output can be useful when diagnosing errors.
1103.Pp
1104.Nm
1105will use the information in the meta file to help determine if
1106a target is out-of-date when the normal dependency rules
1107indicate it is not.
1108.Pp
1109First,
1110the commands to be executed,
1111will be compared to those captured previously,
1112if any differ,
1113the target is out-of-date.
1114.Pp
1115This allows for a huge improvement in the reliability
1116and efficiency of update builds.
1117It is no longer necessary for targets to depend on makefiles
1118just in-case they set a variable that might be relevant.
1119Mechanisms such as
1120.Va .MAKE.META.CMP_FILTER
1121and
1122.Ic .NOMETA_CMP ,
1123allow limiting or disabling that comparison on a per target basis.
1124A reference to the variable
1125.Va .OODATE
1126can be leveraged to block comparison of certain commands.
1127For example:
1128.Ql ${.OODATE:M}
1129will expand to nothing and have no impact on the target,
1130its side-effect though,
1131will be to prevent comparison of any command line it appears on.
1132For documentation purposes
1133.Ql ${.OODATE:MNOMETA_CMP}
1134is useful.
1135.Pp
1136If necessary,
1137.Nm
1138will then use the information captured by
1139.Xr filemon 4 ,
1140to check the modification time of any file used in generating
1141the target,
1142if any is newer,
1143the target is out-of-date.
1144.Pp
1145Such deep inspection can easily lead to cases where a target is
1146.Em always
1147considered out-of-date, which is why
1148.Va .MAKE.META.IGNORE_FILTER ,
1149.Va .MAKE.META.IGNORE_PATHS
1150and
1151.Va .MAKE.META.IGNORE_PATTERNS ,
1152are provided to limit that inspection when necessary.
1153.It Cm curdirOk= Ns Ar bf
1154By default,
1155.Nm
1156does not create
1157.Pa .meta
1158files in
1159.Sq Va .CURDIR .
1160This can be overridden by setting
1161.Ar bf
1162to a value which represents true.
1163.It Cm missing-meta= Ns Ar bf
1164If
1165.Ar bf
1166is true, a missing
1167.Pa .meta
1168file makes the target out-of-date.
1169.It Cm missing-filemon= Ns Ar bf
1170If
1171.Ar bf
1172is true, missing filemon data makes the target out-of-date.
1173.It Cm nofilemon
1174Do not use
1175.Xr filemon 4 .
1176.It Cm env
1177For debugging, it can be useful to include the environment
1178in the
1179.Pa .meta
1180file.
1181.It Cm verbose
1182If in
1183.Dq meta
1184mode, print a clue about the target being built.
1185This is useful if the build is otherwise running silently.
1186The message printed is the expanded value of
1187.Va .MAKE.META.PREFIX .
1188.It Cm ignore-cmd
1189Some makefiles have commands which are simply not stable.
1190This keyword causes them to be ignored for
1191determining whether a target is out of date in
1192.Dq meta
1193mode.
1194See also
1195.Ic .NOMETA_CMP .
1196.It Cm silent= Ns Ar bf
1197If
1198.Ar bf
1199is true, when a .meta file is created, mark the target
1200.Ic .SILENT .
1201.It Cm randomize-targets
1202In both compat and parallel mode, do not make the targets in the usual order,
1203but instead randomize their order.
1204This mode can be used to detect undeclared dependencies between files.
1205.El
1206.It Va MAKEOBJDIR
1207Used to create files in a separate directory, see
1208.Va .OBJDIR .
1209.It Va MAKE_OBJDIR_CHECK_WRITABLE
1210When true,
1211.Nm
1212will check that
1213.Va .OBJDIR
1214is writable, and issue a warning if not.
1215.It Va MAKE_DEBUG_OBJDIR_CHECK_WRITABLE
1216When true and
1217.Nm
1218is warning about an unwritable
1219.Va .OBJDIR ,
1220report the variables listed in
1221.Va MAKE_PRINT_VAR_ON_ERROR
1222to help debug.
1223.It Va MAKEOBJDIRPREFIX
1224Used to create files in a separate directory, see
1225.Va .OBJDIR .
1226It should be an absolute path.
1227.It Va .MAKE.OS
1228The name of the operating system, see
1229.Xr uname 1 .
1230It is read-only.
1231.It Va .MAKEOVERRIDES
1232This variable is used to record the names of variables assigned to
1233on the command line, so that they may be exported as part of
1234.Sq Ev MAKEFLAGS .
1235This behavior can be disabled by assigning an empty value to
1236.Sq Va .MAKEOVERRIDES
1237within a makefile.
1238Extra variables can be exported from a makefile
1239by appending their names to
1240.Sq Va .MAKEOVERRIDES .
1241.Sq Ev MAKEFLAGS
1242is re-exported whenever
1243.Sq Va .MAKEOVERRIDES
1244is modified.
1245.It Va .MAKE.PATH_FILEMON
1246If
1247.Nm
1248was built with
1249.Xr filemon 4
1250support, this is set to the path of the device node.
1251This allows makefiles to test for this support.
1252.It Va .MAKE.PID
1253The process ID of
1254.Nm .
1255It is read-only.
1256.It Va .MAKE.PPID
1257The parent process ID of
1258.Nm .
1259It is read-only.
1260.It Va MAKE_PRINT_VAR_ON_ERROR
1261When
1262.Nm
1263stops due to an error, it sets
1264.Sq Va .ERROR_TARGET
1265to the name of the target that failed,
1266.Sq Va .ERROR_EXIT
1267to the exit status of the failed target,
1268.Sq Va .ERROR_CMD
1269to the commands of the failed target,
1270and in
1271.Dq meta
1272mode, it also sets
1273.Sq Va .ERROR_CWD
1274to the
1275.Xr getcwd 3 ,
1276and
1277.Sq Va .ERROR_META_FILE
1278to the path of the meta file (if any) describing the failed target.
1279It then prints its name and the value of
1280.Sq Va .CURDIR
1281as well as the value of any variables named in
1282.Sq Va MAKE_PRINT_VAR_ON_ERROR .
1283.It Va .MAKE.SAVE_DOLLARS
1284If true,
1285.Ql $$
1286are preserved when doing
1287.Ql :=
1288assignments.
1289The default is false, for backwards compatibility.
1290Set to true for compatability with other makes.
1291If set to false,
1292.Ql $$
1293becomes
1294.Ql $
1295per normal evaluation rules.
1296.It Va .MAKE.TARGET_LOCAL_VARIABLES
1297If set to
1298.Ql false ,
1299apparent variable assignments in dependency lines are
1300treated as normal sources.
1301.It Va .MAKE.UID
1302The numeric ID of the user running
1303.Nm .
1304It is read-only.
1305.\" 'MAKE_VERSION' is intentionally undocumented
1306.\" since it is only defined in the bmake distribution,
1307.\" but not in NetBSD's native make.
1308.\" '.meta.%d.lcwd' is intentionally undocumented
1309.\" since it is an internal implementation detail.
1310.\" '.meta.%d.ldir' is intentionally undocumented
1311.\" since it is an internal implementation detail.
1312.\" 'MFLAGS' is intentionally undocumented
1313.\" since it is obsolete.
1314.It Va .newline
1315This variable is simply assigned a newline character as its value.
1316It is read-only.
1317This allows expansions using the
1318.Cm \&:@
1319modifier to put a newline between
1320iterations of the loop rather than a space.
1321For example, in case of an error,
1322.Nm
1323prints the variable names and their values using:
1324.Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}
1325.It Va .OBJDIR
1326A path to the directory where the targets are built.
1327Its value is determined by trying to
1328.Xr chdir 2
1329to the following directories in order and using the first match:
1330.Bl -enum
1331.It
1332.Cm ${MAKEOBJDIRPREFIX} Ns Cm ${.CURDIR}
1333.Pp
1334(Only if
1335.Sq Ev MAKEOBJDIRPREFIX
1336is set in the environment or on the command line.)
1337.It
1338.Cm ${MAKEOBJDIR}
1339.Pp
1340(Only if
1341.Sq Ev MAKEOBJDIR
1342is set in the environment or on the command line.)
1343.It
1344.Cm ${.CURDIR} Ns Pa /obj. Ns Cm ${MACHINE}
1345.It
1346.Cm ${.CURDIR} Ns Pa /obj
1347.It
1348.Pa /usr/obj/ Ns Cm ${.CURDIR}
1349.It
1350.Cm ${.CURDIR}
1351.El
1352.Pp
1353Variable expansion is performed on the value before it is used,
1354so expressions such as
1355.Cm ${.CURDIR:S,^/usr/src,/var/obj,}
1356may be used.
1357This is especially useful with
1358.Sq Ev MAKEOBJDIR .
1359.Pp
1360.Sq Va .OBJDIR
1361may be modified in the makefile via the special target
1362.Sq Ic .OBJDIR .
1363In all cases,
1364.Nm
1365changes to the specified directory if it exists, and sets
1366.Sq Va .OBJDIR
1367and
1368.Sq Va PWD
1369to that directory before executing any targets.
1370.Pp
1371Except in the case of an explicit
1372.Sq Ic .OBJDIR
1373target,
1374.Nm
1375checks that the specified directory is writable and ignores it if not.
1376This check can be skipped by setting the environment variable
1377.Sq Ev MAKE_OBJDIR_CHECK_WRITABLE
1378to
1379.Dq no .
1380.It Va .PARSEDIR
1381The directory name of the current makefile being parsed.
1382.It Va .PARSEFILE
1383The basename of the current makefile being parsed.
1384This variable and
1385.Sq Va .PARSEDIR
1386are both set only while the makefiles are being parsed.
1387To retain their current values,
1388assign them to a variable using assignment with expansion
1389.Sq Cm \&:= .
1390.It Va .PATH
1391The space-separated list of directories that
1392.Nm
1393searches for files.
1394To update this search list, use the special target
1395.Sq Ic .PATH
1396rather than modifying the variable directly.
1397.It Va %POSIX
1398Is set in POSIX mode, see the special
1399.Ql Va .POSIX
1400target.
1401.\" XXX: There is no make variable named 'PWD',
1402.\" XXX: make only reads and writes the environment variable 'PWD'.
1403.It Va PWD
1404Alternate path to the current directory.
1405.Nm
1406normally sets
1407.Sq Va .CURDIR
1408to the canonical path given by
1409.Xr getcwd 3 .
1410However, if the environment variable
1411.Sq Ev PWD
1412is set and gives a path to the current directory,
1413.Nm
1414sets
1415.Sq Va .CURDIR
1416to the value of
1417.Sq Ev PWD
1418instead.
1419This behavior is disabled if
1420.Sq Ev MAKEOBJDIRPREFIX
1421is set or
1422.Sq Ev MAKEOBJDIR
1423contains a variable transform.
1424.Sq Va PWD
1425is set to the value of
1426.Sq Va .OBJDIR
1427for all programs which
1428.Nm
1429executes.
1430.It Va .SHELL
1431The pathname of the shell used to run target scripts.
1432It is read-only.
1433.It Va .SUFFIXES
1434The list of known suffixes.
1435It is read-only.
1436.It Va .SYSPATH
1437The space-separated list of directories that
1438.Nm
1439searches for makefiles, referred to as the system include path.
1440To update this search list, use the special target
1441.Sq Ic .SYSPATH
1442rather than modifying the variable which is read-only.
1443.It Va .TARGETS
1444The list of targets explicitly specified on the command line, if any.
1445.It Va VPATH
1446The colon-separated
1447.Pq Dq \&:
1448list of directories that
1449.Nm
1450searches for files.
1451This variable is supported for compatibility with old make programs only, use
1452.Sq Va .PATH
1453instead.
1454.El
1455.Ss Variable modifiers
1456The general format of a variable expansion is:
1457.Pp
1458.Sm off
1459.D1 Ic \&${ Ar variable\| Oo Ic \&: Ar modifier\| Oo Ic \&: No ... Oc Oc Ic \&}
1460.Sm on
1461.Pp
1462Each modifier begins with a colon.
1463To escape a colon, precede it with a backslash
1464.Ql \e .
1465.Pp
1466A list of indirect modifiers can be specified via a variable, as follows:
1467.Pp
1468.Bd -literal -offset indent
1469.Ar modifier_variable\^ Li \&= Ar modifier Ns Oo Ic \&: Ns No ... Oc
1470
1471.Sm off
1472.Ic \&${ Ar variable Ic \&:${ Ar modifier_variable Ic \&} Oo Ic \&: No ... Oc Ic \&}
1473.Sm on
1474.Ed
1475.Pp
1476In this case, the first modifier in the
1477.Ar modifier_variable
1478does not start with a colon,
1479since that colon already occurs in the referencing variable.
1480If any of the modifiers in the
1481.Ar modifier_variable
1482contains a dollar sign
1483.Pq Ql $ ,
1484these must be doubled to avoid early expansion.
1485.Pp
1486Some modifiers interpret the expression value as a single string,
1487others treat the expression value as a whitespace-separated list of words.
1488When splitting a string into words,
1489whitespace can be escaped using double quotes, single quotes and backslashes,
1490like in the shell.
1491The quotes and backslashes are retained in the words.
1492.Pp
1493The supported modifiers are:
1494.Bl -tag -width EEE
1495.It Cm \&:E
1496Replaces each word with its suffix.
1497.It Cm \&:H
1498Replaces each word with its dirname.
1499.It Cm \&:M\| Ns Ar pattern
1500Selects only those words that match
1501.Ar pattern .
1502The standard shell wildcard characters
1503.Pf ( Ql * ,
1504.Ql \&? ,
1505and
1506.Ql \&[] )
1507may
1508be used.
1509The wildcard characters may be escaped with a backslash
1510.Pq Ql \e .
1511As a consequence of the way values are split into words, matched,
1512and then joined, the construct
1513.Ql ${VAR:M*}
1514removes all leading and trailing whitespace
1515and normalizes the inter-word spacing to a single space.
1516.It Cm \&:N\| Ns Ar pattern
1517This is the opposite of
1518.Sq Cm \&:M ,
1519selecting all words which do
1520.Em not
1521match
1522.Ar pattern .
1523.It Cm \&:O
1524Orders the words lexicographically.
1525.It Cm \&:On
1526Orders the words numerically.
1527A number followed by one of
1528.Ql k ,
1529.Ql M
1530or
1531.Ql G
1532is multiplied by the appropriate factor, which is 1024 for
1533.Ql k ,
15341048576 for
1535.Ql M ,
1536or 1073741824 for
1537.Ql G .
1538Both upper- and lower-case letters are accepted.
1539.It Cm \&:Or
1540Orders the words in reverse lexicographical order.
1541.It Cm \&:Orn
1542Orders the words in reverse numerical order.
1543.It Cm \&:Ox
1544Shuffles the words.
1545The results are different each time you are referring to the
1546modified variable; use the assignment with expansion
1547.Sq Cm \&:=
1548to prevent such behavior.
1549For example,
1550.Bd -literal -offset indent
1551LIST=			uno due tre quattro
1552RANDOM_LIST=		${LIST:Ox}
1553STATIC_RANDOM_LIST:=	${LIST:Ox}
1554
1555all:
1556	@echo "${RANDOM_LIST}"
1557	@echo "${RANDOM_LIST}"
1558	@echo "${STATIC_RANDOM_LIST}"
1559	@echo "${STATIC_RANDOM_LIST}"
1560.Ed
1561may produce output similar to:
1562.Bd -literal -offset indent
1563quattro due tre uno
1564tre due quattro uno
1565due uno quattro tre
1566due uno quattro tre
1567.Ed
1568.It Cm \&:Q
1569Quotes every shell meta-character in the value, so that it can be passed
1570safely to the shell.
1571.It Cm \&:q
1572Quotes every shell meta-character in the value, and also doubles
1573.Sq $
1574characters so that it can be passed
1575safely through recursive invocations of
1576.Nm .
1577This is equivalent to
1578.Sq Cm \&:S/\e\&$/&&/g:Q .
1579.It Cm \&:R
1580Replaces each word with everything but its suffix.
1581.It Cm \&:range Ns Oo Cm = Ns Ar count Oc
1582The value is an integer sequence representing the words of the original
1583value, or the supplied
1584.Ar count .
1585.It Cm \&:gmtime Ns Oo Cm = Ns Ar timestamp Oc
1586The value is interpreted as a format string for
1587.Xr strftime 3 ,
1588using
1589.Xr gmtime 3 ,
1590producing the formatted timestamp.
1591Note: the
1592.Ql %s
1593format should only be used with
1594.Sq Cm \&:localtime .
1595If a
1596.Ar timestamp
1597value is not provided or is 0, the current time is used.
1598.It Cm \&:hash
1599Computes a 32-bit hash of the value and encodes it as 8 hex digits.
1600.It Cm \&:localtime Ns Oo Cm = Ns Ar timestamp Oc
1601The value is interpreted as a format string for
1602.Xr strftime 3 ,
1603using
1604.Xr localtime 3 ,
1605producing the formatted timestamp.
1606If a
1607.Ar timestamp
1608value is not provided or is 0, the current time is used.
1609.It Cm \&:mtime Ns Oo Cm = Ns Ar timestamp Oc
1610Call
1611.Xr stat 2
1612with each word as pathname;
1613use
1614.Ql st_mtime
1615as the new value.
1616If
1617.Xr stat 2
1618fails; use
1619.Ar timestamp
1620or current time.
1621If
1622.Ar timestamp
1623is set to
1624.Ql error ,
1625then
1626.Xr stat 2
1627failure will cause an error.
1628.It Cm \&:tA
1629Attempts to convert the value to an absolute path using
1630.Xr realpath 3 .
1631If that fails, the value is unchanged.
1632.It Cm \&:tl
1633Converts the value to lower-case letters.
1634.It Cm \&:ts Ns Ar c
1635When joining the words after a modifier that treats the value as words,
1636the words are normally separated by a space.
1637This modifier changes the separator to the character
1638.Ar c .
1639If
1640.Ar c
1641is omitted, no separator is used.
1642The common escapes (including octal numeric codes) work as expected.
1643.It Cm \&:tt
1644Converts the first character of each word to upper-case,
1645and the rest to lower-case letters.
1646.It Cm \&:tu
1647Converts the value to upper-case letters.
1648.It Cm \&:tW
1649Causes subsequent modifiers to treat the value as a single word
1650(possibly containing embedded whitespace).
1651See also
1652.Sq Cm \&:[*] .
1653.It Cm \&:tw
1654Causes the value to be treated as a list of words.
1655See also
1656.Sq Cm \&:[@] .
1657.Sm off
1658.It Cm \&:S\| No \&/ Ar old_string\| No \&/ Ar new_string\| No \&/ Op Cm 1gW
1659.Sm on
1660Modifies the first occurrence of
1661.Ar old_string
1662in each word of the value, replacing it with
1663.Ar new_string .
1664If a
1665.Ql g
1666is appended to the last delimiter of the pattern,
1667all occurrences in each word are replaced.
1668If a
1669.Ql 1
1670is appended to the last delimiter of the pattern,
1671only the first occurrence is affected.
1672If a
1673.Ql W
1674is appended to the last delimiter of the pattern,
1675the value is treated as a single word.
1676If
1677.Ar old_string
1678begins with a caret
1679.Pq Ql ^ ,
1680.Ar old_string
1681is anchored at the beginning of each word.
1682If
1683.Ar old_string
1684ends with a dollar sign
1685.Pq Ql \&$ ,
1686it is anchored at the end of each word.
1687Inside
1688.Ar new_string ,
1689an ampersand
1690.Pq Ql &
1691is replaced by
1692.Ar old_string
1693(without the anchoring
1694.Ql ^
1695or
1696.Ql \&$ ) .
1697Any character may be used as the delimiter for the parts of the modifier
1698string.
1699The anchoring, ampersand and delimiter characters can be escaped with a
1700backslash
1701.Pq Ql \e .
1702.Pp
1703Both
1704.Ar old_string
1705and
1706.Ar new_string
1707may contain nested expressions.
1708To prevent a dollar sign from starting a nested expression,
1709escape it with a backslash.
1710.Sm off
1711.It Cm \&:C\| No \&/ Ar pattern\| No \&/ Ar replacement\| No \&/ Op Cm 1gW
1712.Sm on
1713The
1714.Cm \&:C
1715modifier works like the
1716.Cm \&:S
1717modifier except that the old and new strings, instead of being
1718simple strings, are an extended regular expression
1719.Ar pattern
1720(see
1721.Xr regex 3 )
1722and an
1723.Xr ed 1 Ns \-style
1724.Ar replacement .
1725Normally, the first occurrence of the pattern
1726.Ar pattern
1727in each word of the value is substituted with
1728.Ar replacement .
1729The
1730.Ql 1
1731modifier causes the substitution to apply to at most one word; the
1732.Ql g
1733modifier causes the substitution to apply to as many instances of the
1734search pattern
1735.Ar pattern
1736as occur in the word or words it is found in; the
1737.Ql W
1738modifier causes the value to be treated as a single word
1739(possibly containing embedded whitespace).
1740.Pp
1741As for the
1742.Cm \&:S
1743modifier, the
1744.Ar pattern
1745and
1746.Ar replacement
1747are subjected to variable expansion before being parsed as
1748regular expressions.
1749.It Cm \&:T
1750Replaces each word with its last path component (basename).
1751.It Cm \&:u
1752Removes adjacent duplicate words (like
1753.Xr uniq 1 ) .
1754.Sm off
1755.It Cm \&:\&?\| Ar true_string\| Cm \&: Ar false_string
1756.Sm on
1757If the variable name (not its value), when parsed as a
1758.Cm .if
1759conditional expression, evaluates to true, return as its value the
1760.Ar true_string ,
1761otherwise return the
1762.Ar false_string .
1763Since the variable name is used as the expression,
1764\&:\&? must be the first modifier after the variable name
1765.No itself Ns \^\(em\^ Ns
1766which, of course, usually contains variable expansions.
1767A common error is trying to use expressions like
1768.Dl ${NUMBERS:M42:?match:no}
1769which actually tests defined(NUMBERS).
1770To determine if any words match
1771.Dq 42 ,
1772you need to use something like:
1773.Dl ${"${NUMBERS:M42}" != \&"\&":?match:no} .
1774.It Cm :\| Ns Ar old_string\| Ns Cm = Ns Ar new_string
1775This is the
1776.At V
1777style substitution.
1778It can only be the last modifier specified,
1779as a
1780.Ql \&:
1781in either
1782.Ar old_string
1783or
1784.Ar new_string
1785is treated as a regular character, not as the end of the modifier.
1786.Pp
1787If
1788.Ar old_string
1789does not contain the pattern matching character
1790.Ql % ,
1791and the word ends with
1792.Ar old_string
1793or equals it,
1794that suffix is replaced with
1795.Ar new_string .
1796.Pp
1797Otherwise, the first
1798.Ql %
1799in
1800.Ar old_string
1801matches a possibly empty substring of arbitrary characters,
1802and if the whole pattern is found in the word,
1803the matching part is replaced with
1804.Ar new_string ,
1805and the first occurrence of
1806.Ql %
1807in
1808.Ar new_string
1809(if any) is replaced with the substring matched by the
1810.Ql % .
1811.Pp
1812Both
1813.Ar old_string
1814and
1815.Ar new_string
1816may contain nested expressions.
1817To prevent a dollar sign from starting a nested expression,
1818escape it with a backslash.
1819.Sm off
1820.It Cm \&:@ Ar varname\| Cm @ Ar string\| Cm @
1821.Sm on
1822This is the loop expansion mechanism from the OSF Development
1823Environment (ODE) make.
1824Unlike
1825.Cm \&.for
1826loops, expansion occurs at the time of reference.
1827For each word in the value, assign the word to the variable named
1828.Ar varname
1829and evaluate
1830.Ar string .
1831The ODE convention is that
1832.Ar varname
1833should start and end with a period, for example:
1834.Dl ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@}
1835.Pp
1836However, a single-letter variable is often more readable:
1837.Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}
1838.It Cm \&:_ Ns Oo Cm = Ns Ar var Oc
1839Saves the current variable value in
1840.Ql $_
1841or the named
1842.Ar var
1843for later reference.
1844Example usage:
1845.Bd -literal -offset indent
1846M_cmpv.units = 1 1000 1000000
1847M_cmpv = S,., ,g:_:range:@i@+ $${_:[-$$i]} \&\\
1848\\* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh
1849
1850.Dv .if ${VERSION:${M_cmpv}} < ${3.1.12:L:${M_cmpv}}
1851
1852.Ed
1853Here
1854.Ql $_
1855is used to save the result of the
1856.Ql :S
1857modifier which is later referenced using the index values from
1858.Ql :range .
1859.It Cm \&:U\| Ns Ar newval
1860If the variable is undefined,
1861the optional
1862.Ar newval
1863(which may be empty) is the value.
1864If the variable is defined, the existing value is returned.
1865This is another ODE make feature.
1866It is handy for setting per-target CFLAGS for instance:
1867.Dl ${_${.TARGET:T}_CFLAGS:U${DEF_CFLAGS}}
1868If a value is only required if the variable is undefined, use:
1869.Dl ${VAR:D:Unewval}
1870.It Cm \&:D\| Ns Ar newval
1871If the variable is defined,
1872.Ar newval
1873(which may be empty) is the value.
1874.It Cm \&:L
1875The name of the variable is the value.
1876.It Cm \&:P
1877The path of the node which has the same name as the variable is the value.
1878If no such node exists or its path is null, the name of the variable is used.
1879In order for this modifier to work, the name (node) must at least have
1880appeared on the right-hand side of a dependency.
1881.Sm off
1882.It Cm \&:\&! Ar cmd\| Cm \&!
1883.Sm on
1884The output of running
1885.Ar cmd
1886is the value.
1887.It Cm \&:sh
1888The value is run as a command, and the output becomes the new value.
1889.It Cm \&:sh1
1890The value is run as a command, for the first reference only, and
1891the output is cached for subsequent references.
1892This modifier is useful when the result is not expected to change.
1893.It Cm \&::= Ns Ar str
1894The variable is assigned the value
1895.Ar str
1896after substitution.
1897This modifier and its variations are useful in obscure situations
1898such as wanting to set a variable
1899at a point where a target's shell commands are being parsed.
1900These assignment modifiers always expand to nothing.
1901.Pp
1902The
1903.Sq Cm \&::
1904helps avoid false matches with the
1905.At V
1906style
1907.Ql \&:=
1908modifier and since substitution always occurs, the
1909.Ql \&::=
1910form is vaguely appropriate.
1911.It Cm \&::?= Ns Ar str
1912As for
1913.Cm \&::=
1914but only if the variable does not already have a value.
1915.It Cm \&::+= Ns Ar str
1916Append
1917.Ar str
1918to the variable.
1919.It Cm \&::!= Ns Ar cmd
1920Assign the output of
1921.Ar cmd
1922to the variable.
1923.It Cm \&:\&[ Ns Ar range Ns Cm \&]
1924Selects one or more words from the value,
1925or performs other operations related to the way in which the
1926value is split into words.
1927.Pp
1928An empty value, or a value that consists entirely of white-space,
1929is treated as a single word.
1930For the purposes of the
1931.Sq Cm \&:[]
1932modifier, the words are indexed both forwards using positive integers
1933(where index 1 represents the first word),
1934and backwards using negative integers
1935(where index \-1 represents the last word).
1936.Pp
1937The
1938.Ar range
1939is subjected to variable expansion, and the expanded result is
1940then interpreted as follows:
1941.Bl -tag -width index
1942.\" :[n]
1943.It Ar index
1944Selects a single word from the value.
1945.\" :[start..end]
1946.It Ar start Ns Cm \&.. Ns Ar end
1947Selects all words from
1948.Ar start
1949to
1950.Ar end ,
1951inclusive.
1952For example,
1953.Sq Cm \&:[2..-1]
1954selects all words from the second word to the last word.
1955If
1956.Ar start
1957is greater than
1958.Ar end ,
1959the words are output in reverse order.
1960For example,
1961.Sq Cm \&:[-1..1]
1962selects all the words from last to first.
1963If the list is already ordered,
1964this effectively reverses the list,
1965but it is more efficient to use
1966.Sq Cm \&:Or
1967instead of
1968.Sq Cm \&:O:[-1..1] .
1969.\" :[*]
1970.It Cm \&*
1971Causes subsequent modifiers to treat the value as a single word
1972(possibly containing embedded whitespace).
1973Analogous to the effect of
1974.Li \&$*
1975in Bourne shell.
1976.\" :[0]
1977.It 0
1978Means the same as
1979.Sq Cm \&:[*] .
1980.\" :[*]
1981.It Cm \&@
1982Causes subsequent modifiers to treat the value as a sequence of words
1983delimited by whitespace.
1984Analogous to the effect of
1985.Li \&$@
1986in Bourne shell.
1987.\" :[#]
1988.It Cm \&#
1989Returns the number of words in the value.
1990.El \" :[range]
1991.El
1992.Sh DIRECTIVES
1993.Nm
1994offers directives for including makefiles, conditionals and for loops.
1995All these directives are identified by a line beginning with a single dot
1996.Pq Ql \&.
1997character, followed by the keyword of the directive, such as
1998.Cm include
1999or
2000.Cm if .
2001.Ss File inclusion
2002Files are included with either
2003.Cm \&.include \&< Ns Ar file Ns Cm \&>
2004or
2005.Cm \&.include \&\*q Ns Ar file Ns Cm \&\*q .
2006Variables between the angle brackets or double quotes are expanded
2007to form the file name.
2008If angle brackets are used, the included makefile is expected to be in
2009the system makefile directory.
2010If double quotes are used, the including makefile's directory and any
2011directories specified using the
2012.Fl I
2013option are searched before the system makefile directory.
2014.Pp
2015For compatibility with other make variants,
2016.Sq Cm include Ar file No ...
2017(without leading dot)
2018is also accepted.
2019.Pp
2020If the include statement is written as
2021.Cm .-include
2022or as
2023.Cm .sinclude ,
2024errors locating and/or opening include files are ignored.
2025.Pp
2026If the include statement is written as
2027.Cm .dinclude ,
2028not only are errors locating and/or opening include files ignored,
2029but stale dependencies within the included file are ignored just like in
2030.Va .MAKE.DEPENDFILE .
2031.Ss Exporting variables
2032The directives for exporting and unexporting variables are:
2033.Bl -tag -width Ds
2034.It Ic .export Ar variable No ...
2035Export the specified global variable.
2036.Pp
2037For compatibility with other make programs,
2038.Cm export Ar variable\| Ns Cm \&= Ns Ar value
2039(without leading dot) is also accepted.
2040.Pp
2041Appending a variable name to
2042.Va .MAKE.EXPORTED
2043is equivalent to exporting a variable.
2044.It Ic .export-all
2045Export all globals except for internal variables (those that start with
2046.Ql \&. ) .
2047This is not affected by the
2048.Fl X
2049flag, so should be used with caution.
2050.It Ic .export-env Ar variable No ...
2051The same as
2052.Ql .export ,
2053except that the variable is not appended to
2054.Va .MAKE.EXPORTED .
2055This allows exporting a value to the environment which is different from that
2056used by
2057.Nm
2058internally.
2059.It Ic .export-literal Ar variable No ...
2060The same as
2061.Ql .export-env ,
2062except that variables in the value are not expanded.
2063.It Ic .unexport Ar variable No ...
2064The opposite of
2065.Ql .export .
2066The specified global
2067.Ar variable
2068is removed from
2069.Va .MAKE.EXPORTED .
2070If no variable list is provided, all globals are unexported,
2071and
2072.Va .MAKE.EXPORTED
2073deleted.
2074.It Ic .unexport-env
2075Unexport all globals previously exported and
2076clear the environment inherited from the parent.
2077This operation causes a memory leak of the original environment,
2078so should be used sparingly.
2079Testing for
2080.Va .MAKE.LEVEL
2081being 0 would make sense.
2082Also note that any variables which originated in the parent environment
2083should be explicitly preserved if desired.
2084For example:
2085.Bd -literal -offset indent
2086.Li .if ${.MAKE.LEVEL} == 0
2087PATH := ${PATH}
2088.Li .unexport-env
2089.Li .export PATH
2090.Li .endif
2091.Pp
2092.Ed
2093Would result in an environment containing only
2094.Sq Ev PATH ,
2095which is the minimal useful environment.
2096.\" TODO: Check the below sentence, environment variables don't start with '.'.
2097Actually
2098.Sq Va .MAKE.LEVEL
2099is also pushed into the new environment.
2100.El
2101.Ss Messages
2102The directives for printing messages to the output are:
2103.Bl -tag -width Ds
2104.It Ic .info Ar message
2105The message is printed along with the name of the makefile and line number.
2106.It Ic .warning Ar message
2107The message prefixed by
2108.Sq Li warning:
2109is printed along with the name of the makefile and line number.
2110.It Ic .error Ar message
2111The message is printed along with the name of the makefile and line number,
2112.Nm
2113exits immediately.
2114.El
2115.Ss Conditionals
2116The directives for conditionals are:
2117.ds maybenot Oo Ic \&! Oc Ns
2118.Bl -tag
2119.It Ic .if \*[maybenot] Ar expression Op Ar operator expression No ...
2120Test the value of an expression.
2121.It Ic .ifdef \*[maybenot] Ar variable Op Ar operator variable No ...
2122Test whether a variable is defined.
2123.It Ic .ifndef \*[maybenot] Ar variable Op Ar operator variable No ...
2124Test whether a variable is not defined.
2125.It Ic .ifmake \*[maybenot] Ar target Op Ar operator target No ...
2126Test the target being requested.
2127.It Ic .ifnmake \*[maybenot] Ar target Op Ar operator target No ...
2128Test the target being requested.
2129.It Ic .else
2130Reverse the sense of the last conditional.
2131.It Ic .elif \*[maybenot] Ar expression Op Ar operator expression No ...
2132A combination of
2133.Sq Ic .else
2134followed by
2135.Sq Ic .if .
2136.It Ic .elifdef \*[maybenot] Ar variable Op Ar operator variable No ...
2137A combination of
2138.Sq Ic .else
2139followed by
2140.Sq Ic .ifdef .
2141.It Ic .elifndef \*[maybenot] Ar variable Op Ar operator variable No ...
2142A combination of
2143.Sq Ic .else
2144followed by
2145.Sq Ic .ifndef .
2146.It Ic .elifmake \*[maybenot] Ar target Op Ar operator target No ...
2147A combination of
2148.Sq Ic .else
2149followed by
2150.Sq Ic .ifmake .
2151.It Ic .elifnmake \*[maybenot] Ar target Op Ar operator target No ...
2152A combination of
2153.Sq Ic .else
2154followed by
2155.Sq Ic .ifnmake .
2156.It Ic .endif
2157End the body of the conditional.
2158.El
2159.Pp
2160The
2161.Ar operator
2162may be any one of the following:
2163.Bl -tag
2164.It Ic \&|\&|
2165Logical OR.
2166.It Ic \&&&
2167Logical AND; of higher precedence than
2168.Sq Ic \&|\&| .
2169.El
2170.Pp
2171.Nm
2172only evaluates a conditional as far as is necessary to determine its value.
2173Parentheses can be used to override the operator precedence.
2174The boolean operator
2175.Sq Ic \&!
2176may be used to logically negate an expression, typically a function call.
2177It is of higher precedence than
2178.Sq Ic \&&& .
2179.Pp
2180The value of
2181.Ar expression
2182may be any of the following function call expressions:
2183.Bl -tag
2184.Sm off
2185.It Ic defined Li \&( Ar varname Li \&)
2186.Sm on
2187Evaluates to true if the variable
2188.Ar varname
2189has been defined.
2190.Sm off
2191.It Ic make Li \&( Ar target Li \&)
2192.Sm on
2193Evaluates to true if the target was specified as part of
2194.Nm Ns 's
2195command line or was declared the default target (either implicitly or
2196explicitly, see
2197.Va .MAIN )
2198before the line containing the conditional.
2199.Sm off
2200.It Ic empty Li \&( Ar varname Oo Li : Ar modifiers Oc Li \&)
2201.Sm on
2202Evaluates to true if the expansion of the variable,
2203after applying the modifiers, results in an empty string.
2204.Sm off
2205.It Ic exists Li \&( Ar pathname Li \&)
2206.Sm on
2207Evaluates to true if the given pathname exists.
2208If relative, the pathname is searched for on the system search path (see
2209.Va .PATH ) .
2210.Sm off
2211.It Ic target Li \&( Ar target Li \&)
2212.Sm on
2213Evaluates to true if the target has been defined.
2214.Sm off
2215.It Ic commands Li \&( Ar target Li \&)
2216.Sm on
2217Evaluates to true if the target has been defined
2218and has commands associated with it.
2219.El
2220.Pp
2221.Ar Expression
2222may also be an arithmetic or string comparison.
2223Variable expansion is performed on both sides of the comparison.
2224If both sides are numeric and neither is enclosed in quotes,
2225the comparison is done numerically, otherwise lexicographically.
2226A string is interpreted as a hexadecimal integer if it is preceded by
2227.Li 0x ,
2228otherwise it is interpreted as a decimal floating-point number;
2229octal numbers are not supported.
2230.Pp
2231All comparisons may use the operators
2232.Sq Ic \&==
2233and
2234.Sq Ic \&!= .
2235Numeric comparisons may also use the operators
2236.Sq Ic \&< ,
2237.Sq Ic \&<= ,
2238.Sq Ic \&>
2239and
2240.Sq Ic \&>= .
2241.Pp
2242If the comparison has neither a comparison operator nor a right side,
2243the expression evaluates to true if it is nonempty
2244and its numeric value (if any) is not zero.
2245.Pp
2246When
2247.Nm
2248is evaluating one of these conditional expressions, and it encounters
2249a (whitespace-separated) word it doesn't recognize, either the
2250.Dq make
2251or
2252.Dq defined
2253function is applied to it, depending on the form of the conditional.
2254If the form is
2255.Sq Ic .ifdef ,
2256.Sq Ic .ifndef
2257or
2258.Sq Ic .if ,
2259the
2260.Dq defined
2261function is applied.
2262Similarly, if the form is
2263.Sq Ic .ifmake
2264or
2265.Sq Ic .ifnmake ,
2266the
2267.Dq make
2268function is applied.
2269.Pp
2270If the conditional evaluates to true,
2271parsing of the makefile continues as before.
2272If it evaluates to false, the following lines until the corresponding
2273.Sq Ic .elif
2274variant,
2275.Sq Ic .else
2276or
2277.Sq Ic .endif
2278are skipped.
2279.Ss For loops
2280For loops are typically used to apply a set of rules to a list of files.
2281The syntax of a for loop is:
2282.Pp
2283.Bl -tag -compact -width Ds
2284.It Ic \&.for Ar variable Oo Ar variable No ... Oc Ic in Ar expression
2285.It Aq Ar make-lines
2286.It Ic \&.endfor
2287.El
2288.Pp
2289The
2290.Ar expression
2291is expanded and then split into words.
2292On each iteration of the loop, one word is taken and assigned to each
2293.Ar variable ,
2294in order, and these
2295.Ar variables
2296are substituted into the
2297.Ar make-lines
2298inside the body of the for loop.
2299The number of words must come out even; that is, if there are three
2300iteration variables, the number of words provided must be a multiple
2301of three.
2302.Pp
2303If
2304.Sq Ic .break
2305is encountered within a
2306.Cm \&.for
2307loop, it causes early termination of the loop, otherwise a parse error.
2308.\" TODO: Describe limitations with defined/empty.
2309.Ss Other directives
2310.Bl -tag -width Ds
2311.It Ic .undef Ar variable No ...
2312Un-define the specified global variables.
2313Only global variables can be un-defined.
2314.El
2315.Sh COMMENTS
2316Comments begin with a hash
2317.Pq Ql \&#
2318character, anywhere but in a shell
2319command line, and continue to the end of an unescaped new line.
2320.Sh SPECIAL SOURCES (ATTRIBUTES)
2321.Bl -tag -width .IGNOREx
2322.It Ic .EXEC
2323Target is never out of date, but always execute commands anyway.
2324.It Ic .IGNORE
2325Ignore any errors from the commands associated with this target, exactly
2326as if they all were preceded by a dash
2327.Pq Ql \- .
2328.\" .It Ic .INVISIBLE
2329.\" XXX
2330.\" .It Ic .JOIN
2331.\" XXX
2332.It Ic .MADE
2333Mark all sources of this target as being up to date.
2334.It Ic .MAKE
2335Execute the commands associated with this target even if the
2336.Fl n
2337or
2338.Fl t
2339options were specified.
2340Normally used to mark recursive
2341.Nm Ns s .
2342.It Ic .META
2343Create a meta file for the target, even if it is flagged as
2344.Ic .PHONY ,
2345.Ic .MAKE ,
2346or
2347.Ic .SPECIAL .
2348Usage in conjunction with
2349.Ic .MAKE
2350is the most likely case.
2351In
2352.Dq meta
2353mode, the target is out-of-date if the meta file is missing.
2354.It Ic .NOMETA
2355Do not create a meta file for the target.
2356Meta files are also not created for
2357.Ic .PHONY ,
2358.Ic .MAKE ,
2359or
2360.Ic .SPECIAL
2361targets.
2362.It Ic .NOMETA_CMP
2363Ignore differences in commands when deciding if target is out of date.
2364This is useful if the command contains a value which always changes.
2365If the number of commands change, though,
2366the target is still considered out of date.
2367The same effect applies to any command line that uses the variable
2368.Va .OODATE ,
2369which can be used for that purpose even when not otherwise needed or desired:
2370.Bd -literal -offset indent
2371
2372skip-compare-for-some:
2373	@echo this is compared
2374	@echo this is not ${.OODATE:M.NOMETA_CMP}
2375	@echo this is also compared
2376
2377.Ed
2378The
2379.Cm \&:M
2380pattern suppresses any expansion of the unwanted variable.
2381.It Ic .NOPATH
2382Do not search for the target in the directories specified by
2383.Va .PATH .
2384.It Ic .NOTMAIN
2385Normally
2386.Nm
2387selects the first target it encounters as the default target to be built
2388if no target was specified.
2389This source prevents this target from being selected.
2390.It Ic .OPTIONAL
2391If a target is marked with this attribute and
2392.Nm
2393can't figure out how to create it, it ignores this fact and assumes
2394the file isn't needed or already exists.
2395.It Ic .PHONY
2396The target does not correspond to an actual file;
2397it is always considered to be out of date,
2398and is not created with the
2399.Fl t
2400option.
2401Suffix-transformation rules are not applied to
2402.Ic .PHONY
2403targets.
2404.It Ic .PRECIOUS
2405When
2406.Nm
2407is interrupted, it normally removes any partially made targets.
2408This source prevents the target from being removed.
2409.It Ic .RECURSIVE
2410Synonym for
2411.Ic .MAKE .
2412.It Ic .SILENT
2413Do not echo any of the commands associated with this target, exactly
2414as if they all were preceded by an at sign
2415.Pq Ql @ .
2416.It Ic .USE
2417Turn the target into
2418.Nm Ns 's
2419version of a macro.
2420When the target is used as a source for another target, the other target
2421acquires the commands, sources, and attributes (except for
2422.Ic .USE )
2423of the
2424source.
2425If the target already has commands, the
2426.Ic .USE
2427target's commands are appended
2428to them.
2429.It Ic .USEBEFORE
2430Like
2431.Ic .USE ,
2432but instead of appending, prepend the
2433.Ic .USEBEFORE
2434target commands to the target.
2435.It Ic .WAIT
2436If
2437.Ic .WAIT
2438appears in a dependency line, the sources that precede it are
2439made before the sources that succeed it in the line.
2440Since the dependents of files are not made until the file itself
2441could be made, this also stops the dependents being built unless they
2442are needed for another branch of the dependency tree.
2443So given:
2444.Bd -literal
2445x: a .WAIT b
2446	echo x
2447a:
2448	echo a
2449b: b1
2450	echo b
2451b1:
2452	echo b1
2453
2454.Ed
2455the output is always
2456.Ql a ,
2457.Ql b1 ,
2458.Ql b ,
2459.Ql x .
2460.Pp
2461The ordering imposed by
2462.Ic .WAIT
2463is only relevant for parallel makes.
2464.El
2465.Sh SPECIAL TARGETS
2466Special targets may not be included with other targets, i.e. they must be
2467the only target specified.
2468.Bl -tag -width .BEGINx
2469.It Ic .BEGIN
2470Any command lines attached to this target are executed before anything
2471else is done.
2472.It Ic .DEFAULT
2473This is sort of a
2474.Ic .USE
2475rule for any target (that was used only as a source) that
2476.Nm
2477can't figure out any other way to create.
2478Only the shell script is used.
2479The
2480.Va .IMPSRC
2481variable of a target that inherits
2482.Ic .DEFAULT Ns 's
2483commands is set to the target's own name.
2484.It Ic .DELETE_ON_ERROR
2485If this target is present in the makefile, it globally causes make to
2486delete targets whose commands fail.
2487(By default, only targets whose commands are interrupted during
2488execution are deleted.
2489This is the historical behavior.)
2490This setting can be used to help prevent half-finished or malformed
2491targets from being left around and corrupting future rebuilds.
2492.It Ic .END
2493Any command lines attached to this target are executed after everything
2494else is done successfully.
2495.It Ic .ERROR
2496Any command lines attached to this target are executed when another target fails.
2497See
2498.Va MAKE_PRINT_VAR_ON_ERROR
2499for the variables that will be set.
2500.It Ic .IGNORE
2501Mark each of the sources with the
2502.Ic .IGNORE
2503attribute.
2504If no sources are specified, this is the equivalent of specifying the
2505.Fl i
2506option.
2507.It Ic .INTERRUPT
2508If
2509.Nm
2510is interrupted, the commands for this target are executed.
2511.It Ic .MAIN
2512If no target is specified when
2513.Nm
2514is invoked, this target is built.
2515.It Ic .MAKEFLAGS
2516This target provides a way to specify flags for
2517.Nm
2518at the time when the makefiles are read.
2519The flags are as if typed to the shell, though the
2520.Fl f
2521option has
2522no effect.
2523.\" XXX: NOT YET!!!!
2524.\" .It Ic .NOTPARALLEL
2525.\" The named targets are executed in non parallel mode.
2526.\" If no targets are
2527.\" specified, all targets are executed in non parallel mode.
2528.It Ic .NOPATH
2529Apply the
2530.Ic .NOPATH
2531attribute to any specified sources.
2532.It Ic .NOTPARALLEL
2533Disable parallel mode.
2534.It Ic .NO_PARALLEL
2535Synonym for
2536.Ic .NOTPARALLEL ,
2537for compatibility with other pmake variants.
2538.It Ic .NOREADONLY
2539clear the read-only attribute from the global variables specified as sources.
2540.It Ic .OBJDIR
2541The source is a new value for
2542.Sq Va .OBJDIR .
2543If it exists,
2544.Nm
2545changes the current working directory to it and updates the value of
2546.Sq Va .OBJDIR .
2547.It Ic .ORDER
2548In parallel mode, the named targets are made in sequence.
2549This ordering does not add targets to the list of targets to be made.
2550.Pp
2551Since the dependents of a target do not get built until the target itself
2552could be built, unless
2553.Ql a
2554is built by another part of the dependency graph,
2555the following is a dependency loop:
2556.Bd -literal
2557\&.ORDER: b a
2558b: a
2559.Ed
2560.Pp
2561.\" XXX: NOT YET!!!!
2562.\" .It Ic .PARALLEL
2563.\" The named targets are executed in parallel mode.
2564.\" If no targets are
2565.\" specified, all targets are executed in parallel mode.
2566.It Ic .PATH
2567The sources are directories which are to be searched for files not
2568found in the current directory.
2569If no sources are specified,
2570any previously specified directories are removed from the search path.
2571If the source is the special
2572.Ic .DOTLAST
2573target, the current working directory is searched last.
2574.It Ic .PATH. Ns Ar suffix
2575Like
2576.Ic .PATH
2577but applies only to files with a particular suffix.
2578The suffix must have been previously declared with
2579.Ic .SUFFIXES .
2580.It Ic .PHONY
2581Apply the
2582.Ic .PHONY
2583attribute to any specified sources.
2584.It Ic .POSIX
2585If this is the first non-comment line in the main makefile,
2586the variable
2587.Va %POSIX
2588is set to the value
2589.Ql 1003.2
2590and the makefile
2591.Ql <posix.mk>
2592is included if it exists,
2593to provide POSIX-compatible default rules.
2594If
2595.Nm
2596is run with the
2597.Fl r
2598flag, only
2599.Ql posix.mk
2600contributes to the default rules.
2601In POSIX-compatible mode, the AT&T System V UNIX style substitution
2602modifier is checked first rather than as a fallback.
2603.It Ic .PRECIOUS
2604Apply the
2605.Ic .PRECIOUS
2606attribute to any specified sources.
2607If no sources are specified, the
2608.Ic .PRECIOUS
2609attribute is applied to every target in the file.
2610.It Ic .READONLY
2611set the read-only attribute on the global variables specified as sources.
2612.It Ic .SHELL
2613Sets the shell that
2614.Nm
2615uses to execute commands.
2616The sources are a set of
2617.Ar field\| Ns Cm \&= Ns Ar value
2618pairs.
2619.Bl -tag -width ".Li hasErrCtls"
2620.It Li name
2621This is the minimal specification, used to select one of the built-in
2622shell specs;
2623.Li sh ,
2624.Li ksh ,
2625and
2626.Li csh .
2627.It Li path
2628Specifies the absolute path to the shell.
2629.It Li hasErrCtl
2630Indicates whether the shell supports exit on error.
2631.It Li check
2632The command to turn on error checking.
2633.It Li ignore
2634The command to disable error checking.
2635.It Li echo
2636The command to turn on echoing of commands executed.
2637.It Li quiet
2638The command to turn off echoing of commands executed.
2639.It Li filter
2640The output to filter after issuing the
2641.Li quiet
2642command.
2643It is typically identical to
2644.Li quiet .
2645.It Li errFlag
2646The flag to pass the shell to enable error checking.
2647.It Li echoFlag
2648The flag to pass the shell to enable command echoing.
2649.It Li newline
2650The string literal to pass the shell that results in a single newline
2651character when used outside of any quoting characters.
2652.El
2653Example:
2654.Bd -literal
2655\&.SHELL: name=ksh path=/bin/ksh hasErrCtl=true \e
2656	check="set \-e" ignore="set +e" \e
2657	echo="set \-v" quiet="set +v" filter="set +v" \e
2658	echoFlag=v errFlag=e newline="'\en'"
2659.Ed
2660.It Ic .SILENT
2661Apply the
2662.Ic .SILENT
2663attribute to any specified sources.
2664If no sources are specified, the
2665.Ic .SILENT
2666attribute is applied to every
2667command in the file.
2668.It Ic .STALE
2669This target gets run when a dependency file contains stale entries, having
2670.Va .ALLSRC
2671set to the name of that dependency file.
2672.It Ic .SUFFIXES
2673Each source specifies a suffix to
2674.Nm .
2675If no sources are specified, any previously specified suffixes are deleted.
2676It allows the creation of suffix-transformation rules.
2677.Pp
2678Example:
2679.Bd -literal
2680\&.SUFFIXES: .c .o
2681\&.c.o:
2682	cc \-o ${.TARGET} \-c ${.IMPSRC}
2683.Ed
2684.It Ic .SYSPATH
2685The sources are directories which are to be added to the system
2686include path which
2687.Nm
2688searches for makefiles.
2689If no sources are specified,
2690any previously specified directories are removed from the system
2691include path.
2692.El
2693.Sh ENVIRONMENT
2694.Nm
2695uses the following environment variables, if they exist:
2696.Ev MACHINE ,
2697.Ev MACHINE_ARCH ,
2698.Ev MAKE ,
2699.Ev MAKEFLAGS ,
2700.Ev MAKEOBJDIR ,
2701.Ev MAKEOBJDIRPREFIX ,
2702.Ev MAKESYSPATH ,
2703.Ev MAKE_STACK_TRACE ,
2704.Ev PWD ,
2705and
2706.Ev TMPDIR .
2707.Pp
2708.Ev MAKEOBJDIRPREFIX
2709and
2710.Ev MAKEOBJDIR
2711should be set in the environment or on the command line to
2712.Nm
2713and not as makefile variables;
2714see the description of
2715.Sq Va .OBJDIR
2716for more details.
2717It is possible to set these via makefile variables but unless done
2718very early and the
2719.Sq Ic .OBJDIR
2720target is used to reset
2721.Sq Va .OBJDIR ,
2722there may be unexpected side effects.
2723.Pp
2724If the
2725.Ev MAKE_STACK_TRACE
2726environment variable is set to
2727.Dq yes ,
2728any stack traces include the call chain of the parent processes.
2729.\" .Sh EXIT STATUS
2730.\" .Sh ENVIRONMENT
2731.Sh FILES
2732.Bl -tag -width /usr/share/mk -compact
2733.It .depend
2734list of dependencies
2735.It makefile
2736first default makefile if no makefile is specified on the command line
2737.It Makefile
2738second default makefile if no makefile is specified on the command line
2739.It sys.mk
2740system makefile
2741.It /usr/share/mk
2742system makefile directory
2743.El
2744.\" .Sh EXAMPLES
2745.Sh DIAGNOSTICS
2746.Bl -tag
2747.It Dv Invalid internal option \(dq-J\(dq in \(dq Ns Ar directory Ns Dv \(dq
2748The internal
2749.Fl J
2750option coordinates the main
2751.Nm
2752process with the sub-make processes to limit
2753the number of jobs that run in parallel.
2754The option is passed to all child processes via the
2755.Ev MAKEFLAGS
2756environment variable.
2757To become valid,
2758this option requires that the target running the sub-make is marked with the
2759.Dv .MAKE
2760special source,
2761or that one of the target's commands directly contains the word
2762.Dq make
2763or one of the expressions
2764.Dq ${MAKE} ,
2765.Dq ${.MAKE} ,
2766.Dq $(MAKE) ,
2767.Dq $(.MAKE) .
2768If that's not the case,
2769make issues the above warning and falls back to compat mode.
2770.Pp
2771To see the chain of sub-makes that leads to the invalid option, set the
2772.Ev MAKE_STACK_TRACE
2773environment variable to
2774.Dq yes .
2775.Pp
2776To run the sub-make in parallel mode, even in dry-run mode (see the
2777.Fl n
2778option), add the
2779.Dv .MAKE
2780pseudo source to the target.
2781This is appropriate when the sub-make runs the same target in a subdirectory.
2782.Pp
2783To run the sub-make in parallel mode but not in dry-mode,
2784add a
2785.Dq ${:D make}
2786marker to one of the target's commands.
2787This marker expands to an empty string
2788and thus does not affect the executed commands.
2789.\" The marker can even be added before any of the "@+-" modifiers,
2790.\" so no need to mention this explicitly.
2791.Pp
2792To run the sub-make in compat mode, add the
2793.Fl B
2794option to its invocation.
2795This is appropriate when the sub-make is only used to print a variable's
2796value using the
2797.Fl v
2798or
2799.Fl V
2800options.
2801.Pp
2802To make the sub-make independent from the parent make, unset the
2803.Ev MAKEFLAGS
2804environment variable in the target's commands.
2805.El
2806.Sh COMPATIBILITY
2807The basic make syntax is compatible between different make variants;
2808however the special variables, variable modifiers and conditionals are not.
2809.Ss Older versions
2810An incomplete list of changes in older versions of
2811.Nm :
2812.Pp
2813The way that .for loop variables are substituted changed after
2814.Nx 5.0
2815so that they still appear to be variable expansions.
2816In particular this stops them being treated as syntax, and removes some
2817obscure problems using them in .if statements.
2818.Pp
2819The way that parallel makes are scheduled changed in
2820.Nx 4.0
2821so that .ORDER and .WAIT apply recursively to the dependent nodes.
2822The algorithms used may change again in the future.
2823.Ss Other make dialects
2824Other make dialects (GNU make, SVR4 make, POSIX make, etc.) do not
2825support most of the features of
2826.Nm
2827as described in this manual.
2828Most notably:
2829.Bl -bullet -offset indent
2830.It
2831The
2832.Ic .WAIT
2833and
2834.Ic .ORDER
2835declarations and most functionality pertaining to parallelization.
2836(GNU make supports parallelization but lacks the features needed to
2837control it effectively.)
2838.It
2839Directives, including for loops and conditionals and most of the
2840forms of include files.
2841(GNU make has its own incompatible and less powerful syntax for
2842conditionals.)
2843.\" The "less powerful" above means that GNU make does not have the
2844.\" make(target), target(target) and commands(target) functions.
2845.It
2846All built-in variables that begin with a dot.
2847.It
2848Most of the special sources and targets that begin with a dot,
2849with the notable exception of
2850.Ic .PHONY ,
2851.Ic .PRECIOUS ,
2852and
2853.Ic .SUFFIXES .
2854.It
2855Variable modifiers, except for the
2856.Ql :old=new
2857string substitution, which does not portably support globbing with
2858.Ql %
2859and historically only works on declared suffixes.
2860.It
2861The
2862.Ic $>
2863variable even in its short form; most makes support this functionality
2864but its name varies.
2865.El
2866.Pp
2867Some features are somewhat more portable, such as assignment with
2868.Ic += ,
2869.Ic ?= ,
2870and
2871.Ic != .
2872The
2873.Va .PATH
2874functionality is based on an older feature
2875.Ic VPATH
2876found in GNU make and many versions of SVR4 make; however,
2877historically its behavior is too ill-defined (and too buggy) to rely
2878upon.
2879.Pp
2880The
2881.Ic $@
2882and
2883.Ic $<
2884variables are more or less universally portable, as is the
2885.Ic $(MAKE)
2886variable.
2887Basic use of suffix rules (for files only in the current directory,
2888not trying to chain transformations together, etc.) is also reasonably
2889portable.
2890.Sh SEE ALSO
2891.Xr mkdep 1
2892.\" .Sh STANDARDS
2893.Sh HISTORY
2894.Nm
2895is derived from NetBSD
2896.Xr make 1 .
2897It uses autoconf to facilitate portability to other platforms.
2898.Pp
2899A
2900make
2901command appeared in
2902.At v7 .
2903This
2904make
2905implementation is based on Adam de Boor's pmake program,
2906which was written for Sprite at Berkeley.
2907It was designed to be a parallel distributed make running jobs on different
2908machines using a daemon called
2909.Dq customs .
2910.Pp
2911Historically the target/dependency
2912.Ic FRC
2913has been used to FoRCe rebuilding (since the target/dependency
2914does not exist ... unless someone creates an
2915.Pa FRC
2916file).
2917.\" .Sh AUTHORS
2918.\" .Sh CAVEATS
2919.Sh BUGS
2920The
2921.Nm
2922syntax is difficult to parse.
2923For instance, finding the end of a variable's use should involve scanning
2924each of the modifiers, using the correct terminator for each field.
2925In many places
2926.Nm
2927just counts {} and () in order to find the end of a variable expansion.
2928.Pp
2929There is no way of escaping a space character in a filename.
2930.Pp
2931In jobs mode, when a target fails;
2932.Nm
2933will put an error token into the job token pool.
2934This will cause all other instances of
2935.Nm
2936using that token pool to abort the build and exit with error code 6.
2937Sometimes the attempt to suppress a cascade of unnecessary errors,
2938can result in a seemingly unexplained
2939.Ql *** Error code 6
2940.\" .Sh SECURITY CONSIDERATIONS
2941