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