1 /* Target file hash table management for GNU Make.
2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 2002 Free Software Foundation, Inc.
4 This file is part of GNU Make.
6 GNU Make is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Make is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Make; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
34 /* Remember whether snap_deps has been invoked: we need this to be sure we
35 don't add new rules (via $(eval ...)) afterwards. In the future it would
36 be nice to support this, but it means we'd need to re-run snap_deps() or
37 at least its functionality... it might mean changing snap_deps() to be run
38 per-file, so we can invoke it after the eval... or remembering which files
39 in the hash have been snapped (a new boolean flag?) and having snap_deps()
40 only work on files which have not yet been snapped. */
43 /* Hash table of files the makefile knows how to make. */
46 file_hash_1 (const void *key
)
48 return_ISTRING_HASH_1 (((struct file
const *) key
)->hname
);
52 file_hash_2 (const void *key
)
54 return_ISTRING_HASH_2 (((struct file
const *) key
)->hname
);
58 file_hash_cmp (const void *x
, const void *y
)
60 return_ISTRING_COMPARE (((struct file
const *) x
)->hname
,
61 ((struct file
const *) y
)->hname
);
65 #define FILE_BUCKETS 1007
67 static struct hash_table files
;
69 /* Whether or not .SECONDARY with no prerequisites was given. */
70 static int all_secondary
= 0;
72 /* Access the hash table of all file records.
73 lookup_file given a name, return the struct file * for that name,
74 or nil if there is none.
75 enter_file similar, but create one if there is none. */
78 lookup_file (char *name
)
80 register struct file
*f
;
82 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
83 register char *lname
, *ln
;
86 assert (*name
!= '\0');
88 /* This is also done in parse_file_seq, so this is redundant
89 for names read from makefiles. It is here for names passed
90 on the command line. */
92 # ifndef WANT_CASE_SENSITIVE_TARGETS
95 lname
= (char *) malloc (strlen (name
) + 1);
96 for (n
= name
, ln
= lname
; *n
!= '\0'; ++n
, ++ln
)
97 *ln
= isupper ((unsigned char)*n
) ? tolower ((unsigned char)*n
) : *n
;
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. */
126 file_key
.hname
= name
;
127 f
= (struct file
*) hash_find_item (&files
, &file_key
);
128 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
135 enter_file (char *name
)
137 register struct file
*f
;
138 register struct file
*new;
139 register struct file
**file_slot
;
140 struct file file_key
;
141 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
145 assert (*name
!= '\0');
147 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
150 lname
= (char *) malloc (strlen (name
) + 1);
151 for (n
= name
, ln
= lname
; *n
!= '\0'; ++n
, ++ln
)
153 if (isupper ((unsigned char)*n
))
154 *ln
= tolower ((unsigned char)*n
);
160 /* Creates a possible leak, old value of name is unreachable, but I
161 currently don't know how to fix it. */
166 file_key
.hname
= name
;
167 file_slot
= (struct file
**) hash_find_slot (&files
, &file_key
);
169 if (! HASH_VACANT (f
) && !f
->double_colon
)
171 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
177 new = (struct file
*) xmalloc (sizeof (struct file
));
178 bzero ((char *) new, sizeof (struct file
));
179 new->name
= new->hname
= name
;
180 new->update_status
= -1;
183 hash_insert_at (&files
, new, file_slot
);
186 /* There is already a double-colon entry for this file. */
187 new->double_colon
= f
;
196 /* Rename FILE to NAME. This is not as simple as resetting
197 the `name' member, since it must be put in a new hash bucket,
198 and possibly merged with an existing file called NAME. */
201 rename_file (struct file
*from_file
, char *to_hname
)
203 rehash_file (from_file
, to_hname
);
206 from_file
->name
= from_file
->hname
;
207 from_file
= from_file
->prev
;
211 /* Rehash FILE to NAME. This is not as simple as resetting
212 the `hname' member, since it must be put in a new hash bucket,
213 and possibly merged with an existing file called NAME. */
216 rehash_file (struct file
*from_file
, char *to_hname
)
218 struct file file_key
;
219 struct file
**file_slot
;
220 struct file
*to_file
;
221 struct file
*deleted_file
;
224 file_key
.hname
= to_hname
;
225 if (0 == file_hash_cmp (from_file
, &file_key
))
228 file_key
.hname
= from_file
->hname
;
229 while (from_file
->renamed
!= 0)
230 from_file
= from_file
->renamed
;
231 if (file_hash_cmp (from_file
, &file_key
))
232 /* hname changed unexpectedly */
235 deleted_file
= hash_delete (&files
, from_file
);
236 if (deleted_file
!= from_file
)
237 /* from_file isn't the one stored in files */
240 file_key
.hname
= to_hname
;
241 file_slot
= (struct file
**) hash_find_slot (&files
, &file_key
);
242 to_file
= *file_slot
;
244 from_file
->hname
= to_hname
;
245 for (f
= from_file
->double_colon
; f
!= 0; f
= f
->prev
)
248 if (HASH_VACANT (to_file
))
249 hash_insert_at (&files
, from_file
, file_slot
);
252 /* TO_FILE already exists under TO_HNAME.
253 We must retain TO_FILE and merge FROM_FILE into it. */
255 if (from_file
->cmds
!= 0)
257 if (to_file
->cmds
== 0)
258 to_file
->cmds
= from_file
->cmds
;
259 else if (from_file
->cmds
!= to_file
->cmds
)
261 /* We have two sets of commands. We will go with the
262 one given in the rule explicitly mentioning this name,
263 but give a message to let the user know what's going on. */
264 if (to_file
->cmds
->fileinfo
.filenm
!= 0)
265 error (&from_file
->cmds
->fileinfo
,
266 _("Commands were specified for file `%s' at %s:%lu,"),
267 from_file
->name
, to_file
->cmds
->fileinfo
.filenm
,
268 to_file
->cmds
->fileinfo
.lineno
);
270 error (&from_file
->cmds
->fileinfo
,
271 _("Commands for file `%s' were found by implicit rule search,"),
273 error (&from_file
->cmds
->fileinfo
,
274 _("but `%s' is now considered the same file as `%s'."),
275 from_file
->name
, to_hname
);
276 error (&from_file
->cmds
->fileinfo
,
277 _("Commands for `%s' will be ignored in favor of those for `%s'."),
278 to_hname
, from_file
->name
);
282 /* Merge the dependencies of the two files. */
284 if (to_file
->deps
== 0)
285 to_file
->deps
= from_file
->deps
;
288 register struct dep
*deps
= to_file
->deps
;
289 while (deps
->next
!= 0)
291 deps
->next
= from_file
->deps
;
294 merge_variable_set_lists (&to_file
->variables
, from_file
->variables
);
296 if (to_file
->double_colon
&& from_file
->is_target
&& !from_file
->double_colon
)
297 fatal (NILF
, _("can't rename single-colon `%s' to double-colon `%s'"),
298 from_file
->name
, to_hname
);
299 if (!to_file
->double_colon
&& from_file
->double_colon
)
301 if (to_file
->is_target
)
302 fatal (NILF
, _("can't rename double-colon `%s' to single-colon `%s'"),
303 from_file
->name
, to_hname
);
305 to_file
->double_colon
= from_file
->double_colon
;
308 if (from_file
->last_mtime
> to_file
->last_mtime
)
309 /* %%% Kludge so -W wins on a file that gets vpathized. */
310 to_file
->last_mtime
= from_file
->last_mtime
;
312 to_file
->mtime_before_update
= from_file
->mtime_before_update
;
314 #define MERGE(field) to_file->field |= from_file->field
316 MERGE (tried_implicit
);
322 MERGE (ignore_vpath
);
325 from_file
->renamed
= to_file
;
329 /* Remove all nonprecious intermediate files.
330 If SIG is nonzero, this was caused by a fatal signal,
331 meaning that a different message will be printed, and
332 the message will go to stderr rather than stdout. */
335 remove_intermediates (int sig
)
337 register struct file
**file_slot
;
338 register struct file
**file_end
;
341 /* If there's no way we will ever remove anything anyway, punt early. */
342 if (question_flag
|| touch_flag
|| all_secondary
)
345 if (sig
&& just_print_flag
)
348 file_slot
= (struct file
**) files
.ht_vec
;
349 file_end
= file_slot
+ files
.ht_size
;
350 for ( ; file_slot
< file_end
; file_slot
++)
351 if (! HASH_VACANT (*file_slot
))
353 register struct file
*f
= *file_slot
;
354 /* Is this file eligible for automatic deletion?
355 Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
356 given on the command-line, and it's either a -include makefile or
357 it's not precious. */
358 if (f
->intermediate
&& (f
->dontcare
|| !f
->precious
)
359 && !f
->secondary
&& !f
->cmd_target
)
362 if (f
->update_status
== -1)
363 /* If nothing would have created this file yet,
364 don't print an "rm" command for it. */
370 status
= unlink (f
->name
);
371 if (status
< 0 && errno
== ENOENT
)
377 error (NILF
, _("*** Deleting intermediate file `%s'"), f
->name
);
381 DB (DB_BASIC
, (_("Removing intermediate files...\n")));
386 fputs ("rm ", stdout
);
391 fputs (f
->name
, stdout
);
396 perror_with_name ("unlink: ", f
->name
);
409 parse_prereqs (char *p
)
411 struct dep
*new = (struct dep
*)
412 multi_glob (parse_file_seq (&p
, '|', sizeof (struct dep
), 1),
413 sizeof (struct dep
));
417 /* Files that follow '|' are "order-only" prerequisites that satisfy the
418 dependency by existing: their modification times are irrelevant. */
423 multi_glob (parse_file_seq (&p
, '\0', sizeof (struct dep
), 1),
424 sizeof (struct dep
));
431 for (dp
= new; dp
->next
!= NULL
; dp
= dp
->next
)
436 for (; ood
!= NULL
; ood
= ood
->next
)
437 ood
->ignore_mtime
= 1;
444 /* Set the intermediate flag. */
447 set_intermediate (const void *item
)
449 struct file
*f
= (struct file
*) item
;
453 /* Expand and parse each dependency line. */
455 expand_deps (struct file
*f
)
458 struct dep
*old
= f
->deps
;
459 unsigned int last_dep_has_cmds
= f
->updating
;
465 for (d
= old
; d
!= 0; d
= d
->next
)
467 struct dep
*new, *d1
;
473 /* Create the dependency list.
474 If we're not doing 2nd expansion, then it's just the name. */
475 if (! d
->need_2nd_expansion
)
479 /* If it's from a static pattern rule, convert the patterns into
480 "$*" so they'll expand properly. */
481 if (d
->staticpattern
)
484 char *buffer
= variable_expand ("");
486 o
= subst_expand (buffer
, d
->name
, "%", "$*", 1, 2, 0);
489 d
->name
= savestring (buffer
, o
- buffer
);
490 d
->staticpattern
= 0;
493 /* We are going to do second expansion so initialize file variables
497 initialize_file_variables (f
, 0);
501 set_file_variables (f
);
503 p
= variable_expand_for_file (d
->name
, f
);
506 /* Parse the prerequisites. */
507 new = parse_prereqs (p
);
509 /* If this dep list was from a static pattern rule, expand the %s. We
510 use patsubst_expand to translate the prerequisites' patterns into
511 plain prerequisite names. */
512 if (new && d
->staticpattern
)
515 char *buffer
= variable_expand ("");
516 struct dep
*dp
= new, *dl
= 0;
520 char *percent
= find_percent (dp
->name
);
523 /* We have to handle empty stems specially, because that
524 would be equivalent to $(patsubst %,dp->name,) which
525 will always be empty. */
526 if (f
->stem
[0] == '\0')
527 /* This needs memmove() in ISO C. */
528 bcopy (percent
+1, percent
, strlen (percent
));
531 char *o
= patsubst_expand (buffer
, f
->stem
, pattern
,
539 dp
->name
= savestring (buffer
, o
- buffer
);
543 /* If the name expanded to the empty string, ignore it. */
544 if (dp
->name
[0] == '\0')
548 dp
= new = new->next
;
550 dp
= dl
->next
= dp
->next
;
560 /* Enter them as files. */
561 for (d1
= new; d1
!= 0; d1
= d1
->next
)
563 d1
->file
= lookup_file (d1
->name
);
565 d1
->file
= enter_file (d1
->name
);
569 d1
->staticpattern
= 0;
570 d1
->need_2nd_expansion
= 0;
573 /* Add newly parsed deps to f->deps. If this is the last dependency
574 line and this target has commands then put it in front so the
575 last dependency line (the one with commands) ends up being the
576 first. This is important because people expect $< to hold first
577 prerequisite from the rule with commands. If it is not the last
578 dependency line or the rule does not have commands then link it
579 at the end so it appears in makefile order. */
583 if (d
->next
== 0 && last_dep_has_cmds
)
586 for (d_ptr
= &new; *d_ptr
; d_ptr
= &(*d_ptr
)->next
)
595 for (d_ptr
= &f
->deps
; *d_ptr
; d_ptr
= &(*d_ptr
)->next
)
603 free_ns_chain ((struct nameseq
*) old
);
606 /* For each dependency of each file, make the `struct dep' point
607 at the appropriate `struct file' (which may have to be created).
609 Also mark the files depended on by .PRECIOUS, .PHONY, .SILENT,
610 and various other special targets. */
618 struct file
**file_slot_0
;
619 struct file
**file_slot
;
620 struct file
**file_end
;
622 /* Perform second expansion and enter each dependency
625 /* Expand .SUFFIXES first; it's dependencies are used for
627 for (f
= lookup_file (".SUFFIXES"); f
!= 0; f
= f
->prev
)
630 /* We must use hash_dump (), because within this loop
631 we might add new files to the table, possibly causing
632 an in-situ table expansion. */
633 file_slot_0
= (struct file
**) hash_dump (&files
, 0, 0);
634 file_end
= file_slot_0
+ files
.ht_fill
;
635 for (file_slot
= file_slot_0
; file_slot
< file_end
; file_slot
++)
636 for (f
= *file_slot
; f
!= 0; f
= f
->prev
)
638 if (strcmp (f
->name
, ".SUFFIXES") != 0)
643 for (f
= lookup_file (".PRECIOUS"); f
!= 0; f
= f
->prev
)
644 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
645 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
648 for (f
= lookup_file (".LOW_RESOLUTION_TIME"); f
!= 0; f
= f
->prev
)
649 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
650 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
651 f2
->low_resolution_time
= 1;
653 for (f
= lookup_file (".PHONY"); f
!= 0; f
= f
->prev
)
654 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
655 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
657 /* Mark this file as phony nonexistent target. */
660 f2
->last_mtime
= NONEXISTENT_MTIME
;
661 f2
->mtime_before_update
= NONEXISTENT_MTIME
;
664 for (f
= lookup_file (".INTERMEDIATE"); f
!= 0; f
= f
->prev
)
666 /* .INTERMEDIATE with deps listed
667 marks those deps as intermediate files. */
668 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
669 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
670 f2
->intermediate
= 1;
671 /* .INTERMEDIATE with no deps does nothing.
672 Marking all files as intermediates is useless
673 since the goal targets would be deleted after they are built. */
676 for (f
= lookup_file (".SECONDARY"); f
!= 0; f
= f
->prev
)
678 /* .SECONDARY with deps listed
679 marks those deps as intermediate files
680 in that they don't get rebuilt if not actually needed;
681 but unlike real intermediate files,
682 these are not deleted after make finishes. */
684 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
685 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
686 f2
->intermediate
= f2
->secondary
= 1;
687 /* .SECONDARY with no deps listed marks *all* files that way. */
691 hash_map (&files
, set_intermediate
);
695 f
= lookup_file (".EXPORT_ALL_VARIABLES");
696 if (f
!= 0 && f
->is_target
)
697 export_all_variables
= 1;
699 f
= lookup_file (".IGNORE");
700 if (f
!= 0 && f
->is_target
)
703 ignore_errors_flag
= 1;
705 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
706 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
707 f2
->command_flags
|= COMMANDS_NOERROR
;
710 f
= lookup_file (".SILENT");
711 if (f
!= 0 && f
->is_target
)
716 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
717 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
718 f2
->command_flags
|= COMMANDS_SILENT
;
721 f
= lookup_file (".POSIX");
722 if (f
!= 0 && f
->is_target
)
725 f
= lookup_file (".NOTPARALLEL");
726 if (f
!= 0 && f
->is_target
)
729 /* Remember that we've done this. */
733 /* Set the `command_state' member of FILE and all its `also_make's. */
736 set_command_state (struct file
*file
, enum cmd_state state
)
740 file
->command_state
= state
;
742 for (d
= file
->also_make
; d
!= 0; d
= d
->next
)
743 d
->file
->command_state
= state
;
746 /* Convert an external file timestamp to internal form. */
749 file_timestamp_cons (const char *fname
, time_t s
, int ns
)
751 int offset
= ORDINARY_MTIME_MIN
+ (FILE_TIMESTAMP_HI_RES
? ns
: 0);
752 FILE_TIMESTAMP product
= (FILE_TIMESTAMP
) s
<< FILE_TIMESTAMP_LO_BITS
;
753 FILE_TIMESTAMP ts
= product
+ offset
;
755 if (! (s
<= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX
)
756 && product
<= ts
&& ts
<= ORDINARY_MTIME_MAX
))
758 char buf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
759 ts
= s
<= OLD_MTIME
? ORDINARY_MTIME_MIN
: ORDINARY_MTIME_MAX
;
760 file_timestamp_sprintf (buf
, ts
);
761 error (NILF
, _("%s: Timestamp out of range; substituting %s"),
762 fname
? fname
: _("Current time"), buf
);
768 /* Return the current time as a file timestamp, setting *RESOLUTION to
771 file_timestamp_now (int *resolution
)
777 /* Don't bother with high-resolution clocks if file timestamps have
778 only one-second resolution. The code below should work, but it's
779 not worth the hassle of debugging it on hosts where it fails. */
780 #if FILE_TIMESTAMP_HI_RES
781 # if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME
783 struct timespec timespec
;
784 if (clock_gettime (CLOCK_REALTIME
, ×pec
) == 0)
788 ns
= timespec
.tv_nsec
;
793 # if HAVE_GETTIMEOFDAY
795 struct timeval timeval
;
796 if (gettimeofday (&timeval
, 0) == 0)
800 ns
= timeval
.tv_usec
* 1000;
808 s
= time ((time_t *) 0);
811 #if FILE_TIMESTAMP_HI_RES
815 return file_timestamp_cons (0, s
, ns
);
818 /* Place into the buffer P a printable representation of the file
821 file_timestamp_sprintf (char *p
, FILE_TIMESTAMP ts
)
823 time_t t
= FILE_TIMESTAMP_S (ts
);
824 struct tm
*tm
= localtime (&t
);
827 sprintf (p
, "%04d-%02d-%02d %02d:%02d:%02d",
828 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
829 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
831 sprintf (p
, "%ld", (long) t
);
833 sprintf (p
, "%lu", (unsigned long) t
);
836 /* Append nanoseconds as a fraction, but remove trailing zeros.
837 We don't know the actual timestamp resolution, since clock_getres
838 applies only to local times, whereas this timestamp might come
839 from a remote filesystem. So removing trailing zeros is the
840 best guess that we can do. */
841 sprintf (p
, ".%09d", FILE_TIMESTAMP_NS (ts
));
850 /* Print the data base of files. */
853 print_file (const void *item
)
855 struct file
*f
= (struct file
*) item
;
861 puts (_("# Not a target:"));
862 printf ("%s:%s", f
->name
, f
->double_colon
? ":" : "");
864 /* Print all normal dependencies; note any order-only deps. */
865 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
866 if (! d
->ignore_mtime
)
867 printf (" %s", dep_name (d
));
871 /* Print order-only deps, if we have any. */
874 printf (" | %s", dep_name (ood
));
875 for (d
= ood
->next
; d
!= 0; d
= d
->next
)
877 printf (" %s", dep_name (d
));
883 puts (_("# Precious file (prerequisite of .PRECIOUS)."));
885 puts (_("# Phony target (prerequisite of .PHONY)."));
887 puts (_("# Command-line target."));
889 puts (_("# A default, MAKEFILES, or -include/sinclude makefile."));
890 puts (f
->tried_implicit
891 ? _("# Implicit rule search has been done.")
892 : _("# Implicit rule search has not been done."));
894 printf (_("# Implicit/static pattern stem: `%s'\n"), f
->stem
);
896 puts (_("# File is an intermediate prerequisite."));
897 if (f
->also_make
!= 0)
899 fputs (_("# Also makes:"), stdout
);
900 for (d
= f
->also_make
; d
!= 0; d
= d
->next
)
901 printf (" %s", dep_name (d
));
904 if (f
->last_mtime
== UNKNOWN_MTIME
)
905 puts (_("# Modification time never checked."));
906 else if (f
->last_mtime
== NONEXISTENT_MTIME
)
907 puts (_("# File does not exist."));
908 else if (f
->last_mtime
== OLD_MTIME
)
909 puts (_("# File is very old."));
912 char buf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
913 file_timestamp_sprintf (buf
, f
->last_mtime
);
914 printf (_("# Last modified %s\n"), buf
);
917 ? _("# File has been updated.") : _("# File has not been updated."));
918 switch (f
->command_state
)
921 puts (_("# Commands currently running (THIS IS A BUG)."));
923 case cs_deps_running
:
924 puts (_("# Dependencies commands running (THIS IS A BUG)."));
928 switch (f
->update_status
)
933 puts (_("# Successfully updated."));
936 assert (question_flag
);
937 puts (_("# Needs to be updated (-q is set)."));
940 puts (_("# Failed to be updated."));
943 puts (_("# Invalid value in `update_status' member!"));
950 puts (_("# Invalid value in `command_state' member!"));
956 if (f
->variables
!= 0)
957 print_file_variables (f
);
960 print_commands (f
->cmds
);
963 print_file ((const void *) f
->prev
);
967 print_file_data_base (void)
969 puts (_("\n# Files"));
971 hash_map (&files
, print_file
);
973 fputs (_("\n# files hash-table stats:\n# "), stdout
);
974 hash_print_stats (&files
, stdout
);
977 #define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500)
980 build_target_list (char *value
)
982 static unsigned long last_targ_count
= 0;
984 if (files
.ht_fill
!= last_targ_count
)
986 unsigned long max
= EXPANSION_INCREMENT (strlen (value
));
989 struct file
**fp
= (struct file
**) files
.ht_vec
;
990 struct file
**end
= &fp
[files
.ht_size
];
992 /* Make sure we have at least MAX bytes in the allocated buffer. */
993 value
= xrealloc (value
, max
);
997 for (; fp
< end
; ++fp
)
998 if (!HASH_VACANT (*fp
) && (*fp
)->is_target
)
1000 struct file
*f
= *fp
;
1001 int l
= strlen (f
->name
);
1006 unsigned long off
= p
- value
;
1008 max
+= EXPANSION_INCREMENT (l
+ 1);
1009 value
= xrealloc (value
, max
);
1013 bcopy (f
->name
, p
, l
);
1019 last_targ_count
= files
.ht_fill
;
1026 init_hash_files (void)
1028 hash_init (&files
, 1000, file_hash_1
, file_hash_2
, file_hash_cmp
);