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