Ignore:
Timestamp:
Mar 12, 2018, 8:32:29 PM (7 years ago)
Author:
bird
Message:

Imported make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6) from https://git.savannah.gnu.org/git/make.git.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current/rule.c

    r2596 r3138  
    11/* Pattern and suffix rule internals 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"
     
    7573  char *name;
    7674  int namelen;
    77   struct rule *rule, *lastrule;
     75  struct rule *rule;
    7876
    7977  num_pattern_rules = max_pattern_targets = max_pattern_deps = 0;
     
    8381  namelen = 0;
    8482  rule = pattern_rules;
    85   lastrule = 0;
    8683  while (rule != 0)
    8784    {
     
    9390
    9491      if (rule->num > max_pattern_targets)
    95         max_pattern_targets = rule->num;
     92        max_pattern_targets = rule->num;
    9693
    9794      for (dep = rule->deps; dep != 0; dep = dep->next)
    98         {
     95        {
    9996          const char *dname = dep_name (dep);
    10097          unsigned int len = strlen (dname);
     
    112109          ndeps++;
    113110
    114           if (len > max_pattern_dep_length)
    115             max_pattern_dep_length = len;
    116 
    117           if (p != 0 && p2 > p)
    118             {
    119               /* There is a slash before the % in the dep name.
    120                 Extract the directory name.  */
    121               if (p == dname)
    122                 ++p;
    123               if (p - dname > namelen)
    124                 {
    125                   namelen = p - dname;
    126                   name = xrealloc (name, namelen + 1);
    127                 }
    128               memcpy (name, dname, p - dname);
    129               name[p - dname] = '\0';
    130 
    131               /* In the deps of an implicit rule the `changed' flag
    132                 actually indicates that the dependency is in a
    133                 nonexistent subdirectory.  */
    134 
    135               dep->changed = !dir_file_exists_p (name, "");
    136             }
    137           else
    138             /* This dependency does not reside in a subdirectory.  */
    139             dep->changed = 0;
    140         }
     111          if (len > max_pattern_dep_length)
     112            max_pattern_dep_length = len;
     113
     114          if (p != 0 && p2 > p)
     115            {
     116              /* There is a slash before the % in the dep name.
     117                Extract the directory name.  */
     118              if (p == dname)
     119                ++p;
     120              if (p - dname > namelen)
     121                {
     122                  namelen = p - dname;
     123                  name = xrealloc (name, namelen + 1);
     124                }
     125              memcpy (name, dname, p - dname);
     126              name[p - dname] = '\0';
     127
     128              /* In the deps of an implicit rule the 'changed' flag
     129                actually indicates that the dependency is in a
     130                nonexistent subdirectory.  */
     131
     132              dep->changed = !dir_file_exists_p (name, "");
     133            }
     134          else
     135            /* This dependency does not reside in a subdirectory.  */
     136            dep->changed = 0;
     137        }
    141138
    142139      if (ndeps > max_pattern_deps)
    143         max_pattern_deps = ndeps;
    144 
    145       lastrule = rule;
     140        max_pattern_deps = ndeps;
     141
    146142      rule = next;
    147143    }
    148144
    149   if (name != 0)
    150     free (name);
     145  free (name);
    151146}
    152147
     
    155150   TARGET is the target suffix; SOURCE is the source suffix.
    156151   CMDS are the commands.
    157    If TARGET is nil, it means the target pattern should be `(%.o)'.
     152   If TARGET is nil, it means the target pattern should be '(%.o)'.
    158153   If SOURCE is nil, it means there should be no deps.  */
    159154
     
    170165  if (target == 0)
    171166    {
    172       /* Special case: TARGET being nil means we are defining a `.X.a' suffix
    173          rule; the target pattern is always `(%.o)'.  */
     167      /* Special case: TARGET being nil means we are defining a '.X.a' suffix
     168         rule; the target pattern is always '(%.o)'.  */
    174169#ifdef VMS
    175170      *names = strcache_add_len ("(%.obj)", 7);
     
    225220      unsigned int l = strlen (dep_name (d));
    226221      if (l > maxsuffix)
    227         maxsuffix = l;
     222        maxsuffix = l;
    228223    }
    229224
     
    236231
    237232      /* Make a rule that is just the suffix, with no deps or commands.
    238         This rule exists solely to disqualify match-anything rules.  */
     233        This rule exists solely to disqualify match-anything rules.  */
    239234      convert_suffix_rule (dep_name (d), 0, 0);
    240235
    241236      if (d->file->cmds != 0)
    242         /* Record a pattern for this suffix's null-suffix rule.  */
    243         convert_suffix_rule ("", dep_name (d), d->file->cmds);
     237        /* Record a pattern for this suffix's null-suffix rule.  */
     238        convert_suffix_rule ("", dep_name (d), d->file->cmds);
    244239
    245240      /* Add every other suffix to this one and see if it exists as a
     
    249244
    250245      for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
    251         {
     246        {
    252247          struct file *f;
    253248          unsigned int s2len;
    254249
    255           s2len = strlen (dep_name (d2));
     250          s2len = strlen (dep_name (d2));
    256251
    257252          /* Can't build something from itself.  */
    258           if (slen == s2len && streq (dep_name (d), dep_name (d2)))
    259             continue;
    260 
    261           memcpy (rulename + slen, dep_name (d2), s2len + 1);
    262           f = lookup_file (rulename);
    263           if (f == 0 || f->cmds == 0)
    264             continue;
    265 
    266           if (s2len == 2 && rulename[slen] == '.' && rulename[slen + 1] == 'a')
    267             /* A suffix rule `.X.a:' generates the pattern rule `(%.o): %.X'.
    268                It also generates a normal `%.a: %.X' rule below.  */
    269             convert_suffix_rule (NULL, /* Indicates `(%.o)'.  */
    270                                 dep_name (d),
    271                                 f->cmds);
    272 
    273           /* The suffix rule `.X.Y:' is converted
    274              to the pattern rule `%.Y: %.X'.  */
    275           convert_suffix_rule (dep_name (d2), dep_name (d), f->cmds);
    276         }
     253          if (slen == s2len && streq (dep_name (d), dep_name (d2)))
     254            continue;
     255
     256          memcpy (rulename + slen, dep_name (d2), s2len + 1);
     257          f = lookup_file (rulename);
     258          if (f == 0 || f->cmds == 0)
     259            continue;
     260
     261          if (s2len == 2 && rulename[slen] == '.' && rulename[slen + 1] == 'a')
     262            /* A suffix rule '.X.a:' generates the pattern rule '(%.o): %.X'.
     263               It also generates a normal '%.a: %.X' rule below.  */
     264            convert_suffix_rule (NULL, /* Indicates '(%.o)'.  */
     265                                dep_name (d),
     266                                f->cmds);
     267
     268          /* The suffix rule '.X.Y:' is converted
     269             to the pattern rule '%.Y: %.X'.  */
     270          convert_suffix_rule (dep_name (d2), dep_name (d), f->cmds);
     271        }
    277272    }
    278273}
     
    302297    for (i = 0; i < rule->num; ++i)
    303298      {
    304         for (j = 0; j < r->num; ++j)
    305           if (!streq (rule->targets[i], r->targets[j]))
    306             break;
     299        for (j = 0; j < r->num; ++j)
     300          if (!streq (rule->targets[i], r->targets[j]))
     301            break;
    307302        /* If all the targets matched...  */
    308         if (j == r->num)
    309           {
    310             struct dep *d, *d2;
    311             for (d = rule->deps, d2 = r->deps;
    312                 d != 0 && d2 != 0; d = d->next, d2 = d2->next)
    313               if (!streq (dep_name (d), dep_name (d2)))
    314                 break;
    315             if (d == 0 && d2 == 0)
    316               {
    317                 /* All the dependencies matched.  */
    318                 if (override)
    319                   {
    320                     /* Remove the old rule.  */
    321                     freerule (r, lastrule);
    322                     /* Install the new one.  */
    323                     if (pattern_rules == 0)
    324                       pattern_rules = rule;
    325                     else
    326                       last_pattern_rule->next = rule;
    327                     last_pattern_rule = rule;
    328 
    329                     /* We got one.  Stop looking.  */
    330                     goto matched;
    331                   }
    332                 else
    333                   {
    334                     /* The old rule stays intact.  Destroy the new one.  */
    335                     freerule (rule, (struct rule *) 0);
    336                     return 0;
    337                   }
    338               }
    339           }
     303        if (j == r->num)
     304          {
     305            struct dep *d, *d2;
     306            for (d = rule->deps, d2 = r->deps;
     307                d != 0 && d2 != 0; d = d->next, d2 = d2->next)
     308              if (!streq (dep_name (d), dep_name (d2)))
     309                break;
     310            if (d == 0 && d2 == 0)
     311              {
     312                /* All the dependencies matched.  */
     313                if (override)
     314                  {
     315                    /* Remove the old rule.  */
     316                    freerule (r, lastrule);
     317                    /* Install the new one.  */
     318                    if (pattern_rules == 0)
     319                      pattern_rules = rule;
     320                    else
     321                      last_pattern_rule->next = rule;
     322                    last_pattern_rule = rule;
     323
     324                    /* We got one.  Stop looking.  */
     325                    goto matched;
     326                  }
     327                else
     328                  {
     329                    /* The old rule stays intact.  Destroy the new one.  */
     330                    freerule (rule, (struct rule *) 0);
     331                    return 0;
     332                  }
     333              }
     334          }
    340335      }
    341336
     
    346341      /* There was no rule to replace.  */
    347342      if (pattern_rules == 0)
    348         pattern_rules = rule;
     343        pattern_rules = rule;
    349344      else
    350         last_pattern_rule->next = rule;
     345        last_pattern_rule->next = rule;
    351346      last_pattern_rule = rule;
    352347    }
     
    359354   in the structure P points to.  These strings come from one of
    360355   the arrays of default implicit pattern rules.
    361    TERMINAL specifies what the `terminal' field of the rule should be.  */
     356   TERMINAL specifies what the 'terminal' field of the rule should be.  */
    362357
    363358void
     
    365360{
    366361  struct rule *r;
    367   char *ptr;
     362  const char *ptr;
    368363
    369364  r = xmalloc (sizeof (struct rule));
     
    381376
    382377  ptr = p->dep;
    383   r->deps = PARSE_FILE_SEQ (&ptr, struct dep, '\0', NULL, 0);
     378  r->deps = PARSE_SIMPLE_SEQ ((char **)&ptr, struct dep);
    384379
    385380  if (new_pattern_rule (r, 0))
     
    389384      r->cmds->fileinfo.filenm = 0;
    390385      r->cmds->fileinfo.lineno = 0;
     386      r->cmds->fileinfo.offset = 0;
    391387      /* These will all be string literals, but we malloc space for them
    392         anyway because somebody might want to free them later.  */
     388        anyway because somebody might want to free them later.  */
    393389      r->cmds->commands = xstrdup (p->commands);
    394390      r->cmds->command_lines = 0;
     391      r->cmds->recipe_prefix = RECIPEPREFIX_DEFAULT;
    395392    }
    396393}
     
    416413     are ways that they could be in more than one place:
    417414       * If the commands came from a suffix rule, they could also be in
    418        the `struct file's for other suffix rules or plain targets given
     415       the 'struct file's for other suffix rules or plain targets given
    419416       on the same makefile line.
    420417       * If two suffixes that together make a two-suffix rule were each
    421418       given twice in the .SUFFIXES list, and in the proper order, two
    422419       identical pattern rules would be created and the second one would
    423        be discarded here, but both would contain the same `struct commands'
    424        pointer from the `struct file' for the suffix rule.  */
     420       be discarded here, but both would contain the same 'struct commands'
     421       pointer from the 'struct file' for the suffix rule.  */
    425422
    426423  free (rule);
     
    477474/* Print the data base of rules.  */
    478475
    479 static void                     /* Useful to call from gdb.  */
     476static void                     /* Useful to call from gdb.  */
    480477print_rule (struct rule *r)
    481478{
     
    513510
    514511      if (r->terminal)
    515         ++terminal;
     512        ++terminal;
    516513    }
    517514
     
    521518    {
    522519      printf (_("\n# %u implicit rules, %u"), rules, terminal);
    523 #ifndef NO_FLOAT
     520#ifndef NO_FLOAT
    524521      printf (" (%.1f%%)", (double) terminal / (double) rules * 100.0);
    525522#else
    526523      {
    527         int f = (terminal * 1000 + 5) / rules;
    528         printf (" (%d.%d%%)", f/10, f%10);
     524        int f = (terminal * 1000 + 5) / rules;
     525        printf (" (%d.%d%%)", f/10, f%10);
    529526      }
    530527#endif
     
    537534         makefiles and thus count_implicit_rule_limits wasn't called yet.  */
    538535      if (num_pattern_rules != 0)
    539         fatal (NILF, _("BUG: num_pattern_rules is wrong!  %u != %u"),
    540                num_pattern_rules, rules);
    541     }
    542 }
     536        ONN (fatal, NILF, _("BUG: num_pattern_rules is wrong!  %u != %u"),
     537             num_pattern_rules, rules);
     538    }
     539}
Note: See TracChangeset for help on using the changeset viewer.