xref: /netbsd-src/usr.bin/make/make.1 (revision 28ef056fc275729e9327322d9102bc5d9934cf36)
1.\"	$NetBSD: make.1,v 1.167 2010/02/22 19:20:33 joerg 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 15, 2009
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 BeikNnqrstWX
41.Bk -words
42.Op Fl C Ar directory
43.Ek
44.Bk -words
45.Op Fl D Ar variable
46.Ek
47.Bk -words
48.Op Fl d Ar flags
49.Ek
50.Bk -words
51.Op Fl f Ar makefile
52.Ek
53.Bk -words
54.Op Fl I Ar directory
55.Ek
56.Bk -words
57.Op Fl J Ar private
58.Ek
59.Bk -words
60.Op Fl j Ar max_jobs
61.Ek
62.Bk -words
63.Op Fl m Ar directory
64.Ek
65.Bk -words
66.Op Fl T Ar file
67.Ek
68.Bk -words
69.Op Fl V Ar variable
70.Ek
71.Op Ar variable=value
72.Bk -words
73.Op Ar target ...
74.Ek
75.Sh DESCRIPTION
76.Nm
77is a program designed to simplify the maintenance of other programs.
78Its input is a list of specifications as to the files upon which programs
79and other files depend.
80If no
81.Fl f Ar makefile
82makefile option is given,
83.Nm
84will try to open
85.Ql Pa makefile
86then
87.Ql Pa Makefile
88in order to find the specifications.
89If the file
90.Ql Pa .depend
91exists, it is read (see
92.Xr mkdep 1 ) .
93.Pp
94This manual page is intended as a reference document only.
95For a more thorough description of
96.Nm
97and makefiles, please refer to
98.%T "Make \- A Tutorial" .
99.Pp
100.Nm
101will prepend the contents of the
102.Va MAKEFLAGS
103environment variable to the command line arguments before parsing them.
104.Pp
105The options are as follows:
106.Bl -tag -width Ds
107.It Fl B
108Try to be backwards compatible by executing a single shell per command and
109by executing the commands to make the sources of a dependency line in sequence.
110.It Fl C Ar directory
111Change to
112.Ar directory
113before reading the makefiles or doing anything else.
114If multiple
115.Fl C
116options are specified, each is interpreted relative to the previous one:
117.Fl C Pa / Fl C Pa etc
118is equivalent to
119.Fl C Pa /etc .
120.It Fl D Ar variable
121Define
122.Ar variable
123to be 1, in the global context.
124.It Fl d Ar [-]flags
125Turn on debugging, and specify which portions of
126.Nm
127are to print debugging information.
128Unless the flags are preceded by
129.Ql -
130they are added to the
131.Va MAKEFLAGS
132environment variable and will be processed by any child make processes.
133By default, debugging information is printed to standard error,
134but this can be changed using the
135.Ar F
136debugging flag.
137The debugging output is always unbuffered; in addition, if debugging
138is enabled but debugging output is not directed to standard output,
139then the standard output is line buffered.
140.Ar Flags
141is one or more of the following:
142.Bl -tag -width Ds
143.It Ar A
144Print all possible debugging information;
145equivalent to specifying all of the debugging flags.
146.It Ar a
147Print debugging information about archive searching and caching.
148.It Ar C
149Print debugging information about current working directory.
150.It Ar c
151Print debugging information about conditional evaluation.
152.It Ar d
153Print debugging information about directory searching and caching.
154.It Ar e
155Print debugging information about failed commands and targets.
156.It Ar F Ns Oo Sy \&+ Oc Ns Ar filename
157Specify where debugging output is written.
158This must be the last flag, because it consumes the remainder of
159the argument.
160If the character immediately after the
161.Ql F
162flag is
163.Ql \&+ ,
164then the file will be opened in append mode;
165otherwise the file will be overwritten.
166If the file name is
167.Ql stdout
168or
169.Ql stderr
170then debugging output will be written to the
171standard output or standard error output file descriptors respectively
172(and the
173.Ql \&+
174option has no effect).
175Otherwise, the output will be written to the named file.
176If the file name ends
177.Ql .%d
178then the
179.Ql %d
180is replaced by the pid.
181.It Ar f
182Print debugging information about loop evaluation.
183.It Ar "g1"
184Print the input graph before making anything.
185.It Ar "g2"
186Print the input graph after making everything, or before exiting
187on error.
188.It Ar "g3"
189Print the input graph before exiting on error.
190.It Ar j
191Print debugging information about running multiple shells.
192.It Ar l
193Print commands in Makefiles regardless of whether or not they are prefixed by
194.Ql @
195or other "quiet" flags.
196Also known as "loud" behavior.
197.It Ar m
198Print debugging information about making targets, including modification
199dates.
200.It Ar n
201Don't delete the temporary command scripts created when running commands.
202These temporary scripts are created in the directory
203referred to by the
204.Ev TMPDIR
205environment variable, or in
206.Pa /tmp
207if
208.Ev TMPDIR
209is unset or set to the empty string.
210The temporary scripts are created by
211.Xr mkstemp 3 ,
212and have names of the form
213.Pa makeXXXXXX .
214.Em NOTE :
215This can create many files in
216.Ev TMPDIR
217or
218.Pa /tmp ,
219so use with care.
220.It Ar p
221Print debugging information about makefile parsing.
222.It Ar s
223Print debugging information about suffix-transformation rules.
224.It Ar t
225Print debugging information about target list maintenance.
226.It Ar v
227Print debugging information about variable assignment.
228.It Ar x
229Run shell commands with
230.Fl x
231so the actual commands are printed as they are executed.
232.El
233.It Fl e
234Specify that environment variables override macro assignments within
235makefiles.
236.It Fl f Ar makefile
237Specify a makefile to read instead of the default
238.Ql Pa makefile .
239If
240.Ar makefile
241is
242.Ql Fl ,
243standard input is read.
244Multiple makefiles may be specified, and are read in the order specified.
245.It Fl I Ar directory
246Specify a directory in which to search for makefiles and included makefiles.
247The system makefile directory (or directories, see the
248.Fl m
249option) is automatically included as part of this list.
250.It Fl i
251Ignore non-zero exit of shell commands in the makefile.
252Equivalent to specifying
253.Ql Fl
254before each command line in the makefile.
255.It Fl J Ar private
256This option should
257.Em not
258be specified by the user.
259.Pp
260When the
261.Ar j
262option is in use in a recursive build, this option is passed by a make
263to child makes to allow all the make processes in the build to
264cooperate to avoid overloading the system.
265.It Fl j Ar max_jobs
266Specify the maximum number of jobs that
267.Nm
268may have running at any one time.
269Turns compatibility mode off, unless the
270.Ar B
271flag is also specified.
272When compatibility mode is off, all commands associated with a
273target are executed in a single shell invocation as opposed to the
274traditional one shell invocation per line.
275This can break traditional scripts which change directories on each
276command invocation and then expect to start with a fresh environment
277on the next line.
278It is more efficient to correct the scripts rather than turn backwards
279compatibility on.
280.It Fl k
281Continue processing after errors are encountered, but only on those targets
282that do not depend on the target whose creation caused the error.
283.It Fl m Ar directory
284Specify a directory in which to search for sys.mk and makefiles included
285via the
286.Ao Ar file Ac Ns -style
287include statement.
288The
289.Fl m
290option can be used multiple times to form a search path.
291This path will override the default system include path: /usr/share/mk.
292Furthermore the system include path will be appended to the search path used
293for
294.Qo Ar file Qc Ns -style
295include statements (see the
296.Fl I
297option).
298.Pp
299If a file or directory name in the
300.Fl m
301argument (or the
302.Ev MAKESYSPATH
303environment variable) starts with the string
304.Qq \&.../
305then
306.Nm
307will search for the specified file or directory named in the remaining part
308of the argument string.
309The search starts with the current directory of
310the Makefile and then works upward towards the root of the filesystem.
311If the search is successful, then the resulting directory replaces the
312.Qq \&.../
313specification in the
314.Fl m
315argument.
316If used, this feature allows
317.Nm
318to easily search in the current source tree for customized sys.mk files
319(e.g., by using
320.Qq \&.../mk/sys.mk
321as an argument).
322.It Fl n
323Display the commands that would have been executed, but do not
324actually execute them unless the target depends on the .MAKE special
325source (see below).
326.It Fl N
327Display the commands which would have been executed, but do not
328actually execute any of them; useful for debugging top-level makefiles
329without descending into subdirectories.
330.It Fl q
331Do not execute any commands, but exit 0 if the specified targets are
332up-to-date and 1, otherwise.
333.It Fl r
334Do not use the built-in rules specified in the system makefile.
335.It Fl s
336Do not echo any commands as they are executed.
337Equivalent to specifying
338.Ql Ic @
339before each command line in the makefile.
340.It Fl T Ar tracefile
341When used with the
342.Fl j
343flag,
344append a trace record to
345.Ar tracefile
346for each job started and completed.
347.It Fl t
348Rather than re-building a target as specified in the makefile, create it
349or update its modification time to make it appear up-to-date.
350.It Fl V Ar variable
351Print
352.Nm Ns 's
353idea of the value of
354.Ar variable ,
355in the global context.
356Do not build any targets.
357Multiple instances of this option may be specified;
358the variables will be printed one per line,
359with a blank line for each null or undefined variable.
360If
361.Ar variable
362contains a
363.Ql \&$
364then the value will be expanded before printing.
365.It Fl W
366Treat any warnings during makefile parsing as errors.
367.It Fl X
368Don't export variables passed on the command line to the environment
369individually.
370Variables passed on the command line are still exported
371via the
372.Va MAKEFLAGS
373environment variable.
374This option may be useful on systems which have a small limit on the
375size of command arguments.
376.It Ar variable=value
377Set the value of the variable
378.Ar variable
379to
380.Ar value .
381Normally, all values passed on the command line are also exported to
382sub-makes in the environment.
383The
384.Fl X
385flag disables this behavior.
386Variable assignments should follow options for POSIX compatibility
387but no ordering is enforced.
388.El
389.Pp
390There are seven different types of lines in a makefile: file dependency
391specifications, shell commands, variable assignments, include statements,
392conditional directives, for loops, and comments.
393.Pp
394In general, lines may be continued from one line to the next by ending
395them with a backslash
396.Pq Ql \e .
397The trailing newline character and initial whitespace on the following
398line are compressed into a single space.
399.Sh FILE DEPENDENCY SPECIFICATIONS
400Dependency lines consist of one or more targets, an operator, and zero
401or more sources.
402This creates a relationship where the targets
403.Dq depend
404on the sources
405and are usually created from them.
406The exact relationship between the target and the source is determined
407by the operator that separates them.
408The three operators are as follows:
409.Bl -tag -width flag
410.It Ic \&:
411A target is considered out-of-date if its modification time is less than
412those of any of its sources.
413Sources for a target accumulate over dependency lines when this operator
414is used.
415The target is removed if
416.Nm
417is interrupted.
418.It Ic \&!
419Targets are always re-created, but not until all sources have been
420examined and re-created as necessary.
421Sources for a target accumulate over dependency lines when this operator
422is used.
423The target is removed if
424.Nm
425is interrupted.
426.It Ic \&::
427If no sources are specified, the target is always re-created.
428Otherwise, a target is considered out-of-date if any of its sources has
429been modified more recently than the target.
430Sources for a target do not accumulate over dependency lines when this
431operator is used.
432The target will not be removed if
433.Nm
434is interrupted.
435.El
436.Pp
437Targets and sources may contain the shell wildcard values
438.Ql \&? ,
439.Ql * ,
440.Ql [] ,
441and
442.Ql {} .
443The values
444.Ql \&? ,
445.Ql * ,
446and
447.Ql []
448may only be used as part of the final
449component of the target or source, and must be used to describe existing
450files.
451The value
452.Ql {}
453need not necessarily be used to describe existing files.
454Expansion is in directory order, not alphabetically as done in the shell.
455.Sh SHELL COMMANDS
456Each target may have associated with it a series of shell commands, normally
457used to create the target.
458Each of the commands in this script
459.Em must
460be preceded by a tab.
461While any target may appear on a dependency line, only one of these
462dependencies may be followed by a creation script, unless the
463.Ql Ic \&::
464operator is used.
465.Pp
466If the first characters of the command line are any combination of
467.Ql Ic @ ,
468.Ql Ic + ,
469or
470.Ql Ic \- ,
471the command is treated specially.
472A
473.Ql Ic @
474causes the command not to be echoed before it is executed.
475A
476.Ql Ic +
477causes the command to be executed even when
478.Fl n
479is given.
480This is similar to the effect of the .MAKE special source,
481except that the effect can be limited to a single line of a script.
482A
483.Ql Ic \-
484causes any non-zero exit status of the command line to be ignored.
485.Sh VARIABLE ASSIGNMENTS
486Variables in make are much like variables in the shell, and, by tradition,
487consist of all upper-case letters.
488.Ss Variable assignment modifiers
489The five operators that can be used to assign values to variables are as
490follows:
491.Bl -tag -width Ds
492.It Ic \&=
493Assign the value to the variable.
494Any previous value is overridden.
495.It Ic \&+=
496Append the value to the current value of the variable.
497.It Ic \&?=
498Assign the value to the variable if it is not already defined.
499.It Ic \&:=
500Assign with expansion, i.e. expand the value before assigning it
501to the variable.
502Normally, expansion is not done until the variable is referenced.
503.Em NOTE :
504References to undefined variables are
505.Em not
506expanded.
507This can cause problems when variable modifiers are used.
508.It Ic \&!=
509Expand the value and pass it to the shell for execution and assign
510the result to the variable.
511Any newlines in the result are replaced with spaces.
512.El
513.Pp
514Any white-space before the assigned
515.Ar value
516is removed; if the value is being appended, a single space is inserted
517between the previous contents of the variable and the appended value.
518.Pp
519Variables are expanded by surrounding the variable name with either
520curly braces
521.Pq Ql {}
522or parentheses
523.Pq Ql ()
524and preceding it with
525a dollar sign
526.Pq Ql \&$ .
527If the variable name contains only a single letter, the surrounding
528braces or parentheses are not required.
529This shorter form is not recommended.
530.Pp
531If the variable name contains a dollar, then the name itself is expanded first.
532This allows almost arbitrary variable names, however names containing dollar,
533braces, parenthesis, or whitespace are really best avoided!
534.Pp
535If the result of expanding a variable contains a dollar sign
536.Pq Ql \&$
537the string is expanded again.
538.Pp
539Variable substitution occurs at two distinct times, depending on where
540the variable is being used.
541Variables in dependency lines are expanded as the line is read.
542Variables in shell commands are expanded when the shell command is
543executed.
544.Ss Variable classes
545The four different classes of variables (in order of increasing precedence)
546are:
547.Bl -tag -width Ds
548.It Environment variables
549Variables defined as part of
550.Nm Ns 's
551environment.
552.It Global variables
553Variables defined in the makefile or in included makefiles.
554.It Command line variables
555Variables defined as part of the command line.
556.It Local variables
557Variables that are defined specific to a certain target.
558The seven local variables are as follows:
559.Bl -tag -width ".ARCHIVE"
560.It Va .ALLSRC
561The list of all sources for this target; also known as
562.Ql Va \&\*[Gt] .
563.It Va .ARCHIVE
564The name of the archive file.
565.It Va .IMPSRC
566In suffix-transformation rules, the name/path of the source from which the
567target is to be transformed (the
568.Dq implied
569source); also known as
570.Ql Va \&\*[Lt] .
571It is not defined in explicit rules.
572.It Va .MEMBER
573The name of the archive member.
574.It Va .OODATE
575The list of sources for this target that were deemed out-of-date; also
576known as
577.Ql Va \&? .
578.It Va .PREFIX
579The file prefix of the file, containing only the file portion, no suffix
580or preceding directory components; also known as
581.Ql Va * .
582.It Va .TARGET
583The name of the target; also known as
584.Ql Va @ .
585.El
586.Pp
587The shorter forms
588.Ql Va @ ,
589.Ql Va \&? ,
590.Ql Va \&\*[Lt] ,
591.Ql Va \&\*[Gt] ,
592and
593.Ql Va *
594are permitted for backward
595compatibility with historical makefiles and are not recommended.
596The six variables
597.Ql Va "@F" ,
598.Ql Va "@D" ,
599.Ql Va "\*[Lt]F" ,
600.Ql Va "\*[Lt]D" ,
601.Ql Va "*F" ,
602and
603.Ql Va "*D"
604are permitted for compatibility with
605.At V
606makefiles and are not recommended.
607.Pp
608Four of the local variables may be used in sources on dependency lines
609because they expand to the proper value for each target on the line.
610These variables are
611.Ql Va .TARGET ,
612.Ql Va .PREFIX ,
613.Ql Va .ARCHIVE ,
614and
615.Ql Va .MEMBER .
616.El
617.Ss Additional built-in variables
618In addition,
619.Nm
620sets or knows about the following variables:
621.Bl -tag -width .MAKEOVERRIDES
622.It Va \&$
623A single dollar sign
624.Ql \&$ ,
625i.e.
626.Ql \&$$
627expands to a single dollar
628sign.
629.It Va .ALLTARGETS
630The list of all targets encountered in the Makefile.
631If evaluated during
632Makefile parsing, lists only those targets encountered thus far.
633.It Va .CURDIR
634A path to the directory where
635.Nm
636was executed.
637Refer to the description of
638.Ql Ev PWD
639for more details.
640.It Ev MAKE
641The name that
642.Nm
643was executed with
644.Pq Va argv[0] .
645For compatibility
646.Nm
647also sets
648.Va .MAKE
649with the same value.
650The preferred variable to use is the environment variable
651.Ev MAKE
652because it is more compatible with other versions of
653.Nm
654and cannot be confused with the special target with the same name.
655.It Va .MAKE.EXPORTED
656The list of variables exported by
657.Nm .
658.It Va .MAKE.MAKEFILES
659The list of makefiles read by
660.Nm ,
661which is useful for tracking dependencies.
662Each makefile is recorded only once, regardless of the number of times read.
663.It Va .MAKE.LEVEL
664The recursion depth of
665.Nm .
666The initial instance of
667.Nm
668will be 0, and an incremented value is put into the environment
669to be seen by the next generation.
670This allows tests like:
671.Li .if ${.MAKE.LEVEL} == 0
672to protect things which should only be evaluated in the initial instance of
673.Nm .
674.It Va .MAKE.PID
675The process-id of
676.Nm .
677.It Va .MAKE.PPID
678The parent process-id of
679.Nm .
680.It Va .MAKE.JOB.PREFIX
681If
682.Nm
683is run with
684.Ar j
685then output for each target is prefixed with a token
686.Ql --- target ---
687the first part of which can be controlled via
688.Va .MAKE.JOB.PREFIX .
689.br
690For example:
691.Li .MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}]
692would produce tokens like
693.Ql ---make[1234] target ---
694making it easier to track the degree of parallelism being achieved.
695.It Ev MAKEFLAGS
696The environment variable
697.Ql Ev MAKEFLAGS
698may contain anything that
699may be specified on
700.Nm Ns 's
701command line.
702Anything specified on
703.Nm Ns 's
704command line is appended to the
705.Ql Ev MAKEFLAGS
706variable which is then
707entered into the environment for all programs which
708.Nm
709executes.
710.It Va .MAKEOVERRIDES
711This variable is used to record the names of variables assigned to
712on the command line, so that they may be exported as part of
713.Ql Ev MAKEFLAGS .
714This behaviour can be disabled by assigning an empty value to
715.Ql Va .MAKEOVERRIDES
716within a makefile.
717Extra variables can be exported from a makefile
718by appending their names to
719.Ql Va .MAKEOVERRIDES .
720.Ql Ev MAKEFLAGS
721is re-exported whenever
722.Ql Va .MAKEOVERRIDES
723is modified.
724.It Va MAKE_PRINT_VAR_ON_ERROR
725When
726.Nm
727stops due to an error, it prints its name and the value of
728.Ql Va .CURDIR
729as well as the value of any variables named in
730.Ql Va MAKE_PRINT_VAR_ON_ERROR .
731.It Va .newline
732This variable is simply assigned a newline character as its value.
733This allows expansions using the
734.Cm \&:@
735modifier to put a newline between
736iterations of the loop rather than a space.
737For example, the printing of
738.Ql Va MAKE_PRINT_VAR_ON_ERROR
739could be done as ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}.
740.It Va .OBJDIR
741A path to the directory where the targets are built.
742Its value is determined by trying to
743.Xr chdir 2
744to the following directories in order and using the first match:
745.Bl -enum
746.It
747.Ev ${MAKEOBJDIRPREFIX}${.CURDIR}
748.Pp
749(Only if
750.Ql Ev MAKEOBJDIRPREFIX
751is set in the environment or on the command line.)
752.It
753.Ev ${MAKEOBJDIR}
754.Pp
755(Only if
756.Ql Ev MAKEOBJDIR
757is set in the environment or on the command line.)
758.It
759.Ev ${.CURDIR} Ns Pa /obj. Ns Ev ${MACHINE}
760.It
761.Ev ${.CURDIR} Ns Pa /obj
762.It
763.Pa /usr/obj/ Ns Ev ${.CURDIR}
764.It
765.Ev ${.CURDIR}
766.El
767.Pp
768Variable expansion is performed on the value before it's used,
769so expressions such as
770.Dl ${.CURDIR:C,^/usr/src,/var/obj,}
771may be used.
772.Pp
773.Ql Va .OBJDIR
774may be modified in the makefile as a global variable.
775In all cases,
776.Nm
777will
778.Xr chdir 2
779to
780.Ql Va .OBJDIR
781and set
782.Ql Ev PWD
783to that directory before executing any targets.
784.
785.It Va .PARSEDIR
786A path to the directory of the current
787.Ql Pa Makefile
788being parsed.
789.It Va .PARSEFILE
790The basename of the current
791.Ql Pa Makefile
792being parsed.
793This variable and
794.Ql Va .PARSEDIR
795are both set only while the
796.Ql Pa Makefiles
797are being parsed.
798.It Va .PATH
799A variable that represents the list of directories that
800.Nm
801will search for files.
802The search list should be updated using the target
803.Ql Va .PATH
804rather than the variable.
805.It Ev PWD
806Alternate path to the current directory.
807.Nm
808normally sets
809.Ql Va .CURDIR
810to the canonical path given by
811.Xr getcwd 3 .
812However, if the environment variable
813.Ql Ev PWD
814is set and gives a path to the current directory, then
815.Nm
816sets
817.Ql Va .CURDIR
818to the value of
819.Ql Ev PWD
820instead.
821This behaviour is disabled if
822.Ql Ev MAKEOBJDIRPREFIX
823is set or
824.Ql Ev MAKEOBJDIR
825contains a variable transform.
826.Ql Ev PWD
827is set to the value of
828.Ql Va .OBJDIR
829for all programs which
830.Nm
831executes.
832.It Ev VPATH
833Colon-separated
834.Pq Dq \&:
835lists of directories that
836.Nm
837will search for files.
838The variable is supported for compatibility with old make programs only,
839use
840.Ql Va .PATH
841instead.
842.El
843.Ss Variable modifiers
844Variable expansion may be modified to select or modify each word of the
845variable (where a
846.Dq word
847is white-space delimited sequence of characters).
848The general format of a variable expansion is as follows:
849.Pp
850.Dl ${variable[:modifier[:...]]}
851.Pp
852Each modifier begins with a colon,
853which may be escaped with a backslash
854.Pq Ql \e .
855.Pp
856A set of modifiers can be specified via a variable, as follows:
857.Pp
858.Dl modifier_variable=modifier[:...]
859.Dl ${variable:${modifier_variable}[:...]}
860.Pp
861In this case the first modifier in the modifier_variable does not
862start with a colon, since that must appear in the referencing
863variable.
864If any of the modifiers in the modifier_variable contain a dollar sign
865.Pq Ql $ ,
866these must be doubled to avoid early expansion.
867.Pp
868The supported modifiers are:
869.Bl -tag -width EEE
870.It Cm \&:E
871Replaces each word in the variable with its suffix.
872.It Cm \&:H
873Replaces each word in the variable with everything but the last component.
874.It Cm \&:M Ns Ar pattern
875Select only those words that match
876.Ar pattern .
877The standard shell wildcard characters
878.Pf ( Ql * ,
879.Ql \&? ,
880and
881.Ql Op )
882may
883be used.
884The wildcard characters may be escaped with a backslash
885.Pq Ql \e .
886.It Cm \&:N Ns Ar pattern
887This is identical to
888.Ql Cm \&:M ,
889but selects all words which do not match
890.Ar pattern .
891.It Cm \&:O
892Order every word in variable alphabetically.
893To sort words in
894reverse order use the
895.Ql Cm \&:O:[-1..1]
896combination of modifiers.
897.It Cm \&:Ox
898Randomize words in variable.
899The results will be different each time you are referring to the
900modified variable; use the assignment with expansion
901.Pq Ql Cm \&:=
902to prevent such behaviour.
903For example,
904.Bd -literal -offset indent
905LIST=			uno due tre quattro
906RANDOM_LIST=		${LIST:Ox}
907STATIC_RANDOM_LIST:=	${LIST:Ox}
908
909all:
910	@echo "${RANDOM_LIST}"
911	@echo "${RANDOM_LIST}"
912	@echo "${STATIC_RANDOM_LIST}"
913	@echo "${STATIC_RANDOM_LIST}"
914.Ed
915may produce output similar to:
916.Bd -literal -offset indent
917quattro due tre uno
918tre due quattro uno
919due uno quattro tre
920due uno quattro tre
921.Ed
922.It Cm \&:Q
923Quotes every shell meta-character in the variable, so that it can be passed
924safely through recursive invocations of
925.Nm .
926.It Cm \&:R
927Replaces each word in the variable with everything but its suffix.
928.It Cm \&:tl
929Converts variable to lower-case letters.
930.It Cm \&:ts Ns Ar c
931Words in the variable are normally separated by a space on expansion.
932This modifier sets the separator to the character
933.Ar c .
934If
935.Ar c
936is omitted, then no separator is used.
937.It Cm \&:tu
938Converts variable to upper-case letters.
939.It Cm \&:tW
940Causes the value to be treated as a single word
941(possibly containing embedded white space).
942See also
943.Ql Cm \&:[*] .
944.It Cm \&:tw
945Causes the value to be treated as a sequence of
946words delimited by white space.
947See also
948.Ql Cm \&:[@] .
949.Sm off
950.It Cm \&:S No \&/ Ar old_string No \&/ Ar new_string No \&/ Op Cm 1gW
951.Sm on
952Modify the first occurrence of
953.Ar old_string
954in the variable's value, replacing it with
955.Ar new_string .
956If a
957.Ql g
958is appended to the last slash of the pattern, all occurrences
959in each word are replaced.
960If a
961.Ql 1
962is appended to the last slash of the pattern, only the first word
963is affected.
964If a
965.Ql W
966is appended to the last slash of the pattern,
967then the value is treated as a single word
968(possibly containing embedded white space).
969If
970.Ar old_string
971begins with a caret
972.Pq Ql ^ ,
973.Ar old_string
974is anchored at the beginning of each word.
975If
976.Ar old_string
977ends with a dollar sign
978.Pq Ql \&$ ,
979it is anchored at the end of each word.
980Inside
981.Ar new_string ,
982an ampersand
983.Pq Ql \*[Am]
984is replaced by
985.Ar old_string
986(without any
987.Ql ^
988or
989.Ql \&$ ) .
990Any character may be used as a delimiter for the parts of the modifier
991string.
992The anchoring, ampersand and delimiter characters may be escaped with a
993backslash
994.Pq Ql \e .
995.Pp
996Variable expansion occurs in the normal fashion inside both
997.Ar old_string
998and
999.Ar new_string
1000with the single exception that a backslash is used to prevent the expansion
1001of a dollar sign
1002.Pq Ql \&$ ,
1003not a preceding dollar sign as is usual.
1004.Sm off
1005.It Cm \&:C No \&/ Ar pattern No \&/ Ar replacement No \&/ Op Cm 1gW
1006.Sm on
1007The
1008.Cm \&:C
1009modifier is just like the
1010.Cm \&:S
1011modifier except that the old and new strings, instead of being
1012simple strings, are a regular expression (see
1013.Xr regex 3 )
1014string
1015.Ar pattern
1016and an
1017.Xr ed 1 Ns \-style
1018string
1019.Ar replacement .
1020Normally, the first occurrence of the pattern
1021.Ar pattern
1022in each word of the value is substituted with
1023.Ar replacement .
1024The
1025.Ql 1
1026modifier causes the substitution to apply to at most one word; the
1027.Ql g
1028modifier causes the substitution to apply to as many instances of the
1029search pattern
1030.Ar pattern
1031as occur in the word or words it is found in; the
1032.Ql W
1033modifier causes the value to be treated as a single word
1034(possibly containing embedded white space).
1035Note that
1036.Ql 1
1037and
1038.Ql g
1039are orthogonal; the former specifies whether multiple words are
1040potentially affected, the latter whether multiple substitutions can
1041potentially occur within each affected word.
1042.It Cm \&:T
1043Replaces each word in the variable with its last component.
1044.It Cm \&:u
1045Remove adjacent duplicate words (like
1046.Xr uniq 1 ) .
1047.Sm off
1048.It Cm \&:\&? Ar true_string Cm \&: Ar false_string
1049.Sm on
1050If the variable name (not its value), when parsed as a .if conditional
1051expression, evaluates to true, return as its value the
1052.Ar true_string ,
1053otherwise return the
1054.Ar false_string .
1055Since the variable name is used as the expression, \&:\&? must be the
1056first modifier after the variable name itself - which will, of course,
1057usually contain variable expansions.
1058A common error is trying to use expressions like
1059.Dl ${NUMBERS:M42:?match:no}
1060which actually tests defined(NUMBERS),
1061to determine is any words match "42" you need to use something like:
1062.Dl ${${NUMBERS:M42} != "":?match:no} .
1063.It Ar :old_string=new_string
1064This is the
1065.At V
1066style variable substitution.
1067It must be the last modifier specified.
1068If
1069.Ar old_string
1070or
1071.Ar new_string
1072do not contain the pattern matching character
1073.Ar %
1074then it is assumed that they are
1075anchored at the end of each word, so only suffixes or entire
1076words may be replaced.
1077Otherwise
1078.Ar %
1079is the substring of
1080.Ar old_string
1081to be replaced in
1082.Ar new_string .
1083.Pp
1084Variable expansion occurs in the normal fashion inside both
1085.Ar old_string
1086and
1087.Ar new_string
1088with the single exception that a backslash is used to prevent the
1089expansion of a dollar sign
1090.Pq Ql \&$ ,
1091not a preceding dollar sign as is usual.
1092.Sm off
1093.It Cm \&:@ Ar temp Cm @ Ar string Cm @
1094.Sm on
1095This is the loop expansion mechanism from the OSF Development
1096Environment (ODE) make.
1097Unlike
1098.Cm \&.for
1099loops expansion occurs at the time of
1100reference.
1101Assign
1102.Ar temp
1103to each word in the variable and evaluate
1104.Ar string .
1105The ODE convention is that
1106.Ar temp
1107should start and end with a period.
1108For example.
1109.Dl ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@}
1110.It Cm \&:U Ns Ar newval
1111If the variable is undefined
1112.Ar newval
1113is the value.
1114If the variable is defined, the existing value is returned.
1115This is another ODE make feature.
1116It is handy for setting per-target CFLAGS for instance:
1117.Dl ${_${.TARGET:T}_CFLAGS:U${DEF_CFLAGS}}
1118If a value is only required if the variable is undefined, use:
1119.Dl ${VAR:D:Unewval}
1120.It Cm \&:D Ns Ar newval
1121If the variable is defined
1122.Ar newval
1123is the value.
1124.It Cm \&:L
1125The name of the variable is the value.
1126.It Cm \&:P
1127The path of the node which has the same name as the variable
1128is the value.
1129If no such node exists or its path is null, then the
1130name of the variable is used.
1131.Sm off
1132.It Cm \&:\&! Ar cmd Cm \&!
1133.Sm on
1134The output of running
1135.Ar cmd
1136is the value.
1137.It Cm \&:sh
1138If the variable is non-empty it is run as a command and the output
1139becomes the new value.
1140.It Cm \&::= Ns Ar str
1141The variable is assigned the value
1142.Ar str
1143after substitution.
1144This modifier and its variations are useful in
1145obscure situations such as wanting to set a variable when shell commands
1146are being parsed.
1147These assignment modifiers always expand to
1148nothing, so if appearing in a rule line by themselves should be
1149preceded with something to keep
1150.Nm
1151happy.
1152.Pp
1153The
1154.Ql Cm \&::
1155helps avoid false matches with the
1156.At V
1157style
1158.Cm \&:=
1159modifier and since substitution always occurs the
1160.Cm \&::=
1161form is vaguely appropriate.
1162.It Cm \&::?= Ns Ar str
1163As for
1164.Cm \&::=
1165but only if the variable does not already have a value.
1166.It Cm \&::+= Ns Ar str
1167Append
1168.Ar str
1169to the variable.
1170.It Cm \&::!= Ns Ar cmd
1171Assign the output of
1172.Ar cmd
1173to the variable.
1174.It Cm \&:\&[ Ns Ar range Ns Cm \&]
1175Selects one or more words from the value,
1176or performs other operations related to the way in which the
1177value is divided into words.
1178.Pp
1179Ordinarily, a value is treated as a sequence of words
1180delimited by white space.
1181Some modifiers suppress this behaviour,
1182causing a value to be treated as a single word
1183(possibly containing embedded white space).
1184An empty value, or a value that consists entirely of white-space,
1185is treated as a single word.
1186For the purposes of the
1187.Ql Cm \&:[]
1188modifier, the words are indexed both forwards using positive integers
1189(where index 1 represents the first word),
1190and backwards using negative integers
1191(where index -1 represents the last word).
1192.Pp
1193The
1194.Ar range
1195is subjected to variable expansion, and the expanded result is
1196then interpreted as follows:
1197.Bl -tag -width index
1198.\" :[n]
1199.It Ar index
1200Selects a single word from the value.
1201.\" :[start..end]
1202.It Ar start Ns Cm \&.. Ns Ar end
1203Selects all words from
1204.Ar start
1205to
1206.Ar end ,
1207inclusive.
1208For example,
1209.Ql Cm \&:[2..-1]
1210selects all words from the second word to the last word.
1211If
1212.Ar start
1213is greater than
1214.Ar end ,
1215then the words are output in reverse order.
1216For example,
1217.Ql Cm \&:[-1..1]
1218selects all the words from last to first.
1219.\" :[*]
1220.It Cm \&*
1221Causes subsequent modifiers to treat the value as a single word
1222(possibly containing embedded white space).
1223Analogous to the effect of
1224\&"$*\&"
1225in Bourne shell.
1226.\" :[0]
1227.It 0
1228Means the same as
1229.Ql Cm \&:[*] .
1230.\" :[*]
1231.It Cm \&@
1232Causes subsequent modifiers to treat the value as a sequence of words
1233delimited by white space.
1234Analogous to the effect of
1235\&"$@\&"
1236in Bourne shell.
1237.\" :[#]
1238.It Cm \&#
1239Returns the number of words in the value.
1240.El \" :[range]
1241.El
1242.Sh INCLUDE STATEMENTS, CONDITIONALS AND FOR LOOPS
1243Makefile inclusion, conditional structures and for loops  reminiscent
1244of the C programming language are provided in
1245.Nm .
1246All such structures are identified by a line beginning with a single
1247dot
1248.Pq Ql \&.
1249character.
1250Files are included with either
1251.Cm \&.include Aq Ar file
1252or
1253.Cm \&.include Pf \*q Ar file Ns \*q .
1254Variables between the angle brackets or double quotes are expanded
1255to form the file name.
1256If angle brackets are used, the included makefile is expected to be in
1257the system makefile directory.
1258If double quotes are used, the including makefile's directory and any
1259directories specified using the
1260.Fl I
1261option are searched before the system
1262makefile directory.
1263For compatibility with other versions of
1264.Nm
1265.Ql include file ...
1266is also accepted.
1267If the include statement is written as
1268.Cm .-include
1269or as
1270.Cm .sinclude
1271then errors locating and/or opening include files are ignored.
1272.Pp
1273Conditional expressions are also preceded by a single dot as the first
1274character of a line.
1275The possible conditionals are as follows:
1276.Bl -tag -width Ds
1277.It Ic .export Ar variable ...
1278Export the specified global variable.
1279If no variable list is provided, all globals are exported
1280except for internal variables (those that start with
1281.Ql \&. ) .
1282This is not affected by the
1283.Fl X
1284flag, so should be used with caution.
1285.Pp
1286Appending a variable name to
1287.Va .MAKE.EXPORTED
1288is equivalent to exporting a variable.
1289.It Ic .unexport Ar variable ...
1290The opposite of
1291.Ql .export .
1292The specified global
1293.Va variable
1294will be removed from
1295.Va .MAKE.EXPORTED .
1296If no variable list is provided, all globals are unexported,
1297and
1298.Va .MAKE.EXPORTED
1299deleted.
1300.It Ic .unexport-env
1301Unexport all globals previously exported and
1302clear the environment inherited from the parent.
1303This operation will cause a memory leak of the original environment,
1304so should be used sparingly.
1305Testing for
1306.Va .MAKE.LEVEL
1307being 0, would make sense.
1308Also note that any variables which originated in the parent environment
1309should be explicitly preserved if desired.
1310For example:
1311.Bd -literal -offset indent
1312.Li .if ${.MAKE.LEVEL} == 0
1313PATH := ${PATH}
1314.Li .unexport-env
1315.Li .export PATH
1316.Li .endif
1317.Pp
1318.Ed
1319Would result in an environment containing only
1320.Ql Ev PATH ,
1321which is the minimal useful environment.
1322Actually
1323.Ql Ev .MAKE.LEVEL
1324will also be pushed into the new environment.
1325.It Ic .undef Ar variable
1326Un-define the specified global variable.
1327Only global variables may be un-defined.
1328.It Ic \&.if Oo \&! Oc Ns Ar expression Op Ar operator expression ...
1329Test the value of an expression.
1330.It Ic .ifdef Oo \&! Oc Ns Ar variable Op Ar operator variable ...
1331Test the value of a variable.
1332.It Ic .ifndef Oo \&! Oc Ns Ar variable Op Ar operator variable ...
1333Test the value of a variable.
1334.It Ic .ifmake Oo \&! Oc Ns Ar target Op Ar operator target ...
1335Test the target being built.
1336.It Ic .ifnmake Oo \&! Ns Oc Ar target Op Ar operator target ...
1337Test the target being built.
1338.It Ic .else
1339Reverse the sense of the last conditional.
1340.It Ic .elif Oo \&! Ns Oc Ar expression Op Ar operator expression ...
1341A combination of
1342.Ql Ic .else
1343followed by
1344.Ql Ic .if .
1345.It Ic .elifdef Oo \&! Oc Ns Ar variable Op Ar operator variable ...
1346A combination of
1347.Ql Ic .else
1348followed by
1349.Ql Ic .ifdef .
1350.It Ic .elifndef Oo \&! Oc Ns Ar variable Op Ar operator variable ...
1351A combination of
1352.Ql Ic .else
1353followed by
1354.Ql Ic .ifndef .
1355.It Ic .elifmake Oo \&! Oc Ns Ar target Op Ar operator target ...
1356A combination of
1357.Ql Ic .else
1358followed by
1359.Ql Ic .ifmake .
1360.It Ic .elifnmake Oo \&! Oc Ns Ar target Op Ar operator target ...
1361A combination of
1362.Ql Ic .else
1363followed by
1364.Ql Ic .ifnmake .
1365.It Ic .endif
1366End the body of the conditional.
1367.El
1368.Pp
1369The
1370.Ar operator
1371may be any one of the following:
1372.Bl -tag -width "Cm XX"
1373.It Cm \&|\&|
1374Logical OR.
1375.It Cm \&\*[Am]\*[Am]
1376Logical
1377.Tn AND ;
1378of higher precedence than
1379.Dq \&|\&| .
1380.El
1381.Pp
1382As in C,
1383.Nm
1384will only evaluate a conditional as far as is necessary to determine
1385its value.
1386Parentheses may be used to change the order of evaluation.
1387The boolean operator
1388.Ql Ic \&!
1389may be used to logically negate an entire
1390conditional.
1391It is of higher precedence than
1392.Ql Ic \&\*[Am]\*[Am] .
1393.Pp
1394The value of
1395.Ar expression
1396may be any of the following:
1397.Bl -tag -width defined
1398.It Ic defined
1399Takes a variable name as an argument and evaluates to true if the variable
1400has been defined.
1401.It Ic make
1402Takes a target name as an argument and evaluates to true if the target
1403was specified as part of
1404.Nm Ns 's
1405command line or was declared the default target (either implicitly or
1406explicitly, see
1407.Va .MAIN )
1408before the line containing the conditional.
1409.It Ic empty
1410Takes a variable, with possible modifiers, and evaluates to true if
1411the expansion of the variable would result in an empty string.
1412.It Ic exists
1413Takes a file name as an argument and evaluates to true if the file exists.
1414The file is searched for on the system search path (see
1415.Va .PATH ) .
1416.It Ic target
1417Takes a target name as an argument and evaluates to true if the target
1418has been defined.
1419.It Ic commands
1420Takes a target name as an argument and evaluates to true if the target
1421has been defined and has commands associated with it.
1422.El
1423.Pp
1424.Ar Expression
1425may also be an arithmetic or string comparison.
1426Variable expansion is
1427performed on both sides of the comparison, after which the integral
1428values are compared.
1429A value is interpreted as hexadecimal if it is
1430preceded by 0x, otherwise it is decimal; octal numbers are not supported.
1431The standard C relational operators are all supported.
1432If after
1433variable expansion, either the left or right hand side of a
1434.Ql Ic ==
1435or
1436.Ql Ic "!="
1437operator is not an integral value, then
1438string comparison is performed between the expanded
1439variables.
1440If no relational operator is given, it is assumed that the expanded
1441variable is being compared against 0 or an empty string in the case
1442of a string comparison.
1443.Pp
1444When
1445.Nm
1446is evaluating one of these conditional expressions, and it encounters
1447a (white-space separated) word it doesn't recognize, either the
1448.Dq make
1449or
1450.Dq defined
1451expression is applied to it, depending on the form of the conditional.
1452If the form is
1453.Ql Ic .ifdef ,
1454.Ql Ic .ifndef ,
1455or
1456.Ql Ic .if
1457the
1458.Dq defined
1459expression is applied.
1460Similarly, if the form is
1461.Ql Ic .ifmake
1462or
1463.Ql Ic .ifnmake , the
1464.Dq make
1465expression is applied.
1466.Pp
1467If the conditional evaluates to true the parsing of the makefile continues
1468as before.
1469If it evaluates to false, the following lines are skipped.
1470In both cases this continues until a
1471.Ql Ic .else
1472or
1473.Ql Ic .endif
1474is found.
1475.Pp
1476For loops are typically used to apply a set of rules to a list of files.
1477The syntax of a for loop is:
1478.Pp
1479.Bl -tag -compact -width Ds
1480.It Ic \&.for Ar variable Oo Ar variable ... Oc Ic in Ar expression
1481.It Aq make-rules
1482.It Ic \&.endfor
1483.El
1484.Pp
1485After the for
1486.Ic expression
1487is evaluated, it is split into words.
1488On each iteration of the loop, one word is taken and assigned to each
1489.Ic variable ,
1490in order, and these
1491.Ic variables
1492are substituted into the
1493.Ic make-rules
1494inside the body of the for loop.
1495The number of words must come out even; that is, if there are three
1496iteration variables, the number of words provided must be a multiple
1497of three.
1498.Sh COMMENTS
1499Comments begin with a hash
1500.Pq Ql \&#
1501character, anywhere but in a shell
1502command line, and continue to the end of an unescaped new line.
1503.Sh SPECIAL SOURCES (ATTRIBUTES)
1504.Bl -tag -width .IGNOREx
1505.It Ic .EXEC
1506Target is never out of date, but always execute commands anyway.
1507.It Ic .IGNORE
1508Ignore any errors from the commands associated with this target, exactly
1509as if they all were preceded by a dash
1510.Pq Ql \- .
1511.\" .It Ic .INVISIBLE
1512.\" XXX
1513.\" .It Ic .JOIN
1514.\" XXX
1515.It Ic .MADE
1516Mark all sources of this target as being up-to-date.
1517.It Ic .MAKE
1518Execute the commands associated with this target even if the
1519.Fl n
1520or
1521.Fl t
1522options were specified.
1523Normally used to mark recursive
1524.Nm Ns 's .
1525.It Ic .NOPATH
1526Do not search for the target in the directories specified by
1527.Ic .PATH .
1528.It Ic .NOTMAIN
1529Normally
1530.Nm
1531selects the first target it encounters as the default target to be built
1532if no target was specified.
1533This source prevents this target from being selected.
1534.It Ic .OPTIONAL
1535If a target is marked with this attribute and
1536.Nm
1537can't figure out how to create it, it will ignore this fact and assume
1538the file isn't needed or already exists.
1539.It Ic .PHONY
1540The target does not
1541correspond to an actual file; it is always considered to be out of date,
1542and will not be created with the
1543.Fl t
1544option.
1545.It Ic .PRECIOUS
1546When
1547.Nm
1548is interrupted, it normally removes any partially made targets.
1549This source prevents the target from being removed.
1550.It Ic .RECURSIVE
1551Synonym for
1552.Ic .MAKE .
1553.It Ic .SILENT
1554Do not echo any of the commands associated with this target, exactly
1555as if they all were preceded by an at sign
1556.Pq Ql @ .
1557.It Ic .USE
1558Turn the target into
1559.Nm Ns 's
1560version of a macro.
1561When the target is used as a source for another target, the other target
1562acquires the commands, sources, and attributes (except for
1563.Ic .USE )
1564of the
1565source.
1566If the target already has commands, the
1567.Ic .USE
1568target's commands are appended
1569to them.
1570.It Ic .USEBEFORE
1571Exactly like
1572.Ic .USE ,
1573but prepend the
1574.Ic .USEBEFORE
1575target commands to the target.
1576.It Ic .WAIT
1577If
1578.Ic .WAIT
1579appears in a dependency line, the sources that precede it are
1580made before the sources that succeed it in the line.
1581Since the dependents of files are not made until the file itself
1582could be made, this also stops the dependents being built unless they
1583are needed for another branch of the dependency tree.
1584So given:
1585.Bd -literal
1586x: a .WAIT b
1587	echo x
1588a:
1589	echo a
1590b: b1
1591	echo b
1592b1:
1593	echo b1
1594
1595.Ed
1596the output is always
1597.Ql a ,
1598.Ql b1 ,
1599.Ql b ,
1600.Ql x .
1601.br
1602The ordering imposed by
1603.Ic .WAIT
1604is only relevant for parallel makes.
1605.El
1606.Sh SPECIAL TARGETS
1607Special targets may not be included with other targets, i.e. they must be
1608the only target specified.
1609.Bl -tag -width .BEGINx
1610.It Ic .BEGIN
1611Any command lines attached to this target are executed before anything
1612else is done.
1613.It Ic .DEFAULT
1614This is sort of a
1615.Ic .USE
1616rule for any target (that was used only as a
1617source) that
1618.Nm
1619can't figure out any other way to create.
1620Only the shell script is used.
1621The
1622.Ic .IMPSRC
1623variable of a target that inherits
1624.Ic .DEFAULT Ns 's
1625commands is set
1626to the target's own name.
1627.It Ic .END
1628Any command lines attached to this target are executed after everything
1629else is done.
1630.It Ic .IGNORE
1631Mark each of the sources with the
1632.Ic .IGNORE
1633attribute.
1634If no sources are specified, this is the equivalent of specifying the
1635.Fl i
1636option.
1637.It Ic .INTERRUPT
1638If
1639.Nm
1640is interrupted, the commands for this target will be executed.
1641.It Ic .MAIN
1642If no target is specified when
1643.Nm
1644is invoked, this target will be built.
1645.It Ic .MAKEFLAGS
1646This target provides a way to specify flags for
1647.Nm
1648when the makefile is used.
1649The flags are as if typed to the shell, though the
1650.Fl f
1651option will have
1652no effect.
1653.\" XXX: NOT YET!!!!
1654.\" .It Ic .NOTPARALLEL
1655.\" The named targets are executed in non parallel mode.
1656.\" If no targets are
1657.\" specified, then all targets are executed in non parallel mode.
1658.It Ic .NOPATH
1659Apply the
1660.Ic .NOPATH
1661attribute to any specified sources.
1662.It Ic .NOTPARALLEL
1663Disable parallel mode.
1664.It Ic .NO_PARALLEL
1665Synonym for
1666.Ic .NOTPARALLEL ,
1667for compatibility with other pmake variants.
1668.It Ic .ORDER
1669The named targets are made in sequence.
1670This ordering does not add targets to the list of targets to be made.
1671Since the dependents of a target do not get built until the target itself
1672could be built, unless
1673.Ql a
1674is built by another part of the dependency graph,
1675the following is a dependency loop:
1676.Bd -literal
1677\&.ORDER: a b
1678b: a
1679.Ed
1680.Pp
1681The ordering imposed by
1682.Ic .ORDER
1683is only relevant for parallel makes.
1684.\" XXX: NOT YET!!!!
1685.\" .It Ic .PARALLEL
1686.\" The named targets are executed in parallel mode.
1687.\" If no targets are
1688.\" specified, then all targets are executed in parallel mode.
1689.It Ic .PATH
1690The sources are directories which are to be searched for files not
1691found in the current directory.
1692If no sources are specified, any previously specified directories are
1693deleted.
1694If the source is the special
1695.Ic .DOTLAST
1696target, then the current working
1697directory is searched last.
1698.It Ic .PHONY
1699Apply the
1700.Ic .PHONY
1701attribute to any specified sources.
1702.It Ic .PRECIOUS
1703Apply the
1704.Ic .PRECIOUS
1705attribute to any specified sources.
1706If no sources are specified, the
1707.Ic .PRECIOUS
1708attribute is applied to every
1709target in the file.
1710.It Ic .SHELL
1711Sets the shell that
1712.Nm
1713will use to execute commands.
1714The sources are a set of
1715.Ar field=value
1716pairs.
1717.Bl -tag -width hasErrCtls
1718.It Ar name
1719This is the minimal specification, used to select one of the builtin
1720shell specs;
1721.Ar sh ,
1722.Ar ksh ,
1723and
1724.Ar csh .
1725.It Ar path
1726Specifies the path to the shell.
1727.It Ar hasErrCtl
1728Indicates whether the shell supports exit on error.
1729.It Ar check
1730The command to turn on error checking.
1731.It Ar ignore
1732The command to disable error checking.
1733.It Ar echo
1734The command to turn on echoing of commands executed.
1735.It Ar quiet
1736The command to turn off echoing of commands executed.
1737.It Ar filter
1738The output to filter after issuing the
1739.Ar quiet
1740command.
1741It is typically identical to
1742.Ar quiet .
1743.It Ar errFlag
1744The flag to pass the shell to enable error checking.
1745.It Ar echoFlag
1746The flag to pass the shell to enable command echoing.
1747.It Ar newline
1748The string literal to pass the shell that results in a single newline
1749character when used outside of any quoting characters.
1750.El
1751Example:
1752.Bd -literal
1753\&.SHELL: name=ksh path=/bin/ksh hasErrCtl=true \e
1754	check="set -e" ignore="set +e" \e
1755	echo="set -v" quiet="set +v" filter="set +v" \e
1756	echoFlag=v errFlag=e newline="'\en'"
1757.Ed
1758.It Ic .SILENT
1759Apply the
1760.Ic .SILENT
1761attribute to any specified sources.
1762If no sources are specified, the
1763.Ic .SILENT
1764attribute is applied to every
1765command in the file.
1766.It Ic .SUFFIXES
1767Each source specifies a suffix to
1768.Nm .
1769If no sources are specified, any previously specified suffixes are deleted.
1770It allows the creation of suffix-transformation rules.
1771.Pp
1772Example:
1773.Bd -literal
1774\&.SUFFIXES: .o
1775\&.c.o:
1776	cc -o ${.TARGET} -c ${.IMPSRC}
1777.Ed
1778.El
1779.Sh ENVIRONMENT
1780.Nm
1781uses the following environment variables, if they exist:
1782.Ev MACHINE ,
1783.Ev MACHINE_ARCH ,
1784.Ev MAKE ,
1785.Ev MAKEFLAGS ,
1786.Ev MAKEOBJDIR ,
1787.Ev MAKEOBJDIRPREFIX ,
1788.Ev MAKESYSPATH ,
1789.Ev PWD ,
1790and
1791.Ev TMPDIR .
1792.Pp
1793.Ev MAKEOBJDIRPREFIX
1794and
1795.Ev MAKEOBJDIR
1796may only be set in the environment or on the command line to
1797.Nm
1798and not as makefile variables;
1799see the description of
1800.Ql Va .OBJDIR
1801for more details.
1802.Sh FILES
1803.Bl -tag -width /usr/share/mk -compact
1804.It .depend
1805list of dependencies
1806.It Makefile
1807list of dependencies
1808.It makefile
1809list of dependencies
1810.It sys.mk
1811system makefile
1812.It /usr/share/mk
1813system makefile directory
1814.El
1815.Sh COMPATIBILITY
1816The basic make syntax is compatible between different versions of make,
1817however the special variables, variable modifiers and conditionals are not.
1818.Pp
1819The way that parallel makes are scheduled changed in
1820.Nx 4.0
1821so that .ORDER and .WAIT apply recursively to the dependant nodes.
1822The algorithms used may change again in the future.
1823.Pp
1824The way that .for loop variables are substituted changed after
1825.Nx 5.0
1826so that they still appear to be variable expansions.
1827In particular this stops them being treated as syntax, and removes some
1828obscure problems using them in .if statements.
1829.Sh SEE ALSO
1830.Xr mkdep 1
1831.Sh HISTORY
1832A
1833.Nm
1834command appeared in
1835.At v7 .
1836.Sh BUGS
1837The
1838.Nm
1839syntax is difficult to parse without actually acting of the data.
1840For instance finding the end of a variable use should involve scanning each
1841the modifiers using the correct terminator for each field.
1842In many places
1843.Nm
1844just counts {} and () in order to find the end of a variable expansion.
1845.Pp
1846There is no way of escaping a space character in a filename.
1847