| 1 | .\" Copyright (c) 1990, 1993
|
|---|
| 2 | .\" The Regents of the University of California. All rights reserved.
|
|---|
| 3 | .\"
|
|---|
| 4 | .\" Redistribution and use in source and binary forms, with or without
|
|---|
| 5 | .\" modification, are permitted provided that the following conditions
|
|---|
| 6 | .\" are met:
|
|---|
| 7 | .\" 1. Redistributions of source code must retain the above copyright
|
|---|
| 8 | .\" notice, this list of conditions and the following disclaimer.
|
|---|
| 9 | .\" 2. Redistributions in binary form must reproduce the above copyright
|
|---|
| 10 | .\" notice, this list of conditions and the following disclaimer in the
|
|---|
| 11 | .\" documentation and/or other materials provided with the distribution.
|
|---|
| 12 | .\" 3. All advertising materials mentioning features or use of this software
|
|---|
| 13 | .\" must display the following acknowledgement:
|
|---|
| 14 | .\" This product includes software developed by the University of
|
|---|
| 15 | .\" California, Berkeley and its contributors.
|
|---|
| 16 | .\" 4. Neither the name of the University nor the names of its contributors
|
|---|
| 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 | .\"
|
|---|
| 32 | .\" @(#)make.1 8.8 (Berkeley) 6/13/95
|
|---|
| 33 | .\" $FreeBSD: src/usr.bin/make/make.1,v 1.59 2002/09/27 09:21:07 ru Exp $
|
|---|
| 34 | .\"
|
|---|
| 35 | .Dd June 13, 1995
|
|---|
| 36 | .Dt MAKE 1
|
|---|
| 37 | .Os
|
|---|
| 38 | .Sh NAME
|
|---|
| 39 | .Nm make
|
|---|
| 40 | .Nd maintain program dependencies
|
|---|
| 41 | .Sh SYNOPSIS
|
|---|
| 42 | .Nm
|
|---|
| 43 | .Op Fl BPSXeiknqrstv
|
|---|
| 44 | .Op Fl C Ar directory
|
|---|
| 45 | .Op Fl D Ar variable
|
|---|
| 46 | .Op Fl d Ar flags
|
|---|
| 47 | .Op Fl E Ar variable
|
|---|
| 48 | .Op Fl f Ar makefile
|
|---|
| 49 | .Op Fl I Ar directory
|
|---|
| 50 | .Bk -words
|
|---|
| 51 | .Op Fl j Ar max_jobs
|
|---|
| 52 | .Op Fl m Ar directory
|
|---|
| 53 | .Ek
|
|---|
| 54 | .Op Fl V Ar variable
|
|---|
| 55 | .Op Ar variable Ns No = Ns Ar value
|
|---|
| 56 | .Op Ar target ...
|
|---|
| 57 | .Sh DESCRIPTION
|
|---|
| 58 | The
|
|---|
| 59 | .Nm
|
|---|
| 60 | utility is a program designed to simplify the maintenance of other programs.
|
|---|
| 61 | Its input is a list of specifications
|
|---|
| 62 | describing dependency relationships between the generation of
|
|---|
| 63 | files and programs.
|
|---|
| 64 | The first of
|
|---|
| 65 | .Ql Pa BSDmakefile ,
|
|---|
| 66 | .Ql Pa makefile
|
|---|
| 67 | and
|
|---|
| 68 | .Ql Pa Makefile
|
|---|
| 69 | that can be found in either the current directory or a special object directory
|
|---|
| 70 | (see
|
|---|
| 71 | .Ql Va .OBJDIR )
|
|---|
| 72 | will be read for this list of specifications.
|
|---|
| 73 | If the file
|
|---|
| 74 | .Ql Pa .depend
|
|---|
| 75 | can be found, it is also read (see
|
|---|
| 76 | .Xr mkdep 1 ) .
|
|---|
| 77 | .Pp
|
|---|
| 78 | This manual page is intended as a reference document only.
|
|---|
| 79 | For a more thorough introduction to
|
|---|
| 80 | .Nm
|
|---|
| 81 | and makefiles, please refer to
|
|---|
| 82 | .%T "Make \- A Tutorial" .
|
|---|
| 83 | .Pp
|
|---|
| 84 | The options are as follows:
|
|---|
| 85 | .Bl -tag -width Ds
|
|---|
| 86 | .It Fl B
|
|---|
| 87 | Try to be backwards compatible by executing a single shell per command and
|
|---|
| 88 | by executing the commands to make the sources of a dependency line in sequence.
|
|---|
| 89 | This is turned on by default unless
|
|---|
| 90 | .Fl j
|
|---|
| 91 | is used.
|
|---|
| 92 | .It Fl C Ar directory
|
|---|
| 93 | Change to
|
|---|
| 94 | .Ar directory
|
|---|
| 95 | while running.
|
|---|
| 96 | .It Fl D Ar variable
|
|---|
| 97 | Define
|
|---|
| 98 | .Ar variable
|
|---|
| 99 | to be 1, in the global context.
|
|---|
| 100 | .It Fl d Ar flags
|
|---|
| 101 | Turn on debugging, and specify which portions of
|
|---|
| 102 | .Nm
|
|---|
| 103 | are to print debugging information.
|
|---|
| 104 | Argument
|
|---|
| 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 f
|
|---|
| 118 | Print debugging information about the execution of for loops.
|
|---|
| 119 | Currently a
|
|---|
| 120 | no-op.
|
|---|
| 121 | .It Ar "g1"
|
|---|
| 122 | Print the input graph before making anything.
|
|---|
| 123 | .It Ar "g2"
|
|---|
| 124 | Print the input graph after making everything, or before exiting
|
|---|
| 125 | on error.
|
|---|
| 126 | .It Ar j
|
|---|
| 127 | Print debugging information about running multiple shells.
|
|---|
| 128 | .It Ar l
|
|---|
| 129 | Print commands in Makefiles regardless of whether or not they are prefixed
|
|---|
| 130 | by @ or other "quiet" flags.
|
|---|
| 131 | Also known as "loud" behavior.
|
|---|
| 132 | .It Ar m
|
|---|
| 133 | Print debugging information about making targets, including modification
|
|---|
| 134 | dates.
|
|---|
| 135 | .It Ar s
|
|---|
| 136 | Print debugging information about suffix-transformation rules.
|
|---|
| 137 | .It Ar t
|
|---|
| 138 | Print debugging information about target list maintenance.
|
|---|
| 139 | .It Ar v
|
|---|
| 140 | Print debugging information about variable assignment.
|
|---|
| 141 | .El
|
|---|
| 142 | .It Fl E Ar variable
|
|---|
| 143 | Specify a variable whose environment value (if any) will override
|
|---|
| 144 | macro assignments within makefiles.
|
|---|
| 145 | .It Fl e
|
|---|
| 146 | Specify that environment values override macro assignments within
|
|---|
| 147 | makefiles for all variables.
|
|---|
| 148 | .It Fl f Ar makefile
|
|---|
| 149 | Specify a makefile to read instead of the default
|
|---|
| 150 | .Ql Pa makefile
|
|---|
| 151 | and
|
|---|
| 152 | .Ql Pa Makefile .
|
|---|
| 153 | If
|
|---|
| 154 | .Ar makefile
|
|---|
| 155 | is
|
|---|
| 156 | .Ql \- ,
|
|---|
| 157 | standard input is read.
|
|---|
| 158 | Multiple makefiles may be specified, and are read in the order specified.
|
|---|
| 159 | .It Fl I Ar directory
|
|---|
| 160 | Specify a directory in which to search for makefiles and included makefiles.
|
|---|
| 161 | The system makefile directory (or directories, see the
|
|---|
| 162 | .Fl m
|
|---|
| 163 | option) is automatically included as part of this list.
|
|---|
| 164 | .It Fl i
|
|---|
| 165 | Ignore non-zero exit of shell commands in the makefile.
|
|---|
| 166 | Equivalent to specifying
|
|---|
| 167 | .Ql \-
|
|---|
| 168 | before each command line in the makefile.
|
|---|
| 169 | .It Fl j Ar max_jobs
|
|---|
| 170 | Specify the maximum number of jobs that
|
|---|
| 171 | .Nm
|
|---|
| 172 | may have running at any one time.
|
|---|
| 173 | Turns compatibility mode off, unless the
|
|---|
| 174 | .Ar B
|
|---|
| 175 | flag is also specified.
|
|---|
| 176 | .It Fl k
|
|---|
| 177 | Continue processing after errors are encountered, but only on those targets
|
|---|
| 178 | that do not depend on the target whose creation caused the error.
|
|---|
| 179 | .It Fl m Ar directory
|
|---|
| 180 | Specify a directory in which to search for
|
|---|
| 181 | .Pa sys.mk
|
|---|
| 182 | and makefiles included via the <...> style.
|
|---|
| 183 | Multiple directories can be added to form a search path.
|
|---|
| 184 | This path will override the default system include path:
|
|---|
| 185 | .Pa /usr/share/mk .
|
|---|
| 186 | Furthermore, the system include path will be appended to the search path used
|
|---|
| 187 | for "..."-style inclusions (see the
|
|---|
| 188 | .Fl I
|
|---|
| 189 | option).
|
|---|
| 190 | .It Fl n
|
|---|
| 191 | Display the commands that would have been executed, but do not actually
|
|---|
| 192 | execute them.
|
|---|
| 193 | .It Fl P
|
|---|
| 194 | Collate the output of a given job and display it only when the job finishes,
|
|---|
| 195 | instead of mixing the output of parallel jobs together.
|
|---|
| 196 | This option has no effect unless
|
|---|
| 197 | .Fl j
|
|---|
| 198 | is used too.
|
|---|
| 199 | .It Fl q
|
|---|
| 200 | Do not execute any commands, but exit 0 if the specified targets are
|
|---|
| 201 | up-to-date and 1, otherwise.
|
|---|
| 202 | .It Fl r
|
|---|
| 203 | Do not use the built-in rules specified in the system makefile.
|
|---|
| 204 | .It Fl S
|
|---|
| 205 | Stop processing when an error is encountered.
|
|---|
| 206 | Default behaviour.
|
|---|
| 207 | This is needed to negate the
|
|---|
| 208 | .Fl k
|
|---|
| 209 | option during recursive builds.
|
|---|
| 210 | .It Fl s
|
|---|
| 211 | Do not echo any commands as they are executed.
|
|---|
| 212 | Equivalent to specifying
|
|---|
| 213 | .Ql Ic @
|
|---|
| 214 | before each command line in the makefile.
|
|---|
| 215 | .It Fl t
|
|---|
| 216 | Rather than re-building a target as specified in the makefile, create it
|
|---|
| 217 | or update its modification time to make it appear up-to-date.
|
|---|
| 218 | .It Fl V Ar variable
|
|---|
| 219 | Print
|
|---|
| 220 | .Nm Ns 's
|
|---|
| 221 | idea of the value of
|
|---|
| 222 | .Ar variable ,
|
|---|
| 223 | in the global context.
|
|---|
| 224 | Do not build any targets.
|
|---|
| 225 | Multiple instances of this option may be specified;
|
|---|
| 226 | the variables will be printed one per line,
|
|---|
| 227 | with a blank line for each null or undefined variable.
|
|---|
| 228 | .It Fl v
|
|---|
| 229 | Be extra verbose.
|
|---|
| 230 | For multi-job makes, this will cause file banners to be generated.
|
|---|
| 231 | .It Fl X
|
|---|
| 232 | When using the
|
|---|
| 233 | .Fl V
|
|---|
| 234 | option to print the values of variables,
|
|---|
| 235 | do not recursively expand the values.
|
|---|
| 236 | .It Ar variable Ns No = Ns Ar value
|
|---|
| 237 | Set the value of the variable
|
|---|
| 238 | .Ar variable
|
|---|
| 239 | to
|
|---|
| 240 | .Ar value .
|
|---|
| 241 | .El
|
|---|
| 242 | .Pp
|
|---|
| 243 | There are seven different types of lines in a makefile: file dependency
|
|---|
| 244 | specifications, shell commands, variable assignments, include statements,
|
|---|
| 245 | conditional directives, for loops, and comments.
|
|---|
| 246 | .Pp
|
|---|
| 247 | In general, lines may be continued from one line to the next by ending
|
|---|
| 248 | them with a backslash
|
|---|
| 249 | .Pq Ql \e .
|
|---|
| 250 | The trailing newline character and initial whitespace on the following
|
|---|
| 251 | line are compressed into a single space.
|
|---|
| 252 | .Sh FILE DEPENDENCY SPECIFICATIONS
|
|---|
| 253 | Dependency lines consist of one or more targets, an operator, and zero
|
|---|
| 254 | or more sources.
|
|---|
| 255 | This creates a relationship where the targets
|
|---|
| 256 | .Dq depend
|
|---|
| 257 | on the sources
|
|---|
| 258 | and are usually created from them.
|
|---|
| 259 | The exact relationship between the target and the source is determined
|
|---|
| 260 | by the operator that separates them.
|
|---|
| 261 | The three operators are as follows:
|
|---|
| 262 | .Bl -tag -width flag
|
|---|
| 263 | .It Ic \&:
|
|---|
| 264 | A target is considered out-of-date if its modification time is less than
|
|---|
| 265 | those of any of its sources.
|
|---|
| 266 | Sources for a target accumulate over dependency lines when this operator
|
|---|
| 267 | is used.
|
|---|
| 268 | The target is removed if
|
|---|
| 269 | .Nm
|
|---|
| 270 | is interrupted.
|
|---|
| 271 | .It Ic \&!
|
|---|
| 272 | Targets are always re-created, but not until all sources have been
|
|---|
| 273 | examined and re-created as necessary.
|
|---|
| 274 | Sources for a target accumulate over dependency lines when this operator
|
|---|
| 275 | is used.
|
|---|
| 276 | The target is removed if
|
|---|
| 277 | .Nm
|
|---|
| 278 | is interrupted.
|
|---|
| 279 | .It Ic \&::
|
|---|
| 280 | If no sources are specified, the target is always re-created.
|
|---|
| 281 | Otherwise, a target is considered out-of-date if any of its sources has
|
|---|
| 282 | been modified more recently than the target.
|
|---|
| 283 | Sources for a target do not accumulate over dependency lines when this
|
|---|
| 284 | operator is used.
|
|---|
| 285 | The target will not be removed if
|
|---|
| 286 | .Nm
|
|---|
| 287 | is interrupted.
|
|---|
| 288 | .El
|
|---|
| 289 | .Pp
|
|---|
| 290 | Targets and sources may contain the shell wildcard expressions
|
|---|
| 291 | .Ql \&? ,
|
|---|
| 292 | .Ql * ,
|
|---|
| 293 | .Ql []
|
|---|
| 294 | and
|
|---|
| 295 | .Ql {} .
|
|---|
| 296 | The expressions
|
|---|
| 297 | .Ql \&? ,
|
|---|
| 298 | .Ql *
|
|---|
| 299 | and
|
|---|
| 300 | .Ql []
|
|---|
| 301 | may only be used as part of the final
|
|---|
| 302 | component of the target or source, and must be used to describe existing
|
|---|
| 303 | files.
|
|---|
| 304 | The expression
|
|---|
| 305 | .Ql {}
|
|---|
| 306 | need not necessarily be used to describe existing files.
|
|---|
| 307 | Expansion is in directory order, not alphabetically as done in the shell.
|
|---|
| 308 | .Sh SHELL COMMANDS
|
|---|
| 309 | Each target may have associated with it a series of shell commands, normally
|
|---|
| 310 | used to create the target.
|
|---|
| 311 | Each of the commands in this script
|
|---|
| 312 | .Em must
|
|---|
| 313 | be preceded by a tab.
|
|---|
| 314 | While any target may appear on a dependency line, only one of these
|
|---|
| 315 | dependencies may be followed by a creation script, unless the
|
|---|
| 316 | .Ql Ic ::
|
|---|
| 317 | operator is used.
|
|---|
| 318 | .Pp
|
|---|
| 319 | If the first or first two characters of the command line are
|
|---|
| 320 | .Ql Ic @
|
|---|
| 321 | and/or
|
|---|
| 322 | .Ql Ic \- ,
|
|---|
| 323 | the command is treated specially.
|
|---|
| 324 | A
|
|---|
| 325 | .Ql Ic @
|
|---|
| 326 | causes the command not to be echoed before it is executed.
|
|---|
| 327 | A
|
|---|
| 328 | .Ql Ic \-
|
|---|
| 329 | causes any non-zero exit status of the command line to be ignored.
|
|---|
| 330 | .Sh VARIABLE ASSIGNMENTS
|
|---|
| 331 | Variables in
|
|---|
| 332 | .Nm
|
|---|
| 333 | are much like variables in the shell, and, by tradition,
|
|---|
| 334 | consist of all upper-case letters.
|
|---|
| 335 | The five operators that can be used to assign values to variables are as
|
|---|
| 336 | follows:
|
|---|
| 337 | .Bl -tag -width Ds
|
|---|
| 338 | .It Ic \&=
|
|---|
| 339 | Assign the value to the variable.
|
|---|
| 340 | Any previous value is overridden.
|
|---|
| 341 | .It Ic \&+=
|
|---|
| 342 | Append the value to the current value of the variable.
|
|---|
| 343 | .It Ic \&?=
|
|---|
| 344 | Assign the value to the variable if it is not already defined.
|
|---|
| 345 | .It Ic \&:=
|
|---|
| 346 | Assign with expansion, i.e. expand the value before assigning it
|
|---|
| 347 | to the variable.
|
|---|
| 348 | Normally, expansion is not done until the variable is referenced.
|
|---|
| 349 | .It Ic \&!=
|
|---|
| 350 | Expand the value and pass it to the shell for execution and assign
|
|---|
| 351 | the result to the variable.
|
|---|
| 352 | Any newlines in the result are replaced with spaces.
|
|---|
| 353 | .El
|
|---|
| 354 | .Pp
|
|---|
| 355 | Any whitespace before the assigned
|
|---|
| 356 | .Ar value
|
|---|
| 357 | is removed; if the value is being appended, a single space is inserted
|
|---|
| 358 | between the previous contents of the variable and the appended value.
|
|---|
| 359 | .Pp
|
|---|
| 360 | Variables are expanded by surrounding the variable name with either
|
|---|
| 361 | curly braces
|
|---|
| 362 | .Pq Ql {}
|
|---|
| 363 | or parentheses
|
|---|
| 364 | .Pq Ql ()
|
|---|
| 365 | and preceding it with
|
|---|
| 366 | a dollar sign
|
|---|
| 367 | .Pq Ql \&$ .
|
|---|
| 368 | If the variable name contains only a single letter, the surrounding
|
|---|
| 369 | braces or parentheses are not required.
|
|---|
| 370 | This shorter form is not recommended.
|
|---|
| 371 | .Pp
|
|---|
| 372 | Variable substitution occurs at two distinct times, depending on where
|
|---|
| 373 | the variable is being used.
|
|---|
| 374 | Variables in dependency lines are expanded as the line is read.
|
|---|
| 375 | Variables in shell commands are expanded when the shell command is
|
|---|
| 376 | executed.
|
|---|
| 377 | .Pp
|
|---|
| 378 | The four different classes of variables (in order of increasing precedence)
|
|---|
| 379 | are:
|
|---|
| 380 | .Bl -tag -width Ds
|
|---|
| 381 | .It Environment variables
|
|---|
| 382 | Variables defined as part of
|
|---|
| 383 | .Nm Ns 's
|
|---|
| 384 | environment.
|
|---|
| 385 | .It Global variables
|
|---|
| 386 | Variables defined in the makefile or in included makefiles.
|
|---|
| 387 | .It Command line variables
|
|---|
| 388 | Variables defined as part of the command line.
|
|---|
| 389 | .It Local variables
|
|---|
| 390 | Variables that are defined specific to a certain target.
|
|---|
| 391 | The seven local variables are as follows:
|
|---|
| 392 | .Bl -tag -width ".ARCHIVE"
|
|---|
| 393 | .It Va .ALLSRC
|
|---|
| 394 | The list of all sources for this target; also known as
|
|---|
| 395 | .Ql Va \&> .
|
|---|
| 396 | .It Va .ARCHIVE
|
|---|
| 397 | The name of the archive file; also known as
|
|---|
| 398 | .Ql Va \&! .
|
|---|
| 399 | .It Va .IMPSRC
|
|---|
| 400 | The name/path of the source from which the target is to be transformed
|
|---|
| 401 | (the
|
|---|
| 402 | .Dq implied
|
|---|
| 403 | source); also known as
|
|---|
| 404 | .Ql Va \&< .
|
|---|
| 405 | .It Va .MEMBER
|
|---|
| 406 | The name of the archive member; also known as
|
|---|
| 407 | .Ql Va \&% .
|
|---|
| 408 | .It Va .OODATE
|
|---|
| 409 | The list of sources for this target that were deemed out-of-date; also
|
|---|
| 410 | known as
|
|---|
| 411 | .Ql Va \&? .
|
|---|
| 412 | .It Va .PREFIX
|
|---|
| 413 | The file prefix of the file, containing only the file portion, no suffix
|
|---|
| 414 | or preceding directory components; also known as
|
|---|
| 415 | .Ql Va * .
|
|---|
| 416 | .It Va .TARGET
|
|---|
| 417 | The name of the target; also known as
|
|---|
| 418 | .Ql Va @ .
|
|---|
| 419 | .El
|
|---|
| 420 | .Pp
|
|---|
| 421 | The shorter forms
|
|---|
| 422 | .Ql Va @ ,
|
|---|
| 423 | .Ql Va \&! ,
|
|---|
| 424 | .Ql Va \&< ,
|
|---|
| 425 | .Ql Va \&% ,
|
|---|
| 426 | .Ql Va \&? ,
|
|---|
| 427 | .Ql Va \&> ,
|
|---|
| 428 | and
|
|---|
| 429 | .Ql Va *
|
|---|
| 430 | are permitted for backward
|
|---|
| 431 | compatibility and are not recommended.
|
|---|
| 432 | The six variables
|
|---|
| 433 | .Ql Va "@F" ,
|
|---|
| 434 | .Ql Va "@D" ,
|
|---|
| 435 | .Ql Va "<F" ,
|
|---|
| 436 | .Ql Va "<D" ,
|
|---|
| 437 | .Ql Va "*F" ,
|
|---|
| 438 | and
|
|---|
| 439 | .Ql Va "*D"
|
|---|
| 440 | are
|
|---|
| 441 | permitted for compatibility with
|
|---|
| 442 | .At V
|
|---|
| 443 | makefiles and are not recommended.
|
|---|
| 444 | .Pp
|
|---|
| 445 | Four of the local variables may be used in sources on dependency lines
|
|---|
| 446 | because they expand to the proper value for each target on the line.
|
|---|
| 447 | These variables are
|
|---|
| 448 | .Ql Va .TARGET ,
|
|---|
| 449 | .Ql Va .PREFIX ,
|
|---|
| 450 | .Ql Va .ARCHIVE ,
|
|---|
| 451 | and
|
|---|
| 452 | .Ql Va .MEMBER .
|
|---|
| 453 | .El
|
|---|
| 454 | .Pp
|
|---|
| 455 | In addition,
|
|---|
| 456 | .Nm
|
|---|
| 457 | sets or knows about the following internal variables or environment
|
|---|
| 458 | variables:
|
|---|
| 459 | .Bl -tag -width MAKEFLAGS
|
|---|
| 460 | .It Va \&$
|
|---|
| 461 | A single dollar sign
|
|---|
| 462 | .Ql \&$ ,
|
|---|
| 463 | i.e.\&
|
|---|
| 464 | .Ql \&$$
|
|---|
| 465 | expands to a single dollar
|
|---|
| 466 | sign.
|
|---|
| 467 | .It Va MAKE
|
|---|
| 468 | The name that
|
|---|
| 469 | .Nm
|
|---|
| 470 | was executed with
|
|---|
| 471 | .Pq Va argv Ns Op 0 .
|
|---|
| 472 | .It Va .CURDIR
|
|---|
| 473 | A path to the directory where
|
|---|
| 474 | .Nm
|
|---|
| 475 | was executed.
|
|---|
| 476 | The
|
|---|
| 477 | .Nm
|
|---|
| 478 | utility sets
|
|---|
| 479 | .Va .CURDIR
|
|---|
| 480 | to the canonical path given by
|
|---|
| 481 | .Xr getcwd 3 .
|
|---|
| 482 | .It Va .OBJDIR
|
|---|
| 483 | A path to the directory where the targets are built.
|
|---|
| 484 | At startup,
|
|---|
| 485 | .Nm
|
|---|
| 486 | searches for an alternate directory to place target files.
|
|---|
| 487 | It will attempt to change into this special directory
|
|---|
| 488 | and will search this directory for makefiles
|
|---|
| 489 | not found in the current directory.
|
|---|
| 490 | The following directories are tried in order:
|
|---|
| 491 | .Pp
|
|---|
| 492 | .Bl -enum -compact
|
|---|
| 493 | .It
|
|---|
| 494 | ${MAKEOBJDIRPREFIX}/`pwd`
|
|---|
| 495 | .It
|
|---|
| 496 | ${MAKEOBJDIR}
|
|---|
| 497 | .It
|
|---|
| 498 | obj.${MACHINE}
|
|---|
| 499 | .It
|
|---|
| 500 | obj
|
|---|
| 501 | .It
|
|---|
| 502 | /usr/obj/`pwd`
|
|---|
| 503 | .El
|
|---|
| 504 | .Pp
|
|---|
| 505 | The first directory that
|
|---|
| 506 | .Nm
|
|---|
| 507 | successfully changes into is used.
|
|---|
| 508 | If either
|
|---|
| 509 | .Ev MAKEOBJDIRPREFIX
|
|---|
| 510 | or
|
|---|
| 511 | .Ev MAKEOBJDIR
|
|---|
| 512 | is set in the environment but
|
|---|
| 513 | .Nm
|
|---|
| 514 | is unable to change into the corresponding directory,
|
|---|
| 515 | then the current directory is used
|
|---|
| 516 | without checking the remainder of the list.
|
|---|
| 517 | If they are undefined and
|
|---|
| 518 | .Nm
|
|---|
| 519 | is unable to change into any of the remaining three directories,
|
|---|
| 520 | then the current directory is used.
|
|---|
| 521 | .Pp
|
|---|
| 522 | The
|
|---|
| 523 | .Nm
|
|---|
| 524 | utility sets
|
|---|
| 525 | .Va .OBJDIR
|
|---|
| 526 | to the canonical path given by
|
|---|
| 527 | .Xr getcwd 3 .
|
|---|
| 528 | .It Va .MAKEFLAGS
|
|---|
| 529 | The environment variable
|
|---|
| 530 | .Ev MAKEFLAGS
|
|---|
| 531 | may contain anything that
|
|---|
| 532 | may be specified on
|
|---|
| 533 | .Nm Ns 's
|
|---|
| 534 | command line.
|
|---|
| 535 | Its contents are stored in
|
|---|
| 536 | .Nm Ns 's
|
|---|
| 537 | .Va .MAKEFLAGS
|
|---|
| 538 | variable.
|
|---|
| 539 | Anything specified on
|
|---|
| 540 | .Nm Ns 's
|
|---|
| 541 | command line is appended to the
|
|---|
| 542 | .Va .MAKEFLAGS
|
|---|
| 543 | variable which is then
|
|---|
| 544 | entered into the environment as
|
|---|
| 545 | .Ev MAKEFLAGS
|
|---|
| 546 | for all programs which
|
|---|
| 547 | .Nm
|
|---|
| 548 | executes.
|
|---|
| 549 | .It Va MFLAGS
|
|---|
| 550 | A synonym for
|
|---|
| 551 | .Va .MAKEFLAGS
|
|---|
| 552 | provided for backward compatibility.
|
|---|
| 553 | .It Va .TARGETS
|
|---|
| 554 | List of targets
|
|---|
| 555 | .Nm
|
|---|
| 556 | is currently building.
|
|---|
| 557 | .It Va .INCLUDES
|
|---|
| 558 | See
|
|---|
| 559 | .Ic .INCLUDES
|
|---|
| 560 | special target.
|
|---|
| 561 | .It Va .LIBS
|
|---|
| 562 | See
|
|---|
| 563 | .Ic .LIBS
|
|---|
| 564 | special target.
|
|---|
| 565 | .It Va MACHINE
|
|---|
| 566 | Name of the machine architecture
|
|---|
| 567 | .Nm
|
|---|
| 568 | is running on, obtained from the
|
|---|
| 569 | .Ev MACHINE
|
|---|
| 570 | environment variable, or through
|
|---|
| 571 | .Xr uname 3
|
|---|
| 572 | if not defined.
|
|---|
| 573 | .It Va MACHINE_ARCH
|
|---|
| 574 | Name of the machine architecture
|
|---|
| 575 | .Nm
|
|---|
| 576 | was compiled for, defined at compilation time.
|
|---|
| 577 | .It Va VPATH
|
|---|
| 578 | Makefiles may assign a colon-delimited list of directories to
|
|---|
| 579 | .Va VPATH .
|
|---|
| 580 | These directories will be searched for source files by
|
|---|
| 581 | .Nm
|
|---|
| 582 | after it has finished parsing all input makefiles.
|
|---|
| 583 | .El
|
|---|
| 584 | .Pp
|
|---|
| 585 | Variable expansion may be modified to select or modify each word of the
|
|---|
| 586 | variable (where a
|
|---|
| 587 | .Dq word
|
|---|
| 588 | is whitespace-delimited sequence of characters).
|
|---|
| 589 | The general format of a variable expansion is as follows:
|
|---|
| 590 | .Pp
|
|---|
| 591 | .Dl {variable[:modifier[:...]]}
|
|---|
| 592 | .Pp
|
|---|
| 593 | Each modifier begins with a colon and one of the following
|
|---|
| 594 | special characters.
|
|---|
| 595 | The colon may be escaped with a backslash
|
|---|
| 596 | .Pq Ql \e .
|
|---|
| 597 | .Bl -tag -width Cm
|
|---|
| 598 | .Sm off
|
|---|
| 599 | .It Cm C No \&/ Ar pattern Xo
|
|---|
| 600 | .No \&/ Ar replacement
|
|---|
| 601 | .No \&/ Op Cm 1g
|
|---|
| 602 | .Xc
|
|---|
| 603 | .Sm on
|
|---|
| 604 | The
|
|---|
| 605 | .Cm C
|
|---|
| 606 | modifier is just like the
|
|---|
| 607 | .Cm S
|
|---|
| 608 | modifier except that the old and new strings, instead of being
|
|---|
| 609 | simple strings, are an extended regular expression (see
|
|---|
| 610 | .Xr re_format 7 )
|
|---|
| 611 | and an
|
|---|
| 612 | .Xr ed 1 Ns \-style
|
|---|
| 613 | replacement string.
|
|---|
| 614 | Normally, the first occurrence of the pattern in
|
|---|
| 615 | each word of the value is changed.
|
|---|
| 616 | The
|
|---|
| 617 | .Ql 1
|
|---|
| 618 | modifier causes the substitution to apply to at most one word; the
|
|---|
| 619 | .Ql g
|
|---|
| 620 | modifier causes the substitution to apply to as many instances of the
|
|---|
| 621 | search pattern as occur in the word or words it is found in.
|
|---|
| 622 | Note that
|
|---|
| 623 | .Ql 1
|
|---|
| 624 | and
|
|---|
| 625 | .Ql g
|
|---|
| 626 | are orthogonal; the former specifies whether multiple words are
|
|---|
| 627 | potentially affected, the latter whether multiple substitutions can
|
|---|
| 628 | potentially occur within each affected word.
|
|---|
| 629 | .It Cm E
|
|---|
| 630 | Replaces each word in the variable with its suffix.
|
|---|
| 631 | .It Cm H
|
|---|
| 632 | Replaces each word in the variable with everything but the last component.
|
|---|
| 633 | .It Cm L
|
|---|
| 634 | Converts variable to lower-case letters.
|
|---|
| 635 | .It Cm M Ns Ar pattern
|
|---|
| 636 | Select only those words that match the rest of the modifier.
|
|---|
| 637 | The standard shell wildcard characters
|
|---|
| 638 | .Pf ( Ql * ,
|
|---|
| 639 | .Ql \&? ,
|
|---|
| 640 | and
|
|---|
| 641 | .Ql Op )
|
|---|
| 642 | may
|
|---|
| 643 | be used.
|
|---|
| 644 | The wildcard characters may be escaped with a backslash
|
|---|
| 645 | .Pq Ql \e .
|
|---|
| 646 | .It Cm N Ns Ar pattern
|
|---|
| 647 | This is identical to
|
|---|
| 648 | .Cm M ,
|
|---|
| 649 | but selects all words which do not match
|
|---|
| 650 | the rest of the modifier.
|
|---|
| 651 | .It Cm Q
|
|---|
| 652 | Quotes every shell meta-character in the variable, so that it can be passed
|
|---|
| 653 | safely through recursive invocations of
|
|---|
| 654 | .Nm .
|
|---|
| 655 | .It Cm R
|
|---|
| 656 | Replaces each word in the variable with everything but its suffix.
|
|---|
| 657 | .Sm off
|
|---|
| 658 | .It Cm S No \&/ Ar old_string Xo
|
|---|
| 659 | .No \&/ Ar new_string
|
|---|
| 660 | .No \&/ Op Cm g
|
|---|
| 661 | .Xc
|
|---|
| 662 | .Sm on
|
|---|
| 663 | Modify the first occurrence of
|
|---|
| 664 | .Ar old_string
|
|---|
| 665 | in each word of the variable's value, replacing it with
|
|---|
| 666 | .Ar new_string .
|
|---|
| 667 | If a
|
|---|
| 668 | .Ql g
|
|---|
| 669 | is appended to the last slash of the pattern, all occurrences
|
|---|
| 670 | in each word are replaced.
|
|---|
| 671 | If
|
|---|
| 672 | .Ar old_string
|
|---|
| 673 | begins with a caret
|
|---|
| 674 | .Pq Ql ^ ,
|
|---|
| 675 | .Ar old_string
|
|---|
| 676 | is anchored at the beginning of each word.
|
|---|
| 677 | If
|
|---|
| 678 | .Ar old_string
|
|---|
| 679 | ends with a dollar sign
|
|---|
| 680 | .Pq Ql \&$ ,
|
|---|
| 681 | it is anchored at the end of each word.
|
|---|
| 682 | Inside
|
|---|
| 683 | .Ar new_string ,
|
|---|
| 684 | an ampersand
|
|---|
| 685 | .Pq Ql &
|
|---|
| 686 | is replaced by
|
|---|
| 687 | .Ar old_string .
|
|---|
| 688 | Any character may be used as a delimiter for the parts of the modifier
|
|---|
| 689 | string.
|
|---|
| 690 | The anchoring, ampersand, and delimiter characters may be escaped with a
|
|---|
| 691 | backslash
|
|---|
| 692 | .Pq Ql \e .
|
|---|
| 693 | .Pp
|
|---|
| 694 | Variable expansion occurs in the normal fashion inside both
|
|---|
| 695 | .Ar old_string
|
|---|
| 696 | and
|
|---|
| 697 | .Ar new_string
|
|---|
| 698 | with the single exception that a backslash is used to prevent the expansion
|
|---|
| 699 | of a dollar sign
|
|---|
| 700 | .Pq Ql \&$ ,
|
|---|
| 701 | not a preceding dollar sign as is usual.
|
|---|
| 702 | .It Ar old_string=new_string
|
|---|
| 703 | This is the
|
|---|
| 704 | .At V
|
|---|
| 705 | style variable substitution.
|
|---|
| 706 | It must be the last modifier specified.
|
|---|
| 707 | If
|
|---|
| 708 | .Ar old_string
|
|---|
| 709 | or
|
|---|
| 710 | .Ar new_string
|
|---|
| 711 | do not contain the pattern matching character
|
|---|
| 712 | .Ar %
|
|---|
| 713 | then it is assumed that they are
|
|---|
| 714 | anchored at the end of each word, so only suffixes or entire
|
|---|
| 715 | words may be replaced.
|
|---|
| 716 | Otherwise
|
|---|
| 717 | .Ar %
|
|---|
| 718 | is the substring of
|
|---|
| 719 | .Ar old_string
|
|---|
| 720 | to be replaced in
|
|---|
| 721 | .Ar new_string
|
|---|
| 722 | .It Cm T
|
|---|
| 723 | Replaces each word in the variable with its last component.
|
|---|
| 724 | .It Cm U
|
|---|
| 725 | Converts variable to upper-case letters.
|
|---|
| 726 | .El
|
|---|
| 727 | .Sh DIRECTIVES, CONDITIONALS, AND FOR LOOPS
|
|---|
| 728 | Directives, conditionals, and for loops reminiscent
|
|---|
| 729 | of the C programming language are provided in
|
|---|
| 730 | .Nm .
|
|---|
| 731 | All such structures are identified by a line beginning with a single
|
|---|
| 732 | dot
|
|---|
| 733 | .Pq Ql \&.
|
|---|
| 734 | character.
|
|---|
| 735 | The following directives are supported:
|
|---|
| 736 | .Bl -tag -width Ds
|
|---|
| 737 | .It Ic \&.include Ar <file>
|
|---|
| 738 | .It Ic \&.include Ar \*qfile\*q
|
|---|
| 739 | Include the specified makefile.
|
|---|
| 740 | Variables between the angle brackets
|
|---|
| 741 | or double quotes are expanded to form the file name.
|
|---|
| 742 | If angle brackets
|
|---|
| 743 | are used, the included makefile is expected to be in the system
|
|---|
| 744 | makefile directory.
|
|---|
| 745 | If double quotes are used, the including
|
|---|
| 746 | makefile's directory and any directories specified using the
|
|---|
| 747 | .Fl I
|
|---|
| 748 | option are searched before the system
|
|---|
| 749 | makefile directory.
|
|---|
| 750 | .It Ic \&.undef Ar variable
|
|---|
| 751 | Un-define the specified global variable.
|
|---|
| 752 | Only global variables may be un-defined.
|
|---|
| 753 | .It Ic \&.error Ar message
|
|---|
| 754 | Terminate processing of the makefile immediately.
|
|---|
| 755 | The filename of the
|
|---|
| 756 | makefile, the line on which the error was encountered and the specified
|
|---|
| 757 | message are printed to standard output and
|
|---|
| 758 | .Nm
|
|---|
| 759 | terminates with exit code 1.
|
|---|
| 760 | Variables in the message are expanded.
|
|---|
| 761 | .El
|
|---|
| 762 | .Pp
|
|---|
| 763 | Conditionals are used to determine which parts of the Makefile
|
|---|
| 764 | to process.
|
|---|
| 765 | They are used similarly to the conditionals supported
|
|---|
| 766 | by the C pre-processor.
|
|---|
| 767 | The following conditionals are supported:
|
|---|
| 768 | .Bl -tag -width Ds
|
|---|
| 769 | .It Xo
|
|---|
| 770 | .Ic \&.if
|
|---|
| 771 | .Oo \&! Oc Ns Ar expression
|
|---|
| 772 | .Op Ar operator expression ...
|
|---|
| 773 | .Xc
|
|---|
| 774 | Test the value of an expression.
|
|---|
| 775 | .It Xo
|
|---|
| 776 | .Ic .ifdef
|
|---|
| 777 | .Oo \&! Oc Ns Ar variable
|
|---|
| 778 | .Op Ar operator variable ...
|
|---|
| 779 | .Xc
|
|---|
| 780 | Test the value of a variable.
|
|---|
| 781 | .It Xo
|
|---|
| 782 | .Ic .ifndef
|
|---|
| 783 | .Oo \&! Oc Ns Ar variable
|
|---|
| 784 | .Op Ar operator variable ...
|
|---|
| 785 | .Xc
|
|---|
| 786 | Test the value of a variable.
|
|---|
| 787 | .It Xo
|
|---|
| 788 | .Ic .ifmake
|
|---|
| 789 | .Oo \&! Oc Ns Ar target
|
|---|
| 790 | .Op Ar operator target ...
|
|---|
| 791 | .Xc
|
|---|
| 792 | Test the target being built.
|
|---|
| 793 | .It Xo
|
|---|
| 794 | .Ic .ifnmake
|
|---|
| 795 | .Oo \&! Oc Ns Ar target
|
|---|
| 796 | .Op Ar operator target ...
|
|---|
| 797 | .Xc
|
|---|
| 798 | Test the target being built.
|
|---|
| 799 | .It Ic .else
|
|---|
| 800 | Reverse the sense of the last conditional.
|
|---|
| 801 | .It Xo
|
|---|
| 802 | .Ic .elif
|
|---|
| 803 | .Oo \&! Oc Ns Ar expression
|
|---|
| 804 | .Op Ar operator expression ...
|
|---|
| 805 | .Xc
|
|---|
| 806 | A combination of
|
|---|
| 807 | .Ql Ic .else
|
|---|
| 808 | followed by
|
|---|
| 809 | .Ql Ic .if .
|
|---|
| 810 | .It Xo
|
|---|
| 811 | .Ic .elifdef
|
|---|
| 812 | .Oo \&! Oc Ns Ar variable
|
|---|
| 813 | .Op Ar operator variable ...
|
|---|
| 814 | .Xc
|
|---|
| 815 | A combination of
|
|---|
| 816 | .Ql Ic .else
|
|---|
| 817 | followed by
|
|---|
| 818 | .Ql Ic .ifdef .
|
|---|
| 819 | .It Xo
|
|---|
| 820 | .Ic .elifndef
|
|---|
| 821 | .Oo \&! Oc Ns Ar variable
|
|---|
| 822 | .Op Ar operator variable ...
|
|---|
| 823 | .Xc
|
|---|
| 824 | A combination of
|
|---|
| 825 | .Ql Ic .else
|
|---|
| 826 | followed by
|
|---|
| 827 | .Ql Ic .ifndef .
|
|---|
| 828 | .It Xo
|
|---|
| 829 | .Ic .elifmake
|
|---|
| 830 | .Oo \&! Oc Ns Ar target
|
|---|
| 831 | .Op Ar operator target ...
|
|---|
| 832 | .Xc
|
|---|
| 833 | A combination of
|
|---|
| 834 | .Ql Ic .else
|
|---|
| 835 | followed by
|
|---|
| 836 | .Ql Ic .ifmake .
|
|---|
| 837 | .It Xo
|
|---|
| 838 | .Ic .elifnmake
|
|---|
| 839 | .Oo \&! Oc Ns Ar target
|
|---|
| 840 | .Op Ar operator target ...
|
|---|
| 841 | .Xc
|
|---|
| 842 | A combination of
|
|---|
| 843 | .Ql Ic .else
|
|---|
| 844 | followed by
|
|---|
| 845 | .Ql Ic .ifnmake .
|
|---|
| 846 | .It Ic .endif
|
|---|
| 847 | End the body of the conditional.
|
|---|
| 848 | .El
|
|---|
| 849 | .Pp
|
|---|
| 850 | The
|
|---|
| 851 | .Ar operator
|
|---|
| 852 | may be any one of the following:
|
|---|
| 853 | .Bl -tag -width "Cm XX"
|
|---|
| 854 | .It Cm \&|\&|
|
|---|
| 855 | logical
|
|---|
| 856 | .Tn OR
|
|---|
| 857 | .It Cm \&&&
|
|---|
| 858 | Logical
|
|---|
| 859 | .Tn AND ;
|
|---|
| 860 | of higher precedence than
|
|---|
| 861 | .Ql Ic || .
|
|---|
| 862 | .El
|
|---|
| 863 | .Pp
|
|---|
| 864 | As in C,
|
|---|
| 865 | .Nm
|
|---|
| 866 | will only evaluate a conditional as far as is necessary to determine
|
|---|
| 867 | its value.
|
|---|
| 868 | Parentheses may be used to change the order of evaluation.
|
|---|
| 869 | The boolean operator
|
|---|
| 870 | .Ql Ic !\&
|
|---|
| 871 | may be used to logically negate an entire
|
|---|
| 872 | conditional.
|
|---|
| 873 | It is of higher precedence than
|
|---|
| 874 | .Ql Ic \&&& .
|
|---|
| 875 | .Pp
|
|---|
| 876 | The value of
|
|---|
| 877 | .Ar expression
|
|---|
| 878 | may be any of the following:
|
|---|
| 879 | .Bl -tag -width Ic
|
|---|
| 880 | .It Ic defined
|
|---|
| 881 | Takes a variable name as an argument and evaluates to true if the variable
|
|---|
| 882 | has been defined.
|
|---|
| 883 | .It Ic make
|
|---|
| 884 | Takes a target name as an argument and evaluates to true if the target
|
|---|
| 885 | was specified as part of
|
|---|
| 886 | .Nm Ns 's
|
|---|
| 887 | command line or was declared the default target (either implicitly or
|
|---|
| 888 | explicitly, see
|
|---|
| 889 | .Va .MAIN )
|
|---|
| 890 | before the line containing the conditional.
|
|---|
| 891 | .It Ic empty
|
|---|
| 892 | Takes a variable, with possible modifiers, and evaluates to true if
|
|---|
| 893 | the expansion of the variable would result in an empty string.
|
|---|
| 894 | .It Ic exists
|
|---|
| 895 | Takes a file name as an argument and evaluates to true if the file exists.
|
|---|
| 896 | The file is searched for on the system search path (see
|
|---|
| 897 | .Va .PATH ) .
|
|---|
| 898 | .It Ic target
|
|---|
| 899 | Takes a target name as an argument and evaluates to true if the target
|
|---|
| 900 | has been defined.
|
|---|
| 901 | .El
|
|---|
| 902 | .Pp
|
|---|
| 903 | An
|
|---|
| 904 | .Ar expression
|
|---|
| 905 | may also be an arithmetic or string comparison.
|
|---|
| 906 | Variable expansion is
|
|---|
| 907 | performed on both sides of the comparison, after which the integral
|
|---|
| 908 | values are compared.
|
|---|
| 909 | A value is interpreted as hexadecimal if it is
|
|---|
| 910 | preceded by 0x, otherwise it is decimal; octal numbers are not supported.
|
|---|
| 911 | The standard C relational operators are all supported.
|
|---|
| 912 | If after
|
|---|
| 913 | variable expansion, either the left or right hand side of a
|
|---|
| 914 | .Ql Ic ==
|
|---|
| 915 | or
|
|---|
| 916 | .Ql Ic "!="
|
|---|
| 917 | operator is not an integral value, then
|
|---|
| 918 | string comparison is performed between the expanded
|
|---|
| 919 | variables.
|
|---|
| 920 | If no relational operator is given, it is assumed that the expanded
|
|---|
| 921 | variable is being compared against 0.
|
|---|
| 922 | .Pp
|
|---|
| 923 | When
|
|---|
| 924 | .Nm
|
|---|
| 925 | is evaluating one of these conditional expressions, and it encounters
|
|---|
| 926 | a word it doesn't recognize, either the
|
|---|
| 927 | .Dq make
|
|---|
| 928 | or
|
|---|
| 929 | .Dq defined
|
|---|
| 930 | expression is applied to it, depending on the form of the conditional.
|
|---|
| 931 | If the form is
|
|---|
| 932 | .Ql Ic .ifdef
|
|---|
| 933 | or
|
|---|
| 934 | .Ql Ic .ifndef ,
|
|---|
| 935 | the
|
|---|
| 936 | .Dq defined
|
|---|
| 937 | expression is applied.
|
|---|
| 938 | Similarly, if the form is
|
|---|
| 939 | .Ql Ic .ifmake
|
|---|
| 940 | or
|
|---|
| 941 | .Ql Ic .ifnmake ,
|
|---|
| 942 | the
|
|---|
| 943 | .Dq make
|
|---|
| 944 | expression is applied.
|
|---|
| 945 | .Pp
|
|---|
| 946 | If the conditional evaluates to true the parsing of the makefile continues
|
|---|
| 947 | as before.
|
|---|
| 948 | If it evaluates to false, the following lines are skipped.
|
|---|
| 949 | In both cases this continues until a
|
|---|
| 950 | .Ql Ic .else
|
|---|
| 951 | or
|
|---|
| 952 | .Ql Ic .endif
|
|---|
| 953 | is found.
|
|---|
| 954 | .Pp
|
|---|
| 955 | For loops are typically used to apply a set of rules to a list of files.
|
|---|
| 956 | The syntax of a for loop is:
|
|---|
| 957 | .Pp
|
|---|
| 958 | .Bl -tag -width indent -compact
|
|---|
| 959 | .It Ic .for Ar variable Ic in Ar expression
|
|---|
| 960 | .It <make-rules>
|
|---|
| 961 | .It Ic \&.endfor
|
|---|
| 962 | .El
|
|---|
| 963 | .Pp
|
|---|
| 964 | After the for
|
|---|
| 965 | .Ar expression
|
|---|
| 966 | is evaluated, it is split into words.
|
|---|
| 967 | The
|
|---|
| 968 | iteration
|
|---|
| 969 | .Ar variable
|
|---|
| 970 | is successively set to each word, and substituted in the
|
|---|
| 971 | .Ic make-rules
|
|---|
| 972 | inside the body of the for loop.
|
|---|
| 973 | .Sh COMMENTS
|
|---|
| 974 | Comments begin with a hash
|
|---|
| 975 | .Pq Ql \&#
|
|---|
| 976 | character, anywhere but in a shell
|
|---|
| 977 | command line, and continue to the end of the line.
|
|---|
| 978 | .Sh SPECIAL SOURCES
|
|---|
| 979 | .Bl -tag -width Ic
|
|---|
| 980 | .It Ic .IGNORE
|
|---|
| 981 | Ignore any errors from the commands associated with this target, exactly
|
|---|
| 982 | as if they all were preceded by a dash
|
|---|
| 983 | .Pq Ql \- .
|
|---|
| 984 | .It Ic .MAKE
|
|---|
| 985 | Execute the commands associated with this target even if the
|
|---|
| 986 | .Fl n
|
|---|
| 987 | or
|
|---|
| 988 | .Fl t
|
|---|
| 989 | options were specified.
|
|---|
| 990 | Normally used to mark recursive
|
|---|
| 991 | .Nm Ns 's .
|
|---|
| 992 | .It Ic .NOTMAIN
|
|---|
| 993 | Normally
|
|---|
| 994 | .Nm
|
|---|
| 995 | selects the first target it encounters as the default target to be built
|
|---|
| 996 | if no target was specified.
|
|---|
| 997 | This source prevents this target from being selected.
|
|---|
| 998 | .It Ic .OPTIONAL
|
|---|
| 999 | If a target is marked with this attribute and
|
|---|
| 1000 | .Nm
|
|---|
| 1001 | can't figure out how to create it, it will ignore this fact and assume
|
|---|
| 1002 | the file isn't needed or already exists.
|
|---|
| 1003 | .It Ic .PRECIOUS
|
|---|
| 1004 | When
|
|---|
| 1005 | .Nm
|
|---|
| 1006 | is interrupted, it removes any partially made targets.
|
|---|
| 1007 | This source prevents the target from being removed.
|
|---|
| 1008 | .It Ic .SILENT
|
|---|
| 1009 | Do not echo any of the commands associated with this target, exactly
|
|---|
| 1010 | as if they all were preceded by an at sign
|
|---|
| 1011 | .Pq Ql @ .
|
|---|
| 1012 | .It Ic .USE
|
|---|
| 1013 | Turn the target into
|
|---|
| 1014 | .Nm Ns 's
|
|---|
| 1015 | version of a macro.
|
|---|
| 1016 | When the target is used as a source for another target, the other target
|
|---|
| 1017 | acquires the commands, sources, and attributes (except for
|
|---|
| 1018 | .Ic .USE )
|
|---|
| 1019 | of the
|
|---|
| 1020 | source.
|
|---|
| 1021 | If the target already has commands, the
|
|---|
| 1022 | .Ic .USE
|
|---|
| 1023 | target's commands are appended
|
|---|
| 1024 | to them.
|
|---|
| 1025 | .It Ic .WAIT
|
|---|
| 1026 | If special
|
|---|
| 1027 | .Ic .WAIT
|
|---|
| 1028 | source is appears in a dependency line, the sources that precede it are
|
|---|
| 1029 | made before the sources that succeed it in the line.
|
|---|
| 1030 | Loops are not being
|
|---|
| 1031 | detected and targets that form loops will be silently ignored.
|
|---|
| 1032 | .El
|
|---|
| 1033 | .Sh "SPECIAL TARGETS"
|
|---|
| 1034 | Special targets may not be included with other targets, i.e. they must be
|
|---|
| 1035 | the only target specified.
|
|---|
| 1036 | .Bl -tag -width Ic
|
|---|
| 1037 | .It Ic .BEGIN
|
|---|
| 1038 | Any command lines attached to this target are executed before anything
|
|---|
| 1039 | else is done.
|
|---|
| 1040 | .It Ic .DEFAULT
|
|---|
| 1041 | This is sort of a
|
|---|
| 1042 | .Ic .USE
|
|---|
| 1043 | rule for any target (that was used only as a
|
|---|
| 1044 | source) that
|
|---|
| 1045 | .Nm
|
|---|
| 1046 | can't figure out any other way to create.
|
|---|
| 1047 | Only the shell script is used.
|
|---|
| 1048 | The
|
|---|
| 1049 | .Ic .IMPSRC
|
|---|
| 1050 | variable of a target that inherits
|
|---|
| 1051 | .Ic .DEFAULT Ns 's
|
|---|
| 1052 | commands is set
|
|---|
| 1053 | to the target's own name.
|
|---|
| 1054 | .It Ic .END
|
|---|
| 1055 | Any command lines attached to this target are executed after everything
|
|---|
| 1056 | else is done.
|
|---|
| 1057 | .It Ic .IGNORE
|
|---|
| 1058 | Mark each of the sources with the
|
|---|
| 1059 | .Ic .IGNORE
|
|---|
| 1060 | attribute.
|
|---|
| 1061 | If no sources are specified, this is the equivalent of specifying the
|
|---|
| 1062 | .Fl i
|
|---|
| 1063 | option.
|
|---|
| 1064 | .It Ic .INCLUDES
|
|---|
| 1065 | A list of suffixes that indicate files that can be included in a source
|
|---|
| 1066 | file.
|
|---|
| 1067 | The suffix must have already been declared with
|
|---|
| 1068 | .Ic .SUFFIXES ;
|
|---|
| 1069 | any suffix so declared will have the directories on its search path (see
|
|---|
| 1070 | .Ic .PATH )
|
|---|
| 1071 | placed in the
|
|---|
| 1072 | .Va .INCLUDES
|
|---|
| 1073 | special variable, each preceded by a
|
|---|
| 1074 | .Fl I
|
|---|
| 1075 | flag.
|
|---|
| 1076 | .It Ic .INTERRUPT
|
|---|
| 1077 | If
|
|---|
| 1078 | .Nm
|
|---|
| 1079 | is interrupted, the commands for this target will be executed.
|
|---|
| 1080 | .It Ic .LIBS
|
|---|
| 1081 | This does for libraries what
|
|---|
| 1082 | .Ic .INCLUDES
|
|---|
| 1083 | does for include files, except that the flag used is
|
|---|
| 1084 | .Fl L .
|
|---|
| 1085 | .It Ic .MAIN
|
|---|
| 1086 | If no target is specified when
|
|---|
| 1087 | .Nm
|
|---|
| 1088 | is invoked, this target will be built.
|
|---|
| 1089 | This is always set, either
|
|---|
| 1090 | explicitly, or implicitly when
|
|---|
| 1091 | .Nm
|
|---|
| 1092 | selects the default target, to give the user a way to refer to the default
|
|---|
| 1093 | target on the command line.
|
|---|
| 1094 | .It Ic .MAKEFLAGS
|
|---|
| 1095 | This target provides a way to specify flags for
|
|---|
| 1096 | .Nm
|
|---|
| 1097 | when the makefile is used.
|
|---|
| 1098 | The flags are as if typed to the shell, though the
|
|---|
| 1099 | .Fl f
|
|---|
| 1100 | option will have
|
|---|
| 1101 | no effect.
|
|---|
| 1102 | .\" XXX: NOT YET!!!!
|
|---|
| 1103 | .\" .It Ic .NOTPARALLEL
|
|---|
| 1104 | .\" The named targets are executed in non parallel mode. If no targets are
|
|---|
| 1105 | .\" specified, then all targets are executed in non parallel mode.
|
|---|
| 1106 | .It Ic .NOTPARALLEL
|
|---|
| 1107 | Disable parallel mode.
|
|---|
| 1108 | .It Ic .NO_PARALLEL
|
|---|
| 1109 | Same as above, for compatibility with other
|
|---|
| 1110 | .Nm pmake
|
|---|
| 1111 | variants.
|
|---|
| 1112 | .It Ic .ORDER
|
|---|
| 1113 | The named targets are made in sequence.
|
|---|
| 1114 | .\" XXX: NOT YET!!!!
|
|---|
| 1115 | .\" .It Ic .PARALLEL
|
|---|
| 1116 | .\" The named targets are executed in parallel mode. If no targets are
|
|---|
| 1117 | .\" specified, then all targets are executed in parallel mode.
|
|---|
| 1118 | .It Ic .PATH
|
|---|
| 1119 | The sources are directories which are to be searched for files not
|
|---|
| 1120 | found in the current directory.
|
|---|
| 1121 | If no sources are specified, any previously specified directories are
|
|---|
| 1122 | deleted.
|
|---|
| 1123 | Where possible, use of
|
|---|
| 1124 | .Ic .PATH
|
|---|
| 1125 | is preferred over use of the
|
|---|
| 1126 | .Va VPATH
|
|---|
| 1127 | variable.
|
|---|
| 1128 | .It Ic .PATH\fIsuffix\fR
|
|---|
| 1129 | The sources are directories which are to be searched for suffixed files
|
|---|
| 1130 | not found in the current directory.
|
|---|
| 1131 | The
|
|---|
| 1132 | .Nm
|
|---|
| 1133 | utility
|
|---|
| 1134 | first searches the suffixed search path, before reverting to the default
|
|---|
| 1135 | path if the file is not found there.
|
|---|
| 1136 | This form is required for
|
|---|
| 1137 | .Ic .LIBS
|
|---|
| 1138 | and
|
|---|
| 1139 | .Ic .INCLUDES
|
|---|
| 1140 | to work.
|
|---|
| 1141 | .It Ic .PHONY
|
|---|
| 1142 | Apply the
|
|---|
| 1143 | .Ic .PHONY
|
|---|
| 1144 | attribute to any specified sources.
|
|---|
| 1145 | Targets with this attribute are always
|
|---|
| 1146 | considered to be out of date.
|
|---|
| 1147 | .It Ic .PRECIOUS
|
|---|
| 1148 | Apply the
|
|---|
| 1149 | .Ic .PRECIOUS
|
|---|
| 1150 | attribute to any specified sources.
|
|---|
| 1151 | If no sources are specified, the
|
|---|
| 1152 | .Ic .PRECIOUS
|
|---|
| 1153 | attribute is applied to every
|
|---|
| 1154 | target in the file.
|
|---|
| 1155 | .It Ic .SILENT
|
|---|
| 1156 | Apply the
|
|---|
| 1157 | .Ic .SILENT
|
|---|
| 1158 | attribute to any specified sources.
|
|---|
| 1159 | If no sources are specified, the
|
|---|
| 1160 | .Ic .SILENT
|
|---|
| 1161 | attribute is applied to every
|
|---|
| 1162 | command in the file.
|
|---|
| 1163 | .It Ic .SUFFIXES
|
|---|
| 1164 | Each source specifies a suffix to
|
|---|
| 1165 | .Nm .
|
|---|
| 1166 | If no sources are specified, any previous specified suffices are deleted.
|
|---|
| 1167 | .El
|
|---|
| 1168 | .Sh COMPATIBILITY
|
|---|
| 1169 | Older versions of
|
|---|
| 1170 | .Nm
|
|---|
| 1171 | used
|
|---|
| 1172 | .Ev MAKE
|
|---|
| 1173 | instead of
|
|---|
| 1174 | .Ev MAKEFLAGS .
|
|---|
| 1175 | This was removed for POSIX compatibility.
|
|---|
| 1176 | The internal variable
|
|---|
| 1177 | .Va MAKE
|
|---|
| 1178 | is set to the same value as
|
|---|
| 1179 | .Va .MAKE ;
|
|---|
| 1180 | support for this may be removed in the future.
|
|---|
| 1181 | .Pp
|
|---|
| 1182 | Most of the more esoteric features of
|
|---|
| 1183 | .Nm
|
|---|
| 1184 | should probably be avoided for greater compatibility.
|
|---|
| 1185 | .Sh ENVIRONMENT
|
|---|
| 1186 | The
|
|---|
| 1187 | .Nm
|
|---|
| 1188 | utility uses the following environment variables, if they exist:
|
|---|
| 1189 | .Ev MACHINE ,
|
|---|
| 1190 | .Ev MAKE ,
|
|---|
| 1191 | .Ev MAKEFLAGS ,
|
|---|
| 1192 | .Ev MAKEOBJDIR ,
|
|---|
| 1193 | and
|
|---|
| 1194 | .Ev MAKEOBJDIRPREFIX .
|
|---|
| 1195 | .Sh FILES
|
|---|
| 1196 | .Bl -tag -width /usr/share/doc/psd/12.make -compact
|
|---|
| 1197 | .It Pa .depend
|
|---|
| 1198 | list of dependencies
|
|---|
| 1199 | .It Pa Makefile
|
|---|
| 1200 | list of dependencies
|
|---|
| 1201 | .It Pa makefile
|
|---|
| 1202 | list of dependencies
|
|---|
| 1203 | .It obj
|
|---|
| 1204 | object directory
|
|---|
| 1205 | .It Pa sys.mk
|
|---|
| 1206 | system makefile (processed before any other file, including
|
|---|
| 1207 | .Pa makefile
|
|---|
| 1208 | and
|
|---|
| 1209 | .Pa Makefile )
|
|---|
| 1210 | .It Pa /usr/share/mk
|
|---|
| 1211 | system makefile directory
|
|---|
| 1212 | .It /usr/share/doc/psd/12.make
|
|---|
| 1213 | PMake tutorial
|
|---|
| 1214 | .It Pa /usr/obj
|
|---|
| 1215 | default
|
|---|
| 1216 | .Ev MAKEOBJDIRPREFIX
|
|---|
| 1217 | directory.
|
|---|
| 1218 | .El
|
|---|
| 1219 | .Sh BUGS
|
|---|
| 1220 | The determination of
|
|---|
| 1221 | .Va .OBJDIR
|
|---|
| 1222 | is contorted to the point of absurdity.
|
|---|
| 1223 | .Pp
|
|---|
| 1224 | In the presence of several
|
|---|
| 1225 | .Ic .MAIN
|
|---|
| 1226 | special targets,
|
|---|
| 1227 | .Nm
|
|---|
| 1228 | silently ignores all but the first.
|
|---|
| 1229 | .Pp
|
|---|
| 1230 | .Va .TARGETS
|
|---|
| 1231 | is not set to the default target when
|
|---|
| 1232 | .Nm
|
|---|
| 1233 | is invoked without a target name and no
|
|---|
| 1234 | .Ic .MAIN
|
|---|
| 1235 | special target exists.
|
|---|
| 1236 | .Pp
|
|---|
| 1237 | The evaluation of
|
|---|
| 1238 | .Ar expression
|
|---|
| 1239 | in a test is very simple-minded.
|
|---|
| 1240 | Currently, the only form that works is
|
|---|
| 1241 | .Ql .if ${VAR} op something
|
|---|
| 1242 | For instance, you should write tests as
|
|---|
| 1243 | .Ql .if ${VAR} = "string"
|
|---|
| 1244 | not the other way around, which doesn't work.
|
|---|
| 1245 | .Pp
|
|---|
| 1246 | For loops are expanded before tests, so a fragment such as:
|
|---|
| 1247 | .Bd -literal -offset indent
|
|---|
| 1248 | \&.for TMACHINE in ${SHARED_ARCHS}
|
|---|
| 1249 | \&.if ${TMACHINE} = ${MACHINE}
|
|---|
| 1250 | ...
|
|---|
| 1251 | \&.endif
|
|---|
| 1252 | \&.endfor
|
|---|
| 1253 | .Ed
|
|---|
| 1254 | .Pp
|
|---|
| 1255 | won't work, and should be rewritten the other way around.
|
|---|
| 1256 | .Pp
|
|---|
| 1257 | The parsing code is broken with respect to handling a semicolon
|
|---|
| 1258 | after a colon, so a fragment like this will fail:
|
|---|
| 1259 | .Bd -literal -offset indent
|
|---|
| 1260 | HDRS= foo.h bar.h
|
|---|
| 1261 |
|
|---|
| 1262 | all:
|
|---|
| 1263 | \&.for h in ${HDRS:S;^;${.CURDIR}/;}
|
|---|
| 1264 | ...
|
|---|
| 1265 | \&.endfor
|
|---|
| 1266 | .Ed
|
|---|
| 1267 | .Sh SEE ALSO
|
|---|
| 1268 | .Xr mkdep 1 ,
|
|---|
| 1269 | .Xr make.conf 5
|
|---|
| 1270 | .Rs
|
|---|
| 1271 | .%T "PMake - A Tutorial"
|
|---|
| 1272 | .Re
|
|---|
| 1273 | in
|
|---|
| 1274 | .Pa /usr/share/doc/psd/12.make
|
|---|
| 1275 | .Sh HISTORY
|
|---|
| 1276 | A
|
|---|
| 1277 | .Nm
|
|---|
| 1278 | command appeared in PWB UNIX.
|
|---|