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