[BACK]Return to make.1 CVS log [TXT][DIR] Up to [local] / src / usr.bin / make

Annotation of src/usr.bin/make/make.1, Revision 1.98

1.98    ! espie       1: .\"    $OpenBSD: make.1,v 1.97 2012/10/06 18:41:53 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.98    ! espie      33: .Dd $Mdocdate: October 6 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.98    ! espie     380: is aware of parallel issues, and will not build those targets concurrently.
1.1       deraadt   381: .Sh SHELL COMMANDS
                    382: Each target may have associated with it a series of shell commands, normally
1.98    ! espie     383: used to build the target.
1.95      espie     384: While several dependency lines may name the same target, only one of
                    385: these dependency lines should be followed by shell commands, and thus
                    386: define a complete target rule (unless the
                    387: .Sq Ic ::
                    388: operator is used).
                    389: Each of the shell commands in the target rule
1.1       deraadt   390: .Em must
                    391: be preceded by a tab.
                    392: .Pp
1.34      espie     393: If a command line begins with a combination of the characters,
1.54      jmc       394: .Sq Ic @ ,
                    395: .Sq Ic \-
1.1       deraadt   396: and/or
1.54      jmc       397: .Sq Ic + ,
1.57      jmc       398: the command is treated specially:
1.33      espie     399: .Bl -tag -width `@'
1.54      jmc       400: .It Sq Ic @
1.1       deraadt   401: causes the command not to be echoed before it is executed.
1.54      jmc       402: .It Sq Ic \-
1.1       deraadt   403: causes any non-zero exit status of the command line to be ignored.
1.54      jmc       404: .It Sq Ic +
1.33      espie     405: causes the command to be executed even if
                    406: .Fl n
1.57      jmc       407: has been specified.
                    408: (This can be useful to debug recursive Makefiles.)
1.33      espie     409: .El
1.43      espie     410: .Pp
1.95      espie     411: Commands are always executed using
1.43      espie     412: .Pa /bin/sh
                    413: in
                    414: .Qq set -e
                    415: mode.
1.95      espie     416: .Pp
                    417: As an optimization,
                    418: .Nm
                    419: may execute very simple commands without going through an extra shell
                    420: process, as long as this does not change observable behavior.
1.96      espie     421: .Sh INFERENCE RULES
                    422: .Nm
                    423: also maintains a list of valid suffixes through the use of the
                    424: .Ic .SUFFIXES
                    425: special target.
                    426: .Pp
                    427: These suffixes can be used to write generic transformation rules called
                    428: inference rules.
                    429: .Pp
                    430: If a target has the form
                    431: .Sq \&.s1.s2 ,
                    432: where .s1 and .s2 are currently valid suffixes, then it defines a
1.98    ! espie     433: transformation from *.s1 to *.s2 (double suffix inference).
1.96      espie     434: If a target has the form
                    435: .Sq \&.s1 ,
                    436: where .s1 is a currently valid suffix, then it defines a
1.98    ! espie     437: transformation from *.s1 to * (single suffix inference).
1.96      espie     438: .Pp
                    439: A complete inference rule is a dependency line with such a target, the
                    440: normal dependency operator, no prerequisites and a list of shell commands.
                    441: .Pp
                    442: When
                    443: .Nm
                    444: requires a target for which it has no complete target rule, it will try
                    445: to apply a single active inference rule to create the target.
                    446: .Pp
                    447: For instance, with the following Makefile, describing a C program compiled
                    448: from sources a.c and b.c, with header file a.h:
                    449: .Bd -literal -offset indent
                    450: \&.SUFFIXES: .c .o
                    451: \&.c.o:
                    452:        ${CC} ${CFLAGS} -c $<
                    453:
                    454: prog: a.o b.o
                    455:        ${CC} ${CFLAGS} -o $@ a.o
                    456:
                    457: a.o b.o: a.h
                    458:
                    459: b.o: b.c
                    460:        ${CC} -DFOO ${CFLAGS} -o $@ $<
                    461: .Ed
                    462: .Pp
                    463: Consider b.o:
                    464: there is a complete target rule re-creating it from b.c, so
                    465: it will be compiled using ${CC} -DFOO.
                    466: .Pp
                    467: Consider a.o:
                    468: there is no explicit target rule, so
                    469: .Nm
                    470: will consider valid transforms.
                    471: Fortunately, there is an inference rule that can create a.o from a.c,
                    472: so it will be compiled using ${CC}.
                    473: .Pp
                    474: Note that extra prerequisites are still taken into account, so both a.o
                    475: and b.o depend on a.h for re-creation.
                    476: .Pp
                    477: Valid suffixes accumulate over
                    478: .Ic .SUFFIXES
                    479: lines.
                    480: An empty
                    481: .Ic .SUFFIXES
                    482: can be used to reset the currently valid list of suffixes,
                    483: but inference rules already read are still known by
                    484: .Nm ,
                    485: and they are marked as inactive.
                    486: Redefining the corresponding suffix (or suffixes) will re-active the rule.
                    487: .Pp
                    488: For maximal portability, suffixes should start with a dot.
1.1       deraadt   489: .Sh VARIABLE ASSIGNMENTS
1.14      aaron     490: Variables in
1.19      aaron     491: .Nm
1.14      aaron     492: are much like variables in the shell, and, by tradition,
1.1       deraadt   493: consist of all upper-case letters.
1.60      espie     494: They are also called
                    495: .Sq macros
                    496: in various texts.
1.43      espie     497: For portability, only periods, underscores, digits and letters should be
                    498: used for variable names.
1.1       deraadt   499: The five operators that can be used to assign values to variables are as
                    500: follows:
                    501: .Bl -tag -width Ds
                    502: .It Ic \&=
                    503: Assign the value to the variable.
                    504: Any previous value is overridden.
1.43      espie     505: .It Ic \&:=
                    506: Assign with expansion, i.e., expand the value before assigning it
1.57      jmc       507: to the variable (extension).
1.1       deraadt   508: .It Ic \&+=
1.43      espie     509: Append the value to the current value of the variable (extension).
1.1       deraadt   510: .It Ic \&?=
1.43      espie     511: Assign the value to the variable if it is not already defined (BSD
                    512: extension).
1.1       deraadt   513: Normally, expansion is not done until the variable is referenced.
                    514: .It Ic \&!=
                    515: Expand the value and pass it to the shell for execution and assign
                    516: the result to the variable.
1.43      espie     517: Any newlines in the result are replaced with spaces (BSD extension).
1.1       deraadt   518: .El
                    519: .Pp
1.14      aaron     520: Any whitespace before the assigned
1.1       deraadt   521: .Ar value
                    522: is removed; if the value is being appended, a single space is inserted
                    523: between the previous contents of the variable and the appended value.
                    524: .Pp
                    525: Variables are expanded by surrounding the variable name with either
                    526: curly braces
                    527: .Pq Ql {}
                    528: or parentheses
                    529: .Pq Ql ()
                    530: and preceding it with
                    531: a dollar sign
                    532: .Pq Ql \&$ .
                    533: If the variable name contains only a single letter, the surrounding
                    534: braces or parentheses are not required.
                    535: This shorter form is not recommended.
                    536: .Pp
                    537: Variable substitution occurs at two distinct times, depending on where
                    538: the variable is being used.
                    539: Variables in dependency lines are expanded as the line is read.
                    540: Variables in shell commands are expanded when the shell command is
                    541: executed.
                    542: .Pp
                    543: The four different classes of variables (in order of increasing precedence)
                    544: are:
                    545: .Bl -tag -width Ds
                    546: .It Environment variables
                    547: Variables defined as part of
                    548: .Nm make Ns 's
                    549: environment.
                    550: .It Global variables
                    551: Variables defined in the makefile or in included makefiles.
                    552: .It Command line variables
                    553: Variables defined as part of the command line.
                    554: .It Local variables
                    555: Variables that are defined specific to a certain target.
1.43      espie     556: Standard local variables are as follows:
1.1       deraadt   557: .Bl -tag -width ".ARCHIVE"
1.43      espie     558: .It Va @
                    559: The name of the target.
                    560: .It Va \&%
                    561: The name of the archive member (only valid for library rules).
                    562: .It Va \&!
                    563: The name of the archive file (only valid for library rules).
                    564: .It Va \&?
                    565: The list of prerequisites for this target that were deemed out-of-date.
                    566: .It Va \&<
1.95      espie     567: The name of the prerequisite from which this target is to be built, if a valid
1.96      espie     568: inference rule (suffix rule) is in scope.
1.43      espie     569: .It Va *
                    570: The file prefix of the file, containing only the file portion,
                    571: no suffix or preceding directory components.
                    572: .El
                    573: .Pp
                    574: The six variables
1.54      jmc       575: .Sq Va "@F" ,
                    576: .Sq Va "@D" ,
                    577: .Sq Va "<F" ,
                    578: .Sq Va "<D" ,
                    579: .Sq Va "*F" ,
1.43      espie     580: and
1.54      jmc       581: .Sq Va "*D"
1.43      espie     582: yield the
                    583: .Qq filename
                    584: and
                    585: .Qq directory
                    586: parts of the corresponding macros.
                    587: .Pp
                    588: For maximum compatibility,
1.54      jmc       589: .Sq Va \&<
1.96      espie     590: should only be used for actual inference rules.
                    591: It is also set for normal target rules when there is an inference rule
                    592: that matches the current target and prerequisite in scope.
1.54      jmc       593: That is, in
1.57      jmc       594: .Bd -literal -offset indent
1.65      jmc       595: \&.SUFFIXES: .c .o
1.43      espie     596: file.o: file.c
                    597:        cmd1 $<
                    598:
                    599: \&.c.o:
                    600:        cmd2
                    601: .Ed
1.57      jmc       602: .Pp
1.43      espie     603: building
                    604: .Pa file.o
                    605: will execute
                    606: .Qq cmd1 file.c .
                    607: .Pp
                    608: As an extension,
                    609: .Nm
1.47      jsyn      610: supports the following local variables:
1.43      espie     611: .Bl -tag -width ".ARCHIVE"
                    612: .It Va \&>
1.95      espie     613: The list of all prerequisites for this target.
1.1       deraadt   614: .It Va .ALLSRC
1.43      espie     615: Synonym for
1.54      jmc       616: .Sq Va \&> .
1.1       deraadt   617: .It Va .ARCHIVE
1.43      espie     618: Synonym for
1.54      jmc       619: .Sq Va \&! .
1.1       deraadt   620: .It Va .IMPSRC
1.43      espie     621: Synonym for
1.54      jmc       622: .Sq Va \&< .
1.1       deraadt   623: .It Va .MEMBER
1.43      espie     624: Synonym for
1.54      jmc       625: .Sq Va \&% .
1.1       deraadt   626: .It Va .OODATE
1.43      espie     627: Synonym for
1.54      jmc       628: .Sq Va \&? .
1.1       deraadt   629: .It Va .PREFIX
1.43      espie     630: Synonym for
1.54      jmc       631: .Sq Va * .
1.1       deraadt   632: .It Va .TARGET
1.43      espie     633: Synonym for
1.54      jmc       634: .Sq Va @ .
1.1       deraadt   635: .El
                    636: .Pp
1.43      espie     637: These variables may be used on the dependency half of dependency
                    638: lines, when they make sense.
1.15      espie     639: .El
1.1       deraadt   640: .Pp
                    641: In addition,
1.19      aaron     642: .Nm
                    643: sets or knows about the following internal variables, or environment
1.15      espie     644: variables:
1.1       deraadt   645: .Bl -tag -width MAKEFLAGS
                    646: .It Va \&$
                    647: A single dollar sign
                    648: .Ql \&$ ,
1.29      aaron     649: i.e.,
1.1       deraadt   650: .Ql \&$$
                    651: expands to a single dollar
                    652: sign.
                    653: .It Va .MAKE
                    654: The name that
1.19      aaron     655: .Nm
1.1       deraadt   656: was executed with
1.14      aaron     657: .Pq Va argv Ns Op 0 .
1.1       deraadt   658: .It Va .CURDIR
                    659: A path to the directory where
1.19      aaron     660: .Nm
1.1       deraadt   661: was executed.
                    662: .It Va .OBJDIR
                    663: A path to the directory where the targets are built.
1.8       deraadt   664: At startup,
1.19      aaron     665: .Nm
1.8       deraadt   666: searches for an alternate directory to place target files -- it
                    667: will attempt to change into this special directory.
1.19      aaron     668: First, if
                    669: .Ev MAKEOBJDIRPREFIX
                    670: is defined,
                    671: .Nm
1.18      espie     672: prepends its contents to the current directory name and tries for
1.28      aaron     673: the resulting directory.
                    674: If that fails,
1.19      aaron     675: .Nm
1.18      espie     676: remains in the current directory.
1.19      aaron     677: If
1.15      espie     678: .Ev MAKEOBJDIRPREFIX
1.18      espie     679: is not defined,
1.19      aaron     680: .Nm
1.18      espie     681: checks
1.19      aaron     682: .Ev MAKEOBJDIR
1.28      aaron     683: and tries to change into that directory.
                    684: Should that fail,
1.19      aaron     685: .Nm
1.28      aaron     686: remains in the current directory.
                    687: If
1.18      espie     688: .Ev MAKEOBJDIR
                    689: is not defined, it tries to change into the directory named
                    690: .Pa obj.${MACHINE}
1.19      aaron     691: (see
                    692: .Va MACHINE
1.28      aaron     693: variable).
                    694: If it still has found no special directory,
1.19      aaron     695: .Nm
1.18      espie     696: next tries the directory named
                    697: .Pa obj .
                    698: If this fails,
1.19      aaron     699: .Nm
                    700: tries to prepend
                    701: .Pa /usr/obj
                    702: to the current directory name.
1.18      espie     703: Finally, if none of these directories are available
1.19      aaron     704: .Nm
1.8       deraadt   705: will settle for and use the current directory.
1.15      espie     706: .It Va .MAKEFLAGS
1.1       deraadt   707: The environment variable
1.14      aaron     708: .Ev MAKEFLAGS
1.1       deraadt   709: may contain anything that
                    710: may be specified on
                    711: .Nm make Ns 's
1.28      aaron     712: command line.
                    713: Its contents are stored in
1.15      espie     714: .Nm make Ns 's
1.19      aaron     715: .Va .MAKEFLAGS
1.15      espie     716: variable.
1.40      espie     717: Anything specified on
1.1       deraadt   718: .Nm make Ns 's
                    719: command line is appended to the
1.15      espie     720: .Va .MAKEFLAGS
                    721: variable which is then
1.19      aaron     722: entered into the environment as
1.14      aaron     723: .Ev MAKEFLAGS
1.15      espie     724: for all programs which
1.19      aaron     725: .Nm
1.1       deraadt   726: executes.
1.15      espie     727: .It Va MFLAGS
1.19      aaron     728: A shorter synonym for
1.15      espie     729: .Va .MAKEFLAGS .
1.9       millert   730: .It Ev PWD
                    731: Alternate path to the current directory.
1.19      aaron     732: .Nm
1.9       millert   733: normally sets
1.54      jmc       734: .Sq Va .CURDIR
1.9       millert   735: to the canonical path given by
1.49      jmc       736: .Xr getcwd 3 .
1.9       millert   737: However, if the environment variable
1.14      aaron     738: .Ev PWD
1.9       millert   739: is set and gives a path to the current directory, then
1.19      aaron     740: .Nm
1.9       millert   741: sets
1.54      jmc       742: .Sq Va .CURDIR
1.9       millert   743: to the value of
1.14      aaron     744: .Ev PWD
1.9       millert   745: instead.
1.14      aaron     746: .Ev PWD
1.15      espie     747: is always set to the value of
1.54      jmc       748: .Sq Va .OBJDIR
1.9       millert   749: for all programs which
1.19      aaron     750: .Nm
1.9       millert   751: executes.
1.15      espie     752: .It Va .TARGETS
1.19      aaron     753: List of targets
                    754: .Nm
1.18      espie     755: is currently building.
1.15      espie     756: .It Va MACHINE
1.19      aaron     757: Name of the machine architecture
                    758: .Nm
1.18      espie     759: is running on, obtained from the
                    760: .Ev MACHINE
1.19      aaron     761: environment variable, or through
1.44      deraadt   762: .Xr uname 3
1.18      espie     763: if not defined.
1.15      espie     764: .It Va MACHINE_ARCH
1.18      espie     765: Name of the machine architecture
1.19      aaron     766: .Nm
1.18      espie     767: was compiled for, obtained from the
1.19      aaron     768: .Ev MACHINE_ARCH
1.18      espie     769: environment variable, or defined at compilation time.
1.85      miod      770: .It Va MACHINE_CPU
                    771: Name of the machine processor
                    772: .Nm
                    773: was compiled for, obtained from the
                    774: .Ev MACHINE_CPU
                    775: environment variable, or defined at compilation time.
                    776: On processors where only one endianness is possible, the value of this
                    777: variable is always the same as
                    778: .Ev MACHINE_ARCH .
1.80      bluhm     779: .It Va MAKEFILE
                    780: Possibly the file name of the last makefile that has been read.
                    781: It should not be used; see the
                    782: .Sx BUGS
                    783: section below.
1.1       deraadt   784: .El
                    785: .Pp
                    786: Variable expansion may be modified to select or modify each word of the
1.48      pvalchev  787: variable (where
1.19      aaron     788: .Dq word
1.48      pvalchev  789: is a whitespace delimited sequence of characters).
1.1       deraadt   790: The general format of a variable expansion is as follows:
                    791: .Pp
                    792: .Dl {variable[:modifier[:...]]}
                    793: .Pp
                    794: Each modifier begins with a colon and one of the following
                    795: special characters.
                    796: The colon may be escaped with a backslash
                    797: .Pq Ql \e .
1.54      jmc       798: .Bl -tag -width Ds
1.58      espie     799: .It Cm :E
1.1       deraadt   800: Replaces each word in the variable with its suffix.
1.58      espie     801: .It Cm :H
1.1       deraadt   802: Replaces each word in the variable with everything but the last component.
1.58      espie     803: .It Cm :L
1.20      espie     804: Replaces each word in the variable with its lower case equivalent.
1.58      espie     805: .It Cm :U
1.20      espie     806: Replaces each word in the variable with its upper case equivalent.
1.58      espie     807: .It Cm :M Ns Ar pattern
1.1       deraadt   808: Select only those words that match the rest of the modifier.
                    809: The standard shell wildcard characters
                    810: .Pf ( Ql * ,
1.55      jmc       811: .Ql \&? ,
1.1       deraadt   812: and
1.54      jmc       813: .Ql [] )
1.1       deraadt   814: may
                    815: be used.
                    816: The wildcard characters may be escaped with a backslash
                    817: .Pq Ql \e .
1.58      espie     818: .It Cm :N Ns Ar pattern
1.1       deraadt   819: This is identical to
1.58      espie     820: .Cm :M ,
1.1       deraadt   821: but selects all words which do not match
                    822: the rest of the modifier.
1.58      espie     823: .It Cm :Q
1.10      millert   824: Quotes every shell meta-character in the variable, so that it can be passed
                    825: safely through recursive invocations of
1.14      aaron     826: .Nm make .
1.88      espie     827: .It Cm :QL
                    828: Quote list: quotes every shell meta-character in the variable, except
                    829: whitespace, so that it can be passed to a shell's
                    830: .Sq for
                    831: loops.
1.58      espie     832: .It Cm :R
1.1       deraadt   833: Replaces each word in the variable with everything but its suffix.
                    834: .Sm off
1.58      espie     835: .It Cm :S No \&/ Ar old_string Xo
1.10      millert   836: .No \&/ Ar new_string
                    837: .No \&/ Op Cm 1g
1.1       deraadt   838: .Xc
                    839: .Sm on
                    840: Modify the first occurrence of
1.10      millert   841: .Ar old_string
                    842: in the variable's value, replacing it with
                    843: .Ar new_string .
1.1       deraadt   844: If a
                    845: .Ql g
                    846: is appended to the last slash of the pattern, all occurrences
                    847: in each word are replaced.
1.10      millert   848: If a
                    849: .Ql 1
                    850: is appended to the last slash of the pattern, only the first word
                    851: is affected.
1.1       deraadt   852: If
1.10      millert   853: .Ar old_string
                    854: begins with a caret
1.1       deraadt   855: .Pq Ql ^ ,
1.10      millert   856: .Ar old_string
1.1       deraadt   857: is anchored at the beginning of each word.
                    858: If
1.10      millert   859: .Ar old_string
1.1       deraadt   860: ends with a dollar sign
                    861: .Pq Ql \&$ ,
                    862: it is anchored at the end of each word.
                    863: Inside
                    864: .Ar new_string ,
                    865: an ampersand
                    866: .Pq Ql &
                    867: is replaced by
1.10      millert   868: .Ar old_string
                    869: (without any
                    870: .Ql ^
                    871: or
                    872: .Ql \&$ ) .
1.1       deraadt   873: Any character may be used as a delimiter for the parts of the modifier
                    874: string.
                    875: The anchoring, ampersand and delimiter characters may be escaped with a
                    876: backslash
                    877: .Pq Ql \e .
                    878: .Pp
                    879: Variable expansion occurs in the normal fashion inside both
                    880: .Ar old_string
                    881: and
                    882: .Ar new_string
                    883: with the single exception that a backslash is used to prevent the expansion
                    884: of a dollar sign
1.10      millert   885: .Pq Ql \&$ ,
1.1       deraadt   886: not a preceding dollar sign as is usual.
1.10      millert   887: .Sm off
1.58      espie     888: .It Cm :C No \&/ Ar pattern Xo
1.10      millert   889: .No \&/ Ar replacement
                    890: .No \&/ Op Cm 1g
                    891: .Xc
                    892: .Sm on
                    893: The
1.58      espie     894: .Cm :C
1.10      millert   895: modifier is just like the
1.58      espie     896: .Cm :S
1.13      deraadt   897: modifier except that the old and new strings, instead of being
1.10      millert   898: simple strings, are a regular expression (see
                    899: .Xr regex 3 )
                    900: and an
                    901: .Xr ed 1 Ns \-style
1.28      aaron     902: replacement string.
                    903: Normally, the first occurrence of the pattern in
                    904: each word of the value is changed.
                    905: The
1.10      millert   906: .Ql 1
                    907: modifier causes the substitution to apply to at most one word; the
                    908: .Ql g
                    909: modifier causes the substitution to apply to as many instances of the
1.28      aaron     910: search pattern as occur in the word or words it is found in.
                    911: Note that
1.10      millert   912: .Ql 1
                    913: and
                    914: .Ql g
                    915: are orthogonal; the former specifies whether multiple words are
                    916: potentially affected, the latter whether multiple substitutions can
                    917: potentially occur within each affected word.
1.58      espie     918: .It Cm :T
1.1       deraadt   919: Replaces each word in the variable with its last component.
1.59      jmc       920: .It Ar :old_string Ns = Ns Ar new_string
1.1       deraadt   921: This is the
                    922: .At V
                    923: style variable substitution.
                    924: It must be the last modifier specified.
1.9       millert   925: If
1.1       deraadt   926: .Ar old_string
                    927: or
                    928: .Ar new_string
                    929: do not contain the pattern matching character
                    930: .Ar %
1.9       millert   931: then it is assumed that they are
1.1       deraadt   932: anchored at the end of each word, so only suffixes or entire
1.28      aaron     933: words may be replaced.
                    934: Otherwise
1.1       deraadt   935: .Ar %
1.9       millert   936: is the substring of
                    937: .Ar old_string
1.1       deraadt   938: to be replaced in
1.53      jmc       939: .Ar new_string .
1.88      espie     940: The right hand side
                    941: .Pq Ar new_string
                    942: may contain variable values, which will be expanded.
                    943: To put an actual single dollar, just double it.
1.1       deraadt   944: .El
1.53      jmc       945: .Pp
1.50      jmc       946: All modifiers are BSD extensions, except for the standard
1.46      espie     947: .At V
                    948: style variable substitution.
1.88      espie     949: .Pp
                    950: The interpretation of
                    951: .Ar %
                    952: and
                    953: .Ar $
                    954: in
                    955: .At V
                    956: variable substitutions is not mandated by POSIX, though it is
                    957: fairly common.
1.1       deraadt   958: .Sh INCLUDE STATEMENTS, CONDITIONALS AND FOR LOOPS
1.28      aaron     959: Makefile inclusion, conditional structures and for loops reminiscent
1.1       deraadt   960: of the C programming language are provided in
                    961: .Nm make .
                    962: All such structures are identified by a line beginning with a single
                    963: dot
                    964: .Pq Ql \&.
                    965: character.
1.46      espie     966: Whitespace characters may follow this dot, e.g.,
1.57      jmc       967: .Bd -literal -offset indent
                    968: \&.include <file>
1.46      espie     969: .Ed
                    970: and
1.57      jmc       971: .Bd -literal -offset indent -compact
                    972: \&.   include <file>
1.46      espie     973: .Ed
1.57      jmc       974: .Pp
1.46      espie     975: are identical constructs.
1.1       deraadt   976: Files are included with either
                    977: .Ql .include <file>
                    978: or
                    979: .Ql .include \*qfile\*q .
                    980: Variables between the angle brackets or double quotes are expanded
                    981: to form the file name.
                    982: If angle brackets are used, the included makefile is expected to be in
                    983: the system makefile directory.
                    984: If double quotes are used, the including makefile's directory and any
                    985: directories specified using the
                    986: .Fl I
                    987: option are searched before the system
                    988: makefile directory.
                    989: .Pp
                    990: Conditional expressions are also preceded by a single dot as the first
                    991: character of a line.
                    992: The possible conditionals are as follows:
                    993: .Bl -tag -width Ds
                    994: .It Ic .undef Ar variable
                    995: Un-define the specified global variable.
                    996: Only global variables may be un-defined.
1.69      espie     997: .It Ic .poison Ar variable
                    998: Poison the specified global variable.
1.70      jmc       999: Any further reference to
1.69      espie    1000: .Ar variable
                   1001: will be flagged as an error.
1.70      jmc      1002: .It Ic .poison !defined Pq Ar variable
1.69      espie    1003: It is an error to try to use the value of
                   1004: .Ar variable
1.70      jmc      1005: in a context where it is not defined.
                   1006: .It Ic .poison empty Pq Ar variable
1.69      espie    1007: It is an error to try to use the value of
                   1008: .Ar variable
1.70      jmc      1009: in a context where it is not defined or empty.
1.1       deraadt  1010: .It Xo
                   1011: .Ic \&.if
                   1012: .Oo \&! Oc Ns Ar expression
                   1013: .Op Ar operator expression ...
                   1014: .Xc
                   1015: Test the value of an expression.
                   1016: .It Xo
                   1017: .Ic .ifdef
                   1018: .Oo \&! Oc Ns Ar variable
                   1019: .Op Ar operator variable ...
                   1020: .Xc
                   1021: Test the value of a variable.
                   1022: .It Xo
                   1023: .Ic .ifndef
                   1024: .Oo \&! Oc Ns Ar variable
                   1025: .Op Ar operator variable ...
                   1026: .Xc
                   1027: Test the value of a variable.
                   1028: .It Xo
                   1029: .Ic .ifmake
                   1030: .Oo \&! Oc Ns Ar target
                   1031: .Op Ar operator target ...
                   1032: .Xc
                   1033: Test the target being built.
                   1034: .It Xo
                   1035: .Ic .ifnmake
                   1036: .Oo \&! Oc Ar target
                   1037: .Op Ar operator target ...
                   1038: .Xc
                   1039: Test the target being built.
                   1040: .It Ic .else
                   1041: Reverse the sense of the last conditional.
                   1042: .It Xo
                   1043: .Ic .elif
                   1044: .Oo \&! Oc Ar expression
                   1045: .Op Ar operator expression ...
                   1046: .Xc
                   1047: A combination of
1.54      jmc      1048: .Sq Ic .else
1.1       deraadt  1049: followed by
1.54      jmc      1050: .Sq Ic .if .
1.1       deraadt  1051: .It Xo
                   1052: .Ic .elifdef
                   1053: .Oo \&! Oc Ns Ar variable
                   1054: .Op Ar operator variable ...
                   1055: .Xc
                   1056: A combination of
1.54      jmc      1057: .Sq Ic .else
1.1       deraadt  1058: followed by
1.54      jmc      1059: .Sq Ic .ifdef .
1.1       deraadt  1060: .It Xo
                   1061: .Ic .elifndef
                   1062: .Oo \&! Oc Ns Ar variable
                   1063: .Op Ar operator variable ...
                   1064: .Xc
                   1065: A combination of
1.54      jmc      1066: .Sq Ic .else
1.1       deraadt  1067: followed by
1.54      jmc      1068: .Sq Ic .ifndef .
1.1       deraadt  1069: .It Xo
                   1070: .Ic .elifmake
                   1071: .Oo \&! Oc Ns Ar target
                   1072: .Op Ar operator target ...
                   1073: .Xc
                   1074: A combination of
1.54      jmc      1075: .Sq Ic .else
1.1       deraadt  1076: followed by
1.54      jmc      1077: .Sq Ic .ifmake .
1.1       deraadt  1078: .It Xo
                   1079: .Ic .elifnmake
                   1080: .Oo \&! Oc Ns Ar target
                   1081: .Op Ar operator target ...
                   1082: .Xc
                   1083: A combination of
1.54      jmc      1084: .Sq Ic .else
1.1       deraadt  1085: followed by
1.54      jmc      1086: .Sq Ic .ifnmake .
1.1       deraadt  1087: .It Ic .endif
                   1088: End the body of the conditional.
                   1089: .El
                   1090: .Pp
                   1091: The
                   1092: .Ar operator
                   1093: may be any one of the following:
                   1094: .Bl -tag -width "Cm XX"
1.92      jmc      1095: .It Cm ||
1.1       deraadt  1096: logical OR
                   1097: .It Cm \&&&
                   1098: Logical
                   1099: .Tn AND ;
                   1100: of higher precedence than
1.92      jmc      1101: .Cm || .
1.1       deraadt  1102: .El
                   1103: .Pp
                   1104: As in C,
1.19      aaron    1105: .Nm
1.1       deraadt  1106: will only evaluate a conditional as far as is necessary to determine
                   1107: its value.
1.9       millert  1108: Parentheses may be used to change the order of evaluation.
1.1       deraadt  1109: The boolean operator
1.54      jmc      1110: .Sq Ic \&!
1.1       deraadt  1111: may be used to logically negate an entire
                   1112: conditional.
                   1113: It is of higher precedence than
1.54      jmc      1114: .Sq Ic \&&& .
1.1       deraadt  1115: .Pp
                   1116: The value of
                   1117: .Ar expression
                   1118: may be any of the following:
1.54      jmc      1119: .Bl -tag -width defined
1.98    ! espie    1120: .It Ic commands
        !          1121: Takes a target name as an argument and evaluates to true if the target
        !          1122: has been defined and has shell commands associated with it.
1.1       deraadt  1123: .It Ic defined
                   1124: Takes a variable name as an argument and evaluates to true if the variable
                   1125: has been defined.
                   1126: .It Ic make
                   1127: Takes a target name as an argument and evaluates to true if the target
                   1128: was specified as part of
                   1129: .Nm make Ns 's
                   1130: command line or was declared the default target (either implicitly or
                   1131: explicitly, see
                   1132: .Va .MAIN )
                   1133: before the line containing the conditional.
                   1134: .It Ic empty
                   1135: Takes a variable, with possible modifiers, and evaluates to true if
                   1136: the expansion of the variable would result in an empty string.
                   1137: .It Ic exists
                   1138: Takes a file name as an argument and evaluates to true if the file exists.
                   1139: The file is searched for on the system search path (see
                   1140: .Va .PATH ) .
                   1141: .It Ic target
                   1142: Takes a target name as an argument and evaluates to true if the target
                   1143: has been defined.
                   1144: .El
                   1145: .Pp
1.14      aaron    1146: .Ar expression
1.28      aaron    1147: may also be an arithmetic or string comparison.
                   1148: Variable expansion is
1.1       deraadt  1149: performed on both sides of the comparison, after which the integral
1.28      aaron    1150: values are compared.
                   1151: A value is interpreted as hexadecimal if it is
1.1       deraadt  1152: preceded by 0x, otherwise it is decimal; octal numbers are not supported.
1.28      aaron    1153: The standard C relational operators are all supported.
                   1154: If after
1.1       deraadt  1155: variable expansion, either the left or right hand side of a
1.54      jmc      1156: .Sq Ic ==
1.1       deraadt  1157: or
1.54      jmc      1158: .Sq Ic "!="
1.1       deraadt  1159: operator is not an integral value, then
                   1160: string comparison is performed between the expanded
                   1161: variables.
                   1162: If no relational operator is given, it is assumed that the expanded
                   1163: variable is being compared against 0.
                   1164: .Pp
                   1165: When
1.19      aaron    1166: .Nm
1.14      aaron    1167: is evaluating one of these conditional expressions, and it encounters
1.19      aaron    1168: a word it doesn't recognize, either the
                   1169: .Dq make
                   1170: or
                   1171: .Dq defined
1.1       deraadt  1172: expression is applied to it, depending on the form of the conditional.
                   1173: If the form is
1.54      jmc      1174: .Sq Ic .ifdef
1.1       deraadt  1175: or
1.54      jmc      1176: .Sq Ic .ifndef ,
1.19      aaron    1177: the
                   1178: .Dq defined
                   1179: expression is applied.
1.1       deraadt  1180: Similarly, if the form is
1.54      jmc      1181: .Sq Ic .ifmake
1.1       deraadt  1182: or
1.54      jmc      1183: .Sq Ic .ifnmake ,
1.19      aaron    1184: the
                   1185: .Dq make
1.1       deraadt  1186: expression is applied.
                   1187: .Pp
                   1188: If the conditional evaluates to true the parsing of the makefile continues
                   1189: as before.
                   1190: If it evaluates to false, the following lines are skipped.
                   1191: In both cases this continues until a
1.54      jmc      1192: .Sq Ic .else
1.1       deraadt  1193: or
1.54      jmc      1194: .Sq Ic .endif
1.1       deraadt  1195: is found.
1.9       millert  1196: .Pp
1.1       deraadt  1197: For loops are typically used to apply a set of rules to a list of files.
                   1198: The syntax of a for loop is:
1.54      jmc      1199: .Bd -unfilled -offset indent
1.91      schwarze 1200: .Ic .for Ar variable Oo Ar variable ... Oc Ic in Ar expression
1.54      jmc      1201:        <make-rules>
1.91      schwarze 1202: .Ic .endfor
1.54      jmc      1203: .Ed
                   1204: .Pp
1.1       deraadt  1205: After the for
1.14      aaron    1206: .Ar expression
1.28      aaron    1207: is evaluated, it is split into words.
1.50      jmc      1208: On each iteration of the loop, one word is assigned to each
1.41      espie    1209: .Ar variable ,
                   1210: in order,
1.50      jmc      1211: and these
                   1212: .Ar variables
1.41      espie    1213: are substituted in the
1.9       millert  1214: .Ic make-rules
1.1       deraadt  1215: inside the body of the for loop.
1.41      espie    1216: The number of words must match the number of iteration variables;
                   1217: that is, if there are three iteration variables, the number of words
1.48      pvalchev 1218: must be a multiple of three.
1.45      espie    1219: .Pp
                   1220: Loops and conditional expressions may nest arbitrarily, but
                   1221: they may not cross include file boundaries.
1.1       deraadt  1222: .Sh COMMENTS
                   1223: Comments begin with a hash
                   1224: .Pq Ql \&#
                   1225: character, anywhere but in a shell
1.98    ! espie    1226: command line, and continue to the end of the line
        !          1227: (but a
        !          1228: .Pq Ql \&#
        !          1229: character in a shell command line will be interpreted as a comment by
        !          1230: the shell).
1.97      espie    1231: .Sh TARGET ATTRIBUTES
                   1232: Some targets may be tagged with some specific attributes by one
                   1233: of the
                   1234: .Sx SPECIAL TARGETS
                   1235: or
                   1236: .Sx SPECIAL PREREQUISITES
                   1237: described below.
                   1238: .Bl -tag -width "Ignoring errors"
                   1239: .It Dq Always build
                   1240: Run the commands associated with this target even if the
                   1241: .Fl n
                   1242: or
                   1243: .Fl t
                   1244: options were specified.
                   1245: Can be used to mark recursive
                   1246: .Nm make Ns 's ,
                   1247: but prefer standard
                   1248: .Sq Ic + Ns Ar cmd .
                   1249: .It Dq Cheap
                   1250: In parallel mode, don't scan the commands for occurrences of
                   1251: .Nm ,
                   1252: thus letting normal recursive
                   1253: .Fl j
                   1254: behavior apply.
                   1255: .It Dq Expensive
                   1256: In parallel mode, assume commands will invoke recursive commands.
                   1257: Once
                   1258: .Nm
                   1259: starts building an expensive target, it won't start building anything else
                   1260: until that target has finished building.
                   1261: .It Dq Ignoring errors
                   1262: Ignore any errors generating by running shell commands, exactly
                   1263: as if they were all preceded by a dash
1.1       deraadt  1264: .Pq Ql \- .
1.97      espie    1265: .It Dq Phony
                   1266: A phony target is a target that does not correspond to any object in the
                   1267: file system (more like a placeholder for a list of commands).
                   1268: .Pp
                   1269: Phony targets are always out-of-date at the start of a run, but
                   1270: .Nm
                   1271: still keeps track of when they are built (that is, when the associated
                   1272: command list finishes running).
                   1273: .It Dq Precious
                   1274: Don't remove the target if
                   1275: .Nm
                   1276: is interrupted in the middle of building it.
                   1277: .It Dq Silent
                   1278: Do not display shell commands before running them, exactly as
                   1279: if they were all preceded by a
                   1280: .Sq @ .
                   1281: .El
                   1282: .Sh SPECIAL TARGETS
1.19      aaron    1283: .Nm
1.97      espie    1284: recognizes standard special targets:
                   1285: .Bl -tag -width ".NOTPARALLEL"
                   1286: .It Ic .DEFAULT
                   1287: If there is a
                   1288: .Ic .DEFAULT
                   1289: target rule, with commands but no prequisites, and
                   1290: .Nm
                   1291: can't figure out another way to build a target, it will use that
                   1292: list of commands, setting
                   1293: .Va \&<
                   1294: and
                   1295: .Va @
                   1296: appropriately.
                   1297: .It Ic .IGNORE
                   1298: Mark its prerequisites as
                   1299: .Dq Ignoring errors .
                   1300: .Pp
                   1301: If the list of prerequisites is empty, apply that to all targets, exactly
                   1302: like the
                   1303: .Fl i
                   1304: command-line option.
1.1       deraadt  1305: .It Ic .PRECIOUS
1.97      espie    1306: Mark its prerequisites as
                   1307: .Dq Precious .
                   1308: .Pp
                   1309: If the list of prerequisites is empty, apply that to all targets.
1.1       deraadt  1310: .It Ic .SILENT
1.97      espie    1311: Mark its prerequisites as
                   1312: .Dq Silent .
                   1313: .Pp
                   1314: If the list of prerequisites is empty, apply that to all targets, exactly
                   1315: like the
                   1316: .Fl s
                   1317: command-line option.
                   1318: .It Ic .SUFFIXES
                   1319: See
                   1320: .Sx INFERENCE RULES .
1.1       deraadt  1321: .El
1.97      espie    1322: .Pp
                   1323: and also some other special targets as an extension:
1.54      jmc      1324: .Bl -tag -width ".NOTPARALLEL"
1.1       deraadt  1325: .It Ic .BEGIN
1.97      espie    1326: Command lines attached to this target are executed before anything
1.1       deraadt  1327: else is done.
1.93      espie    1328: .It Ic .CHEAP
1.97      espie    1329: Mark its prerequisites as
                   1330: .Dq Cheap .
1.1       deraadt  1331: .It Ic .END
1.97      espie    1332: Command lines attached to this target are executed at the end of a successful
                   1333: run.
1.93      espie    1334: .It Ic .EXPENSIVE
1.97      espie    1335: Mark its prerequisites as
                   1336: .Dq Expensive .
                   1337: .It Ic .INTERRUPT
                   1338: Command lines attached to this target are executed if
                   1339: .Nm
                   1340: is interrupted by a SIGINT.
1.95      espie    1341: .It Ic .MADE
1.97      espie    1342: Mark its prerequisites as being up-to-date.
1.95      espie    1343: .It Ic .MAKE
1.97      espie    1344: Mark its prerequisites as
                   1345: .Dq Always build .
                   1346: Prefer standard
1.95      espie    1347: .Sq Ic + Ns Ar cmd .
1.1       deraadt  1348: .It Ic .MAIN
                   1349: If no target is specified when
1.19      aaron    1350: .Nm
1.28      aaron    1351: is invoked, this target will be built.
                   1352: This is always set, either
1.19      aaron    1353: explicitly, or implicitly when
                   1354: .Nm
1.16      espie    1355: selects the default target, to give the user a way to refer to the default
                   1356: target on the command line.
1.1       deraadt  1357: .It Ic .MAKEFLAGS
                   1358: This target provides a way to specify flags for
1.19      aaron    1359: .Nm
1.1       deraadt  1360: when the makefile is used.
                   1361: The flags are as if typed to the shell, though the
                   1362: .Fl f
                   1363: option will have
                   1364: no effect.
1.4       deraadt  1365: .It Ic .NOTPARALLEL
1.98    ! espie    1366: Disable parallel mode for the current makefile.
        !          1367: The
        !          1368: .Fl j
        !          1369: option is still passed to submakes.
1.4       deraadt  1370: .It Ic .NO_PARALLEL
                   1371: Same as above, for compatibility with other pmake variants.
                   1372: .It Ic .ORDER
1.97      espie    1373: The list of prerequisites should be built in sequence.
1.1       deraadt  1374: .It Ic .PATH
1.97      espie    1375: The prerequisites define a search path: directories that will be searched
                   1376: for files not found in the current directory.
1.95      espie    1377: If no prerequisites are specified, any previously specified directories are
1.1       deraadt  1378: deleted.
1.97      espie    1379: .It Ic .PATH\fI.suffix\fR
                   1380: This target is only valid if .suffix is a currently valid suffix.
                   1381: The prerequisites defines a search path for files ending in that suffix.
                   1382: For files not found in the current directory,
1.19      aaron    1383: .Nm
1.97      espie    1384: will first look in that path, before reverting to the default search path.
1.6       niklas   1385: .It Ic .PHONY
1.97      espie    1386: Mark its prerequisites as
                   1387: .Dq Phony
                   1388: targets.
                   1389: .El
1.98    ! espie    1390: .Pp
        !          1391: It is an error to use several special targets, or a special target and
        !          1392: normal targets, in a single dependency line.
1.97      espie    1393: .Sh SPECIAL PREREQUISITES
1.98    ! espie    1394: Of the special targets described in the previous
        !          1395: section, the ones that tag prerequisites can also be used as prerequisites,
        !          1396: in which case the corresponding targets will be tagged accordingly.
        !          1397: .Pp
        !          1398: This is an extension, even for standard special targets.
        !          1399: .Pp
        !          1400: .Nm
        !          1401: also recognizes some other prerequisites:
1.97      espie    1402: .Bl -tag -width ".PRECIOUS"
                   1403: .It Ic .NOTMAIN
                   1404: Normally
                   1405: .Nm
                   1406: selects the first target it encounters as the default target to be built
                   1407: if no target was specified.
                   1408: This prerequisite prevents this target from being selected.
                   1409: .It Ic .OPTIONAL
                   1410: If a target is marked with this attribute and
                   1411: .Nm
                   1412: can't figure out how to create it, it will ignore this fact and assume
                   1413: the file isn't needed or already exists.
                   1414: .It Ic .USE
                   1415: Turn the target into
                   1416: .Nm make Ns 's
                   1417: version of a macro.
                   1418: When the target is used as a prerequisite for another target, the other target
                   1419: acquires the commands, prerequisites, and attributes (except for
                   1420: .Ic .USE )
                   1421: of the
                   1422: prerequisite.
                   1423: If the target already has commands, the
                   1424: .Ic .USE
                   1425: target's commands are appended
                   1426: to them.
                   1427: .It Ic .WAIT
                   1428: If
                   1429: .Ic .WAIT
                   1430: appears in a dependency line, the prerequisites that precede it are
                   1431: made before the prerequisites that follow it in the line.
                   1432: Loops are not
                   1433: detected and targets that form loops will be silently ignored.
1.35      aaron    1434: .El
1.1       deraadt  1435: .Sh ENVIRONMENT
1.19      aaron    1436: .Nm
1.15      espie    1437: uses the following environment variables, if they exist:
1.9       millert  1438: .Ev MACHINE ,
1.15      espie    1439: .Ev MACHINE_ARCH ,
1.86      jmc      1440: .Ev MACHINE_CPU ,
1.9       millert  1441: .Ev MAKEFLAGS ,
                   1442: .Ev MAKEOBJDIR ,
1.15      espie    1443: .Ev MAKEOBJDIRPREFIX ,
1.1       deraadt  1444: and
1.9       millert  1445: .Ev PWD .
1.30      espie    1446: .Nm
1.31      aaron    1447: also ignores and unsets
1.30      espie    1448: .Ev CDPATH .
1.1       deraadt  1449: .Sh FILES
                   1450: .Bl -tag -width /usr/share/mk -compact
1.14      aaron    1451: .It Pa .depend
1.1       deraadt  1452: list of dependencies
1.15      espie    1453: .It Pa BSDmakefile
1.66      jmc      1454: default makefile
                   1455: .It Pa makefile
                   1456: default makefile if
                   1457: .Pa BSDmakefile
                   1458: does not exist
1.14      aaron    1459: .It Pa Makefile
1.66      jmc      1460: default makefile if
                   1461: .Pa makefile
                   1462: does not exist
1.14      aaron    1463: .It Pa sys.mk
1.1       deraadt  1464: system makefile
1.14      aaron    1465: .It Pa /usr/share/mk
1.1       deraadt  1466: system makefile directory
1.62      jmc      1467: .It Pa /usr/obj
1.19      aaron    1468: default
1.52      jmc      1469: .Ev MAKEOBJDIRPREFIX
1.57      jmc      1470: directory
1.1       deraadt  1471: .El
1.89      jmc      1472: .Sh EXIT STATUS
                   1473: If
                   1474: .Fl q
                   1475: was specified, the
                   1476: .Nm
                   1477: utility exits with one of the following values:
                   1478: .Pp
                   1479: .Bl -tag -width Ds -offset indent -compact
                   1480: .It 0
                   1481: Normal behavior.
                   1482: .It 1
                   1483: The target was not up-to date.
                   1484: .It \*(Gt1
                   1485: An error occurred.
                   1486: .El
                   1487: .Pp
                   1488: Otherwise, the
                   1489: .Nm
                   1490: utility exits with a value of 0 on success, and \*(Gt0 if an error occurred.
1.37      aaron    1491: .Sh SEE ALSO
1.57      jmc      1492: .Xr ed 1 ,
                   1493: .Xr mkdep 1 ,
                   1494: .Xr sh 1 ,
                   1495: .Xr getcwd 3 ,
                   1496: .Xr regex 3 ,
                   1497: .Xr uname 3
1.52      jmc      1498: .Sh STANDARDS
1.67      jmc      1499: The
1.43      espie    1500: .Nm
1.95      espie    1501: utility is mostly compliant with the
1.83      jmc      1502: .St -p1003.1-2008
1.95      espie    1503: specification.
1.67      jmc      1504: .Pp
                   1505: The flags
1.95      espie    1506: .Op Fl BDdIjmV
1.67      jmc      1507: are extensions to that specification.
1.43      espie    1508: .Pp
1.37      aaron    1509: Older versions of
                   1510: .Nm
                   1511: used
                   1512: .Ev MAKE
                   1513: instead of
                   1514: .Ev MAKEFLAGS .
                   1515: This was removed for POSIX compatibility.
                   1516: The internal variable
                   1517: .Va MAKE
                   1518: is set to the same value as
1.48      pvalchev 1519: .Va .MAKE .
                   1520: Support for this may be removed in the future.
1.37      aaron    1521: .Pp
                   1522: Most of the more esoteric features of
                   1523: .Nm
                   1524: should probably be avoided for greater compatibility.
                   1525: .Sh HISTORY
                   1526: A
                   1527: .Nm
                   1528: command appeared in
                   1529: .At v7 .
1.95      espie    1530: .Pp
                   1531: This implementation is a distant derivative of
                   1532: .Nm pmake ,
                   1533: originally written by Adam de Boor.
1.17      espie    1534: .Sh BUGS
1.18      espie    1535: The determination of
                   1536: .Va .OBJDIR
1.19      aaron    1537: is contorted to the point of absurdity.
1.18      espie    1538: .Pp
1.98    ! espie    1539: If the same target is specified several times in complete target rules,
1.31      aaron    1540: .Nm
1.98    ! espie    1541: ignores all commands after the first non empty set of commands,
1.31      aaron    1542: e.g., in
1.57      jmc      1543: .Bd -literal -offset indent
1.27      espie    1544: a:
                   1545:        @echo "Executed"
                   1546: a:
                   1547:        @echo "Bad luck"
                   1548: .Ed
                   1549: .Pp
1.98    ! espie    1550: @echo "Bad luck" will be ignored.
1.18      espie    1551: .Pp
                   1552: .Va .TARGETS
                   1553: is not set to the default target when
1.19      aaron    1554: .Nm
1.18      espie    1555: is invoked without a target name and no
1.19      aaron    1556: .Ic MAIN
1.18      espie    1557: special target exists.
                   1558: .Pp
1.17      espie    1559: The evaluation of
                   1560: .Ar expression
1.98    ! espie    1561: in a test is somewhat simplistic.
        !          1562: Currently, tests should start with a variable or with a quoted string.
        !          1563: Tests like
1.64      mbalmer  1564: .Ql .if ${VAR} == "string" ,
1.98    ! espie    1565: .Ql .if ${VAR} >= 5
        !          1566: and
        !          1567: .Ql .if "string" == ${VAR}
        !          1568: do work, but
        !          1569: .Ql .if 5 <= ${VAR} ,
        !          1570: .Ql .if 5 <= 10 ,
        !          1571: .Ql .if string = ${VAR}
        !          1572: don'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.