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