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

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

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

CVSweb <webmaster@jp.NetBSD.org>