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