[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.111

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