1.\" $NetBSD: make.1,v 1.193 2011/06/30 20:09:42 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 May 29, 2011 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 curdirOk= Ar bf 784Normally 785.Nm 786will not create .meta files in 787.Ql Va .CURDIR . 788This can be overridden by setting 789.Va bf 790to a value which represents True. 791.It Pa verbose 792If in "meta" mode, print a clue about the target being built. 793This is useful if the build is otherwise running silently. 794The message printed the value of: 795.Va .MAKE.META.PREFIX . 796.It Pa ignore-cmd 797Some makefiles have commands which are simply not stable. 798This keyword causes them to be ignored for 799determining whether a target is out of date in "meta" mode. 800See also 801.Ic .NOMETA_CMP . 802.El 803.It Va .MAKE.META.BAILIWICK 804In "meta" mode, provides a list of prefixes which 805match the directories controlled by 806.Nm . 807If a file that was generated outside of 808.Va .OBJDIR 809but within said bailiwick is missing, 810the current target is considered out-of-date. 811.It Va .MAKE.META.CREATED 812In "meta" mode, this variable contains a list of all the meta files 813updated. 814If not empty, it can be used to trigger processing of 815.Va .MAKE.META.FILES . 816.It Va .MAKE.META.FILES 817In "meta" mode, this variable contains a list of all the meta files 818used (updated or not). 819This list can be used to process the meta files to extract dependency 820information. 821.It Va .MAKE.META.PREFIX 822Defines the message printed for each meta file updated in "meta verbose" mode. 823The default value is: 824.Dl Building ${.TARGET:H:tA}/${.TARGET:T} 825.It Va .MAKEOVERRIDES 826This variable is used to record the names of variables assigned to 827on the command line, so that they may be exported as part of 828.Ql Ev MAKEFLAGS . 829This behaviour can be disabled by assigning an empty value to 830.Ql Va .MAKEOVERRIDES 831within a makefile. 832Extra variables can be exported from a makefile 833by appending their names to 834.Ql Va .MAKEOVERRIDES . 835.Ql Ev MAKEFLAGS 836is re-exported whenever 837.Ql Va .MAKEOVERRIDES 838is modified. 839.It Va .MAKE.PID 840The process-id of 841.Nm . 842.It Va .MAKE.PPID 843The parent process-id of 844.Nm . 845.It Va MAKE_PRINT_VAR_ON_ERROR 846When 847.Nm 848stops due to an error, it prints its name and the value of 849.Ql Va .CURDIR 850as well as the value of any variables named in 851.Ql Va MAKE_PRINT_VAR_ON_ERROR . 852.It Va .newline 853This variable is simply assigned a newline character as its value. 854This allows expansions using the 855.Cm \&:@ 856modifier to put a newline between 857iterations of the loop rather than a space. 858For example, the printing of 859.Ql Va MAKE_PRINT_VAR_ON_ERROR 860could be done as ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}. 861.It Va .OBJDIR 862A path to the directory where the targets are built. 863Its value is determined by trying to 864.Xr chdir 2 865to the following directories in order and using the first match: 866.Bl -enum 867.It 868.Ev ${MAKEOBJDIRPREFIX}${.CURDIR} 869.Pp 870(Only if 871.Ql Ev MAKEOBJDIRPREFIX 872is set in the environment or on the command line.) 873.It 874.Ev ${MAKEOBJDIR} 875.Pp 876(Only if 877.Ql Ev MAKEOBJDIR 878is set in the environment or on the command line.) 879.It 880.Ev ${.CURDIR} Ns Pa /obj. Ns Ev ${MACHINE} 881.It 882.Ev ${.CURDIR} Ns Pa /obj 883.It 884.Pa /usr/obj/ Ns Ev ${.CURDIR} 885.It 886.Ev ${.CURDIR} 887.El 888.Pp 889Variable expansion is performed on the value before it's used, 890so expressions such as 891.Dl ${.CURDIR:S,^/usr/src,/var/obj,} 892may be used. 893This is especially useful with 894.Ql Ev MAKEOBJDIR . 895.Pp 896.Ql Va .OBJDIR 897may be modified in the makefile as a global variable. 898In all cases, 899.Nm 900will 901.Xr chdir 2 902to 903.Ql Va .OBJDIR 904and set 905.Ql Ev PWD 906to that directory before executing any targets. 907. 908.It Va .PARSEDIR 909A path to the directory of the current 910.Ql Pa Makefile 911being parsed. 912.It Va .PARSEFILE 913The basename of the current 914.Ql Pa Makefile 915being parsed. 916This variable and 917.Ql Va .PARSEDIR 918are both set only while the 919.Ql Pa Makefiles 920are being parsed. 921.It Va .PATH 922A variable that represents the list of directories that 923.Nm 924will search for files. 925The search list should be updated using the target 926.Ql Va .PATH 927rather than the variable. 928.It Ev PWD 929Alternate path to the current directory. 930.Nm 931normally sets 932.Ql Va .CURDIR 933to the canonical path given by 934.Xr getcwd 3 . 935However, if the environment variable 936.Ql Ev PWD 937is set and gives a path to the current directory, then 938.Nm 939sets 940.Ql Va .CURDIR 941to the value of 942.Ql Ev PWD 943instead. 944This behaviour is disabled if 945.Ql Ev MAKEOBJDIRPREFIX 946is set or 947.Ql Ev MAKEOBJDIR 948contains a variable transform. 949.Ql Ev PWD 950is set to the value of 951.Ql Va .OBJDIR 952for all programs which 953.Nm 954executes. 955.It Ev .TARGETS 956The list of targets explicitly specified on the command line, if any. 957.It Ev VPATH 958Colon-separated 959.Pq Dq \&: 960lists of directories that 961.Nm 962will search for files. 963The variable is supported for compatibility with old make programs only, 964use 965.Ql Va .PATH 966instead. 967.El 968.Ss Variable modifiers 969Variable expansion may be modified to select or modify each word of the 970variable (where a 971.Dq word 972is white-space delimited sequence of characters). 973The general format of a variable expansion is as follows: 974.Pp 975.Dl ${variable[:modifier[:...]]} 976.Pp 977Each modifier begins with a colon, 978which may be escaped with a backslash 979.Pq Ql \e . 980.Pp 981A set of modifiers can be specified via a variable, as follows: 982.Pp 983.Dl modifier_variable=modifier[:...] 984.Dl ${variable:${modifier_variable}[:...]} 985.Pp 986In this case the first modifier in the modifier_variable does not 987start with a colon, since that must appear in the referencing 988variable. 989If any of the modifiers in the modifier_variable contain a dollar sign 990.Pq Ql $ , 991these must be doubled to avoid early expansion. 992.Pp 993The supported modifiers are: 994.Bl -tag -width EEE 995.It Cm \&:E 996Replaces each word in the variable with its suffix. 997.It Cm \&:H 998Replaces each word in the variable with everything but the last component. 999.It Cm \&:M Ns Ar pattern 1000Select only those words that match 1001.Ar pattern . 1002The standard shell wildcard characters 1003.Pf ( Ql * , 1004.Ql \&? , 1005and 1006.Ql Oo Oc ) 1007may 1008be used. 1009The wildcard characters may be escaped with a backslash 1010.Pq Ql \e . 1011.It Cm \&:N Ns Ar pattern 1012This is identical to 1013.Ql Cm \&:M , 1014but selects all words which do not match 1015.Ar pattern . 1016.It Cm \&:O 1017Order every word in variable alphabetically. 1018To sort words in 1019reverse order use the 1020.Ql Cm \&:O:[-1..1] 1021combination of modifiers. 1022.It Cm \&:Ox 1023Randomize words in variable. 1024The results will be different each time you are referring to the 1025modified variable; use the assignment with expansion 1026.Pq Ql Cm \&:= 1027to prevent such behaviour. 1028For example, 1029.Bd -literal -offset indent 1030LIST= uno due tre quattro 1031RANDOM_LIST= ${LIST:Ox} 1032STATIC_RANDOM_LIST:= ${LIST:Ox} 1033 1034all: 1035 @echo "${RANDOM_LIST}" 1036 @echo "${RANDOM_LIST}" 1037 @echo "${STATIC_RANDOM_LIST}" 1038 @echo "${STATIC_RANDOM_LIST}" 1039.Ed 1040may produce output similar to: 1041.Bd -literal -offset indent 1042quattro due tre uno 1043tre due quattro uno 1044due uno quattro tre 1045due uno quattro tre 1046.Ed 1047.It Cm \&:Q 1048Quotes every shell meta-character in the variable, so that it can be passed 1049safely through recursive invocations of 1050.Nm . 1051.It Cm \&:R 1052Replaces each word in the variable with everything but its suffix. 1053.It Cm \&:gmtime 1054The value is a format string for 1055.Xr strftime 3 , 1056using the current 1057.Xr gmtime 3 . 1058.It Cm \&:hash 1059Compute a 32bit hash of the value and encode it as hex digits. 1060.It Cm \&:localtime 1061The value is a format string for 1062.Xr strftime 3 , 1063using the current 1064.Xr localtime 3 . 1065.It Cm \&:tA 1066Attempt to convert variable to an absolute path using 1067.Xr realpath 3 , 1068if that fails, the value is unchanged. 1069.It Cm \&:tl 1070Converts variable to lower-case letters. 1071.It Cm \&:ts Ns Ar c 1072Words in the variable are normally separated by a space on expansion. 1073This modifier sets the separator to the character 1074.Ar c . 1075If 1076.Ar c 1077is omitted, then no separator is used. 1078The common escapes (including octal numeric codes), work as expected. 1079.It Cm \&:tu 1080Converts variable to upper-case letters. 1081.It Cm \&:tW 1082Causes the value to be treated as a single word 1083(possibly containing embedded white space). 1084See also 1085.Ql Cm \&:[*] . 1086.It Cm \&:tw 1087Causes the value to be treated as a sequence of 1088words delimited by white space. 1089See also 1090.Ql Cm \&:[@] . 1091.Sm off 1092.It Cm \&:S No \&/ Ar old_string No \&/ Ar new_string No \&/ Op Cm 1gW 1093.Sm on 1094Modify the first occurrence of 1095.Ar old_string 1096in the variable's value, replacing it with 1097.Ar new_string . 1098If a 1099.Ql g 1100is appended to the last slash of the pattern, all occurrences 1101in each word are replaced. 1102If a 1103.Ql 1 1104is appended to the last slash of the pattern, only the first word 1105is affected. 1106If a 1107.Ql W 1108is appended to the last slash of the pattern, 1109then the value is treated as a single word 1110(possibly containing embedded white space). 1111If 1112.Ar old_string 1113begins with a caret 1114.Pq Ql ^ , 1115.Ar old_string 1116is anchored at the beginning of each word. 1117If 1118.Ar old_string 1119ends with a dollar sign 1120.Pq Ql \&$ , 1121it is anchored at the end of each word. 1122Inside 1123.Ar new_string , 1124an ampersand 1125.Pq Ql \*[Am] 1126is replaced by 1127.Ar old_string 1128(without any 1129.Ql ^ 1130or 1131.Ql \&$ ) . 1132Any character may be used as a delimiter for the parts of the modifier 1133string. 1134The anchoring, ampersand and delimiter characters may be escaped with a 1135backslash 1136.Pq Ql \e . 1137.Pp 1138Variable expansion occurs in the normal fashion inside both 1139.Ar old_string 1140and 1141.Ar new_string 1142with the single exception that a backslash is used to prevent the expansion 1143of a dollar sign 1144.Pq Ql \&$ , 1145not a preceding dollar sign as is usual. 1146.Sm off 1147.It Cm \&:C No \&/ Ar pattern No \&/ Ar replacement No \&/ Op Cm 1gW 1148.Sm on 1149The 1150.Cm \&:C 1151modifier is just like the 1152.Cm \&:S 1153modifier except that the old and new strings, instead of being 1154simple strings, are a regular expression (see 1155.Xr regex 3 ) 1156string 1157.Ar pattern 1158and an 1159.Xr ed 1 Ns \-style 1160string 1161.Ar replacement . 1162Normally, the first occurrence of the pattern 1163.Ar pattern 1164in each word of the value is substituted with 1165.Ar replacement . 1166The 1167.Ql 1 1168modifier causes the substitution to apply to at most one word; the 1169.Ql g 1170modifier causes the substitution to apply to as many instances of the 1171search pattern 1172.Ar pattern 1173as occur in the word or words it is found in; the 1174.Ql W 1175modifier causes the value to be treated as a single word 1176(possibly containing embedded white space). 1177Note that 1178.Ql 1 1179and 1180.Ql g 1181are orthogonal; the former specifies whether multiple words are 1182potentially affected, the latter whether multiple substitutions can 1183potentially occur within each affected word. 1184.It Cm \&:T 1185Replaces each word in the variable with its last component. 1186.It Cm \&:u 1187Remove adjacent duplicate words (like 1188.Xr uniq 1 ) . 1189.Sm off 1190.It Cm \&:\&? Ar true_string Cm \&: Ar false_string 1191.Sm on 1192If the variable name (not its value), when parsed as a .if conditional 1193expression, evaluates to true, return as its value the 1194.Ar true_string , 1195otherwise return the 1196.Ar false_string . 1197Since the variable name is used as the expression, \&:\&? must be the 1198first modifier after the variable name itself - which will, of course, 1199usually contain variable expansions. 1200A common error is trying to use expressions like 1201.Dl ${NUMBERS:M42:?match:no} 1202which actually tests defined(NUMBERS), 1203to determine is any words match "42" you need to use something like: 1204.Dl ${"${NUMBERS:M42}" != \&"\&":?match:no} . 1205.It Ar :old_string=new_string 1206This is the 1207.At V 1208style variable substitution. 1209It must be the last modifier specified. 1210If 1211.Ar old_string 1212or 1213.Ar new_string 1214do not contain the pattern matching character 1215.Ar % 1216then it is assumed that they are 1217anchored at the end of each word, so only suffixes or entire 1218words may be replaced. 1219Otherwise 1220.Ar % 1221is the substring of 1222.Ar old_string 1223to be replaced in 1224.Ar new_string . 1225.Pp 1226Variable expansion occurs in the normal fashion inside both 1227.Ar old_string 1228and 1229.Ar new_string 1230with the single exception that a backslash is used to prevent the 1231expansion of a dollar sign 1232.Pq Ql \&$ , 1233not a preceding dollar sign as is usual. 1234.Sm off 1235.It Cm \&:@ Ar temp Cm @ Ar string Cm @ 1236.Sm on 1237This is the loop expansion mechanism from the OSF Development 1238Environment (ODE) make. 1239Unlike 1240.Cm \&.for 1241loops expansion occurs at the time of 1242reference. 1243Assign 1244.Ar temp 1245to each word in the variable and evaluate 1246.Ar string . 1247The ODE convention is that 1248.Ar temp 1249should start and end with a period. 1250For example. 1251.Dl ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@} 1252.It Cm \&:U Ns Ar newval 1253If the variable is undefined 1254.Ar newval 1255is the value. 1256If the variable is defined, the existing value is returned. 1257This is another ODE make feature. 1258It is handy for setting per-target CFLAGS for instance: 1259.Dl ${_${.TARGET:T}_CFLAGS:U${DEF_CFLAGS}} 1260If a value is only required if the variable is undefined, use: 1261.Dl ${VAR:D:Unewval} 1262.It Cm \&:D Ns Ar newval 1263If the variable is defined 1264.Ar newval 1265is the value. 1266.It Cm \&:L 1267The name of the variable is the value. 1268.It Cm \&:P 1269The path of the node which has the same name as the variable 1270is the value. 1271If no such node exists or its path is null, then the 1272name of the variable is used. 1273.Sm off 1274.It Cm \&:\&! Ar cmd Cm \&! 1275.Sm on 1276The output of running 1277.Ar cmd 1278is the value. 1279.It Cm \&:sh 1280If the variable is non-empty it is run as a command and the output 1281becomes the new value. 1282.It Cm \&::= Ns Ar str 1283The variable is assigned the value 1284.Ar str 1285after substitution. 1286This modifier and its variations are useful in 1287obscure situations such as wanting to set a variable when shell commands 1288are being parsed. 1289These assignment modifiers always expand to 1290nothing, so if appearing in a rule line by themselves should be 1291preceded with something to keep 1292.Nm 1293happy. 1294.Pp 1295The 1296.Ql Cm \&:: 1297helps avoid false matches with the 1298.At V 1299style 1300.Cm \&:= 1301modifier and since substitution always occurs the 1302.Cm \&::= 1303form is vaguely appropriate. 1304.It Cm \&::?= Ns Ar str 1305As for 1306.Cm \&::= 1307but only if the variable does not already have a value. 1308.It Cm \&::+= Ns Ar str 1309Append 1310.Ar str 1311to the variable. 1312.It Cm \&::!= Ns Ar cmd 1313Assign the output of 1314.Ar cmd 1315to the variable. 1316.It Cm \&:\&[ Ns Ar range Ns Cm \&] 1317Selects one or more words from the value, 1318or performs other operations related to the way in which the 1319value is divided into words. 1320.Pp 1321Ordinarily, a value is treated as a sequence of words 1322delimited by white space. 1323Some modifiers suppress this behaviour, 1324causing a value to be treated as a single word 1325(possibly containing embedded white space). 1326An empty value, or a value that consists entirely of white-space, 1327is treated as a single word. 1328For the purposes of the 1329.Ql Cm \&:[] 1330modifier, the words are indexed both forwards using positive integers 1331(where index 1 represents the first word), 1332and backwards using negative integers 1333(where index -1 represents the last word). 1334.Pp 1335The 1336.Ar range 1337is subjected to variable expansion, and the expanded result is 1338then interpreted as follows: 1339.Bl -tag -width index 1340.\" :[n] 1341.It Ar index 1342Selects a single word from the value. 1343.\" :[start..end] 1344.It Ar start Ns Cm \&.. Ns Ar end 1345Selects all words from 1346.Ar start 1347to 1348.Ar end , 1349inclusive. 1350For example, 1351.Ql Cm \&:[2..-1] 1352selects all words from the second word to the last word. 1353If 1354.Ar start 1355is greater than 1356.Ar end , 1357then the words are output in reverse order. 1358For example, 1359.Ql Cm \&:[-1..1] 1360selects all the words from last to first. 1361.\" :[*] 1362.It Cm \&* 1363Causes subsequent modifiers to treat the value as a single word 1364(possibly containing embedded white space). 1365Analogous to the effect of 1366\&"$*\&" 1367in Bourne shell. 1368.\" :[0] 1369.It 0 1370Means the same as 1371.Ql Cm \&:[*] . 1372.\" :[*] 1373.It Cm \&@ 1374Causes subsequent modifiers to treat the value as a sequence of words 1375delimited by white space. 1376Analogous to the effect of 1377\&"$@\&" 1378in Bourne shell. 1379.\" :[#] 1380.It Cm \&# 1381Returns the number of words in the value. 1382.El \" :[range] 1383.El 1384.Sh INCLUDE STATEMENTS, CONDITIONALS AND FOR LOOPS 1385Makefile inclusion, conditional structures and for loops reminiscent 1386of the C programming language are provided in 1387.Nm . 1388All such structures are identified by a line beginning with a single 1389dot 1390.Pq Ql \&. 1391character. 1392Files are included with either 1393.Cm \&.include Aq Ar file 1394or 1395.Cm \&.include Pf \*q Ar file Ns \*q . 1396Variables between the angle brackets or double quotes are expanded 1397to form the file name. 1398If angle brackets are used, the included makefile is expected to be in 1399the system makefile directory. 1400If double quotes are used, the including makefile's directory and any 1401directories specified using the 1402.Fl I 1403option are searched before the system 1404makefile directory. 1405For compatibility with other versions of 1406.Nm 1407.Ql include file ... 1408is also accepted. 1409If the include statement is written as 1410.Cm .-include 1411or as 1412.Cm .sinclude 1413then errors locating and/or opening include files are ignored. 1414.Pp 1415Conditional expressions are also preceded by a single dot as the first 1416character of a line. 1417The possible conditionals are as follows: 1418.Bl -tag -width Ds 1419.It Ic .error Ar message 1420The message is printed along with the name of the makefile and line number, 1421then 1422.Nm 1423will exit. 1424.It Ic .export Ar variable ... 1425Export the specified global variable. 1426If no variable list is provided, all globals are exported 1427except for internal variables (those that start with 1428.Ql \&. ) . 1429This is not affected by the 1430.Fl X 1431flag, so should be used with caution. 1432.Pp 1433Appending a variable name to 1434.Va .MAKE.EXPORTED 1435is equivalent to exporting a variable. 1436.It Ic .export-env Ar variable ... 1437The same as 1438.Ql .export , 1439except that the variable is not appended to 1440.Va .MAKE.EXPORTED . 1441This allows exporting a value to the environment which is different from that 1442used by 1443.Nm 1444internally. 1445.It Ic .info Ar message 1446The message is printed along with the name of the makefile and line number. 1447.It Ic .undef Ar variable 1448Un-define the specified global variable. 1449Only global variables may be un-defined. 1450.It Ic .unexport Ar variable ... 1451The opposite of 1452.Ql .export . 1453The specified global 1454.Va variable 1455will be removed from 1456.Va .MAKE.EXPORTED . 1457If no variable list is provided, all globals are unexported, 1458and 1459.Va .MAKE.EXPORTED 1460deleted. 1461.It Ic .unexport-env 1462Unexport all globals previously exported and 1463clear the environment inherited from the parent. 1464This operation will cause a memory leak of the original environment, 1465so should be used sparingly. 1466Testing for 1467.Va .MAKE.LEVEL 1468being 0, would make sense. 1469Also note that any variables which originated in the parent environment 1470should be explicitly preserved if desired. 1471For example: 1472.Bd -literal -offset indent 1473.Li .if ${.MAKE.LEVEL} == 0 1474PATH := ${PATH} 1475.Li .unexport-env 1476.Li .export PATH 1477.Li .endif 1478.Pp 1479.Ed 1480Would result in an environment containing only 1481.Ql Ev PATH , 1482which is the minimal useful environment. 1483Actually 1484.Ql Ev .MAKE.LEVEL 1485will also be pushed into the new environment. 1486.It Ic .warning Ar message 1487The message prefixed by 1488.Ql Pa warning: 1489is printed along with the name of the makefile and line number. 1490.It Ic \&.if Oo \&! Oc Ns Ar expression Op Ar operator expression ... 1491Test the value of an expression. 1492.It Ic .ifdef Oo \&! Oc Ns Ar variable Op Ar operator variable ... 1493Test the value of a variable. 1494.It Ic .ifndef Oo \&! Oc Ns Ar variable Op Ar operator variable ... 1495Test the value of a variable. 1496.It Ic .ifmake Oo \&! Oc Ns Ar target Op Ar operator target ... 1497Test the target being built. 1498.It Ic .ifnmake Oo \&! Ns Oc Ar target Op Ar operator target ... 1499Test the target being built. 1500.It Ic .else 1501Reverse the sense of the last conditional. 1502.It Ic .elif Oo \&! Ns Oc Ar expression Op Ar operator expression ... 1503A combination of 1504.Ql Ic .else 1505followed by 1506.Ql Ic .if . 1507.It Ic .elifdef Oo \&! Oc Ns Ar variable Op Ar operator variable ... 1508A combination of 1509.Ql Ic .else 1510followed by 1511.Ql Ic .ifdef . 1512.It Ic .elifndef Oo \&! Oc Ns Ar variable Op Ar operator variable ... 1513A combination of 1514.Ql Ic .else 1515followed by 1516.Ql Ic .ifndef . 1517.It Ic .elifmake Oo \&! Oc Ns Ar target Op Ar operator target ... 1518A combination of 1519.Ql Ic .else 1520followed by 1521.Ql Ic .ifmake . 1522.It Ic .elifnmake Oo \&! Oc Ns Ar target Op Ar operator target ... 1523A combination of 1524.Ql Ic .else 1525followed by 1526.Ql Ic .ifnmake . 1527.It Ic .endif 1528End the body of the conditional. 1529.El 1530.Pp 1531The 1532.Ar operator 1533may be any one of the following: 1534.Bl -tag -width "Cm XX" 1535.It Cm \&|\&| 1536Logical OR. 1537.It Cm \&\*[Am]\*[Am] 1538Logical 1539.Tn AND ; 1540of higher precedence than 1541.Dq \&|\&| . 1542.El 1543.Pp 1544As in C, 1545.Nm 1546will only evaluate a conditional as far as is necessary to determine 1547its value. 1548Parentheses may be used to change the order of evaluation. 1549The boolean operator 1550.Ql Ic \&! 1551may be used to logically negate an entire 1552conditional. 1553It is of higher precedence than 1554.Ql Ic \&\*[Am]\*[Am] . 1555.Pp 1556The value of 1557.Ar expression 1558may be any of the following: 1559.Bl -tag -width defined 1560.It Ic defined 1561Takes a variable name as an argument and evaluates to true if the variable 1562has been defined. 1563.It Ic make 1564Takes a target name as an argument and evaluates to true if the target 1565was specified as part of 1566.Nm Ns 's 1567command line or was declared the default target (either implicitly or 1568explicitly, see 1569.Va .MAIN ) 1570before the line containing the conditional. 1571.It Ic empty 1572Takes a variable, with possible modifiers, and evaluates to true if 1573the expansion of the variable would result in an empty string. 1574.It Ic exists 1575Takes a file name as an argument and evaluates to true if the file exists. 1576The file is searched for on the system search path (see 1577.Va .PATH ) . 1578.It Ic target 1579Takes a target name as an argument and evaluates to true if the target 1580has been defined. 1581.It Ic commands 1582Takes a target name as an argument and evaluates to true if the target 1583has been defined and has commands associated with it. 1584.El 1585.Pp 1586.Ar Expression 1587may also be an arithmetic or string comparison. 1588Variable expansion is 1589performed on both sides of the comparison, after which the integral 1590values are compared. 1591A value is interpreted as hexadecimal if it is 1592preceded by 0x, otherwise it is decimal; octal numbers are not supported. 1593The standard C relational operators are all supported. 1594If after 1595variable expansion, either the left or right hand side of a 1596.Ql Ic == 1597or 1598.Ql Ic "!=" 1599operator is not an integral value, then 1600string comparison is performed between the expanded 1601variables. 1602If no relational operator is given, it is assumed that the expanded 1603variable is being compared against 0 or an empty string in the case 1604of a string comparison. 1605.Pp 1606When 1607.Nm 1608is evaluating one of these conditional expressions, and it encounters 1609a (white-space separated) word it doesn't recognize, either the 1610.Dq make 1611or 1612.Dq defined 1613expression is applied to it, depending on the form of the conditional. 1614If the form is 1615.Ql Ic .ifdef , 1616.Ql Ic .ifndef , 1617or 1618.Ql Ic .if 1619the 1620.Dq defined 1621expression is applied. 1622Similarly, if the form is 1623.Ql Ic .ifmake 1624or 1625.Ql Ic .ifnmake , the 1626.Dq make 1627expression is applied. 1628.Pp 1629If the conditional evaluates to true the parsing of the makefile continues 1630as before. 1631If it evaluates to false, the following lines are skipped. 1632In both cases this continues until a 1633.Ql Ic .else 1634or 1635.Ql Ic .endif 1636is found. 1637.Pp 1638For loops are typically used to apply a set of rules to a list of files. 1639The syntax of a for loop is: 1640.Pp 1641.Bl -tag -compact -width Ds 1642.It Ic \&.for Ar variable Oo Ar variable ... Oc Ic in Ar expression 1643.It Aq make-rules 1644.It Ic \&.endfor 1645.El 1646.Pp 1647After the for 1648.Ic expression 1649is evaluated, it is split into words. 1650On each iteration of the loop, one word is taken and assigned to each 1651.Ic variable , 1652in order, and these 1653.Ic variables 1654are substituted into the 1655.Ic make-rules 1656inside the body of the for loop. 1657The number of words must come out even; that is, if there are three 1658iteration variables, the number of words provided must be a multiple 1659of three. 1660.Sh COMMENTS 1661Comments begin with a hash 1662.Pq Ql \&# 1663character, anywhere but in a shell 1664command line, and continue to the end of an unescaped new line. 1665.Sh SPECIAL SOURCES (ATTRIBUTES) 1666.Bl -tag -width .IGNOREx 1667.It Ic .EXEC 1668Target is never out of date, but always execute commands anyway. 1669.It Ic .IGNORE 1670Ignore any errors from the commands associated with this target, exactly 1671as if they all were preceded by a dash 1672.Pq Ql \- . 1673.\" .It Ic .INVISIBLE 1674.\" XXX 1675.\" .It Ic .JOIN 1676.\" XXX 1677.It Ic .MADE 1678Mark all sources of this target as being up-to-date. 1679.It Ic .MAKE 1680Execute the commands associated with this target even if the 1681.Fl n 1682or 1683.Fl t 1684options were specified. 1685Normally used to mark recursive 1686.Nm Ns 's . 1687.It Ic .META 1688Create a meta file for the target, even if it is flagged as 1689.Ic .PHONY , 1690.Ic .MAKE , 1691or 1692.Ic .SPECIAL . 1693Usage in conjunction with 1694.Ic .MAKE 1695is the most likely case. 1696.It Ic .NOMETA 1697Do not create a meta file for the target. 1698Meta files are also not created for 1699.Ic .PHONY , 1700.Ic .MAKE , 1701or 1702.Ic .SPECIAL 1703targets. 1704.It Ic .NOMETA_CMP 1705Ignore differences in commands when deciding if target is out of date. 1706This is useful if the command contains a value which always changes. 1707If the number of commands change, though, the target will still be out of date. 1708.It Ic .NOPATH 1709Do not search for the target in the directories specified by 1710.Ic .PATH . 1711.It Ic .NOTMAIN 1712Normally 1713.Nm 1714selects the first target it encounters as the default target to be built 1715if no target was specified. 1716This source prevents this target from being selected. 1717.It Ic .OPTIONAL 1718If a target is marked with this attribute and 1719.Nm 1720can't figure out how to create it, it will ignore this fact and assume 1721the file isn't needed or already exists. 1722.It Ic .PHONY 1723The target does not 1724correspond to an actual file; it is always considered to be out of date, 1725and will not be created with the 1726.Fl t 1727option. 1728Suffix-transformation rules are not applied to 1729.Ic .PHONY 1730targets. 1731.It Ic .PRECIOUS 1732When 1733.Nm 1734is interrupted, it normally removes any partially made targets. 1735This source prevents the target from being removed. 1736.It Ic .RECURSIVE 1737Synonym for 1738.Ic .MAKE . 1739.It Ic .SILENT 1740Do not echo any of the commands associated with this target, exactly 1741as if they all were preceded by an at sign 1742.Pq Ql @ . 1743.It Ic .USE 1744Turn the target into 1745.Nm Ns 's 1746version of a macro. 1747When the target is used as a source for another target, the other target 1748acquires the commands, sources, and attributes (except for 1749.Ic .USE ) 1750of the 1751source. 1752If the target already has commands, the 1753.Ic .USE 1754target's commands are appended 1755to them. 1756.It Ic .USEBEFORE 1757Exactly like 1758.Ic .USE , 1759but prepend the 1760.Ic .USEBEFORE 1761target commands to the target. 1762.It Ic .WAIT 1763If 1764.Ic .WAIT 1765appears in a dependency line, the sources that precede it are 1766made before the sources that succeed it in the line. 1767Since the dependents of files are not made until the file itself 1768could be made, this also stops the dependents being built unless they 1769are needed for another branch of the dependency tree. 1770So given: 1771.Bd -literal 1772x: a .WAIT b 1773 echo x 1774a: 1775 echo a 1776b: b1 1777 echo b 1778b1: 1779 echo b1 1780 1781.Ed 1782the output is always 1783.Ql a , 1784.Ql b1 , 1785.Ql b , 1786.Ql x . 1787.br 1788The ordering imposed by 1789.Ic .WAIT 1790is only relevant for parallel makes. 1791.El 1792.Sh SPECIAL TARGETS 1793Special targets may not be included with other targets, i.e. they must be 1794the only target specified. 1795.Bl -tag -width .BEGINx 1796.It Ic .BEGIN 1797Any command lines attached to this target are executed before anything 1798else is done. 1799.It Ic .DEFAULT 1800This is sort of a 1801.Ic .USE 1802rule for any target (that was used only as a 1803source) that 1804.Nm 1805can't figure out any other way to create. 1806Only the shell script is used. 1807The 1808.Ic .IMPSRC 1809variable of a target that inherits 1810.Ic .DEFAULT Ns 's 1811commands is set 1812to the target's own name. 1813.It Ic .END 1814Any command lines attached to this target are executed after everything 1815else is done. 1816.It Ic .ERROR 1817Any command lines attached to this target are executed when another target fails. 1818The 1819.Ic .ERROR_TARGET 1820variable is set to the target that failed. 1821See also 1822.Ic MAKE_PRINT_VAR_ON_ERROR . 1823.It Ic .IGNORE 1824Mark each of the sources with the 1825.Ic .IGNORE 1826attribute. 1827If no sources are specified, this is the equivalent of specifying the 1828.Fl i 1829option. 1830.It Ic .INTERRUPT 1831If 1832.Nm 1833is interrupted, the commands for this target will be executed. 1834.It Ic .MAIN 1835If no target is specified when 1836.Nm 1837is invoked, this target will be built. 1838.It Ic .MAKEFLAGS 1839This target provides a way to specify flags for 1840.Nm 1841when the makefile is used. 1842The flags are as if typed to the shell, though the 1843.Fl f 1844option will have 1845no effect. 1846.\" XXX: NOT YET!!!! 1847.\" .It Ic .NOTPARALLEL 1848.\" The named targets are executed in non parallel mode. 1849.\" If no targets are 1850.\" specified, then all targets are executed in non parallel mode. 1851.It Ic .NOPATH 1852Apply the 1853.Ic .NOPATH 1854attribute to any specified sources. 1855.It Ic .NOTPARALLEL 1856Disable parallel mode. 1857.It Ic .NO_PARALLEL 1858Synonym for 1859.Ic .NOTPARALLEL , 1860for compatibility with other pmake variants. 1861.It Ic .ORDER 1862The named targets are made in sequence. 1863This ordering does not add targets to the list of targets to be made. 1864Since the dependents of a target do not get built until the target itself 1865could be built, unless 1866.Ql a 1867is built by another part of the dependency graph, 1868the following is a dependency loop: 1869.Bd -literal 1870\&.ORDER: b a 1871b: a 1872.Ed 1873.Pp 1874The ordering imposed by 1875.Ic .ORDER 1876is only relevant for parallel makes. 1877.\" XXX: NOT YET!!!! 1878.\" .It Ic .PARALLEL 1879.\" The named targets are executed in parallel mode. 1880.\" If no targets are 1881.\" specified, then all targets are executed in parallel mode. 1882.It Ic .PATH 1883The sources are directories which are to be searched for files not 1884found in the current directory. 1885If no sources are specified, any previously specified directories are 1886deleted. 1887If the source is the special 1888.Ic .DOTLAST 1889target, then the current working 1890directory is searched last. 1891.It Ic .PHONY 1892Apply the 1893.Ic .PHONY 1894attribute to any specified sources. 1895.It Ic .PRECIOUS 1896Apply the 1897.Ic .PRECIOUS 1898attribute to any specified sources. 1899If no sources are specified, the 1900.Ic .PRECIOUS 1901attribute is applied to every 1902target in the file. 1903.It Ic .SHELL 1904Sets the shell that 1905.Nm 1906will use to execute commands. 1907The sources are a set of 1908.Ar field=value 1909pairs. 1910.Bl -tag -width hasErrCtls 1911.It Ar name 1912This is the minimal specification, used to select one of the builtin 1913shell specs; 1914.Ar sh , 1915.Ar ksh , 1916and 1917.Ar csh . 1918.It Ar path 1919Specifies the path to the shell. 1920.It Ar hasErrCtl 1921Indicates whether the shell supports exit on error. 1922.It Ar check 1923The command to turn on error checking. 1924.It Ar ignore 1925The command to disable error checking. 1926.It Ar echo 1927The command to turn on echoing of commands executed. 1928.It Ar quiet 1929The command to turn off echoing of commands executed. 1930.It Ar filter 1931The output to filter after issuing the 1932.Ar quiet 1933command. 1934It is typically identical to 1935.Ar quiet . 1936.It Ar errFlag 1937The flag to pass the shell to enable error checking. 1938.It Ar echoFlag 1939The flag to pass the shell to enable command echoing. 1940.It Ar newline 1941The string literal to pass the shell that results in a single newline 1942character when used outside of any quoting characters. 1943.El 1944Example: 1945.Bd -literal 1946\&.SHELL: name=ksh path=/bin/ksh hasErrCtl=true \e 1947 check="set -e" ignore="set +e" \e 1948 echo="set -v" quiet="set +v" filter="set +v" \e 1949 echoFlag=v errFlag=e newline="'\en'" 1950.Ed 1951.It Ic .SILENT 1952Apply the 1953.Ic .SILENT 1954attribute to any specified sources. 1955If no sources are specified, the 1956.Ic .SILENT 1957attribute is applied to every 1958command in the file. 1959.It Ic .SUFFIXES 1960Each source specifies a suffix to 1961.Nm . 1962If no sources are specified, any previously specified suffixes are deleted. 1963It allows the creation of suffix-transformation rules. 1964.Pp 1965Example: 1966.Bd -literal 1967\&.SUFFIXES: .o 1968\&.c.o: 1969 cc -o ${.TARGET} -c ${.IMPSRC} 1970.Ed 1971.El 1972.Sh ENVIRONMENT 1973.Nm 1974uses the following environment variables, if they exist: 1975.Ev MACHINE , 1976.Ev MACHINE_ARCH , 1977.Ev MAKE , 1978.Ev MAKEFLAGS , 1979.Ev MAKEOBJDIR , 1980.Ev MAKEOBJDIRPREFIX , 1981.Ev MAKESYSPATH , 1982.Ev PWD , 1983and 1984.Ev TMPDIR . 1985.Pp 1986.Ev MAKEOBJDIRPREFIX 1987and 1988.Ev MAKEOBJDIR 1989may only be set in the environment or on the command line to 1990.Nm 1991and not as makefile variables; 1992see the description of 1993.Ql Va .OBJDIR 1994for more details. 1995.Sh FILES 1996.Bl -tag -width /usr/share/mk -compact 1997.It .depend 1998list of dependencies 1999.It Makefile 2000list of dependencies 2001.It makefile 2002list of dependencies 2003.It sys.mk 2004system makefile 2005.It /usr/share/mk 2006system makefile directory 2007.El 2008.Sh COMPATIBILITY 2009The basic make syntax is compatible between different versions of make, 2010however the special variables, variable modifiers and conditionals are not. 2011.Pp 2012The way that parallel makes are scheduled changed in 2013.Nx 4.0 2014so that .ORDER and .WAIT apply recursively to the dependent nodes. 2015The algorithms used may change again in the future. 2016.Pp 2017The way that .for loop variables are substituted changed after 2018.Nx 5.0 2019so that they still appear to be variable expansions. 2020In particular this stops them being treated as syntax, and removes some 2021obscure problems using them in .if statements. 2022.Pp 2023Unlike other 2024.Nm 2025programs, this implementation by default executes all commands for a given 2026target using a single shell invocation. 2027This is done for both efficiency and to simplify error handling in remote 2028command invocations. 2029Typically this is transparent to the user, unless the target commands change 2030the current working directory using 2031.Dq cd 2032or 2033.Dq chdir . 2034To be compatible with Makefiles that do this, one can use 2035.Fl B 2036to disable this behavior. 2037.Sh SEE ALSO 2038.Xr mkdep 1 2039.Sh HISTORY 2040A 2041.Nm 2042command appeared in 2043.At v7 . 2044This 2045.Nm 2046implementation is based on Adam De Boor's pmake program which was written 2047for Sprint at Berkeley. 2048It was designed to be a parallel distributed make running jobs on different 2049machines using a daemon called 2050.Dq customs . 2051.Sh BUGS 2052The 2053.Nm 2054syntax is difficult to parse without actually acting of the data. 2055For instance finding the end of a variable use should involve scanning each 2056the modifiers using the correct terminator for each field. 2057In many places 2058.Nm 2059just counts {} and () in order to find the end of a variable expansion. 2060.Pp 2061There is no way of escaping a space character in a filename. 2062