1 /* Target file management for GNU Make.
2 Copyright (C) 1988-2013 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 (! verify_flag || 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)
185 new = xcalloc (sizeof (struct file));
186 new->name = new->hname = name;
187 new->update_status = us_none;
192 hash_insert_at (&files, new, file_slot);
196 /* There is already a double-colon entry for this file. */
197 new->double_colon = f;
205 /* Rehash FILE to NAME. This is not as simple as resetting
206 the 'hname' member, since it must be put in a new hash bucket,
207 and possibly merged with an existing file called NAME. */
210 rehash_file (struct file *from_file, const char *to_hname)
212 struct file file_key;
213 struct file **file_slot;
214 struct file *to_file;
215 struct file *deleted_file;
218 /* If it's already that name, we're done. */
219 from_file->builtin = 0;
220 file_key.hname = to_hname;
221 if (! file_hash_cmp (from_file, &file_key))
224 /* Find the end of the renamed list for the "from" file. */
225 file_key.hname = from_file->hname;
226 while (from_file->renamed != 0)
227 from_file = from_file->renamed;
228 if (file_hash_cmp (from_file, &file_key))
229 /* hname changed unexpectedly!! */
232 /* Remove the "from" file from the hash. */
233 deleted_file = hash_delete (&files, from_file);
234 if (deleted_file != from_file)
235 /* from_file isn't the one stored in files */
238 /* Find where the newly renamed file will go in the hash. */
239 file_key.hname = to_hname;
240 file_slot = (struct file **) hash_find_slot (&files, &file_key);
241 to_file = *file_slot;
243 /* Change the hash name for this file. */
244 from_file->hname = to_hname;
245 for (f = from_file->double_colon; f != 0; f = f->prev)
248 /* If the new name doesn't exist yet just set it to the renamed file. */
249 if (HASH_VACANT (to_file))
251 hash_insert_at (&files, from_file, file_slot);
255 /* TO_FILE already exists under TO_HNAME.
256 We must retain TO_FILE and merge FROM_FILE into it. */
258 if (from_file->cmds != 0)
260 if (to_file->cmds == 0)
261 to_file->cmds = from_file->cmds;
262 else if (from_file->cmds != to_file->cmds)
264 /* We have two sets of commands. We will go with the
265 one given in the rule explicitly mentioning this name,
266 but give a message to let the user know what's going on. */
267 if (to_file->cmds->fileinfo.filenm != 0)
268 error (&from_file->cmds->fileinfo,
269 _("Recipe was specified for file '%s' at %s:%lu,"),
270 from_file->name, to_file->cmds->fileinfo.filenm,
271 to_file->cmds->fileinfo.lineno);
273 error (&from_file->cmds->fileinfo,
274 _("Recipe for file '%s' was found by implicit rule search,"),
276 error (&from_file->cmds->fileinfo,
277 _("but '%s' is now considered the same file as '%s'."),
278 from_file->name, to_hname);
279 error (&from_file->cmds->fileinfo,
280 _("Recipe for '%s' will be ignored in favor of the one for '%s'."),
281 to_hname, from_file->name);
285 /* Merge the dependencies of the two files. */
287 if (to_file->deps == 0)
288 to_file->deps = from_file->deps;
291 struct dep *deps = to_file->deps;
292 while (deps->next != 0)
294 deps->next = from_file->deps;
297 merge_variable_set_lists (&to_file->variables, from_file->variables);
299 if (to_file->double_colon && from_file->is_target && !from_file->double_colon)
300 fatal (NILF, _("can't rename single-colon '%s' to double-colon '%s'"),
301 from_file->name, to_hname);
302 if (!to_file->double_colon && from_file->double_colon)
304 if (to_file->is_target)
305 fatal (NILF, _("can't rename double-colon '%s' to single-colon '%s'"),
306 from_file->name, to_hname);
308 to_file->double_colon = from_file->double_colon;
311 if (from_file->last_mtime > to_file->last_mtime)
312 /* %%% Kludge so -W wins on a file that gets vpathized. */
313 to_file->last_mtime = from_file->last_mtime;
315 to_file->mtime_before_update = from_file->mtime_before_update;
317 #define MERGE(field) to_file->field |= from_file->field
319 MERGE (tried_implicit);
326 MERGE (ignore_vpath);
329 to_file->builtin = 0;
330 from_file->renamed = to_file;
333 /* Rename FILE to NAME. This is not as simple as resetting
334 the 'name' member, since it must be put in a new hash bucket,
335 and possibly merged with an existing file called NAME. */
338 rename_file (struct file *from_file, const char *to_hname)
340 rehash_file (from_file, to_hname);
343 from_file->name = from_file->hname;
344 from_file = from_file->prev;
348 /* Remove all nonprecious intermediate files.
349 If SIG is nonzero, this was caused by a fatal signal,
350 meaning that a different message will be printed, and
351 the message will go to stderr rather than stdout. */
354 remove_intermediates (int sig)
356 struct file **file_slot;
357 struct file **file_end;
360 /* If there's no way we will ever remove anything anyway, punt early. */
361 if (question_flag || touch_flag || all_secondary)
364 if (sig && just_print_flag)
367 file_slot = (struct file **) files.ht_vec;
368 file_end = file_slot + files.ht_size;
369 for ( ; file_slot < file_end; file_slot++)
370 if (! HASH_VACANT (*file_slot))
372 struct file *f = *file_slot;
373 /* Is this file eligible for automatic deletion?
374 Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
375 given on the command line, and it's either a -include makefile or
376 it's not precious. */
377 if (f->intermediate && (f->dontcare || !f->precious)
378 && !f->secondary && !f->cmd_target)
381 if (f->update_status == us_none)
382 /* If nothing would have created this file yet,
383 don't print an "rm" command for it. */
389 status = unlink (f->name);
390 if (status < 0 && errno == ENOENT)
396 error (NILF, _("*** Deleting intermediate file '%s'"), f->name);
400 DB (DB_BASIC, (_("Removing intermediate files...\n")));
405 fputs ("rm ", stdout);
410 fputs (f->name, stdout);
415 perror_with_name ("unlink: ", f->name);
427 /* Given a string containing prerequisites (fully expanded), break it up into
428 a struct dep list. Enter each of these prereqs into the file database.
431 split_prereqs (char *p)
433 struct dep *new = PARSE_FILE_SEQ (&p, struct dep, MAP_PIPE, NULL,
438 /* Files that follow '|' are "order-only" prerequisites that satisfy the
439 dependency by existing: their modification times are irrelevant. */
443 ood = PARSE_SIMPLE_SEQ (&p, struct dep);
450 for (dp = new; dp->next != NULL; dp = dp->next)
455 for (; ood != NULL; ood = ood->next)
456 ood->ignore_mtime = 1;
462 /* Given a list of prerequisites, enter them into the file database.
463 If STEM is set then first expand patterns using STEM. */
465 enter_prereqs (struct dep *deps, const char *stem)
472 /* If we have a stem, expand the %'s. We use patsubst_expand to translate
473 the prerequisites' patterns into plain prerequisite names. */
476 const char *pattern = "%";
477 char *buffer = variable_expand ("");
478 struct dep *dp = deps, *dl = 0;
483 int nl = strlen (dp->name) + 1;
484 char *nm = alloca (nl);
485 memcpy (nm, dp->name, nl);
486 percent = find_percent (nm);
491 /* We have to handle empty stems specially, because that
492 would be equivalent to $(patsubst %,dp->name,) which
493 will always be empty. */
496 memmove (percent, percent+1, strlen (percent));
497 o = variable_buffer_output (buffer, nm, strlen (nm) + 1);
500 o = patsubst_expand_pat (buffer, stem, pattern, nm,
501 pattern+1, percent+1);
503 /* If the name expanded to the empty string, ignore it. */
504 if (buffer[0] == '\0')
508 dp = deps = deps->next;
510 dp = dl->next = dp->next;
516 dp->name = strcache_add_len (buffer, o - buffer);
519 dp->staticpattern = 1;
525 /* Enter them as files, unless they need a 2nd expansion. */
526 for (d1 = deps; d1 != 0; d1 = d1->next)
528 if (d1->need_2nd_expansion)
531 d1->file = lookup_file (d1->name);
533 d1->file = enter_file (d1->name);
534 d1->staticpattern = 0;
541 /* Set the intermediate flag. */
544 set_intermediate (const void *item)
546 struct file *f = (struct file *) item;
550 /* Expand and parse each dependency line. */
552 expand_deps (struct file *f)
556 const char *file_stem = f->stem;
561 /* Walk through the dependencies. For any dependency that needs 2nd
562 expansion, expand it then insert the result into the list. */
568 struct dep *new, *next;
569 char *name = (char *)d->name;
571 if (! d->name || ! d->need_2nd_expansion)
573 /* This one is all set already. */
579 /* If it's from a static pattern rule, convert the patterns into
580 "$*" so they'll expand properly. */
581 if (d->staticpattern)
583 char *o = variable_expand ("");
584 o = subst_expand (o, name, "%", "$*", 1, 2, 0);
587 d->name = name = xstrdup (variable_buffer);
588 d->staticpattern = 0;
591 /* We're going to do second expansion so initialize file variables for
592 the file. Since the stem for static pattern rules comes from
593 individual dep lines, we will temporarily set f->stem to d->stem. */
596 initialize_file_variables (f, 0);
603 set_file_variables (f);
605 p = variable_expand_for_file (d->name, f);
610 /* At this point we don't need the name anymore: free it. */
613 /* Parse the prerequisites and enter them into the file database. */
614 new = enter_prereqs (split_prereqs (p), d->stem);
616 /* If there were no prereqs here (blank!) then throw this one out. */
625 /* Add newly parsed prerequisites. */
628 for (dp = &new->next, d = new->next; d != 0; dp = &d->next, d = d->next)
635 /* Reset the updating flag. */
638 reset_updating (const void *item)
640 struct file *f = (struct file *) item;
644 /* For each dependency of each file, make the 'struct dep' point
645 at the appropriate 'struct file' (which may have to be created).
647 Also mark the files depended on by .PRECIOUS, .PHONY, .SILENT,
648 and various other special targets. */
657 /* Remember that we've done this. Once we start snapping deps we can no
658 longer define new targets. */
661 /* Perform second expansion and enter each dependency name as a file. We
662 must use hash_dump() here because within these loops we likely add new
663 files to the table, possibly causing an in-situ table expansion.
665 We only need to do this if second_expansion has been defined; if it
666 hasn't then all deps were expanded as the makefile was read in. If we
667 ever change make to be able to unset .SECONDARY_EXPANSION this will have
670 if (second_expansion)
672 struct file **file_slot_0 = (struct file **) hash_dump (&files, 0, 0);
673 struct file **file_end = file_slot_0 + files.ht_fill;
674 struct file **file_slot;
675 const char *suffixes;
677 /* Expand .SUFFIXES: its prerequisites are used for $$* calc. */
678 f = lookup_file (".SUFFIXES");
679 suffixes = f ? f->name : 0;
680 for (; f != 0; f = f->prev)
683 /* For every target that's not .SUFFIXES, expand its prerequisites. */
685 for (file_slot = file_slot_0; file_slot < file_end; file_slot++)
686 for (f = *file_slot; f != 0; f = f->prev)
687 if (f->name != suffixes)
692 /* We're not doing second expansion, so reset updating. */
693 hash_map (&files, reset_updating);
695 /* Now manage all the special targets. */
697 for (f = lookup_file (".PRECIOUS"); f != 0; f = f->prev)
698 for (d = f->deps; d != 0; d = d->next)
699 for (f2 = d->file; f2 != 0; f2 = f2->prev)
702 for (f = lookup_file (".LOW_RESOLUTION_TIME"); f != 0; f = f->prev)
703 for (d = f->deps; d != 0; d = d->next)
704 for (f2 = d->file; f2 != 0; f2 = f2->prev)
705 f2->low_resolution_time = 1;
707 for (f = lookup_file (".PHONY"); f != 0; f = f->prev)
708 for (d = f->deps; d != 0; d = d->next)
709 for (f2 = d->file; f2 != 0; f2 = f2->prev)
711 /* Mark this file as phony nonexistent target. */
714 f2->last_mtime = NONEXISTENT_MTIME;
715 f2->mtime_before_update = NONEXISTENT_MTIME;
718 for (f = lookup_file (".INTERMEDIATE"); f != 0; f = f->prev)
719 /* Mark .INTERMEDIATE deps as intermediate files. */
720 for (d = f->deps; d != 0; d = d->next)
721 for (f2 = d->file; f2 != 0; f2 = f2->prev)
722 f2->intermediate = 1;
723 /* .INTERMEDIATE with no deps does nothing.
724 Marking all files as intermediates is useless since the goal targets
725 would be deleted after they are built. */
727 for (f = lookup_file (".SECONDARY"); f != 0; f = f->prev)
728 /* Mark .SECONDARY deps as both intermediate and secondary. */
730 for (d = f->deps; d != 0; d = d->next)
731 for (f2 = d->file; f2 != 0; f2 = f2->prev)
732 f2->intermediate = f2->secondary = 1;
733 /* .SECONDARY with no deps listed marks *all* files that way. */
737 hash_map (&files, set_intermediate);
740 f = lookup_file (".EXPORT_ALL_VARIABLES");
741 if (f != 0 && f->is_target)
742 export_all_variables = 1;
744 f = lookup_file (".IGNORE");
745 if (f != 0 && f->is_target)
748 ignore_errors_flag = 1;
750 for (d = f->deps; d != 0; d = d->next)
751 for (f2 = d->file; f2 != 0; f2 = f2->prev)
752 f2->command_flags |= COMMANDS_NOERROR;
755 f = lookup_file (".SILENT");
756 if (f != 0 && f->is_target)
761 for (d = f->deps; d != 0; d = d->next)
762 for (f2 = d->file; f2 != 0; f2 = f2->prev)
763 f2->command_flags |= COMMANDS_SILENT;
766 f = lookup_file (".NOTPARALLEL");
767 if (f != 0 && f->is_target)
770 #ifndef NO_MINUS_C_MINUS_O
771 /* If .POSIX was defined, remove OUTPUT_OPTION to comply. */
772 /* This needs more work: what if the user sets this in the makefile?
774 define_variable_cname ("OUTPUT_OPTION", "", o_default, 1);
779 /* Set the 'command_state' member of FILE and all its 'also_make's. */
782 set_command_state (struct file *file, enum cmd_state state)
786 file->command_state = state;
788 for (d = file->also_make; d != 0; d = d->next)
789 d->file->command_state = state;
792 /* Convert an external file timestamp to internal form. */
795 file_timestamp_cons (const char *fname, time_t stamp, long int ns)
797 int offset = ORDINARY_MTIME_MIN + (FILE_TIMESTAMP_HI_RES ? ns : 0);
798 FILE_TIMESTAMP s = stamp;
799 FILE_TIMESTAMP product = (FILE_TIMESTAMP) s << FILE_TIMESTAMP_LO_BITS;
800 FILE_TIMESTAMP ts = product + offset;
802 if (! (s <= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX)
803 && product <= ts && ts <= ORDINARY_MTIME_MAX))
805 char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
806 ts = s <= OLD_MTIME ? ORDINARY_MTIME_MIN : ORDINARY_MTIME_MAX;
807 file_timestamp_sprintf (buf, ts);
808 error (NILF, _("%s: Timestamp out of range; substituting %s"),
809 fname ? fname : _("Current time"), buf);
815 /* Return the current time as a file timestamp, setting *RESOLUTION to
818 file_timestamp_now (int *resolution)
824 /* Don't bother with high-resolution clocks if file timestamps have
825 only one-second resolution. The code below should work, but it's
826 not worth the hassle of debugging it on hosts where it fails. */
827 #if FILE_TIMESTAMP_HI_RES
828 # if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME
830 struct timespec timespec;
831 if (clock_gettime (CLOCK_REALTIME, ×pec) == 0)
835 ns = timespec.tv_nsec;
840 # if HAVE_GETTIMEOFDAY
842 struct timeval timeval;
843 if (gettimeofday (&timeval, 0) == 0)
847 ns = timeval.tv_usec * 1000;
855 s = time ((time_t *) 0);
858 #if FILE_TIMESTAMP_HI_RES
862 return file_timestamp_cons (0, s, ns);
865 /* Place into the buffer P a printable representation of the file
868 file_timestamp_sprintf (char *p, FILE_TIMESTAMP ts)
870 time_t t = FILE_TIMESTAMP_S (ts);
871 struct tm *tm = localtime (&t);
874 sprintf (p, "%04d-%02d-%02d %02d:%02d:%02d",
875 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
876 tm->tm_hour, tm->tm_min, tm->tm_sec);
878 sprintf (p, "%ld", (long) t);
880 sprintf (p, "%lu", (unsigned long) t);
883 /* Append nanoseconds as a fraction, but remove trailing zeros. We don't
884 know the actual timestamp resolution, since clock_getres applies only to
885 local times, whereas this timestamp might come from a remote filesystem.
886 So removing trailing zeros is the best guess that we can do. */
887 sprintf (p, ".%09d", FILE_TIMESTAMP_NS (ts));
896 /* Print the data base of files. */
899 print_prereqs (const struct dep *deps)
901 const struct dep *ood = 0;
903 /* Print all normal dependencies; note any order-only deps. */
904 for (; deps != 0; deps = deps->next)
905 if (! deps->ignore_mtime)
906 printf (" %s", dep_name (deps));
910 /* Print order-only deps, if we have any. */
913 printf (" | %s", dep_name (ood));
914 for (ood = ood->next; ood != 0; ood = ood->next)
915 if (ood->ignore_mtime)
916 printf (" %s", dep_name (ood));
923 print_file (const void *item)
925 const struct file *f = item;
927 /* If we're not using builtin targets, don't show them.
929 Ideally we'd be able to delete them altogether but currently there's no
930 facility to ever delete a file once it's been added. */
931 if (no_builtin_rules_flag && f->builtin)
936 if (f->cmds && f->cmds->recipe_prefix != cmd_prefix)
938 fputs (".RECIPEPREFIX = ", stdout);
939 cmd_prefix = f->cmds->recipe_prefix;
940 if (cmd_prefix != RECIPEPREFIX_DEFAULT)
941 putchar (cmd_prefix);
945 if (f->variables != 0)
946 print_target_variables (f);
949 puts (_("# Not a target:"));
950 printf ("%s:%s", f->name, f->double_colon ? ":" : "");
951 print_prereqs (f->deps);
954 puts (_("# Precious file (prerequisite of .PRECIOUS)."));
956 puts (_("# Phony target (prerequisite of .PHONY)."));
958 puts (_("# Command line target."));
960 puts (_("# A default, MAKEFILES, or -include/sinclude makefile."));
962 puts (_("# Builtin rule"));
963 puts (f->tried_implicit
964 ? _("# Implicit rule search has been done.")
965 : _("# Implicit rule search has not been done."));
967 printf (_("# Implicit/static pattern stem: '%s'\n"), f->stem);
969 puts (_("# File is an intermediate prerequisite."));
970 if (f->also_make != 0)
973 fputs (_("# Also makes:"), stdout);
974 for (d = f->also_make; d != 0; d = d->next)
975 printf (" %s", dep_name (d));
978 if (f->last_mtime == UNKNOWN_MTIME)
979 puts (_("# Modification time never checked."));
980 else if (f->last_mtime == NONEXISTENT_MTIME)
981 puts (_("# File does not exist."));
982 else if (f->last_mtime == OLD_MTIME)
983 puts (_("# File is very old."));
986 char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
987 file_timestamp_sprintf (buf, f->last_mtime);
988 printf (_("# Last modified %s\n"), buf);
991 ? _("# File has been updated.") : _("# File has not been updated."));
992 switch (f->command_state)
995 puts (_("# Recipe currently running (THIS IS A BUG)."));
997 case cs_deps_running:
998 puts (_("# Dependencies recipe running (THIS IS A BUG)."));
1000 case cs_not_started:
1002 switch (f->update_status)
1007 puts (_("# Successfully updated."));
1010 assert (question_flag);
1011 puts (_("# Needs to be updated (-q is set)."));
1014 puts (_("# Failed to be updated."));
1019 puts (_("# Invalid value in 'command_state' member!"));
1025 if (f->variables != 0)
1026 print_file_variables (f);
1029 print_commands (f->cmds);
1032 print_file ((const void *) f->prev);
1036 print_file_data_base (void)
1038 puts (_("\n# Files"));
1040 hash_map (&files, print_file);
1042 fputs (_("\n# files hash-table stats:\n# "), stdout);
1043 hash_print_stats (&files, stdout);
1046 /* Verify the integrity of the data base of files. */
1048 #define VERIFY_CACHED(_p,_n) \
1050 if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \
1051 error (NULL, _("%s: Field '%s' not cached: %s"), _p->name, # _n, _p->_n); \
1055 verify_file (const void *item)
1057 const struct file *f = item;
1058 const struct dep *d;
1060 VERIFY_CACHED (f, name);
1061 VERIFY_CACHED (f, hname);
1062 VERIFY_CACHED (f, vpath);
1063 VERIFY_CACHED (f, stem);
1065 /* Check the deps. */
1066 for (d = f->deps; d != 0; d = d->next)
1068 if (! d->need_2nd_expansion)
1069 VERIFY_CACHED (d, name);
1070 VERIFY_CACHED (d, stem);
1075 verify_file_data_base (void)
1077 hash_map (&files, verify_file);
1080 #define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500)
1083 build_target_list (char *value)
1085 static unsigned long last_targ_count = 0;
1087 if (files.ht_fill != last_targ_count)
1089 unsigned long max = EXPANSION_INCREMENT (strlen (value));
1092 struct file **fp = (struct file **) files.ht_vec;
1093 struct file **end = &fp[files.ht_size];
1095 /* Make sure we have at least MAX bytes in the allocated buffer. */
1096 value = xrealloc (value, max);
1100 for (; fp < end; ++fp)
1101 if (!HASH_VACANT (*fp) && (*fp)->is_target)
1103 struct file *f = *fp;
1104 int l = strlen (f->name);
1109 unsigned long off = p - value;
1111 max += EXPANSION_INCREMENT (l + 1);
1112 value = xrealloc (value, max);
1116 memcpy (p, f->name, l);
1122 last_targ_count = files.ht_fill;
1129 init_hash_files (void)
1131 hash_init (&files, 1000, file_hash_1, file_hash_2, file_hash_cmp);