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