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