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