Changeset 3140 for trunk/src/kmk/file.c
- Timestamp:
- Mar 14, 2018, 10:28:10 PM (7 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk
-
Property svn:mergeinfo
set to
/vendor/gnumake/current merged eligible
-
Property svn:mergeinfo
set to
-
trunk/src/kmk/file.c
r2788 r3140 1 1 /* Target file management for GNU Make. 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 4 2010 Free Software Foundation, Inc. 2 Copyright (C) 1988-2016 Free Software Foundation, Inc. 5 3 This file is part of GNU Make. 6 4 … … 17 15 this program. If not, see <http://www.gnu.org/licenses/>. */ 18 16 19 #include "make .h"17 #include "makeint.h" 20 18 21 19 #include <assert.h> 22 20 21 #include "filedef.h" 23 22 #include "dep.h" 24 #include "filedef.h"25 23 #include "job.h" 26 24 #include "commands.h" … … 63 61 #ifndef CONFIG_WITH_STRCACHE2 64 62 return_ISTRING_COMPARE (((struct file const *) x)->hname, 65 63 ((struct file const *) y)->hname); 66 64 #else /* CONFIG_WITH_STRCACHE2 */ 67 65 return ((struct file const *) x)->hname … … 70 68 } 71 69 72 #ifndef FILE_BUCKETS73 #define FILE_BUCKETS 100774 #endif75 70 static struct hash_table files; 76 71 … … 93 88 struct file *f; 94 89 struct file file_key; 95 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS) 90 #ifdef VMS 91 int want_vmsify; 92 #ifndef WANT_CASE_SENSITIVE_TARGETS 96 93 char *lname; 94 #endif 97 95 #endif 98 96 … … 103 101 on the command line. */ 104 102 #ifdef VMS 103 want_vmsify = (strpbrk (name, "]>:^") != NULL); 105 104 # ifndef WANT_CASE_SENSITIVE_TARGETS 106 105 if (*name != '.') … … 118 117 while (name[0] == '[' && name[1] == ']' && name[2] != '\0') 119 118 name += 2; 119 while (name[0] == '<' && name[1] == '>' && name[2] != '\0') 120 name += 2; 120 121 #endif 121 122 while (name[0] == '.' 122 123 #ifdef HAVE_DOS_PATHS 123 124 && (name[1] == '/' || name[1] == '\\') 124 125 #else 125 126 #endif 127 126 && name[1] == '/' 127 #endif 128 && name[2] != '\0') 128 129 { 129 130 name += 2; 130 131 while (*name == '/' 131 132 #ifdef HAVE_DOS_PATHS 132 133 #endif 134 135 136 133 || *name == '\\' 134 #endif 135 ) 136 /* Skip following slashes: ".//foo" is "foo", not "/foo". */ 137 ++name; 137 138 } 138 139 139 140 if (*name == '\0') 140 /* It was all slashes after a dot. */ 141 { 142 /* It was all slashes after a dot. */ 143 #if defined(_AMIGA) 144 name = ""; 145 #else 146 name = "./"; 147 #endif 141 148 #if defined(VMS) 142 name = "[]"; 143 #elif defined(_AMIGA) 144 name = ""; 145 #else 146 name = "./"; 147 #endif 148 149 /* TODO - This section is probably not needed. */ 150 if (want_vmsify) 151 name = "[]"; 152 #endif 153 } 149 154 #ifndef CONFIG_WITH_STRCACHE2 150 155 file_key.hname = name; … … 209 214 210 215 assert (*name != '\0'); 211 assert ( strcache_iscached (name));216 assert (! verify_flag || strcache_iscached (name)); 212 217 213 218 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS) … … 237 242 f = *file_slot; 238 243 if (! HASH_VACANT (f) && !f->double_colon) 239 return f; 244 { 245 f->builtin = 0; 246 return f; 247 } 240 248 241 249 #ifndef CONFIG_WITH_ALLOC_CACHES … … 245 253 #endif 246 254 new->name = new->hname = name; 247 new->update_status = -1;255 new->update_status = us_none; 248 256 249 257 if (HASH_VACANT (f)) … … 271 279 272 280 /* Rehash FILE to NAME. This is not as simple as resetting 273 the `hname' member, since it must be put in a new hash bucket,281 the 'hname' member, since it must be put in a new hash bucket, 274 282 and possibly merged with an existing file called NAME. */ 275 283 … … 289 297 290 298 /* If it's already that name, we're done. */ 299 from_file->builtin = 0; 291 300 file_key.hname = to_hname; 292 301 if (! file_hash_cmp (from_file, &file_key)) … … 341 350 else if (from_file->cmds != to_file->cmds) 342 351 { 352 size_t l = strlen (from_file->name); 343 353 /* We have two sets of commands. We will go with the 344 354 one given in the rule explicitly mentioning this name, … … 346 356 if (to_file->cmds->fileinfo.filenm != 0) 347 357 error (&from_file->cmds->fileinfo, 348 _("Recipe was specified for file `%s' at %s:%lu,"), 358 l + strlen (to_file->cmds->fileinfo.filenm) + INTSTR_LENGTH, 359 _("Recipe was specified for file '%s' at %s:%lu,"), 349 360 from_file->name, to_file->cmds->fileinfo.filenm, 350 361 to_file->cmds->fileinfo.lineno); 351 362 else 352 error (&from_file->cmds->fileinfo, 353 _("Recipe for file `%s' was found by implicit rule search,"),363 error (&from_file->cmds->fileinfo, l, 364 _("Recipe for file '%s' was found by implicit rule search,"), 354 365 from_file->name); 355 error (&from_file->cmds->fileinfo, 356 _("but `%s' is now considered the same file as `%s'."), 366 l += strlen (to_hname); 367 error (&from_file->cmds->fileinfo, l, 368 _("but '%s' is now considered the same file as '%s'."), 357 369 from_file->name, to_hname); 358 error (&from_file->cmds->fileinfo, 359 _("Recipe for `%s' will be ignored in favor of the one for `%s'."),370 error (&from_file->cmds->fileinfo, l, 371 _("Recipe for '%s' will be ignored in favor of the one for '%s'."), 360 372 to_hname, from_file->name); 361 373 } … … 367 379 { 368 380 if (to_file->multi_head) 369 fatal (NILF, _("can't rename/merge multi target '%s' with multi target '%s'"),370 381 OSS (fatal, NILF, _("can't rename/merge multi target '%s' with multi target '%s'"), 382 from_file->name, to_hname); 371 383 372 384 to_file->multi_maybe = from_file->multi_maybe; … … 411 423 412 424 if (to_file->double_colon && from_file->is_target && !from_file->double_colon) 413 fatal (NILF, _("can't rename single-colon `%s' to double-colon `%s'"),414 425 OSS (fatal, NILF, _("can't rename single-colon '%s' to double-colon '%s'"), 426 from_file->name, to_hname); 415 427 if (!to_file->double_colon && from_file->double_colon) 416 428 { 417 429 if (to_file->is_target) 418 fatal (NILF, _("can't rename double-colon `%s' to single-colon `%s'"), 419 from_file->name, to_hname); 430 OSS (fatal, NILF, 431 _("can't rename double-colon '%s' to single-colon '%s'"), 432 from_file->name, to_hname); 420 433 else 421 434 to_file->double_colon = from_file->double_colon; … … 436 449 MERGE (cmd_target); 437 450 MERGE (phony); 451 MERGE (loaded); 438 452 MERGE (ignore_vpath); 439 453 #undef MERGE 440 454 455 to_file->builtin = 0; 441 456 from_file->renamed = to_file; 442 457 } 443 458 444 459 /* Rename FILE to NAME. This is not as simple as resetting 445 the `name' member, since it must be put in a new hash bucket,460 the 'name' member, since it must be put in a new hash bucket, 446 461 and possibly merged with an existing file called NAME. */ 447 462 … … 498 513 if (! HASH_VACANT (*file_slot)) 499 514 { 500 515 struct file *f = *file_slot; 501 516 /* Is this file eligible for automatic deletion? 502 517 Yes, IFF: it's marked intermediate, it's not secondary, it wasn't 503 518 given on the command line, and it's either a -include makefile or 504 519 it's not precious. */ 505 if (f->intermediate && (f->dontcare || !f->precious) 506 && !f->secondary && !f->cmd_target) 507 { 508 int status; 509 if (f->update_status == -1) 510 /* If nothing would have created this file yet, 511 don't print an "rm" command for it. */ 512 continue; 513 if (just_print_flag) 514 status = 0; 515 else 516 { 517 status = unlink (f->name); 518 if (status < 0 && errno == ENOENT) 519 continue; 520 } 521 if (!f->dontcare) 522 { 523 if (sig) 524 error (NILF, _("*** Deleting intermediate file `%s'"), f->name); 525 else 526 { 527 if (! doneany) 528 DB (DB_BASIC, (_("Removing intermediate files...\n"))); 529 if (!silent_flag) 530 { 531 if (! doneany) 532 { 533 fputs ("rm ", stdout); 534 doneany = 1; 535 } 536 else 537 putchar (' '); 538 fputs (f->name, stdout); 539 fflush (stdout); 540 } 541 } 542 if (status < 0) 543 perror_with_name ("unlink: ", f->name); 544 } 545 } 520 if (f->intermediate && (f->dontcare || !f->precious) 521 && !f->secondary && !f->cmd_target) 522 { 523 int status; 524 if (f->update_status == us_none) 525 /* If nothing would have created this file yet, 526 don't print an "rm" command for it. */ 527 continue; 528 if (just_print_flag) 529 status = 0; 530 else 531 { 532 status = unlink (f->name); 533 if (status < 0 && errno == ENOENT) 534 continue; 535 } 536 if (!f->dontcare) 537 { 538 if (sig) 539 OS (error, NILF, 540 _("*** Deleting intermediate file '%s'"), f->name); 541 else 542 { 543 if (! doneany) 544 DB (DB_BASIC, (_("Removing intermediate files...\n"))); 545 if (!silent_flag) 546 { 547 if (! doneany) 548 { 549 fputs ("rm ", stdout); 550 doneany = 1; 551 } 552 else 553 putchar (' '); 554 fputs (f->name, stdout); 555 fflush (stdout); 556 } 557 } 558 if (status < 0) 559 perror_with_name ("unlink: ", f->name); 560 } 561 } 546 562 } 547 563 … … 560 576 split_prereqs (char *p) 561 577 { 562 struct dep *new = PARSE_FILE_SEQ (&p, struct dep, '|', NULL, 0); 578 struct dep *new = PARSE_FILE_SEQ (&p, struct dep, MAP_PIPE, NULL, 579 PARSEFS_NONE); 563 580 564 581 if (*p) … … 569 586 570 587 ++p; 571 ood = PARSE_ FILE_SEQ (&p, struct dep, '\0', NULL, 0);588 ood = PARSE_SIMPLE_SEQ (&p, struct dep); 572 589 573 590 if (! new) … … 728 745 if (d->staticpattern) 729 746 { 730 char *o; 731 d->name = o = variable_expand (""); 747 char *o = variable_expand (""); 732 748 o = subst_expand (o, name, "%", "$*", 1, 2, 0); 733 749 *o = '\0'; … … 802 818 } 803 819 804 /* For each dependency of each file, make the `struct dep' point805 at the appropriate `struct file' (which may have to be created).820 /* For each dependency of each file, make the 'struct dep' point 821 at the appropriate 'struct file' (which may have to be created). 806 822 807 823 Also mark the files depended on by .PRECIOUS, .PHONY, .SILENT, … … 911 927 for (d = f->deps; d != 0; d = d->next) 912 928 for (f2 = d->file; f2 != 0; f2 = f2->prev) 913 929 f2->precious = 1; 914 930 915 931 for (f = lookup_file (".LOW_RESOLUTION_TIME"); f != 0; f = f->prev) 916 932 for (d = f->deps; d != 0; d = d->next) 917 933 for (f2 = d->file; f2 != 0; f2 = f2->prev) 918 934 f2->low_resolution_time = 1; 919 935 920 936 for (f = lookup_file (".PHONY"); f != 0; f = f->prev) 921 937 for (d = f->deps; d != 0; d = d->next) 922 938 for (f2 = d->file; f2 != 0; f2 = f2->prev) 923 924 925 939 { 940 /* Mark this file as phony nonexistent target. */ 941 f2->phony = 1; 926 942 f2->is_target = 1; 927 928 929 943 f2->last_mtime = NONEXISTENT_MTIME; 944 f2->mtime_before_update = NONEXISTENT_MTIME; 945 } 930 946 931 947 for (f = lookup_file (".INTERMEDIATE"); f != 0; f = f->prev) … … 959 975 { 960 976 if (f->deps == 0) 961 977 ignore_errors_flag = 1; 962 978 else 963 964 965 979 for (d = f->deps; d != 0; d = d->next) 980 for (f2 = d->file; f2 != 0; f2 = f2->prev) 981 f2->command_flags |= COMMANDS_NOERROR; 966 982 } 967 983 … … 970 986 { 971 987 if (f->deps == 0) 972 988 silent_flag = 1; 973 989 else 974 975 976 990 for (d = f->deps; d != 0; d = d->next) 991 for (f2 = d->file; f2 != 0; f2 = f2->prev) 992 f2->command_flags |= COMMANDS_SILENT; 977 993 } 978 994 … … 1005 1021 1006 1022 1007 /* Set the `command_state' member of FILE and all its `also_make's. */1023 /* Set the 'command_state' member of FILE and all its 'also_make's. */ 1008 1024 1009 1025 void … … 1028 1044 1029 1045 FILE_TIMESTAMP 1030 file_timestamp_cons (const char *fname, time_t s ,int ns)1046 file_timestamp_cons (const char *fname, time_t stamp, long int ns) 1031 1047 { 1032 1048 int offset = ORDINARY_MTIME_MIN + (FILE_TIMESTAMP_HI_RES ? ns : 0); 1049 FILE_TIMESTAMP s = stamp; 1033 1050 FILE_TIMESTAMP product = (FILE_TIMESTAMP) s << FILE_TIMESTAMP_LO_BITS; 1034 1051 FILE_TIMESTAMP ts = product + offset; 1035 1052 1036 1053 if (! (s <= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX) 1037 1054 && product <= ts && ts <= ORDINARY_MTIME_MAX)) 1038 1055 { 1039 1056 char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1]; 1057 const char *f = fname ? fname : _("Current time"); 1040 1058 ts = s <= OLD_MTIME ? ORDINARY_MTIME_MIN : ORDINARY_MTIME_MAX; 1041 1059 file_timestamp_sprintf (buf, ts); 1042 error (NILF, _("%s: Timestamp out of range; substituting %s"),1043 fname ? fname : _("Current time"), buf);1060 OSS (error, NILF, 1061 _("%s: Timestamp out of range; substituting %s"), f, buf); 1044 1062 } 1045 1063 … … 1066 1084 if (clock_gettime (CLOCK_REALTIME, ×pec) == 0) 1067 1085 { 1068 1069 1070 1071 1086 r = 1; 1087 s = timespec.tv_sec; 1088 ns = timespec.tv_nsec; 1089 goto got_time; 1072 1090 } 1073 1091 } … … 1078 1096 if (gettimeofday (&timeval, 0) == 0) 1079 1097 { 1080 1081 1082 1083 1098 r = 1000; 1099 s = timeval.tv_sec; 1100 ns = timeval.tv_usec * 1000; 1101 goto got_time; 1084 1102 } 1085 1103 } … … 1108 1126 if (tm) 1109 1127 sprintf (p, "%04d-%02d-%02d %02d:%02d:%02d", 1110 1111 1128 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, 1129 tm->tm_hour, tm->tm_min, tm->tm_sec); 1112 1130 else if (t < 0) 1113 1131 sprintf (p, "%ld", (long) t); … … 1161 1179 const struct file *f = item; 1162 1180 1181 /* If we're not using builtin targets, don't show them. 1182 1183 Ideally we'd be able to delete them altogether but currently there's no 1184 facility to ever delete a file once it's been added. */ 1185 if (no_builtin_rules_flag && f->builtin) 1186 return; 1187 1163 1188 putchar ('\n'); 1189 1190 if (f->cmds && f->cmds->recipe_prefix != cmd_prefix) 1191 { 1192 fputs (".RECIPEPREFIX = ", stdout); 1193 cmd_prefix = f->cmds->recipe_prefix; 1194 if (cmd_prefix != RECIPEPREFIX_DEFAULT) 1195 putchar (cmd_prefix); 1196 putchar ('\n'); 1197 } 1198 1199 if (f->variables != 0) 1200 print_target_variables (f); 1201 1164 1202 if (!f->is_target) 1165 1203 puts (_("# Not a target:")); … … 1228 1266 } 1229 1267 #endif 1230 1268 if (f->builtin) 1269 puts (_("# Builtin rule")); 1231 1270 puts (f->tried_implicit 1232 1271 ? _("# Implicit rule search has been done.") 1233 1272 : _("# Implicit rule search has not been done.")); 1234 1273 if (f->stem != 0) 1235 printf (_("# Implicit/static pattern stem: `%s'\n"), f->stem);1274 printf (_("# Implicit/static pattern stem: '%s'\n"), f->stem); 1236 1275 if (f->intermediate) 1237 1276 puts (_("# File is an intermediate prerequisite.")); … … 1241 1280 fputs (_("# Also makes:"), stdout); 1242 1281 for (d = f->also_make; d != 0; d = d->next) 1243 1282 printf (" %s", dep_name (d)); 1244 1283 putchar ('\n'); 1245 1284 } … … 1269 1308 case cs_finished: 1270 1309 switch (f->update_status) 1271 { 1272 case -1: 1273 break; 1274 case 0: 1275 puts (_("# Successfully updated.")); 1276 break; 1277 case 1: 1278 assert (question_flag); 1279 puts (_("# Needs to be updated (-q is set).")); 1280 break; 1281 case 2: 1282 puts (_("# Failed to be updated.")); 1283 break; 1284 default: 1285 puts (_("# Invalid value in `update_status' member!")); 1286 fflush (stdout); 1287 fflush (stderr); 1288 abort (); 1289 } 1310 { 1311 case us_none: 1312 break; 1313 case us_success: 1314 puts (_("# Successfully updated.")); 1315 break; 1316 case us_question: 1317 assert (question_flag); 1318 puts (_("# Needs to be updated (-q is set).")); 1319 break; 1320 case us_failed: 1321 puts (_("# Failed to be updated.")); 1322 break; 1323 } 1290 1324 break; 1291 1325 default: 1292 puts (_("# Invalid value in `command_state' member!"));1326 puts (_("# Invalid value in 'command_state' member!")); 1293 1327 fflush (stdout); 1294 1328 fflush (stderr); … … 1331 1365 1332 1366 #define VERIFY_CACHED(_p,_n) \ 1333 do{\ 1334 if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \ 1335 error (NULL, "%s: Field '%s' not cached: %s\n", _p->name, # _n, _p->_n); \ 1367 do{ \ 1368 if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \ 1369 error (NULL, strlen (_p->name) + CSTRLEN (# _n) + strlen (_p->_n), \ 1370 _("%s: Field '%s' not cached: %s"), _p->name, # _n, _p->_n); \ 1336 1371 }while(0) 1337 1372
Note:
See TracChangeset
for help on using the changeset viewer.