Changeset 900 in kBuild for vendor/gnumake/current/file.c
- Timestamp:
- May 23, 2007 3:13:11 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/file.c
r501 r900 70 70 /* Access the hash table of all file records. 71 71 lookup_file given a name, return the struct file * for that name, 72 or nil if there is none.73 enter_file similar, but create one if there is none.*/72 or nil if there is none. 73 */ 74 74 75 75 struct file * 76 lookup_file (c har *name)77 { 78 registerstruct file *f;76 lookup_file (const char *name) 77 { 78 struct file *f; 79 79 struct file file_key; 80 80 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS) 81 register char *lname, *ln;81 char *lname; 82 82 #endif 83 83 … … 91 91 if (*name != '.') 92 92 { 93 register char *n; 94 lname = (char *) malloc (strlen (name) + 1); 93 const char *n; 94 char *ln; 95 lname = xstrdup (name); 95 96 for (n = name, ln = lname; *n != '\0'; ++n, ++ln) 96 97 *ln = isupper ((unsigned char)*n) ? tolower ((unsigned char)*n) : *n; … … 113 114 if (*name == '\0') 114 115 /* It was all slashes after a dot. */ 115 #if def VMS116 #if defined(VMS) 116 117 name = "[]"; 117 #else 118 #ifdef _AMIGA 118 #elif defined(_AMIGA) 119 119 name = ""; 120 120 #else 121 121 name = "./"; 122 #endif /* AMIGA */ 123 #endif /* VMS */ 122 #endif 124 123 125 124 file_key.hname = name; 126 f = (struct file *)hash_find_item (&files, &file_key);125 f = hash_find_item (&files, &file_key); 127 126 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS) 128 127 if (*name != '.') 129 128 free (lname); 130 129 #endif 130 131 131 return f; 132 132 } 133 133 134 /* Look up a file record for file NAME and return it. 135 Create a new record if one doesn't exist. NAME will be stored in the 136 new record so it should be constant or in the strcache etc. 137 */ 138 134 139 struct file * 135 enter_file (c har *name)136 { 137 registerstruct file *f;138 registerstruct file *new;139 registerstruct file **file_slot;140 enter_file (const char *name) 141 { 142 struct file *f; 143 struct file *new; 144 struct file **file_slot; 140 145 struct file file_key; 141 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)142 char *lname, *ln;143 #endif144 146 145 147 assert (*name != '\0'); 148 assert (strcache_iscached (name)); 146 149 147 150 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS) 148 151 if (*name != '.') 149 152 { 150 register char *n; 151 lname = (char *) malloc (strlen (name) + 1); 153 const char *n; 154 char *lname, *ln; 155 lname = xstrdup (name); 152 156 for (n = name, ln = lname; *n != '\0'; ++n, ++ln) 153 { 154 if (isupper ((unsigned char)*n)) 155 *ln = tolower ((unsigned char)*n); 156 else 157 *ln = *n; 158 } 159 160 *ln = 0; 161 /* Creates a possible leak, old value of name is unreachable, but I 162 currently don't know how to fix it. */ 163 name = lname; 157 if (isupper ((unsigned char)*n)) 158 *ln = tolower ((unsigned char)*n); 159 else 160 *ln = *n; 161 162 *ln = '\0'; 163 name = strcache_add (lname); 164 free (lname); 164 165 } 165 166 #endif … … 169 170 f = *file_slot; 170 171 if (! HASH_VACANT (f) && !f->double_colon) 171 { 172 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS) 173 if (*name != '.') 174 free (lname); 175 #endif 176 return f; 177 } 178 179 new = (struct file *) xmalloc (sizeof (struct file)); 180 bzero ((char *) new, sizeof (struct file)); 172 return f; 173 174 new = xmalloc (sizeof (struct file)); 175 memset (new, '\0', sizeof (struct file)); 181 176 new->name = new->hname = name; 182 177 new->update_status = -1; … … 199 194 200 195 201 /* Rename FILE to NAME. This is not as simple as resetting202 the `name' member, since it must be put in a new hash bucket,203 and possibly merged with an existing file called NAME. */204 205 void206 rename_file (struct file *from_file, char *to_hname)207 {208 rehash_file (from_file, to_hname);209 while (from_file)210 {211 from_file->name = from_file->hname;212 from_file = from_file->prev;213 }214 }215 216 196 /* Rehash FILE to NAME. This is not as simple as resetting 217 197 the `hname' member, since it must be put in a new hash bucket, … … 219 199 220 200 void 221 rehash_file (struct file *from_file, c har *to_hname)201 rehash_file (struct file *from_file, const char *to_hname) 222 202 { 223 203 struct file file_key; … … 227 207 struct file *f; 228 208 209 /* If it's already that name, we're done. */ 229 210 file_key.hname = to_hname; 230 if ( 0 ==file_hash_cmp (from_file, &file_key))211 if (! file_hash_cmp (from_file, &file_key)) 231 212 return; 232 213 214 /* Find the end of the renamed list for the "from" file. */ 233 215 file_key.hname = from_file->hname; 234 216 while (from_file->renamed != 0) 235 217 from_file = from_file->renamed; 236 218 if (file_hash_cmp (from_file, &file_key)) 237 /* hname changed unexpectedly */219 /* hname changed unexpectedly!! */ 238 220 abort (); 239 221 222 /* Remove the "from" file from the hash. */ 240 223 deleted_file = hash_delete (&files, from_file); 241 224 if (deleted_file != from_file) … … 243 226 abort (); 244 227 228 /* Find where the newly renamed file will go in the hash. */ 245 229 file_key.hname = to_hname; 246 230 file_slot = (struct file **) hash_find_slot (&files, &file_key); 247 231 to_file = *file_slot; 248 232 233 /* Change the hash name for this file. */ 249 234 from_file->hname = to_hname; 250 235 for (f = from_file->double_colon; f != 0; f = f->prev) 251 236 f->hname = to_hname; 252 237 238 /* If the new name doesn't exist yet just set it to the renamed file. */ 253 239 if (HASH_VACANT (to_file)) 254 hash_insert_at (&files, from_file, file_slot); 240 { 241 hash_insert_at (&files, from_file, file_slot); 242 return; 243 } 244 245 /* TO_FILE already exists under TO_HNAME. 246 We must retain TO_FILE and merge FROM_FILE into it. */ 247 248 if (from_file->cmds != 0) 249 { 250 if (to_file->cmds == 0) 251 to_file->cmds = from_file->cmds; 252 else if (from_file->cmds != to_file->cmds) 253 { 254 /* We have two sets of commands. We will go with the 255 one given in the rule explicitly mentioning this name, 256 but give a message to let the user know what's going on. */ 257 if (to_file->cmds->fileinfo.filenm != 0) 258 error (&from_file->cmds->fileinfo, 259 _("Commands were specified for file `%s' at %s:%lu,"), 260 from_file->name, to_file->cmds->fileinfo.filenm, 261 to_file->cmds->fileinfo.lineno); 262 else 263 error (&from_file->cmds->fileinfo, 264 _("Commands for file `%s' were found by implicit rule search,"), 265 from_file->name); 266 error (&from_file->cmds->fileinfo, 267 _("but `%s' is now considered the same file as `%s'."), 268 from_file->name, to_hname); 269 error (&from_file->cmds->fileinfo, 270 _("Commands for `%s' will be ignored in favor of those for `%s'."), 271 to_hname, from_file->name); 272 } 273 } 274 275 /* Merge the dependencies of the two files. */ 276 277 if (to_file->deps == 0) 278 to_file->deps = from_file->deps; 255 279 else 256 280 { 257 /* TO_FILE already exists under TO_HNAME. 258 We must retain TO_FILE and merge FROM_FILE into it. */ 259 260 if (from_file->cmds != 0) 261 { 262 if (to_file->cmds == 0) 263 to_file->cmds = from_file->cmds; 264 else if (from_file->cmds != to_file->cmds) 265 { 266 /* We have two sets of commands. We will go with the 267 one given in the rule explicitly mentioning this name, 268 but give a message to let the user know what's going on. */ 269 if (to_file->cmds->fileinfo.filenm != 0) 270 error (&from_file->cmds->fileinfo, 271 _("Commands were specified for file `%s' at %s:%lu,"), 272 from_file->name, to_file->cmds->fileinfo.filenm, 273 to_file->cmds->fileinfo.lineno); 274 else 275 error (&from_file->cmds->fileinfo, 276 _("Commands for file `%s' were found by implicit rule search,"), 277 from_file->name); 278 error (&from_file->cmds->fileinfo, 279 _("but `%s' is now considered the same file as `%s'."), 280 from_file->name, to_hname); 281 error (&from_file->cmds->fileinfo, 282 _("Commands for `%s' will be ignored in favor of those for `%s'."), 283 to_hname, from_file->name); 284 } 285 } 286 287 /* Merge the dependencies of the two files. */ 288 289 if (to_file->deps == 0) 290 to_file->deps = from_file->deps; 281 struct dep *deps = to_file->deps; 282 while (deps->next != 0) 283 deps = deps->next; 284 deps->next = from_file->deps; 285 } 286 287 merge_variable_set_lists (&to_file->variables, from_file->variables); 288 289 if (to_file->double_colon && from_file->is_target && !from_file->double_colon) 290 fatal (NILF, _("can't rename single-colon `%s' to double-colon `%s'"), 291 from_file->name, to_hname); 292 if (!to_file->double_colon && from_file->double_colon) 293 { 294 if (to_file->is_target) 295 fatal (NILF, _("can't rename double-colon `%s' to single-colon `%s'"), 296 from_file->name, to_hname); 291 297 else 292 { 293 register struct dep *deps = to_file->deps; 294 while (deps->next != 0) 295 deps = deps->next; 296 deps->next = from_file->deps; 297 } 298 299 merge_variable_set_lists (&to_file->variables, from_file->variables); 300 301 if (to_file->double_colon && from_file->is_target && !from_file->double_colon) 302 fatal (NILF, _("can't rename single-colon `%s' to double-colon `%s'"), 303 from_file->name, to_hname); 304 if (!to_file->double_colon && from_file->double_colon) 305 { 306 if (to_file->is_target) 307 fatal (NILF, _("can't rename double-colon `%s' to single-colon `%s'"), 308 from_file->name, to_hname); 309 else 310 to_file->double_colon = from_file->double_colon; 311 } 312 313 if (from_file->last_mtime > to_file->last_mtime) 314 /* %%% Kludge so -W wins on a file that gets vpathized. */ 315 to_file->last_mtime = from_file->last_mtime; 316 317 to_file->mtime_before_update = from_file->mtime_before_update; 298 to_file->double_colon = from_file->double_colon; 299 } 300 301 if (from_file->last_mtime > to_file->last_mtime) 302 /* %%% Kludge so -W wins on a file that gets vpathized. */ 303 to_file->last_mtime = from_file->last_mtime; 304 305 to_file->mtime_before_update = from_file->mtime_before_update; 318 306 319 307 #define MERGE(field) to_file->field |= from_file->field 320 321 322 323 324 325 326 327 308 MERGE (precious); 309 MERGE (tried_implicit); 310 MERGE (updating); 311 MERGE (updated); 312 MERGE (is_target); 313 MERGE (cmd_target); 314 MERGE (phony); 315 MERGE (ignore_vpath); 328 316 #undef MERGE 329 317 330 from_file->renamed = to_file; 318 from_file->renamed = to_file; 319 } 320 321 /* Rename FILE to NAME. This is not as simple as resetting 322 the `name' member, since it must be put in a new hash bucket, 323 and possibly merged with an existing file called NAME. */ 324 325 void 326 rename_file (struct file *from_file, const char *to_hname) 327 { 328 rehash_file (from_file, to_hname); 329 while (from_file) 330 { 331 from_file->name = from_file->hname; 332 from_file = from_file->prev; 331 333 } 332 334 } … … 341 343 remove_intermediates (int sig) 342 344 { 343 registerstruct file **file_slot;344 registerstruct file **file_end;345 struct file **file_slot; 346 struct file **file_end; 345 347 int doneany = 0; 346 348 … … 357 359 if (! HASH_VACANT (*file_slot)) 358 360 { 359 registerstruct file *f = *file_slot;361 struct file *f = *file_slot; 360 362 /* Is this file eligible for automatic deletion? 361 363 Yes, IFF: it's marked intermediate, it's not secondary, it wasn't … … 448 450 } 449 451 450 451 452 /* Set the intermediate flag. */ 452 453 … … 464 465 struct dep *d; 465 466 struct dep *old = f->deps; 466 c har *file_stem = f->stem;467 const char *file_stem = f->stem; 467 468 unsigned int last_dep_has_cmds = f->updating; 468 469 int initialized = 0; … … 480 481 481 482 /* Create the dependency list. 482 If we're not doing 2nd expansion, then it's just the name. */ 483 If we're not doing 2nd expansion, then it's just the name. We will 484 still need to massage it though. */ 483 485 if (! d->need_2nd_expansion) 484 p = d->name; 486 { 487 p = variable_expand (""); 488 variable_buffer_output (p, d->name, strlen (d->name) + 1); 489 } 485 490 else 486 491 { … … 494 499 o = subst_expand (buffer, d->name, "%", "$*", 1, 2, 0); 495 500 496 free (d->name); 497 d->name = savestring (buffer, o - buffer); 501 d->name = strcache_add_len (buffer, o - buffer); 498 502 d->staticpattern = 0; /* Clear staticpattern so that we don't 499 503 re-expand %s below. */ … … 529 533 if (new && d->staticpattern) 530 534 { 531 c har *pattern = "%";535 const char *pattern = "%"; 532 536 char *buffer = variable_expand (""); 533 537 struct dep *dp = new, *dl = 0; … … 535 539 while (dp != 0) 536 540 { 537 char *percent = find_percent (dp->name); 541 char *percent; 542 int nl = strlen (dp->name) + 1; 543 char *nm = alloca (nl); 544 memcpy (nm, dp->name, nl); 545 percent = find_percent (nm); 538 546 if (percent) 539 547 { 548 char *o; 549 540 550 /* We have to handle empty stems specially, because that 541 551 would be equivalent to $(patsubst %,dp->name,) which 542 552 will always be empty. */ 543 553 if (d->stem[0] == '\0') 544 /* This needs memmove() in ISO C. */ 545 bcopy (percent+1, percent, strlen (percent)); 554 { 555 memmove (percent, percent+1, strlen (percent)); 556 o = variable_buffer_output (buffer, nm, strlen (nm) + 1); 557 } 546 558 else 547 { 548 char *o = patsubst_expand (buffer, d->stem, pattern, 549 dp->name, pattern+1, 550 percent+1); 551 if (o == buffer) 552 dp->name[0] = '\0'; 553 else 554 { 555 free (dp->name); 556 dp->name = savestring (buffer, o - buffer); 557 } 558 } 559 o = patsubst_expand_pat (buffer, d->stem, pattern, nm, 560 pattern+1, percent+1); 559 561 560 562 /* If the name expanded to the empty string, ignore it. */ 561 if ( dp->name[0] == '\0')563 if (buffer[0] == '\0') 562 564 { 563 565 struct dep *df = dp; … … 566 568 else 567 569 dp = dl->next = dp->next; 568 /* @@ Are we leaking df->name here? */569 df->name = 0;570 570 free_dep (df); 571 571 continue; 572 572 } 573 574 /* Save the name. */ 575 dp->name = strcache_add_len (buffer, o - buffer); 573 576 } 574 577 dl = dp; … … 583 586 if (d1->file == 0) 584 587 d1->file = enter_file (d1->name); 585 else586 free (d1->name);587 588 d1->name = 0; 588 589 d1->staticpattern = 0; … … 639 640 struct file **file_end; 640 641 641 /* Perform second expansion and enter each dependency 642 name as a file. */ 643 644 /* Expand .SUFFIXES first; it's dependencies are used for 645 $$* calculation. */ 642 /* Perform second expansion and enter each dependency name as a file. */ 643 644 /* Expand .SUFFIXES first; it's dependencies are used for $$* calculation. */ 646 645 for (f = lookup_file (".SUFFIXES"); f != 0; f = f->prev) 647 646 expand_deps (f); 648 647 649 /* We must use hash_dump (), because within this loop650 we might add new files to the table, possibly causing651 an in-situ table expansion. */648 /* For every target that's not .SUFFIXES, expand its dependencies. 649 We must use hash_dump (), because within this loop we might add new files 650 to the table, possibly causing an in-situ table expansion. */ 652 651 file_slot_0 = (struct file **) hash_dump (&files, 0, 0); 653 652 file_end = file_slot_0 + files.ht_fill; 654 653 for (file_slot = file_slot_0; file_slot < file_end; file_slot++) 655 654 for (f = *file_slot; f != 0; f = f->prev) 656 { 657 if (strcmp (f->name, ".SUFFIXES") != 0) 658 expand_deps (f); 659 } 655 if (strcmp (f->name, ".SUFFIXES") != 0) 656 expand_deps (f); 660 657 free (file_slot_0); 658 659 /* Now manage all the special targets. */ 661 660 662 661 for (f = lookup_file (".PRECIOUS"); f != 0; f = f->prev) … … 682 681 683 682 for (f = lookup_file (".INTERMEDIATE"); f != 0; f = f->prev) 684 { 685 /* .INTERMEDIATE with deps listed 686 marks those deps as intermediate files. */ 683 /* Mark .INTERMEDIATE deps as intermediate files. */ 684 for (d = f->deps; d != 0; d = d->next) 685 for (f2 = d->file; f2 != 0; f2 = f2->prev) 686 f2->intermediate = 1; 687 /* .INTERMEDIATE with no deps does nothing. 688 Marking all files as intermediates is useless since the goal targets 689 would be deleted after they are built. */ 690 691 for (f = lookup_file (".SECONDARY"); f != 0; f = f->prev) 692 /* Mark .SECONDARY deps as both intermediate and secondary. */ 693 if (f->deps) 687 694 for (d = f->deps; d != 0; d = d->next) 688 for (f2 = d->file; f2 != 0; f2 = f2->prev) 689 f2->intermediate = 1; 690 /* .INTERMEDIATE with no deps does nothing. 691 Marking all files as intermediates is useless 692 since the goal targets would be deleted after they are built. */ 693 } 694 695 for (f = lookup_file (".SECONDARY"); f != 0; f = f->prev) 696 { 697 /* .SECONDARY with deps listed 698 marks those deps as intermediate files 699 in that they don't get rebuilt if not actually needed; 700 but unlike real intermediate files, 701 these are not deleted after make finishes. */ 702 if (f->deps) 703 for (d = f->deps; d != 0; d = d->next) 704 for (f2 = d->file; f2 != 0; f2 = f2->prev) 705 f2->intermediate = f2->secondary = 1; 706 /* .SECONDARY with no deps listed marks *all* files that way. */ 707 else 708 { 709 all_secondary = 1; 710 hash_map (&files, set_intermediate); 711 } 712 } 695 for (f2 = d->file; f2 != 0; f2 = f2->prev) 696 f2->intermediate = f2->secondary = 1; 697 /* .SECONDARY with no deps listed marks *all* files that way. */ 698 else 699 { 700 all_secondary = 1; 701 hash_map (&files, set_intermediate); 702 } 713 703 714 704 f = lookup_file (".EXPORT_ALL_VARIABLES"); … … 860 850 p += strlen (p); 861 851 862 /* Append nanoseconds as a fraction, but remove trailing zeros. 863 We don't know the actual timestamp resolution, since clock_getres 864 applies only to local times, whereas this timestamp might come 865 from a remote filesystem. So removing trailing zeros is the 866 best guess that we can do. */ 852 /* Append nanoseconds as a fraction, but remove trailing zeros. We don't 853 know the actual timestamp resolution, since clock_getres applies only to 854 local times, whereas this timestamp might come from a remote filesystem. 855 So removing trailing zeros is the best guess that we can do. */ 867 856 sprintf (p, ".%09d", FILE_TIMESTAMP_NS (ts)); 868 857 p += strlen (p) - 1; … … 880 869 print_file (const void *item) 881 870 { 882 struct file *f = (struct file *)item;871 const struct file *f = item; 883 872 struct dep *d; 884 873 struct dep *ood = 0; … … 1002 991 } 1003 992 993 994 /* Verify the integrity of the data base of files. */ 995 996 #define VERIFY_CACHED(_p,_n) \ 997 do{\ 998 if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \ 999 printf ("%s: Field %s not cached: %s\n", _p->name, # _n, _p->_n); \ 1000 }while(0) 1001 1002 static void 1003 verify_file (const void *item) 1004 { 1005 const struct file *f = item; 1006 const struct dep *d; 1007 1008 VERIFY_CACHED (f, name); 1009 VERIFY_CACHED (f, hname); 1010 VERIFY_CACHED (f, vpath); 1011 VERIFY_CACHED (f, stem); 1012 1013 /* Check the deps. */ 1014 for (d = f->deps; d != 0; d = d->next) 1015 { 1016 VERIFY_CACHED (d, name); 1017 VERIFY_CACHED (d, stem); 1018 } 1019 } 1020 1021 void 1022 verify_file_data_base (void) 1023 { 1024 hash_map (&files, verify_file); 1025 } 1026 1004 1027 #define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500) 1005 1028 … … 1038 1061 } 1039 1062 1040 bcopy (f->name, p, l);1063 memcpy (p, f->name, l); 1041 1064 p += l; 1042 1065 *(p++) = ' ';
Note:
See TracChangeset
for help on using the changeset viewer.