Ignore:
Timestamp:
Mar 14, 2018, 10:28:10 PM (7 years ago)
Author:
bird
Message:

kmk: Merged in changes from GNU make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6 / https://git.savannah.gnu.org/git/make.git).

Location:
trunk/src/kmk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk

  • trunk/src/kmk/variable.c

    r3090 r3140  
    11/* Internals of variables for GNU Make.
    2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
    4 2010 Free Software Foundation, Inc.
     2Copyright (C) 1988-2016 Free Software Foundation, Inc.
    53This file is part of GNU Make.
    64
     
    1715this program.  If not, see <http://www.gnu.org/licenses/>.  */
    1816
    19 #include "make.h"
     17#include "makeint.h"
    2018
    2119#include <assert.h>
    2220
     21#include "filedef.h"
    2322#include "dep.h"
    24 #include "filedef.h"
    2523#include "job.h"
    2624#include "commands.h"
     
    6563#endif
    6664
     65/* Incremented every time we add or remove a global variable.  */
     66static unsigned long variable_changenum;
    6767
    6868/* Chain of all pattern-specific variables.  */
     
    135135{
    136136  struct pattern_var *p;
    137   unsigned int targlen = strlen(target);
     137  unsigned int targlen = strlen (target);
    138138
    139139  for (p = start ? start->next : pattern_vars; p != 0; p = p->next)
     
    203203#endif /* !CONFIG_WITH_STRCACHE2 */
    204204
    205 #ifndef VARIABLE_BUCKETS
     205#ifndef VARIABLE_BUCKETS
    206206# ifdef KMK /* Move to Makefile.kmk? (insanely high, but wtf, it gets the collitions down) */
    207 #  define VARIABLE_BUCKETS              65535
     207#  define VARIABLE_BUCKETS              65535
    208208# else  /*!KMK*/
    209 #define VARIABLE_BUCKETS                523
     209#define VARIABLE_BUCKETS                523
    210210# endif /*!KMK*/
    211211#endif
    212 #ifndef PERFILE_VARIABLE_BUCKETS
     212#ifndef PERFILE_VARIABLE_BUCKETS
    213213# ifdef KMK /* Move to Makefile.kmk? */
    214 #  define PERFILE_VARIABLE_BUCKETS      127
     214#  define PERFILE_VARIABLE_BUCKETS      127
    215215# else
    216 #define PERFILE_VARIABLE_BUCKETS        23
     216#define PERFILE_VARIABLE_BUCKETS        23
    217217# endif
    218218#endif
    219 #ifndef SMALL_SCOPE_VARIABLE_BUCKETS
     219#ifndef SMALL_SCOPE_VARIABLE_BUCKETS
    220220# ifdef KMK /* Move to Makefile.kmk? */
    221221#  define SMALL_SCOPE_VARIABLE_BUCKETS  63
    222222# else
    223 #define SMALL_SCOPE_VARIABLE_BUCKETS    13
     223#define SMALL_SCOPE_VARIABLE_BUCKETS    13
    224224# endif
    225225#endif
     
    247247#ifndef CONFIG_WITH_STRCACHE2
    248248  hash_init (&global_variable_set.table, VARIABLE_BUCKETS,
    249              variable_hash_1, variable_hash_2, variable_hash_cmp);
     249             variable_hash_1, variable_hash_2, variable_hash_cmp);
    250250#else  /* CONFIG_WITH_STRCACHE2 */
    251251  strcache2_init (&variable_strcache, "variable", 262144, 0, 0, 0);
     
    268268                        int duplicate_value, enum variable_origin origin,
    269269                        int recursive, struct variable_set *set,
    270                         const struct floc *flocp)
     270                        const floc *flocp)
    271271#else
    272272struct variable *
     
    274274                        const char *value, enum variable_origin origin,
    275275                        int recursive, struct variable_set *set,
    276                         const struct floc *flocp)
     276                        const floc *flocp)
    277277#endif
    278278{
     
    316316  var_key.length = length;
    317317  var_slot = (struct variable **) hash_find_slot (&set->table, &var_key);
     318  v = *var_slot;
     319
     320#ifdef VMS
     321  /* VMS does not populate envp[] with DCL symbols and logical names which
     322     historically are mapped to environent variables.
     323     If the variable is not yet defined, then we need to check if getenv()
     324     can find it.  Do not do this for origin == o_env to avoid infinte
     325     recursion */
     326  if (HASH_VACANT (v) && (origin != o_env))
     327    {
     328      struct variable * vms_variable;
     329      char * vname = alloca (length + 1);
     330      char * vvalue;
     331
     332      strncpy (vname, name, length);
     333      vvalue = getenv(vname);
     334
     335      /* Values starting with '$' are probably foreign commands.
     336         We want to treat them as Shell aliases and not look them up here */
     337      if ((vvalue != NULL) && (vvalue[0] != '$'))
     338        {
     339          vms_variable =  lookup_variable(name, length);
     340          /* Refresh the slot */
     341          var_slot = (struct variable **) hash_find_slot (&set->table,
     342                                                          &var_key);
     343          v = *var_slot;
     344        }
     345    }
     346#endif
    318347
    319348  /* if (env_overrides && origin == o_env)
    320349    origin = o_env_override; - bird moved this up */
    321350
    322   v = *var_slot;
    323351#else  /* CONFIG_WITH_STRCACHE2 */
    324352  name = strcache2_add (&variable_strcache, name, length);
     
    343371#endif
    344372      if (env_overrides && v->origin == o_env)
    345         /* V came from in the environment.  Since it was defined
    346            before the switches were parsed, it wasn't affected by -e.  */
    347         v->origin = o_env_override;
     373        /* V came from in the environment.  Since it was defined
     374           before the switches were parsed, it wasn't affected by -e.  */
     375        v->origin = o_env_override;
    348376
    349377      /* A variable of this name is already defined.
    350         If the old definition is from a stronger source
    351         than this one, don't redefine it.  */
     378        If the old definition is from a stronger source
     379        than this one, don't redefine it.  */
    352380      if ((int) origin >= (int) v->origin)
    353         {
     381        {
    354382#ifdef CONFIG_WITH_VALUE_LENGTH
    355383          if (value_len == ~0U)
     
    390418          v->value_length = value_len;
    391419#else  /* !CONFIG_WITH_VALUE_LENGTH */
    392           if (v->value != 0)
    393             free (v->value);
    394           v->value = xstrdup (value);
     420          free (v->value);
     421          v->value = xstrdup (value);
    395422#endif /* !CONFIG_WITH_VALUE_LENGTH */
    396423          if (flocp != 0)
     
    398425          else
    399426            v->fileinfo.filenm = 0;
    400           v->origin = origin;
    401           v->recursive = recursive;
    402          VARIABLE_CHANGED (v);
    403         }
     427          v->origin = origin;
     428          v->recursive = recursive;
     429          VARIABLE_CHANGED (v);
     430        }
    404431      return v;
    405432    }
     
    419446  v->length = length;
    420447  hash_insert_at (&set->table, v, var_slot);
     448  if (set == &global_variable_set)
     449    ++variable_changenum;
     450
    421451#ifdef CONFIG_WITH_VALUE_LENGTH
    422452  if (value_len == ~0U)
     
    507537
    508538static void
    509 free_variable_name_and_value (const void *item);
     539free_variable_name_and_value (const void *item)
     540{
     541  struct variable *v = (struct variable *) item;
     542#ifndef CONFIG_WITH_STRCACHE2
     543  free (v->name);
     544#endif
     545#ifdef CONFIG_WITH_COMPILER
     546  if (v->evalprog || v->expandprog)
     547    kmk_cc_variable_deleted (v);
     548#endif
     549#ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     550  if (!v->rdonly_val)
     551#endif
     552    free (v->value);
     553}
     554
     555void
     556free_variable_set (struct variable_set_list *list)
     557{
     558  hash_map (&list->set->table, free_variable_name_and_value);
     559#ifndef CONFIG_WITH_ALLOC_CACHES
     560  hash_free (&list->set->table, 1);
     561  free (list->set);
     562  free (list);
     563#else
     564  hash_free_cached (&list->set->table, 1, &variable_cache);
     565  alloccache_free (&variable_set_cache, list->set);
     566  alloccache_free (&variable_set_list_cache, list);
     567#endif
     568}
    510569
    511570void
     
    547606        {
    548607           if (v->aliased)
    549              error (NULL, _("Cannot undefine the aliased variable '%s'"), v->name);
     608             OS (error, NULL, _("Cannot undefine the aliased variable '%s'"), v->name);
    550609           else
    551              error (NULL, _("Cannot undefine the variable alias '%s'"), v->name);
     610             OS (error, NULL, _("Cannot undefine the variable alias '%s'"), v->name);
    552611          return;
    553612        }
     
    555614
    556615      if (env_overrides && v->origin == o_env)
    557         /* V came from in the environment.  Since it was defined
    558            before the switches were parsed, it wasn't affected by -e.  */
    559         v->origin = o_env_override;
    560 
    561       /* If the definition is from a stronger source than this one, don't
    562          undefine it.  */
     616        /* V came from in the environment.  Since it was defined
     617           before the switches were parsed, it wasn't affected by -e.  */
     618        v->origin = o_env_override;
     619
     620      /* Undefine only if this undefinition is from an equal or stronger
     621         source than the variable definition.  */
    563622      if ((int) origin >= (int) v->origin)
    564         {
     623        {
    565624          hash_delete_at (&set->table, var_slot);
    566625#ifdef CONFIG_WITH_STRCACHE2
     
    569628#endif
    570629          free_variable_name_and_value (v);
    571         }
     630          free (v);
     631          if (set == &global_variable_set)
     632            ++variable_changenum;
     633        }
    572634    }
    573635}
     
    580642define_variable_alias_in_set (const char *name, unsigned int length,
    581643                              struct variable *target, enum variable_origin origin,
    582                               struct variable_set *set, const struct floc *flocp)
     644                              struct variable_set *set, const floc *flocp)
    583645{
    584646  struct variable     *v;
     
    707769lookup_special_var (struct variable *var)
    708770{
    709   static unsigned long last_var_count = 0;
     771  static unsigned long last_changenum = 0;
    710772
    711773
     
    735797  */
    736798
    737   if (streq (var->name, ".VARIABLES")
    738       && global_variable_set.table.ht_fill != last_var_count)
     799  if (variable_changenum != last_changenum && streq (var->name, ".VARIABLES"))
    739800    {
    740801#ifndef CONFIG_WITH_VALUE_LENGTH
     
    783844      VARIABLE_CHANGED (var);
    784845
    785       /* Remember how many variables are in our current count.  Since we never
    786          remove variables from the list, this is a reliable way to know whether
    787          the list is up to date or needs to be recomputed.  */
    788 
    789       last_var_count = global_variable_set.table.ht_fill;
     846      /* Remember the current variable change number.  */
     847      last_changenum = variable_changenum;
    790848    }
    791849
     
    920978/* Lookup a variable whose name is a string starting at NAME
    921979   and with LENGTH chars.  NAME need not be null-terminated.
    922    Returns address of the `struct variable' containing all info
     980   Returns address of the 'struct variable' containing all info
    923981   on the variable, or nil if no such variable is defined.  */
    924982
     
    9801038# endif
    9811039          MAKE_STATS_2 (v->references++);
    982            return v->special ? lookup_special_var (v) : v;
     1040          return v->special ? lookup_special_var (v) : v;
    9831041        }
    9841042
     
    9961054#endif /* KMK - need for speed */
    9971055#ifdef VMS
    998   /* since we don't read envp[] on startup, try to get the
    999      variable via getenv() here. */
     1056  /* VMS does not populate envp[] with DCL symbols and logical names which
     1057     historically are mapped to enviroment varables and returned by getenv() */
    10001058  {
    10011059    char *vname = alloca (length + 1);
     
    11271185/* Lookup a variable whose name is a string starting at NAME
    11281186   and with LENGTH chars in set SET.  NAME need not be null-terminated.
    1129    Returns address of the `struct variable' containing all info
     1187   Returns address of the 'struct variable' containing all info
    11301188   on the variable, or nil if no such variable is defined.  */
    11311189
     
    12041262#ifndef CONFIG_WITH_ALLOC_CACHES
    12051263      l = (struct variable_set_list *)
    1206         xmalloc (sizeof (struct variable_set_list));
     1264        xmalloc (sizeof (struct variable_set_list));
    12071265      l->set = xmalloc (sizeof (struct variable_set));
    12081266#else  /* CONFIG_WITH_ALLOC_CACHES */
     
    13311389#ifndef CONFIG_WITH_STRCACHE2
    13321390  hash_init (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS,
    1333              variable_hash_1, variable_hash_2, variable_hash_cmp);
     1391             variable_hash_1, variable_hash_2, variable_hash_cmp);
    13341392#else  /* CONFIG_WITH_STRCACHE2 */
    13351393  hash_init_strcached (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS,
     
    13511409}
    13521410
    1353 static void
    1354 free_variable_name_and_value (const void *item)
    1355 {
    1356   struct variable *v = (struct variable *) item;
    1357 #ifndef CONFIG_WITH_STRCACHE2
    1358   free (v->name);
    1359 #endif
    1360 #ifdef CONFIG_WITH_COMPILER
    1361   if (v->evalprog || v->expandprog)
    1362     kmk_cc_variable_deleted (v);
    1363 #endif
    1364 #ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
    1365   if (!v->rdonly_val)
    1366 #endif
    1367     free (v->value);
    1368 }
    1369 
    1370 void
    1371 free_variable_set (struct variable_set_list *list)
    1372 {
    1373   hash_map (&list->set->table, free_variable_name_and_value);
    1374 #ifndef CONFIG_WITH_ALLOC_CACHES
    1375   hash_free (&list->set->table, 1);
    1376   free (list->set);
    1377   free (list);
    1378 #else
    1379   hash_free_cached (&list->set->table, 1, &variable_cache);
    1380   alloccache_free (&variable_set_cache, list->set);
    1381   alloccache_free (&variable_set_list_cache, list);
    1382 #endif
    1383 }
    1384 
    13851411/* Create a new variable set and push it on the current setlist.
    13861412   If we're pushing a global scope (that is, the current scope is the global
     
    13921418push_new_variable_scope (void)
    13931419{
    1394   current_variable_set_list = create_new_variable_set();
     1420  current_variable_set_list = create_new_variable_set ();
    13951421  if (current_variable_set_list->next == &global_setlist)
    13961422    {
     
    14151441
    14161442  /* Can't call this if there's no scope to pop!  */
    1417   assert(current_variable_set_list->next != NULL);
     1443  assert (current_variable_set_list->next != NULL);
    14181444
    14191445  if (current_variable_set_list != &global_setlist)
     
    14601486  struct variable **from_var_end = from_var_slot + from_set->table.ht_size;
    14611487
     1488  int inc = to_set == &global_variable_set ? 1 : 0;
     1489
    14621490  for ( ; from_var_slot < from_var_end; from_var_slot++)
    14631491    if (! HASH_VACANT (*from_var_slot))
    14641492      {
    1465         struct variable *from_var = *from_var_slot;
    1466         struct variable **to_var_slot
     1493        struct variable *from_var = *from_var_slot;
     1494        struct variable **to_var_slot
    14671495#ifndef CONFIG_WITH_STRCACHE2
    1468           = (struct variable **) hash_find_slot (&to_set->table, *from_var_slot);
     1496          = (struct variable **) hash_find_slot (&to_set->table, *from_var_slot);
    14691497#else  /* CONFIG_WITH_STRCACHE2 */
    14701498          = (struct variable **) hash_find_slot_strcached (&to_set->table,
    14711499                                                           *from_var_slot);
    14721500#endif /* CONFIG_WITH_STRCACHE2 */
    1473         if (HASH_VACANT (*to_var_slot))
    1474           hash_insert_at (&to_set->table, from_var, to_var_slot);
    1475         else
    1476           {
    1477             /* GKM FIXME: delete in from_set->table */
     1501        if (HASH_VACANT (*to_var_slot))
     1502          {
     1503            hash_insert_at (&to_set->table, from_var, to_var_slot);
     1504            variable_changenum += inc;
     1505          }
     1506        else
     1507          {
     1508            /* GKM FIXME: delete in from_set->table */
    14781509#ifdef KMK
    14791510            if (from_var->aliased)
    1480               fatal(NULL, ("Attempting to delete aliased variable '%s'"), from_var->name);
     1511              OS (fatal, NULL, ("Attempting to delete aliased variable '%s'"), from_var->name);
    14811512            if (from_var->alias)
    1482               fatal(NULL, ("Attempting to delete variable aliased '%s'"), from_var->name);
     1513              OS (fatal, NULL, ("Attempting to delete variable aliased '%s'"), from_var->name);
    14831514#endif
    14841515#ifdef CONFIG_WITH_COMPILER
     
    14901521#endif
    14911522              free (from_var->value);
    1492             free (from_var);
    1493           }
     1523            free (from_var);
     1524          }
    14941525      }
    14951526}
     
    15251556    {
    15261557      if (last0 == 0)
    1527         *setlist0 = setlist1;
     1558        *setlist0 = setlist1;
    15281559      else
    1529         last0->next = setlist1;
     1560        last0->next = setlist1;
    15301561    }
    15311562}
     
    15631594define_automatic_variables (void)
    15641595{
    1565 #if defined(WINDOWS32) || defined(__EMX__)
    1566   extern char* default_shell;
    1567 #else
    1568   extern char default_shell[];
    1569 #endif
    1570   register struct variable *v;
     1596  struct variable *v;
    15711597#ifndef KMK
    15721598  char buf[200];
     
    15881614
    15891615  sprintf (buf, "%s%s%s",
    1590            version_string,
    1591            (remote_description == 0 || remote_description[0] == '\0')
    1592            ? "" : "-",
    1593            (remote_description == 0 || remote_description[0] == '\0')
    1594            ? "" : remote_description);
     1616           version_string,
     1617           (remote_description == 0 || remote_description[0] == '\0')
     1618           ? "" : "-",
     1619           (remote_description == 0 || remote_description[0] == '\0')
     1620           ? "" : remote_description);
    15951621#ifndef KMK
    15961622  define_variable_cname ("MAKE_VERSION", buf, o_default, 0);
     1623  define_variable_cname ("MAKE_HOST", make_host, o_default, 0);
    15971624#else /* KMK */
    15981625
     
    16191646  val = envvar1 ? envvar1->value : envvar2 ? envvar2->value : KBUILD_HOST;
    16201647  if (envvar1 && envvar2 && strcmp (envvar1->value, envvar2->value))
    1621     error (NULL, _("KBUILD_HOST and BUILD_PLATFORM differs, using KBUILD_HOST=%s."), val);
     1648    OS (error, NULL, _("KBUILD_HOST and BUILD_PLATFORM differs, using KBUILD_HOST=%s."), val);
    16221649  if (!envvar1)
    16231650    define_variable_cname ("KBUILD_HOST", val, o_default, 0);
     
    16291656  val = envvar1 ? envvar1->value : envvar2 ? envvar2->value : KBUILD_HOST_ARCH;
    16301657  if (envvar1 && envvar2 && strcmp (envvar1->value, envvar2->value))
    1631     error (NULL, _("KBUILD_HOST_ARCH and BUILD_PLATFORM_ARCH differs, using KBUILD_HOST_ARCH=%s."), val);
     1658    OS (error, NULL, _("KBUILD_HOST_ARCH and BUILD_PLATFORM_ARCH differs, using KBUILD_HOST_ARCH=%s."), val);
    16321659  if (!envvar1)
    16331660    define_variable_cname ("KBUILD_HOST_ARCH", val, o_default, 0);
     
    16391666  val = envvar1 ? envvar1->value : envvar2 ? envvar2->value : KBUILD_HOST_CPU;
    16401667  if (envvar1 && envvar2 && strcmp (envvar1->value, envvar2->value))
    1641     error (NULL, _("KBUILD_HOST_CPU and BUILD_PLATFORM_CPU differs, using KBUILD_HOST_CPU=%s."), val);
     1668    OS (error, NULL, _("KBUILD_HOST_CPU and BUILD_PLATFORM_CPU differs, using KBUILD_HOST_CPU=%s."), val);
    16421669  if (!envvar1)
    16431670    define_variable_cname ("KBUILD_HOST_CPU", val, o_default, 0);
     
    18611888    if (mshp)
    18621889      (void) define_variable (shell_str, shlen,
    1863                               mshp->value, o_env_override, 0);
     1890                              mshp->value, o_env_override, 0);
    18641891    else if (comp)
    18651892      {
    1866         /* $(COMSPEC) shouldn't override $(SHELL).  */
    1867         struct variable *shp = lookup_variable (shell_str, shlen);
    1868 
    1869         if (!shp)
    1870           (void) define_variable (shell_str, shlen, comp->value, o_env, 0);
     1893        /* $(COMSPEC) shouldn't override $(SHELL).  */
     1894        struct variable *shp = lookup_variable (shell_str, shlen);
     1895
     1896        if (!shp)
     1897          (void) define_variable (shell_str, shlen, comp->value, o_env, 0);
    18711898      }
    18721899  }
     
    18861913    if (!replace || !*replace->value)
    18871914      if (shell && *shell->value && (shell->origin == o_env
    1888           || shell->origin == o_env_override))
    1889         {
    1890           /* overwrite whatever we got from the environment */
    1891           free(shell->value);
    1892           shell->value = xstrdup (default_shell);
    1893           shell->origin = o_default;
    1894         }
     1915          || shell->origin == o_env_override))
     1916        {
     1917          /* overwrite whatever we got from the environment */
     1918          free (shell->value);
     1919          shell->value = xstrdup (default_shell);
     1920          shell->origin = o_default;
     1921        }
    18951922
    18961923    /* Some people do not like cmd to be used as the default
     
    19121939      /* overwrite $SHELL */
    19131940      (void) define_variable (shell_str, shlen, replace->value,
    1914                               replace->origin, 0);
     1941                              replace->origin, 0);
    19151942    else
    19161943      /* provide a definition if there is none */
    19171944      (void) define_variable (shell_str, shlen, default_shell,
    1918                               o_default, 0);
     1945                              o_default, 0);
    19191946  }
    19201947
     
    19581985     the automatic variables they are variations of.  */
    19591986
    1960 #ifdef VMS
    1961   define_variable_cname ("@D", "$(dir $@)", o_automatic, 1);
    1962   define_variable_cname ("%D", "$(dir $%)", o_automatic, 1);
    1963   define_variable_cname ("*D", "$(dir $*)", o_automatic, 1);
    1964   define_variable_cname ("<D", "$(dir $<)", o_automatic, 1);
    1965   define_variable_cname ("?D", "$(dir $?)", o_automatic, 1);
    1966   define_variable_cname ("^D", "$(dir $^)", o_automatic, 1);
    1967   define_variable_cname ("+D", "$(dir $+)", o_automatic, 1);
    1968 #else
     1987#if defined(__MSDOS__) || defined(WINDOWS32)
     1988  /* For consistency, remove the trailing backslash as well as slash.  */
     1989  define_variable_cname ("@D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $@)))",
     1990                         o_automatic, 1);
     1991  define_variable_cname ("%D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $%)))",
     1992                         o_automatic, 1);
     1993  define_variable_cname ("*D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $*)))",
     1994                         o_automatic, 1);
     1995  define_variable_cname ("<D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $<)))",
     1996                         o_automatic, 1);
     1997  define_variable_cname ("?D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $?)))",
     1998                         o_automatic, 1);
     1999  define_variable_cname ("^D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $^)))",
     2000                         o_automatic, 1);
     2001  define_variable_cname ("+D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $+)))",
     2002                         o_automatic, 1);
     2003#else  /* not __MSDOS__, not WINDOWS32 */
    19692004  define_variable_cname ("@D", "$(patsubst %/,%,$(dir $@))", o_automatic, 1);
    19702005  define_variable_cname ("%D", "$(patsubst %/,%,$(dir $%))", o_automatic, 1);
     
    20732108
    20742109/* Create a new environment for FILE's commands.
    2075    If FILE is nil, this is for the `shell' function.
     2110   If FILE is nil, this is for the 'shell' function.
    20762111   The child's MAKELEVEL variable is incremented.  */
    20772112
     
    21032138#ifndef CONFIG_WITH_STRCACHE2
    21042139  hash_init (&table, ENVIRONMENT_VARIABLE_BUCKETS,
    2105              variable_hash_1, variable_hash_2, variable_hash_cmp);
     2140             variable_hash_1, variable_hash_2, variable_hash_cmp);
    21062141#else  /* CONFIG_WITH_STRCACHE2 */
    21072142  hash_init_strcached (&table, ENVIRONMENT_VARIABLE_BUCKETS,
     
    21242159      v_end = v_slot + set->table.ht_size;
    21252160      for ( ; v_slot < v_end; v_slot++)
    2126         if (! HASH_VACANT (*v_slot))
    2127           {
    2128             struct variable **new_slot;
    2129             struct variable *v = *v_slot;
    2130 
    2131             /* If this is a per-target variable and it hasn't been touched
    2132                already then look up the global version and take its export
    2133                value.  */
    2134             if (v->per_target && v->export == v_default)
    2135               {
    2136                 struct variable *gv;
     2161        if (! HASH_VACANT (*v_slot))
     2162          {
     2163            struct variable **new_slot;
     2164            struct variable *v = *v_slot;
     2165
     2166            /* If this is a per-target variable and it hasn't been touched
     2167               already then look up the global version and take its export
     2168               value.  */
     2169            if (v->per_target && v->export == v_default)
     2170              {
     2171                struct variable *gv;
    21372172
    21382173#ifndef CONFIG_WITH_VALUE_LENGTH
    2139                 gv = lookup_variable_in_set (v->name, strlen(v->name),
     2174                gv = lookup_variable_in_set (v->name, strlen (v->name),
    21402175                                             &global_variable_set);
    21412176#else
    21422177                assert ((int)strlen(v->name) == v->length);
    21432178                gv = lookup_variable_in_set (v->name, v->length,
    2144                                                      &global_variable_set);
    2145 #endif
    2146                 if (gv)
    2147                   v->export = gv->export;
    2148               }
    2149 
    2150             switch (v->export)
    2151               {
    2152               case v_default:
    2153                 if (v->origin == o_default || v->origin == o_automatic)
    2154                   /* Only export default variables by explicit request.  */
    2155                   continue;
     2179                                             &global_variable_set);
     2180#endif
     2181                if (gv)
     2182                  v->export = gv->export;
     2183              }
     2184
     2185            switch (v->export)
     2186              {
     2187              case v_default:
     2188                if (v->origin == o_default || v->origin == o_automatic)
     2189                  /* Only export default variables by explicit request.  */
     2190                  continue;
    21562191
    21572192                /* The variable doesn't have a name that can be exported.  */
     
    21592194                  continue;
    21602195
    2161                 if (! export_all_variables
    2162                     && v->origin != o_command
    2163                     && v->origin != o_env && v->origin != o_env_override)
    2164                   continue;
    2165                 break;
    2166 
    2167               case v_export:
    2168                 break;
    2169 
    2170               case v_noexport:
    2171                 {
    2172                   /* If this is the SHELL variable and it's not exported,
    2173                      then add the value from our original environment, if
    2174                      the original environment defined a value for SHELL.  */
    2175                   extern struct variable shell_var;
    2176                   if (streq (v->name, "SHELL") && shell_var.value)
    2177                     {
    2178                       v = &shell_var;
    2179                       break;
    2180                     }
    2181                   continue;
    2182                 }
    2183 
    2184               case v_ifset:
    2185                 if (v->origin == o_default)
    2186                   continue;
    2187                 break;
    2188               }
     2196                if (! export_all_variables
     2197                    && v->origin != o_command
     2198                    && v->origin != o_env && v->origin != o_env_override)
     2199                  continue;
     2200                break;
     2201
     2202              case v_export:
     2203                break;
     2204
     2205              case v_noexport:
     2206                {
     2207                  /* If this is the SHELL variable and it's not exported,
     2208                     then add the value from our original environment, if
     2209                     the original environment defined a value for SHELL.  */
     2210                  if (streq (v->name, "SHELL") && shell_var.value)
     2211                    {
     2212                      v = &shell_var;
     2213                      break;
     2214                    }
     2215                  continue;
     2216                }
     2217
     2218              case v_ifset:
     2219                if (v->origin == o_default)
     2220                  continue;
     2221                break;
     2222              }
    21892223
    21902224#ifndef CONFIG_WITH_STRCACHE2
    2191             new_slot = (struct variable **) hash_find_slot (&table, v);
     2225            new_slot = (struct variable **) hash_find_slot (&table, v);
    21922226#else  /* CONFIG_WITH_STRCACHE2 */
    21932227            assert (strcache2_is_cached (&variable_strcache, v->name));
    21942228            new_slot = (struct variable **) hash_find_slot_strcached (&table, v);
    21952229#endif /* CONFIG_WITH_STRCACHE2 */
    2196             if (HASH_VACANT (*new_slot))
    2197               hash_insert_at (&table, v, new_slot);
    2198           }
     2230            if (HASH_VACANT (*new_slot))
     2231              hash_insert_at (&table, v, new_slot);
     2232          }
    21992233    }
    22002234
     
    22162250
    22172251#ifndef CONFIG_WITH_STRCACHE2
    2218   makelevel_key.name = MAKELEVEL_NAME;
     2252  makelevel_key.name = (char *)MAKELEVEL_NAME;
    22192253  makelevel_key.length = MAKELEVEL_LENGTH;
    22202254  hash_delete (&table, &makelevel_key);
     
    22392273    if (! HASH_VACANT (*v_slot))
    22402274      {
    2241         struct variable *v = *v_slot;
    2242 
    2243         /* If V is recursively expanded and didn't come from the environment,
    2244            expand its value.  If it came from the environment, it should
    2245            go back into the environment unchanged.  */
    2246         if (v->recursive
    2247             && v->origin != o_env && v->origin != o_env_override)
    2248           {
     2275        struct variable *v = *v_slot;
     2276
     2277        /* If V is recursively expanded and didn't come from the environment,
     2278           expand its value.  If it came from the environment, it should
     2279           go back into the environment unchanged.  */
     2280        if (v->recursive
     2281            && v->origin != o_env && v->origin != o_env_override)
     2282          {
    22492283#ifndef CONFIG_WITH_VALUE_LENGTH
    2250             char *value = recursively_expand_for_file (v, file);
     2284            char *value = recursively_expand_for_file (v, file);
    22512285#else
    22522286            char *value = recursively_expand_for_file (v, file, NULL);
    22532287#endif
    22542288#ifdef WINDOWS32
    2255             if (strcmp(v->name, "Path") == 0 ||
    2256                 strcmp(v->name, "PATH") == 0)
    2257               convert_Path_to_windows32(value, ';');
    2258 #endif
    2259             *result++ = xstrdup (concat (3, v->name, "=", value));
    2260             free (value);
    2261           }
    2262         else
    2263           {
     2289            if (strcmp (v->name, "Path") == 0 ||
     2290                strcmp (v->name, "PATH") == 0)
     2291              convert_Path_to_windows32 (value, ';');
     2292#endif
     2293            *result++ = xstrdup (concat (3, v->name, "=", value));
     2294            free (value);
     2295          }
     2296        else
     2297          {
    22642298#ifdef WINDOWS32
    2265             if (strcmp(v->name, "Path") == 0 ||
    2266                 strcmp(v->name, "PATH") == 0)
    2267               convert_Path_to_windows32(v->value, ';');
    2268 #endif
    2269             *result++ = xstrdup (concat (3, v->name, "=", v->value));
    2270           }
     2299            if (strcmp (v->name, "Path") == 0 ||
     2300                strcmp (v->name, "PATH") == 0)
     2301              convert_Path_to_windows32 (v->value, ';');
     2302#endif
     2303            *result++ = xstrdup (concat (3, v->name, "=", v->value));
     2304          }
    22712305      }
    22722306
     
    23542388
    23552389struct variable *
    2356 do_variable_definition_append (const struct floc *flocp, struct variable *v,
     2390do_variable_definition_append (const floc *flocp, struct variable *v,
    23572391                               const char *value, unsigned int value_len,
    23582392                               int simple_value, enum variable_origin origin,
     
    24112445
    24122446
     2447/* Given a string, shell-execute it and return a malloc'ed string of the
     2448 * result. This removes only ONE newline (if any) at the end, for maximum
     2449 * compatibility with the *BSD makes.  If it fails, returns NULL. */
     2450
     2451static char *
     2452shell_result (const char *p)
     2453{
     2454  char *buf;
     2455  unsigned int len;
     2456  char *args[2];
     2457  char *result;
     2458
     2459  install_variable_buffer (&buf, &len);
     2460
     2461  args[0] = (char *) p;
     2462  args[1] = NULL;
     2463  variable_buffer_output (func_shell_base (variable_buffer, args, 0), "\0", 1);
     2464  result = strdup (variable_buffer);
     2465
     2466  restore_variable_buffer (buf, len);
     2467  return result;
     2468}
     2469
     2470
    24132471/* Given a variable, a value, and a flavor, define the variable.
    24142472   See the try_variable_definition() function for details on the parameters. */
     
    24162474struct variable *
    24172475#ifndef CONFIG_WITH_VALUE_LENGTH
    2418 do_variable_definition (const struct floc *flocp, const char *varname,
     2476do_variable_definition (const floc *flocp, const char *varname,
    24192477                        const char *value, enum variable_origin origin,
    24202478                        enum variable_flavor flavor, int target_var)
    24212479#else  /* CONFIG_WITH_VALUE_LENGTH */
    2422 do_variable_definition_2 (const struct floc *flocp,
     2480do_variable_definition_2 (const floc *flocp,
    24232481                          const char *varname, const char *value,
    24242482                          unsigned int value_len, int simple_value,
     
    24542512      /* A simple variable definition "var := value".  Expand the value.
    24552513         We have to allocate memory since otherwise it'll clobber the
    2456         variable buffer, and we may still need that if we're looking at a
     2514        variable buffer, and we may still need that if we're looking at a
    24572515         target-specific variable.  */
    24582516#ifndef CONFIG_WITH_VALUE_LENGTH
     
    24762534#endif /* CONFIG_WITH_VALUE_LENGTH */
    24772535      break;
     2536    case f_shell:
     2537      {
     2538        /* A shell definition "var != value".  Expand value, pass it to
     2539           the shell, and store the result in recursively-expanded var. */
     2540        char *q = allocated_variable_expand (value);
     2541        p = alloc_value = shell_result (q);
     2542        free (q);
     2543        flavor = f_recursive;
     2544        break;
     2545      }
    24782546    case f_conditional:
    24792547      /* A conditional variable definition "var ?= value".
     
    24962564    case f_recursive:
    24972565      /* A recursive variable definition "var = value".
    2498         The value is used verbatim.  */
     2566        The value is used verbatim.  */
    24992567      p = value;
    25002568      break;
     
    26052673              }
    26062674
    2607             if (tp)
    2608               free (tp);
     2675            free (tp);
    26092676#endif /* !CONFIG_WITH_VALUE_LENGTH */
    26102677          }
     
    26152682  /* Many Unix Makefiles include a line saying "SHELL=/bin/sh", but
    26162683     non-Unix systems don't conform to this default configuration (in
    2617      fact, most of them don't even have `/bin').  On the other hand,
     2684     fact, most of them don't even have '/bin').  On the other hand,
    26182685     $SHELL in the environment, if set, points to the real pathname of
    26192686     the shell.
     
    26342701      /* See if we can find "/bin/sh.exe", "/bin/sh.com", etc.  */
    26352702      if (__dosexec_find_on_path (p, NULL, shellpath))
    2636         {
    2637           char *tp;
    2638 
    2639           for (tp = shellpath; *tp; tp++)
     2703        {
     2704          char *tp;
     2705
     2706          for (tp = shellpath; *tp; tp++)
    26402707            if (*tp == '\\')
    26412708              *tp = '/';
    26422709
    2643           v = define_variable_loc (varname, varname_len,
     2710          v = define_variable_loc (varname, varname_len,
    26442711                                   shellpath, origin, flavor == f_recursive,
    26452712                                   flocp);
    2646         }
     2713        }
    26472714      else
    2648         {
    2649           const char *shellbase, *bslash;
    2650           struct variable *pathv = lookup_variable ("PATH", 4);
    2651           char *path_string;
    2652           char *fake_env[2];
    2653           size_t pathlen = 0;
    2654 
    2655           shellbase = strrchr (p, '/');
    2656           bslash = strrchr (p, '\\');
    2657           if (!shellbase || bslash > shellbase)
    2658             shellbase = bslash;
    2659           if (!shellbase && p[1] == ':')
    2660             shellbase = p + 1;
    2661           if (shellbase)
    2662             shellbase++;
    2663           else
    2664             shellbase = p;
    2665 
    2666           /* Search for the basename of the shell (with standard
    2667              executable extensions) along the $PATH.  */
    2668           if (pathv)
    2669             pathlen = strlen (pathv->value);
    2670           path_string = xmalloc (5 + pathlen + 2 + 1);
    2671           /* On MSDOS, current directory is considered as part of $PATH.  */
    2672           sprintf (path_string, "PATH=.;%s", pathv ? pathv->value : "");
    2673           fake_env[0] = path_string;
    2674           fake_env[1] = 0;
    2675           if (__dosexec_find_on_path (shellbase, fake_env, shellpath))
    2676             {
    2677               char *tp;
    2678 
    2679               for (tp = shellpath; *tp; tp++)
     2715        {
     2716          const char *shellbase, *bslash;
     2717          struct variable *pathv = lookup_variable ("PATH", 4);
     2718          char *path_string;
     2719          char *fake_env[2];
     2720          size_t pathlen = 0;
     2721
     2722          shellbase = strrchr (p, '/');
     2723          bslash = strrchr (p, '\\');
     2724          if (!shellbase || bslash > shellbase)
     2725            shellbase = bslash;
     2726          if (!shellbase && p[1] == ':')
     2727            shellbase = p + 1;
     2728          if (shellbase)
     2729            shellbase++;
     2730          else
     2731            shellbase = p;
     2732
     2733          /* Search for the basename of the shell (with standard
     2734             executable extensions) along the $PATH.  */
     2735          if (pathv)
     2736            pathlen = strlen (pathv->value);
     2737          path_string = xmalloc (5 + pathlen + 2 + 1);
     2738          /* On MSDOS, current directory is considered as part of $PATH.  */
     2739          sprintf (path_string, "PATH=.;%s", pathv ? pathv->value : "");
     2740          fake_env[0] = path_string;
     2741          fake_env[1] = 0;
     2742          if (__dosexec_find_on_path (shellbase, fake_env, shellpath))
     2743            {
     2744              char *tp;
     2745
     2746              for (tp = shellpath; *tp; tp++)
    26802747                if (*tp == '\\')
    26812748                  *tp = '/';
    26822749
    2683               v = define_variable_loc (varname, varname_len,
     2750              v = define_variable_loc (varname, varname_len,
    26842751                                       shellpath, origin,
    26852752                                       flavor == f_recursive, flocp);
    26862753            }
    2687           else
    2688             v = lookup_variable (varname, varname_len);
    2689 
    2690           free (path_string);
    2691         }
     2754          else
     2755            v = lookup_variable (varname, varname_len);
     2756
     2757          free (path_string);
     2758        }
    26922759    }
    26932760  else
     
    26982765      && streq (varname, "SHELL"))
    26992766    {
    2700       extern char *default_shell;
     2767      extern const char *default_shell;
    27012768
    27022769      /* Call shell locator function. If it returns TRUE, then
    2703         set no_default_sh_exe to indicate sh was found and
     2770        set no_default_sh_exe to indicate sh was found and
    27042771         set new value for SHELL variable.  */
    27052772
     
    27392806            v = lookup_variable (varname, varname_len);
    27402807
    2741           if (tp)
    2742             free (tp);
     2808          free (tp);
    27432809        }
    27442810    }
     
    27682834
    27692835#ifndef CONFIG_WITH_VALUE_LENGTH
    2770   if (alloc_value)
    2771     free (alloc_value);
     2836  free (alloc_value);
    27722837#else
    27732838  if (free_value)
     
    27812846/* Parse P (a null-terminated string) as a variable definition.
    27822847
    2783    If it is not a variable definition, return NULL.
     2848   If it is not a variable definition, return NULL and the contents of *VAR
     2849   are undefined, except NAME is set to the first non-space character or NIL.
    27842850
    27852851   If it is a variable definition, return a pointer to the char after the
    2786    assignment token and set *FLAVOR to the type of variable assignment.  */
     2852   assignment token and set the following fields (only) of *VAR:
     2853    name   : name of the variable (ALWAYS SET) (NOT NUL-TERMINATED!)
     2854    length : length of the variable name
     2855    value  : value of the variable (nul-terminated)
     2856    flavor : flavor of the variable
     2857   Other values in *VAR are unchanged.
     2858  */
    27872859
    27882860char *
    2789 parse_variable_definition (const char *p, enum variable_flavor *flavor)
     2861parse_variable_definition (const char *p, struct variable *var)
    27902862{
    27912863  int wspace = 0;
    2792 
    2793   p = next_token (p);
     2864  const char *e = NULL;
     2865
     2866/** @todo merge 4.2.1: parse_variable_definition does more now */
     2867  NEXT_TOKEN (p);
     2868  var->name = (char *)p;
     2869  var->length = 0;
    27942870
    27952871  while (1)
     
    27982874
    27992875      /* If we find a comment or EOS, it's not a variable definition.  */
    2800       if (c == '\0' || c == '#')
    2801         return NULL;
     2876      if (STOP_SET (c, MAP_COMMENT|MAP_NUL))
     2877        return NULL;
    28022878
    28032879      if (c == '$')
    2804         {
    2805           /* This begins a variable expansion reference.  Make sure we don't
    2806              treat chars inside the reference as assignment tokens.  */
    2807           char closeparen;
    2808           int count;
    2809           c = *p++;
    2810           if (c == '(')
    2811             closeparen = ')';
    2812           else if (c == '{')
    2813             closeparen = '}';
    2814           else
     2880        {
     2881          /* This begins a variable expansion reference.  Make sure we don't
     2882             treat chars inside the reference as assignment tokens.  */
     2883          char closeparen;
     2884          unsigned int count;
     2885
     2886          c = *p++;
     2887          if (c == '(')
     2888            closeparen = ')';
     2889          else if (c == '{')
     2890            closeparen = '}';
     2891          else if (c == '\0')
     2892            return NULL;
     2893          else
    28152894            /* '$$' or '$X'.  Either way, nothing special to do here.  */
    2816             continue;
    2817 
    2818           /* P now points past the opening paren or brace.
    2819              Count parens or braces until it is matched.  */
    2820           count = 0;
    2821           for (; *p != '\0'; ++p)
    2822             {
    2823               if (*p == c)
    2824                 ++count;
    2825               else if (*p == closeparen && --count < 0)
    2826                 {
    2827                   ++p;
    2828                   break;
    2829                 }
    2830             }
     2895            continue;
     2896
     2897          /* P now points past the opening paren or brace.
     2898             Count parens or braces until it is matched.  */
     2899          for (count = 1; *p != '\0'; ++p)
     2900            {
     2901              if (*p == closeparen && --count == 0)
     2902                {
     2903                  ++p;
     2904                  break;
     2905                }
     2906              if (*p == c)
     2907                ++count;
     2908            }
    28312909          continue;
    2832         }
     2910        }
    28332911
    28342912      /* If we find whitespace skip it, and remember we found it.  */
    2835       if (isblank ((unsigned char)c))
     2913      if (ISBLANK (c))
    28362914        {
    28372915          wspace = 1;
    2838           p = next_token (p);
     2916          e = p - 1;
     2917          NEXT_TOKEN (p);
    28392918          c = *p;
    28402919          if (c == '\0')
     
    28452924
    28462925      if (c == '=')
    2847         {
    2848           *flavor = f_recursive;
    2849           return (char *)p;
    2850         }
    2851 
    2852       /* Match assignment variants (:=, +=, ?=)  */
     2926        {
     2927          var->flavor = f_recursive;
     2928          if (! e)
     2929            e = p - 1;
     2930          break;
     2931        }
     2932
     2933      /* Match assignment variants (:=, +=, ?=, !=)  */
    28532934      if (*p == '=')
    28542935        {
     
    28562937            {
    28572938              case ':':
    2858                 *flavor = f_simple;
     2939                var->flavor = f_simple;
    28592940                break;
    28602941              case '+':
    2861                 *flavor = f_append;
     2942                var->flavor = f_append;
    28622943                break;
    28632944#ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
    28642945              case '<':
    2865                *flavor = f_prepend;
     2946                var->flavor = f_prepend;
    28662947                break;
    28672948#endif
    28682949              case '?':
    2869                 *flavor = f_conditional;
     2950                var->flavor = f_conditional;
     2951                break;
     2952              case '!':
     2953                var->flavor = f_shell;
    28702954                break;
    28712955              default:
     
    28772961                continue;
    28782962            }
    2879           return (char *)++p;
     2963          if (! e)
     2964            e = p - 1;
     2965          ++p;
     2966          break;
    28802967        }
    2881       else if (c == ':')
    2882         /* A colon other than := is a rule line, not a variable defn.  */
    2883         return NULL;
     2968
     2969      /* Check for POSIX ::= syntax  */
     2970      if (c == ':')
     2971        {
     2972          /* A colon other than :=/::= is not a variable defn.  */
     2973          if (*p != ':' || p[1] != '=')
     2974            return NULL;
     2975
     2976          /* POSIX allows ::= to be the same as GNU make's := */
     2977          var->flavor = f_simple;
     2978          if (! e)
     2979            e = p - 1;
     2980          p += 2;
     2981          break;
     2982        }
    28842983
    28852984      /* If we skipped whitespace, non-assignments means no var.  */
     
    28882987    }
    28892988
     2989  var->length = e - var->name;
     2990  var->value = next_token (p);
     2991#ifdef CONFIG_WITH_VALUE_LENGTH
     2992  var->value_alloc_len = ~(unsigned int)0;
     2993  var->value_length =  -1;
     2994# ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     2995  var->rdonly_val = 0;
     2996# endif
     2997#endif
    28902998  return (char *)p;
    28912999}
     
    28943002/* Try to interpret LINE (a null-terminated string) as a variable definition.
    28953003
    2896    If LINE was recognized as a variable definition, a pointer to its `struct
     3004   If LINE was recognized as a variable definition, a pointer to its 'struct
    28973005   variable' is returned.  If LINE is not a variable definition, NULL is
    28983006   returned.  */
    28993007
    29003008struct variable *
    2901 assign_variable_definition (struct variable *v, char *line IF_WITH_VALUE_LENGTH_PARAM(char *eos))
    2902 {
    2903   char *beg;
    2904   char *end;
    2905   enum variable_flavor flavor;
     3009assign_variable_definition (struct variable *v, const char *line IF_WITH_VALUE_LENGTH_PARAM(char *eos))
     3010{
    29063011#ifndef CONFIG_WITH_VALUE_LENGTH
    29073012  char *name;
    29083013#endif
    29093014
    2910   beg = next_token (line);
    2911   line = parse_variable_definition (beg, &flavor);
    2912   if (!line)
     3015  if (!parse_variable_definition (line, v))
    29133016    return NULL;
    29143017
    2915   end = line - (flavor == f_recursive ? 1 : 2);
    2916   while (end > beg && isblank ((unsigned char)end[-1]))
    2917     --end;
    2918   line = next_token (line);
    2919   v->value = line;
    2920   v->flavor = flavor;
    29213018#ifdef CONFIG_WITH_VALUE_LENGTH
    2922   v->value_alloc_len = ~(unsigned int)0;
    2923   v->value_length = eos != NULL ? eos - line : -1;
    2924   assert (eos == NULL || strchr (line, '\0') == eos);
    2925 # ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
    2926   v->rdonly_val = 0;
    2927 # endif
     3019  if (eos)
     3020    {
     3021      v->value_length = eos - v->value;
     3022      assert (strchr (v->value, '\0') == eos);
     3023    }
    29283024#endif
    29293025
    29303026  /* Expand the name, so "$(foo)bar = baz" works.  */
    29313027#ifndef CONFIG_WITH_VALUE_LENGTH
    2932   name = alloca (end - beg + 1);
    2933   memcpy (name, beg, end - beg);
    2934   name[end - beg] = '\0';
     3028  name = alloca (v->length + 1);
     3029  memcpy (name, v->name, v->length);
     3030  name[v->length] = '\0';
    29353031  v->name = allocated_variable_expand (name);
    29363032#else  /* CONFIG_WITH_VALUE_LENGTH */
    2937   v->name = allocated_variable_expand_2 (beg, end - beg, NULL);
     3033  v->name = allocated_variable_expand_2 (v->name, v->length, NULL);
    29383034#endif /* CONFIG_WITH_VALUE_LENGTH */
    29393035
    29403036  if (v->name[0] == '\0')
    2941     fatal (&v->fileinfo, _("empty variable name"));
     3037    O (fatal, &v->fileinfo, _("empty variable name"));
    29423038
    29433039  return v;
     
    29543050   See the comments for assign_variable_definition().
    29553051
    2956    If LINE was recognized as a variable definition, a pointer to its `struct
     3052   If LINE was recognized as a variable definition, a pointer to its 'struct
    29573053   variable' is returned.  If LINE is not a variable definition, NULL is
    29583054   returned.  */
    29593055
    29603056struct variable *
    2961 try_variable_definition (const struct floc *flocp, char *line
     3057try_variable_definition (const floc *flocp, const char *line
    29623058                         IF_WITH_VALUE_LENGTH_PARAM(char *eos),
    29633059                         enum variable_origin origin, int target_var)
     
    30253121  switch (v->origin)
    30263122    {
     3123    case o_automatic:
     3124      origin = _("automatic");
     3125      break;
    30273126    case o_default:
    30283127      origin = _("default");
     
    30413140      break;
    30423141    case o_override:
    3043       origin = _("`override' directive");
    3044       break;
    3045     case o_automatic:
    3046       origin = _("automatic");
     3142      origin = _("'override' directive");
    30473143      break;
    30483144#ifdef CONFIG_WITH_LOCAL_VARIABLES
     
    30613157#ifndef KMK
    30623158  if (v->fileinfo.filenm)
    3063     printf (_(" (from `%s', line %lu)"),
    3064             v->fileinfo.filenm, v->fileinfo.lineno);
     3159    printf (_(" (from '%s', line %lu)"),
     3160            v->fileinfo.filenm, v->fileinfo.lineno + v->fileinfo.offset);
    30653161#else  /* KMK */
    30663162  if (alias->fileinfo.filenm)
     
    31393235  fputs (prefix, stdout);
    31403236
    3141   /* Is this a `define'?  */
     3237  /* Is this a 'define'?  */
    31423238  if (v->recursive && strchr (v->value, '\n') != 0)
    31433239#ifndef KMK /** @todo language feature for aliases */
     
    31593255      p = next_token (v->value);
    31603256      if (p != v->value && *p == '\0')
    3161         /* All whitespace.  */
    3162         printf ("$(subst ,,%s)", v->value);
     3257        /* All whitespace.  */
     3258        printf ("$(subst ,,%s)", v->value);
    31633259      else if (v->recursive)
    3164         fputs (v->value, stdout);
     3260        fputs (v->value, stdout);
    31653261      else
    3166         /* Double up dollar signs.  */
    3167         for (p = v->value; *p != '\0'; ++p)
    3168           {
    3169             if (*p == '$')
    3170               putchar ('$');
    3171             putchar (*p);
    3172           }
     3262        /* Double up dollar signs.  */
     3263        for (p = v->value; *p != '\0'; ++p)
     3264          {
     3265            if (*p == '$')
     3266              putchar ('$');
     3267            putchar (*p);
     3268          }
    31733269      putchar ('\n');
    31743270    }
     3271}
     3272
     3273
     3274static void
     3275print_auto_variable (const void *item, void *arg)
     3276{
     3277  const struct variable *v = item;
     3278
     3279  if (v->origin == o_automatic)
     3280    print_variable (item, arg);
     3281}
     3282
     3283
     3284static void
     3285print_noauto_variable (const void *item, void *arg)
     3286{
     3287  const struct variable *v = item;
     3288
     3289  if (v->origin != o_automatic)
     3290    print_variable (item, arg);
    31753291}
    31763292
     
    31793295   the actual variable definitions (everything else is comments).  */
    31803296
     3297#ifndef KMK
     3298static
     3299#endif
    31813300void
    3182 print_variable_set (struct variable_set *set, char *prefix)
     3301print_variable_set (struct variable_set *set, const char *prefix, int pauto)
    31833302{
    31843303#if defined (CONFIG_WITH_COMPILER) || defined (CONFIG_WITH_MAKE_STATS)
     
    31963315#endif
    31973316
    3198   hash_map_arg (&set->table, print_variable, prefix);
     3317  hash_map_arg (&set->table, (pauto ? print_auto_variable : print_variable),
     3318                (void *)prefix);
    31993319
    32003320  if (set->table.ht_fill)
     
    32663386  puts (_("\n# Variables\n"));
    32673387
    3268   print_variable_set (&global_variable_set, "");
     3388  print_variable_set (&global_variable_set, "", 0);
    32693389
    32703390  puts (_("\n# Pattern-specific Variable Values"));
     
    32723392  {
    32733393    struct pattern_var *p;
    3274     int rules = 0;
     3394    unsigned int rules = 0;
    32753395
    32763396    for (p = pattern_vars; p != 0; p = p->next)
     
    32783398        ++rules;
    32793399        printf ("\n%s :\n", p->target);
    3280         print_variable (&p->variable, "# ");
     3400        print_variable (&p->variable, (void *)"# ");
    32813401      }
    32823402
     
    33083428{
    33093429  if (file->variables != 0)
    3310     print_variable_set (file->variables->set, "# ");
     3430    print_variable_set (file->variables->set, "# ", 1);
     3431}
     3432
     3433void
     3434print_target_variables (const struct file *file)
     3435{
     3436  if (file->variables != 0)
     3437    {
     3438      int l = strlen (file->name);
     3439      char *t = alloca (l + 3);
     3440
     3441      strcpy (t, file->name);
     3442      t[l] = ':';
     3443      t[l+1] = ' ';
     3444      t[l+2] = '\0';
     3445
     3446      hash_map_arg (&file->variables->set->table, print_noauto_variable, t);
     3447    }
    33113448}
    33123449
     
    33213458    return;
    33223459
    3323   /*
    3324    * If done this before, don't leak memory unnecessarily.
    3325    * Free the previous entry before allocating new one.
    3326    */
    3327   if (environ_path)
    3328     free (environ_path);
    3329 
    3330   /*
    3331    * Create something WINDOWS32 world can grok
    3332    */
     3460  /* If done this before, free the previous entry before allocating new one.  */
     3461  free (environ_path);
     3462
     3463  /* Create something WINDOWS32 world can grok.  */
    33333464  convert_Path_to_windows32 (path, ';');
    33343465  environ_path = xstrdup (concat (3, "PATH", "=", path));
Note: See TracChangeset for help on using the changeset viewer.