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