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