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