VirtualBox

source: kBuild/vendor/gnumake/2005-05-16/file.c@ 1989

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

Current make snaphot, 2005-05-16.

  • Property svn:eol-style set to native
File size: 25.5 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 f = lookup_file (".NOTPARALLEL");
653 if (f != 0 && f->is_target)
654 not_parallel = 1;
655
656 /* Remember that we've done this. */
657 snapped_deps = 1;
658}
659
660
661/* Set the `command_state' member of FILE and all its `also_make's. */
662
663void
664set_command_state (struct file *file, enum cmd_state state)
665{
666 struct dep *d;
667
668 file->command_state = state;
669
670 for (d = file->also_make; d != 0; d = d->next)
671 d->file->command_state = state;
672}
673
674
675/* Convert an external file timestamp to internal form. */
676
677FILE_TIMESTAMP
678file_timestamp_cons (const char *fname, time_t s, int ns)
679{
680 int offset = ORDINARY_MTIME_MIN + (FILE_TIMESTAMP_HI_RES ? ns : 0);
681 FILE_TIMESTAMP product = (FILE_TIMESTAMP) s << FILE_TIMESTAMP_LO_BITS;
682 FILE_TIMESTAMP ts = product + offset;
683
684 if (! (s <= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX)
685 && product <= ts && ts <= ORDINARY_MTIME_MAX))
686 {
687 char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
688 ts = s <= OLD_MTIME ? ORDINARY_MTIME_MIN : ORDINARY_MTIME_MAX;
689 file_timestamp_sprintf (buf, ts);
690 error (NILF, _("%s: Timestamp out of range; substituting %s"),
691 fname ? fname : _("Current time"), buf);
692 }
693
694 return ts;
695}
696
697
698/* Return the current time as a file timestamp, setting *RESOLUTION to
699 its resolution. */
700FILE_TIMESTAMP
701file_timestamp_now (int *resolution)
702{
703 int r;
704 time_t s;
705 int ns;
706
707 /* Don't bother with high-resolution clocks if file timestamps have
708 only one-second resolution. The code below should work, but it's
709 not worth the hassle of debugging it on hosts where it fails. */
710#if FILE_TIMESTAMP_HI_RES
711# if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME
712 {
713 struct timespec timespec;
714 if (clock_gettime (CLOCK_REALTIME, &timespec) == 0)
715 {
716 r = 1;
717 s = timespec.tv_sec;
718 ns = timespec.tv_nsec;
719 goto got_time;
720 }
721 }
722# endif
723# if HAVE_GETTIMEOFDAY
724 {
725 struct timeval timeval;
726 if (gettimeofday (&timeval, 0) == 0)
727 {
728 r = 1000;
729 s = timeval.tv_sec;
730 ns = timeval.tv_usec * 1000;
731 goto got_time;
732 }
733 }
734# endif
735#endif
736
737 r = 1000000000;
738 s = time ((time_t *) 0);
739 ns = 0;
740
741#if FILE_TIMESTAMP_HI_RES
742 got_time:
743#endif
744 *resolution = r;
745 return file_timestamp_cons (0, s, ns);
746}
747
748/* Place into the buffer P a printable representation of the file
749 timestamp TS. */
750void
751file_timestamp_sprintf (char *p, FILE_TIMESTAMP ts)
752{
753 time_t t = FILE_TIMESTAMP_S (ts);
754 struct tm *tm = localtime (&t);
755
756 if (tm)
757 sprintf (p, "%04d-%02d-%02d %02d:%02d:%02d",
758 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
759 tm->tm_hour, tm->tm_min, tm->tm_sec);
760 else if (t < 0)
761 sprintf (p, "%ld", (long) t);
762 else
763 sprintf (p, "%lu", (unsigned long) t);
764 p += strlen (p);
765
766 /* Append nanoseconds as a fraction, but remove trailing zeros.
767 We don't know the actual timestamp resolution, since clock_getres
768 applies only to local times, whereas this timestamp might come
769 from a remote filesystem. So removing trailing zeros is the
770 best guess that we can do. */
771 sprintf (p, ".%09d", FILE_TIMESTAMP_NS (ts));
772 p += strlen (p) - 1;
773 while (*p == '0')
774 p--;
775 p += *p != '.';
776
777 *p = '\0';
778}
779
780
781/* Print the data base of files. */
782
783static void
784print_file (const void *item)
785{
786 struct file *f = (struct file *) item;
787 struct dep *d;
788 struct dep *ood = 0;
789
790 putchar ('\n');
791 if (!f->is_target)
792 puts (_("# Not a target:"));
793 printf ("%s:%s", f->name, f->double_colon ? ":" : "");
794
795 /* Print all normal dependencies; note any order-only deps. */
796 for (d = f->deps; d != 0; d = d->next)
797 if (! d->ignore_mtime)
798 printf (" %s", dep_name (d));
799 else if (! ood)
800 ood = d;
801
802 /* Print order-only deps, if we have any. */
803 if (ood)
804 {
805 printf (" | %s", dep_name (ood));
806 for (d = ood->next; d != 0; d = d->next)
807 if (d->ignore_mtime)
808 printf (" %s", dep_name (d));
809 }
810
811 putchar ('\n');
812
813 if (f->precious)
814 puts (_("# Precious file (prerequisite of .PRECIOUS)."));
815 if (f->phony)
816 puts (_("# Phony target (prerequisite of .PHONY)."));
817 if (f->cmd_target)
818 puts (_("# Command-line target."));
819 if (f->dontcare)
820 puts (_("# A default, MAKEFILES, or -include/sinclude makefile."));
821 puts (f->tried_implicit
822 ? _("# Implicit rule search has been done.")
823 : _("# Implicit rule search has not been done."));
824 if (f->stem != 0)
825 printf (_("# Implicit/static pattern stem: `%s'\n"), f->stem);
826 if (f->intermediate)
827 puts (_("# File is an intermediate prerequisite."));
828 if (f->also_make != 0)
829 {
830 fputs (_("# Also makes:"), stdout);
831 for (d = f->also_make; d != 0; d = d->next)
832 printf (" %s", dep_name (d));
833 putchar ('\n');
834 }
835 if (f->last_mtime == UNKNOWN_MTIME)
836 puts (_("# Modification time never checked."));
837 else if (f->last_mtime == NONEXISTENT_MTIME)
838 puts (_("# File does not exist."));
839 else if (f->last_mtime == OLD_MTIME)
840 puts (_("# File is very old."));
841 else
842 {
843 char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
844 file_timestamp_sprintf (buf, f->last_mtime);
845 printf (_("# Last modified %s\n"), buf);
846 }
847 puts (f->updated
848 ? _("# File has been updated.") : _("# File has not been updated."));
849 switch (f->command_state)
850 {
851 case cs_running:
852 puts (_("# Commands currently running (THIS IS A BUG)."));
853 break;
854 case cs_deps_running:
855 puts (_("# Dependencies commands running (THIS IS A BUG)."));
856 break;
857 case cs_not_started:
858 case cs_finished:
859 switch (f->update_status)
860 {
861 case -1:
862 break;
863 case 0:
864 puts (_("# Successfully updated."));
865 break;
866 case 1:
867 assert (question_flag);
868 puts (_("# Needs to be updated (-q is set)."));
869 break;
870 case 2:
871 puts (_("# Failed to be updated."));
872 break;
873 default:
874 puts (_("# Invalid value in `update_status' member!"));
875 fflush (stdout);
876 fflush (stderr);
877 abort ();
878 }
879 break;
880 default:
881 puts (_("# Invalid value in `command_state' member!"));
882 fflush (stdout);
883 fflush (stderr);
884 abort ();
885 }
886
887 if (f->variables != 0)
888 print_file_variables (f);
889
890 if (f->cmds != 0)
891 print_commands (f->cmds);
892
893 if (f->prev)
894 print_file ((const void *) f->prev);
895}
896
897void
898print_file_data_base (void)
899{
900 puts (_("\n# Files"));
901
902 hash_map (&files, print_file);
903
904 fputs (_("\n# files hash-table stats:\n# "), stdout);
905 hash_print_stats (&files, stdout);
906}
907
908#define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500)
909
910char *
911build_target_list (char *value)
912{
913 static unsigned long last_targ_count = 0;
914
915 if (files.ht_fill != last_targ_count)
916 {
917 unsigned long max = EXPANSION_INCREMENT (strlen (value));
918 unsigned long len;
919 char *p;
920 struct file **fp = (struct file **) files.ht_vec;
921 struct file **end = &fp[files.ht_size];
922
923 /* Make sure we have at least MAX bytes in the allocated buffer. */
924 value = xrealloc (value, max);
925
926 p = value;
927 len = 0;
928 for (; fp < end; ++fp)
929 if (!HASH_VACANT (*fp) && (*fp)->is_target)
930 {
931 struct file *f = *fp;
932 int l = strlen (f->name);
933
934 len += l + 1;
935 if (len > max)
936 {
937 unsigned long off = p - value;
938
939 max += EXPANSION_INCREMENT (l + 1);
940 value = xrealloc (value, max);
941 p = &value[off];
942 }
943
944 bcopy (f->name, p, l);
945 p += l;
946 *(p++) = ' ';
947 }
948 *(p-1) = '\0';
949
950 last_targ_count = files.ht_fill;
951 }
952
953 return value;
954}
955
956void
957init_hash_files (void)
958{
959 hash_init (&files, 1000, file_hash_1, file_hash_2, file_hash_cmp);
960}
961
962/* 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