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