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