Ignore:
Timestamp:
Jun 17, 2012, 10:45:31 PM (13 years ago)
Author:
bird
Message:

kmk: Merged in changes from GNU make 3.82. Previous GNU make base version was gnumake-2008-10-28-CVS.

Location:
trunk/src/kmk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk

    • Property svn:ignore
      •  

        old new  
        1313stamp-*
        1414makebook*
         15
        1516.*gdbinit
         17.gdb_history
         18
        1619*.dep
        1720*.dvi
         
        3134*.pg
        3235*.pgs
         36
        3337README
        3438README.DOS
        3539README.W32
         40README.OS2
        3641aclocal.m4
        3742autom4te.cache
         
        5257config.h.W32
        5358config.h-vms
         59
        5460loadavg
        5561loadavg.c
        5662make
         63
        5764.deps
        5865.dep_segment
         66ID
         67TAGS
         68
        5969_*
        6070sun4
         
        7282sol2
        7383i486-linux
         84
        7485customs
         86
        7587install-sh
        7688mkinstalldirs
         89
         90.directive.asc
  • trunk/src/kmk/variable.c

    r2554 r2591  
    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
     
    4747static struct pattern_var *pattern_vars;
    4848
    49 /* Pointer to last struct in the chain, so we can add onto the end.  */
    50 
    51 static struct pattern_var *last_pattern_var;
    52 
    53 /* Create a new pattern-specific variable struct.  */
     49/* Pointer to the last struct in the pack of a specific size, from 1 to 255.*/
     50
     51static struct pattern_var *last_pattern_vars[256];
     52
     53/* Create a new pattern-specific variable struct. The new variable is
     54   inserted into the PATTERN_VARS list in the shortest patterns first
     55   order to support the shortest stem matching (the variables are
     56   matched in the reverse order so the ones with the longest pattern
     57   will be considered first). Variables with the same pattern length
     58   are inserted in the definition order. */
    5459
    5560struct pattern_var *
    5661create_pattern_var (const char *target, const char *suffix)
    5762{
     63  register unsigned int len = strlen (target);
    5864  register struct pattern_var *p = xmalloc (sizeof (struct pattern_var));
    5965
    60   if (last_pattern_var != 0)
    61     last_pattern_var->next = p;
     66  if (pattern_vars != 0)
     67    {
     68      if (len < 256 && last_pattern_vars[len] != 0)
     69        {
     70          p->next = last_pattern_vars[len]->next;
     71          last_pattern_vars[len]->next = p;
     72        }
     73      else
     74        {
     75          /* Find the position where we can insert this variable. */
     76          register struct pattern_var **v;
     77
     78          for (v = &pattern_vars; ; v = &(*v)->next)
     79            {
     80              /* Insert at the end of the pack so that patterns with the
     81                 same length appear in the order they were defined .*/
     82
     83              if (*v == 0 || (*v)->len > len)
     84                {
     85                  p->next = *v;
     86                  *v = p;
     87                  break;
     88                }
     89            }
     90        }
     91    }
    6292  else
    63     pattern_vars = p;
    64   last_pattern_var = p;
    65   p->next = 0;
     93    {
     94      pattern_vars = p;
     95      p->next = 0;
     96    }
    6697
    6798  p->target = target;
    68   p->len = strlen (target);
     99  p->len = len;
    69100  p->suffix = suffix + 1;
     101
     102  if (len < 256)
     103    last_pattern_vars[len] = p;
    70104
    71105  return p;
     
    170204static struct variable_set global_variable_set;
    171205static struct variable_set_list global_setlist
    172   = { 0, &global_variable_set };
     206  = { 0, &global_variable_set, 0 };
    173207struct variable_set_list *current_variable_set_list = &global_setlist;
    174208
     
    344378#endif
    345379#ifndef CONFIG_WITH_STRCACHE2
    346   v->name = savestring (name, length);
     380  v->name = xstrndup (name, length);
    347381#else
    348382  v->name = name; /* already cached. */
     
    387421  v->per_target = 0;
    388422  v->append = 0;
     423  v->private_var = 0;
    389424  v->export = v_default;
    390425  MAKE_STATS_2(v->changes = 0);
     
    414449}
    415450
     451
     452
     453/* Undefine variable named NAME in SET. LENGTH is the length of NAME, which
     454   does not need to be null-terminated. ORIGIN specifies the origin of the
     455   variable (makefile, command line or environment). */
     456
     457static void
     458free_variable_name_and_value (const void *item);
     459
     460void
     461undefine_variable_in_set (const char *name, unsigned int length,
     462                          enum variable_origin origin,
     463                          struct variable_set *set)
     464{
     465  struct variable *v;
     466  struct variable **var_slot;
     467  struct variable var_key;
     468
     469  if (set == NULL)
     470    set = &global_variable_set;
     471
     472  var_key.name = (char *) name;
     473  var_key.length = length;
     474  var_slot = (struct variable **) hash_find_slot (&set->table, &var_key);
     475
     476  if (env_overrides && origin == o_env)
     477    origin = o_env_override;
     478
     479  v = *var_slot;
     480  if (! HASH_VACANT (v))
     481    {
     482      if (env_overrides && v->origin == o_env)
     483        /* V came from in the environment.  Since it was defined
     484           before the switches were parsed, it wasn't affected by -e.  */
     485        v->origin = o_env_override;
     486
     487      /* If the definition is from a stronger source than this one, don't
     488         undefine it.  */
     489      if ((int) origin >= (int) v->origin)
     490        {
     491          hash_delete_at (&set->table, var_slot);
     492          free_variable_name_and_value (v);
     493        }
     494    }
     495}
    416496
    417497/* If the variable passed in is "special", handle its special nature.
     
    515595
    516596
    517 #ifdef KMK /* bird: speed */
     597#if 0 /*FIX THIS - def KMK*/ /* bird: speed */
    518598MY_INLINE struct variable *
    519599lookup_cached_variable (const char *name)
     
    646726lookup_variable (const char *name, unsigned int length)
    647727{
    648 #ifndef KMK
     728#if 1 /*FIX THIS - ndef KMK*/
    649729  const struct variable_set_list *setlist;
    650730  struct variable var_key;
     
    652732  struct variable *v;
    653733#endif /* KMK */
     734  int is_parent = 0;
    654735#ifdef CONFIG_WITH_STRCACHE2
    655736  const char *cached_name;
     
    662743  name = cached_name;
    663744#endif /* CONFIG_WITH_STRCACHE2 */
    664 #ifndef KMK
     745#if 1  /*FIX THIS - ndef KMK */
    665746
    666747  var_key.name = (char *) name;
     
    678759      v = (struct variable *) hash_find_item_strcached ((struct hash_table *) &set->table, &var_key);
    679760# endif /* CONFIG_WITH_STRCACHE2 */
    680       if (v)
     761      if (v && (!is_parent || !v->private_var))
    681762        return v->special ? lookup_special_var (v) : v;
     763
     764      is_parent |= setlist->next_is_parent;
    682765    }
    683766
     
    747830#endif /* VMS */
    748831
    749 #if !defined (KMK) || defined(VMS)
    750832  return 0;
    751 #endif
    752833}
    753834
     
    838919      initialize_file_variables (file->double_colon, reading);
    839920      l->next = file->double_colon->variables;
     921      l->next_is_parent = 0;
    840922      return;
    841923    }
     
    848930      l->next = file->parent->variables;
    849931    }
     932  l->next_is_parent = 1;
    850933
    851934  /* If we're not reading makefiles and we haven't looked yet, see if
     
    900983              v->per_target = p->variable.per_target;
    901984              v->export = p->variable.export;
     985              v->private_var = p->variable.private_var;
    902986            }
    903987          while ((p = lookup_pattern_var (p, file->name)) != 0);
     
    913997    {
    914998      file->pat_variables->next = l->next;
     999      file->pat_variables->next_is_parent = l->next_is_parent;
    9151000      l->next = file->pat_variables;
     1001      l->next_is_parent = 0;
    9161002    }
    9171003}
     
    9491035  setlist->set = set;
    9501036  setlist->next = current_variable_set_list;
     1037  setlist->next_is_parent = 0;
    9511038
    9521039  return setlist;
     
    10311118      global_setlist.set = setlist->set;
    10321119      global_setlist.next = setlist->next;
     1120      global_setlist.next_is_parent = setlist->next_is_parent;
    10331121    }
    10341122
     
    11691257
    11701258  sprintf (buf, "%u", makelevel);
    1171   (void) define_variable (MAKELEVEL_NAME, MAKELEVEL_LENGTH, buf, o_env, 0);
     1259  define_variable_cname (MAKELEVEL_NAME, buf, o_env, 0);
    11721260
    11731261  sprintf (buf, "%s%s%s",
     
    11781266           ? "" : remote_description);
    11791267#ifndef KMK
    1180   (void) define_variable ("MAKE_VERSION", 12, buf, o_default, 0);
     1268  define_variable_cname ("MAKE_VERSION", buf, o_default, 0);
    11811269#else /* KMK */
    11821270
    11831271  /* Define KMK_VERSION to indicate kMk. */
    1184   (void) define_variable ("KMK_VERSION", 11, buf, o_default, 0);
     1272  define_variable_cname ("KMK_VERSION", buf, o_default, 0);
    11851273
    11861274  /* Define KBUILD_VERSION* */
    11871275  sprintf (buf, "%d", KBUILD_VERSION_MAJOR);
    1188   define_variable ("KBUILD_VERSION_MAJOR", sizeof ("KBUILD_VERSION_MAJOR") - 1,
    1189                    buf, o_default, 0);
     1276  define_variable_cname ("KBUILD_VERSION_MAJOR", buf, o_default, 0);
    11901277  sprintf (buf, "%d", KBUILD_VERSION_MINOR);
    1191   define_variable ("KBUILD_VERSION_MINOR", sizeof("KBUILD_VERSION_MINOR") - 1,
    1192                    buf, o_default, 0);
     1278  define_variable_cname ("KBUILD_VERSION_MINOR", buf, o_default, 0);
    11931279  sprintf (buf, "%d", KBUILD_VERSION_PATCH);
    1194   define_variable ("KBUILD_VERSION_PATCH", sizeof ("KBUILD_VERSION_PATCH") - 1,
    1195                    buf, o_default, 0);
     1280  define_variable_cname ("KBUILD_VERSION_PATCH", buf, o_default, 0);
    11961281  sprintf (buf, "%d", KBUILD_SVN_REV);
    1197   define_variable ("KBUILD_KMK_REVISION", sizeof ("KBUILD_KMK_REVISION") - 1,
    1198                    buf, o_default, 0);
     1282  define_variable_cname ("KBUILD_KMK_REVISION", buf, o_default, 0);
    11991283
    12001284  sprintf (buf, "%d.%d.%d-r%d", KBUILD_VERSION_MAJOR, KBUILD_VERSION_MINOR,
    12011285           KBUILD_VERSION_PATCH, KBUILD_SVN_REV);
    1202   define_variable ("KBUILD_VERSION", sizeof ("KBUILD_VERSION") - 1,
    1203                    buf, o_default, 0);
     1286  define_variable_cname ("KBUILD_VERSION", buf, o_default, 0);
    12041287
    12051288  /* The host defaults. The BUILD_* stuff will be replaced by KBUILD_* soon. */
     
    12101293    error (NULL, _("KBUILD_HOST and BUILD_PLATFORM differs, using KBUILD_HOST=%s."), val);
    12111294  if (!envvar1)
    1212     define_variable ("KBUILD_HOST", sizeof ("KBUILD_HOST") - 1,
    1213                      val, o_default, 0);
     1295    define_variable_cname ("KBUILD_HOST", val, o_default, 0);
    12141296  if (!envvar2)
    1215     define_variable ("BUILD_PLATFORM", sizeof ("BUILD_PLATFORM") - 1,
    1216                      val, o_default, 0);
     1297    define_variable_cname ("BUILD_PLATFORM", val, o_default, 0);
    12171298
    12181299  envvar1 = lookup_variable (STRING_SIZE_TUPLE ("KBUILD_HOST_ARCH"));
     
    12221303    error (NULL, _("KBUILD_HOST_ARCH and BUILD_PLATFORM_ARCH differs, using KBUILD_HOST_ARCH=%s."), val);
    12231304  if (!envvar1)
    1224     define_variable ("KBUILD_HOST_ARCH", sizeof ("KBUILD_HOST_ARCH") - 1,
    1225                      val, o_default, 0);
     1305    define_variable_cname ("KBUILD_HOST_ARCH", val, o_default, 0);
    12261306  if (!envvar2)
    1227     define_variable ("BUILD_PLATFORM_ARCH", sizeof ("BUILD_PLATFORM_ARCH") - 1,
    1228                      val, o_default, 0);
     1307    define_variable_cname ("BUILD_PLATFORM_ARCH", val, o_default, 0);
    12291308
    12301309  envvar1 = lookup_variable (STRING_SIZE_TUPLE ("KBUILD_HOST_CPU"));
     
    12341313    error (NULL, _("KBUILD_HOST_CPU and BUILD_PLATFORM_CPU differs, using KBUILD_HOST_CPU=%s."), val);
    12351314  if (!envvar1)
    1236     define_variable ("KBUILD_HOST_CPU", sizeof ("KBUILD_HOST_CPU") - 1,
    1237                      val, o_default, 0);
     1315    define_variable_cname ("KBUILD_HOST_CPU", val, o_default, 0);
    12381316  if (!envvar2)
    1239     define_variable ("BUILD_PLATFORM_CPU", sizeof ("BUILD_PLATFORM_CPU") - 1,
    1240                      val, o_default, 0);
     1317    define_variable_cname ("BUILD_PLATFORM_CPU", val, o_default, 0);
    12411318
    12421319  /* The host kernel version. */
     
    12771354
    12781355  sprintf (buf, "%lu.%lu.%lu.%lu", ulMajor, ulMinor, ulPatch, ul4th);
    1279   define_variable ("KBUILD_HOST_VERSION", sizeof ("KBUILD_HOST_VERSION") - 1,
    1280                    buf, o_default, 0);
     1356  define_variable_cname ("KBUILD_HOST_VERSION", buf, o_default, 0);
    12811357
    12821358  sprintf (buf, "%lu", ulMajor);
    1283   define_variable ("KBUILD_HOST_VERSION_MAJOR", sizeof ("KBUILD_HOST_VERSION_MAJOR") - 1,
    1284                    buf, o_default, 0);
     1359  define_variable_cname ("KBUILD_HOST_VERSION_MAJOR", buf, o_default, 0);
    12851360
    12861361  sprintf (buf, "%lu", ulMinor);
    1287   define_variable ("KBUILD_HOST_VERSION_MINOR", sizeof ("KBUILD_HOST_VERSION_MINOR") - 1,
    1288                    buf, o_default, 0);
     1362  define_variable_cname ("KBUILD_HOST_VERSION_MINOR", buf, o_default, 0);
    12891363
    12901364  sprintf (buf, "%lu", ulPatch);
    1291   define_variable ("KBUILD_HOST_VERSION_PATCH", sizeof ("KBUILD_HOST_VERSION_PATCH") - 1,
    1292                    buf, o_default, 0);
     1365  define_variable_cname ("KBUILD_HOST_VERSION_PATCH", buf, o_default, 0);
    12931366
    12941367  /* The kBuild locations. */
    1295   define_variable ("KBUILD_PATH", sizeof ("KBUILD_PATH") - 1,
    1296                    get_kbuild_path (), o_default, 0);
    1297   define_variable ("KBUILD_BIN_PATH", sizeof ("KBUILD_BIN_PATH") - 1,
    1298                    get_kbuild_bin_path (), o_default, 0);
    1299 
    1300   define_variable ("PATH_KBUILD", sizeof ("PATH_KBUILD") - 1,
    1301                    get_kbuild_path (), o_default, 0);
    1302   define_variable ("PATH_KBUILD_BIN", sizeof ("PATH_KBUILD_BIN") - 1,
    1303                    get_kbuild_bin_path (), o_default, 0);
     1368  define_variable_cname ("KBUILD_PATH", get_kbuild_path (), o_default, 0);
     1369  define_variable_cname ("KBUILD_BIN_PATH", get_kbuild_bin_path (), o_default, 0);
     1370
     1371  define_variable_cname ("PATH_KBUILD", get_kbuild_path (), o_default, 0);
     1372  define_variable_cname ("PATH_KBUILD_BIN", get_kbuild_bin_path (), o_default, 0);
    13041373
    13051374  /* Define KMK_FEATURES to indicate various working KMK features. */
     
    13301399  && defined (CONFIG_WITH_DEFINED_FUNCTIONS) \
    13311400  && defined (KMK_HELPERS)
    1332   (void) define_variable ("KMK_FEATURES", 12,
    1333                           "append-dash-n abspath includedep-queue install-hard-linking umask"
    1334                           " kBuild-define"
    1335                           " rsort"
    1336                           " abspathex"
    1337                           " toupper tolower"
    1338                           " defined"
    1339                           " comp-vars comp-cmds comp-cmds-ex"
    1340                           " stack"
    1341                           " math-int"
    1342                           " xargs"
    1343                           " explicit-multitarget"
    1344                           " dot-must-make"
    1345                           " prepend-assignment"
    1346                           " set-conditionals intersects"
    1347                           " date"
    1348                           " file-size"
    1349                           " expr if-expr select"
    1350                           " where"
    1351                           " which"
    1352                           " evalctx evalval evalvalctx evalcall evalcall2 eval-opt-var"
    1353                           " make-stats"
    1354                           " commands"
    1355                           " printf"
    1356                           " for while"
    1357                           " root"
    1358                           " length insert pos lastpos substr translate"
    1359                           " kb-src-tool kb-obj-base kb-obj-suff kb-src-prop kb-src-one kb-exp-tmpl"
    1360                           " firstdefined lastdefined"
    1361                           , o_default, 0);
     1401  define_variable_cname ("KMK_FEATURES",
     1402                         "append-dash-n abspath includedep-queue install-hard-linking umask"
     1403                         " kBuild-define"
     1404                         " rsort"
     1405                         " abspathex"
     1406                         " toupper tolower"
     1407                         " defined"
     1408                         " comp-vars comp-cmds comp-cmds-ex"
     1409                         " stack"
     1410                         " math-int"
     1411                         " xargs"
     1412                         " explicit-multitarget"
     1413                         " dot-must-make"
     1414                         " prepend-assignment"
     1415                         " set-conditionals intersects"
     1416                         " date"
     1417                         " file-size"
     1418                         " expr if-expr select"
     1419                         " where"
     1420                         " which"
     1421                         " evalctx evalval evalvalctx evalcall evalcall2 eval-opt-var"
     1422                         " make-stats"
     1423                         " commands"
     1424                         " printf"
     1425                         " for while"
     1426                         " root"
     1427                         " length insert pos lastpos substr translate"
     1428                         " kb-src-tool kb-obj-base kb-obj-suff kb-src-prop kb-src-one kb-exp-tmpl"
     1429                         " firstdefined lastdefined"
     1430                         , o_default, 0);
    13621431# else /* MSC can't deal with strings mixed with #if/#endif, thus the slow way. */
    13631432#  error "All features should be enabled by default!"
     
    14421511  strcat (buf, " kb-src-tool kb-obj-base kb-obj-suff kb-src-prop kb-src-one kb-exp-tmpl");
    14431512#  endif
    1444   (void) define_variable ("KMK_FEATURES", 12, buf, o_default, 0);
     1513  define_variable_cname ("KMK_FEATURES", buf, o_default, 0);
    14451514# endif
    14461515
     
    14491518#ifdef CONFIG_WITH_KMK_BUILTIN
    14501519  /* The supported kMk Builtin commands. */
    1451   (void) define_variable ("KMK_BUILTIN", 11, "append cat chmod cp cmp echo expr install kDepIDB ln md5sum mkdir mv printf rm rmdir sleep test", o_default, 0);
     1520  define_variable_cname ("KMK_BUILTIN", "append cat chmod cp cmp echo expr install kDepIDB ln md5sum mkdir mv printf rm rmdir sleep test", o_default, 0);
    14521521#endif
    14531522
     
    14611530    struct variable *comp = lookup_variable ("COMSPEC", 7);
    14621531
    1463     /* Make $MAKESHELL override $SHELL even if -e is in effect.  */
     1532    /* $(MAKESHELL) overrides $(SHELL) even if -e is in effect.  */
    14641533    if (mshp)
    14651534      (void) define_variable (shell_str, shlen,
     
    14671536    else if (comp)
    14681537      {
    1469         /* $COMSPEC shouldn't override $SHELL.  */
     1538        /* $(COMSPEC) shouldn't override $(SHELL).  */
    14701539        struct variable *shp = lookup_variable (shell_str, shlen);
    14711540
     
    15261595  /* This won't override any definition, but it will provide one if there
    15271596     isn't one there.  */
    1528   v = define_variable ("SHELL", 5, default_shell, o_default, 0);
     1597  v = define_variable_cname ("SHELL", default_shell, o_default, 0);
    15291598#ifdef __MSDOS__
    15301599  v->export = v_export;  /*  Export always SHELL.  */
     
    15551624
    15561625  /* Make sure MAKEFILES gets exported if it is set.  */
    1557   v = define_variable ("MAKEFILES", 9, "", o_default, 0);
     1626  v = define_variable_cname ("MAKEFILES", "", o_default, 0);
    15581627  v->export = v_ifset;
    15591628
     
    15621631
    15631632#ifdef VMS
    1564   define_variable ("@D", 2, "$(dir $@)", o_automatic, 1);
    1565   define_variable ("%D", 2, "$(dir $%)", o_automatic, 1);
    1566   define_variable ("*D", 2, "$(dir $*)", o_automatic, 1);
    1567   define_variable ("<D", 2, "$(dir $<)", o_automatic, 1);
    1568   define_variable ("?D", 2, "$(dir $?)", o_automatic, 1);
    1569   define_variable ("^D", 2, "$(dir $^)", o_automatic, 1);
    1570   define_variable ("+D", 2, "$(dir $+)", o_automatic, 1);
     1633  define_variable_cname ("@D", "$(dir $@)", o_automatic, 1);
     1634  define_variable_cname ("%D", "$(dir $%)", o_automatic, 1);
     1635  define_variable_cname ("*D", "$(dir $*)", o_automatic, 1);
     1636  define_variable_cname ("<D", "$(dir $<)", o_automatic, 1);
     1637  define_variable_cname ("?D", "$(dir $?)", o_automatic, 1);
     1638  define_variable_cname ("^D", "$(dir $^)", o_automatic, 1);
     1639  define_variable_cname ("+D", "$(dir $+)", o_automatic, 1);
    15711640#else
    1572   define_variable ("@D", 2, "$(patsubst %/,%,$(dir $@))", o_automatic, 1);
    1573   define_variable ("%D", 2, "$(patsubst %/,%,$(dir $%))", o_automatic, 1);
    1574   define_variable ("*D", 2, "$(patsubst %/,%,$(dir $*))", o_automatic, 1);
    1575   define_variable ("<D", 2, "$(patsubst %/,%,$(dir $<))", o_automatic, 1);
    1576   define_variable ("?D", 2, "$(patsubst %/,%,$(dir $?))", o_automatic, 1);
    1577   define_variable ("^D", 2, "$(patsubst %/,%,$(dir $^))", o_automatic, 1);
    1578   define_variable ("+D", 2, "$(patsubst %/,%,$(dir $+))", o_automatic, 1);
    1579 #endif
    1580   define_variable ("@F", 2, "$(notdir $@)", o_automatic, 1);
    1581   define_variable ("%F", 2, "$(notdir $%)", o_automatic, 1);
    1582   define_variable ("*F", 2, "$(notdir $*)", o_automatic, 1);
    1583   define_variable ("<F", 2, "$(notdir $<)", o_automatic, 1);
    1584   define_variable ("?F", 2, "$(notdir $?)", o_automatic, 1);
    1585   define_variable ("^F", 2, "$(notdir $^)", o_automatic, 1);
    1586   define_variable ("+F", 2, "$(notdir $+)", o_automatic, 1);
     1641  define_variable_cname ("@D", "$(patsubst %/,%,$(dir $@))", o_automatic, 1);
     1642  define_variable_cname ("%D", "$(patsubst %/,%,$(dir $%))", o_automatic, 1);
     1643  define_variable_cname ("*D", "$(patsubst %/,%,$(dir $*))", o_automatic, 1);
     1644  define_variable_cname ("<D", "$(patsubst %/,%,$(dir $<))", o_automatic, 1);
     1645  define_variable_cname ("?D", "$(patsubst %/,%,$(dir $?))", o_automatic, 1);
     1646  define_variable_cname ("^D", "$(patsubst %/,%,$(dir $^))", o_automatic, 1);
     1647  define_variable_cname ("+D", "$(patsubst %/,%,$(dir $+))", o_automatic, 1);
     1648#endif
     1649  define_variable_cname ("@F", "$(notdir $@)", o_automatic, 1);
     1650  define_variable_cname ("%F", "$(notdir $%)", o_automatic, 1);
     1651  define_variable_cname ("*F", "$(notdir $*)", o_automatic, 1);
     1652  define_variable_cname ("<F", "$(notdir $<)", o_automatic, 1);
     1653  define_variable_cname ("?F", "$(notdir $?)", o_automatic, 1);
     1654  define_variable_cname ("^F", "$(notdir $^)", o_automatic, 1);
     1655  define_variable_cname ("+F", "$(notdir $+)", o_automatic, 1);
    15871656#ifdef CONFIG_WITH_LAZY_DEPS_VARS
    15881657  define_variable ("^", 1, "$(deps $@)", o_automatic, 1);
     
    17531822              convert_Path_to_windows32(value, ';');
    17541823#endif
    1755             *result++ = xstrdup (concat (v->name, "=", value));
     1824            *result++ = xstrdup (concat (3, v->name, "=", value));
    17561825            free (value);
    17571826          }
     
    17631832              convert_Path_to_windows32(v->value, ';');
    17641833#endif
    1765             *result++ = xstrdup (concat (v->name, "=", v->value));
     1834            *result++ = xstrdup (concat (3, v->name, "=", v->value));
    17661835          }
    17671836      }
     
    19542023          value_len = strlen (value);
    19552024        if (!free_value)
    1956           p = alloc_value = savestring (value, value_len);
     2025          p = alloc_value = xstrndup (value, value_len);
    19572026        else
    19582027          {
     
    20482117            unsigned int oldlen, vallen;
    20492118            const char *val;
    2050             char *tp;
     2119            char *tp = NULL;
    20512120
    20522121            val = value;
     
    20612130                 memory for the expansion as we may still need the rest of the
    20622131                 buffer if we're looking at a target-specific variable.  */
    2063               val = alloc_value = allocated_variable_expand (val);
     2132              val = tp = allocated_variable_expand (val);
    20642133
    20652134            oldlen = strlen (v->value);
    20662135            vallen = strlen (val);
    2067             tp = alloca (oldlen + 1 + vallen + 1);
     2136            p = alloc_value = xmalloc (oldlen + 1 + vallen + 1);
    20682137# ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
    20692138            if (org_flavor == f_prepend)
    20702139              {
    2071                 memcpy (tp, val, vallen);
    2072                 tp[oldlen] = ' ';
    2073                 memcpy (&tp[oldlen + 1], v->value, oldlen + 1);
     2140                memcpy (alloc_value, val, vallen);
     2141                alloc_value[oldlen] = ' ';
     2142                memcpy (&alloc_value[oldlen + 1], v->value, oldlen + 1);
    20742143              }
    20752144            else
    20762145# endif /* CONFIG_WITH_PREPEND_ASSIGNMENT */
    20772146              {
    2078                 memcpy (tp, v->value, oldlen);
    2079                 tp[oldlen] = ' ';
    2080                 memcpy (&tp[oldlen + 1], val, vallen + 1);
     2147                memcpy (alloc_value, v->value, oldlen);
     2148                alloc_value[oldlen] = ' ';
     2149                memcpy (&alloc_value[oldlen + 1], val, vallen + 1);
    20812150              }
    2082             p = tp;
     2151
     2152            if (tp)
     2153              free (tp);
    20832154#endif /* !CONFIG_WITH_VALUE_LENGTH */
    20842155          }
     
    21932264      else
    21942265        {
    2195           if (alloc_value)
    2196             free (alloc_value);
     2266          char *tp = alloc_value;
    21972267
    21982268          alloc_value = allocated_variable_expand (p);
     2269
    21992270          if (find_and_set_default_shell (alloc_value))
    22002271            {
     
    22122283          else
    22132284            v = lookup_variable (varname, varname_len);
     2285
     2286          if (tp)
     2287            free (tp);
    22142288        }
    22152289    }
     
    22502324
    22512325
    2252 /* Try to interpret LINE (a null-terminated string) as a variable definition.
    2253 
    2254    ORIGIN may be o_file, o_override, o_env, o_env_override,
    2255    or o_command specifying that the variable definition comes
    2256    from a makefile, an override directive, the environment with
    2257    or without the -e switch, or the command line.
    2258 
    2259    See the comments for parse_variable_definition().
    2260 
    2261    If LINE was recognized as a variable definition, a pointer to its `struct
    2262    variable' is returned.  If LINE is not a variable definition, NULL is
    2263    returned.  */
    2264 
    2265 struct variable *
    2266 #ifndef CONFIG_WITH_VALUE_LENGTH
    2267 parse_variable_definition (struct variable *v, char *line)
    2268 #else
    2269 parse_variable_definition (struct variable *v, char *line, char *eos)
    2270 #endif
    2271 {
    2272   register int c;
    2273   register char *p = line;
    2274   register char *beg;
    2275   register char *end;
    2276   enum variable_flavor flavor = f_bogus;
    2277 #ifndef CONFIG_WITH_VALUE_LENGTH
    2278   char *name;
    2279 #endif
     2326/* Parse P (a null-terminated string) as a variable definition.
     2327
     2328   If it is not a variable definition, return NULL.
     2329
     2330   If it is a variable definition, return a pointer to the char after the
     2331   assignment token and set *FLAVOR to the type of variable assignment.  */
     2332
     2333char *
     2334parse_variable_definition (const char *p, enum variable_flavor *flavor)
     2335{
     2336  int wspace = 0;
     2337
     2338  p = next_token (p);
    22802339
    22812340  while (1)
    22822341    {
    2283       c = *p++;
     2342      int c = *p++;
     2343
     2344      /* If we find a comment or EOS, it's not a variable definition.  */
    22842345      if (c == '\0' || c == '#')
    2285         return 0;
    2286       if (c == '=')
     2346        return NULL;
     2347
     2348      if (c == '$')
    22872349        {
    2288           end = p - 1;
    2289           flavor = f_recursive;
    2290           break;
    2291         }
    2292       else if (c == ':')
    2293         if (*p == '=')
    2294           {
    2295             end = p++ - 1;
    2296             flavor = f_simple;
    2297             break;
    2298           }
    2299         else
    2300           /* A colon other than := is a rule line, not a variable defn.  */
    2301           return 0;
    2302       else if (c == '+' && *p == '=')
    2303         {
    2304           end = p++ - 1;
    2305           flavor = f_append;
    2306           break;
    2307         }
    2308 #ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
    2309       else if (c == '<' && *p == '=')
    2310         {
    2311           end = p++ - 1;
    2312           flavor = f_prepend;
    2313           break;
    2314         }
    2315 #endif
    2316       else if (c == '?' && *p == '=')
    2317         {
    2318           end = p++ - 1;
    2319           flavor = f_conditional;
    2320           break;
    2321         }
    2322       else if (c == '$')
    2323         {
    2324           /* This might begin a variable expansion reference.  Make sure we
    2325              don't misrecognize chars inside the reference as =, := or +=.  */
     2350          /* This begins a variable expansion reference.  Make sure we don't
     2351             treat chars inside the reference as assignment tokens.  */
    23262352          char closeparen;
    23272353          int count;
     
    23322358            closeparen = '}';
    23332359          else
    2334             continue;           /* Nope.  */
     2360            /* '$$' or '$X'.  Either way, nothing special to do here.  */
     2361            continue;
    23352362
    23362363          /* P now points past the opening paren or brace.
     
    23472374                }
    23482375            }
     2376          continue;
    23492377        }
    2350     }
    2351   v->flavor = flavor;
     2378
     2379      /* If we find whitespace skip it, and remember we found it.  */
     2380      if (isblank ((unsigned char)c))
     2381        {
     2382          wspace = 1;
     2383          p = next_token (p);
     2384          c = *p;
     2385          if (c == '\0')
     2386            return NULL;
     2387          ++p;
     2388        }
     2389
     2390
     2391      if (c == '=')
     2392        {
     2393          *flavor = f_recursive;
     2394          return (char *)p;
     2395        }
     2396
     2397      /* Match assignment variants (:=, +=, ?=)  */
     2398      if (*p == '=')
     2399        {
     2400          switch (c)
     2401            {
     2402              case ':':
     2403                *flavor = f_simple;
     2404                break;
     2405              case '+':
     2406                *flavor = f_append;
     2407                break;
     2408#ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
     2409              case '<':
     2410               *flavor = f_prepend;
     2411                break;
     2412#endif
     2413              case '?':
     2414                *flavor = f_conditional;
     2415                break;
     2416              default:
     2417                /* If we skipped whitespace, non-assignments means no var.  */
     2418                if (wspace)
     2419                  return NULL;
     2420
     2421                /* Might be assignment, or might be $= or #=.  Check.  */
     2422                continue;
     2423            }
     2424          return (char *)++p;
     2425        }
     2426      else if (c == ':')
     2427        /* A colon other than := is a rule line, not a variable defn.  */
     2428        return NULL;
     2429
     2430      /* If we skipped whitespace, non-assignments means no var.  */
     2431      if (wspace)
     2432        return NULL;
     2433    }
     2434
     2435  return (char *)p;
     2436}
     2437
     2438
     2439/* Try to interpret LINE (a null-terminated string) as a variable definition.
     2440
     2441   If LINE was recognized as a variable definition, a pointer to its `struct
     2442   variable' is returned.  If LINE is not a variable definition, NULL is
     2443   returned.  */
     2444
     2445struct variable *
     2446assign_variable_definition (struct variable *v, char *line IF_WITH_VALUE_LENGTH_PARAM(char *eos))
     2447{
     2448  char *beg;
     2449  char *end;
     2450  enum variable_flavor flavor;
     2451#ifndef CONFIG_WITH_VALUE_LENGTH
     2452  char *name;
     2453#endif
    23522454
    23532455  beg = next_token (line);
     2456  line = parse_variable_definition (beg, &flavor);
     2457  if (!line)
     2458    return NULL;
     2459
     2460  end = line - (flavor == f_recursive ? 1 : 2);
    23542461  while (end > beg && isblank ((unsigned char)end[-1]))
    23552462    --end;
    2356   p = next_token (p);
    2357   v->value = p;
     2463  line = next_token (line);
     2464  v->value = line;
     2465  v->flavor = flavor;
    23582466#ifdef CONFIG_WITH_VALUE_LENGTH
    23592467  v->value_alloc_len = ~(unsigned int)0;
    2360   v->value_length = eos != NULL ? eos - p : -1;
    2361   assert (eos == NULL || strchr (p, '\0') == eos);
     2468  v->value_length = eos != NULL ? eos - line : -1;
     2469  assert (eos == NULL || strchr (line, '\0') == eos);
    23622470# ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
    23632471  v->rdonly_val = 0;
     
    23892497   or without the -e switch, or the command line.
    23902498
    2391    See the comments for parse_variable_definition().
     2499   See the comments for assign_variable_definition().
    23922500
    23932501   If LINE was recognized as a variable definition, a pointer to its `struct
     
    23962504
    23972505struct variable *
    2398 #ifndef CONFIG_WITH_VALUE_LENGTH
    2399 try_variable_definition (const struct floc *flocp, char *line,
     2506try_variable_definition (const struct floc *flocp, char *line
     2507                         IF_WITH_VALUE_LENGTH_PARAM(char *eos),
    24002508                         enum variable_origin origin, int target_var)
    2401 #else
    2402 try_variable_definition (const struct floc *flocp, char *line, char *eos,
    2403                          enum variable_origin origin, int target_var)
    2404 #endif
    24052509{
    24062510  struct variable v;
     
    24132517
    24142518#ifndef CONFIG_WITH_VALUE_LENGTH
    2415   if (!parse_variable_definition (&v, line))
     2519  if (!assign_variable_definition (&v, line))
    24162520    return 0;
    24172521
     
    24192523                               origin, v.flavor, target_var);
    24202524#else
    2421   if (!parse_variable_definition (&v, line, eos))
     2525  if (!assign_variable_definition (&v, line, eos))
    24222526    return 0;
    24232527
     
    24862590  fputs ("# ", stdout);
    24872591  fputs (origin, stdout);
     2592  if (v->private_var)
     2593    fputs (" private", stdout);
    24882594  if (v->fileinfo.filenm)
    24892595    printf (_(" (from `%s', line %lu)"),
     
    25142620  else
    25152621    {
    2516       register char *p;
     2622      char *p;
    25172623
    25182624      printf ("%s %s= ", v->name, v->recursive ? v->append ? "+" : "" : ":");
     
    26602766   */
    26612767  convert_Path_to_windows32 (path, ';');
    2662   environ_path = xstrdup (concat ("PATH", "=", path));
     2768  environ_path = xstrdup (concat (3, "PATH", "=", path));
    26632769  putenv (environ_path);
    26642770  free (path);
Note: See TracChangeset for help on using the changeset viewer.