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