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

1.82    ! espie       1: .\"    $OpenBSD$
1.40      espie       2: .\"    $OpenPackages$
1.10      millert     3: .\"    $NetBSD: make.1,v 1.18 1997/03/10 21:19:53 christos Exp $
1.7       briggs      4: .\"
1.9       millert     5: .\" Copyright (c) 1990, 1993
                      6: .\"    The Regents of the University of California.  All rights reserved.
1.1       deraadt     7: .\"
                      8: .\" Redistribution and use in source and binary forms, with or without
                      9: .\" modification, are permitted provided that the following conditions
                     10: .\" are met:
                     11: .\" 1. Redistributions of source code must retain the above copyright
                     12: .\"    notice, this list of conditions and the following disclaimer.
                     13: .\" 2. Redistributions in binary form must reproduce the above copyright
                     14: .\"    notice, this list of conditions and the following disclaimer in the
                     15: .\"    documentation and/or other materials provided with the distribution.
1.51      millert    16: .\" 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    17: .\"    may be used to endorse or promote products derived from this software
                     18: .\"    without specific prior written permission.
                     19: .\"
                     20: .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     21: .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22: .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23: .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     24: .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25: .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26: .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27: .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28: .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29: .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30: .\" SUCH DAMAGE.
                     31: .\"
1.9       millert    32: .\"    from: @(#)make.1        8.4 (Berkeley) 3/19/94
1.1       deraadt    33: .\"
1.82    ! espie      34: .Dd $Mdocdate$
1.1       deraadt    35: .Dt MAKE 1
                     36: .Os
                     37: .Sh NAME
                     38: .Nm make
                     39: .Nd maintain program dependencies
                     40: .Sh SYNOPSIS
1.19      aaron      41: .Nm make
1.63      jmc        42: .Op Fl BeiknPqrSst
1.1       deraadt    43: .Op Fl D Ar variable
                     44: .Op Fl d Ar flags
                     45: .Op Fl f Ar makefile
                     46: .Op Fl I Ar directory
                     47: .Op Fl j Ar max_jobs
1.5       niklas     48: .Op Fl m Ar directory
1.9       millert    49: .Op Fl V Ar variable
1.60      espie      50: .Op Ar NAME Ns = Ns Ar value
1.50      jmc        51: .Bk -words
1.1       deraadt    52: .Op Ar target ...
1.50      jmc        53: .Ek
1.1       deraadt    54: .Sh DESCRIPTION
1.19      aaron      55: .Nm
1.1       deraadt    56: is a program designed to simplify the maintenance of other programs.
                     57: Its input is a list of specifications as to the files upon which programs
                     58: and other files depend.
                     59: If the file
1.54      jmc        60: .Sq Pa BSDmakefile
1.12      niklas     61: exists, it is read for this list of specifications.
                     62: If it does not exist, the files
1.54      jmc        63: .Sq Pa makefile
1.12      niklas     64: and
1.54      jmc        65: .Sq Pa Makefile
1.12      niklas     66: are tried in order.
1.1       deraadt    67: If the file
1.54      jmc        68: .Sq Pa .depend
1.40      espie      69: exists, it is read in addition to the makefile (see
1.42      mpech      70: .Xr mkdep 1 ) .
1.1       deraadt    71: .Pp
1.43      espie      72: The handling of
1.54      jmc        73: .Sq Pa BSDmakefile
1.43      espie      74: and
1.54      jmc        75: .Sq Pa .depend
1.43      espie      76: are BSD extensions.
                     77: .Pp
                     78: Standard options are as follows:
                     79: .Bl -tag -width Ds
                     80: .It Fl e
                     81: Specify that environment variables override macro assignments within
                     82: makefiles.
                     83: .It Fl f Ar makefile
                     84: Specify a makefile to read instead of the default
1.54      jmc        85: .Sq Pa makefile
1.43      espie      86: and
1.54      jmc        87: .Sq Pa Makefile .
1.43      espie      88: If
                     89: .Ar makefile
                     90: is
                     91: .Ql \- ,
                     92: standard input is read.
                     93: Multiple makefiles may be specified, and are read in the order specified.
                     94: .It Fl i
                     95: Ignore non-zero exit of shell commands in the makefile.
                     96: Equivalent to specifying
                     97: .Ql \-
                     98: before each command line in the makefile.
                     99: .It Fl k
                    100: Continue processing after errors are encountered, but only on those targets
                    101: that do not depend on the target whose creation caused the error.
                    102: .It Fl n
                    103: Display the commands that would have been executed, but do not actually
                    104: execute them.
                    105: .It Fl q
1.50      jmc       106: Do not execute any commands, but exit with status 0 if the specified targets
1.43      espie     107: are up-to-date, and 1 otherwise.
                    108: .It Fl r
                    109: Do not use the built-in rules specified in the system makefile.
                    110: .It Fl S
                    111: Stop processing when an error is encountered.
                    112: This is the default behavior.
                    113: This is needed to negate the
                    114: .Fl k
                    115: option during recursive builds.
                    116: .It Fl s
                    117: Do not echo commands as they are executed.
                    118: Equivalent to specifying
1.54      jmc       119: .Sq Ic @
1.43      espie     120: before each command line in the makefile.
                    121: .It Fl t
                    122: Rather than re-building a target as specified in the makefile, create it
                    123: or update its modification time to make it appear up-to-date.
1.60      espie     124: .It Ar NAME Ns = Ns Ar value
1.43      espie     125: Set the value of the variable
1.60      espie     126: .Ar NAME
1.43      espie     127: to
                    128: .Ar value .
                    129: .El
1.1       deraadt   130: .Pp
1.43      espie     131: Extended options are as follows:
1.1       deraadt   132: .Bl -tag -width Ds
1.9       millert   133: .It Fl B
1.3       deraadt   134: Try to be backwards compatible by executing a single shell per command and
                    135: by executing the commands to make the sources of a dependency line in sequence.
1.15      espie     136: This is turned on by default unless
                    137: .Fl j
                    138: is used.
1.1       deraadt   139: .It Fl D Ar variable
                    140: Define
                    141: .Ar variable
1.40      espie     142: to be 1.
1.1       deraadt   143: .It Fl d Ar flags
                    144: Turn on debugging, and specify which portions of
1.19      aaron     145: .Nm
1.1       deraadt   146: are to print debugging information.
1.14      aaron     147: .Ar flags
1.1       deraadt   148: is one or more of the following:
                    149: .Bl -tag -width Ds
                    150: .It Ar A
                    151: Print all possible debugging information;
                    152: equivalent to specifying all of the debugging flags.
                    153: .It Ar a
                    154: Print debugging information about archive searching and caching.
                    155: .It Ar c
                    156: Print debugging information about conditional evaluation.
                    157: .It Ar d
                    158: Print debugging information about directory searching and caching.
1.15      espie     159: .It Ar f
1.40      espie     160: Print debugging information about the expansion of for loops.
1.1       deraadt   161: .It Ar "g1"
                    162: Print the input graph before making anything.
                    163: .It Ar "g2"
                    164: Print the input graph after making everything, or before exiting
                    165: on error.
1.72      jmc       166: .It Ar J
                    167: Print job tokens showing which output corresponds to what job.
1.1       deraadt   168: .It Ar j
                    169: Print debugging information about running multiple shells.
1.40      espie     170: .It Ar l
                    171: Print commands in Makefile targets regardless of whether or not they are
                    172: prefixed by @.
                    173: Also known as loud behavior.
1.1       deraadt   174: .It Ar m
                    175: Print debugging information about making targets, including modification
                    176: dates.
1.82    ! espie     177: .It Ar n
        !           178: Print debugging information about target names equivalence computations.
1.75      espie     179: .It Ar p
1.77      jmc       180: Help finding concurrency issues for parallel make by adding some
1.76      espie     181: randomization.
1.75      espie     182: If
                    183: .Va RANDOM_ORDER
                    184: is defined,
                    185: targets will be shuffled before being built.
                    186: If
                    187: .Va RANDOM_DELAY
1.76      espie     188: is defined,
1.75      espie     189: .Nm
                    190: will wait between 0 and ${RANDOM_DELAY} seconds at the start of each job.
                    191: A given random seed can be forced by setting
                    192: .Va RANDOM_SEED ,
                    193: but this does not guarantee reproductibility.
1.1       deraadt   194: .It Ar s
                    195: Print debugging information about suffix-transformation rules.
                    196: .It Ar t
                    197: Print debugging information about target list maintenance.
                    198: .It Ar v
                    199: Print debugging information about variable assignment.
                    200: .El
                    201: .It Fl I Ar directory
                    202: Specify a directory in which to search for makefiles and included makefiles.
1.5       niklas    203: The system makefile directory (or directories, see the
                    204: .Fl m
                    205: option) is automatically included as part of this list.
1.1       deraadt   206: .It Fl j Ar max_jobs
                    207: Specify the maximum number of jobs that
1.19      aaron     208: .Nm
1.28      aaron     209: may have running at any one time.
                    210: Turns compatibility mode off, unless the
1.57      jmc       211: .Fl B
1.3       deraadt   212: flag is also specified.
1.5       niklas    213: .It Fl m Ar directory
1.50      jmc       214: Specify a directory in which to search for
                    215: .Pa sys.mk
1.40      espie     216: and makefiles included
1.28      aaron     217: via the <...> style.
                    218: Multiple directories can be added to form a search path.
1.14      aaron     219: This path will override the default system include path:
                    220: .Pa /usr/share/mk .
                    221: Furthermore, the system include path will be appended to the search path used
1.5       niklas    222: for "..."-style inclusions (see the
                    223: .Fl I
                    224: option).
1.15      espie     225: .It Fl P
1.19      aaron     226: Collate the output of a given job and display it only when the job finishes,
                    227: instead of mixing the output of parallel jobs together.
                    228: This option has no effect unless
1.15      espie     229: .Fl j
                    230: is used too.
1.9       millert   231: .It Fl V Ar variable
                    232: Print
                    233: .Nm make Ns 's
                    234: idea of the value of
1.40      espie     235: .Ar variable .
1.9       millert   236: Do not build any targets.
                    237: Multiple instances of this option may be specified;
                    238: the variables will be printed one per line,
                    239: with a blank line for each null or undefined variable.
1.1       deraadt   240: .El
                    241: .Pp
                    242: There are seven different types of lines in a makefile: file dependency
                    243: specifications, shell commands, variable assignments, include statements,
                    244: conditional directives, for loops, and comments.
1.43      espie     245: Of these, include statements, conditional directives and for loops are
                    246: extensions.
1.1       deraadt   247: .Pp
                    248: In general, lines may be continued from one line to the next by ending
                    249: them with a backslash
                    250: .Pq Ql \e .
                    251: The trailing newline character and initial whitespace on the following
                    252: line are compressed into a single space.
                    253: .Sh FILE DEPENDENCY SPECIFICATIONS
                    254: Dependency lines consist of one or more targets, an operator, and zero
                    255: or more sources.
1.19      aaron     256: This creates a relationship where the targets
                    257: .Dq depend
                    258: on the sources
1.1       deraadt   259: and are usually created from them.
                    260: The exact relationship between the target and the source is determined
                    261: by the operator that separates them.
1.43      espie     262: Note that the use of several targets is merely a shorthand for duplicate
1.50      jmc       263: rules.
1.43      espie     264: Specifically,
1.57      jmc       265: .Bd -literal -offset indent
1.43      espie     266: target1 target2: depa depb
                    267:        cmd1
                    268:        cmd2
                    269: .Ed
1.57      jmc       270: .Pp
1.43      espie     271: is just a short form of
1.57      jmc       272: .Bd -literal -offset indent
1.43      espie     273: target1: depa depb
                    274:        cmd1
                    275:        cmd2
                    276: target2: depa depb
                    277:        cmd1
                    278:        cmd2
                    279: .Ed
                    280: .Pp
                    281: .Nm
                    282: does not support Solaris syntax for true multiple targets:
1.57      jmc       283: .Bd -literal -offset indent
1.43      espie     284: target1 + target2: depa depb
                    285:        cmd1
                    286:        cmd2
                    287: .Ed
                    288: .Pp
1.40      espie     289: The operators are as follows:
1.1       deraadt   290: .Bl -tag -width flag
                    291: .It Ic \&:
                    292: A target is considered out-of-date if its modification time is less than
                    293: those of any of its sources.
                    294: Sources for a target accumulate over dependency lines when this operator
                    295: is used.
                    296: The target is removed if
1.19      aaron     297: .Nm
1.1       deraadt   298: is interrupted.
                    299: .It Ic \&!
                    300: Targets are always re-created, but not until all sources have been
                    301: examined and re-created as necessary.
                    302: Sources for a target accumulate over dependency lines when this operator
                    303: is used.
                    304: The target is removed if
1.19      aaron     305: .Nm
1.1       deraadt   306: is interrupted.
                    307: .It Ic \&::
                    308: If no sources are specified, the target is always re-created.
                    309: Otherwise, a target is considered out-of-date if any of its sources has
                    310: been modified more recently than the target.
                    311: Sources for a target do not accumulate over dependency lines when this
                    312: operator is used.
                    313: The target will not be removed if
1.19      aaron     314: .Nm
1.1       deraadt   315: is interrupted.
                    316: .El
                    317: .Pp
1.43      espie     318: The
                    319: .Ic \&::
                    320: operator is a fairly standard extension.
                    321: The
1.56      jmc       322: .Ic !\&
1.43      espie     323: operator is a BSD extension.
                    324: .Pp
1.50      jmc       325: As an extension, targets and sources may contain the shell wildcard
1.43      espie     326: expressions
1.55      jmc       327: .Ql \&? ,
1.1       deraadt   328: .Ql * ,
                    329: .Ql []
                    330: and
                    331: .Ql {} .
1.15      espie     332: The expressions
1.55      jmc       333: .Ql \&? ,
1.1       deraadt   334: .Ql *
                    335: and
                    336: .Ql []
                    337: may only be used as part of the final
                    338: component of the target or source, and must be used to describe existing
                    339: files.
1.15      espie     340: The expression
1.1       deraadt   341: .Ql {}
                    342: need not necessarily be used to describe existing files.
                    343: Expansion is in directory order, not alphabetically as done in the shell.
1.43      espie     344: .Pp
                    345: For maximum portability, target names should only consist of periods,
                    346: underscores, digits and alphabetic characters.
1.1       deraadt   347: .Sh SHELL COMMANDS
                    348: Each target may have associated with it a series of shell commands, normally
                    349: used to create the target.
                    350: Each of the commands in this script
                    351: .Em must
                    352: be preceded by a tab.
                    353: While any target may appear on a dependency line, only one of these
                    354: dependencies may be followed by a creation script, unless the
1.54      jmc       355: .Sq Ic ::
1.1       deraadt   356: operator is used.
                    357: .Pp
1.34      espie     358: If a command line begins with a combination of the characters,
1.54      jmc       359: .Sq Ic @ ,
                    360: .Sq Ic \-
1.1       deraadt   361: and/or
1.54      jmc       362: .Sq Ic + ,
1.57      jmc       363: the command is treated specially:
1.33      espie     364: .Bl -tag -width `@'
1.54      jmc       365: .It Sq Ic @
1.1       deraadt   366: causes the command not to be echoed before it is executed.
1.54      jmc       367: .It Sq Ic \-
1.1       deraadt   368: causes any non-zero exit status of the command line to be ignored.
1.54      jmc       369: .It Sq Ic +
1.33      espie     370: causes the command to be executed even if
                    371: .Fl n
1.57      jmc       372: has been specified.
                    373: (This can be useful to debug recursive Makefiles.)
1.33      espie     374: .El
1.43      espie     375: .Pp
1.50      jmc       376: The command is always executed using
1.43      espie     377: .Pa /bin/sh
                    378: in
                    379: .Qq set -e
                    380: mode.
1.1       deraadt   381: .Sh VARIABLE ASSIGNMENTS
1.14      aaron     382: Variables in
1.19      aaron     383: .Nm
1.14      aaron     384: are much like variables in the shell, and, by tradition,
1.1       deraadt   385: consist of all upper-case letters.
1.60      espie     386: They are also called
                    387: .Sq macros
                    388: in various texts.
1.43      espie     389: For portability, only periods, underscores, digits and letters should be
                    390: used for variable names.
1.1       deraadt   391: The five operators that can be used to assign values to variables are as
                    392: follows:
                    393: .Bl -tag -width Ds
                    394: .It Ic \&=
                    395: Assign the value to the variable.
                    396: Any previous value is overridden.
1.43      espie     397: .It Ic \&:=
                    398: Assign with expansion, i.e., expand the value before assigning it
1.57      jmc       399: to the variable (extension).
1.1       deraadt   400: .It Ic \&+=
1.43      espie     401: Append the value to the current value of the variable (extension).
1.1       deraadt   402: .It Ic \&?=
1.43      espie     403: Assign the value to the variable if it is not already defined (BSD
                    404: extension).
1.1       deraadt   405: Normally, expansion is not done until the variable is referenced.
                    406: .It Ic \&!=
                    407: Expand the value and pass it to the shell for execution and assign
                    408: the result to the variable.
1.43      espie     409: Any newlines in the result are replaced with spaces (BSD extension).
1.1       deraadt   410: .El
                    411: .Pp
1.14      aaron     412: Any whitespace before the assigned
1.1       deraadt   413: .Ar value
                    414: is removed; if the value is being appended, a single space is inserted
                    415: between the previous contents of the variable and the appended value.
                    416: .Pp
                    417: Variables are expanded by surrounding the variable name with either
                    418: curly braces
                    419: .Pq Ql {}
                    420: or parentheses
                    421: .Pq Ql ()
                    422: and preceding it with
                    423: a dollar sign
                    424: .Pq Ql \&$ .
                    425: If the variable name contains only a single letter, the surrounding
                    426: braces or parentheses are not required.
                    427: This shorter form is not recommended.
                    428: .Pp
                    429: Variable substitution occurs at two distinct times, depending on where
                    430: the variable is being used.
                    431: Variables in dependency lines are expanded as the line is read.
                    432: Variables in shell commands are expanded when the shell command is
                    433: executed.
                    434: .Pp
                    435: The four different classes of variables (in order of increasing precedence)
                    436: are:
                    437: .Bl -tag -width Ds
                    438: .It Environment variables
                    439: Variables defined as part of
                    440: .Nm make Ns 's
                    441: environment.
                    442: .It Global variables
                    443: Variables defined in the makefile or in included makefiles.
                    444: .It Command line variables
                    445: Variables defined as part of the command line.
                    446: .It Local variables
                    447: Variables that are defined specific to a certain target.
1.43      espie     448: Standard local variables are as follows:
1.1       deraadt   449: .Bl -tag -width ".ARCHIVE"
1.43      espie     450: .It Va @
                    451: The name of the target.
                    452: .It Va \&%
                    453: The name of the archive member (only valid for library rules).
                    454: .It Va \&!
                    455: The name of the archive file (only valid for library rules).
                    456: .It Va \&?
                    457: The list of prerequisites for this target that were deemed out-of-date.
                    458: .It Va \&<
                    459: The name of the source from which this target is to be built, if a valid
                    460: implied rule (suffix rule) is in scope.
                    461: .It Va *
                    462: The file prefix of the file, containing only the file portion,
                    463: no suffix or preceding directory components.
                    464: .El
                    465: .Pp
                    466: The six variables
1.54      jmc       467: .Sq Va "@F" ,
                    468: .Sq Va "@D" ,
                    469: .Sq Va "<F" ,
                    470: .Sq Va "<D" ,
                    471: .Sq Va "*F" ,
1.43      espie     472: and
1.54      jmc       473: .Sq Va "*D"
1.43      espie     474: yield the
                    475: .Qq filename
                    476: and
                    477: .Qq directory
                    478: parts of the corresponding macros.
                    479: .Pp
                    480: For maximum compatibility,
1.54      jmc       481: .Sq Va \&<
1.43      espie     482: should only be used for actual implied rules.
                    483: It is also set when there is an implied rule that matches the current
1.54      jmc       484: dependency in scope.
                    485: That is, in
1.57      jmc       486: .Bd -literal -offset indent
1.65      jmc       487: \&.SUFFIXES: .c .o
1.43      espie     488: file.o: file.c
                    489:        cmd1 $<
                    490:
                    491: \&.c.o:
                    492:        cmd2
                    493: .Ed
1.57      jmc       494: .Pp
1.43      espie     495: building
                    496: .Pa file.o
                    497: will execute
                    498: .Qq cmd1 file.c .
                    499: .Pp
                    500: As an extension,
                    501: .Nm
1.47      jsyn      502: supports the following local variables:
1.43      espie     503: .Bl -tag -width ".ARCHIVE"
                    504: .It Va \&>
                    505: The list of all sources for this target.
1.1       deraadt   506: .It Va .ALLSRC
1.43      espie     507: Synonym for
1.54      jmc       508: .Sq Va \&> .
1.1       deraadt   509: .It Va .ARCHIVE
1.43      espie     510: Synonym for
1.54      jmc       511: .Sq Va \&! .
1.1       deraadt   512: .It Va .IMPSRC
1.43      espie     513: Synonym for
1.54      jmc       514: .Sq Va \&< .
1.1       deraadt   515: .It Va .MEMBER
1.43      espie     516: Synonym for
1.54      jmc       517: .Sq Va \&% .
1.1       deraadt   518: .It Va .OODATE
1.43      espie     519: Synonym for
1.54      jmc       520: .Sq Va \&? .
1.1       deraadt   521: .It Va .PREFIX
1.43      espie     522: Synonym for
1.54      jmc       523: .Sq Va * .
1.1       deraadt   524: .It Va .TARGET
1.43      espie     525: Synonym for
1.54      jmc       526: .Sq Va @ .
1.1       deraadt   527: .El
                    528: .Pp
1.43      espie     529: These variables may be used on the dependency half of dependency
                    530: lines, when they make sense.
1.15      espie     531: .El
1.1       deraadt   532: .Pp
                    533: In addition,
1.19      aaron     534: .Nm
                    535: sets or knows about the following internal variables, or environment
1.15      espie     536: variables:
1.1       deraadt   537: .Bl -tag -width MAKEFLAGS
                    538: .It Va \&$
                    539: A single dollar sign
                    540: .Ql \&$ ,
1.29      aaron     541: i.e.,
1.1       deraadt   542: .Ql \&$$
                    543: expands to a single dollar
                    544: sign.
                    545: .It Va .MAKE
                    546: The name that
1.19      aaron     547: .Nm
1.1       deraadt   548: was executed with
1.14      aaron     549: .Pq Va argv Ns Op 0 .
1.1       deraadt   550: .It Va .CURDIR
                    551: A path to the directory where
1.19      aaron     552: .Nm
1.1       deraadt   553: was executed.
                    554: .It Va .OBJDIR
                    555: A path to the directory where the targets are built.
1.8       deraadt   556: At startup,
1.19      aaron     557: .Nm
1.8       deraadt   558: searches for an alternate directory to place target files -- it
                    559: will attempt to change into this special directory.
1.19      aaron     560: First, if
                    561: .Ev MAKEOBJDIRPREFIX
                    562: is defined,
                    563: .Nm
1.18      espie     564: prepends its contents to the current directory name and tries for
1.28      aaron     565: the resulting directory.
                    566: If that fails,
1.19      aaron     567: .Nm
1.18      espie     568: remains in the current directory.
1.19      aaron     569: If
1.15      espie     570: .Ev MAKEOBJDIRPREFIX
1.18      espie     571: is not defined,
1.19      aaron     572: .Nm
1.18      espie     573: checks
1.19      aaron     574: .Ev MAKEOBJDIR
1.28      aaron     575: and tries to change into that directory.
                    576: Should that fail,
1.19      aaron     577: .Nm
1.28      aaron     578: remains in the current directory.
                    579: If
1.18      espie     580: .Ev MAKEOBJDIR
                    581: is not defined, it tries to change into the directory named
                    582: .Pa obj.${MACHINE}
1.19      aaron     583: (see
                    584: .Va MACHINE
1.28      aaron     585: variable).
                    586: If it still has found no special directory,
1.19      aaron     587: .Nm
1.18      espie     588: next tries the directory named
                    589: .Pa obj .
                    590: If this fails,
1.19      aaron     591: .Nm
                    592: tries to prepend
                    593: .Pa /usr/obj
                    594: to the current directory name.
1.18      espie     595: Finally, if none of these directories are available
1.19      aaron     596: .Nm
1.8       deraadt   597: will settle for and use the current directory.
1.15      espie     598: .It Va .MAKEFLAGS
1.1       deraadt   599: The environment variable
1.14      aaron     600: .Ev MAKEFLAGS
1.1       deraadt   601: may contain anything that
                    602: may be specified on
                    603: .Nm make Ns 's
1.28      aaron     604: command line.
                    605: Its contents are stored in
1.15      espie     606: .Nm make Ns 's
1.19      aaron     607: .Va .MAKEFLAGS
1.15      espie     608: variable.
1.40      espie     609: Anything specified on
1.1       deraadt   610: .Nm make Ns 's
                    611: command line is appended to the
1.15      espie     612: .Va .MAKEFLAGS
                    613: variable which is then
1.19      aaron     614: entered into the environment as
1.14      aaron     615: .Ev MAKEFLAGS
1.15      espie     616: for all programs which
1.19      aaron     617: .Nm
1.1       deraadt   618: executes.
1.15      espie     619: .It Va MFLAGS
1.19      aaron     620: A shorter synonym for
1.15      espie     621: .Va .MAKEFLAGS .
1.9       millert   622: .It Ev PWD
                    623: Alternate path to the current directory.
1.19      aaron     624: .Nm
1.9       millert   625: normally sets
1.54      jmc       626: .Sq Va .CURDIR
1.9       millert   627: to the canonical path given by
1.49      jmc       628: .Xr getcwd 3 .
1.9       millert   629: However, if the environment variable
1.14      aaron     630: .Ev PWD
1.9       millert   631: is set and gives a path to the current directory, then
1.19      aaron     632: .Nm
1.9       millert   633: sets
1.54      jmc       634: .Sq Va .CURDIR
1.9       millert   635: to the value of
1.14      aaron     636: .Ev PWD
1.9       millert   637: instead.
1.14      aaron     638: .Ev PWD
1.15      espie     639: is always set to the value of
1.54      jmc       640: .Sq Va .OBJDIR
1.9       millert   641: for all programs which
1.19      aaron     642: .Nm
1.9       millert   643: executes.
1.15      espie     644: .It Va .TARGETS
1.19      aaron     645: List of targets
                    646: .Nm
1.18      espie     647: is currently building.
1.15      espie     648: .It Va .INCLUDES
1.19      aaron     649: See
1.18      espie     650: .Ic .INCLUDES
1.57      jmc       651: special target.
1.15      espie     652: .It Va .LIBS
1.19      aaron     653: See
1.18      espie     654: .Ic .LIBS
1.57      jmc       655: special target.
1.15      espie     656: .It Va MACHINE
1.19      aaron     657: Name of the machine architecture
                    658: .Nm
1.18      espie     659: is running on, obtained from the
                    660: .Ev MACHINE
1.19      aaron     661: environment variable, or through
1.44      deraadt   662: .Xr uname 3
1.18      espie     663: if not defined.
1.15      espie     664: .It Va MACHINE_ARCH
1.18      espie     665: Name of the machine architecture
1.19      aaron     666: .Nm
1.18      espie     667: was compiled for, obtained from the
1.19      aaron     668: .Ev MACHINE_ARCH
1.18      espie     669: environment variable, or defined at compilation time.
1.80      bluhm     670: .It Va MAKEFILE
                    671: Possibly the file name of the last makefile that has been read.
                    672: It should not be used; see the
                    673: .Sx BUGS
                    674: section below.
1.1       deraadt   675: .El
                    676: .Pp
                    677: Variable expansion may be modified to select or modify each word of the
1.48      pvalchev  678: variable (where
1.19      aaron     679: .Dq word
1.48      pvalchev  680: is a whitespace delimited sequence of characters).
1.1       deraadt   681: The general format of a variable expansion is as follows:
                    682: .Pp
                    683: .Dl {variable[:modifier[:...]]}
                    684: .Pp
                    685: Each modifier begins with a colon and one of the following
                    686: special characters.
                    687: The colon may be escaped with a backslash
                    688: .Pq Ql \e .
1.54      jmc       689: .Bl -tag -width Ds
1.58      espie     690: .It Cm :E
1.1       deraadt   691: Replaces each word in the variable with its suffix.
1.58      espie     692: .It Cm :H
1.1       deraadt   693: Replaces each word in the variable with everything but the last component.
1.58      espie     694: .It Cm :L
1.20      espie     695: Replaces each word in the variable with its lower case equivalent.
1.58      espie     696: .It Cm :U
1.20      espie     697: Replaces each word in the variable with its upper case equivalent.
1.58      espie     698: .It Cm :M Ns Ar pattern
1.1       deraadt   699: Select only those words that match the rest of the modifier.
                    700: The standard shell wildcard characters
                    701: .Pf ( Ql * ,
1.55      jmc       702: .Ql \&? ,
1.1       deraadt   703: and
1.54      jmc       704: .Ql [] )
1.1       deraadt   705: may
                    706: be used.
                    707: The wildcard characters may be escaped with a backslash
                    708: .Pq Ql \e .
1.58      espie     709: .It Cm :N Ns Ar pattern
1.1       deraadt   710: This is identical to
1.58      espie     711: .Cm :M ,
1.1       deraadt   712: but selects all words which do not match
                    713: the rest of the modifier.
1.58      espie     714: .It Cm :Q
1.10      millert   715: Quotes every shell meta-character in the variable, so that it can be passed
                    716: safely through recursive invocations of
1.14      aaron     717: .Nm make .
1.58      espie     718: .It Cm :R
1.1       deraadt   719: Replaces each word in the variable with everything but its suffix.
                    720: .Sm off
1.58      espie     721: .It Cm :S No \&/ Ar old_string Xo
1.10      millert   722: .No \&/ Ar new_string
                    723: .No \&/ Op Cm 1g
1.1       deraadt   724: .Xc
                    725: .Sm on
                    726: Modify the first occurrence of
1.10      millert   727: .Ar old_string
                    728: in the variable's value, replacing it with
                    729: .Ar new_string .
1.1       deraadt   730: If a
                    731: .Ql g
                    732: is appended to the last slash of the pattern, all occurrences
                    733: in each word are replaced.
1.10      millert   734: If a
                    735: .Ql 1
                    736: is appended to the last slash of the pattern, only the first word
                    737: is affected.
1.1       deraadt   738: If
1.10      millert   739: .Ar old_string
                    740: begins with a caret
1.1       deraadt   741: .Pq Ql ^ ,
1.10      millert   742: .Ar old_string
1.1       deraadt   743: is anchored at the beginning of each word.
                    744: If
1.10      millert   745: .Ar old_string
1.1       deraadt   746: ends with a dollar sign
                    747: .Pq Ql \&$ ,
                    748: it is anchored at the end of each word.
                    749: Inside
                    750: .Ar new_string ,
                    751: an ampersand
                    752: .Pq Ql &
                    753: is replaced by
1.10      millert   754: .Ar old_string
                    755: (without any
                    756: .Ql ^
                    757: or
                    758: .Ql \&$ ) .
1.1       deraadt   759: Any character may be used as a delimiter for the parts of the modifier
                    760: string.
                    761: The anchoring, ampersand and delimiter characters may be escaped with a
                    762: backslash
                    763: .Pq Ql \e .
                    764: .Pp
                    765: Variable expansion occurs in the normal fashion inside both
                    766: .Ar old_string
                    767: and
                    768: .Ar new_string
                    769: with the single exception that a backslash is used to prevent the expansion
                    770: of a dollar sign
1.10      millert   771: .Pq Ql \&$ ,
1.1       deraadt   772: not a preceding dollar sign as is usual.
1.10      millert   773: .Sm off
1.58      espie     774: .It Cm :C No \&/ Ar pattern Xo
1.10      millert   775: .No \&/ Ar replacement
                    776: .No \&/ Op Cm 1g
                    777: .Xc
                    778: .Sm on
                    779: The
1.58      espie     780: .Cm :C
1.10      millert   781: modifier is just like the
1.58      espie     782: .Cm :S
1.13      deraadt   783: modifier except that the old and new strings, instead of being
1.10      millert   784: simple strings, are a regular expression (see
                    785: .Xr regex 3 )
                    786: and an
                    787: .Xr ed 1 Ns \-style
1.28      aaron     788: replacement string.
                    789: Normally, the first occurrence of the pattern in
                    790: each word of the value is changed.
                    791: The
1.10      millert   792: .Ql 1
                    793: modifier causes the substitution to apply to at most one word; the
                    794: .Ql g
                    795: modifier causes the substitution to apply to as many instances of the
1.28      aaron     796: search pattern as occur in the word or words it is found in.
                    797: Note that
1.10      millert   798: .Ql 1
                    799: and
                    800: .Ql g
                    801: are orthogonal; the former specifies whether multiple words are
                    802: potentially affected, the latter whether multiple substitutions can
                    803: potentially occur within each affected word.
1.58      espie     804: .It Cm :T
1.1       deraadt   805: Replaces each word in the variable with its last component.
1.59      jmc       806: .It Ar :old_string Ns = Ns Ar new_string
1.1       deraadt   807: This is the
                    808: .At V
                    809: style variable substitution.
                    810: It must be the last modifier specified.
1.9       millert   811: If
1.1       deraadt   812: .Ar old_string
                    813: or
                    814: .Ar new_string
                    815: do not contain the pattern matching character
                    816: .Ar %
1.9       millert   817: then it is assumed that they are
1.1       deraadt   818: anchored at the end of each word, so only suffixes or entire
1.28      aaron     819: words may be replaced.
                    820: Otherwise
1.1       deraadt   821: .Ar %
1.9       millert   822: is the substring of
                    823: .Ar old_string
1.1       deraadt   824: to be replaced in
1.53      jmc       825: .Ar new_string .
1.1       deraadt   826: .El
1.53      jmc       827: .Pp
1.50      jmc       828: All modifiers are BSD extensions, except for the standard
1.46      espie     829: .At V
                    830: style variable substitution.
1.1       deraadt   831: .Sh INCLUDE STATEMENTS, CONDITIONALS AND FOR LOOPS
1.28      aaron     832: Makefile inclusion, conditional structures and for loops reminiscent
1.1       deraadt   833: of the C programming language are provided in
                    834: .Nm make .
                    835: All such structures are identified by a line beginning with a single
                    836: dot
                    837: .Pq Ql \&.
                    838: character.
1.46      espie     839: Whitespace characters may follow this dot, e.g.,
1.57      jmc       840: .Bd -literal -offset indent
                    841: \&.include <file>
1.46      espie     842: .Ed
                    843: and
1.57      jmc       844: .Bd -literal -offset indent -compact
                    845: \&.   include <file>
1.46      espie     846: .Ed
1.57      jmc       847: .Pp
1.46      espie     848: are identical constructs.
1.1       deraadt   849: Files are included with either
                    850: .Ql .include <file>
                    851: or
                    852: .Ql .include \*qfile\*q .
                    853: Variables between the angle brackets or double quotes are expanded
                    854: to form the file name.
                    855: If angle brackets are used, the included makefile is expected to be in
                    856: the system makefile directory.
                    857: If double quotes are used, the including makefile's directory and any
                    858: directories specified using the
                    859: .Fl I
                    860: option are searched before the system
                    861: makefile directory.
                    862: .Pp
                    863: Conditional expressions are also preceded by a single dot as the first
                    864: character of a line.
                    865: The possible conditionals are as follows:
                    866: .Bl -tag -width Ds
                    867: .It Ic .undef Ar variable
                    868: Un-define the specified global variable.
                    869: Only global variables may be un-defined.
1.69      espie     870: .It Ic .poison Ar variable
                    871: Poison the specified global variable.
1.70      jmc       872: Any further reference to
1.69      espie     873: .Ar variable
                    874: will be flagged as an error.
1.70      jmc       875: .It Ic .poison !defined Pq Ar variable
1.69      espie     876: It is an error to try to use the value of
                    877: .Ar variable
1.70      jmc       878: in a context where it is not defined.
                    879: .It Ic .poison empty Pq Ar variable
1.69      espie     880: It is an error to try to use the value of
                    881: .Ar variable
1.70      jmc       882: in a context where it is not defined or empty.
1.1       deraadt   883: .It Xo
                    884: .Ic \&.if
                    885: .Oo \&! Oc Ns Ar expression
                    886: .Op Ar operator expression ...
                    887: .Xc
                    888: Test the value of an expression.
                    889: .It Xo
                    890: .Ic .ifdef
                    891: .Oo \&! Oc Ns Ar variable
                    892: .Op Ar operator variable ...
                    893: .Xc
                    894: Test the value of a variable.
                    895: .It Xo
                    896: .Ic .ifndef
                    897: .Oo \&! Oc Ns Ar variable
                    898: .Op Ar operator variable ...
                    899: .Xc
                    900: Test the value of a variable.
                    901: .It Xo
                    902: .Ic .ifmake
                    903: .Oo \&! Oc Ns Ar target
                    904: .Op Ar operator target ...
                    905: .Xc
                    906: Test the target being built.
                    907: .It Xo
                    908: .Ic .ifnmake
                    909: .Oo \&! Oc Ar target
                    910: .Op Ar operator target ...
                    911: .Xc
                    912: Test the target being built.
                    913: .It Ic .else
                    914: Reverse the sense of the last conditional.
                    915: .It Xo
                    916: .Ic .elif
                    917: .Oo \&! Oc Ar expression
                    918: .Op Ar operator expression ...
                    919: .Xc
                    920: A combination of
1.54      jmc       921: .Sq Ic .else
1.1       deraadt   922: followed by
1.54      jmc       923: .Sq Ic .if .
1.1       deraadt   924: .It Xo
                    925: .Ic .elifdef
                    926: .Oo \&! Oc Ns Ar variable
                    927: .Op Ar operator variable ...
                    928: .Xc
                    929: A combination of
1.54      jmc       930: .Sq Ic .else
1.1       deraadt   931: followed by
1.54      jmc       932: .Sq Ic .ifdef .
1.1       deraadt   933: .It Xo
                    934: .Ic .elifndef
                    935: .Oo \&! Oc Ns Ar variable
                    936: .Op Ar operator variable ...
                    937: .Xc
                    938: A combination of
1.54      jmc       939: .Sq Ic .else
1.1       deraadt   940: followed by
1.54      jmc       941: .Sq Ic .ifndef .
1.1       deraadt   942: .It Xo
                    943: .Ic .elifmake
                    944: .Oo \&! Oc Ns Ar target
                    945: .Op Ar operator target ...
                    946: .Xc
                    947: A combination of
1.54      jmc       948: .Sq Ic .else
1.1       deraadt   949: followed by
1.54      jmc       950: .Sq Ic .ifmake .
1.1       deraadt   951: .It Xo
                    952: .Ic .elifnmake
                    953: .Oo \&! Oc Ns Ar target
                    954: .Op Ar operator target ...
                    955: .Xc
                    956: A combination of
1.54      jmc       957: .Sq Ic .else
1.1       deraadt   958: followed by
1.54      jmc       959: .Sq Ic .ifnmake .
1.1       deraadt   960: .It Ic .endif
                    961: End the body of the conditional.
                    962: .El
                    963: .Pp
                    964: The
                    965: .Ar operator
                    966: may be any one of the following:
                    967: .Bl -tag -width "Cm XX"
                    968: .It Cm \&|\&|
                    969: logical OR
                    970: .It Cm \&&&
                    971: Logical
                    972: .Tn AND ;
                    973: of higher precedence than
1.46      espie     974: .Dq \&|\&| .
1.1       deraadt   975: .El
                    976: .Pp
                    977: As in C,
1.19      aaron     978: .Nm
1.1       deraadt   979: will only evaluate a conditional as far as is necessary to determine
                    980: its value.
1.9       millert   981: Parentheses may be used to change the order of evaluation.
1.1       deraadt   982: The boolean operator
1.54      jmc       983: .Sq Ic \&!
1.1       deraadt   984: may be used to logically negate an entire
                    985: conditional.
                    986: It is of higher precedence than
1.54      jmc       987: .Sq Ic \&&& .
1.1       deraadt   988: .Pp
                    989: The value of
                    990: .Ar expression
                    991: may be any of the following:
1.54      jmc       992: .Bl -tag -width defined
1.1       deraadt   993: .It Ic defined
                    994: Takes a variable name as an argument and evaluates to true if the variable
                    995: has been defined.
                    996: .It Ic make
                    997: Takes a target name as an argument and evaluates to true if the target
                    998: was specified as part of
                    999: .Nm make Ns 's
                   1000: command line or was declared the default target (either implicitly or
                   1001: explicitly, see
                   1002: .Va .MAIN )
                   1003: before the line containing the conditional.
                   1004: .It Ic empty
                   1005: Takes a variable, with possible modifiers, and evaluates to true if
                   1006: the expansion of the variable would result in an empty string.
                   1007: .It Ic exists
                   1008: Takes a file name as an argument and evaluates to true if the file exists.
                   1009: The file is searched for on the system search path (see
                   1010: .Va .PATH ) .
                   1011: .It Ic target
                   1012: Takes a target name as an argument and evaluates to true if the target
                   1013: has been defined.
                   1014: .El
                   1015: .Pp
1.14      aaron    1016: .Ar expression
1.28      aaron    1017: may also be an arithmetic or string comparison.
                   1018: Variable expansion is
1.1       deraadt  1019: performed on both sides of the comparison, after which the integral
1.28      aaron    1020: values are compared.
                   1021: A value is interpreted as hexadecimal if it is
1.1       deraadt  1022: preceded by 0x, otherwise it is decimal; octal numbers are not supported.
1.28      aaron    1023: The standard C relational operators are all supported.
                   1024: If after
1.1       deraadt  1025: variable expansion, either the left or right hand side of a
1.54      jmc      1026: .Sq Ic ==
1.1       deraadt  1027: or
1.54      jmc      1028: .Sq Ic "!="
1.1       deraadt  1029: operator is not an integral value, then
                   1030: string comparison is performed between the expanded
                   1031: variables.
                   1032: If no relational operator is given, it is assumed that the expanded
                   1033: variable is being compared against 0.
                   1034: .Pp
                   1035: When
1.19      aaron    1036: .Nm
1.14      aaron    1037: is evaluating one of these conditional expressions, and it encounters
1.19      aaron    1038: a word it doesn't recognize, either the
                   1039: .Dq make
                   1040: or
                   1041: .Dq defined
1.1       deraadt  1042: expression is applied to it, depending on the form of the conditional.
                   1043: If the form is
1.54      jmc      1044: .Sq Ic .ifdef
1.1       deraadt  1045: or
1.54      jmc      1046: .Sq Ic .ifndef ,
1.19      aaron    1047: the
                   1048: .Dq defined
                   1049: expression is applied.
1.1       deraadt  1050: Similarly, if the form is
1.54      jmc      1051: .Sq Ic .ifmake
1.1       deraadt  1052: or
1.54      jmc      1053: .Sq Ic .ifnmake ,
1.19      aaron    1054: the
                   1055: .Dq make
1.1       deraadt  1056: expression is applied.
                   1057: .Pp
                   1058: If the conditional evaluates to true the parsing of the makefile continues
                   1059: as before.
                   1060: If it evaluates to false, the following lines are skipped.
                   1061: In both cases this continues until a
1.54      jmc      1062: .Sq Ic .else
1.1       deraadt  1063: or
1.54      jmc      1064: .Sq Ic .endif
1.1       deraadt  1065: is found.
1.9       millert  1066: .Pp
1.1       deraadt  1067: For loops are typically used to apply a set of rules to a list of files.
                   1068: The syntax of a for loop is:
1.54      jmc      1069: .Bd -unfilled -offset indent
                   1070: .Xo
                   1071: .Ic .for Ar variable Op Ar variable ...
1.9       millert  1072: .Ic in
1.1       deraadt  1073: .Ar expression
                   1074: .Xc
1.54      jmc      1075:        <make-rules>
1.1       deraadt  1076: .Ic \&.endfor
1.54      jmc      1077: .Ed
                   1078: .Pp
1.1       deraadt  1079: After the for
1.14      aaron    1080: .Ar expression
1.28      aaron    1081: is evaluated, it is split into words.
1.50      jmc      1082: On each iteration of the loop, one word is assigned to each
1.41      espie    1083: .Ar variable ,
                   1084: in order,
1.50      jmc      1085: and these
                   1086: .Ar variables
1.41      espie    1087: are substituted in the
1.9       millert  1088: .Ic make-rules
1.1       deraadt  1089: inside the body of the for loop.
1.41      espie    1090: The number of words must match the number of iteration variables;
                   1091: that is, if there are three iteration variables, the number of words
1.48      pvalchev 1092: must be a multiple of three.
1.45      espie    1093: .Pp
                   1094: Loops and conditional expressions may nest arbitrarily, but
                   1095: they may not cross include file boundaries.
1.1       deraadt  1096: .Sh COMMENTS
                   1097: Comments begin with a hash
                   1098: .Pq Ql \&#
                   1099: character, anywhere but in a shell
                   1100: command line, and continue to the end of the line.
                   1101: .Sh SPECIAL SOURCES
1.54      jmc      1102: .Bl -tag -width ".PRECIOUS"
1.1       deraadt  1103: .It Ic .IGNORE
                   1104: Ignore any errors from the commands associated with this target, exactly
                   1105: as if they all were preceded by a dash
                   1106: .Pq Ql \- .
1.10      millert  1107: .It Ic .MADE
1.19      aaron    1108: Mark all sources of this target as being up-to-date.
1.1       deraadt  1109: .It Ic .MAKE
                   1110: Execute the commands associated with this target even if the
                   1111: .Fl n
                   1112: or
                   1113: .Fl t
                   1114: options were specified.
                   1115: Normally used to mark recursive
                   1116: .Nm make Ns 's .
                   1117: .It Ic .NOTMAIN
                   1118: Normally
1.19      aaron    1119: .Nm
1.1       deraadt  1120: selects the first target it encounters as the default target to be built
                   1121: if no target was specified.
                   1122: This source prevents this target from being selected.
                   1123: .It Ic .OPTIONAL
                   1124: If a target is marked with this attribute and
1.19      aaron    1125: .Nm
1.1       deraadt  1126: can't figure out how to create it, it will ignore this fact and assume
                   1127: the file isn't needed or already exists.
                   1128: .It Ic .PRECIOUS
                   1129: When
1.19      aaron    1130: .Nm
1.1       deraadt  1131: is interrupted, it removes any partially made targets.
                   1132: This source prevents the target from being removed.
                   1133: .It Ic .SILENT
                   1134: Do not echo any of the commands associated with this target, exactly
                   1135: as if they all were preceded by an at sign
                   1136: .Pq Ql @ .
                   1137: .It Ic .USE
                   1138: Turn the target into
1.14      aaron    1139: .Nm make Ns 's
1.1       deraadt  1140: version of a macro.
                   1141: When the target is used as a source for another target, the other target
                   1142: acquires the commands, sources, and attributes (except for
                   1143: .Ic .USE )
                   1144: of the
                   1145: source.
                   1146: If the target already has commands, the
                   1147: .Ic .USE
                   1148: target's commands are appended
                   1149: to them.
1.4       deraadt  1150: .It Ic .WAIT
1.48      pvalchev 1151: If
1.4       deraadt  1152: .Ic .WAIT
1.48      pvalchev 1153: appears in a dependency line, the sources that precede it are
1.28      aaron    1154: made before the sources that succeed it in the line.
1.48      pvalchev 1155: Loops are not
1.4       deraadt  1156: detected and targets that form loops will be silently ignored.
1.1       deraadt  1157: .El
1.81      jmc      1158: .Sh SPECIAL TARGETS
1.29      aaron    1159: Special targets may not be included with other targets, i.e., they must be
1.1       deraadt  1160: the only target specified.
1.54      jmc      1161: .Bl -tag -width ".NOTPARALLEL"
1.1       deraadt  1162: .It Ic .BEGIN
                   1163: Any command lines attached to this target are executed before anything
                   1164: else is done.
                   1165: .It Ic .DEFAULT
                   1166: This is sort of a
                   1167: .Ic .USE
                   1168: rule for any target (that was used only as a
                   1169: source) that
1.19      aaron    1170: .Nm
1.1       deraadt  1171: can't figure out any other way to create.
                   1172: Only the shell script is used.
                   1173: The
                   1174: .Ic .IMPSRC
                   1175: variable of a target that inherits
                   1176: .Ic .DEFAULT Ns 's
                   1177: commands is set
                   1178: to the target's own name.
                   1179: .It Ic .END
                   1180: Any command lines attached to this target are executed after everything
                   1181: else is done.
                   1182: .It Ic .IGNORE
                   1183: Mark each of the sources with the
                   1184: .Ic .IGNORE
                   1185: attribute.
                   1186: If no sources are specified, this is the equivalent of specifying the
                   1187: .Fl i
                   1188: option.
1.18      espie    1189: .It Ic .INCLUDES
                   1190: A list of suffixes that indicate files that can be included in a source
1.28      aaron    1191: file.
                   1192: The suffix must have already been declared with
1.18      espie    1193: .Ic .SUFFIXES ,
1.48      pvalchev 1194: any suffix so declared will have the directories in its search path (see
1.18      espie    1195: .Ic .PATH )
1.19      aaron    1196: placed in the
1.18      espie    1197: .Va .INCLUDES
1.19      aaron    1198: special variable, each preceded by a
                   1199: .Fl I
1.18      espie    1200: flag.
1.1       deraadt  1201: .It Ic .INTERRUPT
                   1202: If
1.19      aaron    1203: .Nm
1.1       deraadt  1204: is interrupted, the commands for this target will be executed.
1.18      espie    1205: .It Ic .LIBS
1.19      aaron    1206: This does for libraries what
                   1207: .Ic .INCLUDES
1.18      espie    1208: does for include files, except that the flag used is
                   1209: .Fl L .
1.1       deraadt  1210: .It Ic .MAIN
                   1211: If no target is specified when
1.19      aaron    1212: .Nm
1.28      aaron    1213: is invoked, this target will be built.
                   1214: This is always set, either
1.19      aaron    1215: explicitly, or implicitly when
                   1216: .Nm
1.16      espie    1217: selects the default target, to give the user a way to refer to the default
                   1218: target on the command line.
1.1       deraadt  1219: .It Ic .MAKEFLAGS
                   1220: This target provides a way to specify flags for
1.19      aaron    1221: .Nm
1.1       deraadt  1222: when the makefile is used.
                   1223: The flags are as if typed to the shell, though the
                   1224: .Fl f
                   1225: option will have
                   1226: no effect.
1.4       deraadt  1227: .\" XXX: NOT YET!!!!
                   1228: .\" .It Ic .NOTPARALLEL
                   1229: .\" The named targets are executed in non parallel mode. If no targets are
                   1230: .\" specified, then all targets are executed in non parallel mode.
                   1231: .It Ic .NOTPARALLEL
                   1232: Disable parallel mode.
                   1233: .It Ic .NO_PARALLEL
                   1234: Same as above, for compatibility with other pmake variants.
                   1235: .It Ic .ORDER
                   1236: The named targets are made in sequence.
                   1237: .\" XXX: NOT YET!!!!
                   1238: .\" .It Ic .PARALLEL
                   1239: .\" The named targets are executed in parallel mode. If no targets are
                   1240: .\" specified, then all targets are executed in parallel mode.
1.1       deraadt  1241: .It Ic .PATH
                   1242: The sources are directories which are to be searched for files not
                   1243: found in the current directory.
                   1244: If no sources are specified, any previously specified directories are
                   1245: deleted.
1.18      espie    1246: .It Ic .PATH\fIsuffix\fR
                   1247: The sources are directories which are to be searched for suffixed files
                   1248: not found in the current directory.
1.19      aaron    1249: .Nm
                   1250: first searches the suffixed search path, before reverting to the default
1.18      espie    1251: path if the file is not found there.
1.6       niklas   1252: .It Ic .PHONY
                   1253: Apply the
                   1254: .Ic .PHONY
1.28      aaron    1255: attribute to any specified sources.
                   1256: Targets with this attribute are always
1.6       niklas   1257: considered to be out of date.
1.1       deraadt  1258: .It Ic .PRECIOUS
                   1259: Apply the
                   1260: .Ic .PRECIOUS
                   1261: attribute to any specified sources.
                   1262: If no sources are specified, the
                   1263: .Ic .PRECIOUS
                   1264: attribute is applied to every
                   1265: target in the file.
                   1266: .It Ic .SILENT
                   1267: Apply the
                   1268: .Ic .SILENT
                   1269: attribute to any specified sources.
                   1270: If no sources are specified, the
                   1271: .Ic .SILENT
                   1272: attribute is applied to every
                   1273: command in the file.
                   1274: .It Ic .SUFFIXES
                   1275: Each source specifies a suffix to
                   1276: .Nm make .
1.61      jmc      1277: If no sources are specified, any previously specified suffixes are deleted.
1.35      aaron    1278: .El
1.1       deraadt  1279: .Sh ENVIRONMENT
1.19      aaron    1280: .Nm
1.15      espie    1281: uses the following environment variables, if they exist:
1.9       millert  1282: .Ev MACHINE ,
1.15      espie    1283: .Ev MACHINE_ARCH ,
1.9       millert  1284: .Ev MAKEFLAGS ,
                   1285: .Ev MAKEOBJDIR ,
1.15      espie    1286: .Ev MAKEOBJDIRPREFIX ,
1.1       deraadt  1287: and
1.9       millert  1288: .Ev PWD .
1.30      espie    1289: .Nm
1.31      aaron    1290: also ignores and unsets
1.30      espie    1291: .Ev CDPATH .
1.1       deraadt  1292: .Sh FILES
                   1293: .Bl -tag -width /usr/share/mk -compact
1.14      aaron    1294: .It Pa .depend
1.1       deraadt  1295: list of dependencies
1.15      espie    1296: .It Pa BSDmakefile
1.66      jmc      1297: default makefile
                   1298: .It Pa makefile
                   1299: default makefile if
                   1300: .Pa BSDmakefile
                   1301: does not exist
1.14      aaron    1302: .It Pa Makefile
1.66      jmc      1303: default makefile if
                   1304: .Pa makefile
                   1305: does not exist
1.14      aaron    1306: .It Pa sys.mk
1.1       deraadt  1307: system makefile
1.14      aaron    1308: .It Pa /usr/share/mk
1.1       deraadt  1309: system makefile directory
1.62      jmc      1310: .It Pa /usr/obj
1.19      aaron    1311: default
1.52      jmc      1312: .Ev MAKEOBJDIRPREFIX
1.57      jmc      1313: directory
1.1       deraadt  1314: .El
1.37      aaron    1315: .Sh SEE ALSO
1.57      jmc      1316: .Xr ed 1 ,
                   1317: .Xr mkdep 1 ,
                   1318: .Xr sh 1 ,
                   1319: .Xr getcwd 3 ,
                   1320: .Xr regex 3 ,
                   1321: .Xr uname 3
1.37      aaron    1322: .Pp
1.63      jmc      1323: "Make \(em A Tutorial",
                   1324: .Pa /usr/share/doc/psd/12.make/ .
1.52      jmc      1325: .Sh STANDARDS
1.67      jmc      1326: The
1.43      espie    1327: .Nm
1.67      jmc      1328: utility is compliant with the
                   1329: .St -p1003.1-2004
                   1330: specification.
                   1331: .Pp
                   1332: The flags
                   1333: .Op Fl BDdIjmPV
                   1334: are extensions to that specification.
1.43      espie    1335: .Pp
1.37      aaron    1336: Older versions of
                   1337: .Nm
                   1338: used
                   1339: .Ev MAKE
                   1340: instead of
                   1341: .Ev MAKEFLAGS .
                   1342: This was removed for POSIX compatibility.
                   1343: The internal variable
                   1344: .Va MAKE
                   1345: is set to the same value as
1.48      pvalchev 1346: .Va .MAKE .
                   1347: Support for this may be removed in the future.
1.37      aaron    1348: .Pp
                   1349: Most of the more esoteric features of
                   1350: .Nm
                   1351: should probably be avoided for greater compatibility.
                   1352: .Sh HISTORY
                   1353: A
                   1354: .Nm
                   1355: command appeared in
                   1356: .At v7 .
1.17      espie    1357: .Sh BUGS
1.18      espie    1358: The determination of
                   1359: .Va .OBJDIR
1.19      aaron    1360: is contorted to the point of absurdity.
1.18      espie    1361: .Pp
1.50      jmc      1362: If the same target is specified several times in normal dependency rules,
1.31      aaron    1363: .Nm
1.27      espie    1364: silently ignores all commands after the first non empty set of commands,
1.31      aaron    1365: e.g., in
1.57      jmc      1366: .Bd -literal -offset indent
1.27      espie    1367: a:
                   1368:        @echo "Executed"
                   1369: a:
                   1370:        @echo "Bad luck"
                   1371: .Ed
                   1372: .Pp
                   1373: @echo "Bad luck" will be silently ignored.
1.18      espie    1374: .Pp
                   1375: .Va .TARGETS
                   1376: is not set to the default target when
1.19      aaron    1377: .Nm
1.18      espie    1378: is invoked without a target name and no
1.19      aaron    1379: .Ic MAIN
1.18      espie    1380: special target exists.
                   1381: .Pp
1.17      espie    1382: The evaluation of
                   1383: .Ar expression
1.28      aaron    1384: in a test is very simple-minded.
                   1385: Currently, the only form that works is
1.48      pvalchev 1386: .Ql .if ${VAR} op something \.
1.50      jmc      1387: For instance, tests should be written as
1.64      mbalmer  1388: .Ql .if ${VAR} == "string" ,
1.17      espie    1389: not the other way around, which doesn't work.
                   1390: .Pp
                   1391: For loops are expanded before tests, so a fragment such as:
1.57      jmc      1392: .Bd -literal -offset indent
1.17      espie    1393: \&.for TMACHINE in ${SHARED_ARCHS}
1.64      mbalmer  1394: \&.if ${TMACHINE} == ${MACHINE}
1.17      espie    1395:      ...
                   1396: \&.endif
1.32      ericj    1397: \&.endfor
1.17      espie    1398: .Ed
1.25      espie    1399: .Pp
1.17      espie    1400: won't work, and should be rewritten the other way around.
1.21      espie    1401: .Pp
1.31      aaron    1402: When handling pre-BSD 4.4 archives,
1.21      espie    1403: .Nm
                   1404: may erroneously mark archive members as out of date if the archive name
                   1405: was truncated.
1.26      espie    1406: .Pp
1.57      jmc      1407: The handling of
                   1408: .Sq ;\&
                   1409: and other special characters in tests may be utterly bogus.
1.28      aaron    1410: For instance, in
1.57      jmc      1411: .Bd -literal -offset indent
1.25      espie    1412: \&A=abcd;c.c
                   1413: \&.if ${A:R} == "abcd;c"
                   1414: .Ed
                   1415: .Pp
                   1416: the test will never match, even though the value is correct.
1.26      espie    1417: .Pp
1.28      aaron    1418: The conditional handler is incredibly lame.
                   1419: Junk such as
1.57      jmc      1420: .Pp
                   1421: .Dl \&.if defined anything goes (A)
1.26      espie    1422: .Pp
                   1423: will be accepted silently.
1.25      espie    1424: .Pp
1.57      jmc      1425: In a .for loop, only the variable value is used; assignments will be
1.25      espie    1426: evaluated later, e.g., in
1.57      jmc      1427: .Bd -literal -offset indent
1.25      espie    1428: \&.for I in a b c d
                   1429: I:=${I:S/a/z}
                   1430: A+=$I
                   1431: \&.endfor
                   1432: .Ed
1.57      jmc      1433: .Pp
                   1434: .Sq A
                   1435: will evaluate to a b c d after the loop, not z b c d.
1.73      espie    1436: .Pp
                   1437: .Ic ORDER
                   1438: is only used in parallel mode, so
1.74      jmc      1439: keep dependency ordered for sequential mode!
1.78      espie    1440: .Pp
1.79      jmc      1441: Distinct target names are treated separately, even though they might
1.78      espie    1442: correspond to the same file in the file system.
                   1443: This can cause excessive rebuilds of some targets, and bogus
                   1444: races in parallel mode.
                   1445: This can also prevent
                   1446: .Nm
                   1447: from finding a rule to solve a dependency if the target name is not
                   1448: exactly the same as the dependency.
                   1449: .Pp
                   1450: In parallel mode,
                   1451: .Fl j Ar n
                   1452: only limits the number of concurrent makes it knows about.
                   1453: During recursive invocations, each level will multiply the number
                   1454: of processes by
1.79      jmc      1455: .Ar n .
1.80      bluhm    1456: .Pp
                   1457: The
                   1458: .Va MAKEFILE
                   1459: variable cannot be used reliably.
                   1460: It is a compatibility feature and may get set to the last makefile
                   1461: specified, as it is set by System V make.