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