Changeset 2596 for vendor/gnumake/current/file.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/file.c
r1989 r2596 1 1 /* Target file management 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 … … 104 104 name += 2; 105 105 #endif 106 while (name[0] == '.' && name[1] == '/' && name[2] != '\0') 106 while (name[0] == '.' 107 #ifdef HAVE_DOS_PATHS 108 && (name[1] == '/' || name[1] == '\\') 109 #else 110 && name[1] == '/' 111 #endif 112 && name[2] != '\0') 107 113 { 108 114 name += 2; 109 while (*name == '/') 115 while (*name == '/' 116 #ifdef HAVE_DOS_PATHS 117 || *name == '\\' 118 #endif 119 ) 110 120 /* Skip following slashes: ".//foo" is "foo", not "/foo". */ 111 121 ++name; … … 172 182 return f; 173 183 174 new = xmalloc (sizeof (struct file)); 175 memset (new, '\0', sizeof (struct file)); 184 new = xcalloc (sizeof (struct file)); 176 185 new->name = new->hname = name; 177 186 new->update_status = -1; … … 415 424 416 425 426 /* Given a string containing prerequisites (fully expanded), break it up into 427 a struct dep list. Enter each of these prereqs into the file database. 428 */ 417 429 struct dep * 418 parse_prereqs (char *p) 419 { 420 struct dep *new = (struct dep *) 421 multi_glob (parse_file_seq (&p, '|', sizeof (struct dep), 1), 422 sizeof (struct dep)); 430 split_prereqs (char *p) 431 { 432 struct dep *new = PARSE_FILE_SEQ (&p, struct dep, '|', NULL, 0); 423 433 424 434 if (*p) … … 429 439 430 440 ++p; 431 ood = (struct dep *) 432 multi_glob (parse_file_seq (&p, '\0', sizeof (struct dep), 1), 433 sizeof (struct dep)); 441 ood = PARSE_FILE_SEQ (&p, struct dep, '\0', NULL, 0); 434 442 435 443 if (! new) … … 450 458 } 451 459 460 /* Given a list of prerequisites, enter them into the file database. 461 If STEM is set then first expand patterns using STEM. */ 462 struct dep * 463 enter_prereqs (struct dep *deps, const char *stem) 464 { 465 struct dep *d1; 466 467 if (deps == 0) 468 return 0; 469 470 /* If we have a stem, expand the %'s. We use patsubst_expand to translate 471 the prerequisites' patterns into plain prerequisite names. */ 472 if (stem) 473 { 474 const char *pattern = "%"; 475 char *buffer = variable_expand (""); 476 struct dep *dp = deps, *dl = 0; 477 478 while (dp != 0) 479 { 480 char *percent; 481 int nl = strlen (dp->name) + 1; 482 char *nm = alloca (nl); 483 memcpy (nm, dp->name, nl); 484 percent = find_percent (nm); 485 if (percent) 486 { 487 char *o; 488 489 /* We have to handle empty stems specially, because that 490 would be equivalent to $(patsubst %,dp->name,) which 491 will always be empty. */ 492 if (stem[0] == '\0') 493 { 494 memmove (percent, percent+1, strlen (percent)); 495 o = variable_buffer_output (buffer, nm, strlen (nm) + 1); 496 } 497 else 498 o = patsubst_expand_pat (buffer, stem, pattern, nm, 499 pattern+1, percent+1); 500 501 /* If the name expanded to the empty string, ignore it. */ 502 if (buffer[0] == '\0') 503 { 504 struct dep *df = dp; 505 if (dp == deps) 506 dp = deps = deps->next; 507 else 508 dp = dl->next = dp->next; 509 free_dep (df); 510 continue; 511 } 512 513 /* Save the name. */ 514 dp->name = strcache_add_len (buffer, o - buffer); 515 } 516 dp->stem = stem; 517 dp->staticpattern = 1; 518 dl = dp; 519 dp = dp->next; 520 } 521 } 522 523 /* Enter them as files, unless they need a 2nd expansion. */ 524 for (d1 = deps; d1 != 0; d1 = d1->next) 525 { 526 if (d1->need_2nd_expansion) 527 continue; 528 529 d1->file = lookup_file (d1->name); 530 if (d1->file == 0) 531 d1->file = enter_file (d1->name); 532 d1->staticpattern = 0; 533 d1->name = 0; 534 } 535 536 return deps; 537 } 538 452 539 /* Set the intermediate flag. */ 453 540 … … 464 551 { 465 552 struct dep *d; 466 struct dep * old = f->deps;553 struct dep **dp; 467 554 const char *file_stem = f->stem; 468 unsigned int last_dep_has_cmds = f->updating;469 555 int initialized = 0; 470 556 471 557 f->updating = 0; 472 f->deps = 0; 473 474 for (d = old; d != 0; d = d->next) 475 { 476 struct dep *new, *d1; 558 559 /* Walk through the dependencies. For any dependency that needs 2nd 560 expansion, expand it then insert the result into the list. */ 561 dp = &f->deps; 562 d = f->deps; 563 while (d != 0) 564 { 477 565 char *p; 478 479 if (! d->name) 480 continue; 481 482 /* Create the dependency list. 483 If we're not doing 2nd expansion, then it's just the name. We will 484 still need to massage it though. */ 485 if (! d->need_2nd_expansion) 566 struct dep *new, *next; 567 char *name = (char *)d->name; 568 569 if (! d->name || ! d->need_2nd_expansion) 486 570 { 487 p = variable_expand (""); 488 variable_buffer_output (p, d->name, strlen (d->name) + 1); 489 p = variable_buffer; 571 /* This one is all set already. */ 572 dp = &d->next; 573 d = d->next; 574 continue; 490 575 } 491 else 576 577 /* If it's from a static pattern rule, convert the patterns into 578 "$*" so they'll expand properly. */ 579 if (d->staticpattern) 492 580 { 493 /* If it's from a static pattern rule, convert the patterns into 494 "$*" so they'll expand properly. */ 495 if (d->staticpattern) 496 { 497 char *o; 498 char *buffer = variable_expand (""); 499 500 o = subst_expand (buffer, d->name, "%", "$*", 1, 2, 0); 501 502 d->name = strcache_add_len (variable_buffer, 503 o - variable_buffer); 504 d->staticpattern = 0; /* Clear staticpattern so that we don't 505 re-expand %s below. */ 506 } 507 508 /* We are going to do second expansion so initialize file variables 509 for the file. Since the stem for static pattern rules comes from 510 individual dep lines, we will temporarily set f->stem to d->stem. 511 */ 512 if (!initialized) 513 { 514 initialize_file_variables (f, 0); 515 initialized = 1; 516 } 517 518 if (d->stem != 0) 519 f->stem = d->stem; 520 521 set_file_variables (f); 522 523 p = variable_expand_for_file (d->name, f); 524 525 if (d->stem != 0) 526 f->stem = file_stem; 581 char *o; 582 d->name = o = variable_expand (""); 583 o = subst_expand (o, name, "%", "$*", 1, 2, 0); 584 *o = '\0'; 585 free (name); 586 d->name = name = xstrdup (d->name); 587 d->staticpattern = 0; 527 588 } 528 589 529 /* Parse the prerequisites. */ 530 new = parse_prereqs (p); 531 532 /* If this dep list was from a static pattern rule, expand the %s. We 533 use patsubst_expand to translate the prerequisites' patterns into 534 plain prerequisite names. */ 535 if (new && d->staticpattern) 590 /* We're going to do second expansion so initialize file variables for 591 the file. Since the stem for static pattern rules comes from 592 individual dep lines, we will temporarily set f->stem to d->stem. */ 593 if (!initialized) 536 594 { 537 const char *pattern = "%"; 538 char *buffer = variable_expand (""); 539 struct dep *dp = new, *dl = 0; 540 541 while (dp != 0) 542 { 543 char *percent; 544 int nl = strlen (dp->name) + 1; 545 char *nm = alloca (nl); 546 memcpy (nm, dp->name, nl); 547 percent = find_percent (nm); 548 if (percent) 549 { 550 char *o; 551 552 /* We have to handle empty stems specially, because that 553 would be equivalent to $(patsubst %,dp->name,) which 554 will always be empty. */ 555 if (d->stem[0] == '\0') 556 { 557 memmove (percent, percent+1, strlen (percent)); 558 o = variable_buffer_output (buffer, nm, strlen (nm) + 1); 559 } 560 else 561 o = patsubst_expand_pat (buffer, d->stem, pattern, nm, 562 pattern+1, percent+1); 563 564 /* If the name expanded to the empty string, ignore it. */ 565 if (buffer[0] == '\0') 566 { 567 struct dep *df = dp; 568 if (dp == new) 569 dp = new = new->next; 570 else 571 dp = dl->next = dp->next; 572 free_dep (df); 573 continue; 574 } 575 576 /* Save the name. */ 577 dp->name = strcache_add_len (buffer, o - buffer); 578 } 579 dl = dp; 580 dp = dp->next; 581 } 595 initialize_file_variables (f, 0); 596 initialized = 1; 582 597 } 583 598 584 /* Enter them as files. */ 585 for (d1 = new; d1 != 0; d1 = d1->next) 599 if (d->stem != 0) 600 f->stem = d->stem; 601 602 set_file_variables (f); 603 604 p = variable_expand_for_file (d->name, f); 605 606 if (d->stem != 0) 607 f->stem = file_stem; 608 609 /* At this point we don't need the name anymore: free it. */ 610 free (name); 611 612 /* Parse the prerequisites and enter them into the file database. */ 613 new = enter_prereqs (split_prereqs (p), d->stem); 614 615 /* If there were no prereqs here (blank!) then throw this one out. */ 616 if (new == 0) 586 617 { 587 d1->file = lookup_file (d1->name); 588 if (d1->file == 0) 589 d1->file = enter_file (d1->name); 590 d1->name = 0; 591 d1->staticpattern = 0; 592 d1->need_2nd_expansion = 0; 618 *dp = d->next; 619 free_dep (d); 620 d = *dp; 621 continue; 593 622 } 594 623 595 /* Add newly parsed deps to f->deps. If this is the last dependency 596 line and this target has commands then put it in front so the 597 last dependency line (the one with commands) ends up being the 598 first. This is important because people expect $< to hold first 599 prerequisite from the rule with commands. If it is not the last 600 dependency line or the rule does not have commands then link it 601 at the end so it appears in makefile order. */ 602 603 if (new != 0) 604 { 605 if (d->next == 0 && last_dep_has_cmds) 606 { 607 struct dep **d_ptr; 608 for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next) 609 ; 610 611 *d_ptr = f->deps; 612 f->deps = new; 613 } 614 else 615 { 616 struct dep **d_ptr; 617 for (d_ptr = &f->deps; *d_ptr; d_ptr = &(*d_ptr)->next) 618 ; 619 620 *d_ptr = new; 621 } 622 } 623 } 624 625 free_dep_chain (old); 624 /* Add newly parsed prerequisites. */ 625 next = d->next; 626 *dp = new; 627 for (dp = &new->next, d = new->next; d != 0; dp = &d->next, d = d->next) 628 ; 629 *dp = next; 630 d = *dp; 631 } 632 } 633 634 /* Reset the updating flag. */ 635 636 static void 637 reset_updating (const void *item) 638 { 639 struct file *f = (struct file *) item; 640 f->updating = 0; 626 641 } 627 642 … … 638 653 struct file *f2; 639 654 struct dep *d; 640 struct file **file_slot_0; 641 struct file **file_slot; 642 struct file **file_end; 643 644 /* Perform second expansion and enter each dependency name as a file. */ 645 646 /* Expand .SUFFIXES first; it's dependencies are used for $$* calculation. */ 647 for (f = lookup_file (".SUFFIXES"); f != 0; f = f->prev) 648 expand_deps (f); 649 650 /* For every target that's not .SUFFIXES, expand its dependencies. 651 We must use hash_dump (), because within this loop we might add new files 652 to the table, possibly causing an in-situ table expansion. */ 653 file_slot_0 = (struct file **) hash_dump (&files, 0, 0); 654 file_end = file_slot_0 + files.ht_fill; 655 for (file_slot = file_slot_0; file_slot < file_end; file_slot++) 656 for (f = *file_slot; f != 0; f = f->prev) 657 if (strcmp (f->name, ".SUFFIXES") != 0) 655 656 /* Remember that we've done this. Once we start snapping deps we can no 657 longer define new targets. */ 658 snapped_deps = 1; 659 660 /* Perform second expansion and enter each dependency name as a file. We 661 must use hash_dump() here because within these loops we likely add new 662 files to the table, possibly causing an in-situ table expansion. 663 664 We only need to do this if second_expansion has been defined; if it 665 hasn't then all deps were expanded as the makefile was read in. If we 666 ever change make to be able to unset .SECONDARY_EXPANSION this will have 667 to change. */ 668 669 if (second_expansion) 670 { 671 struct file **file_slot_0 = (struct file **) hash_dump (&files, 0, 0); 672 struct file **file_end = file_slot_0 + files.ht_fill; 673 struct file **file_slot; 674 const char *suffixes; 675 676 /* Expand .SUFFIXES: its prerequisites are used for $$* calc. */ 677 f = lookup_file (".SUFFIXES"); 678 suffixes = f ? f->name : 0; 679 for (; f != 0; f = f->prev) 658 680 expand_deps (f); 659 free (file_slot_0); 681 682 /* For every target that's not .SUFFIXES, expand its prerequisites. */ 683 684 for (file_slot = file_slot_0; file_slot < file_end; file_slot++) 685 for (f = *file_slot; f != 0; f = f->prev) 686 if (f->name != suffixes) 687 expand_deps (f); 688 free (file_slot_0); 689 } 690 else 691 /* We're not doing second expansion, so reset updating. */ 692 hash_map (&files, reset_updating); 660 693 661 694 /* Now manage all the special targets. */ … … 738 771 /* This needs more work: what if the user sets this in the makefile? 739 772 if (posix_pedantic) 740 define_variable (STRING_SIZE_TUPLE("OUTPUT_OPTION"), "", o_default, 1);773 define_variable_cname ("OUTPUT_OPTION", "", o_default, 1); 741 774 */ 742 775 #endif 743 744 /* Remember that we've done this. */745 snapped_deps = 1;746 776 } 747 777 … … 868 898 /* Print the data base of files. */ 869 899 900 void 901 print_prereqs (const struct dep *deps) 902 { 903 const struct dep *ood = 0; 904 905 /* Print all normal dependencies; note any order-only deps. */ 906 for (; deps != 0; deps = deps->next) 907 if (! deps->ignore_mtime) 908 printf (" %s", dep_name (deps)); 909 else if (! ood) 910 ood = deps; 911 912 /* Print order-only deps, if we have any. */ 913 if (ood) 914 { 915 printf (" | %s", dep_name (ood)); 916 for (ood = ood->next; ood != 0; ood = ood->next) 917 if (ood->ignore_mtime) 918 printf (" %s", dep_name (ood)); 919 } 920 921 putchar ('\n'); 922 } 923 870 924 static void 871 925 print_file (const void *item) 872 926 { 873 927 const struct file *f = item; 874 struct dep *d;875 struct dep *ood = 0;876 928 877 929 putchar ('\n'); … … 879 931 puts (_("# Not a target:")); 880 932 printf ("%s:%s", f->name, f->double_colon ? ":" : ""); 881 882 /* Print all normal dependencies; note any order-only deps. */ 883 for (d = f->deps; d != 0; d = d->next) 884 if (! d->ignore_mtime) 885 printf (" %s", dep_name (d)); 886 else if (! ood) 887 ood = d; 888 889 /* Print order-only deps, if we have any. */ 890 if (ood) 891 { 892 printf (" | %s", dep_name (ood)); 893 for (d = ood->next; d != 0; d = d->next) 894 if (d->ignore_mtime) 895 printf (" %s", dep_name (d)); 896 } 897 898 putchar ('\n'); 933 print_prereqs (f->deps); 899 934 900 935 if (f->precious) … … 915 950 if (f->also_make != 0) 916 951 { 952 const struct dep *d; 917 953 fputs (_("# Also makes:"), stdout); 918 954 for (d = f->also_make; d != 0; d = d->next) … … 999 1035 do{\ 1000 1036 if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \ 1001 printf ("%s: Field %snot cached: %s\n", _p->name, # _n, _p->_n); \1037 error (NULL, "%s: Field '%s' not cached: %s\n", _p->name, # _n, _p->_n); \ 1002 1038 }while(0) 1003 1039 … … 1016 1052 for (d = f->deps; d != 0; d = d->next) 1017 1053 { 1018 VERIFY_CACHED (d, name); 1054 if (! d->need_2nd_expansion) 1055 VERIFY_CACHED (d, name); 1019 1056 VERIFY_CACHED (d, stem); 1020 1057 }
Note:
See TracChangeset
for help on using the changeset viewer.