1.\" $MirOS: src/usr.bin/make/make.1,v 1.16 2009/11/22 18:23:46 tg Exp $ 2.\" $OpenBSD: make.1,v 1.68 2007/05/31 19:20:13 jmc Exp $ 3.\" $OpenPackages$ 4.\" $NetBSD: make.1,v 1.18 1997/03/10 21:19:53 christos Exp $ 5.\" 6.\" Copyright (c) 1990, 1993 7.\" The Regents of the University of California. All rights reserved. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. Neither the name of the University nor the names of its contributors 18.\" may be used to endorse or promote products derived from this software 19.\" without specific prior written permission. 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 34.\" 35.\"- 36.\" Copyright (c) 2008, 2009 37.\" Thorsten “mirabilos” Glaser <tg@mirbsd.org> 38.\"- 39.\" Try to make GNU groff and AT&T nroff more compatible 40.\" * ` generates ‘ in gnroff, so use \` 41.\" * ' generates ’ in gnroff, \' generates ´, so use \*(aq 42.\" * - generates ‐ in gnroff, \- generates −, so .tr it to - 43.\" thus use - for hyphens and \- for minus signs and option dashes 44.\" * ~ is size-reduced and placed atop in groff, so use \*(TI 45.\" * ^ is size-reduced and placed atop in groff, so use \*(ha 46.\" * \(en does not work in nroff, so use \*(en 47.\" The section after the "doc" macropackage has been loaded contains 48.\" additional code to convene between the UCB mdoc macropackage (and 49.\" its variant as BSD mdoc in groff) and the GNU mdoc macropackage. 50.\" 51.ie \n(.g \{\ 52. if \*[.T]ascii .tr \-\N'45' 53. if \*[.T]latin1 .tr \-\N'45' 54. if \*[.T]utf8 .tr \-\N'45' 55. ds <= \[<=] 56. ds >= \[>=] 57. ds Rq \[rq] 58. ds Lq \[lq] 59. ds sL \(aq 60. ds sR \(aq 61. if \*[.T]utf8 .ds sL ` 62. if \*[.T]ps .ds sL ` 63. if \*[.T]utf8 .ds sR ' 64. if \*[.T]ps .ds sR ' 65. ds aq \(aq 66. ds TI \(ti 67. ds ha \(ha 68. ds en \(en 69.\} 70.el \{\ 71. ds aq ' 72. ds TI ~ 73. ds ha ^ 74. ds en \(em 75.\} 76.\" 77.\" Implement .Dd with the Mdocdate RCS keyword 78.\" 79.rn Dd xD 80.de Dd 81.ie \\$1$Mdocdate: \{\ 82. xD \\$2 \\$3, \\$4 83.\} 84.el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 85.. 86.\" 87.\" .Dd must come before definition of .Mx, because when called 88.\" with -mandoc, it might implement .Mx itself, but we want to 89.\" use our own definition. And .Dd must come *first*, always. 90.\" 91.Dd $Mdocdate: November 22 2009 $ 92.\" 93.\" Check which macro package we use 94.\" 95.ie \n(.g \{\ 96. ie d volume-ds-1 .ds tT gnu 97. el .ds tT bsd 98.\} 99.el .ds tT ucb 100.\" 101.\" Implement .Mx (MirBSD) 102.\" 103.ie "\*(tT"gnu" \{\ 104. eo 105. de Mx 106. nr curr-font \n[.f] 107. nr curr-size \n[.ps] 108. ds str-Mx \f[\n[curr-font]]\s[\n[curr-size]u] 109. ds str-Mx1 \*[Tn-font-size]\%MirOS\*[str-Mx] 110. if !\n[arg-limit] \ 111. if \n[.$] \{\ 112. ds macro-name Mx 113. parse-args \$@ 114. \} 115. if (\n[arg-limit] > \n[arg-ptr]) \{\ 116. nr arg-ptr +1 117. ie (\n[type\n[arg-ptr]] == 2) \ 118. as str-Mx1 \~\*[arg\n[arg-ptr]] 119. el \ 120. nr arg-ptr -1 121. \} 122. ds arg\n[arg-ptr] "\*[str-Mx1] 123. nr type\n[arg-ptr] 2 124. ds space\n[arg-ptr] "\*[space] 125. nr num-args (\n[arg-limit] - \n[arg-ptr]) 126. nr arg-limit \n[arg-ptr] 127. if \n[num-args] \ 128. parse-space-vector 129. print-recursive 130.. 131. ec 132. ds sP \s0 133. ds tN \*[Tn-font-size] 134.\} 135.el \{\ 136. de Mx 137. nr cF \\n(.f 138. nr cZ \\n(.s 139. ds aa \&\f\\n(cF\s\\n(cZ 140. if \\n(aC==0 \{\ 141. ie \\n(.$==0 \&MirOS\\*(aa 142. el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9 143. \} 144. if \\n(aC>\\n(aP \{\ 145. nr aP \\n(aP+1 146. ie \\n(C\\n(aP==2 \{\ 147. as b1 \&MirOS\ #\&\\*(A\\n(aP\\*(aa 148. ie \\n(aC>\\n(aP \{\ 149. nr aP \\n(aP+1 150. nR 151. \} 152. el .aZ 153. \} 154. el \{\ 155. as b1 \&MirOS\\*(aa 156. nR 157. \} 158. \} 159.. 160.\} 161.\"- 162.Dt MAKE 1 163.Os 164.Sh NAME 165.Nm make 166.Nd maintain program dependencies 167.Sh SYNOPSIS 168.Nm make 169.Op Fl BeiknPqrSst 170.Op Fl D Ar variable 171.Op Fl d Ar flags 172.Op Fl f Ar makefile 173.Op Fl I Ar directory 174.Op Fl j Ar max_jobs 175.Op Fl m Ar directory 176.Op Fl V Ar variable 177.Op Ar NAME Ns = Ns Ar value 178.Bk -words 179.Op Ar target ... 180.Ek 181.Sh DESCRIPTION 182.Nm 183is a program designed to simplify the maintenance of other programs. 184Its input is a list of specifications as to the files upon which programs 185and other files depend. 186If the file 187.Sq Pa BSDmakefile 188exists, it is read for this list of specifications. 189If it does not exist, the files 190.Sq Pa makefile 191and 192.Sq Pa Makefile 193are tried in order. 194If the file 195.Sq Pa .depend 196exists, it is read in addition to the makefile (see 197.Xr mkdep 1 ) . 198.Pp 199The handling of 200.Sq Pa BSDmakefile 201and 202.Sq Pa .depend 203are BSD extensions. 204.Pp 205Standard options are as follows: 206.Bl -tag -width Ds 207.It Fl e 208Specify that environment variables override macro assignments within 209makefiles. 210.It Fl f Ar makefile 211Specify a makefile to read instead of the default 212.Sq Pa makefile 213and 214.Sq Pa Makefile . 215If 216.Ar makefile 217is 218.Ql \- , 219standard input is read. 220Multiple makefiles may be specified, and are read in the order specified. 221.It Fl i 222Ignore non-zero exit of shell commands in the makefile. 223Equivalent to specifying 224.Ql \- 225before each command line in the makefile. 226.It Fl k 227Continue processing after errors are encountered, but only on those targets 228that do not depend on the target whose creation caused the error. 229.It Fl n 230Display the commands that would have been executed, but do not actually 231execute them. 232.It Fl q 233Do not execute any commands, but exit with status 0 if the specified targets 234are up-to-date, and 1 otherwise. 235.It Fl r 236Do not use the built-in rules specified in the system makefile. 237.It Fl S 238Stop processing when an error is encountered. 239This is the default behavior. 240This is needed to negate the 241.Fl k 242option during recursive builds. 243.It Fl s 244Do not echo commands as they are executed. 245Equivalent to specifying 246.Sq Ic @ 247before each command line in the makefile. 248.It Fl t 249Rather than re-building a target as specified in the makefile, create it 250or update its modification time to make it appear up-to-date. 251.It Ar NAME Ns = Ns Ar value 252Set the value of the variable 253.Ar NAME 254to 255.Ar value . 256.El 257.Pp 258Extended options are as follows: 259.Bl -tag -width Ds 260.It Fl B 261Try to be backwards compatible by executing a single shell per command and by 262executing the commands to make the sources of a dependency line in sequence. 263This is turned on by default unless 264.Fl j 265is used. 266.It Fl D Ar variable 267Define 268.Ar variable 269to be 1. 270.It Fl d Ar flags 271Turn on debugging, and specify which portions of 272.Nm 273are to print debugging information. 274.Ar flags 275is one or more of the following: 276.Bl -tag -width Ds 277.It Ar A 278Print all possible debugging information; 279equivalent to specifying all of the debugging flags. 280.It Ar a 281Print debugging information about archive searching and caching. 282.It Ar c 283Print debugging information about conditional evaluation. 284.It Ar d 285Print debugging information about directory searching and caching. 286.It Ar f 287Print debugging information about the expansion of for loops. 288.It Ar "g1" 289Print the input graph before making anything. 290.It Ar "g2" 291Print the input graph after making everything, or before exiting 292on error. 293.It Ar j 294Print debugging information about running multiple shells. 295.It Ar l 296Print commands in Makefile targets regardless of whether or not they are 297prefixed by @. 298Also known as loud behavior. 299.It Ar m 300Print debugging information about making targets, including modification 301dates. 302.It Ar s 303Print debugging information about suffix-transformation rules. 304.It Ar t 305Print debugging information about target list maintenance. 306.It Ar v 307Print debugging information about variable assignment. 308.El 309.It Fl I Ar directory 310Specify a directory in which to search for makefiles and included makefiles. 311The system makefile directory (or directories, see the 312.Fl m 313option) is automatically included as part of this list. 314.It Fl j Ar max_jobs 315Specify the maximum number of jobs that 316.Nm 317may have running at any one time. 318Turns compatibility mode off, unless the 319.Fl B 320flag is also specified. 321.It Fl m Ar directory 322Specify a directory in which to search for 323.Pa sys.mk 324and makefiles included 325via the \*(Lt...\*(Gt style. 326Multiple directories can be added to form a search path. 327This path will override the default system include path: 328.Pa /usr/share/mk . 329Furthermore, the system include path will be appended to the search path used 330for "..."-style inclusions (see the 331.Fl I 332option). 333.It Fl P 334Collate the output of a given job and display it only when the job finishes, 335instead of mixing the output of parallel jobs together. 336This option has no effect unless 337.Fl j 338is used too. 339.It Fl V Ar variable 340Print 341.Nm make Ns 's 342idea of the value of 343.Ar variable . 344Do not build any targets. 345Multiple instances of this option may be specified; 346the variables will be printed one per line, 347with a blank line for each null or undefined variable. 348.El 349.Pp 350There are seven different types of lines in a makefile: file dependency 351specifications, shell commands, variable assignments, include statements, 352conditional directives, for loops, and comments. 353Of these, include statements, conditional directives and for loops are 354extensions. 355.Pp 356In general, lines may be continued from one line to the next by ending 357them with a backslash 358.Pq Ql \e . 359The trailing newline character and initial whitespace on the following 360line are compressed into a single space. 361You cannot embed comments between line continuations. 362.Sh FILE DEPENDENCY SPECIFICATIONS 363Dependency lines consist of one or more targets, an operator, and zero 364or more sources. 365This creates a relationship where the targets 366.Dq depend 367on the sources 368and are usually created from them. 369The exact relationship between the target and the source is determined 370by the operator that separates them. 371Note that the use of several targets is merely a shorthand for duplicate 372rules. 373Specifically, 374.Bd -literal -offset indent 375target1 target2: depa depb 376 cmd1 377 cmd2 378.Ed 379.Pp 380is just a short form of 381.Bd -literal -offset indent 382target1: depa depb 383 cmd1 384 cmd2 385target2: depa depb 386 cmd1 387 cmd2 388.Ed 389.Pp 390.Nm 391does not support Solaris syntax for true multiple targets: 392.Bd -literal -offset indent 393target1 + target2: depa depb 394 cmd1 395 cmd2 396.Ed 397.Pp 398The operators are as follows: 399.Bl -tag -width flag 400.It Ic \&: 401A target is considered out-of-date if its modification time is less than 402those of any of its sources. 403Sources for a target accumulate over dependency lines when this operator 404is used. 405The target is removed if 406.Nm 407is interrupted. 408.It Ic \&! 409Targets are always re-created, but not until all sources have been 410examined and re-created as necessary. 411Sources for a target accumulate over dependency lines when this operator 412is used. 413The target is removed if 414.Nm 415is interrupted. 416.It Ic \&:: 417If no sources are specified, the target is always re-created. 418Otherwise, a target is considered out-of-date if any of its sources has 419been modified more recently than the target. 420Sources for a target do not accumulate over dependency lines when this 421operator is used. 422The target will not be removed if 423.Nm 424is interrupted. 425.El 426.Pp 427The 428.Ic \&:: 429operator is a fairly standard extension. 430The 431.Ic \&!\& 432operator is a BSD extension. 433.Pp 434As an extension, targets and sources may contain the shell wildcard 435expressions 436.Ql \&? , 437.Ql * , 438.Ql [] 439and 440.Ql {} . 441The expressions 442.Ql \&? , 443.Ql * 444and 445.Ql [] 446may only be used as part of the final 447component of the target or source, and must be used to describe existing 448files. 449The expression 450.Ql {} 451need not necessarily be used to describe existing files. 452Expansion is in directory order, not alphabetically as done in the shell. 453.Pp 454For maximum portability, target names should only consist of periods, 455underscores, digits and alphabetic characters. 456.Sh SHELL COMMANDS 457Each target may have associated with it a series of shell commands, normally 458used to create the target. 459Each of the commands in this script 460.Em must 461be preceded by a tab. 462While any target may appear on a dependency line, only one of these 463dependencies may be followed by a creation script, unless the 464.Sq Ic :: 465operator is used. 466.Pp 467If a command line begins with a combination of the characters, 468.Sq Ic @ , 469.Sq Ic \- 470and/or 471.Sq Ic + , 472the command is treated specially: 473.Bl -tag -width '@' 474.It Sq Ic @ 475causes the command not to be echoed before it is executed. 476.It Sq Ic \- 477causes any non-zero exit status of the command line to be ignored. 478.It Sq Ic + 479causes the command to be executed even if 480.Fl n 481has been specified. 482(This can be useful to debug recursive Makefiles.) 483.El 484.Pp 485The command is always executed using 486.Pa @@MKSH@@ 487in 488.Qq set \-e 489mode. 490(Using the MirBSD Korn Shell, 491.Pa @@MKSH@@ , 492instead of the bourne shell, 493.Pa /bin/sh , 494is a MirOS extension.) 495.Sh VARIABLE ASSIGNMENTS 496Variables in 497.Nm 498are much like variables in the shell, and, by tradition, 499consist of all upper-case letters. 500They are also called 501.Sq macros 502in various texts. 503For portability, only periods, underscores, digits and letters should be 504used for variable names. 505The five operators that can be used to assign values to variables are as 506follows: 507.Bl -tag -width Ds 508.It Ic \&= 509Assign the value to the variable. 510Any previous value is overridden. 511.It Ic \&:= 512Assign with expansion, i.e., expand the value before assigning it 513to the variable (extension). 514.It Ic \&+= 515Append the value to the current value of the variable (extension). 516.It Ic \&?= 517Assign the value to the variable if it is not already defined (BSD 518extension). 519Normally, expansion is not done until the variable is referenced. 520.It Ic \&!= 521Expand the value and pass it to the shell for execution and assign 522the result to the variable. 523Any newlines in the result are replaced with spaces (BSD extension). 524.El 525.Pp 526Any whitespace before the assigned 527.Ar value 528is removed; if the value is being appended, a single space is inserted 529between the previous contents of the variable and the appended value. 530.Pp 531Variables are expanded by surrounding the variable name with either 532curly braces 533.Pq Ql {} 534or parentheses 535.Pq Ql () 536and preceding it with 537a dollar sign 538.Pq Ql \&$ . 539If the variable name contains only a single letter, the surrounding 540braces or parentheses are not required. 541This shorter form is not recommended. 542.Pp 543Variable substitution occurs at two distinct times, depending on where 544the variable is being used. 545Variables in dependency lines are expanded as the line is read. 546Variables in shell commands are expanded when the shell command is 547executed. 548.Pp 549The four different classes of variables (in order of increasing precedence) 550are: 551.Bl -tag -width Ds 552.It Environment variables 553Variables defined as part of 554.Nm make Ns 's 555environment. 556.It Global variables 557Variables defined in the makefile or in included makefiles. 558.It Command line variables 559Variables defined as part of the command line. 560.It Local variables 561Variables that are defined specific to a certain target. 562Standard local variables are as follows: 563.Bl -tag -width ".ARCHIVE" 564.It Va @ 565The name of the target. 566.It Va \&% 567The name of the archive member (only valid for library rules). 568.It Va \&! 569The name of the archive file (only valid for library rules). 570.It Va \&? 571The list of prerequisites for this target that were deemed out-of-date. 572.It Va \&\*(Lt 573The name of the source from which this target is to be built, if a valid 574implied rule (suffix rule) is in scope. 575.It Va * 576The file prefix of the file, containing only the file portion, 577no suffix or preceding directory components. 578.El 579.Pp 580The six variables 581.Sq Va "@F" , 582.Sq Va "@D" , 583.Sq Va "\*(LtF" , 584.Sq Va "\*(LtD" , 585.Sq Va "*F" , 586and 587.Sq Va "*D" 588yield the 589.Qq filename 590and 591.Qq directory 592parts of the corresponding macros. 593.Pp 594For maximum compatibility, 595.Sq Va \&\*(Lt 596should only be used for actual implied rules. 597It is also set when there is an implied rule that matches the current 598dependency in scope. 599That is, in 600.Bd -literal -offset indent 601\&.SUFFIXES: .c .o 602file.o: file.c 603 cmd1 $\*(Lt 604 605\&.c.o: 606 cmd2 607.Ed 608.Pp 609building 610.Pa file.o 611will execute 612.Qq cmd1 file.c . 613.Pp 614As an extension, 615.Nm 616supports the following local variables: 617.Bl -tag -width ".ARCHIVE" 618.It Va \&\*(Gt 619The list of all sources for this target. 620.It Va \&\*(ha 621The GNU make equivalent of 622.Sq Va \&\*(Gt . 623Only recognised for compatibility, do not use. 624.It Va .ALLSRC 625Synonym for 626.Sq Va \&\*(Gt . 627.It Va .ARCHIVE 628Synonym for 629.Sq Va \&! . 630.It Va .IMPSRC 631Synonym for 632.Sq Va \&\*(Lt . 633.It Va .MEMBER 634Synonym for 635.Sq Va \&% . 636.It Va .OODATE 637Synonym for 638.Sq Va \&? . 639.It Va .PREFIX 640Synonym for 641.Sq Va * . 642.It Va .TARGET 643Synonym for 644.Sq Va @ . 645.El 646.Pp 647These variables may be used on the dependency half of dependency 648lines, when they make sense. 649.El 650.Pp 651In addition, 652.Nm 653sets or knows about the following internal variables, or environment 654variables: 655.Bl -tag -width MAKEFLAGS 656.It Va \&$ 657A single dollar sign 658.Ql \&$ , 659i.e., 660.Ql \&$$ 661expands to a single dollar 662sign. 663.It Va .MAKE 664The name that 665.Nm 666was executed with 667.Pq Va argv Ns Op 0 . 668.It Va .SYSMK 669Path in which 670.Pa sys.mk 671is found (normally 672.Pa /usr/share/mk , 673can be changed with the 674.Fl m 675option). 676.It Va .CURDIR 677A path to the directory where 678.Nm 679was executed. 680.It Va .OBJDIR 681A path to the directory where the targets are built. 682At startup, 683.Nm 684searches for an alternate directory to place target files \*(en it 685will attempt to change into this special directory. 686First, if 687.Ev MAKEOBJDIRPREFIX 688is defined, 689.Nm 690prepends its contents to the current directory name and tries for 691the resulting directory. 692If that fails, 693.Nm 694remains in the current directory. 695If 696.Ev MAKEOBJDIRPREFIX 697is not defined, 698.Nm 699checks 700.Ev MAKEOBJDIR 701and tries to change into that directory. 702Should that fail, 703.Nm 704remains in the current directory. 705If 706.Ev MAKEOBJDIR 707is not defined, it tries to change into the directory named 708.Pa obj.${MACHINE} 709(see 710.Va MACHINE 711variable). 712If it still has found no special directory, 713.Nm 714next tries the directory named 715.Pa obj . 716If this fails, 717.Nm 718tries to prepend 719.Pa /usr/obj 720to the current directory name. 721Finally, if none of these directories are available 722.Nm 723will settle for and use the current directory. 724This is a BSD (except 725.Nx ) 726extension. 727.It Va .MAKEFLAGS 728The environment variable 729.Ev MAKEFLAGS 730may contain anything that 731may be specified on 732.Nm make Ns 's 733command line. 734Its contents are stored in 735.Nm make Ns 's 736.Va .MAKEFLAGS 737variable. 738Anything specified on 739.Nm make Ns 's 740command line is appended to the 741.Va .MAKEFLAGS 742variable which is then 743entered into the environment as 744.Ev MAKEFLAGS 745for all programs which 746.Nm 747executes. 748.It Va MFLAGS 749A shorter synonym for 750.Va .MAKEFLAGS . 751.It Va PWD 752Alternate path to the current directory. 753.Nm 754normally sets 755.Sq Va .CURDIR 756to the canonical path given by 757.Xr getcwd 3 . 758However, if the environment variable 759.Ev PWD 760is set and gives a path to the current directory, then 761.Nm 762sets 763.Sq Va .CURDIR 764to the value of 765.Ev PWD 766instead. 767.Ev PWD 768is always set to the value of 769.Sq Va .OBJDIR 770for all programs which 771.Nm 772executes. 773.It Va .TARGETS 774List of targets 775.Nm 776is currently building. 777.It Va .INCLUDES 778See 779.Ic .INCLUDES 780special target. 781.It Va .LIBS 782See 783.Ic .LIBS 784special target. 785.It Va MACHINE 786Name of the machine architecture 787.Nm 788is running on, obtained from the 789.Ev MACHINE 790environment variable, or through 791.Xr uname 3 792if not defined. 793.It Va MACHINE_ARCH 794Name of the machine architecture 795.Nm 796was compiled for, obtained from the 797.Ev MACHINE_ARCH 798environment variable, or defined at compilation time. 799.It Va MACHINE_OS 800Name of the operating system type 801.Nm 802was compiled for, obtained from the 803.Ev MACHINE_OS 804environment variable, or defined at compilation time. 805.El 806.Pp 807Variable expansion may be modified to select or modify each word of the 808variable (where 809.Dq word 810is a whitespace delimited sequence of characters). 811The general format of a variable expansion is as follows: 812.Pp 813.Dl {variable[:modifier[:...]]} 814.Pp 815Each modifier begins with a colon and one of the following 816special characters. 817The colon may be escaped with a backslash 818.Pq Ql \e . 819.Bl -tag -width Ds 820.It Cm :E 821Replaces each word in the variable with its suffix. 822.It Cm :H 823Replaces each word in the variable with everything but the last component. 824.It Cm :L 825Replaces each word in the variable with its lower case equivalent. 826.It Cm :U 827Replaces each word in the variable with its upper case equivalent. 828.It Cm :M Ns Ar pattern 829Select only those words that match the rest of the modifier. 830The standard shell wildcard characters 831.Pf ( Ql * , 832.Ql \&? , 833and 834.Ql [] ) 835may 836be used. 837The wildcard characters may be escaped with a backslash 838.Pq Ql \e . 839.It Cm :N Ns Ar pattern 840This is identical to 841.Cm :M , 842but selects all words which do not match 843the rest of the modifier. 844.It Cm :Q 845Quotes every shell meta-character in the variable, so that it can be passed 846safely through recursive invocations of 847.Nm make . 848.It Cm :R 849Replaces each word in the variable with everything but its suffix. 850.Sm off 851.It Cm :S No \&/ Ar old_string Xo 852.No \&/ Ar new_string 853.No \&/ Op Cm 1g 854.Xc 855.Sm on 856Modify the first occurrence of 857.Ar old_string 858in the variable's value, replacing it with 859.Ar new_string . 860If a 861.Ql g 862is appended to the last slash of the pattern, all occurrences 863in each word are replaced. 864If a 865.Ql 1 866is appended to the last slash of the pattern, only the first word 867is affected. 868If 869.Ar old_string 870begins with a caret 871.Pq Ql \*(ha , 872.Ar old_string 873is anchored at the beginning of each word. 874If 875.Ar old_string 876ends with a dollar sign 877.Pq Ql \&$ , 878it is anchored at the end of each word. 879Inside 880.Ar new_string , 881an ampersand 882.Pq Ql & 883is replaced by 884.Ar old_string 885(without any 886.Ql \*(ha 887or 888.Ql \&$ ) . 889Any character may be used as a delimiter for the parts of the modifier 890string. 891The anchoring, ampersand and delimiter characters may be escaped with a 892backslash 893.Pq Ql \e . 894.Pp 895Variable expansion occurs in the normal fashion inside both 896.Ar old_string 897and 898.Ar new_string 899with the single exception that a backslash is used to prevent the expansion 900of a dollar sign 901.Pq Ql \&$ , 902not a preceding dollar sign as is usual. 903.Sm off 904.It Cm :C No \&/ Ar pattern Xo 905.No \&/ Ar replacement 906.No \&/ Op Cm 1g 907.Xc 908.Sm on 909The 910.Cm :C 911modifier is just like the 912.Cm :S 913modifier except that the old and new strings, instead of being 914simple strings, are a POSIX extended regular expression (see 915.Xr re_format 7 ) 916and an 917.Xr ed 1 Ns \-style 918replacement string. 919Normally, the first occurrence of the pattern in 920each word of the value is changed. 921The 922.Ql 1 923modifier causes the substitution to apply to at most one word; the 924.Ql g 925modifier causes the substitution to apply to as many instances of the 926search pattern as occur in the word or words it is found in. 927Note that 928.Ql 1 929and 930.Ql g 931are orthogonal; the former specifies whether multiple words are 932potentially affected, the latter whether multiple substitutions can 933potentially occur within each affected word. 934.It Cm :T 935Replaces each word in the variable with its last component. 936.It Ar :old_string Ns = Ns Ar new_string 937This is the 938.At V 939style variable substitution. 940It must be the last modifier specified. 941If 942.Ar old_string 943or 944.Ar new_string 945do not contain the pattern matching character 946.Ar % 947then it is assumed that they are 948anchored at the end of each word, so only suffixes or entire 949words may be replaced. 950Otherwise 951.Ar % 952is the substring of 953.Ar old_string 954to be replaced in 955.Ar new_string . 956.El 957.Pp 958All modifiers are BSD extensions, except for the standard 959.At V 960style variable substitution. 961.Sh INCLUDE STATEMENTS, CONDITIONALS AND FOR LOOPS 962Makefile inclusion, conditional structures and for loops reminiscent 963of the C programming language are provided in 964.Nm make . 965All such structures are identified by a line beginning with a single 966dot 967.Pq Ql \&. 968character. 969Whitespace characters may follow this dot, e.g., 970.Bd -literal -offset indent 971\&.include \*(Ltfile\*(Gt 972.Ed 973and 974.Bd -literal -offset indent -compact 975\&. include \*(Ltfile\*(Gt 976.Ed 977.Pp 978are identical constructs. 979Files are included with either 980.Ql .include \*(Ltfile\*(Gt 981or 982.Ql .include \*qfile\*q . 983Variables between the angle brackets or double quotes are expanded 984to form the file name. 985If angle brackets are used, the included makefile is expected to be in 986the system makefile directory. 987If double quotes are used, the including makefile's directory and any 988directories specified using the 989.Fl I 990option are searched before the system 991makefile directory. 992.Pp 993Conditional expressions are also preceded by a single dot as the first 994character of a line. 995The possible conditionals are as follows: 996.Bl -tag -width Ds 997.It Ic .error Ar message 998Report the error message to the user and abort. 999Variables are expanded once and their expansion displayed. 1000.It Ic .trace Ar message 1001Report the informal message to the user. 1002Variables are expanded once and their expansion displayed. 1003.It Ic .undef Ar variable 1004Un-define the specified global variable. 1005Only global variables may be un-defined. 1006.It Xo 1007.Ic \&.if 1008.Oo \&! Oc Ns Ar expression 1009.Op Ar operator expression ... 1010.Xc 1011Test the value of an expression. 1012.It Xo 1013.Ic .ifdef 1014.Oo \&! Oc Ns Ar variable 1015.Op Ar operator variable ... 1016.Xc 1017Test the value of a variable. 1018.It Xo 1019.Ic .ifndef 1020.Oo \&! Oc Ns Ar variable 1021.Op Ar operator variable ... 1022.Xc 1023Test the value of a variable. 1024.It Xo 1025.Ic .ifmake 1026.Oo \&! Oc Ns Ar target 1027.Op Ar operator target ... 1028.Xc 1029Test the target being built. 1030.It Xo 1031.Ic .ifnmake 1032.Oo \&! Oc Ar target 1033.Op Ar operator target ... 1034.Xc 1035Test the target being built. 1036.It Ic .else 1037Reverse the sense of the last conditional. 1038.It Xo 1039.Ic .elif 1040.Oo \&! Oc Ar expression 1041.Op Ar operator expression ... 1042.Xc 1043A combination of 1044.Sq Ic .else 1045followed by 1046.Sq Ic .if . 1047.It Xo 1048.Ic .elifdef 1049.Oo \&! Oc Ns Ar variable 1050.Op Ar operator variable ... 1051.Xc 1052A combination of 1053.Sq Ic .else 1054followed by 1055.Sq Ic .ifdef . 1056.It Xo 1057.Ic .elifndef 1058.Oo \&! Oc Ns Ar variable 1059.Op Ar operator variable ... 1060.Xc 1061A combination of 1062.Sq Ic .else 1063followed by 1064.Sq Ic .ifndef . 1065.It Xo 1066.Ic .elifmake 1067.Oo \&! Oc Ns Ar target 1068.Op Ar operator target ... 1069.Xc 1070A combination of 1071.Sq Ic .else 1072followed by 1073.Sq Ic .ifmake . 1074.It Xo 1075.Ic .elifnmake 1076.Oo \&! Oc Ns Ar target 1077.Op Ar operator target ... 1078.Xc 1079A combination of 1080.Sq Ic .else 1081followed by 1082.Sq Ic .ifnmake . 1083.It Ic .endif 1084End the body of the conditional. 1085.El 1086.Pp 1087The 1088.Ar operator 1089may be any one of the following: 1090.Bl -tag -width "Cm XX" 1091.It Cm \*(Ba\*(Ba 1092logical OR 1093.It Cm \&&& 1094Logical 1095.Tn AND ; 1096of higher precedence than 1097.Dq \*(Ba\*(Ba . 1098.El 1099.Pp 1100As in C, 1101.Nm 1102will only evaluate a conditional as far as is necessary to determine 1103its value. 1104Parentheses may be used to change the order of evaluation. 1105The boolean operator 1106.Sq Ic \&! 1107may be used to logically negate an entire 1108conditional. 1109It is of higher precedence than 1110.Sq Ic \&&& . 1111.Pp 1112The value of 1113.Ar expression 1114may be any of the following: 1115.Bl -tag -width defined 1116.It Ic defined 1117Takes a variable name as an argument and evaluates to true if the variable 1118has been defined. 1119.It Ic make 1120Takes a target name as an argument and evaluates to true if the target 1121was specified as part of 1122.Nm make Ns 's 1123command line or was declared the default target (either implicitly or 1124explicitly, see 1125.Va .MAIN ) 1126before the line containing the conditional. 1127.It Ic empty 1128Takes a variable, with possible modifiers, and evaluates to true if 1129the expansion of the variable would result in an empty string. 1130.It Ic exists 1131Takes a file name as an argument and evaluates to true if the file exists. 1132The file is searched for on the system search path (see 1133.Va .PATH ) . 1134.It Ic target 1135Takes a target name as an argument and evaluates to true if the target 1136has been defined. 1137.El 1138.Pp 1139.Ar expression 1140may also be an arithmetic or string comparison. 1141Variable expansion is 1142performed on both sides of the comparison, after which the integral 1143values are compared. 1144A value is interpreted as hexadecimal if it is 1145preceded by 0x, otherwise it is decimal; octal numbers are not supported. 1146The standard C relational operators are all supported. 1147If after 1148variable expansion, either the left or right hand side of a 1149.Sq Ic == 1150or 1151.Sq Ic "!=" 1152operator is not an integral value, then 1153string comparison is performed between the expanded 1154variables. 1155If no relational operator is given, it is assumed that the expanded 1156variable is being compared against 0. 1157.Pp 1158When 1159.Nm 1160is evaluating one of these conditional expressions, and it encounters 1161a word it doesn't recognize, either the 1162.Dq make 1163or 1164.Dq defined 1165expression is applied to it, depending on the form of the conditional. 1166If the form is 1167.Sq Ic .ifdef 1168or 1169.Sq Ic .ifndef , 1170the 1171.Dq defined 1172expression is applied. 1173Similarly, if the form is 1174.Sq Ic .ifmake 1175or 1176.Sq Ic .ifnmake , 1177the 1178.Dq make 1179expression is applied. 1180.Pp 1181If the conditional evaluates to true the parsing of the makefile continues 1182as before. 1183If it evaluates to false, the following lines are skipped. 1184In both cases this continues until a 1185.Sq Ic .else 1186or 1187.Sq Ic .endif 1188is found. 1189.Pp 1190For loops are typically used to apply a set of rules to a list of files. 1191The syntax of a for loop is: 1192.Bd -unfilled -offset indent 1193.Xo 1194.Ic .for Ar variable Op Ar variable ... 1195.Ic in 1196.Ar expression 1197.Xc 1198 \*(Ltmake-rules\*(Gt 1199.Ic \&.endfor 1200.Ed 1201.Pp 1202After the for 1203.Ar expression 1204is evaluated, it is split into words. 1205On each iteration of the loop, one word is assigned to each 1206.Ar variable , 1207in order, 1208and these 1209.Ar variables 1210are substituted in the 1211.Ic make-rules 1212inside the body of the for loop. 1213The number of words must match the number of iteration variables; 1214that is, if there are three iteration variables, the number of words 1215must be a multiple of three. 1216.Pp 1217Loops and conditional expressions may nest arbitrarily, but 1218they may not cross include file boundaries. 1219.Sh COMMENTS 1220Comments begin with a hash 1221.Pq Ql \&# 1222character, anywhere but in a shell 1223command line, and continue to the end of the line. 1224.Sh SPECIAL SOURCES 1225.Bl -tag -width ".PRECIOUS" 1226.It Ic .IGNORE 1227Ignore any errors from the commands associated with this target, exactly 1228as if they all were preceded by a dash 1229.Pq Ql \- . 1230.It Ic .MADE 1231Mark all sources of this target as being up-to-date. 1232.It Ic .MAKE 1233Execute the commands associated with this target even if the 1234.Fl n 1235or 1236.Fl t 1237options were specified. 1238Normally used to mark recursive 1239.Nm make Ns 's . 1240.It Ic .NOTMAIN 1241Normally 1242.Nm 1243selects the first target it encounters as the default target to be built 1244if no target was specified. 1245This source prevents this target from being selected. 1246.It Ic .OPTIONAL 1247If a target is marked with this attribute and 1248.Nm 1249can't figure out how to create it, it will ignore this fact and assume 1250the file isn't needed or already exists. 1251.It Ic .PRECIOUS 1252When 1253.Nm 1254is interrupted, it removes any partially made targets. 1255This source prevents the target from being removed. 1256.It Ic .SILENT 1257Do not echo any of the commands associated with this target, exactly 1258as if they all were preceded by an at sign 1259.Pq Ql @ . 1260.It Ic .USE 1261Turn the target into 1262.Nm make Ns 's 1263version of a macro. 1264When the target is used as a source for another target, the other target 1265acquires the commands, sources, and attributes (except for 1266.Ic .USE ) 1267of the 1268source. 1269If the target already has commands, the 1270.Ic .USE 1271target's commands are appended 1272to them. 1273.It Ic .WAIT 1274If 1275.Ic .WAIT 1276appears in a dependency line, the sources that precede it are 1277made before the sources that succeed it in the line. 1278Loops are not 1279detected and targets that form loops will be silently ignored. 1280.El 1281.Sh "SPECIAL TARGETS" 1282Special targets may not be included with other targets, i.e., they must be 1283the only target specified. 1284.Bl -tag -width ".NOTPARALLEL" 1285.It Ic .BEGIN 1286Any command lines attached to this target are executed before anything 1287else is done. 1288.It Ic .DEFAULT 1289This is sort of a 1290.Ic .USE 1291rule for any target (that was used only as a 1292source) that 1293.Nm 1294can't figure out any other way to create. 1295Only the shell script is used. 1296The 1297.Ic .IMPSRC 1298variable of a target that inherits 1299.Ic .DEFAULT Ns 's 1300commands is set 1301to the target's own name. 1302.It Ic .END 1303Any command lines attached to this target are executed after everything 1304else is done. 1305.It Ic .IGNORE 1306Mark each of the sources with the 1307.Ic .IGNORE 1308attribute. 1309If no sources are specified, this is the equivalent of specifying the 1310.Fl i 1311option. 1312.It Ic .INCLUDES 1313A list of suffixes that indicate files that can be included in a source 1314file. 1315The suffix must have already been declared with 1316.Ic .SUFFIXES , 1317any suffix so declared will have the directories in its search path (see 1318.Ic .PATH ) 1319placed in the 1320.Va .INCLUDES 1321special variable, each preceded by a 1322.Fl I 1323flag. 1324.It Ic .INTERRUPT 1325If 1326.Nm 1327is interrupted, the commands for this target will be executed. 1328.It Ic .LIBS 1329This does for libraries what 1330.Ic .INCLUDES 1331does for include files, except that the flag used is 1332.Fl L . 1333.It Ic .MAIN 1334If no target is specified when 1335.Nm 1336is invoked, this target will be built. 1337This is always set, either 1338explicitly, or implicitly when 1339.Nm 1340selects the default target, to give the user a way to refer to the default 1341target on the command line. 1342.It Ic .MAKEFLAGS 1343This target provides a way to specify flags for 1344.Nm 1345when the makefile is used. 1346The flags are as if typed to the shell, though the 1347.Fl f 1348option will have 1349no effect. 1350.\" XXX: NOT YET!!!! 1351.\" .It Ic .NOTPARALLEL 1352.\" The named targets are executed in non parallel mode. If no targets are 1353.\" specified, then all targets are executed in non parallel mode. 1354.It Ic .NOTPARALLEL 1355Disable parallel mode. 1356.It Ic .NO_PARALLEL 1357Same as above, for compatibility with other pmake variants. 1358.It Ic .ORDER 1359The named targets are made in sequence. 1360.\" XXX: NOT YET!!!! 1361.\" .It Ic .PARALLEL 1362.\" The named targets are executed in parallel mode. If no targets are 1363.\" specified, then all targets are executed in parallel mode. 1364.It Ic .PATH 1365The sources are directories which are to be searched for files not 1366found in the current directory. 1367If no sources are specified, any previously specified directories are 1368deleted. 1369.It Ic .PATH\fIsuffix\fR 1370The sources are directories which are to be searched for suffixed files 1371not found in the current directory. 1372.Nm 1373first searches the suffixed search path, before reverting to the default 1374path if the file is not found there. 1375.It Ic .PHONY 1376Apply the 1377.Ic .PHONY 1378attribute to any specified sources. 1379Targets with this attribute are always 1380considered to be out of date. 1381.It Ic .PRECIOUS 1382Apply the 1383.Ic .PRECIOUS 1384attribute to any specified sources. 1385If no sources are specified, the 1386.Ic .PRECIOUS 1387attribute is applied to every 1388target in the file. 1389.It Ic .SILENT 1390Apply the 1391.Ic .SILENT 1392attribute to any specified sources. 1393If no sources are specified, the 1394.Ic .SILENT 1395attribute is applied to every 1396command in the file. 1397.It Ic .SUFFIXES 1398Each source specifies a suffix to 1399.Nm make . 1400If no sources are specified, any previously specified suffixes are deleted. 1401.El 1402.Sh ENVIRONMENT 1403.Nm 1404uses the following environment variables, if they exist: 1405.Ev MACHINE , 1406.Ev MACHINE_ARCH , 1407.Ev MACHINE_OS , 1408.Ev MAKEFLAGS , 1409.Ev MAKEOBJDIR , 1410.Ev MAKEOBJDIRPREFIX , 1411and 1412.Ev PWD . 1413.Nm 1414also ignores and unsets 1415.Ev CDPATH . 1416.Sh FILES 1417.Bl -tag -width /usr/share/mk -compact 1418.It Pa .depend 1419list of dependencies 1420.It Pa BSDmakefile 1421default makefile 1422.It Pa makefile 1423default makefile if 1424.Pa BSDmakefile 1425does not exist 1426.It Pa Makefile 1427default makefile if 1428.Pa makefile 1429does not exist 1430.It Pa sys.mk 1431system makefile 1432.It Pa /usr/share/mk 1433system makefile directory 1434.It Pa /usr/obj 1435default 1436.Ev MAKEOBJDIRPREFIX 1437directory 1438.El 1439.Sh SEE ALSO 1440.Xr ed 1 , 1441.Xr ksh 1 , 1442.Xr mkdep 1 , 1443.Xr sh 1 , 1444.Xr getcwd 3 , 1445.Xr regex 3 , 1446.Xr uname 3 1447.Pp 1448"Make \(em A Tutorial", 1449.Pa /usr/share/doc/psd/12.make/ . 1450.Sh STANDARDS 1451The 1452.Nm 1453utility is compliant with the 1454.\" .St -p1003.1-2004 1455IEEE Std 1003.1-2004 1456.Pq Dq Tn POSIX 1457specification. 1458.Pp 1459The flags 1460.Op Fl BDdIjmPV 1461are extensions to that specification. 1462.Pp 1463Older versions of 1464.Nm 1465used 1466.Ev MAKE 1467instead of 1468.Ev MAKEFLAGS . 1469This was removed for POSIX compatibility. 1470The internal variable 1471.Va MAKE 1472is set to the same value as 1473.Va .MAKE . 1474Support for this may be removed in the future. 1475.Pp 1476Most of the more esoteric features of 1477.Nm 1478should probably be avoided for greater compatibility. 1479.Sh HISTORY 1480A 1481.Nm 1482command appeared in 1483.At v7 . 1484The choice to use 1485.Nm mirbsdksh 1486extensions was done for 1487.Mx 8 . 1488.Sh BUGS 1489The determination of 1490.Va .OBJDIR 1491is contorted to the point of absurdity. 1492.Pp 1493If the same target is specified several times in normal dependency rules, 1494.Nm 1495silently ignores all commands after the first non empty set of commands, 1496e.g., in 1497.Bd -literal -offset indent 1498a: 1499 @echo "Executed" 1500a: 1501 @echo "Bad luck" 1502.Ed 1503.Pp 1504@echo "Bad luck" will be silently ignored. 1505.Pp 1506.Va .TARGETS 1507is not set to the default target when 1508.Nm 1509is invoked without a target name and no 1510.Ic MAIN 1511special target exists. 1512.Pp 1513The evaluation of 1514.Ar expression 1515in a test is very simple-minded. 1516Currently, the only form that works is 1517.Ql .if ${VAR} op something \. 1518For instance, tests should be written as 1519.Ql .if ${VAR} == "string" , 1520not the other way around, which doesn't work. 1521.Pp 1522For loops are expanded before tests, so a fragment such as: 1523.Bd -literal -offset indent 1524\&.for TMACHINE in ${SHARED_ARCHS} 1525\&.if ${TMACHINE} == ${MACHINE} 1526 ... 1527\&.endif 1528\&.endfor 1529.Ed 1530.Pp 1531won't work, and should be rewritten the other way around. 1532.Pp 1533When handling pre-BSD 4.4 archives, 1534.Nm 1535may erroneously mark archive members as out of date if the archive name 1536was truncated. 1537.Pp 1538The handling of 1539.Sq \&;\& 1540and other special characters in tests may be utterly bogus. 1541For instance, in 1542.Bd -literal -offset indent 1543\&A=abcd;c.c 1544\&.if ${A:R} == "abcd;c" 1545.Ed 1546.Pp 1547the test will never match, even though the value is correct. 1548.Pp 1549The conditional handler is incredibly lame. 1550Junk such as 1551.Pp 1552.Dl \&.if defined anything goes (A) 1553.Pp 1554will be accepted silently. 1555.Pp 1556In a .for loop, only the variable value is used; assignments will be 1557evaluated later, e.g., in 1558.Bd -literal -offset indent 1559\&.for I in a b c d 1560I:=${I:S/a/z} 1561A+=$I 1562\&.endfor 1563.Ed 1564.Pp 1565.Sq A 1566will evaluate to a b c d after the loop, not z b c d. 1567.Pp 1568The 1569.Ql + 1570command modificator is ignored in parallel make mode. 1571