1.\" Copyright (c) 1990, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" %sccs.include.redist.roff% 5.\" 6.\" @(#)make.1 8.4 (Berkeley) 03/19/94 7.\" 8.Dd 9.Dt MAKE 1 10.Os 11.Sh NAME 12.Nm make 13.Nd maintain program dependencies 14.Sh SYNOPSIS 15.Nm make 16.Op Fl eiknqrstv 17.Op Fl D Ar variable 18.Op Fl d Ar flags 19.Op Fl f Ar makefile 20.Op Fl I Ar directory 21.Bk -words 22.Op Fl j Ar max_jobs 23.Ek 24.Op Ar variable=value 25.Op Ar target ... 26.Sh DESCRIPTION 27.Nm Make 28is a program designed to simplify the maintenance of other programs. 29Its input is a list of specifications as to the files upon which programs 30and other files depend. 31If the file 32.Ql Pa makefile 33exists, it is read for this list of specifications. 34If it does not exist, the file 35.Ql Pa Makefile 36is read. 37If the file 38.Ql Pa .depend 39exists, it is read (see 40.Xr mkdep 1) . 41.Pp 42This manual page is intended as a reference document only. 43For a more thorough description of 44.Nm make 45and makefiles, please refer to 46.%T "Make \- A Tutorial" . 47.Pp 48The options are as follows: 49.Bl -tag -width Ds 50.It Fl D Ar variable 51Define Ar variable 52to be 1, in the global context. 53.It Fl d Ar flags 54Turn on debugging, and specify which portions of 55.Nm make 56are to print debugging information. 57.Ar Flags 58is one or more of the following: 59.Bl -tag -width Ds 60.It Ar A 61Print all possible debugging information; 62equivalent to specifying all of the debugging flags. 63.It Ar a 64Print debugging information about archive searching and caching. 65.It Ar c 66Print debugging information about conditional evaluation. 67.It Ar d 68Print debugging information about directory searching and caching. 69.It Ar "g1" 70Print the input graph before making anything. 71.It Ar "g2" 72Print the input graph after making everything, or before exiting 73on error. 74.It Ar j 75Print debugging information about running multiple shells. 76.It Ar m 77Print debugging information about making targets, including modification 78dates. 79.It Ar s 80Print debugging information about suffix-transformation rules. 81.It Ar t 82Print debugging information about target list maintenance. 83.It Ar v 84Print debugging information about variable assignment. 85.El 86.It Fl e 87Specify that environmental variables override macro assignments within 88makefiles. 89.It Fl f Ar makefile 90Specify a makefile to read instead of the default 91.Ql Pa makefile 92and 93.Ql Pa Makefile . 94If 95.Ar makefile 96is 97.Ql Fl , 98standard input is read. 99Multiple makefile's may be specified, and are read in the order specified. 100.It Fl I Ar directory 101Specify a directory in which to search for makefiles and included makefiles. 102The system makefile directory is automatically included as part of this 103list. 104.It Fl i 105Ignore non-zero exit of shell commands in the makefile. 106Equivalent to specifying 107.Ql Fl 108before each command line in the makefile. 109.It Fl j Ar max_jobs 110Specify the maximum number of jobs that 111.Nm make 112may have running at any one time. 113.It Fl k 114Continue processing after errors are encountered, but only on those targets 115that do not depend on the target whose creation caused the error. 116.It Fl n 117Display the commands that would have been executed, but do not actually 118execute them. 119.It Fl q 120Do not execute any commands, but exit 0 if the specified targets are 121up-to-date and 1, otherwise. 122.It Fl r 123Do not use the built-in rules specified in the system makefile. 124.It Fl s 125Do not echo any commands as they are executed. 126Equivalent to specifying 127.Ql Ic @ 128before each command line in the makefile. 129.It Fl t 130Rather than re-building a target as specified in the makefile, create it 131or update its modification time to make it appear up-to-date. 132.It Ar variable=value 133Set the value of the variable 134.Ar variable 135to 136.Ar value . 137.El 138.Pp 139There are seven different types of lines in a makefile: file dependency 140specifications, shell commands, variable assignments, include statements, 141conditional directives, for loops, and comments. 142.Pp 143In general, lines may be continued from one line to the next by ending 144them with a backslash 145.Pq Ql \e . 146The trailing newline character and initial whitespace on the following 147line are compressed into a single space. 148.Sh FILE DEPENDENCY SPECIFICATIONS 149Dependency lines consist of one or more targets, an operator, and zero 150or more sources. 151This creates a relationship where the targets ``depend'' on the sources 152and are usually created from them. 153The exact relationship between the target and the source is determined 154by the operator that separates them. 155The three operators are as follows: 156.Bl -tag -width flag 157.It Ic \&: 158A target is considered out-of-date if its modification time is less than 159those of any of its sources. 160Sources for a target accumulate over dependency lines when this operator 161is used. 162The target is removed if 163.Nm make 164is interrupted. 165.It Ic \&! 166Targets are always re-created, but not until all sources have been 167examined and re-created as necessary. 168Sources for a target accumulate over dependency lines when this operator 169is used. 170The target is removed if 171.Nm make 172is interrupted. 173.It Ic \&:: 174If no sources are specified, the target is always re-created. 175Otherwise, a target is considered out-of-date if any of its sources has 176been modified more recently than the target. 177Sources for a target do not accumulate over dependency lines when this 178operator is used. 179The target will not be removed if 180.Nm make 181is interrupted. 182.El 183.Pp 184Targets and sources may contain the shell wildcard values 185.Ql ? , 186.Ql * , 187.Ql [] 188and 189.Ql {} . 190The values 191.Ql ? , 192.Ql * 193and 194.Ql [] 195may only be used as part of the final 196component of the target or source, and must be used to describe existing 197files. 198The value 199.Ql {} 200need not necessarily be used to describe existing files. 201Expansion is in directory order, not alphabetically as done in the shell. 202.Sh SHELL COMMANDS 203Each target may have associated with it a series of shell commands, normally 204used to create the target. 205Each of the commands in this script 206.Em must 207be preceded by a tab. 208While any target may appear on a dependency line, only one of these 209dependencies may be followed by a creation script, unless the 210.Ql Ic :: 211operator is used. 212.Pp 213If the first or first two characters of the command line are 214.Ql Ic @ 215and/or 216.Ql Ic \- , 217the command is treated specially. 218A 219.Ql Ic @ 220causes the command not to be echoed before it is executed. 221A 222.Ql Ic \- 223causes any non-zero exit status of the command line to be ignored. 224.Sh VARIABLE ASSIGNMENTS 225Variables in make are much like variables in the shell, and, by tradition, 226consist of all upper-case letters. 227The five operators that can be used to assign values to variables are as 228follows: 229.Bl -tag -width Ds 230.It Ic \&= 231Assign the value to the variable. 232Any previous value is overridden. 233.It Ic \&+= 234Append the value to the current value of the variable. 235.It Ic \&?= 236Assign the value to the variable if it is not already defined. 237.It Ic \&:= 238Assign with expansion, i.e. expand the value before assigning it 239to the variable. 240Normally, expansion is not done until the variable is referenced. 241.It Ic \&!= 242Expand the value and pass it to the shell for execution and assign 243the result to the variable. 244Any newlines in the result are replaced with spaces. 245.El 246.Pp 247Any white-space before the assigned 248.Ar value 249is removed; if the value is being appended, a single space is inserted 250between the previous contents of the variable and the appended value. 251.Pp 252Variables are expanded by surrounding the variable name with either 253curly braces 254.Pq Ql {} 255or parenthesis 256.Pq Ql () 257and preceding it with 258a dollar sign 259.Pq Ql \&$ . 260If the variable name contains only a single letter, the surrounding 261braces or parenthesis are not required. 262This shorter form is not recommended. 263.Pp 264Variable substitution occurs at two distinct times, depending on where 265the variable is being used. 266Variables in dependency lines are expanded as the line is read. 267Variables in shell commands are expanded when the shell command is 268executed. 269.Pp 270The four different classes of variables (in order of increasing precedence) 271are: 272.Bl -tag -width Ds 273.It Environment variables 274Variables defined as part of 275.Nm make Ns 's 276environment. 277.It Global variables 278Variables defined in the makefile or in included makefiles. 279.It Command line variables 280Variables defined as part of the command line. 281.It Local variables 282Variables that are defined specific to a certain target. 283The seven local variables are as follows: 284.Bl -tag -width ".ARCHIVE" 285.It Va .ALLSRC 286The list of all sources for this target; also known as 287.Ql Va \&> . 288.It Va .ARCHIVE 289The name of the archive file. 290.It Va .IMPSRC 291The name/path of the source from which the target is to be transformed 292(the ``implied'' source); also known as 293.Ql Va \&< . 294.It Va .MEMBER 295The name of the archive member. 296.It Va .OODATE 297The list of sources for this target that were deemed out-of-date; also 298known as 299.Ql Va \&? . 300.It Va .PREFIX 301The file prefix of the file, containing only the file portion, no suffix 302or preceding directory components; also known as 303.Ql Va * . 304.It Va .TARGET 305The name of the target; also known as 306.Ql Va @ . 307.El 308.Pp 309The shorter forms 310.Ql Va @ , 311.Ql Va ? , 312.Ql Va \&> 313and 314.Ql Va * 315are permitted for backward 316compatibility with historical makefiles and are not recommended. 317The six variables 318.Ql Va "@F" , 319.Ql Va "@D" , 320.Ql Va "<F" , 321.Ql Va "<D" , 322.Ql Va "*F" 323and 324.Ql Va "*D" 325are 326permitted for compatibility with 327.At V 328makefiles and are not recommended. 329.Pp 330Four of the local variables may be used in sources on dependency lines 331because they expand to the proper value for each target on the line. 332These variables are 333.Ql Va .TARGET , 334.Ql Va .PREFIX , 335.Ql Va .ARCHIVE , 336and 337.Ql Va .MEMBER . 338.Pp 339In addition, 340.Nm make 341sets or knows about the following variables: 342.Bl -tag -width MAKEFLAGS 343.It Va \&$ 344A single dollar sign 345.Ql \&$ , 346i.e. 347.Ql \&$$ 348expands to a single dollar 349sign. 350.It Va .MAKE 351The name that 352.Nm make 353was executed with 354.Pq Va argv Op 0 355.It Va .CURDIR 356A path to the directory where 357.Nm make 358was executed. 359.It Va .OBJDIR 360A path to the directory where the targets are built. 361.It Ev MAKEFLAGS 362The environment variable 363.Ql Ev MAKEFLAGS 364may contain anything that 365may be specified on 366.Nm make Ns 's 367command line. 368Anything specified on 369.Nm make Ns 's 370command line is appended to the 371.Ql Ev MAKEFLAGS 372variable which is then 373entered into the environment for all programs which 374.Nm make 375executes. 376.El 377.Pp 378Variable expansion may be modified to select or modify each word of the 379variable (where a ``word'' is white-space delimited sequence of characters). 380The general format of a variable expansion is as follows: 381.Pp 382.Dl {variable[:modifier[:...]]} 383.Pp 384Each modifier begins with a colon and one of the following 385special characters. 386The colon may be escaped with a backslash 387.Pq Ql \e . 388.Bl -tag -width Cm E\& 389.It Cm E 390Replaces each word in the variable with its suffix. 391.It Cm H 392Replaces each word in the variable with everything but the last component. 393.It Cm M Ns Ar pattern 394Select only those words that match the rest of the modifier. 395The standard shell wildcard characters 396.Pf ( Ql * , 397.Ql ? , 398and 399.Ql Op ) 400may 401be used. 402The wildcard characters may be escaped with a backslash 403.Pq Ql \e . 404.It Cm N Ns Ar pattern 405This is identical to 406.Ql Cm M , 407but selects all words which do not match 408the rest of the modifier. 409.It Cm R 410Replaces each word in the variable with everything but its suffix. 411.Sm off 412.It Cm S No \&/ Ar old_pattern Xo 413.No \&/ Ar new_pattern 414.No \&/ Op Cm g 415.Xc 416.Sm on 417Modify the first occurrence of 418.Ar old_pattern 419in each word to be replaced with 420.Ar new_pattern . 421If a 422.Ql g 423is appended to the last slash of the pattern, all occurrences 424in each word are replaced. 425If 426.Ar old_pattern 427begins with a carat 428.Pq Ql ^ , 429.Ar old_pattern 430is anchored at the beginning of each word. 431If 432.Ar old_pattern 433ends with a dollar sign 434.Pq Ql \&$ , 435it is anchored at the end of each word. 436Inside 437.Ar new_string , 438an ampersand 439.Pq Ql & 440is replaced by 441.Ar old_pattern . 442Any character may be used as a delimiter for the parts of the modifier 443string. 444The anchoring, ampersand and delimiter characters may be escaped with a 445backslash 446.Pq Ql \e . 447.Pp 448Variable expansion occurs in the normal fashion inside both 449.Ar old_string 450and 451.Ar new_string 452with the single exception that a backslash is used to prevent the expansion 453of a dollar sign 454.Pq Ql \&$ 455not a preceding dollar sign as is usual. 456.It Cm T 457Replaces each word in the variable with its last component. 458.It Ar old_string=new_string 459This is the 460.At V 461style variable substitution. 462It must be the last modifier specified. 463If 464.Ar old_string 465or 466.Ar new_string 467do not contain the pattern matching character 468.Ar % 469then it is assumed that they are 470anchored at the end of each word, so only suffixes or entire 471words may be replaced. Otherwise 472.Ar % 473is the substring of 474.Ar old_string 475to be replaced in 476.Ar new_string 477.El 478.Sh INCLUDE STATEMENTS, CONDITIONALS AND FOR LOOPS 479Makefile inclusion, conditional structures and for loops reminiscent 480of the C programming language are provided in 481.Nm make . 482All such structures are identified by a line beginning with a single 483dot 484.Pq Ql \&. 485character. 486Files are included with either 487.Ql .include <file> 488or 489.Ql .include \*qfile\*q . 490Variables between the angle brackets or double quotes are expanded 491to form the file name. 492If angle brackets are used, the included makefile is expected to be in 493the system makefile directory. 494If double quotes are used, the including makefile's directory and any 495directories specified using the 496.Fl I 497option are searched before the system 498makefile directory. 499.Pp 500Conditional expressions are also preceded by a single dot as the first 501character of a line. 502The possible conditionals are as follows: 503.Bl -tag -width Ds 504.It Ic .undef Ar variable 505Un-define the specified global variable. 506Only global variables may be un-defined. 507.It Xo 508.Ic \&.if 509.Oo \&! Oc Ns Ar expression 510.Op Ar operator expression ... 511.Xc 512Test the value of an expression. 513.It Xo 514.Ic .ifdef 515.Oo \&! Oc Ns Ar variable 516.Op Ar operator variable ... 517.Xc 518Test the value of a variable. 519.It Xo 520.Ic .ifndef 521.Oo \&! Oc Ns Ar variable 522.Op Ar operator variable ... 523.Xc 524Test the value of a variable. 525.It Xo 526.Ic .ifmake 527.Oo \&! Oc Ns Ar target 528.Op Ar operator target ... 529.Xc 530Test the the target being built. 531.It Xo 532.Ic .ifnmake 533.Oo \&! Oc Ar target 534.Op Ar operator target ... 535.Xc 536Test the target being built. 537.It Ic .else 538Reverse the sense of the last conditional. 539.It Xo 540.Ic .elif 541.Oo \&! Oc Ar expression 542.Op Ar operator expression ... 543.Xc 544A combination of 545.Ql Ic .else 546followed by 547.Ql Ic .if . 548.It Xo 549.Ic .elifdef 550.Oo \&! Oc Ns Ar variable 551.Op Ar operator variable ... 552.Xc 553A combination of 554.Ql Ic .else 555followed by 556.Ql Ic .ifdef . 557.It Xo 558.Ic .elifndef 559.Oo \&! Oc Ns Ar variable 560.Op Ar operator variable ... 561.Xc 562A combination of 563.Ql Ic .else 564followed by 565.Ql Ic .ifndef . 566.It Xo 567.Ic .elifmake 568.Oo \&! Oc Ns Ar target 569.Op Ar operator target ... 570.Xc 571A combination of 572.Ql Ic .else 573followed by 574.Ql Ic .ifmake . 575.It Xo 576.Ic .elifnmake 577.Oo \&! Oc Ns Ar target 578.Op Ar operator target ... 579.Xc 580A combination of 581.Ql Ic .else 582followed by 583.Ql Ic .ifnmake . 584.It Ic .endif 585End the body of the conditional. 586.El 587.Pp 588The 589.Ar operator 590may be any one of the following: 591.Bl -tag -width "Cm XX" 592.It Cm \&|\&| 593logical OR 594.It Cm \&&& 595Logical 596.Tn AND ; 597of higher precedence than 598.Dq . 599.El 600.Pp 601As in C, 602.Nm make 603will only evaluate a conditional as far as is necessary to determine 604its value. 605Parentheses may be used to change the order of evaluation. 606The boolean operator 607.Ql Ic \&! 608may be used to logically negate an entire 609conditional. 610It is of higher precedence than 611.Ql Ic \&&& . 612.Pp 613The value of 614.Ar expression 615may be any of the following: 616.Bl -tag -width Ic defined 617.It Ic defined 618Takes a variable name as an argument and evaluates to true if the variable 619has been defined. 620.It Ic make 621Takes a target name as an argument and evaluates to true if the target 622was specified as part of 623.Nm make Ns 's 624command line or was declared the default target (either implicitly or 625explicitly, see 626.Va .MAIN ) 627before the line containing the conditional. 628.It Ic empty 629Takes a variable, with possible modifiers, and evaluates to true if 630the expansion of the variable would result in an empty string. 631.It Ic exists 632Takes a file name as an argument and evaluates to true if the file exists. 633The file is searched for on the system search path (see 634.Va .PATH ) . 635.It Ic target 636Takes a target name as an argument and evaluates to true if the target 637has been defined. 638.El 639.Pp 640.Ar Expression 641may also be an arithmetic or string comparison. Variable expansion is 642performed on both sides of the comparison, after which the integral 643values are compared. A value is interpreted as hexadecimal if it is 644preceded by 0x, otherwise it is decimal; octal numbers are not supported. 645The standard C relational operators are all supported. If after 646variable expansion, either the left or right hand side of a 647.Ql Ic == 648or 649.Ql Ic "!=" 650operator is not an integral value, then 651string comparison is performed between the expanded 652variables. 653If no relational operator is given, it is assumed that the expanded 654variable is being compared against 0. 655.Pp 656When 657.Nm make 658is evaluating one of these conditional expression, and it encounters 659a word it doesn't recognize, either the ``make'' or ``defined'' 660expression is applied to it, depending on the form of the conditional. 661If the form is 662.Ql Ic .ifdef 663or 664.Ql Ic .ifndef , 665the ``defined'' expression 666is applied. 667Similarly, if the form is 668.Ql Ic .ifmake 669or 670.Ql Ic .ifnmake , the ``make'' 671expression is applied. 672.Pp 673If the conditional evaluates to true the parsing of the makefile continues 674as before. 675If it evaluates to false, the following lines are skipped. 676In both cases this continues until a 677.Ql Ic .else 678or 679.Ql Ic .endif 680is found. 681.Pp 682For loops are typically used to apply a set of rules to a list of files. 683The syntax of a for loop is: 684.Bl -tag -width Ds 685.It Xo 686.Ic \&.for 687.Ar variable 688.Ic in 689.Ar expression 690.Xc 691.It Xo 692<make-rules> 693.Xc 694.It Xo 695.Ic \&.endfor 696.Xc 697.El 698After the for 699.Ic expression 700is evaluated, it is split into words. The 701iteration 702.Ic variable 703is successively set to each word, and substituted in the 704.Ic make-rules 705inside the body of the for loop. 706.Sh COMMENTS 707Comments begin with a hash 708.Pq Ql \&# 709character, anywhere but in a shell 710command line, and continue to the end of the line. 711.Sh SPECIAL SOURCES 712.Bl -tag -width Ic .IGNORE 713.It Ic .IGNORE 714Ignore any errors from the commands associated with this target, exactly 715as if they all were preceded by a dash 716.Pq Ql \- . 717.It Ic .MAKE 718Execute the commands associated with this target even if the 719.Fl n 720or 721.Fl t 722options were specified. 723Normally used to mark recursive 724.Nm make Ns 's . 725.It Ic .NOTMAIN 726Normally 727.Nm make 728selects the first target it encounters as the default target to be built 729if no target was specified. 730This source prevents this target from being selected. 731.It Ic .OPTIONAL 732If a target is marked with this attribute and 733.Nm make 734can't figure out how to create it, it will ignore this fact and assume 735the file isn't needed or already exists. 736.It Ic .PRECIOUS 737When 738.Nm make 739is interrupted, it removes any partially made targets. 740This source prevents the target from being removed. 741.It Ic .SILENT 742Do not echo any of the commands associated with this target, exactly 743as if they all were preceded by an at sign 744.Pq Ql @ . 745.It Ic .USE 746Turn the target into 747.Nm make Ns 's . 748version of a macro. 749When the target is used as a source for another target, the other target 750acquires the commands, sources, and attributes (except for 751.Ic .USE ) 752of the 753source. 754If the target already has commands, the 755.Ic .USE 756target's commands are appended 757to them. 758.El 759.Sh "SPECIAL TARGETS" 760Special targets may not be included with other targets, i.e. they must be 761the only target specified. 762.Bl -tag -width Ic .BEGIN 763.It Ic .BEGIN 764Any command lines attached to this target are executed before anything 765else is done. 766.It Ic .DEFAULT 767This is sort of a 768.Ic .USE 769rule for any target (that was used only as a 770source) that 771.Nm make 772can't figure out any other way to create. 773Only the shell script is used. 774The 775.Ic .IMPSRC 776variable of a target that inherits 777.Ic .DEFAULT Ns 's 778commands is set 779to the target's own name. 780.It Ic .END 781Any command lines attached to this target are executed after everything 782else is done. 783.It Ic .IGNORE 784Mark each of the sources with the 785.Ic .IGNORE 786attribute. 787If no sources are specified, this is the equivalent of specifying the 788.Fl i 789option. 790.It Ic .INTERRUPT 791If 792.Nm make 793is interrupted, the commands for this target will be executed. 794.It Ic .MAIN 795If no target is specified when 796.Nm make 797is invoked, this target will be built. 798.It Ic .MAKEFLAGS 799This target provides a way to specify flags for 800.Nm make 801when the makefile is used. 802The flags are as if typed to the shell, though the 803.Fl f 804option will have 805no effect. 806.It Ic .PATH 807The sources are directories which are to be searched for files not 808found in the current directory. 809If no sources are specified, any previously specified directories are 810deleted. 811.It Ic .PRECIOUS 812Apply the 813.Ic .PRECIOUS 814attribute to any specified sources. 815If no sources are specified, the 816.Ic .PRECIOUS 817attribute is applied to every 818target in the file. 819.It Ic .SILENT 820Apply the 821.Ic .SILENT 822attribute to any specified sources. 823If no sources are specified, the 824.Ic .SILENT 825attribute is applied to every 826command in the file. 827.It Ic .SUFFIXES 828Each source specifies a suffix to 829.Nm make . 830If no sources are specified, any previous specified suffices are deleted. 831.Sh ENVIRONMENT 832.Nm Make 833utilizes the following environment variables, if they exist: 834.Ev MAKE , 835.Ev MAKEFLAGS 836and 837.Ev MAKEOBJDIR . 838.Sh FILES 839.Bl -tag -width /usr/share/mk -compact 840.It .depend 841list of dependencies 842.It Makefile 843list of dependencies 844.It makefile 845list of dependencies 846.It sys.mk 847system makefile 848.It /usr/share/mk 849system makefile directory 850.El 851.Sh SEE ALSO 852.Xr mkdep 1 853.Sh HISTORY 854A 855.Nm Make 856command appeared in 857.At v7 . 858