VirtualBox

source: kBuild/trunk/src/gmake/file.c@ 287

Last change on this file since 287 was 287, checked in by bird, 20 years ago

join + optimizations.

  • Property svn:eol-style set to native
File size: 25.8 KB
Line 
1/* Target file hash table management for GNU Make.
2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
32002 Free Software Foundation, Inc.
4This file is part of GNU Make.
5
6GNU Make is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Make is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Make; see the file COPYING. If not, write to
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21#include "make.h"
22
23#include <assert.h>
24
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"
32
33
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. */
41int snapped_deps = 0;
42
43/* Hash table of files the makefile knows how to make. */
44
45static unsigned long
46file_hash_1 (const void *key)
47{
48 return_ISTRING_HASH_1 (((struct file const *) key)->hname);
49}
50
51static unsigned long
52file_hash_2 (const void *key)
53{
54 return_ISTRING_HASH_2 (((struct file const *) key)->hname);
55}
56
57static int
58file_hash_cmp (const void *x, const void *y)
59{
60 return_ISTRING_COMPARE (((struct file const *) x)->hname,
61 ((struct file const *) y)->hname);
62}
63
64#ifndef FILE_BUCKETS
65#define FILE_BUCKETS 1007
66#endif
67static struct hash_table files;
68
69/* Whether or not .SECONDARY with no prerequisites was given. */
70static int all_secondary = 0;
71
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. */
76
77struct file *
78lookup_file (char *name)
79{
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
85
86 assert (*name != '\0');
87
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
93 {
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;
100 }
101# endif
102
103 while (name[0] == '[' && name[1] == ']' && name[2] != '\0')
104 name += 2;
105#endif
106 while (name[0] == '.' && name[1] == '/' && name[2] != '\0')
107 {
108 name += 2;
109 while (*name == '/')
110 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
111 ++name;
112 }
113
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 */
125
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;
132}
133
134struct file *
135enter_file (char *name)
136{
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
144
145 assert (*name != '\0');
146
147#if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
148 {
149 register char *n;
150 lname = (char *) malloc (strlen (name) + 1);
151 for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
152 {
153 if (isupper ((unsigned char)*n))
154 *ln = tolower ((unsigned char)*n);
155 else
156 *ln = *n;
157 }
158
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;
163 }
164#endif
165
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)
170 {
171#if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
172 free(lname);
173#endif
174 return f;
175 }
176
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;
181
182 if (HASH_VACANT (f))
183 hash_insert_at (&files, new, file_slot);
184 else
185 {
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;
191 }
192
193 return new;
194}
195
196
197/* Rename FILE to NAME. This is not as simple as resetting
198 the `name' member, since it must be put in a new hash bucket,
199 and possibly merged with an existing file called NAME. */
200
201void
202rename_file (struct file *from_file, char *to_hname)
203{
204 rehash_file (from_file, to_hname);
205 while (from_file)
206 {
207 from_file->name = from_file->hname;
208 from_file = from_file->prev;
209 }
210}
211
212/* Rehash FILE to NAME. This is not as simple as resetting
213 the `hname' member, since it must be put in a new hash bucket,
214 and possibly merged with an existing file called NAME. */
215
216void
217rehash_file (struct file *from_file, char *to_hname)
218{
219 struct file file_key;
220 struct file **file_slot;
221 struct file *to_file;
222 struct file *deleted_file;
223 struct file *f;
224
225 file_key.hname = to_hname;
226 if (0 == file_hash_cmp (from_file, &file_key))
227 return;
228
229 file_key.hname = from_file->hname;
230 while (from_file->renamed != 0)
231 from_file = from_file->renamed;
232 if (file_hash_cmp (from_file, &file_key))
233 /* hname changed unexpectedly */
234 abort ();
235
236 deleted_file = hash_delete (&files, from_file);
237 if (deleted_file != from_file)
238 /* from_file isn't the one stored in files */
239 abort ();
240
241 file_key.hname = to_hname;
242 file_slot = (struct file **) hash_find_slot (&files, &file_key);
243 to_file = *file_slot;
244
245 from_file->hname = to_hname;
246 for (f = from_file->double_colon; f != 0; f = f->prev)
247 f->hname = to_hname;
248
249 if (HASH_VACANT (to_file))
250 hash_insert_at (&files, from_file, file_slot);
251 else
252 {
253 /* TO_FILE already exists under TO_HNAME.
254 We must retain TO_FILE and merge FROM_FILE into it. */
255
256 if (from_file->cmds != 0)
257 {
258 if (to_file->cmds == 0)
259 to_file->cmds = from_file->cmds;
260 else if (from_file->cmds != to_file->cmds)
261 {
262 /* We have two sets of commands. We will go with the
263 one given in the rule explicitly mentioning this name,
264 but give a message to let the user know what's going on. */
265 if (to_file->cmds->fileinfo.filenm != 0)
266 error (&from_file->cmds->fileinfo,
267 _("Commands were specified for file `%s' at %s:%lu,"),
268 from_file->name, to_file->cmds->fileinfo.filenm,
269 to_file->cmds->fileinfo.lineno);
270 else
271 error (&from_file->cmds->fileinfo,
272 _("Commands for file `%s' were found by implicit rule search,"),
273 from_file->name);
274 error (&from_file->cmds->fileinfo,
275 _("but `%s' is now considered the same file as `%s'."),
276 from_file->name, to_hname);
277 error (&from_file->cmds->fileinfo,
278 _("Commands for `%s' will be ignored in favor of those for `%s'."),
279 to_hname, from_file->name);
280 }
281 }
282
283 /* Merge the dependencies of the two files. */
284
285 if (to_file->deps == 0)
286 to_file->deps = from_file->deps;
287 else
288 {
289 register struct dep *deps = to_file->deps;
290 while (deps->next != 0)
291 deps = deps->next;
292 deps->next = from_file->deps;
293 }
294
295 merge_variable_set_lists (&to_file->variables, from_file->variables);
296
297 if (to_file->double_colon && from_file->is_target && !from_file->double_colon)
298 fatal (NILF, _("can't rename single-colon `%s' to double-colon `%s'"),
299 from_file->name, to_hname);
300 if (!to_file->double_colon && from_file->double_colon)
301 {
302 if (to_file->is_target)
303 fatal (NILF, _("can't rename double-colon `%s' to single-colon `%s'"),
304 from_file->name, to_hname);
305 else
306 to_file->double_colon = from_file->double_colon;
307 }
308
309 if (from_file->last_mtime > to_file->last_mtime)
310 /* %%% Kludge so -W wins on a file that gets vpathized. */
311 to_file->last_mtime = from_file->last_mtime;
312
313 to_file->mtime_before_update = from_file->mtime_before_update;
314
315#define MERGE(field) to_file->field |= from_file->field
316 MERGE (precious);
317 MERGE (tried_implicit);
318 MERGE (updating);
319 MERGE (updated);
320 MERGE (is_target);
321 MERGE (cmd_target);
322 MERGE (phony);
323 MERGE (ignore_vpath);
324#undef MERGE
325
326 from_file->renamed = to_file;
327 }
328}
329
330
331/* Remove all nonprecious intermediate files.
332 If SIG is nonzero, this was caused by a fatal signal,
333 meaning that a different message will be printed, and
334 the message will go to stderr rather than stdout. */
335
336void
337remove_intermediates (int sig)
338{
339 register struct file **file_slot;
340 register struct file **file_end;
341 int doneany = 0;
342
343 /* If there's no way we will ever remove anything anyway, punt early. */
344 if (question_flag || touch_flag || all_secondary)
345 return;
346
347 if (sig && just_print_flag)
348 return;
349
350 file_slot = (struct file **) files.ht_vec;
351 file_end = file_slot + files.ht_size;
352 for ( ; file_slot < file_end; file_slot++)
353 if (! HASH_VACANT (*file_slot))
354 {
355 register struct file *f = *file_slot;
356 /* Is this file eligible for automatic deletion?
357 Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
358 given on the command-line, and it's either a -include makefile or
359 it's not precious. */
360 if (f->intermediate && (f->dontcare || !f->precious)
361 && !f->secondary && !f->cmd_target)
362 {
363 int status;
364 if (f->update_status == -1)
365 /* If nothing would have created this file yet,
366 don't print an "rm" command for it. */
367 continue;
368 if (just_print_flag)
369 status = 0;
370 else
371 {
372 status = unlink (f->name);
373 if (status < 0 && errno == ENOENT)
374 continue;
375 }
376 if (!f->dontcare)
377 {
378 if (sig)
379 error (NILF, _("*** Deleting intermediate file `%s'"), f->name);
380 else
381 {
382 if (! doneany)
383 DB (DB_BASIC, (_("Removing intermediate files...\n")));
384 if (!silent_flag)
385 {
386 if (! doneany)
387 {
388 fputs ("rm ", stdout);
389 doneany = 1;
390 }
391 else
392 putchar (' ');
393 fputs (f->name, stdout);
394 fflush (stdout);
395 }
396 }
397 if (status < 0)
398 perror_with_name ("unlink: ", f->name);
399 }
400 }
401 }
402
403 if (doneany && !sig)
404 {
405 putchar ('\n');
406 fflush (stdout);
407 }
408}
409
410
411/* Set the intermediate flag. */
412
413static void
414set_intermediate (const void *item)
415{
416 struct file *f = (struct file *) item;
417 f->intermediate = 1;
418}
419
420/* Expand and parse each dependency line. */
421static void
422expand_deps (struct file *f)
423{
424 struct dep *d, *d1;
425 struct dep *new = 0;
426 struct dep *old = f->deps;
427 unsigned int last_dep_has_cmds = f->updating;
428 int initialized = 0;
429
430 f->updating = 0;
431 f->deps = 0;
432
433 for (d = old; d != 0; d = d->next)
434 {
435 if (d->name != 0)
436 {
437 char *p;
438
439 /* If we need a second expansion on these, set up the file
440 variables, etc. It takes a lot of extra memory and processing
441 to do this, so only do it if it's needed. */
442 if (! d->need_2nd_expansion)
443 p = d->name;
444 else
445 {
446 /* We are going to do second expansion so initialize file
447 variables for the file. */
448 if (!initialized)
449 {
450 initialize_file_variables (f, 0);
451 initialized = 1;
452 }
453
454 set_file_variables (f);
455
456 p = variable_expand_for_file (d->name, f);
457 }
458
459 /* Parse the dependencies. */
460 new = (struct dep *)
461 multi_glob (
462 parse_file_seq (&p, '|', sizeof (struct dep), 1),
463 sizeof (struct dep));
464
465 if (*p)
466 {
467 /* Files that follow '|' are special prerequisites that
468 need only exist in order to satisfy the dependency.
469 Their modification times are irrelevant. */
470 struct dep **d_ptr;
471
472 for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)
473 ;
474 ++p;
475
476 *d_ptr = (struct dep *)
477 multi_glob (
478 parse_file_seq (&p, '\0', sizeof (struct dep), 1),
479 sizeof (struct dep));
480
481 for (d1 = *d_ptr; d1 != 0; d1 = d1->next)
482 d1->ignore_mtime = 1;
483 }
484
485 /* Enter them as files. */
486 for (d1 = new; d1 != 0; d1 = d1->next)
487 {
488 d1->file = lookup_file (d1->name);
489 if (d1->file == 0)
490 d1->file = enter_file (d1->name);
491 else
492 free (d1->name);
493 d1->name = 0;
494 d1->need_2nd_expansion = 0;
495 }
496
497 /* Add newly parsed deps to f->deps. If this is the last
498 dependency line and this target has commands then put
499 it in front so the last dependency line (the one with
500 commands) ends up being the first. This is important
501 because people expect $< to hold first prerequisite
502 from the rule with commands. If it is not the last
503 dependency line or the rule does not have commands
504 then link it at the end so it appears in makefile
505 order. */
506
507 if (new != 0)
508 {
509 if (d->next == 0 && last_dep_has_cmds)
510 {
511 struct dep **d_ptr;
512 for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)
513 ;
514
515 *d_ptr = f->deps;
516 f->deps = new;
517 }
518 else
519 {
520 struct dep **d_ptr;
521 for (d_ptr = &f->deps; *d_ptr; d_ptr = &(*d_ptr)->next)
522 ;
523
524 *d_ptr = new;
525 }
526 }
527 }
528 }
529
530 free_ns_chain ((struct nameseq *) old);
531}
532
533/* For each dependency of each file, make the `struct dep' point
534 at the appropriate `struct file' (which may have to be created).
535
536 Also mark the files depended on by .PRECIOUS, .PHONY, .SILENT,
537 and various other special targets. */
538
539void
540snap_deps (void)
541{
542 struct file *f;
543 struct file *f2;
544 struct dep *d;
545 struct file **file_slot_0;
546 struct file **file_slot;
547 struct file **file_end;
548
549 /* Perform second expansion and enter each dependency
550 name as a file. */
551
552 /* Expand .SUFFIXES first; it's dependencies are used for
553 $$* calculation. */
554 for (f = lookup_file (".SUFFIXES"); f != 0; f = f->prev)
555 expand_deps (f);
556
557 /* We must use hash_dump (), because within this loop
558 we might add new files to the table, possibly causing
559 an in-situ table expansion. */
560 file_slot_0 = (struct file **) hash_dump (&files, 0, 0);
561 file_end = file_slot_0 + files.ht_fill;
562 for (file_slot = file_slot_0; file_slot < file_end; file_slot++)
563 for (f = *file_slot; f != 0; f = f->prev)
564 {
565 if (strcmp (f->name, ".SUFFIXES") != 0)
566 expand_deps (f);
567 }
568 free (file_slot_0);
569
570 for (f = lookup_file (".PRECIOUS"); f != 0; f = f->prev)
571 for (d = f->deps; d != 0; d = d->next)
572 for (f2 = d->file; f2 != 0; f2 = f2->prev)
573 f2->precious = 1;
574
575 for (f = lookup_file (".LOW_RESOLUTION_TIME"); f != 0; f = f->prev)
576 for (d = f->deps; d != 0; d = d->next)
577 for (f2 = d->file; f2 != 0; f2 = f2->prev)
578 f2->low_resolution_time = 1;
579
580 for (f = lookup_file (".PHONY"); f != 0; f = f->prev)
581 for (d = f->deps; d != 0; d = d->next)
582 for (f2 = d->file; f2 != 0; f2 = f2->prev)
583 {
584 /* Mark this file as phony nonexistent target. */
585 f2->phony = 1;
586 f2->is_target = 1;
587 f2->last_mtime = NONEXISTENT_MTIME;
588 f2->mtime_before_update = NONEXISTENT_MTIME;
589 }
590
591 for (f = lookup_file (".INTERMEDIATE"); f != 0; f = f->prev)
592 {
593 /* .INTERMEDIATE with deps listed
594 marks those deps as intermediate files. */
595 for (d = f->deps; d != 0; d = d->next)
596 for (f2 = d->file; f2 != 0; f2 = f2->prev)
597 f2->intermediate = 1;
598 /* .INTERMEDIATE with no deps does nothing.
599 Marking all files as intermediates is useless
600 since the goal targets would be deleted after they are built. */
601 }
602
603 for (f = lookup_file (".SECONDARY"); f != 0; f = f->prev)
604 {
605 /* .SECONDARY with deps listed
606 marks those deps as intermediate files
607 in that they don't get rebuilt if not actually needed;
608 but unlike real intermediate files,
609 these are not deleted after make finishes. */
610 if (f->deps)
611 for (d = f->deps; d != 0; d = d->next)
612 for (f2 = d->file; f2 != 0; f2 = f2->prev)
613 f2->intermediate = f2->secondary = 1;
614 /* .SECONDARY with no deps listed marks *all* files that way. */
615 else
616 {
617 all_secondary = 1;
618 hash_map (&files, set_intermediate);
619 }
620 }
621
622 f = lookup_file (".EXPORT_ALL_VARIABLES");
623 if (f != 0 && f->is_target)
624 export_all_variables = 1;
625
626 f = lookup_file (".IGNORE");
627 if (f != 0 && f->is_target)
628 {
629 if (f->deps == 0)
630 ignore_errors_flag = 1;
631 else
632 for (d = f->deps; d != 0; d = d->next)
633 for (f2 = d->file; f2 != 0; f2 = f2->prev)
634 f2->command_flags |= COMMANDS_NOERROR;
635 }
636
637 f = lookup_file (".SILENT");
638 if (f != 0 && f->is_target)
639 {
640 if (f->deps == 0)
641 silent_flag = 1;
642 else
643 for (d = f->deps; d != 0; d = d->next)
644 for (f2 = d->file; f2 != 0; f2 = f2->prev)
645 f2->command_flags |= COMMANDS_SILENT;
646 }
647
648 f = lookup_file (".POSIX");
649 if (f != 0 && f->is_target)
650 posix_pedantic = 1;
651
652 /* kmk changed */
653 f = lookup_file (".NOTPARALLEL");
654 if (f != 0 && f->is_target)
655 {
656 if (f->deps == 0)
657 {
658 DB (DB_KMK, (_("not_parallel -1\n")));
659 not_parallel = -1;
660 }
661 else
662 for (d = f->deps; d != 0; d = d->next)
663 for (f2 = d->file; f2 != 0; f2 = f2->prev)
664 f2->command_flags |= COMMANDS_NOTPARALLEL;
665 }
666
667 /* Remember that we've done this. */
668 snapped_deps = 1;
669}
670
671
672/* Set the `command_state' member of FILE and all its `also_make's. */
673
674void
675set_command_state (struct file *file, enum cmd_state state)
676{
677 struct dep *d;
678
679 file->command_state = state;
680
681 for (d = file->also_make; d != 0; d = d->next)
682 d->file->command_state = state;
683}
684
685
686/* Convert an external file timestamp to internal form. */
687
688FILE_TIMESTAMP
689file_timestamp_cons (const char *fname, time_t s, int ns)
690{
691 int offset = ORDINARY_MTIME_MIN + (FILE_TIMESTAMP_HI_RES ? ns : 0);
692 FILE_TIMESTAMP product = (FILE_TIMESTAMP) s << FILE_TIMESTAMP_LO_BITS;
693 FILE_TIMESTAMP ts = product + offset;
694
695 if (! (s <= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX)
696 && product <= ts && ts <= ORDINARY_MTIME_MAX))
697 {
698 char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
699 ts = s <= OLD_MTIME ? ORDINARY_MTIME_MIN : ORDINARY_MTIME_MAX;
700 file_timestamp_sprintf (buf, ts);
701 error (NILF, _("%s: Timestamp out of range; substituting %s"),
702 fname ? fname : _("Current time"), buf);
703 }
704
705 return ts;
706}
707
708
709/* Return the current time as a file timestamp, setting *RESOLUTION to
710 its resolution. */
711FILE_TIMESTAMP
712file_timestamp_now (int *resolution)
713{
714 int r;
715 time_t s;
716 int ns;
717
718 /* Don't bother with high-resolution clocks if file timestamps have
719 only one-second resolution. The code below should work, but it's
720 not worth the hassle of debugging it on hosts where it fails. */
721#if FILE_TIMESTAMP_HI_RES
722# if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME
723 {
724 struct timespec timespec;
725 if (clock_gettime (CLOCK_REALTIME, &timespec) == 0)
726 {
727 r = 1;
728 s = timespec.tv_sec;
729 ns = timespec.tv_nsec;
730 goto got_time;
731 }
732 }
733# endif
734# if HAVE_GETTIMEOFDAY
735 {
736 struct timeval timeval;
737 if (gettimeofday (&timeval, 0) == 0)
738 {
739 r = 1000;
740 s = timeval.tv_sec;
741 ns = timeval.tv_usec * 1000;
742 goto got_time;
743 }
744 }
745# endif
746#endif
747
748 r = 1000000000;
749 s = time ((time_t *) 0);
750 ns = 0;
751
752#if FILE_TIMESTAMP_HI_RES
753 got_time:
754#endif
755 *resolution = r;
756 return file_timestamp_cons (0, s, ns);
757}
758
759/* Place into the buffer P a printable representation of the file
760 timestamp TS. */
761void
762file_timestamp_sprintf (char *p, FILE_TIMESTAMP ts)
763{
764 time_t t = FILE_TIMESTAMP_S (ts);
765 struct tm *tm = localtime (&t);
766
767 if (tm)
768 sprintf (p, "%04d-%02d-%02d %02d:%02d:%02d",
769 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
770 tm->tm_hour, tm->tm_min, tm->tm_sec);
771 else if (t < 0)
772 sprintf (p, "%ld", (long) t);
773 else
774 sprintf (p, "%lu", (unsigned long) t);
775 p += strlen (p);
776
777 /* Append nanoseconds as a fraction, but remove trailing zeros.
778 We don't know the actual timestamp resolution, since clock_getres
779 applies only to local times, whereas this timestamp might come
780 from a remote filesystem. So removing trailing zeros is the
781 best guess that we can do. */
782 sprintf (p, ".%09d", FILE_TIMESTAMP_NS (ts));
783 p += strlen (p) - 1;
784 while (*p == '0')
785 p--;
786 p += *p != '.';
787
788 *p = '\0';
789}
790
791
792/* Print the data base of files. */
793
794static void
795print_file (const void *item)
796{
797 struct file *f = (struct file *) item;
798 struct dep *d;
799 struct dep *ood = 0;
800
801 putchar ('\n');
802 if (!f->is_target)
803 puts (_("# Not a target:"));
804 printf ("%s:%s", f->name, f->double_colon ? ":" : "");
805
806 /* Print all normal dependencies; note any order-only deps. */
807 for (d = f->deps; d != 0; d = d->next)
808 if (! d->ignore_mtime)
809 printf (" %s", dep_name (d));
810 else if (! ood)
811 ood = d;
812
813 /* Print order-only deps, if we have any. */
814 if (ood)
815 {
816 printf (" | %s", dep_name (ood));
817 for (d = ood->next; d != 0; d = d->next)
818 if (d->ignore_mtime)
819 printf (" %s", dep_name (d));
820 }
821
822 putchar ('\n');
823
824 if (f->precious)
825 puts (_("# Precious file (prerequisite of .PRECIOUS)."));
826 if (f->phony)
827 puts (_("# Phony target (prerequisite of .PHONY)."));
828 if (f->cmd_target)
829 puts (_("# Command-line target."));
830 if (f->dontcare)
831 puts (_("# A default, MAKEFILES, or -include/sinclude makefile."));
832 puts (f->tried_implicit
833 ? _("# Implicit rule search has been done.")
834 : _("# Implicit rule search has not been done."));
835 if (f->stem != 0)
836 printf (_("# Implicit/static pattern stem: `%s'\n"), f->stem);
837 if (f->intermediate)
838 puts (_("# File is an intermediate prerequisite."));
839 if (f->also_make != 0)
840 {
841 fputs (_("# Also makes:"), stdout);
842 for (d = f->also_make; d != 0; d = d->next)
843 printf (" %s", dep_name (d));
844 putchar ('\n');
845 }
846 if (f->last_mtime == UNKNOWN_MTIME)
847 puts (_("# Modification time never checked."));
848 else if (f->last_mtime == NONEXISTENT_MTIME)
849 puts (_("# File does not exist."));
850 else if (f->last_mtime == OLD_MTIME)
851 puts (_("# File is very old."));
852 else
853 {
854 char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
855 file_timestamp_sprintf (buf, f->last_mtime);
856 printf (_("# Last modified %s\n"), buf);
857 }
858 puts (f->updated
859 ? _("# File has been updated.") : _("# File has not been updated."));
860 switch (f->command_state)
861 {
862 case cs_running:
863 puts (_("# Commands currently running (THIS IS A BUG)."));
864 break;
865 case cs_deps_running:
866 puts (_("# Dependencies commands running (THIS IS A BUG)."));
867 break;
868 case cs_not_started:
869 case cs_finished:
870 switch (f->update_status)
871 {
872 case -1:
873 break;
874 case 0:
875 puts (_("# Successfully updated."));
876 break;
877 case 1:
878 assert (question_flag);
879 puts (_("# Needs to be updated (-q is set)."));
880 break;
881 case 2:
882 puts (_("# Failed to be updated."));
883 break;
884 default:
885 puts (_("# Invalid value in `update_status' member!"));
886 fflush (stdout);
887 fflush (stderr);
888 abort ();
889 }
890 break;
891 default:
892 puts (_("# Invalid value in `command_state' member!"));
893 fflush (stdout);
894 fflush (stderr);
895 abort ();
896 }
897
898 if (f->variables != 0)
899 print_file_variables (f);
900
901 if (f->cmds != 0)
902 print_commands (f->cmds);
903
904 if (f->prev)
905 print_file ((const void *) f->prev);
906}
907
908void
909print_file_data_base (void)
910{
911 puts (_("\n# Files"));
912
913 hash_map (&files, print_file);
914
915 fputs (_("\n# files hash-table stats:\n# "), stdout);
916 hash_print_stats (&files, stdout);
917}
918
919#define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500)
920
921char *
922build_target_list (char *value)
923{
924 static unsigned long last_targ_count = 0;
925
926 if (files.ht_fill != last_targ_count)
927 {
928 unsigned long max = EXPANSION_INCREMENT (strlen (value));
929 unsigned long len;
930 char *p;
931 struct file **fp = (struct file **) files.ht_vec;
932 struct file **end = &fp[files.ht_size];
933
934 /* Make sure we have at least MAX bytes in the allocated buffer. */
935 value = xrealloc (value, max);
936
937 p = value;
938 len = 0;
939 for (; fp < end; ++fp)
940 if (!HASH_VACANT (*fp) && (*fp)->is_target)
941 {
942 struct file *f = *fp;
943 int l = strlen (f->name);
944
945 len += l + 1;
946 if (len > max)
947 {
948 unsigned long off = p - value;
949
950 max += EXPANSION_INCREMENT (l + 1);
951 value = xrealloc (value, max);
952 p = &value[off];
953 }
954
955 bcopy (f->name, p, l);
956 p += l;
957 *(p++) = ' ';
958 }
959 *(p-1) = '\0';
960
961 last_targ_count = files.ht_fill;
962 }
963
964 return value;
965}
966
967void
968init_hash_files (void)
969{
970 hash_init (&files, 1000, file_hash_1, file_hash_2, file_hash_cmp);
971}
972
973/* EOF */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette