if (v->append)
value = allocated_variable_append (v);
else
- value = allocated_variable_expand (v->value);
+ value = allocated_expand_string (v->value);
v->expanding = 0;
if (set_reading)
}
\f
/* Scan STRING for variable references and expansion-function calls. Only
- LENGTH bytes of STRING are actually scanned. If LENGTH is -1, scan until
- a null byte is found.
+ LENGTH bytes of STRING are actually scanned.
+ If LENGTH is SIZE_MAX, scan until a null byte is found.
- Write the results to LINE, which must point into 'variable_buffer'. If
- LINE is NULL, start at the beginning of the buffer.
- Return a pointer to LINE, or to the beginning of the buffer if LINE is
+ Write the results to BUF, which must point into 'variable_buffer'. If
+ BUF is NULL, start at the beginning of the current 'variable_buffer'.
+
+ Return a pointer to BUF, or to the beginning of the new buffer if BUF is
NULL.
*/
char *
-variable_expand_string (char *line, const char *string, size_t length)
+expand_string_buf (char *buf, const char *string, size_t length)
{
struct variable *v;
const char *p, *p1;
char *o;
size_t line_offset;
- if (!line)
- line = initialize_variable_output ();
- o = line;
- line_offset = line - variable_buffer;
+ if (!buf)
+ buf = initialize_variable_output ();
+ o = buf;
+ line_offset = buf - variable_buffer;
if (length == 0)
return variable_buffer;
return (variable_buffer + line_offset);
}
\f
-/* Scan LINE for variable references and expansion-function calls.
- Build in 'variable_buffer' the result of expanding the references and calls.
- Return the address of the resulting string, which is null-terminated
- and is valid only until the next time this function is called. */
-char *
-variable_expand (const char *line)
-{
- return variable_expand_string (NULL, line, SIZE_MAX);
-}
-\f
/* Expand an argument for an expansion function.
The text starting at STR and ending at END is variable-expanded
into a null-terminated string that is returned as the value.
return xstrdup ("");
if (!end || *end == '\0')
- return allocated_variable_expand (str);
+ return allocated_expand_string (str);
if (end - str + 1 > 1000)
tmp = alloc = xmalloc (end - str + 1);
memcpy (tmp, str, end - str);
tmp[end - str] = '\0';
- r = allocated_variable_expand (tmp);
+ r = allocated_expand_string (tmp);
free (alloc);
return r;
}
\f
-/* Expand LINE for FILE. Error messages refer to the file and line where
- FILE's commands were found. Expansion uses FILE's variable set list. */
+
+/* Expand STRING for FILE, into the current variable_buffer.
+ Error messages refer to the file and line where FILE's commands were found.
+ Expansion uses FILE's variable set list. */
char *
-variable_expand_for_file (const char *line, struct file *file)
+expand_string_for_file (const char *string, struct file *file)
{
char *result;
struct variable_set_list *savev;
const floc *savef;
- if (file == 0)
- return variable_expand (line);
+ if (!file)
+ return expand_string (string);
savev = current_variable_set_list;
current_variable_set_list = file->variables;
if (file->cmds && file->cmds->fileinfo.filenm)
reading_file = &file->cmds->fileinfo;
else
- reading_file = 0;
+ reading_file = NULL;
- result = variable_expand (line);
+ result = expand_string (string);
current_variable_set_list = savev;
reading_file = savef;
return result;
}
+
+/* Like expand_string_for_file, but the returned string is malloc'd. */
+
+char *
+allocated_expand_string_for_file (const char *string, struct file *file)
+{
+ char *obuf;
+ size_t olen;
+
+ install_variable_buffer (&obuf, &olen);
+
+ expand_string_for_file (string, file);
+
+ return swap_variable_buffer (obuf, olen);
+}
\f
-/* Like allocated_variable_expand, but for += target-specific variables.
+/* Like allocated_expand_string, but for += target-specific variables.
First recursively construct the variable value from its appended parts in
any upper variable sets. Then expand the resulting value. */
if (! v->recursive)
return variable_buffer_output (buf, v->value, strlen (v->value));
- buf = variable_expand_string (buf, v->value, strlen (v->value));
+ buf = expand_string_buf (buf, v->value, strlen (v->value));
return (buf + strlen (buf));
}
return swap_variable_buffer (obuf, olen);
}
-
-/* Like variable_expand_for_file, but the returned string is malloc'd.
- This function is called a lot. It wants to be efficient. */
-
-char *
-allocated_variable_expand_for_file (const char *line, struct file *file)
-{
- char *obuf;
- size_t olen;
-
- install_variable_buffer (&obuf, &olen);
-
- variable_expand_for_file (line, file);
-
- return swap_variable_buffer (obuf, olen);
-}
set_file_variables (f, d->stem ? d->stem : f->stem);
/* Perform second expansion. */
- p = variable_expand_for_file (d->name, f);
+ p = expand_string_for_file (d->name, f);
/* Free the un-expanded name. */
free ((char*)d->name);
expand_extra_prereqs (const struct variable *extra)
{
struct dep *d;
- struct dep *prereqs = extra ? split_prereqs (variable_expand (extra->value)) : NULL;
+ struct dep *prereqs = extra ? split_prereqs (expand_string (extra->value)) : NULL;
for (d = prereqs; d; d = d->next)
{
free (var->value);
var->value = xstrndup (p, len);
- result = allocated_variable_expand (body);
+ result = allocated_expand_string (body);
o = variable_buffer_output (o, result, strlen (result));
o = variable_buffer_output (o, " ", 1);
/* Expand the body in the context of the arguments, adding the result to
the variable buffer. */
- o = variable_expand_string (o, body, SIZE_MAX);
+ o = expand_string_buf (o, body, SIZE_MAX);
pop_variable_scope ();
free (varnames);
saved_args = max_args;
max_args = i;
- o = variable_expand_string (o, body, flen+3);
+ o = expand_string_buf (o, body, flen+3);
max_args = saved_args;
v->exp_count = 0;
}
/* Perform the 2nd expansion. */
- p = variable_expand_for_file (depname, file);
+ p = expand_string_for_file (depname, file);
dptr = &dl;
/* Parse the results into a deps list. */
/* Finally, expand the line. */
cmds->fileinfo.offset = i;
- lines[i] = allocated_variable_expand_for_file (cmds->command_lines[i],
- file);
+ lines[i] = allocated_expand_string_for_file (cmds->command_lines[i],
+ file);
}
cmds->fileinfo.offset = 0;
nm, c->file->name);
else
{
- char *newer = allocated_variable_expand_for_file ("$?", c->file);
+ char *newer = allocated_expand_string_for_file ("$?", c->file);
if (newer[0] != '\0')
{
OSSS (message, 0, _("%s: update target '%s' due to: %s"),
int save = warn_undefined_variables_flag;
warn_undefined_variables_flag = 0;
- shell = allocated_variable_expand_for_file ("$(SHELL)", file);
+ shell = allocated_expand_string_for_file ("$(SHELL)", file);
#if MK_OS_W32
/*
* Convert to forward slashes so that construct_command_argv_internal()
/* In POSIX mode we default to -ec, unless we're ignoring errors. */
shellflags = xstrdup (ANY_SET (cmd_flags, COMMANDS_NOERROR) ? "-c" : "-ec");
else
- shellflags = allocated_variable_expand_for_file (var->value, file);
+ shellflags = allocated_expand_string_for_file (var->value, file);
- ifs = allocated_variable_expand_for_file ("$(IFS)", file);
+ ifs = allocated_expand_string_for_file ("$(IFS)", file);
warn_undefined_variables_flag = save;
}
char *
gmk_expand (const char *ref)
{
- return allocated_variable_expand (ref);
+ return allocated_expand_string (ref);
}
/* Register a function to be called from makefiles. */
int no_builtin_rules_flag = 0;
int no_builtin_variables_flag = 0;
+/* Nonzero means all variables are automatically exported. */
+
+int export_all_variables = 0;
+
/* Nonzero means keep going even if remaking some file fails (-k). */
int keep_going_flag;
char *p;
if (default_goal_var->recursive)
- p = variable_expand (default_goal_var->value);
+ p = expand_string (default_goal_var->value);
else
{
p = variable_buffer_output (variable_buffer, default_goal_var->value,
p = mempcpy (p, envar, len);
*(p++) = ')';
*p = '\0';
- value = variable_expand (varref);
+ value = expand_string (varref);
/* Skip whitespace, and check for an empty value. */
NEXT_TOKEN (value);
extern int just_print_flag, run_silent, ignore_errors_flag, keep_going_flag;
extern int print_data_base_flag, question_flag, touch_flag, always_make_flag;
extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag;
-extern int print_version_flag, check_symlink_flag;
+extern int print_version_flag, check_symlink_flag, export_all_variables;
extern int warn_undefined_variables_flag, posix_pedantic;
extern int not_parallel, second_expansion, clock_skew_detected;
extern int rebuilding_makefiles, one_shell, output_sync, verify_flag;
#define GNUMAKEFLAGS_NAME "GNUMAKEFLAGS"
#define MAKEFLAGS_NAME "MAKEFLAGS"
+#define MAKELEVEL_NAME "MAKELEVEL"
+#define MAKELEVEL_LENGTH (CSTRLEN (MAKELEVEL_NAME))
+
/* Resetting the command script introduction prefix character. */
#define RECIPEPREFIX_NAME ".RECIPEPREFIX"
#define RECIPEPREFIX_DEFAULT '\t'
char *name, *p;
size_t length;
- value = allocated_variable_expand ("$(MAKEFILES)");
+ value = allocated_expand_string ("$(MAKEFILES)");
/* Set NAME to the start of next token and LENGTH to its length.
MAKEFILES is updated for finding remaining tokens. */
/* Expand the line so we can use indirect and constructed
variable names in an (un)export command. */
- cp = ap = allocated_variable_expand (p2);
+ cp = ap = allocated_expand_string (p2);
for (p = find_next_token (&cp, &l); p != 0;
p = find_next_token (&cp, &l))
/* vpath ends the previous rule. */
record_waiting_files ();
- cp = variable_expand (p2);
+ cp = expand_string (p2);
p = find_next_token (&cp, &l);
if (p != 0)
{
/* Include ends the previous rule. */
record_waiting_files ();
- p = allocated_variable_expand (p2);
+ p = allocated_expand_string (p2);
/* If no filenames, it's a no-op. */
if (*p == '\0')
/* Load ends the previous rule. */
record_waiting_files ();
- p = allocated_variable_expand (p2);
+ p = allocated_expand_string (p2);
/* If no filenames, it's a no-op. */
if (*p == '\0')
break;
}
- p2 = variable_expand_string (NULL, lb_next, wlen);
+ p2 = expand_string_buf (NULL, lb_next, wlen);
while (1)
{
entirely consistent, since we do an unconditional
expand below once we know we don't have a
target-specific variable. */
- variable_expand_string (pend, lb_next, SIZE_MAX);
+ expand_string_buf (pend, lb_next, SIZE_MAX);
lb_next += strlen (lb_next);
p2 = variable_buffer + p2_off;
cmdleft = variable_buffer + cmd_off + 1;
p2 += strlen (p2);
*(p2++) = ' ';
- p2 = variable_expand_string (p2, lb_next, wlen);
+ p2 = expand_string_buf (p2, lb_next, wlen);
/* We don't need to worry about cmdleft here, because if it was
found in the variable_buffer the entire buffer has already
been expanded... we'll never get here. */
if (*lb_next != '\0')
{
size_t l = p2 - variable_buffer;
- variable_expand_string (p2 + plen, lb_next, SIZE_MAX);
+ expand_string_buf (p2 + plen, lb_next, SIZE_MAX);
p2 = variable_buffer + l;
/* Look for a semicolon in the expanded line. */
char *p, *var;
/* Expand the variable name and find the beginning (NAME) and end. */
- var = allocated_variable_expand (name);
+ var = allocated_expand_string (name);
name = next_token (var);
if (*name == '\0')
O (fatal, &ebuf->floc, _("empty variable name"));
}
/* Expand the variable name and find the beginning (NAME) and end. */
- n = allocated_variable_expand (name);
+ n = allocated_expand_string (name);
name = next_token (n);
if (name[0] == '\0')
O (fatal, &defstart, _("empty variable name"));
/* Expand the thing we're looking up, so we can use indirect and
constructed variable names. */
- var = allocated_variable_expand (line);
+ var = allocated_expand_string (line);
/* Make sure there's only one variable name to test. */
p = end_of_token (var);
else
*line++ = '\0';
- s2 = variable_expand (s1);
+ s2 = expand_string (s1);
/* We must allocate a new copy of the expanded string because
- variable_expand re-uses the same buffer. */
+ expand_string re-uses the same buffer. */
l = strlen (s2);
s1 = alloca (l + 1);
memcpy (s1, s2, l + 1);
if (*line != '\0')
EXTRATEXT ();
- s2 = variable_expand (s2);
+ s2 = expand_string (s2);
conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq));
}
v->origin = origin;
if (v->flavor == f_simple)
- v->value = allocated_variable_expand (v->value);
+ v->value = allocated_expand_string (v->value);
else
v->value = xstrdup (v->value);
}
int save = warn_undefined_variables_flag;
warn_undefined_variables_flag = 0;
- home_dir = allocated_variable_expand ("$(HOME)");
+ home_dir = allocated_expand_string ("$(HOME)");
warn_undefined_variables_flag = save;
}
const char **dp;
- libpatterns = xstrdup (variable_expand ("$(.LIBPATTERNS)"));
+ libpatterns = xstrdup (expand_string ("$(.LIBPATTERNS)"));
/* Skip the '-l'. */
lib += 2;
define_variable_cname ("+F", "$(notdir $+)", o_automatic, 1);
}
\f
-int export_all_variables;
static int
should_export (const struct variable *v)
We have to allocate memory since otherwise it'll clobber the
variable buffer, and we may still need that if we're looking at a
target-specific variable. */
- newval = alloc_value = allocated_variable_expand (value);
+ newval = alloc_value = allocated_expand_string (value);
break;
case f_expand:
{
/* A POSIX "var :::= value" assignment. Expand the value, then it
becomes a recursive variable. After expansion convert all '$'
tokens to '$$' to resolve to '$' when recursively expanded. */
- char *t = allocated_variable_expand (value);
+ char *t = allocated_expand_string (value);
char *np = alloc_value = xmalloc (strlen (t) * 2 + 1);
char *op = t;
while (op[0] != '\0')
{
/* A shell definition "var != value". Expand value, pass it to
the shell, and store the result in recursively-expanded var. */
- char *q = allocated_variable_expand (value);
+ char *q = allocated_expand_string (value);
alloc_value = shell_result (q);
free (q);
flavor = f_recursive;
when it was set; and from the expanded new value. Allocate
memory for the expansion as we may still need the rest of the
buffer if we're looking at a target-specific variable. */
- val = tp = allocated_variable_expand (val);
+ val = tp = allocated_expand_string (val);
/* If the new value is empty, nothing to do. */
vallen = strlen (val);
{
char *tp = alloc_value;
- alloc_value = allocated_variable_expand (newval);
+ alloc_value = allocated_expand_string (newval);
if (find_and_set_default_shell (alloc_value))
{
name = alloca (v->length + 1);
memcpy (name, v->name, v->length);
name[v->length] = '\0';
- v->name = allocated_variable_expand (name);
+ v->name = allocated_expand_string (name);
if (v->name[0] == '\0')
O (fatal, &v->fileinfo, _("empty variable name"));
{
static char *environ_path = NULL;
char *oldpath = environ_path;
- char *path = allocated_variable_expand ("PATH=$(PATH)");
+ char *path = allocated_expand_string ("PATH=$(PATH)");
if (!path)
return;
void restore_variable_buffer (char *buf, size_t len);
char *swap_variable_buffer (char *buf, size_t len);
-char *variable_expand_string (char *line, const char *string, size_t length);
-char *variable_expand (const char *line);
-char *variable_expand_for_file (const char *line, struct file *file);
-char *allocated_variable_expand_for_file (const char *line, struct file *file);
-#define allocated_variable_expand(line) \
- allocated_variable_expand_for_file (line, (struct file *) 0)
+char *expand_string_buf (char *buf, const char *string, size_t length);
+#define expand_string(s) expand_string_buf (NULL, (s), SIZE_MAX)
+char *expand_string_for_file (const char *string, struct file *file);
+char *allocated_expand_string_for_file (const char *line, struct file *file);
+#define allocated_expand_string(s) allocated_expand_string_for_file ((s), NULL)
char *expand_argument (const char *str, const char *end);
char *recursively_expand_for_file (struct variable *v, struct file *file);
-#define recursively_expand(v) recursively_expand_for_file (v, NULL)
+#define recursively_expand(v) recursively_expand_for_file ((v), NULL)
/* function.c */
int handle_function (char **op, const char **stringp);
struct pattern_var *create_pattern_var (const char *target,
const char *suffix);
-
-extern int export_all_variables;
-
-#define MAKELEVEL_NAME "MAKELEVEL"
-#define MAKELEVEL_LENGTH (CSTRLEN (MAKELEVEL_NAME))
/* If there is a VPATH variable with a nonnull expanded value, construct the
general VPATH list from it. */
- p = variable_expand ("$(strip $(VPATH))");
+ p = expand_string ("$(strip $(VPATH))");
if (*p != '\0')
{
/* If there is a GPATH variable with a nonnull expanded value, construct the
GPATH list from it. */
- p = variable_expand ("$(strip $(GPATH))");
+ p = expand_string ("$(strip $(GPATH))");
if (*p != '\0')
{
char **argvi = argv;
size_t arglen = 0;
- strcpy(buf, variable_expand ("$(SHELL)"));
+ strcpy(buf, expand_string ("$(SHELL)"));
shell_name = &buf[0];
strcpy(exec_fname, "-c");
/* Construct a single command string in argv[0]. */