1.\" $NetBSD: make.1,v 1.360 2023/01/26 20:48:17 sjg Exp $ 2.\" 3.\" Copyright (c) 1990, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 31.\" 32.Dd January 26, 2023 33.Dt MAKE 1 34.Os 35.Sh NAME 36.Nm make 37.Nd maintain program dependencies 38.Sh SYNOPSIS 39.Nm 40.Op Fl BeikNnqrSstWwX 41.Op Fl C Ar directory 42.Op Fl D Ar variable 43.Op Fl d Ar flags 44.Op Fl f Ar makefile 45.Op Fl I Ar directory 46.Op Fl J Ar private 47.Op Fl j Ar max_jobs 48.Op Fl m Ar directory 49.Op Fl T Ar file 50.Op Fl V Ar variable 51.Op Fl v Ar variable 52.Op Ar variable\| Ns Cm \&= Ns Ar value 53.Op Ar target No ... 54.Sh DESCRIPTION 55.Nm 56is a program designed to simplify the maintenance of other programs. 57Its input is a list of specifications as to the files upon which programs 58and other files depend. 59If no 60.Fl f Ar makefile 61option is given, 62.Nm 63tries to open 64.Sq Pa makefile 65then 66.Sq Pa Makefile 67in order to find the specifications. 68If the file 69.Sq Pa .depend 70exists, it is read, see 71.Xr mkdep 1 . 72.Pp 73This manual page is intended as a reference document only. 74For a more thorough description of 75.Nm 76and makefiles, please refer to 77.%T "PMake \- A Tutorial" 78(from 1993). 79.Pp 80.Nm 81prepends the contents of the 82.Ev MAKEFLAGS 83environment variable to the command line arguments before parsing them. 84.Pp 85The options are as follows: 86.Bl -tag -width Ds 87.It Fl B 88Try to be backwards compatible by executing a single shell per command and 89by making the sources of a dependency line in sequence. 90.It Fl C Ar directory 91Change to 92.Ar directory 93before reading the makefiles or doing anything else. 94If multiple 95.Fl C 96options are specified, each is interpreted relative to the previous one: 97.Fl C Pa / Fl C Pa etc 98is equivalent to 99.Fl C Pa /etc . 100.It Fl D Ar variable 101Define 102.Ar variable 103to be 1, in the global scope. 104.It Fl d Oo Cm \- Oc Ns Ar flags 105Turn on debugging, and specify which portions of 106.Nm 107are to print debugging information. 108Unless the flags are preceded by 109.Ql \- , 110they are added to the 111.Ev MAKEFLAGS 112environment variable and are passed on to any child make processes. 113By default, debugging information is printed to standard error, 114but this can be changed using the 115.Cm F 116debugging flag. 117The debugging output is always unbuffered; in addition, if debugging 118is enabled but debugging output is not directed to standard output, 119the standard output is line buffered. 120The available 121.Ar flags 122are: 123.Bl -tag -width Ds 124.It Cm A 125Print all possible debugging information; 126equivalent to specifying all of the debugging flags. 127.It Cm a 128Print debugging information about archive searching and caching. 129.It Cm C 130Print debugging information about the current working directory. 131.It Cm c 132Print debugging information about conditional evaluation. 133.It Cm d 134Print debugging information about directory searching and caching. 135.It Cm e 136Print debugging information about failed commands and targets. 137.It Cm F Ns Oo Cm \&+ Oc Ns Ar filename 138Specify where debugging output is written. 139This must be the last flag, because it consumes the remainder of 140the argument. 141If the character immediately after the 142.Cm F 143flag is 144.Ql \&+ , 145the file is opened in append mode; 146otherwise the file is overwritten. 147If the file name is 148.Ql stdout 149or 150.Ql stderr , 151debugging output is written to the standard output or standard error output 152respectively (and the 153.Ql \&+ 154option has no effect). 155Otherwise, the output is written to the named file. 156If the file name ends with 157.Ql .%d , 158the 159.Ql %d 160is replaced by the pid. 161.It Cm f 162Print debugging information about loop evaluation. 163.It Cm g1 164Print the input graph before making anything. 165.It Cm g2 166Print the input graph after making everything, or before exiting 167on error. 168.It Cm g3 169Print the input graph before exiting on error. 170.It Cm h 171Print debugging information about hash table operations. 172.It Cm j 173Print debugging information about running multiple shells. 174.It Cm L 175Turn on lint checks. 176This throws errors for variable assignments that do not parse correctly, 177at the time of assignment, so the file and line number are available. 178.It Cm l 179Print commands in Makefiles regardless of whether or not they are prefixed by 180.Ql @ 181or other 182.Dq quiet 183flags. 184Also known as 185.Dq loud 186behavior. 187.It Cm M 188Print debugging information about 189.Dq meta 190mode decisions about targets. 191.It Cm m 192Print debugging information about making targets, including modification 193dates. 194.It Cm n 195Don't delete the temporary command scripts created when running commands. 196These temporary scripts are created in the directory 197referred to by the 198.Ev TMPDIR 199environment variable, or in 200.Pa /tmp 201if 202.Ev TMPDIR 203is unset or set to the empty string. 204The temporary scripts are created by 205.Xr mkstemp 3 , 206and have names of the form 207.Pa makeXXXXXX . 208.Em NOTE : 209This can create many files in 210.Ev TMPDIR 211or 212.Pa /tmp , 213so use with care. 214.It Cm p 215Print debugging information about makefile parsing. 216.It Cm s 217Print debugging information about suffix-transformation rules. 218.It Cm t 219Print debugging information about target list maintenance. 220.It Cm V 221Force the 222.Fl V 223option to print raw values of variables, 224overriding the default behavior set via 225.Va .MAKE.EXPAND_VARIABLES . 226.It Cm v 227Print debugging information about variable assignment and expansion. 228.It Cm x 229Run shell commands with 230.Fl x 231so the actual commands are printed as they are executed. 232.El 233.It Fl e 234Let environment variables override global variables within makefiles. 235.It Fl f Ar makefile 236Specify a makefile to read instead of the default 237.Pa makefile 238or 239.Pa Makefile . 240If 241.Ar makefile 242is 243.Ql \&- , 244standard input is read. 245Multiple makefiles may be specified, and are read in the order specified. 246.It Fl I Ar directory 247Specify a directory in which to search for makefiles and included makefiles. 248The system makefile directory (or directories, see the 249.Fl m 250option) is automatically included as part of this list. 251.It Fl i 252Ignore non-zero exit of shell commands in the makefile. 253Equivalent to specifying 254.Ql \&- 255before each command line in the makefile. 256.It Fl J Ar private 257This option should 258.Em not 259be specified by the user. 260.Pp 261When the 262.Fl j 263option is in use in a recursive build, this option is passed by a make 264to child makes to allow all the make processes in the build to 265cooperate to avoid overloading the system. 266.It Fl j Ar max_jobs 267Specify the maximum number of jobs that 268.Nm 269may have running at any one time. 270The value is saved in 271.Va .MAKE.JOBS . 272Turns compatibility mode off, unless the 273.Fl B 274option is also specified. 275When compatibility mode is off, all commands associated with a 276target are executed in a single shell invocation as opposed to the 277traditional one shell invocation per line. 278This can break traditional scripts which change directories on each 279command invocation and then expect to start with a fresh environment 280on the next line. 281It is more efficient to correct the scripts rather than turn backwards 282compatibility on. 283.It Fl k 284Continue processing after errors are encountered, but only on those targets 285that do not depend on the target whose creation caused the error. 286.It Fl m Ar directory 287Specify a directory in which to search for 288.Pa sys.mk 289and makefiles included via the 290.Li \&< Ns Ar file Ns Li \&> Ns -style 291include statement. 292The 293.Fl m 294option can be used multiple times to form a search path. 295This path overrides the default system include path 296.Pa /usr/share/mk . 297Furthermore, the system include path is appended to the search path used for 298.Li \*q Ns Ar file Ns Li \*q Ns -style 299include statements (see the 300.Fl I 301option). 302The system include path can be referenced via the read-only variable 303.Va .SYSPATH . 304.Pp 305If a directory name in the 306.Fl m 307argument (or the 308.Ev MAKESYSPATH 309environment variable) starts with the string 310.Ql \&.../ , 311.Nm 312searches for the specified file or directory named in the remaining part 313of the argument string. 314The search starts with the current directory 315and then works upward towards the root of the file system. 316If the search is successful, the resulting directory replaces the 317.Ql \&.../ 318specification in the 319.Fl m 320argument. 321This feature allows 322.Nm 323to easily search in the current source tree for customized 324.Pa sys.mk 325files (e.g., by using 326.Ql \&.../mk/sys.mk 327as an argument). 328.It Fl n 329Display the commands that would have been executed, but do not 330actually execute them unless the target depends on the 331.Va .MAKE 332special source (see below) or the command is prefixed with 333.Sq Cm + . 334.It Fl N 335Display the commands that would have been executed, 336but do not actually execute any of them; 337useful for debugging top-level makefiles 338without descending into subdirectories. 339.It Fl q 340Do not execute any commands, 341instead exit 0 if the specified targets are up to date, and 1 otherwise. 342.It Fl r 343Do not use the built-in rules specified in the system makefile. 344.It Fl S 345Stop processing if an error is encountered. 346This is the default behavior and the opposite of 347.Fl k . 348.It Fl s 349Do not echo any commands as they are executed. 350Equivalent to specifying 351.Sq Ic @ 352before each command line in the makefile. 353.It Fl T Ar tracefile 354When used with the 355.Fl j 356flag, 357append a trace record to 358.Ar tracefile 359for each job started and completed. 360.It Fl t 361Rather than re-building a target as specified in the makefile, create it 362or update its modification time to make it appear up-to-date. 363.It Fl V Ar variable 364Print the value of 365.Ar variable . 366Do not build any targets. 367Multiple instances of this option may be specified; 368the variables are printed one per line, 369with a blank line for each null or undefined variable. 370The value printed is extracted from the global scope after all 371makefiles have been read. 372.Pp 373By default, the raw variable contents (which may 374include additional unexpanded variable references) are shown. 375If 376.Ar variable 377contains a 378.Ql \&$ , 379it is not interpreted as a variable name but rather as an expression. 380Its value is expanded before printing. 381The value is also expanded before printing if 382.Va .MAKE.EXPAND_VARIABLES 383is set to true and the 384.Fl dV 385option has not been used to override it. 386.Pp 387Note that loop-local and target-local variables, as well as values 388taken temporarily by global variables during makefile processing, are 389not accessible via this option. 390The 391.Fl dv 392debug mode can be used to see these at the cost of generating 393substantial extraneous output. 394.It Fl v Ar variable 395Like 396.Fl V , 397but all printed variables are always expanded to their complete value. 398The last occurrence of 399.Fl V 400or 401.Fl v 402decides whether all variables are expanded or not. 403.It Fl W 404Treat any warnings during makefile parsing as errors. 405.It Fl w 406Print entering and leaving directory messages, pre and post processing. 407.It Fl X 408Don't export variables passed on the command line to the environment 409individually. 410Variables passed on the command line are still exported via the 411.Ev MAKEFLAGS 412environment variable. 413This option may be useful on systems which have a small limit on the 414size of command arguments. 415.It Ar variable\| Ns Cm \&= Ns Ar value 416Set the value of the variable 417.Ar variable 418to 419.Ar value . 420Normally, all values passed on the command line are also exported to 421sub-makes in the environment. 422The 423.Fl X 424flag disables this behavior. 425Variable assignments should follow options for POSIX compatibility 426but no ordering is enforced. 427.El 428.Pp 429There are several different types of lines in a makefile: dependency 430specifications, shell commands, variable assignments, include statements, 431conditional directives, for loops, other directives, and comments. 432.Pp 433Lines may be continued from one line to the next 434by ending them with a backslash 435.Pq Ql \e . 436The trailing newline character and initial whitespace on the following 437line are compressed into a single space. 438.Sh FILE DEPENDENCY SPECIFICATIONS 439Dependency lines consist of one or more targets, an operator, and zero 440or more sources. 441This creates a relationship where the targets 442.Dq depend 443on the sources and are customarily created from them. 444A target is considered out of date if it does not exist, 445or if its modification time is less than that of any of its sources. 446An out-of-date target is re-created, but not until all sources 447have been examined and themselves re-created as needed. 448Three operators may be used: 449.Bl -tag -width flag 450.It Ic \&: 451Many dependency lines may name this target but only one may have 452attached shell commands. 453All sources named in all dependency lines are considered together, 454and if needed the attached shell commands are run to create or 455re-create the target. 456If 457.Nm 458is interrupted, the target is removed. 459.It Ic \&! 460The same, but the target is always re-created whether or not it is out 461of date. 462.It Ic \&:: 463Any dependency line may have attached shell commands, but each one 464is handled independently: its sources are considered and the attached 465shell commands are run if the target is out of date with respect to 466(only) those sources. 467Thus, different groups of the attached shell commands may be run 468depending on the circumstances. 469Furthermore, unlike 470.Ic \&: , 471for dependency lines with no sources, the attached shell 472commands are always run. 473Also unlike 474.Ic \&: , 475the target is not removed if 476.Nm 477is interrupted. 478.El 479.Pp 480All dependency lines mentioning a particular target must use the same 481operator. 482.Pp 483Targets and sources may contain the shell wildcard values 484.Ql \&? , 485.Ql * , 486.Ql [] , 487and 488.Ql {} . 489The values 490.Ql \&? , 491.Ql * , 492and 493.Ql [] 494may only be used as part of the final component of the target or source, 495and only match existing files. 496The value 497.Ql {} 498need not necessarily be used to describe existing files. 499Expansion is in directory order, not alphabetically as done in the shell. 500.Sh SHELL COMMANDS 501Each target may have associated with it one or more lines of shell commands, 502normally used to create the target. 503Each of the lines in this script 504.Em must 505be preceded by a tab. 506(For historical reasons, spaces are not accepted.) 507While targets can occur in many dependency lines if desired, 508by default only one of these rules may be followed by a creation script. 509If the 510.Sq Ic \&:: 511operator is used, however, all rules may include scripts, 512and the respective scripts are executed in the order found. 513.Pp 514Each line is treated as a separate shell command, 515unless the end of line is escaped with a backslash 516.Ql \e , 517in which case that line and the next are combined. 518If the first characters of the command are any combination of 519.Sq Ic @ , 520.Sq Ic + , 521or 522.Sq Ic \- , 523the command is treated specially. 524.Bl -tag -offset indent -width indent 525.It Ic @ 526causes the command not to be echoed before it is executed. 527.It Ic + 528causes the command to be executed even when 529.Fl n 530is given. 531This is similar to the effect of the 532.Va .MAKE 533special source, 534except that the effect can be limited to a single line of a script. 535.It Ic \- 536in compatibility mode 537causes any non-zero exit status of the command line to be ignored. 538.El 539.Pp 540When 541.Nm 542is run in jobs mode with 543.Fl j Ar max_jobs , 544the entire script for the target is fed to a single instance of the shell. 545In compatibility (non-jobs) mode, each command is run in a separate process. 546If the command contains any shell meta characters 547.Pq Ql #=|^(){};&<>*?[]:$`\e\en , 548it is passed to the shell; otherwise 549.Nm 550attempts direct execution. 551If a line starts with 552.Sq Ic \- 553and the shell has ErrCtl enabled, 554failure of the command line is ignored as in compatibility mode. 555Otherwise 556.Sq Ic \- 557affects the entire job; 558the script stops at the first command line that fails, 559but the target is not deemed to have failed. 560.Pp 561Makefiles should be written so that the mode of 562.Nm 563operation does not change their behavior. 564For example, any command which uses 565.Dq cd 566or 567.Dq chdir 568without the intention of changing the directory for subsequent commands 569should be put in parentheses so it executes in a subshell. 570To force the use of a single shell, escape the line breaks so as to make 571the whole script one command. 572For example: 573.Bd -literal -offset indent 574avoid-chdir-side-effects: 575 @echo "Building $@ in $$(pwd)" 576 @(cd ${.CURDIR} && ${MAKE} $@) 577 @echo "Back in $$(pwd)" 578 579ensure-one-shell-regardless-of-mode: 580 @echo "Building $@ in $$(pwd)"; \e 581 (cd ${.CURDIR} && ${MAKE} $@); \e 582 echo "Back in $$(pwd)" 583.Ed 584.Pp 585Since 586.Nm 587changes the current working directory to 588.Sq Va .OBJDIR 589before executing any targets, 590each child process starts with that as its current working directory. 591.Sh VARIABLE ASSIGNMENTS 592Variables in make behave much like macros in the C preprocessor. 593.Pp 594Variable assignments have the form 595.Sq Ar NAME Ar op Ar value , 596where: 597.Bl -tag -offset Ds -width Ds 598.It Ar NAME 599is a single-word variable name, 600consisting, by tradition, of all upper-case letters, 601.It Ar op 602is one of the variable assignment operators described below, and 603.It Ar value 604is interpreted according to the variable assignment operator. 605.El 606.Pp 607Whitespace around 608.Ar NAME , 609.Ar op 610and 611.Ar value 612is discarded. 613.Ss Variable assignment operators 614The five operators that assign values to variables are: 615.Bl -tag -width Ds 616.It Ic \&= 617Assign the value to the variable. 618Any previous value is overwritten. 619.It Ic \&+= 620Append the value to the current value of the variable, 621separating them by a single space. 622.It Ic \&?= 623Assign the value to the variable if it is not already defined. 624.It Ic \&:= 625Expand the value, then assign it to the variable. 626.Pp 627.Em NOTE : 628References to undefined variables are 629.Em not 630expanded. 631This can cause problems when variable modifiers are used. 632.\" See var-op-expand.mk, the section with LATER and INDIRECT. 633.It Ic \&!= 634Expand the value and pass it to the shell for execution, 635then assign the output from the child's standard output to the variable. 636Any newlines in the result are replaced with spaces. 637.El 638.Ss Expansion of variables 639In most contexts where variables are expanded, 640.Ql \&$$ 641expands to a single dollar sign. 642In other contexts (most variable modifiers, string literals in conditions), 643.Ql \&\e$ 644expands to a single dollar sign. 645.Pp 646References to variables have the form 647.Cm \&${ Ns Ar name Ns Oo Ns Cm \&: Ns Ar modifiers Oc Ns Cm \&} 648or 649.Cm \&$( Ns Ar name Ns Oo Ns Cm \&: Ns Ar modifiers Oc Ns Cm \&) . 650If the variable name consists of only a single character 651and the expression contains no modifiers, 652the surrounding curly braces or parentheses are not required. 653This shorter form is not recommended. 654.Pp 655If the variable name contains a dollar, the name itself is expanded first. 656This allows almost arbitrary variable names, however names containing dollar, 657braces, parentheses or whitespace are really best avoided. 658.Pp 659If the result of expanding a nested variable expression contains a dollar sign 660.Pq Ql \&$ , 661the result is subject to further expansion. 662.Pp 663Variable substitution occurs at four distinct times, depending on where 664the variable is being used. 665.Bl -enum 666.It 667Variables in dependency lines are expanded as the line is read. 668.It 669Variables in conditionals are expanded individually, 670but only as far as necessary to determine the result of the conditional. 671.It 672Variables in shell commands are expanded when the shell command is 673executed. 674.It 675.Ic .for 676loop index variables are expanded on each loop iteration. 677Note that other variables are not expanded when composing the body of a loop, 678so the following example code: 679.Bd -literal -offset indent 680\&.for i in 1 2 3 681a+= ${i} 682j= ${i} 683b+= ${j} 684\&.endfor 685 686all: 687 @echo ${a} 688 @echo ${b} 689.Ed 690.Pp 691prints: 692.Bd -literal -offset indent 6931 2 3 6943 3 3 695.Ed 696.Pp 697After the loop is executed: 698.Bl -tag -offset indent -width indent 699.It Va a 700contains 701.Ql ${:U1} ${:U2} ${:U3} , 702which expands to 703.Ql 1 2 3 . 704.It Va j 705contains 706.Ql ${:U3} , 707which expands to 708.Ql 3 . 709.It Va b 710contains 711.Ql ${j} ${j} ${j} , 712which expands to 713.Ql ${:U3} ${:U3} ${:U3} 714and further to 715.Ql 3 3 3 . 716.El 717.El 718.Ss Variable classes 719The four different classes of variables (in order of increasing precedence) 720are: 721.Bl -tag -width Ds 722.It Environment variables 723Variables defined as part of 724.Nm Ns 's 725environment. 726.It Global variables 727Variables defined in the makefile or in included makefiles. 728.It Command line variables 729Variables defined as part of the command line. 730.It Local variables 731Variables that are defined specific to a certain target. 732.El 733.Pp 734Local variables can be set on a dependency line, unless 735.Va .MAKE.TARGET_LOCAL_VARIABLES 736is set to 737.Ql false . 738The rest of the line 739(which already has had global variables expanded) 740is the variable value. 741For example: 742.Bd -literal -offset indent 743COMPILER_WRAPPERS= ccache distcc icecc 744 745${OBJS}: .MAKE.META.CMP_FILTER=${COMPILER_WRAPPERS:S,^,N,} 746.Ed 747.Pp 748Only the targets 749.Ql ${OBJS} 750are impacted by that filter (in 751.Dq meta 752mode) and 753simply enabling/disabling any of the compiler wrappers does not render all 754of those targets out-of-date. 755.Pp 756.Em NOTE : 757target-local variable assignments behave differently in that; 758.Bl -tag -width Ds -offset indent 759.It Ic \&+= 760Only appends to a previous local assignment 761for the same target and variable. 762.It Ic \&:= 763Is redundant with respect to global variables, 764which have already been expanded. 765.El 766.Pp 767The seven built-in local variables are: 768.Bl -tag -width ".Va .ARCHIVE" -offset indent 769.It Va .ALLSRC 770The list of all sources for this target; also known as 771.Sq Va \&> . 772.It Va .ARCHIVE 773The name of the archive file; also known as 774.Sq Va \&! . 775.It Va .IMPSRC 776In suffix-transformation rules, the name/path of the source from which the 777target is to be transformed (the 778.Dq implied 779source); also known as 780.Sq Va \&< . 781It is not defined in explicit rules. 782.It Va .MEMBER 783The name of the archive member; also known as 784.Sq Va % . 785.It Va .OODATE 786The list of sources for this target that were deemed out-of-date; also 787known as 788.Sq Va \&? . 789.It Va .PREFIX 790The file prefix of the target, containing only the file portion, no suffix 791or preceding directory components; also known as 792.Sq Va * . 793The suffix must be one of the known suffixes declared with 794.Ic .SUFFIXES , 795or it is not recognized. 796.It Va .TARGET 797The name of the target; also known as 798.Sq Va @ . 799For compatibility with other makes this is an alias for 800.Va .ARCHIVE 801in archive member rules. 802.El 803.Pp 804The shorter forms 805.Po 806.Sq Va \&> , 807.Sq Va \&! , 808.Sq Va \&< , 809.Sq Va \&% , 810.Sq Va \&? , 811.Sq Va \&* , 812and 813.Sq Va \&@ 814.Pc 815are permitted for backward 816compatibility with historical makefiles and legacy POSIX make and are 817not recommended. 818.Pp 819Variants of these variables with the punctuation followed immediately by 820.Ql D 821or 822.Ql F , 823e.g.\& 824.Ql $(@D) , 825are legacy forms equivalent to using the 826.Ql :H 827and 828.Ql :T 829modifiers. 830These forms are accepted for compatibility with 831.At V 832makefiles and POSIX but are not recommended. 833.Pp 834Four of the local variables may be used in sources on dependency lines 835because they expand to the proper value for each target on the line. 836These variables are 837.Sq Va .TARGET , 838.Sq Va .PREFIX , 839.Sq Va .ARCHIVE , 840and 841.Sq Va .MEMBER . 842.Ss Additional built-in variables 843In addition, 844.Nm 845sets or knows about the following variables: 846.Bl -tag 847.\" NB: This list is sorted case-insensitive, ignoring punctuation. 848.\" NB: To find all built-in variables in make's source code, 849.\" NB: search for Var_*, Global_*, SetVarObjdir, GetBooleanExpr, 850.\" NB: and the implementation of Var_SetWithFlags. 851.\" NB: Last synced on 2023-01-01. 852.It Va .ALLTARGETS 853The list of all targets encountered in the makefiles. 854If evaluated during makefile parsing, 855lists only those targets encountered thus far. 856.It Va .CURDIR 857A path to the directory where 858.Nm 859was executed. 860Refer to the description of 861.Sq Va PWD 862for more details. 863.It Va .ERROR_CMD 864Is used in error handling, see 865.Va MAKE_PRINT_VAR_ON_ERROR . 866.It Va .ERROR_CWD 867Is used in error handling, see 868.Va MAKE_PRINT_VAR_ON_ERROR . 869.It Va .ERROR_META_FILE 870Is used in error handling in 871.Dq meta 872mode, see 873.Va MAKE_PRINT_VAR_ON_ERROR . 874.It Va .ERROR_TARGET 875Is used in error handling, see 876.Va MAKE_PRINT_VAR_ON_ERROR . 877.It Va .INCLUDEDFROMDIR 878The directory of the file this makefile was included from. 879.It Va .INCLUDEDFROMFILE 880The filename of the file this makefile was included from. 881.\" .INCLUDES is intentionally undocumented, as it is obsolete. 882.\" .LIBS is intentionally undocumented, as it is obsolete. 883.It Va MACHINE 884The machine hardware name, see 885.Xr uname 1 . 886.It Va MACHINE_ARCH 887The machine processor architecture name, see 888.Xr uname 1 . 889.It Va MAKE 890The name that 891.Nm 892was executed with 893.Pq Va argv[0] . 894.It Va .MAKE 895The same as 896.Va MAKE , 897for compatibility. 898The preferred variable to use is the environment variable 899.Ev MAKE 900because it is more compatible with other make variants 901and cannot be confused with the special target with the same name. 902.\" '.MAKE.cmd_filtered' is intentionally undocumented, 903.\" as it is an internal implementation detail. 904.It Va .MAKE.DEPENDFILE 905Names the makefile (default 906.Sq Pa .depend ) 907from which generated dependencies are read. 908.It Va .MAKE.DIE_QUIETLY 909If set to 910.Ql true , 911do not print error information at the end. 912.It Va .MAKE.EXPAND_VARIABLES 913A boolean that controls the default behavior of the 914.Fl V 915option. 916If true, variable values printed with 917.Fl V 918are fully expanded; if false, the raw variable contents (which may 919include additional unexpanded variable references) are shown. 920.It Va .MAKE.EXPORTED 921The list of variables exported by 922.Nm . 923.It Va MAKEFILE 924The top-level makefile that is currently read, 925as given in the command line. 926.It Va .MAKEFLAGS 927The environment variable 928.Sq Ev MAKEFLAGS 929may contain anything that 930may be specified on 931.Nm Ns 's 932command line. 933Anything specified on 934.Nm Ns 's 935command line is appended to the 936.Va .MAKEFLAGS 937variable, which is then added to the environment for all programs that 938.Nm 939executes. 940.It Va .MAKE.GID 941The numeric group ID of the user running 942.Nm . 943It is read-only. 944.It Va .MAKE.JOB.PREFIX 945If 946.Nm 947is run with 948.Fl j , 949the output for each target is prefixed with a token 950.Dl --- Ar target Li --- 951the first part of which can be controlled via 952.Va .MAKE.JOB.PREFIX . 953If 954.Va .MAKE.JOB.PREFIX 955is empty, no token is printed. 956For example, setting 957.Va .MAKE.JOB.PREFIX 958to 959.Ql ${.newline}---${.MAKE:T}[${.MAKE.PID}] 960would produce tokens like 961.Dl ---make[1234] Ar target Li --- 962making it easier to track the degree of parallelism being achieved. 963.It Va .MAKE.JOBS 964The argument to the 965.Fl j 966option. 967.It Va .MAKE.LEVEL 968The recursion depth of 969.Nm . 970The top-level instance of 971.Nm 972has level 0, and each child make has its parent level plus 1. 973This allows tests like: 974.Li .if ${.MAKE.LEVEL} == 0 975to protect things which should only be evaluated in the top-level instance of 976.Nm . 977.It Va .MAKE.LEVEL.ENV 978The name of the environment variable that stores the level of nested calls to 979.Nm . 980.It Va .MAKE.MAKEFILE_PREFERENCE 981The ordered list of makefile names 982(default 983.Sq Pa makefile , 984.Sq Pa Makefile ) 985that 986.Nm 987looks for. 988.It Va .MAKE.MAKEFILES 989The list of makefiles read by 990.Nm , 991which is useful for tracking dependencies. 992Each makefile is recorded only once, regardless of the number of times read. 993.It Va .MAKE.META.BAILIWICK 994In 995.Dq meta 996mode, provides a list of prefixes which 997match the directories controlled by 998.Nm . 999If a file that was generated outside of 1000.Va .OBJDIR 1001but within said bailiwick is missing, 1002the current target is considered out-of-date. 1003.It Va .MAKE.META.CMP_FILTER 1004In 1005.Dq meta 1006mode, it can (very rarely!) be useful to filter command 1007lines before comparison. 1008This variable can be set to a set of modifiers that are applied to 1009each line of the old and new command that differ, if the filtered 1010commands still differ, the target is considered out-of-date. 1011.It Va .MAKE.META.CREATED 1012In 1013.Dq meta 1014mode, this variable contains a list of all the meta files 1015updated. 1016If not empty, it can be used to trigger processing of 1017.Va .MAKE.META.FILES . 1018.It Va .MAKE.META.FILES 1019In 1020.Dq meta 1021mode, this variable contains a list of all the meta files 1022used (updated or not). 1023This list can be used to process the meta files to extract dependency 1024information. 1025.It Va .MAKE.META.IGNORE_FILTER 1026Provides a list of variable modifiers to apply to each pathname. 1027Ignore if the expansion is an empty string. 1028.It Va .MAKE.META.IGNORE_PATHS 1029Provides a list of path prefixes that should be ignored; 1030because the contents are expected to change over time. 1031The default list includes: 1032.Sq Pa /dev /etc /proc /tmp /var/run /var/tmp 1033.It Va .MAKE.META.IGNORE_PATTERNS 1034Provides a list of patterns to match against pathnames. 1035Ignore any that match. 1036.It Va .MAKE.META.PREFIX 1037Defines the message printed for each meta file updated in 1038.Dq meta verbose 1039mode. 1040The default value is: 1041.Dl Building ${.TARGET:H:tA}/${.TARGET:T} 1042.It Va .MAKE.MODE 1043Processed after reading all makefiles. 1044Affects the mode that 1045.Nm 1046runs in. 1047It can contain these keywords: 1048.Bl -tag -width indent 1049.It Cm compat 1050Like 1051.Fl B , 1052puts 1053.Nm 1054into 1055.Dq compat 1056mode. 1057.It Cm meta 1058Puts 1059.Nm 1060into 1061.Dq meta 1062mode, where meta files are created for each target 1063to capture the command run, the output generated, and if 1064.Xr filemon 4 1065is available, the system calls which are of interest to 1066.Nm . 1067The captured output can be useful when diagnosing errors. 1068.It Cm curdirOk= Ns Ar bf 1069By default, 1070.Nm 1071does not create 1072.Pa .meta 1073files in 1074.Sq Va .CURDIR . 1075This can be overridden by setting 1076.Ar bf 1077to a value which represents true. 1078.It Cm missing-meta= Ns Ar bf 1079If 1080.Ar bf 1081is true, a missing 1082.Pa .meta 1083file makes the target out-of-date. 1084.It Cm missing-filemon= Ns Ar bf 1085If 1086.Ar bf 1087is true, missing filemon data makes the target out-of-date. 1088.It Cm nofilemon 1089Do not use 1090.Xr filemon 4 . 1091.It Cm env 1092For debugging, it can be useful to include the environment 1093in the 1094.Pa .meta 1095file. 1096.It Cm verbose 1097If in 1098.Dq meta 1099mode, print a clue about the target being built. 1100This is useful if the build is otherwise running silently. 1101The message printed is the expanded value of 1102.Va .MAKE.META.PREFIX . 1103.It Cm ignore-cmd 1104Some makefiles have commands which are simply not stable. 1105This keyword causes them to be ignored for 1106determining whether a target is out of date in 1107.Dq meta 1108mode. 1109See also 1110.Ic .NOMETA_CMP . 1111.It Cm silent= Ns Ar bf 1112If 1113.Ar bf 1114is true, when a .meta file is created, mark the target 1115.Ic .SILENT . 1116.It Cm randomize-targets 1117In both compat and parallel mode, do not make the targets in the usual order, 1118but instead randomize their order. 1119This mode can be used to detect undeclared dependencies between files. 1120.El 1121.It Va MAKEOBJDIR 1122Used to create files in a separate directory, see 1123.Va .OBJDIR . 1124.It Va MAKE_OBJDIR_CHECK_WRITABLE 1125Used to force a separate directory for the created files, 1126even if that directory is not writable, see 1127.Va .OBJDIR . 1128.It Va MAKEOBJDIRPREFIX 1129Used to create files in a separate directory, see 1130.Va .OBJDIR . 1131.It Va .MAKE.OS 1132The name of the operating system, see 1133.Xr uname 1 . 1134It is read-only. 1135.It Va .MAKEOVERRIDES 1136This variable is used to record the names of variables assigned to 1137on the command line, so that they may be exported as part of 1138.Sq Ev MAKEFLAGS . 1139This behavior can be disabled by assigning an empty value to 1140.Sq Va .MAKEOVERRIDES 1141within a makefile. 1142Extra variables can be exported from a makefile 1143by appending their names to 1144.Sq Va .MAKEOVERRIDES . 1145.Sq Ev MAKEFLAGS 1146is re-exported whenever 1147.Sq Va .MAKEOVERRIDES 1148is modified. 1149.It Va .MAKE.PATH_FILEMON 1150If 1151.Nm 1152was built with 1153.Xr filemon 4 1154support, this is set to the path of the device node. 1155This allows makefiles to test for this support. 1156.It Va .MAKE.PID 1157The process ID of 1158.Nm . 1159It is read-only. 1160.It Va .MAKE.PPID 1161The parent process ID of 1162.Nm . 1163It is read-only. 1164.It Va MAKE_PRINT_VAR_ON_ERROR 1165When 1166.Nm 1167stops due to an error, it sets 1168.Sq Va .ERROR_TARGET 1169to the name of the target that failed, 1170.Sq Va .ERROR_CMD 1171to the commands of the failed target, 1172and in 1173.Dq meta 1174mode, it also sets 1175.Sq Va .ERROR_CWD 1176to the 1177.Xr getcwd 3 , 1178and 1179.Sq Va .ERROR_META_FILE 1180to the path of the meta file (if any) describing the failed target. 1181It then prints its name and the value of 1182.Sq Va .CURDIR 1183as well as the value of any variables named in 1184.Sq Va MAKE_PRINT_VAR_ON_ERROR . 1185.It Va .MAKE.SAVE_DOLLARS 1186If true, 1187.Ql $$ 1188are preserved when doing 1189.Ql := 1190assignments. 1191The default is true, for compatibility with other makes. 1192If set to false, 1193.Ql $$ 1194becomes 1195.Ql $ 1196per normal evaluation rules. 1197.It Va .MAKE.TARGET_LOCAL_VARIABLES 1198If set to 1199.Ql false , 1200apparent variable assignments in dependency lines are 1201treated as normal sources. 1202.It Va .MAKE.UID 1203The numeric ID of the user running 1204.Nm . 1205It is read-only. 1206.\" 'MAKE_VERSION' is intentionally undocumented 1207.\" since it is only defined in the bmake distribution, 1208.\" but not in NetBSD's native make. 1209.\" '.meta.%d.lcwd' is intentionally undocumented 1210.\" since it is an internal implementation detail. 1211.\" '.meta.%d.ldir' is intentionally undocumented 1212.\" since it is an internal implementation detail. 1213.\" 'MFLAGS' is intentionally undocumented 1214.\" since it is obsolete. 1215.It Va .newline 1216This variable is simply assigned a newline character as its value. 1217It is read-only. 1218This allows expansions using the 1219.Cm \&:@ 1220modifier to put a newline between 1221iterations of the loop rather than a space. 1222For example, in case of an error, 1223.Nm 1224prints the variable names and their values using: 1225.Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@} 1226.It Va .OBJDIR 1227A path to the directory where the targets are built. 1228Its value is determined by trying to 1229.Xr chdir 2 1230to the following directories in order and using the first match: 1231.Bl -enum 1232.It 1233.Cm ${MAKEOBJDIRPREFIX} Ns Cm ${.CURDIR} 1234.Pp 1235(Only if 1236.Sq Ev MAKEOBJDIRPREFIX 1237is set in the environment or on the command line.) 1238.It 1239.Cm ${MAKEOBJDIR} 1240.Pp 1241(Only if 1242.Sq Ev MAKEOBJDIR 1243is set in the environment or on the command line.) 1244.It 1245.Cm ${.CURDIR} Ns Pa /obj. Ns Cm ${MACHINE} 1246.It 1247.Cm ${.CURDIR} Ns Pa /obj 1248.It 1249.Pa /usr/obj/ Ns Cm ${.CURDIR} 1250.It 1251.Cm ${.CURDIR} 1252.El 1253.Pp 1254Variable expansion is performed on the value before it is used, 1255so expressions such as 1256.Cm ${.CURDIR:S,^/usr/src,/var/obj,} 1257may be used. 1258This is especially useful with 1259.Sq Ev MAKEOBJDIR . 1260.Pp 1261.Sq Va .OBJDIR 1262may be modified in the makefile via the special target 1263.Sq Ic .OBJDIR . 1264In all cases, 1265.Nm 1266changes to the specified directory if it exists, and sets 1267.Sq Va .OBJDIR 1268and 1269.Sq Va PWD 1270to that directory before executing any targets. 1271.Pp 1272Except in the case of an explicit 1273.Sq Ic .OBJDIR 1274target, 1275.Nm 1276checks that the specified directory is writable and ignores it if not. 1277This check can be skipped by setting the environment variable 1278.Sq Ev MAKE_OBJDIR_CHECK_WRITABLE 1279to 1280.Dq no . 1281.It Va .PARSEDIR 1282The directory name of the current makefile being parsed. 1283.It Va .PARSEFILE 1284The basename of the current makefile being parsed. 1285This variable and 1286.Sq Va .PARSEDIR 1287are both set only while the makefiles are being parsed. 1288To retain their current values, 1289assign them to a variable using assignment with expansion 1290.Sq Cm \&:= . 1291.It Va .PATH 1292The space-separated list of directories that 1293.Nm 1294searches for files. 1295To update this search list, use the special target 1296.Sq Ic .PATH 1297rather than modifying the variable directly. 1298.It Va %POSIX 1299Is set in POSIX mode, see the special 1300.Ql Va .POSIX 1301target. 1302.\" XXX: There is no make variable named 'PWD', 1303.\" XXX: make only reads and writes the environment variable 'PWD'. 1304.It Va PWD 1305Alternate path to the current directory. 1306.Nm 1307normally sets 1308.Sq Va .CURDIR 1309to the canonical path given by 1310.Xr getcwd 3 . 1311However, if the environment variable 1312.Sq Ev PWD 1313is set and gives a path to the current directory, 1314.Nm 1315sets 1316.Sq Va .CURDIR 1317to the value of 1318.Sq Ev PWD 1319instead. 1320This behavior is disabled if 1321.Sq Ev MAKEOBJDIRPREFIX 1322is set or 1323.Sq Ev MAKEOBJDIR 1324contains a variable transform. 1325.Sq Va PWD 1326is set to the value of 1327.Sq Va .OBJDIR 1328for all programs which 1329.Nm 1330executes. 1331.It Va .SHELL 1332The pathname of the shell used to run target scripts. 1333It is read-only. 1334.It Va .SUFFIXES 1335The list of known suffixes. 1336It is read-only. 1337.It Va .SYSPATH 1338The space-separated list of directories that 1339.Nm 1340searches for makefiles, referred to as the system include path. 1341To update this search list, use the special target 1342.Sq Ic .SYSPATH 1343rather than modifying the variable which is read-only. 1344.It Va .TARGETS 1345The list of targets explicitly specified on the command line, if any. 1346.It Va VPATH 1347The colon-separated 1348.Pq Dq \&: 1349list of directories that 1350.Nm 1351searches for files. 1352This variable is supported for compatibility with old make programs only, use 1353.Sq Va .PATH 1354instead. 1355.El 1356.Ss Variable modifiers 1357The general format of a variable expansion is: 1358.Pp 1359.Sm off 1360.D1 Ic \&${ Ar variable\| Oo Ic \&: Ar modifier\| Oo Ic \&: No ... Oc Oc Ic \&} 1361.Sm on 1362.Pp 1363Each modifier begins with a colon. 1364To escape a colon, precede it with a backslash 1365.Ql \e . 1366.Pp 1367A list of indirect modifiers can be specified via a variable, as follows: 1368.Pp 1369.Bd -literal -offset indent 1370.Ar modifier_variable\^ Li \&= Ar modifier Ns Oo Ic \&: Ns No ... Oc 1371 1372.Sm off 1373.Ic \&${ Ar variable Ic \&:${ Ar modifier_variable Ic \&} Oo Ic \&: No ... Oc Ic \&} 1374.Sm on 1375.Ed 1376.Pp 1377In this case, the first modifier in the 1378.Ar modifier_variable 1379does not start with a colon, 1380since that colon already occurs in the referencing variable. 1381If any of the modifiers in the 1382.Ar modifier_variable 1383contains a dollar sign 1384.Pq Ql $ , 1385these must be doubled to avoid early expansion. 1386.Pp 1387Some modifiers interpret the expression value as a single string, 1388others treat the expression value as a whitespace-separated list of words. 1389When splitting a string into words, 1390whitespace can be escaped using double quotes, single quotes and backslashes, 1391like in the shell. 1392The quotes and backslashes are retained in the words. 1393.Pp 1394The supported modifiers are: 1395.Bl -tag -width EEE 1396.It Cm \&:E 1397Replaces each word with its suffix. 1398.It Cm \&:H 1399Replaces each word with its dirname. 1400.It Cm \&:M\| Ns Ar pattern 1401Selects only those words that match 1402.Ar pattern . 1403The standard shell wildcard characters 1404.Pf ( Ql * , 1405.Ql \&? , 1406and 1407.Ql \&[] ) 1408may 1409be used. 1410The wildcard characters may be escaped with a backslash 1411.Pq Ql \e . 1412As a consequence of the way values are split into words, matched, 1413and then joined, the construct 1414.Ql ${VAR:M*} 1415removes all leading and trailing whitespace 1416and normalizes the inter-word spacing to a single space. 1417.It Cm \&:N\| Ns Ar pattern 1418This is the opposite of 1419.Sq Cm \&:M , 1420selecting all words which do 1421.Em not 1422match 1423.Ar pattern . 1424.It Cm \&:O 1425Orders the words lexicographically. 1426.It Cm \&:On 1427Orders the words numerically. 1428A number followed by one of 1429.Ql k , 1430.Ql M 1431or 1432.Ql G 1433is multiplied by the appropriate factor, which is 1024 for 1434.Ql k , 14351048576 for 1436.Ql M , 1437or 1073741824 for 1438.Ql G . 1439Both upper- and lower-case letters are accepted. 1440.It Cm \&:Or 1441Orders the words in reverse lexicographical order. 1442.It Cm \&:Orn 1443Orders the words in reverse numerical order. 1444.It Cm \&:Ox 1445Shuffles the words. 1446The results are different each time you are referring to the 1447modified variable; use the assignment with expansion 1448.Sq Cm \&:= 1449to prevent such behavior. 1450For example, 1451.Bd -literal -offset indent 1452LIST= uno due tre quattro 1453RANDOM_LIST= ${LIST:Ox} 1454STATIC_RANDOM_LIST:= ${LIST:Ox} 1455 1456all: 1457 @echo "${RANDOM_LIST}" 1458 @echo "${RANDOM_LIST}" 1459 @echo "${STATIC_RANDOM_LIST}" 1460 @echo "${STATIC_RANDOM_LIST}" 1461.Ed 1462may produce output similar to: 1463.Bd -literal -offset indent 1464quattro due tre uno 1465tre due quattro uno 1466due uno quattro tre 1467due uno quattro tre 1468.Ed 1469.It Cm \&:Q 1470Quotes every shell meta-character in the value, so that it can be passed 1471safely to the shell. 1472.It Cm \&:q 1473Quotes every shell meta-character in the value, and also doubles 1474.Sq $ 1475characters so that it can be passed 1476safely through recursive invocations of 1477.Nm . 1478This is equivalent to 1479.Sq Cm \&:S/\e\&$/&&/g:Q . 1480.It Cm \&:R 1481Replaces each word with everything but its suffix. 1482.It Cm \&:range Ns Oo Cm = Ns Ar count Oc 1483The value is an integer sequence representing the words of the original 1484value, or the supplied 1485.Ar count . 1486.It Cm \&:gmtime Ns Oo Cm = Ns Ar timestamp Oc 1487The value is interpreted as a format string for 1488.Xr strftime 3 , 1489using 1490.Xr gmtime 3 , 1491producing the formatted timestamp. 1492If a 1493.Ar timestamp 1494value is not provided or is 0, the current time is used. 1495.It Cm \&:hash 1496Computes a 32-bit hash of the value and encodes it as 8 hex digits. 1497.It Cm \&:localtime Ns Oo Cm = Ns Ar timestamp Oc 1498The value is interpreted as a format string for 1499.Xr strftime 3 , 1500using 1501.Xr localtime 3 , 1502producing the formatted timestamp. 1503If a 1504.Ar timestamp 1505value is not provided or is 0, the current time is used. 1506.It Cm \&:tA 1507Attempts to convert the value to an absolute path using 1508.Xr realpath 3 . 1509If that fails, the value is unchanged. 1510.It Cm \&:tl 1511Converts the value to lower-case letters. 1512.It Cm \&:ts Ns Ar c 1513When joining the words after a modifier that treats the value as words, 1514the words are normally separated by a space. 1515This modifier changes the separator to the character 1516.Ar c . 1517If 1518.Ar c 1519is omitted, no separator is used. 1520The common escapes (including octal numeric codes) work as expected. 1521.It Cm \&:tu 1522Converts the value to upper-case letters. 1523.It Cm \&:tW 1524Causes subsequent modifiers to treat the value as a single word 1525(possibly containing embedded whitespace). 1526See also 1527.Sq Cm \&:[*] . 1528.It Cm \&:tw 1529Causes the value to be treated as a list of words. 1530See also 1531.Sq Cm \&:[@] . 1532.Sm off 1533.It Cm \&:S\| No \&/ Ar old_string\| No \&/ Ar new_string\| No \&/ Op Cm 1gW 1534.Sm on 1535Modifies the first occurrence of 1536.Ar old_string 1537in each word of the value, replacing it with 1538.Ar new_string . 1539If a 1540.Ql g 1541is appended to the last delimiter of the pattern, 1542all occurrences in each word are replaced. 1543If a 1544.Ql 1 1545is appended to the last delimiter of the pattern, 1546only the first occurrence is affected. 1547If a 1548.Ql W 1549is appended to the last delimiter of the pattern, 1550the value is treated as a single word. 1551If 1552.Ar old_string 1553begins with a caret 1554.Pq Ql ^ , 1555.Ar old_string 1556is anchored at the beginning of each word. 1557If 1558.Ar old_string 1559ends with a dollar sign 1560.Pq Ql \&$ , 1561it is anchored at the end of each word. 1562Inside 1563.Ar new_string , 1564an ampersand 1565.Pq Ql & 1566is replaced by 1567.Ar old_string 1568(without the anchoring 1569.Ql ^ 1570or 1571.Ql \&$ ) . 1572Any character may be used as the delimiter for the parts of the modifier 1573string. 1574The anchoring, ampersand and delimiter characters can be escaped with a 1575backslash 1576.Pq Ql \e . 1577.Pp 1578Both 1579.Ar old_string 1580and 1581.Ar new_string 1582may contain nested expressions. 1583To prevent a dollar sign from starting a nested expression, 1584escape it with a backslash. 1585.Sm off 1586.It Cm \&:C\| No \&/ Ar pattern\| No \&/ Ar replacement\| No \&/ Op Cm 1gW 1587.Sm on 1588The 1589.Cm \&:C 1590modifier works like the 1591.Cm \&:S 1592modifier except that the old and new strings, instead of being 1593simple strings, are an extended regular expression 1594.Ar pattern 1595(see 1596.Xr regex 3 ) 1597and an 1598.Xr ed 1 Ns \-style 1599.Ar replacement . 1600Normally, the first occurrence of the pattern 1601.Ar pattern 1602in each word of the value is substituted with 1603.Ar replacement . 1604The 1605.Ql 1 1606modifier causes the substitution to apply to at most one word; the 1607.Ql g 1608modifier causes the substitution to apply to as many instances of the 1609search pattern 1610.Ar pattern 1611as occur in the word or words it is found in; the 1612.Ql W 1613modifier causes the value to be treated as a single word 1614(possibly containing embedded whitespace). 1615.Pp 1616As for the 1617.Cm \&:S 1618modifier, the 1619.Ar pattern 1620and 1621.Ar replacement 1622are subjected to variable expansion before being parsed as 1623regular expressions. 1624.It Cm \&:T 1625Replaces each word with its last path component (basename). 1626.It Cm \&:u 1627Removes adjacent duplicate words (like 1628.Xr uniq 1 ) . 1629.Sm off 1630.It Cm \&:\&?\| Ar true_string\| Cm \&: Ar false_string 1631.Sm on 1632If the variable name (not its value), when parsed as a 1633.Cm .if 1634conditional expression, evaluates to true, return as its value the 1635.Ar true_string , 1636otherwise return the 1637.Ar false_string . 1638Since the variable name is used as the expression, 1639\&:\&? must be the first modifier after the variable name 1640.No itself Ns \^\(em\^ Ns 1641which, of course, usually contains variable expansions. 1642A common error is trying to use expressions like 1643.Dl ${NUMBERS:M42:?match:no} 1644which actually tests defined(NUMBERS). 1645To determine if any words match 1646.Dq 42 , 1647you need to use something like: 1648.Dl ${"${NUMBERS:M42}" != \&"\&":?match:no} . 1649.It Cm :\| Ns Ar old_string\| Ns Cm = Ns Ar new_string 1650This is the 1651.At V 1652style substitution. 1653It can only be the last modifier specified, 1654as a 1655.Ql \&: 1656in either 1657.Ar old_string 1658or 1659.Ar new_string 1660is treated as a regular character, not as the end of the modifier. 1661.Pp 1662If 1663.Ar old_string 1664does not contain the pattern matching character 1665.Ql % , 1666and the word ends with 1667.Ar old_string 1668or equals it, 1669that suffix is replaced with 1670.Ar new_string . 1671.Pp 1672Otherwise, the first 1673.Ql % 1674in 1675.Ar old_string 1676matches a possibly empty substring of arbitrary characters, 1677and if the whole pattern is found in the word, 1678the matching part is replaced with 1679.Ar new_string , 1680and the first occurrence of 1681.Ql % 1682in 1683.Ar new_string 1684(if any) is replaced with the substring matched by the 1685.Ql % . 1686.Pp 1687Both 1688.Ar old_string 1689and 1690.Ar new_string 1691may contain nested expressions. 1692To prevent a dollar sign from starting a nested expression, 1693escape it with a backslash. 1694.Sm off 1695.It Cm \&:@ Ar varname\| Cm @ Ar string\| Cm @ 1696.Sm on 1697This is the loop expansion mechanism from the OSF Development 1698Environment (ODE) make. 1699Unlike 1700.Cm \&.for 1701loops, expansion occurs at the time of reference. 1702For each word in the value, assign the word to the variable named 1703.Ar varname 1704and evaluate 1705.Ar string . 1706The ODE convention is that 1707.Ar varname 1708should start and end with a period, for example: 1709.Dl ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@} 1710.Pp 1711However, a single-letter variable is often more readable: 1712.Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@} 1713.It Cm \&:_ Ns Oo Cm = Ns Ar var Oc 1714Saves the current variable value in 1715.Ql $_ 1716or the named 1717.Ar var 1718for later reference. 1719Example usage: 1720.Bd -literal -offset indent 1721M_cmpv.units = 1 1000 1000000 1722M_cmpv = S,., ,g:_:range:@i@+ $${_:[-$$i]} \&\\ 1723\\* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh 1724 1725.Dv .if ${VERSION:${M_cmpv}} < ${3.1.12:L:${M_cmpv}} 1726 1727.Ed 1728Here 1729.Ql $_ 1730is used to save the result of the 1731.Ql :S 1732modifier which is later referenced using the index values from 1733.Ql :range . 1734.It Cm \&:U\| Ns Ar newval 1735If the variable is undefined, 1736.Ar newval 1737is the value. 1738If the variable is defined, the existing value is returned. 1739This is another ODE make feature. 1740It is handy for setting per-target CFLAGS for instance: 1741.Dl ${_${.TARGET:T}_CFLAGS:U${DEF_CFLAGS}} 1742If a value is only required if the variable is undefined, use: 1743.Dl ${VAR:D:Unewval} 1744.It Cm \&:D\| Ns Ar newval 1745If the variable is defined, 1746.Ar newval 1747is the value. 1748.It Cm \&:L 1749The name of the variable is the value. 1750.It Cm \&:P 1751The path of the node which has the same name as the variable is the value. 1752If no such node exists or its path is null, the name of the variable is used. 1753In order for this modifier to work, the name (node) must at least have 1754appeared on the right-hand side of a dependency. 1755.Sm off 1756.It Cm \&:\&! Ar cmd\| Cm \&! 1757.Sm on 1758The output of running 1759.Ar cmd 1760is the value. 1761.It Cm \&:sh 1762The value is run as a command, and the output becomes the new value. 1763.It Cm \&::= Ns Ar str 1764The variable is assigned the value 1765.Ar str 1766after substitution. 1767This modifier and its variations are useful in obscure situations 1768such as wanting to set a variable 1769at a point where a target's shell commands are being parsed. 1770These assignment modifiers always expand to nothing. 1771.Pp 1772The 1773.Sq Cm \&:: 1774helps avoid false matches with the 1775.At V 1776style 1777.Ql \&:= 1778modifier and since substitution always occurs, the 1779.Ql \&::= 1780form is vaguely appropriate. 1781.It Cm \&::?= Ns Ar str 1782As for 1783.Cm \&::= 1784but only if the variable does not already have a value. 1785.It Cm \&::+= Ns Ar str 1786Append 1787.Ar str 1788to the variable. 1789.It Cm \&::!= Ns Ar cmd 1790Assign the output of 1791.Ar cmd 1792to the variable. 1793.It Cm \&:\&[ Ns Ar range Ns Cm \&] 1794Selects one or more words from the value, 1795or performs other operations related to the way in which the 1796value is split into words. 1797.Pp 1798An empty value, or a value that consists entirely of white-space, 1799is treated as a single word. 1800For the purposes of the 1801.Sq Cm \&:[] 1802modifier, the words are indexed both forwards using positive integers 1803(where index 1 represents the first word), 1804and backwards using negative integers 1805(where index \-1 represents the last word). 1806.Pp 1807The 1808.Ar range 1809is subjected to variable expansion, and the expanded result is 1810then interpreted as follows: 1811.Bl -tag -width index 1812.\" :[n] 1813.It Ar index 1814Selects a single word from the value. 1815.\" :[start..end] 1816.It Ar start Ns Cm \&.. Ns Ar end 1817Selects all words from 1818.Ar start 1819to 1820.Ar end , 1821inclusive. 1822For example, 1823.Sq Cm \&:[2..-1] 1824selects all words from the second word to the last word. 1825If 1826.Ar start 1827is greater than 1828.Ar end , 1829the words are output in reverse order. 1830For example, 1831.Sq Cm \&:[-1..1] 1832selects all the words from last to first. 1833If the list is already ordered, 1834this effectively reverses the list, 1835but it is more efficient to use 1836.Sq Cm \&:Or 1837instead of 1838.Sq Cm \&:O:[-1..1] . 1839.\" :[*] 1840.It Cm \&* 1841Causes subsequent modifiers to treat the value as a single word 1842(possibly containing embedded whitespace). 1843Analogous to the effect of 1844.Li \&$* 1845in Bourne shell. 1846.\" :[0] 1847.It 0 1848Means the same as 1849.Sq Cm \&:[*] . 1850.\" :[*] 1851.It Cm \&@ 1852Causes subsequent modifiers to treat the value as a sequence of words 1853delimited by whitespace. 1854Analogous to the effect of 1855.Li \&$@ 1856in Bourne shell. 1857.\" :[#] 1858.It Cm \&# 1859Returns the number of words in the value. 1860.El \" :[range] 1861.El 1862.Sh DIRECTIVES 1863.Nm 1864offers directives for including makefiles, conditionals and for loops. 1865All these directives are identified by a line beginning with a single dot 1866.Pq Ql \&. 1867character, followed by the keyword of the directive, such as 1868.Cm include 1869or 1870.Cm if . 1871.Ss File inclusion 1872Files are included with either 1873.Cm \&.include \&< Ns Ar file Ns Cm \&> 1874or 1875.Cm \&.include \&\*q Ns Ar file Ns Cm \&\*q . 1876Variables between the angle brackets or double quotes are expanded 1877to form the file name. 1878If angle brackets are used, the included makefile is expected to be in 1879the system makefile directory. 1880If double quotes are used, the including makefile's directory and any 1881directories specified using the 1882.Fl I 1883option are searched before the system makefile directory. 1884.Pp 1885For compatibility with other make variants, 1886.Sq Cm include Ar file No ... 1887(without leading dot) 1888is also accepted. 1889.Pp 1890If the include statement is written as 1891.Cm .-include 1892or as 1893.Cm .sinclude , 1894errors locating and/or opening include files are ignored. 1895.Pp 1896If the include statement is written as 1897.Cm .dinclude , 1898not only are errors locating and/or opening include files ignored, 1899but stale dependencies within the included file are ignored just like in 1900.Va .MAKE.DEPENDFILE . 1901.Ss Exporting variables 1902The directives for exporting and unexporting variables are: 1903.Bl -tag -width Ds 1904.It Ic .export Ar variable No ... 1905Export the specified global variable. 1906If no variable list is provided, all globals are exported 1907except for internal variables (those that start with 1908.Ql \&. ) . 1909This is not affected by the 1910.Fl X 1911flag, so should be used with caution. 1912For compatibility with other make programs, 1913.Cm export Ar variable\| Ns Cm \&= Ns Ar value 1914(without leading dot) is also accepted. 1915.Pp 1916Appending a variable name to 1917.Va .MAKE.EXPORTED 1918is equivalent to exporting a variable. 1919.It Ic .export-env Ar variable No ... 1920The same as 1921.Ql .export , 1922except that the variable is not appended to 1923.Va .MAKE.EXPORTED . 1924This allows exporting a value to the environment which is different from that 1925used by 1926.Nm 1927internally. 1928.It Ic .export-literal Ar variable No ... 1929The same as 1930.Ql .export-env , 1931except that variables in the value are not expanded. 1932.It Ic .unexport Ar variable No ... 1933The opposite of 1934.Ql .export . 1935The specified global 1936.Ar variable 1937is removed from 1938.Va .MAKE.EXPORTED . 1939If no variable list is provided, all globals are unexported, 1940and 1941.Va .MAKE.EXPORTED 1942deleted. 1943.It Ic .unexport-env 1944Unexport all globals previously exported and 1945clear the environment inherited from the parent. 1946This operation causes a memory leak of the original environment, 1947so should be used sparingly. 1948Testing for 1949.Va .MAKE.LEVEL 1950being 0 would make sense. 1951Also note that any variables which originated in the parent environment 1952should be explicitly preserved if desired. 1953For example: 1954.Bd -literal -offset indent 1955.Li .if ${.MAKE.LEVEL} == 0 1956PATH := ${PATH} 1957.Li .unexport-env 1958.Li .export PATH 1959.Li .endif 1960.Pp 1961.Ed 1962Would result in an environment containing only 1963.Sq Ev PATH , 1964which is the minimal useful environment. 1965.\" TODO: Check the below sentence, environment variables don't start with '.'. 1966Actually 1967.Sq Va .MAKE.LEVEL 1968is also pushed into the new environment. 1969.El 1970.Ss Messages 1971The directives for printing messages to the output are: 1972.Bl -tag -width Ds 1973.It Ic .info Ar message 1974The message is printed along with the name of the makefile and line number. 1975.It Ic .warning Ar message 1976The message prefixed by 1977.Sq Li warning: 1978is printed along with the name of the makefile and line number. 1979.It Ic .error Ar message 1980The message is printed along with the name of the makefile and line number, 1981.Nm 1982exits immediately. 1983.El 1984.Ss Conditionals 1985The directives for conditionals are: 1986.ds maybenot Oo Ic \&! Oc Ns 1987.Bl -tag 1988.It Ic .if \*[maybenot] Ar expression Op Ar operator expression No ... 1989Test the value of an expression. 1990.It Ic .ifdef \*[maybenot] Ar variable Op Ar operator variable No ... 1991Test whether a variable is defined. 1992.It Ic .ifndef \*[maybenot] Ar variable Op Ar operator variable No ... 1993Test whether a variable is not defined. 1994.It Ic .ifmake \*[maybenot] Ar target Op Ar operator target No ... 1995Test the target being requested. 1996.It Ic .ifnmake \*[maybenot] Ar target Op Ar operator target No ... 1997Test the target being requested. 1998.It Ic .else 1999Reverse the sense of the last conditional. 2000.It Ic .elif \*[maybenot] Ar expression Op Ar operator expression No ... 2001A combination of 2002.Sq Ic .else 2003followed by 2004.Sq Ic .if . 2005.It Ic .elifdef \*[maybenot] Ar variable Op Ar operator variable No ... 2006A combination of 2007.Sq Ic .else 2008followed by 2009.Sq Ic .ifdef . 2010.It Ic .elifndef \*[maybenot] Ar variable Op Ar operator variable No ... 2011A combination of 2012.Sq Ic .else 2013followed by 2014.Sq Ic .ifndef . 2015.It Ic .elifmake \*[maybenot] Ar target Op Ar operator target No ... 2016A combination of 2017.Sq Ic .else 2018followed by 2019.Sq Ic .ifmake . 2020.It Ic .elifnmake \*[maybenot] Ar target Op Ar operator target No ... 2021A combination of 2022.Sq Ic .else 2023followed by 2024.Sq Ic .ifnmake . 2025.It Ic .endif 2026End the body of the conditional. 2027.El 2028.Pp 2029The 2030.Ar operator 2031may be any one of the following: 2032.Bl -tag 2033.It Ic \&|\&| 2034Logical OR. 2035.It Ic \&&& 2036Logical AND; of higher precedence than 2037.Sq Ic \&|\&| . 2038.El 2039.Pp 2040.Nm 2041only evaluates a conditional as far as is necessary to determine its value. 2042Parentheses can be used to override the operator precedence. 2043The boolean operator 2044.Sq Ic \&! 2045may be used to logically negate an entire conditional. 2046It is of higher precedence than 2047.Sq Ic \&&& . 2048.Pp 2049The value of 2050.Ar expression 2051may be any of the following function call expressions: 2052.Bl -tag 2053.Sm off 2054.It Ic defined Li \&( Ar varname Li \&) 2055.Sm on 2056Evaluates to true if the variable 2057.Ar varname 2058has been defined. 2059.Sm off 2060.It Ic make Li \&( Ar target Li \&) 2061.Sm on 2062Evaluates to true if the target was specified as part of 2063.Nm Ns 's 2064command line or was declared the default target (either implicitly or 2065explicitly, see 2066.Va .MAIN ) 2067before the line containing the conditional. 2068.Sm off 2069.It Ic empty Li \&( Ar varname Oo Li : Ar modifiers Oc Li \&) 2070.Sm on 2071Evaluates to true if the expansion of the variable, 2072after applying the modifiers, results in an empty string. 2073.Sm off 2074.It Ic exists Li \&( Ar pathname Li \&) 2075.Sm on 2076Evaluates to true if the given pathname exists. 2077If relative, the pathname is searched for on the system search path (see 2078.Va .PATH ) . 2079.Sm off 2080.It Ic target Li \&( Ar target Li \&) 2081.Sm on 2082Evaluates to true if the target has been defined. 2083.Sm off 2084.It Ic commands Li \&( Ar target Li \&) 2085.Sm on 2086Evaluates to true if the target has been defined 2087and has commands associated with it. 2088.El 2089.Pp 2090.Ar Expression 2091may also be an arithmetic or string comparison. 2092Variable expansion is performed on both sides of the comparison. 2093If both sides are numeric and neither is enclosed in quotes, 2094the comparison is done numerically, otherwise lexicographically. 2095A string is interpreted as hexadecimal integer if it is preceded by 2096.Li 0x , 2097otherwise it is a decimal floating-point number; 2098octal numbers are not supported. 2099.Pp 2100All comparisons may use the operators 2101.Sq Ic \&== 2102and 2103.Sq Ic \&!= . 2104Numeric comparisons may also use the operators 2105.Sq Ic \&< , 2106.Sq Ic \&<= , 2107.Sq Ic \&> 2108and 2109.Sq Ic \&>= . 2110.Pp 2111If the comparison has neither a comparison operator nor a right side, 2112the expression evaluates to true if it is nonempty 2113and its numeric value (if any) is not zero. 2114.Pp 2115When 2116.Nm 2117is evaluating one of these conditional expressions, and it encounters 2118a (whitespace separated) word it doesn't recognize, either the 2119.Dq make 2120or 2121.Dq defined 2122function is applied to it, depending on the form of the conditional. 2123If the form is 2124.Sq Ic .ifdef , 2125.Sq Ic .ifndef 2126or 2127.Sq Ic .if , 2128the 2129.Dq defined 2130function is applied. 2131Similarly, if the form is 2132.Sq Ic .ifmake 2133or 2134.Sq Ic .ifnmake , 2135the 2136.Dq make 2137function is applied. 2138.Pp 2139If the conditional evaluates to true, 2140parsing of the makefile continues as before. 2141If it evaluates to false, the following lines are skipped. 2142In both cases, this continues until the corresponding 2143.Sq Ic .else 2144or 2145.Sq Ic .endif 2146is found. 2147.Ss For loops 2148For loops are typically used to apply a set of rules to a list of files. 2149The syntax of a for loop is: 2150.Pp 2151.Bl -tag -compact -width Ds 2152.It Ic \&.for Ar variable Oo Ar variable No ... Oc Ic in Ar expression 2153.It Aq Ar make-lines 2154.It Ic \&.endfor 2155.El 2156.Pp 2157The 2158.Ar expression 2159is expanded and then split into words. 2160On each iteration of the loop, one word is taken and assigned to each 2161.Ar variable , 2162in order, and these 2163.Ar variables 2164are substituted into the 2165.Ar make-lines 2166inside the body of the for loop. 2167The number of words must come out even; that is, if there are three 2168iteration variables, the number of words provided must be a multiple 2169of three. 2170.Pp 2171If 2172.Sq Ic .break 2173is encountered within a 2174.Cm \&.for 2175loop, it causes early termination of the loop, otherwise a parse error. 2176.\" TODO: Describe limitations with defined/empty. 2177.Ss Other directives 2178.Bl -tag -width Ds 2179.It Ic .undef Ar variable No ... 2180Un-define the specified global variables. 2181Only global variables can be un-defined. 2182.El 2183.Sh COMMENTS 2184Comments begin with a hash 2185.Pq Ql \&# 2186character, anywhere but in a shell 2187command line, and continue to the end of an unescaped new line. 2188.Sh SPECIAL SOURCES (ATTRIBUTES) 2189.Bl -tag -width .IGNOREx 2190.It Ic .EXEC 2191Target is never out of date, but always execute commands anyway. 2192.It Ic .IGNORE 2193Ignore any errors from the commands associated with this target, exactly 2194as if they all were preceded by a dash 2195.Pq Ql \- . 2196.\" .It Ic .INVISIBLE 2197.\" XXX 2198.\" .It Ic .JOIN 2199.\" XXX 2200.It Ic .MADE 2201Mark all sources of this target as being up to date. 2202.It Ic .MAKE 2203Execute the commands associated with this target even if the 2204.Fl n 2205or 2206.Fl t 2207options were specified. 2208Normally used to mark recursive 2209.Nm Ns s . 2210.It Ic .META 2211Create a meta file for the target, even if it is flagged as 2212.Ic .PHONY , 2213.Ic .MAKE , 2214or 2215.Ic .SPECIAL . 2216Usage in conjunction with 2217.Ic .MAKE 2218is the most likely case. 2219In 2220.Dq meta 2221mode, the target is out-of-date if the meta file is missing. 2222.It Ic .NOMETA 2223Do not create a meta file for the target. 2224Meta files are also not created for 2225.Ic .PHONY , 2226.Ic .MAKE , 2227or 2228.Ic .SPECIAL 2229targets. 2230.It Ic .NOMETA_CMP 2231Ignore differences in commands when deciding if target is out of date. 2232This is useful if the command contains a value which always changes. 2233If the number of commands change, though, 2234the target is still considered out of date. 2235The same effect applies to any command line that uses the variable 2236.Va .OODATE , 2237which can be used for that purpose even when not otherwise needed or desired: 2238.Bd -literal -offset indent 2239 2240skip-compare-for-some: 2241 @echo this is compared 2242 @echo this is not ${.OODATE:M.NOMETA_CMP} 2243 @echo this is also compared 2244 2245.Ed 2246The 2247.Cm \&:M 2248pattern suppresses any expansion of the unwanted variable. 2249.It Ic .NOPATH 2250Do not search for the target in the directories specified by 2251.Va .PATH . 2252.It Ic .NOTMAIN 2253Normally 2254.Nm 2255selects the first target it encounters as the default target to be built 2256if no target was specified. 2257This source prevents this target from being selected. 2258.It Ic .OPTIONAL 2259If a target is marked with this attribute and 2260.Nm 2261can't figure out how to create it, it ignores this fact and assumes 2262the file isn't needed or already exists. 2263.It Ic .PHONY 2264The target does not correspond to an actual file; 2265it is always considered to be out of date, 2266and is not created with the 2267.Fl t 2268option. 2269Suffix-transformation rules are not applied to 2270.Ic .PHONY 2271targets. 2272.It Ic .PRECIOUS 2273When 2274.Nm 2275is interrupted, it normally removes any partially made targets. 2276This source prevents the target from being removed. 2277.It Ic .RECURSIVE 2278Synonym for 2279.Ic .MAKE . 2280.It Ic .SILENT 2281Do not echo any of the commands associated with this target, exactly 2282as if they all were preceded by an at sign 2283.Pq Ql @ . 2284.It Ic .USE 2285Turn the target into 2286.Nm Ns 's 2287version of a macro. 2288When the target is used as a source for another target, the other target 2289acquires the commands, sources, and attributes (except for 2290.Ic .USE ) 2291of the 2292source. 2293If the target already has commands, the 2294.Ic .USE 2295target's commands are appended 2296to them. 2297.It Ic .USEBEFORE 2298Like 2299.Ic .USE , 2300but instead of appending, prepend the 2301.Ic .USEBEFORE 2302target commands to the target. 2303.It Ic .WAIT 2304If 2305.Ic .WAIT 2306appears in a dependency line, the sources that precede it are 2307made before the sources that succeed it in the line. 2308Since the dependents of files are not made until the file itself 2309could be made, this also stops the dependents being built unless they 2310are needed for another branch of the dependency tree. 2311So given: 2312.Bd -literal 2313x: a .WAIT b 2314 echo x 2315a: 2316 echo a 2317b: b1 2318 echo b 2319b1: 2320 echo b1 2321 2322.Ed 2323the output is always 2324.Ql a , 2325.Ql b1 , 2326.Ql b , 2327.Ql x . 2328.Pp 2329The ordering imposed by 2330.Ic .WAIT 2331is only relevant for parallel makes. 2332.El 2333.Sh SPECIAL TARGETS 2334Special targets may not be included with other targets, i.e. they must be 2335the only target specified. 2336.Bl -tag -width .BEGINx 2337.It Ic .BEGIN 2338Any command lines attached to this target are executed before anything 2339else is done. 2340.It Ic .DEFAULT 2341This is sort of a 2342.Ic .USE 2343rule for any target (that was used only as a source) that 2344.Nm 2345can't figure out any other way to create. 2346Only the shell script is used. 2347The 2348.Va .IMPSRC 2349variable of a target that inherits 2350.Ic .DEFAULT Ns 's 2351commands is set to the target's own name. 2352.It Ic .DELETE_ON_ERROR 2353If this target is present in the makefile, it globally causes make to 2354delete targets whose commands fail. 2355(By default, only targets whose commands are interrupted during 2356execution are deleted. 2357This is the historical behavior.) 2358This setting can be used to help prevent half-finished or malformed 2359targets from being left around and corrupting future rebuilds. 2360.It Ic .END 2361Any command lines attached to this target are executed after everything 2362else is done successfully. 2363.It Ic .ERROR 2364Any command lines attached to this target are executed when another target fails. 2365The 2366.Va .ERROR_TARGET 2367variable is set to the target that failed. 2368See also 2369.Va MAKE_PRINT_VAR_ON_ERROR . 2370.It Ic .IGNORE 2371Mark each of the sources with the 2372.Ic .IGNORE 2373attribute. 2374If no sources are specified, this is the equivalent of specifying the 2375.Fl i 2376option. 2377.It Ic .INTERRUPT 2378If 2379.Nm 2380is interrupted, the commands for this target are executed. 2381.It Ic .MAIN 2382If no target is specified when 2383.Nm 2384is invoked, this target is built. 2385.It Ic .MAKEFLAGS 2386This target provides a way to specify flags for 2387.Nm 2388at the time when the makefiles are read. 2389The flags are as if typed to the shell, though the 2390.Fl f 2391option has 2392no effect. 2393.\" XXX: NOT YET!!!! 2394.\" .It Ic .NOTPARALLEL 2395.\" The named targets are executed in non parallel mode. 2396.\" If no targets are 2397.\" specified, all targets are executed in non parallel mode. 2398.It Ic .NOPATH 2399Apply the 2400.Ic .NOPATH 2401attribute to any specified sources. 2402.It Ic .NOTPARALLEL 2403Disable parallel mode. 2404.It Ic .NO_PARALLEL 2405Synonym for 2406.Ic .NOTPARALLEL , 2407for compatibility with other pmake variants. 2408.It Ic .NOREADONLY 2409clear the read-only attribute from the global variables specified as sources. 2410.It Ic .OBJDIR 2411The source is a new value for 2412.Sq Va .OBJDIR . 2413If it exists, 2414.Nm 2415changes the current working directory to it and updates the value of 2416.Sq Va .OBJDIR . 2417.It Ic .ORDER 2418In parallel mode, the named targets are made in sequence. 2419This ordering does not add targets to the list of targets to be made. 2420.Pp 2421Since the dependents of a target do not get built until the target itself 2422could be built, unless 2423.Ql a 2424is built by another part of the dependency graph, 2425the following is a dependency loop: 2426.Bd -literal 2427\&.ORDER: b a 2428b: a 2429.Ed 2430.Pp 2431.\" XXX: NOT YET!!!! 2432.\" .It Ic .PARALLEL 2433.\" The named targets are executed in parallel mode. 2434.\" If no targets are 2435.\" specified, all targets are executed in parallel mode. 2436.It Ic .PATH 2437The sources are directories which are to be searched for files not 2438found in the current directory. 2439If no sources are specified, 2440any previously specified directories are removed from the search path. 2441If the source is the special 2442.Ic .DOTLAST 2443target, the current working directory is searched last. 2444.It Ic .PATH. Ns Ar suffix 2445Like 2446.Ic .PATH 2447but applies only to files with a particular suffix. 2448The suffix must have been previously declared with 2449.Ic .SUFFIXES . 2450.It Ic .PHONY 2451Apply the 2452.Ic .PHONY 2453attribute to any specified sources. 2454.It Ic .POSIX 2455If this is the first non-comment line in the main makefile, 2456the variable 2457.Va %POSIX 2458is set to the value 2459.Ql 1003.2 2460and the makefile 2461.Ql <posix.mk> 2462is included if it exists, 2463to provide POSIX-compatible default rules. 2464If 2465.Nm 2466is run with the 2467.Fl r 2468flag, only 2469.Ql posix.mk 2470contributes to the default rules. 2471.It Ic .PRECIOUS 2472Apply the 2473.Ic .PRECIOUS 2474attribute to any specified sources. 2475If no sources are specified, the 2476.Ic .PRECIOUS 2477attribute is applied to every target in the file. 2478.It Ic .READONLY 2479set the read-only attribute on the global variables specified as sources. 2480.It Ic .SHELL 2481Sets the shell that 2482.Nm 2483uses to execute commands in jobs mode. 2484The sources are a set of 2485.Ar field\| Ns Cm \&= Ns Ar value 2486pairs. 2487.Bl -tag -width ".Li hasErrCtls" 2488.It Li name 2489This is the minimal specification, used to select one of the built-in 2490shell specs; 2491.Li sh , 2492.Li ksh , 2493and 2494.Li csh . 2495.It Li path 2496Specifies the absolute path to the shell. 2497.It Li hasErrCtl 2498Indicates whether the shell supports exit on error. 2499.It Li check 2500The command to turn on error checking. 2501.It Li ignore 2502The command to disable error checking. 2503.It Li echo 2504The command to turn on echoing of commands executed. 2505.It Li quiet 2506The command to turn off echoing of commands executed. 2507.It Li filter 2508The output to filter after issuing the 2509.Li quiet 2510command. 2511It is typically identical to 2512.Li quiet . 2513.It Li errFlag 2514The flag to pass the shell to enable error checking. 2515.It Li echoFlag 2516The flag to pass the shell to enable command echoing. 2517.It Li newline 2518The string literal to pass the shell that results in a single newline 2519character when used outside of any quoting characters. 2520.El 2521Example: 2522.Bd -literal 2523\&.SHELL: name=ksh path=/bin/ksh hasErrCtl=true \e 2524 check="set \-e" ignore="set +e" \e 2525 echo="set \-v" quiet="set +v" filter="set +v" \e 2526 echoFlag=v errFlag=e newline="'\en'" 2527.Ed 2528.It Ic .SILENT 2529Apply the 2530.Ic .SILENT 2531attribute to any specified sources. 2532If no sources are specified, the 2533.Ic .SILENT 2534attribute is applied to every 2535command in the file. 2536.It Ic .STALE 2537This target gets run when a dependency file contains stale entries, having 2538.Va .ALLSRC 2539set to the name of that dependency file. 2540.It Ic .SUFFIXES 2541Each source specifies a suffix to 2542.Nm . 2543If no sources are specified, any previously specified suffixes are deleted. 2544It allows the creation of suffix-transformation rules. 2545.Pp 2546Example: 2547.Bd -literal 2548\&.SUFFIXES: .c .o 2549\&.c.o: 2550 cc \-o ${.TARGET} \-c ${.IMPSRC} 2551.Ed 2552.It Ic .SYSPATH 2553The sources are directories which are to be added to the system 2554include path which 2555.Nm 2556searches for makefiles. 2557If no sources are specified, 2558any previously specified directories are removed from the system 2559include path. 2560.El 2561.Sh ENVIRONMENT 2562.Nm 2563uses the following environment variables, if they exist: 2564.Ev MACHINE , 2565.Ev MACHINE_ARCH , 2566.Ev MAKE , 2567.Ev MAKEFLAGS , 2568.Ev MAKEOBJDIR , 2569.Ev MAKEOBJDIRPREFIX , 2570.Ev MAKESYSPATH , 2571.Ev PWD , 2572and 2573.Ev TMPDIR . 2574.Pp 2575.Ev MAKEOBJDIRPREFIX 2576and 2577.Ev MAKEOBJDIR 2578may only be set in the environment or on the command line to 2579.Nm 2580and not as makefile variables; 2581see the description of 2582.Sq Va .OBJDIR 2583for more details. 2584.Sh FILES 2585.Bl -tag -width /usr/share/mk -compact 2586.It .depend 2587list of dependencies 2588.It makefile 2589first default makefile if no makefile is specified on the command line 2590.It Makefile 2591second default makefile if no makefile is specified on the command line 2592.It sys.mk 2593system makefile 2594.It /usr/share/mk 2595system makefile directory 2596.El 2597.Sh COMPATIBILITY 2598The basic make syntax is compatible between different make variants; 2599however the special variables, variable modifiers and conditionals are not. 2600.Ss Older versions 2601An incomplete list of changes in older versions of 2602.Nm : 2603.Pp 2604The way that .for loop variables are substituted changed after 2605.Nx 5.0 2606so that they still appear to be variable expansions. 2607In particular this stops them being treated as syntax, and removes some 2608obscure problems using them in .if statements. 2609.Pp 2610The way that parallel makes are scheduled changed in 2611.Nx 4.0 2612so that .ORDER and .WAIT apply recursively to the dependent nodes. 2613The algorithms used may change again in the future. 2614.Ss Other make dialects 2615Other make dialects (GNU make, SVR4 make, POSIX make, etc.) do not 2616support most of the features of 2617.Nm 2618as described in this manual. 2619Most notably: 2620.Bl -bullet -offset indent 2621.It 2622The 2623.Ic .WAIT 2624and 2625.Ic .ORDER 2626declarations and most functionality pertaining to parallelization. 2627(GNU make supports parallelization but lacks the features needed to 2628control it effectively.) 2629.It 2630Directives, including for loops and conditionals and most of the 2631forms of include files. 2632(GNU make has its own incompatible and less powerful syntax for 2633conditionals.) 2634.\" The "less powerful" above means that GNU make does not have the 2635.\" make(target), target(target) and commands(target) functions. 2636.It 2637All built-in variables that begin with a dot. 2638.It 2639Most of the special sources and targets that begin with a dot, 2640with the notable exception of 2641.Ic .PHONY , 2642.Ic .PRECIOUS , 2643and 2644.Ic .SUFFIXES . 2645.It 2646Variable modifiers, except for the 2647.Ql :old=new 2648string substitution, which does not portably support globbing with 2649.Ql % 2650and historically only works on declared suffixes. 2651.It 2652The 2653.Ic $> 2654variable even in its short form; most makes support this functionality 2655but its name varies. 2656.El 2657.Pp 2658Some features are somewhat more portable, such as assignment with 2659.Ic += , 2660.Ic ?= , 2661and 2662.Ic != . 2663The 2664.Va .PATH 2665functionality is based on an older feature 2666.Ic VPATH 2667found in GNU make and many versions of SVR4 make; however, 2668historically its behavior is too ill-defined (and too buggy) to rely 2669upon. 2670.Pp 2671The 2672.Ic $@ 2673and 2674.Ic $< 2675variables are more or less universally portable, as is the 2676.Ic $(MAKE) 2677variable. 2678Basic use of suffix rules (for files only in the current directory, 2679not trying to chain transformations together, etc.) is also reasonably 2680portable. 2681.Sh SEE ALSO 2682.Xr mkdep 1 2683.Sh HISTORY 2684A 2685.Nm 2686command appeared in 2687.At v7 . 2688This 2689.Nm 2690implementation is based on Adam de Boor's pmake program, 2691which was written for Sprite at Berkeley. 2692It was designed to be a parallel distributed make running jobs on different 2693machines using a daemon called 2694.Dq customs . 2695.Pp 2696Historically the target/dependency 2697.Ic FRC 2698has been used to FoRCe rebuilding (since the target/dependency 2699does not exist ... unless someone creates an 2700.Pa FRC 2701file). 2702.Sh BUGS 2703The 2704.Nm 2705syntax is difficult to parse. 2706For instance, finding the end of a variable's use should involve scanning 2707each of the modifiers, using the correct terminator for each field. 2708In many places 2709.Nm 2710just counts {} and () in order to find the end of a variable expansion. 2711.Pp 2712There is no way of escaping a space character in a filename. 2713