1.\" $NetBSD: make.1,v 1.387 2025/07/02 17:11:56 rillig 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 2, 2025 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 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.El 560.Pp 561When 562.Nm 563is run in jobs mode with 564.Fl j Ar max_jobs , 565the entire script for the target is fed to a single instance of the shell. 566In compatibility (non-jobs) mode, each command is run in a separate process. 567If the command contains any shell meta characters 568.Pq Ql #=|^(){};&<>*?[]:$`\e\en , 569it is passed to the shell; otherwise 570.Nm 571attempts direct execution. 572If a line starts with 573.Sq Ic \- 574and the shell has ErrCtl enabled, 575failure of the command line is ignored as in compatibility mode. 576Otherwise 577.Sq Ic \- 578affects the entire job; 579the script stops at the first command line that fails, 580but the target is not deemed to have failed. 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 MAKEFILE 960The top-level makefile that is currently read, 961as given in the command line. 962.It Va .MAKEFLAGS 963The environment variable 964.Sq Ev MAKEFLAGS 965may contain anything that 966may be specified on 967.Nm Ns 's 968command line. 969Anything specified on 970.Nm Ns 's 971command line is appended to the 972.Va .MAKEFLAGS 973variable, which is then added to the environment for all programs that 974.Nm 975executes. 976.It Va .MAKE.GID 977The numeric group ID of the user running 978.Nm . 979It is read-only. 980.It Va .MAKE.JOB.PREFIX 981If 982.Nm 983is run with 984.Fl j , 985the output for each target is prefixed with a token 986.Dl --- Ar target Li --- 987the first part of which can be controlled via 988.Va .MAKE.JOB.PREFIX . 989If 990.Va .MAKE.JOB.PREFIX 991is empty, no token is printed. 992For example, setting 993.Va .MAKE.JOB.PREFIX 994to 995.Ql ${.newline}---${.MAKE:T}[${.MAKE.PID}] 996would produce tokens like 997.Dl ---make[1234] Ar target Li --- 998making it easier to track the degree of parallelism being achieved. 999.It Va .MAKE.JOBS 1000The argument to the 1001.Fl j 1002option. 1003.It Va .MAKE.JOBS.C 1004A read-only boolean that indicates whether the 1005.Fl j 1006option supports use of 1007.Ql C . 1008.It Va .MAKE.LEVEL 1009The recursion depth of 1010.Nm . 1011The top-level instance of 1012.Nm 1013has level 0, and each child make has its parent level plus 1. 1014This allows tests like: 1015.Li .if ${.MAKE.LEVEL} == 0 1016to protect things which should only be evaluated in the top-level instance of 1017.Nm . 1018.It Va .MAKE.LEVEL.ENV 1019The name of the environment variable that stores the level of nested calls to 1020.Nm . 1021.It Va .MAKE.MAKEFILE_PREFERENCE 1022The ordered list of makefile names 1023(default 1024.Sq Pa makefile , 1025.Sq Pa Makefile ) 1026that 1027.Nm 1028looks for. 1029.It Va .MAKE.MAKEFILES 1030The list of makefiles read by 1031.Nm , 1032which is useful for tracking dependencies. 1033Each makefile is recorded only once, regardless of the number of times read. 1034.It Va .MAKE.META.BAILIWICK 1035In 1036.Dq meta 1037mode, provides a list of prefixes which 1038match the directories controlled by 1039.Nm . 1040If a file that was generated outside of 1041.Va .OBJDIR 1042but within said bailiwick is missing, 1043the current target is considered out-of-date. 1044.It Va .MAKE.META.CMP_FILTER 1045In 1046.Dq meta 1047mode, it can (very rarely!) be useful to filter command 1048lines before comparison. 1049This variable can be set to a set of modifiers that are applied to 1050each line of the old and new command that differ, if the filtered 1051commands still differ, the target is considered out-of-date. 1052.It Va .MAKE.META.CREATED 1053In 1054.Dq meta 1055mode, this variable contains a list of all the meta files 1056updated. 1057If not empty, it can be used to trigger processing of 1058.Va .MAKE.META.FILES . 1059.It Va .MAKE.META.FILES 1060In 1061.Dq meta 1062mode, this variable contains a list of all the meta files 1063used (updated or not). 1064This list can be used to process the meta files to extract dependency 1065information. 1066.It Va .MAKE.META.IGNORE_FILTER 1067Provides a list of variable modifiers to apply to each pathname. 1068Ignore if the expansion is an empty string. 1069.It Va .MAKE.META.IGNORE_PATHS 1070Provides a list of path prefixes that should be ignored; 1071because the contents are expected to change over time. 1072The default list includes: 1073.Sq Pa /dev /etc /proc /tmp /var/run /var/tmp 1074.It Va .MAKE.META.IGNORE_PATTERNS 1075Provides a list of patterns to match against pathnames. 1076Ignore any that match. 1077.It Va .MAKE.META.PREFIX 1078Defines the message printed for each meta file updated in 1079.Dq meta verbose 1080mode. 1081The default value is: 1082.Dl Building ${.TARGET:H:tA}/${.TARGET:T} 1083.It Va .MAKE.MODE 1084Processed after reading all makefiles. 1085Affects the mode that 1086.Nm 1087runs in. 1088It can contain these keywords: 1089.Bl -tag -width indent 1090.It Cm compat 1091Like 1092.Fl B , 1093puts 1094.Nm 1095into 1096.Dq compat 1097mode. 1098.It Cm meta 1099Puts 1100.Nm 1101into 1102.Dq meta 1103mode, where meta files are created for each target 1104to capture the commands run, the output generated, and if 1105.Xr filemon 4 1106is available, the system calls which are of interest to 1107.Nm . 1108The captured output can be useful when diagnosing errors. 1109.Pp 1110.Nm 1111will use the information in the meta file to help determine if 1112a target is out-of-date when the normal dependency rules 1113indicate it is not. 1114.Pp 1115First, 1116the commands to be executed, 1117will be compared to those captured previously, 1118if any differ, 1119the target is out-of-date. 1120.Pp 1121This allows for a huge improvement in the reliability 1122and efficiency of update builds. 1123It is no longer necessary for targets to depend on makefiles 1124just in-case they set a variable that might be relevant. 1125Mechanisms such as 1126.Va .MAKE.META.CMP_FILTER 1127and 1128.Ic .NOMETA_CMP , 1129allow limiting or disabling that comparison on a per target basis. 1130A reference to the variable 1131.Va .OODATE 1132can be leveraged to block comparison of certain commands. 1133For example: 1134.Ql ${.OODATE:M} 1135will expand to nothing and have no impact on the target, 1136its side-effect though, 1137will be to prevent comparison of any command line it appears on. 1138For documentation purposes 1139.Ql ${.OODATE:MNOMETA_CMP} 1140is useful. 1141.Pp 1142If necessary, 1143.Nm 1144will then use the information captured by 1145.Xr filemon 4 , 1146to check the modification time of any file used in generating 1147the target, 1148if any is newer, 1149the target is out-of-date. 1150.Pp 1151Such deep inspection can easily lead to cases where a target is 1152.Em always 1153considered out-of-date, which is why 1154.Va .MAKE.META.IGNORE_FILTER , 1155.Va .MAKE.META.IGNORE_PATHS 1156and 1157.Va .MAKE.META.IGNORE_PATTERNS , 1158are provided to limit that inspection when necessary. 1159.It Cm curdirOk= Ns Ar bf 1160By default, 1161.Nm 1162does not create 1163.Pa .meta 1164files in 1165.Sq Va .CURDIR . 1166This can be overridden by setting 1167.Ar bf 1168to a value which represents true. 1169.It Cm missing-meta= Ns Ar bf 1170If 1171.Ar bf 1172is true, a missing 1173.Pa .meta 1174file makes the target out-of-date. 1175.It Cm missing-filemon= Ns Ar bf 1176If 1177.Ar bf 1178is true, missing filemon data makes the target out-of-date. 1179.It Cm nofilemon 1180Do not use 1181.Xr filemon 4 . 1182.It Cm env 1183For debugging, it can be useful to include the environment 1184in the 1185.Pa .meta 1186file. 1187.It Cm verbose 1188If in 1189.Dq meta 1190mode, print a clue about the target being built. 1191This is useful if the build is otherwise running silently. 1192The message printed is the expanded value of 1193.Va .MAKE.META.PREFIX . 1194.It Cm ignore-cmd 1195Some makefiles have commands which are simply not stable. 1196This keyword causes them to be ignored for 1197determining whether a target is out of date in 1198.Dq meta 1199mode. 1200See also 1201.Ic .NOMETA_CMP . 1202.It Cm silent= Ns Ar bf 1203If 1204.Ar bf 1205is true, when a .meta file is created, mark the target 1206.Ic .SILENT . 1207.It Cm randomize-targets 1208In both compat and parallel mode, do not make the targets in the usual order, 1209but instead randomize their order. 1210This mode can be used to detect undeclared dependencies between files. 1211.El 1212.It Va MAKEOBJDIR 1213Used to create files in a separate directory, see 1214.Va .OBJDIR . 1215.It Va MAKE_OBJDIR_CHECK_WRITABLE 1216When true, 1217.Nm 1218will check that 1219.Va .OBJDIR 1220is writable, and issue a warning if not. 1221.It Va MAKE_DEBUG_OBJDIR_CHECK_WRITABLE 1222When true and 1223.Nm 1224is warning about an unwritable 1225.Va .OBJDIR , 1226report the variables listed in 1227.Va MAKE_PRINT_VAR_ON_ERROR 1228to help debug. 1229.It Va MAKEOBJDIRPREFIX 1230Used to create files in a separate directory, see 1231.Va .OBJDIR . 1232It should be an absolute path. 1233.It Va .MAKE.OS 1234The name of the operating system, see 1235.Xr uname 1 . 1236It is read-only. 1237.It Va .MAKEOVERRIDES 1238This variable is used to record the names of variables assigned to 1239on the command line, so that they may be exported as part of 1240.Sq Ev MAKEFLAGS . 1241This behavior can be disabled by assigning an empty value to 1242.Sq Va .MAKEOVERRIDES 1243within a makefile. 1244Extra variables can be exported from a makefile 1245by appending their names to 1246.Sq Va .MAKEOVERRIDES . 1247.Sq Ev MAKEFLAGS 1248is re-exported whenever 1249.Sq Va .MAKEOVERRIDES 1250is modified. 1251.It Va .MAKE.PATH_FILEMON 1252If 1253.Nm 1254was built with 1255.Xr filemon 4 1256support, this is set to the path of the device node. 1257This allows makefiles to test for this support. 1258.It Va .MAKE.PID 1259The process ID of 1260.Nm . 1261It is read-only. 1262.It Va .MAKE.PPID 1263The parent process ID of 1264.Nm . 1265It is read-only. 1266.It Va MAKE_PRINT_VAR_ON_ERROR 1267When 1268.Nm 1269stops due to an error, it sets 1270.Sq Va .ERROR_TARGET 1271to the name of the target that failed, 1272.Sq Va .ERROR_EXIT 1273to the exit status of the failed target, 1274.Sq Va .ERROR_CMD 1275to the commands of the failed target, 1276and in 1277.Dq meta 1278mode, it also sets 1279.Sq Va .ERROR_CWD 1280to the 1281.Xr getcwd 3 , 1282and 1283.Sq Va .ERROR_META_FILE 1284to the path of the meta file (if any) describing the failed target. 1285It then prints its name and the value of 1286.Sq Va .CURDIR 1287as well as the value of any variables named in 1288.Sq Va MAKE_PRINT_VAR_ON_ERROR . 1289.It Va .MAKE.SAVE_DOLLARS 1290If true, 1291.Ql $$ 1292are preserved when doing 1293.Ql := 1294assignments. 1295The default is false, for backwards compatibility. 1296Set to true for compatability with other makes. 1297If set to false, 1298.Ql $$ 1299becomes 1300.Ql $ 1301per normal evaluation rules. 1302.It Va .MAKE.TARGET_LOCAL_VARIABLES 1303If set to 1304.Ql false , 1305apparent variable assignments in dependency lines are 1306treated as normal sources. 1307.It Va .MAKE.UID 1308The numeric ID of the user running 1309.Nm . 1310It is read-only. 1311.\" 'MAKE_VERSION' is intentionally undocumented 1312.\" since it is only defined in the bmake distribution, 1313.\" but not in NetBSD's native make. 1314.\" '.meta.%d.lcwd' is intentionally undocumented 1315.\" since it is an internal implementation detail. 1316.\" '.meta.%d.ldir' is intentionally undocumented 1317.\" since it is an internal implementation detail. 1318.\" 'MFLAGS' is intentionally undocumented 1319.\" since it is obsolete. 1320.It Va .newline 1321This variable is simply assigned a newline character as its value. 1322It is read-only. 1323This allows expansions using the 1324.Cm \&:@ 1325modifier to put a newline between 1326iterations of the loop rather than a space. 1327For example, in case of an error, 1328.Nm 1329prints the variable names and their values using: 1330.Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@} 1331.It Va .OBJDIR 1332A path to the directory where the targets are built. 1333Its value is determined by trying to 1334.Xr chdir 2 1335to the following directories in order and using the first match: 1336.Bl -enum 1337.It 1338.Cm ${MAKEOBJDIRPREFIX} Ns Cm ${.CURDIR} 1339.Pp 1340(Only if 1341.Sq Ev MAKEOBJDIRPREFIX 1342is set in the environment or on the command line.) 1343.It 1344.Cm ${MAKEOBJDIR} 1345.Pp 1346(Only if 1347.Sq Ev MAKEOBJDIR 1348is set in the environment or on the command line.) 1349.It 1350.Cm ${.CURDIR} Ns Pa /obj. Ns Cm ${MACHINE} 1351.It 1352.Cm ${.CURDIR} Ns Pa /obj 1353.It 1354.Pa /usr/obj/ Ns Cm ${.CURDIR} 1355.It 1356.Cm ${.CURDIR} 1357.El 1358.Pp 1359Variable expansion is performed on the value before it is used, 1360so expressions such as 1361.Cm ${.CURDIR:S,^/usr/src,/var/obj,} 1362may be used. 1363This is especially useful with 1364.Sq Ev MAKEOBJDIR . 1365.Pp 1366.Sq Va .OBJDIR 1367may be modified in the makefile via the special target 1368.Sq Ic .OBJDIR . 1369In all cases, 1370.Nm 1371changes to the specified directory if it exists, and sets 1372.Sq Va .OBJDIR 1373and 1374.Sq Va PWD 1375to that directory before executing any targets. 1376.Pp 1377Except in the case of an explicit 1378.Sq Ic .OBJDIR 1379target, 1380.Nm 1381checks that the specified directory is writable and ignores it if not. 1382This check can be skipped by setting the environment variable 1383.Sq Ev MAKE_OBJDIR_CHECK_WRITABLE 1384to 1385.Dq no . 1386.It Va .PARSEDIR 1387The directory name of the current makefile being parsed. 1388.It Va .PARSEFILE 1389The basename of the current makefile being parsed. 1390This variable and 1391.Sq Va .PARSEDIR 1392are both set only while the makefiles are being parsed. 1393To retain their current values, 1394assign them to a variable using assignment with expansion 1395.Sq Cm \&:= . 1396.It Va .PATH 1397The space-separated list of directories that 1398.Nm 1399searches for files. 1400To update this search list, use the special target 1401.Sq Ic .PATH 1402rather than modifying the variable directly. 1403.It Va %POSIX 1404Is set in POSIX mode, see the special 1405.Ql Va .POSIX 1406target. 1407.\" XXX: There is no make variable named 'PWD', 1408.\" XXX: make only reads and writes the environment variable 'PWD'. 1409.It Va PWD 1410Alternate path to the current directory. 1411.Nm 1412normally sets 1413.Sq Va .CURDIR 1414to the canonical path given by 1415.Xr getcwd 3 . 1416However, if the environment variable 1417.Sq Ev PWD 1418is set and gives a path to the current directory, 1419.Nm 1420sets 1421.Sq Va .CURDIR 1422to the value of 1423.Sq Ev PWD 1424instead. 1425This behavior is disabled if 1426.Sq Ev MAKEOBJDIRPREFIX 1427is set or 1428.Sq Ev MAKEOBJDIR 1429contains a variable transform. 1430.Sq Va PWD 1431is set to the value of 1432.Sq Va .OBJDIR 1433for all programs which 1434.Nm 1435executes. 1436.It Va .SHELL 1437The pathname of the shell used to run target scripts. 1438It is read-only. 1439.It Va .SUFFIXES 1440The list of known suffixes. 1441It is read-only. 1442.It Va .SYSPATH 1443The space-separated list of directories that 1444.Nm 1445searches for makefiles, referred to as the system include path. 1446To update this search list, use the special target 1447.Sq Ic .SYSPATH 1448rather than modifying the variable which is read-only. 1449.It Va .TARGETS 1450The list of targets explicitly specified on the command line, if any. 1451.It Va VPATH 1452The colon-separated 1453.Pq Dq \&: 1454list of directories that 1455.Nm 1456searches for files. 1457This variable is supported for compatibility with old make programs only, use 1458.Sq Va .PATH 1459instead. 1460.El 1461.Ss Variable modifiers 1462The general format of a variable expansion is: 1463.Pp 1464.Sm off 1465.D1 Ic \&${ Ar variable\| Oo Ic \&: Ar modifier\| Oo Ic \&: No ... Oc Oc Ic \&} 1466.Sm on 1467.Pp 1468Each modifier begins with a colon. 1469To escape a colon, precede it with a backslash 1470.Ql \e . 1471.Pp 1472A list of indirect modifiers can be specified via a variable, as follows: 1473.Pp 1474.Bd -literal -offset indent 1475.Ar modifier_variable\^ Li \&= Ar modifier Ns Oo Ic \&: Ns No ... Oc 1476 1477.Sm off 1478.Ic \&${ Ar variable Ic \&:${ Ar modifier_variable Ic \&} Oo Ic \&: No ... Oc Ic \&} 1479.Sm on 1480.Ed 1481.Pp 1482In this case, the first modifier in the 1483.Ar modifier_variable 1484does not start with a colon, 1485since that colon already occurs in the referencing variable. 1486If any of the modifiers in the 1487.Ar modifier_variable 1488contains a dollar sign 1489.Pq Ql $ , 1490these must be doubled to avoid early expansion. 1491.Pp 1492Some modifiers interpret the expression value as a single string, 1493others treat the expression value as a whitespace-separated list of words. 1494When splitting a string into words, 1495whitespace can be escaped using double quotes, single quotes and backslashes, 1496like in the shell. 1497The quotes and backslashes are retained in the words. 1498.Pp 1499The supported modifiers are: 1500.Bl -tag -width EEE 1501.It Cm \&:E 1502Replaces each word with its suffix. 1503.It Cm \&:H 1504Replaces each word with its dirname. 1505.It Cm \&:M\| Ns Ar pattern 1506Selects only those words that match 1507.Ar pattern . 1508The standard shell wildcard characters 1509.Pf ( Ql * , 1510.Ql \&? , 1511and 1512.Ql \&[] ) 1513may 1514be used. 1515The wildcard characters may be escaped with a backslash 1516.Pq Ql \e . 1517As a consequence of the way values are split into words, matched, 1518and then joined, the construct 1519.Ql ${VAR:M*} 1520removes all leading and trailing whitespace 1521and normalizes the inter-word spacing to a single space. 1522.It Cm \&:N\| Ns Ar pattern 1523This is the opposite of 1524.Sq Cm \&:M , 1525selecting all words which do 1526.Em not 1527match 1528.Ar pattern . 1529.It Cm \&:O 1530Orders the words lexicographically. 1531.It Cm \&:On 1532Orders the words numerically. 1533A number followed by one of 1534.Ql k , 1535.Ql M 1536or 1537.Ql G 1538is multiplied by the appropriate factor, which is 1024 for 1539.Ql k , 15401048576 for 1541.Ql M , 1542or 1073741824 for 1543.Ql G . 1544Both upper- and lower-case letters are accepted. 1545.It Cm \&:Or 1546Orders the words in reverse lexicographical order. 1547.It Cm \&:Orn 1548Orders the words in reverse numerical order. 1549.It Cm \&:Ox 1550Shuffles the words. 1551The results are different each time you are referring to the 1552modified variable; use the assignment with expansion 1553.Sq Cm \&:= 1554to prevent such behavior. 1555For example, 1556.Bd -literal -offset indent 1557LIST= uno due tre quattro 1558RANDOM_LIST= ${LIST:Ox} 1559STATIC_RANDOM_LIST:= ${LIST:Ox} 1560 1561all: 1562 @echo "${RANDOM_LIST}" 1563 @echo "${RANDOM_LIST}" 1564 @echo "${STATIC_RANDOM_LIST}" 1565 @echo "${STATIC_RANDOM_LIST}" 1566.Ed 1567may produce output similar to: 1568.Bd -literal -offset indent 1569quattro due tre uno 1570tre due quattro uno 1571due uno quattro tre 1572due uno quattro tre 1573.Ed 1574.It Cm \&:Q 1575Quotes every shell meta-character in the value, so that it can be passed 1576safely to the shell. 1577.It Cm \&:q 1578Quotes every shell meta-character in the value, and also doubles 1579.Sq $ 1580characters so that it can be passed 1581safely through recursive invocations of 1582.Nm . 1583This is equivalent to 1584.Sq Cm \&:S/\e\&$/&&/g:Q . 1585.It Cm \&:R 1586Replaces each word with everything but its suffix. 1587.It Cm \&:range Ns Oo Cm = Ns Ar count Oc 1588The value is an integer sequence representing the words of the original 1589value, or the supplied 1590.Ar count . 1591.It Cm \&:gmtime Ns Oo Cm = Ns Ar timestamp Oc 1592The value is interpreted as a format string for 1593.Xr strftime 3 , 1594using 1595.Xr gmtime 3 , 1596producing the formatted timestamp. 1597Note: the 1598.Ql %s 1599format should only be used with 1600.Sq Cm \&:localtime . 1601If a 1602.Ar timestamp 1603value is not provided or is 0, the current time is used. 1604.It Cm \&:hash 1605Computes a 32-bit hash of the value and encodes it as 8 hex digits. 1606.It Cm \&:localtime Ns Oo Cm = Ns Ar timestamp Oc 1607The value is interpreted as a format string for 1608.Xr strftime 3 , 1609using 1610.Xr localtime 3 , 1611producing the formatted timestamp. 1612If a 1613.Ar timestamp 1614value is not provided or is 0, the current time is used. 1615.It Cm \&:mtime Ns Oo Cm = Ns Ar timestamp Oc 1616Call 1617.Xr stat 2 1618with each word as pathname; 1619use 1620.Ql st_mtime 1621as the new value. 1622If 1623.Xr stat 2 1624fails; use 1625.Ar timestamp 1626or current time. 1627If 1628.Ar timestamp 1629is set to 1630.Ql error , 1631then 1632.Xr stat 2 1633failure will cause an error. 1634.It Cm \&:tA 1635Attempts to convert the value to an absolute path using 1636.Xr realpath 3 . 1637If that fails, the value is unchanged. 1638.It Cm \&:tl 1639Converts the value to lower-case letters. 1640.It Cm \&:ts Ns Ar c 1641When joining the words after a modifier that treats the value as words, 1642the words are normally separated by a space. 1643This modifier changes the separator to the character 1644.Ar c . 1645If 1646.Ar c 1647is omitted, no separator is used. 1648The common escapes (including octal numeric codes) work as expected. 1649.It Cm \&:tt 1650Converts the first character of each word to upper-case, 1651and the rest to lower-case letters. 1652.It Cm \&:tu 1653Converts the value to upper-case letters. 1654.It Cm \&:tW 1655Causes subsequent modifiers to treat the value as a single word 1656(possibly containing embedded whitespace). 1657See also 1658.Sq Cm \&:[*] . 1659.It Cm \&:tw 1660Causes the value to be treated as a list of words. 1661See also 1662.Sq Cm \&:[@] . 1663.Sm off 1664.It Cm \&:S\| No \&/ Ar old_string\| No \&/ Ar new_string\| No \&/ Op Cm 1gW 1665.Sm on 1666Modifies the first occurrence of 1667.Ar old_string 1668in each word of the value, replacing it with 1669.Ar new_string . 1670If a 1671.Ql g 1672is appended to the last delimiter of the pattern, 1673all occurrences in each word are replaced. 1674If a 1675.Ql 1 1676is appended to the last delimiter of the pattern, 1677only the first occurrence is affected. 1678If a 1679.Ql W 1680is appended to the last delimiter of the pattern, 1681the value is treated as a single word. 1682If 1683.Ar old_string 1684begins with a caret 1685.Pq Ql ^ , 1686.Ar old_string 1687is anchored at the beginning of each word. 1688If 1689.Ar old_string 1690ends with a dollar sign 1691.Pq Ql \&$ , 1692it is anchored at the end of each word. 1693Inside 1694.Ar new_string , 1695an ampersand 1696.Pq Ql & 1697is replaced by 1698.Ar old_string 1699(without the anchoring 1700.Ql ^ 1701or 1702.Ql \&$ ) . 1703Any character may be used as the delimiter for the parts of the modifier 1704string. 1705The anchoring, ampersand and delimiter characters can be escaped with a 1706backslash 1707.Pq Ql \e . 1708.Pp 1709Both 1710.Ar old_string 1711and 1712.Ar new_string 1713may contain nested expressions. 1714To prevent a dollar sign from starting a nested expression, 1715escape it with a backslash. 1716.Sm off 1717.It Cm \&:C\| No \&/ Ar pattern\| No \&/ Ar replacement\| No \&/ Op Cm 1gW 1718.Sm on 1719The 1720.Cm \&:C 1721modifier works like the 1722.Cm \&:S 1723modifier except that the old and new strings, instead of being 1724simple strings, are an extended regular expression 1725.Ar pattern 1726(see 1727.Xr regex 3 ) 1728and an 1729.Xr ed 1 Ns \-style 1730.Ar replacement . 1731Normally, the first occurrence of the pattern 1732.Ar pattern 1733in each word of the value is substituted with 1734.Ar replacement . 1735The 1736.Ql 1 1737modifier causes the substitution to apply to at most one word; the 1738.Ql g 1739modifier causes the substitution to apply to as many instances of the 1740search pattern 1741.Ar pattern 1742as occur in the word or words it is found in; the 1743.Ql W 1744modifier causes the value to be treated as a single word 1745(possibly containing embedded whitespace). 1746.Pp 1747As for the 1748.Cm \&:S 1749modifier, the 1750.Ar pattern 1751and 1752.Ar replacement 1753are subjected to variable expansion before being parsed as 1754regular expressions. 1755.It Cm \&:T 1756Replaces each word with its last path component (basename). 1757.It Cm \&:u 1758Removes adjacent duplicate words (like 1759.Xr uniq 1 ) . 1760.Sm off 1761.It Cm \&:\&?\| Ar true_string\| Cm \&: Ar false_string 1762.Sm on 1763If the variable name (not its value), when parsed as a 1764.Cm .if 1765conditional expression, evaluates to true, return as its value the 1766.Ar true_string , 1767otherwise return the 1768.Ar false_string . 1769Since the variable name is used as the expression, 1770\&:\&? must be the first modifier after the variable name 1771.No itself Ns \^\(em\^ Ns 1772which, of course, usually contains variable expansions. 1773A common error is trying to use expressions like 1774.Dl ${NUMBERS:M42:?match:no} 1775which actually tests defined(NUMBERS). 1776To determine if any words match 1777.Dq 42 , 1778you need to use something like: 1779.Dl ${"${NUMBERS:M42}" != \&"\&":?match:no} . 1780.It Cm :\| Ns Ar old_string\| Ns Cm = Ns Ar new_string 1781This is the 1782.At V 1783style substitution. 1784It can only be the last modifier specified, 1785as a 1786.Ql \&: 1787in either 1788.Ar old_string 1789or 1790.Ar new_string 1791is treated as a regular character, not as the end of the modifier. 1792.Pp 1793If 1794.Ar old_string 1795does not contain the pattern matching character 1796.Ql % , 1797and the word ends with 1798.Ar old_string 1799or equals it, 1800that suffix is replaced with 1801.Ar new_string . 1802.Pp 1803Otherwise, the first 1804.Ql % 1805in 1806.Ar old_string 1807matches a possibly empty substring of arbitrary characters, 1808and if the whole pattern is found in the word, 1809the matching part is replaced with 1810.Ar new_string , 1811and the first occurrence of 1812.Ql % 1813in 1814.Ar new_string 1815(if any) is replaced with the substring matched by the 1816.Ql % . 1817.Pp 1818Both 1819.Ar old_string 1820and 1821.Ar new_string 1822may contain nested expressions. 1823To prevent a dollar sign from starting a nested expression, 1824escape it with a backslash. 1825.Sm off 1826.It Cm \&:@ Ar varname\| Cm @ Ar string\| Cm @ 1827.Sm on 1828This is the loop expansion mechanism from the OSF Development 1829Environment (ODE) make. 1830Unlike 1831.Cm \&.for 1832loops, expansion occurs at the time of reference. 1833For each word in the value, assign the word to the variable named 1834.Ar varname 1835and evaluate 1836.Ar string . 1837The ODE convention is that 1838.Ar varname 1839should start and end with a period, for example: 1840.Dl ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@} 1841.Pp 1842However, a single-letter variable is often more readable: 1843.Dl ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@} 1844.It Cm \&:_ Ns Oo Cm = Ns Ar var Oc 1845Saves the current variable value in 1846.Ql $_ 1847or the named 1848.Ar var 1849for later reference. 1850Example usage: 1851.Bd -literal -offset indent 1852M_cmpv.units = 1 1000 1000000 1853M_cmpv = S,., ,g:_:range:@i@+ $${_:[-$$i]} \&\\ 1854\\* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh 1855 1856.Dv .if ${VERSION:${M_cmpv}} < ${3.1.12:L:${M_cmpv}} 1857 1858.Ed 1859Here 1860.Ql $_ 1861is used to save the result of the 1862.Ql :S 1863modifier which is later referenced using the index values from 1864.Ql :range . 1865.It Cm \&:U\| Ns Ar newval 1866If the variable is undefined, 1867the optional 1868.Ar newval 1869(which may be empty) is the value. 1870If the variable is defined, the existing value is returned. 1871This is another ODE make feature. 1872It is handy for setting per-target CFLAGS for instance: 1873.Dl ${_${.TARGET:T}_CFLAGS:U${DEF_CFLAGS}} 1874If a value is only required if the variable is undefined, use: 1875.Dl ${VAR:D:Unewval} 1876.It Cm \&:D\| Ns Ar newval 1877If the variable is defined, 1878.Ar newval 1879(which may be empty) is the value. 1880.It Cm \&:L 1881The name of the variable is the value. 1882.It Cm \&:P 1883The path of the node which has the same name as the variable is the value. 1884If no such node exists or its path is null, the name of the variable is used. 1885In order for this modifier to work, the name (node) must at least have 1886appeared on the right-hand side of a dependency. 1887.Sm off 1888.It Cm \&:\&! Ar cmd\| Cm \&! 1889.Sm on 1890The output of running 1891.Ar cmd 1892is the value. 1893.It Cm \&:sh 1894The value is run as a command, and the output becomes the new value. 1895.It Cm \&::= Ns Ar str 1896The variable is assigned the value 1897.Ar str 1898after substitution. 1899This modifier and its variations are useful in obscure situations 1900such as wanting to set a variable 1901at a point where a target's shell commands are being parsed. 1902These assignment modifiers always expand to nothing. 1903.Pp 1904The 1905.Sq Cm \&:: 1906helps avoid false matches with the 1907.At V 1908style 1909.Ql \&:= 1910modifier and since substitution always occurs, the 1911.Ql \&::= 1912form is vaguely appropriate. 1913.It Cm \&::?= Ns Ar str 1914As for 1915.Cm \&::= 1916but only if the variable does not already have a value. 1917.It Cm \&::+= Ns Ar str 1918Append 1919.Ar str 1920to the variable. 1921.It Cm \&::!= Ns Ar cmd 1922Assign the output of 1923.Ar cmd 1924to the variable. 1925.It Cm \&:\&[ Ns Ar range Ns Cm \&] 1926Selects one or more words from the value, 1927or performs other operations related to the way in which the 1928value is split into words. 1929.Pp 1930An empty value, or a value that consists entirely of white-space, 1931is treated as a single word. 1932For the purposes of the 1933.Sq Cm \&:[] 1934modifier, the words are indexed both forwards using positive integers 1935(where index 1 represents the first word), 1936and backwards using negative integers 1937(where index \-1 represents the last word). 1938.Pp 1939The 1940.Ar range 1941is subjected to variable expansion, and the expanded result is 1942then interpreted as follows: 1943.Bl -tag -width index 1944.\" :[n] 1945.It Ar index 1946Selects a single word from the value. 1947.\" :[start..end] 1948.It Ar start Ns Cm \&.. Ns Ar end 1949Selects all words from 1950.Ar start 1951to 1952.Ar end , 1953inclusive. 1954For example, 1955.Sq Cm \&:[2..-1] 1956selects all words from the second word to the last word. 1957If 1958.Ar start 1959is greater than 1960.Ar end , 1961the words are output in reverse order. 1962For example, 1963.Sq Cm \&:[-1..1] 1964selects all the words from last to first. 1965If the list is already ordered, 1966this effectively reverses the list, 1967but it is more efficient to use 1968.Sq Cm \&:Or 1969instead of 1970.Sq Cm \&:O:[-1..1] . 1971.\" :[*] 1972.It Cm \&* 1973Causes subsequent modifiers to treat the value as a single word 1974(possibly containing embedded whitespace). 1975Analogous to the effect of 1976.Li \&$* 1977in Bourne shell. 1978.\" :[0] 1979.It 0 1980Means the same as 1981.Sq Cm \&:[*] . 1982.\" :[*] 1983.It Cm \&@ 1984Causes subsequent modifiers to treat the value as a sequence of words 1985delimited by whitespace. 1986Analogous to the effect of 1987.Li \&$@ 1988in Bourne shell. 1989.\" :[#] 1990.It Cm \&# 1991Returns the number of words in the value. 1992.El \" :[range] 1993.El 1994.Sh DIRECTIVES 1995.Nm 1996offers directives for including makefiles, conditionals and for loops. 1997All these directives are identified by a line beginning with a single dot 1998.Pq Ql \&. 1999character, followed by the keyword of the directive, such as 2000.Cm include 2001or 2002.Cm if . 2003.Ss File inclusion 2004Files are included with either 2005.Cm \&.include \&< Ns Ar file Ns Cm \&> 2006or 2007.Cm \&.include \&\*q Ns Ar file Ns Cm \&\*q . 2008Variables between the angle brackets or double quotes are expanded 2009to form the file name. 2010If angle brackets are used, the included makefile is expected to be in 2011the system makefile directory. 2012If double quotes are used, the including makefile's directory and any 2013directories specified using the 2014.Fl I 2015option are searched before the system makefile directory. 2016.Pp 2017For compatibility with other make variants, 2018.Sq Cm include Ar file No ... 2019(without leading dot) 2020is also accepted. 2021.Pp 2022If the include statement is written as 2023.Cm .-include 2024or as 2025.Cm .sinclude , 2026errors locating and/or opening include files are ignored. 2027.Pp 2028If the include statement is written as 2029.Cm .dinclude , 2030not only are errors locating and/or opening include files ignored, 2031but stale dependencies within the included file are ignored just like in 2032.Va .MAKE.DEPENDFILE . 2033.Ss Exporting variables 2034The directives for exporting and unexporting variables are: 2035.Bl -tag -width Ds 2036.It Ic .export Ar variable No ... 2037Export the specified global variable. 2038.Pp 2039For compatibility with other make programs, 2040.Cm export Ar variable\| Ns Cm \&= Ns Ar value 2041(without leading dot) is also accepted. 2042.Pp 2043Appending a variable name to 2044.Va .MAKE.EXPORTED 2045is equivalent to exporting a variable. 2046.It Ic .export-all 2047Export all globals except for internal variables (those that start with 2048.Ql \&. ) . 2049This is not affected by the 2050.Fl X 2051flag, so should be used with caution. 2052.It Ic .export-env Ar variable No ... 2053The same as 2054.Ql .export , 2055except that the variable is not appended to 2056.Va .MAKE.EXPORTED . 2057This allows exporting a value to the environment which is different from that 2058used by 2059.Nm 2060internally. 2061.It Ic .export-literal Ar variable No ... 2062The same as 2063.Ql .export-env , 2064except that variables in the value are not expanded. 2065.It Ic .unexport Ar variable No ... 2066The opposite of 2067.Ql .export . 2068The specified global 2069.Ar variable 2070is removed from 2071.Va .MAKE.EXPORTED . 2072If no variable list is provided, all globals are unexported, 2073and 2074.Va .MAKE.EXPORTED 2075deleted. 2076.It Ic .unexport-env 2077Unexport all globals previously exported and 2078clear the environment inherited from the parent. 2079This operation causes a memory leak of the original environment, 2080so should be used sparingly. 2081Testing for 2082.Va .MAKE.LEVEL 2083being 0 would make sense. 2084Also note that any variables which originated in the parent environment 2085should be explicitly preserved if desired. 2086For example: 2087.Bd -literal -offset indent 2088.Li .if ${.MAKE.LEVEL} == 0 2089PATH := ${PATH} 2090.Li .unexport-env 2091.Li .export PATH 2092.Li .endif 2093.Pp 2094.Ed 2095Would result in an environment containing only 2096.Sq Ev PATH , 2097which is the minimal useful environment. 2098.\" TODO: Check the below sentence, environment variables don't start with '.'. 2099Actually 2100.Sq Va .MAKE.LEVEL 2101is also pushed into the new environment. 2102.El 2103.Ss Messages 2104The directives for printing messages to the output are: 2105.Bl -tag -width Ds 2106.It Ic .info Ar message 2107The message is printed along with the name of the makefile and line number. 2108.It Ic .warning Ar message 2109The message prefixed by 2110.Sq Li warning: 2111is printed along with the name of the makefile and line number. 2112.It Ic .error Ar message 2113The message is printed along with the name of the makefile and line number, 2114.Nm 2115exits immediately. 2116.El 2117.Ss Conditionals 2118The directives for conditionals are: 2119.ds maybenot Oo Ic \&! Oc Ns 2120.Bl -tag 2121.It Ic .if \*[maybenot] Ar expression Op Ar operator expression No ... 2122Test the value of an expression. 2123.It Ic .ifdef \*[maybenot] Ar variable Op Ar operator variable No ... 2124Test whether a variable is defined. 2125.It Ic .ifndef \*[maybenot] Ar variable Op Ar operator variable No ... 2126Test whether a variable is not defined. 2127.It Ic .ifmake \*[maybenot] Ar target Op Ar operator target No ... 2128Test the target being requested. 2129.It Ic .ifnmake \*[maybenot] Ar target Op Ar operator target No ... 2130Test the target being requested. 2131.It Ic .else 2132Reverse the sense of the last conditional. 2133.It Ic .elif \*[maybenot] Ar expression Op Ar operator expression No ... 2134A combination of 2135.Sq Ic .else 2136followed by 2137.Sq Ic .if . 2138.It Ic .elifdef \*[maybenot] Ar variable Op Ar operator variable No ... 2139A combination of 2140.Sq Ic .else 2141followed by 2142.Sq Ic .ifdef . 2143.It Ic .elifndef \*[maybenot] Ar variable Op Ar operator variable No ... 2144A combination of 2145.Sq Ic .else 2146followed by 2147.Sq Ic .ifndef . 2148.It Ic .elifmake \*[maybenot] Ar target Op Ar operator target No ... 2149A combination of 2150.Sq Ic .else 2151followed by 2152.Sq Ic .ifmake . 2153.It Ic .elifnmake \*[maybenot] Ar target Op Ar operator target No ... 2154A combination of 2155.Sq Ic .else 2156followed by 2157.Sq Ic .ifnmake . 2158.It Ic .endif 2159End the body of the conditional. 2160.El 2161.Pp 2162The 2163.Ar operator 2164may be any one of the following: 2165.Bl -tag 2166.It Ic \&|\&| 2167Logical OR. 2168.It Ic \&&& 2169Logical AND; of higher precedence than 2170.Sq Ic \&|\&| . 2171.El 2172.Pp 2173.Nm 2174only evaluates a conditional as far as is necessary to determine its value. 2175Parentheses can be used to override the operator precedence. 2176The boolean operator 2177.Sq Ic \&! 2178may be used to logically negate an expression, typically a function call. 2179It is of higher precedence than 2180.Sq Ic \&&& . 2181.Pp 2182The value of 2183.Ar expression 2184may be any of the following function call expressions: 2185.Bl -tag 2186.Sm off 2187.It Ic defined Li \&( Ar varname Li \&) 2188.Sm on 2189Evaluates to true if the variable 2190.Ar varname 2191has been defined. 2192.Sm off 2193.It Ic make Li \&( Ar target Li \&) 2194.Sm on 2195Evaluates to true if the target was specified as part of 2196.Nm Ns 's 2197command line or was declared the default target (either implicitly or 2198explicitly, see 2199.Va .MAIN ) 2200before the line containing the conditional. 2201.Sm off 2202.It Ic empty Li \&( Ar varname Oo Li : Ar modifiers Oc Li \&) 2203.Sm on 2204Evaluates to true if the expansion of the variable, 2205after applying the modifiers, results in an empty string. 2206.Sm off 2207.It Ic exists Li \&( Ar pathname Li \&) 2208.Sm on 2209Evaluates to true if the given pathname exists. 2210If relative, the pathname is searched for on the system search path (see 2211.Va .PATH ) . 2212.Sm off 2213.It Ic target Li \&( Ar target Li \&) 2214.Sm on 2215Evaluates to true if the target has been defined. 2216.Sm off 2217.It Ic commands Li \&( Ar target Li \&) 2218.Sm on 2219Evaluates to true if the target has been defined 2220and has commands associated with it. 2221.El 2222.Pp 2223.Ar Expression 2224may also be an arithmetic or string comparison. 2225Variable expansion is performed on both sides of the comparison. 2226If both sides are numeric and neither is enclosed in quotes, 2227the comparison is done numerically, otherwise lexicographically. 2228A string is interpreted as a hexadecimal integer if it is preceded by 2229.Li 0x , 2230otherwise it is interpreted as a decimal floating-point number; 2231octal numbers are not supported. 2232.Pp 2233All comparisons may use the operators 2234.Sq Ic \&== 2235and 2236.Sq Ic \&!= . 2237Numeric comparisons may also use the operators 2238.Sq Ic \&< , 2239.Sq Ic \&<= , 2240.Sq Ic \&> 2241and 2242.Sq Ic \&>= . 2243.Pp 2244If the comparison has neither a comparison operator nor a right side, 2245the expression evaluates to true if it is nonempty 2246and its numeric value (if any) is not zero. 2247.Pp 2248When 2249.Nm 2250is evaluating one of these conditional expressions, and it encounters 2251a (whitespace-separated) word it doesn't recognize, either the 2252.Dq make 2253or 2254.Dq defined 2255function is applied to it, depending on the form of the conditional. 2256If the form is 2257.Sq Ic .ifdef , 2258.Sq Ic .ifndef 2259or 2260.Sq Ic .if , 2261the 2262.Dq defined 2263function is applied. 2264Similarly, if the form is 2265.Sq Ic .ifmake 2266or 2267.Sq Ic .ifnmake , 2268the 2269.Dq make 2270function is applied. 2271.Pp 2272If the conditional evaluates to true, 2273parsing of the makefile continues as before. 2274If it evaluates to false, the following lines until the corresponding 2275.Sq Ic .elif 2276variant, 2277.Sq Ic .else 2278or 2279.Sq Ic .endif 2280are skipped. 2281.Ss For loops 2282For loops are typically used to apply a set of rules to a list of files. 2283The syntax of a for loop is: 2284.Pp 2285.Bl -tag -compact -width Ds 2286.It Ic \&.for Ar variable Oo Ar variable No ... Oc Ic in Ar expression 2287.It Aq Ar make-lines 2288.It Ic \&.endfor 2289.El 2290.Pp 2291The 2292.Ar expression 2293is expanded and then split into words. 2294On each iteration of the loop, one word is taken and assigned to each 2295.Ar variable , 2296in order, and these 2297.Ar variables 2298are substituted into the 2299.Ar make-lines 2300inside the body of the for loop. 2301The number of words must come out even; that is, if there are three 2302iteration variables, the number of words provided must be a multiple 2303of three. 2304.Pp 2305If 2306.Sq Ic .break 2307is encountered within a 2308.Cm \&.for 2309loop, it causes early termination of the loop, otherwise a parse error. 2310.\" TODO: Describe limitations with defined/empty. 2311.Ss Other directives 2312.Bl -tag -width Ds 2313.It Ic .undef Ar variable No ... 2314Un-define the specified global variables. 2315Only global variables can be un-defined. 2316.El 2317.Sh COMMENTS 2318Comments begin with a hash 2319.Pq Ql \&# 2320character, anywhere but in a shell 2321command line, and continue to the end of an unescaped new line. 2322.Sh SPECIAL SOURCES (ATTRIBUTES) 2323.Bl -tag -width .IGNOREx 2324.It Ic .EXEC 2325Target is never out of date, but always execute commands anyway. 2326.It Ic .IGNORE 2327Ignore any errors from the commands associated with this target, exactly 2328as if they all were preceded by a dash 2329.Pq Ql \- . 2330.\" .It Ic .INVISIBLE 2331.\" XXX 2332.\" .It Ic .JOIN 2333.\" XXX 2334.It Ic .MADE 2335Mark all sources of this target as being up to date. 2336.It Ic .MAKE 2337Execute the commands associated with this target even if the 2338.Fl n 2339or 2340.Fl t 2341options were specified. 2342Normally used to mark recursive 2343.Nm Ns s . 2344.It Ic .META 2345Create a meta file for the target, even if it is flagged as 2346.Ic .PHONY , 2347.Ic .MAKE , 2348or 2349.Ic .SPECIAL . 2350Usage in conjunction with 2351.Ic .MAKE 2352is the most likely case. 2353In 2354.Dq meta 2355mode, the target is out-of-date if the meta file is missing. 2356.It Ic .NOMETA 2357Do not create a meta file for the target. 2358Meta files are also not created for 2359.Ic .PHONY , 2360.Ic .MAKE , 2361or 2362.Ic .SPECIAL 2363targets. 2364.It Ic .NOMETA_CMP 2365Ignore differences in commands when deciding if target is out of date. 2366This is useful if the command contains a value which always changes. 2367If the number of commands change, though, 2368the target is still considered out of date. 2369The same effect applies to any command line that uses the variable 2370.Va .OODATE , 2371which can be used for that purpose even when not otherwise needed or desired: 2372.Bd -literal -offset indent 2373 2374skip-compare-for-some: 2375 @echo this is compared 2376 @echo this is not ${.OODATE:M.NOMETA_CMP} 2377 @echo this is also compared 2378 2379.Ed 2380The 2381.Cm \&:M 2382pattern suppresses any expansion of the unwanted variable. 2383.It Ic .NOPATH 2384Do not search for the target in the directories specified by 2385.Va .PATH . 2386.It Ic .NOTMAIN 2387Normally 2388.Nm 2389selects the first target it encounters as the default target to be built 2390if no target was specified. 2391This source prevents this target from being selected. 2392.It Ic .OPTIONAL 2393If a target is marked with this attribute and 2394.Nm 2395can't figure out how to create it, it ignores this fact and assumes 2396the file isn't needed or already exists. 2397.It Ic .PHONY 2398The target does not correspond to an actual file; 2399it is always considered to be out of date, 2400and is not created with the 2401.Fl t 2402option. 2403Suffix-transformation rules are not applied to 2404.Ic .PHONY 2405targets. 2406.It Ic .PRECIOUS 2407When 2408.Nm 2409is interrupted, it normally removes any partially made targets. 2410This source prevents the target from being removed. 2411.It Ic .RECURSIVE 2412Synonym for 2413.Ic .MAKE . 2414.It Ic .SILENT 2415Do not echo any of the commands associated with this target, exactly 2416as if they all were preceded by an at sign 2417.Pq Ql @ . 2418.It Ic .USE 2419Turn the target into 2420.Nm Ns 's 2421version of a macro. 2422When the target is used as a source for another target, the other target 2423acquires the commands, sources, and attributes (except for 2424.Ic .USE ) 2425of the 2426source. 2427If the target already has commands, the 2428.Ic .USE 2429target's commands are appended 2430to them. 2431.It Ic .USEBEFORE 2432Like 2433.Ic .USE , 2434but instead of appending, prepend the 2435.Ic .USEBEFORE 2436target commands to the target. 2437.It Ic .WAIT 2438If 2439.Ic .WAIT 2440appears in a dependency line, the sources that precede it are 2441made before the sources that succeed it in the line. 2442Since the dependents of files are not made until the file itself 2443could be made, this also stops the dependents being built unless they 2444are needed for another branch of the dependency tree. 2445So given: 2446.Bd -literal 2447x: a .WAIT b 2448 echo x 2449a: 2450 echo a 2451b: b1 2452 echo b 2453b1: 2454 echo b1 2455 2456.Ed 2457the output is always 2458.Ql a , 2459.Ql b1 , 2460.Ql b , 2461.Ql x . 2462.Pp 2463The ordering imposed by 2464.Ic .WAIT 2465is only relevant for parallel makes. 2466.El 2467.Sh SPECIAL TARGETS 2468Special targets may not be included with other targets, i.e. they must be 2469the only target specified. 2470.Bl -tag -width .BEGINx 2471.It Ic .BEGIN 2472Any command lines attached to this target are executed before anything 2473else is done. 2474.It Ic .DEFAULT 2475This is sort of a 2476.Ic .USE 2477rule for any target (that was used only as a source) that 2478.Nm 2479can't figure out any other way to create. 2480Only the shell script is used. 2481The 2482.Va .IMPSRC 2483variable of a target that inherits 2484.Ic .DEFAULT Ns 's 2485commands is set to the target's own name. 2486.It Ic .DELETE_ON_ERROR 2487If this target is present in the makefile, it globally causes make to 2488delete targets whose commands fail. 2489(By default, only targets whose commands are interrupted during 2490execution are deleted. 2491This is the historical behavior.) 2492This setting can be used to help prevent half-finished or malformed 2493targets from being left around and corrupting future rebuilds. 2494.It Ic .END 2495Any command lines attached to this target are executed after everything 2496else is done successfully. 2497.It Ic .ERROR 2498Any command lines attached to this target are executed when another target fails. 2499See 2500.Va MAKE_PRINT_VAR_ON_ERROR 2501for the variables that will be set. 2502.It Ic .IGNORE 2503Mark each of the sources with the 2504.Ic .IGNORE 2505attribute. 2506If no sources are specified, this is the equivalent of specifying the 2507.Fl i 2508option. 2509.It Ic .INTERRUPT 2510If 2511.Nm 2512is interrupted, the commands for this target are executed. 2513.It Ic .MAIN 2514If no target is specified when 2515.Nm 2516is invoked, this target is built. 2517.It Ic .MAKEFLAGS 2518This target provides a way to specify flags for 2519.Nm 2520at the time when the makefiles are read. 2521The flags are as if typed to the shell, though the 2522.Fl f 2523option has 2524no effect. 2525.\" XXX: NOT YET!!!! 2526.\" .It Ic .NOTPARALLEL 2527.\" The named targets are executed in non parallel mode. 2528.\" If no targets are 2529.\" specified, all targets are executed in non parallel mode. 2530.It Ic .NOPATH 2531Apply the 2532.Ic .NOPATH 2533attribute to any specified sources. 2534.It Ic .NOTPARALLEL 2535Disable parallel mode. 2536.It Ic .NO_PARALLEL 2537Synonym for 2538.Ic .NOTPARALLEL , 2539for compatibility with other pmake variants. 2540.It Ic .NOREADONLY 2541clear the read-only attribute from the global variables specified as sources. 2542.It Ic .OBJDIR 2543The source is a new value for 2544.Sq Va .OBJDIR . 2545If it exists, 2546.Nm 2547changes the current working directory to it and updates the value of 2548.Sq Va .OBJDIR . 2549.It Ic .ORDER 2550In parallel mode, the named targets are made in sequence. 2551This ordering does not add targets to the list of targets to be made. 2552.Pp 2553Since the dependents of a target do not get built until the target itself 2554could be built, unless 2555.Ql a 2556is built by another part of the dependency graph, 2557the following is a dependency loop: 2558.Bd -literal 2559\&.ORDER: b a 2560b: a 2561.Ed 2562.Pp 2563.\" XXX: NOT YET!!!! 2564.\" .It Ic .PARALLEL 2565.\" The named targets are executed in parallel mode. 2566.\" If no targets are 2567.\" specified, all targets are executed in parallel mode. 2568.It Ic .PATH 2569The sources are directories which are to be searched for files not 2570found in the current directory. 2571If no sources are specified, 2572any previously specified directories are removed from the search path. 2573If the source is the special 2574.Ic .DOTLAST 2575target, the current working directory is searched last. 2576.It Ic .PATH. Ns Ar suffix 2577Like 2578.Ic .PATH 2579but applies only to files with a particular suffix. 2580The suffix must have been previously declared with 2581.Ic .SUFFIXES . 2582.It Ic .PHONY 2583Apply the 2584.Ic .PHONY 2585attribute to any specified sources. 2586.It Ic .POSIX 2587If this is the first non-comment line in the main makefile, 2588the variable 2589.Va %POSIX 2590is set to the value 2591.Ql 1003.2 2592and the makefile 2593.Ql <posix.mk> 2594is included if it exists, 2595to provide POSIX-compatible default rules. 2596If 2597.Nm 2598is run with the 2599.Fl r 2600flag, only 2601.Ql posix.mk 2602contributes to the default rules. 2603In POSIX-compatible mode, the AT&T System V UNIX style substitution 2604modifier is checked first rather than as a fallback. 2605.It Ic .PRECIOUS 2606Apply the 2607.Ic .PRECIOUS 2608attribute to any specified sources. 2609If no sources are specified, the 2610.Ic .PRECIOUS 2611attribute is applied to every target in the file. 2612.It Ic .READONLY 2613set the read-only attribute on the global variables specified as sources. 2614.It Ic .SHELL 2615Sets the shell that 2616.Nm 2617uses to execute commands. 2618The sources are a set of 2619.Ar field\| Ns Cm \&= Ns Ar value 2620pairs. 2621.Bl -tag -width ".Li hasErrCtls" 2622.It Li name 2623This is the minimal specification, used to select one of the built-in 2624shell specs; 2625.Li sh , 2626.Li ksh , 2627and 2628.Li csh . 2629.It Li path 2630Specifies the absolute path to the shell. 2631.It Li hasErrCtl 2632Indicates whether the shell supports exit on error. 2633.It Li check 2634The command to turn on error checking. 2635.It Li ignore 2636The command to disable error checking. 2637.It Li echo 2638The command to turn on echoing of commands executed. 2639.It Li quiet 2640The command to turn off echoing of commands executed. 2641.It Li filter 2642The output to filter after issuing the 2643.Li quiet 2644command. 2645It is typically identical to 2646.Li quiet . 2647.It Li errFlag 2648The flag to pass the shell to enable error checking. 2649.It Li echoFlag 2650The flag to pass the shell to enable command echoing. 2651.It Li newline 2652The string literal to pass the shell that results in a single newline 2653character when used outside of any quoting characters. 2654.El 2655Example: 2656.Bd -literal 2657\&.SHELL: name=ksh path=/bin/ksh hasErrCtl=true \e 2658 check="set \-e" ignore="set +e" \e 2659 echo="set \-v" quiet="set +v" filter="set +v" \e 2660 echoFlag=v errFlag=e newline="'\en'" 2661.Ed 2662.It Ic .SILENT 2663Apply the 2664.Ic .SILENT 2665attribute to any specified sources. 2666If no sources are specified, the 2667.Ic .SILENT 2668attribute is applied to every 2669command in the file. 2670.It Ic .STALE 2671This target gets run when a dependency file contains stale entries, having 2672.Va .ALLSRC 2673set to the name of that dependency file. 2674.It Ic .SUFFIXES 2675Each source specifies a suffix to 2676.Nm . 2677If no sources are specified, any previously specified suffixes are deleted. 2678It allows the creation of suffix-transformation rules. 2679.Pp 2680Example: 2681.Bd -literal 2682\&.SUFFIXES: .c .o 2683\&.c.o: 2684 cc \-o ${.TARGET} \-c ${.IMPSRC} 2685.Ed 2686.It Ic .SYSPATH 2687The sources are directories which are to be added to the system 2688include path which 2689.Nm 2690searches for makefiles. 2691If no sources are specified, 2692any previously specified directories are removed from the system 2693include path. 2694.El 2695.Sh ENVIRONMENT 2696.Nm 2697uses the following environment variables, if they exist: 2698.Ev MACHINE , 2699.Ev MACHINE_ARCH , 2700.Ev MAKE , 2701.Ev MAKEFLAGS , 2702.Ev MAKEOBJDIR , 2703.Ev MAKEOBJDIRPREFIX , 2704.Ev MAKESYSPATH , 2705.Ev MAKE_STACK_TRACE , 2706.Ev PWD , 2707and 2708.Ev TMPDIR . 2709.Pp 2710.Ev MAKEOBJDIRPREFIX 2711and 2712.Ev MAKEOBJDIR 2713should be set in the environment or on the command line to 2714.Nm 2715and not as makefile variables; 2716see the description of 2717.Sq Va .OBJDIR 2718for more details. 2719It is possible to set these via makefile variables but unless done 2720very early and the 2721.Sq Ic .OBJDIR 2722target is used to reset 2723.Sq Va .OBJDIR , 2724there may be unexpected side effects. 2725.Pp 2726If the 2727.Ev MAKE_STACK_TRACE 2728environment variable is set to 2729.Dq yes , 2730any stack traces include the call chain of the parent processes. 2731.\" .Sh EXIT STATUS 2732.\" .Sh ENVIRONMENT 2733.Sh FILES 2734.Bl -tag -width /usr/share/mk -compact 2735.It .depend 2736list of dependencies 2737.It makefile 2738first default makefile if no makefile is specified on the command line 2739.It Makefile 2740second default makefile if no makefile is specified on the command line 2741.It sys.mk 2742system makefile 2743.It /usr/share/mk 2744system makefile directory 2745.El 2746.\" .Sh EXAMPLES 2747.Sh DIAGNOSTICS 2748.Bl -tag 2749.It Dv Invalid internal option \(dq-J\(dq in \(dq Ns Ar directory Ns Dv \(dq 2750The internal 2751.Fl J 2752option coordinates the main 2753.Nm 2754process with the sub-make processes to limit 2755the number of jobs that run in parallel. 2756The option is passed to all child processes via the 2757.Ev MAKEFLAGS 2758environment variable. 2759To become valid, 2760this option requires that the target running the sub-make is marked with the 2761.Dv .MAKE 2762special source, 2763or that one of the target's commands directly contains the word 2764.Dq make 2765or one of the expressions 2766.Dq ${MAKE} , 2767.Dq ${.MAKE} , 2768.Dq $(MAKE) , 2769.Dq $(.MAKE) . 2770If that's not the case, 2771make issues the above warning and falls back to compat mode. 2772.Pp 2773To see the chain of sub-makes that leads to the invalid option, set the 2774.Ev MAKE_STACK_TRACE 2775environment variable to 2776.Dq yes . 2777.Pp 2778To run the sub-make in parallel mode, even in dry-run mode (see the 2779.Fl n 2780option), add the 2781.Dv .MAKE 2782pseudo source to the target. 2783This is appropriate when the sub-make runs the same target in a subdirectory. 2784.Pp 2785To run the sub-make in parallel mode but not in dry-mode, 2786add a 2787.Dq ${:D make} 2788marker to one of the target's commands. 2789This marker expands to an empty string 2790and thus does not affect the executed commands. 2791.\" The marker can even be added before any of the "@+-" modifiers, 2792.\" so no need to mention this explicitly. 2793.Pp 2794To run the sub-make in compat mode, add the 2795.Fl B 2796option to its invocation. 2797This is appropriate when the sub-make is only used to print a variable's 2798value using the 2799.Fl v 2800or 2801.Fl V 2802options. 2803.Pp 2804To make the sub-make independent from the parent make, unset the 2805.Ev MAKEFLAGS 2806environment variable in the target's commands. 2807.El 2808.Sh COMPATIBILITY 2809The basic make syntax is compatible between different make variants; 2810however the special variables, variable modifiers and conditionals are not. 2811.Ss Older versions 2812An incomplete list of changes in older versions of 2813.Nm : 2814.Pp 2815The way that .for loop variables are substituted changed after 2816.Nx 5.0 2817so that they still appear to be variable expansions. 2818In particular this stops them being treated as syntax, and removes some 2819obscure problems using them in .if statements. 2820.Pp 2821The way that parallel makes are scheduled changed in 2822.Nx 4.0 2823so that .ORDER and .WAIT apply recursively to the dependent nodes. 2824The algorithms used may change again in the future. 2825.Ss Other make dialects 2826Other make dialects (GNU make, SVR4 make, POSIX make, etc.) do not 2827support most of the features of 2828.Nm 2829as described in this manual. 2830Most notably: 2831.Bl -bullet -offset indent 2832.It 2833The 2834.Ic .WAIT 2835and 2836.Ic .ORDER 2837declarations and most functionality pertaining to parallelization. 2838(GNU make supports parallelization but lacks the features needed to 2839control it effectively.) 2840.It 2841Directives, including for loops and conditionals and most of the 2842forms of include files. 2843(GNU make has its own incompatible and less powerful syntax for 2844conditionals.) 2845.\" The "less powerful" above means that GNU make does not have the 2846.\" make(target), target(target) and commands(target) functions. 2847.It 2848All built-in variables that begin with a dot. 2849.It 2850Most of the special sources and targets that begin with a dot, 2851with the notable exception of 2852.Ic .PHONY , 2853.Ic .PRECIOUS , 2854and 2855.Ic .SUFFIXES . 2856.It 2857Variable modifiers, except for the 2858.Ql :old=new 2859string substitution, which does not portably support globbing with 2860.Ql % 2861and historically only works on declared suffixes. 2862.It 2863The 2864.Ic $> 2865variable even in its short form; most makes support this functionality 2866but its name varies. 2867.El 2868.Pp 2869Some features are somewhat more portable, such as assignment with 2870.Ic += , 2871.Ic ?= , 2872and 2873.Ic != . 2874The 2875.Va .PATH 2876functionality is based on an older feature 2877.Ic VPATH 2878found in GNU make and many versions of SVR4 make; however, 2879historically its behavior is too ill-defined (and too buggy) to rely 2880upon. 2881.Pp 2882The 2883.Ic $@ 2884and 2885.Ic $< 2886variables are more or less universally portable, as is the 2887.Ic $(MAKE) 2888variable. 2889Basic use of suffix rules (for files only in the current directory, 2890not trying to chain transformations together, etc.) is also reasonably 2891portable. 2892.Sh SEE ALSO 2893.Xr mkdep 1 , 2894.Xr style.Makefile 5 2895.\" .Sh STANDARDS 2896.Sh HISTORY 2897A 2898.Nm 2899command appeared in 2900.At v7 . 2901This 2902.Nm 2903implementation is based on Adam de Boor's pmake program, 2904which was written for Sprite at Berkeley. 2905It was designed to be a parallel distributed make running jobs on different 2906machines using a daemon called 2907.Dq customs . 2908.Pp 2909Historically the target/dependency 2910.Ic FRC 2911has been used to FoRCe rebuilding (since the target/dependency 2912does not exist ... unless someone creates an 2913.Pa FRC 2914file). 2915.\" .Sh AUTHORS 2916.\" .Sh CAVEATS 2917.Sh BUGS 2918The 2919.Nm 2920syntax is difficult to parse. 2921For instance, finding the end of a variable's use should involve scanning 2922each of the modifiers, using the correct terminator for each field. 2923In many places 2924.Nm 2925just counts {} and () in order to find the end of a variable expansion. 2926.Pp 2927There is no way of escaping a space character in a filename. 2928.Pp 2929In jobs mode, when a target fails; 2930.Nm 2931will put an error token into the job token pool. 2932This will cause all other instances of 2933.Nm 2934using that token pool to abort the build and exit with error code 6. 2935Sometimes the attempt to suppress a cascade of unnecessary errors, 2936can result in a seemingly unexplained 2937.Ql *** Error code 6 2938.\" .Sh SECURITY CONSIDERATIONS 2939