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