Ignore:
Timestamp:
May 16, 2005, 6:54:02 PM (20 years ago)
Author:
bird
Message:

Current make snaphot, 2005-05-16.

Location:
branches/GNU/src/gmake
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/gmake

    • Property svn:ignore
      •  

        old new  
        3434README.DOS
        3535README.W32
         36README.OS2
        3637aclocal.m4
        3738autom4te.cache
  • branches/GNU/src/gmake/doc/make.texi

    r153 r280  
    88@c FSF publishers: format makebook.texi instead of using this file directly.
    99
    10 @set RCSID $Id: make.texi,v 1.18 2004/02/23 06:25:54 psmith Exp $
    11 @set EDITION 0.61
     10@set RCSID $Id: make.texi,v 1.30 2005/05/13 12:45:31 psmith Exp $
     11@set EDITION 0.70
    1212@set VERSION 3.81
    13 @set UPDATED 02 May 2003
    14 @set UPDATE-MONTH May 2003
    15 @comment The ISBN number might need to change on next publication.
    16 @set ISBN 1-882114-81-7 @c From Brian Youmans <3diff@gnu.org>, 25 Apr 2000
     13@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
    1717
    1818@c finalout
     
    4040
    4141Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    42 1998, 1999, 2000, 2002, 2003, 2004
     421998, 1999, 2000, 2002, 2003, 2004, 2005
    4343Free Software Foundation, Inc.
    4444
     
    163163                                  with another makefile.
    164164* Reading Makefiles::           How makefiles are parsed.
     165* Secondary Expansion::         How and when secondary expansion is performed.
    165166
    166167Writing Rules
     
    339340* Install Command Categories::  Three categories of commands in the `install'
    340341
    341 Copying This Manual
    342 
    343342@end detailmenu
    344343@end menu
     
    643642prerequisites.  These shell commands say how to update the target file.
    644643A tab character must come at the beginning of every command line to
    645 distinguish commands lines from other lines in the makefile.  (Bear in
     644distinguish command lines from other lines in the makefile.  (Bear in
    646645mind that @code{make} does not know anything about how the commands
    647646work.  It is up to you to supply commands that will update the target
     
    674673names start with @samp{.}).  This is called the @dfn{default goal}.
    675674(@dfn{Goals} are the targets that @code{make} strives ultimately to
    676 update.  @xref{Goals, , Arguments to Specify the Goals}.)
     675update.    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, ,
     678Other Special Variables}).
    677679@cindex default goal
    678680@cindex goal, default
     
    956958                                  with another makefile.
    957959* Reading Makefiles::           How makefiles are parsed.
     960* Secondary Expansion::         How and when secondary expansion is performed.
    958961@end menu
    959962
     
    12241227@cindex makefiles, and @code{MAKEFILE_LIST} variable
    12251228@cindex including (@code{MAKEFILE_LIST} variable)
     1229@vindex MAKEFILE_LIST
    12261230
    12271231As @code{make} reads various makefiles, including any obtained from the
     
    12401244@example
    12411245@group
    1242 name1 := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
     1246name1 := $(lastword $(MAKEFILE_LIST))
    12431247
    12441248include inc.mk
    12451249
    1246 name2 := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
     1250name2 := $(lastword $(MAKEFILE_LIST))
    12471251
    12481252all:
     
    12731277@cindex special variables
    12741278
    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)
     1279GNU @code{make} also supports other special variables.  Unless
     1280otherwise documented here, these values lose their special properties
     1281if 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
     1287Sets the default goal to be used if no targets were specified on the
     1288command line (@pxref{Goals, , Arguments to Specify the Goals}).  The
     1289@code{.DEFAULT_GOAL} variable allows you to discover the current
     1290default goal, restart the default goal selection algorithm by clearing
     1291its value, or to explicitly set the default goal. The following
     1292example illustrates these cases:
     1293
     1294@example
     1295@group
     1296# Query the default goal.
     1297ifeq ($(.DEFAULT_GOAL),)
     1298  $(warning no default goal is set)
     1299endif
     1300
     1301.PHONY: foo
     1302foo: ; @@echo $@@
     1303
     1304$(warning default goal is $(.DEFAULT_GOAL))
     1305
     1306# Reset the default goal.
     1307.DEFAULT_GOAL :=
     1308
     1309.PHONY: bar
     1310bar: ; @@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
     1319This makefile prints:
     1320
     1321@example
     1322@group
     1323no default goal is set
     1324default goal is foo
     1325default goal is bar
     1326foo
     1327@end group
     1328@end example
     1329
     1330Note that assigning more than one target name to @code{.DEFAULT_GOAL} is
     1331illegal and will result in an error.
     1332
    12801333@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 includes
    1284 variables which have empty values, as well as built-in variables
    1285 (@pxref{Implicit Variables, , Variables Used by Implicit Rules}), but
    1286 does not include any variables which are only defined in a
    1287 target-specific context.
    1288 
    1289 @c @vindex $(.TARGETS)
     1334@item .VARIABLES
     1335Expands to a list of the @emph{names} of all global variables defined
     1336so far.  This includes variables which have empty values, as well as
     1337built-in variables (@pxref{Implicit Variables, , Variables Used by
     1338Implicit Rules}), but does not include any variables which are only
     1339defined in a target-specific context.  Note that any value you assign
     1340to this variable will be ignored; it will always return its special
     1341value.
     1342
    12901343@c @vindex .TARGETS @r{(list of targets)}
     1344@c @item .TARGETS
    12911345@c The second special variable is @code{.TARGETS}.  When expanded, the
    12921346@c value consists of a list of all targets defined in all makefiles read
     
    12961350@c file must appear as a target, on the left-hand side of a ``:'', to be
    12971351@c considered a target for the purposes of this variable.
     1352
     1353@vindex .FEATURES @r{(list of supported features)}
     1354@item .FEATURES
     1355Expands 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
     1360Supports target-specific and pattern-specific variable assignments.
     1361@xref{Target-specific, ,Target-specific Variable Values}.
     1362
     1363@item order-only
     1364Supports order-only prerequisites.  @xref{Prerequisite Types, ,Types
     1365of Prerequisites}.
     1366
     1367@item second-expansion
     1368Supports secondary expansion of prerequisite lists.
     1369
     1370@item jobserver
     1371Supports ``job server'' enhanced parallel builds.  @xref{Parallel,
     1372,Parallel Execution}.
     1373
     1374@item check-symlink
     1375Supports the @code{-L} (@code{--check-symlink-times}) flag.
     1376@xref{Options Summary, ,Summary of Options}.
     1377
     1378@end table
     1379
     1380@end table
    12981381
    12991382@node Remaking Makefiles, Overriding Makefiles, Special Variables, Makefiles
     
    14251508@file{force} itself and create a prerequisite loop!
    14261509
    1427 @node Reading Makefiles,  , Overriding Makefiles, Makefiles
     1510@node Reading Makefiles,  Secondary Expansion, Overriding Makefiles, Makefiles
    14281511@section How @code{make} Reads a Makefile
    14291512@cindex reading makefiles
     
    14861569All instances of conditional syntax are parsed immediately, in their
    14871570entirety; this includes the @code{ifdef}, @code{ifeq}, @code{ifndef},
    1488 and @code{ifneq} forms.
     1571and @code{ifneq} forms.  Of course this means that automatic variables
     1572cannot be used in conditional statements, as automatic variables are
     1573not set until the command script for that rule is invoked.  If you
     1574need to use automatic variables in a conditional you @emph{must} use
     1575shell conditional syntax, in your command script proper, for these
     1576tests, not @code{make} conditionals.
    14891577
    14901578@subheading Rule Definition
     
    15061594general rule is true for explicit rules, pattern rules, suffix rules,
    15071595static 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
     1602In the previous section we learned that GNU @code{make} works in two
     1603distinct phases: a read-in phase and a target-update phase
     1604(@pxref{Reading Makefiles, , How @code{make} Reads a Makefile}).
     1605There is an extra wrinkle that comes in between those two phases,
     1606right at the end of the read-in phase: at that time, all the
     1607prerequisites of all of the targets are expanded a @emph{second time}.
     1608In most circumstances this secondary expansion will have no effect,
     1609since all variable and function references will have been expanded
     1610during the initial parsing of the makefiles.  In order to take
     1611advantage of the secondary expansion phase of the parser, then, it's
     1612necessary to @emph{escape} the variable or function reference in the
     1613makefile.  In this case the first expansion merely un-escapes the
     1614reference but doesn't expand it, and expansion is left to the
     1615secondary expansion phase.  For example, consider this makefile:
     1616
     1617@example
     1618ONEVAR = onefile
     1619TWOVAR = twofile
     1620myfile: $(ONEVAR) $$(TWOVAR)
     1621@end example
     1622
     1623After the first expansion phase the prerequisites list of the
     1624@file{myfile} target will be @code{onefile} and @code{$(TWOVAR)}; the
     1625first (unescaped) variable reference to @var{ONEVAR} is expanded,
     1626while the second (escaped) variable reference is simply unescaped,
     1627without being recognized as a variable reference.  Now during the
     1628secondary expansion the first word is expanded again but since it
     1629contains no variable or function references it remains the static
     1630value @file{onefile}, while the second word is now a normal reference
     1631to 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
     1635Obviously, this is not a very interesting case since the same result
     1636could more easily have been achieved simply by having both variables
     1637appear, unescaped, in the prerequisites list.  One difference becomes
     1638apparent if the variables are reset; consider this example:
     1639
     1640@example
     1641AVAR = top
     1642onefile: $(AVAR)
     1643twofile: $$(AVAR)
     1644AVAR = bottom
     1645@end example
     1646
     1647Here the prerequisite of @file{onefile} will be expanded immediately,
     1648and resolve to the value @file{top}, while the prerequisite of
     1649@file{twofile} will not be full expanded until the secondary expansion
     1650and yield a value of @file{bottom}.
     1651
     1652This is marginally more exciting, but the true power of this feature
     1653only becomes apparent when you discover that secondary expansions
     1654always take place within the scope of the automatic variables for that
     1655target.  This means that you can use variables such as @code{$@@},
     1656@code{$*}, etc. during the second expansion and they will have their
     1657expected values, just as in the command script.  All you have to do is
     1658defer the expansion by escaping the @code{$}.  Also, secondary
     1659expansion occurs for both explicit and implicit (pattern) rules.
     1660Knowing this, the possible uses for this feature are almost endless.
     1661For example:
     1662
     1663@example
     1664main_OBJS := main.o try.o test.o
     1665lib_OBJS := lib.o api.o
     1666
     1667main lib: $$($$@@_OBJS)
     1668@end example
     1669
     1670Here, after the initial expansion the prerequisites of both the
     1671@file{main} and @file{lib} targets will be @code{$($@@_OBJS)}.  During
     1672the secondary expansion, the @code{$@@} variable is set to the name of
     1673the 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
     1675secondary expansion for the @file{lib} target will yield
     1676@code{$(lib_OBJS)}, or @code{lib.o api.o}.
     1677
     1678You can also mix functions here, as long as they are properly escaped:
     1679
     1680@example
     1681main_SRCS := main.c try.c test.c
     1682lib_SRCS := lib.c api.c
     1683
     1684main lib: $$(patsubst %.c,%.o,$$($$@@_SRCS))
     1685@end example
     1686
     1687This version allows users to specify source files rather than object
     1688files, but gives the same resulting prerequisites list as the previous
     1689example.
     1690
     1691Evaluation of automatic variables during the secondary expansion
     1692phase, especially of the target name variable @code{$$@@}, behaves
     1693similarly to evaluation within command scripts.  However, there are
     1694some subtle differences and ``corner cases'' which come into play for
     1695the different types of rule definitions that @code{make} understands.
     1696The subtleties of using the different automatic variables are
     1697described below.
     1698
     1699@subheading Secondary Expansion of Explicit Rules
     1700@cindex secondary expansion and explicit rules
     1701@cindex explicit rules, secondary expansion of
     1702
     1703During the secondary expansion of explicit rules, @code{$$@@} and
     1704@code{$$%} evaluate, respectively, to the file name of the target and,
     1705when the target is an archive member, the target member name.  The
     1706@code{$$<} variable evaluates to the first prerequisite in the first
     1707rule for this target.  @code{$$^} and @code{$$+} evaluate to the list
     1708of all prerequisites of rules @emph{that have already appeared} for
     1709the same target (@code{$$+} with repetitions and @code{$$^}
     1710without). The following example will help illustrate these behaviors:
     1711
     1712@example
     1713foo: foo.1 bar.1 $$< $$^ $$+    # line #1
     1714
     1715foo: foo.2 bar.2 $$< $$^ $$+    # line #2
     1716
     1717foo: foo.3 bar.3 $$< $$^ $$+    # line #3
     1718@end example
     1719
     1720For the first line, all three variables (@code{$$<}, @code{$$^}, and
     1721@code{$$+}) expand to the empty string. For the second line, they will
     1722have values @code{foo.1}, @code{foo.1 bar.1}, and @code{foo.1 bar.1}
     1723respectively. 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}
     1725respectively.
     1726
     1727Rules undergo secondary expansion in makefile order, except that
     1728the rule with the command script is always evaluated last.
     1729
     1730The variables @code{$$?} and @code{$$*} are not available and expand
     1731to 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
     1737Rules for secondary expansion of static pattern rules are identical to
     1738those for explicit rules, above, with one exception: for static
     1739pattern rules the @code{$$*} variable is set to the pattern stem.  As
     1740with explicit rules, @code{$$?} is not available and expands to the
     1741empty string.
     1742
     1743@subheading Secondary Expansion of Implicit Rules
     1744@cindex secondary expansion and implicit rules
     1745@cindex implicit rules, secondary expansion of
     1746
     1747As @code{make} searches for an implicit rule, it substitutes the stem
     1748and then performs secondary expansion for every rule with a matching
     1749target pattern.  The value of the automatic variables is derived in
     1750the same fashion as for static pattern rules.  As an example:
     1751
     1752@example
     1753foo: bar
     1754
     1755foo foz: fo%: bo%
     1756
     1757%oo: $$< $$^ $$+ $$*
     1758@end example
     1759
     1760When the implicit rule is tried for target @file{foo}, @code{$$<}
     1761expands 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
     1765Note that the directory prefix (D), as described in @ref{Implicit Rule
     1766Search, ,Implicit Rule Search Algorithm}, is appended (after
     1767expansion) to all the patterns in the prerequisites list.  As an
     1768example:
     1769
     1770@example
     1771/tmp/foo.o:
     1772
     1773%.o: $$(addsuffix /%.c,foo bar) foo.h
     1774@end example
     1775
     1776The prerequisite list after the secondary expansion and directory
     1777prefix reconstruction will be @file{/tmp/foo/foo.c /tmp/var/bar/foo.c
     1778foo.h}.  If you are not interested in this reconstruction, you can use
     1779@code{$$*} instead of @code{%} in the prerequisites list.
    15081780
    15091781@node Rules, Commands, Makefiles, Top
     
    16361908Because dollar signs are used to start variable references, if you really
    16371909want 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
     1911lists you must actually write @emph{four} dollar signs (@samp{$$$$}),
     1912due to secondary expansion (@pxref{Secondary Expansion}).
    16391913You may split a long line by inserting a backslash
    16401914followed by a newline, but this is not required, as @code{make} places no
     
    24262700
    24272701@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}).
     2702Now you can say just @samp{make} to remake all three programs, or
     2703specify as arguments the ones to remake (as in @samp{make prog1
     2704prog3}).  Phoniness is not inherited: the prerequisites of a phony
     2705target are not themselves phony, unless explicitly declared to be so.
    24302706
    24312707When one phony target is a prerequisite of another, it serves as a subroutine
     
    31633439Note that the @samp{.d} files contain target definitions; you should
    31643440be sure to place the @code{include} directive @emph{after} the first,
    3165 default target in your makefiles or run the risk of having a random
    3166 object file become the default target.
     3441default goal in your makefiles or run the risk of having a random
     3442object file become the default goal.
    31673443@xref{How Make Works}.
    31683444
     
    33573633
    33583634@cindex environment, @code{SHELL} in
     3635@vindex MAKESHELL @r{(MS-DOS alternative to @code{SHELL})}
    33593636Unlike most variables, the variable @code{SHELL} is never set from the
    33603637environment.  This is because the @code{SHELL} environment variable is
     
    37334010characters other than letters, numbers, and underscores.
    37344011
    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
     4013The value of the @code{make} variable @code{SHELL} is not exported.
     4014Instead, the value of the @code{SHELL} variable from the invoking
     4015environment 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
     4019The special variable @code{MAKEFLAGS} is always exported (unless you
     4020unexport it).  @code{MAKEFILES} is exported if you set it to anything.
    37384021
    37394022@code{make} automatically passes down variable values that were defined
     
    51385421@cindex environment
    51395422Variables in @code{make} can come from the environment in which
    5140 @code{make} is run.  Every environment variable that @code{make} sees when
    5141 it starts up is transformed into a @code{make} variable with the same name
    5142 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
     5424when it starts up is transformed into a @code{make} variable with the
     5425same name and value.  However, an explicit assignment in the makefile,
     5426or with a command argument, overrides the environment.  (If the
     5427@samp{-e} flag is specified, then values from the environment override
     5428assignments in the makefile.  @xref{Options Summary, ,Summary of
     5429Options}.  But this is not recommended practice.)
    51475430
    51485431Thus, by setting the variable @code{CFLAGS} in your environment, you can
    51495432cause all C compilations in most makefiles to use the compiler switches you
    51505433prefer.  This is safe for variables with standard or conventional meanings
    5151 because you know that no makefile will use them for other things.  (But
     5434because you know that no makefile will use them for other things.  (Note
    51525435this is not totally reliable; some makefiles set @code{CFLAGS} explicitly
    51535436and therefore are not affected by the value in the environment.)
    51545437
    5155 When @code{make} is invoked recursively, variables defined in the
    5156 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 the
    5160 @code{export} directive to pass other variables.
    5161 @xref{Variables/Recursion, , Communicating Variables to a
     5438When @code{make} runs a command script, variables defined in the
     5439makefile are placed into the environment of that command.  This allows
     5440you to pass values to sub-@code{make} invocations. (@pxref{Recursion,
     5441,Recursive Use of @code{make}}).  By default, only variables that came
     5442from the environment or the command line are passed to recursive
     5443invocations.  You can use the @code{export} directive to pass other
     5444variables.  @xref{Variables/Recursion, , Communicating Variables to a
    51625445Sub-@code{make}}, for full details.
    51635446
     
    51685451purpose of most makefiles.
    51695452
     5453@cindex SHELL, import from environment
    51705454Such problems would be especially likely with the variable @code{SHELL},
    51715455which is normally present in the environment to specify the user's choice
     
    51755459usually not set.  @xref{Execution, ,Special handling of SHELL on
    51765460MS-DOS}.)@refill
     5461
     5462@cindex SHELL, export to environment
     5463The @code{SHELL} variable is special in another way: just as the value
     5464of the @code{make} variable @code{SHELL} is not taken from the
     5465environment, so also it is not placed into the environment of commands
     5466that @code{make} invokes.  Instead, the value of @code{SHELL} from the
     5467invoking 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.
    51775470
    51785471@node Target-specific, Pattern-specific, Environment, Using Variables
     
    54315724@end example
    54325725
    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.
     5726or:
     5727
     5728@example
     5729@var{conditional-directive}
     5730@var{text-if-one-is-true}
     5731else @var{conditional-directive}
     5732@var{text-if-true}
     5733else
     5734@var{text-if-false}
     5735endif
     5736@end example
     5737
     5738@noindent
     5739There can be as many ``@code{else} @var{conditional-directive}''
     5740clauses as necessary.  Once a given condition is true,
     5741@var{text-if-true} is used and no other clause is used; if no
     5742condition 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
     5744of text.
    54375745
    54385746The 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:
     5747conditional is simple or complex; after an @code{else} or not.  There
     5748are four different directives that test different conditions.  Here is
     5749a table of them:
    54415750
    54425751@table @code
     
    54795788
    54805789@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.
     5790The @code{ifdef} form takes the @emph{name} of a variable as its
     5791argument, not a reference to a variable.  The value of that variable
     5792has a non-empty value, the @var{text-if-true} is effective; otherwise,
     5793the @var{text-if-false}, if any, is effective.  Variables that have
     5794never been defined have an empty value.  The text @var{variable-name}
     5795is expanded, so it could be a variable or function that expands
     5796to the name of a variable.  For example:
     5797
     5798@example
     5799bar = true
     5800foo = bar
     5801ifdef $(foo)
     5802frobozz = yes
     5803endif
     5804@end example
     5805
     5806The variable reference @code{$(foo)} is expanded, yielding @code{bar},
     5807which 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
     5809it is non-empty.
    54875810
    54885811Note that @code{ifdef} only tests whether a variable has a value.  It
     
    55205843If the variable @var{variable-name} has an empty value, the
    55215844@var{text-if-true} is effective; otherwise, the @var{text-if-false},
    5522 if any, is effective.
     5845if any, is effective.  The rules for expansion and testing of
     5846@var{variable-name} are identical to the @code{ifdef} directive.
    55235847@end table
    55245848
     
    59276251Returns the list of words in @var{text} starting with word @var{s} and
    59286252ending 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,
     6253start from 1; @var{e} may start from 0.  If @var{s} is bigger than the
     6254number of words in @var{text}, the value is empty.  If @var{e} is
     6255bigger 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
     6257is returned.  For example,
    59336258
    59346259@example
     
    59646289@var{text})} is the same as @code{$(word 1,@var{text})}, the
    59656290@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
     6296The argument @var{names} is regarded as a series of names, separated
     6297by whitespace.  The value is the last name in the series.
     6298
     6299For example,
     6300
     6301@example
     6302$(lastword foo bar)
     6303@end example
     6304
     6305@noindent
     6306produces the result @samp{bar}.  Although @code{$(lastword
     6307@var{text})} is the same as @code{$(word $(words @var{text}),@var{text})},
     6308the @code{lastword} function was added for its simplicity and better
     6309performance.@refill
    59666310@end table
     6311
    59676312
    59686313Here is a realistic example of the use of @code{subst} and
     
    61536498that match the pattern.
    61546499@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
     6505For each file name in @var{names} return the canonical absolute name.
     6506A canonical name does not contain any @code{.} or @code{..} components,
     6507nor any repeated path separators (@code{/}) or symlinks. In case of a
     6508failure the empty string is returned. Consult the @code{realpath(3)}
     6509documentation 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
     6515For each file name in @var{names} return an absolute name that does
     6516not contain any @code{.} or @code{..} components, nor any repeated path
     6517separators (@code{/}). Note that in contrast to @code{realpath}
     6518function, @code{abspath} does not resolve symlinks and does not require
     6519the file names to refer to an existing file or directory. Use the
     6520@code{wildcard} function to test for existence.
    61556521@end table
    61566522
     
    66387004sets @code{files} to the expansion of @samp{*.c}.  Unless @code{make} is
    66397005using 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
     7007exists).@refill
    66417008
    66427009@node Make Control Functions,  , Shell Function, Functions
     
    66937060
    66947061The 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
     7066This function does nothing more than print its (expanded) argument(s)
     7067to standard output.  No makefile name or line number is added.  The
     7068result of the expansion of this function is the empty string.
    66957069@end table
    66967070
     
    67717145programs they describe.  If the first rule in the makefile has several
    67727146targets, 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.
     7147the whole list.  You can manage the selection of the default goal from
     7148within your makefile using the @code{.DEFAULT_GOAL} variable
     7149(@pxref{Special Variables, , Other Special Variables}).
     7150
     7151You can also specify a different goal or goals with command-line
     7152arguments to @code{make}.  Use the name of the goal as an argument.
     7153If you specify several goals, @code{make} processes each of them in
     7154turn, in the order you name them.
    67787155
    67797156Any target in the makefile may be specified as a goal (unless it
     
    67837160implicit rules that say how to make them.
    67847161
    6785 @cindex @code{MAKECMDGOALS}
    67867162@vindex MAKECMDGOALS
    67877163@code{Make} will set the special variable @code{MAKECMDGOALS} to the
     
    73087684floating-point number).  With no argument, removes a previous load
    73097685limit.  @xref{Parallel, ,Parallel Execution}.
     7686
     7687@item -L
     7688@cindex @code{-L}
     7689@itemx --check-symlink-times
     7690@cindex @code{--check-symlink-times}
     7691On systems that support symbolic links, this option causes @code{make}
     7692to consider the timestamps on any symbolic links in addition to the
     7693timestamp on the file referenced by those links.  When this option is
     7694provided, the most recent timestamp among the file and the symbolic
     7695links is taken as the modification time for this target file.
    73107696
    73117697@item -n
     
    75207906* Chained Rules::               How to use a chain of implicit rules.
    75217907* Pattern Rules::               How to define new implicit rules.
    7522 * Last Resort::                 How to defining commands for rules
    7523                                   which cannot find any.
     7908* Last Resort::                 How to define commands for rules which
     7909                                cannot find any.
    75247910* Suffix Rules::                The old-fashioned style of implicit rule.
    75257911* Implicit Rule Search::        The precise algorithm for applying
     
    83728758automatic variable values are available: they only have values within
    83738759the 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.
     8760within the target list of a rule; they have no value there and will
     8761expand to the empty string.  Also, they cannot be accessed directly
     8762within the prerequisite list of a rule.  A common mistake is
     8763attempting to use @code{$@@} within the prerequisites list; this will
     8764not work.  However, there is a special feature of GNU @code{make},
     8765secondary expansion (@pxref{Secondary Expansion}), which will allow
     8766automatic variable values to be used in prerequisite lists.
    83798767
    83808768Here is a table of automatic variables:
     
    84228810it depends on, no matter how many times each file is listed as a
    84238811prerequisite.  So if you list a prerequisite more than once for a target,
    8424 the value of @code{$^} contains just one copy of the name.
     8812the value of @code{$^} contains just one copy of the name.  This list
     8813does @strong{not} contain any of the order-only prerequisites; for those
     8814see the @samp{$|} variable, below.
    84258815@cindex prerequisites, list of all
    84268816@cindex list of all prerequisites
     
    84338823primarily useful for use in linking commands where it is meaningful to
    84348824repeat library file names in a particular order.
     8825
     8826@vindex $|
     8827@vindex | @r{(automatic variable)}
     8828@item $|
     8829The names of all the order-only prerequisites, with spaces between
     8830them.
    84358831
    84368832@vindex $*
     
    85658961as @samp{$(CFLAGS)} refers to the variable named @code{CFLAGS}.
    85668962You could just as well use @samp{$(<)} in place of @samp{$<}.
    8567 
    8568 @vindex $$@@
    8569 @vindex $$(@@D)
    8570 @vindex $$(@@F)
    8571 @cindex $$@@, support for
    8572 GNU @code{make} provides support for the SysV @code{make} feature that
    8573 allows special variable references @code{$$@@}, @code{$$(@@D)}, and
    8574 @code{$$(@@F)} (note the required double-''$''!) to appear with the
    8575 @emph{prerequisites list} (normal automatic variables are available
    8576 only within a command script).  When appearing in a prerequisites
    8577 list, these variables are expanded to the name of the target, the
    8578 directory component of the target, and the file component of the
    8579 target, respectively.
    8580 
    8581 Note that these variables are available only within explicit and
    8582 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 its
    8585 entire prerequisite list @emph{twice}, GNU @code{make} does not behave
    8586 this way: instead it simply expands these special variables without
    8587 re-expanding any other part of the prerequisites list.
    8588 
    8589 This somewhat bizarre feature is included only to provide some
    8590 compatibility with SysV makefiles.  In a native GNU @code{make} file
    8591 there are other ways to accomplish the same results.  This feature is
    8592 disabled if the special pseudo target @code{.POSIX} is defined.
    85938963
    85948964@node Pattern Match, Match-Anything Rules, Automatic Variables, Pattern Rules
     
    94469816The built-in variable @samp{MAKE_VERSION} gives the version number of
    94479817@code{make}.
     9818@vindex MAKE_VERSION
    94489819@end itemize
    94499820
     
    963510006@end table
    963610007
    9637 Here is a summary of the text manipulation functions (@pxref{Functions}):
     10008Here is a summary of the built-in functions (@pxref{Functions}):
    963810009
    963910010@table @code
     
    966610037@xref{Text Functions, , Functions for String Substitution and Analysis}.
    966710038
     10039@item $(word @var{n},@var{text})
     10040Extract 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})
     10044Count 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})
     10048Returns 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{})
     10052Extract the first word of @var{names}.@*
     10053@xref{Text Functions, , Functions for String Substitution and Analysis}.
     10054
     10055@item $(lastword @var{names}@dots{})
     10056Extract the last word of @var{names}.@*
     10057@xref{Text Functions, , Functions for String Substitution and Analysis}.
     10058
    966810059@item $(dir @var{names}@dots{})
    966910060Extract the directory part of each file name.@*
     
    969210083@item $(join @var{list1},@var{list2})
    969310084Join 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}.@*
    971010085@xref{File Name Functions, ,Functions for File Names}.
    971110086
     
    971410089@samp{%} pattern).@*
    971510090@xref{Wildcard Function, ,The Function @code{wildcard}}.
     10091
     10092@item $(realpath @var{names}@dots{})
     10093For each file name in @var{names}, expand to an absolute name that
     10094does not contain any @code{.}, @code{..}, nor symlinks.@*
     10095@xref{File Name Functions, ,Functions for File Names}.
     10096
     10097@item $(abspath @var{names}@dots{})
     10098For each file name in @var{names}, expand to an absolute name that
     10099does not contain any @code{.} or @code{..} components, but preserves
     10100symlinks.@*
     10101@xref{File Name Functions, ,Functions for File Names}.
    971610102
    971710103@item $(error @var{text}@dots{})
     
    984010226The name of the system default command interpreter, usually @file{/bin/sh}.
    984110227You can set @code{SHELL} in the makefile to change the shell used to run
    9842 commands.  @xref{Execution, ,Command Execution}.
     10228commands.  @xref{Execution, ,Command Execution}.  The @code{SHELL}
     10229variable is handled specially when importing from and exporting to the
     10230environment.  @xref{Environment, ,Using Variable from the Environment}.
    984310231
    984410232@item MAKESHELL
     
    997010358command line, and @code{make} couldn't find any makefiles to read in.
    997110359The latter means that some makefile was found, but it didn't contain any
    9972 default target and none was given on the command line.  GNU @code{make}
     10360default goal and none was given on the command line.  GNU @code{make}
    997310361has nothing to do in these situations.
    997410362@xref{Makefile Arguments, ,Arguments to Specify the Makefile}.@refill
     
    1022110609@end group
    1022210610
     10611.PHONY: all
    1022310612all:    tar rmt tar.info
    1022410613
    1022510614@group
     10615.PHONY: tar
    1022610616tar:    $(OBJS)
    1022710617        $(CC) $(LDFLAGS) -o $@@ $(OBJS) $(LIBS)
     
    1023910629
    1024010630@group
     10631.PHONY: install
    1024110632install: all
    1024210633        $(INSTALL) tar $(bindir)/$(binprefix)tar
     
    1026710658
    1026810659@group
     10660.PHONY: clean
    1026910661clean:
    1027010662        rm -f *.o tar rmt testpad testpad.h core
     
    1027210664
    1027310665@group
     10666.PHONY: distclean
    1027410667distclean: clean
    1027510668        rm -f TAGS Makefile config.status
     
    1027710670
    1027810671@group
     10672.PHONY: realclean
    1027910673realclean: distclean
    1028010674        rm -f tar.info*
     
    1028210676
    1028310677@group
     10678.PHONY: shar
    1028410679shar: $(SRCS) $(AUX)
    1028510680        shar $(SRCS) $(AUX) | compress \
     
    1029110686
    1029210687@group
     10688.PHONY: dist
    1029310689dist: $(SRCS) $(AUX)
    1029410690        echo tar-`sed \
Note: See TracChangeset for help on using the changeset viewer.