Changeset 2591 for trunk/src/kmk/file.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/file.c
r2024 r2591 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 … … 119 119 name += 2; 120 120 #endif 121 while (name[0] == '.' && name[1] == '/' && name[2] != '\0') 121 while (name[0] == '.' 122 #ifdef HAVE_DOS_PATHS 123 && (name[1] == '/' || name[1] == '\\') 124 #else 125 && name[1] == '/' 126 #endif 127 && name[2] != '\0') 122 128 { 123 129 name += 2; 124 while (*name == '/') 130 while (*name == '/' 131 #ifdef HAVE_DOS_PATHS 132 || *name == '\\' 133 #endif 134 ) 125 135 /* Skip following slashes: ".//foo" is "foo", not "/foo". */ 126 136 ++name; … … 230 240 231 241 #ifndef CONFIG_WITH_ALLOC_CACHES 232 new = xmalloc (sizeof (struct file)); 233 memset (new, '\0', sizeof (struct file)); 242 new = xcalloc (sizeof (struct file)); 234 243 #else 235 244 new = alloccache_calloc (&file_cache); … … 511 520 512 521 522 /* Given a string containing prerequisites (fully expanded), break it up into 523 a struct dep list. Enter each of these prereqs into the file database. 524 */ 513 525 struct dep * 514 parse_prereqs (char *p) 515 { 516 #ifndef CONFIG_WITH_ALLOC_CACHES 517 struct dep *new = (struct dep *) 518 multi_glob (parse_file_seq (&p, '|', sizeof (struct dep), 1), 519 sizeof (struct dep)); 520 #else 521 struct dep *new = (struct dep *) 522 multi_glob (parse_file_seq (&p, '|', &dep_cache, 1), &dep_cache); 523 #endif 526 split_prereqs (char *p) 527 { 528 struct dep *new = PARSE_FILE_SEQ (&p, struct dep, '|', NULL, 0); 524 529 525 530 if (*p) … … 530 535 531 536 ++p; 532 #ifndef CONFIG_WITH_ALLOC_CACHES 533 ood = (struct dep *) 534 multi_glob (parse_file_seq (&p, '\0', sizeof (struct dep), 1), 535 sizeof (struct dep)); 536 #else 537 ood = (struct dep *) 538 multi_glob (parse_file_seq (&p, '\0', &dep_cache, 1), &dep_cache); 539 #endif 537 ood = PARSE_FILE_SEQ (&p, struct dep, '\0', NULL, 0); 540 538 541 539 if (! new) … … 556 554 } 557 555 556 /* Given a list of prerequisites, enter them into the file database. 557 If STEM is set then first expand patterns using STEM. */ 558 struct dep * 559 enter_prereqs (struct dep *deps, const char *stem) 560 { 561 struct dep *d1; 562 563 if (deps == 0) 564 return 0; 565 566 /* If we have a stem, expand the %'s. We use patsubst_expand to translate 567 the prerequisites' patterns into plain prerequisite names. */ 568 if (stem) 569 { 570 const char *pattern = "%"; 571 char *buffer = variable_expand (""); 572 struct dep *dp = deps, *dl = 0; 573 574 while (dp != 0) 575 { 576 char *percent; 577 int nl = strlen (dp->name) + 1; 578 char *nm = alloca (nl); 579 memcpy (nm, dp->name, nl); 580 percent = find_percent (nm); 581 if (percent) 582 { 583 char *o; 584 585 /* We have to handle empty stems specially, because that 586 would be equivalent to $(patsubst %,dp->name,) which 587 will always be empty. */ 588 if (stem[0] == '\0') 589 { 590 memmove (percent, percent+1, strlen (percent)); 591 o = variable_buffer_output (buffer, nm, strlen (nm) + 1); 592 } 593 else 594 o = patsubst_expand_pat (buffer, stem, pattern, nm, 595 pattern+1, percent+1); 596 597 /* If the name expanded to the empty string, ignore it. */ 598 if (buffer[0] == '\0') 599 { 600 struct dep *df = dp; 601 if (dp == deps) 602 dp = deps = deps->next; 603 else 604 dp = dl->next = dp->next; 605 free_dep (df); 606 continue; 607 } 608 609 /* Save the name. */ 610 dp->name = strcache_add_len (buffer, o - buffer); 611 } 612 dp->stem = stem; 613 dp->staticpattern = 1; 614 dl = dp; 615 dp = dp->next; 616 } 617 } 618 619 /* Enter them as files, unless they need a 2nd expansion. */ 620 for (d1 = deps; d1 != 0; d1 = d1->next) 621 { 622 if (d1->need_2nd_expansion) 623 continue; 624 625 d1->file = lookup_file (d1->name); 626 if (d1->file == 0) 627 d1->file = enter_file (d1->name); 628 d1->staticpattern = 0; 629 d1->name = 0; 630 } 631 632 return deps; 633 } 634 558 635 /* Set the intermediate flag. */ 559 636 … … 570 647 { 571 648 struct dep *d; 572 struct dep * old = f->deps;649 struct dep **dp; 573 650 const char *file_stem = f->stem; 574 unsigned int last_dep_has_cmds = f->updating;575 651 int initialized = 0; 576 652 577 653 f->updating = 0; 578 f->deps = 0; 579 580 for (d = old; d != 0; d = d->next) 581 { 582 struct dep *new, *d1; 654 655 /* Walk through the dependencies. For any dependency that needs 2nd 656 expansion, expand it then insert the result into the list. */ 657 dp = &f->deps; 658 d = f->deps; 659 while (d != 0) 660 { 583 661 char *p; 584 #ifdef CONFIG_WITH_STRCACHE2 585 unsigned int len; 586 #endif 587 588 if (! d->name) 589 continue; 662 struct dep *new, *next; 663 char *name = (char *)d->name; 664 665 if (! d->name || ! d->need_2nd_expansion) 666 { 667 /* This one is all set already. */ 668 dp = &d->next; 669 d = d->next; 670 continue; 671 } 590 672 591 673 #ifdef CONFIG_WITH_INCLUDEDEP … … 597 679 if (d->includedep) 598 680 { 599 new = d1= alloc_dep();681 struct dep *d1 = new = alloc_dep(); 600 682 d1->staticpattern = 0; 601 683 d1->need_2nd_expansion = 0; … … 618 700 } 619 701 else 702 { 703 #endif /* CONFIG_WITH_INCLUDEDEP */ 704 705 /* If it's from a static pattern rule, convert the patterns into 706 "$*" so they'll expand properly. */ 707 if (d->staticpattern) 620 708 { 621 #endif 622 623 /* Create the dependency list. 624 If we're not doing 2nd expansion, then it's just the name. We will 625 still need to massage it though. */ 626 if (! d->need_2nd_expansion) 709 char *o; 710 d->name = o = variable_expand (""); 711 o = subst_expand (o, name, "%", "$*", 1, 2, 0); 712 *o = '\0'; 713 free (name); 714 #ifndef CONFIG_WITH_STRCACHE2 715 d->name = name = xstrdup (variable_buffer); /* bird not d->name, can be reallocated */ 716 #else 717 d->name = strcache2_add (&file_strcache, variable_buffer, o - variable_buffer); 718 #endif 719 d->staticpattern = 0; 720 } 721 722 /* We're going to do second expansion so initialize file variables for 723 the file. Since the stem for static pattern rules comes from 724 individual dep lines, we will temporarily set f->stem to d->stem. */ 725 if (!initialized) 627 726 { 628 p = variable_expand (""); 629 #ifndef CONFIG_WITH_STRCACHE2 630 variable_buffer_output (p, d->name, strlen (d->name) + 1); 727 initialize_file_variables (f, 0); 728 initialized = 1; 729 } 730 731 if (d->stem != 0) 732 f->stem = d->stem; 733 734 #if defined(CONFIG_WITH_COMMANDS_FUNC) || defined (CONFIG_WITH_DOT_MUST_MAKE) 735 set_file_variables (f, 0 /* real call, f->deps == 0 so we're ok. */); 631 736 #else 632 len = strcache2_get_len (&file_strcache, d->name); 633 variable_buffer_output (p, d->name, len + 1); 634 #endif 635 p = variable_buffer; 737 set_file_variables (f); 738 #endif 739 740 p = variable_expand_for_file (d->name, f); 741 742 if (d->stem != 0) 743 f->stem = file_stem; 744 745 /* At this point we don't need the name anymore: free it. */ 746 free (name); 747 748 /* Parse the prerequisites and enter them into the file database. */ 749 new = enter_prereqs (split_prereqs (p), d->stem); 750 751 /* If there were no prereqs here (blank!) then throw this one out. */ 752 if (new == 0) 753 { 754 *dp = d->next; 755 free_dep (d); 756 d = *dp; 757 continue; 636 758 } 637 else638 {639 /* If it's from a static pattern rule, convert the patterns into640 "$*" so they'll expand properly. */641 if (d->staticpattern)642 {643 char *o;644 char *buffer = variable_expand ("");645 646 o = subst_expand (buffer, d->name, "%", "$*", 1, 2, 0);647 buffer = variable_buffer; /* bird - variable_buffer may have been reallocated. */648 649 d->name = strcache_add_len (variable_buffer,650 o - variable_buffer);651 d->staticpattern = 0; /* Clear staticpattern so that we don't652 re-expand %s below. */653 }654 655 /* We are going to do second expansion so initialize file variables656 for the file. Since the stem for static pattern rules comes from657 individual dep lines, we will temporarily set f->stem to d->stem.658 */659 if (!initialized)660 {661 initialize_file_variables (f, 0);662 initialized = 1;663 }664 665 if (d->stem != 0)666 f->stem = d->stem;667 668 #if defined(CONFIG_WITH_COMMANDS_FUNC) || defined (CONFIG_WITH_DOT_MUST_MAKE)669 set_file_variables (f, 0 /* real call, f->deps == 0 so we're ok. */);670 #else671 set_file_variables (f);672 #endif673 674 #if !defined (CONFIG_WITH_VALUE_LENGTH) || !defined (CONFIG_WITH_STRCACHE2)675 p = variable_expand_for_file (d->name, f);676 #else677 len = strcache2_get_len (&file_strcache, d->name);678 p = variable_expand_for_file_2 (NULL, d->name, len, f, &len);679 #endif680 681 if (d->stem != 0)682 f->stem = file_stem;683 }684 685 /* Parse the prerequisites. */686 new = parse_prereqs (p);687 688 /* If this dep list was from a static pattern rule, expand the %s. We689 use patsubst_expand to translate the prerequisites' patterns into690 plain prerequisite names. */691 if (new && d->staticpattern)692 {693 const char *pattern = "%";694 char *buffer = variable_expand ("");695 struct dep *dp = new, *dl = 0;696 697 while (dp != 0)698 {699 char *percent;700 #ifndef KMK701 int nl = strlen (dp->name) + 1;702 char *nm = alloca (nl);703 memcpy (nm, dp->name, nl);704 percent = find_percent (nm);705 #else /* KMK - don't make a stack copy unless it's actually required! */706 unsigned int nl = strcache2_get_len (&file_strcache, dp->name);707 char *nm;708 percent = memchr (dp->name, '%', nl);709 if (percent)710 {711 nm = alloca (nl + 1);712 memcpy (nm, dp->name, nl + 1);713 percent = find_percent (nm);714 }715 #endif /* KMK */716 if (percent)717 {718 char *o;719 720 /* We have to handle empty stems specially, because that721 would be equivalent to $(patsubst %,dp->name,) which722 will always be empty. */723 if (d->stem[0] == '\0')724 {725 memmove (percent, percent+1, strlen (percent));726 o = variable_buffer_output (buffer, nm, strlen (nm) + 1);727 }728 else729 {730 o = patsubst_expand_pat (buffer, d->stem, pattern, nm,731 pattern+1, percent+1);732 o = variable_buffer_output (o, "", 1); /* bird fix - patsubst_expand_pat doesn't terminate,733 the if case does and strcache would appreciate it. */734 }735 buffer = variable_buffer; /* bird fix - variable_buffer may have been reallocated. */736 737 738 /* If the name expanded to the empty string, ignore it. */739 if (buffer[0] == '\0')740 {741 struct dep *df = dp;742 if (dp == new)743 dp = new = new->next;744 else745 dp = dl->next = dp->next;746 free_dep (df);747 continue;748 }749 750 /* Save the name. */751 dp->name = strcache_add_len (buffer, o - buffer - 1); /* bird fix - don't include the terminator. */752 }753 dl = dp;754 dp = dp->next;755 }756 }757 758 /* Enter them as files. */759 for (d1 = new; d1 != 0; d1 = d1->next)760 {761 d1->file = lookup_file (d1->name);762 if (d1->file == 0)763 d1->file = enter_file (d1->name);764 d1->name = 0;765 d1->staticpattern = 0;766 d1->need_2nd_expansion = 0;767 }768 759 769 760 #ifdef CONFIG_WITH_INCLUDEDEP 770 } 771 #endif 772 773 /* Add newly parsed deps to f->deps. If this is the last dependency 774 line and this target has commands then put it in front so the 775 last dependency line (the one with commands) ends up being the 776 first. This is important because people expect $< to hold first 777 prerequisite from the rule with commands. If it is not the last 778 dependency line or the rule does not have commands then link it 779 at the end so it appears in makefile order. */ 780 781 if (new != 0) 782 { 783 if (d->next == 0 && last_dep_has_cmds) 784 { 785 struct dep **d_ptr; 786 for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next) 787 ; 788 789 *d_ptr = f->deps; 790 f->deps = new; 791 } 792 else 793 { 794 struct dep **d_ptr; 795 for (d_ptr = &f->deps; *d_ptr; d_ptr = &(*d_ptr)->next) 796 ; 797 798 *d_ptr = new; 799 } 800 } 801 } 802 803 free_dep_chain (old); 761 } 762 #endif 763 764 /* Add newly parsed prerequisites. */ 765 next = d->next; 766 *dp = new; 767 for (dp = &new->next, d = new->next; d != 0; dp = &d->next, d = d->next) 768 ; 769 *dp = next; 770 d = *dp; 771 } 772 } 773 774 /* Reset the updating flag. */ 775 776 static void 777 reset_updating (const void *item) 778 { 779 struct file *f = (struct file *) item; 780 f->updating = 0; 804 781 } 805 782 … … 816 793 struct file *f2; 817 794 struct dep *d; 818 struct file **file_slot_0; 819 struct file **file_slot; 820 struct file **file_end; 821 822 /* Perform second expansion and enter each dependency name as a file. */ 823 824 /* Expand .SUFFIXES first; it's dependencies are used for $$* calculation. */ 825 for (f = lookup_file (".SUFFIXES"); f != 0; f = f->prev) 826 expand_deps (f); 795 796 /* Remember that we've done this. Once we start snapping deps we can no 797 longer define new targets. */ 798 snapped_deps = 1; 827 799 828 800 #ifdef CONFIG_WITH_2ND_TARGET_EXPANSION … … 832 804 if (second_target_expansion) 833 805 { 806 struct file **file_slot_0, **file_end, **file_slot; 834 807 # ifdef KMK /* turn on warnings here. */ 835 808 int save = warn_undefined_variables_flag; … … 862 835 #endif /* CONFIG_WITH_INCLUDEDEP */ 863 836 864 /* For every target that's not .SUFFIXES, expand its dependencies. 865 We must use hash_dump (), because within this loop we might add new files 866 to the table, possibly causing an in-situ table expansion. */ 867 file_slot_0 = (struct file **) hash_dump (&files, 0, 0); 868 file_end = file_slot_0 + files.ht_fill; 869 for (file_slot = file_slot_0; file_slot < file_end; file_slot++) 870 for (f = *file_slot; f != 0; f = f->prev) 871 #ifndef CONFIG_WITH_STRCACHE2 872 if (strcmp (f->name, ".SUFFIXES") != 0) 873 #else 874 if (f->name != suffixes_strcached) 875 #endif 837 /* Perform second expansion and enter each dependency name as a file. We 838 must use hash_dump() here because within these loops we likely add new 839 files to the table, possibly causing an in-situ table expansion. 840 841 We only need to do this if second_expansion has been defined; if it 842 hasn't then all deps were expanded as the makefile was read in. If we 843 ever change make to be able to unset .SECONDARY_EXPANSION this will have 844 to change. */ 845 846 if (second_expansion) 847 { 848 struct file **file_slot_0 = (struct file **) hash_dump (&files, 0, 0); 849 struct file **file_end = file_slot_0 + files.ht_fill; 850 struct file **file_slot; 851 const char *suffixes; 852 853 /* Expand .SUFFIXES: its prerequisites are used for $$* calc. */ 854 f = lookup_file (".SUFFIXES"); 855 suffixes = f ? f->name : 0; 856 for (; f != 0; f = f->prev) 876 857 expand_deps (f); 858 877 859 #ifdef KMK 878 /* This is a HACK to work around the still broken test #9 in879 features/double_colon. It produces the wrong result if the build is880 parallel because of changed evaluation order. Just make these881 problematic rules execute in single field till a proper fix is882 forthcomming... */883 884 for (file_slot = file_slot_0; file_slot < file_end; file_slot++)885 if ( (f = *file_slot) != 0886 && f->double_colon887 && ( f->double_colon != f888 || f->last != f))889 for (f2 = f->double_colon; f2 != 0; f2 = f2->prev)890 f2->command_flags |= COMMANDS_NOTPARALLEL;860 /* This is a HACK to work around the still broken test #9 in 861 features/double_colon. It produces the wrong result if the build is 862 parallel because of changed evaluation order. Just make these 863 problematic rules execute in single field till a proper fix is 864 forthcomming... */ 865 866 for (file_slot = file_slot_0; file_slot < file_end; file_slot++) 867 if ( (f = *file_slot) != 0 868 && f->double_colon 869 && ( f->double_colon != f 870 || f->last != f)) 871 for (f2 = f->double_colon; f2 != 0; f2 = f2->prev) 872 f2->command_flags |= COMMANDS_NOTPARALLEL; 891 873 #endif /* KMK */ 892 free (file_slot_0); 874 875 /* For every target that's not .SUFFIXES, expand its prerequisites. */ 876 877 for (file_slot = file_slot_0; file_slot < file_end; file_slot++) 878 for (f = *file_slot; f != 0; f = f->prev) 879 if (f->name != suffixes) 880 expand_deps (f); 881 free (file_slot_0); 882 } 883 else 884 /* We're not doing second expansion, so reset updating. */ 885 hash_map (&files, reset_updating); 893 886 894 887 /* Now manage all the special targets. */ … … 985 978 /* This needs more work: what if the user sets this in the makefile? 986 979 if (posix_pedantic) 987 define_variable (STRING_SIZE_TUPLE("OUTPUT_OPTION"), "", o_default, 1);980 define_variable_cname ("OUTPUT_OPTION", "", o_default, 1); 988 981 */ 989 982 #endif 990 991 /* Remember that we've done this. */992 snapped_deps = 1;993 983 } 994 984 … … 1121 1111 /* Print the data base of files. */ 1122 1112 1113 void 1114 print_prereqs (const struct dep *deps) 1115 { 1116 const struct dep *ood = 0; 1117 1118 /* Print all normal dependencies; note any order-only deps. */ 1119 for (; deps != 0; deps = deps->next) 1120 if (! deps->ignore_mtime) 1121 printf (" %s", dep_name (deps)); 1122 else if (! ood) 1123 ood = deps; 1124 1125 /* Print order-only deps, if we have any. */ 1126 if (ood) 1127 { 1128 printf (" | %s", dep_name (ood)); 1129 for (ood = ood->next; ood != 0; ood = ood->next) 1130 if (ood->ignore_mtime) 1131 printf (" %s", dep_name (ood)); 1132 } 1133 1134 putchar ('\n'); 1135 } 1136 1123 1137 static void 1124 1138 print_file (const void *item) 1125 1139 { 1126 1140 const struct file *f = item; 1127 struct dep *d;1128 struct dep *ood = 0;1129 1141 1130 1142 putchar ('\n'); … … 1158 1170 printf ("%s:%s", f->name, f->double_colon ? ":" : ""); 1159 1171 1160 /* Print all normal dependencies; note any order-only deps. */ 1161 for (d = f->deps; d != 0; d = d->next) 1162 if (! d->ignore_mtime) 1163 printf (" %s", dep_name (d)); 1164 else if (! ood) 1165 ood = d; 1166 1167 /* Print order-only deps, if we have any. */ 1168 if (ood) 1169 { 1170 printf (" | %s", dep_name (ood)); 1171 for (d = ood->next; d != 0; d = d->next) 1172 if (d->ignore_mtime) 1173 printf (" %s", dep_name (d)); 1174 } 1175 1176 putchar ('\n'); 1172 print_prereqs (f->deps); 1177 1173 1178 1174 #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET … … 1206 1202 if (f->also_make != 0) 1207 1203 { 1204 const struct dep *d; 1208 1205 fputs (_("# Also makes:"), stdout); 1209 1206 for (d = f->also_make; d != 0; d = d->next) … … 1300 1297 do{\ 1301 1298 if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \ 1302 printf ("%s: Field %snot cached: %s\n", _p->name, # _n, _p->_n); \1299 error (NULL, "%s: Field '%s' not cached: %s\n", _p->name, # _n, _p->_n); \ 1303 1300 }while(0) 1304 1301 … … 1317 1314 for (d = f->deps; d != 0; d = d->next) 1318 1315 { 1319 VERIFY_CACHED (d, name); 1316 if (! d->need_2nd_expansion) 1317 VERIFY_CACHED (d, name); 1320 1318 VERIFY_CACHED (d, stem); 1321 1319 }
Note:
See TracChangeset
for help on using the changeset viewer.