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