1 /* Target file management for GNU Make.
2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free
4 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] == '.' && name
[1] == '/' && name
[2] != '\0')
110 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
115 /* It was all slashes after a dot. */
118 #elif defined(_AMIGA)
124 file_key
.hname
= name
;
125 f
= hash_find_item (&files
, &file_key
);
126 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
134 /* Look up a file record for file NAME and return it.
135 Create a new record if one doesn't exist. NAME will be stored in the
136 new record so it should be constant or in the strcache etc.
140 enter_file (const char *name
)
144 struct file
**file_slot
;
145 struct file file_key
;
147 assert (*name
!= '\0');
148 assert (strcache_iscached (name
));
150 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
155 lname
= xstrdup (name
);
156 for (n
= name
, ln
= lname
; *n
!= '\0'; ++n
, ++ln
)
157 if (isupper ((unsigned char)*n
))
158 *ln
= tolower ((unsigned char)*n
);
163 name
= strcache_add (lname
);
168 file_key
.hname
= name
;
169 file_slot
= (struct file
**) hash_find_slot (&files
, &file_key
);
171 if (! HASH_VACANT (f
) && !f
->double_colon
)
174 new = xmalloc (sizeof (struct file
));
175 memset (new, '\0', sizeof (struct file
));
176 new->name
= new->hname
= name
;
177 new->update_status
= -1;
182 hash_insert_at (&files
, new, file_slot
);
186 /* There is already a double-colon entry for this file. */
187 new->double_colon
= f
;
195 /* Rehash FILE to NAME. This is not as simple as resetting
196 the `hname' member, since it must be put in a new hash bucket,
197 and possibly merged with an existing file called NAME. */
200 rehash_file (struct file
*from_file
, const char *to_hname
)
202 struct file file_key
;
203 struct file
**file_slot
;
204 struct file
*to_file
;
205 struct file
*deleted_file
;
208 /* If it's already that name, we're done. */
209 file_key
.hname
= to_hname
;
210 if (! file_hash_cmp (from_file
, &file_key
))
213 /* Find the end of the renamed list for the "from" file. */
214 file_key
.hname
= from_file
->hname
;
215 while (from_file
->renamed
!= 0)
216 from_file
= from_file
->renamed
;
217 if (file_hash_cmp (from_file
, &file_key
))
218 /* hname changed unexpectedly!! */
221 /* Remove the "from" file from the hash. */
222 deleted_file
= hash_delete (&files
, from_file
);
223 if (deleted_file
!= from_file
)
224 /* from_file isn't the one stored in files */
227 /* Find where the newly renamed file will go in the hash. */
228 file_key
.hname
= to_hname
;
229 file_slot
= (struct file
**) hash_find_slot (&files
, &file_key
);
230 to_file
= *file_slot
;
232 /* Change the hash name for this file. */
233 from_file
->hname
= to_hname
;
234 for (f
= from_file
->double_colon
; f
!= 0; f
= f
->prev
)
237 /* If the new name doesn't exist yet just set it to the renamed file. */
238 if (HASH_VACANT (to_file
))
240 hash_insert_at (&files
, from_file
, file_slot
);
244 /* TO_FILE already exists under TO_HNAME.
245 We must retain TO_FILE and merge FROM_FILE into it. */
247 if (from_file
->cmds
!= 0)
249 if (to_file
->cmds
== 0)
250 to_file
->cmds
= from_file
->cmds
;
251 else if (from_file
->cmds
!= to_file
->cmds
)
253 /* We have two sets of commands. We will go with the
254 one given in the rule explicitly mentioning this name,
255 but give a message to let the user know what's going on. */
256 if (to_file
->cmds
->fileinfo
.filenm
!= 0)
257 error (&from_file
->cmds
->fileinfo
,
258 _("Recipe was specified for file `%s' at %s:%lu,"),
259 from_file
->name
, to_file
->cmds
->fileinfo
.filenm
,
260 to_file
->cmds
->fileinfo
.lineno
);
262 error (&from_file
->cmds
->fileinfo
,
263 _("Recipe for file `%s' was found by implicit rule search,"),
265 error (&from_file
->cmds
->fileinfo
,
266 _("but `%s' is now considered the same file as `%s'."),
267 from_file
->name
, to_hname
);
268 error (&from_file
->cmds
->fileinfo
,
269 _("Recipe for `%s' will be ignored in favor of the one for `%s'."),
270 to_hname
, from_file
->name
);
274 /* Merge the dependencies of the two files. */
276 if (to_file
->deps
== 0)
277 to_file
->deps
= from_file
->deps
;
280 struct dep
*deps
= to_file
->deps
;
281 while (deps
->next
!= 0)
283 deps
->next
= from_file
->deps
;
286 merge_variable_set_lists (&to_file
->variables
, from_file
->variables
);
288 if (to_file
->double_colon
&& from_file
->is_target
&& !from_file
->double_colon
)
289 fatal (NILF
, _("can't rename single-colon `%s' to double-colon `%s'"),
290 from_file
->name
, to_hname
);
291 if (!to_file
->double_colon
&& from_file
->double_colon
)
293 if (to_file
->is_target
)
294 fatal (NILF
, _("can't rename double-colon `%s' to single-colon `%s'"),
295 from_file
->name
, to_hname
);
297 to_file
->double_colon
= from_file
->double_colon
;
300 if (from_file
->last_mtime
> to_file
->last_mtime
)
301 /* %%% Kludge so -W wins on a file that gets vpathized. */
302 to_file
->last_mtime
= from_file
->last_mtime
;
304 to_file
->mtime_before_update
= from_file
->mtime_before_update
;
306 #define MERGE(field) to_file->field |= from_file->field
308 MERGE (tried_implicit
);
314 MERGE (ignore_vpath
);
317 from_file
->renamed
= to_file
;
320 /* Rename FILE to NAME. This is not as simple as resetting
321 the `name' member, since it must be put in a new hash bucket,
322 and possibly merged with an existing file called NAME. */
325 rename_file (struct file
*from_file
, const char *to_hname
)
327 rehash_file (from_file
, to_hname
);
330 from_file
->name
= from_file
->hname
;
331 from_file
= from_file
->prev
;
335 /* Remove all nonprecious intermediate files.
336 If SIG is nonzero, this was caused by a fatal signal,
337 meaning that a different message will be printed, and
338 the message will go to stderr rather than stdout. */
341 remove_intermediates (int sig
)
343 struct file
**file_slot
;
344 struct file
**file_end
;
347 /* If there's no way we will ever remove anything anyway, punt early. */
348 if (question_flag
|| touch_flag
|| all_secondary
)
351 if (sig
&& just_print_flag
)
354 file_slot
= (struct file
**) files
.ht_vec
;
355 file_end
= file_slot
+ files
.ht_size
;
356 for ( ; file_slot
< file_end
; file_slot
++)
357 if (! HASH_VACANT (*file_slot
))
359 struct file
*f
= *file_slot
;
360 /* Is this file eligible for automatic deletion?
361 Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
362 given on the command line, and it's either a -include makefile or
363 it's not precious. */
364 if (f
->intermediate
&& (f
->dontcare
|| !f
->precious
)
365 && !f
->secondary
&& !f
->cmd_target
)
368 if (f
->update_status
== -1)
369 /* If nothing would have created this file yet,
370 don't print an "rm" command for it. */
376 status
= unlink (f
->name
);
377 if (status
< 0 && errno
== ENOENT
)
383 error (NILF
, _("*** Deleting intermediate file `%s'"), f
->name
);
387 DB (DB_BASIC
, (_("Removing intermediate files...\n")));
392 fputs ("rm ", stdout
);
397 fputs (f
->name
, stdout
);
402 perror_with_name ("unlink: ", f
->name
);
414 /* Given a string containing prerequisites (fully expanded), break it up into
415 a struct dep list. Enter each of these prereqs into the file database.
418 split_prereqs (char *p
)
420 struct dep
*new = PARSE_FILE_SEQ (&p
, struct dep
, '|', NULL
, 0);
424 /* Files that follow '|' are "order-only" prerequisites that satisfy the
425 dependency by existing: their modification times are irrelevant. */
429 ood
= PARSE_FILE_SEQ (&p
, struct dep
, '\0', NULL
, 0);
436 for (dp
= new; dp
->next
!= NULL
; dp
= dp
->next
)
441 for (; ood
!= NULL
; ood
= ood
->next
)
442 ood
->ignore_mtime
= 1;
448 /* Given a list of prerequisites, enter them into the file database.
449 If STEM is set then first expand patterns using STEM. */
451 enter_prereqs (struct dep
*deps
, const char *stem
)
458 /* If we have a stem, expand the %'s. We use patsubst_expand to translate
459 the prerequisites' patterns into plain prerequisite names. */
462 const char *pattern
= "%";
463 char *buffer
= variable_expand ("");
464 struct dep
*dp
= deps
, *dl
= 0;
469 int nl
= strlen (dp
->name
) + 1;
470 char *nm
= alloca (nl
);
471 memcpy (nm
, dp
->name
, nl
);
472 percent
= find_percent (nm
);
477 /* We have to handle empty stems specially, because that
478 would be equivalent to $(patsubst %,dp->name,) which
479 will always be empty. */
482 memmove (percent
, percent
+1, strlen (percent
));
483 o
= variable_buffer_output (buffer
, nm
, strlen (nm
) + 1);
486 o
= patsubst_expand_pat (buffer
, stem
, pattern
, nm
,
487 pattern
+1, percent
+1);
489 /* If the name expanded to the empty string, ignore it. */
490 if (buffer
[0] == '\0')
494 dp
= deps
= deps
->next
;
496 dp
= dl
->next
= dp
->next
;
502 dp
->name
= strcache_add_len (buffer
, o
- buffer
);
505 dp
->staticpattern
= 1;
511 /* Enter them as files, unless they need a 2nd expansion. */
512 for (d1
= deps
; d1
!= 0; d1
= d1
->next
)
514 if (d1
->need_2nd_expansion
)
517 d1
->file
= lookup_file (d1
->name
);
519 d1
->file
= enter_file (d1
->name
);
520 d1
->staticpattern
= 0;
527 /* Set the intermediate flag. */
530 set_intermediate (const void *item
)
532 struct file
*f
= (struct file
*) item
;
536 /* Expand and parse each dependency line. */
538 expand_deps (struct file
*f
)
542 const char *file_stem
= f
->stem
;
547 /* Walk through the dependencies. For any dependency that needs 2nd
548 expansion, expand it then insert the result into the list. */
554 struct dep
*new, *next
;
555 char *name
= (char *)d
->name
;
557 if (! d
->name
|| ! d
->need_2nd_expansion
)
559 /* This one is all set already. */
565 /* If it's from a static pattern rule, convert the patterns into
566 "$*" so they'll expand properly. */
567 if (d
->staticpattern
)
570 d
->name
= o
= variable_expand ("");
571 o
= subst_expand (o
, name
, "%", "$*", 1, 2, 0);
574 d
->name
= name
= xstrdup (d
->name
);
575 d
->staticpattern
= 0;
578 /* We're going to do second expansion so initialize file variables for
579 the file. Since the stem for static pattern rules comes from
580 individual dep lines, we will temporarily set f->stem to d->stem. */
583 initialize_file_variables (f
, 0);
590 set_file_variables (f
);
592 p
= variable_expand_for_file (d
->name
, f
);
597 /* At this point we don't need the name anymore: free it. */
600 /* Parse the prerequisites and enter them into the file database. */
601 new = enter_prereqs (split_prereqs (p
), d
->stem
);
603 /* If there were no prereqs here (blank!) then throw this one out. */
612 /* Add newly parsed prerequisites. */
615 for (dp
= &new->next
, d
= new->next
; d
!= 0; dp
= &d
->next
, d
= d
->next
)
622 /* Reset the updating flag. */
625 reset_updating (const void *item
)
627 struct file
*f
= (struct file
*) item
;
631 /* For each dependency of each file, make the `struct dep' point
632 at the appropriate `struct file' (which may have to be created).
634 Also mark the files depended on by .PRECIOUS, .PHONY, .SILENT,
635 and various other special targets. */
644 /* Remember that we've done this. Once we start snapping deps we can no
645 longer define new targets. */
648 /* Perform second expansion and enter each dependency name as a file. We
649 must use hash_dump() here because within these loops we likely add new
650 files to the table, possibly causing an in-situ table expansion.
652 We only need to do this if second_expansion has been defined; if it
653 hasn't then all deps were expanded as the makefile was read in. If we
654 ever change make to be able to unset .SECONDARY_EXPANSION this will have
657 if (second_expansion
)
659 struct file
**file_slot_0
= (struct file
**) hash_dump (&files
, 0, 0);
660 struct file
**file_end
= file_slot_0
+ files
.ht_fill
;
661 struct file
**file_slot
;
662 const char *suffixes
;
664 /* Expand .SUFFIXES: its prerequisites are used for $$* calc. */
665 f
= lookup_file (".SUFFIXES");
666 suffixes
= f
? f
->name
: 0;
667 for (; f
!= 0; f
= f
->prev
)
670 /* For every target that's not .SUFFIXES, expand its prerequisites. */
672 for (file_slot
= file_slot_0
; file_slot
< file_end
; file_slot
++)
673 for (f
= *file_slot
; f
!= 0; f
= f
->prev
)
674 if (f
->name
!= suffixes
)
679 /* We're not doing second expansion, so reset updating. */
680 hash_map (&files
, reset_updating
);
682 /* Now manage all the special targets. */
684 for (f
= lookup_file (".PRECIOUS"); f
!= 0; f
= f
->prev
)
685 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
686 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
689 for (f
= lookup_file (".LOW_RESOLUTION_TIME"); f
!= 0; f
= f
->prev
)
690 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
691 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
692 f2
->low_resolution_time
= 1;
694 for (f
= lookup_file (".PHONY"); f
!= 0; f
= f
->prev
)
695 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
696 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
698 /* Mark this file as phony nonexistent target. */
701 f2
->last_mtime
= NONEXISTENT_MTIME
;
702 f2
->mtime_before_update
= NONEXISTENT_MTIME
;
705 for (f
= lookup_file (".INTERMEDIATE"); f
!= 0; f
= f
->prev
)
706 /* Mark .INTERMEDIATE deps as intermediate files. */
707 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
708 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
709 f2
->intermediate
= 1;
710 /* .INTERMEDIATE with no deps does nothing.
711 Marking all files as intermediates is useless since the goal targets
712 would be deleted after they are built. */
714 for (f
= lookup_file (".SECONDARY"); f
!= 0; f
= f
->prev
)
715 /* Mark .SECONDARY deps as both intermediate and secondary. */
717 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
718 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
719 f2
->intermediate
= f2
->secondary
= 1;
720 /* .SECONDARY with no deps listed marks *all* files that way. */
724 hash_map (&files
, set_intermediate
);
727 f
= lookup_file (".EXPORT_ALL_VARIABLES");
728 if (f
!= 0 && f
->is_target
)
729 export_all_variables
= 1;
731 f
= lookup_file (".IGNORE");
732 if (f
!= 0 && f
->is_target
)
735 ignore_errors_flag
= 1;
737 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
738 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
739 f2
->command_flags
|= COMMANDS_NOERROR
;
742 f
= lookup_file (".SILENT");
743 if (f
!= 0 && f
->is_target
)
748 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
749 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
750 f2
->command_flags
|= COMMANDS_SILENT
;
753 f
= lookup_file (".NOTPARALLEL");
754 if (f
!= 0 && f
->is_target
)
757 #ifndef NO_MINUS_C_MINUS_O
758 /* If .POSIX was defined, remove OUTPUT_OPTION to comply. */
759 /* This needs more work: what if the user sets this in the makefile?
761 define_variable_cname ("OUTPUT_OPTION", "", o_default, 1);
766 /* Set the `command_state' member of FILE and all its `also_make's. */
769 set_command_state (struct file
*file
, enum cmd_state state
)
773 file
->command_state
= state
;
775 for (d
= file
->also_make
; d
!= 0; d
= d
->next
)
776 d
->file
->command_state
= state
;
779 /* Convert an external file timestamp to internal form. */
782 file_timestamp_cons (const char *fname
, time_t s
, int ns
)
784 int offset
= ORDINARY_MTIME_MIN
+ (FILE_TIMESTAMP_HI_RES
? ns
: 0);
785 FILE_TIMESTAMP product
= (FILE_TIMESTAMP
) s
<< FILE_TIMESTAMP_LO_BITS
;
786 FILE_TIMESTAMP ts
= product
+ offset
;
788 if (! (s
<= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX
)
789 && product
<= ts
&& ts
<= ORDINARY_MTIME_MAX
))
791 char buf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
792 ts
= s
<= OLD_MTIME
? ORDINARY_MTIME_MIN
: ORDINARY_MTIME_MAX
;
793 file_timestamp_sprintf (buf
, ts
);
794 error (NILF
, _("%s: Timestamp out of range; substituting %s"),
795 fname
? fname
: _("Current time"), buf
);
801 /* Return the current time as a file timestamp, setting *RESOLUTION to
804 file_timestamp_now (int *resolution
)
810 /* Don't bother with high-resolution clocks if file timestamps have
811 only one-second resolution. The code below should work, but it's
812 not worth the hassle of debugging it on hosts where it fails. */
813 #if FILE_TIMESTAMP_HI_RES
814 # if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME
816 struct timespec timespec
;
817 if (clock_gettime (CLOCK_REALTIME
, ×pec
) == 0)
821 ns
= timespec
.tv_nsec
;
826 # if HAVE_GETTIMEOFDAY
828 struct timeval timeval
;
829 if (gettimeofday (&timeval
, 0) == 0)
833 ns
= timeval
.tv_usec
* 1000;
841 s
= time ((time_t *) 0);
844 #if FILE_TIMESTAMP_HI_RES
848 return file_timestamp_cons (0, s
, ns
);
851 /* Place into the buffer P a printable representation of the file
854 file_timestamp_sprintf (char *p
, FILE_TIMESTAMP ts
)
856 time_t t
= FILE_TIMESTAMP_S (ts
);
857 struct tm
*tm
= localtime (&t
);
860 sprintf (p
, "%04d-%02d-%02d %02d:%02d:%02d",
861 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
862 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
864 sprintf (p
, "%ld", (long) t
);
866 sprintf (p
, "%lu", (unsigned long) t
);
869 /* Append nanoseconds as a fraction, but remove trailing zeros. We don't
870 know the actual timestamp resolution, since clock_getres applies only to
871 local times, whereas this timestamp might come from a remote filesystem.
872 So removing trailing zeros is the best guess that we can do. */
873 sprintf (p
, ".%09d", FILE_TIMESTAMP_NS (ts
));
882 /* Print the data base of files. */
885 print_prereqs (const struct dep
*deps
)
887 const struct dep
*ood
= 0;
889 /* Print all normal dependencies; note any order-only deps. */
890 for (; deps
!= 0; deps
= deps
->next
)
891 if (! deps
->ignore_mtime
)
892 printf (" %s", dep_name (deps
));
896 /* Print order-only deps, if we have any. */
899 printf (" | %s", dep_name (ood
));
900 for (ood
= ood
->next
; ood
!= 0; ood
= ood
->next
)
901 if (ood
->ignore_mtime
)
902 printf (" %s", dep_name (ood
));
909 print_file (const void *item
)
911 const struct file
*f
= item
;
915 puts (_("# Not a target:"));
916 printf ("%s:%s", f
->name
, f
->double_colon
? ":" : "");
917 print_prereqs (f
->deps
);
920 puts (_("# Precious file (prerequisite of .PRECIOUS)."));
922 puts (_("# Phony target (prerequisite of .PHONY)."));
924 puts (_("# Command line target."));
926 puts (_("# A default, MAKEFILES, or -include/sinclude makefile."));
927 puts (f
->tried_implicit
928 ? _("# Implicit rule search has been done.")
929 : _("# Implicit rule search has not been done."));
931 printf (_("# Implicit/static pattern stem: `%s'\n"), f
->stem
);
933 puts (_("# File is an intermediate prerequisite."));
934 if (f
->also_make
!= 0)
937 fputs (_("# Also makes:"), stdout
);
938 for (d
= f
->also_make
; d
!= 0; d
= d
->next
)
939 printf (" %s", dep_name (d
));
942 if (f
->last_mtime
== UNKNOWN_MTIME
)
943 puts (_("# Modification time never checked."));
944 else if (f
->last_mtime
== NONEXISTENT_MTIME
)
945 puts (_("# File does not exist."));
946 else if (f
->last_mtime
== OLD_MTIME
)
947 puts (_("# File is very old."));
950 char buf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
951 file_timestamp_sprintf (buf
, f
->last_mtime
);
952 printf (_("# Last modified %s\n"), buf
);
955 ? _("# File has been updated.") : _("# File has not been updated."));
956 switch (f
->command_state
)
959 puts (_("# Recipe currently running (THIS IS A BUG)."));
961 case cs_deps_running
:
962 puts (_("# Dependencies recipe running (THIS IS A BUG)."));
966 switch (f
->update_status
)
971 puts (_("# Successfully updated."));
974 assert (question_flag
);
975 puts (_("# Needs to be updated (-q is set)."));
978 puts (_("# Failed to be updated."));
981 puts (_("# Invalid value in `update_status' member!"));
988 puts (_("# Invalid value in `command_state' member!"));
994 if (f
->variables
!= 0)
995 print_file_variables (f
);
998 print_commands (f
->cmds
);
1001 print_file ((const void *) f
->prev
);
1005 print_file_data_base (void)
1007 puts (_("\n# Files"));
1009 hash_map (&files
, print_file
);
1011 fputs (_("\n# files hash-table stats:\n# "), stdout
);
1012 hash_print_stats (&files
, stdout
);
1015 /* Verify the integrity of the data base of files. */
1017 #define VERIFY_CACHED(_p,_n) \
1019 if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \
1020 error (NULL, "%s: Field '%s' not cached: %s\n", _p->name, # _n, _p->_n); \
1024 verify_file (const void *item
)
1026 const struct file
*f
= item
;
1027 const struct dep
*d
;
1029 VERIFY_CACHED (f
, name
);
1030 VERIFY_CACHED (f
, hname
);
1031 VERIFY_CACHED (f
, vpath
);
1032 VERIFY_CACHED (f
, stem
);
1034 /* Check the deps. */
1035 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
1037 if (! d
->need_2nd_expansion
)
1038 VERIFY_CACHED (d
, name
);
1039 VERIFY_CACHED (d
, stem
);
1044 verify_file_data_base (void)
1046 hash_map (&files
, verify_file
);
1049 #define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500)
1052 build_target_list (char *value
)
1054 static unsigned long last_targ_count
= 0;
1056 if (files
.ht_fill
!= last_targ_count
)
1058 unsigned long max
= EXPANSION_INCREMENT (strlen (value
));
1061 struct file
**fp
= (struct file
**) files
.ht_vec
;
1062 struct file
**end
= &fp
[files
.ht_size
];
1064 /* Make sure we have at least MAX bytes in the allocated buffer. */
1065 value
= xrealloc (value
, max
);
1069 for (; fp
< end
; ++fp
)
1070 if (!HASH_VACANT (*fp
) && (*fp
)->is_target
)
1072 struct file
*f
= *fp
;
1073 int l
= strlen (f
->name
);
1078 unsigned long off
= p
- value
;
1080 max
+= EXPANSION_INCREMENT (l
+ 1);
1081 value
= xrealloc (value
, max
);
1085 memcpy (p
, f
->name
, l
);
1091 last_targ_count
= files
.ht_fill
;
1098 init_hash_files (void)
1100 hash_init (&files
, 1000, file_hash_1
, file_hash_2
, file_hash_cmp
);