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

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