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