Changeset 287 for trunk/src/gmake/read.c
- Timestamp:
- May 17, 2005, 1:34:55 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/read.c
r191 r287 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, … … 257 258 d->file->dontcare = 1; 258 259 d->ignore_mtime = 0; 260 d->need_2nd_expansion = 0; 259 261 /* Tell update_goal_chain to bail out as soon as this file is 260 262 made, and main not to die if we can't make this file. */ … … 372 374 deps->file = lookup_file (filename); 373 375 if (deps->file == 0) 374 { 375 deps->file = enter_file (xstrdup (filename)); 376 if (flags & RM_DONTCARE) 377 deps->file->dontcare = 1; 378 } 376 deps->file = enter_file (xstrdup (filename)); 379 377 if (filename != ebuf.floc.filenm) 380 378 free (filename); … … 382 380 deps->changed = flags; 383 381 deps->ignore_mtime = 0; 382 deps->need_2nd_expansion = 0; 383 if (flags & RM_DONTCARE) 384 deps->file->dontcare = 1; 384 385 385 386 /* If the makefile can't be found at all, give up entirely. */ … … 413 414 414 415 free (ebuf.bufstart); 416 alloca (0); 415 417 return r; 416 418 } … … 444 446 reading_file = curfile; 445 447 448 alloca (0); 446 449 return r; 447 450 } … … 465 468 int ignoring = 0, in_ignored_define = 0; 466 469 int no_targets = 0; /* Set when reading a rule without targets. */ 467 int have_sysv_atvar = 0;468 470 struct nameseq *filenames = 0; 469 471 struct dep *deps = 0; … … 482 484 record_files (filenames, pattern, pattern_percent, deps, \ 483 485 cmds_started, commands, commands_idx, two_colon, \ 484 have_sysv_atvar, &fi, set_default);\486 &fi); \ 485 487 } \ 486 488 filenames = 0; \ … … 619 621 following lines. */ 620 622 621 if (!in_ignored_define 622 && (word1eq ("ifdef") || word1eq ("ifndef")623 || word1eq ("ifeq") || word1eq ("ifneq") 624 || word1eq ("else") || word1eq ("endif")))625 626 int i = conditional_line (p, fstart);627 if (i < 0) 628 fatal (fstart, _("invalid syntax in conditional")); 629 630 ignoring = i;631 continue; 623 if (!in_ignored_define) 624 { 625 int i = conditional_line (p, len, fstart); 626 if (i != -2) 627 { 628 if (i == -1) 629 fatal (fstart, _("invalid syntax in conditional")); 630 631 ignoring = i; 632 continue; 633 } 632 634 } 633 635 … … 854 856 goto rule_complete; 855 857 858 /* This line starts with a tab but was not caught above because there 859 was no preceding target, and the line might have been usable as a 860 variable definition. But now we know it is definitely lossage. */ 856 861 if (line[0] == '\t') 857 { 858 p = collapsed; /* Ignore comments, etc. */ 859 while (isblank ((unsigned char)*p)) 860 ++p; 861 if (*p == '\0') 862 /* The line is completely blank; that is harmless. */ 863 continue; 864 865 /* This line starts with a tab but was not caught above 866 because there was no preceding target, and the line 867 might have been usable as a variable definition. 868 But now we know it is definitely lossage. */ 869 fatal(fstart, _("commands commence before first target")); 870 } 862 fatal(fstart, _("commands commence before first target")); 871 863 872 864 /* This line describes some target files. This is complicated by … … 887 879 unsigned int len, plen = 0; 888 880 char *colonp; 881 const char *end, *beg; /* Helpers for whitespace stripping. */ 889 882 890 883 /* Record the previous rule. */ … … 935 928 936 929 p2 = variable_expand_string(NULL, lb_next, len); 930 937 931 while (1) 938 932 { … … 1041 1035 if (*lb_next != '\0') 1042 1036 { 1043 unsigned int l = p - variable_buffer; 1044 unsigned int l2 = p2 - variable_buffer; 1037 unsigned int l = p2 - variable_buffer; 1045 1038 plen = strlen (p2); 1046 1039 (void) variable_buffer_output (p2+plen, 1047 1040 lb_next, strlen (lb_next)+1); 1048 p = variable_buffer + l; 1049 p2 = variable_buffer + l2; 1041 p2 = variable_buffer + l; 1050 1042 } 1051 1043 … … 1113 1105 } 1114 1106 } 1115 1116 /* Do any of the prerequisites appear to have $@ etc.? */1117 have_sysv_atvar = 0;1118 if (!posix_pedantic)1119 for (p = strchr (p2, '$'); p != 0; p = strchr (p+1, '$'))1120 if (p[1] == '@' || ((p[1] == '(' || p[1] == '{') && p[2] == '@'))1121 {1122 have_sysv_atvar = 1;1123 break;1124 }1125 1107 1126 1108 /* Is this a static pattern rule: `target: %targ: %dep; ...'? */ … … 1188 1170 pattern = 0; 1189 1171 1190 /* Parse the dependencies. */ 1191 deps = (struct dep *) 1192 multi_glob (parse_file_seq (&p2, '|', sizeof (struct dep), 1), 1193 sizeof (struct dep)); 1194 if (*p2) 1172 /* Strip leading and trailing whitespaces. */ 1173 beg = p2; 1174 end = beg + strlen (beg) - 1; 1175 strip_whitespace (&beg, &end); 1176 1177 if (beg <= end && *beg != '\0') 1195 1178 { 1196 /* Files that follow '|' are special prerequisites that 1197 need only exist in order to satisfy the dependency. 1198 Their modification times are irrelevant. */ 1199 struct dep **deps_ptr = &deps; 1200 struct dep *d; 1201 for (deps_ptr = &deps; *deps_ptr; deps_ptr = &(*deps_ptr)->next) 1202 ; 1203 ++p2; 1204 *deps_ptr = (struct dep *) 1205 multi_glob (parse_file_seq (&p2, '\0', sizeof (struct dep), 1), 1206 sizeof (struct dep)); 1207 for (d = *deps_ptr; d != 0; d = d->next) 1208 d->ignore_mtime = 1; 1179 char *top; 1180 const char *fromp = beg; 1181 1182 /* Make a copy of the dependency string. Note if we find '$'. */ 1183 deps = (struct dep*) xmalloc (sizeof (struct dep)); 1184 deps->next = 0; 1185 deps->name = top = (char *) xmalloc (end - beg + 2); 1186 deps->need_2nd_expansion = 0; 1187 while (fromp <= end) 1188 { 1189 if (*fromp == '$') 1190 deps->need_2nd_expansion = 1; 1191 *(top++) = *(fromp++); 1192 } 1193 *top = '\0'; 1194 deps->file = 0; 1209 1195 } 1196 else 1197 deps = 0; 1210 1198 1211 1199 commands_idx = 0; … … 1226 1214 commands_idx += len; 1227 1215 commands[commands_idx++] = '\n'; 1216 } 1217 1218 /* Determine if this target should be made default. We used to do 1219 this in record_files() but because of the delayed target recording 1220 and because preprocessor directives are legal in target's commands 1221 it is too late. Consider this fragment for example: 1222 1223 foo: 1224 1225 ifeq ($(.DEFAULT_GOAL),foo) 1226 ... 1227 endif 1228 1229 Because the target is not recorded until after ifeq directive is 1230 evaluated the .DEFAULT_GOAL does not contain foo yet as one 1231 would expect. Because of this we have to move some of the logic 1232 here. */ 1233 1234 if (**default_goal_name == '\0' && set_default) 1235 { 1236 char* name; 1237 struct dep *d; 1238 struct nameseq *t = filenames; 1239 1240 for (; t != 0; t = t->next) 1241 { 1242 int reject = 0; 1243 name = t->name; 1244 1245 /* We have nothing to do if this is an implicit rule. */ 1246 if (strchr (name, '%') != 0) 1247 break; 1248 1249 /* See if this target's name does not start with a `.', 1250 unless it contains a slash. */ 1251 if (*name == '.' && strchr (name, '/') == 0 1252 #ifdef HAVE_DOS_PATHS 1253 && strchr (name, '\\') == 0 1254 #endif 1255 ) 1256 continue; 1257 1258 1259 /* If this file is a suffix, don't let it be 1260 the default goal file. */ 1261 for (d = suffix_file->deps; d != 0; d = d->next) 1262 { 1263 register struct dep *d2; 1264 if (*dep_name (d) != '.' && streq (name, dep_name (d))) 1265 { 1266 reject = 1; 1267 break; 1268 } 1269 for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next) 1270 { 1271 register unsigned int len = strlen (dep_name (d2)); 1272 if (!strneq (name, dep_name (d2), len)) 1273 continue; 1274 if (streq (name + len, dep_name (d))) 1275 { 1276 reject = 1; 1277 break; 1278 } 1279 } 1280 1281 if (reject) 1282 break; 1283 } 1284 1285 if (!reject) 1286 { 1287 define_variable_global (".DEFAULT_GOAL", 13, t->name, 1288 o_file, 0, NILF); 1289 break; 1290 } 1291 } 1228 1292 } 1229 1293 … … 1284 1348 char *line; 1285 1349 1350 nlines = readline (ebuf); 1286 1351 ebuf->floc.lineno += nlines; 1287 nlines = readline (ebuf);1288 1352 1289 1353 /* If there is nothing left to eval, we're done. */ … … 1366 1430 current makefile. They are used for error messages. 1367 1431 1368 Value is -1 if the line is invalid, 1432 Value is -2 if the line is not a conditional at all, 1433 -1 if the line is an invalid conditional, 1369 1434 0 if following text should be interpreted, 1370 1435 1 if following text should be ignored. */ 1371 1436 1372 1437 static int 1373 conditional_line (char *line, const struct floc *flocp)1438 conditional_line (char *line, int len, const struct floc *flocp) 1374 1439 { 1375 int notdef;1376 1440 char *cmdname; 1377 register unsigned int i; 1378 1379 if (*line == 'i') 1380 { 1381 /* It's an "if..." command. */ 1382 notdef = line[2] == 'n'; 1383 if (notdef) 1384 { 1385 cmdname = line[3] == 'd' ? "ifndef" : "ifneq"; 1386 line += cmdname[3] == 'd' ? 7 : 6; 1387 } 1388 else 1389 { 1390 cmdname = line[2] == 'd' ? "ifdef" : "ifeq"; 1391 line += cmdname[2] == 'd' ? 6 : 5; 1392 } 1393 } 1441 enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, c_else, c_endif } cmdtype; 1442 unsigned int i; 1443 unsigned int o; 1444 1445 /* Compare a word, both length and contents. */ 1446 #define word1eq(s) (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1)) 1447 #define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); } 1448 1449 /* Make sure this line is a conditional. */ 1450 chkword ("ifdef", c_ifdef) 1451 else chkword ("ifndef", c_ifndef) 1452 else chkword ("ifeq", c_ifeq) 1453 else chkword ("ifneq", c_ifneq) 1454 else chkword ("else", c_else) 1455 else chkword ("endif", c_endif) 1394 1456 else 1395 { 1396 /* It's an "else" or "endif" command. */ 1397 notdef = line[1] == 'n'; 1398 cmdname = notdef ? "endif" : "else"; 1399 line += notdef ? 5 : 4; 1400 } 1401 1402 line = next_token (line); 1403 1404 if (*cmdname == 'e') 1457 return -2; 1458 1459 /* Found one: skip past it and any whitespace after it. */ 1460 line = next_token (line + len); 1461 1462 #define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname) 1463 1464 /* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */ 1465 if (cmdtype == c_endif) 1405 1466 { 1406 1467 if (*line != '\0') 1407 error (flocp, _("Extraneous text after `%s' directive"), cmdname);1408 /* "Else" or "endif". */ 1409 if ( conditionals->if_cmds == 0)1468 EXTRANEOUS (); 1469 1470 if (!conditionals->if_cmds) 1410 1471 fatal (flocp, _("extraneous `%s'"), cmdname); 1411 /* NOTDEF indicates an `endif' command. */ 1412 if (notdef) 1413 --conditionals->if_cmds; 1414 else if (conditionals->seen_else[conditionals->if_cmds - 1]) 1415 fatal (flocp, _("only one `else' per conditional")); 1472 1473 --conditionals->if_cmds; 1474 1475 goto DONE; 1476 } 1477 1478 /* An 'else' statement can either be simple, or it can have another 1479 conditional after it. */ 1480 if (cmdtype == c_else) 1481 { 1482 const char *p; 1483 1484 if (!conditionals->if_cmds) 1485 fatal (flocp, _("extraneous `%s'"), cmdname); 1486 1487 o = conditionals->if_cmds - 1; 1488 1489 if (conditionals->seen_else[o]) 1490 fatal (flocp, _("only one `else' per conditional")); 1491 1492 /* Change the state of ignorance. */ 1493 switch (conditionals->ignoring[o]) 1494 { 1495 case 0: 1496 /* We've just been interpreting. Never do it again. */ 1497 conditionals->ignoring[o] = 2; 1498 break; 1499 case 1: 1500 /* We've never interpreted yet. Maybe this time! */ 1501 conditionals->ignoring[o] = 0; 1502 break; 1503 } 1504 1505 /* It's a simple 'else'. */ 1506 if (*line == '\0') 1507 { 1508 conditionals->seen_else[o] = 1; 1509 goto DONE; 1510 } 1511 1512 /* The 'else' has extra text. That text must be another conditional 1513 and cannot be an 'else' or 'endif'. */ 1514 1515 /* Find the length of the next word. */ 1516 for (p = line+1; *p != '\0' && !isspace ((unsigned char)*p); ++p) 1517 ; 1518 len = p - line; 1519 1520 /* If it's 'else' or 'endif' or an illegal conditional, fail. */ 1521 if (word1eq("else") || word1eq("endif") 1522 || conditional_line (line, len, flocp) < 0) 1523 EXTRANEOUS (); 1416 1524 else 1417 { 1418 /* Toggle the state of ignorance. */ 1419 conditionals->ignoring[conditionals->if_cmds - 1] 1420 = !conditionals->ignoring[conditionals->if_cmds - 1]; 1421 /* Record that we have seen an `else' in this conditional. 1422 A second `else' will be erroneous. */ 1423 conditionals->seen_else[conditionals->if_cmds - 1] = 1; 1424 } 1425 for (i = 0; i < conditionals->if_cmds; ++i) 1426 if (conditionals->ignoring[i]) 1427 return 1; 1428 return 0; 1525 { 1526 /* conditional_line() created a new level of conditional. 1527 Raise it back to this level. */ 1528 if (conditionals->ignoring[o] < 2) 1529 conditionals->ignoring[o] = conditionals->ignoring[o+1]; 1530 --conditionals->if_cmds; 1531 } 1532 1533 goto DONE; 1429 1534 } 1430 1535 … … 1436 1541 } 1437 1542 1438 ++conditionals->if_cmds;1543 o = conditionals->if_cmds++; 1439 1544 if (conditionals->if_cmds > conditionals->allocated) 1440 1545 { … … 1447 1552 1448 1553 /* Record that we have seen an `if...' but no `else' so far. */ 1449 conditionals->seen_else[ conditionals->if_cmds - 1] = 0;1554 conditionals->seen_else[o] = 0; 1450 1555 1451 1556 /* Search through the stack to see if we're already ignoring. */ 1452 for (i = 0; i < conditionals->if_cmds - 1; ++i)1557 for (i = 0; i < o; ++i) 1453 1558 if (conditionals->ignoring[i]) 1454 1559 { 1455 /* We are already ignoring, so just push a level 1456 to match the next "else" or "endif", and keep ignoring.1457 We don't want to expandvariables in the condition. */1458 conditionals->ignoring[ conditionals->if_cmds - 1] = 1;1560 /* We are already ignoring, so just push a level to match the next 1561 "else" or "endif", and keep ignoring. We don't want to expand 1562 variables in the condition. */ 1563 conditionals->ignoring[o] = 1; 1459 1564 return 1; 1460 1565 } 1461 1566 1462 if (cmd name[notdef ? 3 : 2] == 'd')1567 if (cmdtype == c_ifdef || cmdtype == c_ifndef) 1463 1568 { 1464 /* "Ifdef" or "ifndef". */1465 1569 char *var; 1466 1570 struct variable *v; 1467 registerchar *p;1571 char *p; 1468 1572 1469 1573 /* Expand the thing we're looking up, so we can use indirect and … … 1479 1583 1480 1584 var[i] = '\0'; 1481 v = lookup_variable (var, strlen (var)); 1482 conditionals->ignoring[conditionals->if_cmds - 1] 1483 = (v != 0 && *v->value != '\0') == notdef; 1585 v = lookup_variable (var, i); 1586 1587 conditionals->ignoring[o] = 1588 ((v != 0 && *v->value != '\0') == (cmdtype == c_ifndef)); 1484 1589 1485 1590 free (var); … … 1499 1604 if (termin == ',') 1500 1605 { 1501 registerint count = 0;1606 int count = 0; 1502 1607 for (; *line != '\0'; ++line) 1503 1608 if (*line == '(') … … 1573 1678 line = next_token (++line); 1574 1679 if (*line != '\0') 1575 error (flocp, _("Extraneous text after `%s' directive"), cmdname);1680 EXTRANEOUS (); 1576 1681 1577 1682 s2 = variable_expand (s2); 1578 conditionals->ignoring[conditionals->if_cmds - 1] 1579 = streq (s1, s2) == notdef; 1683 conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq)); 1580 1684 } 1581 1685 1686 DONE: 1582 1687 /* Search through the stack to see if we're ignoring. */ 1583 1688 for (i = 0; i < conditionals->if_cmds; ++i) … … 1695 1800 p = create_pattern_var (name, percent); 1696 1801 p->variable.fileinfo = *flocp; 1802 /* I don't think this can fail since we already determined it was a 1803 variable definition. */ 1697 1804 v = parse_variable_definition (&p->variable, defn); 1698 v->value = xstrdup (v->value); 1699 if (!v) 1700 error (flocp, _("Malformed pattern-specific variable definition")); 1805 assert (v != 0); 1806 1807 if (v->flavor == f_simple) 1808 v->value = allocated_variable_expand (v->value); 1809 else 1810 v->value = xstrdup (v->value); 1811 1701 1812 fname = p->target; 1702 1813 } … … 1772 1883 struct dep *deps, unsigned int cmds_started, char *commands, 1773 1884 unsigned int commands_idx, int two_colon, 1774 int have_sysv_atvar, const struct floc *flocp, int set_default)1885 const struct floc *flocp) 1775 1886 { 1776 1887 struct nameseq *nextf; … … 1779 1890 char **targets = 0, **target_percents = 0; 1780 1891 struct commands *cmds; 1892 1893 /* If we've already snapped deps, that means we're in an eval being 1894 resolved after the makefiles have been read in. We can't add more rules 1895 at this time, since they won't get snapped and we'll get core dumps. 1896 See Savannah bug # 12124. */ 1897 if (snapped_deps) 1898 fatal (flocp, _("prerequisites cannot be defined in command scripts")); 1781 1899 1782 1900 if (commands_idx > 0) … … 1844 1962 /* If there are multiple filenames, copy the chain DEPS 1845 1963 for all but the last one. It is not safe for the same deps 1846 to go in more than one place in the data 1964 to go in more than one place in the database. */ 1847 1965 this = nextf != 0 ? copy_dep_chain (deps) : deps; 1848 1966 … … 1861 1979 } 1862 1980 else 1863 { 1864 /* We use patsubst_expand to do the work of translating 1865 the target pattern, the target's name and the dependencies' 1866 patterns into plain dependency names. */ 1867 char *buffer = variable_expand (""); 1868 1869 for (d = this; d != 0; d = d->next) 1870 { 1871 char *o; 1872 char *percent = find_percent (d->name); 1873 if (percent == 0) 1874 continue; 1875 o = patsubst_expand (buffer, name, pattern, d->name, 1876 pattern_percent, percent); 1877 /* If the name expanded to the empty string, that's 1878 illegal. */ 1879 if (o == buffer) 1880 fatal (flocp, 1881 _("target `%s' leaves prerequisite pattern empty"), 1882 name); 1883 free (d->name); 1884 d->name = savestring (buffer, o - buffer); 1885 } 1886 } 1887 } 1888 1889 /* If at least one of the dependencies uses $$@ etc. deal with that. 1890 It would be very nice and very simple to just expand everything, but 1891 it would break a lot of backward compatibility. Maybe that's OK 1892 since we're just emulating a SysV function, and if we do that then 1893 why not emulate it completely (that's what SysV make does: it 1894 re-expands the entire prerequisite list, all the time, with $@ 1895 etc. in scope). But, it would be a pain indeed to document this 1896 ("iff you use $$@, your prerequisite lists is expanded twice...") 1897 Ouch. Maybe better to make the code more complex. */ 1898 1899 if (have_sysv_atvar) 1900 { 1901 char *p; 1902 int tlen = strlen (name); 1903 char *fnp = strrchr (name, '/'); 1904 int dlen; 1905 int flen; 1906 1907 if (fnp) 1908 { 1909 dlen = fnp - name; 1910 ++fnp; 1911 flen = strlen (fnp); 1912 } 1913 else 1914 { 1915 dlen = 0; 1916 fnp = name; 1917 flen = tlen; 1918 } 1919 1920 1921 for (d = this; d != 0; d = d->next) 1922 for (p = strchr (d->name, '$'); p != 0; p = strchr (p+1, '$')) 1981 /* We use subst_expand to do the work of translating % to $* in 1982 the dependency line. */ 1983 1984 if (this != 0 && find_percent (this->name) != 0) 1923 1985 { 1924 char *s = p; 1925 char *at; 1926 int atlen; 1927 1928 /* If it's '$@', '$(@', or '${@', it's escaped */ 1929 if ((++p)[0] == '$' 1930 && (p[1] == '@' 1931 || ((p[1] == '(' || p[1] == '{') && p[2] == '@'))) 1932 { 1933 bcopy (p, s, strlen (p)+1); 1934 continue; 1935 } 1936 1937 /* Maybe found one. We like anything of any form matching @, 1938 [({]@[}):], or [({]@[DF][}):]. */ 1939 1940 if (! (p[0] == '@' 1941 || ((p[0] == '(' || p[0] == '{') && (++p)[0] == '@' 1942 && (((++p)[0] == ')' || p[0] == '}' || p[0] == ':') 1943 || ((p[1] == ')' || p[1] == '}' || p[1] == ':') 1944 && (p[0] == 'D' || p[0] == 'F')))))) 1945 continue; 1946 1947 /* Found one. Compute the length and string ptr. Move p 1948 past the variable reference. */ 1949 switch (p[0]) 1950 { 1951 case 'D': 1952 atlen = dlen; 1953 at = name; 1954 p += 2; 1955 break; 1956 1957 case 'F': 1958 atlen = flen; 1959 at = fnp; 1960 p += 2; 1961 break; 1962 1963 default: 1964 atlen = tlen; 1965 at = name; 1966 ++p; 1967 break; 1968 } 1969 1970 /* Get more space. */ 1971 { 1972 int soff = s - d->name; 1973 int poff = p - d->name; 1974 d->name = (char *) xrealloc (d->name, 1975 strlen (d->name) + atlen + 1); 1976 s = d->name + soff; 1977 p = d->name + poff; 1978 } 1979 1980 /* Copy the string over. */ 1981 bcopy(p, s+atlen, strlen (p)+1); 1982 bcopy(at, s, atlen); 1983 p = s + atlen - 1; 1986 char *o; 1987 char *buffer = variable_expand (""); 1988 1989 o = subst_expand (buffer, this->name, "%", "$*", 1, 2, 0); 1990 1991 free (this->name); 1992 this->name = savestring (buffer, o - buffer); 1993 this->need_2nd_expansion = 1; 1984 1994 } 1985 1995 } 1986 1996 1987 1997 if (!two_colon) … … 2022 2032 if (cmds != 0) 2023 2033 f->cmds = cmds; 2034 2024 2035 /* Defining .SUFFIXES with no dependencies 2025 2036 clears out the list of suffixes. */ … … 2036 2047 f->deps = 0; 2037 2048 } 2038 else if (f->deps != 0)2049 else if (this != 0) 2039 2050 { 2040 2051 /* Add the file's old deps and the new ones in THIS together. */ 2041 2052 2042 struct dep *firstdeps, *moredeps; 2043 if (cmds != 0) 2044 { 2045 /* This is the rule with commands, so put its deps first. 2046 The rationale behind this is that $< expands to the 2047 first dep in the chain, and commands use $< expecting 2048 to get the dep that rule specifies. */ 2049 firstdeps = this; 2050 moredeps = f->deps; 2051 } 2052 else 2053 { 2054 /* Append the new deps to the old ones. */ 2055 firstdeps = f->deps; 2056 moredeps = this; 2057 } 2058 2059 if (firstdeps == 0) 2060 firstdeps = moredeps; 2061 else 2062 { 2063 d = firstdeps; 2064 while (d->next != 0) 2065 d = d->next; 2066 d->next = moredeps; 2067 } 2068 2069 f->deps = firstdeps; 2053 if (f->deps != 0) 2054 { 2055 struct dep **d_ptr = &f->deps; 2056 2057 while ((*d_ptr)->next != 0) 2058 d_ptr = &(*d_ptr)->next; 2059 2060 if (cmds != 0) 2061 { 2062 /* This is the rule with commands, so put its deps 2063 last. The rationale behind this is that $< expands 2064 to the first dep in the chain, and commands use $< 2065 expecting to get the dep that rule specifies. 2066 However the second expansion algorithm reverses 2067 the order thus we need to make it last here. */ 2068 2069 (*d_ptr)->next = this; 2070 } 2071 else 2072 { 2073 /* This is the rule without commands. Put its 2074 dependencies at the end but before dependencies 2075 from the rule with commands (if any). This way 2076 everything appears in makefile order. */ 2077 2078 if (f->cmds != 0) 2079 { 2080 this->next = *d_ptr; 2081 *d_ptr = this; 2082 } 2083 else 2084 (*d_ptr)->next = this; 2085 } 2086 } 2087 else 2088 f->deps = this; 2089 2090 /* This is a hack. I need a way to communicate to snap_deps() 2091 that the last dependency line in this file came with commands 2092 (so that logic in snap_deps() can put it in front and all 2093 this $< -logic works). I cannot simply rely on file->cmds 2094 being not 0 because of the cases like the following: 2095 2096 foo: bar 2097 foo: 2098 ... 2099 2100 I am going to temporarily "borrow" UPDATING member in 2101 `struct file' for this. */ 2102 2103 if (cmds != 0) 2104 f->updating = 1; 2070 2105 } 2071 else2072 f->deps = this;2073 2106 2074 2107 /* If this is a static pattern rule, set the file's stem to … … 2080 2113 char *buffer = variable_expand (""); 2081 2114 char *o = patsubst_expand (buffer, name, pattern, percent, 2082 pattern_percent , percent);2115 pattern_percent+1, percent+1); 2083 2116 f->stem = savestring (buffer, o - buffer); 2084 2117 } … … 2116 2149 } 2117 2150 2118 /* See if this is first target seen whose name does 2119 not start with a `.', unless it contains a slash. */ 2120 if (default_goal_file == 0 && set_default 2121 && (*name != '.' || strchr (name, '/') != 0 2122 #ifdef HAVE_DOS_PATHS 2123 || strchr (name, '\\') != 0 2124 #endif 2125 )) 2126 { 2127 int reject = 0; 2128 2129 /* If this file is a suffix, don't 2130 let it be the default goal file. */ 2131 2132 for (d = suffix_file->deps; d != 0; d = d->next) 2133 { 2134 register struct dep *d2; 2135 if (*dep_name (d) != '.' && streq (name, dep_name (d))) 2136 { 2137 reject = 1; 2138 break; 2139 } 2140 for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next) 2141 { 2142 register unsigned int len = strlen (dep_name (d2)); 2143 if (!strneq (name, dep_name (d2), len)) 2144 continue; 2145 if (streq (name + len, dep_name (d))) 2146 { 2147 reject = 1; 2148 break; 2149 } 2150 } 2151 if (reject) 2152 break; 2153 } 2154 2155 if (!reject) 2156 default_goal_file = f; 2157 } 2151 /* If this target is a default target, update DEFAULT_GOAL_FILE. */ 2152 if (strcmp (*default_goal_name, name) == 0 2153 && (default_goal_file == 0 2154 || strcmp (default_goal_file->name, name) != 0)) 2155 default_goal_file = f; 2158 2156 } 2159 2157 … … 2179 2177 unsigned int string_len = 0; 2180 2178 register char *p = string; 2179 register int ch; 2181 2180 2182 2181 while (1) 2183 2182 { 2184 2183 if (stop2 && blank) 2185 while ( *p != '\0' && *p != stop1 && *p!= stop22186 && ! isblank ((unsigned char) *p))2184 while ((ch = *p) != '\0' && ch != stop1 && ch != stop2 2185 && ! isblank ((unsigned char) ch)) 2187 2186 ++p; 2188 2187 else if (stop2) 2189 while ( *p != '\0' && *p != stop1 && *p!= stop2)2188 while ((ch = *p) != '\0' && ch != stop1 && ch != stop2) 2190 2189 ++p; 2191 2190 else if (blank) 2192 while ( *p != '\0' && *p!= stop12193 && ! isblank ((unsigned char) *p))2191 while ((ch = *p) != '\0' && ch != stop1 2192 && ! isblank ((unsigned char) ch)) 2194 2193 ++p; 2195 2194 else 2196 while ( *p != '\0' && *p!= stop1)2195 while ((ch = *p) != '\0' && ch != stop1) 2197 2196 ++p; 2198 2197 2199 if ( *p== '\0')2198 if (ch == '\0') 2200 2199 break; 2201 2200 … … 2499 2498 readstring (struct ebuffer *ebuf) 2500 2499 { 2501 char * p;2500 char *eol; 2502 2501 2503 2502 /* If there is nothing left in this buffer, return 0. */ 2504 if (ebuf->bufnext > ebuf->bufstart + ebuf->size)2503 if (ebuf->bufnext >= ebuf->bufstart + ebuf->size) 2505 2504 return -1; 2506 2505 … … 2508 2507 next logical line (taking into account backslash/newline pairs). */ 2509 2508 2510 p= ebuf->buffer = ebuf->bufnext;2509 eol = ebuf->buffer = ebuf->bufnext; 2511 2510 2512 2511 while (1) 2513 2512 { 2514 2513 int backslash = 0; 2515 2516 /* Find the next newline. Keep track of backslashes as we look. */ 2517 for (; *p != '\n' && *p != '\0'; ++p) 2518 if (*p == '\\') 2519 backslash = !backslash; 2520 2521 /* If we got to the end of the string or a newline with no backslash, 2522 we're done. */ 2523 if (*p == '\0' || !backslash) 2514 char *bol = eol; 2515 char *p; 2516 2517 /* Find the next newline. At EOS, stop. */ 2518 eol = p = strchr (eol , '\n'); 2519 if (!eol) 2520 { 2521 ebuf->bufnext = ebuf->bufstart + ebuf->size + 1; 2522 return 0; 2523 } 2524 2525 /* Found a newline; if it's escaped continue; else we're done. */ 2526 while (p > bol && *(--p) == '\\') 2527 backslash = !backslash; 2528 if (!backslash) 2524 2529 break; 2530 ++eol; 2525 2531 } 2526 2532 2527 2533 /* Overwrite the newline char. */ 2528 * p= '\0';2529 ebuf->bufnext = p+1;2534 *eol = '\0'; 2535 ebuf->bufnext = eol+1; 2530 2536 2531 2537 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.