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