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