xref: /netbsd-src/usr.bin/make/make.1 (revision 9fbd88883c38d0c0fbfcbe66d76fe6b0fab3f9de)
1.\"	$NetBSD: make.1,v 1.58 2001/12/23 10:51:56 lukem 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. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"	from: @(#)make.1	8.4 (Berkeley) 3/19/94
35.\"
36.Dd December 23, 2001
37.Dt MAKE 1
38.Os
39.Sh NAME
40.Nm make
41.Nd maintain program dependencies
42.Sh SYNOPSIS
43.Nm ""
44.Op Fl BeikNnqrstW
45.Bk -words
46.Op Fl D Ar variable
47.Ek
48.Bk -words
49.Op Fl d Ar flags
50.Ek
51.Bk -words
52.Op Fl f Ar makefile
53.Ek
54.Bk -words
55.Op Fl I Ar directory
56.Ek
57.Bk -words
58.Op Fl j Ar max_jobs
59.Ek
60.Bk -words
61.Op Fl J Ar private
62.Ek
63.Bk -words
64.Op Fl m Ar directory
65.Ek
66.Bk -words
67.Op Fl T Ar file
68.Ek
69.Bk -words
70.Op Fl V Ar variable
71.Ek
72.Op Ar variable=value
73.Bk -words
74.Op Ar target ...
75.Ek
76.Sh DESCRIPTION
77.Nm
78is a program designed to simplify the maintenance of other programs.
79Its input is a list of specifications as to the files upon which programs
80and other files depend.
81If the file
82.Ql Pa makefile
83exists, it is read for this list of specifications.
84If it does not exist, the file
85.Ql Pa Makefile
86is read.
87If the file
88.Ql Pa .depend
89exists, it is read (see
90.Xr mkdep 1) .
91.Pp
92This manual page is intended as a reference document only.
93For a more thorough description of
94.Nm
95and makefiles, please refer to
96.%T "Make \- A Tutorial" .
97.Pp
98The options are as follows:
99.Bl -tag -width Ds
100.It Fl B
101Try to be backwards compatible by executing a single shell per command and
102by executing the commands to make the sources of a dependency line in sequence.
103.It Fl D Ar variable
104Define
105.Ar variable
106to be 1, in the global context.
107.It Fl d Ar flags
108Turn on debugging, and specify which portions of
109.Nm
110are to print debugging information.
111.Ar Flags
112is one or more of the following:
113.Bl -tag -width Ds
114.It Ar A
115Print all possible debugging information;
116equivalent to specifying all of the debugging flags.
117.It Ar a
118Print debugging information about archive searching and caching.
119.It Ar c
120Print debugging information about conditional evaluation.
121.It Ar d
122Print debugging information about directory searching and caching.
123.It Ar "g1"
124Print the input graph before making anything.
125.It Ar "g2"
126Print the input graph after making everything, or before exiting
127on error.
128.It Ar j
129Print debugging information about running multiple shells.
130.It Ar m
131Print debugging information about making targets, including modification
132dates.
133.It Ar s
134Print debugging information about suffix-transformation rules.
135.It Ar t
136Print debugging information about target list maintenance.
137.It Ar v
138Print debugging information about variable assignment.
139.It Ar x
140Run shell commands with
141.Fl x
142so the actual commands are printed as they are executed.
143.El
144.It Fl e
145Specify that environmental variables override macro assignments within
146makefiles.
147.It Fl f Ar makefile
148Specify a makefile to read instead of the default
149.Ql Pa makefile
150and
151If
152.Ar makefile
153is
154.Ql Fl ,
155standard input is read.
156Multiple makefile's may be specified, and are read in the order specified.
157.It Fl I Ar directory
158Specify a directory in which to search for makefiles and included makefiles.
159The system makefile directory (or directories, see the
160.Fl m
161option) is automatically included as part of this list.
162.It Fl i
163Ignore non-zero exit of shell commands in the makefile.
164Equivalent to specifying
165.Ql Fl
166before each command line in the makefile.
167.It Fl J Ar private
168This option should
169.Em not
170be specified by the user.
171.Pp
172When the
173.Ar j
174option is in use in a recursive build, this option is passed by a make
175to child makes to allow all the make processes in the build to
176cooperate to avoid overloading the system.
177.It Fl j Ar max_jobs
178Specify the maximum number of jobs that
179.Nm
180may have running at any one time. Turns compatibility mode off, unless the
181.Ar B
182flag is also specified.
183.It Fl k
184Continue processing after errors are encountered, but only on those targets
185that do not depend on the target whose creation caused the error.
186.It Fl m Ar directory
187Specify a directory in which to search for sys.mk and makefiles included
188via the <...> style.  Multiple directories can be added to form a search path.
189This path will override the default system include path: /usr/share/mk.
190Furthermore the system include path will be appended to the search path used
191for "..."-style inclusions (see the
192.Fl I
193option).
194.It Fl n
195Display the commands that would have been executed, but do not
196actually execute them unless the target depends on the .MAKE special
197source (see below)
198.It Fl N
199Display the commands which would have been executed, but do not
200actually execute any of them; useful for debugging top-level makefiles
201without descending into subdirectories.
202.It Fl q
203Do not execute any commands, but exit 0 if the specified targets are
204up-to-date and 1, otherwise.
205.It Fl r
206Do not use the built-in rules specified in the system makefile.
207.It Fl s
208Do not echo any commands as they are executed.
209Equivalent to specifying
210.Ql Ic @
211before each command line in the makefile.
212.It Fl T Ar tracefile
213When used with the
214.Fl j
215flag,
216append a trace record to
217.Ar tracefile
218for each job started and completed.
219.It Fl t
220Rather than re-building a target as specified in the makefile, create it
221or update its modification time to make it appear up-to-date.
222.It Fl V Ar variable
223Print
224.Nm "" Ns 's
225idea of the value of
226.Ar variable ,
227in the global context.
228Do not build any targets.
229Multiple instances of this option may be specified;
230the variables will be printed one per line,
231with a blank line for each null or undefined variable.
232.It Fl W
233Treat any warnings during makefile parsing as errors.
234.It Ar variable=value
235Set the value of the variable
236.Ar variable
237to
238.Ar value .
239.El
240.Pp
241There are seven different types of lines in a makefile: file dependency
242specifications, shell commands, variable assignments, include statements,
243conditional directives, for loops, and comments.
244.Pp
245In general, lines may be continued from one line to the next by ending
246them with a backslash
247.Pq Ql \e .
248The trailing newline character and initial whitespace on the following
249line are compressed into a single space.
250.Sh FILE DEPENDENCY SPECIFICATIONS
251Dependency lines consist of one or more targets, an operator, and zero
252or more sources.
253This creates a relationship where the targets ``depend'' on the sources
254and are usually created from them.
255The exact relationship between the target and the source is determined
256by the operator that separates them.
257The three operators are as follows:
258.Bl -tag -width flag
259.It Ic \&:
260A target is considered out-of-date if its modification time is less than
261those of any of its sources.
262Sources for a target accumulate over dependency lines when this operator
263is used.
264The target is removed if
265.Nm
266is interrupted.
267.It Ic \&!
268Targets are always re-created, but not until all sources have been
269examined and re-created as necessary.
270Sources for a target accumulate over dependency lines when this operator
271is used.
272The target is removed if
273.Nm
274is interrupted.
275.It Ic \&::
276If no sources are specified, the target is always re-created.
277Otherwise, a target is considered out-of-date if any of its sources has
278been modified more recently than the target.
279Sources for a target do not accumulate over dependency lines when this
280operator is used.
281The target will not be removed if
282.Nm
283is interrupted.
284.El
285.Pp
286Targets and sources may contain the shell wildcard values
287.Ql ? ,
288.Ql * ,
289.Ql []
290and
291.Ql {} .
292The values
293.Ql ? ,
294.Ql *
295and
296.Ql []
297may only be used as part of the final
298component of the target or source, and must be used to describe existing
299files.
300The value
301.Ql {}
302need not necessarily be used to describe existing files.
303Expansion is in directory order, not alphabetically as done in the shell.
304.Sh SHELL COMMANDS
305Each target may have associated with it a series of shell commands, normally
306used to create the target.
307Each of the commands in this script
308.Em must
309be preceded by a tab.
310While any target may appear on a dependency line, only one of these
311dependencies may be followed by a creation script, unless the
312.Ql Ic ::
313operator is used.
314.Pp
315If the first or first two characters of the command line are
316.Ql Ic @
317and/or
318.Ql Ic \- ,
319the command is treated specially.
320A
321.Ql Ic @
322causes the command not to be echoed before it is executed.
323A
324.Ql Ic \-
325causes any non-zero exit status of the command line to be ignored.
326.Sh VARIABLE ASSIGNMENTS
327Variables in make are much like variables in the shell, and, by tradition,
328consist of all upper-case letters.
329The five operators that can be used to assign values to variables are as
330follows:
331.Bl -tag -width Ds
332.It Ic \&=
333Assign the value to the variable.
334Any previous value is overridden.
335.It Ic \&+=
336Append the value to the current value of the variable.
337.It Ic \&?=
338Assign the value to the variable if it is not already defined.
339.It Ic \&:=
340Assign with expansion, i.e. expand the value before assigning it
341to the variable.
342Normally, expansion is not done until the variable is referenced.
343.It Ic \&!=
344Expand the value and pass it to the shell for execution and assign
345the result to the variable.
346Any newlines in the result are replaced with spaces.
347.El
348.Pp
349Any white-space before the assigned
350.Ar value
351is removed; if the value is being appended, a single space is inserted
352between the previous contents of the variable and the appended value.
353.Pp
354Variables are expanded by surrounding the variable name with either
355curly braces
356.Pq Ql {}
357or parentheses
358.Pq Ql ()
359and preceding it with
360a dollar sign
361.Pq Ql \&$ .
362If the variable name contains only a single letter, the surrounding
363braces or parentheses are not required.
364This shorter form is not recommended.
365.Pp
366Variable substitution occurs at two distinct times, depending on where
367the variable is being used.
368Variables in dependency lines are expanded as the line is read.
369Variables in shell commands are expanded when the shell command is
370executed.
371.Pp
372The four different classes of variables (in order of increasing precedence)
373are:
374.Bl -tag -width Ds
375.It Environment variables
376Variables defined as part of
377.Nm "" Ns 's
378environment.
379.It Global variables
380Variables defined in the makefile or in included makefiles.
381.It Command line variables
382Variables defined as part of the command line.
383.It Local variables
384Variables that are defined specific to a certain target.
385The seven local variables are as follows:
386.Bl -tag -width ".ARCHIVE"
387.It Va .ALLSRC
388The list of all sources for this target; also known as
389.Ql Va \&> .
390.It Va .ARCHIVE
391The name of the archive file.
392.It Va .IMPSRC
393The name/path of the source from which the target is to be transformed
394(the ``implied'' source); also known as
395.Ql Va \&< .
396.It Va .MEMBER
397The name of the archive member.
398.It Va .OODATE
399The list of sources for this target that were deemed out-of-date; also
400known as
401.Ql Va \&? .
402.It Va .PREFIX
403The file prefix of the file, containing only the file portion, no suffix
404or preceding directory components; also known as
405.Ql Va * .
406.It Va .TARGET
407The name of the target; also known as
408.Ql Va @ .
409.El
410.Pp
411The shorter forms
412.Ql Va @ ,
413.Ql Va ? ,
414.Ql Va \&>
415and
416.Ql Va *
417are permitted for backward
418compatibility with historical makefiles and are not recommended.
419The six variables
420.Ql Va "@F" ,
421.Ql Va "@D" ,
422.Ql Va "<F" ,
423.Ql Va "<D" ,
424.Ql Va "*F"
425and
426.Ql Va "*D"
427are
428permitted for compatibility with
429.At V
430makefiles and are not recommended.
431.Pp
432Four of the local variables may be used in sources on dependency lines
433because they expand to the proper value for each target on the line.
434These variables are
435.Ql Va .TARGET ,
436.Ql Va .PREFIX ,
437.Ql Va .ARCHIVE ,
438and
439.Ql Va .MEMBER .
440.Pp
441In addition,
442.Nm
443sets or knows about the following variables:
444.Bl -tag -width .MAKEOVERRIDES
445.It Va \&$
446A single dollar sign
447.Ql \&$ ,
448i.e.
449.Ql \&$$
450expands to a single dollar
451sign.
452.Pq Va argv[0]
453.It Va .ALLTARGETS
454The list of all targets encountered in the Makefile.  If evaluated during
455Makefile parsing, lists only those targets encountered thus far.
456.It Va .CURDIR
457A path to the directory where
458.Nm
459was executed.
460.It Va .MAKE
461The name that
462.Nm
463was executed with
464.It Ev MAKEFLAGS
465The environment variable
466.Ql Ev MAKEFLAGS
467may contain anything that
468may be specified on
469.Nm "" Ns 's
470command line.
471Anything specified on
472.Nm "" Ns 's
473command line is appended to the
474.Ql Ev MAKEFLAGS
475variable which is then
476entered into the environment for all programs which
477.Nm
478executes.
479.It Va .MAKEOVERRIDES
480This variable is used to record the names of variables assigned to
481on the command line, so that they may be exported as part of
482.Ql Ev MAKEFLAGS .
483This behaviour can be disabled by assigning an empty value to
484.Ql Va .MAKEOVERRIDES
485within a makefile.  Extra variables can be exported from a makefile
486by appending their names to
487.Ql Va .MAKEOVERRIDES .
488.Ql Ev MAKEFLAGS
489is re-exported whenever
490.Ql Va .MAKEOVERRIDES
491is modified.
492.It Va MAKE_PRINT_VAR_ON_ERROR
493When
494.Nm
495stops due to an error, it prints its name and the value of
496.Ql Va .CURDIR
497as well as the value of any variables named in
498.Ql Va MAKE_PRINT_VAR_ON_ERROR .
499.It Va .newline
500This variable is simply assigned a newline character as its value.
501This allows expansions using the :@ modifier to put a newline between
502iterations of the loop rather than a space.  For example, the printing of
503.Ql Va MAKE_PRINT_VAR_ON_ERROR
504could be done as ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}.
505.It Va .OBJDIR
506A path to the directory where the targets are built.
507.It Va .PARSEDIR
508A path to the directory of the current
509.Ql Pa Makefile
510being parsed.
511.It Va .PARSEFILE
512The basename of the current
513.Ql Pa Makefile
514being parsed.
515This variable and
516.Ql Va .PARSEDIR
517are both set only while the
518.Ql Pa Makefiles
519are being parsed.
520.It Ev PWD
521Alternate path to the current directory.
522.Nm
523normally sets
524.Ql Va .CURDIR
525to the canonical path given by
526.Xr getcwd 3 .
527However, if the environment variable
528.Ql Ev PWD
529is set and gives a path to the current directory, then
530.Nm
531sets
532.Ql Va .CURDIR
533to the value of
534.Ql Ev PWD
535instead.  This behaviour is disabled if
536.Ql Ev MAKEOBJDIRPREFIX
537is set.
538.Ql Ev PWD
539is set to the value of
540.Ql Va .OBJDIR
541for all programs which
542.Nm
543executes.
544.El
545.El
546.Pp
547Variable expansion may be modified to select or modify each word of the
548variable (where a ``word'' is white-space delimited sequence of characters).
549The general format of a variable expansion is as follows:
550.Pp
551.Dl {variable[:modifier[:...]]}
552.Pp
553Each modifier begins with a colon and one of the following
554special characters.
555The colon may be escaped with a backslash
556.Pq Ql \e .
557.Bl -tag -width Cm E\&
558.It Cm E
559Replaces each word in the variable with its suffix.
560.It Cm H
561Replaces each word in the variable with everything but the last component.
562.It Cm M Ns Ar pattern
563Select only those words that match the rest of the modifier.
564The standard shell wildcard characters
565.Pf ( Ql * ,
566.Ql ? ,
567and
568.Ql Op )
569may
570be used.
571The wildcard characters may be escaped with a backslash
572.Pq Ql \e .
573.It Cm N Ns Ar pattern
574This is identical to
575.Ql Cm M ,
576but selects all words which do not match
577the rest of the modifier.
578.It Cm O
579Order every word in variable alphabetically.
580.It Cm Q
581Quotes every shell meta-character in the variable, so that it can be passed
582safely through recursive invocations of
583.Nm "" .
584.It Cm R
585Replaces each word in the variable with everything but its suffix.
586.Sm off
587.It Cm S No \&/ Ar old_string Xo
588.No \&/ Ar new_string
589.No \&/ Op Cm 1g
590.Xc
591.Sm on
592Modify the first occurrence of
593.Ar old_string
594in the variable's value, replacing it with
595.Ar new_string .
596If a
597.Ql g
598is appended to the last slash of the pattern, all occurrences
599in each word are replaced.
600If a
601.Ql 1
602is appended to the last slash of the pattern, only the first word
603is affected.
604If
605.Ar old_string
606begins with a caret
607.Pq Ql ^ ,
608.Ar old_string
609is anchored at the beginning of each word.
610If
611.Ar old_string
612ends with a dollar sign
613.Pq Ql \&$ ,
614it is anchored at the end of each word.
615Inside
616.Ar new_string ,
617an ampersand
618.Pq Ql &
619is replaced by
620.Ar old_string
621(without any
622.Ql ^
623or
624.Ql \&$ ) .
625Any character may be used as a delimiter for the parts of the modifier
626string.
627The anchoring, ampersand and delimiter characters may be escaped with a
628backslash
629.Pq Ql \e .
630.Pp
631Variable expansion occurs in the normal fashion inside both
632.Ar old_string
633and
634.Ar new_string
635with the single exception that a backslash is used to prevent the expansion
636of a dollar sign
637.Pq Ql \&$ ,
638not a preceding dollar sign as is usual.
639.Sm off
640.It Cm C No \&/ Ar pattern Xo
641.No \&/ Ar replacement
642.No \&/ Op Cm 1g
643.Xc
644.Sm on
645The
646.Cm C
647modifier is just like the
648.Cm S
649modifier except that the old and new strings, instead of being
650simple strings, are a regular expression (see
651.Xr regex 3 )
652and an
653.Xr ed 1 Ns \-style
654replacement string.  Normally, the first occurrence of the pattern in
655each word of the value is changed.  The
656.Ql 1
657modifier causes the substitution to apply to at most one word; the
658.Ql g
659modifier causes the substitution to apply to as many instances of the
660search pattern as occur in the word or words it is found in.  Note that
661.Ql 1
662and
663.Ql g
664are orthogonal; the former specifies whether multiple words are
665potentially affected, the latter whether multiple substitutions can
666potentially occur within each affected word.
667.It Cm T
668Replaces each word in the variable with its last component.
669.It Cm u
670Remove adjacent duplicate words (like
671.Xr uniq 1 ) .
672.It Cm ? Ar true_string Cm : Ar false_string
673If the variable evaluates to true, return as its value the
674.Ar true_string ,
675otherwise return the
676.Ar false_string .
677.It Ar old_string=new_string
678This is the
679.At V
680style variable substitution.
681It must be the last modifier specified.
682If
683.Ar old_string
684or
685.Ar new_string
686do not contain the pattern matching character
687.Ar %
688then it is assumed that they are
689anchored at the end of each word, so only suffixes or entire
690words may be replaced. Otherwise
691.Ar %
692is the substring of
693.Ar old_string
694to be replaced in
695.Ar new_string
696.It Cm @ Ar temp Cm @ Xo
697.No Ar string Cm @
698.Xc
699This is the loop expansion mechanism from the OSF Development
700Environment (ODE) make.  Unlike
701.Cm \&.for
702loops expansion occurs at the time of
703reference.  Assign
704.Ar temp
705to each word in the variable and evaluate
706.Ar string .
707The ODE convention is that
708.Ar temp
709should start and end with a period. For example.
710.Dl ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@}
711.It Cm U Ar newval
712If the variable is undefined
713.Ar newval
714is the value.  This is another ODE make feature.  It is handy for
715setting per-target CFLAGS for instance:
716.Dl ${_${.TARGET:T}_CFLAGS:U${DEF_CFLAGS}}
717.It Cm D Ar newval
718If the variable is defined
719.Ar newval
720is the value.
721.It Cm L
722The name of the variable is the value.
723.It Cm P
724The path of the node which has the same name as the variable
725is the value.  If no such node exists or its path is null, then the
726name of the variable is used.
727.It Cm ! Ar cmd Cm !
728The output of running
729.Ar cmd
730is the value.
731.It Cm sh
732If the variable is non-empty it is run as a command and the output
733becomes the new value.
734.It Cm \&:= Ar str
735The variable is assigned the value
736.Ar str
737after substitution.  This modifier and its variations are useful in
738obscure situations such as wanting to apply modifiers to
739.Cm \&.for
740loop iteration variables which won't work due to the way
741.Cm \&.for
742loops are implemented.  These assignment modifiers always expand to
743nothing, so if appearing in a rule line by themselves should be
744preceded with something to keep
745.Nm
746happy.  As in:
747.Bd -literal
748use_foo: \&.USE
749\&.for i in ${\&.TARGET} ${\&.TARGET:R}\&.gz
750	@: ${t::=$i}
751	@echo t:R:T=${t:R:T}
752\&.endfor
753
754.Ed
755The double
756.Cm \&:
757helps avoid false matches with the
758.At V
759style
760.Cm \&=
761modifier and since substitution always occurs the
762.Cm \&:=
763form is vaguely appropriate.
764.It Cm \&:?= Ar str
765As for
766.Cm \&:=
767but only if the variable does not already have a value.
768.It Cm \&:+= Ar str
769Append
770.Ar str
771to the variable.
772.It Cm \&:!= Ar cmd
773Assign the output of
774.Ar cmd
775to the variable.
776.El
777.Sh INCLUDE STATEMENTS, CONDITIONALS AND FOR LOOPS
778Makefile inclusion, conditional structures and for loops  reminiscent
779of the C programming language are provided in
780.Nm "" .
781All such structures are identified by a line beginning with a single
782dot
783.Pq Ql \&.
784character.
785Files are included with either
786.Cm \&.include Aq Ar file
787or
788.Cm \&.include Pf \*q Ar file Ns \*q .
789Variables between the angle brackets or double quotes are expanded
790to form the file name.
791If angle brackets are used, the included makefile is expected to be in
792the system makefile directory.
793If double quotes are used, the including makefile's directory and any
794directories specified using the
795.Fl I
796option are searched before the system
797makefile directory.
798For compatibility with other versions of
799.Nm
800.Ql include file ...
801is also accepted. If the include statement is written as
802.Cm .-include
803or as
804.Cm .sinclude
805then errors locating and/or opening include files are ignored.
806.Pp
807Conditional expressions are also preceded by a single dot as the first
808character of a line.
809The possible conditionals are as follows:
810.Bl -tag -width Ds
811.It Ic .undef Ar variable
812Un-define the specified global variable.
813Only global variables may be un-defined.
814.It Xo
815.Ic \&.if
816.Oo \&! Oc Ns Ar expression
817.Op Ar operator expression ...
818.Xc
819Test the value of an expression.
820.It Xo
821.Ic .ifdef
822.Oo \&! Oc Ns Ar variable
823.Op Ar operator variable ...
824.Xc
825Test the value of a variable.
826.It Xo
827.Ic .ifndef
828.Oo \&! Oc Ns Ar variable
829.Op Ar operator variable ...
830.Xc
831Test the value of a variable.
832.It Xo
833.Ic .ifmake
834.Oo \&! Oc Ns Ar target
835.Op Ar operator target ...
836.Xc
837Test the target being built.
838.It Xo
839.Ic .ifnmake
840.Oo \&! Oc Ar target
841.Op Ar operator target ...
842.Xc
843Test the target being built.
844.It Ic .else
845Reverse the sense of the last conditional.
846.It Xo
847.Ic .elif
848.Oo \&! Oc Ar expression
849.Op Ar operator expression ...
850.Xc
851A combination of
852.Ql Ic .else
853followed by
854.Ql Ic .if .
855.It Xo
856.Ic .elifdef
857.Oo \&! Oc Ns Ar variable
858.Op Ar operator variable ...
859.Xc
860A combination of
861.Ql Ic .else
862followed by
863.Ql Ic .ifdef .
864.It Xo
865.Ic .elifndef
866.Oo \&! Oc Ns Ar variable
867.Op Ar operator variable ...
868.Xc
869A combination of
870.Ql Ic .else
871followed by
872.Ql Ic .ifndef .
873.It Xo
874.Ic .elifmake
875.Oo \&! Oc Ns Ar target
876.Op Ar operator target ...
877.Xc
878A combination of
879.Ql Ic .else
880followed by
881.Ql Ic .ifmake .
882.It Xo
883.Ic .elifnmake
884.Oo \&! Oc Ns Ar target
885.Op Ar operator target ...
886.Xc
887A combination of
888.Ql Ic .else
889followed by
890.Ql Ic .ifnmake .
891.It Ic .endif
892End the body of the conditional.
893.El
894.Pp
895The
896.Ar operator
897may be any one of the following:
898.Bl -tag -width "Cm XX"
899.It Cm \&|\&|
900logical OR
901.It Cm \&&&
902Logical
903.Tn AND ;
904of higher precedence than
905.Dq \&|\&| .
906.El
907.Pp
908As in C,
909.Nm
910will only evaluate a conditional as far as is necessary to determine
911its value.
912Parentheses may be used to change the order of evaluation.
913The boolean operator
914.Ql Ic \&!
915may be used to logically negate an entire
916conditional.
917It is of higher precedence than
918.Ql Ic \&&& .
919.Pp
920The value of
921.Ar expression
922may be any of the following:
923.Bl -tag -width Ic defined
924.It Ic defined
925Takes a variable name as an argument and evaluates to true if the variable
926has been defined.
927.It Ic make
928Takes a target name as an argument and evaluates to true if the target
929was specified as part of
930.Nm "" Ns 's
931command line or was declared the default target (either implicitly or
932explicitly, see
933.Va .MAIN )
934before the line containing the conditional.
935.It Ic empty
936Takes a variable, with possible modifiers, and evaluates to true if
937the expansion of the variable would result in an empty string.
938.It Ic exists
939Takes a file name as an argument and evaluates to true if the file exists.
940The file is searched for on the system search path (see
941.Va .PATH ) .
942.It Ic target
943Takes a target name as an argument and evaluates to true if the target
944has been defined.
945.It Ic commands
946Takes a target name as an argument and evaluates to true if the target
947has been defined and has commands associated with it.
948.El
949.Pp
950.Ar Expression
951may also be an arithmetic or string comparison.  Variable expansion is
952performed on both sides of the comparison, after which the integral
953values are compared.  A value is interpreted as hexadecimal if it is
954preceded by 0x, otherwise it is decimal; octal numbers are not supported.
955The standard C relational operators are all supported.  If after
956variable expansion, either the left or right hand side of a
957.Ql Ic ==
958or
959.Ql Ic "!="
960operator is not an integral value, then
961string comparison is performed between the expanded
962variables.
963If no relational operator is given, it is assumed that the expanded
964variable is being compared against 0.
965.Pp
966When
967.Nm
968is evaluating one of these conditional expression, and it encounters
969a word it doesn't recognize, either the ``make'' or ``defined''
970expression is applied to it, depending on the form of the conditional.
971If the form is
972.Ql Ic .ifdef
973or
974.Ql Ic .ifndef ,
975the ``defined'' expression
976is applied.
977Similarly, if the form is
978.Ql Ic .ifmake
979or
980.Ql Ic .ifnmake , the ``make''
981expression is applied.
982.Pp
983If the conditional evaluates to true the parsing of the makefile continues
984as before.
985If it evaluates to false, the following lines are skipped.
986In both cases this continues until a
987.Ql Ic .else
988or
989.Ql Ic .endif
990is found.
991.Pp
992For loops are typically used to apply a set of rules to a list of files.
993The syntax of a for loop is:
994.Bl -tag -width Ds
995.It Xo
996.Ic \&.for
997.Ar variable
998.Op Ar variable ...
999.Ic in
1000.Ar expression
1001.Xc
1002.It Xo
1003<make-rules>
1004.Xc
1005.It Xo
1006.Ic \&.endfor
1007.Xc
1008.El
1009After the for
1010.Ic expression
1011is evaluated, it is split into words. On each iteration of the loop,
1012one word is taken and assigned to each
1013.Ic variable ,
1014in order, and these
1015.Ic variables
1016are substituted into the
1017.Ic make-rules
1018inside the body of the for loop.
1019The number of words must come out even; that is, if there are three
1020iteration variables, the number of words provided must be a multiple
1021of three.
1022.Sh COMMENTS
1023Comments begin with a hash
1024.Pq Ql \&#
1025character, anywhere but in a shell
1026command line, and continue to the end of the line.
1027.Sh SPECIAL SOURCES
1028.Bl -tag -width Ic .IGNORE
1029.It Ic .IGNORE
1030Ignore any errors from the commands associated with this target, exactly
1031as if they all were preceded by a dash
1032.Pq Ql \- .
1033.It Ic .MADE
1034Mark all sources of this target as being up-to-date.
1035.It Ic .MAKE
1036Execute the commands associated with this target even if the
1037.Fl n
1038or
1039.Fl t
1040options were specified.
1041Normally used to mark recursive
1042.Nm "" Ns 's .
1043.It Ic .NOTMAIN
1044Normally
1045.Nm
1046selects the first target it encounters as the default target to be built
1047if no target was specified.
1048This source prevents this target from being selected.
1049.It Ic .OPTIONAL
1050If a target is marked with this attribute and
1051.Nm
1052can't figure out how to create it, it will ignore this fact and assume
1053the file isn't needed or already exists.
1054.It Ic .PRECIOUS
1055When
1056.Nm
1057is interrupted, it removes any partially made targets.
1058This source prevents the target from being removed.
1059.It Ic .SILENT
1060Do not echo any of the commands associated with this target, exactly
1061as if they all were preceded by an at sign
1062.Pq Ql @ .
1063.It Ic .USE
1064Turn the target into
1065.Nm "" Ns 's
1066version of a macro.
1067When the target is used as a source for another target, the other target
1068acquires the commands, sources, and attributes (except for
1069.Ic .USE )
1070of the
1071source.
1072If the target already has commands, the
1073.Ic .USE
1074target's commands are appended
1075to them.
1076.It Ic .USEBEFORE
1077Exactly like
1078.Ic .USE ,
1079but prepend the
1080.Ic .USEBEFORE
1081target commands to the target.
1082.It Ic .WAIT
1083If special
1084.Ic .WAIT
1085source is appears in a dependency line, the sources that precede it are
1086made before the sources that succeed it in the line.  Loops are not being
1087detected and targets that form loops will be silently ignored.
1088.El
1089.Sh SPECIAL TARGETS
1090Special targets may not be included with other targets, i.e. they must be
1091the only target specified.
1092.Bl -tag -width Ic .BEGIN
1093.It Ic .BEGIN
1094Any command lines attached to this target are executed before anything
1095else is done.
1096.It Ic .DEFAULT
1097This is sort of a
1098.Ic .USE
1099rule for any target (that was used only as a
1100source) that
1101.Nm
1102can't figure out any other way to create.
1103Only the shell script is used.
1104The
1105.Ic .IMPSRC
1106variable of a target that inherits
1107.Ic .DEFAULT Ns 's
1108commands is set
1109to the target's own name.
1110.It Ic .END
1111Any command lines attached to this target are executed after everything
1112else is done.
1113.It Ic .IGNORE
1114Mark each of the sources with the
1115.Ic .IGNORE
1116attribute.
1117If no sources are specified, this is the equivalent of specifying the
1118.Fl i
1119option.
1120.It Ic .INTERRUPT
1121If
1122.Nm
1123is interrupted, the commands for this target will be executed.
1124.It Ic .MAIN
1125If no target is specified when
1126.Nm
1127is invoked, this target will be built.
1128.It Ic .MAKEFLAGS
1129This target provides a way to specify flags for
1130.Nm
1131when the makefile is used.
1132The flags are as if typed to the shell, though the
1133.Fl f
1134option will have
1135no effect.
1136.\" XXX: NOT YET!!!!
1137.\" .It Ic .NOTPARALLEL
1138.\" The named targets are executed in non parallel mode. If no targets are
1139.\" specified, then all targets are executed in non parallel mode.
1140.It Ic .NOPATH
1141Apply the
1142.Ic .NOPATH
1143attribute to any specified sources. Targets with this attribute are not
1144searched for in the directories specified by
1145.Ic .PATH .
1146.It Ic .NOTPARALLEL
1147Disable parallel mode.
1148.It Ic .NO_PARALLEL
1149Same as above, for compatibility with other pmake variants.
1150.It Ic .ORDER
1151The named targets are made in sequence.
1152.\" XXX: NOT YET!!!!
1153.\" .It Ic .PARALLEL
1154.\" The named targets are executed in parallel mode. If no targets are
1155.\" specified, then all targets are executed in parallel mode.
1156.It Ic .PATH
1157The sources are directories which are to be searched for files not
1158found in the current directory.
1159If no sources are specified, any previously specified directories are
1160deleted.
1161If the source is the special
1162.Ic .DOTLAST
1163target, then the current working
1164directory is searched last.
1165.It Ic .PHONY
1166Apply the
1167.Ic .PHONY
1168attribute to any specified sources. Targets with this attribute do not
1169correspond to actual files; they are always considered to be out of date,
1170and will not be created with the
1171.Fl t
1172option.
1173.It Ic .PRECIOUS
1174Apply the
1175.Ic .PRECIOUS
1176attribute to any specified sources.
1177If no sources are specified, the
1178.Ic .PRECIOUS
1179attribute is applied to every
1180target in the file.
1181.It Ic .SILENT
1182Apply the
1183.Ic .SILENT
1184attribute to any specified sources.
1185If no sources are specified, the
1186.Ic .SILENT
1187attribute is applied to every
1188command in the file.
1189.It Ic .SUFFIXES
1190Each source specifies a suffix to
1191.Nm "" .
1192If no sources are specified, any previous specified suffixes are deleted.
1193.El
1194.Sh ENVIRONMENT
1195.Nm
1196utilizes the following environment variables, if they exist:
1197.Ev MACHINE ,
1198.Ev MACHINE_ARCH ,
1199.Ev MAKE ,
1200.Ev MAKEFLAGS ,
1201.Ev MAKEOBJDIR ,
1202.Ev MAKEOBJDIRPREFIX ,
1203and
1204.Ev PWD .
1205.Pp
1206If
1207.Ev MAKEOBJDIRPREFIX
1208is set, then
1209.Nm
1210will
1211.Xr chdir 2
1212to ${MAKEOBJDIRPREFIX}${.CURDIR} if it exists.
1213Otherwise if
1214.Ev MAKEOBJDIR
1215and the named directory exists
1216.Nm
1217will
1218.Xr chdir 2
1219to it.
1220These actions are taken before any makefiles are read which is why they
1221need to be set in the environment.
1222.Sh FILES
1223.Bl -tag -width /usr/share/mk -compact
1224.It .depend
1225list of dependencies
1226.It Makefile
1227list of dependencies
1228.It makefile
1229list of dependencies
1230.It sys.mk
1231system makefile
1232.It /usr/share/mk
1233system makefile directory
1234.El
1235.Sh SEE ALSO
1236.Xr mkdep 1
1237.Sh HISTORY
1238A
1239.Nm
1240command appeared in
1241.At v7 .
1242