| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "makeint.h" |
| 18 |
#include "filedef.h" |
| 19 |
#include "rule.h" |
| 20 |
#include "dep.h" |
| 21 |
#include "debug.h" |
| 22 |
#include "variable.h" |
| 23 |
#include "job.h" |
| 24 |
#include "commands.h" |
| 25 |
|
| 26 |
static int pattern_search (struct file *file, int archive, |
| 27 |
unsigned int depth, unsigned int recursions); |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
int |
| 36 |
try_implicit_rule (struct file *file, unsigned int depth) |
| 37 |
{ |
| 38 |
DBF (DB_IMPLICIT, _("Looking for an implicit rule for '%s'.\n")); |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
if (pattern_search (file, 0, depth, 0)) |
| 46 |
return 1; |
| 47 |
|
| 48 |
#ifndef NO_ARCHIVES |
| 49 |
|
| 50 |
|
| 51 |
if (ar_name (file->name)) |
| 52 |
{ |
| 53 |
DBF (DB_IMPLICIT, |
| 54 |
_("Looking for archive-member implicit rule for '%s'.\n")); |
| 55 |
if (pattern_search (file, 1, depth, 0)) |
| 56 |
return 1; |
| 57 |
} |
| 58 |
#endif |
| 59 |
|
| 60 |
return 0; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
static const char * |
| 69 |
get_next_word (const char *buffer, size_t *length) |
| 70 |
{ |
| 71 |
const char *p = buffer, *beg; |
| 72 |
char c; |
| 73 |
|
| 74 |
|
| 75 |
NEXT_TOKEN (p); |
| 76 |
|
| 77 |
beg = p; |
| 78 |
c = *(p++); |
| 79 |
|
| 80 |
if (c == '\0') |
| 81 |
return 0; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
while (1) |
| 86 |
{ |
| 87 |
char closeparen; |
| 88 |
int count; |
| 89 |
|
| 90 |
switch (c) |
| 91 |
{ |
| 92 |
case '\0': |
| 93 |
case ' ': |
| 94 |
case '\t': |
| 95 |
goto done_word; |
| 96 |
|
| 97 |
case '$': |
| 98 |
c = *(p++); |
| 99 |
if (c == '$') |
| 100 |
break; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
if (c == '(') |
| 106 |
closeparen = ')'; |
| 107 |
else if (c == '{') |
| 108 |
closeparen = '}'; |
| 109 |
else |
| 110 |
|
| 111 |
break; |
| 112 |
|
| 113 |
for (count = 0; *p != '\0'; ++p) |
| 114 |
{ |
| 115 |
if (*p == c) |
| 116 |
++count; |
| 117 |
else if (*p == closeparen && --count < 0) |
| 118 |
{ |
| 119 |
++p; |
| 120 |
break; |
| 121 |
} |
| 122 |
} |
| 123 |
break; |
| 124 |
|
| 125 |
case '|': |
| 126 |
goto done; |
| 127 |
|
| 128 |
default: |
| 129 |
break; |
| 130 |
} |
| 131 |
|
| 132 |
c = *(p++); |
| 133 |
} |
| 134 |
done_word: |
| 135 |
--p; |
| 136 |
|
| 137 |
done: |
| 138 |
if (length) |
| 139 |
*length = p - beg; |
| 140 |
|
| 141 |
return beg; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
struct patdeps |
| 150 |
{ |
| 151 |
const char *name; |
| 152 |
const char *pattern; |
| 153 |
struct file *file; |
| 154 |
unsigned int ignore_mtime : 1; |
| 155 |
unsigned int ignore_automatic_vars : 1; |
| 156 |
}; |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
struct tryrule |
| 162 |
{ |
| 163 |
struct rule *rule; |
| 164 |
|
| 165 |
|
| 166 |
size_t stemlen; |
| 167 |
|
| 168 |
|
| 169 |
unsigned int matches; |
| 170 |
|
| 171 |
|
| 172 |
unsigned int order; |
| 173 |
|
| 174 |
|
| 175 |
char checked_lastslash; |
| 176 |
}; |
| 177 |
|
| 178 |
int |
| 179 |
stemlen_compare (const void *v1, const void *v2) |
| 180 |
{ |
| 181 |
const struct tryrule *r1 = v1; |
| 182 |
const struct tryrule *r2 = v2; |
| 183 |
int r = (int) (r1->stemlen - r2->stemlen); |
| 184 |
return r != 0 ? r : (int) (r1->order - r2->order); |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
static int |
| 202 |
pattern_search (struct file *file, int archive, |
| 203 |
unsigned int depth, unsigned int recursions) |
| 204 |
{ |
| 205 |
|
| 206 |
const char *filename = archive ? strchr (file->name, '(') : file->name; |
| 207 |
|
| 208 |
|
| 209 |
size_t namelen = strlen (filename); |
| 210 |
|
| 211 |
|
| 212 |
const char *lastslash; |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
struct file *int_file = 0; |
| 218 |
|
| 219 |
|
| 220 |
unsigned int max_deps = max_pattern_deps; |
| 221 |
struct patdeps *deplist = xmalloc (max_deps * sizeof (struct patdeps)); |
| 222 |
struct patdeps *pat = deplist; |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
char *depname = alloca (namelen + max_pattern_dep_length + 4); |
| 227 |
|
| 228 |
|
| 229 |
const char *stem = 0; |
| 230 |
size_t stemlen = 0; |
| 231 |
size_t fullstemlen = 0; |
| 232 |
|
| 233 |
|
| 234 |
struct tryrule *tryrules = xmalloc (num_pattern_rules * max_pattern_targets |
| 235 |
* sizeof (struct tryrule)); |
| 236 |
|
| 237 |
|
| 238 |
unsigned int nrules; |
| 239 |
|
| 240 |
|
| 241 |
unsigned int foundrule; |
| 242 |
|
| 243 |
|
| 244 |
int intermed_ok; |
| 245 |
|
| 246 |
|
| 247 |
int file_vars_initialized = 0; |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
int specific_rule_matched = 0; |
| 252 |
|
| 253 |
unsigned int ri; |
| 254 |
struct rule *rule; |
| 255 |
|
| 256 |
char *pathdir = NULL; |
| 257 |
size_t pathlen; |
| 258 |
|
| 259 |
PATH_VAR (stem_str); |
| 260 |
|
| 261 |
#ifndef NO_ARCHIVES |
| 262 |
if (archive || ar_name (filename)) |
| 263 |
lastslash = 0; |
| 264 |
else |
| 265 |
#endif |
| 266 |
{ |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
lastslash = memrchr (filename, '/', namelen - 1); |
| 271 |
} |
| 272 |
|
| 273 |
pathlen = lastslash ? lastslash - filename + 1 : 0; |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
nrules = 0; |
| 279 |
for (rule = pattern_rules; rule != 0; rule = rule->next) |
| 280 |
{ |
| 281 |
unsigned int ti; |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
if (rule->deps != 0 && rule->cmds == 0) |
| 286 |
continue; |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
if (rule->in_use) |
| 291 |
{ |
| 292 |
DBS (DB_IMPLICIT, (_("Avoiding implicit rule recursion.\n"))); |
| 293 |
continue; |
| 294 |
} |
| 295 |
|
| 296 |
for (ti = 0; ti < rule->num; ++ti) |
| 297 |
{ |
| 298 |
const char *target = rule->targets[ti]; |
| 299 |
const char *suffix = rule->suffixes[ti]; |
| 300 |
char check_lastslash; |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
if (recursions > 0 && target[1] == '\0' && !rule->terminal) |
| 306 |
continue; |
| 307 |
|
| 308 |
if (rule->lens[ti] > namelen) |
| 309 |
|
| 310 |
continue; |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
stem = filename + (suffix - target - 1); |
| 315 |
stemlen = namelen - rule->lens[ti] + 1; |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
check_lastslash = 0; |
| 321 |
if (lastslash) |
| 322 |
{ |
| 323 |
#ifdef VMS |
| 324 |
check_lastslash = strpbrk (target, "/]>:") == NULL; |
| 325 |
#else |
| 326 |
check_lastslash = strchr (target, '/') == 0; |
| 327 |
#endif |
| 328 |
#ifdef HAVE_DOS_PATHS |
| 329 |
|
| 330 |
if (check_lastslash) |
| 331 |
{ |
| 332 |
char *b = strchr (target, '\\'); |
| 333 |
check_lastslash = !(b || (target[0] && target[1] == ':')); |
| 334 |
} |
| 335 |
#endif |
| 336 |
} |
| 337 |
if (check_lastslash) |
| 338 |
{ |
| 339 |
|
| 340 |
if (pathlen > stemlen) |
| 341 |
continue; |
| 342 |
stemlen -= pathlen; |
| 343 |
stem += pathlen; |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
if (check_lastslash) |
| 348 |
{ |
| 349 |
if (stem > (lastslash + 1) |
| 350 |
&& !strneq (target, lastslash + 1, stem - lastslash - 1)) |
| 351 |
continue; |
| 352 |
} |
| 353 |
else if (stem > filename |
| 354 |
&& !strneq (target, filename, stem - filename)) |
| 355 |
continue; |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
if (*suffix != stem[stemlen] |
| 363 |
|| (*suffix != '\0' && !streq (&suffix[1], &stem[stemlen + 1]))) |
| 364 |
continue; |
| 365 |
|
| 366 |
|
| 367 |
if (target[1] != '\0') |
| 368 |
specific_rule_matched = 1; |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
if (rule->deps == 0 && rule->cmds == 0) |
| 373 |
continue; |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
tryrules[nrules].rule = rule; |
| 379 |
tryrules[nrules].matches = ti; |
| 380 |
tryrules[nrules].stemlen = stemlen + (check_lastslash ? pathlen : 0); |
| 381 |
tryrules[nrules].order = nrules; |
| 382 |
tryrules[nrules].checked_lastslash = check_lastslash; |
| 383 |
++nrules; |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
if (nrules == 0) |
| 389 |
goto done; |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
if (nrules > 1) |
| 394 |
qsort (tryrules, nrules, sizeof (struct tryrule), stemlen_compare); |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
if (specific_rule_matched) |
| 399 |
for (ri = 0; ri < nrules; ++ri) |
| 400 |
if (!tryrules[ri].rule->terminal) |
| 401 |
{ |
| 402 |
unsigned int j; |
| 403 |
for (j = 0; j < tryrules[ri].rule->num; ++j) |
| 404 |
if (tryrules[ri].rule->targets[j][1] == '\0') |
| 405 |
{ |
| 406 |
tryrules[ri].rule = 0; |
| 407 |
break; |
| 408 |
} |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
for (intermed_ok = 0; intermed_ok < 2; ++intermed_ok) |
| 413 |
{ |
| 414 |
pat = deplist; |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
for (ri = 0; ri < nrules; ri++) |
| 419 |
{ |
| 420 |
struct dep *dep; |
| 421 |
char check_lastslash; |
| 422 |
unsigned int failed = 0; |
| 423 |
int file_variables_set = 0; |
| 424 |
unsigned int deps_found = 0; |
| 425 |
|
| 426 |
const char *nptr = 0; |
| 427 |
int order_only = 0; |
| 428 |
unsigned int matches; |
| 429 |
|
| 430 |
rule = tryrules[ri].rule; |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
if (rule == 0) |
| 435 |
continue; |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
if (intermed_ok && rule->terminal) |
| 440 |
continue; |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
matches = tryrules[ri].matches; |
| 445 |
stem = filename + (rule->suffixes[matches] |
| 446 |
- rule->targets[matches]) - 1; |
| 447 |
stemlen = (namelen - rule->lens[matches]) + 1; |
| 448 |
check_lastslash = tryrules[ri].checked_lastslash; |
| 449 |
if (check_lastslash) |
| 450 |
{ |
| 451 |
stem += pathlen; |
| 452 |
stemlen -= pathlen; |
| 453 |
|
| 454 |
|
| 455 |
if (! pathdir) |
| 456 |
{ |
| 457 |
pathdir = alloca (pathlen + 1); |
| 458 |
memcpy (pathdir, filename, pathlen); |
| 459 |
pathdir[pathlen] = '\0'; |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
if (stemlen + (check_lastslash ? pathlen : 0) > GET_PATH_MAX) |
| 464 |
{ |
| 465 |
DBS (DB_IMPLICIT, (_("Stem too long: '%s%.*s'.\n"), |
| 466 |
check_lastslash ? pathdir : "", |
| 467 |
(int) stemlen, stem)); |
| 468 |
continue; |
| 469 |
} |
| 470 |
|
| 471 |
DBS (DB_IMPLICIT, (_("Trying pattern rule with stem '%.*s'.\n"), |
| 472 |
(int) stemlen, stem)); |
| 473 |
|
| 474 |
if (!check_lastslash) |
| 475 |
{ |
| 476 |
memcpy (stem_str, stem, stemlen); |
| 477 |
stem_str[stemlen] = '\0'; |
| 478 |
} |
| 479 |
else |
| 480 |
{ |
| 481 |
|
| 482 |
|
| 483 |
memcpy (stem_str, filename, pathlen); |
| 484 |
memcpy (stem_str + pathlen, stem, stemlen); |
| 485 |
stem_str[pathlen + stemlen] = '\0'; |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
if (rule->deps == 0) |
| 490 |
break; |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
file->stem = stem_str; |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
rule->in_use = 1; |
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
pat = deplist; |
| 505 |
dep = rule->deps; |
| 506 |
nptr = dep_name (dep); |
| 507 |
while (1) |
| 508 |
{ |
| 509 |
struct dep *dl, *d; |
| 510 |
char *p; |
| 511 |
|
| 512 |
|
| 513 |
if (! nptr) |
| 514 |
{ |
| 515 |
dep = dep->next; |
| 516 |
if (dep == 0) |
| 517 |
break; |
| 518 |
nptr = dep_name (dep); |
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
if (! dep->need_2nd_expansion) |
| 523 |
{ |
| 524 |
p = strchr (nptr, '%'); |
| 525 |
if (p == 0) |
| 526 |
strcpy (depname, nptr); |
| 527 |
else |
| 528 |
{ |
| 529 |
char *o = depname; |
| 530 |
if (check_lastslash) |
| 531 |
{ |
| 532 |
memcpy (o, filename, pathlen); |
| 533 |
o += pathlen; |
| 534 |
} |
| 535 |
memcpy (o, nptr, p - nptr); |
| 536 |
o += p - nptr; |
| 537 |
memcpy (o, stem, stemlen); |
| 538 |
o += stemlen; |
| 539 |
strcpy (o, p + 1); |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
p = depname; |
| 544 |
dl = PARSE_FILE_SEQ (&p, struct dep, MAP_NUL, NULL, PARSEFS_ONEWORD); |
| 545 |
for (d = dl; d != NULL; d = d->next) |
| 546 |
{ |
| 547 |
++deps_found; |
| 548 |
d->ignore_mtime = dep->ignore_mtime; |
| 549 |
d->ignore_automatic_vars = dep->ignore_automatic_vars; |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
nptr = 0; |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
else |
| 566 |
{ |
| 567 |
int add_dir = 0; |
| 568 |
size_t len; |
| 569 |
struct dep **dptr; |
| 570 |
|
| 571 |
nptr = get_next_word (nptr, &len); |
| 572 |
if (nptr == 0) |
| 573 |
continue; |
| 574 |
|
| 575 |
|
| 576 |
if (! order_only && len == 1 && nptr[0] == '|') |
| 577 |
{ |
| 578 |
order_only = 1; |
| 579 |
nptr += len; |
| 580 |
continue; |
| 581 |
} |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
p = lindex (nptr, nptr + len, '%'); |
| 595 |
if (p == 0) |
| 596 |
{ |
| 597 |
memcpy (depname, nptr, len); |
| 598 |
depname[len] = '\0'; |
| 599 |
} |
| 600 |
else |
| 601 |
{ |
| 602 |
size_t i = p - nptr; |
| 603 |
char *o = depname; |
| 604 |
memcpy (o, nptr, i); |
| 605 |
o += i; |
| 606 |
if (check_lastslash) |
| 607 |
{ |
| 608 |
add_dir = 1; |
| 609 |
memcpy (o, "$(*F)", 5); |
| 610 |
o += 5; |
| 611 |
} |
| 612 |
else |
| 613 |
{ |
| 614 |
memcpy (o, "$*", 2); |
| 615 |
o += 2; |
| 616 |
} |
| 617 |
memcpy (o, p + 1, len - i - 1); |
| 618 |
o[len - i - 1] = '\0'; |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
nptr += len; |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
if (!file_vars_initialized) |
| 627 |
{ |
| 628 |
initialize_file_variables (file, 0); |
| 629 |
set_file_variables (file); |
| 630 |
file_vars_initialized = 1; |
| 631 |
} |
| 632 |
|
| 633 |
else if (!file_variables_set) |
| 634 |
{ |
| 635 |
define_variable_for_file ( |
| 636 |
"*", 1, file->stem, o_automatic, 0, file); |
| 637 |
file_variables_set = 1; |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
p = variable_expand_for_file (depname, file); |
| 642 |
dptr = &dl; |
| 643 |
|
| 644 |
|
| 645 |
do |
| 646 |
{ |
| 647 |
|
| 648 |
struct dep *dp = PARSE_FILE_SEQ (&p, struct dep, |
| 649 |
order_only ? MAP_NUL : MAP_PIPE, |
| 650 |
add_dir ? pathdir : NULL, PARSEFS_NONE); |
| 651 |
*dptr = dp; |
| 652 |
|
| 653 |
for (d = dp; d != NULL; d = d->next) |
| 654 |
{ |
| 655 |
++deps_found; |
| 656 |
if (order_only) |
| 657 |
d->ignore_mtime = 1; |
| 658 |
dptr = &d->next; |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
if (*p == '|') |
| 663 |
{ |
| 664 |
order_only = 1; |
| 665 |
++p; |
| 666 |
} |
| 667 |
} |
| 668 |
while (*p != '\0'); |
| 669 |
} |
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
if (deps_found > max_deps) |
| 675 |
{ |
| 676 |
size_t l = pat - deplist; |
| 677 |
|
| 678 |
max_pattern_deps = MAX(max_pattern_deps, deps_found); |
| 679 |
max_deps = max_pattern_deps; |
| 680 |
deplist = xrealloc (deplist, |
| 681 |
max_deps * sizeof (struct patdeps)); |
| 682 |
pat = deplist + l; |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
for (d = dl; d != 0; d = d->next) |
| 687 |
{ |
| 688 |
struct dep *expl_d; |
| 689 |
int is_rule = d->name == dep_name (dep); |
| 690 |
|
| 691 |
if (file_impossible_p (d->name)) |
| 692 |
{ |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
DBS (DB_IMPLICIT, |
| 697 |
(is_rule |
| 698 |
? _("Rejecting impossible rule prerequisite '%s'.\n") |
| 699 |
: _("Rejecting impossible implicit prerequisite '%s'.\n"), |
| 700 |
d->name)); |
| 701 |
tryrules[ri].rule = 0; |
| 702 |
|
| 703 |
failed = 1; |
| 704 |
break; |
| 705 |
} |
| 706 |
|
| 707 |
memset (pat, '\0', sizeof (struct patdeps)); |
| 708 |
pat->ignore_mtime = d->ignore_mtime; |
| 709 |
pat->ignore_automatic_vars = d->ignore_automatic_vars; |
| 710 |
|
| 711 |
DBS (DB_IMPLICIT, |
| 712 |
(is_rule |
| 713 |
? _("Trying rule prerequisite '%s'.\n") |
| 714 |
: _("Trying implicit prerequisite '%s'.\n"), d->name)); |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
for (expl_d = file->deps; expl_d != 0; expl_d = expl_d->next) |
| 721 |
if (streq (dep_name (expl_d), d->name)) |
| 722 |
break; |
| 723 |
if (expl_d != 0) |
| 724 |
{ |
| 725 |
(pat++)->name = d->name; |
| 726 |
continue; |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
if (lookup_file (d->name) != 0 |
| 738 |
|
| 739 |
|| file_exists_p (d->name)) |
| 740 |
{ |
| 741 |
(pat++)->name = d->name; |
| 742 |
continue; |
| 743 |
} |
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
{ |
| 749 |
const char *vname = vpath_search (d->name, 0, NULL, NULL); |
| 750 |
if (vname) |
| 751 |
{ |
| 752 |
DBS (DB_IMPLICIT, |
| 753 |
(_("Found prerequisite '%s' as VPATH '%s'\n"), |
| 754 |
d->name, vname)); |
| 755 |
(pat++)->name = d->name; |
| 756 |
continue; |
| 757 |
} |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
if (intermed_ok) |
| 765 |
{ |
| 766 |
DBS (DB_IMPLICIT, |
| 767 |
(_("Looking for a rule with intermediate file '%s'.\n"), |
| 768 |
d->name)); |
| 769 |
|
| 770 |
if (int_file == 0) |
| 771 |
int_file = alloca (sizeof (struct file)); |
| 772 |
memset (int_file, '\0', sizeof (struct file)); |
| 773 |
int_file->name = d->name; |
| 774 |
|
| 775 |
if (pattern_search (int_file, |
| 776 |
0, |
| 777 |
depth + 1, |
| 778 |
recursions + 1)) |
| 779 |
{ |
| 780 |
pat->pattern = int_file->name; |
| 781 |
int_file->name = d->name; |
| 782 |
pat->file = int_file; |
| 783 |
int_file = 0; |
| 784 |
(pat++)->name = d->name; |
| 785 |
continue; |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
if (int_file->variables) |
| 792 |
free_variable_set (int_file->variables); |
| 793 |
if (int_file->pat_variables) |
| 794 |
free_variable_set (int_file->pat_variables); |
| 795 |
file_impossible (d->name); |
| 796 |
} |
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
failed = 1; |
| 801 |
break; |
| 802 |
} |
| 803 |
|
| 804 |
|
| 805 |
free_dep_chain (dl); |
| 806 |
|
| 807 |
if (failed) |
| 808 |
break; |
| 809 |
} |
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
file->stem = 0; |
| 814 |
|
| 815 |
|
| 816 |
rule->in_use = 0; |
| 817 |
|
| 818 |
if (! failed) |
| 819 |
|
| 820 |
break; |
| 821 |
|
| 822 |
|
| 823 |
} |
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
if (ri < nrules) |
| 828 |
break; |
| 829 |
|
| 830 |
rule = 0; |
| 831 |
} |
| 832 |
|
| 833 |
|
| 834 |
if (rule == 0) |
| 835 |
goto done; |
| 836 |
|
| 837 |
foundrule = ri; |
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
if (recursions > 0) |
| 843 |
|
| 844 |
file->name = rule->targets[tryrules[foundrule].matches]; |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
while (pat-- > deplist) |
| 851 |
{ |
| 852 |
struct dep *dep; |
| 853 |
const char *s; |
| 854 |
|
| 855 |
if (pat->file != 0) |
| 856 |
{ |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
struct file *imf = pat->file; |
| 864 |
struct file *f = lookup_file (imf->name); |
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
if (f != 0) |
| 871 |
f->secondary = 1; |
| 872 |
else |
| 873 |
f = enter_file (imf->name); |
| 874 |
|
| 875 |
f->deps = imf->deps; |
| 876 |
f->cmds = imf->cmds; |
| 877 |
f->stem = imf->stem; |
| 878 |
f->variables = imf->variables; |
| 879 |
f->pat_variables = imf->pat_variables; |
| 880 |
f->pat_searched = imf->pat_searched; |
| 881 |
f->also_make = imf->also_make; |
| 882 |
f->is_target = 1; |
| 883 |
f->intermediate = 1; |
| 884 |
f->tried_implicit = 1; |
| 885 |
|
| 886 |
imf = lookup_file (pat->pattern); |
| 887 |
if (imf != 0 && imf->precious) |
| 888 |
f->precious = 1; |
| 889 |
|
| 890 |
for (dep = f->deps; dep != 0; dep = dep->next) |
| 891 |
{ |
| 892 |
dep->file = enter_file (dep->name); |
| 893 |
dep->name = 0; |
| 894 |
dep->file->tried_implicit |= dep->changed; |
| 895 |
} |
| 896 |
} |
| 897 |
|
| 898 |
dep = alloc_dep (); |
| 899 |
dep->ignore_mtime = pat->ignore_mtime; |
| 900 |
dep->ignore_automatic_vars = pat->ignore_automatic_vars; |
| 901 |
s = strcache_add (pat->name); |
| 902 |
if (recursions) |
| 903 |
dep->name = s; |
| 904 |
else |
| 905 |
{ |
| 906 |
dep->file = lookup_file (s); |
| 907 |
if (dep->file == 0) |
| 908 |
dep->file = enter_file (s); |
| 909 |
} |
| 910 |
|
| 911 |
if (pat->file == 0 && tryrules[foundrule].rule->terminal) |
| 912 |
{ |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
if (dep->file == 0) |
| 919 |
dep->changed = 1; |
| 920 |
else |
| 921 |
dep->file->tried_implicit = 1; |
| 922 |
} |
| 923 |
|
| 924 |
dep->next = file->deps; |
| 925 |
file->deps = dep; |
| 926 |
} |
| 927 |
|
| 928 |
if (!tryrules[foundrule].checked_lastslash) |
| 929 |
{ |
| 930 |
|
| 931 |
|
| 932 |
file->stem = strcache_add_len (stem, stemlen); |
| 933 |
fullstemlen = stemlen; |
| 934 |
} |
| 935 |
else |
| 936 |
{ |
| 937 |
|
| 938 |
|
| 939 |
fullstemlen = pathlen + stemlen; |
| 940 |
memcpy (stem_str, filename, pathlen); |
| 941 |
memcpy (stem_str + pathlen, stem, stemlen); |
| 942 |
stem_str[fullstemlen] = '\0'; |
| 943 |
file->stem = strcache_add (stem_str); |
| 944 |
} |
| 945 |
|
| 946 |
file->cmds = rule->cmds; |
| 947 |
file->is_target = 1; |
| 948 |
|
| 949 |
|
| 950 |
{ |
| 951 |
struct file *f = lookup_file (rule->targets[tryrules[foundrule].matches]); |
| 952 |
if (f && f->precious) |
| 953 |
file->precious = 1; |
| 954 |
} |
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
if (rule->num > 1) |
| 960 |
for (ri = 0; ri < rule->num; ++ri) |
| 961 |
if (ri != tryrules[foundrule].matches) |
| 962 |
{ |
| 963 |
char *nm = alloca (rule->lens[ri] + fullstemlen + 1); |
| 964 |
char *p = nm; |
| 965 |
struct file *f; |
| 966 |
struct dep *new = alloc_dep (); |
| 967 |
|
| 968 |
|
| 969 |
memcpy (p, rule->targets[ri], |
| 970 |
rule->suffixes[ri] - rule->targets[ri] - 1); |
| 971 |
p += rule->suffixes[ri] - rule->targets[ri] - 1; |
| 972 |
memcpy (p, file->stem, fullstemlen); |
| 973 |
p += fullstemlen; |
| 974 |
memcpy (p, rule->suffixes[ri], |
| 975 |
rule->lens[ri] - (rule->suffixes[ri] - rule->targets[ri])+1); |
| 976 |
new->name = strcache_add (nm); |
| 977 |
new->file = enter_file (new->name); |
| 978 |
new->next = file->also_make; |
| 979 |
|
| 980 |
|
| 981 |
f = lookup_file (rule->targets[ri]); |
| 982 |
if (f && f->precious) |
| 983 |
new->file->precious = 1; |
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
new->file->is_target = 1; |
| 989 |
|
| 990 |
file->also_make = new; |
| 991 |
} |
| 992 |
|
| 993 |
done: |
| 994 |
free (tryrules); |
| 995 |
free (deplist); |
| 996 |
|
| 997 |
return rule != 0; |
| 998 |
} |