- Fixed a bug reported by Michael Matz regarding handling of parallel
[make.git] / file.c
blob9f9ddb55a550363089c95a78d4ee04e359b20a92
1 /* Target file hash table management for GNU Make.
2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 2002 Free Software Foundation, Inc.
4 This file is part of GNU Make.
6 GNU Make is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Make is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Make; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include "make.h"
23 #include <assert.h>
25 #include "dep.h"
26 #include "filedef.h"
27 #include "job.h"
28 #include "commands.h"
29 #include "variable.h"
30 #include "debug.h"
31 #include "hash.h"
34 /* Remember whether snap_deps has been invoked: we need this to be sure we
35 don't add new rules (via $(eval ...)) afterwards. In the future it would
36 be nice to support this, but it means we'd need to re-run snap_deps() or
37 at least its functionality... it might mean changing snap_deps() to be run
38 per-file, so we can invoke it after the eval... or remembering which files
39 in the hash have been snapped (a new boolean flag?) and having snap_deps()
40 only work on files which have not yet been snapped. */
41 int snapped_deps = 0;
43 /* Hash table of files the makefile knows how to make. */
45 static unsigned long
46 file_hash_1 (const void *key)
48 return_ISTRING_HASH_1 (((struct file const *) key)->hname);
51 static unsigned long
52 file_hash_2 (const void *key)
54 return_ISTRING_HASH_2 (((struct file const *) key)->hname);
57 static int
58 file_hash_cmp (const void *x, const void *y)
60 return_ISTRING_COMPARE (((struct file const *) x)->hname,
61 ((struct file const *) y)->hname);
64 #ifndef FILE_BUCKETS
65 #define FILE_BUCKETS 1007
66 #endif
67 static struct hash_table files;
69 /* Whether or not .SECONDARY with no prerequisites was given. */
70 static int all_secondary = 0;
72 /* Access the hash table of all file records.
73 lookup_file given a name, return the struct file * for that name,
74 or nil if there is none.
75 enter_file similar, but create one if there is none. */
77 struct file *
78 lookup_file (char *name)
80 register struct file *f;
81 struct file file_key;
82 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
83 register char *lname, *ln;
84 #endif
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. */
91 #ifdef VMS
92 # ifndef WANT_CASE_SENSITIVE_TARGETS
94 register char *n;
95 lname = (char *) malloc (strlen (name) + 1);
96 for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
97 *ln = isupper ((unsigned char)*n) ? tolower ((unsigned char)*n) : *n;
98 *ln = '\0';
99 name = lname;
101 # endif
103 while (name[0] == '[' && name[1] == ']' && name[2] != '\0')
104 name += 2;
105 #endif
106 while (name[0] == '.' && name[1] == '/' && name[2] != '\0')
108 name += 2;
109 while (*name == '/')
110 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
111 ++name;
114 if (*name == '\0')
115 /* It was all slashes after a dot. */
116 #ifdef VMS
117 name = "[]";
118 #else
119 #ifdef _AMIGA
120 name = "";
121 #else
122 name = "./";
123 #endif /* AMIGA */
124 #endif /* VMS */
126 file_key.hname = name;
127 f = (struct file *) hash_find_item (&files, &file_key);
128 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
129 free (lname);
130 #endif
131 return f;
134 struct file *
135 enter_file (char *name)
137 register struct file *f;
138 register struct file *new;
139 register struct file **file_slot;
140 struct file file_key;
141 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
142 char *lname, *ln;
143 #endif
145 assert (*name != '\0');
147 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
149 register char *n;
150 lname = (char *) malloc (strlen (name) + 1);
151 for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
153 if (isupper ((unsigned char)*n))
154 *ln = tolower ((unsigned char)*n);
155 else
156 *ln = *n;
159 *ln = 0;
160 /* Creates a possible leak, old value of name is unreachable, but I
161 currently don't know how to fix it. */
162 name = lname;
164 #endif
166 file_key.hname = name;
167 file_slot = (struct file **) hash_find_slot (&files, &file_key);
168 f = *file_slot;
169 if (! HASH_VACANT (f) && !f->double_colon)
171 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
172 free(lname);
173 #endif
174 return f;
177 new = (struct file *) xmalloc (sizeof (struct file));
178 bzero ((char *) new, sizeof (struct file));
179 new->name = new->hname = name;
180 new->update_status = -1;
182 if (HASH_VACANT (f))
183 hash_insert_at (&files, new, file_slot);
184 else
186 /* There is already a double-colon entry for this file. */
187 new->double_colon = f;
188 while (f->prev != 0)
189 f = f->prev;
190 f->prev = new;
193 return new;
196 /* Rename FILE to NAME. This is not as simple as resetting
197 the `name' member, since it must be put in a new hash bucket,
198 and possibly merged with an existing file called NAME. */
200 void
201 rename_file (struct file *from_file, char *to_hname)
203 rehash_file (from_file, to_hname);
204 while (from_file)
206 from_file->name = from_file->hname;
207 from_file = from_file->prev;
211 /* Rehash FILE to NAME. This is not as simple as resetting
212 the `hname' member, since it must be put in a new hash bucket,
213 and possibly merged with an existing file called NAME. */
215 void
216 rehash_file (struct file *from_file, char *to_hname)
218 struct file file_key;
219 struct file **file_slot;
220 struct file *to_file;
221 struct file *deleted_file;
222 struct file *f;
224 file_key.hname = to_hname;
225 if (0 == file_hash_cmp (from_file, &file_key))
226 return;
228 file_key.hname = from_file->hname;
229 while (from_file->renamed != 0)
230 from_file = from_file->renamed;
231 if (file_hash_cmp (from_file, &file_key))
232 /* hname changed unexpectedly */
233 abort ();
235 deleted_file = hash_delete (&files, from_file);
236 if (deleted_file != from_file)
237 /* from_file isn't the one stored in files */
238 abort ();
240 file_key.hname = to_hname;
241 file_slot = (struct file **) hash_find_slot (&files, &file_key);
242 to_file = *file_slot;
244 from_file->hname = to_hname;
245 for (f = from_file->double_colon; f != 0; f = f->prev)
246 f->hname = to_hname;
248 if (HASH_VACANT (to_file))
249 hash_insert_at (&files, from_file, file_slot);
250 else
252 /* TO_FILE already exists under TO_HNAME.
253 We must retain TO_FILE and merge FROM_FILE into it. */
255 if (from_file->cmds != 0)
257 if (to_file->cmds == 0)
258 to_file->cmds = from_file->cmds;
259 else if (from_file->cmds != to_file->cmds)
261 /* We have two sets of commands. We will go with the
262 one given in the rule explicitly mentioning this name,
263 but give a message to let the user know what's going on. */
264 if (to_file->cmds->fileinfo.filenm != 0)
265 error (&from_file->cmds->fileinfo,
266 _("Commands were specified for file `%s' at %s:%lu,"),
267 from_file->name, to_file->cmds->fileinfo.filenm,
268 to_file->cmds->fileinfo.lineno);
269 else
270 error (&from_file->cmds->fileinfo,
271 _("Commands for file `%s' were found by implicit rule search,"),
272 from_file->name);
273 error (&from_file->cmds->fileinfo,
274 _("but `%s' is now considered the same file as `%s'."),
275 from_file->name, to_hname);
276 error (&from_file->cmds->fileinfo,
277 _("Commands for `%s' will be ignored in favor of those for `%s'."),
278 to_hname, from_file->name);
282 /* Merge the dependencies of the two files. */
284 if (to_file->deps == 0)
285 to_file->deps = from_file->deps;
286 else
288 register struct dep *deps = to_file->deps;
289 while (deps->next != 0)
290 deps = deps->next;
291 deps->next = from_file->deps;
294 merge_variable_set_lists (&to_file->variables, from_file->variables);
296 if (to_file->double_colon && from_file->is_target && !from_file->double_colon)
297 fatal (NILF, _("can't rename single-colon `%s' to double-colon `%s'"),
298 from_file->name, to_hname);
299 if (!to_file->double_colon && from_file->double_colon)
301 if (to_file->is_target)
302 fatal (NILF, _("can't rename double-colon `%s' to single-colon `%s'"),
303 from_file->name, to_hname);
304 else
305 to_file->double_colon = from_file->double_colon;
308 if (from_file->last_mtime > to_file->last_mtime)
309 /* %%% Kludge so -W wins on a file that gets vpathized. */
310 to_file->last_mtime = from_file->last_mtime;
312 to_file->mtime_before_update = from_file->mtime_before_update;
314 #define MERGE(field) to_file->field |= from_file->field
315 MERGE (precious);
316 MERGE (tried_implicit);
317 MERGE (updating);
318 MERGE (updated);
319 MERGE (is_target);
320 MERGE (cmd_target);
321 MERGE (phony);
322 MERGE (ignore_vpath);
323 #undef MERGE
325 from_file->renamed = to_file;
329 /* Remove all nonprecious intermediate files.
330 If SIG is nonzero, this was caused by a fatal signal,
331 meaning that a different message will be printed, and
332 the message will go to stderr rather than stdout. */
334 void
335 remove_intermediates (int sig)
337 register struct file **file_slot;
338 register struct file **file_end;
339 int doneany = 0;
341 /* If there's no way we will ever remove anything anyway, punt early. */
342 if (question_flag || touch_flag || all_secondary)
343 return;
345 if (sig && just_print_flag)
346 return;
348 file_slot = (struct file **) files.ht_vec;
349 file_end = file_slot + files.ht_size;
350 for ( ; file_slot < file_end; file_slot++)
351 if (! HASH_VACANT (*file_slot))
353 register struct file *f = *file_slot;
354 /* Is this file eligible for automatic deletion?
355 Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
356 given on the command-line, and it's either a -include makefile or
357 it's not precious. */
358 if (f->intermediate && (f->dontcare || !f->precious)
359 && !f->secondary && !f->cmd_target)
361 int status;
362 if (f->update_status == -1)
363 /* If nothing would have created this file yet,
364 don't print an "rm" command for it. */
365 continue;
366 if (just_print_flag)
367 status = 0;
368 else
370 status = unlink (f->name);
371 if (status < 0 && errno == ENOENT)
372 continue;
374 if (!f->dontcare)
376 if (sig)
377 error (NILF, _("*** Deleting intermediate file `%s'"), f->name);
378 else
380 if (! doneany)
381 DB (DB_BASIC, (_("Removing intermediate files...\n")));
382 if (!silent_flag)
384 if (! doneany)
386 fputs ("rm ", stdout);
387 doneany = 1;
389 else
390 putchar (' ');
391 fputs (f->name, stdout);
392 fflush (stdout);
395 if (status < 0)
396 perror_with_name ("unlink: ", f->name);
401 if (doneany && !sig)
403 putchar ('\n');
404 fflush (stdout);
408 /* Set the intermediate flag. */
410 static void
411 set_intermediate (const void *item)
413 struct file *f = (struct file *) item;
414 f->intermediate = 1;
417 /* Expand and parse each dependency line. */
418 static void
419 expand_deps (struct file *f)
421 struct dep *d, *d1;
422 struct dep *new = 0;
423 struct dep *old = f->deps;
424 unsigned int last_dep_has_cmds = f->updating;
425 int initialized = 0;
427 f->updating = 0;
428 f->deps = 0;
430 for (d = old; d != 0; d = d->next)
432 if (d->name != 0)
434 char *p;
436 /* If we need a second expansion on these, set up the file
437 variables, etc. It takes a lot of extra memory and processing
438 to do this, so only do it if it's needed. */
439 if (! d->need_2nd_expansion)
440 p = d->name;
441 else
443 /* We are going to do second expansion so initialize file
444 variables for the file. */
445 if (!initialized)
447 initialize_file_variables (f, 0);
448 initialized = 1;
451 set_file_variables (f);
453 p = variable_expand_for_file (d->name, f);
456 /* Parse the dependencies. */
457 new = (struct dep *)
458 multi_glob (
459 parse_file_seq (&p, '|', sizeof (struct dep), 1),
460 sizeof (struct dep));
462 if (*p)
464 /* Files that follow '|' are special prerequisites that
465 need only exist in order to satisfy the dependency.
466 Their modification times are irrelevant. */
467 struct dep **d_ptr;
469 for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)
471 ++p;
473 *d_ptr = (struct dep *)
474 multi_glob (
475 parse_file_seq (&p, '\0', sizeof (struct dep), 1),
476 sizeof (struct dep));
478 for (d1 = *d_ptr; d1 != 0; d1 = d1->next)
479 d1->ignore_mtime = 1;
482 /* Enter them as files. */
483 for (d1 = new; d1 != 0; d1 = d1->next)
485 d1->file = lookup_file (d1->name);
486 if (d1->file == 0)
487 d1->file = enter_file (d1->name);
488 else
489 free (d1->name);
490 d1->name = 0;
491 d1->need_2nd_expansion = 0;
494 /* Add newly parsed deps to f->deps. If this is the last
495 dependency line and this target has commands then put
496 it in front so the last dependency line (the one with
497 commands) ends up being the first. This is important
498 because people expect $< to hold first prerequisite
499 from the rule with commands. If it is not the last
500 dependency line or the rule does not have commands
501 then link it at the end so it appears in makefile
502 order. */
504 if (new != 0)
506 if (d->next == 0 && last_dep_has_cmds)
508 struct dep **d_ptr;
509 for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)
512 *d_ptr = f->deps;
513 f->deps = new;
515 else
517 struct dep **d_ptr;
518 for (d_ptr = &f->deps; *d_ptr; d_ptr = &(*d_ptr)->next)
521 *d_ptr = new;
527 free_ns_chain ((struct nameseq *) old);
530 /* For each dependency of each file, make the `struct dep' point
531 at the appropriate `struct file' (which may have to be created).
533 Also mark the files depended on by .PRECIOUS, .PHONY, .SILENT,
534 and various other special targets. */
536 void
537 snap_deps (void)
539 struct file *f;
540 struct file *f2;
541 struct dep *d;
542 struct file **file_slot_0;
543 struct file **file_slot;
544 struct file **file_end;
546 /* Perform second expansion and enter each dependency
547 name as a file. */
549 /* Expand .SUFFIXES first; it's dependencies are used for
550 $$* calculation. */
551 for (f = lookup_file (".SUFFIXES"); f != 0; f = f->prev)
552 expand_deps (f);
554 /* We must use hash_dump (), because within this loop
555 we might add new files to the table, possibly causing
556 an in-situ table expansion. */
557 file_slot_0 = (struct file **) hash_dump (&files, 0, 0);
558 file_end = file_slot_0 + files.ht_fill;
559 for (file_slot = file_slot_0; file_slot < file_end; file_slot++)
560 for (f = *file_slot; f != 0; f = f->prev)
562 if (strcmp (f->name, ".SUFFIXES") != 0)
563 expand_deps (f);
565 free (file_slot_0);
567 for (f = lookup_file (".PRECIOUS"); f != 0; f = f->prev)
568 for (d = f->deps; d != 0; d = d->next)
569 for (f2 = d->file; f2 != 0; f2 = f2->prev)
570 f2->precious = 1;
572 for (f = lookup_file (".LOW_RESOLUTION_TIME"); f != 0; f = f->prev)
573 for (d = f->deps; d != 0; d = d->next)
574 for (f2 = d->file; f2 != 0; f2 = f2->prev)
575 f2->low_resolution_time = 1;
577 for (f = lookup_file (".PHONY"); f != 0; f = f->prev)
578 for (d = f->deps; d != 0; d = d->next)
579 for (f2 = d->file; f2 != 0; f2 = f2->prev)
581 /* Mark this file as phony nonexistent target. */
582 f2->phony = 1;
583 f2->is_target = 1;
584 f2->last_mtime = NONEXISTENT_MTIME;
585 f2->mtime_before_update = NONEXISTENT_MTIME;
588 for (f = lookup_file (".INTERMEDIATE"); f != 0; f = f->prev)
590 /* .INTERMEDIATE with deps listed
591 marks those deps as intermediate files. */
592 for (d = f->deps; d != 0; d = d->next)
593 for (f2 = d->file; f2 != 0; f2 = f2->prev)
594 f2->intermediate = 1;
595 /* .INTERMEDIATE with no deps does nothing.
596 Marking all files as intermediates is useless
597 since the goal targets would be deleted after they are built. */
600 for (f = lookup_file (".SECONDARY"); f != 0; f = f->prev)
602 /* .SECONDARY with deps listed
603 marks those deps as intermediate files
604 in that they don't get rebuilt if not actually needed;
605 but unlike real intermediate files,
606 these are not deleted after make finishes. */
607 if (f->deps)
608 for (d = f->deps; d != 0; d = d->next)
609 for (f2 = d->file; f2 != 0; f2 = f2->prev)
610 f2->intermediate = f2->secondary = 1;
611 /* .SECONDARY with no deps listed marks *all* files that way. */
612 else
614 all_secondary = 1;
615 hash_map (&files, set_intermediate);
619 f = lookup_file (".EXPORT_ALL_VARIABLES");
620 if (f != 0 && f->is_target)
621 export_all_variables = 1;
623 f = lookup_file (".IGNORE");
624 if (f != 0 && f->is_target)
626 if (f->deps == 0)
627 ignore_errors_flag = 1;
628 else
629 for (d = f->deps; d != 0; d = d->next)
630 for (f2 = d->file; f2 != 0; f2 = f2->prev)
631 f2->command_flags |= COMMANDS_NOERROR;
634 f = lookup_file (".SILENT");
635 if (f != 0 && f->is_target)
637 if (f->deps == 0)
638 silent_flag = 1;
639 else
640 for (d = f->deps; d != 0; d = d->next)
641 for (f2 = d->file; f2 != 0; f2 = f2->prev)
642 f2->command_flags |= COMMANDS_SILENT;
645 f = lookup_file (".POSIX");
646 if (f != 0 && f->is_target)
647 posix_pedantic = 1;
649 f = lookup_file (".NOTPARALLEL");
650 if (f != 0 && f->is_target)
651 not_parallel = 1;
653 /* Remember that we've done this. */
654 snapped_deps = 1;
657 /* Set the `command_state' member of FILE and all its `also_make's. */
659 void
660 set_command_state (struct file *file, enum cmd_state state)
662 struct dep *d;
664 file->command_state = state;
666 for (d = file->also_make; d != 0; d = d->next)
667 d->file->command_state = state;
670 /* Convert an external file timestamp to internal form. */
672 FILE_TIMESTAMP
673 file_timestamp_cons (const char *fname, time_t s, int ns)
675 int offset = ORDINARY_MTIME_MIN + (FILE_TIMESTAMP_HI_RES ? ns : 0);
676 FILE_TIMESTAMP product = (FILE_TIMESTAMP) s << FILE_TIMESTAMP_LO_BITS;
677 FILE_TIMESTAMP ts = product + offset;
679 if (! (s <= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX)
680 && product <= ts && ts <= ORDINARY_MTIME_MAX))
682 char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
683 ts = s <= OLD_MTIME ? ORDINARY_MTIME_MIN : ORDINARY_MTIME_MAX;
684 file_timestamp_sprintf (buf, ts);
685 error (NILF, _("%s: Timestamp out of range; substituting %s"),
686 fname ? fname : _("Current time"), buf);
689 return ts;
692 /* Return the current time as a file timestamp, setting *RESOLUTION to
693 its resolution. */
694 FILE_TIMESTAMP
695 file_timestamp_now (int *resolution)
697 int r;
698 time_t s;
699 int ns;
701 /* Don't bother with high-resolution clocks if file timestamps have
702 only one-second resolution. The code below should work, but it's
703 not worth the hassle of debugging it on hosts where it fails. */
704 #if FILE_TIMESTAMP_HI_RES
705 # if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME
707 struct timespec timespec;
708 if (clock_gettime (CLOCK_REALTIME, &timespec) == 0)
710 r = 1;
711 s = timespec.tv_sec;
712 ns = timespec.tv_nsec;
713 goto got_time;
716 # endif
717 # if HAVE_GETTIMEOFDAY
719 struct timeval timeval;
720 if (gettimeofday (&timeval, 0) == 0)
722 r = 1000;
723 s = timeval.tv_sec;
724 ns = timeval.tv_usec * 1000;
725 goto got_time;
728 # endif
729 #endif
731 r = 1000000000;
732 s = time ((time_t *) 0);
733 ns = 0;
735 #if FILE_TIMESTAMP_HI_RES
736 got_time:
737 #endif
738 *resolution = r;
739 return file_timestamp_cons (0, s, ns);
742 /* Place into the buffer P a printable representation of the file
743 timestamp TS. */
744 void
745 file_timestamp_sprintf (char *p, FILE_TIMESTAMP ts)
747 time_t t = FILE_TIMESTAMP_S (ts);
748 struct tm *tm = localtime (&t);
750 if (tm)
751 sprintf (p, "%04d-%02d-%02d %02d:%02d:%02d",
752 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
753 tm->tm_hour, tm->tm_min, tm->tm_sec);
754 else if (t < 0)
755 sprintf (p, "%ld", (long) t);
756 else
757 sprintf (p, "%lu", (unsigned long) t);
758 p += strlen (p);
760 /* Append nanoseconds as a fraction, but remove trailing zeros.
761 We don't know the actual timestamp resolution, since clock_getres
762 applies only to local times, whereas this timestamp might come
763 from a remote filesystem. So removing trailing zeros is the
764 best guess that we can do. */
765 sprintf (p, ".%09d", FILE_TIMESTAMP_NS (ts));
766 p += strlen (p) - 1;
767 while (*p == '0')
768 p--;
769 p += *p != '.';
771 *p = '\0';
774 /* Print the data base of files. */
776 static void
777 print_file (const void *item)
779 struct file *f = (struct file *) item;
780 struct dep *d;
781 struct dep *ood = 0;
783 putchar ('\n');
784 if (!f->is_target)
785 puts (_("# Not a target:"));
786 printf ("%s:%s", f->name, f->double_colon ? ":" : "");
788 /* Print all normal dependencies; note any order-only deps. */
789 for (d = f->deps; d != 0; d = d->next)
790 if (! d->ignore_mtime)
791 printf (" %s", dep_name (d));
792 else if (! ood)
793 ood = d;
795 /* Print order-only deps, if we have any. */
796 if (ood)
798 printf (" | %s", dep_name (ood));
799 for (d = ood->next; d != 0; d = d->next)
800 if (d->ignore_mtime)
801 printf (" %s", dep_name (d));
804 putchar ('\n');
806 if (f->precious)
807 puts (_("# Precious file (prerequisite of .PRECIOUS)."));
808 if (f->phony)
809 puts (_("# Phony target (prerequisite of .PHONY)."));
810 if (f->cmd_target)
811 puts (_("# Command-line target."));
812 if (f->dontcare)
813 puts (_("# A default, MAKEFILES, or -include/sinclude makefile."));
814 puts (f->tried_implicit
815 ? _("# Implicit rule search has been done.")
816 : _("# Implicit rule search has not been done."));
817 if (f->stem != 0)
818 printf (_("# Implicit/static pattern stem: `%s'\n"), f->stem);
819 if (f->intermediate)
820 puts (_("# File is an intermediate prerequisite."));
821 if (f->also_make != 0)
823 fputs (_("# Also makes:"), stdout);
824 for (d = f->also_make; d != 0; d = d->next)
825 printf (" %s", dep_name (d));
826 putchar ('\n');
828 if (f->last_mtime == UNKNOWN_MTIME)
829 puts (_("# Modification time never checked."));
830 else if (f->last_mtime == NONEXISTENT_MTIME)
831 puts (_("# File does not exist."));
832 else if (f->last_mtime == OLD_MTIME)
833 puts (_("# File is very old."));
834 else
836 char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
837 file_timestamp_sprintf (buf, f->last_mtime);
838 printf (_("# Last modified %s\n"), buf);
840 puts (f->updated
841 ? _("# File has been updated.") : _("# File has not been updated."));
842 switch (f->command_state)
844 case cs_running:
845 puts (_("# Commands currently running (THIS IS A BUG)."));
846 break;
847 case cs_deps_running:
848 puts (_("# Dependencies commands running (THIS IS A BUG)."));
849 break;
850 case cs_not_started:
851 case cs_finished:
852 switch (f->update_status)
854 case -1:
855 break;
856 case 0:
857 puts (_("# Successfully updated."));
858 break;
859 case 1:
860 assert (question_flag);
861 puts (_("# Needs to be updated (-q is set)."));
862 break;
863 case 2:
864 puts (_("# Failed to be updated."));
865 break;
866 default:
867 puts (_("# Invalid value in `update_status' member!"));
868 fflush (stdout);
869 fflush (stderr);
870 abort ();
872 break;
873 default:
874 puts (_("# Invalid value in `command_state' member!"));
875 fflush (stdout);
876 fflush (stderr);
877 abort ();
880 if (f->variables != 0)
881 print_file_variables (f);
883 if (f->cmds != 0)
884 print_commands (f->cmds);
886 if (f->prev)
887 print_file ((const void *) f->prev);
890 void
891 print_file_data_base (void)
893 puts (_("\n# Files"));
895 hash_map (&files, print_file);
897 fputs (_("\n# files hash-table stats:\n# "), stdout);
898 hash_print_stats (&files, stdout);
901 #define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500)
903 char *
904 build_target_list (char *value)
906 static unsigned long last_targ_count = 0;
908 if (files.ht_fill != last_targ_count)
910 unsigned long max = EXPANSION_INCREMENT (strlen (value));
911 unsigned long len;
912 char *p;
913 struct file **fp = (struct file **) files.ht_vec;
914 struct file **end = &fp[files.ht_size];
916 /* Make sure we have at least MAX bytes in the allocated buffer. */
917 value = xrealloc (value, max);
919 p = value;
920 len = 0;
921 for (; fp < end; ++fp)
922 if (!HASH_VACANT (*fp) && (*fp)->is_target)
924 struct file *f = *fp;
925 int l = strlen (f->name);
927 len += l + 1;
928 if (len > max)
930 unsigned long off = p - value;
932 max += EXPANSION_INCREMENT (l + 1);
933 value = xrealloc (value, max);
934 p = &value[off];
937 bcopy (f->name, p, l);
938 p += l;
939 *(p++) = ' ';
941 *(p-1) = '\0';
943 last_targ_count = files.ht_fill;
946 return value;
949 void
950 init_hash_files (void)
952 hash_init (&files, 1000, file_hash_1, file_hash_2, file_hash_cmp);
955 /* EOF */