Changeset 280 for branches/GNU/src/gmake/read.c
- Timestamp:
- May 16, 2005, 6:54:02 PM (20 years ago)
- Location:
- branches/GNU/src/gmake
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gmake
- Property svn:ignore
-
old new 34 34 README.DOS 35 35 README.W32 36 README.OS2 36 37 aclocal.m4 37 38 autom4te.cache
-
- Property svn:ignore
-
branches/GNU/src/gmake/read.c
r153 r280 79 79 unsigned int if_cmds; /* Depth of conditional nesting. */ 80 80 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 */ 82 84 char *seen_else; /* Have we already seen an `else'? */ 83 85 }; … … 131 133 enum variable_origin origin, 132 134 struct ebuffer *ebuf)); 133 static int conditional_line PARAMS ((char *line, const struct floc *flocp));135 static int conditional_line PARAMS ((char *line, int len, const struct floc *flocp)); 134 136 static void record_files PARAMS ((struct nameseq *filenames, char *pattern, char *pattern_percent, 135 137 struct dep *deps, unsigned int cmds_started, char *commands, 136 138 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)); 139 140 static void record_target_var PARAMS ((struct nameseq *filenames, char *defn, 140 141 enum variable_origin origin, … … 256 257 d->file->dontcare = 1; 257 258 d->ignore_mtime = 0; 259 d->need_2nd_expansion = 0; 258 260 /* Tell update_goal_chain to bail out as soon as this file is 259 261 made, and main not to die if we can't make this file. */ … … 371 373 deps->file = lookup_file (filename); 372 374 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)); 378 376 if (filename != ebuf.floc.filenm) 379 377 free (filename); … … 381 379 deps->changed = flags; 382 380 deps->ignore_mtime = 0; 381 deps->need_2nd_expansion = 0; 382 if (flags & RM_DONTCARE) 383 deps->file->dontcare = 1; 383 384 384 385 /* If the makefile can't be found at all, give up entirely. */ … … 412 413 413 414 free (ebuf.bufstart); 415 alloca (0); 414 416 return r; 415 417 } … … 443 445 reading_file = curfile; 444 446 447 alloca (0); 445 448 return r; 446 449 } … … 464 467 int ignoring = 0, in_ignored_define = 0; 465 468 int no_targets = 0; /* Set when reading a rule without targets. */ 466 int have_sysv_atvar = 0;467 469 struct nameseq *filenames = 0; 468 470 struct dep *deps = 0; … … 481 483 record_files (filenames, pattern, pattern_percent, deps, \ 482 484 cmds_started, commands, commands_idx, two_colon, \ 483 have_sysv_atvar, &fi, set_default);\485 &fi); \ 484 486 } \ 485 487 filenames = 0; \ … … 618 620 following lines. */ 619 621 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 } 631 633 } 632 634 … … 853 855 goto rule_complete; 854 856 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. */ 855 860 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")); 870 862 871 863 /* This line describes some target files. This is complicated by … … 886 878 unsigned int len, plen = 0; 887 879 char *colonp; 880 const char *end, *beg; /* Helpers for whitespace stripping. */ 888 881 889 882 /* Record the previous rule. */ … … 934 927 935 928 p2 = variable_expand_string(NULL, lb_next, len); 929 936 930 while (1) 937 931 { … … 1040 1034 if (*lb_next != '\0') 1041 1035 { 1042 unsigned int l = p - variable_buffer; 1043 unsigned int l2 = p2 - variable_buffer; 1036 unsigned int l = p2 - variable_buffer; 1044 1037 plen = strlen (p2); 1045 1038 (void) variable_buffer_output (p2+plen, 1046 1039 lb_next, strlen (lb_next)+1); 1047 p = variable_buffer + l; 1048 p2 = variable_buffer + l2; 1040 p2 = variable_buffer + l; 1049 1041 } 1050 1042 … … 1112 1104 } 1113 1105 } 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 }1124 1106 1125 1107 /* Is this a static pattern rule: `target: %targ: %dep; ...'? */ … … 1187 1169 pattern = 0; 1188 1170 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') 1194 1177 { 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; 1208 1194 } 1195 else 1196 deps = 0; 1209 1197 1210 1198 commands_idx = 0; … … 1225 1213 commands_idx += len; 1226 1214 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 } 1227 1291 } 1228 1292 … … 1283 1347 char *line; 1284 1348 1349 nlines = readline (ebuf); 1285 1350 ebuf->floc.lineno += nlines; 1286 nlines = readline (ebuf);1287 1351 1288 1352 /* If there is nothing left to eval, we're done. */ … … 1365 1429 current makefile. They are used for error messages. 1366 1430 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, 1368 1433 0 if following text should be interpreted, 1369 1434 1 if following text should be ignored. */ 1370 1435 1371 1436 static int 1372 conditional_line (char *line, const struct floc *flocp)1437 conditional_line (char *line, int len, const struct floc *flocp) 1373 1438 { 1374 int notdef;1375 1439 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) 1393 1455 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) 1404 1465 { 1405 1466 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) 1409 1470 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 (); 1415 1523 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; 1428 1533 } 1429 1534 … … 1435 1540 } 1436 1541 1437 ++conditionals->if_cmds;1542 o = conditionals->if_cmds++; 1438 1543 if (conditionals->if_cmds > conditionals->allocated) 1439 1544 { … … 1446 1551 1447 1552 /* 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; 1449 1554 1450 1555 /* 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) 1452 1557 if (conditionals->ignoring[i]) 1453 1558 { 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 expandvariables 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; 1458 1563 return 1; 1459 1564 } 1460 1565 1461 if (cmd name[notdef ? 3 : 2] == 'd')1566 if (cmdtype == c_ifdef || cmdtype == c_ifndef) 1462 1567 { 1463 /* "Ifdef" or "ifndef". */1464 1568 char *var; 1465 1569 struct variable *v; 1466 registerchar *p;1570 char *p; 1467 1571 1468 1572 /* Expand the thing we're looking up, so we can use indirect and … … 1478 1582 1479 1583 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)); 1483 1588 1484 1589 free (var); … … 1498 1603 if (termin == ',') 1499 1604 { 1500 registerint count = 0;1605 int count = 0; 1501 1606 for (; *line != '\0'; ++line) 1502 1607 if (*line == '(') … … 1572 1677 line = next_token (++line); 1573 1678 if (*line != '\0') 1574 error (flocp, _("Extraneous text after `%s' directive"), cmdname);1679 EXTRANEOUS (); 1575 1680 1576 1681 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)); 1579 1683 } 1580 1684 1685 DONE: 1581 1686 /* Search through the stack to see if we're ignoring. */ 1582 1687 for (i = 0; i < conditionals->if_cmds; ++i) … … 1694 1799 p = create_pattern_var (name, percent); 1695 1800 p->variable.fileinfo = *flocp; 1801 /* I don't think this can fail since we already determined it was a 1802 variable definition. */ 1696 1803 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 1700 1811 fname = p->target; 1701 1812 } … … 1771 1882 struct dep *deps, unsigned int cmds_started, char *commands, 1772 1883 unsigned int commands_idx, int two_colon, 1773 int have_sysv_atvar, const struct floc *flocp, int set_default)1884 const struct floc *flocp) 1774 1885 { 1775 1886 struct nameseq *nextf; … … 1778 1889 char **targets = 0, **target_percents = 0; 1779 1890 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")); 1780 1898 1781 1899 if (commands_idx > 0) … … 1843 1961 /* If there are multiple filenames, copy the chain DEPS 1844 1962 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 1963 to go in more than one place in the database. */ 1846 1964 this = nextf != 0 ? copy_dep_chain (deps) : deps; 1847 1965 … … 1860 1978 } 1861 1979 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) 1922 1984 { 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; 1983 1993 } 1984 1994 } 1985 1995 1986 1996 if (!two_colon) … … 2021 2031 if (cmds != 0) 2022 2032 f->cmds = cmds; 2033 2023 2034 /* Defining .SUFFIXES with no dependencies 2024 2035 clears out the list of suffixes. */ … … 2035 2046 f->deps = 0; 2036 2047 } 2037 else if (f->deps != 0)2048 else if (this != 0) 2038 2049 { 2039 2050 /* Add the file's old deps and the new ones in THIS together. */ 2040 2051 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; 2069 2104 } 2070 else2071 f->deps = this;2072 2105 2073 2106 /* If this is a static pattern rule, set the file's stem to … … 2079 2112 char *buffer = variable_expand (""); 2080 2113 char *o = patsubst_expand (buffer, name, pattern, percent, 2081 pattern_percent , percent);2114 pattern_percent+1, percent+1); 2082 2115 f->stem = savestring (buffer, o - buffer); 2083 2116 } … … 2115 2148 } 2116 2149 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; 2157 2155 } 2158 2156 … … 2498 2496 readstring (struct ebuffer *ebuf) 2499 2497 { 2500 char * p;2498 char *eol; 2501 2499 2502 2500 /* 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) 2504 2502 return -1; 2505 2503 … … 2507 2505 next logical line (taking into account backslash/newline pairs). */ 2508 2506 2509 p= ebuf->buffer = ebuf->bufnext;2507 eol = ebuf->buffer = ebuf->bufnext; 2510 2508 2511 2509 while (1) 2512 2510 { 2513 2511 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) 2523 2527 break; 2528 ++eol; 2524 2529 } 2525 2530 2526 2531 /* Overwrite the newline char. */ 2527 * p= '\0';2528 ebuf->bufnext = p+1;2532 *eol = '\0'; 2533 ebuf->bufnext = eol+1; 2529 2534 2530 2535 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.