1.\" $NetBSD: make.1,v 1.182 2010/09/14 11:57:03 wiz 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 September 13, 2010 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 BeikNnqrstWX 41.Bk -words 42.Op Fl C Ar directory 43.Ek 44.Bk -words 45.Op Fl D Ar variable 46.Ek 47.Bk -words 48.Op Fl d Ar flags 49.Ek 50.Bk -words 51.Op Fl f Ar makefile 52.Ek 53.Bk -words 54.Op Fl I Ar directory 55.Ek 56.Bk -words 57.Op Fl J Ar private 58.Ek 59.Bk -words 60.Op Fl j Ar max_jobs 61.Ek 62.Bk -words 63.Op Fl m Ar directory 64.Ek 65.Bk -words 66.Op Fl T Ar file 67.Ek 68.Bk -words 69.Op Fl V Ar variable 70.Ek 71.Op Ar variable=value 72.Bk -words 73.Op Ar target ... 74.Ek 75.Sh DESCRIPTION 76.Nm 77is a program designed to simplify the maintenance of other programs. 78Its input is a list of specifications as to the files upon which programs 79and other files depend. 80If no 81.Fl f Ar makefile 82makefile option is given, 83.Nm 84will try to open 85.Ql Pa makefile 86then 87.Ql Pa Makefile 88in order to find the specifications. 89If the file 90.Ql Pa .depend 91exists, it is read (see 92.Xr mkdep 1 ) . 93.Pp 94This manual page is intended as a reference document only. 95For a more thorough description of 96.Nm 97and makefiles, please refer to 98.%T "Make \- A Tutorial" . 99.Pp 100.Nm 101will prepend the contents of the 102.Va MAKEFLAGS 103environment variable to the command line arguments before parsing them. 104.Pp 105The options are as follows: 106.Bl -tag -width Ds 107.It Fl B 108Try to be backwards compatible by executing a single shell per command and 109by executing the commands to make the sources of a dependency line in sequence. 110.It Fl C Ar directory 111Change to 112.Ar directory 113before reading the makefiles or doing anything else. 114If multiple 115.Fl C 116options are specified, each is interpreted relative to the previous one: 117.Fl C Pa / Fl C Pa etc 118is equivalent to 119.Fl C Pa /etc . 120.It Fl D Ar variable 121Define 122.Ar variable 123to be 1, in the global context. 124.It Fl d Ar [-]flags 125Turn on debugging, and specify which portions of 126.Nm 127are to print debugging information. 128Unless the flags are preceded by 129.Ql - 130they are added to the 131.Va MAKEFLAGS 132environment variable and will be processed by any child make processes. 133By default, debugging information is printed to standard error, 134but this can be changed using the 135.Ar F 136debugging flag. 137The debugging output is always unbuffered; in addition, if debugging 138is enabled but debugging output is not directed to standard output, 139then the standard output is line buffered. 140.Ar Flags 141is one or more of the following: 142.Bl -tag -width Ds 143.It Ar A 144Print all possible debugging information; 145equivalent to specifying all of the debugging flags. 146.It Ar a 147Print debugging information about archive searching and caching. 148.It Ar C 149Print debugging information about current working directory. 150.It Ar c 151Print debugging information about conditional evaluation. 152.It Ar d 153Print debugging information about directory searching and caching. 154.It Ar e 155Print debugging information about failed commands and targets. 156.It Ar F Ns Oo Sy \&+ Oc Ns Ar filename 157Specify where debugging output is written. 158This must be the last flag, because it consumes the remainder of 159the argument. 160If the character immediately after the 161.Ql F 162flag is 163.Ql \&+ , 164then the file will be opened in append mode; 165otherwise the file will be overwritten. 166If the file name is 167.Ql stdout 168or 169.Ql stderr 170then debugging output will be written to the 171standard output or standard error output file descriptors respectively 172(and the 173.Ql \&+ 174option has no effect). 175Otherwise, the output will be written to the named file. 176If the file name ends 177.Ql .%d 178then the 179.Ql %d 180is replaced by the pid. 181.It Ar f 182Print debugging information about loop evaluation. 183.It Ar "g1" 184Print the input graph before making anything. 185.It Ar "g2" 186Print the input graph after making everything, or before exiting 187on error. 188.It Ar "g3" 189Print the input graph before exiting on error. 190.It Ar j 191Print debugging information about running multiple shells. 192.It Ar l 193Print commands in Makefiles regardless of whether or not they are prefixed by 194.Ql @ 195or other "quiet" flags. 196Also known as "loud" behavior. 197.It Ar M 198Print debugging information about "meta" mode decisions about targets. 199.It Ar m 200Print debugging information about making targets, including modification 201dates. 202.It Ar n 203Don't delete the temporary command scripts created when running commands. 204These temporary scripts are created in the directory 205referred to by the 206.Ev TMPDIR 207environment variable, or in 208.Pa /tmp 209if 210.Ev TMPDIR 211is unset or set to the empty string. 212The temporary scripts are created by 213.Xr mkstemp 3 , 214and have names of the form 215.Pa makeXXXXXX . 216.Em NOTE : 217This can create many files in 218.Ev TMPDIR 219or 220.Pa /tmp , 221so use with care. 222.It Ar p 223Print debugging information about makefile parsing. 224.It Ar s 225Print debugging information about suffix-transformation rules. 226.It Ar t 227Print debugging information about target list maintenance. 228.It Ar v 229Print debugging information about variable assignment. 230.It Ar x 231Run shell commands with 232.Fl x 233so the actual commands are printed as they are executed. 234.El 235.It Fl e 236Specify that environment variables override macro assignments within 237makefiles. 238.It Fl f Ar makefile 239Specify a makefile to read instead of the default 240.Ql Pa makefile . 241If 242.Ar makefile 243is 244.Ql Fl , 245standard input is read. 246Multiple makefiles may be specified, and are read in the order specified. 247.It Fl I Ar directory 248Specify a directory in which to search for makefiles and included makefiles. 249The system makefile directory (or directories, see the 250.Fl m 251option) is automatically included as part of this list. 252.It Fl i 253Ignore non-zero exit of shell commands in the makefile. 254Equivalent to specifying 255.Ql Fl 256before each command line in the makefile. 257.It Fl J Ar private 258This option should 259.Em not 260be specified by the user. 261.Pp 262When the 263.Ar j 264option is in use in a recursive build, this option is passed by a make 265to child makes to allow all the make processes in the build to 266cooperate to avoid overloading the system. 267.It Fl j Ar max_jobs 268Specify the maximum number of jobs that 269.Nm 270may have running at any one time. 271The value is saved in 272.Va .MAKE.JOBS . 273Turns compatibility mode off, unless the 274.Ar B 275flag is also specified. 276When compatibility mode is off, all commands associated with a 277target are executed in a single shell invocation as opposed to the 278traditional one shell invocation per line. 279This can break traditional scripts which change directories on each 280command invocation and then expect to start with a fresh environment 281on the next line. 282It is more efficient to correct the scripts rather than turn backwards 283compatibility on. 284.It Fl k 285Continue processing after errors are encountered, but only on those targets 286that do not depend on the target whose creation caused the error. 287.It Fl m Ar directory 288Specify a directory in which to search for sys.mk and makefiles included 289via the 290.Ao Ar file Ac Ns -style 291include statement. 292The 293.Fl m 294option can be used multiple times to form a search path. 295This path will override the default system include path: /usr/share/mk. 296Furthermore the system include path will be appended to the search path used 297for 298.Qo Ar file Qc Ns -style 299include statements (see the 300.Fl I 301option). 302.Pp 303If a file or directory name in the 304.Fl m 305argument (or the 306.Ev MAKESYSPATH 307environment variable) starts with the string 308.Qq \&.../ 309then 310.Nm 311will search for the specified file or directory named in the remaining part 312of the argument string. 313The search starts with the current directory of 314the Makefile and then works upward towards the root of the filesystem. 315If the search is successful, then the resulting directory replaces the 316.Qq \&.../ 317specification in the 318.Fl m 319argument. 320If used, this feature allows 321.Nm 322to easily search in the current source tree for customized sys.mk files 323(e.g., by using 324.Qq \&.../mk/sys.mk 325as an argument). 326.It Fl n 327Display the commands that would have been executed, but do not 328actually execute them unless the target depends on the .MAKE special 329source (see below). 330.It Fl N 331Display the commands which would have been executed, but do not 332actually execute any of them; useful for debugging top-level makefiles 333without descending into subdirectories. 334.It Fl q 335Do not execute any commands, but exit 0 if the specified targets are 336up-to-date and 1, otherwise. 337.It Fl r 338Do not use the built-in rules specified in the system makefile. 339.It Fl s 340Do not echo any commands as they are executed. 341Equivalent to specifying 342.Ql Ic @ 343before each command line in the makefile. 344.It Fl T Ar tracefile 345When used with the 346.Fl j 347flag, 348append a trace record to 349.Ar tracefile 350for each job started and completed. 351.It Fl t 352Rather than re-building a target as specified in the makefile, create it 353or update its modification time to make it appear up-to-date. 354.It Fl V Ar variable 355Print 356.Nm Ns 's 357idea of the value of 358.Ar variable , 359in the global context. 360Do not build any targets. 361Multiple instances of this option may be specified; 362the variables will be printed one per line, 363with a blank line for each null or undefined variable. 364If 365.Ar variable 366contains a 367.Ql \&$ 368then the value will be expanded before printing. 369.It Fl W 370Treat any warnings during makefile parsing as errors. 371.It Fl X 372Don't export variables passed on the command line to the environment 373individually. 374Variables passed on the command line are still exported 375via the 376.Va MAKEFLAGS 377environment variable. 378This option may be useful on systems which have a small limit on the 379size of command arguments. 380.It Ar variable=value 381Set the value of the variable 382.Ar variable 383to 384.Ar value . 385Normally, all values passed on the command line are also exported to 386sub-makes in the environment. 387The 388.Fl X 389flag disables this behavior. 390Variable assignments should follow options for POSIX compatibility 391but no ordering is enforced. 392.El 393.Pp 394There are seven different types of lines in a makefile: file dependency 395specifications, shell commands, variable assignments, include statements, 396conditional directives, for loops, and comments. 397.Pp 398In general, lines may be continued from one line to the next by ending 399them with a backslash 400.Pq Ql \e . 401The trailing newline character and initial whitespace on the following 402line are compressed into a single space. 403.Sh FILE DEPENDENCY SPECIFICATIONS 404Dependency lines consist of one or more targets, an operator, and zero 405or more sources. 406This creates a relationship where the targets 407.Dq depend 408on the sources 409and are usually created from them. 410The exact relationship between the target and the source is determined 411by the operator that separates them. 412The three operators are as follows: 413.Bl -tag -width flag 414.It Ic \&: 415A target is considered out-of-date if its modification time is less than 416those of any of its sources. 417Sources for a target accumulate over dependency lines when this operator 418is used. 419The target is removed if 420.Nm 421is interrupted. 422.It Ic \&! 423Targets are always re-created, but not until all sources have been 424examined and re-created as necessary. 425Sources for a target accumulate over dependency lines when this operator 426is used. 427The target is removed if 428.Nm 429is interrupted. 430.It Ic \&:: 431If no sources are specified, the target is always re-created. 432Otherwise, a target is considered out-of-date if any of its sources has 433been modified more recently than the target. 434Sources for a target do not accumulate over dependency lines when this 435operator is used. 436The target will not be removed if 437.Nm 438is interrupted. 439.El 440.Pp 441Targets and sources may contain the shell wildcard values 442.Ql \&? , 443.Ql * , 444.Ql [] , 445and 446.Ql {} . 447The values 448.Ql \&? , 449.Ql * , 450and 451.Ql [] 452may only be used as part of the final 453component of the target or source, and must be used to describe existing 454files. 455The value 456.Ql {} 457need not necessarily be used to describe existing files. 458Expansion is in directory order, not alphabetically as done in the shell. 459.Sh SHELL COMMANDS 460Each target may have associated with it a series of shell commands, normally 461used to create the target. 462Each of the commands in this script 463.Em must 464be preceded by a tab. 465While any target may appear on a dependency line, only one of these 466dependencies may be followed by a creation script, unless the 467.Ql Ic \&:: 468operator is used. 469.Pp 470If the first characters of the command line are any combination of 471.Ql Ic @ , 472.Ql Ic + , 473or 474.Ql Ic \- , 475the command is treated specially. 476A 477.Ql Ic @ 478causes the command not to be echoed before it is executed. 479A 480.Ql Ic + 481causes the command to be executed even when 482.Fl n 483is given. 484This is similar to the effect of the .MAKE special source, 485except that the effect can be limited to a single line of a script. 486A 487.Ql Ic \- 488causes any non-zero exit status of the command line to be ignored. 489.Sh VARIABLE ASSIGNMENTS 490Variables in make are much like variables in the shell, and, by tradition, 491consist of all upper-case letters. 492.Ss Variable assignment modifiers 493The five operators that can be used to assign values to variables are as 494follows: 495.Bl -tag -width Ds 496.It Ic \&= 497Assign the value to the variable. 498Any previous value is overridden. 499.It Ic \&+= 500Append the value to the current value of the variable. 501.It Ic \&?= 502Assign the value to the variable if it is not already defined. 503.It Ic \&:= 504Assign with expansion, i.e. expand the value before assigning it 505to the variable. 506Normally, expansion is not done until the variable is referenced. 507.Em NOTE : 508References to undefined variables are 509.Em not 510expanded. 511This can cause problems when variable modifiers are used. 512.It Ic \&!= 513Expand the value and pass it to the shell for execution and assign 514the result to the variable. 515Any newlines in the result are replaced with spaces. 516.El 517.Pp 518Any white-space before the assigned 519.Ar value 520is removed; if the value is being appended, a single space is inserted 521between the previous contents of the variable and the appended value. 522.Pp 523Variables are expanded by surrounding the variable name with either 524curly braces 525.Pq Ql {} 526or parentheses 527.Pq Ql () 528and preceding it with 529a dollar sign 530.Pq Ql \&$ . 531If the variable name contains only a single letter, the surrounding 532braces or parentheses are not required. 533This shorter form is not recommended. 534.Pp 535If the variable name contains a dollar, then the name itself is expanded first. 536This allows almost arbitrary variable names, however names containing dollar, 537braces, parenthesis, or whitespace are really best avoided! 538.Pp 539If the result of expanding a variable contains a dollar sign 540.Pq Ql \&$ 541the string is expanded again. 542.Pp 543Variable substitution occurs at three distinct times, depending on where 544the variable is being used. 545.Bl -enum 546.It 547Variables in dependency lines are expanded as the line is read. 548.It 549Variables in shell commands are expanded when the shell command is 550executed. 551.It 552.Dq .for 553loop index variables are expanded on each loop iteration. 554Note that other variables are not expanded inside loops so 555the following example code: 556.Bd -literal -offset indent 557 558.Dv .for i in 1 2 3 559a+= ${i} 560j= ${i} 561b+= ${j} 562.Dv .endfor 563 564all: 565 @echo ${a} 566 @echo ${b} 567 568.Ed 569will print: 570.Bd -literal -offset indent 5711 2 3 5723 3 3 573 574.Ed 575Because while ${a} contains 576.Dq 1 2 3 577after the loop is executed, ${b} 578contains 579.Dq ${j} ${j} ${j} 580which expands to 581.Dq 3 3 3 582since after the loop completes ${j} contains 583.Dq 3 . 584.El 585.Ss Variable classes 586The four different classes of variables (in order of increasing precedence) 587are: 588.Bl -tag -width Ds 589.It Environment variables 590Variables defined as part of 591.Nm Ns 's 592environment. 593.It Global variables 594Variables defined in the makefile or in included makefiles. 595.It Command line variables 596Variables defined as part of the command line. 597.It Local variables 598Variables that are defined specific to a certain target. 599The seven local variables are as follows: 600.Bl -tag -width ".ARCHIVE" 601.It Va .ALLSRC 602The list of all sources for this target; also known as 603.Ql Va \&\*[Gt] . 604.It Va .ARCHIVE 605The name of the archive file. 606.It Va .IMPSRC 607In suffix-transformation rules, the name/path of the source from which the 608target is to be transformed (the 609.Dq implied 610source); also known as 611.Ql Va \&\*[Lt] . 612It is not defined in explicit rules. 613.It Va .MEMBER 614The name of the archive member. 615.It Va .OODATE 616The list of sources for this target that were deemed out-of-date; also 617known as 618.Ql Va \&? . 619.It Va .PREFIX 620The file prefix of the target, containing only the file portion, no suffix 621or preceding directory components; also known as 622.Ql Va * . 623.It Va .TARGET 624The name of the target; also known as 625.Ql Va @ . 626.El 627.Pp 628The shorter forms 629.Ql Va @ , 630.Ql Va \&? , 631.Ql Va \&\*[Lt] , 632.Ql Va \&\*[Gt] , 633and 634.Ql Va * 635are permitted for backward 636compatibility with historical makefiles and are not recommended. 637The six variables 638.Ql Va "@F" , 639.Ql Va "@D" , 640.Ql Va "\*[Lt]F" , 641.Ql Va "\*[Lt]D" , 642.Ql Va "*F" , 643and 644.Ql Va "*D" 645are permitted for compatibility with 646.At V 647makefiles and are not recommended. 648.Pp 649Four of the local variables may be used in sources on dependency lines 650because they expand to the proper value for each target on the line. 651These variables are 652.Ql Va .TARGET , 653.Ql Va .PREFIX , 654.Ql Va .ARCHIVE , 655and 656.Ql Va .MEMBER . 657.El 658.Ss Additional built-in variables 659In addition, 660.Nm 661sets or knows about the following variables: 662.Bl -tag -width .MAKEOVERRIDES 663.It Va \&$ 664A single dollar sign 665.Ql \&$ , 666i.e. 667.Ql \&$$ 668expands to a single dollar 669sign. 670.It Va .ALLTARGETS 671The list of all targets encountered in the Makefile. 672If evaluated during 673Makefile parsing, lists only those targets encountered thus far. 674.It Va .CURDIR 675A path to the directory where 676.Nm 677was executed. 678Refer to the description of 679.Ql Ev PWD 680for more details. 681.It Ev MAKE 682The name that 683.Nm 684was executed with 685.Pq Va argv[0] . 686For compatibility 687.Nm 688also sets 689.Va .MAKE 690with the same value. 691The preferred variable to use is the environment variable 692.Ev MAKE 693because it is more compatible with other versions of 694.Nm 695and cannot be confused with the special target with the same name. 696.It Va .MAKE.DEPENDFILE 697Names the makefile (default 698.Ql Pa .depend ) 699from which generated dependencies are read. 700.It Va .MAKE.EXPORTED 701The list of variables exported by 702.Nm . 703.It Va .MAKE.JOBS 704The argument to the 705.Fl j 706option. 707.It Va .MAKE.JOB.PREFIX 708If 709.Nm 710is run with 711.Ar j 712then output for each target is prefixed with a token 713.Ql --- target --- 714the first part of which can be controlled via 715.Va .MAKE.JOB.PREFIX . 716.br 717For example: 718.Li .MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}] 719would produce tokens like 720.Ql ---make[1234] target --- 721making it easier to track the degree of parallelism being achieved. 722.It Ev MAKEFLAGS 723The environment variable 724.Ql Ev MAKEFLAGS 725may contain anything that 726may be specified on 727.Nm Ns 's 728command line. 729Anything specified on 730.Nm Ns 's 731command line is appended to the 732.Ql Ev MAKEFLAGS 733variable which is then 734entered into the environment for all programs which 735.Nm 736executes. 737.It Va .MAKE.LEVEL 738The recursion depth of 739.Nm . 740The initial instance of 741.Nm 742will be 0, and an incremented value is put into the environment 743to be seen by the next generation. 744This allows tests like: 745.Li .if ${.MAKE.LEVEL} == 0 746to protect things which should only be evaluated in the initial instance of 747.Nm . 748.It Va .MAKE.MAKEFILE_PREFERENCE 749The ordered list of makefile names 750(default 751.Ql Pa makefile , 752.Ql Pa Makefile ) 753that 754.Nm 755will look for. 756.It Va .MAKE.MAKEFILES 757The list of makefiles read by 758.Nm , 759which is useful for tracking dependencies. 760Each makefile is recorded only once, regardless of the number of times read. 761.It Va .MAKE.MODE 762Processed after reading all makefiles. 763Can affect the mode that 764.Nm 765runs in. 766It can contain a number of keywords: 767.Bl -hang -width ignore-cmd 768.It Pa compat 769Like 770.Fl B 771puts 772.Nm 773into "compat" mode. 774.It Pa meta 775Puts 776.Nm 777into "meta" mode, where meta files are created for each target 778to capture the command run, the output generated and if 779.Xr filemon 4 780is available, the system calls which are of interest to 781.Nm . 782The captured output can be very useful when diagnosing errors. 783.It Pa verbose 784If in "meta" mode, print a clue about the target being built. 785This is useful if the build is otherwise running silently. 786The message printed the value of: 787.Va .MAKE.META.PREFIX . 788.It Pa ignore-cmd 789Some makefiles have commands which are simply not stable. 790This keyword causes them to be ignored for 791determining whether a target is out of date in "meta" mode. 792See also 793.Ic .NOMETA_CMP . 794.El 795.It Va .MAKE.META.CREATED 796In "meta" mode, this variable contains a list of all the meta files 797updated. 798If not empty, it can be used to trigger processing of 799.Va .MAKE.META.FILES . 800.It Va .MAKE.META.FILES 801In "meta" mode, this variable contains a list of all the meta files 802used (updated or not). 803This list can be used to process the meta files to extract dependency 804information. 805.It Va .MAKE.META.PREFIX 806Defines the message printed for each meta file updated in "meta verbose" mode. 807The default value is: 808.Dl Building ${.TARGET:H:tA}/${.TARGET:T} 809.It Va .MAKEOVERRIDES 810This variable is used to record the names of variables assigned to 811on the command line, so that they may be exported as part of 812.Ql Ev MAKEFLAGS . 813This behaviour can be disabled by assigning an empty value to 814.Ql Va .MAKEOVERRIDES 815within a makefile. 816Extra variables can be exported from a makefile 817by appending their names to 818.Ql Va .MAKEOVERRIDES . 819.Ql Ev MAKEFLAGS 820is re-exported whenever 821.Ql Va .MAKEOVERRIDES 822is modified. 823.It Va .MAKE.PID 824The process-id of 825.Nm . 826.It Va .MAKE.PPID 827The parent process-id of 828.Nm . 829.It Va MAKE_PRINT_VAR_ON_ERROR 830When 831.Nm 832stops due to an error, it prints its name and the value of 833.Ql Va .CURDIR 834as well as the value of any variables named in 835.Ql Va MAKE_PRINT_VAR_ON_ERROR . 836.It Va .newline 837This variable is simply assigned a newline character as its value. 838This allows expansions using the 839.Cm \&:@ 840modifier to put a newline between 841iterations of the loop rather than a space. 842For example, the printing of 843.Ql Va MAKE_PRINT_VAR_ON_ERROR 844could be done as ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}. 845.It Va .OBJDIR 846A path to the directory where the targets are built. 847Its value is determined by trying to 848.Xr chdir 2 849to the following directories in order and using the first match: 850.Bl -enum 851.It 852.Ev ${MAKEOBJDIRPREFIX}${.CURDIR} 853.Pp 854(Only if 855.Ql Ev MAKEOBJDIRPREFIX 856is set in the environment or on the command line.) 857.It 858.Ev ${MAKEOBJDIR} 859.Pp 860(Only if 861.Ql Ev MAKEOBJDIR 862is set in the environment or on the command line.) 863.It 864.Ev ${.CURDIR} Ns Pa /obj. Ns Ev ${MACHINE} 865.It 866.Ev ${.CURDIR} Ns Pa /obj 867.It 868.Pa /usr/obj/ Ns Ev ${.CURDIR} 869.It 870.Ev ${.CURDIR} 871.El 872.Pp 873Variable expansion is performed on the value before it's used, 874so expressions such as 875.Dl ${.CURDIR:S,^/usr/src,/var/obj,} 876may be used. 877This is especially useful with 878.Ql Ev MAKEOBJDIR . 879.Pp 880.Ql Va .OBJDIR 881may be modified in the makefile as a global variable. 882In all cases, 883.Nm 884will 885.Xr chdir 2 886to 887.Ql Va .OBJDIR 888and set 889.Ql Ev PWD 890to that directory before executing any targets. 891. 892.It Va .PARSEDIR 893A path to the directory of the current 894.Ql Pa Makefile 895being parsed. 896.It Va .PARSEFILE 897The basename of the current 898.Ql Pa Makefile 899being parsed. 900This variable and 901.Ql Va .PARSEDIR 902are both set only while the 903.Ql Pa Makefiles 904are being parsed. 905.It Va .PATH 906A variable that represents the list of directories that 907.Nm 908will search for files. 909The search list should be updated using the target 910.Ql Va .PATH 911rather than the variable. 912.It Ev PWD 913Alternate path to the current directory. 914.Nm 915normally sets 916.Ql Va .CURDIR 917to the canonical path given by 918.Xr getcwd 3 . 919However, if the environment variable 920.Ql Ev PWD 921is set and gives a path to the current directory, then 922.Nm 923sets 924.Ql Va .CURDIR 925to the value of 926.Ql Ev PWD 927instead. 928This behaviour is disabled if 929.Ql Ev MAKEOBJDIRPREFIX 930is set or 931.Ql Ev MAKEOBJDIR 932contains a variable transform. 933.Ql Ev PWD 934is set to the value of 935.Ql Va .OBJDIR 936for all programs which 937.Nm 938executes. 939.It Ev .TARGETS 940The list of targets explicitly specified on the command line, if any. 941.It Ev VPATH 942Colon-separated 943.Pq Dq \&: 944lists of directories that 945.Nm 946will search for files. 947The variable is supported for compatibility with old make programs only, 948use 949.Ql Va .PATH 950instead. 951.El 952.Ss Variable modifiers 953Variable expansion may be modified to select or modify each word of the 954variable (where a 955.Dq word 956is white-space delimited sequence of characters). 957The general format of a variable expansion is as follows: 958.Pp 959.Dl ${variable[:modifier[:...]]} 960.Pp 961Each modifier begins with a colon, 962which may be escaped with a backslash 963.Pq Ql \e . 964.Pp 965A set of modifiers can be specified via a variable, as follows: 966.Pp 967.Dl modifier_variable=modifier[:...] 968.Dl ${variable:${modifier_variable}[:...]} 969.Pp 970In this case the first modifier in the modifier_variable does not 971start with a colon, since that must appear in the referencing 972variable. 973If any of the modifiers in the modifier_variable contain a dollar sign 974.Pq Ql $ , 975these must be doubled to avoid early expansion. 976.Pp 977The supported modifiers are: 978.Bl -tag -width EEE 979.It Cm \&:E 980Replaces each word in the variable with its suffix. 981.It Cm \&:H 982Replaces each word in the variable with everything but the last component. 983.It Cm \&:M Ns Ar pattern 984Select only those words that match 985.Ar pattern . 986The standard shell wildcard characters 987.Pf ( Ql * , 988.Ql \&? , 989and 990.Ql Oo Oc ) 991may 992be used. 993The wildcard characters may be escaped with a backslash 994.Pq Ql \e . 995.It Cm \&:N Ns Ar pattern 996This is identical to 997.Ql Cm \&:M , 998but selects all words which do not match 999.Ar pattern . 1000.It Cm \&:O 1001Order every word in variable alphabetically. 1002To sort words in 1003reverse order use the 1004.Ql Cm \&:O:[-1..1] 1005combination of modifiers. 1006.It Cm \&:Ox 1007Randomize words in variable. 1008The results will be different each time you are referring to the 1009modified variable; use the assignment with expansion 1010.Pq Ql Cm \&:= 1011to prevent such behaviour. 1012For example, 1013.Bd -literal -offset indent 1014LIST= uno due tre quattro 1015RANDOM_LIST= ${LIST:Ox} 1016STATIC_RANDOM_LIST:= ${LIST:Ox} 1017 1018all: 1019 @echo "${RANDOM_LIST}" 1020 @echo "${RANDOM_LIST}" 1021 @echo "${STATIC_RANDOM_LIST}" 1022 @echo "${STATIC_RANDOM_LIST}" 1023.Ed 1024may produce output similar to: 1025.Bd -literal -offset indent 1026quattro due tre uno 1027tre due quattro uno 1028due uno quattro tre 1029due uno quattro tre 1030.Ed 1031.It Cm \&:Q 1032Quotes every shell meta-character in the variable, so that it can be passed 1033safely through recursive invocations of 1034.Nm . 1035.It Cm \&:R 1036Replaces each word in the variable with everything but its suffix. 1037.It Cm \&:tA 1038Attempt to convert variable to an absolute path using 1039.Xr realpath 3 , 1040if that fails, the value is unchanged. 1041.It Cm \&:tl 1042Converts variable to lower-case letters. 1043.It Cm \&:ts Ns Ar c 1044Words in the variable are normally separated by a space on expansion. 1045This modifier sets the separator to the character 1046.Ar c . 1047If 1048.Ar c 1049is omitted, then no separator is used. 1050The common escapes (including octal numeric codes), work as expected. 1051.It Cm \&:tu 1052Converts variable to upper-case letters. 1053.It Cm \&:tW 1054Causes the value to be treated as a single word 1055(possibly containing embedded white space). 1056See also 1057.Ql Cm \&:[*] . 1058.It Cm \&:tw 1059Causes the value to be treated as a sequence of 1060words delimited by white space. 1061See also 1062.Ql Cm \&:[@] . 1063.Sm off 1064.It Cm \&:S No \&/ Ar old_string No \&/ Ar new_string No \&/ Op Cm 1gW 1065.Sm on 1066Modify the first occurrence of 1067.Ar old_string 1068in the variable's value, replacing it with 1069.Ar new_string . 1070If a 1071.Ql g 1072is appended to the last slash of the pattern, all occurrences 1073in each word are replaced. 1074If a 1075.Ql 1 1076is appended to the last slash of the pattern, only the first word 1077is affected. 1078If a 1079.Ql W 1080is appended to the last slash of the pattern, 1081then the value is treated as a single word 1082(possibly containing embedded white space). 1083If 1084.Ar old_string 1085begins with a caret 1086.Pq Ql ^ , 1087.Ar old_string 1088is anchored at the beginning of each word. 1089If 1090.Ar old_string 1091ends with a dollar sign 1092.Pq Ql \&$ , 1093it is anchored at the end of each word. 1094Inside 1095.Ar new_string , 1096an ampersand 1097.Pq Ql \*[Am] 1098is replaced by 1099.Ar old_string 1100(without any 1101.Ql ^ 1102or 1103.Ql \&$ ) . 1104Any character may be used as a delimiter for the parts of the modifier 1105string. 1106The anchoring, ampersand and delimiter characters may be escaped with a 1107backslash 1108.Pq Ql \e . 1109.Pp 1110Variable expansion occurs in the normal fashion inside both 1111.Ar old_string 1112and 1113.Ar new_string 1114with the single exception that a backslash is used to prevent the expansion 1115of a dollar sign 1116.Pq Ql \&$ , 1117not a preceding dollar sign as is usual. 1118.Sm off 1119.It Cm \&:C No \&/ Ar pattern No \&/ Ar replacement No \&/ Op Cm 1gW 1120.Sm on 1121The 1122.Cm \&:C 1123modifier is just like the 1124.Cm \&:S 1125modifier except that the old and new strings, instead of being 1126simple strings, are a regular expression (see 1127.Xr regex 3 ) 1128string 1129.Ar pattern 1130and an 1131.Xr ed 1 Ns \-style 1132string 1133.Ar replacement . 1134Normally, the first occurrence of the pattern 1135.Ar pattern 1136in each word of the value is substituted with 1137.Ar replacement . 1138The 1139.Ql 1 1140modifier causes the substitution to apply to at most one word; the 1141.Ql g 1142modifier causes the substitution to apply to as many instances of the 1143search pattern 1144.Ar pattern 1145as occur in the word or words it is found in; the 1146.Ql W 1147modifier causes the value to be treated as a single word 1148(possibly containing embedded white space). 1149Note that 1150.Ql 1 1151and 1152.Ql g 1153are orthogonal; the former specifies whether multiple words are 1154potentially affected, the latter whether multiple substitutions can 1155potentially occur within each affected word. 1156.It Cm \&:T 1157Replaces each word in the variable with its last component. 1158.It Cm \&:u 1159Remove adjacent duplicate words (like 1160.Xr uniq 1 ) . 1161.Sm off 1162.It Cm \&:\&? Ar true_string Cm \&: Ar false_string 1163.Sm on 1164If the variable name (not its value), when parsed as a .if conditional 1165expression, evaluates to true, return as its value the 1166.Ar true_string , 1167otherwise return the 1168.Ar false_string . 1169Since the variable name is used as the expression, \&:\&? must be the 1170first modifier after the variable name itself - which will, of course, 1171usually contain variable expansions. 1172A common error is trying to use expressions like 1173.Dl ${NUMBERS:M42:?match:no} 1174which actually tests defined(NUMBERS), 1175to determine is any words match "42" you need to use something like: 1176.Dl ${${NUMBERS:M42} != "":?match:no} . 1177.It Ar :old_string=new_string 1178This is the 1179.At V 1180style variable substitution. 1181It must be the last modifier specified. 1182If 1183.Ar old_string 1184or 1185.Ar new_string 1186do not contain the pattern matching character 1187.Ar % 1188then it is assumed that they are 1189anchored at the end of each word, so only suffixes or entire 1190words may be replaced. 1191Otherwise 1192.Ar % 1193is the substring of 1194.Ar old_string 1195to be replaced in 1196.Ar new_string . 1197.Pp 1198Variable expansion occurs in the normal fashion inside both 1199.Ar old_string 1200and 1201.Ar new_string 1202with the single exception that a backslash is used to prevent the 1203expansion of a dollar sign 1204.Pq Ql \&$ , 1205not a preceding dollar sign as is usual. 1206.Sm off 1207.It Cm \&:@ Ar temp Cm @ Ar string Cm @ 1208.Sm on 1209This is the loop expansion mechanism from the OSF Development 1210Environment (ODE) make. 1211Unlike 1212.Cm \&.for 1213loops expansion occurs at the time of 1214reference. 1215Assign 1216.Ar temp 1217to each word in the variable and evaluate 1218.Ar string . 1219The ODE convention is that 1220.Ar temp 1221should start and end with a period. 1222For example. 1223.Dl ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@} 1224.It Cm \&:U Ns Ar newval 1225If the variable is undefined 1226.Ar newval 1227is the value. 1228If the variable is defined, the existing value is returned. 1229This is another ODE make feature. 1230It is handy for setting per-target CFLAGS for instance: 1231.Dl ${_${.TARGET:T}_CFLAGS:U${DEF_CFLAGS}} 1232If a value is only required if the variable is undefined, use: 1233.Dl ${VAR:D:Unewval} 1234.It Cm \&:D Ns Ar newval 1235If the variable is defined 1236.Ar newval 1237is the value. 1238.It Cm \&:L 1239The name of the variable is the value. 1240.It Cm \&:P 1241The path of the node which has the same name as the variable 1242is the value. 1243If no such node exists or its path is null, then the 1244name of the variable is used. 1245.Sm off 1246.It Cm \&:\&! Ar cmd Cm \&! 1247.Sm on 1248The output of running 1249.Ar cmd 1250is the value. 1251.It Cm \&:sh 1252If the variable is non-empty it is run as a command and the output 1253becomes the new value. 1254.It Cm \&::= Ns Ar str 1255The variable is assigned the value 1256.Ar str 1257after substitution. 1258This modifier and its variations are useful in 1259obscure situations such as wanting to set a variable when shell commands 1260are being parsed. 1261These assignment modifiers always expand to 1262nothing, so if appearing in a rule line by themselves should be 1263preceded with something to keep 1264.Nm 1265happy. 1266.Pp 1267The 1268.Ql Cm \&:: 1269helps avoid false matches with the 1270.At V 1271style 1272.Cm \&:= 1273modifier and since substitution always occurs the 1274.Cm \&::= 1275form is vaguely appropriate. 1276.It Cm \&::?= Ns Ar str 1277As for 1278.Cm \&::= 1279but only if the variable does not already have a value. 1280.It Cm \&::+= Ns Ar str 1281Append 1282.Ar str 1283to the variable. 1284.It Cm \&::!= Ns Ar cmd 1285Assign the output of 1286.Ar cmd 1287to the variable. 1288.It Cm \&:\&[ Ns Ar range Ns Cm \&] 1289Selects one or more words from the value, 1290or performs other operations related to the way in which the 1291value is divided into words. 1292.Pp 1293Ordinarily, a value is treated as a sequence of words 1294delimited by white space. 1295Some modifiers suppress this behaviour, 1296causing a value to be treated as a single word 1297(possibly containing embedded white space). 1298An empty value, or a value that consists entirely of white-space, 1299is treated as a single word. 1300For the purposes of the 1301.Ql Cm \&:[] 1302modifier, the words are indexed both forwards using positive integers 1303(where index 1 represents the first word), 1304and backwards using negative integers 1305(where index -1 represents the last word). 1306.Pp 1307The 1308.Ar range 1309is subjected to variable expansion, and the expanded result is 1310then interpreted as follows: 1311.Bl -tag -width index 1312.\" :[n] 1313.It Ar index 1314Selects a single word from the value. 1315.\" :[start..end] 1316.It Ar start Ns Cm \&.. Ns Ar end 1317Selects all words from 1318.Ar start 1319to 1320.Ar end , 1321inclusive. 1322For example, 1323.Ql Cm \&:[2..-1] 1324selects all words from the second word to the last word. 1325If 1326.Ar start 1327is greater than 1328.Ar end , 1329then the words are output in reverse order. 1330For example, 1331.Ql Cm \&:[-1..1] 1332selects all the words from last to first. 1333.\" :[*] 1334.It Cm \&* 1335Causes subsequent modifiers to treat the value as a single word 1336(possibly containing embedded white space). 1337Analogous to the effect of 1338\&"$*\&" 1339in Bourne shell. 1340.\" :[0] 1341.It 0 1342Means the same as 1343.Ql Cm \&:[*] . 1344.\" :[*] 1345.It Cm \&@ 1346Causes subsequent modifiers to treat the value as a sequence of words 1347delimited by white space. 1348Analogous to the effect of 1349\&"$@\&" 1350in Bourne shell. 1351.\" :[#] 1352.It Cm \&# 1353Returns the number of words in the value. 1354.El \" :[range] 1355.El 1356.Sh INCLUDE STATEMENTS, CONDITIONALS AND FOR LOOPS 1357Makefile inclusion, conditional structures and for loops reminiscent 1358of the C programming language are provided in 1359.Nm . 1360All such structures are identified by a line beginning with a single 1361dot 1362.Pq Ql \&. 1363character. 1364Files are included with either 1365.Cm \&.include Aq Ar file 1366or 1367.Cm \&.include Pf \*q Ar file Ns \*q . 1368Variables between the angle brackets or double quotes are expanded 1369to form the file name. 1370If angle brackets are used, the included makefile is expected to be in 1371the system makefile directory. 1372If double quotes are used, the including makefile's directory and any 1373directories specified using the 1374.Fl I 1375option are searched before the system 1376makefile directory. 1377For compatibility with other versions of 1378.Nm 1379.Ql include file ... 1380is also accepted. 1381If the include statement is written as 1382.Cm .-include 1383or as 1384.Cm .sinclude 1385then errors locating and/or opening include files are ignored. 1386.Pp 1387Conditional expressions are also preceded by a single dot as the first 1388character of a line. 1389The possible conditionals are as follows: 1390.Bl -tag -width Ds 1391.It Ic .error Ar message 1392The message is printed along with the name of the makefile and line number, 1393then 1394.Nm 1395will exit. 1396.It Ic .export Ar variable ... 1397Export the specified global variable. 1398If no variable list is provided, all globals are exported 1399except for internal variables (those that start with 1400.Ql \&. ) . 1401This is not affected by the 1402.Fl X 1403flag, so should be used with caution. 1404.Pp 1405Appending a variable name to 1406.Va .MAKE.EXPORTED 1407is equivalent to exporting a variable. 1408.It Ic .export-env Ar variable ... 1409The same as 1410.Ql .export , 1411except that the variable is not appended to 1412.Va .MAKE.EXPORTED . 1413This allows exporting a value to the environment which is different from that 1414used by 1415.Nm 1416internally. 1417.It Ic .info Ar message 1418The message is printed along with the name of the makefile and line number. 1419.It Ic .undef Ar variable 1420Un-define the specified global variable. 1421Only global variables may be un-defined. 1422.It Ic .unexport Ar variable ... 1423The opposite of 1424.Ql .export . 1425The specified global 1426.Va variable 1427will be removed from 1428.Va .MAKE.EXPORTED . 1429If no variable list is provided, all globals are unexported, 1430and 1431.Va .MAKE.EXPORTED 1432deleted. 1433.It Ic .unexport-env 1434Unexport all globals previously exported and 1435clear the environment inherited from the parent. 1436This operation will cause a memory leak of the original environment, 1437so should be used sparingly. 1438Testing for 1439.Va .MAKE.LEVEL 1440being 0, would make sense. 1441Also note that any variables which originated in the parent environment 1442should be explicitly preserved if desired. 1443For example: 1444.Bd -literal -offset indent 1445.Li .if ${.MAKE.LEVEL} == 0 1446PATH := ${PATH} 1447.Li .unexport-env 1448.Li .export PATH 1449.Li .endif 1450.Pp 1451.Ed 1452Would result in an environment containing only 1453.Ql Ev PATH , 1454which is the minimal useful environment. 1455Actually 1456.Ql Ev .MAKE.LEVEL 1457will also be pushed into the new environment. 1458.It Ic .warning Ar message 1459The message prefixed by 1460.Ql Pa warning: 1461is printed along with the name of the makefile and line number. 1462.It Ic \&.if Oo \&! Oc Ns Ar expression Op Ar operator expression ... 1463Test the value of an expression. 1464.It Ic .ifdef Oo \&! Oc Ns Ar variable Op Ar operator variable ... 1465Test the value of a variable. 1466.It Ic .ifndef Oo \&! Oc Ns Ar variable Op Ar operator variable ... 1467Test the value of a variable. 1468.It Ic .ifmake Oo \&! Oc Ns Ar target Op Ar operator target ... 1469Test the target being built. 1470.It Ic .ifnmake Oo \&! Ns Oc Ar target Op Ar operator target ... 1471Test the target being built. 1472.It Ic .else 1473Reverse the sense of the last conditional. 1474.It Ic .elif Oo \&! Ns Oc Ar expression Op Ar operator expression ... 1475A combination of 1476.Ql Ic .else 1477followed by 1478.Ql Ic .if . 1479.It Ic .elifdef Oo \&! Oc Ns Ar variable Op Ar operator variable ... 1480A combination of 1481.Ql Ic .else 1482followed by 1483.Ql Ic .ifdef . 1484.It Ic .elifndef Oo \&! Oc Ns Ar variable Op Ar operator variable ... 1485A combination of 1486.Ql Ic .else 1487followed by 1488.Ql Ic .ifndef . 1489.It Ic .elifmake Oo \&! Oc Ns Ar target Op Ar operator target ... 1490A combination of 1491.Ql Ic .else 1492followed by 1493.Ql Ic .ifmake . 1494.It Ic .elifnmake Oo \&! Oc Ns Ar target Op Ar operator target ... 1495A combination of 1496.Ql Ic .else 1497followed by 1498.Ql Ic .ifnmake . 1499.It Ic .endif 1500End the body of the conditional. 1501.El 1502.Pp 1503The 1504.Ar operator 1505may be any one of the following: 1506.Bl -tag -width "Cm XX" 1507.It Cm \&|\&| 1508Logical OR. 1509.It Cm \&\*[Am]\*[Am] 1510Logical 1511.Tn AND ; 1512of higher precedence than 1513.Dq \&|\&| . 1514.El 1515.Pp 1516As in C, 1517.Nm 1518will only evaluate a conditional as far as is necessary to determine 1519its value. 1520Parentheses may be used to change the order of evaluation. 1521The boolean operator 1522.Ql Ic \&! 1523may be used to logically negate an entire 1524conditional. 1525It is of higher precedence than 1526.Ql Ic \&\*[Am]\*[Am] . 1527.Pp 1528The value of 1529.Ar expression 1530may be any of the following: 1531.Bl -tag -width defined 1532.It Ic defined 1533Takes a variable name as an argument and evaluates to true if the variable 1534has been defined. 1535.It Ic make 1536Takes a target name as an argument and evaluates to true if the target 1537was specified as part of 1538.Nm Ns 's 1539command line or was declared the default target (either implicitly or 1540explicitly, see 1541.Va .MAIN ) 1542before the line containing the conditional. 1543.It Ic empty 1544Takes a variable, with possible modifiers, and evaluates to true if 1545the expansion of the variable would result in an empty string. 1546.It Ic exists 1547Takes a file name as an argument and evaluates to true if the file exists. 1548The file is searched for on the system search path (see 1549.Va .PATH ) . 1550.It Ic target 1551Takes a target name as an argument and evaluates to true if the target 1552has been defined. 1553.It Ic commands 1554Takes a target name as an argument and evaluates to true if the target 1555has been defined and has commands associated with it. 1556.El 1557.Pp 1558.Ar Expression 1559may also be an arithmetic or string comparison. 1560Variable expansion is 1561performed on both sides of the comparison, after which the integral 1562values are compared. 1563A value is interpreted as hexadecimal if it is 1564preceded by 0x, otherwise it is decimal; octal numbers are not supported. 1565The standard C relational operators are all supported. 1566If after 1567variable expansion, either the left or right hand side of a 1568.Ql Ic == 1569or 1570.Ql Ic "!=" 1571operator is not an integral value, then 1572string comparison is performed between the expanded 1573variables. 1574If no relational operator is given, it is assumed that the expanded 1575variable is being compared against 0 or an empty string in the case 1576of a string comparison. 1577.Pp 1578When 1579.Nm 1580is evaluating one of these conditional expressions, and it encounters 1581a (white-space separated) word it doesn't recognize, either the 1582.Dq make 1583or 1584.Dq defined 1585expression is applied to it, depending on the form of the conditional. 1586If the form is 1587.Ql Ic .ifdef , 1588.Ql Ic .ifndef , 1589or 1590.Ql Ic .if 1591the 1592.Dq defined 1593expression is applied. 1594Similarly, if the form is 1595.Ql Ic .ifmake 1596or 1597.Ql Ic .ifnmake , the 1598.Dq make 1599expression is applied. 1600.Pp 1601If the conditional evaluates to true the parsing of the makefile continues 1602as before. 1603If it evaluates to false, the following lines are skipped. 1604In both cases this continues until a 1605.Ql Ic .else 1606or 1607.Ql Ic .endif 1608is found. 1609.Pp 1610For loops are typically used to apply a set of rules to a list of files. 1611The syntax of a for loop is: 1612.Pp 1613.Bl -tag -compact -width Ds 1614.It Ic \&.for Ar variable Oo Ar variable ... Oc Ic in Ar expression 1615.It Aq make-rules 1616.It Ic \&.endfor 1617.El 1618.Pp 1619After the for 1620.Ic expression 1621is evaluated, it is split into words. 1622On each iteration of the loop, one word is taken and assigned to each 1623.Ic variable , 1624in order, and these 1625.Ic variables 1626are substituted into the 1627.Ic make-rules 1628inside the body of the for loop. 1629The number of words must come out even; that is, if there are three 1630iteration variables, the number of words provided must be a multiple 1631of three. 1632.Sh COMMENTS 1633Comments begin with a hash 1634.Pq Ql \&# 1635character, anywhere but in a shell 1636command line, and continue to the end of an unescaped new line. 1637.Sh SPECIAL SOURCES (ATTRIBUTES) 1638.Bl -tag -width .IGNOREx 1639.It Ic .EXEC 1640Target is never out of date, but always execute commands anyway. 1641.It Ic .IGNORE 1642Ignore any errors from the commands associated with this target, exactly 1643as if they all were preceded by a dash 1644.Pq Ql \- . 1645.\" .It Ic .INVISIBLE 1646.\" XXX 1647.\" .It Ic .JOIN 1648.\" XXX 1649.It Ic .MADE 1650Mark all sources of this target as being up-to-date. 1651.It Ic .MAKE 1652Execute the commands associated with this target even if the 1653.Fl n 1654or 1655.Fl t 1656options were specified. 1657Normally used to mark recursive 1658.Nm Ns 's . 1659.It Ic .META 1660Create a meta file for the target, even if it is flagged as 1661.Ic .PHONY , 1662.Ic .MAKE , 1663or 1664.Ic .SPECIAL . 1665Usage in conjunction with 1666.Ic .MAKE 1667is the most likely case. 1668.It Ic .NOMETA 1669Do not create a meta file for the target. 1670Meta files are also not created for 1671.Ic .PHONY , 1672.Ic .MAKE , 1673or 1674.Ic .SPECIAL 1675targets. 1676.It Ic .NOMETA_CMP 1677Ignore differences in commands when deciding if target is out of date. 1678This is useful if the command contains a value which always changes. 1679If the number of commands change, though, the target will still be out of date. 1680.It Ic .NOPATH 1681Do not search for the target in the directories specified by 1682.Ic .PATH . 1683.It Ic .NOTMAIN 1684Normally 1685.Nm 1686selects the first target it encounters as the default target to be built 1687if no target was specified. 1688This source prevents this target from being selected. 1689.It Ic .OPTIONAL 1690If a target is marked with this attribute and 1691.Nm 1692can't figure out how to create it, it will ignore this fact and assume 1693the file isn't needed or already exists. 1694.It Ic .PHONY 1695The target does not 1696correspond to an actual file; it is always considered to be out of date, 1697and will not be created with the 1698.Fl t 1699option. 1700Suffix-transformation rules are not applied to 1701.Ic .PHONY 1702targets. 1703.It Ic .PRECIOUS 1704When 1705.Nm 1706is interrupted, it normally removes any partially made targets. 1707This source prevents the target from being removed. 1708.It Ic .RECURSIVE 1709Synonym for 1710.Ic .MAKE . 1711.It Ic .SILENT 1712Do not echo any of the commands associated with this target, exactly 1713as if they all were preceded by an at sign 1714.Pq Ql @ . 1715.It Ic .USE 1716Turn the target into 1717.Nm Ns 's 1718version of a macro. 1719When the target is used as a source for another target, the other target 1720acquires the commands, sources, and attributes (except for 1721.Ic .USE ) 1722of the 1723source. 1724If the target already has commands, the 1725.Ic .USE 1726target's commands are appended 1727to them. 1728.It Ic .USEBEFORE 1729Exactly like 1730.Ic .USE , 1731but prepend the 1732.Ic .USEBEFORE 1733target commands to the target. 1734.It Ic .WAIT 1735If 1736.Ic .WAIT 1737appears in a dependency line, the sources that precede it are 1738made before the sources that succeed it in the line. 1739Since the dependents of files are not made until the file itself 1740could be made, this also stops the dependents being built unless they 1741are needed for another branch of the dependency tree. 1742So given: 1743.Bd -literal 1744x: a .WAIT b 1745 echo x 1746a: 1747 echo a 1748b: b1 1749 echo b 1750b1: 1751 echo b1 1752 1753.Ed 1754the output is always 1755.Ql a , 1756.Ql b1 , 1757.Ql b , 1758.Ql x . 1759.br 1760The ordering imposed by 1761.Ic .WAIT 1762is only relevant for parallel makes. 1763.El 1764.Sh SPECIAL TARGETS 1765Special targets may not be included with other targets, i.e. they must be 1766the only target specified. 1767.Bl -tag -width .BEGINx 1768.It Ic .BEGIN 1769Any command lines attached to this target are executed before anything 1770else is done. 1771.It Ic .DEFAULT 1772This is sort of a 1773.Ic .USE 1774rule for any target (that was used only as a 1775source) that 1776.Nm 1777can't figure out any other way to create. 1778Only the shell script is used. 1779The 1780.Ic .IMPSRC 1781variable of a target that inherits 1782.Ic .DEFAULT Ns 's 1783commands is set 1784to the target's own name. 1785.It Ic .END 1786Any command lines attached to this target are executed after everything 1787else is done. 1788.It Ic .ERROR 1789Any command lines attached to this target are executed when another target fails. 1790The 1791.Ic .ERROR_TARGET 1792variable is set to the target that failed. 1793See also 1794.Ic MAKE_PRINT_VAR_ON_ERROR . 1795.It Ic .IGNORE 1796Mark each of the sources with the 1797.Ic .IGNORE 1798attribute. 1799If no sources are specified, this is the equivalent of specifying the 1800.Fl i 1801option. 1802.It Ic .INTERRUPT 1803If 1804.Nm 1805is interrupted, the commands for this target will be executed. 1806.It Ic .MAIN 1807If no target is specified when 1808.Nm 1809is invoked, this target will be built. 1810.It Ic .MAKEFLAGS 1811This target provides a way to specify flags for 1812.Nm 1813when the makefile is used. 1814The flags are as if typed to the shell, though the 1815.Fl f 1816option will have 1817no effect. 1818.\" XXX: NOT YET!!!! 1819.\" .It Ic .NOTPARALLEL 1820.\" The named targets are executed in non parallel mode. 1821.\" If no targets are 1822.\" specified, then all targets are executed in non parallel mode. 1823.It Ic .NOPATH 1824Apply the 1825.Ic .NOPATH 1826attribute to any specified sources. 1827.It Ic .NOTPARALLEL 1828Disable parallel mode. 1829.It Ic .NO_PARALLEL 1830Synonym for 1831.Ic .NOTPARALLEL , 1832for compatibility with other pmake variants. 1833.It Ic .ORDER 1834The named targets are made in sequence. 1835This ordering does not add targets to the list of targets to be made. 1836Since the dependents of a target do not get built until the target itself 1837could be built, unless 1838.Ql a 1839is built by another part of the dependency graph, 1840the following is a dependency loop: 1841.Bd -literal 1842\&.ORDER: a b 1843b: a 1844.Ed 1845.Pp 1846The ordering imposed by 1847.Ic .ORDER 1848is only relevant for parallel makes. 1849.\" XXX: NOT YET!!!! 1850.\" .It Ic .PARALLEL 1851.\" The named targets are executed in parallel mode. 1852.\" If no targets are 1853.\" specified, then all targets are executed in parallel mode. 1854.It Ic .PATH 1855The sources are directories which are to be searched for files not 1856found in the current directory. 1857If no sources are specified, any previously specified directories are 1858deleted. 1859If the source is the special 1860.Ic .DOTLAST 1861target, then the current working 1862directory is searched last. 1863.It Ic .PHONY 1864Apply the 1865.Ic .PHONY 1866attribute to any specified sources. 1867.It Ic .PRECIOUS 1868Apply the 1869.Ic .PRECIOUS 1870attribute to any specified sources. 1871If no sources are specified, the 1872.Ic .PRECIOUS 1873attribute is applied to every 1874target in the file. 1875.It Ic .SHELL 1876Sets the shell that 1877.Nm 1878will use to execute commands. 1879The sources are a set of 1880.Ar field=value 1881pairs. 1882.Bl -tag -width hasErrCtls 1883.It Ar name 1884This is the minimal specification, used to select one of the builtin 1885shell specs; 1886.Ar sh , 1887.Ar ksh , 1888and 1889.Ar csh . 1890.It Ar path 1891Specifies the path to the shell. 1892.It Ar hasErrCtl 1893Indicates whether the shell supports exit on error. 1894.It Ar check 1895The command to turn on error checking. 1896.It Ar ignore 1897The command to disable error checking. 1898.It Ar echo 1899The command to turn on echoing of commands executed. 1900.It Ar quiet 1901The command to turn off echoing of commands executed. 1902.It Ar filter 1903The output to filter after issuing the 1904.Ar quiet 1905command. 1906It is typically identical to 1907.Ar quiet . 1908.It Ar errFlag 1909The flag to pass the shell to enable error checking. 1910.It Ar echoFlag 1911The flag to pass the shell to enable command echoing. 1912.It Ar newline 1913The string literal to pass the shell that results in a single newline 1914character when used outside of any quoting characters. 1915.El 1916Example: 1917.Bd -literal 1918\&.SHELL: name=ksh path=/bin/ksh hasErrCtl=true \e 1919 check="set -e" ignore="set +e" \e 1920 echo="set -v" quiet="set +v" filter="set +v" \e 1921 echoFlag=v errFlag=e newline="'\en'" 1922.Ed 1923.It Ic .SILENT 1924Apply the 1925.Ic .SILENT 1926attribute to any specified sources. 1927If no sources are specified, the 1928.Ic .SILENT 1929attribute is applied to every 1930command in the file. 1931.It Ic .SUFFIXES 1932Each source specifies a suffix to 1933.Nm . 1934If no sources are specified, any previously specified suffixes are deleted. 1935It allows the creation of suffix-transformation rules. 1936.Pp 1937Example: 1938.Bd -literal 1939\&.SUFFIXES: .o 1940\&.c.o: 1941 cc -o ${.TARGET} -c ${.IMPSRC} 1942.Ed 1943.El 1944.Sh ENVIRONMENT 1945.Nm 1946uses the following environment variables, if they exist: 1947.Ev MACHINE , 1948.Ev MACHINE_ARCH , 1949.Ev MAKE , 1950.Ev MAKEFLAGS , 1951.Ev MAKEOBJDIR , 1952.Ev MAKEOBJDIRPREFIX , 1953.Ev MAKESYSPATH , 1954.Ev PWD , 1955and 1956.Ev TMPDIR . 1957.Pp 1958.Ev MAKEOBJDIRPREFIX 1959and 1960.Ev MAKEOBJDIR 1961may only be set in the environment or on the command line to 1962.Nm 1963and not as makefile variables; 1964see the description of 1965.Ql Va .OBJDIR 1966for more details. 1967.Sh FILES 1968.Bl -tag -width /usr/share/mk -compact 1969.It .depend 1970list of dependencies 1971.It Makefile 1972list of dependencies 1973.It makefile 1974list of dependencies 1975.It sys.mk 1976system makefile 1977.It /usr/share/mk 1978system makefile directory 1979.El 1980.Sh COMPATIBILITY 1981The basic make syntax is compatible between different versions of make, 1982however the special variables, variable modifiers and conditionals are not. 1983.Pp 1984The way that parallel makes are scheduled changed in 1985.Nx 4.0 1986so that .ORDER and .WAIT apply recursively to the dependant nodes. 1987The algorithms used may change again in the future. 1988.Pp 1989The way that .for loop variables are substituted changed after 1990.Nx 5.0 1991so that they still appear to be variable expansions. 1992In particular this stops them being treated as syntax, and removes some 1993obscure problems using them in .if statements. 1994.Sh SEE ALSO 1995.Xr mkdep 1 1996.Sh HISTORY 1997A 1998.Nm 1999command appeared in 2000.At v7 . 2001.Sh BUGS 2002The 2003.Nm 2004syntax is difficult to parse without actually acting of the data. 2005For instance finding the end of a variable use should involve scanning each 2006the modifiers using the correct terminator for each field. 2007In many places 2008.Nm 2009just counts {} and () in order to find the end of a variable expansion. 2010.Pp 2011There is no way of escaping a space character in a filename. 2012