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