Changeset 2591 for trunk/src/kmk/implicit.c
- Timestamp:
- Jun 17, 2012, 10:45:31 PM (13 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk
- Property svn:ignore
-
old new 13 13 stamp-* 14 14 makebook* 15 15 16 .*gdbinit 17 .gdb_history 18 16 19 *.dep 17 20 *.dvi … … 31 34 *.pg 32 35 *.pgs 36 33 37 README 34 38 README.DOS 35 39 README.W32 40 README.OS2 36 41 aclocal.m4 37 42 autom4te.cache … … 52 57 config.h.W32 53 58 config.h-vms 59 54 60 loadavg 55 61 loadavg.c 56 62 make 63 57 64 .deps 58 65 .dep_segment 66 ID 67 TAGS 68 59 69 _* 60 70 sun4 … … 72 82 sol2 73 83 i486-linux 84 74 85 customs 86 75 87 install-sh 76 88 mkinstalldirs 89 90 .directive.asc
-
- Property svn:ignore
-
trunk/src/kmk/implicit.c
r2024 r2591 1 1 /* Implicit rule searching for GNU Make. 2 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software4 Foundation, Inc.3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 4 2010 Free Software Foundation, Inc. 5 5 This file is part of GNU Make. 6 6 … … 49 49 return 1; 50 50 51 #ifndef 51 #ifndef NO_ARCHIVES 52 52 /* If this is an archive member reference, use just the 53 53 archive member name to search for implicit rules. */ … … 57 57 _("Looking for archive-member implicit rule for `%s'.\n")); 58 58 if (pattern_search (file, 1, depth, 0)) 59 59 return 1; 60 60 } 61 61 #endif … … 64 64 } 65 65 66 67 68 #ifdef CONFIG_WITH_ALLOC_CACHES69 struct alloccache idep_cache;70 #endif71 72 /* Struct idep captures information about implicit prerequisites73 that come from implicit rules. */74 struct idep75 {76 struct idep *next; /* struct dep -compatible interface */77 const char *name; /* name of the prerequisite */78 struct file *intermediate_file; /* intermediate file, 0 otherwise */79 const char *intermediate_pattern; /* pattern for intermediate file */80 unsigned char had_stem; /* had % substituted with stem */81 unsigned char ignore_mtime; /* ignore_mtime flag */82 };83 84 static void85 free_idep_chain (struct idep *p)86 {87 struct idep *n;88 89 for (; p != 0; p = n)90 {91 n = p->next;92 #ifndef CONFIG_WITH_ALLOC_CACHES93 free (p);94 #else95 alloccache_free (&idep_cache, p);96 #endif97 }98 }99 66 100 67 … … 103 70 length of the word. */ 104 71 105 static c har *72 static const char * 106 73 get_next_word (const char *buffer, unsigned int *length) 107 74 { … … 181 148 *length = p - beg; 182 149 183 return (char *)beg; 150 return beg; 151 } 152 153 /* This structure stores information about the expanded prerequisites for a 154 pattern rule. NAME is always set to the strcache'd name of the prereq. 155 FILE and PATTERN will be set for intermediate files only. IGNORE_MTIME is 156 copied from the prerequisite we expanded. 157 */ 158 struct patdeps 159 { 160 const char *name; 161 const char *pattern; 162 struct file *file; 163 unsigned int ignore_mtime : 1; 164 }; 165 166 /* This structure stores information about pattern rules that we need 167 to try. 168 */ 169 struct tryrule 170 { 171 struct rule *rule; 172 173 /* Index of the target in this rule that matched the file. */ 174 unsigned int matches; 175 176 /* Stem length for this match. */ 177 unsigned int stemlen; 178 179 /* Definition order of this rule. Used to implement stable sort.*/ 180 unsigned int order; 181 182 /* Nonzero if the LASTSLASH logic was used in matching this rule. */ 183 char checked_lastslash; 184 }; 185 186 int 187 stemlen_compare (const void *v1, const void *v2) 188 { 189 const struct tryrule *r1 = v1; 190 const struct tryrule *r2 = v2; 191 int r = r1->stemlen - r2->stemlen; 192 return r != 0 ? r : (int)(r1->order - r2->order); 184 193 } 185 194 … … 209 218 210 219 /* The last slash in FILENAME (or nil if there is none). */ 211 c har *lastslash;220 const char *lastslash; 212 221 213 222 /* This is a file-object used as an argument in 214 223 recursive calls. It never contains any data 215 224 except during a recursive call. */ 216 struct file *int ermediate_file = 0;217 218 /* This linked list records all the prerequisites actually219 found for a rule along with some other useful information220 (see struct idep for details). */221 struct idep* deps = 0;222 223 /* 1 if we need to remove explicit prerequisites, 0 otherwise.*/224 unsigned int remove_explicit_deps = 0;225 struct file *int_file = 0; 226 227 /* List of dependencies found recursively. */ 228 struct patdeps *deplist 229 = xmalloc (max_pattern_deps * sizeof (struct patdeps)); 230 struct patdeps *pat = deplist; 231 232 /* All the prerequisites actually found for a rule, after expansion. */ 233 struct dep *deps; 225 234 226 235 /* Names of possible dependencies are constructed in this buffer. */ … … 233 242 234 243 /* Buffer in which we store all the rules that are possibly applicable. */ 235 struct rule **tryrules = xmalloc (num_pattern_rules * max_pattern_targets236 * sizeof (struct rule *));244 struct tryrule *tryrules = xmalloc (num_pattern_rules * max_pattern_targets 245 * sizeof (struct tryrule)); 237 246 238 247 /* Number of valid elements in TRYRULES. */ 239 248 unsigned int nrules; 240 249 241 /* The numbers of the rule targets of each rule242 in TRYRULES that matched the target file. */243 unsigned int *matches = alloca (num_pattern_rules * sizeof (unsigned int));244 245 /* Each element is nonzero if LASTSLASH was used in246 matching the corresponding element of TRYRULES. */247 char *checked_lastslash = alloca (num_pattern_rules * sizeof (char));248 249 250 /* The index in TRYRULES of the rule we found. */ 250 251 unsigned int foundrule; … … 252 253 /* Nonzero if should consider intermediate files as dependencies. */ 253 254 int intermed_ok; 255 256 /* Nonzero if we have initialized file variables for this target. */ 257 int file_vars_initialized = 0; 254 258 255 259 /* Nonzero if we have matched a pattern-rule target … … 257 261 int specific_rule_matched = 0; 258 262 263 struct dep dep_simple; 264 259 265 unsigned int ri; /* uninit checks OK */ 260 266 struct rule *rule; 261 struct dep *dep, *expl_d; 262 263 struct idep *d; 264 struct idep **id_ptr; 265 struct dep **d_ptr; 267 268 char *pathdir = NULL; 269 unsigned long pathlen; 266 270 267 271 PATH_VAR (stem_str); /* @@ Need to get rid of stem, stemlen, etc. */ 268 272 269 #ifdef CONFIG_WITH_ALLOC_CACHES 270 if (!idep_cache.size) 271 alloccache_init (&idep_cache, sizeof (struct idep), "idep", NULL, NULL); 272 #endif 273 274 #ifndef NO_ARCHIVES 273 #ifndef NO_ARCHIVES 275 274 if (archive || ar_name (filename)) 276 275 lastslash = 0; … … 279 278 { 280 279 /* Set LASTSLASH to point at the last slash in FILENAME 281 282 280 but not counting any slash at the end. (foo/bar/ counts as 281 bar/ in directory foo/, not empty in directory foo/bar/.) */ 283 282 #ifdef VMS 284 283 lastslash = strrchr (filename, ']'); 285 284 if (lastslash == 0) 286 285 lastslash = strrchr (filename, ':'); 287 286 #else 288 287 lastslash = strrchr (filename, '/'); 289 288 #ifdef HAVE_DOS_PATHS 290 289 /* Handle backslashes (possibly mixed with forward slashes) 291 290 and the case of "d:file". */ 292 291 { 293 294 295 296 297 lastslash = (char *)filename + 1;292 char *bslash = strrchr (filename, '\\'); 293 if (lastslash == 0 || bslash > lastslash) 294 lastslash = bslash; 295 if (lastslash == 0 && filename[0] && filename[1] == ':') 296 lastslash = filename + 1; 298 297 } 299 298 #endif 300 299 #endif 301 300 if (lastslash != 0 && lastslash[1] == '\0') 302 301 lastslash = 0; 303 302 } 304 303 305 /* First see which pattern rules match this target 306 and may be considered. Put them in TRYRULES. */ 304 pathlen = lastslash - filename + 1; 305 306 /* First see which pattern rules match this target and may be considered. 307 Put them in TRYRULES. */ 307 308 308 309 nrules = 0; … … 312 313 313 314 /* If the pattern rule has deps but no commands, ignore it. 314 315 Users cancel built-in rules by redefining them without commands. */ 315 316 if (rule->deps != 0 && rule->cmds == 0) 316 317 continue; 317 318 318 319 /* If this rule is in use by a parent pattern_search, 319 320 don't use it here. */ 320 321 if (rule->in_use) 321 322 323 324 322 { 323 DBS (DB_IMPLICIT, (_("Avoiding implicit rule recursion.\n"))); 324 continue; 325 } 325 326 326 327 for (ti = 0; ti < rule->num; ++ti) 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 328 { 329 const char *target = rule->targets[ti]; 330 const char *suffix = rule->suffixes[ti]; 331 int check_lastslash; 332 333 /* Rules that can match any filename and are not terminal 334 are ignored if we're recursing, so that they cannot be 335 intermediate files. */ 336 if (recursions > 0 && target[1] == '\0' && !rule->terminal) 337 continue; 338 339 if (rule->lens[ti] > namelen) 340 /* It can't possibly match. */ 341 continue; 342 343 /* From the lengths of the filename and the pattern parts, 344 find the stem: the part of the filename that matches the %. */ 345 stem = filename + (suffix - target - 1); 346 stemlen = namelen - rule->lens[ti] + 1; 347 348 /* Set CHECK_LASTSLASH if FILENAME contains a directory 349 prefix and the target pattern does not contain a slash. */ 349 350 350 351 check_lastslash = 0; … … 366 367 #endif 367 368 } 368 if (check_lastslash) 369 { 370 /* If so, don't include the directory prefix in STEM here. */ 371 unsigned int difference = lastslash - filename + 1; 372 if (difference > stemlen) 373 continue; 374 stemlen -= difference; 375 stem += difference; 376 } 377 378 /* Check that the rule pattern matches the text before the stem. */ 379 if (check_lastslash) 380 { 381 if (stem > (lastslash + 1) 382 && !strneq (target, lastslash + 1, stem - lastslash - 1)) 383 continue; 384 } 385 else if (stem > filename 386 && !strneq (target, filename, stem - filename)) 387 continue; 388 389 /* Check that the rule pattern matches the text after the stem. 390 We could test simply use streq, but this way we compare the 391 first two characters immediately. This saves time in the very 392 common case where the first character matches because it is a 393 period. */ 394 if (*suffix != stem[stemlen] 395 || (*suffix != '\0' && !streq (&suffix[1], &stem[stemlen + 1]))) 396 continue; 397 398 /* Record if we match a rule that not all filenames will match. */ 399 if (target[1] != '\0') 400 specific_rule_matched = 1; 401 402 /* A rule with no dependencies and no commands exists solely to set 403 specific_rule_matched when it matches. Don't try to use it. */ 404 if (rule->deps == 0 && rule->cmds == 0) 405 continue; 406 407 /* Record this rule in TRYRULES and the index of the matching 408 target in MATCHES. If several targets of the same rule match, 409 that rule will be in TRYRULES more than once. */ 410 tryrules[nrules] = rule; 411 matches[nrules] = ti; 412 checked_lastslash[nrules] = check_lastslash; 413 ++nrules; 414 } 369 if (check_lastslash) 370 { 371 /* If so, don't include the directory prefix in STEM here. */ 372 if (pathlen > stemlen) 373 continue; 374 stemlen -= pathlen; 375 stem += pathlen; 376 } 377 378 /* Check that the rule pattern matches the text before the stem. */ 379 if (check_lastslash) 380 { 381 if (stem > (lastslash + 1) 382 && !strneq (target, lastslash + 1, stem - lastslash - 1)) 383 continue; 384 } 385 else if (stem > filename 386 && !strneq (target, filename, stem - filename)) 387 continue; 388 389 /* Check that the rule pattern matches the text after the stem. 390 We could test simply use streq, but this way we compare the 391 first two characters immediately. This saves time in the very 392 common case where the first character matches because it is a 393 period. */ 394 if (*suffix != stem[stemlen] 395 || (*suffix != '\0' && !streq (&suffix[1], &stem[stemlen + 1]))) 396 continue; 397 398 /* Record if we match a rule that not all filenames will match. */ 399 if (target[1] != '\0') 400 specific_rule_matched = 1; 401 402 /* A rule with no dependencies and no commands exists solely to set 403 specific_rule_matched when it matches. Don't try to use it. */ 404 if (rule->deps == 0 && rule->cmds == 0) 405 continue; 406 407 /* Record this rule in TRYRULES and the index of the matching 408 target in MATCHES. If several targets of the same rule match, 409 that rule will be in TRYRULES more than once. */ 410 tryrules[nrules].rule = rule; 411 tryrules[nrules].matches = ti; 412 tryrules[nrules].stemlen = stemlen + (check_lastslash ? pathlen : 0); 413 tryrules[nrules].order = nrules; 414 tryrules[nrules].checked_lastslash = check_lastslash; 415 ++nrules; 416 } 415 417 } 418 419 /* Bail out early if we haven't found any rules. */ 420 if (nrules == 0) 421 goto done; 422 423 /* Sort the rules to place matches with the shortest stem first. This 424 way the most specific rules will be tried first. */ 425 if (nrules > 1) 426 qsort (tryrules, nrules, sizeof (struct tryrule), stemlen_compare); 416 427 417 428 /* If we have found a matching rule that won't match all filenames, … … 419 430 if (specific_rule_matched) 420 431 for (ri = 0; ri < nrules; ++ri) 421 if (!tryrules[ri] ->terminal)422 423 424 for (j = 0; j < tryrules[ri]->num; ++j)425 if (tryrules[ri]->targets[j][1] == '\0')432 if (!tryrules[ri].rule->terminal) 433 { 434 unsigned int j; 435 for (j = 0; j < tryrules[ri].rule->num; ++j) 436 if (tryrules[ri].rule->targets[j][1] == '\0') 426 437 { 427 tryrules[ri] = 0;438 tryrules[ri].rule = 0; 428 439 break; 429 440 } 430 } 431 432 /* We are going to do second expansion so initialize file variables 433 for the rule. */ 434 initialize_file_variables (file, 0); 441 } 435 442 436 443 /* Try each rule once without intermediate files, then once with them. */ 437 for (intermed_ok = 0; intermed_ok == !!intermed_ok; ++intermed_ok)444 for (intermed_ok = 0; intermed_ok < 2; ++intermed_ok) 438 445 { 439 /* Try each pattern rule till we find one that applies.440 If it does, expand its dependencies (as substituted) 441 and chain them in DEPS. */ 442 446 pat = deplist; 447 448 /* Try each pattern rule till we find one that applies. If it does, 449 expand its dependencies (as substituted) and chain them in DEPS. */ 443 450 for (ri = 0; ri < nrules; ri++) 444 { 445 struct file *f; 451 { 452 struct dep *dep; 453 int check_lastslash; 446 454 unsigned int failed = 0; 447 int check_lastslash;448 455 int file_variables_set = 0; 449 450 rule = tryrules[ri]; 451 452 remove_explicit_deps = 0; 453 454 /* RULE is nil when we discover that a rule, 455 already placed in TRYRULES, should not be applied. */ 456 if (rule == 0) 457 continue; 458 459 /* Reject any terminal rules if we're 460 looking to make intermediate files. */ 461 if (intermed_ok && rule->terminal) 462 continue; 463 464 /* Mark this rule as in use so a recursive 465 pattern_search won't try to use it. */ 466 rule->in_use = 1; 467 468 /* From the lengths of the filename and the matching pattern parts, 469 find the stem: the part of the filename that matches the %. */ 470 stem = filename 471 + (rule->suffixes[matches[ri]] - rule->targets[matches[ri]]) - 1; 472 stemlen = namelen - rule->lens[matches[ri]] + 1; 473 check_lastslash = checked_lastslash[ri]; 474 if (check_lastslash) 475 { 476 stem += lastslash - filename + 1; 477 stemlen -= (lastslash - filename) + 1; 478 } 479 480 DBS (DB_IMPLICIT, (_("Trying pattern rule with stem `%.*s'.\n"), 456 unsigned int deps_found = 0; 457 /* NPTR points to the part of the prereq we haven't processed. */ 458 const char *nptr = 0; 459 const char *dir = NULL; 460 int order_only = 0; 461 unsigned int matches; 462 463 rule = tryrules[ri].rule; 464 465 /* RULE is nil when we discover that a rule, already placed in 466 TRYRULES, should not be applied. */ 467 if (rule == 0) 468 continue; 469 470 /* Reject any terminal rules if we're looking to make intermediate 471 files. */ 472 if (intermed_ok && rule->terminal) 473 continue; 474 475 /* From the lengths of the filename and the matching pattern parts, 476 find the stem: the part of the filename that matches the %. */ 477 matches = tryrules[ri].matches; 478 stem = filename + (rule->suffixes[matches] 479 - rule->targets[matches]) - 1; 480 stemlen = (namelen - rule->lens[matches]) + 1; 481 check_lastslash = tryrules[ri].checked_lastslash; 482 if (check_lastslash) 483 { 484 stem += pathlen; 485 stemlen -= pathlen; 486 487 /* We need to add the directory prefix, so set it up. */ 488 if (! pathdir) 489 { 490 pathdir = alloca (pathlen + 1); 491 memcpy (pathdir, filename, pathlen); 492 pathdir[pathlen] = '\0'; 493 } 494 dir = pathdir; 495 } 496 497 DBS (DB_IMPLICIT, (_("Trying pattern rule with stem `%.*s'.\n"), 481 498 (int) stemlen, stem)); 482 499 483 500 strncpy (stem_str, stem, stemlen); 484 501 stem_str[stemlen] = '\0'; 502 503 /* If there are no prerequisites, then this rule matches. */ 504 if (rule->deps == 0) 505 break; 485 506 486 507 /* Temporary assign STEM to file->stem (needed to set file … … 488 509 file->stem = stem_str; 489 510 490 /* Try each dependency; see if it "exists". */ 491 492 for (dep = rule->deps; dep != 0; dep = dep->next) 493 { 494 unsigned int len; 511 /* Mark this rule as in use so a recursive pattern_search won't try 512 to use it. */ 513 rule->in_use = 1; 514 515 /* Try each prerequisite; see if it exists or can be created. We'll 516 build a list of prereq info in DEPLIST. Due to 2nd expansion we 517 may have to process multiple prereqs for a single dep entry. */ 518 519 pat = deplist; 520 dep = rule->deps; 521 nptr = dep_name (dep); 522 while (1) 523 { 524 struct dep *dl, *d; 495 525 char *p; 496 char *p2; 497 unsigned int order_only = 0; /* Set if '|' was seen. */ 498 499 /* In an ideal world we would take the dependency line, 500 substitute the stem, re-expand the whole line and chop it 501 into individual prerequisites. Unfortunately this won't work 502 because of the "check_lastslash" twist. Instead, we will 503 have to go word by word, taking $()'s into account, for each 504 word we will substitute the stem, re-expand, chop it up, and, 505 if check_lastslash != 0, add the directory part to each 526 527 /* If we're out of name to parse, start the next prereq. */ 528 if (! nptr) 529 { 530 dep = dep->next; 531 if (dep == 0) 532 break; 533 nptr = dep_name (dep); 534 } 535 536 /* If we don't need a second expansion, just replace the %. */ 537 if (! dep->need_2nd_expansion) 538 { 539 dep_simple = *dep; 540 dep_simple.next = 0; 541 p = strchr (nptr, '%'); 542 if (p == 0) 543 dep_simple.name = nptr; 544 else 545 { 546 char *o = depname; 547 if (check_lastslash) 548 { 549 memcpy (o, filename, pathlen); 550 o += pathlen; 551 } 552 memcpy (o, nptr, p - nptr); 553 o += p - nptr; 554 memcpy (o, stem_str, stemlen); 555 o += stemlen; 556 strcpy (o, p + 1); 557 dep_simple.name = strcache_add (depname); 558 } 559 dl = &dep_simple; 560 561 /* We've used up this dep, so next time get a new one. */ 562 nptr = 0; 563 ++deps_found; 564 } 565 566 /* We have to perform second expansion on this prereq. In an 567 ideal world we would take the dependency line, substitute the 568 stem, re-expand the whole line and chop it into individual 569 prerequisites. Unfortunately this won't work because of the 570 "check_lastslash" twist. Instead, we will have to go word by 571 word, taking $()'s into account. For each word we will 572 substitute the stem, re-expand, chop it up, and, if 573 check_lastslash != 0, add the directory part to each 506 574 resulting prerequisite. */ 507 508 p = get_next_word (dep->name, &len); 509 510 while (1) 575 else 511 576 { 512 577 int add_dir = 0; 513 int had_stem = 0; 514 578 unsigned int len; 579 580 nptr = get_next_word (nptr, &len); 581 if (nptr == 0) 582 continue; 583 584 /* See this is a transition to order-only prereqs. */ 585 if (! order_only && len == 1 && nptr[0] == '|') 586 { 587 order_only = 1; 588 nptr += len; 589 continue; 590 } 591 592 /* If the dependency name has %, substitute the stem. If we 593 just replace % with the stem value then later, when we do 594 the 2nd expansion, we will re-expand this stem value 595 again. This is not good if you have certain characters 596 in your stem (like $). 597 598 Instead, we will replace % with $* and allow the second 599 expansion to take care of it for us. This way (since $* 600 is a simple variable) there won't be additional 601 re-expansion of the stem. */ 602 603 p = lindex (nptr, nptr + len, '%'); 515 604 if (p == 0) 516 break; /* No more words */ 517 518 /* Is there a pattern in this prerequisite? */ 519 520 for (p2 = p; p2 < p + len && *p2 != '%'; ++p2) 521 ; 522 523 if (dep->need_2nd_expansion) 524 { 525 /* If the dependency name has %, substitute the stem. 526 527 Watch out, we are going to do something tricky 528 here. If we just replace % with the stem value, 529 later, when we do the second expansion, we will 530 re-expand this stem value once again. This is not 531 good especially if you have certain characters in 532 your stem (like $). 533 534 Instead, we will replace % with $* and allow the 535 second expansion to take care of it for us. This way 536 (since $* is a simple variable) there won't be 537 additional re-expansion of the stem. */ 538 539 if (p2 < p + len) 540 { 541 unsigned int i = p2 - p; 542 memcpy (depname, p, i); 543 memcpy (depname + i, "$*", 2); 544 memcpy (depname + i + 2, p2 + 1, len - i - 1); 545 depname[len + 2 - 1] = '\0'; 546 547 if (check_lastslash) 548 add_dir = 1; 549 550 had_stem = 1; 551 } 552 else 553 { 554 memcpy (depname, p, len); 555 depname[len] = '\0'; 556 } 557 558 /* Set file variables. Note that we cannot do it once 559 at the beginning of the function because of the stem 560 value. */ 561 if (!file_variables_set) 562 { 605 { 606 memcpy (depname, nptr, len); 607 depname[len] = '\0'; 608 } 609 else 610 { 611 unsigned int i = p - nptr; 612 memcpy (depname, nptr, i); 613 memcpy (depname + i, "$*", 2); 614 memcpy (depname + i + 2, p + 1, len - i - 1); 615 depname[len + 2 - 1] = '\0'; 616 617 if (check_lastslash) 618 add_dir = 1; 619 } 620 621 /* Initialize and set file variables if we haven't already 622 done so. */ 623 if (!file_vars_initialized) 624 { 625 initialize_file_variables (file, 0); 563 626 #if defined(CONFIG_WITH_COMMANDS_FUNC) || defined (CONFIG_WITH_DOT_MUST_MAKE) 564 627 set_file_variables (file, 0 /* real call */); 565 628 #else 566 629 set_file_variables (file); 567 630 #endif 568 file_variables_set = 1; 569 } 570 571 p2 = variable_expand_for_file (depname, file); 572 } 573 else 574 { 575 if (p2 < p + len) 576 { 577 unsigned int i = p2 - p; 578 memcpy (depname, p, i); 579 memcpy (depname + i, stem_str, stemlen); 580 memcpy (depname + i + stemlen, p2 + 1, len - i - 1); 581 depname[len + stemlen - 1] = '\0'; 582 583 if (check_lastslash) 584 add_dir = 1; 585 586 had_stem = 1; 587 } 588 else 589 { 590 memcpy (depname, p, len); 591 depname[len] = '\0'; 592 } 593 594 p2 = depname; 595 } 596 597 /* Parse the dependencies. */ 598 599 while (1) 600 { 601 id_ptr = &deps; 602 603 for (; *id_ptr; id_ptr = &(*id_ptr)->next) 604 ; 605 606 #ifndef CONFIG_WITH_ALLOC_CACHES 607 *id_ptr = (struct idep *) 608 multi_glob ( 609 parse_file_seq (&p2, 610 order_only ? '\0' : '|', 611 sizeof (struct idep), 612 1), sizeof (struct idep)); 613 #else 614 *id_ptr = (struct idep *) 615 multi_glob ( 616 parse_file_seq (&p2, 617 order_only ? '\0' : '|', 618 &idep_cache, 1), 619 &idep_cache); 620 #endif 621 622 /* @@ It would be nice to teach parse_file_seq or 623 multi_glob to add prefix. This would save us some 624 reallocations. */ 625 626 if (order_only || add_dir || had_stem) 627 { 628 unsigned long l = lastslash - filename + 1; 629 630 for (d = *id_ptr; d != 0; d = d->next) 631 { 632 if (order_only) 633 d->ignore_mtime = 1; 634 635 if (add_dir) 636 { 637 char *n = alloca (strlen (d->name) + l + 1); 638 memcpy (n, filename, l); 639 memcpy (n+l, d->name, strlen (d->name) + 1); 640 d->name = strcache_add (n); 641 } 642 643 if (had_stem) 644 d->had_stem = 1; 645 } 646 } 647 648 if (!order_only && *p2) 631 file_vars_initialized = 1; 632 } 633 /* Update the stem value in $* for this rule. */ 634 else if (!file_variables_set) 635 { 636 define_variable_for_file ( 637 "*", 1, file->stem, o_automatic, 0, file); 638 file_variables_set = 1; 639 } 640 641 /* Perform the 2nd expansion. */ 642 p = variable_expand_for_file (depname, file); 643 644 /* Parse the expanded string. */ 645 dl = PARSE_FILE_SEQ (&p, struct dep, order_only ? '\0' : '|', 646 add_dir ? dir : NULL, 0); 647 648 for (d = dl; d != NULL; d = d->next) 649 { 650 ++deps_found; 651 if (order_only) 652 d->ignore_mtime = 1; 653 } 654 655 /* Set up for the next word. */ 656 nptr += len; 657 } 658 659 /* If there are more than max_pattern_deps prerequisites (due to 660 2nd expansion), reset it and realloc the arrays. */ 661 662 if (deps_found > max_pattern_deps) 663 { 664 unsigned int l = pat - deplist; 665 deplist = xrealloc (deplist, 666 deps_found * sizeof (struct patdeps)); 667 pat = deplist + l; 668 max_pattern_deps = deps_found; 669 } 670 671 /* Go through the nameseq and handle each as a prereq name. */ 672 for (d = dl; d != 0; d = d->next) 673 { 674 struct dep *expl_d; 675 int is_rule = d->name == dep_name (dep); 676 677 if (file_impossible_p (d->name)) 678 { 679 /* If this prereq has already been ruled "impossible", 680 then the rule fails. Don't bother trying it on the 681 second pass either since we know that will fail. */ 682 DBS (DB_IMPLICIT, 683 (is_rule 684 ? _("Rejecting impossible rule prerequisite `%s'.\n") 685 : _("Rejecting impossible implicit prerequisite `%s'.\n"), 686 d->name)); 687 tryrules[ri].rule = 0; 688 689 failed = 1; 690 break; 691 } 692 693 memset (pat, '\0', sizeof (struct patdeps)); 694 pat->ignore_mtime = d->ignore_mtime; 695 696 DBS (DB_IMPLICIT, 697 (is_rule 698 ? _("Trying rule prerequisite `%s'.\n") 699 : _("Trying implicit prerequisite `%s'.\n"), d->name)); 700 701 /* If this prereq is also explicitly mentioned for FILE, 702 skip all tests below since it must be built no matter 703 which implicit rule we choose. */ 704 705 for (expl_d = file->deps; expl_d != 0; expl_d = expl_d->next) 706 if (streq (dep_name (expl_d), d->name)) 707 break; 708 if (expl_d != 0) 709 { 710 (pat++)->name = d->name; 711 continue; 712 } 713 714 /* The DEP->changed flag says that this dependency resides 715 in a nonexistent directory. So we normally can skip 716 looking for the file. However, if CHECK_LASTSLASH is 717 set, then the dependency file we are actually looking for 718 is in a different directory (the one gotten by prepending 719 FILENAME's directory), so it might actually exist. */ 720 721 /* @@ dep->changed check is disabled. */ 722 if (lookup_file (d->name) != 0 723 /*|| ((!dep->changed || check_lastslash) && */ 724 || file_exists_p (d->name)) 725 { 726 (pat++)->name = d->name; 727 continue; 728 } 729 730 /* This code, given FILENAME = "lib/foo.o", dependency name 731 "lib/foo.c", and VPATH=src, searches for 732 "src/lib/foo.c". */ 733 { 734 const char *vname = vpath_search (d->name, 0, NULL, NULL); 735 if (vname) 649 736 { 650 ++p2; 651 order_only = 1; 737 DBS (DB_IMPLICIT, 738 (_("Found prerequisite `%s' as VPATH `%s'\n"), 739 d->name, vname)); 740 (pat++)->name = d->name; 652 741 continue; 653 742 } 654 655 break; 656 } 657 658 p += len; 659 p = get_next_word (p, &len); 660 } 661 } 662 663 /* Reset the stem in FILE. */ 664 665 file->stem = 0; 666 667 /* @@ This loop can be combined with the previous one. I do 668 it separately for now for transparency.*/ 669 670 for (d = deps; d != 0; d = d->next) 671 { 672 const char *name = d->name; 673 674 if (file_impossible_p (name)) 675 { 676 /* If this dependency has already been ruled "impossible", 677 then the rule fails and don't bother trying it on the 678 second pass either since we know that will fail too. */ 679 DBS (DB_IMPLICIT, 680 (d->had_stem 681 ? _("Rejecting impossible implicit prerequisite `%s'.\n") 682 : _("Rejecting impossible rule prerequisite `%s'.\n"), 683 name)); 684 tryrules[ri] = 0; 685 743 } 744 745 /* We could not find the file in any place we should look. 746 Try to make this dependency as an intermediate file, but 747 only on the second pass. */ 748 749 if (intermed_ok) 750 { 751 DBS (DB_IMPLICIT, 752 (_("Looking for a rule with intermediate file `%s'.\n"), 753 d->name)); 754 755 if (int_file == 0) 756 int_file = alloca (sizeof (struct file)); 757 memset (int_file, '\0', sizeof (struct file)); 758 int_file->name = d->name; 759 760 if (pattern_search (int_file, 761 0, 762 depth + 1, 763 recursions + 1)) 764 { 765 pat->pattern = int_file->name; 766 int_file->name = d->name; 767 pat->file = int_file; 768 (pat++)->name = d->name; 769 int_file = 0; 770 continue; 771 } 772 773 /* If we have tried to find P as an intermediate file 774 and failed, mark that name as impossible so we won't 775 go through the search again later. */ 776 if (int_file->variables) 777 free_variable_set (int_file->variables); 778 if (int_file->pat_variables) 779 free_variable_set (int_file->pat_variables); 780 file_impossible (d->name); 781 } 782 783 /* A dependency of this rule does not exist. Therefore, this 784 rule fails. */ 686 785 failed = 1; 687 786 break; 688 787 } 689 788 690 DBS (DB_IMPLICIT, 691 (d->had_stem 692 ? _("Trying implicit prerequisite `%s'.\n") 693 : _("Trying rule prerequisite `%s'.\n"), name)); 694 695 /* If this prerequisite also happened to be explicitly mentioned 696 for FILE skip all the test below since it it has to be built 697 anyway, no matter which implicit rule we choose. */ 698 699 for (expl_d = file->deps; expl_d != 0; expl_d = expl_d->next) 700 if (streq (dep_name (expl_d), name)) 701 break; 702 if (expl_d != 0) 703 continue; 704 705 /* The DEP->changed flag says that this dependency resides in a 706 nonexistent directory. So we normally can skip looking for 707 the file. However, if CHECK_LASTSLASH is set, then the 708 dependency file we are actually looking for is in a different 709 directory (the one gotten by prepending FILENAME's directory), 710 so it might actually exist. */ 711 712 /* @@ dep->changed check is disabled. */ 713 if (((f = lookup_file (name)) != 0 && f->is_target) 714 /*|| ((!dep->changed || check_lastslash) && */ 715 || file_exists_p (name)) 716 continue; 717 718 /* This code, given FILENAME = "lib/foo.o", dependency name 719 "lib/foo.c", and VPATH=src, searches for "src/lib/foo.c". */ 720 { 721 const char *vname = vpath_search (name, 0); 722 if (vname) 723 { 724 DBS (DB_IMPLICIT, 725 (_("Found prerequisite `%s' as VPATH `%s'\n"), 726 name, vname)); 727 continue; 728 } 729 } 730 731 732 /* We could not find the file in any place we should look. Try 733 to make this dependency as an intermediate file, but only on 734 the second pass. */ 735 736 if (intermed_ok) 737 { 738 if (intermediate_file == 0) 739 intermediate_file = alloca (sizeof (struct file)); 740 741 DBS (DB_IMPLICIT, 742 (_("Looking for a rule with intermediate file `%s'.\n"), 743 name)); 744 745 memset (intermediate_file, '\0', sizeof (struct file)); 746 intermediate_file->name = name; 747 if (pattern_search (intermediate_file, 748 0, 749 depth + 1, 750 recursions + 1)) 751 { 752 d->intermediate_pattern = intermediate_file->name; 753 intermediate_file->name = strcache_add (name); 754 d->intermediate_file = intermediate_file; 755 intermediate_file = 0; 756 757 continue; 758 } 759 760 /* If we have tried to find P as an intermediate 761 file and failed, mark that name as impossible 762 so we won't go through the search again later. */ 763 if (intermediate_file->variables) 764 free_variable_set (intermediate_file->variables); 765 file_impossible (name); 766 } 767 768 /* A dependency of this rule does not exist. Therefore, 769 this rule fails. */ 770 failed = 1; 771 break; 789 /* Free the ns chain. */ 790 if (dl != &dep_simple) 791 free_dep_chain (dl); 792 793 if (failed) 794 break; 772 795 } 773 796 797 /* Reset the stem in FILE. */ 798 799 file->stem = 0; 800 774 801 /* This rule is no longer `in use' for recursive searches. */ 775 rule->in_use = 0; 776 777 if (failed) 778 { 779 /* This pattern rule does not apply. If some of its 780 dependencies succeeded, free the data structure 781 describing them. */ 782 free_idep_chain (deps); 783 deps = 0; 784 } 785 else 786 /* This pattern rule does apply. Stop looking for one. */ 787 break; 788 } 789 790 /* If we found an applicable rule without 791 intermediate files, don't try with them. */ 802 rule->in_use = 0; 803 804 if (! failed) 805 /* This pattern rule does apply. Stop looking for one. */ 806 break; 807 808 /* This pattern rule does not apply. If some of its dependencies 809 succeeded, free the data structure describing them. */ 810 /* free_idep_chain (deps); */ 811 deps = 0; 812 } 813 814 /* If we found an applicable rule without intermediate files, don't try 815 with them. */ 792 816 if (ri < nrules) 793 817 break; 794 818 795 819 rule = 0; 796 820 } 797 821 798 /* RULE is nil if the loop went all the way 799 through the list and everything failed. */ 822 /* RULE is nil if the loop went through the list but everything failed. */ 800 823 if (rule == 0) 801 824 goto done; … … 803 826 foundrule = ri; 804 827 805 /* If we are recursing, store the pattern that matched 806 FILE NAME in FILE->name for use in upper levels. */828 /* If we are recursing, store the pattern that matched FILENAME in 829 FILE->name for use in upper levels. */ 807 830 808 831 if (recursions > 0) 809 832 /* Kludge-o-matic */ 810 file->name = rule->targets[ matches[foundrule]];811 812 /* FOUND_FILES lists the dependencies for the rule we found.813 This includes the intermediate files, if any.814 Convert them into entries on the deps-chainof FILE. */815 816 if (remove_explicit_deps)833 file->name = rule->targets[tryrules[foundrule].matches]; 834 835 /* DEPLIST lists the prerequisites for the rule we found. This includes the 836 intermediate files, if any. Convert them into entries on the deps-chain 837 of FILE. */ 838 839 while (pat-- > deplist) 817 840 { 818 /* Remove all the dependencies that didn't come from 819 this implicit rule. */ 820 821 dep = file->deps; 822 while (dep != 0) 841 struct dep *dep; 842 const char *s; 843 844 if (pat->file != 0) 823 845 { 824 struct dep *next = dep->next; 825 free_dep (dep); 826 dep = next; 827 } 828 file->deps = 0; 829 } 830 831 expl_d = file->deps; /* We will add them at the end. */ 832 d_ptr = &file->deps; 833 834 for (d = deps; d != 0; d = d->next) 835 { 836 const char *s; 837 838 if (d->intermediate_file != 0) 839 { 840 /* If we need to use an intermediate file, 841 make sure it is entered as a target, with the info that was 842 found for it in the recursive pattern_search call. 843 We know that the intermediate file did not already exist as 844 a target; therefore we can assume that the deps and cmds 845 of F below are null before we change them. */ 846 847 struct file *imf = d->intermediate_file; 848 register struct file *f = lookup_file (imf->name); 846 /* If we need to use an intermediate file, make sure it is entered 847 as a target, with the info that was found for it in the recursive 848 pattern_search call. We know that the intermediate file did not 849 already exist as a target; therefore we can assume that the deps 850 and cmds of F below are null before we change them. */ 851 852 struct file *imf = pat->file; 853 struct file *f = lookup_file (imf->name); 849 854 850 855 /* We don't want to delete an intermediate file that happened … … 854 859 f->precious = 1; 855 860 else 856 f = enter_file (strcache_add (imf->name)); 857 858 f->deps = imf->deps; 859 f->cmds = imf->cmds; 860 f->stem = imf->stem; 861 f = enter_file (imf->name); 862 863 f->deps = imf->deps; 864 f->cmds = imf->cmds; 865 f->stem = imf->stem; 866 f->variables = imf->variables; 867 f->pat_variables = imf->pat_variables; 868 f->pat_searched = imf->pat_searched; 861 869 f->also_make = imf->also_make; 862 870 f->is_target = 1; 863 864 if (!f->precious) 871 f->intermediate = 1; 872 f->tried_implicit = 1; 873 874 imf = lookup_file (pat->pattern); 875 if (imf != 0 && imf->precious) 876 f->precious = 1; 877 878 for (dep = f->deps; dep != 0; dep = dep->next) 865 879 { 866 imf = lookup_file (d->intermediate_pattern);867 if (imf != 0 && imf->precious)868 f->precious = 1;880 dep->file = enter_file (dep->name); 881 dep->name = 0; 882 dep->file->tried_implicit |= dep->changed; 869 883 } 870 871 f->intermediate = 1; 872 f->tried_implicit = 1; 873 for (dep = f->deps; dep != 0; dep = dep->next) 874 { 875 dep->file = enter_file (dep->name); 876 dep->name = 0; 877 dep->file->tried_implicit |= dep->changed; 878 } 879 } 884 } 880 885 881 886 dep = alloc_dep (); 882 dep->ignore_mtime = d->ignore_mtime; 883 s = d->name; /* Hijacking the name. */ 884 d->name = 0; 885 if (recursions == 0) 886 { 887 dep->file = lookup_file (s); 888 if (dep->file == 0) 889 dep->file = enter_file (s); 890 } 887 dep->ignore_mtime = pat->ignore_mtime; 888 s = strcache_add (pat->name); 889 if (recursions) 890 dep->name = s; 891 891 else 892 dep->name = s; 893 894 if (d->intermediate_file == 0 && tryrules[foundrule]->terminal) 895 { 896 /* If the file actually existed (was not an intermediate file), 897 and the rule that found it was a terminal one, then we want 898 to mark the found file so that it will not have implicit rule 899 search done for it. If we are not entering a `struct file' for 900 it now, we indicate this with the `changed' flag. */ 901 if (dep->file == 0) 902 dep->changed = 1; 903 else 904 dep->file->tried_implicit = 1; 905 } 906 907 *d_ptr = dep; 908 d_ptr = &dep->next; 892 { 893 dep->file = lookup_file (s); 894 if (dep->file == 0) 895 dep->file = enter_file (s); 896 } 897 898 if (pat->file == 0 && tryrules[foundrule].rule->terminal) 899 { 900 /* If the file actually existed (was not an intermediate file), and 901 the rule that found it was a terminal one, then we want to mark 902 the found file so that it will not have implicit rule search done 903 for it. If we are not entering a `struct file' for it now, we 904 indicate this with the `changed' flag. */ 905 if (dep->file == 0) 906 dep->changed = 1; 907 else 908 dep->file->tried_implicit = 1; 909 } 910 911 dep->next = file->deps; 912 file->deps = dep; 909 913 } 910 914 911 *d_ptr = expl_d; 912 913 if (!checked_lastslash[foundrule]) 915 if (!tryrules[foundrule].checked_lastslash) 914 916 { 915 /* Always allocate new storage, since STEM might be 916 on the stack for anintermediate file. */917 /* Always allocate new storage, since STEM might be on the stack for an 918 intermediate file. */ 917 919 file->stem = strcache_add_len (stem, stemlen); 918 920 fullstemlen = stemlen; … … 924 926 925 927 /* We want to prepend the directory from 926 928 the original FILENAME onto the stem. */ 927 929 fullstemlen = dirlen + stemlen; 928 930 sp = alloca (fullstemlen + 1); … … 942 944 /* Set precious flag. */ 943 945 { 944 struct file *f = lookup_file (rule->targets[ matches[foundrule]]);946 struct file *f = lookup_file (rule->targets[tryrules[foundrule].matches]); 945 947 if (f && f->precious) 946 948 file->precious = 1; … … 952 954 if (rule->num > 1) 953 955 for (ri = 0; ri < rule->num; ++ri) 954 if (ri != matches[foundrule]) 955 { 956 char *p = alloca (rule->lens[ri] + fullstemlen + 1); 957 struct file *f; 958 struct dep *new = alloc_dep (); 959 960 /* GKM FIMXE: handle '|' here too */ 961 memcpy (p, rule->targets[ri], 956 if (ri != tryrules[foundrule].matches) 957 { 958 char *nm = alloca (rule->lens[ri] + fullstemlen + 1); 959 char *p = nm; 960 struct file *f; 961 struct dep *new = alloc_dep (); 962 963 /* GKM FIMXE: handle '|' here too */ 964 memcpy (p, rule->targets[ri], 962 965 rule->suffixes[ri] - rule->targets[ri] - 1); 963 964 965 966 966 p += rule->suffixes[ri] - rule->targets[ri] - 1; 967 memcpy (p, file->stem, fullstemlen); 968 p += fullstemlen; 969 memcpy (p, rule->suffixes[ri], 967 970 rule->lens[ri] - (rule->suffixes[ri] - rule->targets[ri])+1); 968 new->name = strcache_add ( p);969 970 971 972 973 974 971 new->name = strcache_add (nm); 972 new->file = enter_file (new->name); 973 new->next = file->also_make; 974 975 /* Set precious flag. */ 976 f = lookup_file (rule->targets[ri]); 977 if (f && f->precious) 975 978 new->file->precious = 1; 976 979 977 /* Set the is_target flag so that this file is not treated 978 asintermediate by the pattern rule search algorithm and980 /* Set the is_target flag so that this file is not treated as 981 intermediate by the pattern rule search algorithm and 979 982 file_exists_p cannot pick it up yet. */ 980 983 new->file->is_target = 1; 981 984 982 983 985 file->also_make = new; 986 } 984 987 985 988 done: 986 free_idep_chain (deps);987 989 free (tryrules); 990 free (deplist); 988 991 989 992 return rule != 0;
Note:
See TracChangeset
for help on using the changeset viewer.