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