Annotation of src/usr.bin/make/make.1, Revision 1.23
1.23 ! pk 1: .\" $NetBSD: make.1,v 1.22 1997/05/26 21:04:28 pk Exp $
1.15 thorpej 2: .\"
1.16 christos 3: .\" Copyright (c) 1990, 1993
4: .\" The Regents of the University of California. All rights reserved.
1.1 cgd 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: .\"
1.16 christos 34: .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
1.1 cgd 35: .\"
1.16 christos 36: .Dd March 19, 1994
1.1 cgd 37: .Dt MAKE 1
38: .Os
39: .Sh NAME
40: .Nm make
41: .Nd maintain program dependencies
42: .Sh SYNOPSIS
43: .Nm make
1.16 christos 44: .Op Fl Beiknqrst
1.1 cgd 45: .Op Fl D Ar variable
46: .Op Fl d Ar flags
47: .Op Fl f Ar makefile
48: .Op Fl I Ar directory
49: .Bk -words
50: .Op Fl j Ar max_jobs
1.13 christos 51: .Op Fl m Ar directory
1.1 cgd 52: .Ek
1.16 christos 53: .Op Fl V Ar variable
1.1 cgd 54: .Op Ar variable=value
55: .Op Ar target ...
56: .Sh DESCRIPTION
57: .Nm Make
58: is a program designed to simplify the maintenance of other programs.
59: Its input is a list of specifications as to the files upon which programs
60: and other files depend.
61: If the file
62: .Ql Pa makefile
63: exists, it is read for this list of specifications.
64: If it does not exist, the file
65: .Ql Pa Makefile
66: is read.
67: If the file
68: .Ql Pa .depend
69: exists, it is read (see
70: .Xr mkdep 1) .
71: .Pp
72: This manual page is intended as a reference document only.
73: For a more thorough description of
74: .Nm make
75: and makefiles, please refer to
76: .%T "Make \- A Tutorial" .
77: .Pp
78: The options are as follows:
79: .Bl -tag -width Ds
1.16 christos 80: .It Fl B
1.10 christos 81: Try to be backwards compatible by executing a single shell per command and
82: by executing the commands to make the sources of a dependency line in sequence.
1.1 cgd 83: .It Fl D Ar variable
1.8 christos 84: Define
85: .Ar variable
1.1 cgd 86: to be 1, in the global context.
87: .It Fl d Ar flags
88: Turn on debugging, and specify which portions of
89: .Nm make
90: are to print debugging information.
91: .Ar Flags
92: is one or more of the following:
93: .Bl -tag -width Ds
94: .It Ar A
95: Print all possible debugging information;
96: equivalent to specifying all of the debugging flags.
97: .It Ar a
98: Print debugging information about archive searching and caching.
99: .It Ar c
100: Print debugging information about conditional evaluation.
101: .It Ar d
102: Print debugging information about directory searching and caching.
103: .It Ar "g1"
104: Print the input graph before making anything.
105: .It Ar "g2"
106: Print the input graph after making everything, or before exiting
107: on error.
108: .It Ar j
109: Print debugging information about running multiple shells.
110: .It Ar m
111: Print debugging information about making targets, including modification
112: dates.
113: .It Ar s
114: Print debugging information about suffix-transformation rules.
115: .It Ar t
116: Print debugging information about target list maintenance.
117: .It Ar v
118: Print debugging information about variable assignment.
119: .El
120: .It Fl e
121: Specify that environmental variables override macro assignments within
122: makefiles.
123: .It Fl f Ar makefile
124: Specify a makefile to read instead of the default
125: .Ql Pa makefile
126: and
127: .Ql Pa Makefile .
128: If
129: .Ar makefile
130: is
131: .Ql Fl ,
132: standard input is read.
133: Multiple makefile's may be specified, and are read in the order specified.
134: .It Fl I Ar directory
135: Specify a directory in which to search for makefiles and included makefiles.
1.13 christos 136: The system makefile directory (or directories, see the
137: .Fl m
138: option) is automatically included as part of this list.
1.1 cgd 139: .It Fl i
140: Ignore non-zero exit of shell commands in the makefile.
141: Equivalent to specifying
142: .Ql Fl
143: before each command line in the makefile.
144: .It Fl j Ar max_jobs
145: Specify the maximum number of jobs that
146: .Nm make
1.16 christos 147: may have running at any one time. Turns compatibility mode off, unless the
1.11 christos 148: .Ar B
149: flag is also specified.
1.1 cgd 150: .It Fl k
151: Continue processing after errors are encountered, but only on those targets
152: that do not depend on the target whose creation caused the error.
1.13 christos 153: .It Fl m Ar directory
154: Specify a directory in which to search for sys.mk and makefiles included
155: via the <...> style. Multiple directories can be added to form a search path.
156: This path will override the default system include path: /usr/share/mk.
157: Furthermore the system include path will be appended to the search path used
158: for "..."-style inclusions (see the
159: .Fl I
160: option).
1.1 cgd 161: .It Fl n
162: Display the commands that would have been executed, but do not actually
163: execute them.
164: .It Fl q
165: Do not execute any commands, but exit 0 if the specified targets are
166: up-to-date and 1, otherwise.
167: .It Fl r
168: Do not use the built-in rules specified in the system makefile.
169: .It Fl s
170: Do not echo any commands as they are executed.
171: Equivalent to specifying
172: .Ql Ic @
173: before each command line in the makefile.
174: .It Fl t
175: Rather than re-building a target as specified in the makefile, create it
176: or update its modification time to make it appear up-to-date.
1.16 christos 177: .It Fl V Ar variable
178: Print
179: .Nm make Ns 's
180: idea of the value of
181: .Ar variable ,
182: in the global context.
183: Do not build any targets.
184: Multiple instances of this option may be specified;
185: the variables will be printed one per line,
186: with a blank line for each null or undefined variable.
1.1 cgd 187: .It Ar variable=value
188: Set the value of the variable
189: .Ar variable
190: to
191: .Ar value .
192: .El
193: .Pp
1.6 cgd 194: There are seven different types of lines in a makefile: file dependency
1.1 cgd 195: specifications, shell commands, variable assignments, include statements,
1.6 cgd 196: conditional directives, for loops, and comments.
1.1 cgd 197: .Pp
198: In general, lines may be continued from one line to the next by ending
199: them with a backslash
200: .Pq Ql \e .
201: The trailing newline character and initial whitespace on the following
202: line are compressed into a single space.
203: .Sh FILE DEPENDENCY SPECIFICATIONS
204: Dependency lines consist of one or more targets, an operator, and zero
205: or more sources.
206: This creates a relationship where the targets ``depend'' on the sources
207: and are usually created from them.
208: The exact relationship between the target and the source is determined
209: by the operator that separates them.
210: The three operators are as follows:
211: .Bl -tag -width flag
212: .It Ic \&:
213: A target is considered out-of-date if its modification time is less than
214: those of any of its sources.
215: Sources for a target accumulate over dependency lines when this operator
216: is used.
217: The target is removed if
218: .Nm make
219: is interrupted.
220: .It Ic \&!
221: Targets are always re-created, but not until all sources have been
222: examined and re-created as necessary.
223: Sources for a target accumulate over dependency lines when this operator
224: is used.
225: The target is removed if
226: .Nm make
227: is interrupted.
228: .It Ic \&::
229: If no sources are specified, the target is always re-created.
230: Otherwise, a target is considered out-of-date if any of its sources has
231: been modified more recently than the target.
232: Sources for a target do not accumulate over dependency lines when this
233: operator is used.
234: The target will not be removed if
235: .Nm make
236: is interrupted.
237: .El
238: .Pp
239: Targets and sources may contain the shell wildcard values
240: .Ql ? ,
241: .Ql * ,
242: .Ql []
243: and
244: .Ql {} .
245: The values
246: .Ql ? ,
247: .Ql *
248: and
249: .Ql []
250: may only be used as part of the final
251: component of the target or source, and must be used to describe existing
252: files.
253: The value
254: .Ql {}
255: need not necessarily be used to describe existing files.
256: Expansion is in directory order, not alphabetically as done in the shell.
257: .Sh SHELL COMMANDS
258: Each target may have associated with it a series of shell commands, normally
259: used to create the target.
260: Each of the commands in this script
261: .Em must
262: be preceded by a tab.
263: While any target may appear on a dependency line, only one of these
264: dependencies may be followed by a creation script, unless the
265: .Ql Ic ::
266: operator is used.
267: .Pp
268: If the first or first two characters of the command line are
269: .Ql Ic @
270: and/or
271: .Ql Ic \- ,
272: the command is treated specially.
273: A
274: .Ql Ic @
275: causes the command not to be echoed before it is executed.
276: A
277: .Ql Ic \-
278: causes any non-zero exit status of the command line to be ignored.
279: .Sh VARIABLE ASSIGNMENTS
280: Variables in make are much like variables in the shell, and, by tradition,
281: consist of all upper-case letters.
282: The five operators that can be used to assign values to variables are as
283: follows:
284: .Bl -tag -width Ds
285: .It Ic \&=
286: Assign the value to the variable.
287: Any previous value is overridden.
288: .It Ic \&+=
289: Append the value to the current value of the variable.
290: .It Ic \&?=
291: Assign the value to the variable if it is not already defined.
292: .It Ic \&:=
293: Assign with expansion, i.e. expand the value before assigning it
294: to the variable.
295: Normally, expansion is not done until the variable is referenced.
296: .It Ic \&!=
297: Expand the value and pass it to the shell for execution and assign
298: the result to the variable.
299: Any newlines in the result are replaced with spaces.
300: .El
301: .Pp
302: Any white-space before the assigned
303: .Ar value
304: is removed; if the value is being appended, a single space is inserted
305: between the previous contents of the variable and the appended value.
306: .Pp
307: Variables are expanded by surrounding the variable name with either
308: curly braces
309: .Pq Ql {}
1.7 mycroft 310: or parentheses
1.1 cgd 311: .Pq Ql ()
312: and preceding it with
313: a dollar sign
314: .Pq Ql \&$ .
315: If the variable name contains only a single letter, the surrounding
1.7 mycroft 316: braces or parentheses are not required.
1.1 cgd 317: This shorter form is not recommended.
318: .Pp
319: Variable substitution occurs at two distinct times, depending on where
320: the variable is being used.
321: Variables in dependency lines are expanded as the line is read.
322: Variables in shell commands are expanded when the shell command is
323: executed.
324: .Pp
325: The four different classes of variables (in order of increasing precedence)
326: are:
327: .Bl -tag -width Ds
328: .It Environment variables
329: Variables defined as part of
330: .Nm make Ns 's
331: environment.
332: .It Global variables
333: Variables defined in the makefile or in included makefiles.
334: .It Command line variables
335: Variables defined as part of the command line.
336: .It Local variables
337: Variables that are defined specific to a certain target.
338: The seven local variables are as follows:
339: .Bl -tag -width ".ARCHIVE"
340: .It Va .ALLSRC
341: The list of all sources for this target; also known as
342: .Ql Va \&> .
343: .It Va .ARCHIVE
344: The name of the archive file.
345: .It Va .IMPSRC
346: The name/path of the source from which the target is to be transformed
347: (the ``implied'' source); also known as
348: .Ql Va \&< .
349: .It Va .MEMBER
350: The name of the archive member.
351: .It Va .OODATE
352: The list of sources for this target that were deemed out-of-date; also
353: known as
354: .Ql Va \&? .
355: .It Va .PREFIX
356: The file prefix of the file, containing only the file portion, no suffix
357: or preceding directory components; also known as
358: .Ql Va * .
359: .It Va .TARGET
360: The name of the target; also known as
361: .Ql Va @ .
362: .El
363: .Pp
364: The shorter forms
365: .Ql Va @ ,
366: .Ql Va ? ,
367: .Ql Va \&>
368: and
369: .Ql Va *
370: are permitted for backward
371: compatibility with historical makefiles and are not recommended.
372: The six variables
373: .Ql Va "@F" ,
374: .Ql Va "@D" ,
375: .Ql Va "<F" ,
376: .Ql Va "<D" ,
377: .Ql Va "*F"
378: and
379: .Ql Va "*D"
380: are
381: permitted for compatibility with
382: .At V
383: makefiles and are not recommended.
384: .Pp
385: Four of the local variables may be used in sources on dependency lines
386: because they expand to the proper value for each target on the line.
387: These variables are
388: .Ql Va .TARGET ,
389: .Ql Va .PREFIX ,
390: .Ql Va .ARCHIVE ,
391: and
392: .Ql Va .MEMBER .
393: .Pp
394: In addition,
395: .Nm make
396: sets or knows about the following variables:
397: .Bl -tag -width MAKEFLAGS
398: .It Va \&$
399: A single dollar sign
400: .Ql \&$ ,
401: i.e.
402: .Ql \&$$
403: expands to a single dollar
404: sign.
405: .It Va .MAKE
406: The name that
407: .Nm make
408: was executed with
1.22 pk 409: .Pq Va argv[0]
1.1 cgd 410: .It Va .CURDIR
411: A path to the directory where
412: .Nm make
413: was executed.
1.4 pk 414: .It Va .OBJDIR
415: A path to the directory where the targets are built.
1.1 cgd 416: .It Ev MAKEFLAGS
417: The environment variable
418: .Ql Ev MAKEFLAGS
419: may contain anything that
420: may be specified on
421: .Nm make Ns 's
422: command line.
423: Anything specified on
424: .Nm make Ns 's
425: command line is appended to the
426: .Ql Ev MAKEFLAGS
427: variable which is then
428: entered into the environment for all programs which
429: .Nm make
430: executes.
1.16 christos 431: .It Ev PWD
432: Alternate path to the current directory.
433: .Nm make
434: normally sets
435: .Ql Va .CURDIR
436: to the canonical path given by
437: .Xr getcwd 2 .
438: However, if the environment variable
439: .Ql Ev PWD
440: is set and gives a path to the current directory, then
441: .Nm make
442: sets
443: .Ql Va .CURDIR
444: to the value of
445: .Ql Ev PWD
446: instead.
447: .Ql Ev PWD
448: is set to the value of
449: .Ql Va .OBJDIR
450: for all programs which
451: .Nm make
452: executes.
1.1 cgd 453: .El
454: .Pp
455: Variable expansion may be modified to select or modify each word of the
456: variable (where a ``word'' is white-space delimited sequence of characters).
457: The general format of a variable expansion is as follows:
458: .Pp
459: .Dl {variable[:modifier[:...]]}
460: .Pp
461: Each modifier begins with a colon and one of the following
462: special characters.
463: The colon may be escaped with a backslash
464: .Pq Ql \e .
465: .Bl -tag -width Cm E\&
466: .It Cm E
467: Replaces each word in the variable with its suffix.
468: .It Cm H
469: Replaces each word in the variable with everything but the last component.
470: .It Cm M Ns Ar pattern
471: Select only those words that match the rest of the modifier.
472: The standard shell wildcard characters
473: .Pf ( Ql * ,
474: .Ql ? ,
475: and
476: .Ql Op )
477: may
478: be used.
479: The wildcard characters may be escaped with a backslash
480: .Pq Ql \e .
481: .It Cm N Ns Ar pattern
482: This is identical to
483: .Ql Cm M ,
484: but selects all words which do not match
485: the rest of the modifier.
1.17 christos 486: .It Cm Q
487: Quotes every shell meta-character in the variable, so that it can be passed
488: safely through recursive invocations of
489: .Nm .
1.1 cgd 490: .It Cm R
491: Replaces each word in the variable with everything but its suffix.
492: .Sm off
1.17 christos 493: .It Cm S No \&/ Ar old_string Xo
494: .No \&/ Ar new_string
495: .No \&/ Op Cm 1g
1.1 cgd 496: .Xc
497: .Sm on
498: Modify the first occurrence of
1.17 christos 499: .Ar old_string
500: in the variable's value, replacing it with
501: .Ar new_string .
1.1 cgd 502: If a
503: .Ql g
504: is appended to the last slash of the pattern, all occurrences
505: in each word are replaced.
1.17 christos 506: If a
507: .Ql 1
508: is appended to the last slash of the pattern, only the first word
509: is affected.
1.1 cgd 510: If
1.17 christos 511: .Ar old_string
512: begins with a caret
1.1 cgd 513: .Pq Ql ^ ,
1.17 christos 514: .Ar old_string
1.1 cgd 515: is anchored at the beginning of each word.
516: If
1.17 christos 517: .Ar old_string
1.1 cgd 518: ends with a dollar sign
519: .Pq Ql \&$ ,
520: it is anchored at the end of each word.
521: Inside
522: .Ar new_string ,
523: an ampersand
524: .Pq Ql &
525: is replaced by
1.17 christos 526: .Ar old_string
527: (without any
528: .Ql ^
529: or
530: .Ql \&$ ) .
1.1 cgd 531: Any character may be used as a delimiter for the parts of the modifier
532: string.
533: The anchoring, ampersand and delimiter characters may be escaped with a
534: backslash
535: .Pq Ql \e .
536: .Pp
537: Variable expansion occurs in the normal fashion inside both
538: .Ar old_string
539: and
540: .Ar new_string
541: with the single exception that a backslash is used to prevent the expansion
542: of a dollar sign
1.17 christos 543: .Pq Ql \&$ ,
1.1 cgd 544: not a preceding dollar sign as is usual.
1.17 christos 545: .Sm off
546: .It Cm C No \&/ Ar pattern Xo
547: .No \&/ Ar replacement
548: .No \&/ Op Cm 1g
549: .Xc
550: .Sm on
551: The
552: .Cm C
553: modifier is just like the
554: .Cm S
555: modifier except that the the old and new strings, instead of being
556: simple strings, are a regular expression (see
557: .Xr regex 3 )
558: and an
559: .Xr ed 1 Ns \-style
560: replacement string. Normally, the first occurrence of the pattern in
561: each word of the value is changed. The
562: .Ql 1
563: modifier causes the substitution to apply to at most one word; the
564: .Ql g
565: modifier causes the substitution to apply to as many instances of the
566: search pattern as occur in the word or words it is found in. Note that
567: .Ql 1
568: and
569: .Ql g
570: are orthogonal; the former specifies whether multiple words are
571: potentially affected, the latter whether multiple substitutions can
572: potentially occur within each affected word.
1.1 cgd 573: .It Cm T
574: Replaces each word in the variable with its last component.
575: .It Ar old_string=new_string
576: This is the
577: .At V
578: style variable substitution.
579: It must be the last modifier specified.
1.16 christos 580: If
1.6 cgd 581: .Ar old_string
582: or
583: .Ar new_string
584: do not contain the pattern matching character
585: .Ar %
1.16 christos 586: then it is assumed that they are
1.6 cgd 587: anchored at the end of each word, so only suffixes or entire
1.16 christos 588: words may be replaced. Otherwise
1.6 cgd 589: .Ar %
1.16 christos 590: is the substring of
591: .Ar old_string
1.6 cgd 592: to be replaced in
593: .Ar new_string
594: .El
595: .Sh INCLUDE STATEMENTS, CONDITIONALS AND FOR LOOPS
1.16 christos 596: Makefile inclusion, conditional structures and for loops reminiscent
1.6 cgd 597: of the C programming language are provided in
1.1 cgd 598: .Nm make .
599: All such structures are identified by a line beginning with a single
600: dot
601: .Pq Ql \&.
602: character.
603: Files are included with either
604: .Ql .include <file>
605: or
606: .Ql .include \*qfile\*q .
607: Variables between the angle brackets or double quotes are expanded
608: to form the file name.
609: If angle brackets are used, the included makefile is expected to be in
610: the system makefile directory.
611: If double quotes are used, the including makefile's directory and any
612: directories specified using the
613: .Fl I
614: option are searched before the system
615: makefile directory.
616: .Pp
617: Conditional expressions are also preceded by a single dot as the first
1.5 jtc 618: character of a line.
1.1 cgd 619: The possible conditionals are as follows:
620: .Bl -tag -width Ds
621: .It Ic .undef Ar variable
622: Un-define the specified global variable.
623: Only global variables may be un-defined.
624: .It Xo
625: .Ic \&.if
626: .Oo \&! Oc Ns Ar expression
627: .Op Ar operator expression ...
628: .Xc
629: Test the value of an expression.
630: .It Xo
631: .Ic .ifdef
632: .Oo \&! Oc Ns Ar variable
633: .Op Ar operator variable ...
634: .Xc
1.7 mycroft 635: Test the value of a variable.
1.1 cgd 636: .It Xo
637: .Ic .ifndef
638: .Oo \&! Oc Ns Ar variable
639: .Op Ar operator variable ...
640: .Xc
1.7 mycroft 641: Test the value of a variable.
1.1 cgd 642: .It Xo
643: .Ic .ifmake
644: .Oo \&! Oc Ns Ar target
645: .Op Ar operator target ...
646: .Xc
1.7 mycroft 647: Test the target being built.
1.1 cgd 648: .It Xo
649: .Ic .ifnmake
650: .Oo \&! Oc Ar target
651: .Op Ar operator target ...
652: .Xc
653: Test the target being built.
654: .It Ic .else
655: Reverse the sense of the last conditional.
656: .It Xo
657: .Ic .elif
658: .Oo \&! Oc Ar expression
659: .Op Ar operator expression ...
660: .Xc
661: A combination of
662: .Ql Ic .else
663: followed by
664: .Ql Ic .if .
665: .It Xo
666: .Ic .elifdef
667: .Oo \&! Oc Ns Ar variable
668: .Op Ar operator variable ...
669: .Xc
670: A combination of
671: .Ql Ic .else
672: followed by
673: .Ql Ic .ifdef .
674: .It Xo
675: .Ic .elifndef
676: .Oo \&! Oc Ns Ar variable
677: .Op Ar operator variable ...
678: .Xc
679: A combination of
680: .Ql Ic .else
681: followed by
682: .Ql Ic .ifndef .
683: .It Xo
684: .Ic .elifmake
685: .Oo \&! Oc Ns Ar target
686: .Op Ar operator target ...
687: .Xc
688: A combination of
689: .Ql Ic .else
690: followed by
691: .Ql Ic .ifmake .
692: .It Xo
693: .Ic .elifnmake
694: .Oo \&! Oc Ns Ar target
695: .Op Ar operator target ...
696: .Xc
697: A combination of
698: .Ql Ic .else
699: followed by
700: .Ql Ic .ifnmake .
701: .It Ic .endif
702: End the body of the conditional.
703: .El
704: .Pp
705: The
706: .Ar operator
707: may be any one of the following:
708: .Bl -tag -width "Cm XX"
709: .It Cm \&|\&|
710: logical OR
711: .It Cm \&&&
712: Logical
713: .Tn AND ;
714: of higher precedence than
715: .Dq .
716: .El
717: .Pp
718: As in C,
719: .Nm make
720: will only evaluate a conditional as far as is necessary to determine
721: its value.
1.16 christos 722: Parentheses may be used to change the order of evaluation.
1.1 cgd 723: The boolean operator
724: .Ql Ic \&!
725: may be used to logically negate an entire
726: conditional.
1.5 jtc 727: It is of higher precedence than
1.1 cgd 728: .Ql Ic \&&& .
729: .Pp
730: The value of
731: .Ar expression
732: may be any of the following:
733: .Bl -tag -width Ic defined
734: .It Ic defined
735: Takes a variable name as an argument and evaluates to true if the variable
736: has been defined.
737: .It Ic make
738: Takes a target name as an argument and evaluates to true if the target
739: was specified as part of
740: .Nm make Ns 's
741: command line or was declared the default target (either implicitly or
742: explicitly, see
743: .Va .MAIN )
744: before the line containing the conditional.
745: .It Ic empty
1.5 jtc 746: Takes a variable, with possible modifiers, and evaluates to true if
1.1 cgd 747: the expansion of the variable would result in an empty string.
748: .It Ic exists
749: Takes a file name as an argument and evaluates to true if the file exists.
750: The file is searched for on the system search path (see
751: .Va .PATH ) .
752: .It Ic target
753: Takes a target name as an argument and evaluates to true if the target
754: has been defined.
755: .El
756: .Pp
757: .Ar Expression
1.6 cgd 758: may also be an arithmetic or string comparison. Variable expansion is
759: performed on both sides of the comparison, after which the integral
760: values are compared. A value is interpreted as hexadecimal if it is
761: preceded by 0x, otherwise it is decimal; octal numbers are not supported.
762: The standard C relational operators are all supported. If after
763: variable expansion, either the left or right hand side of a
1.1 cgd 764: .Ql Ic ==
765: or
766: .Ql Ic "!="
1.6 cgd 767: operator is not an integral value, then
768: string comparison is performed between the expanded
769: variables.
1.1 cgd 770: If no relational operator is given, it is assumed that the expanded
771: variable is being compared against 0.
772: .Pp
773: When
774: .Nm make
775: is evaluating one of these conditional expression, and it encounters
776: a word it doesn't recognize, either the ``make'' or ``defined''
777: expression is applied to it, depending on the form of the conditional.
778: If the form is
779: .Ql Ic .ifdef
780: or
781: .Ql Ic .ifndef ,
782: the ``defined'' expression
783: is applied.
784: Similarly, if the form is
785: .Ql Ic .ifmake
786: or
787: .Ql Ic .ifnmake , the ``make''
788: expression is applied.
789: .Pp
790: If the conditional evaluates to true the parsing of the makefile continues
791: as before.
792: If it evaluates to false, the following lines are skipped.
793: In both cases this continues until a
794: .Ql Ic .else
795: or
796: .Ql Ic .endif
797: is found.
1.16 christos 798: .Pp
1.6 cgd 799: For loops are typically used to apply a set of rules to a list of files.
800: The syntax of a for loop is:
801: .Bl -tag -width Ds
802: .It Xo
803: .Ic \&.for
1.16 christos 804: .Ar variable
805: .Ic in
1.6 cgd 806: .Ar expression
807: .Xc
808: .It Xo
809: <make-rules>
810: .Xc
811: .It Xo
812: .Ic \&.endfor
813: .Xc
814: .El
815: After the for
1.16 christos 816: .Ic expression
817: is evaluated, it is split into words. The
1.6 cgd 818: iteration
819: .Ic variable
1.16 christos 820: is successively set to each word, and substituted in the
821: .Ic make-rules
1.6 cgd 822: inside the body of the for loop.
1.1 cgd 823: .Sh COMMENTS
824: Comments begin with a hash
825: .Pq Ql \&#
826: character, anywhere but in a shell
827: command line, and continue to the end of the line.
828: .Sh SPECIAL SOURCES
829: .Bl -tag -width Ic .IGNORE
830: .It Ic .IGNORE
831: Ignore any errors from the commands associated with this target, exactly
832: as if they all were preceded by a dash
833: .Pq Ql \- .
1.18 christos 834: .It Ic .MADE
835: Mark all sources of this target as being up-to-date.
1.1 cgd 836: .It Ic .MAKE
837: Execute the commands associated with this target even if the
838: .Fl n
839: or
840: .Fl t
841: options were specified.
842: Normally used to mark recursive
843: .Nm make Ns 's .
844: .It Ic .NOTMAIN
845: Normally
846: .Nm make
847: selects the first target it encounters as the default target to be built
848: if no target was specified.
849: This source prevents this target from being selected.
850: .It Ic .OPTIONAL
851: If a target is marked with this attribute and
852: .Nm make
853: can't figure out how to create it, it will ignore this fact and assume
854: the file isn't needed or already exists.
855: .It Ic .PRECIOUS
856: When
857: .Nm make
858: is interrupted, it removes any partially made targets.
859: This source prevents the target from being removed.
860: .It Ic .SILENT
861: Do not echo any of the commands associated with this target, exactly
862: as if they all were preceded by an at sign
863: .Pq Ql @ .
864: .It Ic .USE
865: Turn the target into
1.23 ! pk 866: .Nm make Ns 's
1.1 cgd 867: version of a macro.
868: When the target is used as a source for another target, the other target
869: acquires the commands, sources, and attributes (except for
870: .Ic .USE )
871: of the
872: source.
873: If the target already has commands, the
874: .Ic .USE
875: target's commands are appended
876: to them.
1.12 christos 877: .It Ic .WAIT
878: If special
879: .Ic .WAIT
880: source is appears in a dependency line, the sources that precede it are
881: made before the sources that succeed it in the line. Loops are not being
882: detected and targets that form loops will be silently ignored.
1.1 cgd 883: .El
884: .Sh "SPECIAL TARGETS"
885: Special targets may not be included with other targets, i.e. they must be
886: the only target specified.
887: .Bl -tag -width Ic .BEGIN
888: .It Ic .BEGIN
889: Any command lines attached to this target are executed before anything
890: else is done.
891: .It Ic .DEFAULT
892: This is sort of a
893: .Ic .USE
894: rule for any target (that was used only as a
895: source) that
896: .Nm make
897: can't figure out any other way to create.
898: Only the shell script is used.
899: The
900: .Ic .IMPSRC
901: variable of a target that inherits
902: .Ic .DEFAULT Ns 's
903: commands is set
904: to the target's own name.
905: .It Ic .END
906: Any command lines attached to this target are executed after everything
907: else is done.
908: .It Ic .IGNORE
909: Mark each of the sources with the
910: .Ic .IGNORE
911: attribute.
912: If no sources are specified, this is the equivalent of specifying the
913: .Fl i
914: option.
915: .It Ic .INTERRUPT
916: If
917: .Nm make
918: is interrupted, the commands for this target will be executed.
919: .It Ic .MAIN
920: If no target is specified when
921: .Nm make
922: is invoked, this target will be built.
923: .It Ic .MAKEFLAGS
924: This target provides a way to specify flags for
925: .Nm make
926: when the makefile is used.
927: The flags are as if typed to the shell, though the
928: .Fl f
929: option will have
930: no effect.
1.12 christos 931: .\" XXX: NOT YET!!!!
932: .\" .It Ic .NOTPARALLEL
933: .\" The named targets are executed in non parallel mode. If no targets are
934: .\" specified, then all targets are executed in non parallel mode.
1.20 gwr 935: .It Ic .NOPATH
936: Apply the
937: .Ic .NOPATH
1.21 mycroft 938: attribute to any specified sources. Targets with this attribute are not
939: searched for in the directories specified by
940: .Ic .PATH .
1.12 christos 941: .It Ic .NOTPARALLEL
942: Disable parallel mode.
943: .It Ic .NO_PARALLEL
944: Same as above, for compatibility with other pmake variants.
945: .It Ic .ORDER
946: The named targets are made in sequence.
947: .\" XXX: NOT YET!!!!
948: .\" .It Ic .PARALLEL
949: .\" The named targets are executed in parallel mode. If no targets are
950: .\" specified, then all targets are executed in parallel mode.
1.1 cgd 951: .It Ic .PATH
952: The sources are directories which are to be searched for files not
953: found in the current directory.
954: If no sources are specified, any previously specified directories are
955: deleted.
1.14 christos 956: .It Ic .PHONY
957: Apply the
958: .Ic .PHONY
1.19 mycroft 959: attribute to any specified sources. Targets with this attribute do not
960: correspond to actual files; they are always considered to be out of date,
961: and will not be created with the
962: .Fl t
963: option.
1.1 cgd 964: .It Ic .PRECIOUS
965: Apply the
966: .Ic .PRECIOUS
967: attribute to any specified sources.
968: If no sources are specified, the
969: .Ic .PRECIOUS
970: attribute is applied to every
971: target in the file.
972: .It Ic .SILENT
973: Apply the
974: .Ic .SILENT
975: attribute to any specified sources.
976: If no sources are specified, the
977: .Ic .SILENT
978: attribute is applied to every
979: command in the file.
980: .It Ic .SUFFIXES
981: Each source specifies a suffix to
982: .Nm make .
1.4 pk 983: If no sources are specified, any previous specified suffices are deleted.
1.1 cgd 984: .Sh ENVIRONMENT
985: .Nm Make
986: utilizes the following environment variables, if they exist:
1.16 christos 987: .Ev MACHINE ,
1.1 cgd 988: .Ev MAKE ,
1.16 christos 989: .Ev MAKEFLAGS ,
990: .Ev MAKEOBJDIR ,
1.1 cgd 991: and
1.16 christos 992: .Ev PWD .
1.1 cgd 993: .Sh FILES
994: .Bl -tag -width /usr/share/mk -compact
995: .It .depend
996: list of dependencies
997: .It Makefile
998: list of dependencies
999: .It makefile
1000: list of dependencies
1001: .It sys.mk
1002: system makefile
1003: .It /usr/share/mk
1004: system makefile directory
1005: .El
1006: .Sh SEE ALSO
1007: .Xr mkdep 1
1008: .Sh HISTORY
1009: A
1010: .Nm Make
1011: command appeared in
1012: .At v7 .
CVSweb <webmaster@jp.NetBSD.org>