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