1 /* Target file management for GNU Make.
2 Copyright (C) 1988-2012 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 <http://www.gnu.org/licenses/>. */
30 /* Remember whether snap_deps has been invoked: we need this to be sure we
31 don't add new rules (via $(eval ...)) afterwards. In the future it would
32 be nice to support this, but it means we'd need to re-run snap_deps() or
33 at least its functionality... it might mean changing snap_deps() to be run
34 per-file, so we can invoke it after the eval... or remembering which files
35 in the hash have been snapped (a new boolean flag?) and having snap_deps()
36 only work on files which have not yet been snapped. */
39 /* Hash table of files the makefile knows how to make. */
42 file_hash_1 (const void *key
)
44 return_ISTRING_HASH_1 (((struct file
const *) key
)->hname
);
48 file_hash_2 (const void *key
)
50 return_ISTRING_HASH_2 (((struct file
const *) key
)->hname
);
54 file_hash_cmp (const void *x
, const void *y
)
56 return_ISTRING_COMPARE (((struct file
const *) x
)->hname
,
57 ((struct file
const *) y
)->hname
);
61 #define FILE_BUCKETS 1007
63 static struct hash_table files
;
65 /* Whether or not .SECONDARY with no prerequisites was given. */
66 static int all_secondary
= 0;
68 /* Access the hash table of all file records.
69 lookup_file given a name, return the struct file * for that name,
70 or nil if there is none.
74 lookup_file (const char *name
)
78 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
82 assert (*name
!= '\0');
84 /* This is also done in parse_file_seq, so this is redundant
85 for names read from makefiles. It is here for names passed
86 on the command line. */
88 # ifndef WANT_CASE_SENSITIVE_TARGETS
93 lname
= xstrdup (name
);
94 for (n
= name
, ln
= lname
; *n
!= '\0'; ++n
, ++ln
)
95 *ln
= isupper ((unsigned char)*n
) ? tolower ((unsigned char)*n
) : *n
;
101 while (name
[0] == '[' && name
[1] == ']' && name
[2] != '\0')
104 while (name
[0] == '.'
105 #ifdef HAVE_DOS_PATHS
106 && (name
[1] == '/' || name
[1] == '\\')
114 #ifdef HAVE_DOS_PATHS
118 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
123 /* It was all slashes after a dot. */
126 #elif defined(_AMIGA)
132 file_key
.hname
= name
;
133 f
= hash_find_item (&files
, &file_key
);
134 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
142 /* Look up a file record for file NAME and return it.
143 Create a new record if one doesn't exist. NAME will be stored in the
144 new record so it should be constant or in the strcache etc.
148 enter_file (const char *name
)
152 struct file
**file_slot
;
153 struct file file_key
;
155 assert (*name
!= '\0');
156 assert (strcache_iscached (name
));
158 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
163 lname
= xstrdup (name
);
164 for (n
= name
, ln
= lname
; *n
!= '\0'; ++n
, ++ln
)
165 if (isupper ((unsigned char)*n
))
166 *ln
= tolower ((unsigned char)*n
);
171 name
= strcache_add (lname
);
176 file_key
.hname
= name
;
177 file_slot
= (struct file
**) hash_find_slot (&files
, &file_key
);
179 if (! HASH_VACANT (f
) && !f
->double_colon
)
182 new = xcalloc (sizeof (struct file
));
183 new->name
= new->hname
= name
;
184 new->update_status
= -1;
189 hash_insert_at (&files
, new, file_slot
);
193 /* There is already a double-colon entry for this file. */
194 new->double_colon
= f
;
202 /* Rehash FILE to NAME. This is not as simple as resetting
203 the 'hname' member, since it must be put in a new hash bucket,
204 and possibly merged with an existing file called NAME. */
207 rehash_file (struct file
*from_file
, const char *to_hname
)
209 struct file file_key
;
210 struct file
**file_slot
;
211 struct file
*to_file
;
212 struct file
*deleted_file
;
215 /* If it's already that name, we're done. */
216 file_key
.hname
= to_hname
;
217 if (! file_hash_cmp (from_file
, &file_key
))
220 /* Find the end of the renamed list for the "from" file. */
221 file_key
.hname
= from_file
->hname
;
222 while (from_file
->renamed
!= 0)
223 from_file
= from_file
->renamed
;
224 if (file_hash_cmp (from_file
, &file_key
))
225 /* hname changed unexpectedly!! */
228 /* Remove the "from" file from the hash. */
229 deleted_file
= hash_delete (&files
, from_file
);
230 if (deleted_file
!= from_file
)
231 /* from_file isn't the one stored in files */
234 /* Find where the newly renamed file will go in the hash. */
235 file_key
.hname
= to_hname
;
236 file_slot
= (struct file
**) hash_find_slot (&files
, &file_key
);
237 to_file
= *file_slot
;
239 /* Change the hash name for this file. */
240 from_file
->hname
= to_hname
;
241 for (f
= from_file
->double_colon
; f
!= 0; f
= f
->prev
)
244 /* If the new name doesn't exist yet just set it to the renamed file. */
245 if (HASH_VACANT (to_file
))
247 hash_insert_at (&files
, from_file
, file_slot
);
251 /* TO_FILE already exists under TO_HNAME.
252 We must retain TO_FILE and merge FROM_FILE into it. */
254 if (from_file
->cmds
!= 0)
256 if (to_file
->cmds
== 0)
257 to_file
->cmds
= from_file
->cmds
;
258 else if (from_file
->cmds
!= to_file
->cmds
)
260 /* We have two sets of commands. We will go with the
261 one given in the rule explicitly mentioning this name,
262 but give a message to let the user know what's going on. */
263 if (to_file
->cmds
->fileinfo
.filenm
!= 0)
264 error (&from_file
->cmds
->fileinfo
,
265 _("Recipe was specified for file '%s' at %s:%lu,"),
266 from_file
->name
, to_file
->cmds
->fileinfo
.filenm
,
267 to_file
->cmds
->fileinfo
.lineno
);
269 error (&from_file
->cmds
->fileinfo
,
270 _("Recipe for file '%s' was found by implicit rule search,"),
272 error (&from_file
->cmds
->fileinfo
,
273 _("but '%s' is now considered the same file as '%s'."),
274 from_file
->name
, to_hname
);
275 error (&from_file
->cmds
->fileinfo
,
276 _("Recipe for '%s' will be ignored in favor of the one for '%s'."),
277 to_hname
, from_file
->name
);
281 /* Merge the dependencies of the two files. */
283 if (to_file
->deps
== 0)
284 to_file
->deps
= from_file
->deps
;
287 struct dep
*deps
= to_file
->deps
;
288 while (deps
->next
!= 0)
290 deps
->next
= from_file
->deps
;
293 merge_variable_set_lists (&to_file
->variables
, from_file
->variables
);
295 if (to_file
->double_colon
&& from_file
->is_target
&& !from_file
->double_colon
)
296 fatal (NILF
, _("can't rename single-colon '%s' to double-colon '%s'"),
297 from_file
->name
, to_hname
);
298 if (!to_file
->double_colon
&& from_file
->double_colon
)
300 if (to_file
->is_target
)
301 fatal (NILF
, _("can't rename double-colon '%s' to single-colon '%s'"),
302 from_file
->name
, to_hname
);
304 to_file
->double_colon
= from_file
->double_colon
;
307 if (from_file
->last_mtime
> to_file
->last_mtime
)
308 /* %%% Kludge so -W wins on a file that gets vpathized. */
309 to_file
->last_mtime
= from_file
->last_mtime
;
311 to_file
->mtime_before_update
= from_file
->mtime_before_update
;
313 #define MERGE(field) to_file->field |= from_file->field
315 MERGE (tried_implicit
);
321 MERGE (ignore_vpath
);
324 from_file
->renamed
= to_file
;
327 /* Rename FILE to NAME. This is not as simple as resetting
328 the 'name' member, since it must be put in a new hash bucket,
329 and possibly merged with an existing file called NAME. */
332 rename_file (struct file
*from_file
, const char *to_hname
)
334 rehash_file (from_file
, to_hname
);
337 from_file
->name
= from_file
->hname
;
338 from_file
= from_file
->prev
;
342 /* Remove all nonprecious intermediate files.
343 If SIG is nonzero, this was caused by a fatal signal,
344 meaning that a different message will be printed, and
345 the message will go to stderr rather than stdout. */
348 remove_intermediates (int sig
)
350 struct file
**file_slot
;
351 struct file
**file_end
;
354 /* If there's no way we will ever remove anything anyway, punt early. */
355 if (question_flag
|| touch_flag
|| all_secondary
)
358 if (sig
&& just_print_flag
)
361 file_slot
= (struct file
**) files
.ht_vec
;
362 file_end
= file_slot
+ files
.ht_size
;
363 for ( ; file_slot
< file_end
; file_slot
++)
364 if (! HASH_VACANT (*file_slot
))
366 struct file
*f
= *file_slot
;
367 /* Is this file eligible for automatic deletion?
368 Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
369 given on the command line, and it's either a -include makefile or
370 it's not precious. */
371 if (f
->intermediate
&& (f
->dontcare
|| !f
->precious
)
372 && !f
->secondary
&& !f
->cmd_target
)
375 if (f
->update_status
== -1)
376 /* If nothing would have created this file yet,
377 don't print an "rm" command for it. */
383 status
= unlink (f
->name
);
384 if (status
< 0 && errno
== ENOENT
)
390 error (NILF
, _("*** Deleting intermediate file '%s'"), f
->name
);
394 DB (DB_BASIC
, (_("Removing intermediate files...\n")));
399 fputs ("rm ", stdout
);
404 fputs (f
->name
, stdout
);
409 perror_with_name ("unlink: ", f
->name
);
421 /* Given a string containing prerequisites (fully expanded), break it up into
422 a struct dep list. Enter each of these prereqs into the file database.
425 split_prereqs (char *p
)
427 struct dep
*new = PARSE_FILE_SEQ (&p
, struct dep
, '|', NULL
, 0);
431 /* Files that follow '|' are "order-only" prerequisites that satisfy the
432 dependency by existing: their modification times are irrelevant. */
436 ood
= PARSE_FILE_SEQ (&p
, struct dep
, '\0', NULL
, 0);
443 for (dp
= new; dp
->next
!= NULL
; dp
= dp
->next
)
448 for (; ood
!= NULL
; ood
= ood
->next
)
449 ood
->ignore_mtime
= 1;
455 /* Given a list of prerequisites, enter them into the file database.
456 If STEM is set then first expand patterns using STEM. */
458 enter_prereqs (struct dep
*deps
, const char *stem
)
465 /* If we have a stem, expand the %'s. We use patsubst_expand to translate
466 the prerequisites' patterns into plain prerequisite names. */
469 const char *pattern
= "%";
470 char *buffer
= variable_expand ("");
471 struct dep
*dp
= deps
, *dl
= 0;
476 int nl
= strlen (dp
->name
) + 1;
477 char *nm
= alloca (nl
);
478 memcpy (nm
, dp
->name
, nl
);
479 percent
= find_percent (nm
);
484 /* We have to handle empty stems specially, because that
485 would be equivalent to $(patsubst %,dp->name,) which
486 will always be empty. */
489 memmove (percent
, percent
+1, strlen (percent
));
490 o
= variable_buffer_output (buffer
, nm
, strlen (nm
) + 1);
493 o
= patsubst_expand_pat (buffer
, stem
, pattern
, nm
,
494 pattern
+1, percent
+1);
496 /* If the name expanded to the empty string, ignore it. */
497 if (buffer
[0] == '\0')
501 dp
= deps
= deps
->next
;
503 dp
= dl
->next
= dp
->next
;
509 dp
->name
= strcache_add_len (buffer
, o
- buffer
);
512 dp
->staticpattern
= 1;
518 /* Enter them as files, unless they need a 2nd expansion. */
519 for (d1
= deps
; d1
!= 0; d1
= d1
->next
)
521 if (d1
->need_2nd_expansion
)
524 d1
->file
= lookup_file (d1
->name
);
526 d1
->file
= enter_file (d1
->name
);
527 d1
->staticpattern
= 0;
534 /* Set the intermediate flag. */
537 set_intermediate (const void *item
)
539 struct file
*f
= (struct file
*) item
;
543 /* Expand and parse each dependency line. */
545 expand_deps (struct file
*f
)
549 const char *file_stem
= f
->stem
;
554 /* Walk through the dependencies. For any dependency that needs 2nd
555 expansion, expand it then insert the result into the list. */
561 struct dep
*new, *next
;
562 char *name
= (char *)d
->name
;
564 if (! d
->name
|| ! d
->need_2nd_expansion
)
566 /* This one is all set already. */
572 /* If it's from a static pattern rule, convert the patterns into
573 "$*" so they'll expand properly. */
574 if (d
->staticpattern
)
577 d
->name
= o
= variable_expand ("");
578 o
= subst_expand (o
, name
, "%", "$*", 1, 2, 0);
581 d
->name
= name
= xstrdup (d
->name
);
582 d
->staticpattern
= 0;
585 /* We're going to do second expansion so initialize file variables for
586 the file. Since the stem for static pattern rules comes from
587 individual dep lines, we will temporarily set f->stem to d->stem. */
590 initialize_file_variables (f
, 0);
597 set_file_variables (f
);
599 p
= variable_expand_for_file (d
->name
, f
);
604 /* At this point we don't need the name anymore: free it. */
607 /* Parse the prerequisites and enter them into the file database. */
608 new = enter_prereqs (split_prereqs (p
), d
->stem
);
610 /* If there were no prereqs here (blank!) then throw this one out. */
619 /* Add newly parsed prerequisites. */
622 for (dp
= &new->next
, d
= new->next
; d
!= 0; dp
= &d
->next
, d
= d
->next
)
629 /* Reset the updating flag. */
632 reset_updating (const void *item
)
634 struct file
*f
= (struct file
*) item
;
638 /* For each dependency of each file, make the 'struct dep' point
639 at the appropriate 'struct file' (which may have to be created).
641 Also mark the files depended on by .PRECIOUS, .PHONY, .SILENT,
642 and various other special targets. */
651 /* Remember that we've done this. Once we start snapping deps we can no
652 longer define new targets. */
655 /* Perform second expansion and enter each dependency name as a file. We
656 must use hash_dump() here because within these loops we likely add new
657 files to the table, possibly causing an in-situ table expansion.
659 We only need to do this if second_expansion has been defined; if it
660 hasn't then all deps were expanded as the makefile was read in. If we
661 ever change make to be able to unset .SECONDARY_EXPANSION this will have
664 if (second_expansion
)
666 struct file
**file_slot_0
= (struct file
**) hash_dump (&files
, 0, 0);
667 struct file
**file_end
= file_slot_0
+ files
.ht_fill
;
668 struct file
**file_slot
;
669 const char *suffixes
;
671 /* Expand .SUFFIXES: its prerequisites are used for $$* calc. */
672 f
= lookup_file (".SUFFIXES");
673 suffixes
= f
? f
->name
: 0;
674 for (; f
!= 0; f
= f
->prev
)
677 /* For every target that's not .SUFFIXES, expand its prerequisites. */
679 for (file_slot
= file_slot_0
; file_slot
< file_end
; file_slot
++)
680 for (f
= *file_slot
; f
!= 0; f
= f
->prev
)
681 if (f
->name
!= suffixes
)
686 /* We're not doing second expansion, so reset updating. */
687 hash_map (&files
, reset_updating
);
689 /* Now manage all the special targets. */
691 for (f
= lookup_file (".PRECIOUS"); f
!= 0; f
= f
->prev
)
692 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
693 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
696 for (f
= lookup_file (".LOW_RESOLUTION_TIME"); f
!= 0; f
= f
->prev
)
697 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
698 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
699 f2
->low_resolution_time
= 1;
701 for (f
= lookup_file (".PHONY"); f
!= 0; f
= f
->prev
)
702 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
703 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
705 /* Mark this file as phony nonexistent target. */
708 f2
->last_mtime
= NONEXISTENT_MTIME
;
709 f2
->mtime_before_update
= NONEXISTENT_MTIME
;
712 for (f
= lookup_file (".INTERMEDIATE"); f
!= 0; f
= f
->prev
)
713 /* Mark .INTERMEDIATE deps as intermediate files. */
714 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
715 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
716 f2
->intermediate
= 1;
717 /* .INTERMEDIATE with no deps does nothing.
718 Marking all files as intermediates is useless since the goal targets
719 would be deleted after they are built. */
721 for (f
= lookup_file (".SECONDARY"); f
!= 0; f
= f
->prev
)
722 /* Mark .SECONDARY deps as both intermediate and secondary. */
724 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
725 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
726 f2
->intermediate
= f2
->secondary
= 1;
727 /* .SECONDARY with no deps listed marks *all* files that way. */
731 hash_map (&files
, set_intermediate
);
734 f
= lookup_file (".EXPORT_ALL_VARIABLES");
735 if (f
!= 0 && f
->is_target
)
736 export_all_variables
= 1;
738 f
= lookup_file (".IGNORE");
739 if (f
!= 0 && f
->is_target
)
742 ignore_errors_flag
= 1;
744 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
745 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
746 f2
->command_flags
|= COMMANDS_NOERROR
;
749 f
= lookup_file (".SILENT");
750 if (f
!= 0 && f
->is_target
)
755 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
756 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
757 f2
->command_flags
|= COMMANDS_SILENT
;
760 f
= lookup_file (".NOTPARALLEL");
761 if (f
!= 0 && f
->is_target
)
764 #ifndef NO_MINUS_C_MINUS_O
765 /* If .POSIX was defined, remove OUTPUT_OPTION to comply. */
766 /* This needs more work: what if the user sets this in the makefile?
768 define_variable_cname ("OUTPUT_OPTION", "", o_default, 1);
773 /* Set the 'command_state' member of FILE and all its 'also_make's. */
776 set_command_state (struct file
*file
, enum cmd_state state
)
780 file
->command_state
= state
;
782 for (d
= file
->also_make
; d
!= 0; d
= d
->next
)
783 d
->file
->command_state
= state
;
786 /* Convert an external file timestamp to internal form. */
789 file_timestamp_cons (const char *fname
, time_t stamp
, long int ns
)
791 int offset
= ORDINARY_MTIME_MIN
+ (FILE_TIMESTAMP_HI_RES
? ns
: 0);
792 FILE_TIMESTAMP s
= stamp
;
793 FILE_TIMESTAMP product
= (FILE_TIMESTAMP
) s
<< FILE_TIMESTAMP_LO_BITS
;
794 FILE_TIMESTAMP ts
= product
+ offset
;
796 if (! (s
<= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX
)
797 && product
<= ts
&& ts
<= ORDINARY_MTIME_MAX
))
799 char buf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
800 ts
= s
<= OLD_MTIME
? ORDINARY_MTIME_MIN
: ORDINARY_MTIME_MAX
;
801 file_timestamp_sprintf (buf
, ts
);
802 error (NILF
, _("%s: Timestamp out of range; substituting %s"),
803 fname
? fname
: _("Current time"), buf
);
809 /* Return the current time as a file timestamp, setting *RESOLUTION to
812 file_timestamp_now (int *resolution
)
818 /* Don't bother with high-resolution clocks if file timestamps have
819 only one-second resolution. The code below should work, but it's
820 not worth the hassle of debugging it on hosts where it fails. */
821 #if FILE_TIMESTAMP_HI_RES
822 # if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME
824 struct timespec timespec
;
825 if (clock_gettime (CLOCK_REALTIME
, ×pec
) == 0)
829 ns
= timespec
.tv_nsec
;
834 # if HAVE_GETTIMEOFDAY
836 struct timeval timeval
;
837 if (gettimeofday (&timeval
, 0) == 0)
841 ns
= timeval
.tv_usec
* 1000;
849 s
= time ((time_t *) 0);
852 #if FILE_TIMESTAMP_HI_RES
856 return file_timestamp_cons (0, s
, ns
);
859 /* Place into the buffer P a printable representation of the file
862 file_timestamp_sprintf (char *p
, FILE_TIMESTAMP ts
)
864 time_t t
= FILE_TIMESTAMP_S (ts
);
865 struct tm
*tm
= localtime (&t
);
868 sprintf (p
, "%04d-%02d-%02d %02d:%02d:%02d",
869 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
870 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
872 sprintf (p
, "%ld", (long) t
);
874 sprintf (p
, "%lu", (unsigned long) t
);
877 /* Append nanoseconds as a fraction, but remove trailing zeros. We don't
878 know the actual timestamp resolution, since clock_getres applies only to
879 local times, whereas this timestamp might come from a remote filesystem.
880 So removing trailing zeros is the best guess that we can do. */
881 sprintf (p
, ".%09d", FILE_TIMESTAMP_NS (ts
));
890 /* Print the data base of files. */
893 print_prereqs (const struct dep
*deps
)
895 const struct dep
*ood
= 0;
897 /* Print all normal dependencies; note any order-only deps. */
898 for (; deps
!= 0; deps
= deps
->next
)
899 if (! deps
->ignore_mtime
)
900 printf (" %s", dep_name (deps
));
904 /* Print order-only deps, if we have any. */
907 printf (" | %s", dep_name (ood
));
908 for (ood
= ood
->next
; ood
!= 0; ood
= ood
->next
)
909 if (ood
->ignore_mtime
)
910 printf (" %s", dep_name (ood
));
917 print_file (const void *item
)
919 const struct file
*f
= item
;
923 if (f
->cmds
&& f
->cmds
->recipe_prefix
!= cmd_prefix
)
925 fputs (".RECIPEPREFIX = ", stdout
);
926 cmd_prefix
= f
->cmds
->recipe_prefix
;
927 if (cmd_prefix
!= RECIPEPREFIX_DEFAULT
)
928 putchar (cmd_prefix
);
932 if (f
->variables
!= 0)
933 print_target_variables (f
);
936 puts (_("# Not a target:"));
937 printf ("%s:%s", f
->name
, f
->double_colon
? ":" : "");
938 print_prereqs (f
->deps
);
941 puts (_("# Precious file (prerequisite of .PRECIOUS)."));
943 puts (_("# Phony target (prerequisite of .PHONY)."));
945 puts (_("# Command line target."));
947 puts (_("# A default, MAKEFILES, or -include/sinclude makefile."));
948 puts (f
->tried_implicit
949 ? _("# Implicit rule search has been done.")
950 : _("# Implicit rule search has not been done."));
952 printf (_("# Implicit/static pattern stem: '%s'\n"), f
->stem
);
954 puts (_("# File is an intermediate prerequisite."));
955 if (f
->also_make
!= 0)
958 fputs (_("# Also makes:"), stdout
);
959 for (d
= f
->also_make
; d
!= 0; d
= d
->next
)
960 printf (" %s", dep_name (d
));
963 if (f
->last_mtime
== UNKNOWN_MTIME
)
964 puts (_("# Modification time never checked."));
965 else if (f
->last_mtime
== NONEXISTENT_MTIME
)
966 puts (_("# File does not exist."));
967 else if (f
->last_mtime
== OLD_MTIME
)
968 puts (_("# File is very old."));
971 char buf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
972 file_timestamp_sprintf (buf
, f
->last_mtime
);
973 printf (_("# Last modified %s\n"), buf
);
976 ? _("# File has been updated.") : _("# File has not been updated."));
977 switch (f
->command_state
)
980 puts (_("# Recipe currently running (THIS IS A BUG)."));
982 case cs_deps_running
:
983 puts (_("# Dependencies recipe running (THIS IS A BUG)."));
987 switch (f
->update_status
)
992 puts (_("# Successfully updated."));
995 assert (question_flag
);
996 puts (_("# Needs to be updated (-q is set)."));
999 puts (_("# Failed to be updated."));
1002 puts (_("# Invalid value in 'update_status' member!"));
1009 puts (_("# Invalid value in 'command_state' member!"));
1015 if (f
->variables
!= 0)
1016 print_file_variables (f
);
1019 print_commands (f
->cmds
);
1022 print_file ((const void *) f
->prev
);
1026 print_file_data_base (void)
1028 puts (_("\n# Files"));
1030 hash_map (&files
, print_file
);
1032 fputs (_("\n# files hash-table stats:\n# "), stdout
);
1033 hash_print_stats (&files
, stdout
);
1036 /* Verify the integrity of the data base of files. */
1038 #define VERIFY_CACHED(_p,_n) \
1040 if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \
1041 error (NULL, "%s: Field '%s' not cached: %s\n", _p->name, # _n, _p->_n); \
1045 verify_file (const void *item
)
1047 const struct file
*f
= item
;
1048 const struct dep
*d
;
1050 VERIFY_CACHED (f
, name
);
1051 VERIFY_CACHED (f
, hname
);
1052 VERIFY_CACHED (f
, vpath
);
1053 VERIFY_CACHED (f
, stem
);
1055 /* Check the deps. */
1056 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
1058 if (! d
->need_2nd_expansion
)
1059 VERIFY_CACHED (d
, name
);
1060 VERIFY_CACHED (d
, stem
);
1065 verify_file_data_base (void)
1067 hash_map (&files
, verify_file
);
1070 #define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500)
1073 build_target_list (char *value
)
1075 static unsigned long last_targ_count
= 0;
1077 if (files
.ht_fill
!= last_targ_count
)
1079 unsigned long max
= EXPANSION_INCREMENT (strlen (value
));
1082 struct file
**fp
= (struct file
**) files
.ht_vec
;
1083 struct file
**end
= &fp
[files
.ht_size
];
1085 /* Make sure we have at least MAX bytes in the allocated buffer. */
1086 value
= xrealloc (value
, max
);
1090 for (; fp
< end
; ++fp
)
1091 if (!HASH_VACANT (*fp
) && (*fp
)->is_target
)
1093 struct file
*f
= *fp
;
1094 int l
= strlen (f
->name
);
1099 unsigned long off
= p
- value
;
1101 max
+= EXPANSION_INCREMENT (l
+ 1);
1102 value
= xrealloc (value
, max
);
1106 memcpy (p
, f
->name
, l
);
1112 last_targ_count
= files
.ht_fill
;
1119 init_hash_files (void)
1121 hash_init (&files
, 1000, file_hash_1
, file_hash_2
, file_hash_cmp
);