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