1 /* Target file management for GNU Make.
2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
4 2012 Free Software Foundation, Inc.
5 This file is part of GNU Make.
7 GNU Make is free software; you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 3 of the License, or (at your option) any later
12 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along with
17 this program. If not, see <http://www.gnu.org/licenses/>. */
32 /* Remember whether snap_deps has been invoked: we need this to be sure we
33 don't add new rules (via $(eval ...)) afterwards. In the future it would
34 be nice to support this, but it means we'd need to re-run snap_deps() or
35 at least its functionality... it might mean changing snap_deps() to be run
36 per-file, so we can invoke it after the eval... or remembering which files
37 in the hash have been snapped (a new boolean flag?) and having snap_deps()
38 only work on files which have not yet been snapped. */
41 /* Hash table of files the makefile knows how to make. */
44 file_hash_1 (const void *key
)
46 return_ISTRING_HASH_1 (((struct file
const *) key
)->hname
);
50 file_hash_2 (const void *key
)
52 return_ISTRING_HASH_2 (((struct file
const *) key
)->hname
);
56 file_hash_cmp (const void *x
, const void *y
)
58 return_ISTRING_COMPARE (((struct file
const *) x
)->hname
,
59 ((struct file
const *) y
)->hname
);
63 #define FILE_BUCKETS 1007
65 static struct hash_table files
;
67 /* Whether or not .SECONDARY with no prerequisites was given. */
68 static int all_secondary
= 0;
70 /* Access the hash table of all file records.
71 lookup_file given a name, return the struct file * for that name,
72 or nil if there is none.
76 lookup_file (const char *name
)
80 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
84 assert (*name
!= '\0');
86 /* This is also done in parse_file_seq, so this is redundant
87 for names read from makefiles. It is here for names passed
88 on the command line. */
90 # ifndef WANT_CASE_SENSITIVE_TARGETS
95 lname
= xstrdup (name
);
96 for (n
= name
, ln
= lname
; *n
!= '\0'; ++n
, ++ln
)
97 *ln
= isupper ((unsigned char)*n
) ? tolower ((unsigned char)*n
) : *n
;
103 while (name
[0] == '[' && name
[1] == ']' && name
[2] != '\0')
106 while (name
[0] == '.'
107 #ifdef HAVE_DOS_PATHS
108 && (name
[1] == '/' || name
[1] == '\\')
116 #ifdef HAVE_DOS_PATHS
120 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
125 /* It was all slashes after a dot. */
128 #elif defined(_AMIGA)
134 file_key
.hname
= name
;
135 f
= hash_find_item (&files
, &file_key
);
136 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
144 /* Look up a file record for file NAME and return it.
145 Create a new record if one doesn't exist. NAME will be stored in the
146 new record so it should be constant or in the strcache etc.
150 enter_file (const char *name
)
154 struct file
**file_slot
;
155 struct file file_key
;
157 assert (*name
!= '\0');
158 assert (strcache_iscached (name
));
160 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
165 lname
= xstrdup (name
);
166 for (n
= name
, ln
= lname
; *n
!= '\0'; ++n
, ++ln
)
167 if (isupper ((unsigned char)*n
))
168 *ln
= tolower ((unsigned char)*n
);
173 name
= strcache_add (lname
);
178 file_key
.hname
= name
;
179 file_slot
= (struct file
**) hash_find_slot (&files
, &file_key
);
181 if (! HASH_VACANT (f
) && !f
->double_colon
)
184 new = xcalloc (sizeof (struct file
));
185 new->name
= new->hname
= name
;
186 new->update_status
= -1;
191 hash_insert_at (&files
, new, file_slot
);
195 /* There is already a double-colon entry for this file. */
196 new->double_colon
= f
;
204 /* Rehash FILE to NAME. This is not as simple as resetting
205 the 'hname' member, since it must be put in a new hash bucket,
206 and possibly merged with an existing file called NAME. */
209 rehash_file (struct file
*from_file
, const char *to_hname
)
211 struct file file_key
;
212 struct file
**file_slot
;
213 struct file
*to_file
;
214 struct file
*deleted_file
;
217 /* If it's already that name, we're done. */
218 file_key
.hname
= to_hname
;
219 if (! file_hash_cmp (from_file
, &file_key
))
222 /* Find the end of the renamed list for the "from" file. */
223 file_key
.hname
= from_file
->hname
;
224 while (from_file
->renamed
!= 0)
225 from_file
= from_file
->renamed
;
226 if (file_hash_cmp (from_file
, &file_key
))
227 /* hname changed unexpectedly!! */
230 /* Remove the "from" file from the hash. */
231 deleted_file
= hash_delete (&files
, from_file
);
232 if (deleted_file
!= from_file
)
233 /* from_file isn't the one stored in files */
236 /* Find where the newly renamed file will go in the hash. */
237 file_key
.hname
= to_hname
;
238 file_slot
= (struct file
**) hash_find_slot (&files
, &file_key
);
239 to_file
= *file_slot
;
241 /* Change the hash name for this file. */
242 from_file
->hname
= to_hname
;
243 for (f
= from_file
->double_colon
; f
!= 0; f
= f
->prev
)
246 /* If the new name doesn't exist yet just set it to the renamed file. */
247 if (HASH_VACANT (to_file
))
249 hash_insert_at (&files
, from_file
, file_slot
);
253 /* TO_FILE already exists under TO_HNAME.
254 We must retain TO_FILE and merge FROM_FILE into it. */
256 if (from_file
->cmds
!= 0)
258 if (to_file
->cmds
== 0)
259 to_file
->cmds
= from_file
->cmds
;
260 else if (from_file
->cmds
!= to_file
->cmds
)
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 _("Recipe was specified for file '%s' at %s:%lu,"),
268 from_file
->name
, to_file
->cmds
->fileinfo
.filenm
,
269 to_file
->cmds
->fileinfo
.lineno
);
271 error (&from_file
->cmds
->fileinfo
,
272 _("Recipe for file '%s' was found by implicit rule search,"),
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 _("Recipe for '%s' will be ignored in favor of the one for '%s'."),
279 to_hname
, from_file
->name
);
283 /* Merge the dependencies of the two files. */
285 if (to_file
->deps
== 0)
286 to_file
->deps
= from_file
->deps
;
289 struct dep
*deps
= to_file
->deps
;
290 while (deps
->next
!= 0)
292 deps
->next
= from_file
->deps
;
295 merge_variable_set_lists (&to_file
->variables
, from_file
->variables
);
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
)
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
);
306 to_file
->double_colon
= from_file
->double_colon
;
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
;
313 to_file
->mtime_before_update
= from_file
->mtime_before_update
;
315 #define MERGE(field) to_file->field |= from_file->field
317 MERGE (tried_implicit
);
323 MERGE (ignore_vpath
);
326 from_file
->renamed
= to_file
;
329 /* Rename FILE to NAME. This is not as simple as resetting
330 the 'name' member, since it must be put in a new hash bucket,
331 and possibly merged with an existing file called NAME. */
334 rename_file (struct file
*from_file
, const char *to_hname
)
336 rehash_file (from_file
, to_hname
);
339 from_file
->name
= from_file
->hname
;
340 from_file
= from_file
->prev
;
344 /* Remove all nonprecious intermediate files.
345 If SIG is nonzero, this was caused by a fatal signal,
346 meaning that a different message will be printed, and
347 the message will go to stderr rather than stdout. */
350 remove_intermediates (int sig
)
352 struct file
**file_slot
;
353 struct file
**file_end
;
356 /* If there's no way we will ever remove anything anyway, punt early. */
357 if (question_flag
|| touch_flag
|| all_secondary
)
360 if (sig
&& just_print_flag
)
363 file_slot
= (struct file
**) files
.ht_vec
;
364 file_end
= file_slot
+ files
.ht_size
;
365 for ( ; file_slot
< file_end
; file_slot
++)
366 if (! HASH_VACANT (*file_slot
))
368 struct file
*f
= *file_slot
;
369 /* Is this file eligible for automatic deletion?
370 Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
371 given on the command line, and it's either a -include makefile or
372 it's not precious. */
373 if (f
->intermediate
&& (f
->dontcare
|| !f
->precious
)
374 && !f
->secondary
&& !f
->cmd_target
)
377 if (f
->update_status
== -1)
378 /* If nothing would have created this file yet,
379 don't print an "rm" command for it. */
385 status
= unlink (f
->name
);
386 if (status
< 0 && errno
== ENOENT
)
392 error (NILF
, _("*** Deleting intermediate file '%s'"), f
->name
);
396 DB (DB_BASIC
, (_("Removing intermediate files...\n")));
401 fputs ("rm ", stdout
);
406 fputs (f
->name
, stdout
);
411 perror_with_name ("unlink: ", f
->name
);
423 /* Given a string containing prerequisites (fully expanded), break it up into
424 a struct dep list. Enter each of these prereqs into the file database.
427 split_prereqs (char *p
)
429 struct dep
*new = PARSE_FILE_SEQ (&p
, struct dep
, '|', NULL
, 0);
433 /* Files that follow '|' are "order-only" prerequisites that satisfy the
434 dependency by existing: their modification times are irrelevant. */
438 ood
= PARSE_FILE_SEQ (&p
, struct dep
, '\0', NULL
, 0);
445 for (dp
= new; dp
->next
!= NULL
; dp
= dp
->next
)
450 for (; ood
!= NULL
; ood
= ood
->next
)
451 ood
->ignore_mtime
= 1;
457 /* Given a list of prerequisites, enter them into the file database.
458 If STEM is set then first expand patterns using STEM. */
460 enter_prereqs (struct dep
*deps
, const char *stem
)
467 /* If we have a stem, expand the %'s. We use patsubst_expand to translate
468 the prerequisites' patterns into plain prerequisite names. */
471 const char *pattern
= "%";
472 char *buffer
= variable_expand ("");
473 struct dep
*dp
= deps
, *dl
= 0;
478 int nl
= strlen (dp
->name
) + 1;
479 char *nm
= alloca (nl
);
480 memcpy (nm
, dp
->name
, nl
);
481 percent
= find_percent (nm
);
486 /* We have to handle empty stems specially, because that
487 would be equivalent to $(patsubst %,dp->name,) which
488 will always be empty. */
491 memmove (percent
, percent
+1, strlen (percent
));
492 o
= variable_buffer_output (buffer
, nm
, strlen (nm
) + 1);
495 o
= patsubst_expand_pat (buffer
, stem
, pattern
, nm
,
496 pattern
+1, percent
+1);
498 /* If the name expanded to the empty string, ignore it. */
499 if (buffer
[0] == '\0')
503 dp
= deps
= deps
->next
;
505 dp
= dl
->next
= dp
->next
;
511 dp
->name
= strcache_add_len (buffer
, o
- buffer
);
514 dp
->staticpattern
= 1;
520 /* Enter them as files, unless they need a 2nd expansion. */
521 for (d1
= deps
; d1
!= 0; d1
= d1
->next
)
523 if (d1
->need_2nd_expansion
)
526 d1
->file
= lookup_file (d1
->name
);
528 d1
->file
= enter_file (d1
->name
);
529 d1
->staticpattern
= 0;
536 /* Set the intermediate flag. */
539 set_intermediate (const void *item
)
541 struct file
*f
= (struct file
*) item
;
545 /* Expand and parse each dependency line. */
547 expand_deps (struct file
*f
)
551 const char *file_stem
= f
->stem
;
556 /* Walk through the dependencies. For any dependency that needs 2nd
557 expansion, expand it then insert the result into the list. */
563 struct dep
*new, *next
;
564 char *name
= (char *)d
->name
;
566 if (! d
->name
|| ! d
->need_2nd_expansion
)
568 /* This one is all set already. */
574 /* If it's from a static pattern rule, convert the patterns into
575 "$*" so they'll expand properly. */
576 if (d
->staticpattern
)
579 d
->name
= o
= variable_expand ("");
580 o
= subst_expand (o
, name
, "%", "$*", 1, 2, 0);
583 d
->name
= name
= xstrdup (d
->name
);
584 d
->staticpattern
= 0;
587 /* We're going to do second expansion so initialize file variables for
588 the file. Since the stem for static pattern rules comes from
589 individual dep lines, we will temporarily set f->stem to d->stem. */
592 initialize_file_variables (f
, 0);
599 set_file_variables (f
);
601 p
= variable_expand_for_file (d
->name
, f
);
606 /* At this point we don't need the name anymore: free it. */
609 /* Parse the prerequisites and enter them into the file database. */
610 new = enter_prereqs (split_prereqs (p
), d
->stem
);
612 /* If there were no prereqs here (blank!) then throw this one out. */
621 /* Add newly parsed prerequisites. */
624 for (dp
= &new->next
, d
= new->next
; d
!= 0; dp
= &d
->next
, d
= d
->next
)
631 /* Reset the updating flag. */
634 reset_updating (const void *item
)
636 struct file
*f
= (struct file
*) item
;
640 /* For each dependency of each file, make the 'struct dep' point
641 at the appropriate 'struct file' (which may have to be created).
643 Also mark the files depended on by .PRECIOUS, .PHONY, .SILENT,
644 and various other special targets. */
653 /* Remember that we've done this. Once we start snapping deps we can no
654 longer define new targets. */
657 /* Perform second expansion and enter each dependency name as a file. We
658 must use hash_dump() here because within these loops we likely add new
659 files to the table, possibly causing an in-situ table expansion.
661 We only need to do this if second_expansion has been defined; if it
662 hasn't then all deps were expanded as the makefile was read in. If we
663 ever change make to be able to unset .SECONDARY_EXPANSION this will have
666 if (second_expansion
)
668 struct file
**file_slot_0
= (struct file
**) hash_dump (&files
, 0, 0);
669 struct file
**file_end
= file_slot_0
+ files
.ht_fill
;
670 struct file
**file_slot
;
671 const char *suffixes
;
673 /* Expand .SUFFIXES: its prerequisites are used for $$* calc. */
674 f
= lookup_file (".SUFFIXES");
675 suffixes
= f
? f
->name
: 0;
676 for (; f
!= 0; f
= f
->prev
)
679 /* For every target that's not .SUFFIXES, expand its prerequisites. */
681 for (file_slot
= file_slot_0
; file_slot
< file_end
; file_slot
++)
682 for (f
= *file_slot
; f
!= 0; f
= f
->prev
)
683 if (f
->name
!= suffixes
)
688 /* We're not doing second expansion, so reset updating. */
689 hash_map (&files
, reset_updating
);
691 /* Now manage all the special targets. */
693 for (f
= lookup_file (".PRECIOUS"); f
!= 0; f
= f
->prev
)
694 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
695 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
698 for (f
= lookup_file (".LOW_RESOLUTION_TIME"); f
!= 0; f
= f
->prev
)
699 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
700 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
701 f2
->low_resolution_time
= 1;
703 for (f
= lookup_file (".PHONY"); f
!= 0; f
= f
->prev
)
704 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
705 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
707 /* Mark this file as phony nonexistent target. */
710 f2
->last_mtime
= NONEXISTENT_MTIME
;
711 f2
->mtime_before_update
= NONEXISTENT_MTIME
;
714 for (f
= lookup_file (".INTERMEDIATE"); f
!= 0; f
= f
->prev
)
715 /* Mark .INTERMEDIATE deps as intermediate files. */
716 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
717 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
718 f2
->intermediate
= 1;
719 /* .INTERMEDIATE with no deps does nothing.
720 Marking all files as intermediates is useless since the goal targets
721 would be deleted after they are built. */
723 for (f
= lookup_file (".SECONDARY"); f
!= 0; f
= f
->prev
)
724 /* Mark .SECONDARY deps as both intermediate and secondary. */
726 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
727 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
728 f2
->intermediate
= f2
->secondary
= 1;
729 /* .SECONDARY with no deps listed marks *all* files that way. */
733 hash_map (&files
, set_intermediate
);
736 f
= lookup_file (".EXPORT_ALL_VARIABLES");
737 if (f
!= 0 && f
->is_target
)
738 export_all_variables
= 1;
740 f
= lookup_file (".IGNORE");
741 if (f
!= 0 && f
->is_target
)
744 ignore_errors_flag
= 1;
746 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
747 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
748 f2
->command_flags
|= COMMANDS_NOERROR
;
751 f
= lookup_file (".SILENT");
752 if (f
!= 0 && f
->is_target
)
757 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
758 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
759 f2
->command_flags
|= COMMANDS_SILENT
;
762 f
= lookup_file (".NOTPARALLEL");
763 if (f
!= 0 && f
->is_target
)
766 #ifndef NO_MINUS_C_MINUS_O
767 /* If .POSIX was defined, remove OUTPUT_OPTION to comply. */
768 /* This needs more work: what if the user sets this in the makefile?
770 define_variable_cname ("OUTPUT_OPTION", "", o_default, 1);
775 /* Set the 'command_state' member of FILE and all its 'also_make's. */
778 set_command_state (struct file
*file
, enum cmd_state state
)
782 file
->command_state
= state
;
784 for (d
= file
->also_make
; d
!= 0; d
= d
->next
)
785 d
->file
->command_state
= state
;
788 /* Convert an external file timestamp to internal form. */
791 file_timestamp_cons (const char *fname
, time_t stamp
, long int ns
)
793 int offset
= ORDINARY_MTIME_MIN
+ (FILE_TIMESTAMP_HI_RES
? ns
: 0);
794 FILE_TIMESTAMP s
= stamp
;
795 FILE_TIMESTAMP product
= (FILE_TIMESTAMP
) s
<< FILE_TIMESTAMP_LO_BITS
;
796 FILE_TIMESTAMP ts
= product
+ offset
;
798 if (! (s
<= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX
)
799 && product
<= ts
&& ts
<= ORDINARY_MTIME_MAX
))
801 char buf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
802 ts
= s
<= OLD_MTIME
? ORDINARY_MTIME_MIN
: ORDINARY_MTIME_MAX
;
803 file_timestamp_sprintf (buf
, ts
);
804 error (NILF
, _("%s: Timestamp out of range; substituting %s"),
805 fname
? fname
: _("Current time"), buf
);
811 /* Return the current time as a file timestamp, setting *RESOLUTION to
814 file_timestamp_now (int *resolution
)
820 /* Don't bother with high-resolution clocks if file timestamps have
821 only one-second resolution. The code below should work, but it's
822 not worth the hassle of debugging it on hosts where it fails. */
823 #if FILE_TIMESTAMP_HI_RES
824 # if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME
826 struct timespec timespec
;
827 if (clock_gettime (CLOCK_REALTIME
, ×pec
) == 0)
831 ns
= timespec
.tv_nsec
;
836 # if HAVE_GETTIMEOFDAY
838 struct timeval timeval
;
839 if (gettimeofday (&timeval
, 0) == 0)
843 ns
= timeval
.tv_usec
* 1000;
851 s
= time ((time_t *) 0);
854 #if FILE_TIMESTAMP_HI_RES
858 return file_timestamp_cons (0, s
, ns
);
861 /* Place into the buffer P a printable representation of the file
864 file_timestamp_sprintf (char *p
, FILE_TIMESTAMP ts
)
866 time_t t
= FILE_TIMESTAMP_S (ts
);
867 struct tm
*tm
= localtime (&t
);
870 sprintf (p
, "%04d-%02d-%02d %02d:%02d:%02d",
871 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
872 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
874 sprintf (p
, "%ld", (long) t
);
876 sprintf (p
, "%lu", (unsigned long) t
);
879 /* Append nanoseconds as a fraction, but remove trailing zeros. We don't
880 know the actual timestamp resolution, since clock_getres applies only to
881 local times, whereas this timestamp might come from a remote filesystem.
882 So removing trailing zeros is the best guess that we can do. */
883 sprintf (p
, ".%09d", FILE_TIMESTAMP_NS (ts
));
892 /* Print the data base of files. */
895 print_prereqs (const struct dep
*deps
)
897 const struct dep
*ood
= 0;
899 /* Print all normal dependencies; note any order-only deps. */
900 for (; deps
!= 0; deps
= deps
->next
)
901 if (! deps
->ignore_mtime
)
902 printf (" %s", dep_name (deps
));
906 /* Print order-only deps, if we have any. */
909 printf (" | %s", dep_name (ood
));
910 for (ood
= ood
->next
; ood
!= 0; ood
= ood
->next
)
911 if (ood
->ignore_mtime
)
912 printf (" %s", dep_name (ood
));
919 print_file (const void *item
)
921 const struct file
*f
= item
;
925 if (f
->cmds
&& f
->cmds
->recipe_prefix
!= cmd_prefix
)
927 fputs (".RECIPEPREFIX = ", stdout
);
928 cmd_prefix
= f
->cmds
->recipe_prefix
;
929 if (cmd_prefix
!= RECIPEPREFIX_DEFAULT
)
930 putchar (cmd_prefix
);
934 if (f
->variables
!= 0)
935 print_target_variables (f
);
938 puts (_("# Not a target:"));
939 printf ("%s:%s", f
->name
, f
->double_colon
? ":" : "");
940 print_prereqs (f
->deps
);
943 puts (_("# Precious file (prerequisite of .PRECIOUS)."));
945 puts (_("# Phony target (prerequisite of .PHONY)."));
947 puts (_("# Command line target."));
949 puts (_("# A default, MAKEFILES, or -include/sinclude makefile."));
950 puts (f
->tried_implicit
951 ? _("# Implicit rule search has been done.")
952 : _("# Implicit rule search has not been done."));
954 printf (_("# Implicit/static pattern stem: '%s'\n"), f
->stem
);
956 puts (_("# File is an intermediate prerequisite."));
957 if (f
->also_make
!= 0)
960 fputs (_("# Also makes:"), stdout
);
961 for (d
= f
->also_make
; d
!= 0; d
= d
->next
)
962 printf (" %s", dep_name (d
));
965 if (f
->last_mtime
== UNKNOWN_MTIME
)
966 puts (_("# Modification time never checked."));
967 else if (f
->last_mtime
== NONEXISTENT_MTIME
)
968 puts (_("# File does not exist."));
969 else if (f
->last_mtime
== OLD_MTIME
)
970 puts (_("# File is very old."));
973 char buf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
974 file_timestamp_sprintf (buf
, f
->last_mtime
);
975 printf (_("# Last modified %s\n"), buf
);
978 ? _("# File has been updated.") : _("# File has not been updated."));
979 switch (f
->command_state
)
982 puts (_("# Recipe currently running (THIS IS A BUG)."));
984 case cs_deps_running
:
985 puts (_("# Dependencies recipe running (THIS IS A BUG)."));
989 switch (f
->update_status
)
994 puts (_("# Successfully updated."));
997 assert (question_flag
);
998 puts (_("# Needs to be updated (-q is set)."));
1001 puts (_("# Failed to be updated."));
1004 puts (_("# Invalid value in 'update_status' member!"));
1011 puts (_("# Invalid value in 'command_state' member!"));
1017 if (f
->variables
!= 0)
1018 print_file_variables (f
);
1021 print_commands (f
->cmds
);
1024 print_file ((const void *) f
->prev
);
1028 print_file_data_base (void)
1030 puts (_("\n# Files"));
1032 hash_map (&files
, print_file
);
1034 fputs (_("\n# files hash-table stats:\n# "), stdout
);
1035 hash_print_stats (&files
, stdout
);
1038 /* Verify the integrity of the data base of files. */
1040 #define VERIFY_CACHED(_p,_n) \
1042 if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \
1043 error (NULL, "%s: Field '%s' not cached: %s\n", _p->name, # _n, _p->_n); \
1047 verify_file (const void *item
)
1049 const struct file
*f
= item
;
1050 const struct dep
*d
;
1052 VERIFY_CACHED (f
, name
);
1053 VERIFY_CACHED (f
, hname
);
1054 VERIFY_CACHED (f
, vpath
);
1055 VERIFY_CACHED (f
, stem
);
1057 /* Check the deps. */
1058 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
1060 if (! d
->need_2nd_expansion
)
1061 VERIFY_CACHED (d
, name
);
1062 VERIFY_CACHED (d
, stem
);
1067 verify_file_data_base (void)
1069 hash_map (&files
, verify_file
);
1072 #define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500)
1075 build_target_list (char *value
)
1077 static unsigned long last_targ_count
= 0;
1079 if (files
.ht_fill
!= last_targ_count
)
1081 unsigned long max
= EXPANSION_INCREMENT (strlen (value
));
1084 struct file
**fp
= (struct file
**) files
.ht_vec
;
1085 struct file
**end
= &fp
[files
.ht_size
];
1087 /* Make sure we have at least MAX bytes in the allocated buffer. */
1088 value
= xrealloc (value
, max
);
1092 for (; fp
< end
; ++fp
)
1093 if (!HASH_VACANT (*fp
) && (*fp
)->is_target
)
1095 struct file
*f
= *fp
;
1096 int l
= strlen (f
->name
);
1101 unsigned long off
= p
- value
;
1103 max
+= EXPANSION_INCREMENT (l
+ 1);
1104 value
= xrealloc (value
, max
);
1108 memcpy (p
, f
->name
, l
);
1114 last_targ_count
= files
.ht_fill
;
1121 init_hash_files (void)
1123 hash_init (&files
, 1000, file_hash_1
, file_hash_2
, file_hash_cmp
);