Changeset 280 for branches/GNU/src/gmake/doc/make.texi
- Timestamp:
- May 16, 2005, 6:54:02 PM (20 years ago)
- Location:
- branches/GNU/src/gmake
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gmake
- Property svn:ignore
-
old new 34 34 README.DOS 35 35 README.W32 36 README.OS2 36 37 aclocal.m4 37 38 autom4te.cache
-
- Property svn:ignore
-
branches/GNU/src/gmake/doc/make.texi
r153 r280 8 8 @c FSF publishers: format makebook.texi instead of using this file directly. 9 9 10 @set RCSID $Id: make.texi,v 1. 18 2004/02/23 06:25:54psmith Exp $11 @set EDITION 0. 6110 @set RCSID $Id: make.texi,v 1.30 2005/05/13 12:45:31 psmith Exp $ 11 @set EDITION 0.70 12 12 @set VERSION 3.81 13 @set UPDATED 0 2 May 200314 @set UPDATE-MONTH May 200 315 @c omment The ISBN number might need to change on next publication.16 @set ISBN 1-882114-8 1-7 @c From Brian Youmans <3diff@gnu.org>, 25 Apr 200013 @set UPDATED 07 May 2005 14 @set UPDATE-MONTH May 2005 15 @c ISBN provided by Lisa M. Opus Goldstein <opus@gnu.org>, 5 May 2004 16 @set ISBN 1-882114-83-5 17 17 18 18 @c finalout … … 40 40 41 41 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 42 1998, 1999, 2000, 2002, 2003, 2004 42 1998, 1999, 2000, 2002, 2003, 2004, 2005 43 43 Free Software Foundation, Inc. 44 44 … … 163 163 with another makefile. 164 164 * Reading Makefiles:: How makefiles are parsed. 165 * Secondary Expansion:: How and when secondary expansion is performed. 165 166 166 167 Writing Rules … … 339 340 * Install Command Categories:: Three categories of commands in the `install' 340 341 341 Copying This Manual342 343 342 @end detailmenu 344 343 @end menu … … 643 642 prerequisites. These shell commands say how to update the target file. 644 643 A tab character must come at the beginning of every command line to 645 distinguish command slines from other lines in the makefile. (Bear in644 distinguish command lines from other lines in the makefile. (Bear in 646 645 mind that @code{make} does not know anything about how the commands 647 646 work. It is up to you to supply commands that will update the target … … 674 673 names start with @samp{.}). This is called the @dfn{default goal}. 675 674 (@dfn{Goals} are the targets that @code{make} strives ultimately to 676 update. @xref{Goals, , Arguments to Specify the Goals}.) 675 update. You can override this behavior using the command line 676 (@pxref{Goals, , Arguments to Specify the Goals}) or with the 677 @code{.DEFAULT_GOAL} special variable (@pxref{Special Variables, , 678 Other Special Variables}). 677 679 @cindex default goal 678 680 @cindex goal, default … … 956 958 with another makefile. 957 959 * Reading Makefiles:: How makefiles are parsed. 960 * Secondary Expansion:: How and when secondary expansion is performed. 958 961 @end menu 959 962 … … 1224 1227 @cindex makefiles, and @code{MAKEFILE_LIST} variable 1225 1228 @cindex including (@code{MAKEFILE_LIST} variable) 1229 @vindex MAKEFILE_LIST 1226 1230 1227 1231 As @code{make} reads various makefiles, including any obtained from the … … 1240 1244 @example 1241 1245 @group 1242 name1 := $( word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))1246 name1 := $(lastword $(MAKEFILE_LIST)) 1243 1247 1244 1248 include inc.mk 1245 1249 1246 name2 := $( word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))1250 name2 := $(lastword $(MAKEFILE_LIST)) 1247 1251 1248 1252 all: … … 1273 1277 @cindex special variables 1274 1278 1275 GNU @code{make} also supports a special variable. Note that any value 1276 you assign to this variable will be ignored; it will always return its 1277 special value. 1278 1279 @vindex $(.VARIABLES) 1279 GNU @code{make} also supports other special variables. Unless 1280 otherwise documented here, these values lose their special properties 1281 if they are set by a makefile or on the command line. 1282 1283 @table @code 1284 1285 @vindex .DEFAULT_GOAL @r{(define default goal)} 1286 @item .DEFAULT_GOAL 1287 Sets the default goal to be used if no targets were specified on the 1288 command line (@pxref{Goals, , Arguments to Specify the Goals}). The 1289 @code{.DEFAULT_GOAL} variable allows you to discover the current 1290 default goal, restart the default goal selection algorithm by clearing 1291 its value, or to explicitly set the default goal. The following 1292 example illustrates these cases: 1293 1294 @example 1295 @group 1296 # Query the default goal. 1297 ifeq ($(.DEFAULT_GOAL),) 1298 $(warning no default goal is set) 1299 endif 1300 1301 .PHONY: foo 1302 foo: ; @@echo $@@ 1303 1304 $(warning default goal is $(.DEFAULT_GOAL)) 1305 1306 # Reset the default goal. 1307 .DEFAULT_GOAL := 1308 1309 .PHONY: bar 1310 bar: ; @@echo $@@ 1311 1312 $(warning default goal is $(.DEFAULT_GOAL)) 1313 1314 # Set our own. 1315 .DEFAULT_GOAL := foo 1316 @end group 1317 @end example 1318 1319 This makefile prints: 1320 1321 @example 1322 @group 1323 no default goal is set 1324 default goal is foo 1325 default goal is bar 1326 foo 1327 @end group 1328 @end example 1329 1330 Note that assigning more than one target name to @code{.DEFAULT_GOAL} is 1331 illegal and will result in an error. 1332 1280 1333 @vindex .VARIABLES @r{(list of variables)} 1281 The first special variable is @code{.VARIABLES}. When expanded, the 1282 value consists of a list of the @emph{names} of all global variables 1283 defined in all makefiles read up until that point. This includes1284 variables which have empty values, as well as built-in variables 1285 (@pxref{Implicit Variables, , Variables Used by Implicit Rules}), but 1286 d oes not include any variables which are only defined in a1287 t arget-specific context.1288 1289 @c @vindex $(.TARGETS) 1334 @item .VARIABLES 1335 Expands to a list of the @emph{names} of all global variables defined 1336 so far. This includes variables which have empty values, as well as 1337 built-in variables (@pxref{Implicit Variables, , Variables Used by 1338 Implicit Rules}), but does not include any variables which are only 1339 defined in a target-specific context. Note that any value you assign 1340 to this variable will be ignored; it will always return its special 1341 value. 1342 1290 1343 @c @vindex .TARGETS @r{(list of targets)} 1344 @c @item .TARGETS 1291 1345 @c The second special variable is @code{.TARGETS}. When expanded, the 1292 1346 @c value consists of a list of all targets defined in all makefiles read … … 1296 1350 @c file must appear as a target, on the left-hand side of a ``:'', to be 1297 1351 @c considered a target for the purposes of this variable. 1352 1353 @vindex .FEATURES @r{(list of supported features)} 1354 @item .FEATURES 1355 Expands to a list of special features supported by this version of 1356 @code{make}. Possible values include: 1357 1358 @table @samp 1359 @item target-specific 1360 Supports target-specific and pattern-specific variable assignments. 1361 @xref{Target-specific, ,Target-specific Variable Values}. 1362 1363 @item order-only 1364 Supports order-only prerequisites. @xref{Prerequisite Types, ,Types 1365 of Prerequisites}. 1366 1367 @item second-expansion 1368 Supports secondary expansion of prerequisite lists. 1369 1370 @item jobserver 1371 Supports ``job server'' enhanced parallel builds. @xref{Parallel, 1372 ,Parallel Execution}. 1373 1374 @item check-symlink 1375 Supports the @code{-L} (@code{--check-symlink-times}) flag. 1376 @xref{Options Summary, ,Summary of Options}. 1377 1378 @end table 1379 1380 @end table 1298 1381 1299 1382 @node Remaking Makefiles, Overriding Makefiles, Special Variables, Makefiles … … 1425 1508 @file{force} itself and create a prerequisite loop! 1426 1509 1427 @node Reading Makefiles, , Overriding Makefiles, Makefiles1510 @node Reading Makefiles, Secondary Expansion, Overriding Makefiles, Makefiles 1428 1511 @section How @code{make} Reads a Makefile 1429 1512 @cindex reading makefiles … … 1486 1569 All instances of conditional syntax are parsed immediately, in their 1487 1570 entirety; this includes the @code{ifdef}, @code{ifeq}, @code{ifndef}, 1488 and @code{ifneq} forms. 1571 and @code{ifneq} forms. Of course this means that automatic variables 1572 cannot be used in conditional statements, as automatic variables are 1573 not set until the command script for that rule is invoked. If you 1574 need to use automatic variables in a conditional you @emph{must} use 1575 shell conditional syntax, in your command script proper, for these 1576 tests, not @code{make} conditionals. 1489 1577 1490 1578 @subheading Rule Definition … … 1506 1594 general rule is true for explicit rules, pattern rules, suffix rules, 1507 1595 static pattern rules, and simple prerequisite definitions. 1596 1597 @node Secondary Expansion, , Reading Makefiles, Makefiles 1598 @section Secondary Expansion 1599 @cindex secondary expansion 1600 @cindex expansion, secondary 1601 1602 In the previous section we learned that GNU @code{make} works in two 1603 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 1618 ONEVAR = onefile 1619 TWOVAR = twofile 1620 myfile: $(ONEVAR) $$(TWOVAR) 1621 @end example 1622 1623 After the first expansion phase the prerequisites list of the 1624 @file{myfile} target will be @code{onefile} and @code{$(TWOVAR)}; the 1625 first (unescaped) variable reference to @var{ONEVAR} is expanded, 1626 while the second (escaped) variable reference is simply unescaped, 1627 without being recognized as a variable reference. Now during the 1628 secondary expansion the first word is expanded again but since it 1629 contains no variable or function references it remains the static 1630 value @file{onefile}, while the second word is now a normal reference 1631 to the variable @var{TWOVAR}, which is expanded to the value 1632 @file{twofile}. The final result is that there are two prerequisites, 1633 @file{onefile} and @file{twofile}. 1634 1635 Obviously, this is not a very interesting case since the same result 1636 could more easily have been achieved simply by having both variables 1637 appear, unescaped, in the prerequisites list. One difference becomes 1638 apparent if the variables are reset; consider this example: 1639 1640 @example 1641 AVAR = top 1642 onefile: $(AVAR) 1643 twofile: $$(AVAR) 1644 AVAR = bottom 1645 @end example 1646 1647 Here the prerequisite of @file{onefile} will be expanded immediately, 1648 and resolve to the value @file{top}, while the prerequisite of 1649 @file{twofile} will not be full expanded until the secondary expansion 1650 and yield a value of @file{bottom}. 1651 1652 This is marginally more exciting, but the true power of this feature 1653 only becomes apparent when you discover that secondary expansions 1654 always take place within the scope of the automatic variables for that 1655 target. This means that you can use variables such as @code{$@@}, 1656 @code{$*}, etc. during the second expansion and they will have their 1657 expected values, just as in the command script. All you have to do is 1658 defer the expansion by escaping the @code{$}. Also, secondary 1659 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 1664 main_OBJS := main.o try.o test.o 1665 lib_OBJS := lib.o api.o 1666 1667 main lib: $$($$@@_OBJS) 1668 @end example 1669 1670 Here, after the initial expansion the prerequisites of both the 1671 @file{main} and @file{lib} targets will be @code{$($@@_OBJS)}. During 1672 the secondary expansion, the @code{$@@} variable is set to the name of 1673 the target and so the expansion for the @file{main} target will yield 1674 @code{$(main_OBJS)}, or @code{main.o try.o test.o}, while the 1675 secondary expansion for the @file{lib} target will yield 1676 @code{$(lib_OBJS)}, or @code{lib.o api.o}. 1677 1678 You can also mix functions here, as long as they are properly escaped: 1679 1680 @example 1681 main_SRCS := main.c try.c test.c 1682 lib_SRCS := lib.c api.c 1683 1684 main lib: $$(patsubst %.c,%.o,$$($$@@_SRCS)) 1685 @end example 1686 1687 This version allows users to specify source files rather than object 1688 files, but gives the same resulting prerequisites list as the previous 1689 example. 1690 1691 Evaluation of automatic variables during the secondary expansion 1692 phase, especially of the target name variable @code{$$@@}, behaves 1693 similarly to evaluation within command scripts. However, there are 1694 some subtle differences and ``corner cases'' which come into play for 1695 the different types of rule definitions that @code{make} understands. 1696 The subtleties of using the different automatic variables are 1697 described below. 1698 1699 @subheading Secondary Expansion of Explicit Rules 1700 @cindex secondary expansion and explicit rules 1701 @cindex explicit rules, secondary expansion of 1702 1703 During the secondary expansion of explicit rules, @code{$$@@} and 1704 @code{$$%} evaluate, respectively, to the file name of the target and, 1705 when the target is an archive member, the target member name. The 1706 @code{$$<} variable evaluates to the first prerequisite in the first 1707 rule for this target. @code{$$^} and @code{$$+} evaluate to the list 1708 of all prerequisites of rules @emph{that have already appeared} for 1709 the same target (@code{$$+} with repetitions and @code{$$^} 1710 without). The following example will help illustrate these behaviors: 1711 1712 @example 1713 foo: foo.1 bar.1 $$< $$^ $$+ # line #1 1714 1715 foo: foo.2 bar.2 $$< $$^ $$+ # line #2 1716 1717 foo: foo.3 bar.3 $$< $$^ $$+ # line #3 1718 @end example 1719 1720 For the first line, all three variables (@code{$$<}, @code{$$^}, and 1721 @code{$$+}) expand to the empty string. For the second line, they will 1722 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. 1726 1727 Rules undergo secondary expansion in makefile order, except that 1728 the rule with the command script is always evaluated last. 1729 1730 The variables @code{$$?} and @code{$$*} are not available and expand 1731 to the empty string. 1732 1733 @subheading Secondary Expansion of Static Pattern Rules 1734 @cindex secondary expansion and static pattern rules 1735 @cindex static pattern rules, secondary expansion of 1736 1737 Rules for secondary expansion of static pattern rules are identical to 1738 those for explicit rules, above, with one exception: for static 1739 pattern rules the @code{$$*} variable is set to the pattern stem. As 1740 with explicit rules, @code{$$?} is not available and expands to the 1741 empty string. 1742 1743 @subheading Secondary Expansion of Implicit Rules 1744 @cindex secondary expansion and implicit rules 1745 @cindex implicit rules, secondary expansion of 1746 1747 As @code{make} searches for an implicit rule, it substitutes the stem 1748 and then performs secondary expansion for every rule with a matching 1749 target pattern. The value of the automatic variables is derived in 1750 the same fashion as for static pattern rules. As an example: 1751 1752 @example 1753 foo: bar 1754 1755 foo foz: fo%: bo% 1756 1757 %oo: $$< $$^ $$+ $$* 1758 @end example 1759 1760 When the implicit rule is tried for target @file{foo}, @code{$$<} 1761 expands to @file{bar}, @code{$$^} expands to @file{bar boo}, 1762 @code{$$+} also expands to @file{bar boo}, and @code{$$*} expands to 1763 @file{f}. 1764 1765 Note that the directory prefix (D), as described in @ref{Implicit Rule 1766 Search, ,Implicit Rule Search Algorithm}, is appended (after 1767 expansion) to all the patterns in the prerequisites list. As an 1768 example: 1769 1770 @example 1771 /tmp/foo.o: 1772 1773 %.o: $$(addsuffix /%.c,foo bar) foo.h 1774 @end example 1775 1776 The prerequisite list after the secondary expansion and directory 1777 prefix reconstruction will be @file{/tmp/foo/foo.c /tmp/var/bar/foo.c 1778 foo.h}. If you are not interested in this reconstruction, you can use 1779 @code{$$*} instead of @code{%} in the prerequisites list. 1508 1780 1509 1781 @node Rules, Commands, Makefiles, Top … … 1636 1908 Because dollar signs are used to start variable references, if you really 1637 1909 want a dollar sign in a rule you must write two of them, @samp{$$} 1638 (@pxref{Using Variables, ,How to Use Variables}). 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}). 1639 1913 You may split a long line by inserting a backslash 1640 1914 followed by a newline, but this is not required, as @code{make} places no … … 2426 2700 2427 2701 @noindent 2428 Now you can say just @samp{make} to remake all three programs, or specify 2429 as arguments the ones to remake (as in @samp{make prog1 prog3}). 2702 Now you can say just @samp{make} to remake all three programs, or 2703 specify as arguments the ones to remake (as in @samp{make prog1 2704 prog3}). Phoniness is not inherited: the prerequisites of a phony 2705 target are not themselves phony, unless explicitly declared to be so. 2430 2706 2431 2707 When one phony target is a prerequisite of another, it serves as a subroutine … … 3163 3439 Note that the @samp{.d} files contain target definitions; you should 3164 3440 be sure to place the @code{include} directive @emph{after} the first, 3165 default targetin your makefiles or run the risk of having a random3166 object file become the default target.3441 default goal in your makefiles or run the risk of having a random 3442 object file become the default goal. 3167 3443 @xref{How Make Works}. 3168 3444 … … 3357 3633 3358 3634 @cindex environment, @code{SHELL} in 3635 @vindex MAKESHELL @r{(MS-DOS alternative to @code{SHELL})} 3359 3636 Unlike most variables, the variable @code{SHELL} is never set from the 3360 3637 environment. This is because the @code{SHELL} environment variable is … … 3733 4010 characters other than letters, numbers, and underscores. 3734 4011 3735 The special variables @code{SHELL} and @code{MAKEFLAGS} are always 3736 exported (unless you unexport them). 3737 @code{MAKEFILES} is exported if you set it to anything. 4012 @cindex SHELL, exported value 4013 The value of the @code{make} variable @code{SHELL} is not exported. 4014 Instead, the value of the @code{SHELL} variable from the invoking 4015 environment is passed to the sub-@code{make}. You can force 4016 @code{make} to export its value for @code{SHELL} by using the 4017 @code{export} directive, described below. 4018 4019 The special variable @code{MAKEFLAGS} is always exported (unless you 4020 unexport it). @code{MAKEFILES} is exported if you set it to anything. 3738 4021 3739 4022 @code{make} automatically passes down variable values that were defined … … 5138 5421 @cindex environment 5139 5422 Variables in @code{make} can come from the environment in which 5140 @code{make} is run. Every environment variable that @code{make} sees when5141 it starts up is transformed into a @code{make} variable with the same name5142 and value. But an explicit assignment in the makefile, or with a command 5143 argument, overrides the environment. (If the @samp{-e} flag is specified, 5144 then values from the environment override assignments in the makefile. 5145 @xref{Options Summary, ,Summary of Options}. 5146 But this is not recommended practice.)5423 @code{make} is run. Every environment variable that @code{make} sees 5424 when it starts up is transformed into a @code{make} variable with the 5425 same name and value. However, an explicit assignment in the makefile, 5426 or with a command argument, overrides the environment. (If the 5427 @samp{-e} flag is specified, then values from the environment override 5428 assignments in the makefile. @xref{Options Summary, ,Summary of 5429 Options}. But this is not recommended practice.) 5147 5430 5148 5431 Thus, by setting the variable @code{CFLAGS} in your environment, you can 5149 5432 cause all C compilations in most makefiles to use the compiler switches you 5150 5433 prefer. This is safe for variables with standard or conventional meanings 5151 because you know that no makefile will use them for other things. ( But5434 because you know that no makefile will use them for other things. (Note 5152 5435 this is not totally reliable; some makefiles set @code{CFLAGS} explicitly 5153 5436 and therefore are not affected by the value in the environment.) 5154 5437 5155 When @code{make} is invoked recursively, variables defined in the5156 outer invocation can be passed to inner invocations through the 5157 environment (@pxref{Recursion, ,Recursive Use of @code{make}}). By 5158 default, only variables that came from the environment or the command 5159 line are passed to recursive invocations. You can use the5160 @code{export} directive to pass other variables. 5161 @xref{Variables/Recursion, , Communicating Variables to a5438 When @code{make} runs a command script, variables defined in the 5439 makefile are placed into the environment of that command. This allows 5440 you to pass values to sub-@code{make} invocations. (@pxref{Recursion, 5441 ,Recursive Use of @code{make}}). By default, only variables that came 5442 from the environment or the command line are passed to recursive 5443 invocations. You can use the @code{export} directive to pass other 5444 variables. @xref{Variables/Recursion, , Communicating Variables to a 5162 5445 Sub-@code{make}}, for full details. 5163 5446 … … 5168 5451 purpose of most makefiles. 5169 5452 5453 @cindex SHELL, import from environment 5170 5454 Such problems would be especially likely with the variable @code{SHELL}, 5171 5455 which is normally present in the environment to specify the user's choice … … 5175 5459 usually not set. @xref{Execution, ,Special handling of SHELL on 5176 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. 5177 5470 5178 5471 @node Target-specific, Pattern-specific, Environment, Using Variables … … 5431 5724 @end example 5432 5725 5433 @noindent 5434 If the condition is true, @var{text-if-true} is used; otherwise, 5435 @var{text-if-false} is used instead. The @var{text-if-false} can be any 5436 number of lines of text. 5726 or: 5727 5728 @example 5729 @var{conditional-directive} 5730 @var{text-if-one-is-true} 5731 else @var{conditional-directive} 5732 @var{text-if-true} 5733 else 5734 @var{text-if-false} 5735 endif 5736 @end example 5737 5738 @noindent 5739 There can be as many ``@code{else} @var{conditional-directive}'' 5740 clauses as necessary. Once a given condition is true, 5741 @var{text-if-true} is used and no other clause is used; if no 5742 condition is true then @var{text-if-false} is used. The 5743 @var{text-if-true} and @var{text-if-false} can be any number of lines 5744 of text. 5437 5745 5438 5746 The syntax of the @var{conditional-directive} is the same whether the 5439 conditional is simple or complex. There are four different directives that 5440 test different conditions. Here is a table of them: 5747 conditional is simple or complex; after an @code{else} or not. There 5748 are four different directives that test different conditions. Here is 5749 a table of them: 5441 5750 5442 5751 @table @code … … 5479 5788 5480 5789 @item ifdef @var{variable-name} 5481 If the variable @var{variable-name} has a non-empty value, the 5482 @var{text-if-true} is effective; otherwise, the @var{text-if-false}, 5483 if any, is effective. Variables that have never been defined have an 5484 empty value. The variable @var{variable-name} is itself expanded, so 5485 it could be a variable or function that expands to the name of a 5486 variable. 5790 The @code{ifdef} form takes the @emph{name} of a variable as its 5791 argument, not a reference to a variable. The value of that variable 5792 has a non-empty value, the @var{text-if-true} is effective; otherwise, 5793 the @var{text-if-false}, if any, is effective. Variables that have 5794 never been defined have an empty value. The text @var{variable-name} 5795 is expanded, so it could be a variable or function that expands 5796 to the name of a variable. For example: 5797 5798 @example 5799 bar = true 5800 foo = bar 5801 ifdef $(foo) 5802 frobozz = yes 5803 endif 5804 @end example 5805 5806 The variable reference @code{$(foo)} is expanded, yielding @code{bar}, 5807 which is considered to be the name of a variable. The variable 5808 @code{bar} is not expanded, but its value is examined to determine if 5809 it is non-empty. 5487 5810 5488 5811 Note that @code{ifdef} only tests whether a variable has a value. It … … 5520 5843 If the variable @var{variable-name} has an empty value, the 5521 5844 @var{text-if-true} is effective; otherwise, the @var{text-if-false}, 5522 if any, is effective. 5845 if any, is effective. The rules for expansion and testing of 5846 @var{variable-name} are identical to the @code{ifdef} directive. 5523 5847 @end table 5524 5848 … … 5927 6251 Returns the list of words in @var{text} starting with word @var{s} and 5928 6252 ending with word @var{e} (inclusive). The legitimate values of @var{s} 5929 and @var{e} start from 1. If @var{s} is bigger than the number of words 5930 in @var{text}, the value is empty. If @var{e} is bigger than the number 5931 of words in @var{text}, words up to the end of @var{text} are returned. 5932 If @var{s} is greater than @var{e}, nothing is returned. For example, 6253 start from 1; @var{e} may start from 0. If @var{s} is bigger than the 6254 number of words in @var{text}, the value is empty. If @var{e} is 6255 bigger than the number of words in @var{text}, words up to the end of 6256 @var{text} are returned. If @var{s} is greater than @var{e}, nothing 6257 is returned. For example, 5933 6258 5934 6259 @example … … 5964 6289 @var{text})} is the same as @code{$(word 1,@var{text})}, the 5965 6290 @code{firstword} function is retained for its simplicity.@refill 6291 6292 6293 @item $(lastword @var{names}@dots{}) 6294 @findex lastword 6295 @cindex words, extracting last 6296 The argument @var{names} is regarded as a series of names, separated 6297 by whitespace. The value is the last name in the series. 6298 6299 For example, 6300 6301 @example 6302 $(lastword foo bar) 6303 @end example 6304 6305 @noindent 6306 produces the result @samp{bar}. Although @code{$(lastword 6307 @var{text})} is the same as @code{$(word $(words @var{text}),@var{text})}, 6308 the @code{lastword} function was added for its simplicity and better 6309 performance.@refill 5966 6310 @end table 6311 5967 6312 5968 6313 Here is a realistic example of the use of @code{subst} and … … 6153 6498 that match the pattern. 6154 6499 @xref{Wildcards, ,Using Wildcard Characters in File Names}. 6500 6501 @item $(realpath @var{names}@dots{}) 6502 @findex realpath 6503 @cindex realpath 6504 @cindex file name, realpath of 6505 For each file name in @var{names} return the canonical absolute name. 6506 A canonical name does not contain any @code{.} or @code{..} components, 6507 nor any repeated path separators (@code{/}) or symlinks. In case of a 6508 failure the empty string is returned. Consult the @code{realpath(3)} 6509 documentation for a list of possible failure causes. 6510 6511 @item $(abspath @var{names}@dots{}) 6512 @findex abspath 6513 @cindex abspath 6514 @cindex file name, abspath of 6515 For each file name in @var{names} return an absolute name that does 6516 not contain any @code{.} or @code{..} components, nor any repeated path 6517 separators (@code{/}). Note that in contrast to @code{realpath} 6518 function, @code{abspath} does not resolve symlinks and does not require 6519 the file names to refer to an existing file or directory. Use the 6520 @code{wildcard} function to test for existence. 6155 6521 @end table 6156 6522 … … 6638 7004 sets @code{files} to the expansion of @samp{*.c}. Unless @code{make} is 6639 7005 using a very strange shell, this has the same result as 6640 @w{@samp{$(wildcard *.c)}}.@refill 7006 @w{@samp{$(wildcard *.c)}} (as long as at least one @samp{.c} file 7007 exists).@refill 6641 7008 6642 7009 @node Make Control Functions, , Shell Function, Functions … … 6693 7060 6694 7061 The result of the expansion of this function is the empty string. 7062 7063 @item $(info @var{text}@dots{}) 7064 @findex info 7065 @cindex printing messages 7066 This function does nothing more than print its (expanded) argument(s) 7067 to standard output. No makefile name or line number is added. The 7068 result of the expansion of this function is the empty string. 6695 7069 @end table 6696 7070 … … 6771 7145 programs they describe. If the first rule in the makefile has several 6772 7146 targets, only the first target in the rule becomes the default goal, not 6773 the whole list. 6774 6775 You can specify a different goal or goals with arguments to @code{make}. 6776 Use the name of the goal as an argument. If you specify several goals, 6777 @code{make} processes each of them in turn, in the order you name them. 7147 the whole list. You can manage the selection of the default goal from 7148 within your makefile using the @code{.DEFAULT_GOAL} variable 7149 (@pxref{Special Variables, , Other Special Variables}). 7150 7151 You can also specify a different goal or goals with command-line 7152 arguments to @code{make}. Use the name of the goal as an argument. 7153 If you specify several goals, @code{make} processes each of them in 7154 turn, in the order you name them. 6778 7155 6779 7156 Any target in the makefile may be specified as a goal (unless it … … 6783 7160 implicit rules that say how to make them. 6784 7161 6785 @cindex @code{MAKECMDGOALS}6786 7162 @vindex MAKECMDGOALS 6787 7163 @code{Make} will set the special variable @code{MAKECMDGOALS} to the … … 7308 7684 floating-point number). With no argument, removes a previous load 7309 7685 limit. @xref{Parallel, ,Parallel Execution}. 7686 7687 @item -L 7688 @cindex @code{-L} 7689 @itemx --check-symlink-times 7690 @cindex @code{--check-symlink-times} 7691 On systems that support symbolic links, this option causes @code{make} 7692 to consider the timestamps on any symbolic links in addition to the 7693 timestamp on the file referenced by those links. When this option is 7694 provided, the most recent timestamp among the file and the symbolic 7695 links is taken as the modification time for this target file. 7310 7696 7311 7697 @item -n … … 7520 7906 * Chained Rules:: How to use a chain of implicit rules. 7521 7907 * Pattern Rules:: How to define new implicit rules. 7522 * Last Resort:: How to defin ing commands for rules7523 whichcannot find any.7908 * Last Resort:: How to define commands for rules which 7909 cannot find any. 7524 7910 * Suffix Rules:: The old-fashioned style of implicit rule. 7525 7911 * Implicit Rule Search:: The precise algorithm for applying … … 8372 8758 automatic variable values are available: they only have values within 8373 8759 the command script. In particular, you cannot use them anywhere 8374 within the target or prerequisite lists of a rule; they have no value 8375 there and will expand to the empty string. A common mistake is 8376 attempting to use @code{$@@} within the prerequisites list in a rule; 8377 this will not work. However, see below for information on the 8378 SysV-style @code{$$@@} variables. 8760 within the target list of a rule; they have no value there and will 8761 expand to the empty string. Also, they cannot be accessed directly 8762 within the prerequisite list of a rule. A common mistake is 8763 attempting to use @code{$@@} within the prerequisites list; this will 8764 not work. However, there is a special feature of GNU @code{make}, 8765 secondary expansion (@pxref{Secondary Expansion}), which will allow 8766 automatic variable values to be used in prerequisite lists. 8379 8767 8380 8768 Here is a table of automatic variables: … … 8422 8810 it depends on, no matter how many times each file is listed as a 8423 8811 prerequisite. So if you list a prerequisite more than once for a target, 8424 the value of @code{$^} contains just one copy of the name. 8812 the value of @code{$^} contains just one copy of the name. This list 8813 does @strong{not} contain any of the order-only prerequisites; for those 8814 see the @samp{$|} variable, below. 8425 8815 @cindex prerequisites, list of all 8426 8816 @cindex list of all prerequisites … … 8433 8823 primarily useful for use in linking commands where it is meaningful to 8434 8824 repeat library file names in a particular order. 8825 8826 @vindex $| 8827 @vindex | @r{(automatic variable)} 8828 @item $| 8829 The names of all the order-only prerequisites, with spaces between 8830 them. 8435 8831 8436 8832 @vindex $* … … 8565 8961 as @samp{$(CFLAGS)} refers to the variable named @code{CFLAGS}. 8566 8962 You could just as well use @samp{$(<)} in place of @samp{$<}. 8567 8568 @vindex $$@@8569 @vindex $$(@@D)8570 @vindex $$(@@F)8571 @cindex $$@@, support for8572 GNU @code{make} provides support for the SysV @code{make} feature that8573 allows special variable references @code{$$@@}, @code{$$(@@D)}, and8574 @code{$$(@@F)} (note the required double-''$''!) to appear with the8575 @emph{prerequisites list} (normal automatic variables are available8576 only within a command script). When appearing in a prerequisites8577 list, these variables are expanded to the name of the target, the8578 directory component of the target, and the file component of the8579 target, respectively.8580 8581 Note that these variables are available only within explicit and8582 static pattern (@pxref{Static Pattern, ,Static Pattern Rules}) rules;8583 they have no special significance within implicit (suffix or pattern)8584 rules. Also note that while SysV @code{make} actually expands its8585 entire prerequisite list @emph{twice}, GNU @code{make} does not behave8586 this way: instead it simply expands these special variables without8587 re-expanding any other part of the prerequisites list.8588 8589 This somewhat bizarre feature is included only to provide some8590 compatibility with SysV makefiles. In a native GNU @code{make} file8591 there are other ways to accomplish the same results. This feature is8592 disabled if the special pseudo target @code{.POSIX} is defined.8593 8963 8594 8964 @node Pattern Match, Match-Anything Rules, Automatic Variables, Pattern Rules … … 9446 9816 The built-in variable @samp{MAKE_VERSION} gives the version number of 9447 9817 @code{make}. 9818 @vindex MAKE_VERSION 9448 9819 @end itemize 9449 9820 … … 9635 10006 @end table 9636 10007 9637 Here is a summary of the text manipulation functions (@pxref{Functions}):10008 Here is a summary of the built-in functions (@pxref{Functions}): 9638 10009 9639 10010 @table @code … … 9666 10037 @xref{Text Functions, , Functions for String Substitution and Analysis}. 9667 10038 10039 @item $(word @var{n},@var{text}) 10040 Extract the @var{n}th word (one-origin) of @var{text}.@* 10041 @xref{Text Functions, , Functions for String Substitution and Analysis}. 10042 10043 @item $(words @var{text}) 10044 Count the number of words in @var{text}.@* 10045 @xref{Text Functions, , Functions for String Substitution and Analysis}. 10046 10047 @item $(wordlist @var{s},@var{e},@var{text}) 10048 Returns the list of words in @var{text} from @var{s} to @var{e}.@* 10049 @xref{Text Functions, , Functions for String Substitution and Analysis}. 10050 10051 @item $(firstword @var{names}@dots{}) 10052 Extract the first word of @var{names}.@* 10053 @xref{Text Functions, , Functions for String Substitution and Analysis}. 10054 10055 @item $(lastword @var{names}@dots{}) 10056 Extract the last word of @var{names}.@* 10057 @xref{Text Functions, , Functions for String Substitution and Analysis}. 10058 9668 10059 @item $(dir @var{names}@dots{}) 9669 10060 Extract the directory part of each file name.@* … … 9692 10083 @item $(join @var{list1},@var{list2}) 9693 10084 Join two parallel lists of words.@* 9694 @xref{File Name Functions, ,Functions for File Names}.9695 9696 @item $(word @var{n},@var{text})9697 Extract the @var{n}th word (one-origin) of @var{text}.@*9698 @xref{File Name Functions, ,Functions for File Names}.9699 9700 @item $(words @var{text})9701 Count the number of words in @var{text}.@*9702 @xref{File Name Functions, ,Functions for File Names}.9703 9704 @item $(wordlist @var{s},@var{e},@var{text})9705 Returns the list of words in @var{text} from @var{s} to @var{e}.@*9706 @xref{File Name Functions, ,Functions for File Names}.9707 9708 @item $(firstword @var{names}@dots{})9709 Extract the first word of @var{names}.@*9710 10085 @xref{File Name Functions, ,Functions for File Names}. 9711 10086 … … 9714 10089 @samp{%} pattern).@* 9715 10090 @xref{Wildcard Function, ,The Function @code{wildcard}}. 10091 10092 @item $(realpath @var{names}@dots{}) 10093 For each file name in @var{names}, expand to an absolute name that 10094 does not contain any @code{.}, @code{..}, nor symlinks.@* 10095 @xref{File Name Functions, ,Functions for File Names}. 10096 10097 @item $(abspath @var{names}@dots{}) 10098 For each file name in @var{names}, expand to an absolute name that 10099 does not contain any @code{.} or @code{..} components, but preserves 10100 symlinks.@* 10101 @xref{File Name Functions, ,Functions for File Names}. 9716 10102 9717 10103 @item $(error @var{text}@dots{}) … … 9840 10226 The name of the system default command interpreter, usually @file{/bin/sh}. 9841 10227 You can set @code{SHELL} in the makefile to change the shell used to run 9842 commands. @xref{Execution, ,Command Execution}. 10228 commands. @xref{Execution, ,Command Execution}. The @code{SHELL} 10229 variable is handled specially when importing from and exporting to the 10230 environment. @xref{Environment, ,Using Variable from the Environment}. 9843 10231 9844 10232 @item MAKESHELL … … 9970 10358 command line, and @code{make} couldn't find any makefiles to read in. 9971 10359 The latter means that some makefile was found, but it didn't contain any 9972 default targetand none was given on the command line. GNU @code{make}10360 default goal and none was given on the command line. GNU @code{make} 9973 10361 has nothing to do in these situations. 9974 10362 @xref{Makefile Arguments, ,Arguments to Specify the Makefile}.@refill … … 10221 10609 @end group 10222 10610 10611 .PHONY: all 10223 10612 all: tar rmt tar.info 10224 10613 10225 10614 @group 10615 .PHONY: tar 10226 10616 tar: $(OBJS) 10227 10617 $(CC) $(LDFLAGS) -o $@@ $(OBJS) $(LIBS) … … 10239 10629 10240 10630 @group 10631 .PHONY: install 10241 10632 install: all 10242 10633 $(INSTALL) tar $(bindir)/$(binprefix)tar … … 10267 10658 10268 10659 @group 10660 .PHONY: clean 10269 10661 clean: 10270 10662 rm -f *.o tar rmt testpad testpad.h core … … 10272 10664 10273 10665 @group 10666 .PHONY: distclean 10274 10667 distclean: clean 10275 10668 rm -f TAGS Makefile config.status … … 10277 10670 10278 10671 @group 10672 .PHONY: realclean 10279 10673 realclean: distclean 10280 10674 rm -f tar.info* … … 10282 10676 10283 10677 @group 10678 .PHONY: shar 10284 10679 shar: $(SRCS) $(AUX) 10285 10680 shar $(SRCS) $(AUX) | compress \ … … 10291 10686 10292 10687 @group 10688 .PHONY: dist 10293 10689 dist: $(SRCS) $(AUX) 10294 10690 echo tar-`sed \
Note:
See TracChangeset
for help on using the changeset viewer.