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