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