Ignore:
Timestamp:
Jun 20, 2012, 12:44:52 AM (13 years ago)
Author:
bird
Message:

gnumake/current -> 3.82-cvs.

Location:
vendor/gnumake/current
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current

    • Property svn:ignore deleted
  • vendor/gnumake/current/variable.c

    r1989 r2596  
    11/* Internals of variables for GNU Make.
    22Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
    4 Foundation, Inc.
     31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
     42010 Free Software Foundation, Inc.
    55This file is part of GNU Make.
    66
     
    3636static struct pattern_var *pattern_vars;
    3737
    38 /* Pointer to last struct in the chain, so we can add onto the end.  */
    39 
    40 static struct pattern_var *last_pattern_var;
    41 
    42 /* Create a new pattern-specific variable struct.  */
     38/* Pointer to the last struct in the pack of a specific size, from 1 to 255.*/
     39
     40static struct pattern_var *last_pattern_vars[256];
     41
     42/* Create a new pattern-specific variable struct. The new variable is
     43   inserted into the PATTERN_VARS list in the shortest patterns first
     44   order to support the shortest stem matching (the variables are
     45   matched in the reverse order so the ones with the longest pattern
     46   will be considered first). Variables with the same pattern length
     47   are inserted in the definition order. */
    4348
    4449struct pattern_var *
    4550create_pattern_var (const char *target, const char *suffix)
    4651{
     52  register unsigned int len = strlen (target);
    4753  register struct pattern_var *p = xmalloc (sizeof (struct pattern_var));
    4854
    49   if (last_pattern_var != 0)
    50     last_pattern_var->next = p;
     55  if (pattern_vars != 0)
     56    {
     57      if (len < 256 && last_pattern_vars[len] != 0)
     58        {
     59          p->next = last_pattern_vars[len]->next;
     60          last_pattern_vars[len]->next = p;
     61        }
     62      else
     63        {
     64          /* Find the position where we can insert this variable. */
     65          register struct pattern_var **v;
     66
     67          for (v = &pattern_vars; ; v = &(*v)->next)
     68            {
     69              /* Insert at the end of the pack so that patterns with the
     70                 same length appear in the order they were defined .*/
     71
     72              if (*v == 0 || (*v)->len > len)
     73                {
     74                  p->next = *v;
     75                  *v = p;
     76                  break;
     77                }
     78            }
     79        }
     80    }
    5181  else
    52     pattern_vars = p;
    53   last_pattern_var = p;
    54   p->next = 0;
     82    {
     83      pattern_vars = p;
     84      p->next = 0;
     85    }
    5586
    5687  p->target = target;
    57   p->len = strlen (target);
     88  p->len = len;
    5889  p->suffix = suffix + 1;
     90
     91  if (len < 256)
     92    last_pattern_vars[len] = p;
    5993
    6094  return p;
     
    140174static struct variable_set global_variable_set;
    141175static struct variable_set_list global_setlist
    142   = { 0, &global_variable_set };
     176  = { 0, &global_variable_set, 0 };
    143177struct variable_set_list *current_variable_set_list = &global_setlist;
    144178
     
    209243
    210244  v = xmalloc (sizeof (struct variable));
    211   v->name = savestring (name, length);
     245  v->name = xstrndup (name, length);
    212246  v->length = length;
    213247  hash_insert_at (&set->table, v, var_slot);
     
    224258  v->per_target = 0;
    225259  v->append = 0;
     260  v->private_var = 0;
    226261  v->export = v_default;
    227262
     
    244279}
    245280
     281
     282
     283/* Undefine variable named NAME in SET. LENGTH is the length of NAME, which
     284   does not need to be null-terminated. ORIGIN specifies the origin of the
     285   variable (makefile, command line or environment). */
     286
     287static void
     288free_variable_name_and_value (const void *item);
     289
     290void
     291undefine_variable_in_set (const char *name, unsigned int length,
     292                          enum variable_origin origin,
     293                          struct variable_set *set)
     294{
     295  struct variable *v;
     296  struct variable **var_slot;
     297  struct variable var_key;
     298
     299  if (set == NULL)
     300    set = &global_variable_set;
     301
     302  var_key.name = (char *) name;
     303  var_key.length = length;
     304  var_slot = (struct variable **) hash_find_slot (&set->table, &var_key);
     305
     306  if (env_overrides && origin == o_env)
     307    origin = o_env_override;
     308
     309  v = *var_slot;
     310  if (! HASH_VACANT (v))
     311    {
     312      if (env_overrides && v->origin == o_env)
     313        /* V came from in the environment.  Since it was defined
     314           before the switches were parsed, it wasn't affected by -e.  */
     315        v->origin = o_env_override;
     316
     317      /* If the definition is from a stronger source than this one, don't
     318         undefine it.  */
     319      if ((int) origin >= (int) v->origin)
     320        {
     321          hash_delete_at (&set->table, var_slot);
     322          free_variable_name_and_value (v);
     323        }
     324    }
     325}
    246326
    247327/* If the variable passed in is "special", handle its special nature.
     
    345425  const struct variable_set_list *setlist;
    346426  struct variable var_key;
     427  int is_parent = 0;
    347428
    348429  var_key.name = (char *) name;
     
    356437
    357438      v = (struct variable *) hash_find_item ((struct hash_table *) &set->table, &var_key);
    358       if (v)
     439      if (v && (!is_parent || !v->private_var))
    359440        return v->special ? lookup_special_var (v) : v;
     441
     442      is_parent |= setlist->next_is_parent;
    360443    }
    361444
     
    470553      initialize_file_variables (file->double_colon, reading);
    471554      l->next = file->double_colon->variables;
     555      l->next_is_parent = 0;
    472556      return;
    473557    }
     
    480564      l->next = file->parent->variables;
    481565    }
     566  l->next_is_parent = 1;
    482567
    483568  /* If we're not reading makefiles and we haven't looked yet, see if
     
    525610              v->per_target = p->variable.per_target;
    526611              v->export = p->variable.export;
     612              v->private_var = p->variable.private_var;
    527613            }
    528614          while ((p = lookup_pattern_var (p, file->name)) != 0);
     
    538624    {
    539625      file->pat_variables->next = l->next;
     626      file->pat_variables->next_is_parent = l->next_is_parent;
    540627      l->next = file->pat_variables;
     628      l->next_is_parent = 0;
    541629    }
    542630}
     
    560648  setlist->set = set;
    561649  setlist->next = current_variable_set_list;
     650  setlist->next_is_parent = 0;
    562651
    563652  return setlist;
     
    631720      global_setlist.set = setlist->set;
    632721      global_setlist.next = setlist->next;
     722      global_setlist.next_is_parent = setlist->next_is_parent;
    633723    }
    634724
     
    719809
    720810  sprintf (buf, "%u", makelevel);
    721   (void) define_variable (MAKELEVEL_NAME, MAKELEVEL_LENGTH, buf, o_env, 0);
     811  define_variable_cname (MAKELEVEL_NAME, buf, o_env, 0);
    722812
    723813  sprintf (buf, "%s%s%s",
     
    727817           (remote_description == 0 || remote_description[0] == '\0')
    728818           ? "" : remote_description);
    729   (void) define_variable ("MAKE_VERSION", 12, buf, o_default, 0);
     819  define_variable_cname ("MAKE_VERSION", buf, o_default, 0);
    730820
    731821#ifdef  __MSDOS__
     
    738828    struct variable *comp = lookup_variable ("COMSPEC", 7);
    739829
    740     /* Make $MAKESHELL override $SHELL even if -e is in effect.  */
     830    /* $(MAKESHELL) overrides $(SHELL) even if -e is in effect.  */
    741831    if (mshp)
    742832      (void) define_variable (shell_str, shlen,
     
    744834    else if (comp)
    745835      {
    746         /* $COMSPEC shouldn't override $SHELL.  */
     836        /* $(COMSPEC) shouldn't override $(SHELL).  */
    747837        struct variable *shp = lookup_variable (shell_str, shlen);
    748838
     
    803893  /* This won't override any definition, but it will provide one if there
    804894     isn't one there.  */
    805   v = define_variable ("SHELL", 5, default_shell, o_default, 0);
     895  v = define_variable_cname ("SHELL", default_shell, o_default, 0);
    806896#ifdef __MSDOS__
    807897  v->export = v_export;  /*  Export always SHELL.  */
     
    823913
    824914  /* Make sure MAKEFILES gets exported if it is set.  */
    825   v = define_variable ("MAKEFILES", 9, "", o_default, 0);
     915  v = define_variable_cname ("MAKEFILES", "", o_default, 0);
    826916  v->export = v_ifset;
    827917
     
    830920
    831921#ifdef VMS
    832   define_variable ("@D", 2, "$(dir $@)", o_automatic, 1);
    833   define_variable ("%D", 2, "$(dir $%)", o_automatic, 1);
    834   define_variable ("*D", 2, "$(dir $*)", o_automatic, 1);
    835   define_variable ("<D", 2, "$(dir $<)", o_automatic, 1);
    836   define_variable ("?D", 2, "$(dir $?)", o_automatic, 1);
    837   define_variable ("^D", 2, "$(dir $^)", o_automatic, 1);
    838   define_variable ("+D", 2, "$(dir $+)", o_automatic, 1);
     922  define_variable_cname ("@D", "$(dir $@)", o_automatic, 1);
     923  define_variable_cname ("%D", "$(dir $%)", o_automatic, 1);
     924  define_variable_cname ("*D", "$(dir $*)", o_automatic, 1);
     925  define_variable_cname ("<D", "$(dir $<)", o_automatic, 1);
     926  define_variable_cname ("?D", "$(dir $?)", o_automatic, 1);
     927  define_variable_cname ("^D", "$(dir $^)", o_automatic, 1);
     928  define_variable_cname ("+D", "$(dir $+)", o_automatic, 1);
    839929#else
    840   define_variable ("@D", 2, "$(patsubst %/,%,$(dir $@))", o_automatic, 1);
    841   define_variable ("%D", 2, "$(patsubst %/,%,$(dir $%))", o_automatic, 1);
    842   define_variable ("*D", 2, "$(patsubst %/,%,$(dir $*))", o_automatic, 1);
    843   define_variable ("<D", 2, "$(patsubst %/,%,$(dir $<))", o_automatic, 1);
    844   define_variable ("?D", 2, "$(patsubst %/,%,$(dir $?))", o_automatic, 1);
    845   define_variable ("^D", 2, "$(patsubst %/,%,$(dir $^))", o_automatic, 1);
    846   define_variable ("+D", 2, "$(patsubst %/,%,$(dir $+))", o_automatic, 1);
     930  define_variable_cname ("@D", "$(patsubst %/,%,$(dir $@))", o_automatic, 1);
     931  define_variable_cname ("%D", "$(patsubst %/,%,$(dir $%))", o_automatic, 1);
     932  define_variable_cname ("*D", "$(patsubst %/,%,$(dir $*))", o_automatic, 1);
     933  define_variable_cname ("<D", "$(patsubst %/,%,$(dir $<))", o_automatic, 1);
     934  define_variable_cname ("?D", "$(patsubst %/,%,$(dir $?))", o_automatic, 1);
     935  define_variable_cname ("^D", "$(patsubst %/,%,$(dir $^))", o_automatic, 1);
     936  define_variable_cname ("+D", "$(patsubst %/,%,$(dir $+))", o_automatic, 1);
    847937#endif
    848   define_variable ("@F", 2, "$(notdir $@)", o_automatic, 1);
    849   define_variable ("%F", 2, "$(notdir $%)", o_automatic, 1);
    850   define_variable ("*F", 2, "$(notdir $*)", o_automatic, 1);
    851   define_variable ("<F", 2, "$(notdir $<)", o_automatic, 1);
    852   define_variable ("?F", 2, "$(notdir $?)", o_automatic, 1);
    853   define_variable ("^F", 2, "$(notdir $^)", o_automatic, 1);
    854   define_variable ("+F", 2, "$(notdir $+)", o_automatic, 1);
     938  define_variable_cname ("@F", "$(notdir $@)", o_automatic, 1);
     939  define_variable_cname ("%F", "$(notdir $%)", o_automatic, 1);
     940  define_variable_cname ("*F", "$(notdir $*)", o_automatic, 1);
     941  define_variable_cname ("<F", "$(notdir $<)", o_automatic, 1);
     942  define_variable_cname ("?F", "$(notdir $?)", o_automatic, 1);
     943  define_variable_cname ("^F", "$(notdir $^)", o_automatic, 1);
     944  define_variable_cname ("+F", "$(notdir $+)", o_automatic, 1);
    855945}
    856946
     
    9791069              convert_Path_to_windows32(value, ';');
    9801070#endif
    981             *result++ = xstrdup (concat (v->name, "=", value));
     1071            *result++ = xstrdup (concat (3, v->name, "=", value));
    9821072            free (value);
    9831073          }
     
    9891079              convert_Path_to_windows32(v->value, ';');
    9901080#endif
    991             *result++ = xstrdup (concat (v->name, "=", v->value));
     1081            *result++ = xstrdup (concat (3, v->name, "=", v->value));
    9921082          }
    9931083      }
     
    10931183            unsigned int oldlen, vallen;
    10941184            const char *val;
    1095             char *tp;
     1185            char *tp = NULL;
    10961186
    10971187            val = value;
     
    11061196                 memory for the expansion as we may still need the rest of the
    11071197                 buffer if we're looking at a target-specific variable.  */
    1108               val = alloc_value = allocated_variable_expand (val);
     1198              val = tp = allocated_variable_expand (val);
    11091199
    11101200            oldlen = strlen (v->value);
    11111201            vallen = strlen (val);
    1112             tp = alloca (oldlen + 1 + vallen + 1);
    1113             memcpy (tp, v->value, oldlen);
    1114             tp[oldlen] = ' ';
    1115             memcpy (&tp[oldlen + 1], val, vallen + 1);
    1116             p = tp;
     1202            p = alloc_value = xmalloc (oldlen + 1 + vallen + 1);
     1203            memcpy (alloc_value, v->value, oldlen);
     1204            alloc_value[oldlen] = ' ';
     1205            memcpy (&alloc_value[oldlen + 1], val, vallen + 1);
     1206
     1207            if (tp)
     1208              free (tp);
    11171209          }
    11181210      }
     
    12221314      else
    12231315        {
    1224           if (alloc_value)
    1225             free (alloc_value);
     1316          char *tp = alloc_value;
    12261317
    12271318          alloc_value = allocated_variable_expand (p);
     1319
    12281320          if (find_and_set_default_shell (alloc_value))
    12291321            {
     
    12381330          else
    12391331            v = lookup_variable (varname, strlen (varname));
     1332
     1333          if (tp)
     1334            free (tp);
    12401335        }
    12411336    }
     
    12641359
    12651360
    1266 /* Try to interpret LINE (a null-terminated string) as a variable definition.
    1267 
    1268    ORIGIN may be o_file, o_override, o_env, o_env_override,
    1269    or o_command specifying that the variable definition comes
    1270    from a makefile, an override directive, the environment with
    1271    or without the -e switch, or the command line.
    1272 
    1273    See the comments for parse_variable_definition().
    1274 
    1275    If LINE was recognized as a variable definition, a pointer to its `struct
    1276    variable' is returned.  If LINE is not a variable definition, NULL is
    1277    returned.  */
    1278 
    1279 struct variable *
    1280 parse_variable_definition (struct variable *v, char *line)
    1281 {
    1282   register int c;
    1283   register char *p = line;
    1284   register char *beg;
    1285   register char *end;
    1286   enum variable_flavor flavor = f_bogus;
    1287   char *name;
     1361/* Parse P (a null-terminated string) as a variable definition.
     1362
     1363   If it is not a variable definition, return NULL.
     1364
     1365   If it is a variable definition, return a pointer to the char after the
     1366   assignment token and set *FLAVOR to the type of variable assignment.  */
     1367
     1368char *
     1369parse_variable_definition (const char *p, enum variable_flavor *flavor)
     1370{
     1371  int wspace = 0;
     1372
     1373  p = next_token (p);
    12881374
    12891375  while (1)
    12901376    {
    1291       c = *p++;
     1377      int c = *p++;
     1378
     1379      /* If we find a comment or EOS, it's not a variable definition.  */
    12921380      if (c == '\0' || c == '#')
    1293         return 0;
    1294       if (c == '=')
     1381        return NULL;
     1382
     1383      if (c == '$')
    12951384        {
    1296           end = p - 1;
    1297           flavor = f_recursive;
    1298           break;
    1299         }
    1300       else if (c == ':')
    1301         if (*p == '=')
    1302           {
    1303             end = p++ - 1;
    1304             flavor = f_simple;
    1305             break;
    1306           }
    1307         else
    1308           /* A colon other than := is a rule line, not a variable defn.  */
    1309           return 0;
    1310       else if (c == '+' && *p == '=')
    1311         {
    1312           end = p++ - 1;
    1313           flavor = f_append;
    1314           break;
    1315         }
    1316       else if (c == '?' && *p == '=')
    1317         {
    1318           end = p++ - 1;
    1319           flavor = f_conditional;
    1320           break;
    1321         }
    1322       else if (c == '$')
    1323         {
    1324           /* This might begin a variable expansion reference.  Make sure we
    1325              don't misrecognize chars inside the reference as =, := or +=.  */
     1385          /* This begins a variable expansion reference.  Make sure we don't
     1386             treat chars inside the reference as assignment tokens.  */
    13261387          char closeparen;
    13271388          int count;
     
    13321393            closeparen = '}';
    13331394          else
    1334             continue;           /* Nope.  */
     1395            /* '$$' or '$X'.  Either way, nothing special to do here.  */
     1396            continue;
    13351397
    13361398          /* P now points past the opening paren or brace.
     
    13471409                }
    13481410            }
     1411          continue;
    13491412        }
    1350     }
    1351   v->flavor = flavor;
     1413
     1414      /* If we find whitespace skip it, and remember we found it.  */
     1415      if (isblank ((unsigned char)c))
     1416        {
     1417          wspace = 1;
     1418          p = next_token (p);
     1419          c = *p;
     1420          if (c == '\0')
     1421            return NULL;
     1422          ++p;
     1423        }
     1424
     1425
     1426      if (c == '=')
     1427        {
     1428          *flavor = f_recursive;
     1429          return (char *)p;
     1430        }
     1431
     1432      /* Match assignment variants (:=, +=, ?=)  */
     1433      if (*p == '=')
     1434        {
     1435          switch (c)
     1436            {
     1437              case ':':
     1438                *flavor = f_simple;
     1439                break;
     1440              case '+':
     1441                *flavor = f_append;
     1442                break;
     1443              case '?':
     1444                *flavor = f_conditional;
     1445                break;
     1446              default:
     1447                /* If we skipped whitespace, non-assignments means no var.  */
     1448                if (wspace)
     1449                  return NULL;
     1450
     1451                /* Might be assignment, or might be $= or #=.  Check.  */
     1452                continue;
     1453            }
     1454          return (char *)++p;
     1455        }
     1456      else if (c == ':')
     1457        /* A colon other than := is a rule line, not a variable defn.  */
     1458        return NULL;
     1459
     1460      /* If we skipped whitespace, non-assignments means no var.  */
     1461      if (wspace)
     1462        return NULL;
     1463    }
     1464
     1465  return (char *)p;
     1466}
     1467
     1468
     1469/* Try to interpret LINE (a null-terminated string) as a variable definition.
     1470
     1471   If LINE was recognized as a variable definition, a pointer to its `struct
     1472   variable' is returned.  If LINE is not a variable definition, NULL is
     1473   returned.  */
     1474
     1475struct variable *
     1476assign_variable_definition (struct variable *v, char *line)
     1477{
     1478  char *beg;
     1479  char *end;
     1480  enum variable_flavor flavor;
     1481  char *name;
    13521482
    13531483  beg = next_token (line);
     1484  line = parse_variable_definition (beg, &flavor);
     1485  if (!line)
     1486    return NULL;
     1487
     1488  end = line - (flavor == f_recursive ? 1 : 2);
    13541489  while (end > beg && isblank ((unsigned char)end[-1]))
    13551490    --end;
    1356   p = next_token (p);
    1357   v->value = p;
     1491  line = next_token (line);
     1492  v->value = line;
     1493  v->flavor = flavor;
    13581494
    13591495  /* Expand the name, so "$(foo)bar = baz" works.  */
     
    13771513   or without the -e switch, or the command line.
    13781514
    1379    See the comments for parse_variable_definition().
     1515   See the comments for assign_variable_definition().
    13801516
    13811517   If LINE was recognized as a variable definition, a pointer to its `struct
     
    13951531    v.fileinfo.filenm = 0;
    13961532
    1397   if (!parse_variable_definition (&v, line))
     1533  if (!assign_variable_definition (&v, line))
    13981534    return 0;
    13991535
     
    14451581  fputs ("# ", stdout);
    14461582  fputs (origin, stdout);
     1583  if (v->private_var)
     1584    fputs (" private", stdout);
    14471585  if (v->fileinfo.filenm)
    14481586    printf (_(" (from `%s', line %lu)"),
     
    14561594  else
    14571595    {
    1458       register char *p;
     1596      char *p;
    14591597
    14601598      printf ("%s %s= ", v->name, v->recursive ? v->append ? "+" : "" : ":");
     
    15541692   */
    15551693  convert_Path_to_windows32 (path, ';');
    1556   environ_path = xstrdup (concat ("PATH", "=", path));
     1694  environ_path = xstrdup (concat (3, "PATH", "=", path));
    15571695  putenv (environ_path);
    15581696  free (path);
Note: See TracChangeset for help on using the changeset viewer.