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