* Pattern Intro:: An introduction to pattern rules.
* Pattern Examples:: Examples of pattern rules.
-* Automatic:: How to use automatic variables in the
+* Automatic Variables:: How to use automatic variables in the
commands of implicit rules.
* Pattern Match:: How patterns match.
* Match-Anything Rules:: Precautions you should take prior to
This rule uses @file{print} as an empty target file; see @ref{Empty
Targets, ,Empty Target Files to Record Events}. (The automatic variable
@samp{$?} is used to print only those files that have changed; see
-@ref{Automatic, ,Automatic Variables}.)@refill
+@ref{Automatic Variables}.)@refill
Wildcard expansion does not happen when you define a variable. Thus, if
you write this:
the prerequisite in the directory where @code{make} finds it.
This is done with the @dfn{automatic variables} such as @samp{$^}
-(@pxref{Automatic, ,Automatic Variables}).
+(@pxref{Automatic Variables}).
For instance, the value of @samp{$^} is a
list of all the prerequisites of the rule, including the names of
the directories in which they were found, and the value of
With this rule, @samp{make print} will execute the @code{lpr} command if
either source file has changed since the last @samp{make print}. The
automatic variable @samp{$?} is used to print only those files that have
-changed (@pxref{Automatic, ,Automatic Variables}).
+changed (@pxref{Automatic Variables}).
@node Special Targets, Multiple Targets, Empty Targets, Rules
@section Special Built-in Target Names
Similar commands work for all the targets. The commands do not need
to be absolutely identical, since the automatic variable @samp{$@@}
can be used to substitute the particular target to be remade into the
-commands (@pxref{Automatic, ,Automatic Variables}). For example:
+commands (@pxref{Automatic Variables}). For example:
@example
@group
@noindent
Here @samp{$<} is the automatic variable that holds the name of the
prerequisite and @samp{$@@} is the automatic variable that holds the name
-of the target; see @ref{Automatic, , Automatic Variables}.
+of the target; see @ref{Automatic Variables}.
Each target specified must match the target pattern; a warning is issued
for each target that does not. If you have a list of files, only some of
A few variables have names that are a single punctuation character or
just a few characters. These are the @dfn{automatic variables}, and
-they have particular specialized uses. @xref{Automatic, ,Automatic Variables}.
+they have particular specialized uses. @xref{Automatic Variables}.
@menu
* Reference:: How to use the value of a variable.
open-parenthesis or open-brace treats that single character as the
variable name. Thus, you could reference the variable @code{x} with
@samp{$x}. However, this practice is strongly discouraged, except in
-the case of the automatic variables (@pxref{Automatic, ,Automatic Variables}).
+the case of the automatic variables (@pxref{Automatic Variables}).
@node Flavors, Advanced, Reference, Using Variables
@section The Two Flavors of Variables
@item
Several @dfn{automatic} variables are given new values for each rule.
Each of these has a single conventional use.
-@xref{Automatic, ,Automatic Variables}.
+@xref{Automatic Variables}.
@item
Several variables have constant initial values.
(@pxref{Implicit Variables, ,Variables Used by Implicit Rules}).
Several special variables are set
automatically to a new value for each rule; these are called the
-@dfn{automatic} variables (@pxref{Automatic, ,Automatic Variables}).
+@dfn{automatic} variables (@pxref{Automatic Variables}).
If you'd like a variable to be set to a value only if it's not already
set, then you can use the shorthand operator @samp{?=} instead of
Variable values in @code{make} are usually global; that is, they are the
same regardless of where they are evaluated (unless they're reset, of
course). One exception to that is automatic variables
-(@pxref{Automatic, ,Automatic Variables}).
+(@pxref{Automatic Variables}).
The other exception is @dfn{target-specific variable values}. This
feature allows you to define different values for the same variable,
@var{target} @dots{} : override @var{variable-assignment}
@end example
+@noindent
+or like this:
+
+@example
+@var{target} @dots{} : export @var{variable-assignment}
+@end example
+
Multiple @var{target} values create a target-specific variable value for
each member of the target list individually.
@code{make} evaluates conditionals when it reads a makefile.
Consequently, you cannot use automatic variables in the tests of
conditionals because they are not defined until commands are run
-(@pxref{Automatic, , Automatic Variables}).
+(@pxref{Automatic Variables}).
To prevent intolerable confusion, it is not permitted to start a
conditional in one makefile and end it in another. However, you may
if @var{variable} is an automatic variable defined for the
execution of the commands for each rule
-(@pxref{Automatic, , Automatic Variables}).
+(@pxref{Automatic Variables}).
@end table
This information is primarily useful (other than for your curiosity) to
@menu
* Pattern Intro:: An introduction to pattern rules.
* Pattern Examples:: Examples of pattern rules.
-* Automatic:: How to use automatic variables in the
+* Automatic Variables:: How to use automatic variables in the
commands of implicit rules.
* Pattern Match:: How patterns match.
* Match-Anything Rules:: Precautions you should take prior to
@cindex pattern rules, order of
@cindex order of pattern rules
-@node Pattern Examples, Automatic, Pattern Intro, Pattern Rules
+@node Pattern Examples, Automatic Variables, Pattern Intro, Pattern Rules
@subsection Pattern Rule Examples
Here are some examples of pattern rules actually predefined in
defines a rule that can make any file @file{@var{x}.o} from
@file{@var{x}.c}. The command uses the automatic variables @samp{$@@} and
@samp{$<} to substitute the names of the target file and the source file
-in each case where the rule applies (@pxref{Automatic, ,Automatic Variables}).@refill
+in each case where the rule applies (@pxref{Automatic Variables}).@refill
Here is a second built-in rule:
linked from @file{parse.tab.o}, @file{scan.o}, and its other
prerequisites, and it will execute happily ever after.)@refill
-@node Automatic, Pattern Match, Pattern Examples, Pattern Rules
+@node Automatic Variables, Pattern Match, Pattern Examples, Pattern Rules
@subsection Automatic Variables
@cindex automatic variables
@cindex variables, automatic
example, you would use @samp{$@@} for the object file name and @samp{$<}
for the source file name.
+@cindex automatic variables in prerequisites
+@cindex prerequisites, and automatic variables
+It's very important that you recognize the limited scope in which
+automatic variable values are available: they only have values within
+the command script. In particular, you cannot use them anywhere
+within the target or prerequisite lists of a rule; they have no value
+there and will expand to the empty string. A common mistake is
+attempting to use @code{$@@} within the prerequisites list in a rule;
+this will not work. However, see below for information on the
+SysV-style @code{$$@@} variables.
+
Here is a table of automatic variables:
@table @code
there are other ways to accomplish the same results. This feature is
disabled if the special pseudo target @code{.POSIX} is defined.
-@node Pattern Match, Match-Anything Rules, Automatic, Pattern Rules
+@node Pattern Match, Match-Anything Rules, Automatic Variables, Pattern Rules
@subsection How Patterns Match
@cindex stem
When the commands of a pattern rule are executed for @var{t}, the automatic
variables are set corresponding to the target and prerequisites.
-@xref{Automatic, ,Automatic Variables}.
+@xref{Automatic Variables}.
@node Archives, Features, Implicit Rules, Top
@chapter Using @code{make} to Update Archive Files
file. @xref{Chained Rules, ,Chains of Implicit Rules}.
Implicit rules such as this one are written using the automatic variable
-@samp{$%}. @xref{Automatic, ,Automatic Variables}.
+@samp{$%}. @xref{Automatic Variables}.
An archive member name in an archive cannot contain a directory name, but
it may be useful in a makefile to pretend that it does. If you write an
@item
The automatic variable @code{$%} is set to the member name
-in an archive reference. @xref{Automatic, ,Automatic Variables}.
+in an archive reference. @xref{Automatic Variables}.
@item
The automatic variables @code{$@@}, @code{$*}, @code{$<}, @code{$%},
and @code{$?} have corresponding forms like @code{$(@@F)} and
@code{$(@@D)}. We have generalized this to @code{$^} as an obvious
-extension. @xref{Automatic, ,Automatic Variables}.@refill
+extension. @xref{Automatic Variables}.@refill
@item
Substitution variable references.
@item
The automatic variable @code{$^} containing a list of all prerequisites
of the current target. We did not invent this, but we have no idea who
-did. @xref{Automatic, ,Automatic Variables}. The automatic variable
+did. @xref{Automatic Variables}. The automatic variable
@code{$+} is a simple extension of @code{$^}.
@item
@end table
Here is a summary of the automatic variables.
-@xref{Automatic, ,Automatic Variables},
+@xref{Automatic Variables},
for full information.
@table @code
static void record_target_var PARAMS ((struct nameseq *filenames, char *defn,
int two_colon,
enum variable_origin origin,
+ int enabled,
const struct floc *flocp));
static enum make_word_type get_next_mword PARAMS ((char *buffer, char *delim,
char **startp, unsigned int *length));
{
enum make_word_type wtype;
enum variable_origin v_origin;
+ int exported;
char *cmdleft, *semip, *lb_next;
unsigned int len, plen = 0;
char *colonp;
p2 = variable_buffer + l;
}
- /* See if it's an "override" keyword; if so see if what comes after
- it looks like a variable definition. */
+ /* See if it's an "override" or "export" keyword; if so see if what
+ comes after it looks like a variable definition. */
wtype = get_next_mword (p2, NULL, &p, &len);
v_origin = o_file;
- if (wtype == w_static && word1eq ("override"))
- {
- v_origin = o_override;
- wtype = get_next_mword (p+len, NULL, &p, &len);
- }
+ exported = 0;
+ if (wtype == w_static)
+ if (word1eq ("override"))
+ {
+ v_origin = o_override;
+ wtype = get_next_mword (p+len, NULL, &p, &len);
+ }
+ else if (word1eq ("export"))
+ {
+ exported = 1;
+ wtype = get_next_mword (p+len, NULL, &p, &len);
+ }
if (wtype != w_eol)
wtype = get_next_mword (p+len, NULL, NULL, NULL);
variable_buffer_output (p2 + strlen (p2),
semip, strlen (semip)+1);
}
- record_target_var (filenames, p, two_colon, v_origin, fstart);
+ record_target_var (filenames, p, two_colon, v_origin, exported,
+ fstart);
filenames = 0;
continue;
}
variable value list. */
static void
-record_target_var (filenames, defn, two_colon, origin, flocp)
+record_target_var (filenames, defn, two_colon, origin, exported, flocp)
struct nameseq *filenames;
char *defn;
int two_colon;
enum variable_origin origin;
+ int exported;
const struct floc *flocp;
{
struct nameseq *nextf;
if (!v)
error (flocp, _("Malformed per-target variable definition"));
v->per_target = 1;
+ if (exported)
+ v->export = v_export;
/* If it's not an override, check to see if there was a command-line
setting. If so, reset the value. */