Changeset 3138 in kBuild for vendor/gnumake/current/file.c
- Timestamp:
- Mar 12, 2018 7:32:29 PM (7 years ago)
- File:
-
- 1 edited
-
vendor/gnumake/current/file.c (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/file.c
r2596 r3138 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" … … 57 55 { 58 56 return_ISTRING_COMPARE (((struct file const *) x)->hname, 59 ((struct file const *) y)->hname); 60 } 61 62 #ifndef FILE_BUCKETS 63 #define FILE_BUCKETS 1007 64 #endif 57 ((struct file const *) y)->hname); 58 } 59 65 60 static struct hash_table files; 66 61 … … 78 73 struct file *f; 79 74 struct file file_key; 80 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS) 75 #ifdef VMS 76 int want_vmsify; 77 #ifndef WANT_CASE_SENSITIVE_TARGETS 81 78 char *lname; 79 #endif 82 80 #endif 83 81 … … 88 86 on the command line. */ 89 87 #ifdef VMS 88 want_vmsify = (strpbrk (name, "]>:^") != NULL); 90 89 # ifndef WANT_CASE_SENSITIVE_TARGETS 91 90 if (*name != '.') … … 103 102 while (name[0] == '[' && name[1] == ']' && name[2] != '\0') 104 103 name += 2; 104 while (name[0] == '<' && name[1] == '>' && name[2] != '\0') 105 name += 2; 105 106 #endif 106 107 while (name[0] == '.' 107 108 #ifdef HAVE_DOS_PATHS 108 && (name[1] == '/' || name[1] == '\\')109 && (name[1] == '/' || name[1] == '\\') 109 110 #else 110 && name[1] == '/'111 && name[1] == '/' 111 112 #endif 112 && name[2] != '\0')113 && name[2] != '\0') 113 114 { 114 115 name += 2; 115 116 while (*name == '/' 116 117 #ifdef HAVE_DOS_PATHS 117 || *name == '\\'118 || *name == '\\' 118 119 #endif 119 )120 /* Skip following slashes: ".//foo" is "foo", not "/foo". */121 ++name;120 ) 121 /* Skip following slashes: ".//foo" is "foo", not "/foo". */ 122 ++name; 122 123 } 123 124 124 125 if (*name == '\0') 125 /* It was all slashes after a dot. */ 126 { 127 /* It was all slashes after a dot. */ 128 #if defined(_AMIGA) 129 name = ""; 130 #else 131 name = "./"; 132 #endif 126 133 #if defined(VMS) 127 name = "[]"; 128 #elif defined(_AMIGA) 129 name = ""; 130 #else 131 name = "./"; 134 /* TODO - This section is probably not needed. */ 135 if (want_vmsify) 136 name = "[]"; 132 137 #endif 133 138 } 134 139 file_key.hname = name; 135 140 f = hash_find_item (&files, &file_key); … … 156 161 157 162 assert (*name != '\0'); 158 assert ( strcache_iscached (name));163 assert (! verify_flag || strcache_iscached (name)); 159 164 160 165 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS) … … 180 185 f = *file_slot; 181 186 if (! HASH_VACANT (f) && !f->double_colon) 182 return f; 187 { 188 f->builtin = 0; 189 return f; 190 } 183 191 184 192 new = xcalloc (sizeof (struct file)); 185 193 new->name = new->hname = name; 186 new->update_status = -1;194 new->update_status = us_none; 187 195 188 196 if (HASH_VACANT (f)) … … 204 212 205 213 /* Rehash FILE to NAME. This is not as simple as resetting 206 the `hname' member, since it must be put in a new hash bucket,214 the 'hname' member, since it must be put in a new hash bucket, 207 215 and possibly merged with an existing file called NAME. */ 208 216 … … 217 225 218 226 /* If it's already that name, we're done. */ 227 from_file->builtin = 0; 219 228 file_key.hname = to_hname; 220 229 if (! file_hash_cmp (from_file, &file_key)) … … 261 270 else if (from_file->cmds != to_file->cmds) 262 271 { 272 size_t l = strlen (from_file->name); 263 273 /* We have two sets of commands. We will go with the 264 274 one given in the rule explicitly mentioning this name, … … 266 276 if (to_file->cmds->fileinfo.filenm != 0) 267 277 error (&from_file->cmds->fileinfo, 268 _("Recipe was specified for file `%s' at %s:%lu,"), 278 l + strlen (to_file->cmds->fileinfo.filenm) + INTSTR_LENGTH, 279 _("Recipe was specified for file '%s' at %s:%lu,"), 269 280 from_file->name, to_file->cmds->fileinfo.filenm, 270 281 to_file->cmds->fileinfo.lineno); 271 282 else 272 error (&from_file->cmds->fileinfo, 273 _("Recipe for file `%s' was found by implicit rule search,"),283 error (&from_file->cmds->fileinfo, l, 284 _("Recipe for file '%s' was found by implicit rule search,"), 274 285 from_file->name); 275 error (&from_file->cmds->fileinfo, 276 _("but `%s' is now considered the same file as `%s'."), 286 l += strlen (to_hname); 287 error (&from_file->cmds->fileinfo, l, 288 _("but '%s' is now considered the same file as '%s'."), 277 289 from_file->name, to_hname); 278 error (&from_file->cmds->fileinfo, 279 _("Recipe for `%s' will be ignored in favor of the one for `%s'."),290 error (&from_file->cmds->fileinfo, l, 291 _("Recipe for '%s' will be ignored in favor of the one for '%s'."), 280 292 to_hname, from_file->name); 281 293 } … … 297 309 298 310 if (to_file->double_colon && from_file->is_target && !from_file->double_colon) 299 fatal (NILF, _("can't rename single-colon `%s' to double-colon `%s'"),300 from_file->name, to_hname);311 OSS (fatal, NILF, _("can't rename single-colon '%s' to double-colon '%s'"), 312 from_file->name, to_hname); 301 313 if (!to_file->double_colon && from_file->double_colon) 302 314 { 303 315 if (to_file->is_target) 304 fatal (NILF, _("can't rename double-colon `%s' to single-colon `%s'"), 305 from_file->name, to_hname); 316 OSS (fatal, NILF, 317 _("can't rename double-colon '%s' to single-colon '%s'"), 318 from_file->name, to_hname); 306 319 else 307 320 to_file->double_colon = from_file->double_colon; … … 322 335 MERGE (cmd_target); 323 336 MERGE (phony); 337 MERGE (loaded); 324 338 MERGE (ignore_vpath); 325 339 #undef MERGE 326 340 341 to_file->builtin = 0; 327 342 from_file->renamed = to_file; 328 343 } 329 344 330 345 /* Rename FILE to NAME. This is not as simple as resetting 331 the `name' member, since it must be put in a new hash bucket,346 the 'name' member, since it must be put in a new hash bucket, 332 347 and possibly merged with an existing file called NAME. */ 333 348 … … 368 383 if (! HASH_VACANT (*file_slot)) 369 384 { 370 struct file *f = *file_slot;385 struct file *f = *file_slot; 371 386 /* Is this file eligible for automatic deletion? 372 387 Yes, IFF: it's marked intermediate, it's not secondary, it wasn't 373 388 given on the command line, and it's either a -include makefile or 374 389 it's not precious. */ 375 if (f->intermediate && (f->dontcare || !f->precious) 376 && !f->secondary && !f->cmd_target) 377 { 378 int status; 379 if (f->update_status == -1) 380 /* If nothing would have created this file yet, 381 don't print an "rm" command for it. */ 382 continue; 383 if (just_print_flag) 384 status = 0; 385 else 386 { 387 status = unlink (f->name); 388 if (status < 0 && errno == ENOENT) 389 continue; 390 } 391 if (!f->dontcare) 392 { 393 if (sig) 394 error (NILF, _("*** Deleting intermediate file `%s'"), f->name); 395 else 396 { 397 if (! doneany) 398 DB (DB_BASIC, (_("Removing intermediate files...\n"))); 399 if (!silent_flag) 400 { 401 if (! doneany) 402 { 403 fputs ("rm ", stdout); 404 doneany = 1; 405 } 406 else 407 putchar (' '); 408 fputs (f->name, stdout); 409 fflush (stdout); 410 } 411 } 412 if (status < 0) 413 perror_with_name ("unlink: ", f->name); 414 } 415 } 390 if (f->intermediate && (f->dontcare || !f->precious) 391 && !f->secondary && !f->cmd_target) 392 { 393 int status; 394 if (f->update_status == us_none) 395 /* If nothing would have created this file yet, 396 don't print an "rm" command for it. */ 397 continue; 398 if (just_print_flag) 399 status = 0; 400 else 401 { 402 status = unlink (f->name); 403 if (status < 0 && errno == ENOENT) 404 continue; 405 } 406 if (!f->dontcare) 407 { 408 if (sig) 409 OS (error, NILF, 410 _("*** Deleting intermediate file '%s'"), f->name); 411 else 412 { 413 if (! doneany) 414 DB (DB_BASIC, (_("Removing intermediate files...\n"))); 415 if (!silent_flag) 416 { 417 if (! doneany) 418 { 419 fputs ("rm ", stdout); 420 doneany = 1; 421 } 422 else 423 putchar (' '); 424 fputs (f->name, stdout); 425 fflush (stdout); 426 } 427 } 428 if (status < 0) 429 perror_with_name ("unlink: ", f->name); 430 } 431 } 416 432 } 417 433 … … 430 446 split_prereqs (char *p) 431 447 { 432 struct dep *new = PARSE_FILE_SEQ (&p, struct dep, '|', NULL, 0); 448 struct dep *new = PARSE_FILE_SEQ (&p, struct dep, MAP_PIPE, NULL, 449 PARSEFS_NONE); 433 450 434 451 if (*p) … … 439 456 440 457 ++p; 441 ood = PARSE_ FILE_SEQ (&p, struct dep, '\0', NULL, 0);458 ood = PARSE_SIMPLE_SEQ (&p, struct dep); 442 459 443 460 if (! new) … … 579 596 if (d->staticpattern) 580 597 { 581 char *o; 582 d->name = o = variable_expand (""); 598 char *o = variable_expand (""); 583 599 o = subst_expand (o, name, "%", "$*", 1, 2, 0); 584 600 *o = '\0'; 585 601 free (name); 586 d->name = name = xstrdup ( d->name);602 d->name = name = xstrdup (variable_buffer); 587 603 d->staticpattern = 0; 588 604 } … … 641 657 } 642 658 643 /* For each dependency of each file, make the `struct dep' point644 at the appropriate `struct file' (which may have to be created).659 /* For each dependency of each file, make the 'struct dep' point 660 at the appropriate 'struct file' (which may have to be created). 645 661 646 662 Also mark the files depended on by .PRECIOUS, .PHONY, .SILENT, … … 697 713 for (d = f->deps; d != 0; d = d->next) 698 714 for (f2 = d->file; f2 != 0; f2 = f2->prev) 699 f2->precious = 1;715 f2->precious = 1; 700 716 701 717 for (f = lookup_file (".LOW_RESOLUTION_TIME"); f != 0; f = f->prev) 702 718 for (d = f->deps; d != 0; d = d->next) 703 719 for (f2 = d->file; f2 != 0; f2 = f2->prev) 704 f2->low_resolution_time = 1;720 f2->low_resolution_time = 1; 705 721 706 722 for (f = lookup_file (".PHONY"); f != 0; f = f->prev) 707 723 for (d = f->deps; d != 0; d = d->next) 708 724 for (f2 = d->file; f2 != 0; f2 = f2->prev) 709 {710 /* Mark this file as phony nonexistent target. */711 f2->phony = 1;725 { 726 /* Mark this file as phony nonexistent target. */ 727 f2->phony = 1; 712 728 f2->is_target = 1; 713 f2->last_mtime = NONEXISTENT_MTIME;714 f2->mtime_before_update = NONEXISTENT_MTIME;715 }729 f2->last_mtime = NONEXISTENT_MTIME; 730 f2->mtime_before_update = NONEXISTENT_MTIME; 731 } 716 732 717 733 for (f = lookup_file (".INTERMEDIATE"); f != 0; f = f->prev) … … 745 761 { 746 762 if (f->deps == 0) 747 ignore_errors_flag = 1;763 ignore_errors_flag = 1; 748 764 else 749 for (d = f->deps; d != 0; d = d->next)750 for (f2 = d->file; f2 != 0; f2 = f2->prev)751 f2->command_flags |= COMMANDS_NOERROR;765 for (d = f->deps; d != 0; d = d->next) 766 for (f2 = d->file; f2 != 0; f2 = f2->prev) 767 f2->command_flags |= COMMANDS_NOERROR; 752 768 } 753 769 … … 756 772 { 757 773 if (f->deps == 0) 758 silent_flag = 1;774 silent_flag = 1; 759 775 else 760 for (d = f->deps; d != 0; d = d->next)761 for (f2 = d->file; f2 != 0; f2 = f2->prev)762 f2->command_flags |= COMMANDS_SILENT;776 for (d = f->deps; d != 0; d = d->next) 777 for (f2 = d->file; f2 != 0; f2 = f2->prev) 778 f2->command_flags |= COMMANDS_SILENT; 763 779 } 764 780 … … 777 793 778 794 779 /* Set the `command_state' member of FILE and all its `also_make's. */795 /* Set the 'command_state' member of FILE and all its 'also_make's. */ 780 796 781 797 void … … 794 810 795 811 FILE_TIMESTAMP 796 file_timestamp_cons (const char *fname, time_t s ,int ns)812 file_timestamp_cons (const char *fname, time_t stamp, long int ns) 797 813 { 798 814 int offset = ORDINARY_MTIME_MIN + (FILE_TIMESTAMP_HI_RES ? ns : 0); 815 FILE_TIMESTAMP s = stamp; 799 816 FILE_TIMESTAMP product = (FILE_TIMESTAMP) s << FILE_TIMESTAMP_LO_BITS; 800 817 FILE_TIMESTAMP ts = product + offset; 801 818 802 819 if (! (s <= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX) 803 && product <= ts && ts <= ORDINARY_MTIME_MAX))820 && product <= ts && ts <= ORDINARY_MTIME_MAX)) 804 821 { 805 822 char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1]; 823 const char *f = fname ? fname : _("Current time"); 806 824 ts = s <= OLD_MTIME ? ORDINARY_MTIME_MIN : ORDINARY_MTIME_MAX; 807 825 file_timestamp_sprintf (buf, ts); 808 error (NILF, _("%s: Timestamp out of range; substituting %s"),809 fname ? fname : _("Current time"), buf);826 OSS (error, NILF, 827 _("%s: Timestamp out of range; substituting %s"), f, buf); 810 828 } 811 829 … … 832 850 if (clock_gettime (CLOCK_REALTIME, ×pec) == 0) 833 851 { 834 r = 1;835 s = timespec.tv_sec;836 ns = timespec.tv_nsec;837 goto got_time;852 r = 1; 853 s = timespec.tv_sec; 854 ns = timespec.tv_nsec; 855 goto got_time; 838 856 } 839 857 } … … 844 862 if (gettimeofday (&timeval, 0) == 0) 845 863 { 846 r = 1000;847 s = timeval.tv_sec;848 ns = timeval.tv_usec * 1000;849 goto got_time;864 r = 1000; 865 s = timeval.tv_sec; 866 ns = timeval.tv_usec * 1000; 867 goto got_time; 850 868 } 851 869 } … … 874 892 if (tm) 875 893 sprintf (p, "%04d-%02d-%02d %02d:%02d:%02d", 876 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,877 tm->tm_hour, tm->tm_min, tm->tm_sec);894 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, 895 tm->tm_hour, tm->tm_min, tm->tm_sec); 878 896 else if (t < 0) 879 897 sprintf (p, "%ld", (long) t); … … 927 945 const struct file *f = item; 928 946 947 /* If we're not using builtin targets, don't show them. 948 949 Ideally we'd be able to delete them altogether but currently there's no 950 facility to ever delete a file once it's been added. */ 951 if (no_builtin_rules_flag && f->builtin) 952 return; 953 929 954 putchar ('\n'); 955 956 if (f->cmds && f->cmds->recipe_prefix != cmd_prefix) 957 { 958 fputs (".RECIPEPREFIX = ", stdout); 959 cmd_prefix = f->cmds->recipe_prefix; 960 if (cmd_prefix != RECIPEPREFIX_DEFAULT) 961 putchar (cmd_prefix); 962 putchar ('\n'); 963 } 964 965 if (f->variables != 0) 966 print_target_variables (f); 967 930 968 if (!f->is_target) 931 969 puts (_("# Not a target:")); … … 941 979 if (f->dontcare) 942 980 puts (_("# A default, MAKEFILES, or -include/sinclude makefile.")); 981 if (f->builtin) 982 puts (_("# Builtin rule")); 943 983 puts (f->tried_implicit 944 984 ? _("# Implicit rule search has been done.") 945 985 : _("# Implicit rule search has not been done.")); 946 986 if (f->stem != 0) 947 printf (_("# Implicit/static pattern stem: `%s'\n"), f->stem);987 printf (_("# Implicit/static pattern stem: '%s'\n"), f->stem); 948 988 if (f->intermediate) 949 989 puts (_("# File is an intermediate prerequisite.")); … … 953 993 fputs (_("# Also makes:"), stdout); 954 994 for (d = f->also_make; d != 0; d = d->next) 955 printf (" %s", dep_name (d));995 printf (" %s", dep_name (d)); 956 996 putchar ('\n'); 957 997 } … … 981 1021 case cs_finished: 982 1022 switch (f->update_status) 983 { 984 case -1: 985 break; 986 case 0: 987 puts (_("# Successfully updated.")); 988 break; 989 case 1: 990 assert (question_flag); 991 puts (_("# Needs to be updated (-q is set).")); 992 break; 993 case 2: 994 puts (_("# Failed to be updated.")); 995 break; 996 default: 997 puts (_("# Invalid value in `update_status' member!")); 998 fflush (stdout); 999 fflush (stderr); 1000 abort (); 1001 } 1023 { 1024 case us_none: 1025 break; 1026 case us_success: 1027 puts (_("# Successfully updated.")); 1028 break; 1029 case us_question: 1030 assert (question_flag); 1031 puts (_("# Needs to be updated (-q is set).")); 1032 break; 1033 case us_failed: 1034 puts (_("# Failed to be updated.")); 1035 break; 1036 } 1002 1037 break; 1003 1038 default: 1004 puts (_("# Invalid value in `command_state' member!"));1039 puts (_("# Invalid value in 'command_state' member!")); 1005 1040 fflush (stdout); 1006 1041 fflush (stderr); … … 1033 1068 1034 1069 #define VERIFY_CACHED(_p,_n) \ 1035 do{\ 1036 if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \ 1037 error (NULL, "%s: Field '%s' not cached: %s\n", _p->name, # _n, _p->_n); \ 1070 do{ \ 1071 if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \ 1072 error (NULL, strlen (_p->name) + CSTRLEN (# _n) + strlen (_p->_n), \ 1073 _("%s: Field '%s' not cached: %s"), _p->name, # _n, _p->_n); \ 1038 1074 }while(0) 1039 1075
Note:
See TracChangeset
for help on using the changeset viewer.

