Annotation of src/usr.bin/make/make.1, Revision 1.99
1.99 ! espie 1: .\" $OpenBSD: make.1,v 1.98 2012/10/09 19:52:44 espie 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.
1.51 millert 15: .\" 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 16: .\" may be used to endorse or promote products derived from this software
17: .\" without specific prior written permission.
18: .\"
19: .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20: .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21: .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22: .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23: .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24: .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25: .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26: .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27: .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28: .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29: .\" SUCH DAMAGE.
30: .\"
1.9 millert 31: .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
1.1 deraadt 32: .\"
1.99 ! espie 33: .Dd $Mdocdate: October 9 2012 $
1.1 deraadt 34: .Dt MAKE 1
35: .Os
36: .Sh NAME
37: .Nm make
38: .Nd maintain program dependencies
39: .Sh SYNOPSIS
1.19 aaron 40: .Nm make
1.95 espie 41: .Op Fl BeiknpqrSst
1.1 deraadt 42: .Op Fl D Ar variable
43: .Op Fl d Ar flags
44: .Op Fl f Ar makefile
45: .Op Fl I Ar directory
1.95 espie 46: .Op Fl j Ar max_processes
1.5 niklas 47: .Op Fl m Ar directory
1.9 millert 48: .Op Fl V Ar variable
1.60 espie 49: .Op Ar NAME Ns = Ns Ar value
1.50 jmc 50: .Bk -words
1.1 deraadt 51: .Op Ar target ...
1.50 jmc 52: .Ek
1.1 deraadt 53: .Sh DESCRIPTION
1.19 aaron 54: .Nm
1.1 deraadt 55: is a program designed to simplify the maintenance of other programs.
1.95 espie 56: Its input is a
57: .Ar makefile :
1.98 espie 58: a list of specifications (target rules) describing build
1.95 espie 59: relationships between programs and other files.
60: By default, this
61: .Ar makefile
62: is determined as follows:
63: first the file
64: .Sq Pa BSDmakefile ,
65: if it exists, then the files
1.54 jmc 66: .Sq Pa makefile
1.12 niklas 67: and
1.95 espie 68: .Sq Pa Makefile ,
69: in that order.
70: If none of these files exist,
71: .Nm
72: can still rely on a set of built-in system rules.
73: .Pp
74: In addition, if the file
1.54 jmc 75: .Sq Pa .depend
1.95 espie 76: exists, it is also read on top of the main
77: .Ar makefile
78: (see
1.42 mpech 79: .Xr mkdep 1 ) .
1.1 deraadt 80: .Pp
1.43 espie 81: The handling of
1.54 jmc 82: .Sq Pa BSDmakefile
1.43 espie 83: and
1.54 jmc 84: .Sq Pa .depend
1.43 espie 85: are BSD extensions.
86: .Pp
87: Standard options are as follows:
88: .Bl -tag -width Ds
89: .It Fl e
90: Specify that environment variables override macro assignments within
91: makefiles.
92: .It Fl f Ar makefile
1.95 espie 93: Specify a makefile to read instead of the default.
1.43 espie 94: If
95: .Ar makefile
96: is
97: .Ql \- ,
98: standard input is read.
99: Multiple makefiles may be specified, and are read in the order specified.
100: .It Fl i
101: Ignore non-zero exit of shell commands in the makefile.
102: Equivalent to specifying
103: .Ql \-
104: before each command line in the makefile.
105: .It Fl k
106: Continue processing after errors are encountered, but only on those targets
107: that do not depend on the target whose creation caused the error.
108: .It Fl n
109: Display the commands that would have been executed, but do not actually
110: execute them.
1.95 espie 111: .It Fl p
112: Print a dump of the target rules and variables on stdout.
113: Do not build anything.
1.43 espie 114: .It Fl q
1.50 jmc 115: Do not execute any commands, but exit with status 0 if the specified targets
1.43 espie 116: are up-to-date, and 1 otherwise.
117: .It Fl r
118: Do not use the built-in rules specified in the system makefile.
119: .It Fl S
120: Stop processing when an error is encountered.
121: This is the default behavior.
122: This is needed to negate the
123: .Fl k
124: option during recursive builds.
125: .It Fl s
126: Do not echo commands as they are executed.
127: Equivalent to specifying
1.54 jmc 128: .Sq Ic @
1.43 espie 129: before each command line in the makefile.
130: .It Fl t
131: Rather than re-building a target as specified in the makefile, create it
132: or update its modification time to make it appear up-to-date.
1.60 espie 133: .It Ar NAME Ns = Ns Ar value
1.43 espie 134: Set the value of the variable
1.60 espie 135: .Ar NAME
1.43 espie 136: to
137: .Ar value .
138: .El
1.1 deraadt 139: .Pp
1.43 espie 140: Extended options are as follows:
1.1 deraadt 141: .Bl -tag -width Ds
1.9 millert 142: .It Fl B
1.95 espie 143: Try to be backwards compatible by executing the commands to make
144: the prerequisites in a target rule in sequence.
145: This is the default, in the absence of
146: .Fl j Ar max_processes .
1.1 deraadt 147: .It Fl D Ar variable
148: Define
149: .Ar variable
1.40 espie 150: to be 1.
1.1 deraadt 151: .It Fl d Ar flags
152: Turn on debugging, and specify which portions of
1.19 aaron 153: .Nm
1.1 deraadt 154: are to print debugging information.
1.14 aaron 155: .Ar flags
1.1 deraadt 156: is one or more of the following:
157: .Bl -tag -width Ds
158: .It Ar A
159: Print all possible debugging information;
160: equivalent to specifying all of the debugging flags.
161: .It Ar a
162: Print debugging information about archive searching and caching.
163: .It Ar c
164: Print debugging information about conditional evaluation.
165: .It Ar d
166: Print debugging information about directory searching and caching.
1.98 espie 167: .It Ar D
168: Print warning messages about multiply defined command lists.
1.94 espie 169: .It Ar e
1.95 espie 170: Print debugging information about expensive command heuristics.
1.15 espie 171: .It Ar f
1.40 espie 172: Print debugging information about the expansion of for loops.
1.1 deraadt 173: .It Ar "g1"
174: Print the input graph before making anything.
175: .It Ar "g2"
176: Print the input graph after making everything, or before exiting
177: on error.
1.98 espie 178: .It Ar h
179: Print information about jobs being held back because of sibling/target
180: groups races.
1.1 deraadt 181: .It Ar j
1.95 espie 182: Print debugging information about forking processes to run commands.
1.96 espie 183: .It Ar k
184: Print debugging information about manually killing processes.
1.40 espie 185: .It Ar l
186: Print commands in Makefile targets regardless of whether or not they are
187: prefixed by @.
188: Also known as loud behavior.
1.1 deraadt 189: .It Ar m
190: Print debugging information about making targets, including modification
191: dates.
1.82 espie 192: .It Ar n
193: Print debugging information about target names equivalence computations.
1.75 espie 194: .It Ar p
1.77 jmc 195: Help finding concurrency issues for parallel make by adding some
1.76 espie 196: randomization.
1.75 espie 197: If
198: .Va RANDOM_ORDER
199: is defined,
200: targets will be shuffled before being built.
201: If
202: .Va RANDOM_DELAY
1.76 espie 203: is defined,
1.75 espie 204: .Nm
1.95 espie 205: will wait between 0 and ${RANDOM_DELAY} seconds before starting a command.
1.75 espie 206: A given random seed can be forced by setting
207: .Va RANDOM_SEED ,
208: but this does not guarantee reproductibility.
1.94 espie 209: .It Ar q
210: .Sq quick death
211: option: after a fatal error, instead of waiting for other jobs to die,
212: kill them right away.
1.1 deraadt 213: .It Ar s
1.96 espie 214: Print debugging information about inference (suffix) transformation rules.
1.1 deraadt 215: .It Ar t
216: Print debugging information about target list maintenance.
1.98 espie 217: .It Ar T
218: Print debugging information about target group determination.
1.1 deraadt 219: .It Ar v
220: Print debugging information about variable assignment.
221: .El
222: .It Fl I Ar directory
223: Specify a directory in which to search for makefiles and included makefiles.
1.5 niklas 224: The system makefile directory (or directories, see the
225: .Fl m
226: option) is automatically included as part of this list.
1.95 espie 227: .It Fl j Ar max_processes
228: Specify the maximum number of processes that
1.19 aaron 229: .Nm
1.28 aaron 230: may have running at any one time.
1.5 niklas 231: .It Fl m Ar directory
1.50 jmc 232: Specify a directory in which to search for
233: .Pa sys.mk
1.40 espie 234: and makefiles included
1.28 aaron 235: via the <...> style.
236: Multiple directories can be added to form a search path.
1.14 aaron 237: This path will override the default system include path:
238: .Pa /usr/share/mk .
239: Furthermore, the system include path will be appended to the search path used
1.5 niklas 240: for "..."-style inclusions (see the
241: .Fl I
242: option).
1.9 millert 243: .It Fl V Ar variable
244: Print
245: .Nm make Ns 's
246: idea of the value of
1.40 espie 247: .Ar variable .
1.9 millert 248: Do not build any targets.
249: Multiple instances of this option may be specified;
250: the variables will be printed one per line,
251: with a blank line for each null or undefined variable.
1.1 deraadt 252: .El
253: .Pp
1.95 espie 254: There are seven different types of lines in a makefile: dependency
255: lines, shell commands, variable assignments, include statements,
1.1 deraadt 256: conditional directives, for loops, and comments.
1.43 espie 257: Of these, include statements, conditional directives and for loops are
258: extensions.
1.1 deraadt 259: .Pp
1.95 espie 260: A complete target rule is composed of a dependency line,
261: followed by a list of shell commands.
262: .Pp
1.1 deraadt 263: In general, lines may be continued from one line to the next by ending
264: them with a backslash
265: .Pq Ql \e .
266: The trailing newline character and initial whitespace on the following
267: line are compressed into a single space.
1.95 espie 268: .Sh DEPENDENCY LINES
1.1 deraadt 269: Dependency lines consist of one or more targets, an operator, and zero
1.95 espie 270: or more prerequisites.
1.19 aaron 271: This creates a relationship where the targets
272: .Dq depend
1.98 espie 273: on the prerequisites and are usually built from them.
1.96 espie 274: The exact relationship between targets and prerequisites is determined
1.1 deraadt 275: by the operator that separates them.
1.57 jmc 276: .Pp
1.96 espie 277: It is an error to use different dependency operators for the same target.
1.43 espie 278: .Pp
1.40 espie 279: The operators are as follows:
1.1 deraadt 280: .Bl -tag -width flag
281: .It Ic \&:
1.96 espie 282: A target is considered out-of-date if any of its prerequisites has
283: been modified more recently than the target (that is, its modification time
284: is less than that of any of its prerequisites).
285: Thus, targets with no prerequisites are always out-of-date.
286: .Pp
287: .Nm
288: will then execute the list of shell commands associated with that target.
289: .Pp
290: Additional prerequisites may be specified over additional dependency lines:
291: .Nm
292: will consider all prerequisites for determining out-of-date status.
1.1 deraadt 293: The target is removed if
1.19 aaron 294: .Nm
1.1 deraadt 295: is interrupted.
296: .It Ic \&!
1.96 espie 297: .Nm
298: first examines all prerequisites and re-creates them as necessary.
299: .Pp
300: It will then always execute the list of shell commands associated with
301: that target (as if the target always was out-of-date).
302: .Pp
303: Like
304: .Ic \&: ,
305: additional prerequisites may be specified over additional dependency lines,
306: and the target is still removed if
1.19 aaron 307: .Nm
1.1 deraadt 308: is interrupted.
309: .It Ic \&::
1.96 espie 310: Each dependency line for a target is considered independently.
311: A target is considered out-of-date for this target rule if any of its
312: prerequisites in this dependency has been modified more recently than
313: the target.
314: .Pp
315: .Nm
316: will then execute the list of shell commands associated with that target.
317: Target rules that specify no prerequisites are always executed.
318: .Pp
1.1 deraadt 319: The target will not be removed if
1.19 aaron 320: .Nm
1.1 deraadt 321: is interrupted.
322: .El
323: .Pp
1.43 espie 324: The
1.96 espie 325: .Ic \&:
326: operator is the only standard operator.
327: The
1.43 espie 328: .Ic \&::
1.96 espie 329: operator is a fairly standard extension,
330: popularized by
331: .Xr imake .
1.43 espie 332: The
1.56 jmc 333: .Ic !\&
1.43 espie 334: operator is a BSD extension.
335: .Pp
1.95 espie 336: As an extension, targets and prerequisites may contain the shell wildcard
1.43 espie 337: expressions
1.55 jmc 338: .Ql \&? ,
1.1 deraadt 339: .Ql * ,
340: .Ql []
341: and
342: .Ql {} .
1.15 espie 343: The expressions
1.55 jmc 344: .Ql \&? ,
1.1 deraadt 345: .Ql *
346: and
347: .Ql []
348: may only be used as part of the final
1.95 espie 349: component of the target or prerequisite, and must be used to describe existing
1.1 deraadt 350: files.
1.15 espie 351: The expression
1.1 deraadt 352: .Ql {}
353: need not necessarily be used to describe existing files.
354: Expansion is in directory order, not alphabetically as done in the shell.
1.43 espie 355: .Pp
356: For maximum portability, target names should only consist of periods,
357: underscores, digits and alphabetic characters.
1.96 espie 358: .Pp
1.98 espie 359: The use of several targets can be a shorthand for duplicate rules.
1.96 espie 360: Specifically,
361: .Bd -literal -offset indent
362: target1 target2: reqa reqa
363: cmd1
364: cmd2
365: .Ed
366: .Pp
1.98 espie 367: may be replaced with
1.96 espie 368: .Bd -literal -offset indent
369: target1: reqa reqa
370: cmd1
371: cmd2
372: target2: reqa reqa
373: cmd1
374: cmd2
375: .Ed
376: .Pp
1.98 espie 377: in general.
378: But
1.96 espie 379: .Nm
1.99 ! espie 380: is aware of parallel issues, and will not build those targets concurrently,
! 381: if not appropriate.
1.1 deraadt 382: .Sh SHELL COMMANDS
383: Each target may have associated with it a series of shell commands, normally
1.98 espie 384: used to build the target.
1.95 espie 385: While several dependency lines may name the same target, only one of
386: these dependency lines should be followed by shell commands, and thus
387: define a complete target rule (unless the
388: .Sq Ic ::
389: operator is used).
390: Each of the shell commands in the target rule
1.1 deraadt 391: .Em must
392: be preceded by a tab.
393: .Pp
1.34 espie 394: If a command line begins with a combination of the characters,
1.54 jmc 395: .Sq Ic @ ,
396: .Sq Ic \-
1.1 deraadt 397: and/or
1.54 jmc 398: .Sq Ic + ,
1.57 jmc 399: the command is treated specially:
1.33 espie 400: .Bl -tag -width `@'
1.54 jmc 401: .It Sq Ic @
1.1 deraadt 402: causes the command not to be echoed before it is executed.
1.54 jmc 403: .It Sq Ic \-
1.1 deraadt 404: causes any non-zero exit status of the command line to be ignored.
1.54 jmc 405: .It Sq Ic +
1.33 espie 406: causes the command to be executed even if
407: .Fl n
1.57 jmc 408: has been specified.
409: (This can be useful to debug recursive Makefiles.)
1.33 espie 410: .El
1.43 espie 411: .Pp
1.95 espie 412: Commands are always executed using
1.43 espie 413: .Pa /bin/sh
414: in
415: .Qq set -e
416: mode.
1.95 espie 417: .Pp
418: As an optimization,
419: .Nm
420: may execute very simple commands without going through an extra shell
421: process, as long as this does not change observable behavior.
1.96 espie 422: .Sh INFERENCE RULES
423: .Nm
424: also maintains a list of valid suffixes through the use of the
425: .Ic .SUFFIXES
426: special target.
427: .Pp
428: These suffixes can be used to write generic transformation rules called
429: inference rules.
430: .Pp
431: If a target has the form
432: .Sq \&.s1.s2 ,
433: where .s1 and .s2 are currently valid suffixes, then it defines a
1.98 espie 434: transformation from *.s1 to *.s2 (double suffix inference).
1.96 espie 435: If a target has the form
436: .Sq \&.s1 ,
437: where .s1 is a currently valid suffix, then it defines a
1.98 espie 438: transformation from *.s1 to * (single suffix inference).
1.96 espie 439: .Pp
440: A complete inference rule is a dependency line with such a target, the
441: normal dependency operator, no prerequisites and a list of shell commands.
442: .Pp
443: When
444: .Nm
445: requires a target for which it has no complete target rule, it will try
446: to apply a single active inference rule to create the target.
447: .Pp
448: For instance, with the following Makefile, describing a C program compiled
449: from sources a.c and b.c, with header file a.h:
450: .Bd -literal -offset indent
451: \&.SUFFIXES: .c .o
452: \&.c.o:
453: ${CC} ${CFLAGS} -c $<
454:
455: prog: a.o b.o
456: ${CC} ${CFLAGS} -o $@ a.o
457:
458: a.o b.o: a.h
459:
460: b.o: b.c
461: ${CC} -DFOO ${CFLAGS} -o $@ $<
462: .Ed
463: .Pp
464: Consider b.o:
465: there is a complete target rule re-creating it from b.c, so
466: it will be compiled using ${CC} -DFOO.
467: .Pp
468: Consider a.o:
469: there is no explicit target rule, so
470: .Nm
471: will consider valid transforms.
472: Fortunately, there is an inference rule that can create a.o from a.c,
473: so it will be compiled using ${CC}.
474: .Pp
475: Note that extra prerequisites are still taken into account, so both a.o
476: and b.o depend on a.h for re-creation.
477: .Pp
478: Valid suffixes accumulate over
479: .Ic .SUFFIXES
480: lines.
481: An empty
482: .Ic .SUFFIXES
483: can be used to reset the currently valid list of suffixes,
484: but inference rules already read are still known by
485: .Nm ,
486: and they are marked as inactive.
487: Redefining the corresponding suffix (or suffixes) will re-active the rule.
488: .Pp
489: For maximal portability, suffixes should start with a dot.
1.1 deraadt 490: .Sh VARIABLE ASSIGNMENTS
1.14 aaron 491: Variables in
1.19 aaron 492: .Nm
1.14 aaron 493: are much like variables in the shell, and, by tradition,
1.1 deraadt 494: consist of all upper-case letters.
1.60 espie 495: They are also called
496: .Sq macros
497: in various texts.
1.43 espie 498: For portability, only periods, underscores, digits and letters should be
499: used for variable names.
1.1 deraadt 500: The five operators that can be used to assign values to variables are as
501: follows:
502: .Bl -tag -width Ds
503: .It Ic \&=
504: Assign the value to the variable.
505: Any previous value is overridden.
1.43 espie 506: .It Ic \&:=
507: Assign with expansion, i.e., expand the value before assigning it
1.57 jmc 508: to the variable (extension).
1.1 deraadt 509: .It Ic \&+=
1.43 espie 510: Append the value to the current value of the variable (extension).
1.1 deraadt 511: .It Ic \&?=
1.43 espie 512: Assign the value to the variable if it is not already defined (BSD
513: extension).
1.1 deraadt 514: Normally, expansion is not done until the variable is referenced.
515: .It Ic \&!=
516: Expand the value and pass it to the shell for execution and assign
517: the result to the variable.
1.43 espie 518: Any newlines in the result are replaced with spaces (BSD extension).
1.1 deraadt 519: .El
520: .Pp
1.14 aaron 521: Any whitespace before the assigned
1.1 deraadt 522: .Ar value
523: is removed; if the value is being appended, a single space is inserted
524: between the previous contents of the variable and the appended value.
525: .Pp
526: Variables are expanded by surrounding the variable name with either
527: curly braces
528: .Pq Ql {}
529: or parentheses
530: .Pq Ql ()
531: and preceding it with
532: a dollar sign
533: .Pq Ql \&$ .
534: If the variable name contains only a single letter, the surrounding
535: braces or parentheses are not required.
536: This shorter form is not recommended.
537: .Pp
538: Variable substitution occurs at two distinct times, depending on where
539: the variable is being used.
540: Variables in dependency lines are expanded as the line is read.
541: Variables in shell commands are expanded when the shell command is
542: executed.
543: .Pp
544: The four different classes of variables (in order of increasing precedence)
545: are:
546: .Bl -tag -width Ds
547: .It Environment variables
548: Variables defined as part of
549: .Nm make Ns 's
550: environment.
551: .It Global variables
552: Variables defined in the makefile or in included makefiles.
553: .It Command line variables
554: Variables defined as part of the command line.
555: .It Local variables
556: Variables that are defined specific to a certain target.
1.43 espie 557: Standard local variables are as follows:
1.1 deraadt 558: .Bl -tag -width ".ARCHIVE"
1.43 espie 559: .It Va @
560: The name of the target.
561: .It Va \&%
562: The name of the archive member (only valid for library rules).
563: .It Va \&!
564: The name of the archive file (only valid for library rules).
565: .It Va \&?
566: The list of prerequisites for this target that were deemed out-of-date.
567: .It Va \&<
1.95 espie 568: The name of the prerequisite from which this target is to be built, if a valid
1.96 espie 569: inference rule (suffix rule) is in scope.
1.43 espie 570: .It Va *
571: The file prefix of the file, containing only the file portion,
572: no suffix or preceding directory components.
573: .El
574: .Pp
575: The six variables
1.54 jmc 576: .Sq Va "@F" ,
577: .Sq Va "@D" ,
578: .Sq Va "<F" ,
579: .Sq Va "<D" ,
580: .Sq Va "*F" ,
1.43 espie 581: and
1.54 jmc 582: .Sq Va "*D"
1.43 espie 583: yield the
584: .Qq filename
585: and
586: .Qq directory
587: parts of the corresponding macros.
588: .Pp
589: For maximum compatibility,
1.54 jmc 590: .Sq Va \&<
1.96 espie 591: should only be used for actual inference rules.
592: It is also set for normal target rules when there is an inference rule
593: that matches the current target and prerequisite in scope.
1.54 jmc 594: That is, in
1.57 jmc 595: .Bd -literal -offset indent
1.65 jmc 596: \&.SUFFIXES: .c .o
1.43 espie 597: file.o: file.c
598: cmd1 $<
599:
600: \&.c.o:
601: cmd2
602: .Ed
1.57 jmc 603: .Pp
1.43 espie 604: building
605: .Pa file.o
606: will execute
607: .Qq cmd1 file.c .
608: .Pp
609: As an extension,
610: .Nm
1.47 jsyn 611: supports the following local variables:
1.43 espie 612: .Bl -tag -width ".ARCHIVE"
613: .It Va \&>
1.95 espie 614: The list of all prerequisites for this target.
1.1 deraadt 615: .It Va .ALLSRC
1.43 espie 616: Synonym for
1.54 jmc 617: .Sq Va \&> .
1.1 deraadt 618: .It Va .ARCHIVE
1.43 espie 619: Synonym for
1.54 jmc 620: .Sq Va \&! .
1.1 deraadt 621: .It Va .IMPSRC
1.43 espie 622: Synonym for
1.54 jmc 623: .Sq Va \&< .
1.1 deraadt 624: .It Va .MEMBER
1.43 espie 625: Synonym for
1.54 jmc 626: .Sq Va \&% .
1.1 deraadt 627: .It Va .OODATE
1.43 espie 628: Synonym for
1.54 jmc 629: .Sq Va \&? .
1.1 deraadt 630: .It Va .PREFIX
1.43 espie 631: Synonym for
1.54 jmc 632: .Sq Va * .
1.1 deraadt 633: .It Va .TARGET
1.43 espie 634: Synonym for
1.54 jmc 635: .Sq Va @ .
1.1 deraadt 636: .El
637: .Pp
1.43 espie 638: These variables may be used on the dependency half of dependency
639: lines, when they make sense.
1.15 espie 640: .El
1.1 deraadt 641: .Pp
642: In addition,
1.19 aaron 643: .Nm
644: sets or knows about the following internal variables, or environment
1.15 espie 645: variables:
1.1 deraadt 646: .Bl -tag -width MAKEFLAGS
647: .It Va \&$
648: A single dollar sign
649: .Ql \&$ ,
1.29 aaron 650: i.e.,
1.1 deraadt 651: .Ql \&$$
652: expands to a single dollar
653: sign.
654: .It Va .MAKE
655: The name that
1.19 aaron 656: .Nm
1.1 deraadt 657: was executed with
1.14 aaron 658: .Pq Va argv Ns Op 0 .
1.1 deraadt 659: .It Va .CURDIR
660: A path to the directory where
1.19 aaron 661: .Nm
1.1 deraadt 662: was executed.
663: .It Va .OBJDIR
664: A path to the directory where the targets are built.
1.8 deraadt 665: At startup,
1.19 aaron 666: .Nm
1.8 deraadt 667: searches for an alternate directory to place target files -- it
668: will attempt to change into this special directory.
1.19 aaron 669: First, if
670: .Ev MAKEOBJDIRPREFIX
671: is defined,
672: .Nm
1.18 espie 673: prepends its contents to the current directory name and tries for
1.28 aaron 674: the resulting directory.
675: If that fails,
1.19 aaron 676: .Nm
1.18 espie 677: remains in the current directory.
1.19 aaron 678: If
1.15 espie 679: .Ev MAKEOBJDIRPREFIX
1.18 espie 680: is not defined,
1.19 aaron 681: .Nm
1.18 espie 682: checks
1.19 aaron 683: .Ev MAKEOBJDIR
1.28 aaron 684: and tries to change into that directory.
685: Should that fail,
1.19 aaron 686: .Nm
1.28 aaron 687: remains in the current directory.
688: If
1.18 espie 689: .Ev MAKEOBJDIR
690: is not defined, it tries to change into the directory named
691: .Pa obj.${MACHINE}
1.19 aaron 692: (see
693: .Va MACHINE
1.28 aaron 694: variable).
695: If it still has found no special directory,
1.19 aaron 696: .Nm
1.18 espie 697: next tries the directory named
698: .Pa obj .
699: If this fails,
1.19 aaron 700: .Nm
701: tries to prepend
702: .Pa /usr/obj
703: to the current directory name.
1.18 espie 704: Finally, if none of these directories are available
1.19 aaron 705: .Nm
1.8 deraadt 706: will settle for and use the current directory.
1.15 espie 707: .It Va .MAKEFLAGS
1.1 deraadt 708: The environment variable
1.14 aaron 709: .Ev MAKEFLAGS
1.1 deraadt 710: may contain anything that
711: may be specified on
712: .Nm make Ns 's
1.28 aaron 713: command line.
714: Its contents are stored in
1.15 espie 715: .Nm make Ns 's
1.19 aaron 716: .Va .MAKEFLAGS
1.15 espie 717: variable.
1.40 espie 718: Anything specified on
1.1 deraadt 719: .Nm make Ns 's
720: command line is appended to the
1.15 espie 721: .Va .MAKEFLAGS
722: variable which is then
1.19 aaron 723: entered into the environment as
1.14 aaron 724: .Ev MAKEFLAGS
1.15 espie 725: for all programs which
1.19 aaron 726: .Nm
1.1 deraadt 727: executes.
1.15 espie 728: .It Va MFLAGS
1.19 aaron 729: A shorter synonym for
1.15 espie 730: .Va .MAKEFLAGS .
1.9 millert 731: .It Ev PWD
732: Alternate path to the current directory.
1.19 aaron 733: .Nm
1.9 millert 734: normally sets
1.54 jmc 735: .Sq Va .CURDIR
1.9 millert 736: to the canonical path given by
1.49 jmc 737: .Xr getcwd 3 .
1.9 millert 738: However, if the environment variable
1.14 aaron 739: .Ev PWD
1.9 millert 740: is set and gives a path to the current directory, then
1.19 aaron 741: .Nm
1.9 millert 742: sets
1.54 jmc 743: .Sq Va .CURDIR
1.9 millert 744: to the value of
1.14 aaron 745: .Ev PWD
1.9 millert 746: instead.
1.14 aaron 747: .Ev PWD
1.15 espie 748: is always set to the value of
1.54 jmc 749: .Sq Va .OBJDIR
1.9 millert 750: for all programs which
1.19 aaron 751: .Nm
1.9 millert 752: executes.
1.15 espie 753: .It Va .TARGETS
1.19 aaron 754: List of targets
755: .Nm
1.18 espie 756: is currently building.
1.15 espie 757: .It Va MACHINE
1.19 aaron 758: Name of the machine architecture
759: .Nm
1.18 espie 760: is running on, obtained from the
761: .Ev MACHINE
1.19 aaron 762: environment variable, or through
1.44 deraadt 763: .Xr uname 3
1.18 espie 764: if not defined.
1.15 espie 765: .It Va MACHINE_ARCH
1.18 espie 766: Name of the machine architecture
1.19 aaron 767: .Nm
1.18 espie 768: was compiled for, obtained from the
1.19 aaron 769: .Ev MACHINE_ARCH
1.18 espie 770: environment variable, or defined at compilation time.
1.85 miod 771: .It Va MACHINE_CPU
772: Name of the machine processor
773: .Nm
774: was compiled for, obtained from the
775: .Ev MACHINE_CPU
776: environment variable, or defined at compilation time.
777: On processors where only one endianness is possible, the value of this
778: variable is always the same as
779: .Ev MACHINE_ARCH .
1.80 bluhm 780: .It Va MAKEFILE
781: Possibly the file name of the last makefile that has been read.
782: It should not be used; see the
783: .Sx BUGS
784: section below.
1.1 deraadt 785: .El
786: .Pp
787: Variable expansion may be modified to select or modify each word of the
1.48 pvalchev 788: variable (where
1.19 aaron 789: .Dq word
1.48 pvalchev 790: is a whitespace delimited sequence of characters).
1.1 deraadt 791: The general format of a variable expansion is as follows:
792: .Pp
793: .Dl {variable[:modifier[:...]]}
794: .Pp
795: Each modifier begins with a colon and one of the following
796: special characters.
797: The colon may be escaped with a backslash
798: .Pq Ql \e .
1.54 jmc 799: .Bl -tag -width Ds
1.58 espie 800: .It Cm :E
1.1 deraadt 801: Replaces each word in the variable with its suffix.
1.58 espie 802: .It Cm :H
1.1 deraadt 803: Replaces each word in the variable with everything but the last component.
1.58 espie 804: .It Cm :L
1.20 espie 805: Replaces each word in the variable with its lower case equivalent.
1.58 espie 806: .It Cm :U
1.20 espie 807: Replaces each word in the variable with its upper case equivalent.
1.58 espie 808: .It Cm :M Ns Ar pattern
1.1 deraadt 809: Select only those words that match the rest of the modifier.
810: The standard shell wildcard characters
811: .Pf ( Ql * ,
1.55 jmc 812: .Ql \&? ,
1.1 deraadt 813: and
1.54 jmc 814: .Ql [] )
1.1 deraadt 815: may
816: be used.
817: The wildcard characters may be escaped with a backslash
818: .Pq Ql \e .
1.58 espie 819: .It Cm :N Ns Ar pattern
1.1 deraadt 820: This is identical to
1.58 espie 821: .Cm :M ,
1.1 deraadt 822: but selects all words which do not match
823: the rest of the modifier.
1.58 espie 824: .It Cm :Q
1.10 millert 825: Quotes every shell meta-character in the variable, so that it can be passed
826: safely through recursive invocations of
1.14 aaron 827: .Nm make .
1.88 espie 828: .It Cm :QL
829: Quote list: quotes every shell meta-character in the variable, except
830: whitespace, so that it can be passed to a shell's
831: .Sq for
832: loops.
1.58 espie 833: .It Cm :R
1.1 deraadt 834: Replaces each word in the variable with everything but its suffix.
835: .Sm off
1.58 espie 836: .It Cm :S No \&/ Ar old_string Xo
1.10 millert 837: .No \&/ Ar new_string
838: .No \&/ Op Cm 1g
1.1 deraadt 839: .Xc
840: .Sm on
841: Modify the first occurrence of
1.10 millert 842: .Ar old_string
843: in the variable's value, replacing it with
844: .Ar new_string .
1.1 deraadt 845: If a
846: .Ql g
847: is appended to the last slash of the pattern, all occurrences
848: in each word are replaced.
1.10 millert 849: If a
850: .Ql 1
851: is appended to the last slash of the pattern, only the first word
852: is affected.
1.1 deraadt 853: If
1.10 millert 854: .Ar old_string
855: begins with a caret
1.1 deraadt 856: .Pq Ql ^ ,
1.10 millert 857: .Ar old_string
1.1 deraadt 858: is anchored at the beginning of each word.
859: If
1.10 millert 860: .Ar old_string
1.1 deraadt 861: ends with a dollar sign
862: .Pq Ql \&$ ,
863: it is anchored at the end of each word.
864: Inside
865: .Ar new_string ,
866: an ampersand
867: .Pq Ql &
868: is replaced by
1.10 millert 869: .Ar old_string
870: (without any
871: .Ql ^
872: or
873: .Ql \&$ ) .
1.1 deraadt 874: Any character may be used as a delimiter for the parts of the modifier
875: string.
876: The anchoring, ampersand and delimiter characters may be escaped with a
877: backslash
878: .Pq Ql \e .
879: .Pp
880: Variable expansion occurs in the normal fashion inside both
881: .Ar old_string
882: and
883: .Ar new_string
884: with the single exception that a backslash is used to prevent the expansion
885: of a dollar sign
1.10 millert 886: .Pq Ql \&$ ,
1.1 deraadt 887: not a preceding dollar sign as is usual.
1.10 millert 888: .Sm off
1.58 espie 889: .It Cm :C No \&/ Ar pattern Xo
1.10 millert 890: .No \&/ Ar replacement
891: .No \&/ Op Cm 1g
892: .Xc
893: .Sm on
894: The
1.58 espie 895: .Cm :C
1.10 millert 896: modifier is just like the
1.58 espie 897: .Cm :S
1.13 deraadt 898: modifier except that the old and new strings, instead of being
1.10 millert 899: simple strings, are a regular expression (see
900: .Xr regex 3 )
901: and an
902: .Xr ed 1 Ns \-style
1.28 aaron 903: replacement string.
904: Normally, the first occurrence of the pattern in
905: each word of the value is changed.
906: The
1.10 millert 907: .Ql 1
908: modifier causes the substitution to apply to at most one word; the
909: .Ql g
910: modifier causes the substitution to apply to as many instances of the
1.28 aaron 911: search pattern as occur in the word or words it is found in.
912: Note that
1.10 millert 913: .Ql 1
914: and
915: .Ql g
916: are orthogonal; the former specifies whether multiple words are
917: potentially affected, the latter whether multiple substitutions can
918: potentially occur within each affected word.
1.58 espie 919: .It Cm :T
1.1 deraadt 920: Replaces each word in the variable with its last component.
1.59 jmc 921: .It Ar :old_string Ns = Ns Ar new_string
1.1 deraadt 922: This is the
923: .At V
924: style variable substitution.
925: It must be the last modifier specified.
1.9 millert 926: If
1.1 deraadt 927: .Ar old_string
928: or
929: .Ar new_string
930: do not contain the pattern matching character
931: .Ar %
1.9 millert 932: then it is assumed that they are
1.1 deraadt 933: anchored at the end of each word, so only suffixes or entire
1.28 aaron 934: words may be replaced.
935: Otherwise
1.1 deraadt 936: .Ar %
1.9 millert 937: is the substring of
938: .Ar old_string
1.1 deraadt 939: to be replaced in
1.53 jmc 940: .Ar new_string .
1.88 espie 941: The right hand side
942: .Pq Ar new_string
943: may contain variable values, which will be expanded.
944: To put an actual single dollar, just double it.
1.1 deraadt 945: .El
1.53 jmc 946: .Pp
1.50 jmc 947: All modifiers are BSD extensions, except for the standard
1.46 espie 948: .At V
949: style variable substitution.
1.88 espie 950: .Pp
951: The interpretation of
952: .Ar %
953: and
954: .Ar $
955: in
956: .At V
957: variable substitutions is not mandated by POSIX, though it is
958: fairly common.
1.1 deraadt 959: .Sh INCLUDE STATEMENTS, CONDITIONALS AND FOR LOOPS
1.28 aaron 960: Makefile inclusion, conditional structures and for loops reminiscent
1.1 deraadt 961: of the C programming language are provided in
962: .Nm make .
963: All such structures are identified by a line beginning with a single
964: dot
965: .Pq Ql \&.
966: character.
1.46 espie 967: Whitespace characters may follow this dot, e.g.,
1.57 jmc 968: .Bd -literal -offset indent
969: \&.include <file>
1.46 espie 970: .Ed
971: and
1.57 jmc 972: .Bd -literal -offset indent -compact
973: \&. include <file>
1.46 espie 974: .Ed
1.57 jmc 975: .Pp
1.46 espie 976: are identical constructs.
1.1 deraadt 977: Files are included with either
978: .Ql .include <file>
979: or
980: .Ql .include \*qfile\*q .
981: Variables between the angle brackets or double quotes are expanded
982: to form the file name.
983: If angle brackets are used, the included makefile is expected to be in
984: the system makefile directory.
985: If double quotes are used, the including makefile's directory and any
986: directories specified using the
987: .Fl I
988: option are searched before the system
989: makefile directory.
990: .Pp
991: Conditional expressions are also preceded by a single dot as the first
992: character of a line.
993: The possible conditionals are as follows:
994: .Bl -tag -width Ds
995: .It Ic .undef Ar variable
996: Un-define the specified global variable.
997: Only global variables may be un-defined.
1.69 espie 998: .It Ic .poison Ar variable
999: Poison the specified global variable.
1.70 jmc 1000: Any further reference to
1.69 espie 1001: .Ar variable
1002: will be flagged as an error.
1.70 jmc 1003: .It Ic .poison !defined Pq Ar variable
1.69 espie 1004: It is an error to try to use the value of
1005: .Ar variable
1.70 jmc 1006: in a context where it is not defined.
1007: .It Ic .poison empty Pq Ar variable
1.69 espie 1008: It is an error to try to use the value of
1009: .Ar variable
1.70 jmc 1010: in a context where it is not defined or empty.
1.1 deraadt 1011: .It Xo
1012: .Ic \&.if
1013: .Oo \&! Oc Ns Ar expression
1014: .Op Ar operator expression ...
1015: .Xc
1016: Test the value of an expression.
1017: .It Xo
1018: .Ic .ifdef
1019: .Oo \&! Oc Ns Ar variable
1020: .Op Ar operator variable ...
1021: .Xc
1022: Test the value of a variable.
1023: .It Xo
1024: .Ic .ifndef
1025: .Oo \&! Oc Ns Ar variable
1026: .Op Ar operator variable ...
1027: .Xc
1028: Test the value of a variable.
1029: .It Xo
1030: .Ic .ifmake
1031: .Oo \&! Oc Ns Ar target
1032: .Op Ar operator target ...
1033: .Xc
1034: Test the target being built.
1035: .It Xo
1036: .Ic .ifnmake
1037: .Oo \&! Oc Ar target
1038: .Op Ar operator target ...
1039: .Xc
1040: Test the target being built.
1041: .It Ic .else
1042: Reverse the sense of the last conditional.
1043: .It Xo
1044: .Ic .elif
1045: .Oo \&! Oc Ar expression
1046: .Op Ar operator expression ...
1047: .Xc
1048: A combination of
1.54 jmc 1049: .Sq Ic .else
1.1 deraadt 1050: followed by
1.54 jmc 1051: .Sq Ic .if .
1.1 deraadt 1052: .It Xo
1053: .Ic .elifdef
1054: .Oo \&! Oc Ns Ar variable
1055: .Op Ar operator variable ...
1056: .Xc
1057: A combination of
1.54 jmc 1058: .Sq Ic .else
1.1 deraadt 1059: followed by
1.54 jmc 1060: .Sq Ic .ifdef .
1.1 deraadt 1061: .It Xo
1062: .Ic .elifndef
1063: .Oo \&! Oc Ns Ar variable
1064: .Op Ar operator variable ...
1065: .Xc
1066: A combination of
1.54 jmc 1067: .Sq Ic .else
1.1 deraadt 1068: followed by
1.54 jmc 1069: .Sq Ic .ifndef .
1.1 deraadt 1070: .It Xo
1071: .Ic .elifmake
1072: .Oo \&! Oc Ns Ar target
1073: .Op Ar operator target ...
1074: .Xc
1075: A combination of
1.54 jmc 1076: .Sq Ic .else
1.1 deraadt 1077: followed by
1.54 jmc 1078: .Sq Ic .ifmake .
1.1 deraadt 1079: .It Xo
1080: .Ic .elifnmake
1081: .Oo \&! Oc Ns Ar target
1082: .Op Ar operator target ...
1083: .Xc
1084: A combination of
1.54 jmc 1085: .Sq Ic .else
1.1 deraadt 1086: followed by
1.54 jmc 1087: .Sq Ic .ifnmake .
1.1 deraadt 1088: .It Ic .endif
1089: End the body of the conditional.
1090: .El
1091: .Pp
1092: The
1093: .Ar operator
1094: may be any one of the following:
1095: .Bl -tag -width "Cm XX"
1.92 jmc 1096: .It Cm ||
1.1 deraadt 1097: logical OR
1098: .It Cm \&&&
1099: Logical
1100: .Tn AND ;
1101: of higher precedence than
1.92 jmc 1102: .Cm || .
1.1 deraadt 1103: .El
1104: .Pp
1105: As in C,
1.19 aaron 1106: .Nm
1.1 deraadt 1107: will only evaluate a conditional as far as is necessary to determine
1108: its value.
1.9 millert 1109: Parentheses may be used to change the order of evaluation.
1.1 deraadt 1110: The boolean operator
1.54 jmc 1111: .Sq Ic \&!
1.1 deraadt 1112: may be used to logically negate an entire
1113: conditional.
1114: It is of higher precedence than
1.54 jmc 1115: .Sq Ic \&&& .
1.1 deraadt 1116: .Pp
1117: The value of
1118: .Ar expression
1119: may be any of the following:
1.99 ! espie 1120: .Bl -tag -width commands
1.98 espie 1121: .It Ic commands
1122: Takes a target name as an argument and evaluates to true if the target
1123: has been defined and has shell commands associated with it.
1.1 deraadt 1124: .It Ic defined
1125: Takes a variable name as an argument and evaluates to true if the variable
1126: has been defined.
1127: .It Ic make
1128: Takes a target name as an argument and evaluates to true if the target
1129: was specified as part of
1130: .Nm make Ns 's
1131: command line or was declared the default target (either implicitly or
1132: explicitly, see
1133: .Va .MAIN )
1134: before the line containing the conditional.
1135: .It Ic empty
1136: Takes a variable, with possible modifiers, and evaluates to true if
1137: the expansion of the variable would result in an empty string.
1138: .It Ic exists
1139: Takes a file name as an argument and evaluates to true if the file exists.
1140: The file is searched for on the system search path (see
1141: .Va .PATH ) .
1142: .It Ic target
1143: Takes a target name as an argument and evaluates to true if the target
1144: has been defined.
1145: .El
1146: .Pp
1.14 aaron 1147: .Ar expression
1.28 aaron 1148: may also be an arithmetic or string comparison.
1149: Variable expansion is
1.1 deraadt 1150: performed on both sides of the comparison, after which the integral
1.28 aaron 1151: values are compared.
1152: A value is interpreted as hexadecimal if it is
1.1 deraadt 1153: preceded by 0x, otherwise it is decimal; octal numbers are not supported.
1.28 aaron 1154: The standard C relational operators are all supported.
1155: If after
1.1 deraadt 1156: variable expansion, either the left or right hand side of a
1.54 jmc 1157: .Sq Ic ==
1.1 deraadt 1158: or
1.54 jmc 1159: .Sq Ic "!="
1.1 deraadt 1160: operator is not an integral value, then
1161: string comparison is performed between the expanded
1162: variables.
1163: If no relational operator is given, it is assumed that the expanded
1164: variable is being compared against 0.
1165: .Pp
1166: When
1.19 aaron 1167: .Nm
1.14 aaron 1168: is evaluating one of these conditional expressions, and it encounters
1.19 aaron 1169: a word it doesn't recognize, either the
1170: .Dq make
1171: or
1172: .Dq defined
1.1 deraadt 1173: expression is applied to it, depending on the form of the conditional.
1174: If the form is
1.54 jmc 1175: .Sq Ic .ifdef
1.1 deraadt 1176: or
1.54 jmc 1177: .Sq Ic .ifndef ,
1.19 aaron 1178: the
1179: .Dq defined
1180: expression is applied.
1.1 deraadt 1181: Similarly, if the form is
1.54 jmc 1182: .Sq Ic .ifmake
1.1 deraadt 1183: or
1.54 jmc 1184: .Sq Ic .ifnmake ,
1.19 aaron 1185: the
1186: .Dq make
1.1 deraadt 1187: expression is applied.
1188: .Pp
1189: If the conditional evaluates to true the parsing of the makefile continues
1190: as before.
1191: If it evaluates to false, the following lines are skipped.
1192: In both cases this continues until a
1.54 jmc 1193: .Sq Ic .else
1.1 deraadt 1194: or
1.54 jmc 1195: .Sq Ic .endif
1.1 deraadt 1196: is found.
1.9 millert 1197: .Pp
1.1 deraadt 1198: For loops are typically used to apply a set of rules to a list of files.
1199: The syntax of a for loop is:
1.54 jmc 1200: .Bd -unfilled -offset indent
1.91 schwarze 1201: .Ic .for Ar variable Oo Ar variable ... Oc Ic in Ar expression
1.54 jmc 1202: <make-rules>
1.91 schwarze 1203: .Ic .endfor
1.54 jmc 1204: .Ed
1205: .Pp
1.1 deraadt 1206: After the for
1.14 aaron 1207: .Ar expression
1.28 aaron 1208: is evaluated, it is split into words.
1.50 jmc 1209: On each iteration of the loop, one word is assigned to each
1.41 espie 1210: .Ar variable ,
1211: in order,
1.50 jmc 1212: and these
1213: .Ar variables
1.41 espie 1214: are substituted in the
1.9 millert 1215: .Ic make-rules
1.1 deraadt 1216: inside the body of the for loop.
1.41 espie 1217: The number of words must match the number of iteration variables;
1218: that is, if there are three iteration variables, the number of words
1.48 pvalchev 1219: must be a multiple of three.
1.45 espie 1220: .Pp
1221: Loops and conditional expressions may nest arbitrarily, but
1222: they may not cross include file boundaries.
1.1 deraadt 1223: .Sh COMMENTS
1224: Comments begin with a hash
1225: .Pq Ql \&#
1226: character, anywhere but in a shell
1.98 espie 1227: command line, and continue to the end of the line
1228: (but a
1229: .Pq Ql \&#
1230: character in a shell command line will be interpreted as a comment by
1231: the shell).
1.97 espie 1232: .Sh TARGET ATTRIBUTES
1233: Some targets may be tagged with some specific attributes by one
1234: of the
1235: .Sx SPECIAL TARGETS
1236: or
1237: .Sx SPECIAL PREREQUISITES
1238: described below.
1239: .Bl -tag -width "Ignoring errors"
1240: .It Dq Always build
1241: Run the commands associated with this target even if the
1242: .Fl n
1243: or
1244: .Fl t
1245: options were specified.
1246: Can be used to mark recursive
1247: .Nm make Ns 's ,
1248: but prefer standard
1249: .Sq Ic + Ns Ar cmd .
1250: .It Dq Cheap
1251: In parallel mode, don't scan the commands for occurrences of
1252: .Nm ,
1253: thus letting normal recursive
1254: .Fl j
1255: behavior apply.
1256: .It Dq Expensive
1257: In parallel mode, assume commands will invoke recursive commands.
1258: Once
1259: .Nm
1260: starts building an expensive target, it won't start building anything else
1261: until that target has finished building.
1262: .It Dq Ignoring errors
1263: Ignore any errors generating by running shell commands, exactly
1264: as if they were all preceded by a dash
1.1 deraadt 1265: .Pq Ql \- .
1.97 espie 1266: .It Dq Phony
1267: A phony target is a target that does not correspond to any object in the
1268: file system (more like a placeholder for a list of commands).
1269: .Pp
1270: Phony targets are always out-of-date at the start of a run, but
1271: .Nm
1272: still keeps track of when they are built (that is, when the associated
1273: command list finishes running).
1274: .It Dq Precious
1275: Don't remove the target if
1276: .Nm
1277: is interrupted in the middle of building it.
1278: .It Dq Silent
1279: Do not display shell commands before running them, exactly as
1280: if they were all preceded by a
1281: .Sq @ .
1282: .El
1283: .Sh SPECIAL TARGETS
1.19 aaron 1284: .Nm
1.97 espie 1285: recognizes standard special targets:
1286: .Bl -tag -width ".NOTPARALLEL"
1287: .It Ic .DEFAULT
1288: If there is a
1289: .Ic .DEFAULT
1290: target rule, with commands but no prequisites, and
1291: .Nm
1292: can't figure out another way to build a target, it will use that
1293: list of commands, setting
1294: .Va \&<
1295: and
1296: .Va @
1297: appropriately.
1298: .It Ic .IGNORE
1299: Mark its prerequisites as
1300: .Dq Ignoring errors .
1301: .Pp
1302: If the list of prerequisites is empty, apply that to all targets, exactly
1303: like the
1304: .Fl i
1305: command-line option.
1.1 deraadt 1306: .It Ic .PRECIOUS
1.97 espie 1307: Mark its prerequisites as
1308: .Dq Precious .
1309: .Pp
1310: If the list of prerequisites is empty, apply that to all targets.
1.1 deraadt 1311: .It Ic .SILENT
1.97 espie 1312: Mark its prerequisites as
1313: .Dq Silent .
1314: .Pp
1315: If the list of prerequisites is empty, apply that to all targets, exactly
1316: like the
1317: .Fl s
1318: command-line option.
1319: .It Ic .SUFFIXES
1320: See
1321: .Sx INFERENCE RULES .
1.1 deraadt 1322: .El
1.97 espie 1323: .Pp
1324: and also some other special targets as an extension:
1.54 jmc 1325: .Bl -tag -width ".NOTPARALLEL"
1.1 deraadt 1326: .It Ic .BEGIN
1.97 espie 1327: Command lines attached to this target are executed before anything
1.1 deraadt 1328: else is done.
1.93 espie 1329: .It Ic .CHEAP
1.97 espie 1330: Mark its prerequisites as
1331: .Dq Cheap .
1.1 deraadt 1332: .It Ic .END
1.97 espie 1333: Command lines attached to this target are executed at the end of a successful
1334: run.
1.93 espie 1335: .It Ic .EXPENSIVE
1.97 espie 1336: Mark its prerequisites as
1337: .Dq Expensive .
1338: .It Ic .INTERRUPT
1339: Command lines attached to this target are executed if
1340: .Nm
1341: is interrupted by a SIGINT.
1.95 espie 1342: .It Ic .MADE
1.97 espie 1343: Mark its prerequisites as being up-to-date.
1.95 espie 1344: .It Ic .MAKE
1.97 espie 1345: Mark its prerequisites as
1346: .Dq Always build .
1347: Prefer standard
1.95 espie 1348: .Sq Ic + Ns Ar cmd .
1.1 deraadt 1349: .It Ic .MAIN
1350: If no target is specified when
1.19 aaron 1351: .Nm
1.28 aaron 1352: is invoked, this target will be built.
1353: This is always set, either
1.19 aaron 1354: explicitly, or implicitly when
1355: .Nm
1.16 espie 1356: selects the default target, to give the user a way to refer to the default
1357: target on the command line.
1.1 deraadt 1358: .It Ic .MAKEFLAGS
1359: This target provides a way to specify flags for
1.19 aaron 1360: .Nm
1.1 deraadt 1361: when the makefile is used.
1362: The flags are as if typed to the shell, though the
1363: .Fl f
1364: option will have
1365: no effect.
1.4 deraadt 1366: .It Ic .NOTPARALLEL
1.98 espie 1367: Disable parallel mode for the current makefile.
1368: The
1369: .Fl j
1370: option is still passed to submakes.
1.4 deraadt 1371: .It Ic .NO_PARALLEL
1372: Same as above, for compatibility with other pmake variants.
1373: .It Ic .ORDER
1.97 espie 1374: The list of prerequisites should be built in sequence.
1.1 deraadt 1375: .It Ic .PATH
1.97 espie 1376: The prerequisites define a search path: directories that will be searched
1377: for files not found in the current directory.
1.95 espie 1378: If no prerequisites are specified, any previously specified directories are
1.1 deraadt 1379: deleted.
1.97 espie 1380: .It Ic .PATH\fI.suffix\fR
1381: This target is only valid if .suffix is a currently valid suffix.
1382: The prerequisites defines a search path for files ending in that suffix.
1383: For files not found in the current directory,
1.19 aaron 1384: .Nm
1.97 espie 1385: will first look in that path, before reverting to the default search path.
1.6 niklas 1386: .It Ic .PHONY
1.97 espie 1387: Mark its prerequisites as
1388: .Dq Phony
1389: targets.
1390: .El
1.98 espie 1391: .Pp
1392: It is an error to use several special targets, or a special target and
1393: normal targets, in a single dependency line.
1.97 espie 1394: .Sh SPECIAL PREREQUISITES
1.98 espie 1395: Of the special targets described in the previous
1396: section, the ones that tag prerequisites can also be used as prerequisites,
1397: in which case the corresponding targets will be tagged accordingly.
1398: .Pp
1399: This is an extension, even for standard special targets.
1400: .Pp
1401: .Nm
1402: also recognizes some other prerequisites:
1.97 espie 1403: .Bl -tag -width ".PRECIOUS"
1404: .It Ic .NOTMAIN
1405: Normally
1406: .Nm
1407: selects the first target it encounters as the default target to be built
1408: if no target was specified.
1409: This prerequisite prevents this target from being selected.
1410: .It Ic .OPTIONAL
1411: If a target is marked with this attribute and
1412: .Nm
1413: can't figure out how to create it, it will ignore this fact and assume
1414: the file isn't needed or already exists.
1415: .It Ic .USE
1416: Turn the target into
1417: .Nm make Ns 's
1418: version of a macro.
1419: When the target is used as a prerequisite for another target, the other target
1420: acquires the commands, prerequisites, and attributes (except for
1421: .Ic .USE )
1422: of the
1423: prerequisite.
1424: If the target already has commands, the
1425: .Ic .USE
1426: target's commands are appended
1427: to them.
1428: .It Ic .WAIT
1429: If
1430: .Ic .WAIT
1431: appears in a dependency line, the prerequisites that precede it are
1432: made before the prerequisites that follow it in the line.
1433: Loops are not
1434: detected and targets that form loops will be silently ignored.
1.35 aaron 1435: .El
1.1 deraadt 1436: .Sh ENVIRONMENT
1.19 aaron 1437: .Nm
1.15 espie 1438: uses the following environment variables, if they exist:
1.9 millert 1439: .Ev MACHINE ,
1.15 espie 1440: .Ev MACHINE_ARCH ,
1.86 jmc 1441: .Ev MACHINE_CPU ,
1.9 millert 1442: .Ev MAKEFLAGS ,
1443: .Ev MAKEOBJDIR ,
1.15 espie 1444: .Ev MAKEOBJDIRPREFIX ,
1.1 deraadt 1445: and
1.9 millert 1446: .Ev PWD .
1.30 espie 1447: .Nm
1.31 aaron 1448: also ignores and unsets
1.30 espie 1449: .Ev CDPATH .
1.1 deraadt 1450: .Sh FILES
1451: .Bl -tag -width /usr/share/mk -compact
1.14 aaron 1452: .It Pa .depend
1.1 deraadt 1453: list of dependencies
1.15 espie 1454: .It Pa BSDmakefile
1.66 jmc 1455: default makefile
1456: .It Pa makefile
1457: default makefile if
1458: .Pa BSDmakefile
1459: does not exist
1.14 aaron 1460: .It Pa Makefile
1.66 jmc 1461: default makefile if
1462: .Pa makefile
1463: does not exist
1.14 aaron 1464: .It Pa sys.mk
1.1 deraadt 1465: system makefile
1.14 aaron 1466: .It Pa /usr/share/mk
1.1 deraadt 1467: system makefile directory
1.62 jmc 1468: .It Pa /usr/obj
1.19 aaron 1469: default
1.52 jmc 1470: .Ev MAKEOBJDIRPREFIX
1.57 jmc 1471: directory
1.1 deraadt 1472: .El
1.89 jmc 1473: .Sh EXIT STATUS
1474: If
1475: .Fl q
1476: was specified, the
1477: .Nm
1478: utility exits with one of the following values:
1479: .Pp
1480: .Bl -tag -width Ds -offset indent -compact
1481: .It 0
1482: Normal behavior.
1483: .It 1
1484: The target was not up-to date.
1485: .It \*(Gt1
1486: An error occurred.
1487: .El
1488: .Pp
1489: Otherwise, the
1490: .Nm
1491: utility exits with a value of 0 on success, and \*(Gt0 if an error occurred.
1.37 aaron 1492: .Sh SEE ALSO
1.57 jmc 1493: .Xr ed 1 ,
1494: .Xr mkdep 1 ,
1495: .Xr sh 1 ,
1496: .Xr getcwd 3 ,
1497: .Xr regex 3 ,
1498: .Xr uname 3
1.52 jmc 1499: .Sh STANDARDS
1.67 jmc 1500: The
1.43 espie 1501: .Nm
1.95 espie 1502: utility is mostly compliant with the
1.83 jmc 1503: .St -p1003.1-2008
1.95 espie 1504: specification.
1.67 jmc 1505: .Pp
1506: The flags
1.95 espie 1507: .Op Fl BDdIjmV
1.67 jmc 1508: are extensions to that specification.
1.43 espie 1509: .Pp
1.37 aaron 1510: Older versions of
1511: .Nm
1512: used
1513: .Ev MAKE
1514: instead of
1515: .Ev MAKEFLAGS .
1516: This was removed for POSIX compatibility.
1517: The internal variable
1518: .Va MAKE
1519: is set to the same value as
1.48 pvalchev 1520: .Va .MAKE .
1521: Support for this may be removed in the future.
1.37 aaron 1522: .Pp
1523: Most of the more esoteric features of
1524: .Nm
1525: should probably be avoided for greater compatibility.
1526: .Sh HISTORY
1527: A
1528: .Nm
1529: command appeared in
1530: .At v7 .
1.95 espie 1531: .Pp
1532: This implementation is a distant derivative of
1533: .Nm pmake ,
1534: originally written by Adam de Boor.
1.17 espie 1535: .Sh BUGS
1.18 espie 1536: The determination of
1537: .Va .OBJDIR
1.19 aaron 1538: is contorted to the point of absurdity.
1.18 espie 1539: .Pp
1.98 espie 1540: If the same target is specified several times in complete target rules,
1.31 aaron 1541: .Nm
1.98 espie 1542: ignores all commands after the first non empty set of commands,
1.31 aaron 1543: e.g., in
1.57 jmc 1544: .Bd -literal -offset indent
1.27 espie 1545: a:
1546: @echo "Executed"
1547: a:
1548: @echo "Bad luck"
1549: .Ed
1550: .Pp
1.98 espie 1551: @echo "Bad luck" will be ignored.
1.18 espie 1552: .Pp
1553: .Va .TARGETS
1554: is not set to the default target when
1.19 aaron 1555: .Nm
1.18 espie 1556: is invoked without a target name and no
1.19 aaron 1557: .Ic MAIN
1.18 espie 1558: special target exists.
1559: .Pp
1.17 espie 1560: The evaluation of
1561: .Ar expression
1.98 espie 1562: in a test is somewhat simplistic.
1.99 ! espie 1563: Variables don't need to be quoted, but strings do:
1.98 espie 1564: Tests like
1.64 mbalmer 1565: .Ql .if ${VAR} == "string" ,
1.99 ! espie 1566: .Ql .if ${VAR} >= 5 ,
! 1567: .Ql .if 5 <= 10 ,
1.98 espie 1568: and
1569: .Ql .if "string" == ${VAR}
1570: do work, but
1571: .Ql .if string = ${VAR}
1.99 ! espie 1572: doesn't.
1.17 espie 1573: .Pp
1574: For loops are expanded before tests, so a fragment such as:
1.57 jmc 1575: .Bd -literal -offset indent
1.17 espie 1576: \&.for TMACHINE in ${SHARED_ARCHS}
1.98 espie 1577: \&.if "${TMACHINE}" == ${MACHINE}
1.17 espie 1578: ...
1579: \&.endif
1.32 ericj 1580: \&.endfor
1.17 espie 1581: .Ed
1.25 espie 1582: .Pp
1.98 espie 1583: requires the quotes.
1.21 espie 1584: .Pp
1.31 aaron 1585: When handling pre-BSD 4.4 archives,
1.21 espie 1586: .Nm
1587: may erroneously mark archive members as out of date if the archive name
1588: was truncated.
1.26 espie 1589: .Pp
1.57 jmc 1590: The handling of
1591: .Sq ;\&
1592: and other special characters in tests may be utterly bogus.
1.28 aaron 1593: For instance, in
1.57 jmc 1594: .Bd -literal -offset indent
1.25 espie 1595: \&A=abcd;c.c
1596: \&.if ${A:R} == "abcd;c"
1597: .Ed
1598: .Pp
1599: the test will never match, even though the value is correct.
1.26 espie 1600: .Pp
1.28 aaron 1601: The conditional handler is incredibly lame.
1602: Junk such as
1.57 jmc 1603: .Pp
1604: .Dl \&.if defined anything goes (A)
1.26 espie 1605: .Pp
1606: will be accepted silently.
1.25 espie 1607: .Pp
1.57 jmc 1608: In a .for loop, only the variable value is used; assignments will be
1.25 espie 1609: evaluated later, e.g., in
1.57 jmc 1610: .Bd -literal -offset indent
1.25 espie 1611: \&.for I in a b c d
1612: I:=${I:S/a/z}
1613: A+=$I
1614: \&.endfor
1615: .Ed
1.57 jmc 1616: .Pp
1617: .Sq A
1618: will evaluate to a b c d after the loop, not z b c d.
1.73 espie 1619: .Pp
1620: .Ic ORDER
1.95 espie 1621: is currently only used in parallel mode, so
1622: keep prerequisites ordered for sequential mode!
1.78 espie 1623: .Pp
1.79 jmc 1624: Distinct target names are treated separately, even though they might
1.78 espie 1625: correspond to the same file in the file system.
1626: This can cause excessive rebuilds of some targets, and bogus
1627: races in parallel mode.
1628: This can also prevent
1629: .Nm
1630: from finding a rule to solve a dependency if the target name is not
1631: exactly the same as the dependency.
1632: .Pp
1633: In parallel mode,
1634: .Fl j Ar n
1.95 espie 1635: only limits the number of direct children of
1636: .Nm .
1637: During recursive invocations, each level may multiply the total number
1.78 espie 1638: of processes by
1.79 jmc 1639: .Ar n .
1.95 espie 1640: However,
1641: .Nm
1642: includes some heuristics to try to prevent catastrophic behavior:
1643: if a command is marked as expensive, or preceded by
1644: .Sq + ,
1645: or seems to
1646: invoke a program that looks sufficiently like
1647: .Sq make ,
1648: .Nm
1649: will assume recursive invocation, and not start any new process until
1650: said command has finished running.
1651: Thus the number of processes run directly or indirectly by
1652: .Nm
1653: will increase linearly with each level of recursion instead of exponentially.
1.80 bluhm 1654: .Pp
1655: The
1656: .Va MAKEFILE
1657: variable cannot be used reliably.
1658: It is a compatibility feature and may get set to the last makefile
1659: specified, as it is set by System V make.