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