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/commands.c

    r2027 r2591  
    11/* Command processing 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
     
    4444
    4545
     46#ifndef CONFIG_WITH_STRCACHE2
     47
     48static unsigned long
     49dep_hash_1 (const void *key)
     50{
     51  const struct dep *d = key;
     52  return_STRING_HASH_1 (dep_name (d));
     53}
     54
     55static unsigned long
     56dep_hash_2 (const void *key)
     57{
     58  const struct dep *d = key;
     59  return_STRING_HASH_2 (dep_name (d));
     60}
     61
     62static int
     63dep_hash_cmp (const void *x, const void *y)
     64{
     65  const struct dep *dx = x;
     66  const struct dep *dy = y;
     67  return strcmp (dep_name (dx), dep_name (dy));
     68}
     69
     70
     71#else  /* CONFIG_WITH_STRCACHE2 */
     72
     73/* Exploit the fact that all names are in the string cache. This means equal
     74   names shall have the same storage and there is no need for hashing or
     75   comparing. Use the address as the first hash, avoiding any touching of
     76   the name, and the length as the second. */
     77
     78static unsigned long
     79dep_hash_1 (const void *key)
     80{
     81  const char *name = dep_name ((struct dep const *) key);
     82  assert (strcache2_is_cached (&file_strcache, name));
     83  return (size_t) name / sizeof(void *);
     84}
     85
     86static unsigned long
     87dep_hash_2 (const void *key)
     88{
     89  const char *name = dep_name ((struct dep const *) key);
     90  return strcache2_get_len (&file_strcache, name);
     91}
     92
     93static int
     94dep_hash_cmp (const void *x, const void *y)
     95{
     96  struct dep *dx = (struct dep *) x;
     97  struct dep *dy = (struct dep *) y;
     98  const char *dxname = dep_name (dx);
     99  const char *dyname = dep_name (dy);
     100  int cmp = dxname == dyname ? 0 : 1;
     101
     102  /* check preconds: both cached and the cache contains no duplicates. */
     103  assert (strcache2_is_cached (&file_strcache, dxname));
     104  assert (strcache2_is_cached (&file_strcache, dyname));
     105  assert (cmp == 0 || strcmp (dxname, dyname) != 0);
     106
     107  /* If the names are the same but ignore_mtimes are not equal, one of these
     108     is an order-only prerequisite and one isn't.  That means that we should
     109     remove the one that isn't and keep the one that is.  */
     110
     111  if (!cmp && dx->ignore_mtime != dy->ignore_mtime)
     112    dx->ignore_mtime = dy->ignore_mtime = 0;
     113
     114  return cmp;
     115}
     116
     117#endif /* CONFIG_WITH_STRCACHE2 */
     118
    46119/* Set FILE's automatic variables up.  */
    47120
     
    53126#endif
    54127{
    55   const struct dep *d;
     128  struct dep *d;
    56129  const char *at, *percent, *star, *less;
    57130#ifdef CONFIG_WITH_STRCACHE2
     
    138211    if (!d->ignore_mtime)
    139212      {
    140         less = dep_name (d);
     213        if (!d->need_2nd_expansion)
     214          less = dep_name (d);
    141215        break;
    142216      }
     
    214288    unsigned int len;
    215289
     290    struct hash_table dep_hash;
     291    void **slot;
     292
    216293    /* Compute first the value for $+, which is supposed to contain
    217294       duplicate dependencies as they were listed in the makefile.  */
    218295
    219296    plus_len = 0;
     297    bar_len = 0;
    220298    for (d = file->deps; d != 0; d = d->next)
    221299      if (! d->ignore_mtime)
     300      {
     301        if (!d->need_2nd_expansion)
     302          {
    222303#ifndef CONFIG_WITH_STRCACHE2
    223         plus_len += strlen (dep_name (d)) + 1;
    224 #else
    225         plus_len += strcache2_get_len (&file_strcache, dep_name (d)) + 1;
    226 #endif
     304            if (d->ignore_mtime)
     305              bar_len += strlen (dep_name (d)) + 1;
     306            else
     307              plus_len += strlen (dep_name (d)) + 1;
     308#else
     309            if (d->ignore_mtime)
     310              bar_len += strcache2_get_len (&file_strcache, dep_name (d)) + 1;
     311            else
     312              plus_len += strcache2_get_len (&file_strcache, dep_name (d)) + 1;
     313#endif
     314          }
     315      }
     316
     317    if (bar_len == 0)
     318      bar_len++;
    227319    if (plus_len == 0)
    228320      plus_len++;
     
    230322    if (plus_len > plus_max)
    231323      plus_value = xrealloc (plus_value, plus_max = plus_len);
     324
    232325    cp = plus_value;
    233326
    234327    qmark_len = plus_len + 1;   /* Will be this or less.  */
    235328    for (d = file->deps; d != 0; d = d->next)
    236       if (! d->ignore_mtime)
     329      if (! d->ignore_mtime && ! d->need_2nd_expansion)
    237330        {
    238331          const char *c = dep_name (d);
     
    255348          cp += len;
    256349          *cp++ = FILE_LIST_SEPARATOR;
    257           if (! d->changed)
     350          if (! (d->changed || always_make_flag))
    258351            qmark_len -= len + 1;       /* Don't space in $? for this one.  */
    259352        }
     
    263356    cp[cp > plus_value ? -1 : 0] = '\0';
    264357    DEFINE_VARIABLE ("+", 1, plus_value);
    265 
    266     /* Make sure that no dependencies are repeated.  This does not
    267        really matter for the purpose of updating targets, but it
    268        might make some names be listed twice for $^ and $?.  */
    269 
    270     uniquize_deps (file->deps);
    271 
    272     bar_len = 0;
    273     for (d = file->deps; d != 0; d = d->next)
    274       if (d->ignore_mtime)
    275 #ifndef CONFIG_WITH_STRCACHE2
    276         bar_len += strlen (dep_name (d)) + 1;
    277 #else
    278         bar_len += strcache2_get_len (&file_strcache, dep_name (d)) + 1;
    279 #endif
    280     if (bar_len == 0)
    281       bar_len++;
    282358
    283359    /* Compute the values for $^, $?, and $|.  */
     
    293369    bp = bar_value;
    294370
     371    /* Make sure that no dependencies are repeated in $^, $?, and $|.  It
     372       would be natural to combine the next two loops but we can't do it
     373       because of a situation where we have two dep entries, the first
     374       is order-only and the second is normal (see below).  */
     375
     376    hash_init (&dep_hash, 500, dep_hash_1, dep_hash_2, dep_hash_cmp);
     377
    295378    for (d = file->deps; d != 0; d = d->next)
    296379      {
    297         const char *c = dep_name (d);
    298 
     380        if (d->need_2nd_expansion)
     381          continue;
     382
     383        slot = hash_find_slot (&dep_hash, d);
     384        if (HASH_VACANT (*slot))
     385          hash_insert_at (&dep_hash, d, slot);
     386        else
     387          {
     388            /* Check if the two prerequisites have different ignore_mtime.
     389               If so then we need to "upgrade" one that is order-only.  */
     390
     391            struct dep* hd = (struct dep*) *slot;
     392
     393            if (d->ignore_mtime != hd->ignore_mtime)
     394              d->ignore_mtime = hd->ignore_mtime = 0;
     395          }
     396      }
     397
     398    for (d = file->deps; d != 0; d = d->next)
     399      {
     400        const char *c;
     401
     402        if (d->need_2nd_expansion || hash_find_item (&dep_hash, d) != d)
     403          continue;
     404
     405        c = dep_name (d);
    299406#ifndef NO_ARCHIVES
    300         if (ar_name (c))
     407        if (ar_name (c))
    301408          {
    302409            c = strchr (c, '(') + 1;
     
    313420        if (d->ignore_mtime)
    314421          {
    315             memcpy (bp, c, len);
     422            memcpy (bp, c, len);
    316423            bp += len;
    317424            *bp++ = FILE_LIST_SEPARATOR;
    318425          }
    319426        else
    320           {
     427          {
    321428            memcpy (cp, c, len);
    322429            cp += len;
    323430            *cp++ = FILE_LIST_SEPARATOR;
    324             if (d->changed)
     431            if (d->changed || always_make_flag)
    325432              {
    326433                memcpy (qp, c, len);
     
    331438      }
    332439
     440    hash_free (&dep_hash, 0);
     441
    333442    /* Kill the last spaces and define the variables.  */
    334443
     
    352461      file->org_deps = copy_dep_chain (file->deps);
    353462
    354       uniquize_deps (file->deps);
     463      /** @todo do uniquize_deps (file->deps); in the $(dep-* ) functions, it'll
     464       *        save even more space that way. */
    355465   }
    356466#endif /* CONFIG_WITH_LAZY_DEPS_VARS */
     
    365475chop_commands (struct commands *cmds)
    366476{
    367   const char *p;
    368477  unsigned int nlines, idx;
    369478  char **lines;
     
    375484    return;
    376485
    377   /* Chop CMDS->commands up into lines in CMDS->command_lines.
    378          Also set the corresponding CMDS->lines_flags elements,
    379          and the CMDS->any_recurse flag.  */
    380 
    381   nlines = 5;
    382   lines = xmalloc (5 * sizeof (char *));
    383   idx = 0;
    384   p = cmds->commands;
    385   while (*p != '\0')
    386     {
    387       const char *end = p;
    388     find_end:;
    389       end = strchr (end, '\n');
    390       if (end == 0)
    391         end = p + strlen (p);
    392       else if (end > p && end[-1] == '\\')
     486  /* Chop CMDS->commands up into lines in CMDS->command_lines.  */
     487
     488  if (one_shell)
     489    {
     490      int l = strlen (cmds->commands);
     491
     492      nlines = 1;
     493      lines = xmalloc (nlines * sizeof (char *));
     494      lines[0] = xstrdup (cmds->commands);
     495
     496      /* Strip the trailing newline.  */
     497      if (l > 0 && lines[0][l-1] == '\n')
     498        lines[0][l-1] = '\0';
     499    }
     500  else
     501    {
     502      const char *p;
     503
     504      nlines = 5;
     505      lines = xmalloc (nlines * sizeof (char *));
     506      idx = 0;
     507      p = cmds->commands;
     508      while (*p != '\0')
    393509        {
    394           int backslash = 1;
    395           const char *b;
    396           for (b = end - 2; b >= p && *b == '\\'; --b)
    397             backslash = !backslash;
    398           if (backslash)
     510          const char *end = p;
     511        find_end:;
     512          end = strchr (end, '\n');
     513          if (end == 0)
     514            end = p + strlen (p);
     515          else if (end > p && end[-1] == '\\')
    399516            {
    400               ++end;
    401               goto find_end;
     517              int backslash = 1;
     518              const char *b;
     519              for (b = end - 2; b >= p && *b == '\\'; --b)
     520                backslash = !backslash;
     521              if (backslash)
     522                {
     523                  ++end;
     524                  goto find_end;
     525                }
    402526            }
     527
     528          if (idx == nlines)
     529            {
     530              nlines += 2;
     531              lines = xrealloc (lines, nlines * sizeof (char *));
     532            }
     533          lines[idx++] = xstrndup (p, end - p);
     534          p = end;
     535          if (*p != '\0')
     536            ++p;
    403537        }
    404538
    405       if (idx == nlines)
     539      if (idx != nlines)
    406540        {
    407           nlines += 2;
     541          nlines = idx;
    408542          lines = xrealloc (lines, nlines * sizeof (char *));
    409543        }
    410       lines[idx++] = savestring (p, end - p);
    411       p = end;
    412       if (*p != '\0')
    413         ++p;
    414     }
    415 
    416   if (idx != nlines)
    417     {
    418       nlines = idx;
    419       lines = xrealloc (lines, nlines * sizeof (char *));
    420     }
     544    }
     545
     546  /* Finally, set the corresponding CMDS->lines_flags elements and the
     547     CMDS->any_recurse flag.  */
    421548
    422549  cmds->ncommand_lines = nlines;
     
    429556  cmds->lines_flags = xmalloc (nlines * sizeof (cmds->lines_flags[0]));
    430557#endif
     558
    431559  for (idx = 0; idx < nlines; ++idx)
    432560    {
    433561      int flags = 0;
    434 
    435       for (p = lines[idx];
    436 #ifndef CONFIG_WITH_COMMANDS_FUNC
    437             isblank ((unsigned char)*p) || *p == '-' || *p == '@' || *p == '+';
    438 #else
    439            isblank ((unsigned char)*p) || *p == '-' || *p == '@' || *p == '+' || *p == '%';
    440 #endif
    441            ++p)
    442         switch (*p)
     562      const char *p = lines[idx];
     563
     564      while (isblank (*p) || *p == '-' || *p == '@' || *p == '+' IF_WITH_COMMANDS_FUNC(|| *p == '%'))
     565        switch (*(p++))
    443566          {
    444567          case '+':
Note: See TracChangeset for help on using the changeset viewer.