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