Changeset 1993 in kBuild for trunk/src/kmk/doc
- Timestamp:
- Oct 29, 2008 12:37:51 AM (16 years ago)
- Location:
- trunk/src/kmk/doc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/doc/Makefile.am
r503 r1993 1 1 # -*-Makefile-*-, or close enough 2 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software2 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software 3 3 # Foundation, Inc. 4 4 # This file is part of GNU Make. 5 5 # 6 # GNU Make is free software; you can redistribute it and/or modify it under the 7 # terms of the GNU General Public License as published by the Free Software 8 # Foundation; either version 2, or (at your option) any later version. 6 # GNU Make is free software; you can redistribute it and/or modify it under 7 # the terms of the GNU General Public License as published by the Free Software 8 # Foundation; either version 3 of the License, or (at your option) any later 9 # version. 9 10 # 10 11 # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY 11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 # details. 13 15 # 14 16 # You should have received a copy of the GNU General Public License along with 15 # GNU Make; see the file COPYING. If not, write to the Free Software 16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 # this program. If not, see <http://www.gnu.org/licenses/>. 17 18 18 19 TEXI2HTML = texi2html -
trunk/src/kmk/doc/make.texi
r903 r1993 5 5 @include version.texi 6 6 @set EDITION 0.70 7 @set RCSID $Id: make.texi,v 1. 47 2007/05/11 20:57:21psmith Exp $7 @set RCSID $Id: make.texi,v 1.52 2008/05/18 15:11:40 psmith Exp $ 8 8 9 9 @settitle GNU @code{make} … … 27 27 28 28 Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 29 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006 29 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007 30 30 Free Software Foundation, Inc. 31 31 … … 39 39 License.'' 40 40 41 (a) The FSF's Back-Cover Text is: ``You have freedomto copy and modify42 this GNU Manual , like GNU software. Copies published by the Free43 Software Foundation raise funds for GNU development.''41 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify 42 this GNU Manual. Buying copies from GNU Press supports the FSF in 43 developing GNU and promoting software freedom.'' 44 44 @end quotation 45 45 @end copying … … 92 92 * Makefiles:: Makefiles tell @code{make} what to do. 93 93 * Rules:: Rules describe when a file must be remade. 94 * Commands:: Commands say how to remake a file.94 * Recipes:: Recipes say how to remake a file. 95 95 * Using Variables:: You can use variables to avoid repetition. 96 96 * Conditionals:: Use or ignore parts of the makefile based … … 119 119 Overview of @code{make} 120 120 121 * Preparing:: Preparing and Running Make122 * Reading:: On Reading this Text123 * Bugs:: Problems and Bugs121 * Preparing:: Preparing and running make 122 * Reading:: On reading this text 123 * Bugs:: Problems and bugs 124 124 125 125 An Introduction to Makefiles 126 126 127 127 * Rule Introduction:: What a rule looks like. 128 * Simple Makefile:: A Simple Makefile129 * How Make Works:: How @code{make} Processes This Makefile130 * Variables Simplify:: Variables Make Makefiles Simpler131 * make Deduces:: Letting @code{make} Deduce the Commands132 * Combine By Prerequisite:: Another Style of Makefile133 * Cleanup:: Rules for Cleaning the Directory128 * Simple Makefile:: A simple makefile 129 * How Make Works:: How @code{make} processes this makefile 130 * Variables Simplify:: Variables make makefiles simpler 131 * make Deduces:: Letting @code{make} deduce the recipe 132 * Combine By Prerequisite:: Another style of makefile 133 * Cleanup:: Rules for cleaning the directory 134 134 135 135 Writing Makefiles … … 139 139 * Include:: How one makefile can use another makefile. 140 140 * MAKEFILES Variable:: The environment can specify extra makefiles. 141 * MAKEFILE_LIST Variable:: Discover which makefiles have been read.142 * Special Variables:: Other special variables.143 141 * Remaking Makefiles:: How makefiles get remade. 144 142 * Overriding Makefiles:: How to override part of one makefile … … 155 153 * Directory Search:: Searching other directories for source files. 156 154 * Phony Targets:: Using a target that is not a real file's name. 157 * Force Targets:: You can use a target without commands155 * Force Targets:: You can use a target without a recipe 158 156 or prerequisites to mark other targets 159 157 as phony. … … 185 183 for a specified class of names. 186 184 * Search Algorithm:: When and how search paths are applied. 187 * Commands/Search:: How to write shell commands that work together185 * Recipes/Search:: How to write recipes that work together 188 186 with search paths. 189 187 * Implicit/Search:: How search paths affect implicit rules. … … 195 193 * Static versus Implicit:: When are they better than implicit rules? 196 194 197 Writing the Commands in Rules198 199 * Command Syntax:: Commandsyntax features and pitfalls.200 * Echoing:: How to control when commands are echoed.201 * Execution:: How commands are executed.202 * Parallel:: How commands can be executed in parallel.203 * Errors:: What happens after a commandexecution error.204 * Interrupts:: What happens when a commandis interrupted.195 Writing Recipes in Rules 196 197 * Recipe Syntax:: Recipe syntax features and pitfalls. 198 * Echoing:: How to control when recipes are echoed. 199 * Execution:: How recipes are executed. 200 * Parallel:: How recipes can be executed in parallel. 201 * Errors:: What happens after a recipe execution error. 202 * Interrupts:: What happens when a recipe is interrupted. 205 203 * Recursion:: Invoking @code{make} from makefiles. 206 * Sequences:: Defining canned sequences of commands.207 * Empty Commands:: Defining useful, do-nothing commands.208 209 CommandSyntax210 211 * Splitting Lines:: Breaking long commandlines for readability.212 * Variables in Commands:: Using @code{make} variables in commands.213 214 CommandExecution204 * Sequences:: Defining canned recipes. 205 * Empty Recipes:: Defining useful, do-nothing recipes. 206 207 Recipe Syntax 208 209 * Splitting Lines:: Breaking long recipe lines for readability. 210 * Variables in Recipes:: Using @code{make} variables in recipes. 211 212 Recipe Execution 215 213 216 214 * Choosing the Shell:: How @code{make} chooses the shell used 217 to run commands.215 to run recipes. 218 216 219 217 Recursive Use of @code{make} … … 243 241 * Pattern-specific:: Target-specific variable values can be applied 244 242 to a group of targets that match a pattern. 243 * Special Variables:: Variables with special meaning or behavior. 245 244 246 245 Advanced Features for Reference to Variables … … 277 276 parts of the makefile to use. 278 277 * Instead of Execution:: How to use mode flags to specify what 279 kind of thing to do with the commands278 kind of thing to do with the recipes 280 279 in the makefile other than simply 281 280 execute them. … … 290 289 291 290 * Using Implicit:: How to use an existing implicit rule 292 to get the commandsfor updating a file.291 to get the recipe for updating a file. 293 292 * Catalogue of Rules:: A list of built-in implicit rules. 294 293 * Implicit Variables:: How to change what predefined rules do. 295 294 * Chained Rules:: How to use a chain of implicit rules. 296 295 * Pattern Rules:: How to define new implicit rules. 297 * Last Resort:: How to define commandsfor rules which296 * Last Resort:: How to define a recipe for rules which 298 297 cannot find any. 299 298 * Suffix Rules:: The old-fashioned style of implicit rule. … … 306 305 * Pattern Examples:: Examples of pattern rules. 307 306 * Automatic Variables:: How to use automatic variables in the 308 commandsof implicit rules.307 recipe of implicit rules. 309 308 * Pattern Match:: How patterns match. 310 309 * Match-Anything Rules:: Precautions you should take prior to … … 378 377 uses the makefile data base and the last-modification times of the files to 379 378 decide which of the files need to be updated. For each of those files, it 380 issues the commands recorded in the data base.379 issues the recipes recorded in the data base. 381 380 382 381 You can provide command line arguments to @code{make} to control which … … 432 431 these messages: it's best to cut and paste them into your report. 433 432 When generating this small makefile, be sure to not use any non-free 434 or unusual tools in your commands: you can almost always emulate what433 or unusual tools in your recipes: you can almost always emulate what 435 434 such a tool would do with simple shell commands. Finally, be sure to 436 435 explain what you expected to occur; this will help us decide whether … … 490 489 * How Make Works:: How @code{make} Processes This Makefile 491 490 * Variables Simplify:: Variables Make Makefiles Simpler 492 * make Deduces:: Letting @code{make} Deduce the Commands491 * make Deduces:: Letting @code{make} Deduce the Recipes 493 492 * Combine By Prerequisite:: Another Style of Makefile 494 493 * Cleanup:: Rules for Cleaning the Directory … … 506 505 @cindex targets, introduction to 507 506 @cindex prerequisites, introduction to 508 @cindex commands, introduction to507 @cindex recipes, introduction to 509 508 @example 510 509 @group 511 510 @var{target} @dots{} : @var{prerequisites} @dots{} 512 @var{ command}511 @var{recipe} 513 512 @dots{} 514 513 @dots{} … … 525 524 526 525 @cindex tabs in rules 527 A @dfn{ command} is an action that @code{make} carries out.528 A r ule may have more than one command, each on its own line.526 A @dfn{recipe} is an action that @code{make} carries out. 527 A recipe may have more than one command, each on its own line. 529 528 @strong{Please note:} you need to put a tab character at the beginning of 530 every command line! This is an obscurity that catches the unwary. 531 532 Usually a command is in a rule with prerequisites and serves to create a 529 every command line! This is an obscurity that catches the unwary. If 530 you prefer to prefix your recipes with a character other than tab, 531 you can set the @code{.CMDPREFIX} variable to an alternate character 532 (@pxref{Special Variables}). 533 534 Usually a recipe is in a rule with prerequisites and serves to create a 533 535 target file if any of the prerequisites change. However, the rule that 534 specifies commandsfor the target need not have prerequisites. For536 specifies a recipe for the target need not have prerequisites. For 535 537 example, the rule containing the delete command associated with the 536 538 target @samp{clean} does not have prerequisites. … … 538 540 A @dfn{rule}, then, explains how and when to remake certain files 539 541 which are the targets of the particular rule. @code{make} carries out 540 the commandson the prerequisites to create or update the target. A542 the recipe on the prerequisites to create or update the target. A 541 543 rule can also explain how and when to carry out an action. 542 544 @xref{Rules, , Writing Rules}. … … 615 617 prerequisites are files such as @samp{main.c} and @samp{defs.h}. 616 618 In fact, each @samp{.o} file is both a target and a prerequisite. 617 Commands include @w{@samp{cc -c main.c}} and @w{@samp{cc -c kbd.c}}.619 Recipes include @w{@samp{cc -c main.c}} and @w{@samp{cc -c kbd.c}}. 618 620 619 621 When a target is a file, it needs to be recompiled or relinked if any … … 624 626 on the header file @file{defs.h}. 625 627 626 A shell command follows each line that contains a target and 627 prerequisites. These shell commands say how to update the target file. 628 A tab character must come at the beginning of every command line to 629 distinguish command lines from other lines in the makefile. (Bear in 630 mind that @code{make} does not know anything about how the commands 631 work. It is up to you to supply commands that will update the target 632 file properly. All @code{make} does is execute the commands in the rule 633 you have specified when the target file needs to be updated.) 634 @cindex shell command 628 A recipe may follow each line that contains a target and 629 prerequisites. These recipes say how to update the target file. A 630 tab character (or whatever character is specified by the 631 @code{.CMDPREFIX} variable; @pxref{Special Variables}) must come at 632 the beginning of every line in the recipe to distinguish recipes from 633 other lines in the makefile. (Bear in mind that @code{make} does not 634 know anything about how the recipes work. It is up to you to supply 635 recipes that will update the target file properly. All @code{make} 636 does is execute the commands in the recipe you have specified when the 637 target file needs to be updated.)@refill 638 @cindex recipe 635 639 636 640 The target @samp{clean} is not a file, but merely the name of an 637 action. Since you 638 normally 639 do not want to carry out the actions in this rule, @samp{clean} is not a prerequisite of any other rule. 641 action. Since you normally do not want to carry out the actions in 642 this rule, @samp{clean} is not a prerequisite of any other rule. 640 643 Consequently, @code{make} never does anything with it unless you tell 641 it specifically. Note that this rule not only is not a prerequisite, it642 also does not have any prerequisites, so the only purpose of the rule643 is to run the specified commands. Targets that do not refer to files 644 but are just actions are called @dfn{phony targets}. @xref{Phony 645 Targets}, for information about this kind of target. @xref{Errors, , 646 Errors in Commands}, to see how to cause @code{make} to ignore errors 647 from @code{rm} or any other command.644 it specifically. Note that this rule not only is not a prerequisite, 645 it also does not have any prerequisites, so the only purpose of the 646 rule is to run the specified recipe. Targets that do not refer to 647 files but are just actions are called @dfn{phony targets}. 648 @xref{Phony Targets}, for information about this kind of target. 649 @xref{Errors, , Errors in Recipes}, to see how to cause @code{make} 650 to ignore errors from @code{rm} or any other command. 648 651 @cindex @code{clean} target 649 652 @cindex @code{rm} (shell command) … … 793 796 794 797 @node make Deduces, Combine By Prerequisite, Variables Simplify, Introduction 795 @section Letting @code{make} Deduce the Commands796 @cindex deducing commands (implicit rules)798 @section Letting @code{make} Deduce the Recipes 799 @cindex deducing recipes (implicit rules) 797 800 @cindex implicit rule, introduction to 798 801 @cindex rule, implicit, introduction to 799 802 800 It is not necessary to spell out the commands for compiling the individual803 It is not necessary to spell out the recipes for compiling the individual 801 804 C source files, because @code{make} can figure them out: it has an 802 805 @dfn{implicit rule} for updating a @samp{.o} file from a correspondingly 803 806 named @samp{.c} file using a @samp{cc -c} command. For example, it will 804 use the command@samp{cc -c main.c -o main.o} to compile @file{main.c} into805 @file{main.o}. We can therefore omit the commands from the rules for the807 use the recipe @samp{cc -c main.c -o main.o} to compile @file{main.c} into 808 @file{main.o}. We can therefore omit the recipes from the rules for the 806 809 object files. @xref{Implicit Rules, ,Using Implicit Rules}.@refill 807 810 808 811 When a @samp{.c} file is used automatically in this way, it is also 809 812 automatically added to the list of prerequisites. We can therefore omit 810 the @samp{.c} files from the prerequisites, provided we omit the commands.813 the @samp{.c} files from the prerequisites, provided we omit the recipe. 811 814 812 815 Here is the entire example, with both of these changes, and a variable … … 839 842 This is how we would write the makefile in actual practice. (The 840 843 complications associated with @samp{clean} are described elsewhere. 841 See @ref{Phony Targets}, and @ref{Errors, ,Errors in Commands}.)844 See @ref{Phony Targets}, and @ref{Errors, ,Errors in Recipes}.) 842 845 843 846 Because implicit rules are so convenient, they are important. You … … 912 915 called @file{clean} and causes it to continue in spite of errors from 913 916 @code{rm}. (See @ref{Phony Targets}, and @ref{Errors, ,Errors in 914 Commands}.)917 Recipes}.) 915 918 916 919 @noindent … … 937 940 * Include:: How one makefile can use another makefile. 938 941 * MAKEFILES Variable:: The environment can specify extra makefiles. 939 * MAKEFILE_LIST Variable:: Discover which makefiles have been read.940 * Special Variables:: Other special variables.941 942 * Remaking Makefiles:: How makefiles get remade. 942 943 * Overriding Makefiles:: How to override part of one makefile … … 961 962 called the rule's @dfn{targets}. It lists the other files that the 962 963 targets depend on, called the @dfn{prerequisites} of the target, and 963 may also give commandsto use to create or update the targets.964 may also give a recipe to use to create or update the targets. 964 965 @xref{Rules, ,Writing Rules}. 965 966 … … 969 970 An @dfn{implicit rule} says when and how to remake a class of files 970 971 based on their names. It describes how a target may depend on a file 971 with a name similar to the target and gives commandsto create or972 with a name similar to the target and gives a recipe to create or 972 973 update such a target. @xref{Implicit Rules, ,Using Implicit Rules}. 973 974 … … 982 983 @cindex directive 983 984 @item 984 A @dfn{directive} is a command for @code{make} to do something special while985 reading the makefile. These include:985 A @dfn{directive} is an instruction for @code{make} to do something 986 special while reading the makefile. These include: 986 987 987 988 @itemize @bullet … … 1014 1015 start of a comment) inside a variable reference or function call. 1015 1016 1016 Within a command script (if the line begins with a TAB character) the 1017 entire line is passed to the shell, just as with any other line that 1018 begins with a TAB. The shell decides how to interpret the text: 1019 whether or not this is a comment is up to the shell. 1017 Comments within a recipe are passed to the shell, just as with any 1018 other recipe text. The shell decides how to interpret it: whether or 1019 not this is a comment is up to the shell. 1020 1020 1021 1021 Within a @code{define} directive, comments are not ignored during the 1022 1022 definition of the variable, but rather kept intact in the value of the 1023 1023 variable. When the variable is expanded they will either be treated 1024 as @code{make} comments or as command script text, depending on the1025 context inwhich the variable is evaluated.1024 as @code{make} comments or as recipe text, depending on the context in 1025 which the variable is evaluated. 1026 1026 @end itemize 1027 1027 … … 1096 1096 1097 1097 Extra spaces are allowed and ignored at the beginning of the line, but 1098 a tab is not allowed. (If the line begins with a tab, it will be 1099 considered a command line.) Whitespace is required between 1098 the first character must not be a tab (or the value of 1099 @code{.CMDPREFIX})---if the line begins with a tab, it will be 1100 considered a recipe line. Whitespace is required between 1100 1101 @code{include} and the file names, and between file names; extra 1101 1102 whitespace is ignored there and at the end of the directive. A … … 1182 1183 @code{sinclude} is another name for @w{@code{-include}}. 1183 1184 1184 @node MAKEFILES Variable, MAKEFILE_LIST Variable, Include, Makefiles1185 @node MAKEFILES Variable, Remaking Makefiles, Include, Makefiles 1185 1186 @section The Variable @code{MAKEFILES} 1186 1187 @cindex makefile, and @code{MAKEFILES} variable … … 1212 1213 in the makefiles. @xref{Include, , Including Other Makefiles}. 1213 1214 1214 @node MAKEFILE_LIST Variable, Special Variables, MAKEFILES Variable, Makefiles 1215 @comment node-name, next, previous, up 1216 @section The Variable @code{MAKEFILE_LIST} 1217 @cindex makefiles, and @code{MAKEFILE_LIST} variable 1218 @cindex including (@code{MAKEFILE_LIST} variable) 1219 @vindex MAKEFILE_LIST 1220 1221 As @code{make} reads various makefiles, including any obtained from the 1222 @code{MAKEFILES} variable, the command line, the default files, or 1223 from @code{include} directives, their names will be automatically 1224 appended to the @code{MAKEFILE_LIST} variable. They are added right 1225 before @code{make} begins to parse them. 1226 1227 This means that if the first thing a makefile does is examine the last 1228 word in this variable, it will be the name of the current makefile. 1229 Once the current makefile has used @code{include}, however, the last 1230 word will be the just-included makefile. 1231 1232 If a makefile named @code{Makefile} has this content: 1233 1234 @example 1235 @group 1236 name1 := $(lastword $(MAKEFILE_LIST)) 1237 1238 include inc.mk 1239 1240 name2 := $(lastword $(MAKEFILE_LIST)) 1241 1242 all: 1243 @@echo name1 = $(name1) 1244 @@echo name2 = $(name2) 1245 @end group 1246 @end example 1247 1248 @noindent 1249 then you would expect to see this output: 1250 1251 @example 1252 @group 1253 name1 = Makefile 1254 name2 = inc.mk 1255 @end group 1256 @end example 1257 1258 @xref{Text Functions}, for more information on the @code{lastword} 1259 function used above. @xref{Flavors, The Two Flavors of Variables}, 1260 for more information on simply-expanded (@code{:=}) variable 1261 definitions. 1262 1263 @node Special Variables, Remaking Makefiles, MAKEFILE_LIST Variable, Makefiles 1264 @comment node-name, next, previous, up 1265 @section Other Special Variables 1266 @cindex makefiles, and special variables 1267 @cindex special variables 1268 1269 GNU @code{make} also supports other special variables. Unless 1270 otherwise documented here, these values lose their special properties 1271 if they are set by a makefile or on the command line. 1272 1273 @table @code 1274 1275 @vindex .DEFAULT_GOAL @r{(define default goal)} 1276 @item .DEFAULT_GOAL 1277 Sets the default goal to be used if no targets were specified on the 1278 command line (@pxref{Goals, , Arguments to Specify the Goals}). The 1279 @code{.DEFAULT_GOAL} variable allows you to discover the current 1280 default goal, restart the default goal selection algorithm by clearing 1281 its value, or to explicitly set the default goal. The following 1282 example illustrates these cases: 1283 1284 @example 1285 @group 1286 # Query the default goal. 1287 ifeq ($(.DEFAULT_GOAL),) 1288 $(warning no default goal is set) 1289 endif 1290 1291 .PHONY: foo 1292 foo: ; @@echo $@@ 1293 1294 $(warning default goal is $(.DEFAULT_GOAL)) 1295 1296 # Reset the default goal. 1297 .DEFAULT_GOAL := 1298 1299 .PHONY: bar 1300 bar: ; @@echo $@@ 1301 1302 $(warning default goal is $(.DEFAULT_GOAL)) 1303 1304 # Set our own. 1305 .DEFAULT_GOAL := foo 1306 @end group 1307 @end example 1308 1309 This makefile prints: 1310 1311 @example 1312 @group 1313 no default goal is set 1314 default goal is foo 1315 default goal is bar 1316 foo 1317 @end group 1318 @end example 1319 1320 Note that assigning more than one target name to @code{.DEFAULT_GOAL} is 1321 illegal and will result in an error. 1322 1323 @vindex MAKE_RESTARTS @r{(number of times @code{make} has restarted)} 1324 @item MAKE_RESTARTS 1325 This variable is set only if this instance of @code{make} has 1326 restarted (@pxref{Remaking Makefiles, , How Makefiles Are Remade}): it 1327 will contain the number of times this instance has restarted. Note 1328 this is not the same as recursion (counted by the @code{MAKELEVEL} 1329 variable). You should not set, modify, or export this variable. 1330 1331 @vindex .VARIABLES @r{(list of variables)} 1332 @item .VARIABLES 1333 Expands to a list of the @emph{names} of all global variables defined 1334 so far. This includes variables which have empty values, as well as 1335 built-in variables (@pxref{Implicit Variables, , Variables Used by 1336 Implicit Rules}), but does not include any variables which are only 1337 defined in a target-specific context. Note that any value you assign 1338 to this variable will be ignored; it will always return its special 1339 value. 1340 1341 @c @vindex .TARGETS @r{(list of targets)} 1342 @c @item .TARGETS 1343 @c The second special variable is @code{.TARGETS}. When expanded, the 1344 @c value consists of a list of all targets defined in all makefiles read 1345 @c up until that point. Note it's not enough for a file to be simply 1346 @c mentioned in the makefile to be listed in this variable, even if it 1347 @c would match an implicit rule and become an ``implicit target''. The 1348 @c file must appear as a target, on the left-hand side of a ``:'', to be 1349 @c considered a target for the purposes of this variable. 1350 1351 @vindex .FEATURES @r{(list of supported features)} 1352 @item .FEATURES 1353 Expands to a list of special features supported by this version of 1354 @code{make}. Possible values include: 1355 1356 @table @samp 1357 1358 @item archives 1359 Supports @code{ar} (archive) files using special filename syntax. 1360 @xref{Archives, ,Using @code{make} to Update Archive Files}. 1361 1362 @item check-symlink 1363 Supports the @code{-L} (@code{--check-symlink-times}) flag. 1364 @xref{Options Summary, ,Summary of Options}. 1365 1366 @item else-if 1367 Supports ``else if'' non-nested conditionals. @xref{Conditional 1368 Syntax, ,Syntax of Conditionals}. 1369 1370 @item jobserver 1371 Supports ``job server'' enhanced parallel builds. @xref{Parallel, 1372 ,Parallel Execution}. 1373 1374 @item second-expansion 1375 Supports secondary expansion of prerequisite lists. 1376 1377 @item order-only 1378 Supports order-only prerequisites. @xref{Prerequisite Types, ,Types 1379 of Prerequisites}. 1380 1381 @item target-specific 1382 Supports target-specific and pattern-specific variable assignments. 1383 @xref{Target-specific, ,Target-specific Variable Values}. 1384 1385 @end table 1386 1387 @vindex .INCLUDE_DIRS @r{(list of include directories)} 1388 @item .INCLUDE_DIRS 1389 Expands to a list of directories that @code{make} searches for 1390 included makefiles (@pxref{Include, , Including Other Makefiles}). 1391 1392 @end table 1393 1394 @node Remaking Makefiles, Overriding Makefiles, Special Variables, Makefiles 1215 @node Remaking Makefiles, Overriding Makefiles, MAKEFILES Variable, Makefiles 1395 1216 @section How Makefiles Are Remade 1396 1217 … … 1413 1234 date.)@refill 1414 1235 1415 If you know that one or more of your makefiles cannot be remade and you1416 want to keep @code{make} from performing an implicit rule search on 1417 them, perhaps for efficiency reasons, you can use any normal method of 1418 preventing implicit rule lookup to do so. For example, you can writean1419 explicit rule with the makefile as the target, and an empty command 1420 string (@pxref{Empty Commands, ,Using Empty Commands}).1236 If you know that one or more of your makefiles cannot be remade and 1237 you want to keep @code{make} from performing an implicit rule search 1238 on them, perhaps for efficiency reasons, you can use any normal method 1239 of preventing implicit rule lookup to do so. For example, you can 1240 write an explicit rule with the makefile as the target, and an empty 1241 recipe (@pxref{Empty Recipes, ,Using Empty Recipes}). 1421 1242 1422 1243 If the makefiles specify a double-colon rule to remake a file with 1423 commandsbut no prerequisites, that file will always be remade1244 a recipe but no prerequisites, that file will always be remade 1424 1245 (@pxref{Double-Colon}). In the case of makefiles, a makefile that has a 1425 double-colon rule with commandsbut no prerequisites will be remade every1246 double-colon rule with a recipe but no prerequisites will be remade every 1426 1247 time @code{make} is run, and then again after @code{make} starts over 1427 1248 and reads the makefiles in again. This would cause an infinite loop: … … 1429 1250 else. So, to avoid this, @code{make} will @strong{not} attempt to 1430 1251 remake makefiles which are specified as targets of a double-colon rule 1431 with commandsbut no prerequisites.@refill1252 with a recipe but no prerequisites.@refill 1432 1253 1433 1254 If you do not specify any makefiles to be read with @samp{-f} or … … 1448 1269 1449 1270 When you use the @samp{-t} or @samp{--touch} option 1450 (@pxref{Instead of Execution, ,Instead of Executing the Commands}),1271 (@pxref{Instead of Execution, ,Instead of Executing the Recipe}), 1451 1272 you would not want to use an out-of-date makefile to decide which 1452 1273 targets to touch. So the @samp{-t} option has no effect on updating … … 1456 1277 out-of-date makefile would result in the wrong output for other targets. 1457 1278 Thus, @samp{make -f mfile -n foo} will update @file{mfile}, read it in, 1458 and then print the commandsto update @file{foo} and its prerequisites1459 without running them. The commands printed for @file{foo} will be those1279 and then print the recipe to update @file{foo} and its prerequisites 1280 without running it. The recipe printed for @file{foo} will be the one 1460 1281 specified in the updated contents of @file{mfile}. 1461 1282 … … 1467 1288 1468 1289 Thus, @samp{make -f mfile -n mfile foo} would read the makefile 1469 @file{mfile}, print the commandsneeded to update it without actually1470 running them, and then print the commandsneeded to update @file{foo}1471 without running th em. The commands for @file{foo} will be those1290 @file{mfile}, print the recipe needed to update it without actually 1291 running it, and then print the recipe needed to update @file{foo} 1292 without running that. The recipe for @file{foo} will be the one 1472 1293 specified by the existing contents of @file{mfile}. 1473 1294 … … 1480 1301 another makefile. You can often use the @samp{include} directive to 1481 1302 include one in the other, and add more targets or variable definitions. 1482 However, i f the two makefiles give different commands for the same1483 t arget, @code{make} will not let you just do this. But there is another way.1303 However, it is illegal for two makefiles to give different recipes for 1304 the same target. But there is another way. 1484 1305 1485 1306 @cindex match-anything rule, used to override … … 1504 1325 1505 1326 If you say @samp{make foo}, @code{make} will find @file{GNUmakefile}, 1506 read it, and see that to make @file{foo}, it needs to run the command1327 read it, and see that to make @file{foo}, it needs to run the recipe 1507 1328 @samp{frobnicate > foo}. If you say @samp{make bar}, @code{make} will 1508 1329 find no way to make @file{bar} in @file{GNUmakefile}, so it will use the 1509 commandsfrom the pattern rule: @samp{make -f Makefile bar}. If1330 recipe from the pattern rule: @samp{make -f Makefile bar}. If 1510 1331 @file{Makefile} provides a rule for updating @file{bar}, @code{make} 1511 1332 will apply the rule. And likewise for any other target that … … 1514 1335 The way this works is that the pattern rule has a pattern of just 1515 1336 @samp{%}, so it matches any target whatever. The rule specifies a 1516 prerequisite @file{force}, to guarantee that the commandswill be run even1517 if the target file already exists. We give @file{force} target empty1518 commandsto prevent @code{make} from searching for an implicit rule to1337 prerequisite @file{force}, to guarantee that the recipe will be run even 1338 if the target file already exists. We give the @file{force} target an 1339 empty recipe to prevent @code{make} from searching for an implicit rule to 1519 1340 build it---otherwise it would apply the same match-anything rule to 1520 1341 @file{force} itself and create a prerequisite loop! … … 1542 1363 construct as the makefile is parsed. We say that expansion is 1543 1364 @dfn{deferred} if expansion is not performed immediately. Expansion of 1544 deferred construct is not performed until either the construct appears1365 a deferred construct is not performed until either the construct appears 1545 1366 later in an immediate context, or until the second phase. 1546 1367 … … 1573 1394 (@samp{:=}), and deferred otherwise. 1574 1395 1575 @subheading Conditional Statements1396 @subheading Conditional Directives 1576 1397 @cindex ifdef, expansion 1577 1398 @cindex ifeq, expansion … … 1579 1400 @cindex ifneq, expansion 1580 1401 1581 All instances of conditional syntax are parsed immediately, in their 1582 entirety; this includes the @code{ifdef}, @code{ifeq}, @code{ifndef}, 1583 and @code{ifneq} forms. Of course this means that automatic variables 1584 cannot be used in conditional statements, as automatic variables are 1585 not set until the command script for that rule is invoked. If you 1586 need to use automatic variables in a conditional you @emph{must} use 1587 shell conditional syntax, in your command script proper, for these 1588 tests, not @code{make} conditionals. 1402 Conditional directives are parsed immediately. This means, for 1403 example, that automatic variables cannot be used in conditional 1404 directives, as automatic variables are not set until the recipe for 1405 that rule is invoked. If you need to use automatic variables in a 1406 conditional directive you @emph{must} move the condition into the 1407 recipe and use shell conditional syntax instead. 1589 1408 1590 1409 @subheading Rule Definition … … 1603 1422 1604 1423 That is, the target and prerequisite sections are expanded immediately, 1605 and the commands used to construct the target arealways deferred. This1424 and the recipe used to construct the target is always deferred. This 1606 1425 general rule is true for explicit rules, pattern rules, suffix rules, 1607 1426 static pattern rules, and simple prerequisite definitions. … … 1677 1496 target. This means that you can use variables such as @code{$@@}, 1678 1497 @code{$*}, etc. during the second expansion and they will have their 1679 expected values, just as in the command script. All you have to do is1680 defer the expansion by escaping the @code{$}. Also, secondary 1681 expansion occurs for both explicit and implicit (pattern) rules. 1682 Knowing this, the possible uses for this feature increase 1683 dramatically. Forexample:1498 expected values, just as in the recipe. All you have to do is defer 1499 the expansion by escaping the @code{$}. Also, secondary expansion 1500 occurs for both explicit and implicit (pattern) rules. Knowing this, 1501 the possible uses for this feature increase dramatically. For 1502 example: 1684 1503 1685 1504 @example … … 1699 1518 @code{$(lib_OBJS)}, or @code{lib.o api.o}. 1700 1519 1701 You can also mix functions here, as long as they are properly escaped:1520 You can also mix in functions here, as long as they are properly escaped: 1702 1521 1703 1522 @example … … 1715 1534 Evaluation of automatic variables during the secondary expansion 1716 1535 phase, especially of the target name variable @code{$$@@}, behaves 1717 similarly to evaluation within command scripts. However, there are1718 s ome subtle differences and ``corner cases'' which come into play for1719 the different types of rule definitions that @code{make} understands. 1720 The subtleties of using the different automatic variables are 1721 describedbelow.1536 similarly to evaluation within recipes. However, there are some 1537 subtle differences and ``corner cases'' which come into play for the 1538 different types of rule definitions that @code{make} understands. The 1539 subtleties of using the different automatic variables are described 1540 below. 1722 1541 1723 1542 @subheading Secondary Expansion of Explicit Rules … … 1752 1571 1753 1572 Rules undergo secondary expansion in makefile order, except that 1754 the rule with the command scriptis always evaluated last.1573 the rule with the recipe is always evaluated last. 1755 1574 1756 1575 The variables @code{$$?} and @code{$$*} are not available and expand … … 1809 1628 @code{$$*} instead of @code{%} in the prerequisites list. 1810 1629 1811 @node Rules, Commands, Makefiles, Top1630 @node Rules, Recipes, Makefiles, Top 1812 1631 @chapter Writing Rules 1813 1632 @cindex writing rules … … 1819 1638 certain files, called the rule's @dfn{targets} (most often only one per rule). 1820 1639 It lists the other files that are the @dfn{prerequisites} of the target, and 1821 @dfn{commands} to use to create or update the target.1640 the @dfn{recipe} to use to create or update the target. 1822 1641 1823 1642 @cindex default goal … … 1845 1664 * Directory Search:: Searching other directories for source files. 1846 1665 * Phony Targets:: Using a target that is not a real file's name. 1847 * Force Targets:: You can use a target without commands1666 * Force Targets:: You can use a target without recipes 1848 1667 or prerequisites to mark other targets 1849 1668 as phony. … … 1874 1693 1875 1694 Its target is @file{foo.o} and its prerequisites are @file{foo.c} and 1876 @file{defs.h}. It has one command , which is@samp{cc -c -g foo.c}.1877 The command line starts with a tab to identify it as a command.1695 @file{defs.h}. It has one command in the recipe: @samp{cc -c -g foo.c}. 1696 The recipe starts with a tab to identify it as a recipe. 1878 1697 1879 1698 This rule says two things: … … 1887 1706 @item 1888 1707 How to update the file @file{foo.o}: by running @code{cc} as stated. 1889 The commanddoes not explicitly mention @file{defs.h}, but we presume1708 The recipe does not explicitly mention @file{defs.h}, but we presume 1890 1709 that @file{foo.c} includes it, and that that is why @file{defs.h} was 1891 1710 added to the prerequisites. … … 1902 1721 @example 1903 1722 @var{targets} : @var{prerequisites} 1904 @var{ command}1723 @var{recipe} 1905 1724 @dots{} 1906 1725 @end example … … 1910 1729 1911 1730 @example 1912 @var{targets} : @var{prerequisites} ; @var{ command}1913 @var{ command}1731 @var{targets} : @var{prerequisites} ; @var{recipe} 1732 @var{recipe} 1914 1733 @dots{} 1915 1734 @end example … … 1926 1745 (@pxref{Multiple Targets, , Multiple Targets in a Rule}).@refill 1927 1746 1928 @cindex commands1747 @cindex recipes 1929 1748 @cindex tab character (in commands) 1930 The @var{command} lines start with a tab character. The first command may 1931 appear on the line after the prerequisites, with a tab character, or may 1932 appear on the same line, with a semicolon. Either way, the effect is the 1933 same. There are other differences in the syntax of command lines. 1934 @xref{Commands, ,Writing the Commands in Rules}. 1749 The @var{recipe} lines start with a tab character (or the first 1750 character in the value of the @code{.CMDPREFIX} variable; 1751 @pxref{Special Variables}). The first recipe line may appear on the line 1752 after the prerequisites, with a tab character, or may appear on the 1753 same line, with a semicolon. Either way, the effect is the same. 1754 There are other differences in the syntax of recipes. 1755 @xref{Recipes, ,Writing Recipes in Rules}. 1935 1756 1936 1757 @cindex dollar sign (@code{$}), in rules … … 1964 1785 valid. 1965 1786 1966 How to update is specified by @var{commands}. These are lines to be1967 executed by the shell (normally @samp{sh}), but with some extra features 1968 (@pxref{Commands, ,Writing the Commands in Rules}).1787 How to update is specified by a @var{recipe}. This is one or more 1788 lines to be executed by the shell (normally @samp{sh}), but with some 1789 extra features (@pxref{Recipes, ,Writing Recipes in Rules}). 1969 1790 1970 1791 @node Prerequisite Types, Wildcards, Rule Syntax, Rules … … 1982 1803 previous section, and @dfn{order-only} prerequisites. A normal 1983 1804 prerequisite makes two statements: first, it imposes an order of 1984 execution of build commands: any commands necessary to build any of a1985 target's prerequisites will be fully executed before any commands1805 execution of recipes: any recipes necessary to build any of a 1806 target's prerequisites will be fully executed before any recipe 1986 1807 necessary to build the target. Second, it imposes a dependency 1987 1808 relationship: if any prerequisite is newer than the target, then the … … 2070 1891 2071 1892 Wildcard expansion is performed by @code{make} automatically in 2072 targets and in prerequisites. In commandsthe shell is responsible1893 targets and in prerequisites. In recipes, the shell is responsible 2073 1894 for wildcard expansion. In other contexts, wildcard expansion happens 2074 1895 only if you request it explicitly with the @code{wildcard} function. … … 2089 1910 @subsection Wildcard Examples 2090 1911 2091 Wildcards can be used in the commandsof a rule, where they are expanded1912 Wildcards can be used in the recipe of a rule, where they are expanded 2092 1913 by the shell. For example, here is a rule to delete all the object files: 2093 1914 … … 2129 1950 then the value of the variable @code{objects} is the actual string 2130 1951 @samp{*.o}. However, if you use the value of @code{objects} in a target, 2131 prerequisite or command, wildcard expansion will take place at that time.1952 prerequisite, or recipe, wildcard expansion will take place at that time. 2132 1953 To set @code{objects} to the expansion, instead use: 2133 1954 … … 2276 2097 for a specified class of names. 2277 2098 * Search Algorithm:: When and how search paths are applied. 2278 * Commands/Search:: How to write shell commands that work together2099 * Recipes/Search:: How to write recipes that work together 2279 2100 with search paths. 2280 2101 * Implicit/Search:: How search paths affect implicit rules. … … 2297 2118 them, that file may become the prerequisite (see below). Rules may then 2298 2119 specify the names of files in the prerequisite list as if they all 2299 existed in the current directory. @xref{Commands/Search, ,Writing Shell 2300 Commands with Directory Search}. 2120 existed in the current directory. @xref{Recipes/Search, ,Writing Recipes with Directory Search}. 2301 2121 2302 2122 In the @code{VPATH} variable, directory names are separated by colons or … … 2433 2253 @file{bar}, then @file{blish}. 2434 2254 2435 @node Search Algorithm, Commands/Search, Selective Search, Directory Search2255 @node Search Algorithm, Recipes/Search, Selective Search, Directory Search 2436 2256 @subsection How Directory Searches are Performed 2437 2257 @cindex algorithm for directory search … … 2500 2320 rebuilt using the expanded path. 2501 2321 2502 @node Commands/Search, Implicit/Search, Search Algorithm, Directory Search2503 @subsection Writing Shell Commands with Directory Search2504 @cindex shell command, and directory search2505 @cindex directory search (@code{VPATH}), and shell commands2322 @node Recipes/Search, Implicit/Search, Search Algorithm, Directory Search 2323 @subsection Writing Recipes with Directory Search 2324 @cindex recipes, and directory search 2325 @cindex directory search (@code{VPATH}), and recipes 2506 2326 2507 2327 When a prerequisite is found in another directory through directory search, 2508 this cannot change the commandsof the rule; they will execute as written.2509 Therefore, you must write the commands with care so that theywill look for2328 this cannot change the recipe of the rule; they will execute as written. 2329 Therefore, you must write the recipe with care so that it will look for 2510 2330 the prerequisite in the directory where @code{make} finds it. 2511 2331 … … 2529 2349 2530 2350 Often the prerequisites include header files as well, which you do not 2531 want to mention in the commands. The automatic variable @samp{$<} is2351 want to mention in the recipe. The automatic variable @samp{$<} is 2532 2352 just the first prerequisite: 2533 2353 … … 2538 2358 @end example 2539 2359 2540 @node Implicit/Search, Libraries/Search, Commands/Search, Directory Search2360 @node Implicit/Search, Libraries/Search, Recipes/Search, Directory Search 2541 2361 @subsection Directory Search and Implicit Rules 2542 2362 @cindex @code{VPATH}, and implicit rules … … 2559 2379 directories, the implicit rule for C compilation is applied. 2560 2380 2561 The commands of implicit rules normally use automatic variables as a2381 The recipes of implicit rules normally use automatic variables as a 2562 2382 matter of necessity; consequently they will use the file names found by 2563 2383 directory search with no extra effort. … … 2630 2450 @cindex targets without a file 2631 2451 2632 A phony target is one that is not really the name of a file . It is just a2633 name for some commands to be executed when you make an explicit request. 2634 There are two reasons to use a phony target: to avoid a conflict with 2635 a file of the same name, and to improve performance.2636 2637 If you write a rule whose commandswill not create the target file, the2638 commandswill be executed every time the target comes up for remaking.2452 A phony target is one that is not really the name of a file; rather it 2453 is just a name for a recipe to be executed when you make an explicit 2454 request. There are two reasons to use a phony target: to avoid a 2455 conflict with a file of the same name, and to improve performance. 2456 2457 If you write a rule whose recipe will not create the target file, the 2458 recipe will be executed every time the target comes up for remaking. 2639 2459 Here is an example: 2640 2460 … … 2656 2476 named @file{clean} in this directory. Since it has no prerequisites, the 2657 2477 file @file{clean} would inevitably be considered up to date, and its 2658 commandswould not be executed. To avoid this problem, you can explicitly2478 recipe would not be executed. To avoid this problem, you can explicitly 2659 2479 declare the target to be phony, using the special target @code{.PHONY} 2660 2480 (@pxref{Special Targets, ,Special Built-in Target Names}) as follows: … … 2665 2485 2666 2486 @noindent 2667 Once this is done, @samp{make clean} will run the commandsregardless of2487 Once this is done, @samp{make clean} will run the recipe regardless of 2668 2488 whether there is a file named @file{clean}. 2669 2489 … … 2690 2510 makefile will often contain a variable which lists a number of 2691 2511 subdirectories to be built. One way to handle this is with one rule 2692 whose commandis a shell loop over the subdirectories, like this:2512 whose recipe is a shell loop over the subdirectories, like this: 2693 2513 2694 2514 @example … … 2703 2523 @end example 2704 2524 2705 There are a fewproblems with this method, however. First, any error2706 detected in a submake is not noted by this rule, so it will continue to2707 build the rest of the directories even when one fails. This can be2525 There are problems with this method, however. First, any error 2526 detected in a submake is ignored by this rule, so it will continue 2527 to build the rest of the directories even when one fails. This can be 2708 2528 overcome by adding shell commands to note the error and exit, but then 2709 it will do so even if @code{make} is invoked with the @code{-k} option, 2710 which is unfortunate. Second, and perhaps more importantly, you cannot 2711 take advantage of @code{make}'s ability to build targets in parallel 2712 (@pxref{Parallel, ,Parallel Execution}), since there is only one rule. 2529 it will do so even if @code{make} is invoked with the @code{-k} 2530 option, which is unfortunate. Second, and perhaps more importantly, 2531 you cannot take advantage of @code{make}'s ability to build targets in 2532 parallel (@pxref{Parallel, ,Parallel Execution}), since there is only 2533 one rule. 2713 2534 2714 2535 By declaring the subdirectories as phony targets (you must do this as … … 2737 2558 2738 2559 A phony target should not be a prerequisite of a real target file; if it 2739 is, its commands are run every time @code{make} goes to update that2560 is, its recipe will be run every time @code{make} goes to update that 2740 2561 file. As long as a phony target is never a prerequisite of a real 2741 target, the phony target commandswill be executed only when the phony2562 target, the phony target recipe will be executed only when the phony 2742 2563 target is a specified goal (@pxref{Goals, ,Arguments to Specify the 2743 2564 Goals}). … … 2788 2609 2789 2610 @node Force Targets, Empty Targets, Phony Targets, Rules 2790 @section Rules without Commands or Prerequisites2611 @section Rules without Recipes or Prerequisites 2791 2612 @cindex force targets 2792 2613 @cindex targets, force 2793 2614 @cindex @code{FORCE} 2794 @cindex rule, no commandsor prerequisites2795 2796 If a rule has no prerequisites or commands, and the target of the rule2615 @cindex rule, no recipe or prerequisites 2616 2617 If a rule has no prerequisites or recipe, and the target of the rule 2797 2618 is a nonexistent file, then @code{make} imagines this target to have 2798 2619 been updated whenever its rule is run. This implies that all targets 2799 depending on this one will always have their commandsrun.2620 depending on this one will always have their recipe run. 2800 2621 2801 2622 An example will illustrate this: … … 2810 2631 2811 2632 Here the target @samp{FORCE} satisfies the special conditions, so the 2812 target @file{clean} that depends on it is forced to run its commands.2813 There is nothing special about the name @samp{FORCE}, but that is one name2814 commonly used this way.2633 target @file{clean} that depends on it is forced to run its recipe. 2634 There is nothing special about the name @samp{FORCE}, but that is one 2635 name commonly used this way. 2815 2636 2816 2637 As you can see, using @samp{FORCE} this way has the same results as using … … 2828 2649 2829 2650 The @dfn{empty target} is a variant of the phony target; it is used to hold 2830 commands for an action that you request explicitly from time to time.2651 recipes for an action that you request explicitly from time to time. 2831 2652 Unlike a phony target, this target file can really exist; but the file's 2832 2653 contents do not matter, and usually are empty. 2833 2654 2834 2655 The purpose of the empty target file is to record, with its 2835 last-modification time, when the rule's commands werelast executed. It2836 does so because one of the commands i s a @code{touch} command to update the2837 target file.2656 last-modification time, when the rule's recipe was last executed. It 2657 does so because one of the commands in the recipe is a @code{touch} 2658 command to update the target file. 2838 2659 2839 2660 The empty target file should have some prerequisites (otherwise it 2840 2661 doesn't make sense). When you ask to remake the empty target, the 2841 commands areexecuted if any prerequisite is more recent than the target;2662 recipe is executed if any prerequisite is more recent than the target; 2842 2663 in other words, if a prerequisite has changed since the last time you 2843 2664 remade the target. Here is an example: … … 2872 2693 The prerequisites of the special target @code{.PHONY} are considered to 2873 2694 be phony targets. When it is time to consider such a target, 2874 @code{make} will run its commandsunconditionally, regardless of2695 @code{make} will run its recipe unconditionally, regardless of 2875 2696 whether a file with that name exists or what its last-modification 2876 2697 time is. @xref{Phony Targets, ,Phony Targets}. … … 2886 2707 @item .DEFAULT 2887 2708 2888 The commands specified for @code{.DEFAULT} areused for any target for2709 The recipe specified for @code{.DEFAULT} is used for any target for 2889 2710 which no rules are found (either explicit rules or implicit rules). 2890 @xref{Last Resort}. If @code{.DEFAULT} commands arespecified, every2711 @xref{Last Resort}. If a @code{.DEFAULT} recipe is specified, every 2891 2712 file mentioned as a prerequisite, but not as a target in a rule, will have 2892 th ese commandsexecuted on its behalf. @xref{Implicit Rule Search,2713 that recipe executed on its behalf. @xref{Implicit Rule Search, 2893 2714 ,Implicit Rule Search Algorithm}. 2894 2715 … … 2900 2721 The targets which @code{.PRECIOUS} depends on are given the following 2901 2722 special treatment: if @code{make} is killed or interrupted during the 2902 execution of their commands, the target is not deleted.2723 execution of their recipes, the target is not deleted. 2903 2724 @xref{Interrupts, ,Interrupting or Killing @code{make}}. Also, if the 2904 2725 target is an intermediate file, it will not be deleted after it is no … … 2947 2768 If @code{.DELETE_ON_ERROR} is mentioned as a target anywhere in the 2948 2769 makefile, then @code{make} will delete the target of a rule if it has 2949 changed and its commands exitwith a nonzero exit status, just as it2950 does when it receives a signal. @xref{Errors, ,Errors in Commands}.2770 changed and its recipe exits with a nonzero exit status, just as it 2771 does when it receives a signal. @xref{Errors, ,Errors in Recipes}. 2951 2772 2952 2773 @findex .IGNORE … … 2954 2775 2955 2776 If you specify prerequisites for @code{.IGNORE}, then @code{make} will 2956 ignore errors in execution of the commands run for those particular2957 files. The commands for @code{.IGNORE} are not meaningful.2777 ignore errors in execution of the recipe for those particular files. 2778 The recipe for @code{.IGNORE} (if any) is ignored. 2958 2779 2959 2780 If mentioned as a target with no prerequisites, @code{.IGNORE} says to 2960 ignore errors in execution of commands for all files. This usage of2781 ignore errors in execution of recipes for all files. This usage of 2961 2782 @samp{.IGNORE} is supported only for historical compatibility. Since 2962 this affects every commandin the makefile, it is not very useful; we2783 this affects every recipe in the makefile, it is not very useful; we 2963 2784 recommend you use the more selective ways to ignore errors in specific 2964 commands. @xref{Errors, ,Errors in Commands}.2785 recipes. @xref{Errors, ,Errors in Recipes}. 2965 2786 2966 2787 @findex .LOW_RESOLUTION_TIME … … 2969 2790 If you specify prerequisites for @code{.LOW_RESOLUTION_TIME}, 2970 2791 @command{make} assumes that these files are created by commands that 2971 generate low resolution time stamps. The commands for 2972 @code{.LOW_RESOLUTION_TIME} are not meaningful. 2973 2974 The high resolution file time stamps of many modern hosts lessen the 2975 chance of @command{make} incorrectly concluding that a file is up to 2976 date. Unfortunately, these hosts provide no way to set a high 2977 resolution file time stamp, so commands like @samp{cp -p} that 2978 explicitly set a file's time stamp must discard its subsecond part. If 2979 a file is created by such a command, you should list it as a 2980 prerequisite of @code{.LOW_RESOLUTION_TIME} so that @command{make} does 2981 not mistakenly conclude that the file is out of date. For example: 2792 generate low resolution time stamps. The recipe for the 2793 @code{.LOW_RESOLUTION_TIME} target are ignored. 2794 2795 The high resolution file time stamps of many modern file systems 2796 lessen the chance of @command{make} incorrectly concluding that a file 2797 is up to date. Unfortunately, some hosts do not provide a way to set a 2798 high resolution file time stamp, so commands like @samp{cp -p} that 2799 explicitly set a file's time stamp must discard its subsecond part. 2800 If a file is created by such a command, you should list it as a 2801 prerequisite of @code{.LOW_RESOLUTION_TIME} so that @command{make} 2802 does not mistakenly conclude that the file is out of date. For 2803 example: 2982 2804 2983 2805 @example … … 3004 2826 3005 2827 If you specify prerequisites for @code{.SILENT}, then @code{make} will 3006 not print the commands to remake those particular files before executing3007 them. The commands for @code{.SILENT} are not meaningful.2828 not print the recipe used to remake those particular files before 2829 executing them. The recipe for @code{.SILENT} is ignored. 3008 2830 3009 2831 If mentioned as a target with no prerequisites, @code{.SILENT} says not 3010 to print any commands before executing them. This usage of2832 to print any recipes before executing them. This usage of 3011 2833 @samp{.SILENT} is supported only for historical compatibility. We 3012 recommend you use the more selective ways to silence specific commands.3013 @xref{Echoing, , Command Echoing}. If you want to silence all commands2834 recommend you use the more selective ways to silence specific recipes. 2835 @xref{Echoing, ,Recipe Echoing}. If you want to silence all recipes 3014 2836 for a particular run of @code{make}, use the @samp{-s} or 3015 2837 @w{@samp{--silent}} option (@pxref{Options Summary}). … … 3030 2852 of @code{make} will be run serially, even if the @samp{-j} option is 3031 2853 given. Any recursively invoked @code{make} command will still run 3032 commands in parallel (unless its makefile also contains this target).2854 recipes in parallel (unless its makefile also contains this target). 3033 2855 Any prerequisites on this target are ignored. 3034 2856 @end table … … 3051 2873 3052 2874 A rule with multiple targets is equivalent to writing many rules, each with 3053 one target, and all identical aside from that. The same commands applyto3054 all the targets, but their effectsmay vary because you can substitute the3055 actual target name into the commandusing @samp{$@@}. The rule contributes2875 one target, and all identical aside from that. The same recipe applies to 2876 all the targets, but its effect may vary because you can substitute the 2877 actual target name into the recipe using @samp{$@@}. The rule contributes 3056 2878 the same prerequisites to all the targets also. 3057 2879 … … 3060 2882 @itemize @bullet 3061 2883 @item 3062 You want just prerequisites, no commands. For example:2884 You want just prerequisites, no recipe. For example: 3063 2885 3064 2886 @example … … 3071 2893 3072 2894 @item 3073 Similar commands work for all the targets. The commands do not need2895 Similar recipes work for all the targets. The recipes do not need 3074 2896 to be absolutely identical, since the automatic variable @samp{$@@} 3075 2897 can be used to substitute the particular target to be remade into the … … 3102 2924 @end itemize 3103 2925 3104 Suppose you would like to vary the prerequisites according to the target,3105 much as the variable @samp{$@@} allows you to vary the commands.3106 You cannot do this with multiple targets in an ordinary rule, but you can3107 do it with a @dfn{static pattern rule}. 3108 @xref{Static Pattern,,Static Pattern Rules}.2926 Suppose you would like to vary the prerequisites according to the 2927 target, much as the variable @samp{$@@} allows you to vary the recipe. 2928 You cannot do this with multiple targets in an ordinary rule, but you 2929 can do it with a @dfn{static pattern rule}. @xref{Static Pattern, 2930 ,Static Pattern Rules}. 3109 2931 3110 2932 @node Multiple Rules, Static Pattern, Multiple Targets, Rules … … 3118 2940 mentioned in all the rules are merged into one list of prerequisites for 3119 2941 the target. If the target is older than any prerequisite from any rule, 3120 the commands areexecuted.3121 3122 There can only be one set of commands to be executed for a file. If3123 more than one rule gives commands for the same file, @code{make} uses 3124 the last set given and prints an error message. (As a special case, 3125 if the file's name begins with a dot, no error message is printed. 3126 This odd behavior is only for compatibility with other implementations 3127 of@code{make}@dots{} you should avoid using it). Occasionally it is3128 useful to have the same target invoke multiple commands which are2942 the recipe is executed. 2943 2944 There can only be one recipe to be executed for a file. If more than 2945 one rule gives a recipe for the same file, @code{make} uses the last 2946 one given and prints an error message. (As a special case, if the 2947 file's name begins with a dot, no error message is printed. This odd 2948 behavior is only for compatibility with other implementations of 2949 @code{make}@dots{} you should avoid using it). Occasionally it is 2950 useful to have the same target invoke multiple recipes which are 3129 2951 defined in different parts of your makefile; you can use 3130 2952 @dfn{double-colon rules} (@pxref{Double-Colon}) for this. … … 3148 2970 you wish to add the additional prerequisite intermittently. 3149 2971 3150 Another wrinkle is that the additional prerequisites could be specified with3151 a variable that you set with a command argument to @code{make} 3152 (@pxref{Overriding, ,Overriding Variables}). For example,2972 Another wrinkle is that the additional prerequisites could be 2973 specified with a variable that you set with a command line argument to 2974 @code{make} (@pxref{Overriding, ,Overriding Variables}). For example, 3153 2975 3154 2976 @example … … 3164 2986 will not. 3165 2987 3166 If none of the explicit rules for a target has commands, then @code{make}3167 searches for an applicable implicit rule to find some commands2988 If none of the explicit rules for a target has a recipe, then @code{make} 2989 searches for an applicable implicit rule to find one 3168 2990 @pxref{Implicit Rules, ,Using Implicit Rules}). 3169 2991 … … 3196 3018 @example 3197 3019 @var{targets} @dots{}: @var{target-pattern}: @var{prereq-patterns} @dots{} 3198 @var{ commands}3020 @var{recipe} 3199 3021 @dots{} 3200 3022 @end example … … 3311 3133 3312 3134 An implicit rule @emph{can} apply to any target that matches its pattern, 3313 but it @emph{does} apply only when the target has no commandsotherwise3135 but it @emph{does} apply only when the target has no recipe otherwise 3314 3136 specified, and only when the prerequisites can be found. If more than one 3315 3137 implicit rule appears applicable, only one applies; the choice depends on … … 3319 3141 that you specify in the rule. It cannot apply to any other target and it 3320 3142 invariably does apply to each of the targets specified. If two conflicting 3321 rules apply, and both have commands, that's an error.3143 rules apply, and both have recipes, that's an error. 3322 3144 3323 3145 The static pattern rule can be better than an implicit rule for these … … 3352 3174 When a target appears in multiple rules, all the rules must be the same 3353 3175 type: all ordinary, or all double-colon. If they are double-colon, each 3354 of them is independent of the others. Each double-colon rule's commands3355 areexecuted if the target is older than any prerequisites of that rule.3356 If there are no prerequisites for that rule, its commands arealways3176 of them is independent of the others. Each double-colon rule's recipe 3177 is executed if the target is older than any prerequisites of that rule. 3178 If there are no prerequisites for that rule, its recipe is always 3357 3179 executed (even if the target already exists). This can result in 3358 3180 executing none, any, or all of the double-colon rules. … … 3364 3186 The double-colon rules for a target are executed in the order they appear 3365 3187 in the makefile. However, the cases where double-colon rules really make 3366 sense are those where the order of executing the commands would not matter.3188 sense are those where the order of executing the recipes would not matter. 3367 3189 3368 3190 Double-colon rules are somewhat obscure and not often very useful; they … … 3371 3193 cases are rare. 3372 3194 3373 Each double-colon rule should specify commands; if it does not, an3195 Each double-colon rule should specify a recipe; if it does not, an 3374 3196 implicit rule will be used if one applies. 3375 3197 @xref{Implicit Rules, ,Using Implicit Rules}. … … 3516 3338 @xref{How Make Works}. 3517 3339 3518 @node Commands, Using Variables, Rules, Top3519 @chapter Writing the Commands in Rules3520 @cindex commands, how to write3521 @cindex r ule commands3522 @cindex writing r ule commands3523 3524 The commands of a rule consistof one or more shell command lines to3340 @node Recipes, Using Variables, Rules, Top 3341 @chapter Writing Recipes in Rules 3342 @cindex recipes 3343 @cindex recipes, how to write 3344 @cindex writing recipes 3345 3346 The recipe of a rule consists of one or more shell command lines to 3525 3347 be executed, one at a time, in the order they appear. Typically, the 3526 3348 result of executing these commands is that the target of the rule is 3527 3349 brought up to date. 3528 3350 3529 Users use many different shell programs, but commands in makefiles are3351 Users use many different shell programs, but recipes in makefiles are 3530 3352 always interpreted by @file{/bin/sh} unless the makefile specifies 3531 3353 otherwise. @xref{Execution, ,Command Execution}. 3532 3354 3533 3355 @menu 3534 * Command Syntax:: Commandsyntax features and pitfalls.3535 * Echoing:: How to control when commands are echoed.3536 * Execution:: How commands are executed.3537 * Parallel:: How commands can be executed in parallel.3538 * Errors:: What happens after a commandexecution error.3539 * Interrupts:: What happens when a commandis interrupted.3356 * Recipe Syntax:: Recipe syntax features and pitfalls. 3357 * Echoing:: How to control when recipes are echoed. 3358 * Execution:: How recipes are executed. 3359 * Parallel:: How recipes can be executed in parallel. 3360 * Errors:: What happens after a recipe execution error. 3361 * Interrupts:: What happens when a recipe is interrupted. 3540 3362 * Recursion:: Invoking @code{make} from makefiles. 3541 * Sequences:: Defining canned sequences of commands.3542 * Empty Commands:: Defining useful, do-nothing commands.3363 * Sequences:: Defining canned recipes. 3364 * Empty Recipes:: Defining useful, do-nothing recipes. 3543 3365 @end menu 3544 3366 3545 @node Command Syntax, Echoing, Commands, Commands3546 @section CommandSyntax3547 @cindex commandsyntax3548 @cindex syntax of commands3367 @node Recipe Syntax, Echoing, Recipes, Recipes 3368 @section Recipe Syntax 3369 @cindex recipe syntax 3370 @cindex syntax of recipe 3549 3371 3550 3372 Makefiles have the unusual property that there are really two distinct 3551 3373 syntaxes in one file. Most of the makefile uses @code{make} syntax 3552 (@pxref{Makefiles, ,Writing Makefiles}). However, commands are meant to be 3553 interpreted by the shell and so they are written using shell syntax. 3554 The @code{make} program does not try to understand shell syntax: it 3555 performs only a very few specific translations on the content of the 3556 command before handing it to the shell. 3557 3558 Each command line must start with a tab, except that the first command 3559 line may be attached to the target-and-prerequisites line with a 3560 semicolon in between. @emph{Any} line in the makefile that begins 3561 with a tab and appears in a ``rule context'' (that is, after a rule 3562 has been started until another rule or variable definition) will be 3563 considered a command line for that rule. Blank lines and lines of 3564 just comments may appear among the command lines; they are ignored. 3374 (@pxref{Makefiles, ,Writing Makefiles}). However, recipes are meant 3375 to be interpreted by the shell and so they are written using shell 3376 syntax. The @code{make} program does not try to understand shell 3377 syntax: it performs only a very few specific translations on the 3378 content of the recipe before handing it to the shell. 3379 3380 Each line in the recipe must start with a tab (or the first character 3381 in the value of the @code{.CMDPREFIX} variable; @pxref{Special 3382 Variables}), except that the first recipe line may be attached to the 3383 target-and-prerequisites line with a semicolon in between. @emph{Any} 3384 line in the makefile that begins with a tab and appears in a ``rule 3385 context'' (that is, after a rule has been started until another rule 3386 or variable definition) will be considered part of a recipe for that 3387 rule. Blank lines and lines of just comments may appear among the 3388 recipe lines; they are ignored. 3565 3389 3566 3390 Some consequences of these rules include: … … 3569 3393 @item 3570 3394 A blank line that begins with a tab is not blank: it's an empty 3571 command (@pxref{Empty Commands}).3572 3573 @cindex comments, in commands3574 @cindex commands, comments in3575 @cindex @code{#} (comments), in commands3395 recipe (@pxref{Empty Recipes}). 3396 3397 @cindex comments, in recipes 3398 @cindex recipes, comments in 3399 @cindex @code{#} (comments), in recipes 3576 3400 @item 3577 A comment in a command line is not a @code{make} comment; it will be3401 A comment in a recipe is not a @code{make} comment; it will be 3578 3402 passed to the shell as-is. Whether the shell treats it as a comment 3579 3403 or not depends on your shell. … … 3581 3405 @item 3582 3406 A variable definition in a ``rule context'' which is indented by a tab 3583 as the first character on the line, will be considered a command line, 3584 not a @code{make} variable definition, and passed to the shell. 3407 as the first character on the line, will be considered part of a 3408 recipe, not a @code{make} variable definition, and passed to the 3409 shell. 3585 3410 3586 3411 @item … … 3588 3413 etc. @pxref{Conditional Syntax, ,Syntax of Conditionals}) in a ``rule 3589 3414 context'' which is indented by a tab as the first character on the 3590 line, will be considered a command line and be passed to the shell.3415 line, will be considered part of a recipe and be passed to the shell. 3591 3416 3592 3417 @end itemize 3593 3418 3594 3419 @menu 3595 * Splitting Lines:: Breaking long commandlines for readability.3596 * Variables in Commands:: Using @code{make} variables in commands.3420 * Splitting Lines:: Breaking long recipe lines for readability. 3421 * Variables in Recipes:: Using @code{make} variables in recipes. 3597 3422 @end menu 3598 3423 3599 @node Splitting Lines, Variables in Commands, Command Syntax, CommandSyntax3600 @subsection Splitting CommandLines3601 @cindex commands, splitting3602 @cindex splitting commands3603 @cindex commands, backslash (@code{\}) in3604 @cindex commands, quoting newlines in3605 @cindex backslash (@code{\}), in commands3606 @cindex @code{\} (backslash), in commands3607 @cindex quoting newline, in commands3608 @cindex newline, quoting, in commands3609 3610 One of the few ways in which @code{make} does interpret command lines3611 ischecking for a backslash just before the newline. As in normal3612 makefile syntax, a single command can be split into multiple lines in3613 the makefile by placing a backslash before each newline. A sequence3614 of lines like this is considered a single command, and one instance of 3615 the shell will be invoked to run it.3424 @node Splitting Lines, Variables in Recipes, Recipe Syntax, Recipe Syntax 3425 @subsection Splitting Recipe Lines 3426 @cindex recipes, splitting 3427 @cindex splitting recipes 3428 @cindex recipes, backslash (@code{\}) in 3429 @cindex recipes, quoting newlines in 3430 @cindex backslash (@code{\}), in recipes 3431 @cindex @code{\} (backslash), in recipes 3432 @cindex quoting newline, in recipes 3433 @cindex newline, quoting, in recipes 3434 3435 One of the few ways in which @code{make} does interpret recipes is 3436 checking for a backslash just before the newline. As in normal 3437 makefile syntax, a single logical recipe line can be split into 3438 multiple physical lines in the makefile by placing a backslash before 3439 each newline. A sequence of lines like this is considered a single 3440 recipe line, and one instance of the shell will be invoked to run it. 3616 3441 3617 3442 However, in contrast to how they are treated in other places in a 3618 3443 makefile, backslash-newline pairs are @emph{not} removed from the 3619 command. Both the backslash and the newline characters are preserved3444 recipe. Both the backslash and the newline characters are preserved 3620 3445 and passed to the shell. How the backslash-newline is interpreted 3621 depends on your shell. If the first character of the next line 3622 after the backslash-newline is a tab, then that tab (and only that 3623 tab) is removed. Whitespace is never added to the command. 3624 3625 For example, this makefile: 3446 depends on your shell. If the first character of the next line after 3447 the backslash-newline is the recipe prefix character (a tab by 3448 default; @pxref{Special Variables}), then that character (and only 3449 that character) is removed. Whitespace is never added to the recipe. 3450 3451 For example, the recipe for the all target in this makefile: 3626 3452 3627 3453 @example … … 3662 3488 3663 3489 @noindent 3664 will run one shell with a command scriptof:3490 will invoke one shell with a command of: 3665 3491 3666 3492 @example … … 3697 3523 or even be a syntax error. One simple way of handling this is to 3698 3524 place the quoted string, or even the entire command, into a 3699 @code{make} variable then use the variable in the command. In this3525 @code{make} variable then use the variable in the recipe. In this 3700 3526 situation the newline quoting rules for makefiles will be used, and 3701 3527 the backslash-newline will be removed. If we rewrite our example … … 3722 3548 If you like, you can also use target-specific variables 3723 3549 (@pxref{Target-specific, ,Target-specific Variable Values}) to obtain 3724 a tighter correspondence between the variable and the commandthat3550 a tighter correspondence between the variable and the recipe that 3725 3551 uses it. 3726 3552 3727 @node Variables in Commands, , Splitting Lines, CommandSyntax3728 @subsection Using Variables in Commands3729 @cindex variable references in commands3730 @cindex commands, using variables in3731 3732 The other way in which @code{make} processes commands is by expanding3553 @node Variables in Recipes, , Splitting Lines, Recipe Syntax 3554 @subsection Using Variables in Recipes 3555 @cindex variable references in recipes 3556 @cindex recipes, using variables in 3557 3558 The other way in which @code{make} processes recipes is by expanding 3733 3559 any variable references in them (@pxref{Reference,Basics of Variable 3734 3560 References}). This occurs after make has finished reading all the 3735 3561 makefiles and the target is determined to be out of date; so, the 3736 commands for targets which are not rebuilt are never expanded.3737 3738 Variable and function references in commands have identical syntax and3562 recipes for targets which are not rebuilt are never expanded. 3563 3564 Variable and function references in recipes have identical syntax and 3739 3565 semantics to references elsewhere in the makefile. They also have the 3740 3566 same quoting rules: if you want a dollar sign to appear in your 3741 command, you must double it (@samp{$$}). For shells like the default3567 recipe, you must double it (@samp{$$}). For shells like the default 3742 3568 shell, that use dollar signs to introduce variables, it's important to 3743 3569 keep clear in your mind whether the variable you want to reference is … … 3777 3603 @end example 3778 3604 3779 @node Echoing, Execution, Command Syntax, Commands3780 @section CommandEchoing3781 @cindex echoing of commands3605 @node Echoing, Execution, Recipe Syntax, Recipes 3606 @section Recipe Echoing 3607 @cindex echoing of recipes 3782 3608 @cindex silent operation 3783 @cindex @code{@@} (in commands)3784 @cindex commands, echoing3785 @cindex printing of commands3786 3787 Normally @code{make} prints each command line before it is executed.3788 We call this @dfn{echoing} because it gives the appearance that you 3789 are typing the commands yourself.3609 @cindex @code{@@} (in recipes) 3610 @cindex recipes, echoing 3611 @cindex printing of recipes 3612 3613 Normally @code{make} prints each line of the recipe before it is 3614 executed. We call this @dfn{echoing} because it gives the appearance 3615 that you are typing the lines yourself. 3790 3616 3791 3617 When a line starts with @samp{@@}, the echoing of that line is suppressed. 3792 The @samp{@@} is discarded before the commandis passed to the shell.3618 The @samp{@@} is discarded before the line is passed to the shell. 3793 3619 Typically you would use this for a command whose only effect is to print 3794 3620 something, such as an @code{echo} command to indicate progress through … … 3804 3630 @cindex @code{--recon} 3805 3631 When @code{make} is given the flag @samp{-n} or @samp{--just-print} 3806 it only echoes commands, it won't execute them. @xref{Options Summary,3632 it only echoes recipes, it won't execute them. @xref{Options Summary, 3807 3633 ,Summary of Options}. In this case and only this case, even the 3808 commands starting with @samp{@@} are printed. This flag is useful for3809 finding out which commands @code{make} thinks are necessary without3634 recipe lines starting with @samp{@@} are printed. This flag is useful for 3635 finding out which recipes @code{make} thinks are necessary without 3810 3636 actually doing them. 3811 3637 … … 3815 3641 @findex .SILENT 3816 3642 The @samp{-s} or @samp{--silent} 3817 flag to @code{make} prevents all echoing, as if all commands3643 flag to @code{make} prevents all echoing, as if all recipes 3818 3644 started with @samp{@@}. A rule in the makefile for the special target 3819 3645 @code{.SILENT} without prerequisites has the same effect … … 3821 3647 @code{.SILENT} is essentially obsolete since @samp{@@} is more flexible.@refill 3822 3648 3823 @node Execution, Parallel, Echoing, Commands 3824 @section Command Execution 3825 @cindex commands, execution 3826 @cindex execution, of commands 3827 @cindex shell command, execution 3828 @vindex @code{SHELL} @r{(command execution)} 3829 3830 When it is time to execute commands to update a target, they are 3831 executed by invoking a new subshell for each command line. (In 3649 @node Execution, Parallel, Echoing, Recipes 3650 @section Recipe Execution 3651 @cindex recipe, execution 3652 @cindex execution, of recipes 3653 @vindex @code{SHELL} @r{(recipe execution)} 3654 3655 When it is time to execute recipes to update a target, they are 3656 executed by invoking a new subshell for each line of the recipe. (In 3832 3657 practice, @code{make} may take shortcuts that do not affect the 3833 3658 results.) 3834 3659 3835 3660 @cindex @code{cd} (shell command) 3836 @cindex shell variables, setting in commands3837 @cindex commands setting shell variables3661 @cindex shell variables, setting in recipes 3662 @cindex recipes setting shell variables 3838 3663 @strong{Please note:} this implies that setting shell variables and 3839 3664 invoking shell commands such as @code{cd} that set a context local to 3840 each process will not affect the following command lines.@footnote{On3665 each process will not affect the following lines in the recipe.@footnote{On 3841 3666 MS-DOS, the value of current working directory is @strong{global}, so 3842 changing it @emph{will} affect the following commandlines on those3667 changing it @emph{will} affect the following recipe lines on those 3843 3668 systems.} If you want to use @code{cd} to affect the next statement, 3844 put both statements in a single commandline. Then @code{make} will3669 put both statements in a single recipe line. Then @code{make} will 3845 3670 invoke one shell to run the entire line, and the shell will execute 3846 3671 the statements in sequence. For example: … … 3860 3685 @menu 3861 3686 * Choosing the Shell:: How @code{make} chooses the shell used 3862 to run commands.3687 to run recipes. 3863 3688 @end menu 3864 3689 … … 3882 3707 3883 3708 Furthermore, when you do set @code{SHELL} in your makefile that value 3884 is @emph{not} exported in the environment to commands that @code{make}3885 invokes. Instead, the value inherited from the user's environment, if 3886 any, is exported. You can override this behavior by explicitly3887 exp orting @code{SHELL} (@pxref{Variables/Recursion, ,Communicating3888 Variables to a Sub-@code{make}}), forcing it to be passed in the3889 environment to commands.3709 is @emph{not} exported in the environment to recipe lines that 3710 @code{make} invokes. Instead, the value inherited from the user's 3711 environment, if any, is exported. You can override this behavior by 3712 explicitly exporting @code{SHELL} (@pxref{Variables/Recursion, 3713 ,Communicating Variables to a Sub-@code{make}}), forcing it to be 3714 passed in the environment to recipe lines. 3890 3715 3891 3716 @vindex @code{MAKESHELL} @r{(MS-DOS alternative to @code{SHELL})} … … 3962 3787 directory along your @code{PATH}. 3963 3788 3964 @node Parallel, Errors, Execution, Commands3789 @node Parallel, Errors, Execution, Recipes 3965 3790 @section Parallel Execution 3966 @cindex commands, execution in parallel3791 @cindex recipes, execution in parallel 3967 3792 @cindex parallel execution 3968 3793 @cindex execution, in parallel … … 3971 3796 @cindex @code{--jobs} 3972 3797 3973 GNU @code{make} knows how to execute several commands at once.3974 Normally, @code{make} will execute only one commandat a time, waiting3798 GNU @code{make} knows how to execute several recipes at once. 3799 Normally, @code{make} will execute only one recipe at a time, waiting 3975 3800 for it to finish before executing the next. However, the @samp{-j} or 3976 @samp{--jobs} option tells @code{make} to execute many commands3801 @samp{--jobs} option tells @code{make} to execute many recipes 3977 3802 simultaneously. You can inhibit parallelism in a particular makefile 3978 3803 with the @code{.NOTPARALLEL} pseudo-target (@pxref{Special … … 3983 3808 3984 3809 If the @samp{-j} option is followed by an integer, this is the number of 3985 commands to execute at once; this is called the number of @dfn{job slots}.3810 recipes to execute at once; this is called the number of @dfn{job slots}. 3986 3811 If there is nothing looking like an integer after the @samp{-j} option, 3987 3812 there is no limit on the number of job slots. The default number of job 3988 3813 slots is one, which means serial execution (one thing at a time). 3989 3814 3990 One unpleasant consequence of running several commands simultaneously is3991 that output generated by the commands appears whenever each command3992 sends it, so messages from different commands may be interspersed.3815 One unpleasant consequence of running several recipes simultaneously is 3816 that output generated by the recipes appears whenever each recipe 3817 sends it, so messages from different recipes may be interspersed. 3993 3818 3994 3819 Another problem is that two processes cannot both take input from the 3995 same device; so to make sure that only one commandtries to take input3820 same device; so to make sure that only one recipe tries to take input 3996 3821 from the terminal at once, @code{make} will invalidate the standard 3997 input streams of all but one running command. This means that3822 input streams of all but one running recipe. This means that 3998 3823 attempting to read from standard input will usually be a fatal error (a 3999 3824 @samp{Broken pipe} signal) for most child processes if there are … … 4002 3827 @cindex standard input 4003 3828 4004 It is unpredictable which commandwill have a valid standard input stream3829 It is unpredictable which recipe will have a valid standard input stream 4005 3830 (which will come from the terminal, or wherever you redirect the standard 4006 input of @code{make}). The first commandrun will always get it first, and4007 the first commandstarted after that one finishes will get it next, and so3831 input of @code{make}). The first recipe run will always get it first, and 3832 the first recipe started after that one finishes will get it next, and so 4008 3833 on. 4009 3834 4010 3835 We will change how this aspect of @code{make} works if we find a better 4011 alternative. In the mean time, you should not rely on any commandusing3836 alternative. In the mean time, you should not rely on any recipe using 4012 3837 standard input at all if you are using the parallel execution feature; but 4013 3838 if you are not using this feature, then standard input works normally in 4014 all commands.3839 all recipes. 4015 3840 4016 3841 Finally, handling recursive @code{make} invocations raises issues. For … … 4018 3843 @ref{Options/Recursion, ,Communicating Options to a Sub-@code{make}}. 4019 3844 4020 If a commandfails (is killed by a signal or exits with a nonzero4021 status), and errors are not ignored for that command4022 (@pxref{Errors, ,Errors in Commands}),4023 the remaining commandlines to remake the same target will not be run.4024 If a commandfails and the @samp{-k} or @samp{--keep-going}3845 If a recipe fails (is killed by a signal or exits with a nonzero 3846 status), and errors are not ignored for that recipe 3847 (@pxref{Errors, ,Errors in Recipes}), 3848 the remaining recipe lines to remake the same target will not be run. 3849 If a recipe fails and the @samp{-k} or @samp{--keep-going} 4025 3850 option was not given 4026 3851 (@pxref{Options Summary, ,Summary of Options}), … … 4058 3883 By default, there is no load limit. 4059 3884 4060 @node Errors, Interrupts, Parallel, Commands4061 @section Errors in Commands4062 @cindex errors (in commands)4063 @cindex commands, errors in3885 @node Errors, Interrupts, Parallel, Recipes 3886 @section Errors in Recipes 3887 @cindex errors (in recipes) 3888 @cindex recipes, errors in 4064 3889 @cindex exit status (errors) 4065 3890 4066 After each shell command returns, @code{make} looks at its exit status.4067 If the command completed successfully, the next command line is executed 4068 in a new shell; after the last command line is finished, the rule is 4069 finished.3891 After each shell invocation returns, @code{make} looks at its exit 3892 status. If the shell completed successfully (the exit status is 3893 zero), the next line in the recipe is executed in a new shell; after 3894 the last line is finished, the rule is finished. 4070 3895 4071 3896 If there is an error (the exit status is nonzero), @code{make} gives up on 4072 3897 the current rule, and perhaps on all rules. 4073 3898 4074 Sometimes the failure of a certain commanddoes not indicate a problem.3899 Sometimes the failure of a certain recipe line does not indicate a problem. 4075 3900 For example, you may use the @code{mkdir} command to ensure that a 4076 3901 directory exists. If the directory already exists, @code{mkdir} will 4077 3902 report an error, but you probably want @code{make} to continue regardless. 4078 3903 4079 @cindex @code{-} (in commands)4080 To ignore errors in a command line, write a @samp{-} at the beginning of4081 the line's text (after the initial tab). The @samp{-} is discarded before 4082 the commandis passed to the shell for execution.3904 @cindex @code{-} (in recipes) 3905 To ignore errors in a recipe line, write a @samp{-} at the beginning 3906 of the line's text (after the initial tab). The @samp{-} is discarded 3907 before the line is passed to the shell for execution. 4083 3908 4084 3909 For example, … … 4093 3918 4094 3919 @noindent 4095 This causes @code{rm} to continue even if it is unable to remove a file. 3920 This causes @code{make} to continue even if @code{rm} is unable to 3921 remove a file. 4096 3922 4097 3923 @cindex @code{-i} … … 4099 3925 @findex .IGNORE 4100 3926 When you run @code{make} with the @samp{-i} or @samp{--ignore-errors} 4101 flag, errors are ignored in all commands of all rules. A rule in the3927 flag, errors are ignored in all recipes of all rules. A rule in the 4102 3928 makefile for the special target @code{.IGNORE} has the same effect, if 4103 3929 there are no prerequisites. These ways of ignoring errors are obsolete … … 4107 3933 @samp{-i} flag, @code{make} treats an error return just like success, 4108 3934 except that it prints out a message that tells you the status code 4109 the commandexited with, and says that the error has been ignored.3935 the shell exited with, and says that the error has been ignored. 4110 3936 4111 3937 When an error happens that @code{make} has not been told to ignore, 4112 3938 it implies that the current target cannot be correctly remade, and neither 4113 3939 can any other that depends on it either directly or indirectly. No further 4114 commands will be executed for these targets, since their preconditions3940 recipes will be executed for these targets, since their preconditions 4115 3941 have not been achieved. 4116 3942 … … 4141 3967 @cindex removal of target files 4142 3968 @cindex target, deleting on error 4143 Usually when a commandfails, if it has changed the target file at all,3969 Usually when a recipe line fails, if it has changed the target file at all, 4144 3970 the file is corrupted and cannot be used---or at least it is not 4145 3971 completely updated. Yet the file's time stamp says that it is now up to 4146 3972 date, so the next time @code{make} runs, it will not try to update that 4147 file. The situation is just the same as when the commandis killed by a3973 file. The situation is just the same as when the shell is killed by a 4148 3974 signal; @pxref{Interrupts}. So generally the right thing to do is to 4149 delete the target file if the commandfails after beginning to change3975 delete the target file if the recipe fails after beginning to change 4150 3976 the file. @code{make} will do this if @code{.DELETE_ON_ERROR} appears 4151 3977 as a target. This is almost always what you want @code{make} to do, but … … 4153 3979 request it. 4154 3980 4155 @node Interrupts, Recursion, Errors, Commands3981 @node Interrupts, Recursion, Errors, Recipes 4156 3982 @section Interrupting or Killing @code{make} 4157 3983 @cindex interrupt … … 4162 3988 @cindex killing (interruption) 4163 3989 4164 If @code{make} gets a fatal signal while a commandis executing, it may4165 delete the target file that the commandwas supposed to update. This is3990 If @code{make} gets a fatal signal while a shell is executing, it may 3991 delete the target file that the recipe was supposed to update. This is 4166 3992 done if the target file's last-modification time has changed since 4167 3993 @code{make} first checked it. … … 4188 4014 times to prevent other sorts of trouble. 4189 4015 4190 @node Recursion, Sequences, Interrupts, Commands4016 @node Recursion, Sequences, Interrupts, Recipes 4191 4017 @section Recursive Use of @code{make} 4192 4018 @cindex recursion … … 4258 4084 4259 4085 The value of this variable is the file name with which @code{make} was 4260 invoked. If this file name was @file{/bin/make}, then the commandexecuted4086 invoked. If this file name was @file{/bin/make}, then the recipe executed 4261 4087 is @samp{cd subdir && /bin/make}. If you use a special version of 4262 4088 @code{make} to run the top-level makefile, the same special version will be … … 4264 4090 @cindex @code{cd} (shell command) 4265 4091 4266 @cindex +, and commands4267 As a special feature, using the variable @code{MAKE} in the commandsof4092 @cindex +, and recipes 4093 As a special feature, using the variable @code{MAKE} in the recipe of 4268 4094 a rule alters the effects of the @samp{-t} (@samp{--touch}), @samp{-n} 4269 4095 (@samp{--just-print}), or @samp{-q} (@w{@samp{--question}}) option. 4270 4096 Using the @code{MAKE} variable has the same effect as using a @samp{+} 4271 character at the beginning of the commandline. @xref{Instead of4272 Execution, ,Instead of Executing the Commands}. This special feature4097 character at the beginning of the recipe line. @xref{Instead of 4098 Execution, ,Instead of Executing the Recipes}. This special feature 4273 4099 is only enabled if the @code{MAKE} variable appears directly in the 4274 command script: it does not apply if the @code{MAKE} variable is 4275 referenced through expansion of another variable. In the latter case 4276 you mustuse the @samp{+} token to get these special effects.@refill4100 recipe: it does not apply if the @code{MAKE} variable is referenced 4101 through expansion of another variable. In the latter case you must 4102 use the @samp{+} token to get these special effects.@refill 4277 4103 4278 4104 Consider the command @samp{make -t} in the above example. (The 4279 4105 @samp{-t} option marks targets as up to date without actually running 4280 any commands; see @ref{Instead of Execution}.) Following the usual4106 any recipes; see @ref{Instead of Execution}.) Following the usual 4281 4107 definition of @samp{-t}, a @samp{make -t} command in the example would 4282 4108 create a file named @file{subsystem} and do nothing else. What you 4283 really want it to do is run @samp{@w{cd subdir &&} @w{make -t}}; but that would4284 require executing the command, and @samp{-t} says not to execute 4285 commands.@refill4109 really want it to do is run @samp{@w{cd subdir &&} @w{make -t}}; but 4110 that would require executing the recipe, and @samp{-t} says not to 4111 execute recipes.@refill 4286 4112 @cindex @code{-t}, and recursion 4287 4113 @cindex recursion, and @code{-t} 4288 4114 @cindex @code{--touch}, and recursion 4289 4115 4290 The special feature makes this do what you want: whenever a command4116 The special feature makes this do what you want: whenever a recipe 4291 4117 line of a rule contains the variable @code{MAKE}, the flags @samp{-t}, 4292 @samp{-n} and @samp{-q} do not apply to that line. Commandlines4118 @samp{-n} and @samp{-q} do not apply to that line. Recipe lines 4293 4119 containing @code{MAKE} are executed normally despite the presence of a 4294 flag that causes most commands not to be run. The usual4120 flag that causes most recipes not to be run. The usual 4295 4121 @code{MAKEFLAGS} mechanism passes the flags to the sub-@code{make} 4296 4122 (@pxref{Options/Recursion, ,Communicating Options to a 4297 4123 Sub-@code{make}}), so your request to touch the files, or print the 4298 commands, is propagated to the subsystem.@refill4124 recipes, is propagated to the subsystem.@refill 4299 4125 4300 4126 @node Variables/Recursion, Options/Recursion, MAKE Variable, Recursion … … 4315 4141 ,Summary of Options}).@refill 4316 4142 4317 To pass down, or @dfn{export}, a variable, @code{make} adds the variable4318 and its value to the environment for running each command. The4319 sub-@code{make}, in turn, uses the environment to initialize its table 4320 of variable values. @xref{Environment, ,Variables from the 4321 Environment}.4143 To pass down, or @dfn{export}, a variable, @code{make} adds the 4144 variable and its value to the environment for running each line of the 4145 recipe. The sub-@code{make}, in turn, uses the environment to 4146 initialize its table of variable values. @xref{Environment, 4147 ,Variables from the Environment}. 4322 4148 4323 4149 Except by explicit request, @code{make} exports a variable only if it … … 4454 4280 by itself earlier (in an included makefile, perhaps). You 4455 4281 @strong{cannot} use @code{export} and @code{unexport} by themselves to 4456 have variables exported for some commands and not for others. The last4282 have variables exported for some recipes and not for others. The last 4457 4283 @code{export} or @code{unexport} directive that appears by itself 4458 4284 determines the behavior for the entire run of @code{make}.@refill … … 4465 4291 @samp{0} for the top-level @code{make}; @samp{1} for a sub-@code{make}, 4466 4292 @samp{2} for a sub-sub-@code{make}, and so on. The incrementation 4467 happens when @code{make} sets up the environment for a command.@refill4293 happens when @code{make} sets up the environment for a recipe.@refill 4468 4294 4469 4295 The main use of @code{MAKELEVEL} is to test it in a conditional … … 4534 4360 ensure that there are only @samp{N} jobs running at the same time 4535 4361 between them all. Note that any job that is marked recursive 4536 (@pxref{Instead of Execution, ,Instead of Executing the Commands})4362 (@pxref{Instead of Execution, ,Instead of Executing the Recipes}) 4537 4363 doesn't count against the total jobs (otherwise we could get @samp{N} 4538 4364 sub-@code{make}s running and have no slots left over for any real work!) … … 4670 4496 disable it. 4671 4497 4672 @node Sequences, Empty Commands, Recursion, Commands 4673 @section Defining Canned Command Sequences 4498 @node Sequences, Empty Recipes, Recursion, Recipes 4499 @section Defining Canned Recipes 4500 @cindex canned recipes 4501 @cindex recipes, canned 4674 4502 @cindex sequences of commands 4675 4503 @cindex commands, sequences of 4676 4504 4677 When the same sequence of commands is useful in making various targets, you4678 can define it as a canned sequence with the @code{define} directive, and 4679 refer to the canned sequence from the rules for those targets. The canned 4680 sequence is actually a variable, so the name must not conflict with other 4681 variable names.4682 4683 Here is an example of defining a canned sequence of commands:4505 When the same sequence of commands is useful in making various 4506 targets, you can define it as a canned sequence with the @code{define} 4507 directive, and refer to the canned sequence from the recipes for those 4508 targets. The canned sequence is actually a variable, so the name must 4509 not conflict with other variable names. 4510 4511 Here is an example of defining a canned recipes: 4684 4512 4685 4513 @example … … 4706 4534 rule's target file name. 4707 4535 4708 To use the canned sequence, substitute the variable into the commandsof a4536 To use the canned sequence, substitute the variable into the recipe of a 4709 4537 rule. You can substitute it like any other variable 4710 4538 (@pxref{Reference, ,Basics of Variable References}). … … 4730 4558 @cindex -, and @code{define} 4731 4559 @cindex +, and @code{define} 4732 In commandexecution, each line of a canned sequence is treated just as4560 In recipe execution, each line of a canned sequence is treated just as 4733 4561 if the line appeared on its own in the rule, preceded by a tab. In 4734 4562 particular, @code{make} invokes a separate subshell for each line. You 4735 4563 can use the special prefix characters that affect command lines 4736 4564 (@samp{@@}, @samp{-}, and @samp{+}) on each line of a canned sequence. 4737 @xref{ Commands, ,Writing the Commands in Rules}.4565 @xref{Recipes, ,Writing Recipes in Rules}. 4738 4566 For example, using this canned sequence: 4739 4567 … … 4748 4576 @noindent 4749 4577 @code{make} will not echo the first line, the @code{echo} command. 4750 But it @emph{will} echo the following two commandlines.4751 4752 On the other hand, prefix characters on the commandline that refers to4578 But it @emph{will} echo the following two recipe lines. 4579 4580 On the other hand, prefix characters on the recipe line that refers to 4753 4581 a canned sequence apply to every line in the sequence. So the rule: 4754 4582 … … 4759 4587 4760 4588 @noindent 4761 does not echo @emph{any} commands.4762 (@xref{Echoing, , CommandEchoing}, for a full explanation of @samp{@@}.)4763 4764 @node Empty Commands, , Sequences, Commands4765 @section Using Empty Commands4766 @cindex empty commands4767 @cindex commands, empty4768 4769 It is sometimes useful to define commands which do nothing. This is done4770 simply by giving a commandthat consists of nothing but whitespace. For4589 does not echo @emph{any} recipe lines. 4590 (@xref{Echoing, ,Recipe Echoing}, for a full explanation of @samp{@@}.) 4591 4592 @node Empty Recipes, , Sequences, Recipes 4593 @section Using Empty Recipes 4594 @cindex empty recipes 4595 @cindex recipes, empty 4596 4597 It is sometimes useful to define recipes which do nothing. This is done 4598 simply by giving a recipe that consists of nothing but whitespace. For 4771 4599 example: 4772 4600 … … 4776 4604 4777 4605 @noindent 4778 defines an empty command string for @file{target}. You could also use a4779 line beginning with a tab character to define an empty command string,4606 defines an empty recipe for @file{target}. You could also use a line 4607 beginning with a recipe prefix character to define an empty recipe, 4780 4608 but this would be confusing because such a line looks empty. 4781 4609 4782 @findex .DEFAULT@r{, and empty commands}4783 You may be wondering why you would want to define a command stringthat4610 @findex .DEFAULT@r{, and empty recipes} 4611 You may be wondering why you would want to define a recipe that 4784 4612 does nothing. The only reason this is useful is to prevent a target 4785 from getting implicit commands (from implicit rules or the4613 from getting implicit recipes (from implicit rules or the 4786 4614 @code{.DEFAULT} special target; @pxref{Implicit Rules} and 4787 4615 @pxref{Last Resort, ,Defining Last-Resort Default Rules}).@refill … … 4797 4625 @end ignore 4798 4626 4799 You may be inclined to define empty command strings for targets that are4627 You may be inclined to define empty recipes for targets that are 4800 4628 not actual files, but only exist so that their prerequisites can be 4801 4629 remade. However, this is not the best way to do that, because the … … 4803 4631 @xref{Phony Targets, ,Phony Targets}, for a better way to do this. 4804 4632 4805 @node Using Variables, Conditionals, Commands, Top4633 @node Using Variables, Conditionals, Recipes, Top 4806 4634 @chapter How to Use Variables 4807 4635 @cindex variable … … 4812 4640 A @dfn{variable} is a name defined in a makefile to represent a string 4813 4641 of text, called the variable's @dfn{value}. These values are 4814 substituted by explicit request into targets, prerequisites, commands,4642 substituted by explicit request into targets, prerequisites, recipes, 4815 4643 and other parts of the makefile. (In some other versions of @code{make}, 4816 4644 variables are called @dfn{macros}.) … … 4818 4646 4819 4647 Variables and functions in all parts of a makefile are expanded when 4820 read, except for the shell commands in rules, the right-hand sides of4821 variable definitions using @samp{=}, and the bodies of variable 4822 definitionsusing the @code{define} directive.@refill4648 read, except for in recipes, the right-hand sides of variable 4649 definitions using @samp{=}, and the bodies of variable definitions 4650 using the @code{define} directive.@refill 4823 4651 4824 4652 Variables can represent lists of file names, options to pass to compilers, … … 4864 4692 * Pattern-specific:: Target-specific variable values can be applied 4865 4693 to a group of targets that match a pattern. 4694 * Special Variables:: Variables with special meaning or behavior. 4866 4695 @end menu 4867 4696 … … 4877 4706 @samp{$@{foo@}} is a valid reference to the variable @code{foo}. This 4878 4707 special significance of @samp{$} is why you must write @samp{$$} to have 4879 the effect of a single dollar sign in a file name or command.4708 the effect of a single dollar sign in a file name or recipe. 4880 4709 4881 4710 Variable references can be used in any context: targets, prerequisites, 4882 commands, most directives, and new variable values. Here is an4711 recipes, most directives, and new variable values. Here is an 4883 4712 example of a common case, where a variable holds the names of all the 4884 4713 object files in a program: … … 4962 4791 4963 4792 @noindent 4964 will do what was intended: when @samp{CFLAGS} is expanded in a command,4793 will do what was intended: when @samp{CFLAGS} is expanded in a recipe, 4965 4794 it will expand to @samp{-Ifoo -Ibar -O}. A major disadvantage is that you 4966 4795 cannot append something on the end of a variable, as in … … 5038 4867 @noindent 5039 4868 An advantage of this use of @samp{:=} is that a typical 5040 `descend into a directory' commandthen looks like this:4869 `descend into a directory' recipe then looks like this: 5041 4870 5042 4871 @example … … 5686 5515 You may nest @code{define} directives: @code{make} will keep track of 5687 5516 nested directives and report an error if they are not all properly 5688 closed with @code{endef}. Note that lines beginning with t ab5689 characters are considered part of a command script, so any 5690 @code{define} or @code{endef} strings appearing on such a line will 5691 not beconsidered @code{make} operators.5517 closed with @code{endef}. Note that lines beginning with the recipe 5518 prefix character are considered part of a recipe, so any @code{define} 5519 or @code{endef} strings appearing on such a line will not be 5520 considered @code{make} operators. 5692 5521 5693 5522 @example … … 5704 5533 5705 5534 @need 800 5706 When used in a command script, the previous example is functionally5707 equivalentto this:5535 When used in a recipe, the previous example is functionally equivalent 5536 to this: 5708 5537 5709 5538 @example … … 5715 5544 shell commands. However, note that using two separate lines means 5716 5545 @code{make} will invoke the shell twice, running an independent subshell 5717 for each line. @xref{Execution, , CommandExecution}.5546 for each line. @xref{Execution, ,Recipe Execution}. 5718 5547 5719 5548 If you want variable definitions made with @code{define} to take … … 5752 5581 and therefore are not affected by the value in the environment.) 5753 5582 5754 When @code{make} runs a command script, variables defined in the5755 makefile are placed into the environment of that command. This allows5583 When @code{make} runs a recipe, variables defined in the 5584 makefile are placed into the environment of each shell. This allows 5756 5585 you to pass values to sub-@code{make} invocations (@pxref{Recursion, 5757 5586 ,Recursive Use of @code{make}}). By default, only variables that came … … 5789 5618 based on the target that @code{make} is currently building. As with 5790 5619 automatic variables, these values are only available within the context 5791 of a target's command script(and in other target-specific assignments).5620 of a target's recipe (and in other target-specific assignments). 5792 5621 5793 5622 Set a target-specific variable value like this: … … 5824 5653 5825 5654 Target-specific variables have the same priority as any other makefile 5826 variable. Variables provided on the command -line (and in the5655 variable. Variables provided on the command line (and in the 5827 5656 environment if the @samp{-e} option is in force) will take precedence. 5828 5657 Specifying the @code{override} directive will allow the target-specific … … 5842 5671 5843 5672 @noindent 5844 will set @code{CFLAGS} to @samp{-g} in the command script for 5845 @file{prog}, but it will also set @code{CFLAGS} to @samp{-g} in the 5846 command scripts that create @file{prog.o}, @file{foo.o}, and 5847 @file{bar.o}, and any command scripts which create their 5848 prerequisites. 5673 will set @code{CFLAGS} to @samp{-g} in the recipe for @file{prog}, but 5674 it will also set @code{CFLAGS} to @samp{-g} in the recipes that create 5675 @file{prog.o}, @file{foo.o}, and @file{bar.o}, and any recipes which 5676 create their prerequisites. 5849 5677 5850 5678 Be aware that a given prerequisite will only be built once per … … 5856 5684 ignore the target-specific values from any other targets. 5857 5685 5858 @node Pattern-specific, 5686 @node Pattern-specific, Special Variables, Target-specific, Using Variables 5859 5687 @section Pattern-specific Variable Values 5860 5688 @cindex pattern-specific variables … … 5889 5717 values, multiple @var{pattern} values create a pattern-specific variable 5890 5718 value for each pattern individually. The @var{variable-assignment} can 5891 be any valid form of assignment. Any command -line variable setting will5719 be any valid form of assignment. Any command line variable setting will 5892 5720 take precedence, unless @code{override} is specified. 5893 5721 … … 5902 5730 matching the pattern @code{%.o}. 5903 5731 5732 @node Special Variables, , Pattern-specific, Using Variables 5733 @comment node-name, next, previous, up 5734 @section Other Special Variables 5735 @cindex makefiles, and special variables 5736 @cindex special variables 5737 5738 GNU @code{make} supports some variables that have special properties. 5739 5740 @table @code 5741 5742 @vindex MAKEFILE_LIST @r{(list of parsed makefiles)} 5743 @cindex makefiles, and @code{MAKEFILE_LIST} variable 5744 @cindex including (@code{MAKEFILE_LIST} variable) 5745 @item MAKEFILE_LIST 5746 Contains the name of each makefile that is parsed by @code{make}, in 5747 the order in which it was parsed. The name is appended just 5748 before @code{make} begins to parse the makefile. Thus, if the first 5749 thing a makefile does is examine the last word in this variable, it 5750 will be the name of the current makefile. Once the current makefile 5751 has used @code{include}, however, the last word will be the 5752 just-included makefile. 5753 5754 If a makefile named @code{Makefile} has this content: 5755 5756 @example 5757 @group 5758 name1 := $(lastword $(MAKEFILE_LIST)) 5759 5760 include inc.mk 5761 5762 name2 := $(lastword $(MAKEFILE_LIST)) 5763 5764 all: 5765 @@echo name1 = $(name1) 5766 @@echo name2 = $(name2) 5767 @end group 5768 @end example 5769 5770 @noindent 5771 then you would expect to see this output: 5772 5773 @example 5774 @group 5775 name1 = Makefile 5776 name2 = inc.mk 5777 @end group 5778 @end example 5779 5780 @vindex .DEFAULT_GOAL @r{(define default goal)} 5781 @item .DEFAULT_GOAL 5782 Sets the default goal to be used if no targets were specified on the 5783 command line (@pxref{Goals, , Arguments to Specify the Goals}). The 5784 @code{.DEFAULT_GOAL} variable allows you to discover the current 5785 default goal, restart the default goal selection algorithm by clearing 5786 its value, or to explicitly set the default goal. The following 5787 example illustrates these cases: 5788 5789 @example 5790 @group 5791 # Query the default goal. 5792 ifeq ($(.DEFAULT_GOAL),) 5793 $(warning no default goal is set) 5794 endif 5795 5796 .PHONY: foo 5797 foo: ; @@echo $@@ 5798 5799 $(warning default goal is $(.DEFAULT_GOAL)) 5800 5801 # Reset the default goal. 5802 .DEFAULT_GOAL := 5803 5804 .PHONY: bar 5805 bar: ; @@echo $@@ 5806 5807 $(warning default goal is $(.DEFAULT_GOAL)) 5808 5809 # Set our own. 5810 .DEFAULT_GOAL := foo 5811 @end group 5812 @end example 5813 5814 This makefile prints: 5815 5816 @example 5817 @group 5818 no default goal is set 5819 default goal is foo 5820 default goal is bar 5821 foo 5822 @end group 5823 @end example 5824 5825 Note that assigning more than one target name to @code{.DEFAULT_GOAL} is 5826 illegal and will result in an error. 5827 5828 @vindex MAKE_RESTARTS @r{(number of times @code{make} has restarted)} 5829 @item MAKE_RESTARTS 5830 This variable is set only if this instance of @code{make} has 5831 restarted (@pxref{Remaking Makefiles, , How Makefiles Are Remade}): it 5832 will contain the number of times this instance has restarted. Note 5833 this is not the same as recursion (counted by the @code{MAKELEVEL} 5834 variable). You should not set, modify, or export this variable. 5835 5836 @vindex .CMDPREFIX @r{(change the recipe prefix character)} 5837 @item .CMDPREFIX 5838 The first character of the value of this variable is used as the 5839 character make assumes is introducing a recipe line. If the variable 5840 is empty (as it is by default) that character is the standard tab 5841 character. For example, this is a valid makefile: 5842 5843 @example 5844 @group 5845 .CMDPREFIX = > 5846 all: 5847 > @@echo Hello, world 5848 @end group 5849 @end example 5850 5851 The value of @code{.CMDPREFIX} can be changed multiple times; once set 5852 it stays in effect for all rules parsed until it is modified. 5853 5854 @vindex .VARIABLES @r{(list of variables)} 5855 @item .VARIABLES 5856 Expands to a list of the @emph{names} of all global variables defined 5857 so far. This includes variables which have empty values, as well as 5858 built-in variables (@pxref{Implicit Variables, , Variables Used by 5859 Implicit Rules}), but does not include any variables which are only 5860 defined in a target-specific context. Note that any value you assign 5861 to this variable will be ignored; it will always return its special 5862 value. 5863 5864 @c @vindex .TARGETS @r{(list of targets)} 5865 @c @item .TARGETS 5866 @c The second special variable is @code{.TARGETS}. When expanded, the 5867 @c value consists of a list of all targets defined in all makefiles read 5868 @c up until that point. Note it's not enough for a file to be simply 5869 @c mentioned in the makefile to be listed in this variable, even if it 5870 @c would match an implicit rule and become an ``implicit target''. The 5871 @c file must appear as a target, on the left-hand side of a ``:'', to be 5872 @c considered a target for the purposes of this variable. 5873 5874 @vindex .FEATURES @r{(list of supported features)} 5875 @item .FEATURES 5876 Expands to a list of special features supported by this version of 5877 @code{make}. Possible values include: 5878 5879 @table @samp 5880 5881 @item archives 5882 Supports @code{ar} (archive) files using special filename syntax. 5883 @xref{Archives, ,Using @code{make} to Update Archive Files}. 5884 5885 @item check-symlink 5886 Supports the @code{-L} (@code{--check-symlink-times}) flag. 5887 @xref{Options Summary, ,Summary of Options}. 5888 5889 @item else-if 5890 Supports ``else if'' non-nested conditionals. @xref{Conditional 5891 Syntax, ,Syntax of Conditionals}. 5892 5893 @item jobserver 5894 Supports ``job server'' enhanced parallel builds. @xref{Parallel, 5895 ,Parallel Execution}. 5896 5897 @item second-expansion 5898 Supports secondary expansion of prerequisite lists. 5899 5900 @item order-only 5901 Supports order-only prerequisites. @xref{Prerequisite Types, ,Types 5902 of Prerequisites}. 5903 5904 @item target-specific 5905 Supports target-specific and pattern-specific variable assignments. 5906 @xref{Target-specific, ,Target-specific Variable Values}. 5907 5908 @end table 5909 5910 @vindex .INCLUDE_DIRS @r{(list of include directories)} 5911 @item .INCLUDE_DIRS 5912 Expands to a list of directories that @code{make} searches for 5913 included makefiles (@pxref{Include, , Including Other Makefiles}). 5914 5915 @end table 5916 5904 5917 @node Conditionals, Functions, Using Variables, Top 5905 5918 @chapter Conditional Parts of Makefiles 5906 5919 5907 5920 @cindex conditionals 5908 A @dfn{conditional} causes part of a makefile to be obeyed or ignored5909 depending on the values of variables. Conditionals can compare the 5910 value of one variable to another, or the value of a variable to 5911 a constant string. Conditionals control what @code{make} actually 5912 ``sees'' in the makefile, so they @emph{cannot} be used to control shell 5913 co mmands at the time of execution.@refill5921 A @dfn{conditional} directive causes part of a makefile to be obeyed 5922 or ignored depending on the values of variables. Conditionals can 5923 compare the value of one variable to another, or the value of a 5924 variable to a constant string. Conditionals control what @code{make} 5925 actually ``sees'' in the makefile, so they @emph{cannot} be used to 5926 control recipes at the time of execution.@refill 5914 5927 5915 5928 @menu … … 5922 5935 @section Example of a Conditional 5923 5936 5924 The following example of a conditional tells @code{make} to use one set5925 of libraries if the @code{CC} variable is @samp{gcc}, and a different 5926 set of libraries otherwise. It works by controlling which of two 5927 command lines will be used as the command for a rule. The result is 5928 that@samp{CC=gcc} as an argument to @code{make} changes not only which5937 The following example of a conditional tells @code{make} to use one 5938 set of libraries if the @code{CC} variable is @samp{gcc}, and a 5939 different set of libraries otherwise. It works by controlling which 5940 of two recipe lines will be used for the rule. The result is that 5941 @samp{CC=gcc} as an argument to @code{make} changes not only which 5929 5942 compiler is used but also which libraries are linked. 5930 5943 … … 6153 6166 @end table 6154 6167 6155 Extra spaces are allowed and ignored at the beginning of the conditional6156 directive line, but a tab is not allowed. (If the line begins with a tab, 6157 it will be considered a command for a rule.) Aside from this, extra spaces 6158 or tabs may be inserted with no effect anywhere except within the directive 6159 name or within an argument. A comment starting with @samp{#} may appear at 6160 the end of the line.6168 Extra spaces are allowed and ignored at the beginning of the 6169 conditional directive line, but a tab is not allowed. (If the line 6170 begins with a tab, it will be considered part of a recipe for a rule.) 6171 Aside from this, extra spaces or tabs may be inserted with no effect 6172 anywhere except within the directive name or within an argument. A 6173 comment starting with @samp{#} may appear at the end of the line. 6161 6174 6162 6175 The other two directives that play a part in a conditional are @code{else} … … 6175 6188 @code{make} evaluates conditionals when it reads a makefile. 6176 6189 Consequently, you cannot use automatic variables in the tests of 6177 conditionals because they are not defined until commands are run6190 conditionals because they are not defined until recipes are run 6178 6191 (@pxref{Automatic Variables}). 6179 6192 … … 6212 6225 6213 6226 @noindent 6214 The @samp{+} prefix marks those command lines as ``recursive'' so6215 th at they will be executed despite use of the @samp{-t} flag.6227 The @samp{+} prefix marks those recipe lines as ``recursive'' so that 6228 they will be executed despite use of the @samp{-t} flag. 6216 6229 @xref{Recursion, ,Recursive Use of @code{make}}. 6217 6230 … … 6220 6233 @cindex functions 6221 6234 6222 @dfn{Functions} allow you to do text processing in the makefile to compute 6223 the files to operate on or the commands to use. You use a function in a 6224 @dfn{function call}, where you give the name of the function and some text 6225 (the @dfn{arguments}) for the function to operate on. The result of the 6226 function's processing is substituted into the makefile at the point of the 6227 call, just as a variable might be substituted. 6235 @dfn{Functions} allow you to do text processing in the makefile to 6236 compute the files to operate on or the commands to use in recipes. 6237 You use a function in a @dfn{function call}, where you give the name 6238 of the function and some text (the @dfn{arguments}) for the function 6239 to operate on. The result of the function's processing is substituted 6240 into the makefile at the point of the call, just as a variable might 6241 be substituted. 6228 6242 6229 6243 @menu … … 7238 7252 @item automatic 7239 7253 7240 if @var{variable} is an automatic variable defined for the 7241 execution of the commands for each rule 7242 (@pxref{Automatic Variables}). 7254 if @var{variable} is an automatic variable defined for the execution 7255 of the recipe for each rule (@pxref{Automatic Variables}). 7243 7256 @end table 7244 7257 … … 7330 7343 @section The @code{shell} Function 7331 7344 @findex shell 7332 @cindex command s,expansion7345 @cindex command expansion 7333 7346 @cindex backquotes 7334 7347 @cindex shell command, function for … … 7389 7402 @cindex error, stopping on 7390 7403 @cindex stopping make 7391 Generates a fatal error where the message is @var{text}. Note that the7392 error is generated whenever this function is evaluated. So, if you put 7393 it inside a command script or on the right side of a recursive variable7394 assignment, it won't be evaluated until later. The @var{text} will be7395 expanded before the error is generated.7404 Generates a fatal error where the message is @var{text}. Note that 7405 the error is generated whenever this function is evaluated. So, if 7406 you put it inside a recipe or on the right side of a recursive 7407 variable assignment, it won't be evaluated until later. The 7408 @var{text} will be expanded before the error is generated. 7396 7409 7397 7410 For example, … … 7463 7476 The exit status is one if you use the @samp{-q} flag and @code{make} 7464 7477 determines that some target is not already up to date. 7465 @xref{Instead of Execution, ,Instead of Executing the Commands}.7478 @xref{Instead of Execution, ,Instead of Executing the Recipes}. 7466 7479 @end table 7467 7480 … … 7471 7484 parts of the makefile to use. 7472 7485 * Instead of Execution:: How to use mode flags to specify what 7473 kind of thing to do with the commands7486 kind of thing to do with the recipes 7474 7487 in the makefile other than simply 7475 7488 execute them. … … 7518 7531 (@pxref{Special Variables, , Other Special Variables}). 7519 7532 7520 You can also specify a different goal or goals with command -line7533 You can also specify a different goal or goals with command line 7521 7534 arguments to @code{make}. Use the name of the goal as an argument. 7522 7535 If you specify several goals, @code{make} processes each of them in … … 7568 7581 a rule in the makefile but is not a prerequisite of the default goal. 7569 7582 7570 Another use of specifying a goal is to run the commandsassociated with7583 Another use of specifying a goal is to run the recipe associated with 7571 7584 a phony target (@pxref{Phony Targets}) or empty target (@pxref{Empty 7572 7585 Targets, ,Empty Target Files to Record Events}). Many makefiles contain … … 7640 7653 7641 7654 @node Instead of Execution, Avoiding Compilation, Goals, Running 7642 @section Instead of Executing the Commands7655 @section Instead of Executing the Recipes 7643 7656 @cindex execution, instead of 7644 @cindex commands, instead of executing7657 @cindex recipes, instead of executing 7645 7658 7646 7659 The makefile tells @code{make} how to tell whether a target is up to date, … … 7659 7672 @cindex @code{-n} 7660 7673 7661 ``No-op''. The activity is to print what commandswould be used to make7662 the targets up to date, but not actually execute them.7674 ``No-op''. The activity is to print what recipe would be used to make 7675 the targets up to date, but not actually execute it. 7663 7676 7664 7677 @item -t … … 7680 7693 7681 7694 ``Question''. The activity is to find out silently whether the targets 7682 are up to date already; but execute no commandsin either case. In other7695 are up to date already; but execute no recipe in either case. In other 7683 7696 words, neither compilation nor output will occur. 7684 7697 … … 7701 7714 @end table 7702 7715 7703 With the @samp{-n} flag, @code{make} prints the commandsthat it would7704 normally execute but does not execute them.7705 7706 With the @samp{-t} flag, @code{make} ignores the commands in the rules7716 With the @samp{-n} flag, @code{make} prints the recipe that it would 7717 normally execute but does not execute it. 7718 7719 With the @samp{-t} flag, @code{make} ignores the recipes in the rules 7707 7720 and uses (in effect) the command @code{touch} for each target that needs to 7708 7721 be remade. The @code{touch} command is also printed, unless @samp{-s} or … … 7711 7724 7712 7725 With the @samp{-q} flag, @code{make} prints nothing and executes no 7713 commands, but the exit status code it returns is zero if and only if the7726 recipes, but the exit status code it returns is zero if and only if the 7714 7727 targets to be considered are already up to date. If the exit status is 7715 7728 one, then some updating needs to be done. If @code{make} encounters an … … 7720 7733 invocation of @code{make}. 7721 7734 7722 @cindex +, and commandexecution7723 The @samp{-n}, @samp{-t}, and @samp{-q} options do not affect command7735 @cindex +, and recipe execution 7736 The @samp{-n}, @samp{-t}, and @samp{-q} options do not affect recipe 7724 7737 lines that begin with @samp{+} characters or contain the strings 7725 7738 @samp{$(MAKE)} or @samp{$@{MAKE@}}. Note that only the line containing … … 7738 7751 @item 7739 7752 Without the @samp{-n} or @samp{-q} flag, when @code{make} is actually 7740 executing commands, the @samp{-W} flag can direct @code{make} to act7741 as if some files had been modified, without actually modifying the 7742 f iles.@refill7753 executing recipes, the @samp{-W} flag can direct @code{make} to act as 7754 if some files had been modified, without actually running the recipes 7755 for those files.@refill 7743 7756 @end itemize 7744 7757 … … 7766 7779 If you anticipate the problem before changing the header file, you can 7767 7780 use the @samp{-t} flag. This flag tells @code{make} not to run the 7768 commands in the rules, but rather to mark the target up to date by7781 recipes in the rules, but rather to mark the target up to date by 7769 7782 changing its last-modification date. You would follow this procedure: 7770 7783 … … 7817 7830 The most common way to use this facility is to pass extra flags to 7818 7831 compilers. For example, in a properly written makefile, the variable 7819 @code{CFLAGS} is included in each commandthat runs the C compiler, so a7832 @code{CFLAGS} is included in each recipe that runs the C compiler, so a 7820 7833 file @file{foo.c} would be compiled something like this: 7821 7834 … … 7847 7860 makefile works by changing the variables. 7848 7861 7849 When you override a variable with a command argument, you can define either7850 a recursively-expanded variable or a simply-expanded variable. The 7851 examples shown above make a recursively-expanded variable; to make a 7852 simply-expanded variable, write @samp{:=} instead of @samp{=}. But, unless 7853 you want to include a variable reference or function call in the 7854 @emph{value} that you specify, it makes no difference which kind of 7855 variable you create.7862 When you override a variable with a command line argument, you can 7863 define either a recursively-expanded variable or a simply-expanded 7864 variable. The examples shown above make a recursively-expanded 7865 variable; to make a simply-expanded variable, write @samp{:=} instead 7866 of @samp{=}. But, unless you want to include a variable reference or 7867 function call in the @emph{value} that you specify, it makes no 7868 difference which kind of variable you create. 7856 7869 7857 7870 There is one way that the makefile can change a variable that you have … … 7866 7879 7867 7880 Normally, when an error happens in executing a shell command, @code{make} 7868 gives up immediately, returning a nonzero status. No further commands are7881 gives up immediately, returning a nonzero status. No further recipes are 7869 7882 executed for any target. The error implies that the goal cannot be 7870 7883 correctly remade, and @code{make} reports this as soon as it knows. … … 8015 8028 @itemx --ignore-errors 8016 8029 @cindex @code{--ignore-errors} 8017 Ignore all errors in commands executed to remake files.8018 @xref{Errors, ,Errors in Commands}.8030 Ignore all errors in recipes executed to remake files. 8031 @xref{Errors, ,Errors in Recipes}. 8019 8032 8020 8033 @item -I @var{dir} … … 8031 8044 @itemx --jobs[=@var{jobs}] 8032 8045 @cindex @code{--jobs} 8033 Specifies the number of jobs (commands) to run simultaneously. With no 8034 argument, @code{make} runs as many jobs simultaneously as possible. If 8035 there is more than one @samp{-j} option, the last one is effective. 8036 @xref{Parallel, ,Parallel Execution}, 8037 for more information on how commands are run. 8038 Note that this option is ignored on MS-DOS. 8046 Specifies the number of recipes (jobs) to run simultaneously. With no 8047 argument, @code{make} runs as many recipes simultaneously as possible. 8048 If there is more than one @samp{-j} option, the last one is effective. 8049 @xref{Parallel, ,Parallel Execution}, for more information on how 8050 recipes are run. Note that this option is ignored on MS-DOS. 8039 8051 8040 8052 @item -k … … 8053 8065 @itemx --max-load[=@var{load}] 8054 8066 @cindex @code{--max-load} 8055 Specifies that no new jobs (commands) should be started if there are8056 other jobs running and the load average is at least @var{load} (a8067 Specifies that no new recipes should be started if there are other 8068 recipes running and the load average is at least @var{load} (a 8057 8069 floating-point number). With no argument, removes a previous load 8058 8070 limit. @xref{Parallel, ,Parallel Execution}. … … 8078 8090 @c Extra blank line here makes the table look better. 8079 8091 8080 Print the commands that would be executed, but do not execute them.8081 @xref{Instead of Execution, ,Instead of Executing the Commands}.8092 Print the recipe that would be executed, but do not execute it. 8093 @xref{Instead of Execution, ,Instead of Executing the Recipes}. 8082 8094 8083 8095 @item -o @var{file} … … 8100 8112 @cindex predefined rules and variables, printing 8101 8113 Print the data base (rules and variable values) that results from 8102 reading the makefiles; then execute as usual or as otherwise specified. 8103 This also prints the version information given by the @samp{-v} switch 8104 (see below). To print the data base without trying to remake any files, 8105 use @w{@samp{make -qp}}. To print the data base of predefined rules and 8106 variables, use @w{@samp{make -p -f /dev/null}}. The data base output 8107 contains filename and linenumber information for command and variable 8108 definitions, so it can be a useful debugging tool in complex environments. 8114 reading the makefiles; then execute as usual or as otherwise 8115 specified. This also prints the version information given by the 8116 @samp{-v} switch (see below). To print the data base without trying 8117 to remake any files, use @w{@samp{make -qp}}. To print the data base 8118 of predefined rules and variables, use @w{@samp{make -p -f /dev/null}}. 8119 The data base output contains filename and linenumber information for 8120 recipe and variable definitions, so it can be a useful debugging tool 8121 in complex environments. 8109 8122 8110 8123 @item -q … … 8112 8125 @itemx --question 8113 8126 @cindex @code{--question} 8114 ``Question mode''. Do not run any commands, or print anything; just8127 ``Question mode''. Do not run any recipes, or print anything; just 8115 8128 return an exit status that is zero if the specified targets are already 8116 8129 up to date, one if any remaking is required, or two if an error is 8117 8130 encountered. @xref{Instead of Execution, ,Instead of Executing the 8118 Commands}.@refill8131 Recipes}.@refill 8119 8132 8120 8133 @item -r … … 8151 8164 @c Extra blank line here makes the table look better. 8152 8165 8153 Silent operation; do not print the commands as they are executed.8154 @xref{Echoing, , CommandEchoing}.8166 Silent operation; do not print the recipes as they are executed. 8167 @xref{Echoing, ,Recipe Echoing}. 8155 8168 8156 8169 @item -S … … 8175 8188 8176 8189 Touch files (mark them up to date without really changing them) 8177 instead of running their commands. This is used to pretend that the8178 commands were done, in order to fool future invocations of8179 @code{make}. @xref{Instead of Execution, ,Instead of Executing the Commands}.8190 instead of running their recipes. This is used to pretend that the 8191 recipes were done, in order to fool future invocations of 8192 @code{make}. @xref{Instead of Execution, ,Instead of Executing the Recipes}. 8180 8193 8181 8194 @item -v … … 8218 8231 @code{make}, except that the modification time is changed only in the 8219 8232 imagination of @code{make}. 8220 @xref{Instead of Execution, ,Instead of Executing the Commands}.8233 @xref{Instead of Execution, ,Instead of Executing the Recipes}. 8221 8234 8222 8235 @item --warn-undefined-variables … … 8252 8265 @end iftex 8253 8266 8254 The built-in implicit rules use several variables in their commands so8267 The built-in implicit rules use several variables in their recipes so 8255 8268 that, by changing the values of the variables, you can change the way the 8256 8269 implicit rule works. For example, the variable @code{CFLAGS} controls the … … 8274 8287 @menu 8275 8288 * Using Implicit:: How to use an existing implicit rule 8276 to get the commands for updating a file.8289 to get the recipes for updating a file. 8277 8290 * Catalogue of Rules:: A list of built-in implicit rules. 8278 8291 * Implicit Variables:: How to change what predefined rules do. 8279 8292 * Chained Rules:: How to use a chain of implicit rules. 8280 8293 * Pattern Rules:: How to define new implicit rules. 8281 * Last Resort:: How to define commands for rules which8294 * Last Resort:: How to define recipes for rules which 8282 8295 cannot find any. 8283 8296 * Suffix Rules:: The old-fashioned style of implicit rule. … … 8291 8304 @cindex rule, implicit, how to use 8292 8305 8293 To allow @code{make} to find a customary method for updating a target file,8294 all you have to do is refrain from specifying commands yourself. Either 8295 write a rule with no command lines, or don't write a rule at all. Then 8296 @code{make} will figure out which implicit rule to use based on which 8297 kind of source file exists or can be made.8306 To allow @code{make} to find a customary method for updating a target 8307 file, all you have to do is refrain from specifying recipes yourself. 8308 Either write a rule with no recipe, or don't write a rule at all. 8309 Then @code{make} will figure out which implicit rule to use based on 8310 which kind of source file exists or can be made. 8298 8311 8299 8312 For example, suppose the makefile looks like this: … … 8309 8322 This happens whether or not the file @file{foo.o} currently exists. 8310 8323 8311 If an implicit rule is found, it can supply both commandsand one or8324 If an implicit rule is found, it can supply both a recipe and one or 8312 8325 more prerequisites (the source files). You would want to write a rule 8313 for @file{foo.o} with no command linesif you need to specify additional8326 for @file{foo.o} with no recipe if you need to specify additional 8314 8327 prerequisites, such as header files, that the implicit rule cannot 8315 8328 supply. … … 8338 8351 8339 8352 In general, @code{make} searches for an implicit rule for each target, and 8340 for each double-colon rule, that has no commands. A file that is mentioned8353 for each double-colon rule, that has no recipe. A file that is mentioned 8341 8354 only as a prerequisite is considered a target whose rule specifies nothing, 8342 8355 so implicit rule search happens for it. @xref{Implicit Rule Search, ,Implicit Rule Search Algorithm}, for the … … 8361 8374 8362 8375 If you do not want an implicit rule to be used for a target that has no 8363 commands, you can give that target empty commandsby writing a semicolon8364 (@pxref{Empty Commands, ,Defining Empty Commands}).8376 recipe, you can give that target an empty recipe by writing a semicolon 8377 (@pxref{Empty Recipes, ,Defining Empty Recipes}). 8365 8378 8366 8379 @node Catalogue of Rules, Implicit Variables, Using Implicit, Implicit Rules … … 8408 8421 @pindex .c 8409 8422 @file{@var{n}.o} is made automatically from @file{@var{n}.c} with 8410 a commandof the form @samp{$(CC) -c $(CPPFLAGS) $(CFLAGS)}.@refill8423 a recipe of the form @samp{$(CC) -c $(CPPFLAGS) $(CFLAGS)}.@refill 8411 8424 8412 8425 @item Compiling C++ programs … … 8417 8430 @pindex .C 8418 8431 @file{@var{n}.o} is made automatically from @file{@var{n}.cc}, 8419 @file{@var{n}.cpp}, or @file{@var{n}.C} with a commandof the form8432 @file{@var{n}.cpp}, or @file{@var{n}.C} with a recipe of the form 8420 8433 @samp{$(CXX) -c $(CPPFLAGS) $(CXXFLAGS)}. We encourage you to use the 8421 8434 suffix @samp{.cc} for C++ source files instead of @samp{.C}.@refill … … 8426 8439 @pindex .p 8427 8440 @file{@var{n}.o} is made automatically from @file{@var{n}.p} 8428 with the command@samp{$(PC) -c $(PFLAGS)}.@refill8441 with the recipe @samp{$(PC) -c $(PFLAGS)}.@refill 8429 8442 8430 8443 @item Compiling Fortran and Ratfor programs … … 8437 8450 @file{@var{n}.o} is made automatically from @file{@var{n}.r}, 8438 8451 @file{@var{n}.F} or @file{@var{n}.f} by running the 8439 Fortran compiler. The precise commandused is as follows:@refill8452 Fortran compiler. The precise recipe used is as follows:@refill 8440 8453 8441 8454 @table @samp … … 8452 8465 @file{@var{n}.F}. This rule runs just the preprocessor to convert a 8453 8466 Ratfor or preprocessable Fortran program into a strict Fortran 8454 program. The precise commandused is as follows:@refill8467 program. The precise recipe used is as follows:@refill 8455 8468 8456 8469 @table @samp … … 8467 8480 @pindex .def 8468 8481 @pindex .mod 8469 @file{@var{n}.sym} is made from @file{@var{n}.def} with a command8482 @file{@var{n}.sym} is made from @file{@var{n}.def} with a recipe 8470 8483 of the form @samp{$(M2C) $(M2FLAGS) $(DEFFLAGS)}. @file{@var{n}.o} 8471 8484 is made from @file{@var{n}.mod}; the form is: … … 8478 8491 @pindex .s 8479 8492 @file{@var{n}.o} is made automatically from @file{@var{n}.s} by 8480 running the assembler, @code{as}. The precise commandis8493 running the assembler, @code{as}. The precise recipe is 8481 8494 @samp{$(AS) $(ASFLAGS)}.@refill 8482 8495 8483 8496 @pindex .S 8484 8497 @file{@var{n}.s} is made automatically from @file{@var{n}.S} by 8485 running the C preprocessor, @code{cpp}. The precise commandis8498 running the C preprocessor, @code{cpp}. The precise recipe is 8486 8499 @w{@samp{$(CPP) $(CPPFLAGS)}}. 8487 8500 … … 8492 8505 @file{@var{n}} is made automatically from @file{@var{n}.o} by running 8493 8506 the linker (usually called @code{ld}) via the C compiler. The precise 8494 commandused is @w{@samp{$(CC) $(LDFLAGS) @var{n}.o $(LOADLIBES) $(LDLIBS)}}.8507 recipe used is @w{@samp{$(CC) $(LDFLAGS) @var{n}.o $(LOADLIBES) $(LDLIBS)}}. 8495 8508 8496 8509 This rule does the right thing for a simple program with only one … … 8521 8534 In more complicated cases, such as when there is no object file whose 8522 8535 name derives from the executable file name, you must write an explicit 8523 commandfor linking.8536 recipe for linking. 8524 8537 8525 8538 Each kind of file automatically made into @samp{.o} object files will … … 8536 8549 @pindex .y 8537 8550 @file{@var{n}.c} is made automatically from @file{@var{n}.y} by 8538 running Yacc with the command@samp{$(YACC) $(YFLAGS)}.8551 running Yacc with the recipe @samp{$(YACC) $(YFLAGS)}. 8539 8552 8540 8553 @item Lex for C programs … … 8543 8556 @pindex .l 8544 8557 @file{@var{n}.c} is made automatically from @file{@var{n}.l} by 8545 running Lex. The actual commandis @samp{$(LEX) $(LFLAGS)}.8558 running Lex. The actual recipe is @samp{$(LEX) $(LFLAGS)}. 8546 8559 8547 8560 @item Lex for Ratfor programs 8548 8561 @file{@var{n}.r} is made automatically from @file{@var{n}.l} by 8549 running Lex. The actual commandis @samp{$(LEX) $(LFLAGS)}.8562 running Lex. The actual recipe is @samp{$(LEX) $(LFLAGS)}. 8550 8563 8551 8564 The convention of using the same suffix @samp{.l} for all Lex files … … 8572 8585 @pindex .ln 8573 8586 @file{@var{n}.ln} is made from @file{@var{n}.c} by running @code{lint}. 8574 The precise commandis @w{@samp{$(LINT) $(LINTFLAGS) $(CPPFLAGS) -i}}.8575 The same commandis used on the C code produced from8587 The precise recipe is @w{@samp{$(LINT) $(LINTFLAGS) $(CPPFLAGS) -i}}. 8588 The same recipe is used on the C code produced from 8576 8589 @file{@var{n}.y} or @file{@var{n}.l}.@refill 8577 8590 … … 8589 8602 @pindex .w 8590 8603 @pindex .ch 8591 @file{@var{n}.dvi} is made from @file{@var{n}.tex} with the command8604 @file{@var{n}.dvi} is made from @file{@var{n}.tex} with the recipe 8592 8605 @samp{$(TEX)}. @file{@var{n}.tex} is made from @file{@var{n}.web} with 8593 8606 @samp{$(WEAVE)}, or from @file{@var{n}.w} (and from @file{@var{n}.ch} if … … 8607 8620 @pindex .txinfo 8608 8621 @file{@var{n}.dvi} is made from @file{@var{n}.texinfo}, 8609 @file{@var{n}.texi}, or @file{@var{n}.txinfo}, with the command8622 @file{@var{n}.texi}, or @file{@var{n}.txinfo}, with the recipe 8610 8623 @w{@samp{$(TEXI2DVI) $(TEXI2DVI_FLAGS)}}. @file{@var{n}.info} is made from 8611 8624 @file{@var{n}.texinfo}, @file{@var{n}.texi}, or @file{@var{n}.txinfo}, with 8612 the command@w{@samp{$(MAKEINFO) $(MAKEINFO_FLAGS)}}.8625 the recipe @w{@samp{$(MAKEINFO) $(MAKEINFO_FLAGS)}}. 8613 8626 8614 8627 @item RCS … … 8618 8631 Any file @file{@var{n}} is extracted if necessary from an RCS file 8619 8632 named either @file{@var{n},v} or @file{RCS/@var{n},v}. The precise 8620 commandused is @w{@samp{$(CO) $(COFLAGS)}}. @file{@var{n}} will not be8633 recipe used is @w{@samp{$(CO) $(COFLAGS)}}. @file{@var{n}} will not be 8621 8634 extracted from RCS if it already exists, even if the RCS file is 8622 8635 newer. The rules for RCS are terminal … … 8631 8644 Any file @file{@var{n}} is extracted if necessary from an SCCS file 8632 8645 named either @file{s.@var{n}} or @file{SCCS/s.@var{n}}. The precise 8633 commandused is @w{@samp{$(GET) $(GFLAGS)}}. The rules for SCCS are8646 recipe used is @w{@samp{$(GET) $(GFLAGS)}}. The rules for SCCS are 8634 8647 terminal (@pxref{Match-Anything Rules, ,Match-Anything Pattern Rules}), 8635 8648 so SCCS files cannot be generated from another source; they must … … 8652 8665 above, which are documented in the following section. 8653 8666 8654 However, the commands in built-in implicit rules actually use8667 However, the recipes in built-in implicit rules actually use 8655 8668 variables such as @code{COMPILE.c}, @code{LINK.p}, and 8656 @code{PREPROCESS.S}, whose values contain the commands listed above.8669 @code{PREPROCESS.S}, whose values contain the recipes listed above. 8657 8670 8658 8671 @code{make} follows the convention that the rule to compile a … … 8679 8692 @cindex flags for compilers 8680 8693 8681 The commands in built-in implicit rules make liberal use of certain8694 The recipes in built-in implicit rules make liberal use of certain 8682 8695 predefined variables. You can alter the values of these variables in 8683 8696 the makefile, with arguments to @code{make}, or in the environment to … … 8686 8699 the @samp{-R} or @samp{--no-builtin-variables} option. 8687 8700 8688 For example, the commandused to compile a C source file actually says8701 For example, the recipe used to compile a C source file actually says 8689 8702 @samp{$(CC) -c $(CFLAGS) $(CPPFLAGS)}. The default values of the variables 8690 8703 used are @samp{cc} and nothing, resulting in the command @samp{cc -c}. By … … 8705 8718 The following tables describe of some of the more commonly-used predefined 8706 8719 variables. This list is not exhaustive, and the default values shown here may 8707 not be what are selected by @code{make}for your environment. To see the8720 not be what @code{make} selects for your environment. To see the 8708 8721 complete list of predefined variables for your instance of GNU @code{make} you 8709 8722 can run @samp{make -p} in a directory with no makefiles. … … 8999 9012 * Pattern Examples:: Examples of pattern rules. 9000 9013 * Automatic Variables:: How to use automatic variables in the 9001 commands of implicit rules.9014 recipes of implicit rules. 9002 9015 * Pattern Match:: How patterns match. 9003 9016 * Match-Anything Rules:: Precautions you should take prior to … … 9036 9049 9037 9050 @example 9038 %.o : %.c ; @var{ command}@dots{}9051 %.o : %.c ; @var{recipe}@dots{} 9039 9052 @end example 9040 9053 … … 9054 9067 9055 9068 @c !!! The end of of this paragraph should be rewritten. --bob 9056 Pattern rules may have more than one target. Unlike normal rules, this 9057 does not act as many different rules with the same prerequisites and 9058 commands. If a pattern rule has multiple targets, @code{make} knows that 9059 the rule's commands are responsible for making all of the targets. The 9060 commands are executed only once to make all the targets. When searching 9061 for a pattern rule to match a target, the target patterns of a rule other 9062 than the one that matches the target in need of a rule are incidental: 9063 @code{make} worries only about giving commands and prerequisites to the file 9064 presently in question. However, when this file's commands are run, the 9065 other targets are marked as having been updated themselves. 9069 Pattern rules may have more than one target. Unlike normal rules, 9070 this does not act as many different rules with the same prerequisites 9071 and recipe. If a pattern rule has multiple targets, @code{make} knows 9072 that the rule's recipe is responsible for making all of the targets. 9073 The recipe is executed only once to make all the targets. When 9074 searching for a pattern rule to match a target, the target patterns of 9075 a rule other than the one that matches the target in need of a rule 9076 are incidental: @code{make} worries only about giving a recipe and 9077 prerequisites to the file presently in question. However, when this 9078 file's recipe is run, the other targets are marked as having been 9079 updated themselves. 9066 9080 @cindex multiple targets, in pattern rule 9067 9081 @cindex target, multiple in pattern rule … … 9091 9105 @noindent 9092 9106 defines a rule that can make any file @file{@var{x}.o} from 9093 @file{@var{x}.c}. The commanduses the automatic variables @samp{$@@} and9107 @file{@var{x}.c}. The recipe uses the automatic variables @samp{$@@} and 9094 9108 @samp{$<} to substitute the names of the target file and the source file 9095 9109 in each case where the rule applies (@pxref{Automatic Variables}).@refill … … 9122 9136 @noindent 9123 9137 @c The following paragraph is rewritten to avoid overfull hboxes 9124 This tells @code{make} that the command@samp{bison -d @var{x}.y} will9138 This tells @code{make} that the recipe @samp{bison -d @var{x}.y} will 9125 9139 make both @file{@var{x}.tab.c} and @file{@var{x}.tab.h}. If the file 9126 9140 @file{foo} depends on the files @file{parse.tab.o} and @file{scan.o} 9127 9141 and the file @file{scan.o} depends on the file @file{parse.tab.h}, 9128 when @file{parse.y} is changed, the command@samp{bison -d parse.y}9142 when @file{parse.y} is changed, the recipe @samp{bison -d parse.y} 9129 9143 will be executed only once, and the prerequisites of both 9130 9144 @file{parse.tab.o} and @file{scan.o} will be satisfied. (Presumably … … 9142 9156 Suppose you are writing a pattern rule to compile a @samp{.c} file into a 9143 9157 @samp{.o} file: how do you write the @samp{cc} command so that it operates 9144 on the right source file name? You cannot write the name in the command,9158 on the right source file name? You cannot write the name in the recipe, 9145 9159 because the name is different each time the implicit rule is applied. 9146 9160 … … 9155 9169 It's very important that you recognize the limited scope in which 9156 9170 automatic variable values are available: they only have values within 9157 the command script. In particular, you cannot use them anywhere9171 the recipe. In particular, you cannot use them anywhere 9158 9172 within the target list of a rule; they have no value there and will 9159 9173 expand to the empty string. Also, they cannot be accessed directly … … 9174 9188 rule that has multiple targets (@pxref{Pattern Intro, ,Introduction to 9175 9189 Pattern Rules}), @samp{$@@} is the name of whichever target caused the 9176 rule's commandsto be run.9190 rule's recipe to be run. 9177 9191 9178 9192 @vindex $% … … 9187 9201 @vindex < @r{(automatic variable)} 9188 9202 @item $< 9189 The name of the first prerequisite. If the target got its commandsfrom9203 The name of the first prerequisite. If the target got its recipe from 9190 9204 an implicit rule, this will be the first prerequisite added by the 9191 9205 implicit rule (@pxref{Implicit Rules}). … … 9196 9210 The names of all the prerequisites that are newer than the target, with 9197 9211 spaces between them. For prerequisites which are archive members, only 9198 the member namedis used (@pxref{Archives}).9212 the named member is used (@pxref{Archives}). 9199 9213 @cindex prerequisites, list of changed 9200 9214 @cindex list of changed prerequisites … … 9204 9218 @item $^ 9205 9219 The names of all the prerequisites, with spaces between them. For 9206 prerequisites which are archive members, only the member namedis used9220 prerequisites which are archive members, only the named member is used 9207 9221 (@pxref{Archives}). A target has only one prerequisite on each other file 9208 9222 it depends on, no matter how many times each file is listed as a … … 9453 9467 Special built-in dummy pattern rules are provided solely to recognize 9454 9468 certain file names so that nonterminal match-anything rules will not be 9455 considered. These dummy rules have no prerequisites and no commands, and9469 considered. These dummy rules have no prerequisites and no recipes, and 9456 9470 they are ignored for all other purposes. For example, the built-in 9457 9471 implicit rule … … 9474 9488 You can override a built-in implicit rule (or one you have defined 9475 9489 yourself) by defining a new pattern rule with the same target and 9476 prerequisites, but different commands. When the new rule is defined, the9490 prerequisites, but a different recipe. When the new rule is defined, the 9477 9491 built-in one is replaced. The new rule's position in the sequence of 9478 9492 implicit rules is determined by where you write the new rule. 9479 9493 9480 9494 You can cancel a built-in implicit rule by defining a pattern rule with the 9481 same target and prerequisites, but no commands. For example, the following9495 same target and prerequisites, but no recipe. For example, the following 9482 9496 would cancel the rule that runs the assembler: 9483 9497 … … 9495 9509 Rules}). This is just like any other pattern rule; the only thing 9496 9510 special about it is that it will match any target. So such a rule's 9497 commands are used for all targets and prerequisites that have no commands 9511 recipe is used for all targets and prerequisites that have no recipe 9498 9512 of their own and for which no other implicit rule applies. 9499 9513 … … 9511 9525 9512 9526 @findex .DEFAULT 9513 You can instead define commandsto be used for targets for which there9514 are no rules at all, even ones which don't specify commands. You do9527 You can instead define a recipe to be used for targets for which there 9528 are no rules at all, even ones which don't specify recipes. You do 9515 9529 this by writing a rule for the target @code{.DEFAULT}. Such a rule's 9516 commands areused for all prerequisites which do not appear as targets in9530 recipe is used for all prerequisites which do not appear as targets in 9517 9531 any explicit rule, and for which no implicit rule applies. Naturally, 9518 9532 there is no @code{.DEFAULT} rule unless you write one. 9519 9533 9520 If you use @code{.DEFAULT} with no commandsor prerequisites:9534 If you use @code{.DEFAULT} with no recipe or prerequisites: 9521 9535 9522 9536 @example … … 9525 9539 9526 9540 @noindent 9527 the commands previously stored for @code{.DEFAULT} are cleared.9528 Then@code{make} acts as if you had never defined @code{.DEFAULT} at all.9529 9530 If you do not want a target to get the commandsfrom a match-anything9531 pattern rule or @code{.DEFAULT}, but you also do not want any commands9532 to be run for the target, you can give it empty commands (@pxref{Empty9533 Commands, ,Defining Empty Commands}).@refill9541 the recipe previously stored for @code{.DEFAULT} is cleared. Then 9542 @code{make} acts as if you had never defined @code{.DEFAULT} at all. 9543 9544 If you do not want a target to get the recipe from a match-anything 9545 pattern rule or @code{.DEFAULT}, but you also do not want any recipe 9546 to be run for the target, you can give it an empty recipe 9547 (@pxref{Empty Recipes, ,Defining Empty Recipes}).@refill 9534 9548 9535 9549 You can use a last-resort rule to override part of another makefile. … … 9599 9613 @samp{.o} files using this pattern rule also depend on @file{foo.h}. 9600 9614 9601 Suffix rules with no commandsare also meaningless. They do not remove9602 previous rules as do pattern rules with no commands(@pxref{Canceling9603 Rules, , Canceling Implicit Rules}). They simply enter the suffix or pair of suffixes concatenated as9604 a target in the data base.@refill9615 Suffix rules with no recipe are also meaningless. They do not remove 9616 previous rules as do pattern rules with no recipe (@pxref{Canceling 9617 Rules, , Canceling Implicit Rules}). They simply enter the suffix or 9618 pair of suffixes concatenated as a target in the data base.@refill 9605 9619 9606 9620 @findex .SUFFIXES … … 9645 9659 Here is the procedure @code{make} uses for searching for an implicit rule 9646 9660 for a target @var{t}. This procedure is followed for each double-colon 9647 rule with no commands, for each target of ordinary rules none of which have9648 commands, and for each prerequisite that is not the target of any rule. It9661 rule with no recipe, for each target of ordinary rules none of which have 9662 a recipe, and for each prerequisite that is not the target of any rule. It 9649 9663 is also followed recursively for prerequisites that come from implicit 9650 9664 rules, in the search for a chain of rules. … … 9675 9689 9676 9690 @item 9677 Remove from the list all rules with no commands.9691 Remove from the list all rules with no recipe. 9678 9692 9679 9693 @item … … 9725 9739 @item 9726 9740 If no implicit rule applies, the rule for @code{.DEFAULT}, if any, 9727 applies. In that case, give @var{t} the same commandsthat9728 @code{.DEFAULT} has. Otherwise, there are no commandsfor @var{t}.9741 applies. In that case, give @var{t} the same recipe that 9742 @code{.DEFAULT} has. Otherwise, there is no recipe for @var{t}. 9729 9743 @end enumerate 9730 9744 9731 Once a rule that applies has been found, for each target pattern of the9732 rule other than the one that matched @var{t} or @var{n}, the @samp{%} in 9733 the pattern is replaced with @var{s} and the resultant file name is stored 9734 until the commands to remake the target file @var{t} are executed. After 9735 these commands are executed, each of these stored file names are entered 9736 into the data base and marked as having been updated and having the same 9737 update status as the file @var{t}.9738 9739 When the commands of a pattern rule are executed for @var{t}, the automatic9740 variables are set corresponding to the target and prerequisites. 9741 @xref{Automatic Variables}.9745 Once a rule that applies has been found, for each target pattern of 9746 the rule other than the one that matched @var{t} or @var{n}, the 9747 @samp{%} in the pattern is replaced with @var{s} and the resultant 9748 file name is stored until the recipe to remake the target file @var{t} 9749 is executed. After the recipe is executed, each of these stored file 9750 names are entered into the data base and marked as having been updated 9751 and having the same update status as the file @var{t}. 9752 9753 When the recipe of a pattern rule is executed for @var{t}, the 9754 automatic variables are set corresponding to the target and 9755 prerequisites. @xref{Automatic Variables}. 9742 9756 9743 9757 @node Archives, Features, Implicit Rules, Top … … 9771 9785 @noindent 9772 9786 This construct is available only in targets and prerequisites, not in 9773 commands! Most programs that you might use in commands do not support this 9774 syntax and cannot act directly on archive members. Only @code{ar} and 9775 other programs specifically designed to operate on archives can do so. 9776 Therefore, valid commands to update an archive member target probably must 9777 use @code{ar}. For example, this rule says to create a member 9778 @file{hack.o} in archive @file{foolib} by copying the file @file{hack.o}: 9787 recipes! Most programs that you might use in recipes do not support 9788 this syntax and cannot act directly on archive members. Only 9789 @code{ar} and other programs specifically designed to operate on 9790 archives can do so. Therefore, valid recipes to update an archive 9791 member target probably must use @code{ar}. For example, this rule 9792 says to create a member @file{hack.o} in archive @file{foolib} by 9793 copying the file @file{hack.o}: 9779 9794 9780 9795 @example … … 9829 9844 @samp{(} and @samp{)} from being interpreted specially by the shell) in 9830 9845 the presence of a file @file{bar.c} is enough to cause the following 9831 commandsto be run, even without a makefile:9846 recipe to be run, even without a makefile: 9832 9847 9833 9848 @example … … 9847 9862 it may be useful in a makefile to pretend that it does. If you write an 9848 9863 archive member target @file{foo.a(dir/file.o)}, @code{make} will perform 9849 automatic updating with this command:9864 automatic updating with this recipe: 9850 9865 9851 9866 @example … … 9912 9927 9913 9928 Possibly a future version of @code{make} will provide a mechanism to 9914 circumvent this problem by serializing all commands that operate on the9929 circumvent this problem by serializing all recipes that operate on the 9915 9930 same archive file. But for the time being, you must either write your 9916 9931 makefiles to avoid this problem in some other way, or not use @code{-j}. … … 10018 10033 10019 10034 @item 10020 The command -line options @samp{-b} and @samp{-m}, accepted and10035 The command line options @samp{-b} and @samp{-m}, accepted and 10021 10036 ignored. In System V @code{make}, these options actually do something. 10022 10037 … … 10035 10050 @item 10036 10051 The arrangement of lines and backslash-newline combinations in 10037 commands is retained when the commands are printed, so they appear as10052 recipes is retained when the recipes are printed, so they appear as 10038 10053 they do in the makefile, except for the stripping of initial 10039 10054 whitespace. … … 10069 10084 The ``what if'' flag (@samp{-W} in GNU @code{make}) was (as far as we know) 10070 10085 invented by Andrew Hume in @code{mk}. 10071 @xref{Instead of Execution, ,Instead of Executing the Commands}.10086 @xref{Instead of Execution, ,Instead of Executing the Recipes}. 10072 10087 10073 10088 @item 10074 10089 The concept of doing several things at once (parallelism) exists in 10075 10090 many incarnations of @code{make} and similar programs, though not in the 10076 System V or BSD implementations. @xref{Execution, , CommandExecution}.10091 System V or BSD implementations. @xref{Execution, ,Recipe Execution}. 10077 10092 10078 10093 @item … … 10086 10101 10087 10102 @item 10088 The special significance of @samp{+} characters preceding command lines 10089 (@pxref{Instead of Execution, ,Instead of Executing the Commands}) is 10090 mandated by 10091 @cite{IEEE Standard 1003.2-1992} (POSIX.2). 10103 The special significance of @samp{+} characters preceding recipe lines 10104 (@pxref{Instead of Execution, ,Instead of Executing the Recipes}) is 10105 mandated by @cite{IEEE Standard 1003.2-1992} (POSIX.2). 10092 10106 10093 10107 @item … … 10123 10137 10124 10138 @item 10125 Pass command -line variable assignments automatically through the10139 Pass command line variable assignments automatically through the 10126 10140 variable @code{MAKE} to recursive @code{make} invocations. 10127 10141 @xref{Recursion, ,Recursive Use of @code{make}}. … … 10255 10269 10256 10270 @item 10257 In System V and 4.3 BSD @code{make}, files found by @code{VPATH} search 10258 (@pxref{Directory Search, ,Searching Directories for Prerequisites}) have their names changed inside command 10259 strings. We feel it is much cleaner to always use automatic variables 10260 and thus make this feature obsolete.@refill 10271 In System V and 4.3 BSD @code{make}, files found by @code{VPATH} 10272 search (@pxref{Directory Search, ,Searching Directories for 10273 Prerequisites}) have their names changed inside recipes. We feel it 10274 is much cleaner to always use automatic variables and thus make this 10275 feature obsolete.@refill 10261 10276 10262 10277 @item … … 10269 10284 10270 10285 @item 10271 In some Unix @code{make}s, implicit rule search 10272 (@pxref{Implicit Rules, ,Using Implicit Rules}) is apparently done for 10273 @emph{all} targets, not just those without commands. This means you can10286 In some Unix @code{make}s, implicit rule search (@pxref{Implicit 10287 Rules, ,Using Implicit Rules}) is apparently done for @emph{all} 10288 targets, not just those without recipes. This means you can 10274 10289 do:@refill 10275 10290 … … 10295 10310 10296 10311 @item 10297 It appears that in SVR4 @code{make}, a suffix rule can be specified with10298 no commands, and it is treated as if it had empty commands 10299 (@pxref{Empty Commands}). For example:10312 It appears that in SVR4 @code{make}, a suffix rule can be specified 10313 with no recipe, and it is treated as if it had an empty recipe 10314 (@pxref{Empty Recipes}). For example: 10300 10315 10301 10316 @example … … 10306 10321 will override the built-in @file{.c.a} suffix rule. 10307 10322 10308 We feel that it is cleaner for a rule without commandsto always simply10323 We feel that it is cleaner for a rule without a recipe to always simply 10309 10324 add to the prerequisite list for the target. The above example can be 10310 10325 easily rewritten to get the desired behavior in GNU @code{make}: … … 10319 10334 Program}). The @samp{-e} flag tells the shell to exit as soon as any 10320 10335 program it runs returns a nonzero status. We feel it is cleaner to 10321 write each shell command line to stand on its own and not require this10336 write each line of the recipe to stand on its own and not require this 10322 10337 special treatment. 10323 10338 @end itemize … … 10571 10586 newer than the target, with spaces between them. 10572 10587 For prerequisites which are archive members, only 10573 the member namedis used (@pxref{Archives}).10588 the named member is used (@pxref{Archives}). 10574 10589 10575 10590 @item $^ 10576 10591 @itemx $+ 10577 10592 The names of all the prerequisites, with spaces between them. For 10578 prerequisites which are archive members, only the member namedis used10593 prerequisites which are archive members, only the named member is used 10579 10594 (@pxref{Archives}). The value of @code{$^} omits duplicate 10580 10595 prerequisites, while @code{$+} retains them and preserves their order. … … 10630 10645 The name of the system default command interpreter, usually @file{/bin/sh}. 10631 10646 You can set @code{SHELL} in the makefile to change the shell used to run 10632 commands. @xref{Execution, ,CommandExecution}. The @code{SHELL}10647 recipes. @xref{Execution, ,Recipe Execution}. The @code{SHELL} 10633 10648 variable is handled specially when importing from and exporting to the 10634 10649 environment. @xref{Choosing the Shell}. … … 10642 10657 @item MAKE 10643 10658 10644 The name with which @code{make} was invoked. 10645 Using this variable in commands has special meaning. 10646 @ xref{MAKE Variable, ,How the @code{MAKE} Variable Works}.10659 The name with which @code{make} was invoked. Using this variable in 10660 recipes has special meaning. @xref{MAKE Variable, ,How the 10661 @code{MAKE} Variable Works}. 10647 10662 10648 10663 @item MAKELEVEL … … 10657 10672 @xref{Options/Recursion, ,Communicating Options to a Sub-@code{make}}. 10658 10673 10659 It is @emph{never} appropriate to use @code{MAKEFLAGS} directly on a10660 commandline: its contents may not be quoted correctly for use in the10674 It is @emph{never} appropriate to use @code{MAKEFLAGS} directly in a 10675 recipe line: its contents may not be quoted correctly for use in the 10661 10676 shell. Always allow recursive @code{make}'s to obtain these values 10662 10677 through the environment from its parent. … … 10694 10709 10695 10710 Sometimes @code{make} errors are not fatal, especially in the presence 10696 of a @code{-} prefix on a command script line, or the @code{-k} command10697 lineoption. Errors that are fatal are prefixed with the string10711 of a @code{-} prefix on a recipe line, or the @code{-k} command line 10712 option. Errors that are fatal are prefixed with the string 10698 10713 @code{***}. 10699 10714 … … 10709 10724 @itemx [@var{foo}] @var{signal description} 10710 10725 These errors are not really @code{make} errors at all. They mean that a 10711 program that @code{make} invoked as part of a command scriptreturned a10726 program that @code{make} invoked as part of a recipe returned a 10712 10727 non-0 error code (@samp{Error @var{NN}}), which @code{make} interprets 10713 10728 as failure, or it exited in some other abnormal fashion (with a 10714 signal of some type). @xref{Errors, ,Errors in Commands}.10729 signal of some type). @xref{Errors, ,Errors in Recipes}. 10715 10730 10716 10731 If no @code{***} is attached to the message, then the subprocess failed … … 10720 10735 @item missing separator. Stop. 10721 10736 @itemx missing separator (did you mean TAB instead of 8 spaces?). Stop. 10722 This means that @code{make} could not understand much of anything about 10723 the command line it just read. GNU @code{make} looks for various kinds 10724 of separators (@code{:}, @code{=}, TAB characters, etc.) to help it 10725 decide what kind of commandline it's seeing. This means it couldn't 10726 find a valid one. 10727 10728 One of the most common reasons for this message is that you (or perhaps 10729 your oh-so-helpful editor, as is the case with many MS-Windows editors) 10730 have attempted to indent your command scripts with spaces instead of a 10731 TAB character. In this case, @code{make} will use the second form of 10732 the error above. Remember that every line in the command script must 10733 begin with a TAB character. Eight spaces do not count. @xref{Rule 10734 Syntax}. 10735 10736 @item commands commence before first target. Stop. 10737 @itemx missing rule before commands. Stop. 10738 This means the first thing in the makefile seems to be part of a command 10739 script: it begins with a TAB character and doesn't appear to be a legal 10740 @code{make} command (such as a variable assignment). Command scripts 10741 must always be associated with a target. 10737 This means that @code{make} could not understand much of anything 10738 about the makefile line it just read. GNU @code{make} looks for 10739 various separators (@code{:}, @code{=}, recipe prefix characters, 10740 etc.) to indicate what kind of line it's parsing. This message means 10741 it couldn't find a valid one. 10742 10743 One of the most common reasons for this message is that you (or 10744 perhaps your oh-so-helpful editor, as is the case with many MS-Windows 10745 editors) have attempted to indent your recipe lines with spaces 10746 instead of a tab character. In this case, @code{make} will use the 10747 second form of the error above. Remember that every line in the 10748 recipe must begin with a tab character (unless you set 10749 @code{.CMDPREFIX}; @pxref{Special Variables}). Eight spaces do not 10750 count. @xref{Rule Syntax}. 10751 10752 @item recipe commences before first target. Stop. 10753 @itemx missing rule before recipe. Stop. 10754 This means the first thing in the makefile seems to be part of a 10755 recipe: it begins with a recipe prefix character and doesn't appear to 10756 be a legal @code{make} directive (such as a variable assignment). 10757 Recipes must always be associated with a target. 10742 10758 10743 10759 The second form is generated if the line has a semicolon as the first … … 10771 10787 (second form) was not found. 10772 10788 10773 @item warning: overriding commandsfor target `@var{xxx}'10774 @itemx warning: ignoring old commandsfor target `@var{xxx}'10775 GNU @code{make} allows commands to be specified only onceper target10776 (except for double-colon rules). If you give commandsfor a target10777 which already has been defined to have commands, this warning is issued10778 and the second set of commands will overwrite the first set. 10779 @xref{Multiple Rules,,Multiple Rules for One Target}.10789 @item warning: overriding recipe for target `@var{xxx}' 10790 @itemx warning: ignoring old recipe for target `@var{xxx}' 10791 GNU @code{make} allows only one recipe to be specified per target 10792 (except for double-colon rules). If you give a recipe for a target 10793 which already has been defined to have one, this warning is issued and 10794 the second recipe will overwrite the first. @xref{Multiple Rules, 10795 ,Multiple Rules for One Target}. 10780 10796 10781 10797 @item Circular @var{xxx} <- @var{yyy} dependency dropped. … … 11017 11033 11018 11034 @group 11019 .PHONY: tar11020 11035 tar: $(OBJS) 11021 11036 $(CC) $(LDFLAGS) -o $@@ $(OBJS) $(LIBS) … … 11118 11133 @end example 11119 11134 11120 @raisesections 11135 @node GNU Free Documentation License, Concept Index, Complex Makefile, Top 11136 @appendixsec GNU Free Documentation License 11137 @cindex FDL, GNU Free Documentation License 11121 11138 @include fdl.texi 11122 @lowersections11123 11139 11124 11140 @node Concept Index, Name Index, GNU Free Documentation License, Top
Note:
See TracChangeset
for help on using the changeset viewer.