Changeset 3140 for trunk/src/kmk/doc
- Timestamp:
- Mar 14, 2018, 10:28:10 PM (7 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk
-
Property svn:mergeinfo
set to
/vendor/gnumake/current merged eligible
-
Property svn:mergeinfo
set to
-
trunk/src/kmk/doc/Makefile.am
r2591 r3140 1 1 # -*-Makefile-*-, or close enough 2 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 3 # 2010 Free Software Foundation, Inc. 2 # Copyright (C) 2000-2016 Free Software Foundation, Inc. 4 3 # This file is part of GNU Make. 5 4 # … … 24 23 25 24 CLEANFILES = make*.html 26 27 ## ----------------------------- ##28 ## Other documentation formats. ##29 ## ----------------------------- ##30 31 html: make_1.html32 33 make_1.html: $(info_TEXINFOS) $(make_TEXINFOS)34 $(TEXI2HTML) $(TEXI2HTML_FLAGS) $(srcdir)/make.texi35 36 .PHONY: html -
trunk/src/kmk/doc/make.texi
r2591 r3140 4 4 5 5 @include version.texi 6 @set EDITION 0.71 7 @set RCSID $Id: make.texi,v 1.66 2010/07/19 07:10:54 psmith Exp $ 6 @set EDITION 0.74 8 7 9 8 @settitle GNU @code{make} … … 28 27 Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 29 28 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 30 2008, 2009, 2010 Free Software Foundation, Inc. 29 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free Software 30 Foundation, Inc. 31 31 32 32 @quotation 33 33 Permission is granted to copy, distribute and/or modify this document 34 under the terms of the GNU Free Documentation License, Version 1. 2or34 under the terms of the GNU Free Documentation License, Version 1.3 or 35 35 any later version published by the Free Software Foundation; with no 36 36 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,'' … … 101 101 based on their file names. 102 102 * Archives:: How @code{make} can update library archives. 103 * Extending make:: Using extensions to @code{make}. 104 * Integrating make:: Integrating @code{make} with other tools. 103 105 * Features:: Features GNU @code{make} has over other @code{make}s. 104 106 * Missing:: What GNU @code{make} lacks from other @code{make}s. … … 110 112 but nontrivial, makefile. 111 113 112 * GNU Free Documentation License:: License for copying this manual 113 * Concept Index:: Index of Concepts 114 * Name Index:: Index of Functions, Variables, & Directives 114 * GNU Free Documentation License:: License for copying this manual. 115 * Concept Index:: Index of Concepts. 116 * Name Index:: Index of Functions, Variables, & Directives. 115 117 116 118 @detailmenu … … 119 121 Overview of @code{make} 120 122 121 * Preparing:: Preparing and running make122 * Reading:: On reading this text 123 * Bugs:: Problems and bugs 123 * Preparing:: Preparing and running @code{make}. 124 * Reading:: On reading this text. 125 * Bugs:: Problems and bugs. 124 126 125 127 An Introduction to Makefiles 126 128 127 129 * Rule Introduction:: What a rule looks like. 128 * 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 130 * Simple Makefile:: A simple makefile. 131 * How Make Works:: How @code{make} processes this makefile. 132 * Variables Simplify:: Variables make makefiles simpler. 133 * make Deduces:: Letting @code{make} deduce the recipes. 134 * Combine By Prerequisite:: Another style of makefile. 135 * Cleanup:: Rules for cleaning the directory. 134 136 135 137 Writing Makefiles … … 144 146 * Reading Makefiles:: How makefiles are parsed. 145 147 * Secondary Expansion:: How and when secondary expansion is performed. 148 149 What Makefiles Contain 150 151 * Splitting Lines:: Splitting long lines in makefiles 146 152 147 153 Writing Rules … … 171 177 Using Wildcard Characters in File Names 172 178 173 * Wildcard Examples:: Several examples 179 * Wildcard Examples:: Several examples. 174 180 * Wildcard Pitfall:: Problems to avoid. 175 181 * Wildcard Function:: How to cause wildcard expansion where … … 207 213 Recipe Syntax 208 214 209 * Splitting Lines::Breaking long recipe lines for readability.215 * Splitting Recipe Lines:: Breaking long recipe lines for readability. 210 216 * Variables in Recipes:: Using @code{make} variables in recipes. 211 217 212 218 Recipe Execution 213 219 220 * One Shell:: One shell for all lines in a recipe. 214 221 * Choosing the Shell:: How @code{make} chooses the shell used 215 222 to run recipes. 223 224 Parallel Execution 225 226 * Parallel Output:: Handling output during parallel execution 227 * Parallel Input:: Handling input during parallel execution 216 228 217 229 Recursive Use of @code{make} … … 236 248 * Multi-Line:: An alternate way to set a variable 237 249 to a multi-line string. 250 * Undefine Directive:: How to undefine a variable so that it appears 251 as if it was never set. 238 252 * Environment:: Variable values can come from the environment. 239 253 * Target-specific:: Variable values can be defined on a per-target … … 263 277 * Conditional Functions:: Functions that implement conditions. 264 278 * Foreach Function:: Repeat some text with controlled variation. 279 * File Function:: Write text to a file. 265 280 * Call Function:: Expand a user-defined function. 266 281 * Value Function:: Return the un-expanded value of a variable. … … 268 283 * Origin Function:: Find where a variable got its value. 269 284 * Flavor Function:: Find out the flavor of a variable. 285 * Make Control Functions:: Functions that control how make runs. 270 286 * Shell Function:: Substitute the output of a shell command. 271 * Make Control Functions:: Functions that control how make runs.287 * Guile Function:: Use GNU Guile embedded scripting language. 272 288 273 289 How to Run @code{make} … … 290 306 291 307 * Using Implicit:: How to use an existing implicit rule 292 to get the recipe for updating a file.293 * Catalogue of Rules:: A list of built-in implicitrules.308 to get the recipes for updating a file. 309 * Catalogue of Rules:: A list of built-in rules. 294 310 * Implicit Variables:: How to change what predefined rules do. 295 311 * Chained Rules:: How to use a chain of implicit rules. … … 325 341 * Archive Symbols:: How to update archive symbol directories. 326 342 343 Extending GNU @code{make} 344 345 * Guile Integration:: Using Guile as an embedded scripting language. 346 * Loading Objects:: Loading dynamic objects as extensions. 347 348 GNU Guile Integration 349 350 * Guile Types:: Converting Guile types to @code{make} strings. 351 * Guile Interface:: Invoking @code{make} functions from Guile. 352 * Guile Example:: Example using Guile in @code{make}. 353 354 Loading Dynamic Objects 355 356 * load Directive:: Loading dynamic objects as extensions. 357 * Remaking Loaded Objects:: How loaded objects get remade. 358 * Loaded Object API:: Programmatic interface for loaded objects. 359 * Loaded Object Example:: Example of a loaded object 360 361 Integrating GNU @code{make} 362 363 * Job Slots:: Share job slots with GNU @code{make}. 364 * Terminal Output:: Control output to terminals. 365 366 Sharing Job Slots with GNU @code{make} 367 368 * POSIX Jobserver:: Using the jobserver on POSIX systems. 369 * Windows Jobserver:: Using the jobserver on Windows systems. 370 327 371 @end detailmenu 328 372 @end menu … … 351 395 352 396 @menu 353 * Preparing:: Preparing and Running Make354 * Reading:: On Reading this Text355 * Bugs:: Problems and Bugs397 * Preparing:: Preparing and running @code{make}. 398 * Reading:: On reading this text. 399 * Bugs:: Problems and bugs. 356 400 @end menu 357 401 … … 487 531 @menu 488 532 * Rule Introduction:: What a rule looks like. 489 * Simple Makefile:: A Simple Makefile490 * How Make Works:: How @code{make} Processes This Makefile491 * Variables Simplify:: Variables Make Makefiles Simpler492 * make Deduces:: Letting @code{make} Deduce the Recipes493 * Combine By Prerequisite:: Another Style of Makefile494 * Cleanup:: Rules for Cleaning the Directory533 * Simple Makefile:: A simple makefile. 534 * How Make Works:: How @code{make} processes this makefile. 535 * Variables Simplify:: Variables make makefiles simpler. 536 * make Deduces:: Letting @code{make} deduce the recipes. 537 * Combine By Prerequisite:: Another style of makefile. 538 * Cleanup:: Rules for cleaning the directory. 495 539 @end menu 496 540 … … 592 636 593 637 @noindent 594 We split each long line into two lines using backslash-newline; this is 595 like using one long line, but is easier to read. 638 We split each long line into two lines using backslash/newline; this is 639 like using one long line, but is easier to read. @xref{Splitting Lines, 640 , Splitting Long Lines}. 596 641 @cindex continuation lines 597 642 @cindex @code{\} (backslash), for continuation lines … … 1027 1072 @end itemize 1028 1073 1074 @menu 1075 * Splitting Lines:: Splitting long lines in makefiles 1076 @end menu 1077 1078 @node Splitting Lines, , Makefile Contents, Makefile Contents 1079 @subsection Splitting Long Lines 1080 @cindex splitting long lines 1081 @cindex long lines, splitting 1082 @cindex backslash (@code{\}), to quote newlines 1083 1084 Makefiles use a ``line-based'' syntax in which the newline character 1085 is special and marks the end of a statement. GNU @code{make} has no 1086 limit on the length of a statement line, up to the amount of memory in 1087 your computer. 1088 1089 However, it is difficult to read lines which are too long to display 1090 without wrapping or scrolling. So, you can format your makefiles for 1091 readability by adding newlines into the middle of a statement: you do 1092 this by escaping the internal newlines with a backslash (@code{\}) 1093 character. Where we need to make a distinction we will refer to 1094 ``physical lines'' as a single line ending with a newline (regardless 1095 of whether it is escaped) and a ``logical line'' being a complete 1096 statement including all escaped newlines up to the first non-escaped 1097 newline. 1098 1099 The way in which backslash/newline combinations are handled depends on 1100 whether the statement is a recipe line or a non-recipe line. Handling 1101 of backslash/newline in a recipe line is discussed later 1102 (@pxref{Splitting Recipe Lines}). 1103 1104 Outside of recipe lines, backslash/newlines are converted into a 1105 single space character. Once that is done, all whitespace around the 1106 backslash/newline is condensed into a single space: this includes all 1107 whitespace preceding the backslash, all whitespace at the beginning of 1108 the line after the backslash/newline, and any consecutive 1109 backslash/newline combinations. 1110 1111 If the @code{.POSIX} special target is defined then backslash/newline 1112 handling is modified slightly to conform to POSIX.2: first, whitespace 1113 preceding a backslash is not removed and second, consecutive 1114 backslash/newlines are not condensed. 1115 1029 1116 @node Makefile Names, Include, Makefile Contents, Makefiles 1030 1117 @section What Name to Give Your Makefile … … 1220 1307 @node Remaking Makefiles, Overriding Makefiles, MAKEFILES Variable, Makefiles 1221 1308 @section How Makefiles Are Remade 1222 1223 1309 @cindex updating makefiles 1224 1310 @cindex remaking makefiles … … 1242 1328 you want to keep @code{make} from performing an implicit rule search 1243 1329 on them, perhaps for efficiency reasons, you can use any normal method 1244 of preventing implicit rule look up to do so. For example, you can1330 of preventing implicit rule look-up to do so. For example, you can 1245 1331 write an explicit rule with the makefile as the target, and an empty 1246 1332 recipe (@pxref{Empty Recipes, ,Using Empty Recipes}). … … 1306 1392 another makefile. You can often use the @samp{include} directive to 1307 1393 include one in the other, and add more targets or variable definitions. 1308 However, it is i llegalfor two makefiles to give different recipes for1394 However, it is invalid for two makefiles to give different recipes for 1309 1395 the same target. But there is another way. 1310 1396 … … 1380 1466 @cindex ?=, expansion 1381 1467 @cindex +=, expansion 1468 @cindex !=, expansion 1382 1469 @cindex define, expansion 1383 1470 … … 1388 1475 @var{immediate} ?= @var{deferred} 1389 1476 @var{immediate} := @var{immediate} 1477 @var{immediate} ::= @var{immediate} 1390 1478 @var{immediate} += @var{deferred} or @var{immediate} 1479 @var{immediate} != @var{immediate} 1391 1480 1392 1481 define @var{immediate} … … 1406 1495 endef 1407 1496 1497 define @var{immediate} ::= 1498 @var{immediate} 1499 endef 1500 1408 1501 define @var{immediate} += 1409 1502 @var{deferred} or @var{immediate} 1410 1503 endef 1504 1505 define @var{immediate} != 1506 @var{immediate} 1507 endef 1411 1508 @end example 1412 1509 1413 1510 For the append operator, @samp{+=}, the right-hand side is considered 1414 1511 immediate if the variable was previously set as a simple variable 1415 (@samp{:=}), and deferred otherwise. 1512 (@samp{:=} or @samp{::=}), and deferred otherwise. 1513 1514 For the shell assignment operator, @samp{!=}, the right-hand side is 1515 evaluated immediately and handed to the shell. The result is stored in the 1516 variable named on the left, and that variable becomes a simple variable 1517 (and will thus be re-evaluated on each reference). 1416 1518 1417 1519 @subheading Conditional Directives … … 1439 1541 @example 1440 1542 @var{immediate} : @var{immediate} ; @var{deferred} 1441 1543 @var{deferred} 1442 1544 @end example 1443 1545 … … 1488 1590 without being recognized as a variable reference. Now during the 1489 1591 secondary expansion the first word is expanded again but since it 1490 contains no variable or function references it remains the static1491 value @file{onefile}, while the second word is now a normal reference1492 to the variable @var{TWOVAR}, which is expanded to the value 1493 @file{twofile}. The final result is that there are two prerequisites, 1494 @file{onefile}and @file{twofile}.1592 contains no variable or function references it remains the value 1593 @file{onefile}, while the second word is now a normal reference to the 1594 variable @var{TWOVAR}, which is expanded to the value @file{twofile}. 1595 The final result is that there are two prerequisites, @file{onefile} 1596 and @file{twofile}. 1495 1597 1496 1598 Obviously, this is not a very interesting case since the same result … … 1634 1736 Search, ,Implicit Rule Search Algorithm}, is appended (after 1635 1737 expansion) to all the patterns in the prerequisites list. As an 1636 example: 1738 example:@refill 1637 1739 1638 1740 @example … … 1642 1744 1643 1745 %.o: $$(addsuffix /%.c,foo bar) foo.h 1644 @end example 1645 1646 The prerequisite list after the secondary expansion and directory 1647 prefix reconstruction will be @file{/tmp/foo/foo.c /tmp/var/bar/foo.c 1648 foo.h}. If you are not interested in this reconstruction, you can use 1649 @code{$$*} instead of @code{%} in the prerequisites list. 1746 @@echo $^ 1747 @end example 1748 1749 The prerequisite list printed, after the secondary expansion and 1750 directory prefix reconstruction, will be @file{/tmp/foo/foo.c 1751 /tmp/bar/foo.c foo.h}. If you are not interested in this 1752 reconstruction, you can use @code{$$*} instead of @code{%} in the 1753 prerequisites list. 1650 1754 1651 1755 @node Rules, Recipes, Makefiles, Top … … 1685 1789 * Directory Search:: Searching other directories for source files. 1686 1790 * Phony Targets:: Using a target that is not a real file's name. 1687 * Force Targets:: You can use a target without recipes1791 * Force Targets:: You can use a target without a recipe 1688 1792 or prerequisites to mark other targets 1689 1793 as phony. … … 1922 2026 1923 2027 @menu 1924 * Wildcard Examples:: Several examples 2028 * Wildcard Examples:: Several examples. 1925 2029 * Wildcard Pitfall:: Problems to avoid. 1926 2030 * Wildcard Function:: How to cause wildcard expansion where … … 2120 2224 for a specified class of names. 2121 2225 * Search Algorithm:: When and how search paths are applied. 2122 * Recipes/Search:: How to write recipes that work together2226 * Recipes/Search:: How to write recipes that work together 2123 2227 with search paths. 2124 2228 * Implicit/Search:: How search paths affect implicit rules. … … 2456 2560 @samp{-l@var{name}} is seen, @code{make} will replace the percent in 2457 2561 each pattern in the list with @var{name} and perform the above directory 2458 searches using each library file name.2562 searches using each library file name. 2459 2563 2460 2564 The default value for @code{.LIBPATTERNS} is @samp{lib%.so lib%.a}, … … 2493 2597 2494 2598 @findex .PHONY 2495 The phony target will cease to work if anything ever does create a file 2496 named @file{clean} in this directory. Since it has no prerequisites, the 2497 file @file{clean} would inevitably be considered up to date, and its 2498 recipe would not be executed. To avoid this problem, you can explicitly 2499 declare the target to be phony, using the special target @code{.PHONY} 2599 In this example, the @file{clean} target will not work properly if a 2600 file named @file{clean} is ever created in this directory. Since it 2601 has no prerequisites, @file{clean} would always be considered up to 2602 date and its recipe would not be executed. To avoid this problem you 2603 can explicitly declare the target to be phony by making it a 2604 prerequisite of the special target @code{.PHONY} 2500 2605 (@pxref{Special Targets, ,Special Built-in Target Names}) as follows: 2501 2502 @example2503 .PHONY : clean2504 @end example2505 2506 @noindent2507 Once this is done, @samp{make clean} will run the recipe regardless of2508 whether there is a file named @file{clean}.2509 2510 Since it knows that phony targets do not name actual files that could be2511 remade from other files, @code{make} skips the implicit rule search for2512 phony targets (@pxref{Implicit Rules}). This is why declaring a target2513 phony is good for performance, even if you are not worried about the2514 actual file existing.2515 2516 Thus, you first write the line that states that @code{clean} is a2517 phony target, then you write the rule, like this:2518 2606 2519 2607 @example … … 2525 2613 @end example 2526 2614 2527 Another example of the usefulness of phony targets is in conjunction 2528 with recursive invocations of @code{make} (for more information, see 2529 @ref{Recursion, ,Recursive Use of @code{make}}). In this case the 2530 makefile will often contain a variable which lists a number of 2531 subdirectories to be built. One way to handle this is with one rule 2532 whose recipe is a shell loop over the subdirectories, like this: 2615 @noindent 2616 Once this is done, @samp{make clean} will run the recipe regardless of 2617 whether there is a file named @file{clean}. 2618 2619 Phony targets are also useful in conjunction with recursive 2620 invocations of @code{make} (@pxref{Recursion, ,Recursive Use of @code{make}}). 2621 In this situation the makefile will often contain a variable which 2622 lists a number of sub-directories to be built. A simplistic way to 2623 handle this is to define one rule with a recipe that loops over the 2624 sub-directories, like this: 2533 2625 2534 2626 @example … … 2544 2636 2545 2637 There are problems with this method, however. First, any error 2546 detected in a sub make is ignored by this rule, so it will continue2638 detected in a sub-make is ignored by this rule, so it will continue 2547 2639 to build the rest of the directories even when one fails. This can be 2548 2640 overcome by adding shell commands to note the error and exit, but then … … 2553 2645 one rule. 2554 2646 2555 By declaring the sub directories as phony targets (you must do this as2556 th e subdirectory obviously always exists; otherwise it won't be built)2557 you can remove these problems:2647 By declaring the sub-directories as @code{.PHONY} targets (you must do 2648 this as the sub-directory obviously always exists; otherwise it won't 2649 be built) you can remove these problems: 2558 2650 2559 2651 @example … … 2572 2664 @end example 2573 2665 2574 Here we've also declared that the @file{foo} sub directory cannot be2575 built until after the @file{baz} sub directory is complete; this kind of2666 Here we've also declared that the @file{foo} sub-directory cannot be 2667 built until after the @file{baz} sub-directory is complete; this kind of 2576 2668 relationship declaration is particularly important when attempting 2577 2669 parallel builds. 2670 2671 The implicit rule search (@pxref{Implicit Rules}) is skipped for 2672 @code{.PHONY} targets. This is why declaring a target as 2673 @code{.PHONY} is good for performance, even if you are not worried 2674 about the actual file existing. 2578 2675 2579 2676 A phony target should not be a prerequisite of a real target file; if it … … 2817 2914 is up to date. Unfortunately, some hosts do not provide a way to set a 2818 2915 high resolution file time stamp, so commands like @samp{cp -p} that 2819 explicitly set a file's time stamp must discard its sub second part.2916 explicitly set a file's time stamp must discard its sub-second part. 2820 2917 If a file is created by such a command, you should list it as a 2821 2918 prerequisite of @code{.LOW_RESOLUTION_TIME} so that @command{make} … … 2831 2928 @end example 2832 2929 2833 Since @samp{cp -p} discards the sub second part of @file{src}'s time2930 Since @samp{cp -p} discards the sub-second part of @file{src}'s time 2834 2931 stamp, @file{dst} is typically slightly older than @file{src} even when 2835 2932 it is up to date. The @code{.LOW_RESOLUTION_TIME} line causes … … 3133 3230 for each target that does not. If you have a list of files, only some of 3134 3231 which will match the pattern, you can use the @code{filter} function to 3135 remove non matching file names (@pxref{Text Functions, ,Functions for String Substitution and Analysis}):3232 remove non-matching file names (@pxref{Text Functions, ,Functions for String Substitution and Analysis}): 3136 3233 3137 3234 @example … … 3287 3384 The compiler will do it for you. 3288 3385 3289 Note that such a prerequisite constitutes mentioning @file{main.o} in a 3290 makefile, so it can never be considered an intermediate file by implicit 3291 rule search. This means that @code{make} won't ever remove the file 3292 after using it; @pxref{Chained Rules, ,Chains of Implicit Rules}. 3386 Note that such a rule constitutes mentioning @file{main.o} in a 3387 makefile, so it can never be considered an intermediate file by 3388 implicit rule search. This means that @code{make} won't ever remove 3389 the file after using it; @pxref{Chained Rules, ,Chains of Implicit 3390 Rules}. 3293 3391 3294 3392 @cindex @code{make depend} … … 3335 3433 of @samp{-M}. This omits prerequisites on system header files. 3336 3434 @xref{Preprocessor Options, , Options Controlling the Preprocessor, 3337 gcc .info, Using GNU CC}, for details.3435 gcc, Using GNU CC}, for details. 3338 3436 3339 3437 @cindex @code{sed} (shell command) … … 3464 3562 3465 3563 @menu 3466 * Splitting Lines::Breaking long recipe lines for readability.3564 * Splitting Recipe Lines:: Breaking long recipe lines for readability. 3467 3565 * Variables in Recipes:: Using @code{make} variables in recipes. 3468 3566 @end menu 3469 3567 3470 @node Splitting Lines, Variables in Recipes, Recipe Syntax, Recipe Syntax3568 @node Splitting Recipe Lines, Variables in Recipes, Recipe Syntax, Recipe Syntax 3471 3569 @subsection Splitting Recipe Lines 3472 3570 @cindex recipes, splitting … … 3487 3585 3488 3586 However, in contrast to how they are treated in other places in a 3489 makefile, backslash-newline pairs are @emph{not} removed from the 3490 recipe. Both the backslash and the newline characters are preserved 3491 and passed to the shell. How the backslash-newline is interpreted 3492 depends on your shell. If the first character of the next line after 3493 the backslash-newline is the recipe prefix character (a tab by 3494 default; @pxref{Special Variables}), then that character (and only 3495 that character) is removed. Whitespace is never added to the recipe. 3587 makefile (@pxref{Splitting Lines, , Splitting Long Lines}), 3588 backslash/newline pairs are @emph{not} removed from the recipe. Both 3589 the backslash and the newline characters are preserved and passed to 3590 the shell. How the backslash/newline is interpreted depends on your 3591 shell. If the first character of the next line after the 3592 backslash/newline is the recipe prefix character (a tab by default; 3593 @pxref{Special Variables}), then that character (and only that 3594 character) is removed. Whitespace is never added to the recipe. 3496 3595 3497 3596 For example, the recipe for the all target in this makefile: … … 3564 3663 3565 3664 Sometimes you want to split a long line inside of single quotes, but 3566 you don't want the backslash -newline to appear in the quoted content.3665 you don't want the backslash/newline to appear in the quoted content. 3567 3666 This is often the case when passing scripts to languages such as Perl, 3568 3667 where extraneous backslashes inside the script can change its meaning … … 3571 3670 @code{make} variable then use the variable in the recipe. In this 3572 3671 situation the newline quoting rules for makefiles will be used, and 3573 the backslash -newline will be removed. If we rewrite our example3672 the backslash/newline will be removed. If we rewrite our example 3574 3673 above using this method: 3575 3674 … … 3597 3696 uses it. 3598 3697 3599 @node Variables in Recipes, , Splitting Lines, Recipe Syntax3698 @node Variables in Recipes, , Splitting Recipe Lines, Recipe Syntax 3600 3699 @subsection Using Variables in Recipes 3601 3700 @cindex variable references in recipes … … 3700 3799 3701 3800 When it is time to execute recipes to update a target, they are 3702 executed by invoking a new sub shell for each line of the recipe,3801 executed by invoking a new sub-shell for each line of the recipe, 3703 3802 unless the @code{.ONESHELL} special target is in effect 3704 3803 (@pxref{One Shell, ,Using One Shell}) (In practice, @code{make} may … … 3731 3830 3732 3831 @menu 3733 * One Shell:: One shell for all lines in a recipe 3832 * One Shell:: One shell for all lines in a recipe. 3734 3833 * Choosing the Shell:: How @code{make} chooses the shell used 3735 3834 to run recipes. … … 3970 4069 slots is one, which means serial execution (one thing at a time). 3971 4070 3972 One unpleasant consequence of running several recipes simultaneously is 3973 that output generated by the recipes appears whenever each recipe 3974 sends it, so messages from different recipes may be interspersed. 3975 3976 Another problem is that two processes cannot both take input from the 3977 same device; so to make sure that only one recipe tries to take input 3978 from the terminal at once, @code{make} will invalidate the standard 3979 input streams of all but one running recipe. This means that 3980 attempting to read from standard input will usually be a fatal error (a 3981 @samp{Broken pipe} signal) for most child processes if there are 3982 several. 3983 @cindex broken pipe 3984 @cindex standard input 3985 3986 It is unpredictable which recipe will have a valid standard input stream 3987 (which will come from the terminal, or wherever you redirect the standard 3988 input of @code{make}). The first recipe run will always get it first, and 3989 the first recipe started after that one finishes will get it next, and so 3990 on. 3991 3992 We will change how this aspect of @code{make} works if we find a better 3993 alternative. In the mean time, you should not rely on any recipe using 3994 standard input at all if you are using the parallel execution feature; but 3995 if you are not using this feature, then standard input works normally in 3996 all recipes. 3997 3998 Finally, handling recursive @code{make} invocations raises issues. For 3999 more information on this, see 4000 @ref{Options/Recursion, ,Communicating Options to a Sub-@code{make}}. 4071 Handling recursive @code{make} invocations raises issues for parallel 4072 execution. For more information on this, see @ref{Options/Recursion, 4073 ,Communicating Options to a Sub-@code{make}}. 4001 4074 4002 4075 If a recipe fails (is killed by a signal or exits with a nonzero 4003 status), and errors are not ignored for that recipe 4004 (@pxref{Errors, ,Errors in Recipes}), 4005 the remaining recipe lines to remake the same target will not be run. 4006 If a recipe fails and the @samp{-k} or @samp{--keep-going} 4007 option was not given 4008 (@pxref{Options Summary, ,Summary of Options}), 4009 @code{make} aborts execution. If make 4076 status), and errors are not ignored for that recipe (@pxref{Errors, 4077 ,Errors in Recipes}), the remaining recipe lines to remake the same 4078 target will not be run. If a recipe fails and the @samp{-k} or 4079 @samp{--keep-going} option was not given (@pxref{Options Summary, 4080 ,Summary of Options}), @code{make} aborts execution. If make 4010 4081 terminates for any reason (including a signal) with child processes 4011 4082 running, it waits for them to finish before actually exiting.@refill … … 4039 4110 4040 4111 By default, there is no load limit. 4112 4113 @menu 4114 * Parallel Output:: Handling output during parallel execution 4115 * Parallel Input:: Handling input during parallel execution 4116 @end menu 4117 4118 @node Parallel Output, Parallel Input, Parallel, Parallel 4119 @subsection Output During Parallel Execution 4120 @cindex output during parallel execution 4121 @cindex parallel execution, output during 4122 4123 When running several recipes in parallel the output from each 4124 recipe appears as soon as it is generated, with the result that 4125 messages from different recipes may be interspersed, sometimes even 4126 appearing on the same line. This can make reading the output very 4127 difficult. 4128 4129 @cindex @code{--output-sync} 4130 @cindex @code{-O} 4131 To avoid this you can use the @samp{--output-sync} (@samp{-O}) option. 4132 This option instructs @code{make} to save the output from the commands 4133 it invokes and print it all once the commands are completed. 4134 Additionally, if there are multiple recursive @code{make} invocations 4135 running in parallel, they will communicate so that only one of them is 4136 generating output at a time. 4137 4138 If working directory printing is enabled (@pxref{-w Option, ,The 4139 @samp{--print-directory} Option}), the enter/leave messages are 4140 printed around each output grouping. If you prefer not to see these 4141 messages add the @samp{--no-print-directory} option to @code{MAKEFLAGS}. 4142 4143 There are four levels of granularity when synchronizing output, 4144 specified by giving an argument to the option (e.g., @samp{-Oline} or 4145 @samp{--output-sync=recurse}). 4146 4147 @table @code 4148 @item none 4149 This is the default: all output is sent directly as it is generated and 4150 no synchronization is performed. 4151 4152 @item line 4153 Output from each individual line of the recipe is grouped and printed 4154 as soon as that line is complete. If a recipe consists of multiple 4155 lines, they may be interspersed with lines from other recipes. 4156 4157 @item target 4158 Output from the entire recipe for each target is grouped and printed 4159 once the target is complete. This is the default if the 4160 @code{--output-sync} or @code{-O} option is given with no argument. 4161 4162 @item recurse 4163 Output from each recursive invocation of @code{make} is grouped and 4164 printed once the recursive invocation is complete. 4165 4166 @end table 4167 4168 Regardless of the mode chosen, the total build time will be the same. 4169 The only difference is in how the output appears. 4170 4171 The @samp{target} and @samp{recurse} modes both collect the output of 4172 the entire recipe of a target and display it uninterrupted when the 4173 recipe completes. The difference between them is in how recipes that 4174 contain recursive invocations of @code{make} are treated 4175 (@pxref{Recursion, ,Recursive Use of @code{make}}). For all recipes 4176 which have no recursive lines, the @samp{target} and @samp{recurse} 4177 modes behave identically. 4178 4179 If the @samp{recurse} mode is chosen, recipes that contain recursive 4180 @code{make} invocations are treated the same as other targets: the 4181 output from the recipe, including the output from the recursive 4182 @code{make}, is saved and printed after the entire recipe is complete. 4183 This ensures output from all the targets built by a given recursive 4184 @code{make} instance are grouped together, which may make the output 4185 easier to understand. However it also leads to long periods of time 4186 during the build where no output is seen, followed by large bursts of 4187 output. If you are not watching the build as it proceeds, but instead 4188 viewing a log of the build after the fact, this may be the best option 4189 for you. 4190 4191 If you are watching the output, the long gaps of quiet during the 4192 build can be frustrating. The @samp{target} output synchronization 4193 mode detects when @code{make} is going to be invoked recursively, 4194 using the standard methods, and it will not synchronize the output of 4195 those lines. The recursive @code{make} will perform the 4196 synchronization for its targets and the output from each will be 4197 displayed immediately when it completes. Be aware that output from 4198 recursive lines of the recipe are not synchronized (for example if 4199 the recursive line prints a message before running @code{make}, that 4200 message will not be synchronized). 4201 4202 The @samp{line} mode can be useful for front-ends that are watching 4203 the output of @code{make} to track when recipes are started and 4204 completed. 4205 4206 Some programs invoked by @code{make} may behave differently if they 4207 determine they're writing output to a terminal versus a file (often 4208 described as ``interactive'' vs. ``non-interactive'' modes). For 4209 example, many programs that can display colorized output will not do 4210 so if they determine they are not writing to a terminal. If your 4211 makefile invokes a program like this then using the output 4212 synchronization options will cause the program to believe it's running 4213 in ``non-interactive'' mode even though the output will ultimately go 4214 to the terminal. 4215 4216 @node Parallel Input, , Parallel Output, Parallel 4217 @subsection Input During Parallel Execution 4218 @cindex input during parallel execution 4219 @cindex parallel execution, input during 4220 @cindex standard input 4221 4222 Two processes cannot both take input from the same device at the same 4223 time. To make sure that only one recipe tries to take input from the 4224 terminal at once, @code{make} will invalidate the standard input 4225 streams of all but one running recipe. If another recipe attempts to 4226 read from standard input it will usually incur a fatal error (a 4227 @samp{Broken pipe} signal). 4228 @cindex broken pipe 4229 4230 It is unpredictable which recipe will have a valid standard input stream 4231 (which will come from the terminal, or wherever you redirect the standard 4232 input of @code{make}). The first recipe run will always get it first, and 4233 the first recipe started after that one finishes will get it next, and so 4234 on. 4235 4236 We will change how this aspect of @code{make} works if we find a better 4237 alternative. In the mean time, you should not rely on any recipe using 4238 standard input at all if you are using the parallel execution feature; but 4239 if you are not using this feature, then standard input works normally in 4240 all recipes. 4041 4241 4042 4242 @node Errors, Interrupts, Parallel, Recipes … … 4179 4379 makefile. This technique is useful when you want separate makefiles for 4180 4380 various subsystems that compose a larger system. For example, suppose you 4181 have a sub directory @file{subdir} which has its own makefile, and you would4381 have a sub-directory @file{subdir} which has its own makefile, and you would 4182 4382 like the containing directory's makefile to run @code{make} on the 4183 sub directory. You can do it by writing this:4383 sub-directory. You can do it by writing this: 4184 4384 4185 4385 @example … … 4293 4493 Variable values of the top-level @code{make} can be passed to the 4294 4494 sub-@code{make} through the environment by explicit request. These 4295 variables are defined in the sub-@code{make} as defaults, but do not4296 override what is specified in the makefile used by the sub-@code{make} 4297 makefile unless you use the @samp{-e} switch (@pxref{Options Summary, 4298 ,Summary of Options}).@refill4495 variables are defined in the sub-@code{make} as defaults, but they do 4496 not override variables defined in the makefile used by 4497 the sub-@code{make} unless you use the @samp{-e} switch (@pxref{Options 4498 Summary, ,Summary of Options}).@refill 4299 4499 4300 4500 To pass down, or @dfn{export}, a variable, @code{make} adds the … … 4522 4722 4523 4723 If your operating system doesn't support the above communication, then 4524 @samp{-j 1} is always put into @code{MAKEFLAGS} instead of the value you 4525 specified. This is because if the @w{@samp{-j}} option were passed down4526 to sub-@code{make}s ,you would get many more jobs running in parallel4724 no @samp{-j} is added to @code{MAKEFLAGS}, so that sub-@code{make}s 4725 run in non-parallel mode. If the @w{@samp{-j}} option were passed down 4726 to sub-@code{make}s you would get many more jobs running in parallel 4527 4727 than you asked for. If you give @samp{-j} with no numeric argument, 4528 4728 meaning to run as many jobs as possible in parallel, this is passed … … 4556 4756 see the error message @samp{Arg list too long}, this may be the problem. 4557 4757 @findex .POSIX 4558 @cindex POSIX .24758 @cindex POSIX 4559 4759 (For strict compliance with POSIX.2, changing @code{MAKEOVERRIDES} does 4560 4760 not affect @code{MAKEFLAGS} if the special target @samp{.POSIX} appears … … 4608 4808 put in one of these variables, could have disastrous consequences and would 4609 4809 certainly have at least surprising and probably annoying effects.@refill 4810 4811 If you'd like to run other implementations of @code{make} in addition 4812 to GNU @code{make}, and hence do not want to add GNU 4813 @code{make}-specific flags to the @code{MAKEFLAGS} variable, you can 4814 add them to the @code{GNUMAKEFLAGS} variable instead. This variable 4815 is parsed just before @code{MAKEFLAGS}, in the same way as 4816 @code{MAKEFLAGS}. When @code{make} constructs @code{MAKEFLAGS} to 4817 pass to a recursive @code{make} it will include all flags, even those 4818 taken from @code{GNUMAKEFLAGS}. As a result, after parsing 4819 @code{GNUMAKEFLAGS} GNU @code{make} sets this variable to the empty 4820 string to avoid duplicating flags during recursion. 4821 4822 It's best to use @code{GNUMAKEFLAGS} only with flags which won't 4823 materially change the behavior of your makefiles. If your makefiles 4824 require GNU make anyway then simply use @code{MAKEFLAGS}. Flags such 4825 as @samp{--no-print-directory} or @samp{--output-sync} may be 4826 appropriate for @code{GNUMAKEFLAGS}. 4610 4827 4611 4828 @node -w Option, , Options/Recursion, Recursion … … 4717 4934 In recipe execution, each line of a canned sequence is treated just as 4718 4935 if the line appeared on its own in the rule, preceded by a tab. In 4719 particular, @code{make} invokes a separate sub shell for each line. You4936 particular, @code{make} invokes a separate sub-shell for each line. You 4720 4937 can use the special prefix characters that affect command lines 4721 4938 (@samp{@@}, @samp{-}, and @samp{+}) on each line of a canned sequence. … … 4766 4983 4767 4984 @findex .DEFAULT@r{, and empty recipes} 4768 You may be wondering why you would want to define a recipe that 4769 does nothing. The only reason this is useful is to prevent a target 4770 from getting implicit recipes (from implicit rules or the 4771 @code{.DEFAULT} special target; @pxref{Implicit Rules} and 4772 @pxref{Last Resort, ,Defining Last-Resort Default Rules}).@refill 4773 4774 @c !!! another reason is for canonical stamp files: 4775 @ignore 4776 @example 4777 foo: stamp-foo ; 4778 stamp-foo: foo.in 4779 create foo frm foo.in 4780 touch $@ 4781 @end example 4782 @end ignore 4783 4784 You may be inclined to define empty recipes for targets that are 4785 not actual files, but only exist so that their prerequisites can be 4985 You may be wondering why you would want to define a recipe that does 4986 nothing. One reason this is useful is to prevent a target from 4987 getting implicit recipes (from implicit rules or the @code{.DEFAULT} 4988 special target; @pxref{Implicit Rules} and @pxref{Last Resort, 4989 ,Defining Last-Resort Default Rules}).@refill 4990 4991 Empty recipes can also be used to avoid errors for targets that will 4992 be created as a side-effect of another recipe: if the target does not 4993 exist the empty recipe ensures that @code{make} won't complain that it 4994 doesn't know how to build the target, and @code{make} will assume the 4995 target is out of date. 4996 4997 You may be inclined to define empty recipes for targets that are not 4998 actual files, but only exist so that their prerequisites can be 4786 4999 remade. However, this is not the best way to do that, because the 4787 prerequisites may not be remade properly if the target file actually does exist. 4788 @xref{Phony Targets, ,Phony Targets}, for a better way to do this. 5000 prerequisites may not be remade properly if the target file actually 5001 does exist. @xref{Phony Targets, ,Phony Targets}, for a better way to 5002 do this. 4789 5003 4790 5004 @node Using Variables, Conditionals, Recipes, Top … … 4811 5025 write output in, or anything else you can imagine. 4812 5026 4813 A variable name may be any sequence of characters not containing @samp{:}, 4814 @samp{#}, @samp{=}, or leading or trailing whitespace. However, 4815 variable names containing characters other than letters, numbers, and 4816 underscores should be avoided, as they may be given special meanings in the 4817 future, and with some shells they cannot be passed through the environment to a 4818 sub-@code{make} 4819 (@pxref{Variables/Recursion, ,Communicating Variables to a Sub-@code{make}}). 5027 A variable name may be any sequence of characters not containing 5028 @samp{:}, @samp{#}, @samp{=}, or whitespace. However, variable names 5029 containing characters other than letters, numbers, and underscores 5030 should be considered carefully, as in some shells they cannot be 5031 passed through the environment to a sub-@code{make} 5032 (@pxref{Variables/Recursion, ,Communicating Variables to a 5033 Sub-@code{make}}). Variable names beginning with @samp{.} and an 5034 uppercase letter may be given special meaning in future versions of 5035 @code{make}. 4820 5036 4821 5037 Variable names are case-sensitive. The names @samp{foo}, @samp{FOO}, … … 4941 5157 expands to @samp{$(ugh)} which finally expands to @samp{Huh?}.@refill 4942 5158 4943 This flavor of variable is the only sort supported by other versions of4944 @code{make}. It has its advantages and its disadvantages. An advantage 4945 (most would say) is that:5159 This flavor of variable is the only sort supported by most other 5160 versions of @code{make}. It has its advantages and its disadvantages. 5161 An advantage (most would say) is that: 4946 5162 4947 5163 @example … … 4979 5195 @cindex variables, simply expanded 4980 5196 @cindex := 5197 @cindex ::= 4981 5198 @dfn{Simply expanded variables} are defined by lines using @samp{:=} 4982 (@pxref{Setting, ,Setting Variables}). 5199 or @samp{::=} (@pxref{Setting, ,Setting Variables}). Both forms are 5200 equivalent in GNU @code{make}; however only the @samp{::=} form is 5201 described by the POSIX standard (support for @samp{::=} was added to 5202 the POSIX standard in 2012, so older versions of @code{make} won't 5203 accept this form either). 5204 4983 5205 The value of a simply expanded variable is scanned 4984 5206 once and for all, expanding any references to other variables and … … 5220 5442 5221 5443 References to recursively-expanded variables within a variable name are 5222 re expanded in the usual fashion. For example:5444 re-expanded in the usual fashion. For example: 5223 5445 5224 5446 @example … … 5399 5621 @cindex = 5400 5622 @cindex := 5623 @cindex ::= 5401 5624 @cindex ?= 5625 @cindex != 5402 5626 5403 5627 To set a variable from the makefile, write a line starting with the 5404 variable name followed by @samp{=} or @samp{:=}. Whatever follows the 5405 @samp{=} or @samp{:=} on the line becomes the value. For example, 5628 variable name followed by @samp{=}, @samp{:=}, or @samp{::=}. Whatever 5629 follows the @samp{=}, @samp{:=}, or @samp{::=} on the line becomes the 5630 value. For example, 5406 5631 5407 5632 @example … … 5413 5638 name and immediately after the @samp{=} is ignored. 5414 5639 5415 Variables defined with @samp{=} are @dfn{recursively expanded} variables. 5416 Variables defined with @samp{:=} are @dfn{simply expanded} variables; these 5417 definitions can contain variable references which will be expanded before 5418 the definition is made. @xref{Flavors, ,The Two Flavors of Variables}. 5640 Variables defined with @samp{=} are @dfn{recursively expanded} 5641 variables. Variables defined with @samp{:=} or @samp{::=} are 5642 @dfn{simply expanded} variables; these definitions can contain 5643 variable references which will be expanded before the definition is 5644 made. @xref{Flavors, ,The Two Flavors of Variables}. 5419 5645 5420 5646 The variable name may contain function and variable references, which … … 5422 5648 5423 5649 There is no limit on the length of the value of a variable except the 5424 amount of swapping space on the computer. When a variable definition is 5425 long, it is a good idea to break it into several lines by inserting 5426 backslash-newline at convenient places in the definition. This will not 5427 affect the functioning of @code{make}, but it will make the makefile easier 5428 to read. 5650 amount of memory on the computer. You can split the value of a 5651 variable into multiple physical lines for readability 5652 (@pxref{Splitting Lines, ,Splitting Long Lines}). 5429 5653 5430 5654 Most variable names are considered to have the empty string as a value if … … 5454 5678 @end example 5455 5679 5680 The shell assignment operator @samp{!=} can be used to execute a 5681 shell script and set a variable to its output. This operator first 5682 evaluates the right-hand side, then passes that result to the shell 5683 for execution. If the result of the execution ends in a newline, that 5684 one newline is removed; all other newlines are replaced by spaces. 5685 The resulting string is then placed into the named 5686 recursively-expanded variable. For example: 5687 5688 @example 5689 hash != printf '\043' 5690 file_list != find . -name '*.c' 5691 @end example 5692 5693 If the result of the execution could produce a @code{$}, and you don't 5694 intend what follows that to be interpreted as a make variable or 5695 function reference, then you must replace every @code{$} with 5696 @code{$$} as part of the execution. Alternatively, you can set a 5697 simply expanded variable to the result of running a program using the 5698 @code{shell} function call. @xref{Shell Function, , The @code{shell} 5699 Function}. For example: 5700 5701 @example 5702 hash := $(shell printf '\043') 5703 var := $(shell find . -name "*.c") 5704 @end example 5705 5706 As with the @code{shell} function, the exit status of the just-invoked 5707 shell script is stored in the @code{.SHELLSTATUS} variable. 5708 5709 5456 5710 @node Appending, Override Directive, Setting, Using Variables 5457 5711 @section Appending More Text to Variables … … 5498 5752 When you add to a variable's value with @samp{+=}, @code{make} acts 5499 5753 essentially as if you had included the extra text in the initial 5500 definition of the variable. If you defined it first with @samp{:=} ,5501 making it a simply-expanded variable, @samp{+=} adds to that 5502 simply-expanded definition, and expands the new text before appending it 5503 to the old value just as @samp{:=} does 5504 (see @ref{Setting, ,Setting Variables}, for a full explanation of @samp{:=}). 5505 In fact,5754 definition of the variable. If you defined it first with @samp{:=} or 5755 @samp{::=}, making it a simply-expanded variable, @samp{+=} adds to 5756 that simply-expanded definition, and expands the new text before 5757 appending it to the old value just as @samp{:=} does (see 5758 @ref{Setting, ,Setting Variables}, for a full explanation of 5759 @samp{:=} or @samp{::=}). In fact, 5506 5760 5507 5761 @example … … 5561 5815 The first line defines the @code{CFLAGS} variable with a reference to another 5562 5816 variable, @code{includes}. (@code{CFLAGS} is used by the rules for C 5563 compilation; @pxref{Catalogue of Rules, ,Catalogue of ImplicitRules}.)5817 compilation; @pxref{Catalogue of Rules, ,Catalogue of Built-In Rules}.) 5564 5818 Using @samp{=} for the definition makes @code{CFLAGS} a recursively-expanded 5565 5819 variable, meaning @w{@samp{$(includes) -O}} is @emph{not} expanded when … … 5717 5971 since two commands separated by semicolon behave much like two separate 5718 5972 shell commands. However, note that using two separate lines means 5719 @code{make} will invoke the shell twice, running an independent sub shell5973 @code{make} will invoke the shell twice, running an independent sub-shell 5720 5974 for each line. @xref{Execution, ,Recipe Execution}. 5721 5975 … … 5843 6097 5844 6098 The @var{variable-assignment} can be any valid form of assignment; 5845 recursive (@samp{=}), s tatic (@samp{:=}), appending (@samp{+=}), or5846 conditional (@samp{?=}). All variables that appear within the 5847 @var{variable-assignment} are evaluated within the context of the 5848 target: thus, any previously-defined target-specific variable values 5849 will be in effect. Note that this variable is actually distinct from 5850 any ``global'' value: the two variables do not have to have the same 5851 flavor (recursive vs.@: static).6099 recursive (@samp{=}), simple (@samp{:=} or @samp{::=}), appending 6100 (@samp{+=}), or conditional (@samp{?=}). All variables that appear 6101 within the @var{variable-assignment} are evaluated within the context 6102 of the target: thus, any previously-defined target-specific variable 6103 values will be in effect. Note that this variable is actually 6104 distinct from any ``global'' value: the two variables do not have to 6105 have the same flavor (recursive vs.@: simple). 5852 6106 5853 6107 Target-specific variables have the same priority as any other makefile … … 5974 6228 Due to the @code{private} modifier, @code{a.o} and @code{b.o} will not 5975 6229 inherit the @code{EXTRA_CFLAGS} variable assignment from the 5976 @code{prog s} target.6230 @code{prog} target. 5977 6231 5978 6232 @node Special Variables, , Suppressing Inheritance, Using Variables … … 6070 6324 6071 6325 Note that assigning more than one target name to @code{.DEFAULT_GOAL} is 6072 i llegaland will result in an error.6326 invalid and will result in an error. 6073 6327 6074 6328 @vindex MAKE_RESTARTS @r{(number of times @code{make} has restarted)} … … 6079 6333 this is not the same as recursion (counted by the @code{MAKELEVEL} 6080 6334 variable). You should not set, modify, or export this variable. 6335 6336 @vindex MAKE_TERMOUT @r{(whether stdout is a terminal)} 6337 @vindex MAKE_TERMERR @r{(whether stderr is a terminal)} 6338 @item MAKE_TERMOUT 6339 @itemx MAKE_TERMERR 6340 When @code{make} starts it will check whether stdout and stderr will 6341 show their output on a terminal. If so, it will set 6342 @code{MAKE_TERMOUT} and @code{MAKE_TERMERR}, respectively, to the name 6343 of the terminal device (or @code{true} if this cannot be determined). 6344 If set these variables will be marked for export. These variables 6345 will not be changed by @code{make} and they will not be modified if 6346 already set. 6347 6348 These values can be used (particularly in combination with output 6349 synchronization (@pxref{Parallel Output, ,Output During Parallel 6350 Execution}) to determine whether @code{make} itself is writing to a 6351 terminal; they can be tested to decide whether to force recipe 6352 commands to generate colorized output for example. 6353 6354 If you invoke a sub-@code{make} and redirect its stdout or stderr it 6355 is your responsibility to reset or unexport these variables as well, 6356 if your makefiles rely on them. 6081 6357 6082 6358 @vindex .RECIPEPREFIX @r{(change the recipe prefix character)} … … 6121 6397 @item .FEATURES 6122 6398 Expands to a list of special features supported by this version of 6123 @code{make}. Possible values include :6399 @code{make}. Possible values include, but are not limited to: 6124 6400 6125 6401 @table @samp 6126 6402 6127 6403 @item archives 6128 Supports @code{ar} (archive) files using special file name syntax.6404 Supports @code{ar} (archive) files using special file name syntax. 6129 6405 @xref{Archives, ,Using @code{make} to Update Archive Files}. 6130 6406 … … 6141 6417 ,Parallel Execution}. 6142 6418 6143 @item second-expansion 6144 Supports secondary expansion of prerequisite lists. 6419 @item oneshell 6420 Supports the @code{.ONESHELL} special target. @xref{One Shell, ,Using 6421 One Shell}. 6145 6422 6146 6423 @item order-only … … 6148 6425 of Prerequisites}. 6149 6426 6427 @item second-expansion 6428 Supports secondary expansion of prerequisite lists. 6429 6430 @item shortest-stem 6431 Uses the ``shortest stem'' method of choosing which pattern, of 6432 multiple applicable options, will be used. @xref{Pattern Match, ,How 6433 Patterns Match}. 6434 6150 6435 @item target-specific 6151 6436 Supports target-specific and pattern-specific variable assignments. 6152 6437 @xref{Target-specific, ,Target-specific Variable Values}. 6153 6438 6439 @item undefine 6440 Supports the @code{undefine} directive. @xref{Undefine Directive}. 6441 6442 @item guile 6443 Has GNU Guile available as an embedded extension language. 6444 @xref{Guile Integration, ,GNU Guile Integration}. 6445 6446 @item load 6447 Supports dynamically loadable objects for creating custom extensions. 6448 @xref{Loading Objects, ,Loading Dynamic Objects}. 6154 6449 @end table 6155 6450 … … 6292 6587 6293 6588 @example 6294 @var{conditional-directive }6589 @var{conditional-directive-one} 6295 6590 @var{text-if-one-is-true} 6296 else @var{conditional-directive }6297 @var{text-if-t rue}6591 else @var{conditional-directive-two} 6592 @var{text-if-two-is-true} 6298 6593 else 6299 @var{text-if- false}6594 @var{text-if-one-and-two-are-false} 6300 6595 endif 6301 6596 @end example … … 6354 6649 @item ifdef @var{variable-name} 6355 6650 The @code{ifdef} form takes the @emph{name} of a variable as its 6356 argument, not a reference to a variable. The value of that variable6357 has a non-empty value, the @var{text-if-true} is effective; otherwise, 6358 the @var{text-if-false}, if any, is effective. Variables that have 6359 never been defined have an empty value. The text @var{variable-name} 6360 is expanded, so it could be a variable or function that expands 6361 t o the name of a variable. For example:6651 argument, not a reference to a variable. If the value of that 6652 variable has a non-empty value, the @var{text-if-true} is effective; 6653 otherwise, the @var{text-if-false}, if any, is effective. Variables 6654 that have never been defined have an empty value. The text 6655 @var{variable-name} is expanded, so it could be a variable or function 6656 that expands to the name of a variable. For example: 6362 6657 6363 6658 @example … … 6493 6788 * Conditional Functions:: Functions that implement conditions. 6494 6789 * Foreach Function:: Repeat some text with controlled variation. 6790 * File Function:: Write text to a file. 6495 6791 * Call Function:: Expand a user-defined function. 6496 6792 * Value Function:: Return the un-expanded value of a variable. … … 6498 6794 * Origin Function:: Find where a variable got its value. 6499 6795 * Flavor Function:: Find out the flavor of a variable. 6796 * Make Control Functions:: Functions that control how make runs. 6500 6797 * Shell Function:: Substitute the output of a shell command. 6501 * Make Control Functions:: Functions that control how make runs.6798 * Guile Function:: Use GNU Guile embedded scripting language. 6502 6799 @end menu 6503 6800 … … 6509 6806 @cindex functions, syntax of 6510 6807 6511 A function call resembles a variable reference. It looks like this: 6808 A function call resembles a variable reference. It can appear 6809 anywhere a variable reference can appear, and it is expanded using the 6810 same rules as variable references. A function call looks like this: 6512 6811 6513 6812 @example … … 6524 6823 Here @var{function} is a function name; one of a short list of names 6525 6824 that are part of @code{make}. You can also essentially create your own 6526 functions by using the @code{call} built in function.6825 functions by using the @code{call} built-in function. 6527 6826 6528 6827 The @var{arguments} are the arguments of the function. They are … … 7141 7440 @end table 7142 7441 7143 @node Foreach Function, CallFunction, Conditional Functions, Functions7442 @node Foreach Function, File Function, Conditional Functions, Functions 7144 7443 @section The @code{foreach} Function 7145 7444 @findex foreach … … 7203 7502 Here we use the variable @code{find_files} this way. We use plain @samp{=} 7204 7503 to define a recursively-expanding variable, so that its value contains an 7205 actual function call to be re expanded under the control of @code{foreach};7504 actual function call to be re-expanded under the control of @code{foreach}; 7206 7505 a simply-expanded variable would not do, since @code{wildcard} would be 7207 7506 called only once at the time of defining @code{find_files}. … … 7221 7520 7222 7521 @smallexample 7223 files := $(foreach Esta escrito enespanol!,b c ch,$(find_files))7522 files := $(foreach Esta-escrito-en-espanol!,b c ch,$(find_files)) 7224 7523 @end smallexample 7225 7524 7226 7525 @noindent 7227 7526 might be useful if the value of @code{find_files} references the variable 7228 whose name is @samp{Esta escrito enespanol!} (es un nombre bastante largo,7527 whose name is @samp{Esta-escrito-en-espanol!} (es un nombre bastante largo, 7229 7528 no?), but it is more likely to be a mistake. 7230 7529 7231 @node Call Function, Value Function, Foreach Function, Functions 7530 @node File Function, Call Function, Foreach Function, Functions 7531 @section The @code{file} Function 7532 @findex file 7533 @cindex writing to a file 7534 @cindex file, writing to 7535 @cindex reading from a file 7536 @cindex file, reading from 7537 7538 The @code{file} function allows the makefile to write to or read from 7539 a file. Two modes of writing are supported: overwrite, where the text 7540 is written to the beginning of the file and any existing content is 7541 lost, and append, where the text is written to the end of the file, 7542 preserving the existing content. In both cases the file is created if 7543 it does not exist. It is a fatal error if the file cannot be opened 7544 for writing, or if the write operation fails. The @code{file} 7545 function expands to the empty string when writing to a file. 7546 7547 When reading from a file, the @code{file} function expands to the 7548 verbatim contents of the file, except that the final newline (if there 7549 is one) will be stripped. Attempting to read from a non-existent file 7550 expands to the empty string. 7551 7552 The syntax of the @code{file} function is: 7553 7554 @example 7555 $(file @var{op} @var{filename}[,@var{text}]) 7556 @end example 7557 7558 When the @code{file} function is evaluated all its arguments are 7559 expanded first, then the file indicated by @var{filename} will be 7560 opened in the mode described by @var{op}. 7561 7562 The operator @var{op} can be @code{>} to indicate the file will be 7563 overwritten with new content, @code{>>} to indicate the current 7564 contents of the file will be appended to, or @code{<} to indicate the 7565 contents of the file will be read in. The @var{filename} specifies 7566 the file to be written to or read from. There may optionally be 7567 whitespace between the operator and the file name. 7568 7569 When reading files, it is an error to provide a @var{text} value. 7570 7571 When writing files, @var{text} will be written to the file. If 7572 @var{text} does not already end in a newline a final newline will be 7573 written (even if @var{text} is the empty string). If the @var{text} 7574 argument is not given at all, nothing will be written. 7575 7576 For example, the @code{file} function can be useful if your build 7577 system has a limited command line size and your recipe runs a command 7578 that can accept arguments from a file as well. Many commands use the 7579 convention that an argument prefixed with an @code{@@} specifies a 7580 file containing more arguments. Then you might write your recipe in 7581 this way: 7582 7583 @example 7584 @group 7585 program: $(OBJECTS) 7586 $(file >$@@.in,$^) 7587 $(CMD) $(CMDFLAGS) @@$@@.in 7588 @@rm $@@.in 7589 @end group 7590 @end example 7591 7592 If the command required each argument to be on a separate line of the 7593 input file, you might write your recipe like this: 7594 7595 @example 7596 @group 7597 program: $(OBJECTS) 7598 $(file >$@@.in) $(foreach O,$^,$(file >>$@@.in,$O)) 7599 $(CMD) $(CMDFLAGS) @@$@@.in 7600 @@rm $@@.in 7601 @end group 7602 @end example 7603 7604 @node Call Function, Value Function, File Function, Functions 7232 7605 @section The @code{call} Function 7233 7606 @findex call … … 7263 7636 constant.) 7264 7637 7265 If @var{variable} is the name of a built in function, the builtin function7638 If @var{variable} is the name of a built-in function, the built-in function 7266 7639 is always invoked (even if a @code{make} variable by that name also 7267 7640 exists). … … 7269 7642 The @code{call} function expands the @var{param} arguments before 7270 7643 assigning them to temporary variables. This means that @var{variable} 7271 values containing references to built in functions that have special7644 values containing references to built-in functions that have special 7272 7645 expansion rules, like @code{foreach} or @code{if}, may not work as you 7273 7646 expect. … … 7341 7714 @end example 7342 7715 7343 Note that @var{variable} is the @emph{name} of a variable ;not a7716 Note that @var{variable} is the @emph{name} of a variable, not a 7344 7717 @emph{reference} to that variable. Therefore you would not normally 7345 7718 use a @samp{$} or parentheses when writing it. (You can, however, use … … 7452 7825 @end example 7453 7826 7454 Note that @var{variable} is the @emph{name} of a variable to inquire about ;7827 Note that @var{variable} is the @emph{name} of a variable to inquire about, 7455 7828 not a @emph{reference} to that variable. Therefore you would not normally 7456 7829 use a @samp{$} or parentheses when writing it. (You can, however, use a … … 7545 7918 @xref{Text Functions, , Functions for String Substitution and Analysis}. 7546 7919 7547 @node Flavor Function, Shell Function, Origin Function, Functions7920 @node Flavor Function, Make Control Functions, Origin Function, Functions 7548 7921 @section The @code{flavor} Function 7549 7922 @findex flavor … … 7551 7924 @cindex flavor of variable 7552 7925 7553 The @code{flavor} function is unlike most other functions (and like 7554 @code{origin} function) in that it does not operate on the values of 7555 variables; it tells you something @emph{about} a variable. 7556 Specifically, it tells you the flavor of a variable (@pxref{Flavors, 7557 ,The Two Flavors of Variables}). 7926 The @code{flavor} function, like the @code{origin} function, does not 7927 operate on the values of variables but rather it tells you something 7928 @emph{about} a variable. Specifically, it tells you the flavor of a 7929 variable (@pxref{Flavors, ,The Two Flavors of Variables}). 7558 7930 7559 7931 The syntax of the @code{flavor} function is: … … 7563 7935 @end example 7564 7936 7565 Note that @var{variable} is the @emph{name} of a variable to inquire about ;7937 Note that @var{variable} is the @emph{name} of a variable to inquire about, 7566 7938 not a @emph{reference} to that variable. Therefore you would not normally 7567 7939 use a @samp{$} or parentheses when writing it. (You can, however, use a … … 7586 7958 @end table 7587 7959 7588 7589 @node Shell Function, Make Control Functions, Flavor Function, Functions 7590 @section The @code{shell} Function 7591 @findex shell 7592 @cindex command expansion 7593 @cindex backquotes 7594 @cindex shell command, function for 7595 7596 The @code{shell} function is unlike any other function other than the 7597 @code{wildcard} function 7598 (@pxref{Wildcard Function, ,The Function @code{wildcard}}) in that it 7599 communicates with the world outside of @code{make}. 7600 7601 The @code{shell} function performs the same function that backquotes 7602 (@samp{`}) perform in most shells: it does @dfn{command expansion}. 7603 This means that it takes as an argument a shell command and evaluates 7604 to the output of the command. The only processing @code{make} does on 7605 the result is to convert each newline (or carriage-return / newline 7606 pair) to a single space. If there is a trailing (carriage-return 7607 and) newline it will simply be removed.@refill 7608 7609 The commands run by calls to the @code{shell} function are run when the 7610 function calls are expanded (@pxref{Reading Makefiles, , How 7611 @code{make} Reads a Makefile}). Because this function involves 7612 spawning a new shell, you should carefully consider the performance 7613 implications of using the @code{shell} function within recursively 7614 expanded variables vs.@: simply expanded variables (@pxref{Flavors, ,The 7615 Two Flavors of Variables}). 7616 7617 Here are some examples of the use of the @code{shell} function: 7618 7619 @example 7620 contents := $(shell cat foo) 7621 @end example 7622 7623 @noindent 7624 sets @code{contents} to the contents of the file @file{foo}, with a space 7625 (rather than a newline) separating each line. 7626 7627 @example 7628 files := $(shell echo *.c) 7629 @end example 7630 7631 @noindent 7632 sets @code{files} to the expansion of @samp{*.c}. Unless @code{make} is 7633 using a very strange shell, this has the same result as 7634 @w{@samp{$(wildcard *.c)}} (as long as at least one @samp{.c} file 7635 exists).@refill 7636 7637 @node Make Control Functions, , Shell Function, Functions 7960 @node Make Control Functions, Shell Function, Flavor Function, Functions 7638 7961 @section Functions That Control Make 7639 7962 @cindex functions, for controlling make … … 7696 8019 result of the expansion of this function is the empty string. 7697 8020 @end table 8021 8022 @node Shell Function, Guile Function, Make Control Functions, Functions 8023 @section The @code{shell} Function 8024 @findex shell 8025 @cindex command expansion 8026 @cindex backquotes 8027 @cindex shell command, function for 8028 8029 The @code{shell} function is unlike any other function other than the 8030 @code{wildcard} function 8031 (@pxref{Wildcard Function, ,The Function @code{wildcard}}) in that it 8032 communicates with the world outside of @code{make}. 8033 8034 The @code{shell} function performs the same function that backquotes 8035 (@samp{`}) perform in most shells: it does @dfn{command expansion}. 8036 This means that it takes as an argument a shell command and evaluates 8037 to the output of the command. The only processing @code{make} does on 8038 the result is to convert each newline (or carriage-return / newline 8039 pair) to a single space. If there is a trailing (carriage-return 8040 and) newline it will simply be removed.@refill 8041 8042 The commands run by calls to the @code{shell} function are run when the 8043 function calls are expanded (@pxref{Reading Makefiles, , How 8044 @code{make} Reads a Makefile}). Because this function involves 8045 spawning a new shell, you should carefully consider the performance 8046 implications of using the @code{shell} function within recursively 8047 expanded variables vs.@: simply expanded variables (@pxref{Flavors, ,The 8048 Two Flavors of Variables}). 8049 8050 @vindex .SHELLSTATUS 8051 After the @code{shell} function or @samp{!=} assignment operator is 8052 used, its exit status is placed in the @code{.SHELLSTATUS} variable. 8053 8054 Here are some examples of the use of the @code{shell} function: 8055 8056 @example 8057 contents := $(shell cat foo) 8058 @end example 8059 8060 @noindent 8061 sets @code{contents} to the contents of the file @file{foo}, with a space 8062 (rather than a newline) separating each line. 8063 8064 @example 8065 files := $(shell echo *.c) 8066 @end example 8067 8068 @noindent 8069 sets @code{files} to the expansion of @samp{*.c}. Unless @code{make} is 8070 using a very strange shell, this has the same result as 8071 @w{@samp{$(wildcard *.c)}} (as long as at least one @samp{.c} file 8072 exists).@refill 8073 8074 @node Guile Function, , Shell Function, Functions 8075 @section The @code{guile} Function 8076 @findex guile 8077 @cindex Guile 8078 8079 If GNU @code{make} is built with support for GNU Guile as an embedded 8080 extension language then the @code{guile} function will be available. 8081 The @code{guile} function takes one argument which is first expanded 8082 by @code{make} in the normal fashion, then passed to the GNU Guile 8083 evaluator. The result of the evaluator is converted into a string and 8084 used as the expansion of the @code{guile} function in the makefile. 8085 See @ref{Guile Integration, ,GNU Guile Integration} for details on 8086 writing extensions to @code{make} in Guile. 8087 8088 You can determine whether GNU Guile support is available by checking 8089 the @code{.FEATURES} variable for the word @var{guile}. 7698 8090 7699 8091 @node Running, Implicit Rules, Functions, Top … … 7919 8311 @cindex @code{-n} 7920 8312 7921 ``No-op''. The activity is to print what recipe would be used to make 7922 the targets up to date, but not actually execute it. Some recipes are 7923 still executed, even with this flag (@pxref{MAKE Variable, ,How the @code{MAKE} Variable Works}). 8313 ``No-op''. Causes @code{make} to print the recipes that are needed to 8314 make the targets up to date, but not actually execute them. Note that 8315 some recipes are still executed, even with this flag (@pxref{MAKE 8316 Variable, ,How the @code{MAKE} Variable Works}). Also any recipes 8317 needed to update included makefiles are still executed 8318 (@pxref{Remaking Makefiles, ,How Makefiles Are Remade}). 7924 8319 7925 8320 @item -t … … 7930 8325 @cindex @code{-t} 7931 8326 7932 ``Touch''. The activity is to mark the targets as up to date without 7933 actually changing them. In other words, @code{make} pretends to compile 7934 the targets but does not really change their contents. 8327 ``Touch''. Marks targets as up to date without actually changing 8328 them. In other words, @code{make} pretends to update the targets but 8329 does not really change their contents; instead only their modified 8330 times are updated. 7935 8331 7936 8332 @item -q … … 7940 8336 @cindex question mode 7941 8337 7942 ``Question''. The activity is to find out silently whether the targets7943 are up to date already; but execute no recipe in either case. In other 7944 words, neither compilation nor output will occur.8338 ``Question''. Silently check whether the targets are up to date, but 8339 do not execute recipes; the exit code shows whether any updates are 8340 needed. 7945 8341 7946 8342 @item -W @var{file} … … 8116 8512 define either a recursively-expanded variable or a simply-expanded 8117 8513 variable. The examples shown above make a recursively-expanded 8118 variable; to make a simply-expanded variable, write @samp{:=} instead8119 of @samp{=}. But, unless you want to include a variable reference or 8120 function call in the @emph{value} that you specify, it makes no 8121 difference which kind of variable you create.8514 variable; to make a simply-expanded variable, write @samp{:=} or 8515 @samp{::=} instead of @samp{=}. But, unless you want to include a 8516 variable reference or function call in the @emph{value} that you 8517 specify, it makes no difference which kind of variable you create. 8122 8518 8123 8519 There is one way that the makefile can change a variable that you have … … 8243 8639 8244 8640 @item j (@i{jobs}) 8245 Prints messages giving details on the invocation of specific sub commands.8641 Prints messages giving details on the invocation of specific sub-commands. 8246 8642 8247 8643 @item m (@i{makefile}) … … 8250 8646 too. Note that the @samp{all} option does enable this option. This 8251 8647 option also enables @samp{basic} messages. 8648 8649 @item n (@i{none}) 8650 Disable all debugging currently enabled. If additional debugging 8651 flags are encountered after this they will still take effect. 8252 8652 @end table 8253 8653 … … 8367 8767 are ignored. @xref{Avoiding Compilation, ,Avoiding Recompilation of 8368 8768 Some Files}.@refill 8769 8770 @item -O[@var{type}] 8771 @cindex @code{-O} 8772 @itemx --output-sync[=@var{type}] 8773 @cindex @code{--output-sync} 8774 @cindex output during parallel execution 8775 @cindex parallel execution, output during 8776 Ensure that the complete output from each recipe is printed in one 8777 uninterrupted sequence. This option is only useful when using the 8778 @code{--jobs} option to run multiple recipes simultaneously 8779 (@pxref{Parallel, ,Parallel Execution}) Without this option output 8780 will be displayed as it is generated by the recipes.@refill 8781 8782 With no type or the type @samp{target}, output from the entire recipe 8783 of each target is grouped together. With the type @samp{line}, output 8784 from each line in the recipe is grouped together. With the type 8785 @samp{recurse}, the output from an entire recursive make is grouped 8786 together. With the type @samp{none}, no output synchronization is 8787 performed. @xref{Parallel Output, ,Output During Parallel Execution}. 8369 8788 8370 8789 @item -p … … 8380 8799 to remake any files, use @w{@samp{make -qp}}. To print the data base 8381 8800 of predefined rules and variables, use @w{@samp{make -p -f /dev/null}}. 8382 The data base output contains file name and linenumber information for8801 The data base output contains file name and line number information for 8383 8802 recipe and variable definitions, so it can be a useful debugging tool 8384 8803 in complex environments. … … 8455 8874 @code{make}. @xref{Instead of Execution, ,Instead of Executing Recipes}. 8456 8875 8876 @item --trace 8877 @cindex @code{--trace} 8878 Show tracing information for @code{make} execution. Prints the entire 8879 recipe to be executed, even for recipes that are normally silent (due 8880 to @code{.SILENT} or @samp{@@}). Also prints the makefile name and 8881 line number where the recipe was defined, and information on why the 8882 target is being rebuilt. 8883 8457 8884 @item -v 8458 8885 @cindex @code{-v} … … 8473 8900 see @ref{-w Option, ,The @samp{--print-directory} Option}.) 8474 8901 8475 @item x--no-print-directory8902 @item --no-print-directory 8476 8903 @cindex @code{--no-print-directory} 8477 8904 Disable printing of the working directory under @code{-w}. … … 8551 8978 * Using Implicit:: How to use an existing implicit rule 8552 8979 to get the recipes for updating a file. 8553 * Catalogue of Rules:: A list of built-in implicitrules.8980 * Catalogue of Rules:: A list of built-in rules. 8554 8981 * Implicit Variables:: How to change what predefined rules do. 8555 8982 * Chained Rules:: How to use a chain of implicit rules. 8556 8983 * Pattern Rules:: How to define new implicit rules. 8557 * Last Resort:: How to define recipesfor rules which8984 * Last Resort:: How to define a recipe for rules which 8558 8985 cannot find any. 8559 8986 * Suffix Rules:: The old-fashioned style of implicit rule. … … 8603 9030 want @code{make} to use, and you know it will choose that one because you 8604 9031 know which possible prerequisite files are supposed to exist. 8605 @xref{Catalogue of Rules, ,Catalogue of ImplicitRules},9032 @xref{Catalogue of Rules, ,Catalogue of Built-In Rules}, 8606 9033 for a catalogue of all the predefined implicit rules. 8607 9034 … … 8633 9060 rule to make an object file from a C source file is used instead, 8634 9061 because it appears before the Pascal rule in the list of predefined 8635 implicit rules (@pxref{Catalogue of Rules, , Catalogue of Implicit9062 implicit rules (@pxref{Catalogue of Rules, , Catalogue of Built-In 8636 9063 Rules}). 8637 9064 … … 8641 9068 8642 9069 @node Catalogue of Rules, Implicit Variables, Using Implicit, Implicit Rules 8643 @section Catalogue of ImplicitRules9070 @section Catalogue of Built-In Rules 8644 9071 @cindex implicit rule, predefined 8645 9072 @cindex rule, implicit, predefined … … 8987 9414 Here is a table of some of the more common variables used as names of 8988 9415 programs in built-in rules: 8989 makefiles.8990 9416 8991 9417 @table @code … … 9142 9568 @vindex LDFLAGS 9143 9569 Extra flags to give to compilers when they are supposed to invoke the linker, 9144 @samp{ld}. 9570 @samp{ld}, such as @code{-L}. Libraries (@code{-lfoo}) should be 9571 added to the @code{LDLIBS} variable instead. 9572 9573 @item LDLIBS 9574 @vindex LDLIBS 9575 @vindex LOADLIBES 9576 Library flags or names given to compilers when they are supposed to 9577 invoke the linker, @samp{ld}. @code{LOADLIBES} is a deprecated (but 9578 still supported) alternative to @code{LDLIBS}. Non-library linker 9579 flags, such as @code{-L}, should go in the @code{LDFLAGS} variable. 9145 9580 9146 9581 @item LFLAGS … … 9275 9710 * Pattern Examples:: Examples of pattern rules. 9276 9711 * Automatic Variables:: How to use automatic variables in the 9277 recipe sof implicit rules.9712 recipe of implicit rules. 9278 9713 * Pattern Match:: How patterns match. 9279 9714 * Match-Anything Rules:: Precautions you should take prior to … … 9375 9810 @noindent 9376 9811 defines a rule that can make any file @file{@var{x}} whatsoever from a 9377 corresponding file @file{@var{x},v} in the sub directory @file{RCS}. Since9812 corresponding file @file{@var{x},v} in the sub-directory @file{RCS}. Since 9378 9813 the target is @samp{%}, this rule will apply to any file whatever, provided 9379 9814 the appropriate prerequisite file exists. The double colon makes the rule … … 9748 10183 9749 10184 If you do not mark the match-anything rule as terminal, then it is 9750 non terminal. A nonterminal match-anything rule cannot apply to a file name10185 non-terminal. A non-terminal match-anything rule cannot apply to a file name 9751 10186 that indicates a specific type of data. A file name indicates a specific 9752 10187 type of data if some non-match-anything implicit rule target matches it. … … 9756 10191 rule is actually applicable (which happens only if there is a file 9757 10192 @file{foo.y}), the fact that its target matches is enough to prevent 9758 consideration of any non terminal match-anything rules for the file10193 consideration of any non-terminal match-anything rules for the file 9759 10194 @file{foo.c}. Thus, @code{make} will not even consider trying to make 9760 10195 @file{foo.c} as an executable file from @file{foo.c.o}, @file{foo.c.c}, 9761 10196 @file{foo.c.p}, etc.@refill 9762 10197 9763 The motivation for this constraint is that non terminal match-anything10198 The motivation for this constraint is that non-terminal match-anything 9764 10199 rules are used for making files containing specific types of data (such as 9765 10200 executable files) and a file name with a recognized suffix indicates some … … 9767 10202 9768 10203 Special built-in dummy pattern rules are provided solely to recognize 9769 certain file names so that non terminal match-anything rules will not be10204 certain file names so that non-terminal match-anything rules will not be 9770 10205 considered. These dummy rules have no prerequisites and no recipes, and 9771 10206 they are ignored for all other purposes. For example, the built-in … … 9987 10422 @item 9988 10423 If any rule in that list is @emph{not} a match-anything rule, then 9989 remove all non terminal match-anything rules from the list.10424 remove all non-terminal match-anything rules from the list. 9990 10425 9991 10426 @item … … 10056 10491 prerequisites. @xref{Automatic Variables}. 10057 10492 10058 @node Archives, Features, Implicit Rules, Top10493 @node Archives, Extending make, Implicit Rules, Top 10059 10494 @chapter Using @code{make} to Update Archive Files 10060 10495 @cindex archive 10061 10496 10062 @dfn{Archive files} are files containing named sub files called10497 @dfn{Archive files} are files containing named sub-files called 10063 10498 @dfn{members}; they are maintained with the program @code{ar} and their 10064 10499 main use is as subroutine libraries for linking. … … 10283 10718 @w{%.@var{x}}} and @samp{@w{%.a}: @w{%.@var{x}}}.@refill 10284 10719 10285 @node Features, Missing, Archives, Top 10720 @node Extending make, Integrating make, Archives, Top 10721 @chapter Extending GNU @code{make} 10722 @cindex make extensions 10723 10724 GNU @code{make} provides many advanced capabilities, including many 10725 useful functions. However, it does not contain a complete programming 10726 language and so it has limitations. Sometimes these limitations can be 10727 overcome through use of the @code{shell} function to invoke a separate 10728 program, although this can be inefficient. 10729 10730 In cases where the built-in capabilities of GNU @code{make} are 10731 insufficient to your requirements there are two options for extending 10732 @code{make}. On systems where it's provided, you can utilize GNU 10733 Guile as an embedded scripting language (@pxref{Guile Integration,,GNU 10734 Guile Integration}). On systems which support dynamically loadable 10735 objects, you can write your own extension in any language (which can 10736 be compiled into such an object) and load it to provide extended 10737 capabilities (@pxref{load Directive, ,The @code{load} Directive}). 10738 10739 @menu 10740 * Guile Integration:: Using Guile as an embedded scripting language. 10741 * Loading Objects:: Loading dynamic objects as extensions. 10742 @end menu 10743 10744 @node Guile Integration, Loading Objects, Extending make, Extending make 10745 @section GNU Guile Integration 10746 @cindex Guile 10747 @cindex extensions, Guile 10748 10749 GNU @code{make} may be built with support for GNU Guile as an embedded 10750 extension language. Guile implements the Scheme language. A review 10751 of GNU Guile and the Scheme language and its features is beyond the 10752 scope of this manual: see the documentation for GNU Guile and Scheme. 10753 10754 You can determine if @code{make} contains support for Guile by 10755 examining the @code{.FEATURES} variable; it will contain the word 10756 @var{guile} if Guile support is available. 10757 10758 The Guile integration provides one new @code{make} function: @code{guile}. 10759 The @code{guile} function takes one argument which is first expanded 10760 by @code{make} in the normal fashion, then passed to the GNU Guile 10761 evaluator. The result of the evaluator is converted into a string and 10762 used as the expansion of the @code{guile} function in the makefile. 10763 10764 In addition, GNU @code{make} exposes Guile procedures for use in Guile 10765 scripts. 10766 10767 @menu 10768 * Guile Types:: Converting Guile types to @code{make} strings. 10769 * Guile Interface:: Invoking @code{make} functions from Guile. 10770 * Guile Example:: Example using Guile in @code{make}. 10771 @end menu 10772 10773 @node Guile Types, Guile Interface, Guile Integration, Guile Integration 10774 @subsection Conversion of Guile Types 10775 @cindex convert guile types 10776 @cindex guile, conversion of types 10777 @cindex types, conversion of 10778 10779 There is only one ``data type'' in @code{make}: a string. GNU Guile, 10780 on the other hand, provides a rich variety of different data types. 10781 An important aspect of the interface between @code{make} and GNU Guile 10782 is the conversion of Guile data types into @code{make} strings. 10783 10784 This conversion is relevant in two places: when a makefile invokes the 10785 @code{guile} function to evaluate a Guile expression, the result of 10786 that evaluation must be converted into a make string so it can be 10787 further evaluated by @code{make}. And secondly, when a Guile script 10788 invokes one of the procedures exported by @code{make} the argument 10789 provided to the procedure must be converted into a string. 10790 10791 The conversion of Guile types into @code{make} strings is as below: 10792 10793 @table @code 10794 @item #f 10795 False is converted into the empty string: in @code{make} conditionals 10796 the empty string is considered false. 10797 10798 @item #t 10799 True is converted to the string @samp{#t}: in @code{make} conditionals 10800 any non-empty string is considered true. 10801 10802 @item symbol 10803 @item number 10804 A symbol or number is converted into the string representation of that 10805 symbol or number. 10806 10807 @item character 10808 A printable character is converted to the same character. 10809 10810 @item string 10811 A string containing only printable characters is converted to the same 10812 string. 10813 10814 @item list 10815 A list is converted recursively according to the above rules. This 10816 implies that any structured list will be flattened (that is, a result 10817 of @samp{'(a b (c d) e)} will be converted to the @code{make} string 10818 @samp{a b c d e}). 10819 10820 @item other 10821 Any other Guile type results in an error. In future versions of 10822 @code{make}, other Guile types may be converted. 10823 10824 @end table 10825 10826 The translation of @samp{#f} (to the empty string) and @samp{#t} (to 10827 the non-empty string @samp{#t}) is designed to allow you to use Guile 10828 boolean results directly as @code{make} boolean conditions. For 10829 example: 10830 10831 @example 10832 $(if $(guile (access? "myfile" R_OK)),$(info myfile exists)) 10833 @end example 10834 10835 As a consequence of these conversion rules you must consider the 10836 result of your Guile script, as that result will be converted into a 10837 string and parsed by @code{make}. If there is no natural result for 10838 the script (that is, the script exists solely for its side-effects), 10839 you should add @samp{#f} as the final expression in order to avoid 10840 syntax errors in your makefile. 10841 10842 @node Guile Interface, Guile Example, Guile Types, Guile Integration 10843 @subsection Interfaces from Guile to @code{make} 10844 @cindex make interface to guile 10845 @cindex make procedures in guile 10846 10847 In addition to the @code{guile} function available in makefiles, 10848 @code{make} exposes some procedures for use in your Guile scripts. At 10849 startup @code{make} creates a new Guile module, @code{gnu make}, and 10850 exports these procedures as public interfaces from that module: 10851 10852 @table @code 10853 @item gmk-expand 10854 @findex gmk-expand 10855 This procedure takes a single argument which is converted into a 10856 string. The string is expanded by @code{make} using normal 10857 @code{make} expansion rules. The result of the expansion is converted 10858 into a Guile string and provided as the result of the procedure. 10859 10860 @item gmk-eval 10861 @findex gmk-eval 10862 This procedure takes a single argument which is converted into a 10863 string. The string is evaluated by @code{make} as if it were a 10864 makefile. This is the same capability available via the @code{eval} 10865 function (@pxref{Eval Function}). The result of the @code{gmk-eval} 10866 procedure is always the empty string. 10867 10868 Note that @code{gmk-eval} is not quite the same as using 10869 @code{gmk-expand} with the @code{eval} function: in the latter case 10870 the evaluated string will be expanded @emph{twice}; first by 10871 @code{gmk-expand}, then again by the @code{eval} function. 10872 10873 @end table 10874 10875 @node Guile Example, , Guile Interface, Guile Integration 10876 @subsection Example Using Guile in @code{make} 10877 @cindex Guile example 10878 @cindex example using Guile 10879 10880 Here is a very simple example using GNU Guile to manage writing to a 10881 file. These Guile procedures simply open a file, allow writing to the 10882 file (one string per line), and close the file. Note that because we 10883 cannot store complex values such as Guile ports in @code{make} 10884 variables, we'll keep the port as a global variable in the Guile 10885 interpreter. 10886 10887 You can create Guile functions easily using @code{define}/@code{endef} 10888 to create a Guile script, then use the @code{guile} function to 10889 internalize it: 10890 10891 @example 10892 @group 10893 define GUILEIO 10894 ;; A simple Guile IO library for GNU make 10895 10896 (define MKPORT #f) 10897 10898 (define (mkopen name mode) 10899 (set! MKPORT (open-file name mode)) 10900 #f) 10901 10902 (define (mkwrite s) 10903 (display s MKPORT) 10904 (newline MKPORT) 10905 #f) 10906 10907 (define (mkclose) 10908 (close-port MKPORT) 10909 #f) 10910 10911 #f 10912 endef 10913 10914 # Internalize the Guile IO functions 10915 $(guile $(GUILEIO)) 10916 @end group 10917 @end example 10918 10919 If you have a significant amount of Guile support code, you might 10920 consider keeping it in a different file (e.g., @file{guileio.scm}) and 10921 then loading it in your makefile using the @code{guile} function: 10922 10923 @example 10924 $(guile (load "guileio.scm")) 10925 @end example 10926 10927 An advantage to this method is that when editing @file{guileio.scm}, 10928 your editor will understand that this file contains Scheme syntax 10929 rather than makefile syntax. 10930 10931 Now you can use these Guile functions to create files. Suppose you 10932 need to operate on a very large list, which cannot fit on the command 10933 line, but the utility you're using accepts the list as input as well: 10934 10935 @example 10936 @group 10937 prog: $(PREREQS) 10938 @@$(guile (mkopen "tmp.out" "w")) \ 10939 $(foreach X,$^,$(guile (mkwrite "$(X)"))) \ 10940 $(guile (mkclose)) 10941 $(LINK) < tmp.out 10942 @end group 10943 @end example 10944 10945 A more comprehensive suite of file manipulation procedures is possible 10946 of course. You could, for example, maintain multiple output files at 10947 the same time by choosing a symbol for each one and using it as the 10948 key to a hash table, where the value is a port, then returning the 10949 symbol to be stored in a @code{make} variable. 10950 10951 @node Loading Objects, , Guile Integration, Extending make 10952 @section Loading Dynamic Objects 10953 @cindex loaded objects 10954 @cindex objects, loaded 10955 @cindex extensions, loading 10956 10957 @cartouche 10958 @quotation Warning 10959 The @code{load} directive and extension capability is considered a 10960 ``technology preview'' in this release of GNU make. We encourage you 10961 to experiment with this feature and we appreciate any feedback on it. 10962 However we cannot guarantee to maintain backward-compatibility in the 10963 next release. Consider using GNU Guile instead for extending GNU make 10964 (@pxref{Guile Function, ,The @code{guile} Function}). 10965 @end quotation 10966 @end cartouche 10967 10968 Many operating systems provide a facility for dynamically loading 10969 compiled objects. If your system provides this facility, GNU 10970 @code{make} can make use of it to load dynamic objects at runtime, 10971 providing new capabilities which may then be invoked by your makefile. 10972 10973 The @code{load} directive is used to load a dynamic object. Once the 10974 object is loaded, a ``setup'' function will be invoked to allow the 10975 object to initialize itself and register new facilities with GNU 10976 @code{make}. A dynamic object might include new @code{make} functions, 10977 for example, and the ``setup'' function would register them with GNU 10978 @code{make}'s function handling system. 10979 10980 @menu 10981 * load Directive:: Loading dynamic objects as extensions. 10982 * Remaking Loaded Objects:: How loaded objects get remade. 10983 * Loaded Object API:: Programmatic interface for loaded objects. 10984 * Loaded Object Example:: Example of a loaded object 10985 @end menu 10986 10987 @node load Directive, Remaking Loaded Objects, Loading Objects, Loading Objects 10988 @subsection The @code{load} Directive 10989 @cindex load directive 10990 @cindex extensions, load directive 10991 10992 Objects are loaded into GNU @code{make} by placing the @code{load} 10993 directive into your makefile. The syntax of the @code{load} directive 10994 is as follows: 10995 10996 @findex load 10997 @example 10998 load @var{object-file} @dots{} 10999 @end example 11000 11001 or: 11002 11003 @example 11004 load @var{object-file}(@var{symbol-name}) @dots{} 11005 @end example 11006 11007 The file @var{object-file} is dynamically loaded by GNU @code{make}. 11008 If @var{object-file} does not include a directory path then it is 11009 first looked for in the current directory. If it is not found there, 11010 or a directory path is included, then system-specific paths will be 11011 searched. If the load fails for any reason, @code{make} will print a 11012 message and exit. 11013 11014 If the load succeeds @code{make} will invoke an initializing function. 11015 11016 If @var{symbol-name} is provided, it will be used as the name of the 11017 initializing function. 11018 11019 If no @var{symbol-name} is provided, the initializing function name is 11020 created by taking the base file name of @var{object-file}, up to the 11021 first character which is not a valid symbol name character 11022 (alphanumerics and underscores are valid symbol name characters). To 11023 this prefix will be appended the suffix @code{_gmk_setup}. 11024 11025 More than one object file may be loaded with a single @code{load} 11026 directive, and both forms of @code{load} arguments may be used in the 11027 same directive. 11028 11029 The initializing function will be provided the file name and line 11030 number of the invocation of the @code{load} operation. It should 11031 return a value of type @code{int}, which must be @code{0} on failure 11032 and non-@code{0} on success. If the return value is @code{-1}, then 11033 GNU make will @emph{not} attempt to rebuild the object file 11034 (@pxref{Remaking Loaded Objects, ,How Loaded Objects Are Remade}). 11035 11036 For example: 11037 11038 @example 11039 load ../mk_funcs.so 11040 @end example 11041 11042 will load the dynamic object @file{../mk_funcs.so}. After the object 11043 is loaded, @code{make} will invoke the function (assumed to be defined 11044 by the shared object) @code{mk_funcs_gmk_setup}. 11045 11046 On the other hand: 11047 11048 @example 11049 load ../mk_funcs.so(init_mk_func) 11050 @end example 11051 11052 will load the dynamic object @file{../mk_funcs.so}. After the object 11053 is loaded, @code{make} will invoke the function @code{init_mk_func}. 11054 11055 Regardless of how many times an object file appears in a @code{load} 11056 directive, it will only be loaded (and its setup function will only 11057 be invoked) once. 11058 11059 @vindex .LOADED 11060 After an object has been successfully loaded, its file name is 11061 appended to the @code{.LOADED} variable. 11062 11063 @findex -load 11064 If you would prefer that failure to load a dynamic object not be 11065 reported as an error, you can use the @code{-load} directive instead 11066 of @code{load}. GNU @code{make} will not fail and no message will be 11067 generated if an object fails to load. The failed object is not added 11068 to the @code{.LOADED} variable, which can then be consulted to 11069 determine if the load was successful. 11070 11071 @node Remaking Loaded Objects, Loaded Object API, load Directive, Loading Objects 11072 @subsection How Loaded Objects Are Remade 11073 @cindex updating loaded objects 11074 @cindex remaking loaded objects 11075 @cindex loaded objects, remaking of 11076 11077 Loaded objects undergo the same re-make procedure as makefiles 11078 (@pxref{Remaking Makefiles, ,How Makefiles Are Remade}). If any 11079 loaded object is recreated, then @code{make} will start from scratch 11080 and re-read all the makefiles, and reload the object files again. It 11081 is not necessary for the loaded object to do anything special to 11082 support this.@refill 11083 11084 It's up to the makefile author to provide the rules needed for 11085 rebuilding the loaded object. 11086 11087 @node Loaded Object API, Loaded Object Example, Remaking Loaded Objects, Loading Objects 11088 @subsection Loaded Object Interface 11089 @cindex loaded object API 11090 @cindex interface for loaded objects 11091 11092 @cartouche 11093 @quotation Warning 11094 For this feature to be useful your extensions will need to invoke 11095 various functions internal to GNU @code{make}. The programming 11096 interfaces provided in this release should not be considered stable: 11097 functions may be added, removed, or change calling signatures or 11098 implementations in future versions of GNU @code{make}. 11099 @end quotation 11100 @end cartouche 11101 11102 To be useful, loaded objects must be able to interact with GNU 11103 @code{make}. This interaction includes both interfaces the loaded 11104 object provides to makefiles and also interfaces @code{make} provides 11105 to the loaded object to manipulate @code{make}'s operation. 11106 11107 The interface between loaded objects and @code{make} is defined by the 11108 @file{gnumake.h} C header file. All loaded objects written in C 11109 should include this header file. Any loaded object not written in C 11110 will need to implement the interface defined in this header file. 11111 11112 Typically, a loaded object will register one or more new GNU 11113 @code{make} functions using the @code{gmk_add_function} routine from 11114 within its setup function. The implementations of these @code{make} 11115 functions may make use of the @code{gmk_expand} and @code{gmk_eval} 11116 routines to perform their tasks, then optionally return a string as 11117 the result of the function expansion. 11118 11119 @subsubheading Loaded Object Licensing 11120 @cindex loaded object licensing 11121 @cindex plugin_is_GPL_compatible 11122 11123 Every dynamic extension should define the global symbol 11124 @code{plugin_is_GPL_compatible} to assert that it has been licensed 11125 under a GPL-compatible license. If this symbol does not exist, 11126 @code{make} emits a fatal error and exits when it tries to load your 11127 extension. 11128 11129 The declared type of the symbol should be @code{int}. It does not need 11130 to be in any allocated section, though. The code merely asserts that 11131 the symbol exists in the global scope. Something like this is enough: 11132 11133 @example 11134 int plugin_is_GPL_compatible; 11135 @end example 11136 11137 @subsubheading Data Structures 11138 11139 @table @code 11140 @item gmk_floc 11141 This structure represents a filename/location pair. It is provided 11142 when defining items, so GNU @code{make} can inform the user later 11143 where the definition occurred if necessary. 11144 @end table 11145 11146 @subsubheading Registering Functions 11147 @findex gmk_add_function 11148 11149 There is currently one way for makefiles to invoke operations provided 11150 by the loaded object: through the @code{make} function call 11151 interface. A loaded object can register one or more new functions 11152 which may then be invoked from within the makefile in the same way as 11153 any other function. 11154 11155 Use @code{gmk_add_function} to create a new @code{make} function. Its 11156 arguments are as follows: 11157 11158 @table @code 11159 @item name 11160 The function name. This is what the makefile should use to invoke the 11161 function. The name must be between 1 and 255 characters long and it 11162 may only contain alphanumeric, period (@samp{.}), dash (@samp{-}), and 11163 underscore (@samp{_}) characters. It may not begin with a period. 11164 11165 @item func_ptr 11166 A pointer to a function that @code{make} will invoke when it expands 11167 the function in a makefile. This function must be defined by the 11168 loaded object. 11169 11170 @item min_args 11171 The minimum number of arguments the function will accept. Must be 11172 between 0 and 255. GNU @code{make} will check this and fail before 11173 invoking @code{func_ptr} if the function was invoked with too few 11174 arguments. 11175 11176 @item max_args 11177 The maximum number of arguments the function will accept. Must be 11178 between 0 and 255. GNU @code{make} will check this and fail before 11179 invoking @code{func_ptr} if the function was invoked with too few 11180 arguments. If the value is 0, then any number of arguments is 11181 accepted. If the value is greater than 0, then it must be greater 11182 than or equal to @code{min_args}. 11183 11184 @item flags 11185 Flags that specify how this function will operate; the desired flags 11186 should be OR'd together. If the @code{GMK_FUNC_NOEXPAND} flag is 11187 given then the function arguments will not be expanded before the 11188 function is called; otherwise they will be expanded first. 11189 @end table 11190 11191 @subsubheading Registered Function Interface 11192 @findex gmk_func_ptr 11193 11194 A function registered with @code{make} must match the 11195 @code{gmk_func_ptr} type. It will be invoked with three parameters: 11196 @code{name} (the name of the function), @code{argc} (the number of 11197 arguments to the function), and @code{argv} (an array of pointers to 11198 arguments to the function). The last pointer (that is, 11199 @code{argv[argc]}) will be null (@code{0}). 11200 11201 The return value of the function is the result of expanding the 11202 function. If the function expands to nothing the return value may be 11203 null. Otherwise, it must be a pointer to a string created with 11204 @code{gmk_alloc}. Once the function returns, @code{make} owns this 11205 string and will free it when appropriate; it cannot be accessed by the 11206 loaded object. 11207 11208 @subsubheading GNU @code{make} Facilities 11209 11210 There are some facilities exported by GNU @code{make} for use by 11211 loaded objects. Typically these would be run from within the 11212 setup function and/or the functions registered via 11213 @code{gmk_add_function}, to retrieve or modify the data @code{make} 11214 works with. 11215 11216 @table @code 11217 @item gmk_expand 11218 @findex gmk_expand 11219 This function takes a string and expands it using @code{make} 11220 expansion rules. The result of the expansion is returned in a 11221 nil-terminated string buffer. The caller is responsible for calling 11222 @code{gmk_free} with a pointer to the returned buffer when done. 11223 11224 @item gmk_eval 11225 @findex gmk_eval 11226 This function takes a buffer and evaluates it as a segment of makefile 11227 syntax. This function can be used to define new variables, new rules, 11228 etc. It is equivalent to using the @code{eval} @code{make} function. 11229 @end table 11230 11231 Note that there is a difference between @code{gmk_eval} and calling 11232 @code{gmk_expand} with a string using the @code{eval} function: in 11233 the latter case the string will be expanded @emph{twice}; once by 11234 @code{gmk_expand} and then again by the @code{eval} function. Using 11235 @code{gmk_eval} the buffer is only expanded once, at most (as it's 11236 read by the @code{make} parser). 11237 11238 @subsubheading Memory Management 11239 11240 Some systems allow for different memory management schemes. Thus you 11241 should never pass memory that you've allocated directly to any 11242 @code{make} function, nor should you attempt to directly free any 11243 memory returned to you by any @code{make} function. Instead, use the 11244 @code{gmk_alloc} and @code{gmk_free} functions. 11245 11246 In particular, the string returned to @code{make} by a function 11247 registered using @code{gmk_add_function} @emph{must} be allocated 11248 using @code{gmk_alloc}, and the string returned from the @code{make} 11249 @code{gmk_expand} function @emph{must} be freed (when no longer 11250 needed) using @code{gmk_free}. 11251 11252 @table @code 11253 @item gmk_alloc 11254 @findex gmk_alloc 11255 Return a pointer to a newly-allocated buffer. This function will 11256 always return a valid pointer; if not enough memory is available 11257 @code{make} will exit. 11258 11259 @item gmk_free 11260 @findex gmk_free 11261 Free a buffer returned to you by @code{make}. Once the 11262 @code{gmk_free} function returns the string will no longer be valid. 11263 @end table 11264 11265 @node Loaded Object Example, , Loaded Object API, Loading Objects 11266 @subsection Example Loaded Object 11267 @cindex loaded object example 11268 @cindex example of loaded objects 11269 11270 Let's suppose we wanted to write a new GNU @code{make} function that 11271 would create a temporary file and return its name. We would like our 11272 function to take a prefix as an argument. First we can write the 11273 function in a file @file{mk_temp.c}: 11274 11275 @example 11276 @group 11277 #include <stdlib.h> 11278 #include <stdlib.h> 11279 #include <stdio.h> 11280 #include <string.h> 11281 #include <unistd.h> 11282 #include <errno.h> 11283 11284 #include <gnumake.h> 11285 11286 int plugin_is_GPL_compatible; 11287 11288 char * 11289 gen_tmpfile(const char *nm, int argc, char **argv) 11290 @{ 11291 int fd; 11292 11293 /* Compute the size of the filename and allocate space for it. */ 11294 int len = strlen (argv[0]) + 6 + 1; 11295 char *buf = gmk_alloc (len); 11296 11297 strcpy (buf, argv[0]); 11298 strcat (buf, "XXXXXX"); 11299 11300 fd = mkstemp(buf); 11301 if (fd >= 0) 11302 @{ 11303 /* Don't leak the file descriptor. */ 11304 close (fd); 11305 return buf; 11306 @} 11307 11308 /* Failure. */ 11309 fprintf (stderr, "mkstemp(%s) failed: %s\n", buf, strerror (errno)); 11310 gmk_free (buf); 11311 return NULL; 11312 @} 11313 11314 int 11315 mk_temp_gmk_setup () 11316 @{ 11317 /* Register the function with make name "mk-temp". */ 11318 gmk_add_function ("mk-temp", gen_tmpfile, 1, 1, 1); 11319 return 1; 11320 @} 11321 @end group 11322 @end example 11323 11324 Next, we will write a makefile that can build this shared object, load 11325 it, and use it: 11326 11327 @example 11328 @group 11329 all: 11330 @@echo Temporary file: $(mk-temp tmpfile.) 11331 11332 load mk_temp.so 11333 11334 mk_temp.so: mk_temp.c 11335 $(CC) -shared -fPIC -o $@ $< 11336 @end group 11337 @end example 11338 11339 On MS-Windows, due to peculiarities of how shared objects are 11340 produced, the compiler needs to scan the @dfn{import library} produced 11341 when building @code{make}, typically called 11342 @file{libgnumake-@var{version}.dll.a}, where @var{version} is the 11343 version of the load object API. So the recipe to produce a shared 11344 object will look on Windows like this (assuming the API version is 1): 11345 11346 @example 11347 @group 11348 mk_temp.dll: mk_temp.c 11349 $(CC) -shared -o $@ $< -lgnumake-1 11350 @end group 11351 @end example 11352 11353 Now when you run @code{make} you'll see something like: 11354 11355 @example 11356 $ make 11357 cc -shared -fPIC -o mk_temp.so mk_temp.c 11358 Temporary filename: tmpfile.A7JEwd 11359 @end example 11360 11361 @node Integrating make, Features, Extending make, Top 11362 @chapter Integrating GNU @code{make} 11363 @cindex make integration 11364 11365 GNU @code{make} is often one component in a larger system of tools, 11366 including integrated development environments, compiler toolchains, 11367 and others. The role of @code{make} is to start commands and 11368 determine whether they succeeded or not: no special integration is 11369 needed to accomplish that. However, sometimes it is convenient to 11370 bind @code{make} more tightly with other parts of the system, both 11371 higher-level (tools that invoke @code{make}) and lower-level (tools 11372 that @code{make} invokes). 11373 11374 @menu 11375 * Job Slots:: Share job slots with GNU @code{make}. 11376 * Terminal Output:: Control output to terminals. 11377 @end menu 11378 11379 @node Job Slots, Terminal Output, Integrating make, Integrating make 11380 @section Sharing Job Slots with GNU @code{make} 11381 @cindex job slots, sharing 11382 @cindex tools, sharing job slots 11383 11384 GNU @code{make} has the ability to run multiple recipes in parallel 11385 (@pxref{Parallel, ,Parallel Execution}) and to cap the total number of 11386 parallel jobs even across recursive invocations of @code{make} 11387 (@pxref{Options/Recursion, ,Communicating Options to a 11388 Sub-@code{make}}). Tools that @code{make} invokes which are also able 11389 to run multiple operations in parallel, either using multiple threads 11390 or multiple processes, can be enhanced to participate in GNU 11391 @code{make}'s job management facility to ensure that the total number 11392 of active threads/processes running on the system does not exceed the 11393 maximum number of slots provided to GNU @code{make}. @refill 11394 11395 @cindex jobserver 11396 GNU @code{make} uses a method called the ``jobserver'' to control the 11397 number of active jobs across recursive invocations. The actual 11398 implementation of the jobserver varies across different operating 11399 systems, but some fundamental aspects are always true. 11400 11401 First, only command lines that @code{make} understands to be recursive 11402 invocations of @code{make} (@pxref{MAKE Variable, ,How the @code{MAKE} 11403 Variable Works}) will have access to the jobserver. When writing 11404 makefiles you must be sure to mark the command as recursive (most 11405 commonly by prefixing the command line with the @code{+} indicator 11406 (@pxref{Recursion, ,Recursive Use of @code{make}}). 11407 11408 Second, @code{make} will provide information necessary for accessing 11409 the jobserver through the environment to its children, in the 11410 @code{MAKEFLAGS} environment variable. Tools which want to 11411 participate in the jobserver protocol will need to parse this 11412 environment variable, as described in subsequent sections. 11413 11414 Third, every command @code{make} starts has one implicit job slot 11415 reserved for it before it starts. Any tool which wants to participate 11416 in the jobserver protocol should assume it can always run one job 11417 without having to contact the jobserver at all. 11418 11419 Finally, it's critical that tools that participate in the jobserver 11420 protocol return the exact number of slots they obtained from the 11421 jobserver back to the jobserver before they exit, even under error 11422 conditions. Remember that the implicit job slot should @strong{not} 11423 be returned to the jobserver! Returning too few slots means that 11424 those slots will be lost for the rest of the build process; returning 11425 too many slots means that extra slots will be available. The 11426 top-level @code{make} command will print an error message at the end 11427 of the build if it detects an incorrect number of slots available in 11428 the jobserver. 11429 11430 As an example, suppose you are implementing a linker which provides 11431 for multithreaded operation. You would like to enhance the linker so 11432 that if it is invoked by GNU @code{make} it can participate in the 11433 jobserver protocol to control how many threads are used during link. 11434 First you will need to modify the linker to determine if the 11435 @code{MAKEFLAGS} environment variable is set. Next you will need to 11436 parse the value of that variable to determine if the jobserver is 11437 available, and how to access it. If it is available then you can 11438 access it to obtain job slots controlling how much parallelism your 11439 tool can use. Once done your tool must return those job slots back to 11440 the jobserver. 11441 11442 @menu 11443 * POSIX Jobserver:: Using the jobserver on POSIX systems. 11444 * Windows Jobserver:: Using the jobserver on Windows systems. 11445 @end menu 11446 11447 @node POSIX Jobserver, Windows Jobserver, Job Slots, Job Slots 11448 @subsection POSIX Jobserver Interaction 11449 @cindex jobserver on POSIX 11450 11451 On POSIX systems the jobserver is implemented as a simple UNIX pipe. 11452 The pipe will be pre-loaded with one single-character token for each 11453 available job. To obtain an extra slot you must read a single 11454 character from the jobserver pipe; to release a slot you must write a 11455 single character back into the jobserver pipe. 11456 11457 To access the pipe you must parse the @code{MAKEFLAGS} variable and 11458 look for the argument string @code{--jobserver-auth=R,W} where 11459 @samp{R} and @samp{W} are non-negative integers representing file 11460 descriptors: @samp{R} is the read file descriptor and @samp{W} is the 11461 write file descriptor. 11462 11463 It's important that when you release the job slot, you write back the 11464 same character you read from the pipe for that slot. Don't assume 11465 that all tokens are the same character; different characters may have 11466 different meanings to GNU @code{make}. The order is not important, 11467 since @code{make} has no idea in what order jobs will complete anyway. 11468 11469 There are various error conditions you must consider to ensure your 11470 implementation is robust: 11471 11472 @itemize @bullet 11473 @item 11474 Usually you will have a command-line argument controlling the parallel 11475 operation of your tool. Consider whether your tool should detect 11476 situations where both the jobserver and the command-line argument are 11477 specified, and how it should react. 11478 11479 @item 11480 If your tool determines that the @code{--jobserver-auth} option is 11481 available in @code{MAKEFLAGS} but that the file descriptors specified 11482 are closed, this means that the calling @code{make} process did not 11483 think that your tool was a recursive @code{make} invocation (e.g., the 11484 command line was not prefixed with a @code{+} character). You should 11485 notify your users of this situation. 11486 11487 @item 11488 Your tool should also examine the first word of the @code{MAKEFLAGS} 11489 variable and look for the character @code{n}. If this character is 11490 present then @code{make} was invoked with the @samp{-n} option and 11491 your tool should stop without performing any operations. 11492 11493 @item 11494 Your tool should be sure to write back the tokens it read, even under 11495 error conditions. This includes not only errors in your tool but also 11496 outside influences such as interrupts (@code{SIGINT}), etc. You may 11497 want to install signal handlers to manage this write-back. 11498 @end itemize 11499 11500 @node Windows Jobserver, , POSIX Jobserver, Job Slots 11501 @subsection Windows Jobserver Interaction 11502 @cindex jobserver on Windows 11503 11504 On Windows systems the jobserver is implemented as a named semaphore. 11505 The semaphore will be set with an initial count equal to the number of 11506 available slots; to obtain a slot you must wait on the semaphore (with 11507 or without a timeout). To release a slot, release the semaphore. 11508 11509 To access the semaphore you must parse the @code{MAKEFLAGS} variable and 11510 look for the argument string @code{--jobserver-auth=NAME} where 11511 @samp{NAME} is the name of the named semaphore. Use this name with 11512 @code{OpenSemaphore} to create a handle to the semaphore. 11513 11514 There are various error conditions you must consider to ensure your 11515 implementation is robust: 11516 11517 @itemize @bullet 11518 @item 11519 Usually you will have a command-line argument controlling the parallel 11520 operation of your tool. Consider whether your tool should detect 11521 situations where both the jobserver and the command-line argument are 11522 specified, and how it should react. 11523 11524 @item 11525 Your tool should be sure to release the semaphore for the tokens it 11526 read, even under error conditions. This includes not only errors in 11527 your tool but also outside influences such as interrupts 11528 (@code{SIGINT}), etc. You may want to install signal handlers to 11529 manage this write-back. 11530 @end itemize 11531 11532 @node Terminal Output, , Job Slots, Integrating make 11533 @section Synchronized Terminal Output 11534 @cindex parallel output to terminal 11535 @cindex terminal, output to 11536 11537 Normally GNU @code{make} will invoke all commands with access to the 11538 same standard and error outputs that @code{make} itself was started 11539 with. A number of tools will detect whether the output is a terminal 11540 or not-a-terminal, and use this information to change the output 11541 style. For example if the output goes to a terminal the tool may add 11542 control characters that set color, or even change the location of the 11543 cursor. If the output is not going to a terminal then these special 11544 control characters are not emitted so that they don't corrupt log 11545 files, etc. 11546 11547 The @code{--output-sync} (@pxref{Parallel Output, ,Output During 11548 Parallel Output}) option will defeat the terminal detection. When 11549 output synchronization is enabled GNU @code{make} arranges for all 11550 command output to be written to a file, so that its output can be 11551 written as a block without interference from other commands. This 11552 means that all tools invoked by @code{make} will believe that their 11553 output is not going to be displayed on a terminal, even when it will 11554 be (because @code{make} will display it there after the command is 11555 completed). 11556 11557 In order to facilitate tools which would like to determine whether or 11558 not their output will be displayed on a terminal, GNU @code{make} will 11559 set the @code{MAKE_TERMOUT} and @code{MAKE_TERMERR} environment 11560 variables before invoking any commands. Tools which would like to 11561 determine whether standard or error output (respectively) will be 11562 displayed on a terminal can check these environment variables to 11563 determine if they exist and contain a non-empty value. If so the tool 11564 can assume that the output will (eventually) be displayed on a 11565 terminal. If the variables are not set or have an empty value, then 11566 the tool should fall back to its normal methods of detecting whether 11567 output is going to a terminal or not. 11568 11569 The content of the variables can be parsed to determine the type of 11570 terminal which will be used to display the output. 11571 11572 Similarly, environments which invoke @code{make} and would like to 11573 capture the output and eventually display it on a terminal (or some 11574 display which can interpret terminal control characters) can set these 11575 variables before invoking @code{make}. GNU @code{make} will not 11576 modify these environment variables if they already exist when it 11577 starts. 11578 11579 @node Features, Missing, Integrating make, Top 10286 11580 @chapter Features of GNU @code{make} 10287 11581 @cindex features of GNU @code{make} … … 10350 11644 10351 11645 @item 10352 The arrangement of lines and backslash -newline combinations in11646 The arrangement of lines and backslash/newline combinations in 10353 11647 recipes is retained when the recipes are printed, so they appear as 10354 11648 they do in the makefile, except for the stripping of initial … … 10393 11687 10394 11688 @item 11689 A number of different build tools that support parallelism also 11690 support collecting output and displaying as a single block. 11691 @xref{Parallel Output, ,Output During Parallel Execution}. 11692 11693 @item 10395 11694 Modified variable references using pattern substitution come from 10396 11695 SunOS 4. @xref{Reference, ,Basics of Variable References}. … … 10421 11720 @code{-include} directive.) The same feature appears with the name 10422 11721 @code{sinclude} in SGI @code{make} and perhaps others. 11722 11723 @item 11724 The @code{!=} shell assignment operator exists in many BSD of 11725 @code{make} and is purposefully implemented here to behave identically 11726 to those implementations. 11727 11728 @item 11729 Various build management tools are implemented using scripting 11730 languages such as Perl or Python and thus provide a natural embedded 11731 scripting language, similar to GNU @code{make}'s integration of GNU 11732 Guile. 10423 11733 @end itemize 10424 11734 … … 10524 11834 @item 10525 11835 Various new built-in implicit rules. 10526 @xref{Catalogue of Rules, ,Catalogue of ImplicitRules}.11836 @xref{Catalogue of Rules, ,Catalogue of Built-In Rules}. 10527 11837 10528 11838 @item 10529 The built-in variable @samp{MAKE_VERSION} gives the version number of 10530 @code{make}. 10531 @vindex MAKE_VERSION 11839 Load dynamic objects which can modify the behavior of @code{make}. 11840 @xref{Loading Objects, ,Loading Dynamic Objects}. 10532 11841 @end itemize 10533 11842 … … 10550 11859 10551 11860 This feature was not put into GNU @code{make} because of the 10552 non modularity of putting knowledge into @code{make} of the internal11861 non-modularity of putting knowledge into @code{make} of the internal 10553 11862 format of archive file symbol tables. 10554 11863 @xref{Archive Symbols, ,Updating Archive Symbol Directories}. … … 10648 11957 This appendix summarizes the directives, text manipulation functions, 10649 11958 and special variables which GNU @code{make} understands. 10650 @xref{Special Targets}, @ref{Catalogue of Rules, ,Catalogue of ImplicitRules},11959 @xref{Special Targets}, @ref{Catalogue of Rules, ,Catalogue of Built-In Rules}, 10651 11960 and @ref{Options Summary, ,Summary of Options}, 10652 11961 for other summaries. … … 10658 11967 @itemx define @var{variable} = 10659 11968 @itemx define @var{variable} := 11969 @itemx define @var{variable} ::= 10660 11970 @itemx define @var{variable} += 10661 11971 @itemx define @var{variable} ?= … … 10872 12182 @xref{Eval Function, ,The @code{eval} Function}. 10873 12183 12184 @item $(file @var{op} @var{filename},@var{text}) 12185 Expand the arguments, then open the file @var{filename} using mode 12186 @var{op} and write @var{text} to that file.@* 12187 @xref{File Function, ,The @code{file} Function}. 12188 10874 12189 @item $(value @var{var}) 10875 12190 Evaluates to the contents of the variable @var{var}, with no expansion … … 10971 12286 @code{MAKE} Variable Works}. 10972 12287 12288 @item MAKE_VERSION 12289 12290 The built-in variable @samp{MAKE_VERSION} expands to the version 12291 number of the GNU @code{make} program. 12292 @vindex MAKE_VERSION 12293 12294 @item MAKE_HOST 12295 12296 The built-in variable @samp{MAKE_HOST} expands to a string 12297 representing the host that GNU @code{make} was built to run on. 12298 @vindex MAKE_HOST 12299 10973 12300 @item MAKELEVEL 10974 12301 … … 10987 12314 through the environment from its parent. 10988 12315 12316 @item GNUMAKEFLAGS 12317 12318 Other flags parsed by @code{make}. You can set this in the environment or 12319 a makefile to set @code{make} command-line flags. GNU @code{make} 12320 never sets this variable itself. This variable is only needed if 12321 you'd like to set GNU @code{make}-specific flags in a POSIX-compliant 12322 makefile. This variable will be seen by GNU @code{make} and ignored 12323 by other @code{make} implementations. It's not needed if you only use 12324 GNU @code{make}; just use @code{MAKEFLAGS} directly. 12325 @xref{Options/Recursion, ,Communicating Options to a Sub-@code{make}}. 12326 10989 12327 @item MAKECMDGOALS 10990 12328 … … 10995 12333 @item CURDIR 10996 12334 10997 Set to the pathname of the current working directory (after all10998 @code{-C} options are processed, if any). Setting this variable has no 10999 effect on the operation of @code{make}.@*12335 Set to the absolute pathname of the current working directory (after 12336 all @code{-C} options are processed, if any). Setting this variable 12337 has no effect on the operation of @code{make}.@* 11000 12338 @xref{Recursion, ,Recursive Use of @code{make}}. 11001 12339 … … 11025 12363 Error messages are all either prefixed with the name of the program 11026 12364 (usually @samp{make}), or, if the error is found in a makefile, the name 11027 of the file and line number containing the problem.12365 of the file and line number containing the problem. 11028 12366 11029 12367 In the table below, these common prefixes are left off. … … 11039 12377 signal of some type). @xref{Errors, ,Errors in Recipes}. 11040 12378 11041 If no @code{***} is attached to the message, then the sub process failed12379 If no @code{***} is attached to the message, then the sub-process failed 11042 12380 but the rule in the makefile was prefixed with the @code{-} special 11043 12381 character, so @code{make} ignored the error. … … 11079 12417 If you want that file to be built, you will need to add a rule to your 11080 12418 makefile describing how that target can be built. Other possible 11081 sources of this problem are typos in the makefile (if that file name is12419 sources of this problem are typos in the makefile (if that file name is 11082 12420 wrong) or a corrupted source tree (if that file is not supposed to be 11083 12421 built, but rather only a prerequisite). … … 11113 12451 This means you've defined a normal (recursive) @code{make} variable 11114 12452 @var{xxx} that, when it's expanded, will refer to itself (@var{xxx}). 11115 This is not allowed; either use simply-expanded variables (@ code{:=}) or11116 use the append operator (@code{+=}). @xref{Using Variables, ,How to Use 11117 Variables }.12453 This is not allowed; either use simply-expanded variables (@samp{:=} 12454 or @samp{::=}) or use the append operator (@samp{+=}). @xref{Using 12455 Variables, ,How to Use Variables}. 11118 12456 11119 12457 @item Unterminated variable reference. Stop. … … 11130 12468 @itemx target pattern contains no `%'. Stop. 11131 12469 @itemx mixed implicit and static pattern rules. Stop. 11132 These are generated for malformed static pattern rules. The first means 11133 there's no pattern in the target section of the rule; the second means 11134 there are multiple patterns in the target section; the third means 11135 the target doesn't contain a pattern character (@code{%}); and the 11136 fourth means that all three parts of the static pattern rule contain 11137 pattern characters (@code{%})--only the first two parts should. 12470 These are generated for malformed static pattern rules. The first 12471 means there's no pattern in the target section of the rule; the second 12472 means there are multiple patterns in the target section; the third 12473 means the target doesn't contain a pattern character (@code{%}); and 12474 the fourth means that all three parts of the static pattern rule 12475 contain pattern characters (@code{%})--only the first two parts 12476 should. If you see these errors and you aren't trying to create a 12477 static pattern rule, check the value of any variables in your target 12478 and prerequisite lists to be sure they do not contain colons. 11138 12479 @xref{Static Usage, ,Syntax of Static Pattern Rules}. 11139 12480 … … 11168 12509 11169 12510 Here is the makefile for the GNU @code{tar} program. This is a 11170 moderately complex makefile. 12511 moderately complex makefile. The first line uses a @code{#!} setting 12512 to allow the makefile to be executed directly. 11171 12513 11172 12514 Because it is the first target, the default goal is @samp{all}. An … … 11204 12546 @example 11205 12547 @group 12548 #!/usr/bin/make -f 11206 12549 # Generated automatically from Makefile.in by configure. 11207 12550 # Un*x Makefile for GNU tar program.
Note:
See TracChangeset
for help on using the changeset viewer.