Ignore:
Timestamp:
May 16, 2005, 6:54:02 PM (20 years ago)
Author:
bird
Message:

Current make snaphot, 2005-05-16.

Location:
branches/GNU/src/gmake
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/gmake

    • Property svn:ignore
      •  

        old new  
        3434README.DOS
        3535README.W32
         36README.OS2
        3637aclocal.m4
        3738autom4te.cache
  • branches/GNU/src/gmake/read.c

    r153 r280  
    7979    unsigned int if_cmds;       /* Depth of conditional nesting.  */
    8080    unsigned int allocated;     /* Elts allocated in following arrays.  */
    81     char *ignoring;             /* Are we ignoring or interepreting?  */
     81    char *ignoring;             /* Are we ignoring or interpreting?
     82                                   0=interpreting, 1=not yet interpreted,
     83                                   2=already interpreted */
    8284    char *seen_else;            /* Have we already seen an `else'?  */
    8385  };
     
    131133                               enum variable_origin origin,
    132134                               struct ebuffer *ebuf));
    133 static int conditional_line PARAMS ((char *line, const struct floc *flocp));
     135static int conditional_line PARAMS ((char *line, int len, const struct floc *flocp));
    134136static void record_files PARAMS ((struct nameseq *filenames, char *pattern, char *pattern_percent,
    135137                        struct dep *deps, unsigned int cmds_started, char *commands,
    136138                        unsigned int commands_idx, int two_colon,
    137                         int have_sysv_atvar,
    138                         const struct floc *flocp, int set_default));
     139                        const struct floc *flocp));
    139140static void record_target_var PARAMS ((struct nameseq *filenames, char *defn,
    140141                                       enum variable_origin origin,
     
    256257              d->file->dontcare = 1;
    257258              d->ignore_mtime = 0;
     259              d->need_2nd_expansion = 0;
    258260              /* Tell update_goal_chain to bail out as soon as this file is
    259261                 made, and main not to die if we can't make this file.  */
     
    371373  deps->file = lookup_file (filename);
    372374  if (deps->file == 0)
    373     {
    374       deps->file = enter_file (xstrdup (filename));
    375       if (flags & RM_DONTCARE)
    376         deps->file->dontcare = 1;
    377     }
     375    deps->file = enter_file (xstrdup (filename));
    378376  if (filename != ebuf.floc.filenm)
    379377    free (filename);
     
    381379  deps->changed = flags;
    382380  deps->ignore_mtime = 0;
     381  deps->need_2nd_expansion = 0;
     382  if (flags & RM_DONTCARE)
     383    deps->file->dontcare = 1;
    383384
    384385  /* If the makefile can't be found at all, give up entirely.  */
     
    412413
    413414  free (ebuf.bufstart);
     415  alloca (0);
    414416  return r;
    415417}
     
    443445  reading_file = curfile;
    444446
     447  alloca (0);
    445448  return r;
    446449}
     
    464467  int ignoring = 0, in_ignored_define = 0;
    465468  int no_targets = 0;           /* Set when reading a rule without targets.  */
    466   int have_sysv_atvar = 0;
    467469  struct nameseq *filenames = 0;
    468470  struct dep *deps = 0;
     
    481483          record_files (filenames, pattern, pattern_percent, deps,            \
    482484                        cmds_started, commands, commands_idx, two_colon,      \
    483                         have_sysv_atvar, &fi, set_default);                   \
     485                        &fi);                                                 \
    484486        }                                                                     \
    485487      filenames = 0;                                                          \
     
    618620         following lines.  */
    619621
    620       if (!in_ignored_define
    621           && (word1eq ("ifdef") || word1eq ("ifndef")
    622               || word1eq ("ifeq") || word1eq ("ifneq")
    623               || word1eq ("else") || word1eq ("endif")))
    624         {
    625           int i = conditional_line (p, fstart);
    626           if (i < 0)
    627             fatal (fstart, _("invalid syntax in conditional"));
    628 
    629           ignoring = i;
    630           continue;
     622      if (!in_ignored_define)
     623        {
     624          int i = conditional_line (p, len, fstart);
     625          if (i != -2)
     626            {
     627              if (i == -1)
     628                fatal (fstart, _("invalid syntax in conditional"));
     629
     630              ignoring = i;
     631              continue;
     632            }
    631633        }
    632634
     
    853855        goto rule_complete;
    854856
     857      /* This line starts with a tab but was not caught above because there
     858         was no preceding target, and the line might have been usable as a
     859         variable definition.  But now we know it is definitely lossage.  */
    855860      if (line[0] == '\t')
    856         {
    857           p = collapsed;        /* Ignore comments, etc.  */
    858           while (isblank ((unsigned char)*p))
    859             ++p;
    860           if (*p == '\0')
    861             /* The line is completely blank; that is harmless.  */
    862             continue;
    863 
    864           /* This line starts with a tab but was not caught above
    865              because there was no preceding target, and the line
    866              might have been usable as a variable definition.
    867              But now we know it is definitely lossage.  */
    868           fatal(fstart, _("commands commence before first target"));
    869         }
     861        fatal(fstart, _("commands commence before first target"));
    870862
    871863      /* This line describes some target files.  This is complicated by
     
    886878        unsigned int len, plen = 0;
    887879        char *colonp;
     880        const char *end, *beg; /* Helpers for whitespace stripping. */
    888881
    889882        /* Record the previous rule.  */
     
    934927
    935928        p2 = variable_expand_string(NULL, lb_next, len);
     929
    936930        while (1)
    937931          {
     
    10401034        if (*lb_next != '\0')
    10411035          {
    1042             unsigned int l = p - variable_buffer;
    1043             unsigned int l2 = p2 - variable_buffer;
     1036            unsigned int l = p2 - variable_buffer;
    10441037            plen = strlen (p2);
    10451038            (void) variable_buffer_output (p2+plen,
    10461039                                           lb_next, strlen (lb_next)+1);
    1047             p = variable_buffer + l;
    1048             p2 = variable_buffer + l2;
     1040            p2 = variable_buffer + l;
    10491041          }
    10501042
     
    11121104              }
    11131105          }
    1114 
    1115         /* Do any of the prerequisites appear to have $@ etc.?  */
    1116         have_sysv_atvar = 0;
    1117         if (!posix_pedantic)
    1118           for (p = strchr (p2, '$'); p != 0; p = strchr (p+1, '$'))
    1119             if (p[1] == '@' || ((p[1] == '(' || p[1] == '{') && p[2] == '@'))
    1120               {
    1121                 have_sysv_atvar = 1;
    1122                 break;
    1123               }
    11241106
    11251107        /* Is this a static pattern rule: `target: %targ: %dep; ...'?  */
     
    11871169          pattern = 0;
    11881170
    1189         /* Parse the dependencies.  */
    1190         deps = (struct dep *)
    1191           multi_glob (parse_file_seq (&p2, '|', sizeof (struct dep), 1),
    1192                       sizeof (struct dep));
    1193         if (*p2)
     1171        /* Strip leading and trailing whitespaces. */
     1172        beg = p2;
     1173        end = beg + strlen (beg) - 1;
     1174        strip_whitespace (&beg, &end);
     1175
     1176        if (beg <= end && *beg != '\0')
    11941177          {
    1195             /* Files that follow '|' are special prerequisites that
    1196                need only exist in order to satisfy the dependency.
    1197                Their modification times are irrelevant.  */
    1198             struct dep **deps_ptr = &deps;
    1199             struct dep *d;
    1200             for (deps_ptr = &deps; *deps_ptr; deps_ptr = &(*deps_ptr)->next)
    1201               ;
    1202             ++p2;
    1203             *deps_ptr = (struct dep *)
    1204               multi_glob (parse_file_seq (&p2, '\0', sizeof (struct dep), 1),
    1205                           sizeof (struct dep));
    1206             for (d = *deps_ptr; d != 0; d = d->next)
    1207               d->ignore_mtime = 1;
     1178            char *top;
     1179            const char *fromp = beg;
     1180
     1181            /* Make a copy of the dependency string.  Note if we find '$'.  */
     1182            deps = (struct dep*) xmalloc (sizeof (struct dep));
     1183            deps->next = 0;
     1184            deps->name = top = (char *) xmalloc (end - beg + 2);
     1185            deps->need_2nd_expansion = 0;
     1186            while (fromp <= end)
     1187              {
     1188                if (*fromp == '$')
     1189                  deps->need_2nd_expansion = 1;
     1190                *(top++) = *(fromp++);
     1191              }
     1192            *top = '\0';
     1193            deps->file = 0;
    12081194          }
     1195        else
     1196          deps = 0;
    12091197
    12101198        commands_idx = 0;
     
    12251213            commands_idx += len;
    12261214            commands[commands_idx++] = '\n';
     1215          }
     1216
     1217        /* Determine if this target should be made default. We used to do
     1218           this in record_files() but because of the delayed target recording
     1219           and because preprocessor directives are legal in target's commands
     1220           it is too late. Consider this fragment for example:
     1221
     1222           foo:
     1223
     1224           ifeq ($(.DEFAULT_GOAL),foo)
     1225              ...
     1226           endif
     1227
     1228           Because the target is not recorded until after ifeq directive is
     1229           evaluated the .DEFAULT_GOAL does not contain foo yet as one
     1230           would expect. Because of this we have to move some of the logic
     1231           here.  */
     1232
     1233        if (**default_goal_name == '\0' && set_default)
     1234          {
     1235            char* name;
     1236            struct dep *d;
     1237            struct nameseq *t = filenames;
     1238
     1239            for (; t != 0; t = t->next)
     1240              {
     1241                int reject = 0;
     1242                name = t->name;
     1243
     1244                /* We have nothing to do if this is an implicit rule. */
     1245                if (strchr (name, '%') != 0)
     1246                  break;
     1247
     1248                /* See if this target's name does not start with a `.',
     1249                   unless it contains a slash.  */
     1250                if (*name == '.' && strchr (name, '/') == 0
     1251#ifdef HAVE_DOS_PATHS
     1252                    && strchr (name, '\\') == 0
     1253#endif
     1254                    )
     1255                  continue;
     1256
     1257
     1258                /* If this file is a suffix, don't let it be
     1259                   the default goal file.  */
     1260                for (d = suffix_file->deps; d != 0; d = d->next)
     1261                  {
     1262                    register struct dep *d2;
     1263                    if (*dep_name (d) != '.' && streq (name, dep_name (d)))
     1264                      {
     1265                        reject = 1;
     1266                        break;
     1267                      }
     1268                    for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
     1269                      {
     1270                        register unsigned int len = strlen (dep_name (d2));
     1271                        if (!strneq (name, dep_name (d2), len))
     1272                          continue;
     1273                        if (streq (name + len, dep_name (d)))
     1274                          {
     1275                            reject = 1;
     1276                            break;
     1277                          }
     1278                      }
     1279
     1280                    if (reject)
     1281                      break;
     1282                  }
     1283
     1284                if (!reject)
     1285                  {
     1286                    define_variable_global (".DEFAULT_GOAL", 13, t->name,
     1287                                            o_file, 0, NILF);
     1288                    break;
     1289                  }
     1290              }
    12271291          }
    12281292
     
    12831347      char *line;
    12841348
     1349      nlines = readline (ebuf);
    12851350      ebuf->floc.lineno += nlines;
    1286       nlines = readline (ebuf);
    12871351
    12881352      /* If there is nothing left to eval, we're done. */
     
    13651429   current makefile.  They are used for error messages.
    13661430
    1367    Value is -1 if the line is invalid,
     1431   Value is -2 if the line is not a conditional at all,
     1432   -1 if the line is an invalid conditional,
    13681433   0 if following text should be interpreted,
    13691434   1 if following text should be ignored.  */
    13701435
    13711436static int
    1372 conditional_line (char *line, const struct floc *flocp)
     1437conditional_line (char *line, int len, const struct floc *flocp)
    13731438{
    1374   int notdef;
    13751439  char *cmdname;
    1376   register unsigned int i;
    1377 
    1378   if (*line == 'i')
    1379     {
    1380       /* It's an "if..." command.  */
    1381       notdef = line[2] == 'n';
    1382       if (notdef)
    1383         {
    1384           cmdname = line[3] == 'd' ? "ifndef" : "ifneq";
    1385           line += cmdname[3] == 'd' ? 7 : 6;
    1386         }
    1387       else
    1388         {
    1389           cmdname = line[2] == 'd' ? "ifdef" : "ifeq";
    1390           line += cmdname[2] == 'd' ? 6 : 5;
    1391         }
    1392     }
     1440  enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, c_else, c_endif } cmdtype;
     1441  unsigned int i;
     1442  unsigned int o;
     1443
     1444  /* Compare a word, both length and contents. */
     1445#define word1eq(s)      (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1))
     1446#define chkword(s, t)   if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
     1447
     1448  /* Make sure this line is a conditional.  */
     1449  chkword ("ifdef", c_ifdef)
     1450  else chkword ("ifndef", c_ifndef)
     1451  else chkword ("ifeq", c_ifeq)
     1452  else chkword ("ifneq", c_ifneq)
     1453  else chkword ("else", c_else)
     1454  else chkword ("endif", c_endif)
    13931455  else
    1394     {
    1395       /* It's an "else" or "endif" command.  */
    1396       notdef = line[1] == 'n';
    1397       cmdname = notdef ? "endif" : "else";
    1398       line += notdef ? 5 : 4;
    1399     }
    1400 
    1401   line = next_token (line);
    1402 
    1403   if (*cmdname == 'e')
     1456    return -2;
     1457
     1458  /* Found one: skip past it and any whitespace after it.  */
     1459  line = next_token (line + len);
     1460
     1461#define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname)
     1462
     1463  /* An 'endif' cannot contain extra text, and reduces the if-depth by 1  */
     1464  if (cmdtype == c_endif)
    14041465    {
    14051466      if (*line != '\0')
    1406         error (flocp, _("Extraneous text after `%s' directive"), cmdname);
    1407       /* "Else" or "endif".  */
    1408       if (conditionals->if_cmds == 0)
     1467        EXTRANEOUS ();
     1468
     1469      if (!conditionals->if_cmds)
    14091470        fatal (flocp, _("extraneous `%s'"), cmdname);
    1410       /* NOTDEF indicates an `endif' command.  */
    1411       if (notdef)
    1412         --conditionals->if_cmds;
    1413       else if (conditionals->seen_else[conditionals->if_cmds - 1])
    1414         fatal (flocp, _("only one `else' per conditional"));
     1471
     1472      --conditionals->if_cmds;
     1473
     1474      goto DONE;
     1475    }
     1476
     1477  /* An 'else' statement can either be simple, or it can have another
     1478     conditional after it.  */
     1479  if (cmdtype == c_else)
     1480    {
     1481      const char *p;
     1482
     1483      if (!conditionals->if_cmds)
     1484        fatal (flocp, _("extraneous `%s'"), cmdname);
     1485
     1486      o = conditionals->if_cmds - 1;
     1487
     1488      if (conditionals->seen_else[o])
     1489        fatal (flocp, _("only one `else' per conditional"));
     1490
     1491      /* Change the state of ignorance.  */
     1492      switch (conditionals->ignoring[o])
     1493        {
     1494          case 0:
     1495            /* We've just been interpreting.  Never do it again.  */
     1496            conditionals->ignoring[o] = 2;
     1497            break;
     1498          case 1:
     1499            /* We've never interpreted yet.  Maybe this time!  */
     1500            conditionals->ignoring[o] = 0;
     1501            break;
     1502        }
     1503
     1504      /* It's a simple 'else'.  */
     1505      if (*line == '\0')
     1506        {
     1507          conditionals->seen_else[o] = 1;
     1508          goto DONE;
     1509        }
     1510
     1511      /* The 'else' has extra text.  That text must be another conditional
     1512         and cannot be an 'else' or 'endif'.  */
     1513
     1514      /* Find the length of the next word.  */
     1515      for (p = line+1; *p != '\0' && !isspace ((unsigned char)*p); ++p)
     1516        ;
     1517      len = p - line;
     1518
     1519      /* If it's 'else' or 'endif' or an illegal conditional, fail.  */
     1520      if (word1eq("else") || word1eq("endif")
     1521          || conditional_line (line, len, flocp) < 0)
     1522        EXTRANEOUS ();
    14151523      else
    1416         {
    1417           /* Toggle the state of ignorance.  */
    1418           conditionals->ignoring[conditionals->if_cmds - 1]
    1419             = !conditionals->ignoring[conditionals->if_cmds - 1];
    1420           /* Record that we have seen an `else' in this conditional.
    1421              A second `else' will be erroneous.  */
    1422           conditionals->seen_else[conditionals->if_cmds - 1] = 1;
    1423         }
    1424       for (i = 0; i < conditionals->if_cmds; ++i)
    1425         if (conditionals->ignoring[i])
    1426           return 1;
    1427       return 0;
     1524        {
     1525          /* conditional_line() created a new level of conditional.
     1526             Raise it back to this level.  */
     1527          if (conditionals->ignoring[o] < 2)
     1528            conditionals->ignoring[o] = conditionals->ignoring[o+1];
     1529          --conditionals->if_cmds;
     1530        }
     1531
     1532      goto DONE;
    14281533    }
    14291534
     
    14351540    }
    14361541
    1437   ++conditionals->if_cmds;
     1542  o = conditionals->if_cmds++;
    14381543  if (conditionals->if_cmds > conditionals->allocated)
    14391544    {
     
    14461551
    14471552  /* Record that we have seen an `if...' but no `else' so far.  */
    1448   conditionals->seen_else[conditionals->if_cmds - 1] = 0;
     1553  conditionals->seen_else[o] = 0;
    14491554
    14501555  /* Search through the stack to see if we're already ignoring.  */
    1451   for (i = 0; i < conditionals->if_cmds - 1; ++i)
     1556  for (i = 0; i < o; ++i)
    14521557    if (conditionals->ignoring[i])
    14531558      {
    1454         /* We are already ignoring, so just push a level
    1455            to match the next "else" or "endif", and keep ignoring.
    1456            We don't want to expand variables in the condition.  */
    1457         conditionals->ignoring[conditionals->if_cmds - 1] = 1;
     1559        /* We are already ignoring, so just push a level to match the next
     1560           "else" or "endif", and keep ignoring.  We don't want to expand
     1561           variables in the condition.  */
     1562        conditionals->ignoring[o] = 1;
    14581563        return 1;
    14591564      }
    14601565
    1461   if (cmdname[notdef ? 3 : 2] == 'd')
     1566  if (cmdtype == c_ifdef || cmdtype == c_ifndef)
    14621567    {
    1463       /* "Ifdef" or "ifndef".  */
    14641568      char *var;
    14651569      struct variable *v;
    1466       register char *p;
     1570      char *p;
    14671571
    14681572      /* Expand the thing we're looking up, so we can use indirect and
     
    14781582
    14791583      var[i] = '\0';
    1480       v = lookup_variable (var, strlen (var));
    1481       conditionals->ignoring[conditionals->if_cmds - 1]
    1482         = (v != 0 && *v->value != '\0') == notdef;
     1584      v = lookup_variable (var, i);
     1585
     1586      conditionals->ignoring[o] =
     1587        ((v != 0 && *v->value != '\0') == (cmdtype == c_ifndef));
    14831588
    14841589      free (var);
     
    14981603      if (termin == ',')
    14991604        {
    1500           register int count = 0;
     1605          int count = 0;
    15011606          for (; *line != '\0'; ++line)
    15021607            if (*line == '(')
     
    15721677      line = next_token (++line);
    15731678      if (*line != '\0')
    1574         error (flocp, _("Extraneous text after `%s' directive"), cmdname);
     1679        EXTRANEOUS ();
    15751680
    15761681      s2 = variable_expand (s2);
    1577       conditionals->ignoring[conditionals->if_cmds - 1]
    1578         = streq (s1, s2) == notdef;
     1682      conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq));
    15791683    }
    15801684
     1685 DONE:
    15811686  /* Search through the stack to see if we're ignoring.  */
    15821687  for (i = 0; i < conditionals->if_cmds; ++i)
     
    16941799          p = create_pattern_var (name, percent);
    16951800          p->variable.fileinfo = *flocp;
     1801          /* I don't think this can fail since we already determined it was a
     1802             variable definition.  */
    16961803          v = parse_variable_definition (&p->variable, defn);
    1697           v->value = xstrdup (v->value);
    1698           if (!v)
    1699             error (flocp, _("Malformed pattern-specific variable definition"));
     1804          assert (v != 0);
     1805
     1806          if (v->flavor == f_simple)
     1807            v->value = allocated_variable_expand (v->value);
     1808          else
     1809            v->value = xstrdup (v->value);
     1810
    17001811          fname = p->target;
    17011812        }
     
    17711882              struct dep *deps, unsigned int cmds_started, char *commands,
    17721883              unsigned int commands_idx, int two_colon,
    1773               int have_sysv_atvar, const struct floc *flocp, int set_default)
     1884              const struct floc *flocp)
    17741885{
    17751886  struct nameseq *nextf;
     
    17781889  char **targets = 0, **target_percents = 0;
    17791890  struct commands *cmds;
     1891
     1892  /* If we've already snapped deps, that means we're in an eval being
     1893     resolved after the makefiles have been read in.  We can't add more rules
     1894     at this time, since they won't get snapped and we'll get core dumps.
     1895     See Savannah bug # 12124.  */
     1896  if (snapped_deps)
     1897    fatal (flocp, _("prerequisites cannot be defined in command scripts"));
    17801898
    17811899  if (commands_idx > 0)
     
    18431961      /* If there are multiple filenames, copy the chain DEPS
    18441962         for all but the last one.  It is not safe for the same deps
    1845          to go in more than one place in the data base.  */
     1963         to go in more than one place in the database.  */
    18461964      this = nextf != 0 ? copy_dep_chain (deps) : deps;
    18471965
     
    18601978            }
    18611979          else
    1862             {
    1863               /* We use patsubst_expand to do the work of translating
    1864                  the target pattern, the target's name and the dependencies'
    1865                  patterns into plain dependency names.  */
    1866               char *buffer = variable_expand ("");
    1867 
    1868               for (d = this; d != 0; d = d->next)
    1869                 {
    1870                   char *o;
    1871                   char *percent = find_percent (d->name);
    1872                   if (percent == 0)
    1873                     continue;
    1874                   o = patsubst_expand (buffer, name, pattern, d->name,
    1875                                        pattern_percent, percent);
    1876                   /* If the name expanded to the empty string, that's
    1877                      illegal.  */
    1878                   if (o == buffer)
    1879                     fatal (flocp,
    1880                            _("target `%s' leaves prerequisite pattern empty"),
    1881                            name);
    1882                   free (d->name);
    1883                   d->name = savestring (buffer, o - buffer);
    1884                 }
    1885             }
    1886         }
    1887 
    1888       /* If at least one of the dependencies uses $$@ etc. deal with that.
    1889          It would be very nice and very simple to just expand everything, but
    1890          it would break a lot of backward compatibility.  Maybe that's OK
    1891          since we're just emulating a SysV function, and if we do that then
    1892          why not emulate it completely (that's what SysV make does: it
    1893          re-expands the entire prerequisite list, all the time, with $@
    1894          etc. in scope).  But, it would be a pain indeed to document this
    1895          ("iff you use $$@, your prerequisite lists is expanded twice...")
    1896          Ouch.  Maybe better to make the code more complex.  */
    1897 
    1898       if (have_sysv_atvar)
    1899         {
    1900           char *p;
    1901           int tlen = strlen (name);
    1902           char *fnp = strrchr (name, '/');
    1903           int dlen;
    1904           int flen;
    1905 
    1906           if (fnp)
    1907             {
    1908               dlen = fnp - name;
    1909               ++fnp;
    1910               flen = strlen (fnp);
    1911             }
    1912           else
    1913             {
    1914               dlen = 0;
    1915               fnp = name;
    1916               flen = tlen;
    1917             }
    1918 
    1919 
    1920           for (d = this; d != 0; d = d->next)
    1921             for (p = strchr (d->name, '$'); p != 0; p = strchr (p+1, '$'))
     1980            /* We use subst_expand to do the work of translating % to $* in
     1981               the dependency line.  */
     1982
     1983            if (this != 0 && find_percent (this->name) != 0)
    19221984              {
    1923                 char *s = p;
    1924                 char *at;
    1925                 int atlen;
    1926 
    1927                 /* If it's '$@', '$(@', or '${@', it's escaped */
    1928                 if ((++p)[0] == '$'
    1929                     && (p[1] == '@'
    1930                         || ((p[1] == '(' || p[1] == '{') && p[2] == '@')))
    1931                   {
    1932                     bcopy (p, s, strlen (p)+1);
    1933                     continue;
    1934                   }
    1935 
    1936                 /* Maybe found one.  We like anything of any form matching @,
    1937                    [({]@[}):], or [({]@[DF][}):].  */
    1938 
    1939                 if (! (p[0] == '@'
    1940                        || ((p[0] == '(' || p[0] == '{') && (++p)[0] == '@'
    1941                            && (((++p)[0] == ')' || p[0] == '}' || p[0] == ':')
    1942                                || ((p[1] == ')' || p[1] == '}' || p[1] == ':')
    1943                                    && (p[0] == 'D' || p[0] == 'F'))))))
    1944                   continue;
    1945 
    1946                 /* Found one.  Compute the length and string ptr.  Move p
    1947                    past the variable reference.  */
    1948                 switch (p[0])
    1949                   {
    1950                   case 'D':
    1951                     atlen = dlen;
    1952                     at = name;
    1953                     p += 2;
    1954                     break;
    1955 
    1956                   case 'F':
    1957                     atlen = flen;
    1958                     at = fnp;
    1959                     p += 2;
    1960                     break;
    1961 
    1962                   default:
    1963                     atlen = tlen;
    1964                     at = name;
    1965                     ++p;
    1966                     break;
    1967                   }
    1968 
    1969                 /* Get more space.  */
    1970                 {
    1971                   int soff = s - d->name;
    1972                   int poff = p - d->name;
    1973                   d->name = (char *) xrealloc (d->name,
    1974                                                strlen (d->name) + atlen + 1);
    1975                   s = d->name + soff;
    1976                   p = d->name + poff;
    1977                 }
    1978 
    1979                 /* Copy the string over.  */
    1980                 bcopy(p, s+atlen, strlen (p)+1);
    1981                 bcopy(at, s, atlen);
    1982                 p = s + atlen - 1;
     1985                char *o;
     1986                char *buffer = variable_expand ("");
     1987
     1988                o = subst_expand (buffer, this->name, "%", "$*", 1, 2, 0);
     1989
     1990                free (this->name);
     1991                this->name = savestring (buffer, o - buffer);
     1992                this->need_2nd_expansion = 1;
    19831993              }
    1984         }
     1994        }
    19851995
    19861996      if (!two_colon)
     
    20212031          if (cmds != 0)
    20222032            f->cmds = cmds;
     2033
    20232034          /* Defining .SUFFIXES with no dependencies
    20242035             clears out the list of suffixes.  */
     
    20352046              f->deps = 0;
    20362047            }
    2037           else if (f->deps != 0)
     2048          else if (this != 0)
    20382049            {
    20392050              /* Add the file's old deps and the new ones in THIS together.  */
    20402051
    2041               struct dep *firstdeps, *moredeps;
    2042               if (cmds != 0)
    2043                 {
    2044                   /* This is the rule with commands, so put its deps first.
    2045                      The rationale behind this is that $< expands to the
    2046                      first dep in the chain, and commands use $< expecting
    2047                      to get the dep that rule specifies.  */
    2048                   firstdeps = this;
    2049                   moredeps = f->deps;
    2050                 }
    2051               else
    2052                 {
    2053                   /* Append the new deps to the old ones.  */
    2054                   firstdeps = f->deps;
    2055                   moredeps = this;
    2056                 }
    2057 
    2058               if (firstdeps == 0)
    2059                 firstdeps = moredeps;
    2060               else
    2061                 {
    2062                   d = firstdeps;
    2063                   while (d->next != 0)
    2064                     d = d->next;
    2065                   d->next = moredeps;
    2066                 }
    2067 
    2068               f->deps = firstdeps;
     2052              if (f->deps != 0)
     2053                {
     2054                  struct dep **d_ptr = &f->deps;
     2055
     2056                  while ((*d_ptr)->next != 0)
     2057                    d_ptr = &(*d_ptr)->next;
     2058
     2059                  if (cmds != 0)
     2060                    {
     2061                      /* This is the rule with commands, so put its deps
     2062                         last. The rationale behind this is that $< expands
     2063                         to the first dep in the chain, and commands use $<
     2064                         expecting to get the dep that rule specifies.
     2065                         However the second expansion algorithm reverses
     2066                         the order thus we need to make it last here.  */
     2067
     2068                      (*d_ptr)->next = this;
     2069                    }
     2070                  else
     2071                    {
     2072                      /* This is the rule without commands. Put its
     2073                         dependencies at the end but before dependencies
     2074                         from the rule with commands (if any). This way
     2075                         everything appears in makefile order.  */
     2076
     2077                      if (f->cmds != 0)
     2078                        {
     2079                          this->next = *d_ptr;
     2080                          *d_ptr = this;
     2081                        }
     2082                      else
     2083                        (*d_ptr)->next = this;
     2084                    }
     2085                }
     2086              else
     2087                f->deps = this;
     2088
     2089              /* This is a hack. I need a way to communicate to snap_deps()
     2090                 that the last dependency line in this file came with commands
     2091                 (so that logic in snap_deps() can put it in front and all
     2092                 this $< -logic works). I cannot simply rely on file->cmds
     2093                 being not 0 because of the cases like the following:
     2094
     2095                 foo: bar
     2096                 foo:
     2097                     ...
     2098
     2099                 I am going to temporarily "borrow" UPDATING member in
     2100                 `struct file' for this.   */
     2101
     2102              if (cmds != 0)
     2103                f->updating = 1;
    20692104            }
    2070           else
    2071             f->deps = this;
    20722105
    20732106          /* If this is a static pattern rule, set the file's stem to
     
    20792112              char *buffer = variable_expand ("");
    20802113              char *o = patsubst_expand (buffer, name, pattern, percent,
    2081                                          pattern_percent, percent);
     2114                                         pattern_percent+1, percent+1);
    20822115              f->stem = savestring (buffer, o - buffer);
    20832116            }
     
    21152148        }
    21162149
    2117       /* See if this is first target seen whose name does
    2118          not start with a `.', unless it contains a slash.  */
    2119       if (default_goal_file == 0 && set_default
    2120           && (*name != '.' || strchr (name, '/') != 0
    2121 #ifdef HAVE_DOS_PATHS
    2122                            || strchr (name, '\\') != 0
    2123 #endif
    2124               ))
    2125         {
    2126           int reject = 0;
    2127 
    2128           /* If this file is a suffix, don't
    2129              let it be the default goal file.  */
    2130 
    2131           for (d = suffix_file->deps; d != 0; d = d->next)
    2132             {
    2133               register struct dep *d2;
    2134               if (*dep_name (d) != '.' && streq (name, dep_name (d)))
    2135                 {
    2136                   reject = 1;
    2137                   break;
    2138                 }
    2139               for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
    2140                 {
    2141                   register unsigned int len = strlen (dep_name (d2));
    2142                   if (!strneq (name, dep_name (d2), len))
    2143                     continue;
    2144                   if (streq (name + len, dep_name (d)))
    2145                     {
    2146                       reject = 1;
    2147                       break;
    2148                     }
    2149                 }
    2150               if (reject)
    2151                 break;
    2152             }
    2153 
    2154           if (!reject)
    2155             default_goal_file = f;
    2156         }
     2150      /* If this target is a default target, update DEFAULT_GOAL_FILE.  */
     2151      if (strcmp (*default_goal_name, name) == 0
     2152          && (default_goal_file == 0
     2153              || strcmp (default_goal_file->name, name) != 0))
     2154        default_goal_file = f;
    21572155    }
    21582156
     
    24982496readstring (struct ebuffer *ebuf)
    24992497{
    2500   char *p;
     2498  char *eol;
    25012499
    25022500  /* If there is nothing left in this buffer, return 0.  */
    2503   if (ebuf->bufnext > ebuf->bufstart + ebuf->size)
     2501  if (ebuf->bufnext >= ebuf->bufstart + ebuf->size)
    25042502    return -1;
    25052503
     
    25072505     next logical line (taking into account backslash/newline pairs).  */
    25082506
    2509   p = ebuf->buffer = ebuf->bufnext;
     2507  eol = ebuf->buffer = ebuf->bufnext;
    25102508
    25112509  while (1)
    25122510    {
    25132511      int backslash = 0;
    2514 
    2515       /* Find the next newline.  Keep track of backslashes as we look.  */
    2516       for (; *p != '\n' && *p != '\0'; ++p)
    2517         if (*p == '\\')
    2518           backslash = !backslash;
    2519 
    2520       /* If we got to the end of the string or a newline with no backslash,
    2521          we're done. */
    2522       if (*p == '\0' || !backslash)
     2512      char *bol = eol;
     2513      char *p;
     2514
     2515      /* Find the next newline.  At EOS, stop.  */
     2516      eol = p = strchr (eol , '\n');
     2517      if (!eol)
     2518        {
     2519          ebuf->bufnext = ebuf->bufstart + ebuf->size + 1;
     2520          return 0;
     2521        }
     2522
     2523      /* Found a newline; if it's escaped continue; else we're done.  */
     2524      while (p > bol && *(--p) == '\\')
     2525        backslash = !backslash;
     2526      if (!backslash)
    25232527        break;
     2528      ++eol;
    25242529    }
    25252530
    25262531  /* Overwrite the newline char.  */
    2527   *p = '\0';
    2528   ebuf->bufnext = p+1;
     2532  *eol = '\0';
     2533  ebuf->bufnext = eol+1;
    25292534
    25302535  return 0;
Note: See TracChangeset for help on using the changeset viewer.