1 /* Target file management for GNU Make.
2 Copyright (C) 1988-2022 Free Software Foundation, Inc.
3 This file is part of GNU Make.
5 GNU Make is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3 of the License, or (at your option) any later
10 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along with
15 this program. If not, see <https://www.gnu.org/licenses/>. */
31 /* Remember whether snap_deps has been invoked: we need this to be sure we
32 don't add new rules (via $(eval ...)) afterwards. In the future it would
33 be nice to support this, but it means we'd need to re-run snap_deps() or
34 at least its functionality... it might mean changing snap_deps() to be run
35 per-file, so we can invoke it after the eval... or remembering which files
36 in the hash have been snapped (a new boolean flag?) and having snap_deps()
37 only work on files which have not yet been snapped. */
40 /* Hash table of files the makefile knows how to make. */
43 file_hash_1 (const void *key)
45 return_ISTRING_HASH_1 (((struct file const *) key)->hname);
49 file_hash_2 (const void *key)
51 return_ISTRING_HASH_2 (((struct file const *) key)->hname);
55 file_hash_cmp (const void *x, const void *y)
57 return_ISTRING_COMPARE (((struct file const *) x)->hname,
58 ((struct file const *) y)->hname);
61 static struct hash_table files;
63 /* Whether or not .SECONDARY with no prerequisites was given. */
64 static int all_secondary = 0;
66 /* Whether or not .NOTINTERMEDIATE with no prerequisites was given. */
67 static int no_intermediates = 0;
69 /* Access the hash table of all file records.
70 lookup_file given a name, return the struct file * for that name,
71 or nil if there is none.
75 lookup_file (const char *name)
81 #ifndef WANT_CASE_SENSITIVE_TARGETS
86 assert (*name != '\0');
88 /* This is also done in parse_file_seq, so this is redundant
89 for names read from makefiles. It is here for names passed
90 on the command line. */
92 want_vmsify = (strpbrk (name, "]>:^") != NULL);
93 # ifndef WANT_CASE_SENSITIVE_TARGETS
98 lname = xstrdup (name);
99 for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
100 *ln = isupper ((unsigned char)*n) ? tolower ((unsigned char)*n) : *n;
106 while (name[0] == '[' && name[1] == ']' && name[2] != '\0')
108 while (name[0] == '<' && name[1] == '>' && name[2] != '\0')
111 while (name[0] == '.' && ISDIRSEP (name[1]) && name[2] != '\0')
114 while (ISDIRSEP (*name))
115 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
121 /* It was all slashes after a dot. */
128 /* TODO - This section is probably not needed. */
133 file_key.hname = name;
134 f = hash_find_item (&files, &file_key);
135 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
143 /* Look up a file record for file NAME and return it.
144 Create a new record if one doesn't exist. NAME will be stored in the
145 new record so it should be constant or in the strcache etc.
149 enter_file (const char *name)
153 struct file **file_slot;
154 struct file file_key;
156 assert (*name != '\0');
157 assert (! verify_flag || strcache_iscached (name));
159 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
164 lname = xstrdup (name);
165 for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
166 if (isupper ((unsigned char)*n))
167 *ln = tolower ((unsigned char)*n);
172 name = strcache_add (lname);
177 file_key.hname = name;
178 file_slot = (struct file **) hash_find_slot (&files, &file_key);
180 if (! HASH_VACANT (f) && !f->double_colon)
186 new = xcalloc (sizeof (struct file));
187 new->name = new->hname = name;
188 new->update_status = us_none;
193 hash_insert_at (&files, new, file_slot);
197 /* There is already a double-colon entry for this file. */
198 new->double_colon = f;
206 /* Rehash FILE to NAME. This is not as simple as resetting
207 the 'hname' member, since it must be put in a new hash bucket,
208 and possibly merged with an existing file called NAME. */
211 rehash_file (struct file *from_file, const char *to_hname)
213 struct file file_key;
214 struct file **file_slot;
215 struct file *to_file;
216 struct file *deleted_file;
219 /* If it's already that name, we're done. */
220 from_file->builtin = 0;
221 file_key.hname = to_hname;
222 if (! file_hash_cmp (from_file, &file_key))
225 /* Find the end of the renamed list for the "from" file. */
226 file_key.hname = from_file->hname;
227 while (from_file->renamed != 0)
228 from_file = from_file->renamed;
229 if (file_hash_cmp (from_file, &file_key))
230 /* hname changed unexpectedly!! */
233 /* Remove the "from" file from the hash. */
234 deleted_file = hash_delete (&files, from_file);
235 if (deleted_file != from_file)
236 /* from_file isn't the one stored in files */
239 /* Find where the newly renamed file will go in the hash. */
240 file_key.hname = to_hname;
241 file_slot = (struct file **) hash_find_slot (&files, &file_key);
242 to_file = *file_slot;
244 /* Change the hash name for this file. */
245 from_file->hname = to_hname;
246 for (f = from_file->double_colon; f != 0; f = f->prev)
249 /* If the new name doesn't exist yet just set it to the renamed file. */
250 if (HASH_VACANT (to_file))
252 hash_insert_at (&files, from_file, file_slot);
256 /* TO_FILE already exists under TO_HNAME.
257 We must retain TO_FILE and merge FROM_FILE into it. */
259 if (from_file->cmds != 0)
261 if (to_file->cmds == 0)
262 to_file->cmds = from_file->cmds;
263 else if (from_file->cmds != to_file->cmds)
265 size_t l = strlen (from_file->name);
266 /* We have two sets of commands. We will go with the
267 one given in the rule found through directory search,
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 l + strlen (to_file->cmds->fileinfo.filenm) + INTSTR_LENGTH,
272 _("Recipe was specified for file '%s' at %s:%lu,"),
273 from_file->name, from_file->cmds->fileinfo.filenm,
274 from_file->cmds->fileinfo.lineno);
276 error (&from_file->cmds->fileinfo, l,
277 _("Recipe for file '%s' was found by implicit rule search,"),
279 l += strlen (to_hname);
280 error (&from_file->cmds->fileinfo, l,
281 _("but '%s' is now considered the same file as '%s'."),
282 from_file->name, to_hname);
283 error (&from_file->cmds->fileinfo, l,
284 _("Recipe for '%s' will be ignored in favor of the one for '%s'."),
285 from_file->name, to_hname);
289 /* Merge the dependencies of the two files. */
291 if (to_file->deps == 0)
292 to_file->deps = from_file->deps;
295 struct dep *deps = to_file->deps;
296 while (deps->next != 0)
298 deps->next = from_file->deps;
301 merge_variable_set_lists (&to_file->variables, from_file->variables);
303 if (to_file->double_colon && from_file->is_target && !from_file->double_colon)
304 OSS (fatal, NILF, _("can't rename single-colon '%s' to double-colon '%s'"),
305 from_file->name, to_hname);
306 if (!to_file->double_colon && from_file->double_colon)
308 if (to_file->is_target)
310 _("can't rename double-colon '%s' to single-colon '%s'"),
311 from_file->name, to_hname);
313 to_file->double_colon = from_file->double_colon;
316 if (from_file->last_mtime > to_file->last_mtime)
317 /* %%% Kludge so -W wins on a file that gets vpathized. */
318 to_file->last_mtime = from_file->last_mtime;
320 to_file->mtime_before_update = from_file->mtime_before_update;
322 #define MERGE(field) to_file->field |= from_file->field
325 MERGE (tried_implicit);
331 /* Don't merge intermediate because this file might be pre-existing */
334 MERGE (notintermediate);
335 MERGE (ignore_vpath);
339 to_file->builtin = 0;
340 from_file->renamed = to_file;
343 /* Rename FILE to NAME. This is not as simple as resetting
344 the 'name' member, since it must be put in a new hash bucket,
345 and possibly merged with an existing file called NAME. */
348 rename_file (struct file *from_file, const char *to_hname)
350 rehash_file (from_file, to_hname);
353 from_file->name = from_file->hname;
354 from_file = from_file->prev;
358 /* Remove all nonprecious intermediate files.
359 If SIG is nonzero, this was caused by a fatal signal,
360 meaning that a different message will be printed, and
361 the message will go to stderr rather than stdout. */
364 remove_intermediates (int sig)
366 struct file **file_slot;
367 struct file **file_end;
370 /* If there's no way we will ever remove anything anyway, punt early. */
371 if (question_flag || touch_flag || all_secondary)
374 if (sig && just_print_flag)
377 file_slot = (struct file **) files.ht_vec;
378 file_end = file_slot + files.ht_size;
379 for ( ; file_slot < file_end; file_slot++)
380 if (! HASH_VACANT (*file_slot))
382 struct file *f = *file_slot;
383 /* Is this file eligible for automatic deletion?
384 Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
385 given on the command line, and it's either a -include makefile or
386 it's not precious. */
387 if (f->intermediate && (f->dontcare || !f->precious)
388 && !f->secondary && !f->notintermediate && !f->cmd_target)
391 if (f->update_status == us_none)
392 /* If nothing would have created this file yet,
393 don't print an "rm" command for it. */
399 status = unlink (f->name);
400 if (status < 0 && errno == ENOENT)
407 _("*** Deleting intermediate file '%s'"), f->name);
411 DB (DB_BASIC, (_("Removing intermediate files...\n")));
416 fputs ("rm ", stdout);
421 fputs (f->name, stdout);
427 perror_with_name ("\nunlink: ", f->name);
428 /* Start printing over. */
442 /* Given a string containing prerequisites (fully expanded), break it up into
443 a struct dep list. Enter each of these prereqs into the file database.
446 split_prereqs (char *p)
448 struct dep *new = PARSE_FILE_SEQ (&p, struct dep, MAP_PIPE, NULL, PARSEFS_WAIT);
452 /* Files that follow '|' are "order-only" prerequisites that satisfy the
453 dependency by existing: their modification times are irrelevant. */
457 ood = PARSE_FILE_SEQ (&p, struct dep, MAP_NUL, NULL, PARSEFS_WAIT);
464 for (dp = new; dp->next != NULL; dp = dp->next)
469 for (; ood != NULL; ood = ood->next)
470 ood->ignore_mtime = 1;
476 /* Given a list of prerequisites, enter them into the file database.
477 If STEM is set then first expand patterns using STEM. */
479 enter_prereqs (struct dep *deps, const char *stem)
486 /* If we have a stem, expand the %'s. We use patsubst_expand to translate
487 the prerequisites' patterns into plain prerequisite names. */
490 const char *pattern = "%";
491 struct dep *dp = deps, *dl = 0;
496 size_t nl = strlen (dp->name) + 1;
497 char *nm = alloca (nl);
498 memcpy (nm, dp->name, nl);
499 percent = find_percent (nm);
504 /* We have to handle empty stems specially, because that
505 would be equivalent to $(patsubst %,dp->name,) which
506 will always be empty. */
509 memmove (percent, percent+1, strlen (percent));
510 o = variable_buffer_output (variable_buffer, nm,
514 o = patsubst_expand_pat (variable_buffer, stem, pattern, nm,
515 pattern+1, percent+1);
517 /* If the name expanded to the empty string, ignore it. */
518 if (variable_buffer[0] == '\0')
522 dp = deps = deps->next;
524 dp = dl->next = dp->next;
530 dp->name = strcache_add_len (variable_buffer,
531 o - variable_buffer);
534 dp->staticpattern = 1;
540 /* Enter them as files, unless they need a 2nd expansion. */
541 for (d1 = deps; d1 != 0; d1 = d1->next)
543 if (d1->need_2nd_expansion)
546 d1->file = lookup_file (d1->name);
548 d1->file = enter_file (d1->name);
549 d1->staticpattern = 0;
552 /* This file is explicitly mentioned as a prereq. */
553 d1->file->is_explicit = 1;
559 /* Expand and parse each dependency line.
560 For each dependency of the file, make the 'struct dep' point
561 at the appropriate 'struct file' (which may have to be created). */
563 expand_deps (struct file *f)
575 /* Walk through the dependencies. For any dependency that needs 2nd
576 expansion, expand it then insert the result into the list. */
582 struct dep *new, *next;
584 if (! d->name || ! d->need_2nd_expansion)
586 /* This one is all set already. */
592 /* If it's from a static pattern rule, convert the initial pattern in
593 each word to "$*" so they'll expand properly. */
594 if (d->staticpattern)
596 const char *cs = d->name;
599 /* Count the number of % in the string. */
600 while ((cs = strchr (cs, '%')) != NULL)
608 /* Allocate enough space to replace all % with $*. */
609 size_t slen = strlen (d->name) + nperc + 1;
610 const char *pcs = d->name;
611 char *name = xmalloc (slen);
614 /* Substitute the first % in each word. */
615 cs = strchr (pcs, '%');
619 s = mempcpy (s, pcs, cs - pcs);
624 /* Find the first % after the next whitespace. */
625 cs = strchr (end_of_token (cs), '%');
629 free ((char*)d->name);
634 /* We're going to do second expansion so initialize file variables for
635 the file. Since the stem for static pattern rules comes from
636 individual dep lines, we will temporarily set f->stem to d->stem. */
639 initialize_file_variables (f, 0);
643 set_file_variables (f, d->stem ? d->stem : f->stem);
645 /* Perform second expansion. */
646 p = variable_expand_for_file (d->name, f);
648 /* Free the un-expanded name. */
649 free ((char*)d->name);
651 /* Parse the prerequisites and enter them into the file database. */
652 new = split_prereqs (p);
654 /* If there were no prereqs here (blank!) then throw this one out. */
664 /* Add newly parsed prerequisites. */
670 for (dp = &new, d = new; d != 0; dp = &d->next, d = d->next)
672 d->file = lookup_file (d->name);
674 d->file = enter_file (d->name);
678 /* This file is explicitly mentioned as a prereq. */
679 d->file->is_explicit = 1;
685 /* Shuffle mode assumes '->next' and '->shuf' links both traverse the same
686 dependencies (in different sequences). Regenerate '->shuf' so we don't
687 refer to stale data. */
689 shuffle_deps_recursive (f->deps);
692 /* Add extra prereqs to the file in question. */
695 expand_extra_prereqs (const struct variable *extra)
698 struct dep *prereqs = extra ? split_prereqs (variable_expand (extra->value)) : NULL;
700 for (d = prereqs; d; d = d->next)
702 d->file = lookup_file (d->name);
704 d->file = enter_file (d->name);
706 d->ignore_automatic_vars = 1;
712 /* Perform per-file snap operations. */
715 snap_file (const void *item, void *arg)
717 struct file *f = (struct file*)item;
718 struct dep *prereqs = NULL;
720 /* If we're not doing second expansion then reset updating. */
721 if (!second_expansion)
724 /* More specific setting has priority. */
726 /* If .SECONDARY is set with no deps, mark all targets as intermediate,
727 unless the target is a prereq of .NOTINTERMEDIATE. */
728 if (all_secondary && !f->notintermediate)
731 /* If .NOTINTERMEDIATE is set with no deps, mark all targets as
732 notintermediate, unless the target is a prereq of .INTERMEDIATE. */
733 if (no_intermediates && !f->intermediate && !f->secondary)
734 f->notintermediate = 1;
736 /* If .EXTRA_PREREQS is set, add them as ignored by automatic variables. */
738 prereqs = expand_extra_prereqs (lookup_variable_in_set (STRING_SIZE_TUPLE(".EXTRA_PREREQS"), f->variables->set));
740 else if (f->is_target)
741 prereqs = copy_dep_chain (arg);
746 for (d = prereqs; d; d = d->next)
747 if (streq (f->name, dep_name (d)))
748 /* Skip circular dependencies. */
752 /* We broke early: must have found a circular dependency. */
753 free_dep_chain (prereqs);
766 /* Mark the files depended on by .PRECIOUS, .PHONY, .SILENT,
767 and various other special targets. */
776 /* Remember that we've done this. Once we start snapping deps we can no
777 longer define new targets. */
780 /* Now manage all the special targets. */
782 for (f = lookup_file (".PRECIOUS"); f != 0; f = f->prev)
783 for (d = f->deps; d != 0; d = d->next)
784 for (f2 = d->file; f2 != 0; f2 = f2->prev)
787 for (f = lookup_file (".LOW_RESOLUTION_TIME"); f != 0; f = f->prev)
788 for (d = f->deps; d != 0; d = d->next)
789 for (f2 = d->file; f2 != 0; f2 = f2->prev)
790 f2->low_resolution_time = 1;
792 for (f = lookup_file (".PHONY"); f != 0; f = f->prev)
793 for (d = f->deps; d != 0; d = d->next)
794 for (f2 = d->file; f2 != 0; f2 = f2->prev)
796 /* Mark this file as phony nonexistent target. */
799 f2->last_mtime = NONEXISTENT_MTIME;
800 f2->mtime_before_update = NONEXISTENT_MTIME;
803 for (f = lookup_file (".NOTINTERMEDIATE"); f != 0; f = f->prev)
804 /* Mark .NOTINTERMEDIATE deps as notintermediate files. */
806 for (d = f->deps; d != 0; d = d->next)
807 for (f2 = d->file; f2 != 0; f2 = f2->prev)
808 f2->notintermediate = 1;
809 /* .NOTINTERMEDIATE with no deps marks all files as notintermediate. */
811 no_intermediates = 1;
813 /* The same file connot be both .INTERMEDIATE and .NOTINTERMEDIATE.
814 However, it is possible for a file to be .INTERMEDIATE and also match a
815 .NOTINTERMEDIATE pattern. In that case, the intermediate file has
816 priority over the notintermediate pattern. This priority is enforced by
819 for (f = lookup_file (".INTERMEDIATE"); f != 0; f = f->prev)
820 /* Mark .INTERMEDIATE deps as intermediate files. */
821 for (d = f->deps; d != 0; d = d->next)
822 for (f2 = d->file; f2 != 0; f2 = f2->prev)
823 if (f2->notintermediate)
825 _("%s cannot be both .NOTINTERMEDIATE and .INTERMEDIATE"),
828 f2->intermediate = 1;
829 /* .INTERMEDIATE with no deps does nothing.
830 Marking all files as intermediates is useless since the goal targets
831 would be deleted after they are built. */
833 for (f = lookup_file (".SECONDARY"); f != 0; f = f->prev)
834 /* Mark .SECONDARY deps as both intermediate and secondary. */
836 for (d = f->deps; d != 0; d = d->next)
837 for (f2 = d->file; f2 != 0; f2 = f2->prev)
838 if (f2->notintermediate)
840 _("%s cannot be both .NOTINTERMEDIATE and .SECONDARY"),
843 f2->intermediate = f2->secondary = 1;
844 /* .SECONDARY with no deps listed marks *all* files that way. */
848 if (no_intermediates && all_secondary)
850 _(".NOTINTERMEDIATE and .SECONDARY are mutually exclusive"));
852 f = lookup_file (".EXPORT_ALL_VARIABLES");
853 if (f != 0 && f->is_target)
854 export_all_variables = 1;
856 f = lookup_file (".IGNORE");
857 if (f != 0 && f->is_target)
860 ignore_errors_flag = 1;
862 for (d = f->deps; d != 0; d = d->next)
863 for (f2 = d->file; f2 != 0; f2 = f2->prev)
864 f2->command_flags |= COMMANDS_NOERROR;
867 f = lookup_file (".SILENT");
868 if (f != 0 && f->is_target)
873 for (d = f->deps; d != 0; d = d->next)
874 for (f2 = d->file; f2 != 0; f2 = f2->prev)
875 f2->command_flags |= COMMANDS_SILENT;
878 f = lookup_file (".NOTPARALLEL");
879 if (f != 0 && f->is_target)
886 /* Set a wait point between every prerequisite of each target. */
887 for (d = f->deps; d != NULL; d = d->next)
888 for (f2 = d->file; f2 != NULL; f2 = f2->prev)
890 for (d2 = f2->deps->next; d2 != NULL; d2 = d2->next)
895 struct dep *prereqs = expand_extra_prereqs (lookup_variable (STRING_SIZE_TUPLE(".EXTRA_PREREQS")));
897 /* Perform per-file snap operations. */
898 hash_map_arg(&files, snap_file, prereqs);
900 free_dep_chain (prereqs);
903 #ifndef NO_MINUS_C_MINUS_O
904 /* If .POSIX was defined, remove OUTPUT_OPTION to comply. */
905 /* This needs more work: what if the user sets this in the makefile?
907 define_variable_cname ("OUTPUT_OPTION", "", o_default, 1);
912 /* Set the 'command_state' member of FILE and all its 'also_make's.
913 Don't decrease the state of also_make's (e.g., don't downgrade a 'running'
914 also_make to a 'deps_running' also_make). */
917 set_command_state (struct file *file, enum cmd_state state)
921 file->command_state = state;
923 for (d = file->also_make; d != 0; d = d->next)
924 if (state > d->file->command_state)
925 d->file->command_state = state;
928 /* Convert an external file timestamp to internal form. */
931 file_timestamp_cons (const char *fname, time_t stamp, long int ns)
933 int offset = ORDINARY_MTIME_MIN + (FILE_TIMESTAMP_HI_RES ? ns : 0);
934 FILE_TIMESTAMP s = stamp;
935 FILE_TIMESTAMP product = (FILE_TIMESTAMP) s << FILE_TIMESTAMP_LO_BITS;
936 FILE_TIMESTAMP ts = product + offset;
938 if (! (s <= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX)
939 && product <= ts && ts <= ORDINARY_MTIME_MAX))
941 char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
942 const char *f = fname ? fname : _("Current time");
943 ts = s <= OLD_MTIME ? ORDINARY_MTIME_MIN : ORDINARY_MTIME_MAX;
944 file_timestamp_sprintf (buf, ts);
946 _("%s: Timestamp out of range; substituting %s"), f, buf);
952 /* Return the current time as a file timestamp, setting *RESOLUTION to
955 file_timestamp_now (int *resolution)
961 /* Don't bother with high-resolution clocks if file timestamps have
962 only one-second resolution. The code below should work, but it's
963 not worth the hassle of debugging it on hosts where it fails. */
964 #if FILE_TIMESTAMP_HI_RES
965 # if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME
967 struct timespec timespec;
968 if (clock_gettime (CLOCK_REALTIME, ×pec) == 0)
972 ns = timespec.tv_nsec;
977 # if HAVE_GETTIMEOFDAY
979 struct timeval timeval;
980 if (gettimeofday (&timeval, 0) == 0)
984 ns = timeval.tv_usec * 1000;
992 s = time ((time_t *) 0);
995 #if FILE_TIMESTAMP_HI_RES
999 return file_timestamp_cons (0, s, ns);
1002 /* Place into the buffer P a printable representation of the file
1005 file_timestamp_sprintf (char *p, FILE_TIMESTAMP ts)
1007 time_t t = FILE_TIMESTAMP_S (ts);
1008 struct tm *tm = localtime (&t);
1012 intmax_t year = tm->tm_year;
1013 sprintf (p, "%04" PRIdMAX "-%02d-%02d %02d:%02d:%02d",
1014 year + 1900, tm->tm_mon + 1, tm->tm_mday,
1015 tm->tm_hour, tm->tm_min, tm->tm_sec);
1018 sprintf (p, "%" PRIdMAX, (intmax_t) t);
1020 sprintf (p, "%" PRIuMAX, (uintmax_t) t);
1023 /* Append nanoseconds as a fraction, but remove trailing zeros. We don't
1024 know the actual timestamp resolution, since clock_getres applies only to
1025 local times, whereas this timestamp might come from a remote filesystem.
1026 So removing trailing zeros is the best guess that we can do. */
1027 sprintf (p, ".%09d", FILE_TIMESTAMP_NS (ts));
1028 p += strlen (p) - 1;
1036 /* Print the data base of files. */
1039 print_prereqs (const struct dep *deps)
1041 const struct dep *ood = 0;
1043 /* Print all normal dependencies; note any order-only deps. */
1044 for (; deps != 0; deps = deps->next)
1045 if (! deps->ignore_mtime)
1046 printf (" %s%s", deps->wait_here ? ".WAIT " : "", dep_name (deps));
1050 /* Print order-only deps, if we have any. */
1053 printf (" | %s%s", ood->wait_here ? ".WAIT " : "", dep_name (ood));
1054 for (ood = ood->next; ood != 0; ood = ood->next)
1055 if (ood->ignore_mtime)
1056 printf (" %s%s", ood->wait_here ? ".WAIT " : "", dep_name (ood));
1063 print_file (const void *item)
1065 const struct file *f = item;
1067 /* If we're not using builtin targets, don't show them.
1069 Ideally we'd be able to delete them altogether but currently there's no
1070 facility to ever delete a file once it's been added. */
1071 if (no_builtin_rules_flag && f->builtin)
1076 if (f->cmds && f->cmds->recipe_prefix != cmd_prefix)
1078 fputs (".RECIPEPREFIX = ", stdout);
1079 cmd_prefix = f->cmds->recipe_prefix;
1080 if (cmd_prefix != RECIPEPREFIX_DEFAULT)
1081 putchar (cmd_prefix);
1085 if (f->variables != 0)
1086 print_target_variables (f);
1089 puts (_("# Not a target:"));
1090 printf ("%s:%s", f->name, f->double_colon ? ":" : "");
1091 print_prereqs (f->deps);
1094 puts (_("# Precious file (prerequisite of .PRECIOUS)."));
1096 puts (_("# Phony target (prerequisite of .PHONY)."));
1098 puts (_("# Command line target."));
1100 puts (_("# A default, MAKEFILES, or -include/sinclude makefile."));
1102 puts (_("# Builtin rule"));
1103 puts (f->tried_implicit
1104 ? _("# Implicit rule search has been done.")
1105 : _("# Implicit rule search has not been done."));
1107 printf (_("# Implicit/static pattern stem: '%s'\n"), f->stem);
1108 if (f->intermediate)
1109 puts (_("# File is an intermediate prerequisite."));
1110 if (f->notintermediate)
1111 puts (_("# File is a prerequisite of .NOTINTERMEDIATE."));
1113 puts (_("# File is secondary (prerequisite of .SECONDARY)."));
1114 if (f->also_make != 0)
1116 const struct dep *d;
1117 fputs (_("# Also makes:"), stdout);
1118 for (d = f->also_make; d != 0; d = d->next)
1119 printf (" %s", dep_name (d));
1122 if (f->last_mtime == UNKNOWN_MTIME)
1123 puts (_("# Modification time never checked."));
1124 else if (f->last_mtime == NONEXISTENT_MTIME)
1125 puts (_("# File does not exist."));
1126 else if (f->last_mtime == OLD_MTIME)
1127 puts (_("# File is very old."));
1130 char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
1131 file_timestamp_sprintf (buf, f->last_mtime);
1132 printf (_("# Last modified %s\n"), buf);
1135 ? _("# File has been updated.") : _("# File has not been updated."));
1136 switch (f->command_state)
1139 puts (_("# Recipe currently running (THIS IS A BUG)."));
1141 case cs_deps_running:
1142 puts (_("# Dependencies recipe running (THIS IS A BUG)."));
1144 case cs_not_started:
1146 switch (f->update_status)
1151 puts (_("# Successfully updated."));
1154 assert (question_flag);
1155 puts (_("# Needs to be updated (-q is set)."));
1158 puts (_("# Failed to be updated."));
1163 puts (_("# Invalid value in 'command_state' member!"));
1169 if (f->variables != 0)
1170 print_file_variables (f);
1173 print_commands (f->cmds);
1176 print_file ((const void *) f->prev);
1180 print_file_data_base (void)
1182 puts (_("\n# Files"));
1184 hash_map (&files, print_file);
1186 fputs (_("\n# files hash-table stats:\n# "), stdout);
1187 hash_print_stats (&files, stdout);
1190 /* Verify the integrity of the data base of files. */
1192 #define VERIFY_CACHED(_p,_n) \
1194 if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \
1195 error (NULL, strlen (_p->name) + CSTRLEN (# _n) + strlen (_p->_n), \
1196 _("%s: Field '%s' not cached: %s"), _p->name, # _n, _p->_n); \
1200 verify_file (const void *item)
1202 const struct file *f = item;
1203 const struct dep *d;
1205 VERIFY_CACHED (f, name);
1206 VERIFY_CACHED (f, hname);
1207 VERIFY_CACHED (f, vpath);
1208 VERIFY_CACHED (f, stem);
1210 /* Check the deps. */
1211 for (d = f->deps; d != 0; d = d->next)
1213 if (! d->need_2nd_expansion)
1214 VERIFY_CACHED (d, name);
1215 VERIFY_CACHED (d, stem);
1220 verify_file_data_base (void)
1222 hash_map (&files, verify_file);
1225 #define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500)
1228 build_target_list (char *value)
1230 static unsigned long last_targ_count = 0;
1232 if (files.ht_fill != last_targ_count)
1234 size_t max = EXPANSION_INCREMENT (strlen (value));
1237 struct file **fp = (struct file **) files.ht_vec;
1238 struct file **end = &fp[files.ht_size];
1240 /* Make sure we have at least MAX bytes in the allocated buffer. */
1241 value = xrealloc (value, max);
1245 for (; fp < end; ++fp)
1246 if (!HASH_VACANT (*fp) && (*fp)->is_target)
1248 struct file *f = *fp;
1249 size_t l = strlen (f->name);
1254 size_t off = p - value;
1256 max += EXPANSION_INCREMENT (l + 1);
1257 value = xrealloc (value, max);
1261 p = mempcpy (p, f->name, l);
1266 last_targ_count = files.ht_fill;
1273 init_hash_files (void)
1275 hash_init (&files, 1000, file_hash_1, file_hash_2, file_hash_cmp);