Changeset 503 in kBuild for trunk/src/gmake/doc/make.texi
- Timestamp:
- Sep 15, 2006 5:09:38 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/doc/make.texi
r281 r503 2 2 @c %**start of header 3 3 @setfilename make.info 4 5 @include version.texi 6 @set EDITION 0.70 7 @set RCSID $Id: make.texi,v 1.45 2006/04/01 06:36:40 psmith Exp $ 8 4 9 @settitle GNU @code{make} 5 10 @setchapternewpage odd 6 @c %**end of header7 8 @c FSF publishers: format makebook.texi instead of using this file directly.9 10 @set RCSID $Id: make.texi,v 1.30 2005/05/13 12:45:31 psmith Exp $11 @set EDITION 0.7012 @set VERSION 3.8113 @set UPDATED 07 May 200514 @set UPDATE-MONTH May 200515 @c ISBN provided by Lisa M. Opus Goldstein <[email protected]>, 5 May 200416 @set ISBN 1-882114-83-517 18 @c finalout19 20 @c ISPELL CHECK: done, 10 June 1993 --roland21 @c ISPELL CHECK: done, 2000-06-25 --Martin Buchholz22 23 11 @c Combine the variable and function indices: 24 12 @syncodeindex vr fn 25 13 @c Combine the program and concept indices: 26 14 @syncodeindex pg cp 15 @c FSF publishers: format makebook.texi instead of using this file directly. 16 @c ISBN provided by Lisa M. Opus Goldstein <[email protected]>, 5 May 2004 17 @set ISBN 1-882114-83-5 18 @c %**end of header 19 20 @copying 21 This file documents the GNU @code{make} utility, which determines 22 automatically which pieces of a large program need to be recompiled, 23 and issues the commands to recompile them. 24 25 This is Edition @value{EDITION}, last updated @value{UPDATED}, 26 of @cite{The GNU Make Manual}, for GNU @code{make} version @value{VERSION}. 27 28 Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 29 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006 30 Free Software Foundation, Inc. 31 32 @quotation 33 Permission is granted to copy, distribute and/or modify this document 34 under the terms of the GNU Free Documentation License, Version 1.2 or 35 any later version published by the Free Software Foundation; with no 36 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,'' 37 and with the Back-Cover Texts as in (a) below. A copy of the 38 license is included in the section entitled ``GNU Free Documentation 39 License.'' 40 41 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify 42 this GNU Manual, like GNU software. Copies published by the Free 43 Software Foundation raise funds for GNU development.'' 44 @end quotation 45 @end copying 46 47 @c finalout 48 49 @c ISPELL CHECK: done, 10 June 1993 --roland 50 @c ISPELL CHECK: done, 2000-06-25 --Martin Buchholz 51 27 52 28 53 @dircategory GNU Packages … … 30 55 * Make: (make). Remake files automatically. 31 56 @end direntry 32 33 @ifnottex34 This file documents the GNU Make utility, which determines35 automatically which pieces of a large program need to be recompiled,36 and issues the commands to recompile them.37 38 This is Edition @value{EDITION}, last updated @value{UPDATED},39 of @cite{The GNU Make Manual}, for @code{make}, Version @value{VERSION}.40 41 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,42 1998, 1999, 2000, 2002, 2003, 2004, 200543 Free Software Foundation, Inc.44 45 Permission is granted to copy, distribute and/or modify this document46 under the terms of the GNU Free Documentation License, Version 1.1 or47 any later version published by the Free Software Foundation; with no48 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover49 Texts. A copy of the license is included in the section entitled50 ``GNU Free Documentation License''.51 @end ifnottex52 57 53 58 @iftex … … 58 63 @subtitle A Program for Directing Recompilation 59 64 @subtitle GNU @code{make} Version @value{VERSION} 60 @subtitle @value{UPDATE -MONTH}65 @subtitle @value{UPDATED-MONTH} 61 66 @author Richard M. Stallman, Roland McGrath, Paul D. Smith 62 67 @page 63 68 @vskip 0pt plus 1filll 64 Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 65 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc. 69 @insertcopying 66 70 @sp 2 67 71 Published by the Free Software Foundation @* 68 5 9 Temple Place -- Suite 330,@*69 Boston, MA 0211 1-1307USA @*72 51 Franklin St. -- Fifth Floor @* 73 Boston, MA 02110-1301 USA @* 70 74 ISBN @value{ISBN} @* 71 72 Permission is granted to copy, distribute and/or modify this document73 under the terms of the GNU Free Documentation License, Version 1.1 or74 any later version published by the Free Software Foundation; with the75 Invariant Sections being ``GNU General Public License'', the Front-Cover76 Texts being ``A GNU Manual'', and with the Back-Cover Texts being as in77 (a) below. A copy of the license is included in the section entitled78 ``GNU Free Documentation License''.79 80 (a) The FSF's Back-Cover Text is:81 82 @quotation83 You have freedom to copy and modify this GNU Manual, like GNU84 software. Copies published by the Free Software Foundation raise85 funds for GNU development.86 @end quotation87 75 @sp 2 88 76 Cover art by Etienne Suvasa. 89 77 @end titlepage 90 @page 78 79 @summarycontents 80 @contents 91 81 92 82 @ifnottex 93 83 @node Top, Overview, (dir), (dir) 94 @top Make 95 96 The GNU @code{make} utility automatically determines which pieces of a 97 large program need to be recompiled, and issues the commands to 98 recompile them.@refill 99 100 This edition of the @cite{GNU Make Manual}, 101 last updated @value{UPDATED}, 102 documents GNU @code{make} Version @value{VERSION}.@refill 103 104 This manual describes @code{make} and contains the following chapters:@refill 84 @top GNU @code{make} 85 86 @insertcopying 105 87 @end ifnottex 106 88 … … 174 156 * Phony Targets:: Using a target that is not a real file's name. 175 157 * Force Targets:: You can use a target without commands 176 or prerequisites to mark other 177 targetsas phony.158 or prerequisites to mark other targets 159 as phony. 178 160 * Empty Targets:: When only the date matters and the 179 161 files are empty. … … 215 197 Writing the Commands in Rules 216 198 199 * Command Syntax:: Command syntax features and pitfalls. 217 200 * Echoing:: How to control when commands are echoed. 218 201 * Execution:: How commands are executed. … … 223 206 * Sequences:: Defining canned sequences of commands. 224 207 * Empty Commands:: Defining useful, do-nothing commands. 208 209 Command Syntax 210 211 * Splitting Lines:: Breaking long command lines for readability. 212 * Variables in Commands:: Using @code{make} variables in commands. 213 214 Command Execution 215 216 * Choosing the Shell:: How @code{make} chooses the shell used 217 to run commands. 225 218 226 219 Recursive Use of @code{make} … … 268 261 * Text Functions:: General-purpose text manipulation functions. 269 262 * File Name Functions:: Functions for manipulating file names. 263 * Conditional Functions:: Functions that implement conditions. 270 264 * Foreach Function:: Repeat some text with controlled variation. 271 * If Function:: Conditionally expand a value.272 265 * Call Function:: Expand a user-defined function. 273 266 * Value Function:: Return the un-expanded value of a variable. 274 267 * Eval Function:: Evaluate the arguments as makefile syntax. 275 268 * Origin Function:: Find where a variable got its value. 269 * Flavor Function:: Find out the flavor of a variable. 276 270 * Shell Function:: Substitute the output of a shell command. 277 271 * Make Control Functions:: Functions that control how make runs. … … 301 295 * Chained Rules:: How to use a chain of implicit rules. 302 296 * Pattern Rules:: How to define new implicit rules. 303 * Last Resort:: How to defin ing commands for rules304 whichcannot find any.297 * Last Resort:: How to define commands for rules which 298 cannot find any. 305 299 * Suffix Rules:: The old-fashioned style of implicit rule. 306 300 * Implicit Rule Search:: The precise algorithm for applying … … 330 324 331 325 * Archive Symbols:: How to update archive symbol directories. 332 333 Makefile Conventions334 335 * Makefile Basics:: General Conventions for Makefiles336 * Utilities in Makefiles:: Utilities in Makefiles337 * Command Variables:: Variables for Specifying Commands338 * Directory Variables:: Variables for Installation Directories339 * Standard Targets:: Standard Targets for Users340 * Install Command Categories:: Three categories of commands in the `install'341 326 342 327 @end detailmenu … … 1100 1085 1101 1086 @noindent 1102 @var{filenames} can contain shell file name patterns. 1087 @var{filenames} can contain shell file name patterns. If 1088 @var{filenames} is empty, nothing is included and no error is printed. 1103 1089 @cindex shell file name pattern (in @code{include}) 1104 1090 @cindex shell wildcards (in @code{include}) … … 1289 1275 @code{.DEFAULT_GOAL} variable allows you to discover the current 1290 1276 default goal, restart the default goal selection algorithm by clearing 1291 its value, or to explicitly set the default goal. The following1277 its value, or to explicitly set the default goal. The following 1292 1278 example illustrates these cases: 1293 1279 … … 1330 1316 Note that assigning more than one target name to @code{.DEFAULT_GOAL} is 1331 1317 illegal and will result in an error. 1318 1319 @vindex MAKE_RESTARTS @r{(number of times @code{make} has restarted)} 1320 @item MAKE_RESTARTS 1321 This variable is set only if this instance of @code{make} has 1322 restarted (@pxref{Remaking Makefiles, , How Makefiles Are Remade}): it 1323 will contain the number of times this instance has restarted. Note 1324 this is not the same as recursion (counted by the @code{MAKELEVEL} 1325 variable). You should not set, modify, or export this variable. 1332 1326 1333 1327 @vindex .VARIABLES @r{(list of variables)} … … 1357 1351 1358 1352 @table @samp 1353 1354 @item archives 1355 Supports @code{ar} (archive) files using special filename syntax. 1356 @xref{Archives, ,Using @code{make} to Update Archive Files}. 1357 1358 @item check-symlink 1359 Supports the @code{-L} (@code{--check-symlink-times}) flag. 1360 @xref{Options Summary, ,Summary of Options}. 1361 1362 @item else-if 1363 Supports ``else if'' non-nested conditionals. @xref{Conditional 1364 Syntax, ,Syntax of Conditionals}. 1365 1366 @item jobserver 1367 Supports ``job server'' enhanced parallel builds. @xref{Parallel, 1368 ,Parallel Execution}. 1369 1370 @item second-expansion 1371 Supports secondary expansion of prerequisite lists. 1372 1373 @item order-only 1374 Supports order-only prerequisites. @xref{Prerequisite Types, ,Types 1375 of Prerequisites}. 1376 1359 1377 @item target-specific 1360 1378 Supports target-specific and pattern-specific variable assignments. 1361 1379 @xref{Target-specific, ,Target-specific Variable Values}. 1362 1380 1363 @item order-only1364 Supports order-only prerequisites. @xref{Prerequisite Types, ,Types1365 of Prerequisites}.1366 1367 @item second-expansion1368 Supports secondary expansion of prerequisite lists.1369 1370 @item jobserver1371 Supports ``job server'' enhanced parallel builds. @xref{Parallel,1372 ,Parallel Execution}.1373 1374 @item check-symlink1375 Supports the @code{-L} (@code{--check-symlink-times}) flag.1376 @xref{Options Summary, ,Summary of Options}.1377 1378 1381 @end table 1382 1383 @vindex .INCLUDE_DIRS @r{(list of include directories)} 1384 @item .INCLUDE_DIRS 1385 Expands to a list of directories that @code{make} searches for 1386 included makefiles (@pxref{Include, , Including Other Makefiles}). 1379 1387 1380 1388 @end table … … 1600 1608 @cindex expansion, secondary 1601 1609 1610 @findex .SECONDEXPANSION 1602 1611 In the previous section we learned that GNU @code{make} works in two 1603 1612 distinct phases: a read-in phase and a target-update phase 1604 (@pxref{Reading Makefiles, , How @code{make} Reads a Makefile}). 1605 There is an extra wrinkle that comes in between those two phases, 1606 right at the end of the read-in phase: at that time, all the 1607 prerequisites of all of the targets are expanded a @emph{second time}. 1608 In most circumstances this secondary expansion will have no effect, 1609 since all variable and function references will have been expanded 1610 during the initial parsing of the makefiles. In order to take 1611 advantage of the secondary expansion phase of the parser, then, it's 1612 necessary to @emph{escape} the variable or function reference in the 1613 makefile. In this case the first expansion merely un-escapes the 1614 reference but doesn't expand it, and expansion is left to the 1615 secondary expansion phase. For example, consider this makefile: 1616 1617 @example 1613 (@pxref{Reading Makefiles, , How @code{make} Reads a Makefile}). GNU 1614 make also has the ability to enable a @emph{second expansion} of the 1615 prerequisites (only) for some or all targets defined in the makefile. 1616 In order for this second expansion to occur, the special target 1617 @code{.SECONDEXPANSION} must be defined before the first prerequisite 1618 list that makes use of this feature. 1619 1620 If that special target is defined then in between the two phases 1621 mentioned above, right at the end of the read-in phase, all the 1622 prerequisites of the targets defined after the special target are 1623 expanded a @emph{second time}. In most circumstances this secondary 1624 expansion will have no effect, since all variable and function 1625 references will have been expanded during the initial parsing of the 1626 makefiles. In order to take advantage of the secondary expansion 1627 phase of the parser, then, it's necessary to @emph{escape} the 1628 variable or function reference in the makefile. In this case the 1629 first expansion merely un-escapes the reference but doesn't expand it, 1630 and expansion is left to the secondary expansion phase. For example, 1631 consider this makefile: 1632 1633 @example 1634 .SECONDEXPANSION: 1618 1635 ONEVAR = onefile 1619 1636 TWOVAR = twofile … … 1639 1656 1640 1657 @example 1658 .SECONDEXPANSION: 1641 1659 AVAR = top 1642 1660 onefile: $(AVAR) … … 1658 1676 defer the expansion by escaping the @code{$}. Also, secondary 1659 1677 expansion occurs for both explicit and implicit (pattern) rules. 1660 Knowing this, the possible uses for this feature are almost endless. 1661 For example: 1662 1663 @example 1678 Knowing this, the possible uses for this feature increase 1679 dramatically. For example: 1680 1681 @example 1682 .SECONDEXPANSION: 1664 1683 main_OBJS := main.o try.o test.o 1665 1684 lib_OBJS := lib.o api.o … … 1682 1701 lib_SRCS := lib.c api.c 1683 1702 1703 .SECONDEXPANSION: 1684 1704 main lib: $$(patsubst %.c,%.o,$$($$@@_SRCS)) 1685 1705 @end example … … 1708 1728 of all prerequisites of rules @emph{that have already appeared} for 1709 1729 the same target (@code{$$+} with repetitions and @code{$$^} 1710 without). The following example will help illustrate these behaviors: 1711 1712 @example 1730 without). The following example will help illustrate these behaviors: 1731 1732 @example 1733 .SECONDEXPANSION: 1734 1713 1735 foo: foo.1 bar.1 $$< $$^ $$+ # line #1 1714 1736 … … 1718 1740 @end example 1719 1741 1720 For the first line, all three variables (@code{$$<}, @code{$$^}, and 1721 @code{$$ +}) expand to the empty string. For the second line, they will1722 have values @code{foo.1}, @code{foo.1 bar.1}, and @code{foo.1 bar.1} 1723 respectively. For the third they will have values @code{foo.1}, 1724 @code{foo.1 bar.1 foo.2 bar.2}, and @code{foo.1 bar.1 foo.2 bar.2}1725 respectively.1742 In the first prerequisite list, all three variables (@code{$$<}, 1743 @code{$$^}, and @code{$$+}) expand to the empty string. In the 1744 second, they will have values @code{foo.1}, @code{foo.1 bar.1}, and 1745 @code{foo.1 bar.1} respectively. In the third they will have values 1746 @code{foo.1}, @code{foo.1 bar.1 foo.2 bar.2}, and @code{foo.1 bar.1 1747 foo.2 bar.2} respectively. 1726 1748 1727 1749 Rules undergo secondary expansion in makefile order, except that … … 1751 1773 1752 1774 @example 1775 .SECONDEXPANSION: 1776 1753 1777 foo: bar 1754 1778 … … 1769 1793 1770 1794 @example 1795 .SECONDEXPANSION: 1796 1771 1797 /tmp/foo.o: 1772 1798 … … 1816 1842 * Phony Targets:: Using a target that is not a real file's name. 1817 1843 * Force Targets:: You can use a target without commands 1818 or prerequisites to mark other 1819 targetsas phony.1844 or prerequisites to mark other targets 1845 as phony. 1820 1846 * Empty Targets:: When only the date matters and the 1821 1847 files are empty. … … 1901 1927 appear on the line after the prerequisites, with a tab character, or may 1902 1928 appear on the same line, with a semicolon. Either way, the effect is the 1903 same. @xref{Commands, ,Writing the Commands in Rules}. 1929 same. There are other differences in the syntax of command lines. 1930 @xref{Commands, ,Writing the Commands in Rules}. 1904 1931 1905 1932 @cindex dollar sign (@code{$}), in rules 1906 1933 @cindex @code{$}, in rules 1907 @cindex rule, and @code{$} 1908 Because dollar signs are used to start variable references, if you really 1909 want a dollar sign in a rule you must write two of them, @samp{$$} 1910 (@pxref{Using Variables, ,How to Use Variables}). In prerequisite 1911 lists you must actually write @emph{four} dollar signs (@samp{$$$$}), 1912 due to secondary expansion (@pxref{Secondary Expansion}). 1913 You may split a long line by inserting a backslash 1914 followed by a newline, but this is not required, as @code{make} places no 1915 limit on the length of a line in a makefile. 1934 @cindex rules, and @code{$} 1935 Because dollar signs are used to start @code{make} variable 1936 references, if you really want a dollar sign in a target or 1937 prerequisite you must write two of them, @samp{$$} (@pxref{Using 1938 Variables, ,How to Use Variables}). If you have enabled secondary 1939 expansion (@pxref{Secondary Expansion}) and you want a literal dollar 1940 sign in the prerequisites lise, you must actually write @emph{four} 1941 dollar signs (@samp{$$$$}). 1942 1943 You may split a long line by inserting a backslash followed by a 1944 newline, but this is not required, as @code{make} places no limit on 1945 the length of a line in a makefile. 1916 1946 1917 1947 A rule tells @code{make} two things: when the targets are out of date, … … 2004 2034 @var{HOME}.@refill 2005 2035 2006 Wildcard expansion happens automatically in targets, in prerequisites,2007 and in commands (where the shell does the expansion). In other 2008 contexts, wildcard expansion happens only if you request it explicitly 2009 with the @code{wildcard} function.2036 Wildcard expansion is performed by @code{make} automatically in 2037 targets and in prerequisites. In commands the shell is responsible 2038 for wildcard expansion. In other contexts, wildcard expansion happens 2039 only if you request it explicitly with the @code{wildcard} function. 2010 2040 2011 2041 The special significance of a wildcard character can be turned off by … … 2553 2583 word in the list will be used. 2554 2584 2555 The default value for @code{.LIBPATTERNS} is ``@samp{lib%.so lib%.a}'',2585 The default value for @code{.LIBPATTERNS} is @samp{lib%.so lib%.a}, 2556 2586 which provides the default behavior described above. 2557 2587 … … 2644 2674 it will do so even if @code{make} is invoked with the @code{-k} option, 2645 2675 which is unfortunate. Second, and perhaps more importantly, you cannot 2646 take advantage of the parallel build capabilities of make using this2647 method, since there is only one rule.2676 take advantage of @code{make}'s ability to build targets in parallel 2677 (@pxref{Parallel, ,Parallel Execution}), since there is only one rule. 2648 2678 2649 2679 By declaring the subdirectories as phony targets (you must do this as … … 2867 2897 as secondary (i.e., no target is removed because it is considered 2868 2898 intermediate). 2899 2900 @findex .SECONDEXPANSION 2901 @item .SECONDEXPANSION 2902 2903 If @code{.SECONDEXPANSION} is mentioned as a target anywhere in the 2904 makefile, then all prerequisite lists defined @emph{after} it appears 2905 will be expanded a second time after all makefiles have been read in. 2906 @xref{Secondary Expansion, ,Secondary Expansion}. 2907 2908 The prerequisites of the special target @code{.SUFFIXES} are the list 2909 of suffixes to be used in checking for suffix rules. 2910 @xref{Suffix Rules, , Old-Fashioned Suffix Rules}. 2869 2911 2870 2912 @findex .DELETE_ON_ERROR … … 3376 3418 @group 3377 3419 %.d: %.c 3378 @ set -e; rm -f $@@; \3420 @@set -e; rm -f $@@; \ 3379 3421 $(CC) -M $(CPPFLAGS) $< > $@@.$$$$; \ 3380 3422 sed 's,\($*\)\.o[ :]*,\1.o $@@ : ,g' < $@@.$$$$ > $@@; \ … … 3449 3491 @cindex writing rule commands 3450 3492 3451 The commands of a rule consist of shell command lines to be executed one 3452 by one. Each command line must start with a tab, except that the first 3453 command line may be attached to the target-and-prerequisites line with a 3454 semicolon in between. Blank lines and lines of just comments may appear 3455 among the command lines; they are ignored. (But beware, an apparently 3456 ``blank'' line that begins with a tab is @emph{not} blank! It is an 3457 empty command; @pxref{Empty Commands}.) 3493 The commands of a rule consist of one or more shell command lines to 3494 be executed, one at a time, in the order they appear. Typically, the 3495 result of executing these commands is that the target of the rule is 3496 brought up to date. 3458 3497 3459 3498 Users use many different shell programs, but commands in makefiles are … … 3461 3500 otherwise. @xref{Execution, ,Command Execution}. 3462 3501 3463 @cindex comments, in commands3464 @cindex commands, comments in3465 @cindex @code{#} (comments), in commands3466 The shell that is in use determines whether comments can be written on3467 command lines, and what syntax they use. When the shell is3468 @file{/bin/sh}, a @samp{#} starts a comment that extends to the end of3469 the line. The @samp{#} does not have to be at the beginning of a line.3470 Text on a line before a @samp{#} is not part of the comment.3471 3472 3502 @menu 3503 * Command Syntax:: Command syntax features and pitfalls. 3473 3504 * Echoing:: How to control when commands are echoed. 3474 3505 * Execution:: How commands are executed. … … 3481 3512 @end menu 3482 3513 3483 @node Echoing, Execution, Commands, Commands 3514 @node Command Syntax, Echoing, Commands, Commands 3515 @section Command Syntax 3516 @cindex command syntax 3517 @cindex syntax of commands 3518 3519 Makefiles have the unusual property that there are really two distinct 3520 syntaxes in one file. Most of the makefile uses @code{make} syntax 3521 (@pxref{Makefiles, ,Writing Makefiles}). However, commands are meant to be 3522 interpreted by the shell and so they are written using shell syntax. 3523 The @code{make} program does not try to understand shell syntax: it 3524 performs only a very few specific translations on the content of the 3525 command before handing it to the shell. 3526 3527 Each command line must start with a tab, except that the first command 3528 line may be attached to the target-and-prerequisites line with a 3529 semicolon in between. @emph{Any} line in the makefile that begins 3530 with a tab and appears in a ``rule context'' (that is, after a rule 3531 has been started until another rule or variable definition) will be 3532 considered a command line for that rule. Blank lines and lines of 3533 just comments may appear among the command lines; they are ignored. 3534 3535 Some consequences of these rules include: 3536 3537 @itemize @bullet 3538 @item 3539 A blank line that begins with a tab is not blank: it's an empty 3540 command (@pxref{Empty Commands}). 3541 3542 @cindex comments, in commands 3543 @cindex commands, comments in 3544 @cindex @code{#} (comments), in commands 3545 @item 3546 A comment in a command line is not a @code{make} comment; it will be 3547 passed to the shell as-is. Whether the shell treats it as a comment 3548 or not depends on your shell. 3549 3550 @item 3551 A variable definition in a ``rule context'' which is indented by a tab 3552 as the first character on the line, will be considered a command line, 3553 not a @code{make} variable definition, and passed to the shell. 3554 3555 @item 3556 A conditional expression (@code{ifdef}, @code{ifeq}, 3557 etc. @pxref{Conditional Syntax, ,Syntax of Conditionals}) in a ``rule 3558 context'' which is indented by a tab as the first character on the 3559 line, will be considered a command line and be passed to the shell. 3560 3561 @end itemize 3562 3563 @menu 3564 * Splitting Lines:: Breaking long command lines for readability. 3565 * Variables in Commands:: Using @code{make} variables in commands. 3566 @end menu 3567 3568 @node Splitting Lines, Variables in Commands, Command Syntax, Command Syntax 3569 @subsection Splitting Command Lines 3570 @cindex commands, splitting 3571 @cindex splitting commands 3572 @cindex commands, backslash (@code{\}) in 3573 @cindex commands, quoting newlines in 3574 @cindex backslash (@code{\}), in commands 3575 @cindex @code{\} (backslash), in commands 3576 @cindex quoting newline, in commands 3577 @cindex newline, quoting, in commands 3578 3579 One of the few ways in which @code{make} does interpret command lines 3580 is checking for a backslash just before the newline. As in normal 3581 makefile syntax, a single command can be split into multiple lines in 3582 the makefile by placing a backslash before each newline. A sequence 3583 of lines like this is considered a single command, and one instance of 3584 the shell will be invoked to run it. 3585 3586 However, in contrast to how they are treated in other places in a 3587 makefile, backslash-newline pairs are @emph{not} removed from the 3588 command. Both the backslash and the newline characters are preserved 3589 and passed to the shell. How the backslash-newline is interpreted 3590 depends on your shell. If the first character of the next line 3591 after the backslash-newline is a tab, then that tab (and only that 3592 tab) is removed. Whitespace is never added to the command. 3593 3594 For example, this makefile: 3595 3596 @example 3597 @group 3598 all : 3599 @@echo no\ 3600 space 3601 @@echo no\ 3602 space 3603 @@echo one \ 3604 space 3605 @@echo one\ 3606 space 3607 @end group 3608 @end example 3609 3610 @noindent 3611 consists of four separate shell commands where the output is: 3612 3613 @example 3614 @group 3615 nospace 3616 nospace 3617 one space 3618 one space 3619 @end group 3620 @end example 3621 3622 As a more complex example, this makefile: 3623 3624 @example 3625 @group 3626 all : ; @@echo 'hello \ 3627 world' ; echo "hello \ 3628 world" 3629 @end group 3630 @end example 3631 3632 @noindent 3633 will run one shell with a command script of: 3634 3635 @example 3636 @group 3637 echo 'hello \ 3638 world' ; echo "hello \ 3639 world" 3640 @end group 3641 @end example 3642 3643 @noindent 3644 which, according to shell quoting rules, will yield the following output: 3645 3646 @example 3647 @group 3648 hello \ 3649 world 3650 hello world 3651 @end group 3652 @end example 3653 3654 @noindent 3655 Notice how the backslash/newline pair was removed inside the string quoted 3656 with double quotes (@code{"..."}), but not from the string quoted with single 3657 quotes (@code{'...'}). This is the way the default shell (@file{/bin/sh}) 3658 handles backslash/newline pairs. If you specify a different shell in your 3659 makefiles it may treat them differently. 3660 3661 Sometimes you want to split a long line inside of single quotes, but 3662 you don't want the backslash-newline to appear in the quoted content. 3663 This is often the case when passing scripts to languages such as Perl, 3664 where extraneous backslashes inside the script can change its meaning 3665 or even be a syntax error. One simple way of handling this is to 3666 place the quoted string, or even the entire command, into a 3667 @code{make} variable then use the variable in the command. In this 3668 situation the newline quoting rules for makefiles will be used, and 3669 the backslash-newline will be removed. If we rewrite our example 3670 above using this method: 3671 3672 @example 3673 @group 3674 HELLO = 'hello \ 3675 world' 3676 3677 all : ; @@echo $(HELLO) 3678 @end group 3679 @end example 3680 3681 @noindent 3682 we will get output like this: 3683 3684 @example 3685 @group 3686 hello world 3687 @end group 3688 @end example 3689 3690 If you like, you can also use target-specific variables 3691 (@pxref{Target-specific, ,Target-specific Variable Values}) to obtain 3692 a tighter correspondence between the variable and the command that 3693 uses it. 3694 3695 @node Variables in Commands, , Splitting Lines, Command Syntax 3696 @subsection Using Variables in Commands 3697 @cindex variable references in commands 3698 @cindex commands, using variables in 3699 3700 The other way in which @code{make} processes commands is by expanding 3701 any variable references in them (@pxref{Reference,Basics of Variable 3702 References}). This occurs after make has finished reading all the 3703 makefiles and the target is determined to be out of date; so, the 3704 commands for targets which are not rebuilt are never expanded. 3705 3706 Variable and function references in commands have identical syntax and 3707 semantics to references elsewhere in the makefile. They also have the 3708 same quoting rules: if you want a dollar sign to appear in your 3709 command, you must double it (@samp{$$}). For shells like the default 3710 shell, that use dollar signs to introduce variables, it's important to 3711 keep clear in your mind whether the variable you want to reference is 3712 a @code{make} variable (use a single dollar sign) or a shell variable 3713 (use two dollar signs). For example: 3714 3715 @example 3716 @group 3717 LIST = one two three 3718 all: 3719 for i in $(LIST); do \ 3720 echo $$i; \ 3721 done 3722 @end group 3723 @end example 3724 3725 @noindent 3726 results in the following command being passed to the shell: 3727 3728 @example 3729 @group 3730 for i in one two three; do \ 3731 echo $i; \ 3732 done 3733 @end group 3734 @end example 3735 3736 @noindent 3737 which generates the expected result: 3738 3739 @example 3740 @group 3741 one 3742 two 3743 three 3744 @end group 3745 @end example 3746 3747 @node Echoing, Execution, Command Syntax, Commands 3484 3748 @section Command Echoing 3485 3749 @cindex echoing of commands … … 3530 3794 @cindex execution, of commands 3531 3795 @cindex shell command, execution 3532 @vindex SHELL @r{(command execution)} 3533 3534 When it is time to execute commands to update a target, they are executed 3535 by making a new subshell for each line. (In practice, @code{make} may 3536 take shortcuts that do not affect the results.) 3796 @vindex @code{SHELL} @r{(command execution)} 3797 3798 When it is time to execute commands to update a target, they are 3799 executed by invoking a new subshell for each command line. (In 3800 practice, @code{make} may take shortcuts that do not affect the 3801 results.) 3537 3802 3538 3803 @cindex @code{cd} (shell command) 3539 @strong{Please note:} this implies that shell commands such as @code{cd} 3540 that set variables local to each process will not affect the following 3541 command lines. @footnote{On MS-DOS, the value of current working 3542 directory is @strong{global}, so changing it @emph{will} affect the 3543 following command lines on those systems.} If you want to use @code{cd} 3544 to affect the next command, put the two on a single line with a 3545 semicolon between them. Then @code{make} will consider them a single 3546 command and pass them, together, to a shell which will execute them in 3547 sequence. For example: 3804 @cindex shell variables, setting in commands 3805 @cindex commands setting shell variables 3806 @strong{Please note:} this implies that setting shell variables and 3807 invoking shell commands such as @code{cd} that set a context local to 3808 each process will not affect the following command lines.@footnote{On 3809 MS-DOS, the value of current working directory is @strong{global}, so 3810 changing it @emph{will} affect the following command lines on those 3811 systems.} If you want to use @code{cd} to affect the next statement, 3812 put both statements in a single command line. Then @code{make} will 3813 invoke one shell to run the entire line, and the shell will execute 3814 the statements in sequence. For example: 3548 3815 3549 3816 @example 3550 3817 foo : bar/lose 3551 cd bar; gobble lose > ../foo 3552 @end example 3553 3554 @cindex commands, backslash (@code{\}) in 3555 @cindex commands, quoting newlines in 3556 @cindex backslash (@code{\}), in commands 3557 @cindex @code{\} (backslash), in commands 3558 @cindex quoting newline, in commands 3559 @cindex newline, quoting, in commands 3560 If you would like to split a single shell command into multiple lines of 3561 text, you must use a backslash at the end of all but the last subline. 3562 Such a sequence of lines is combined into a single line, by deleting the 3563 backslash-newline sequences, before passing it to the shell. Thus, the 3564 following is equivalent to the preceding example: 3565 3566 @example 3567 @group 3568 foo : bar/lose 3569 cd bar; \ 3570 gobble lose > ../foo 3571 @end group 3572 @end example 3818 cd $(@@D) && gobble $(@@F) > ../$@@ 3819 @end example 3820 3821 @noindent 3822 Here we use the shell AND operator (@code{&&}) so that if the 3823 @code{cd} command fails, the script will fail without trying to invoke 3824 the @code{gobble} command in the wrong directory, which could cause 3825 problems (in this case it would certainly cause @file{../foo} to be 3826 truncated, at least). 3827 3828 @menu 3829 * Choosing the Shell:: How @code{make} chooses the shell used 3830 to run commands. 3831 @end menu 3832 3833 @node Choosing the Shell, , Execution, Execution 3834 @subsection Choosing the Shell 3835 @cindex shell, choosing the 3836 @cindex @code{SHELL}, value of 3573 3837 3574 3838 @vindex SHELL 3575 3839 The program used as the shell is taken from the variable @code{SHELL}. 3576 By default, the program @file{/bin/sh} is used. 3840 If this variable is not set in your makefile, the program 3841 @file{/bin/sh} is used as the shell. 3842 3843 @cindex environment, @code{SHELL} in 3844 Unlike most variables, the variable @code{SHELL} is never set from the 3845 environment. This is because the @code{SHELL} environment variable is 3846 used to specify your personal choice of shell program for interactive 3847 use. It would be very bad for personal choices like this to affect the 3848 functioning of makefiles. @xref{Environment, ,Variables from the 3849 Environment}. 3850 3851 Furthermore, when you do set @code{SHELL} in your makefile that value 3852 is @emph{not} exported in the environment to commands that @code{make} 3853 invokes. Instead, the value inherited from the user's environment, if 3854 any, is exported. You can override this behavior by explicitly 3855 exporting @code{SHELL} (@pxref{Variables/Recursion, ,Communicating 3856 Variables to a Sub-@code{make}}), forcing it to be passed in the 3857 environment to commands. 3858 3859 @vindex @code{MAKESHELL} @r{(MS-DOS alternative to @code{SHELL})} 3860 However, on MS-DOS and MS-Windows the value of @code{SHELL} in the 3861 environment @strong{is} used, since on those systems most users do not 3862 set this variable, and therefore it is most likely set specifically to 3863 be used by @code{make}. On MS-DOS, if the setting of @code{SHELL} is 3864 not suitable for @code{make}, you can set the variable 3865 @code{MAKESHELL} to the shell that @code{make} should use; if set it 3866 will be used as the shell instead of the value of @code{SHELL}. 3867 3868 @subsubheading Choosing a Shell in DOS and Windows 3869 @cindex shell, in DOS and Windows 3870 @cindex DOS, choosing a shell in 3871 @cindex Windows, choosing a shell in 3872 3873 Choosing a shell in MS-DOS and MS-Windows is much more complex than on 3874 other systems. 3577 3875 3578 3876 @vindex COMSPEC … … 3628 3926 3629 3927 The effect of the above DOS-specific processing is that a Makefile that 3630 says @samp{SHELL = /bin/sh} (as many Unix makefiles do), will work3631 on MS-DOS unaltered if you have e.g. @file{sh.exe} installed in some3928 contains @samp{SHELL = /bin/sh} (as many Unix makefiles do), will work 3929 on MS-DOS unaltered if you have e.g.@: @file{sh.exe} installed in some 3632 3930 directory along your @code{PATH}. 3633 3634 @cindex environment, @code{SHELL} in3635 @vindex MAKESHELL @r{(MS-DOS alternative to @code{SHELL})}3636 Unlike most variables, the variable @code{SHELL} is never set from the3637 environment. This is because the @code{SHELL} environment variable is3638 used to specify your personal choice of shell program for interactive3639 use. It would be very bad for personal choices like this to affect the3640 functioning of makefiles. @xref{Environment, ,Variables from the3641 Environment}. However, on MS-DOS and MS-Windows the value of3642 @code{SHELL} in the environment @strong{is} used, since on those systems3643 most users do not set this variable, and therefore it is most likely set3644 specifically to be used by @code{make}. On MS-DOS, if the setting of3645 @code{SHELL} is not suitable for @code{make}, you can set the variable3646 @code{MAKESHELL} to the shell that @code{make} should use; this will3647 override the value of @code{SHELL}.3648 3931 3649 3932 @node Parallel, Errors, Execution, Commands … … 4015 4298 environment is passed to the sub-@code{make}. You can force 4016 4299 @code{make} to export its value for @code{SHELL} by using the 4017 @code{export} directive, described below. 4300 @code{export} directive, described below. @xref{Choosing the Shell}. 4018 4301 4019 4302 The special variable @code{MAKEFLAGS} is always exported (unless you … … 4712 4995 @group 4713 4996 ifeq (0,$@{MAKELEVEL@}) 4714 cur-dir := $(shell pwd)4715 4997 whoami := $(shell whoami) 4716 4998 host-type := $(shell arch) … … 4727 5009 @group 4728 5010 $@{subdirs@}: 4729 $@{MAKE@} cur-dir=$@{cur-dir@}/$@@-C $@@ all5011 $@{MAKE@} -C $@@ all 4730 5012 @end group 4731 5013 @end example … … 5197 5479 simply-expanded definition, and expands the new text before appending it 5198 5480 to the old value just as @samp{:=} does 5199 ( @pxref{Setting, ,Setting Variables}, for a full explanation of @samp{:=}).5481 (see @ref{Setting, ,Setting Variables}, for a full explanation of @samp{:=}). 5200 5482 In fact, 5201 5483 … … 5438 5720 When @code{make} runs a command script, variables defined in the 5439 5721 makefile are placed into the environment of that command. This allows 5440 you to pass values to sub-@code{make} invocations .(@pxref{Recursion,5722 you to pass values to sub-@code{make} invocations (@pxref{Recursion, 5441 5723 ,Recursive Use of @code{make}}). By default, only variables that came 5442 5724 from the environment or the command line are passed to recursive … … 5452 5734 5453 5735 @cindex SHELL, import from environment 5454 Such problems would be especially likely with the variable @code{SHELL}, 5455 which is normally present in the environment to specify the user's choice 5456 of interactive shell. It would be very undesirable for this choice to 5457 affect @code{make}. So @code{make} ignores the environment value of 5458 @code{SHELL} (except on MS-DOS and MS-Windows, where @code{SHELL} is 5459 usually not set. @xref{Execution, ,Special handling of SHELL on 5460 MS-DOS}.)@refill 5461 5462 @cindex SHELL, export to environment 5463 The @code{SHELL} variable is special in another way: just as the value 5464 of the @code{make} variable @code{SHELL} is not taken from the 5465 environment, so also it is not placed into the environment of commands 5466 that @code{make} invokes. Instead, the value of @code{SHELL} from the 5467 invoking environment is provided to the command. You can use 5468 @code{export SHELL} to force the value of the @code{make} variable 5469 @code{SHELL} to be placed in the environment of commands. 5736 Such problems would be especially likely with the variable 5737 @code{SHELL}, which is normally present in the environment to specify 5738 the user's choice of interactive shell. It would be very undesirable 5739 for this choice to affect @code{make}; so, @code{make} handles the 5740 @code{SHELL} environment variable in a special way; see @ref{Choosing 5741 the Shell}.@refill 5470 5742 5471 5743 @node Target-specific, Pattern-specific, Environment, Using Variables … … 5515 5787 will be in effect. Note that this variable is actually distinct from 5516 5788 any ``global'' value: the two variables do not have to have the same 5517 flavor (recursive vs. static).5789 flavor (recursive vs.@: static). 5518 5790 5519 5791 Target-specific variables have the same priority as any other makefile … … 5526 5798 you define a target-specific variable that variable value is also in 5527 5799 effect for all prerequisites of this target, and all their 5528 prerequisites, etc. (unless those prerequisites override that variable5800 prerequisites, etc.@: (unless those prerequisites override that variable 5529 5801 with their own target-specific variable value). So, for example, a 5530 5802 statement like this: … … 5925 6197 * Text Functions:: General-purpose text manipulation functions. 5926 6198 * File Name Functions:: Functions for manipulating file names. 6199 * Conditional Functions:: Functions that implement conditions. 5927 6200 * Foreach Function:: Repeat some text with controlled variation. 5928 * If Function:: Conditionally expand a value.5929 6201 * Call Function:: Expand a user-defined function. 5930 6202 * Value Function:: Return the un-expanded value of a variable. 5931 6203 * Eval Function:: Evaluate the arguments as makefile syntax. 5932 6204 * Origin Function:: Find where a variable got its value. 6205 * Flavor Function:: Find out the flavor of a variable. 5933 6206 * Shell Function:: Substitute the output of a shell command. 5934 6207 * Make Control Functions:: Functions that control how make runs. … … 6345 6618 Directive, , The @code{override} Directive}). 6346 6619 6347 @node File Name Functions, Foreach Function, Text Functions, Functions6620 @node File Name Functions, Conditional Functions, Text Functions, Functions 6348 6621 @section Functions for File Names 6349 6622 @cindex functions, for file names … … 6505 6778 For each file name in @var{names} return the canonical absolute name. 6506 6779 A canonical name does not contain any @code{.} or @code{..} components, 6507 nor any repeated path separators (@code{/}) or symlinks. In case of a6508 failure the empty string is returned. Consult the @code{realpath(3)}6780 nor any repeated path separators (@code{/}) or symlinks. In case of a 6781 failure the empty string is returned. Consult the @code{realpath(3)} 6509 6782 documentation for a list of possible failure causes. 6510 6783 … … 6515 6788 For each file name in @var{names} return an absolute name that does 6516 6789 not contain any @code{.} or @code{..} components, nor any repeated path 6517 separators (@code{/}). Note thatin contrast to @code{realpath}6790 separators (@code{/}). Note that, in contrast to @code{realpath} 6518 6791 function, @code{abspath} does not resolve symlinks and does not require 6519 the file names to refer to an existing file or directory. Use the6792 the file names to refer to an existing file or directory. Use the 6520 6793 @code{wildcard} function to test for existence. 6521 6794 @end table 6522 6795 6523 @node Foreach Function, If Function, File Name Functions, Functions 6796 @node Conditional Functions, Foreach Function, File Name Functions, Functions 6797 @section Functions for Conditionals 6798 @findex if 6799 @cindex conditional expansion 6800 There are three functions that provide conditional expansion. A key 6801 aspect of these functions is that not all of the arguments are 6802 expanded initially. Only those arguments which need to be expanded, 6803 will be expanded. 6804 6805 @table @code 6806 @item $(if @var{condition},@var{then-part}[,@var{else-part}]) 6807 @findex if 6808 The @code{if} function provides support for conditional expansion in a 6809 functional context (as opposed to the GNU @code{make} makefile 6810 conditionals such as @code{ifeq} (@pxref{Conditional Syntax, ,Syntax of 6811 Conditionals}). 6812 6813 The first argument, @var{condition}, first has all preceding and 6814 trailing whitespace stripped, then is expanded. If it expands to any 6815 non-empty string, then the condition is considered to be true. If it 6816 expands to an empty string, the condition is considered to be false. 6817 6818 If the condition is true then the second argument, @var{then-part}, is 6819 evaluated and this is used as the result of the evaluation of the entire 6820 @code{if} function. 6821 6822 If the condition is false then the third argument, @var{else-part}, is 6823 evaluated and this is the result of the @code{if} function. If there is 6824 no third argument, the @code{if} function evaluates to nothing (the 6825 empty string). 6826 6827 Note that only one of the @var{then-part} or the @var{else-part} will be 6828 evaluated, never both. Thus, either can contain side-effects (such as 6829 @code{shell} function calls, etc.) 6830 6831 @item $(or @var{condition1}[,@var{condition2}[,@var{condition3}@dots{}]]) 6832 @findex or 6833 The @code{or} function provides a ``short-circuiting'' OR operation. 6834 Each argument is expanded, in order. If an argument expands to a 6835 non-empty string the processing stops and the result of the expansion 6836 is that string. If, after all arguments are expanded, all of them are 6837 false (empty), then the result of the expansion is the empty string. 6838 6839 @item $(and @var{condition1}[,@var{condition2}[,@var{condition3}@dots{}]]) 6840 @findex and 6841 The @code{and} function provides a ``short-circuiting'' AND operation. 6842 Each argument is expanded, in order. If an argument expands to an 6843 empty string the processing stops and the result of the expansion is 6844 the empty string. If all arguments expand to a non-empty string then 6845 the result of the expansion is the expansion of the last argument. 6846 6847 @end table 6848 6849 @node Foreach Function, Call Function, Conditional Functions, Functions 6524 6850 @section The @code{foreach} Function 6525 6851 @findex foreach … … 6609 6935 no?), but it is more likely to be a mistake. 6610 6936 6611 @node If Function, Call Function, Foreach Function, Functions 6612 @section The @code{if} Function 6613 @findex if 6614 @cindex conditional expansion 6615 6616 The @code{if} function provides support for conditional expansion in a 6617 functional context (as opposed to the GNU @code{make} makefile 6618 conditionals such as @code{ifeq} (@pxref{Conditional Syntax, ,Syntax of 6619 Conditionals}). 6620 6621 An @code{if} function call can contain either two or three arguments: 6622 6623 @example 6624 $(if @var{condition},@var{then-part}[,@var{else-part}]) 6625 @end example 6626 6627 The first argument, @var{condition}, first has all preceding and 6628 trailing whitespace stripped, then is expanded. If it expands to any 6629 non-empty string, then the condition is considered to be true. If it 6630 expands to an empty string, the condition is considered to be false. 6631 6632 If the condition is true then the second argument, @var{then-part}, is 6633 evaluated and this is used as the result of the evaluation of the entire 6634 @code{if} function. 6635 6636 If the condition is false then the third argument, @var{else-part}, is 6637 evaluated and this is the result of the @code{if} function. If there is 6638 no third argument, the @code{if} function evaluates to nothing (the 6639 empty string). 6640 6641 Note that only one of the @var{then-part} or the @var{else-part} will be 6642 evaluated, never both. Thus, either can contain side-effects (such as 6643 @code{shell} function calls, etc.) 6644 6645 @node Call Function, Value Function, If Function, Functions 6937 @node Call Function, Value Function, Foreach Function, Functions 6646 6938 @section The @code{call} Function 6647 6939 @findex call … … 6713 7005 6714 7006 The @code{call} function can be nested. Each recursive invocation gets 6715 its own local values for @code{$(1)}, etc. that mask the values of7007 its own local values for @code{$(1)}, etc.@: that mask the values of 6716 7008 higher-level @code{call}. For example, here is an implementation of a 6717 7009 @dfn{map} function: … … 6850 7142 @end example 6851 7143 6852 @node Origin Function, ShellFunction, Eval Function, Functions7144 @node Origin Function, Flavor Function, Eval Function, Functions 6853 7145 @section The @code{origin} Function 6854 7146 @findex origin … … 6959 7251 @xref{Text Functions, , Functions for String Substitution and Analysis}. 6960 7252 6961 @node Shell Function, Make Control Functions, Origin Function, Functions 7253 @node Flavor Function, Shell Function, Origin Function, Functions 7254 @section The @code{flavor} Function 7255 @findex flavor 7256 @cindex variables, flavor of 7257 @cindex flavor of variable 7258 7259 The @code{flavor} function is unlike most other functions (and like 7260 @code{origin} function) in that it does not operate on the values of 7261 variables; it tells you something @emph{about} a variable. 7262 Specifically, it tells you the flavor of a variable (@pxref{Flavors, 7263 ,The Two Flavors of Variables}). 7264 7265 The syntax of the @code{flavor} function is: 7266 7267 @example 7268 $(flavor @var{variable}) 7269 @end example 7270 7271 Note that @var{variable} is the @emph{name} of a variable to inquire about; 7272 not a @emph{reference} to that variable. Therefore you would not normally 7273 use a @samp{$} or parentheses when writing it. (You can, however, use a 7274 variable reference in the name if you want the name not to be a constant.) 7275 7276 The result of this function is a string that identifies the flavor of the 7277 variable @var{variable}: 7278 7279 @table @samp 7280 @item undefined 7281 7282 if @var{variable} was never defined. 7283 7284 @item recursive 7285 7286 if @var{variable} is a recursively expanded variable. 7287 7288 @item simple 7289 7290 if @var{variable} is a simply expanded variable. 7291 7292 @end table 7293 7294 7295 @node Shell Function, Make Control Functions, Flavor Function, Functions 6962 7296 @section The @code{shell} Function 6963 7297 @findex shell … … 6984 7318 spawning a new shell, you should carefully consider the performance 6985 7319 implications of using the @code{shell} function within recursively 6986 expanded variables vs. simply expanded variables (@pxref{Flavors, ,The7320 expanded variables vs.@: simply expanded variables (@pxref{Flavors, ,The 6987 7321 Two Flavors of Variables}). 6988 7322 … … 7084 7418 things and many others. 7085 7419 7420 @cindex exit status of make 7086 7421 The exit status of @code{make} is always one of three values: 7087 7422 @table @code … … 7550 7885 Consider all targets out-of-date. GNU @code{make} proceeds to 7551 7886 consider targets and their prerequisites using the normal algorithms; 7552 however, all these targets are remade, regardless of the status of 7553 their prerequisites. 7887 however, all targets so considered are always remade regardless of the 7888 status of their prerequisites. To avoid infinite recursion, if 7889 @code{MAKE_RESTARTS} (@pxref{Special Variables, , Other Special 7890 Variables}) is set to a number greater than 0 this option is disabled 7891 when considering whether to remake makefiles (@pxref{Remaking 7892 Makefiles, , How Makefiles Are Remade}). 7554 7893 7555 7894 @item -C @var{dir} … … 7907 8246 * Pattern Rules:: How to define new implicit rules. 7908 8247 * Last Resort:: How to define commands for rules which 7909 cannot find any.8248 cannot find any. 7910 8249 * Suffix Rules:: The old-fashioned style of implicit rule. 7911 8250 * Implicit Rule Search:: The precise algorithm for applying … … 8002 8341 @samp{--no-builtin-rules} option cancels all predefined rules. 8003 8342 8343 This manual only documents the default rules available on POSIX-based 8344 operating systems. Other operating systems, such as VMS, Windows, 8345 OS/2, etc. may have different sets of default rules. To see the full 8346 list of default rules and variables available in your version of GNU 8347 @code{make}, run @samp{make -p} in a directory with no makefile. 8348 8004 8349 Not all of these rules will always be defined, even when the @samp{-r} 8005 8350 option is not given. Many of the predefined implicit rules are … … 8008 8353 the special target @code{.SUFFIXES}). The default suffix list is: 8009 8354 @code{.out}, @code{.a}, @code{.ln}, @code{.o}, @code{.c}, @code{.cc}, 8010 @code{.C}, @code{. p}, @code{.f}, @code{.F}, @code{.r}, @code{.y},8355 @code{.C}, @code{.cpp}, @code{.p}, @code{.f}, @code{.F}, @code{.r}, @code{.y}, 8011 8356 @code{.l}, @code{.s}, @code{.S}, @code{.mod}, @code{.sym}, @code{.def}, 8012 8357 @code{.h}, @code{.info}, @code{.dvi}, @code{.tex}, @code{.texinfo}, … … 8033 8378 @cindex C++, rule to compile 8034 8379 @pindex g++ 8380 @pindex .cc 8381 @pindex .cpp 8035 8382 @pindex .C 8036 @pindex .cc 8037 @file{@var{n}.o} is made automatically from @file{@var{n}.cc} or 8038 @file{@var{n}.C} with a command of the form @samp{$(CXX) -c $(CPPFLAGS) 8039 $(CXXFLAGS)}. We encourage you to use the suffix @samp{.cc} for C++ 8040 source files instead of @samp{.C}.@refill 8383 @file{@var{n}.o} is made automatically from @file{@var{n}.cc}, 8384 @file{@var{n}.cpp}, or @file{@var{n}.C} with a command of the form 8385 @samp{$(CXX) -c $(CPPFLAGS) $(CXXFLAGS)}. We encourage you to use the 8386 suffix @samp{.cc} for C++ source files instead of @samp{.C}.@refill 8041 8387 8042 8388 @item Compiling Pascal programs … … 8299 8645 8300 8646 The commands in built-in implicit rules make liberal use of certain 8301 predefined variables. You can alter the se variables in the makefile,8302 with arguments to @code{make}, or in the environment to alter how the 8303 implicit rules work without redefining the rules themselves. You can 8304 cancel all variables used by implicit rules with the @samp{-R} or 8305 @samp{--no-builtin-variables} option.8647 predefined variables. You can alter the values of these variables in 8648 the makefile, with arguments to @code{make}, or in the environment to 8649 alter how the implicit rules work without redefining the rules 8650 themselves. You can cancel all variables used by implicit rules with 8651 the @samp{-R} or @samp{--no-builtin-variables} option. 8306 8652 8307 8653 For example, the command used to compile a C source file actually says … … 8322 8668 with spaces. 8323 8669 8324 Here is a table of variables used as names of programs in built-in rules: 8670 The following tables describe of some of the more commonly-used predefined 8671 variables. This list is not exhaustive, and the default values shown here may 8672 not be what are selected by @code{make} for your environment. To see the 8673 complete list of predefined variables for your instance of GNU @code{make} you 8674 can run @samp{make -p} in a directory with no makefiles. 8675 8676 Here is a table of some of the more common variables used as names of 8677 programs in built-in rules: 8678 makefiles. 8325 8679 8326 8680 @table @code … … 8332 8686 @item AS 8333 8687 @vindex AS 8334 Program for doing assembly; default @samp{as}.8688 Program for compiling assembly files; default @samp{as}. 8335 8689 @pindex as 8336 8690 … … 8338 8692 @vindex CC 8339 8693 Program for compiling C programs; default @samp{cc}. 8694 @pindex cc 8695 8696 @item CO 8697 @vindex CO 8698 Program for checking out files from RCS; default @samp{co}. 8340 8699 @pindex cc 8341 8700 … … 8368 8727 @item LEX 8369 8728 @vindex LEX 8370 Program to use to turn Lex grammars into C programs or Ratfor programs; 8371 default @samp{lex}. 8729 Program to use to turn Lex grammars into source code; default @samp{lex}. 8372 8730 @pindex lex 8731 8732 @item YACC 8733 @vindex YACC 8734 Program to use to turn Yacc grammars into source code; default @samp{yacc}. 8735 @pindex yacc 8736 8737 @item LINT 8738 @vindex LINT 8739 Program to use to run lint on source code; default @samp{lint}. 8740 @pindex lint 8741 8742 @item M2C 8743 @vindex M2C 8744 Program to use to compile Modula-2 source code; default @samp{m2c}. 8745 @pindex m2c 8373 8746 8374 8747 @item PC … … 8376 8749 Program for compiling Pascal programs; default @samp{pc}. 8377 8750 @pindex pc 8378 8379 @item YACC8380 @vindex YACC8381 Program to use to turn Yacc grammars into C programs; default @samp{yacc}.8382 @pindex yacc8383 8384 @item YACCR8385 @vindex YACCR8386 Program to use to turn Yacc grammars into Ratfor8387 programs; default @samp{yacc -r}.8388 8751 8389 8752 @item MAKEINFO … … 8472 8835 @item LDFLAGS 8473 8836 @vindex LDFLAGS 8474 Extra flags to give to compilers when they are 8475 supposed to invoke the linker,@samp{ld}.8837 Extra flags to give to compilers when they are supposed to invoke the linker, 8838 @samp{ld}. 8476 8839 8477 8840 @item LFLAGS … … 8479 8842 Extra flags to give to Lex. 8480 8843 8844 @item YFLAGS 8845 @vindex YFLAGS 8846 Extra flags to give to Yacc. 8847 8481 8848 @item PFLAGS 8482 8849 @vindex PFLAGS … … 8487 8854 Extra flags to give to the Fortran compiler for Ratfor programs. 8488 8855 8489 @item YFLAGS8490 @vindex YFLAGS8491 Extra flags to give to Yacc.8856 @item LINTFLAGS 8857 @vindex LINTFLAGS 8858 Extra flags to give to lint. 8492 8859 @end table 8493 8860 … … 8629 8996 8630 8997 @samp{%} in a prerequisite of a pattern rule stands for the same stem 8631 that was matched by the @samp{%} in the target. In order for 8632 the pattern rule to apply, its target pattern must match the file name 8633 under consideration, and its prerequisite patterns must name files that 8634 exist or can be made. These files become prerequisites of the target. 8998 that was matched by the @samp{%} in the target. In order for the 8999 pattern rule to apply, its target pattern must match the file name 9000 under consideration and all of its prerequisites (after pattern 9001 substitution) must name files that exist or can be made. These files 9002 become prerequisites of the target. 8635 9003 @cindex prerequisite pattern, implicit 8636 9004 … … 8982 9350 names, along with the slash that ends them, are added on to the 8983 9351 prerequisite file names generated from the pattern rule's prerequisite 8984 patterns and the file name. The directories are ignored only for the9352 patterns and the file name. The directories are ignored only for the 8985 9353 purpose of finding an implicit rule to use, not in the application of 8986 9354 that rule. Thus, @samp{e%t} matches the file name @file{src/eat}, … … 9386 9754 9387 9755 In fact, nearly all archive member targets are updated in just this way 9388 and there is an implicit rule to do it for you. @strong{ Note:} The9756 and there is an implicit rule to do it for you. @strong{Please note:} The 9389 9757 @samp{c} flag to @code{ar} is required if the archive file does not 9390 9758 already exist. … … 10124 10492 @xref{Origin Function, , The @code{origin} Function}. 10125 10493 10494 @item $(flavor @var{variable}) 10495 10496 Return a string describing the flavor of the @code{make} variable 10497 @var{variable}.@* 10498 @xref{Flavor Function, , The @code{flavor} Function}. 10499 10126 10500 @item $(foreach @var{var},@var{words},@var{text}) 10127 10501 … … 10133 10507 10134 10508 Evaluate the variable @var{var} replacing any references to @code{$(1)}, 10135 @code{$(2)} with the first, second, etc. @var{param} values.@*10509 @code{$(2)} with the first, second, etc.@: @var{param} values.@* 10136 10510 @xref{Call Function, ,The @code{call} Function}. 10137 10511 … … 10228 10602 commands. @xref{Execution, ,Command Execution}. The @code{SHELL} 10229 10603 variable is handled specially when importing from and exporting to the 10230 environment. @xref{ Environment, ,Using Variable from the Environment}.10604 environment. @xref{Choosing the Shell}. 10231 10605 10232 10606 @item MAKESHELL 10233 10607 10234 10608 On MS-DOS only, the name of the command interpreter that is to be used 10235 by @code{make}. This value takes precedence over the value of10609 by @code{make}. This value takes precedence over the value of 10236 10610 @code{SHELL}. @xref{Execution, ,MAKESHELL variable}. 10237 10611 … … 10728 11102 @printindex fn 10729 11103 10730 @summarycontents10731 @contents10732 11104 @bye
Note:
See TracChangeset
for help on using the changeset viewer.