1991-10-07 22:04:20 +00:00
|
|
|
|
/* Internals of variables for GNU Make.
|
2002-07-11 06:38:57 +00:00
|
|
|
|
Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997,
|
|
|
|
|
2002 Free Software Foundation, Inc.
|
1991-10-07 22:04:20 +00:00
|
|
|
|
This file is part of GNU Make.
|
|
|
|
|
|
|
|
|
|
GNU Make is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
|
|
GNU Make is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with GNU Make; see the file COPYING. If not, write to
|
1999-03-05 05:55:11 +00:00
|
|
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
Boston, MA 02111-1307, USA. */
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
|
|
|
|
#include "make.h"
|
2005-06-09 19:19:20 +00:00
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#include "dep.h"
|
|
|
|
|
#include "filedef.h"
|
|
|
|
|
#include "job.h"
|
1991-10-07 22:04:20 +00:00
|
|
|
|
#include "commands.h"
|
|
|
|
|
#include "variable.h"
|
2000-02-05 07:37:40 +00:00
|
|
|
|
#include "rule.h"
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-22 21:51:45 +00:00
|
|
|
|
#include "pathstuff.h"
|
|
|
|
|
#endif
|
2002-07-11 06:38:57 +00:00
|
|
|
|
#include "hash.h"
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
2003-05-02 01:44:59 +00:00
|
|
|
|
/* Chain of all pattern-specific variables. */
|
|
|
|
|
|
|
|
|
|
static struct pattern_var *pattern_vars;
|
|
|
|
|
|
|
|
|
|
/* Pointer to last struct in the chain, so we can add onto the end. */
|
|
|
|
|
|
|
|
|
|
static struct pattern_var *last_pattern_var;
|
|
|
|
|
|
|
|
|
|
/* Create a new pattern-specific variable struct. */
|
|
|
|
|
|
|
|
|
|
struct pattern_var *
|
|
|
|
|
create_pattern_var (char *target, char *suffix)
|
|
|
|
|
{
|
|
|
|
|
register struct pattern_var *p
|
|
|
|
|
= (struct pattern_var *) xmalloc (sizeof (struct pattern_var));
|
|
|
|
|
|
|
|
|
|
if (last_pattern_var != 0)
|
|
|
|
|
last_pattern_var->next = p;
|
|
|
|
|
else
|
|
|
|
|
pattern_vars = p;
|
|
|
|
|
last_pattern_var = p;
|
|
|
|
|
p->next = 0;
|
|
|
|
|
|
|
|
|
|
p->target = target;
|
|
|
|
|
p->len = strlen (target);
|
|
|
|
|
p->suffix = suffix + 1;
|
|
|
|
|
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Look up a target in the pattern-specific variable list. */
|
|
|
|
|
|
|
|
|
|
static struct pattern_var *
|
|
|
|
|
lookup_pattern_var (struct pattern_var *start, char *target)
|
|
|
|
|
{
|
|
|
|
|
struct pattern_var *p;
|
|
|
|
|
unsigned int targlen = strlen(target);
|
|
|
|
|
|
|
|
|
|
for (p = start ? start->next : pattern_vars; p != 0; p = p->next)
|
|
|
|
|
{
|
|
|
|
|
char *stem;
|
|
|
|
|
unsigned int stemlen;
|
|
|
|
|
|
|
|
|
|
if (p->len > targlen)
|
|
|
|
|
/* It can't possibly match. */
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* From the lengths of the filename and the pattern parts,
|
|
|
|
|
find the stem: the part of the filename that matches the %. */
|
|
|
|
|
stem = target + (p->suffix - p->target - 1);
|
|
|
|
|
stemlen = targlen - p->len + 1;
|
|
|
|
|
|
|
|
|
|
/* Compare the text in the pattern before the stem, if any. */
|
|
|
|
|
if (stem > target && !strneq (p->target, target, stem - target))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* Compare the text in the pattern after the stem, if any.
|
|
|
|
|
We could test simply using streq, but this way we compare the
|
|
|
|
|
first two characters immediately. This saves time in the very
|
|
|
|
|
common case where the first character matches because it is a
|
|
|
|
|
period. */
|
|
|
|
|
if (*p->suffix == stem[stemlen]
|
|
|
|
|
&& (*p->suffix == '\0' || streq (&p->suffix[1], &stem[stemlen+1])))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
1991-10-07 22:04:20 +00:00
|
|
|
|
/* Hash table of all global variable definitions. */
|
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
static unsigned long
|
2002-10-14 21:54:04 +00:00
|
|
|
|
variable_hash_1 (const void *keyv)
|
2002-07-11 06:38:57 +00:00
|
|
|
|
{
|
|
|
|
|
struct variable const *key = (struct variable const *) keyv;
|
|
|
|
|
return_STRING_N_HASH_1 (key->name, key->length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned long
|
2002-10-14 21:54:04 +00:00
|
|
|
|
variable_hash_2 (const void *keyv)
|
2002-07-11 06:38:57 +00:00
|
|
|
|
{
|
|
|
|
|
struct variable const *key = (struct variable const *) keyv;
|
|
|
|
|
return_STRING_N_HASH_2 (key->name, key->length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2002-10-14 21:54:04 +00:00
|
|
|
|
variable_hash_cmp (const void *xv, const void *yv)
|
2002-07-11 06:38:57 +00:00
|
|
|
|
{
|
|
|
|
|
struct variable const *x = (struct variable const *) xv;
|
|
|
|
|
struct variable const *y = (struct variable const *) yv;
|
|
|
|
|
int result = x->length - y->length;
|
|
|
|
|
if (result)
|
|
|
|
|
return result;
|
|
|
|
|
return_STRING_N_COMPARE (x->name, y->name, x->length);
|
|
|
|
|
}
|
|
|
|
|
|
1991-10-07 22:04:20 +00:00
|
|
|
|
#ifndef VARIABLE_BUCKETS
|
|
|
|
|
#define VARIABLE_BUCKETS 523
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef PERFILE_VARIABLE_BUCKETS
|
|
|
|
|
#define PERFILE_VARIABLE_BUCKETS 23
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef SMALL_SCOPE_VARIABLE_BUCKETS
|
|
|
|
|
#define SMALL_SCOPE_VARIABLE_BUCKETS 13
|
|
|
|
|
#endif
|
2002-07-11 06:38:57 +00:00
|
|
|
|
|
|
|
|
|
static struct variable_set global_variable_set;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
static struct variable_set_list global_setlist
|
|
|
|
|
= { 0, &global_variable_set };
|
|
|
|
|
struct variable_set_list *current_variable_set_list = &global_setlist;
|
|
|
|
|
|
|
|
|
|
/* Implement variables. */
|
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
init_hash_global_variable_set (void)
|
2002-07-11 06:38:57 +00:00
|
|
|
|
{
|
|
|
|
|
hash_init (&global_variable_set.table, VARIABLE_BUCKETS,
|
|
|
|
|
variable_hash_1, variable_hash_2, variable_hash_cmp);
|
|
|
|
|
}
|
|
|
|
|
|
1991-10-07 22:04:20 +00:00
|
|
|
|
/* Define variable named NAME with value VALUE in SET. VALUE is copied.
|
|
|
|
|
LENGTH is the length of NAME, which does not need to be null-terminated.
|
|
|
|
|
ORIGIN specifies the origin of the variable (makefile, command line
|
|
|
|
|
or environment).
|
|
|
|
|
If RECURSIVE is nonzero a flag is set in the variable saying
|
|
|
|
|
that it should be recursively re-expanded. */
|
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
|
struct variable *
|
2002-10-14 21:54:04 +00:00
|
|
|
|
define_variable_in_set (const char *name, unsigned int length,
|
|
|
|
|
char *value, enum variable_origin origin,
|
|
|
|
|
int recursive, struct variable_set *set,
|
|
|
|
|
const struct floc *flocp)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
2002-07-11 06:38:57 +00:00
|
|
|
|
struct variable *v;
|
|
|
|
|
struct variable **var_slot;
|
|
|
|
|
struct variable var_key;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
2002-07-08 02:26:47 +00:00
|
|
|
|
if (set == NULL)
|
|
|
|
|
set = &global_variable_set;
|
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
var_key.name = (char *) name;
|
|
|
|
|
var_key.length = length;
|
|
|
|
|
var_slot = (struct variable **) hash_find_slot (&set->table, &var_key);
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
|
|
|
|
if (env_overrides && origin == o_env)
|
|
|
|
|
origin = o_env_override;
|
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
v = *var_slot;
|
|
|
|
|
if (! HASH_VACANT (v))
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
|
|
|
|
if (env_overrides && v->origin == o_env)
|
|
|
|
|
/* V came from in the environment. Since it was defined
|
|
|
|
|
before the switches were parsed, it wasn't affected by -e. */
|
|
|
|
|
v->origin = o_env_override;
|
|
|
|
|
|
|
|
|
|
/* A variable of this name is already defined.
|
|
|
|
|
If the old definition is from a stronger source
|
|
|
|
|
than this one, don't redefine it. */
|
|
|
|
|
if ((int) origin >= (int) v->origin)
|
|
|
|
|
{
|
1992-10-09 17:50:55 +00:00
|
|
|
|
if (v->value != 0)
|
|
|
|
|
free (v->value);
|
1999-07-21 05:53:23 +00:00
|
|
|
|
v->value = xstrdup (value);
|
2000-02-05 07:37:40 +00:00
|
|
|
|
if (flocp != 0)
|
|
|
|
|
v->fileinfo = *flocp;
|
|
|
|
|
else
|
|
|
|
|
v->fileinfo.filenm = 0;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
v->origin = origin;
|
|
|
|
|
v->recursive = recursive;
|
|
|
|
|
}
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Create a new variable definition and add it to the hash table. */
|
|
|
|
|
|
|
|
|
|
v = (struct variable *) xmalloc (sizeof (struct variable));
|
|
|
|
|
v->name = savestring (name, length);
|
2002-07-11 06:38:57 +00:00
|
|
|
|
v->length = length;
|
|
|
|
|
hash_insert_at (&set->table, v, var_slot);
|
1999-07-21 05:53:23 +00:00
|
|
|
|
v->value = xstrdup (value);
|
2000-02-05 07:37:40 +00:00
|
|
|
|
if (flocp != 0)
|
|
|
|
|
v->fileinfo = *flocp;
|
|
|
|
|
else
|
|
|
|
|
v->fileinfo.filenm = 0;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
v->origin = origin;
|
|
|
|
|
v->recursive = recursive;
|
2003-05-02 01:44:59 +00:00
|
|
|
|
v->special = 0;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
v->expanding = 0;
|
2002-05-10 03:15:07 +00:00
|
|
|
|
v->exp_count = 0;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
v->per_target = 0;
|
1999-12-08 20:13:50 +00:00
|
|
|
|
v->append = 0;
|
1992-05-03 22:02:26 +00:00
|
|
|
|
v->export = v_default;
|
2002-07-11 06:38:57 +00:00
|
|
|
|
|
2002-08-01 13:16:57 +00:00
|
|
|
|
v->exportable = 1;
|
|
|
|
|
if (*name != '_' && (*name < 'A' || *name > 'Z')
|
|
|
|
|
&& (*name < 'a' || *name > 'z'))
|
|
|
|
|
v->exportable = 0;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (++name; *name != '\0'; ++name)
|
|
|
|
|
if (*name != '_' && (*name < 'a' || *name > 'z')
|
|
|
|
|
&& (*name < 'A' || *name > 'Z') && !ISDIGIT(*name))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (*name != '\0')
|
|
|
|
|
v->exportable = 0;
|
|
|
|
|
}
|
|
|
|
|
|
1991-10-07 22:04:20 +00:00
|
|
|
|
return v;
|
|
|
|
|
}
|
2002-08-01 13:16:57 +00:00
|
|
|
|
|
|
|
|
|
/* If the variable passed in is "special", handle its special nature.
|
|
|
|
|
Currently there are two such variables, both used for introspection:
|
2002-08-08 00:11:19 +00:00
|
|
|
|
.VARIABLES expands to a list of all the variables defined in this instance
|
2002-08-01 13:16:57 +00:00
|
|
|
|
of make.
|
2002-08-08 00:11:19 +00:00
|
|
|
|
.TARGETS expands to a list of all the targets defined in this
|
2002-08-01 13:16:57 +00:00
|
|
|
|
instance of make.
|
|
|
|
|
Returns the variable reference passed in. */
|
|
|
|
|
|
|
|
|
|
#define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500)
|
|
|
|
|
|
|
|
|
|
static struct variable *
|
2002-10-14 21:54:04 +00:00
|
|
|
|
handle_special_var (struct variable *var)
|
2002-08-01 13:16:57 +00:00
|
|
|
|
{
|
|
|
|
|
static unsigned long last_var_count = 0;
|
|
|
|
|
|
|
|
|
|
|
2002-08-08 00:11:19 +00:00
|
|
|
|
/* This one actually turns out to be very hard, due to the way the parser
|
|
|
|
|
records targets. The way it works is that target information is collected
|
|
|
|
|
internally until make knows the target is completely specified. It unitl
|
|
|
|
|
it sees that some new construct (a new target or variable) is defined that
|
|
|
|
|
it knows the previous one is done. In short, this means that if you do
|
|
|
|
|
this:
|
|
|
|
|
|
|
|
|
|
all:
|
|
|
|
|
|
|
|
|
|
TARGS := $(.TARGETS)
|
|
|
|
|
|
|
|
|
|
then $(TARGS) won't contain "all", because it's not until after the
|
|
|
|
|
variable is created that the previous target is completed.
|
|
|
|
|
|
|
|
|
|
Changing this would be a major pain. I think a less complex way to do it
|
|
|
|
|
would be to pre-define the target files as soon as the first line is
|
|
|
|
|
parsed, then come back and do the rest of the definition as now. That
|
|
|
|
|
would allow $(.TARGETS) to be correct without a major change to the way
|
|
|
|
|
the parser works.
|
|
|
|
|
|
|
|
|
|
if (streq (var->name, ".TARGETS"))
|
2002-08-01 13:16:57 +00:00
|
|
|
|
var->value = build_target_list (var->value);
|
2002-08-08 00:11:19 +00:00
|
|
|
|
else
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (streq (var->name, ".VARIABLES")
|
2002-08-01 13:16:57 +00:00
|
|
|
|
&& global_variable_set.table.ht_fill != last_var_count)
|
|
|
|
|
{
|
|
|
|
|
unsigned long max = EXPANSION_INCREMENT (strlen (var->value));
|
|
|
|
|
unsigned long len;
|
|
|
|
|
char *p;
|
|
|
|
|
struct variable **vp = (struct variable **) global_variable_set.table.ht_vec;
|
|
|
|
|
struct variable **end = &vp[global_variable_set.table.ht_size];
|
|
|
|
|
|
|
|
|
|
/* Make sure we have at least MAX bytes in the allocated buffer. */
|
|
|
|
|
var->value = xrealloc (var->value, max);
|
|
|
|
|
|
2002-08-08 00:11:19 +00:00
|
|
|
|
/* Walk through the hash of variables, constructing a list of names. */
|
2002-08-01 13:16:57 +00:00
|
|
|
|
p = var->value;
|
|
|
|
|
len = 0;
|
|
|
|
|
for (; vp < end; ++vp)
|
|
|
|
|
if (!HASH_VACANT (*vp))
|
|
|
|
|
{
|
|
|
|
|
struct variable *v = *vp;
|
|
|
|
|
int l = v->length;
|
|
|
|
|
|
|
|
|
|
len += l + 1;
|
|
|
|
|
if (len > max)
|
|
|
|
|
{
|
|
|
|
|
unsigned long off = p - var->value;
|
|
|
|
|
|
|
|
|
|
max += EXPANSION_INCREMENT (l + 1);
|
|
|
|
|
var->value = xrealloc (var->value, max);
|
|
|
|
|
p = &var->value[off];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bcopy (v->name, p, l);
|
|
|
|
|
p += l;
|
|
|
|
|
*(p++) = ' ';
|
|
|
|
|
}
|
|
|
|
|
*(p-1) = '\0';
|
|
|
|
|
|
2002-08-08 00:11:19 +00:00
|
|
|
|
/* Remember how many variables are in our current count. Since we never
|
|
|
|
|
remove variables from the list, this is a reliable way to know whether
|
|
|
|
|
the list is up to date or needs to be recomputed. */
|
|
|
|
|
|
2002-08-01 13:16:57 +00:00
|
|
|
|
last_var_count = global_variable_set.table.ht_fill;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return var;
|
|
|
|
|
}
|
|
|
|
|
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
|
|
|
|
/* Lookup a variable whose name is a string starting at NAME
|
|
|
|
|
and with LENGTH chars. NAME need not be null-terminated.
|
|
|
|
|
Returns address of the `struct variable' containing all info
|
2001-01-21 06:49:11 +00:00
|
|
|
|
on the variable, or nil if no such variable is defined. */
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
|
|
|
|
struct variable *
|
2002-10-14 21:54:04 +00:00
|
|
|
|
lookup_variable (const char *name, unsigned int length)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
2001-01-21 06:49:11 +00:00
|
|
|
|
const struct variable_set_list *setlist;
|
2002-07-11 06:38:57 +00:00
|
|
|
|
struct variable var_key;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
var_key.name = (char *) name;
|
|
|
|
|
var_key.length = length;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
|
|
|
|
for (setlist = current_variable_set_list;
|
|
|
|
|
setlist != 0; setlist = setlist->next)
|
|
|
|
|
{
|
2001-01-21 06:49:11 +00:00
|
|
|
|
const struct variable_set *set = setlist->set;
|
|
|
|
|
struct variable *v;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
v = (struct variable *) hash_find_item ((struct hash_table *) &set->table, &var_key);
|
|
|
|
|
if (v)
|
2002-08-08 00:11:19 +00:00
|
|
|
|
return v->special ? handle_special_var (v) : v;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-22 05:43:03 +00:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
/* since we don't read envp[] on startup, try to get the
|
|
|
|
|
variable via getenv() here. */
|
2001-01-21 06:49:11 +00:00
|
|
|
|
{
|
|
|
|
|
char *vname = alloca (length + 1);
|
|
|
|
|
char *value;
|
|
|
|
|
strncpy (vname, name, length);
|
|
|
|
|
vname[length] = 0;
|
|
|
|
|
value = getenv (vname);
|
|
|
|
|
if (value != 0)
|
|
|
|
|
{
|
|
|
|
|
char *sptr;
|
|
|
|
|
int scnt;
|
2000-01-22 05:43:03 +00:00
|
|
|
|
|
2001-01-21 06:49:11 +00:00
|
|
|
|
sptr = value;
|
|
|
|
|
scnt = 0;
|
2000-01-22 05:43:03 +00:00
|
|
|
|
|
2001-01-21 06:49:11 +00:00
|
|
|
|
while ((sptr = strchr (sptr, '$')))
|
|
|
|
|
{
|
|
|
|
|
scnt++;
|
|
|
|
|
sptr++;
|
|
|
|
|
}
|
2000-01-22 05:43:03 +00:00
|
|
|
|
|
2001-01-21 06:49:11 +00:00
|
|
|
|
if (scnt > 0)
|
|
|
|
|
{
|
|
|
|
|
char *nvalue;
|
|
|
|
|
char *nptr;
|
|
|
|
|
|
|
|
|
|
nvalue = alloca (strlen (value) + scnt + 1);
|
|
|
|
|
sptr = value;
|
|
|
|
|
nptr = nvalue;
|
|
|
|
|
|
|
|
|
|
while (*sptr)
|
|
|
|
|
{
|
|
|
|
|
if (*sptr == '$')
|
|
|
|
|
{
|
|
|
|
|
*nptr++ = '$';
|
|
|
|
|
*nptr++ = '$';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*nptr++ = *sptr;
|
|
|
|
|
}
|
|
|
|
|
sptr++;
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-01 03:56:50 +00:00
|
|
|
|
*nptr = '\0';
|
2001-01-21 06:49:11 +00:00
|
|
|
|
return define_variable (vname, length, nvalue, o_env, 1);
|
2000-01-22 05:43:03 +00:00
|
|
|
|
|
2001-01-21 06:49:11 +00:00
|
|
|
|
}
|
2000-01-22 05:43:03 +00:00
|
|
|
|
|
2001-01-21 06:49:11 +00:00
|
|
|
|
return define_variable (vname, length, value, o_env, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-01-22 05:43:03 +00:00
|
|
|
|
#endif /* VMS */
|
|
|
|
|
|
2001-01-21 06:49:11 +00:00
|
|
|
|
return 0;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
|
/* Lookup a variable whose name is a string starting at NAME
|
|
|
|
|
and with LENGTH chars in set SET. NAME need not be null-terminated.
|
|
|
|
|
Returns address of the `struct variable' containing all info
|
|
|
|
|
on the variable, or nil if no such variable is defined. */
|
|
|
|
|
|
2001-01-21 06:49:11 +00:00
|
|
|
|
struct variable *
|
2002-10-14 21:54:04 +00:00
|
|
|
|
lookup_variable_in_set (const char *name, unsigned int length,
|
|
|
|
|
const struct variable_set *set)
|
1998-07-30 20:54:47 +00:00
|
|
|
|
{
|
2002-07-11 06:38:57 +00:00
|
|
|
|
struct variable var_key;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
var_key.name = (char *) name;
|
|
|
|
|
var_key.length = length;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
return (struct variable *) hash_find_item ((struct hash_table *) &set->table, &var_key);
|
1998-07-30 20:54:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
1991-10-07 22:04:20 +00:00
|
|
|
|
/* Initialize FILE's variable set list. If FILE already has a variable set
|
|
|
|
|
list, the topmost variable set is left intact, but the the rest of the
|
2002-09-17 21:52:45 +00:00
|
|
|
|
chain is replaced with FILE->parent's setlist. If FILE is a double-colon
|
|
|
|
|
rule, then we will use the "root" double-colon target's variable set as the
|
|
|
|
|
parent of FILE's variable set.
|
|
|
|
|
|
|
|
|
|
If we're READing a makefile, don't do the pattern variable search now,
|
|
|
|
|
since the pattern variable might not have been defined yet. */
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
initialize_file_variables (struct file *file, int reading)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
|
|
|
|
register struct variable_set_list *l = file->variables;
|
2000-02-05 07:37:40 +00:00
|
|
|
|
|
1991-10-07 22:04:20 +00:00
|
|
|
|
if (l == 0)
|
|
|
|
|
{
|
|
|
|
|
l = (struct variable_set_list *)
|
|
|
|
|
xmalloc (sizeof (struct variable_set_list));
|
|
|
|
|
l->set = (struct variable_set *) xmalloc (sizeof (struct variable_set));
|
2002-07-11 06:38:57 +00:00
|
|
|
|
hash_init (&l->set->table, PERFILE_VARIABLE_BUCKETS,
|
2002-09-17 21:52:45 +00:00
|
|
|
|
variable_hash_1, variable_hash_2, variable_hash_cmp);
|
1991-10-07 22:04:20 +00:00
|
|
|
|
file->variables = l;
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-17 21:52:45 +00:00
|
|
|
|
/* If this is a double-colon, then our "parent" is the "root" target for
|
|
|
|
|
this double-colon rule. Since that rule has the same name, parent,
|
|
|
|
|
etc. we can just use its variables as the "next" for ours. */
|
|
|
|
|
|
|
|
|
|
if (file->double_colon && file->double_colon != file)
|
|
|
|
|
{
|
|
|
|
|
initialize_file_variables (file->double_colon, reading);
|
|
|
|
|
l->next = file->double_colon->variables;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
1991-10-07 22:04:20 +00:00
|
|
|
|
if (file->parent == 0)
|
|
|
|
|
l->next = &global_setlist;
|
|
|
|
|
else
|
|
|
|
|
{
|
2000-02-05 07:37:40 +00:00
|
|
|
|
initialize_file_variables (file->parent, reading);
|
1991-10-07 22:04:20 +00:00
|
|
|
|
l->next = file->parent->variables;
|
|
|
|
|
}
|
2000-02-05 07:37:40 +00:00
|
|
|
|
|
|
|
|
|
/* If we're not reading makefiles and we haven't looked yet, see if
|
2003-05-02 01:44:59 +00:00
|
|
|
|
we can find pattern variables for this target. */
|
2000-02-05 07:37:40 +00:00
|
|
|
|
|
|
|
|
|
if (!reading && !file->pat_searched)
|
|
|
|
|
{
|
2003-05-02 01:44:59 +00:00
|
|
|
|
struct pattern_var *p;
|
2000-02-05 07:37:40 +00:00
|
|
|
|
|
2003-05-02 01:44:59 +00:00
|
|
|
|
p = lookup_pattern_var (0, file->name);
|
2000-02-05 07:37:40 +00:00
|
|
|
|
if (p != 0)
|
|
|
|
|
{
|
2003-05-02 01:44:59 +00:00
|
|
|
|
struct variable_set_list *global = current_variable_set_list;
|
|
|
|
|
|
|
|
|
|
/* We found at least one. Set up a new variable set to accumulate
|
|
|
|
|
all the pattern variables that match this target. */
|
|
|
|
|
|
|
|
|
|
file->pat_variables = create_new_variable_set ();
|
|
|
|
|
current_variable_set_list = file->pat_variables;
|
|
|
|
|
|
|
|
|
|
do
|
2004-09-27 18:09:52 +00:00
|
|
|
|
{
|
|
|
|
|
/* We found one, so insert it into the set. */
|
2004-10-05 16:56:14 +00:00
|
|
|
|
|
|
|
|
|
struct variable *v;
|
|
|
|
|
|
|
|
|
|
if (p->variable.flavor == f_simple)
|
|
|
|
|
{
|
|
|
|
|
v = define_variable_loc (
|
|
|
|
|
p->variable.name, strlen (p->variable.name),
|
|
|
|
|
p->variable.value, p->variable.origin,
|
|
|
|
|
0, &p->variable.fileinfo);
|
|
|
|
|
|
|
|
|
|
v->flavor = f_simple;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
v = do_variable_definition (
|
|
|
|
|
&p->variable.fileinfo, p->variable.name,
|
|
|
|
|
p->variable.value, p->variable.origin,
|
|
|
|
|
p->variable.flavor, 1);
|
|
|
|
|
}
|
2004-09-27 18:09:52 +00:00
|
|
|
|
|
|
|
|
|
/* Also mark it as a per-target and copy export status. */
|
|
|
|
|
v->per_target = p->variable.per_target;
|
|
|
|
|
v->export = p->variable.export;
|
|
|
|
|
}
|
2003-05-02 01:44:59 +00:00
|
|
|
|
while ((p = lookup_pattern_var (p, file->name)) != 0);
|
|
|
|
|
|
|
|
|
|
current_variable_set_list = global;
|
2000-02-05 07:37:40 +00:00
|
|
|
|
}
|
2003-05-02 01:44:59 +00:00
|
|
|
|
file->pat_searched = 1;
|
2000-02-05 07:37:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we have a pattern variable match, set it up. */
|
|
|
|
|
|
|
|
|
|
if (file->pat_variables != 0)
|
|
|
|
|
{
|
|
|
|
|
file->pat_variables->next = l->next;
|
|
|
|
|
l->next = file->pat_variables;
|
|
|
|
|
}
|
1991-10-07 22:04:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Pop the top set off the current variable set list,
|
|
|
|
|
and free all its storage. */
|
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
static void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
free_variable_name_and_value (const void *item)
|
2002-07-11 06:38:57 +00:00
|
|
|
|
{
|
|
|
|
|
struct variable *v = (struct variable *) item;
|
|
|
|
|
free (v->name);
|
|
|
|
|
free (v->value);
|
|
|
|
|
}
|
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
|
struct variable_set_list *
|
2002-10-14 21:54:04 +00:00
|
|
|
|
create_new_variable_set (void)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
|
|
|
|
register struct variable_set_list *setlist;
|
|
|
|
|
register struct variable_set *set;
|
|
|
|
|
|
|
|
|
|
set = (struct variable_set *) xmalloc (sizeof (struct variable_set));
|
2002-07-11 06:38:57 +00:00
|
|
|
|
hash_init (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS,
|
|
|
|
|
variable_hash_1, variable_hash_2, variable_hash_cmp);
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
|
|
|
|
setlist = (struct variable_set_list *)
|
|
|
|
|
xmalloc (sizeof (struct variable_set_list));
|
|
|
|
|
setlist->set = set;
|
|
|
|
|
setlist->next = current_variable_set_list;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
|
|
|
|
|
return setlist;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-09 19:19:20 +00:00
|
|
|
|
/* Create a new variable set and push it on the current setlist.
|
|
|
|
|
If we're pushing a global scope (that is, the current scope is the global
|
|
|
|
|
scope) then we need to "push" it the other way: file variable sets point
|
|
|
|
|
directly to the global_setlist so we need to replace that with the new one.
|
|
|
|
|
*/
|
1998-07-30 20:54:47 +00:00
|
|
|
|
|
|
|
|
|
struct variable_set_list *
|
2002-10-14 21:54:04 +00:00
|
|
|
|
push_new_variable_scope (void)
|
1998-07-30 20:54:47 +00:00
|
|
|
|
{
|
2005-06-09 19:19:20 +00:00
|
|
|
|
current_variable_set_list = create_new_variable_set();
|
|
|
|
|
if (current_variable_set_list->next == &global_setlist)
|
|
|
|
|
{
|
|
|
|
|
/* It was the global, so instead of new -> &global we want to replace
|
|
|
|
|
&global with the new one and have &global -> new, with current still
|
|
|
|
|
pointing to &global */
|
|
|
|
|
struct variable_set *set = current_variable_set_list->set;
|
|
|
|
|
current_variable_set_list->set = global_setlist.set;
|
|
|
|
|
global_setlist.set = set;
|
|
|
|
|
current_variable_set_list->next = global_setlist.next;
|
|
|
|
|
global_setlist.next = current_variable_set_list;
|
|
|
|
|
current_variable_set_list = &global_setlist;
|
|
|
|
|
}
|
|
|
|
|
return (current_variable_set_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
pop_variable_scope (void)
|
|
|
|
|
{
|
|
|
|
|
struct variable_set_list *setlist;
|
|
|
|
|
struct variable_set *set;
|
|
|
|
|
|
|
|
|
|
/* Can't call this if there's no scope to pop! */
|
|
|
|
|
assert(current_variable_set_list->next != NULL);
|
|
|
|
|
|
|
|
|
|
if (current_variable_set_list != &global_setlist)
|
|
|
|
|
{
|
|
|
|
|
/* We're not pointing to the global setlist, so pop this one. */
|
|
|
|
|
setlist = current_variable_set_list;
|
|
|
|
|
set = setlist->set;
|
|
|
|
|
current_variable_set_list = setlist->next;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* This set is the one in the global_setlist, but there is another global
|
|
|
|
|
set beyond that. We want to copy that set to global_setlist, then
|
|
|
|
|
delete what used to be in global_setlist. */
|
|
|
|
|
setlist = global_setlist.next;
|
|
|
|
|
set = global_setlist.set;
|
|
|
|
|
global_setlist.set = setlist->set;
|
|
|
|
|
global_setlist.next = setlist->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free the one we no longer need. */
|
|
|
|
|
free ((char *) setlist);
|
|
|
|
|
hash_map (&set->table, free_variable_name_and_value);
|
|
|
|
|
hash_free (&set->table, 1);
|
|
|
|
|
free ((char *) set);
|
1991-10-07 22:04:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-05-02 01:44:59 +00:00
|
|
|
|
/* Merge FROM_SET into TO_SET, freeing unused storage in FROM_SET. */
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
|
|
|
|
static void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
merge_variable_sets (struct variable_set *to_set,
|
|
|
|
|
struct variable_set *from_set)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
2002-07-11 06:38:57 +00:00
|
|
|
|
struct variable **from_var_slot = (struct variable **) from_set->table.ht_vec;
|
|
|
|
|
struct variable **from_var_end = from_var_slot + from_set->table.ht_size;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
for ( ; from_var_slot < from_var_end; from_var_slot++)
|
|
|
|
|
if (! HASH_VACANT (*from_var_slot))
|
|
|
|
|
{
|
|
|
|
|
struct variable *from_var = *from_var_slot;
|
|
|
|
|
struct variable **to_var_slot
|
|
|
|
|
= (struct variable **) hash_find_slot (&to_set->table, *from_var_slot);
|
|
|
|
|
if (HASH_VACANT (*to_var_slot))
|
|
|
|
|
hash_insert_at (&to_set->table, from_var, to_var_slot);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* GKM FIXME: delete in from_set->table */
|
|
|
|
|
free (from_var->value);
|
|
|
|
|
free (from_var);
|
|
|
|
|
}
|
|
|
|
|
}
|
1991-10-07 22:04:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Merge SETLIST1 into SETLIST0, freeing unused storage in SETLIST1. */
|
|
|
|
|
|
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
merge_variable_set_lists (struct variable_set_list **setlist0,
|
|
|
|
|
struct variable_set_list *setlist1)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
|
|
|
|
register struct variable_set_list *list0 = *setlist0;
|
|
|
|
|
struct variable_set_list *last0 = 0;
|
|
|
|
|
|
|
|
|
|
while (setlist1 != 0 && list0 != 0)
|
|
|
|
|
{
|
|
|
|
|
struct variable_set_list *next = setlist1;
|
|
|
|
|
setlist1 = setlist1->next;
|
|
|
|
|
|
|
|
|
|
merge_variable_sets (list0->set, next->set);
|
|
|
|
|
|
|
|
|
|
last0 = list0;
|
|
|
|
|
list0 = list0->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (setlist1 != 0)
|
|
|
|
|
{
|
|
|
|
|
if (last0 == 0)
|
|
|
|
|
*setlist0 = setlist1;
|
|
|
|
|
else
|
|
|
|
|
last0->next = setlist1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Define the automatic variables, and record the addresses
|
|
|
|
|
of their structures so we can change their values quickly. */
|
|
|
|
|
|
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
define_automatic_variables (void)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
2003-03-24 23:14:15 +00:00
|
|
|
|
#if defined(WINDOWS32) || defined(__EMX__)
|
1996-05-22 21:51:45 +00:00
|
|
|
|
extern char* default_shell;
|
|
|
|
|
#else
|
1991-10-07 22:04:20 +00:00
|
|
|
|
extern char default_shell[];
|
1996-05-22 21:51:45 +00:00
|
|
|
|
#endif
|
1991-10-07 22:04:20 +00:00
|
|
|
|
register struct variable *v;
|
1993-08-19 20:36:05 +00:00
|
|
|
|
char buf[200];
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
|
|
|
|
sprintf (buf, "%u", makelevel);
|
2002-07-11 06:38:57 +00:00
|
|
|
|
(void) define_variable (MAKELEVEL_NAME, MAKELEVEL_LENGTH, buf, o_env, 0);
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
1993-08-19 20:36:05 +00:00
|
|
|
|
sprintf (buf, "%s%s%s",
|
|
|
|
|
version_string,
|
|
|
|
|
(remote_description == 0 || remote_description[0] == '\0')
|
|
|
|
|
? "" : "-",
|
|
|
|
|
(remote_description == 0 || remote_description[0] == '\0')
|
|
|
|
|
? "" : remote_description);
|
|
|
|
|
(void) define_variable ("MAKE_VERSION", 12, buf, o_default, 0);
|
|
|
|
|
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef __MSDOS__
|
|
|
|
|
/* Allow to specify a special shell just for Make,
|
|
|
|
|
and use $COMSPEC as the default $SHELL when appropriate. */
|
|
|
|
|
{
|
|
|
|
|
static char shell_str[] = "SHELL";
|
|
|
|
|
const int shlen = sizeof (shell_str) - 1;
|
|
|
|
|
struct variable *mshp = lookup_variable ("MAKESHELL", 9);
|
|
|
|
|
struct variable *comp = lookup_variable ("COMSPEC", 7);
|
|
|
|
|
|
|
|
|
|
/* Make $MAKESHELL override $SHELL even if -e is in effect. */
|
|
|
|
|
if (mshp)
|
|
|
|
|
(void) define_variable (shell_str, shlen,
|
|
|
|
|
mshp->value, o_env_override, 0);
|
|
|
|
|
else if (comp)
|
|
|
|
|
{
|
|
|
|
|
/* $COMSPEC shouldn't override $SHELL. */
|
|
|
|
|
struct variable *shp = lookup_variable (shell_str, shlen);
|
|
|
|
|
|
|
|
|
|
if (!shp)
|
|
|
|
|
(void) define_variable (shell_str, shlen, comp->value, o_env, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-24 23:14:15 +00:00
|
|
|
|
#elif defined(__EMX__)
|
|
|
|
|
{
|
|
|
|
|
static char shell_str[] = "SHELL";
|
|
|
|
|
const int shlen = sizeof (shell_str) - 1;
|
|
|
|
|
struct variable *shell = lookup_variable (shell_str, shlen);
|
|
|
|
|
struct variable *replace = lookup_variable ("MAKESHELL", 9);
|
|
|
|
|
|
|
|
|
|
/* if $MAKESHELL is defined in the environment assume o_env_override */
|
|
|
|
|
if (replace && *replace->value && replace->origin == o_env)
|
|
|
|
|
replace->origin = o_env_override;
|
|
|
|
|
|
|
|
|
|
/* if $MAKESHELL is not defined use $SHELL but only if the variable
|
|
|
|
|
did not come from the environment */
|
|
|
|
|
if (!replace || !*replace->value)
|
|
|
|
|
if (shell && *shell->value && (shell->origin == o_env
|
|
|
|
|
|| shell->origin == o_env_override))
|
|
|
|
|
{
|
|
|
|
|
/* overwrite whatever we got from the environment */
|
|
|
|
|
free(shell->value);
|
|
|
|
|
shell->value = xstrdup (default_shell);
|
|
|
|
|
shell->origin = o_default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Some people do not like cmd to be used as the default
|
|
|
|
|
if $SHELL is not defined in the Makefile.
|
|
|
|
|
With -DNO_CMD_DEFAULT you can turn off this behaviour */
|
|
|
|
|
# ifndef NO_CMD_DEFAULT
|
|
|
|
|
/* otherwise use $COMSPEC */
|
|
|
|
|
if (!replace || !*replace->value)
|
|
|
|
|
replace = lookup_variable ("COMSPEC", 7);
|
|
|
|
|
|
|
|
|
|
/* otherwise use $OS2_SHELL */
|
|
|
|
|
if (!replace || !*replace->value)
|
|
|
|
|
replace = lookup_variable ("OS2_SHELL", 9);
|
|
|
|
|
# else
|
|
|
|
|
# warning NO_CMD_DEFAULT: GNU make will not use CMD.EXE as default shell
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
if (replace && *replace->value)
|
|
|
|
|
/* overwrite $SHELL */
|
|
|
|
|
(void) define_variable (shell_str, shlen, replace->value,
|
|
|
|
|
replace->origin, 0);
|
|
|
|
|
else
|
|
|
|
|
/* provide a definition if there is none */
|
|
|
|
|
(void) define_variable (shell_str, shlen, default_shell,
|
|
|
|
|
o_default, 0);
|
|
|
|
|
}
|
|
|
|
|
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#endif
|
1996-05-13 18:40:28 +00:00
|
|
|
|
|
2004-11-28 23:11:23 +00:00
|
|
|
|
/* This won't override any definition, but it will provide one if there
|
|
|
|
|
isn't one there. */
|
1991-10-07 22:04:20 +00:00
|
|
|
|
v = define_variable ("SHELL", 5, default_shell, o_default, 0);
|
|
|
|
|
|
2004-11-28 23:11:23 +00:00
|
|
|
|
/* On MSDOS we do use SHELL from environment, since it isn't a standard
|
|
|
|
|
environment variable on MSDOS, so whoever sets it, does that on purpose.
|
|
|
|
|
On OS/2 we do not use SHELL from environment but we have already handled
|
|
|
|
|
that problem above. */
|
2003-03-24 23:14:15 +00:00
|
|
|
|
#if !defined(__MSDOS__) && !defined(__EMX__)
|
1992-05-12 04:42:11 +00:00
|
|
|
|
/* Don't let SHELL come from the environment. */
|
1993-01-13 21:09:20 +00:00
|
|
|
|
if (*v->value == '\0' || v->origin == o_env || v->origin == o_env_override)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
1992-10-23 19:57:55 +00:00
|
|
|
|
free (v->value);
|
1991-10-07 22:04:20 +00:00
|
|
|
|
v->origin = o_file;
|
1999-07-21 05:53:23 +00:00
|
|
|
|
v->value = xstrdup (default_shell);
|
1991-10-07 22:04:20 +00:00
|
|
|
|
}
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#endif
|
1992-07-10 04:06:22 +00:00
|
|
|
|
|
|
|
|
|
/* Make sure MAKEFILES gets exported if it is set. */
|
1992-07-24 06:16:47 +00:00
|
|
|
|
v = define_variable ("MAKEFILES", 9, "", o_default, 0);
|
1992-07-10 04:06:22 +00:00
|
|
|
|
v->export = v_ifset;
|
1993-01-28 23:01:01 +00:00
|
|
|
|
|
|
|
|
|
/* Define the magic D and F variables in terms of
|
|
|
|
|
the automatic variables they are variations of. */
|
|
|
|
|
|
2000-01-22 05:43:03 +00:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
define_variable ("@D", 2, "$(dir $@)", o_automatic, 1);
|
|
|
|
|
define_variable ("%D", 2, "$(dir $%)", o_automatic, 1);
|
|
|
|
|
define_variable ("*D", 2, "$(dir $*)", o_automatic, 1);
|
|
|
|
|
define_variable ("<D", 2, "$(dir $<)", o_automatic, 1);
|
|
|
|
|
define_variable ("?D", 2, "$(dir $?)", o_automatic, 1);
|
|
|
|
|
define_variable ("^D", 2, "$(dir $^)", o_automatic, 1);
|
|
|
|
|
define_variable ("+D", 2, "$(dir $+)", o_automatic, 1);
|
|
|
|
|
#else
|
1994-01-26 00:48:30 +00:00
|
|
|
|
define_variable ("@D", 2, "$(patsubst %/,%,$(dir $@))", o_automatic, 1);
|
|
|
|
|
define_variable ("%D", 2, "$(patsubst %/,%,$(dir $%))", o_automatic, 1);
|
|
|
|
|
define_variable ("*D", 2, "$(patsubst %/,%,$(dir $*))", o_automatic, 1);
|
|
|
|
|
define_variable ("<D", 2, "$(patsubst %/,%,$(dir $<))", o_automatic, 1);
|
|
|
|
|
define_variable ("?D", 2, "$(patsubst %/,%,$(dir $?))", o_automatic, 1);
|
|
|
|
|
define_variable ("^D", 2, "$(patsubst %/,%,$(dir $^))", o_automatic, 1);
|
1994-10-10 08:08:58 +00:00
|
|
|
|
define_variable ("+D", 2, "$(patsubst %/,%,$(dir $+))", o_automatic, 1);
|
2000-01-22 05:43:03 +00:00
|
|
|
|
#endif
|
1993-01-28 23:01:01 +00:00
|
|
|
|
define_variable ("@F", 2, "$(notdir $@)", o_automatic, 1);
|
|
|
|
|
define_variable ("%F", 2, "$(notdir $%)", o_automatic, 1);
|
|
|
|
|
define_variable ("*F", 2, "$(notdir $*)", o_automatic, 1);
|
|
|
|
|
define_variable ("<F", 2, "$(notdir $<)", o_automatic, 1);
|
|
|
|
|
define_variable ("?F", 2, "$(notdir $?)", o_automatic, 1);
|
|
|
|
|
define_variable ("^F", 2, "$(notdir $^)", o_automatic, 1);
|
1994-10-10 08:08:58 +00:00
|
|
|
|
define_variable ("+F", 2, "$(notdir $+)", o_automatic, 1);
|
1991-10-07 22:04:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1992-05-04 22:37:22 +00:00
|
|
|
|
int export_all_variables;
|
|
|
|
|
|
1991-10-07 22:04:20 +00:00
|
|
|
|
/* Create a new environment for FILE's commands.
|
1993-07-15 00:22:56 +00:00
|
|
|
|
If FILE is nil, this is for the `shell' function.
|
1991-10-07 22:04:20 +00:00
|
|
|
|
The child's MAKELEVEL variable is incremented. */
|
|
|
|
|
|
|
|
|
|
char **
|
2002-10-14 21:54:04 +00:00
|
|
|
|
target_environment (struct file *file)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
1993-07-15 01:59:03 +00:00
|
|
|
|
struct variable_set_list *set_list;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
register struct variable_set_list *s;
|
2002-07-11 06:38:57 +00:00
|
|
|
|
struct hash_table table;
|
|
|
|
|
struct variable **v_slot;
|
|
|
|
|
struct variable **v_end;
|
|
|
|
|
struct variable makelevel_key;
|
|
|
|
|
char **result_0;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
char **result;
|
|
|
|
|
|
1993-07-15 00:22:56 +00:00
|
|
|
|
if (file == 0)
|
1993-07-15 01:59:03 +00:00
|
|
|
|
set_list = current_variable_set_list;
|
1993-07-15 00:22:56 +00:00
|
|
|
|
else
|
1993-07-15 01:59:03 +00:00
|
|
|
|
set_list = file->variables;
|
1993-07-15 00:22:56 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
hash_init (&table, VARIABLE_BUCKETS,
|
|
|
|
|
variable_hash_1, variable_hash_2, variable_hash_cmp);
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
|
|
|
|
/* Run through all the variable sets in the list,
|
|
|
|
|
accumulating variables in TABLE. */
|
1993-07-15 01:59:03 +00:00
|
|
|
|
for (s = set_list; s != 0; s = s->next)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
2002-07-11 06:38:57 +00:00
|
|
|
|
struct variable_set *set = s->set;
|
|
|
|
|
v_slot = (struct variable **) set->table.ht_vec;
|
|
|
|
|
v_end = v_slot + set->table.ht_size;
|
|
|
|
|
for ( ; v_slot < v_end; v_slot++)
|
|
|
|
|
if (! HASH_VACANT (*v_slot))
|
|
|
|
|
{
|
|
|
|
|
struct variable **new_slot;
|
|
|
|
|
struct variable *v = *v_slot;
|
|
|
|
|
|
|
|
|
|
/* If this is a per-target variable and it hasn't been touched
|
|
|
|
|
already then look up the global version and take its export
|
|
|
|
|
value. */
|
|
|
|
|
if (v->per_target && v->export == v_default)
|
|
|
|
|
{
|
|
|
|
|
struct variable *gv;
|
|
|
|
|
|
|
|
|
|
gv = lookup_variable_in_set (v->name, strlen(v->name),
|
|
|
|
|
&global_variable_set);
|
|
|
|
|
if (gv)
|
|
|
|
|
v->export = gv->export;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (v->export)
|
|
|
|
|
{
|
|
|
|
|
case v_default:
|
|
|
|
|
if (v->origin == o_default || v->origin == o_automatic)
|
|
|
|
|
/* Only export default variables by explicit request. */
|
|
|
|
|
continue;
|
|
|
|
|
|
2002-08-01 13:16:57 +00:00
|
|
|
|
/* The variable doesn't have a name that can be exported. */
|
|
|
|
|
if (! v->exportable)
|
|
|
|
|
continue;
|
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
if (! export_all_variables
|
|
|
|
|
&& v->origin != o_command
|
|
|
|
|
&& v->origin != o_env && v->origin != o_env_override)
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
1992-05-03 22:02:26 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
case v_export:
|
|
|
|
|
break;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
case v_noexport:
|
2004-11-28 23:11:23 +00:00
|
|
|
|
/* If this is the SHELL variable and it's not exported, then
|
|
|
|
|
add the value from our original environment. */
|
2004-12-05 18:09:31 +00:00
|
|
|
|
if (streq (v->name, "SHELL"))
|
|
|
|
|
{
|
|
|
|
|
extern struct variable shell_var;
|
|
|
|
|
v = &shell_var;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
case v_ifset:
|
|
|
|
|
if (v->origin == o_default)
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
}
|
1998-07-30 20:54:47 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
new_slot = (struct variable **) hash_find_slot (&table, v);
|
|
|
|
|
if (HASH_VACANT (*new_slot))
|
|
|
|
|
hash_insert_at (&table, v, new_slot);
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-07-30 20:54:47 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
makelevel_key.name = MAKELEVEL_NAME;
|
|
|
|
|
makelevel_key.length = MAKELEVEL_LENGTH;
|
|
|
|
|
hash_delete (&table, &makelevel_key);
|
1998-07-30 20:54:47 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
result = result_0 = (char **) xmalloc ((table.ht_fill + 2) * sizeof (char *));
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
v_slot = (struct variable **) table.ht_vec;
|
|
|
|
|
v_end = v_slot + table.ht_size;
|
|
|
|
|
for ( ; v_slot < v_end; v_slot++)
|
|
|
|
|
if (! HASH_VACANT (*v_slot))
|
|
|
|
|
{
|
|
|
|
|
struct variable *v = *v_slot;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
/* If V is recursively expanded and didn't come from the environment,
|
|
|
|
|
expand its value. If it came from the environment, it should
|
|
|
|
|
go back into the environment unchanged. */
|
|
|
|
|
if (v->recursive
|
|
|
|
|
&& v->origin != o_env && v->origin != o_env_override)
|
|
|
|
|
{
|
|
|
|
|
char *value = recursively_expand_for_file (v, file);
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
2002-07-11 06:38:57 +00:00
|
|
|
|
if (strcmp(v->name, "Path") == 0 ||
|
|
|
|
|
strcmp(v->name, "PATH") == 0)
|
|
|
|
|
convert_Path_to_windows32(value, ';');
|
1996-05-22 21:51:45 +00:00
|
|
|
|
#endif
|
2002-07-11 06:38:57 +00:00
|
|
|
|
*result++ = concat (v->name, "=", value);
|
|
|
|
|
free (value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-22 21:51:45 +00:00
|
|
|
|
if (strcmp(v->name, "Path") == 0 ||
|
|
|
|
|
strcmp(v->name, "PATH") == 0)
|
1997-04-07 07:21:16 +00:00
|
|
|
|
convert_Path_to_windows32(v->value, ';');
|
1996-05-22 21:51:45 +00:00
|
|
|
|
#endif
|
2002-07-11 06:38:57 +00:00
|
|
|
|
*result++ = concat (v->name, "=", v->value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*result = (char *) xmalloc (100);
|
|
|
|
|
(void) sprintf (*result, "%s=%u", MAKELEVEL_NAME, makelevel + 1);
|
|
|
|
|
*++result = 0;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
hash_free (&table, 0);
|
|
|
|
|
|
|
|
|
|
return result_0;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-08 02:26:47 +00:00
|
|
|
|
/* Given a variable, a value, and a flavor, define the variable.
|
|
|
|
|
See the try_variable_definition() function for details on the parameters. */
|
1992-05-03 22:02:26 +00:00
|
|
|
|
|
|
|
|
|
struct variable *
|
2002-10-14 21:54:04 +00:00
|
|
|
|
do_variable_definition (const struct floc *flocp, const char *varname,
|
|
|
|
|
char *value, enum variable_origin origin,
|
|
|
|
|
enum variable_flavor flavor, int target_var)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
2002-07-08 02:26:47 +00:00
|
|
|
|
char *p, *alloc_value = NULL;
|
1992-11-23 20:53:24 +00:00
|
|
|
|
struct variable *v;
|
1999-11-17 07:33:47 +00:00
|
|
|
|
int append = 0;
|
2003-05-02 01:44:59 +00:00
|
|
|
|
int conditional = 0;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
1993-04-12 20:02:24 +00:00
|
|
|
|
/* Calculate the variable's new value in VALUE. */
|
|
|
|
|
|
|
|
|
|
switch (flavor)
|
|
|
|
|
{
|
2002-07-08 02:26:47 +00:00
|
|
|
|
default:
|
1998-07-30 20:54:47 +00:00
|
|
|
|
case f_bogus:
|
1993-04-12 20:02:24 +00:00
|
|
|
|
/* Should not be possible. */
|
|
|
|
|
abort ();
|
1998-07-30 20:54:47 +00:00
|
|
|
|
case f_simple:
|
1999-02-22 07:23:30 +00:00
|
|
|
|
/* A simple variable definition "var := value". Expand the value.
|
|
|
|
|
We have to allocate memory since otherwise it'll clobber the
|
1999-08-22 17:50:57 +00:00
|
|
|
|
variable buffer, and we may still need that if we're looking at a
|
|
|
|
|
target-specific variable. */
|
2002-07-08 02:26:47 +00:00
|
|
|
|
p = alloc_value = allocated_variable_expand (value);
|
1993-04-12 20:02:24 +00:00
|
|
|
|
break;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
case f_conditional:
|
|
|
|
|
/* A conditional variable definition "var ?= value".
|
|
|
|
|
The value is set IFF the variable is not defined yet. */
|
2002-07-08 02:26:47 +00:00
|
|
|
|
v = lookup_variable (varname, strlen (varname));
|
1998-07-30 20:54:47 +00:00
|
|
|
|
if (v)
|
2002-07-08 02:26:47 +00:00
|
|
|
|
return v;
|
|
|
|
|
|
2003-05-02 01:44:59 +00:00
|
|
|
|
conditional = 1;
|
1999-03-04 17:03:56 +00:00
|
|
|
|
flavor = f_recursive;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
case f_recursive:
|
1993-04-12 20:02:24 +00:00
|
|
|
|
/* A recursive variable definition "var = value".
|
|
|
|
|
The value is used verbatim. */
|
2002-07-08 02:26:47 +00:00
|
|
|
|
p = value;
|
1993-04-12 20:02:24 +00:00
|
|
|
|
break;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
case f_append:
|
2000-08-21 06:18:35 +00:00
|
|
|
|
{
|
|
|
|
|
/* If we have += but we're in a target variable context, we want to
|
|
|
|
|
append only with other variables in the context of this target. */
|
|
|
|
|
if (target_var)
|
|
|
|
|
{
|
|
|
|
|
append = 1;
|
2002-07-08 02:26:47 +00:00
|
|
|
|
v = lookup_variable_in_set (varname, strlen (varname),
|
2001-01-21 06:49:11 +00:00
|
|
|
|
current_variable_set_list->set);
|
2004-03-22 15:11:48 +00:00
|
|
|
|
|
|
|
|
|
/* Don't append from the global set if a previous non-appending
|
|
|
|
|
target-specific variable definition exists. */
|
|
|
|
|
if (v && !v->append)
|
|
|
|
|
append = 0;
|
2000-08-21 06:18:35 +00:00
|
|
|
|
}
|
2001-01-21 06:49:11 +00:00
|
|
|
|
else
|
2002-07-08 02:26:47 +00:00
|
|
|
|
v = lookup_variable (varname, strlen (varname));
|
2000-08-21 06:18:35 +00:00
|
|
|
|
|
|
|
|
|
if (v == 0)
|
|
|
|
|
{
|
|
|
|
|
/* There was no old value.
|
|
|
|
|
This becomes a normal recursive definition. */
|
2002-07-08 02:26:47 +00:00
|
|
|
|
p = value;
|
2000-08-21 06:18:35 +00:00
|
|
|
|
flavor = f_recursive;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Paste the old and new values together in VALUE. */
|
|
|
|
|
|
2002-08-08 00:11:19 +00:00
|
|
|
|
unsigned int oldlen, vallen;
|
|
|
|
|
char *val;
|
2000-08-21 06:18:35 +00:00
|
|
|
|
|
2002-08-08 00:11:19 +00:00
|
|
|
|
val = value;
|
2000-08-21 06:18:35 +00:00
|
|
|
|
if (v->recursive)
|
|
|
|
|
/* The previous definition of the variable was recursive.
|
|
|
|
|
The new value is the unexpanded old and new values. */
|
|
|
|
|
flavor = f_recursive;
|
|
|
|
|
else
|
|
|
|
|
/* The previous definition of the variable was simple.
|
|
|
|
|
The new value comes from the old value, which was expanded
|
|
|
|
|
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. */
|
2002-08-08 00:11:19 +00:00
|
|
|
|
val = alloc_value = allocated_variable_expand (val);
|
2000-08-21 06:18:35 +00:00
|
|
|
|
|
|
|
|
|
oldlen = strlen (v->value);
|
2002-08-08 00:11:19 +00:00
|
|
|
|
vallen = strlen (val);
|
|
|
|
|
p = (char *) alloca (oldlen + 1 + vallen + 1);
|
2002-07-08 02:26:47 +00:00
|
|
|
|
bcopy (v->value, p, oldlen);
|
|
|
|
|
p[oldlen] = ' ';
|
2002-08-08 00:11:19 +00:00
|
|
|
|
bcopy (val, &p[oldlen + 1], vallen + 1);
|
2000-08-21 06:18:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1993-04-12 20:02:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef __MSDOS__
|
|
|
|
|
/* Many Unix Makefiles include a line saying "SHELL=/bin/sh", but
|
|
|
|
|
non-Unix systems don't conform to this default configuration (in
|
|
|
|
|
fact, most of them don't even have `/bin'). On the other hand,
|
|
|
|
|
$SHELL in the environment, if set, points to the real pathname of
|
|
|
|
|
the shell.
|
|
|
|
|
Therefore, we generally won't let lines like "SHELL=/bin/sh" from
|
|
|
|
|
the Makefile override $SHELL from the environment. But first, we
|
|
|
|
|
look for the basename of the shell in the directory where SHELL=
|
|
|
|
|
points, and along the $PATH; if it is found in any of these places,
|
|
|
|
|
we define $SHELL to be the actual pathname of the shell. Thus, if
|
|
|
|
|
you have bash.exe installed as d:/unix/bash.exe, and d:/unix is on
|
|
|
|
|
your $PATH, then SHELL=/usr/local/bin/bash will have the effect of
|
|
|
|
|
defining SHELL to be "d:/unix/bash.exe". */
|
1999-07-16 02:25:03 +00:00
|
|
|
|
if ((origin == o_file || origin == o_override)
|
2002-07-08 02:26:47 +00:00
|
|
|
|
&& strcmp (varname, "SHELL") == 0)
|
1997-04-07 07:21:16 +00:00
|
|
|
|
{
|
2005-02-28 07:48:22 +00:00
|
|
|
|
PATH_VAR (shellpath);
|
1997-04-07 07:21:16 +00:00
|
|
|
|
extern char * __dosexec_find_on_path (const char *, char *[], char *);
|
|
|
|
|
|
|
|
|
|
/* See if we can find "/bin/sh.exe", "/bin/sh.com", etc. */
|
2002-07-08 02:26:47 +00:00
|
|
|
|
if (__dosexec_find_on_path (p, (char **)0, shellpath))
|
1997-04-07 07:21:16 +00:00
|
|
|
|
{
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
for (p = shellpath; *p; p++)
|
|
|
|
|
{
|
|
|
|
|
if (*p == '\\')
|
|
|
|
|
*p = '/';
|
|
|
|
|
}
|
2002-07-08 02:26:47 +00:00
|
|
|
|
v = define_variable_loc (varname, strlen (varname),
|
2000-02-05 07:37:40 +00:00
|
|
|
|
shellpath, origin, flavor == f_recursive,
|
|
|
|
|
flocp);
|
1997-04-07 07:21:16 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char *shellbase, *bslash;
|
|
|
|
|
struct variable *pathv = lookup_variable ("PATH", 4);
|
|
|
|
|
char *path_string;
|
|
|
|
|
char *fake_env[2];
|
|
|
|
|
size_t pathlen = 0;
|
|
|
|
|
|
2002-07-08 02:26:47 +00:00
|
|
|
|
shellbase = strrchr (p, '/');
|
|
|
|
|
bslash = strrchr (p, '\\');
|
1997-04-07 07:21:16 +00:00
|
|
|
|
if (!shellbase || bslash > shellbase)
|
|
|
|
|
shellbase = bslash;
|
2002-07-08 02:26:47 +00:00
|
|
|
|
if (!shellbase && p[1] == ':')
|
|
|
|
|
shellbase = p + 1;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
if (shellbase)
|
|
|
|
|
shellbase++;
|
|
|
|
|
else
|
2002-07-08 02:26:47 +00:00
|
|
|
|
shellbase = p;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
|
|
|
|
|
/* Search for the basename of the shell (with standard
|
|
|
|
|
executable extensions) along the $PATH. */
|
|
|
|
|
if (pathv)
|
|
|
|
|
pathlen = strlen (pathv->value);
|
|
|
|
|
path_string = (char *)xmalloc (5 + pathlen + 2 + 1);
|
|
|
|
|
/* On MSDOS, current directory is considered as part of $PATH. */
|
|
|
|
|
sprintf (path_string, "PATH=.;%s", pathv ? pathv->value : "");
|
|
|
|
|
fake_env[0] = path_string;
|
|
|
|
|
fake_env[1] = (char *)0;
|
|
|
|
|
if (__dosexec_find_on_path (shellbase, fake_env, shellpath))
|
|
|
|
|
{
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
for (p = shellpath; *p; p++)
|
|
|
|
|
{
|
|
|
|
|
if (*p == '\\')
|
|
|
|
|
*p = '/';
|
|
|
|
|
}
|
2002-07-08 02:26:47 +00:00
|
|
|
|
v = define_variable_loc (varname, strlen (varname),
|
2000-02-05 07:37:40 +00:00
|
|
|
|
shellpath, origin,
|
|
|
|
|
flavor == f_recursive, flocp);
|
1997-04-07 07:21:16 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2002-07-08 02:26:47 +00:00
|
|
|
|
v = lookup_variable (varname, strlen (varname));
|
1997-04-07 07:21:16 +00:00
|
|
|
|
|
|
|
|
|
free (path_string);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif /* __MSDOS__ */
|
1998-07-30 20:54:47 +00:00
|
|
|
|
#ifdef WINDOWS32
|
2002-07-08 02:26:47 +00:00
|
|
|
|
if ((origin == o_file || origin == o_override) && streq (varname, "SHELL"))
|
2000-08-21 06:18:35 +00:00
|
|
|
|
{
|
2002-07-08 02:26:47 +00:00
|
|
|
|
extern char *default_shell;
|
|
|
|
|
|
|
|
|
|
/* Call shell locator function. If it returns TRUE, then
|
|
|
|
|
set no_default_sh_exe to indicate sh was found and
|
|
|
|
|
set new value for SHELL variable. */
|
|
|
|
|
|
|
|
|
|
if (find_and_set_default_shell (p))
|
|
|
|
|
{
|
|
|
|
|
v = define_variable_in_set (varname, strlen (varname), default_shell,
|
|
|
|
|
origin, flavor == f_recursive,
|
|
|
|
|
(target_var
|
|
|
|
|
? current_variable_set_list->set
|
|
|
|
|
: NULL),
|
|
|
|
|
flocp);
|
|
|
|
|
no_default_sh_exe = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
v = lookup_variable (varname, strlen (varname));
|
1998-07-30 20:54:47 +00:00
|
|
|
|
}
|
2000-08-21 06:18:35 +00:00
|
|
|
|
else
|
1998-07-30 20:54:47 +00:00
|
|
|
|
#endif
|
1997-04-07 07:21:16 +00:00
|
|
|
|
|
2002-07-08 02:26:47 +00:00
|
|
|
|
/* If we are defining variables inside an $(eval ...), we might have a
|
|
|
|
|
different variable context pushed, not the global context (maybe we're
|
|
|
|
|
inside a $(call ...) or something. Since this function is only ever
|
|
|
|
|
invoked in places where we want to define globally visible variables,
|
|
|
|
|
make sure we define this variable in the global set. */
|
|
|
|
|
|
|
|
|
|
v = define_variable_in_set (varname, strlen (varname), p,
|
|
|
|
|
origin, flavor == f_recursive,
|
|
|
|
|
(target_var
|
|
|
|
|
? current_variable_set_list->set : NULL),
|
|
|
|
|
flocp);
|
1999-11-17 07:33:47 +00:00
|
|
|
|
v->append = append;
|
2003-05-02 01:44:59 +00:00
|
|
|
|
v->conditional = conditional;
|
1999-11-17 07:33:47 +00:00
|
|
|
|
|
1999-02-22 07:23:30 +00:00
|
|
|
|
if (alloc_value)
|
|
|
|
|
free (alloc_value);
|
2002-07-08 02:26:47 +00:00
|
|
|
|
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try to interpret LINE (a null-terminated string) as a variable definition.
|
|
|
|
|
|
|
|
|
|
ORIGIN may be o_file, o_override, o_env, o_env_override,
|
|
|
|
|
or o_command specifying that the variable definition comes
|
|
|
|
|
from a makefile, an override directive, the environment with
|
|
|
|
|
or without the -e switch, or the command line.
|
|
|
|
|
|
|
|
|
|
See the comments for parse_variable_definition().
|
|
|
|
|
|
|
|
|
|
If LINE was recognized as a variable definition, a pointer to its `struct
|
|
|
|
|
variable' is returned. If LINE is not a variable definition, NULL is
|
|
|
|
|
returned. */
|
|
|
|
|
|
|
|
|
|
struct variable *
|
2003-05-02 01:44:59 +00:00
|
|
|
|
parse_variable_definition (struct variable *v, char *line)
|
2002-07-08 02:26:47 +00:00
|
|
|
|
{
|
|
|
|
|
register int c;
|
|
|
|
|
register char *p = line;
|
|
|
|
|
register char *beg;
|
|
|
|
|
register char *end;
|
|
|
|
|
enum variable_flavor flavor = f_bogus;
|
2003-05-02 01:44:59 +00:00
|
|
|
|
char *name;
|
2002-07-08 02:26:47 +00:00
|
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
c = *p++;
|
|
|
|
|
if (c == '\0' || c == '#')
|
|
|
|
|
return 0;
|
|
|
|
|
if (c == '=')
|
|
|
|
|
{
|
|
|
|
|
end = p - 1;
|
|
|
|
|
flavor = f_recursive;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (c == ':')
|
|
|
|
|
if (*p == '=')
|
|
|
|
|
{
|
|
|
|
|
end = p++ - 1;
|
|
|
|
|
flavor = f_simple;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
/* A colon other than := is a rule line, not a variable defn. */
|
|
|
|
|
return 0;
|
|
|
|
|
else if (c == '+' && *p == '=')
|
|
|
|
|
{
|
|
|
|
|
end = p++ - 1;
|
|
|
|
|
flavor = f_append;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (c == '?' && *p == '=')
|
|
|
|
|
{
|
|
|
|
|
end = p++ - 1;
|
|
|
|
|
flavor = f_conditional;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (c == '$')
|
|
|
|
|
{
|
|
|
|
|
/* This might begin a variable expansion reference. Make sure we
|
|
|
|
|
don't misrecognize chars inside the reference as =, := or +=. */
|
|
|
|
|
char closeparen;
|
|
|
|
|
int count;
|
|
|
|
|
c = *p++;
|
|
|
|
|
if (c == '(')
|
|
|
|
|
closeparen = ')';
|
|
|
|
|
else if (c == '{')
|
|
|
|
|
closeparen = '}';
|
|
|
|
|
else
|
|
|
|
|
continue; /* Nope. */
|
|
|
|
|
|
|
|
|
|
/* P now points past the opening paren or brace.
|
|
|
|
|
Count parens or braces until it is matched. */
|
|
|
|
|
count = 0;
|
|
|
|
|
for (; *p != '\0'; ++p)
|
|
|
|
|
{
|
|
|
|
|
if (*p == c)
|
|
|
|
|
++count;
|
|
|
|
|
else if (*p == closeparen && --count < 0)
|
|
|
|
|
{
|
|
|
|
|
++p;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-05-02 01:44:59 +00:00
|
|
|
|
v->flavor = flavor;
|
2002-07-08 02:26:47 +00:00
|
|
|
|
|
|
|
|
|
beg = next_token (line);
|
|
|
|
|
while (end > beg && isblank ((unsigned char)end[-1]))
|
|
|
|
|
--end;
|
|
|
|
|
p = next_token (p);
|
2003-05-02 01:44:59 +00:00
|
|
|
|
v->value = p;
|
2002-07-08 02:26:47 +00:00
|
|
|
|
|
|
|
|
|
/* Expand the name, so "$(foo)bar = baz" works. */
|
|
|
|
|
name = (char *) alloca (end - beg + 1);
|
|
|
|
|
bcopy (beg, name, end - beg);
|
|
|
|
|
name[end - beg] = '\0';
|
2003-05-02 01:44:59 +00:00
|
|
|
|
v->name = allocated_variable_expand (name);
|
|
|
|
|
|
|
|
|
|
if (v->name[0] == '\0')
|
|
|
|
|
fatal (&v->fileinfo, _("empty variable name"));
|
|
|
|
|
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try to interpret LINE (a null-terminated string) as a variable definition.
|
2002-07-08 02:26:47 +00:00
|
|
|
|
|
2003-05-02 01:44:59 +00:00
|
|
|
|
ORIGIN may be o_file, o_override, o_env, o_env_override,
|
|
|
|
|
or o_command specifying that the variable definition comes
|
|
|
|
|
from a makefile, an override directive, the environment with
|
|
|
|
|
or without the -e switch, or the command line.
|
2002-07-08 02:26:47 +00:00
|
|
|
|
|
2003-05-02 01:44:59 +00:00
|
|
|
|
See the comments for parse_variable_definition().
|
2002-07-08 02:26:47 +00:00
|
|
|
|
|
2003-05-02 01:44:59 +00:00
|
|
|
|
If LINE was recognized as a variable definition, a pointer to its `struct
|
|
|
|
|
variable' is returned. If LINE is not a variable definition, NULL is
|
|
|
|
|
returned. */
|
1992-11-23 20:53:24 +00:00
|
|
|
|
|
2003-05-02 01:44:59 +00:00
|
|
|
|
struct variable *
|
|
|
|
|
try_variable_definition (const struct floc *flocp, char *line,
|
|
|
|
|
enum variable_origin origin, int target_var)
|
|
|
|
|
{
|
|
|
|
|
struct variable v;
|
|
|
|
|
struct variable *vp;
|
|
|
|
|
|
|
|
|
|
if (flocp != 0)
|
|
|
|
|
v.fileinfo = *flocp;
|
|
|
|
|
else
|
|
|
|
|
v.fileinfo.filenm = 0;
|
|
|
|
|
|
|
|
|
|
if (!parse_variable_definition (&v, line))
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
vp = do_variable_definition (flocp, v.name, v.value,
|
|
|
|
|
origin, v.flavor, target_var);
|
|
|
|
|
|
|
|
|
|
free (v.name);
|
|
|
|
|
|
|
|
|
|
return vp;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print information for variable V, prefixing it with PREFIX. */
|
|
|
|
|
|
|
|
|
|
static void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
print_variable (const void *item, void *arg)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
2002-10-14 21:54:04 +00:00
|
|
|
|
const struct variable *v = (struct variable *) item;
|
|
|
|
|
const char *prefix = (char *) arg;
|
1999-08-25 21:39:28 +00:00
|
|
|
|
const char *origin;
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
|
|
|
|
switch (v->origin)
|
|
|
|
|
{
|
|
|
|
|
case o_default:
|
2000-02-05 07:37:40 +00:00
|
|
|
|
origin = _("default");
|
1991-10-07 22:04:20 +00:00
|
|
|
|
break;
|
|
|
|
|
case o_env:
|
2000-02-05 07:37:40 +00:00
|
|
|
|
origin = _("environment");
|
1991-10-07 22:04:20 +00:00
|
|
|
|
break;
|
|
|
|
|
case o_file:
|
2000-02-05 07:37:40 +00:00
|
|
|
|
origin = _("makefile");
|
1991-10-07 22:04:20 +00:00
|
|
|
|
break;
|
|
|
|
|
case o_env_override:
|
2000-02-05 07:37:40 +00:00
|
|
|
|
origin = _("environment under -e");
|
1991-10-07 22:04:20 +00:00
|
|
|
|
break;
|
|
|
|
|
case o_command:
|
2000-02-05 07:37:40 +00:00
|
|
|
|
origin = _("command line");
|
1991-10-07 22:04:20 +00:00
|
|
|
|
break;
|
|
|
|
|
case o_override:
|
2000-02-05 07:37:40 +00:00
|
|
|
|
origin = _("`override' directive");
|
1991-10-07 22:04:20 +00:00
|
|
|
|
break;
|
|
|
|
|
case o_automatic:
|
2000-02-05 07:37:40 +00:00
|
|
|
|
origin = _("automatic");
|
1991-10-07 22:04:20 +00:00
|
|
|
|
break;
|
|
|
|
|
case o_invalid:
|
|
|
|
|
default:
|
|
|
|
|
abort ();
|
|
|
|
|
}
|
2000-02-05 07:37:40 +00:00
|
|
|
|
fputs ("# ", stdout);
|
|
|
|
|
fputs (origin, stdout);
|
|
|
|
|
if (v->fileinfo.filenm)
|
2001-08-19 04:55:51 +00:00
|
|
|
|
printf (_(" (from `%s', line %lu)"),
|
|
|
|
|
v->fileinfo.filenm, v->fileinfo.lineno);
|
2000-02-05 07:37:40 +00:00
|
|
|
|
putchar ('\n');
|
1991-10-07 22:04:20 +00:00
|
|
|
|
fputs (prefix, stdout);
|
|
|
|
|
|
|
|
|
|
/* Is this a `define'? */
|
1999-10-15 07:00:58 +00:00
|
|
|
|
if (v->recursive && strchr (v->value, '\n') != 0)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
printf ("define %s\n%s\nendef\n", v->name, v->value);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
register char *p;
|
|
|
|
|
|
1999-12-18 17:43:47 +00:00
|
|
|
|
printf ("%s %s= ", v->name, v->recursive ? v->append ? "+" : "" : ":");
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
|
|
|
|
/* Check if the value is just whitespace. */
|
|
|
|
|
p = next_token (v->value);
|
|
|
|
|
if (p != v->value && *p == '\0')
|
|
|
|
|
/* All whitespace. */
|
|
|
|
|
printf ("$(subst ,,%s)", v->value);
|
|
|
|
|
else if (v->recursive)
|
|
|
|
|
fputs (v->value, stdout);
|
|
|
|
|
else
|
|
|
|
|
/* Double up dollar signs. */
|
|
|
|
|
for (p = v->value; *p != '\0'; ++p)
|
|
|
|
|
{
|
|
|
|
|
if (*p == '$')
|
|
|
|
|
putchar ('$');
|
|
|
|
|
putchar (*p);
|
|
|
|
|
}
|
|
|
|
|
putchar ('\n');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Print all the variables in SET. PREFIX is printed before
|
|
|
|
|
the actual variable definitions (everything else is comments). */
|
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
print_variable_set (struct variable_set *set, char *prefix)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
2002-07-11 06:38:57 +00:00
|
|
|
|
hash_map_arg (&set->table, print_variable, prefix);
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
2002-07-11 06:38:57 +00:00
|
|
|
|
fputs (_("# variable set hash-table stats:\n"), stdout);
|
|
|
|
|
fputs ("# ", stdout);
|
|
|
|
|
hash_print_stats (&set->table, stdout);
|
|
|
|
|
putc ('\n', stdout);
|
1991-10-07 22:04:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print the data base of variables. */
|
|
|
|
|
|
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
print_variable_data_base (void)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
1999-07-28 06:23:37 +00:00
|
|
|
|
puts (_("\n# Variables\n"));
|
1991-10-07 22:04:20 +00:00
|
|
|
|
|
|
|
|
|
print_variable_set (&global_variable_set, "");
|
2003-05-02 01:44:59 +00:00
|
|
|
|
|
|
|
|
|
puts (_("\n# Pattern-specific Variable Values"));
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
struct pattern_var *p;
|
|
|
|
|
int rules = 0;
|
|
|
|
|
|
|
|
|
|
for (p = pattern_vars; p != 0; p = p->next)
|
|
|
|
|
{
|
|
|
|
|
++rules;
|
|
|
|
|
printf ("\n%s :\n", p->target);
|
|
|
|
|
print_variable (&p->variable, "# ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rules == 0)
|
|
|
|
|
puts (_("\n# No pattern-specific variable values."));
|
|
|
|
|
else
|
|
|
|
|
printf (_("\n# %u pattern-specific variable values"), rules);
|
|
|
|
|
}
|
1991-10-07 22:04:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Print all the local variables of FILE. */
|
|
|
|
|
|
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
print_file_variables (struct file *file)
|
1991-10-07 22:04:20 +00:00
|
|
|
|
{
|
|
|
|
|
if (file->variables != 0)
|
|
|
|
|
print_variable_set (file->variables->set, "# ");
|
|
|
|
|
}
|
1996-05-22 21:51:45 +00:00
|
|
|
|
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-22 21:51:45 +00:00
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
sync_Path_environment (void)
|
1996-05-22 21:51:45 +00:00
|
|
|
|
{
|
2005-04-08 12:51:20 +00:00
|
|
|
|
char *path = allocated_variable_expand ("$(PATH)");
|
2002-10-14 21:54:04 +00:00
|
|
|
|
static char *environ_path = NULL;
|
|
|
|
|
|
|
|
|
|
if (!path)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If done this before, don't leak memory unnecessarily.
|
|
|
|
|
* Free the previous entry before allocating new one.
|
|
|
|
|
*/
|
|
|
|
|
if (environ_path)
|
|
|
|
|
free (environ_path);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Create something WINDOWS32 world can grok
|
|
|
|
|
*/
|
|
|
|
|
convert_Path_to_windows32 (path, ';');
|
2005-04-08 12:51:20 +00:00
|
|
|
|
environ_path = concat ("PATH", "=", path);
|
2002-10-14 21:54:04 +00:00
|
|
|
|
putenv (environ_path);
|
|
|
|
|
free (path);
|
1996-05-22 21:51:45 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|