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 Free Software
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 2, or (at your option) any later version.
11 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along with
16 GNU Make; see the file COPYING. If not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */
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.
73 enter_file similar, but create one if there is none. */
76 lookup_file (char *name
)
78 register struct file
*f
;
80 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
81 register char *lname
, *ln
;
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
94 lname
= (char *) malloc (strlen (name
) + 1);
95 for (n
= name
, ln
= lname
; *n
!= '\0'; ++n
, ++ln
)
96 *ln
= isupper ((unsigned char)*n
) ? tolower ((unsigned char)*n
) : *n
;
102 while (name
[0] == '[' && name
[1] == ']' && name
[2] != '\0')
105 while (name
[0] == '.' && name
[1] == '/' && name
[2] != '\0')
109 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
114 /* It was all slashes after a dot. */
125 file_key
.hname
= name
;
126 f
= (struct file
*) hash_find_item (&files
, &file_key
);
127 #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)
151 lname
= (char *) malloc (strlen (name
) + 1);
152 for (n
= name
, ln
= lname
; *n
!= '\0'; ++n
, ++ln
)
154 if (isupper ((unsigned char)*n
))
155 *ln
= tolower ((unsigned char)*n
);
161 /* Creates a possible leak, old value of name is unreachable, but I
162 currently don't know how to fix it. */
167 file_key
.hname
= name
;
168 file_slot
= (struct file
**) hash_find_slot (&files
, &file_key
);
170 if (! HASH_VACANT (f
) && !f
->double_colon
)
172 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
179 new = (struct file
*) xmalloc (sizeof (struct file
));
180 bzero ((char *) new, sizeof (struct file
));
181 new->name
= new->hname
= name
;
182 new->update_status
= -1;
187 hash_insert_at (&files
, new, file_slot
);
191 /* There is already a double-colon entry for this file. */
192 new->double_colon
= f
;
200 /* Rename FILE to NAME. This is not as simple as resetting
201 the `name' member, since it must be put in a new hash bucket,
202 and possibly merged with an existing file called NAME. */
205 rename_file (struct file
*from_file
, char *to_hname
)
207 rehash_file (from_file
, to_hname
);
210 from_file
->name
= from_file
->hname
;
211 from_file
= from_file
->prev
;
215 /* Rehash FILE to NAME. This is not as simple as resetting
216 the `hname' member, since it must be put in a new hash bucket,
217 and possibly merged with an existing file called NAME. */
220 rehash_file (struct file
*from_file
, char *to_hname
)
222 struct file file_key
;
223 struct file
**file_slot
;
224 struct file
*to_file
;
225 struct file
*deleted_file
;
228 file_key
.hname
= to_hname
;
229 if (0 == file_hash_cmp (from_file
, &file_key
))
232 file_key
.hname
= from_file
->hname
;
233 while (from_file
->renamed
!= 0)
234 from_file
= from_file
->renamed
;
235 if (file_hash_cmp (from_file
, &file_key
))
236 /* hname changed unexpectedly */
239 deleted_file
= hash_delete (&files
, from_file
);
240 if (deleted_file
!= from_file
)
241 /* from_file isn't the one stored in files */
244 file_key
.hname
= to_hname
;
245 file_slot
= (struct file
**) hash_find_slot (&files
, &file_key
);
246 to_file
= *file_slot
;
248 from_file
->hname
= to_hname
;
249 for (f
= from_file
->double_colon
; f
!= 0; f
= f
->prev
)
252 if (HASH_VACANT (to_file
))
253 hash_insert_at (&files
, from_file
, file_slot
);
256 /* TO_FILE already exists under TO_HNAME.
257 We must retain TO_FILE and merge FROM_FILE into it. */
259 if (from_file
->cmds
!= 0)
261 if (to_file
->cmds
== 0)
262 to_file
->cmds
= from_file
->cmds
;
263 else if (from_file
->cmds
!= to_file
->cmds
)
265 /* We have two sets of commands. We will go with the
266 one given in the rule explicitly mentioning this name,
267 but give a message to let the user know what's going on. */
268 if (to_file
->cmds
->fileinfo
.filenm
!= 0)
269 error (&from_file
->cmds
->fileinfo
,
270 _("Commands were specified for file `%s' at %s:%lu,"),
271 from_file
->name
, to_file
->cmds
->fileinfo
.filenm
,
272 to_file
->cmds
->fileinfo
.lineno
);
274 error (&from_file
->cmds
->fileinfo
,
275 _("Commands for file `%s' were found by implicit rule search,"),
277 error (&from_file
->cmds
->fileinfo
,
278 _("but `%s' is now considered the same file as `%s'."),
279 from_file
->name
, to_hname
);
280 error (&from_file
->cmds
->fileinfo
,
281 _("Commands for `%s' will be ignored in favor of those for `%s'."),
282 to_hname
, from_file
->name
);
286 /* Merge the dependencies of the two files. */
288 if (to_file
->deps
== 0)
289 to_file
->deps
= from_file
->deps
;
292 register struct dep
*deps
= to_file
->deps
;
293 while (deps
->next
!= 0)
295 deps
->next
= from_file
->deps
;
298 merge_variable_set_lists (&to_file
->variables
, from_file
->variables
);
300 if (to_file
->double_colon
&& from_file
->is_target
&& !from_file
->double_colon
)
301 fatal (NILF
, _("can't rename single-colon `%s' to double-colon `%s'"),
302 from_file
->name
, to_hname
);
303 if (!to_file
->double_colon
&& from_file
->double_colon
)
305 if (to_file
->is_target
)
306 fatal (NILF
, _("can't rename double-colon `%s' to single-colon `%s'"),
307 from_file
->name
, to_hname
);
309 to_file
->double_colon
= from_file
->double_colon
;
312 if (from_file
->last_mtime
> to_file
->last_mtime
)
313 /* %%% Kludge so -W wins on a file that gets vpathized. */
314 to_file
->last_mtime
= from_file
->last_mtime
;
316 to_file
->mtime_before_update
= from_file
->mtime_before_update
;
318 #define MERGE(field) to_file->field |= from_file->field
320 MERGE (tried_implicit
);
326 MERGE (ignore_vpath
);
329 from_file
->renamed
= to_file
;
333 /* Remove all nonprecious intermediate files.
334 If SIG is nonzero, this was caused by a fatal signal,
335 meaning that a different message will be printed, and
336 the message will go to stderr rather than stdout. */
339 remove_intermediates (int sig
)
341 register struct file
**file_slot
;
342 register struct file
**file_end
;
345 /* If there's no way we will ever remove anything anyway, punt early. */
346 if (question_flag
|| touch_flag
|| all_secondary
)
349 if (sig
&& just_print_flag
)
352 file_slot
= (struct file
**) files
.ht_vec
;
353 file_end
= file_slot
+ files
.ht_size
;
354 for ( ; file_slot
< file_end
; file_slot
++)
355 if (! HASH_VACANT (*file_slot
))
357 register struct file
*f
= *file_slot
;
358 /* Is this file eligible for automatic deletion?
359 Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
360 given on the command-line, and it's either a -include makefile or
361 it's not precious. */
362 if (f
->intermediate
&& (f
->dontcare
|| !f
->precious
)
363 && !f
->secondary
&& !f
->cmd_target
)
366 if (f
->update_status
== -1)
367 /* If nothing would have created this file yet,
368 don't print an "rm" command for it. */
374 status
= unlink (f
->name
);
375 if (status
< 0 && errno
== ENOENT
)
381 error (NILF
, _("*** Deleting intermediate file `%s'"), f
->name
);
385 DB (DB_BASIC
, (_("Removing intermediate files...\n")));
390 fputs ("rm ", stdout
);
395 fputs (f
->name
, stdout
);
400 perror_with_name ("unlink: ", f
->name
);
413 parse_prereqs (char *p
)
415 struct dep
*new = (struct dep
*)
416 multi_glob (parse_file_seq (&p
, '|', sizeof (struct dep
), 1),
417 sizeof (struct dep
));
421 /* Files that follow '|' are "order-only" prerequisites that satisfy the
422 dependency by existing: their modification times are irrelevant. */
427 multi_glob (parse_file_seq (&p
, '\0', sizeof (struct dep
), 1),
428 sizeof (struct dep
));
435 for (dp
= new; dp
->next
!= NULL
; dp
= dp
->next
)
440 for (; ood
!= NULL
; ood
= ood
->next
)
441 ood
->ignore_mtime
= 1;
448 /* Set the intermediate flag. */
451 set_intermediate (const void *item
)
453 struct file
*f
= (struct file
*) item
;
457 /* Expand and parse each dependency line. */
459 expand_deps (struct file
*f
)
462 struct dep
*old
= f
->deps
;
463 char *file_stem
= f
->stem
;
464 unsigned int last_dep_has_cmds
= f
->updating
;
470 for (d
= old
; d
!= 0; d
= d
->next
)
472 struct dep
*new, *d1
;
478 /* Create the dependency list.
479 If we're not doing 2nd expansion, then it's just the name. */
480 if (! d
->need_2nd_expansion
)
484 /* If it's from a static pattern rule, convert the patterns into
485 "$*" so they'll expand properly. */
486 if (d
->staticpattern
)
489 char *buffer
= variable_expand ("");
491 o
= subst_expand (buffer
, d
->name
, "%", "$*", 1, 2, 0);
494 d
->name
= savestring (buffer
, o
- buffer
);
495 d
->staticpattern
= 0; /* Clear staticpattern so that we don't
496 re-expand %s below. */
499 /* We are going to do second expansion so initialize file variables
500 for the file. Since the stem for static pattern rules comes from
501 individual dep lines, we will temporarily set f->stem to d->stem.
505 initialize_file_variables (f
, 0);
512 set_file_variables (f
);
514 p
= variable_expand_for_file (d
->name
, f
);
520 /* Parse the prerequisites. */
521 new = parse_prereqs (p
);
523 /* If this dep list was from a static pattern rule, expand the %s. We
524 use patsubst_expand to translate the prerequisites' patterns into
525 plain prerequisite names. */
526 if (new && d
->staticpattern
)
529 char *buffer
= variable_expand ("");
530 struct dep
*dp
= new, *dl
= 0;
534 char *percent
= find_percent (dp
->name
);
537 /* We have to handle empty stems specially, because that
538 would be equivalent to $(patsubst %,dp->name,) which
539 will always be empty. */
540 if (d
->stem
[0] == '\0')
541 /* This needs memmove() in ISO C. */
542 bcopy (percent
+1, percent
, strlen (percent
));
545 char *o
= patsubst_expand (buffer
, d
->stem
, pattern
,
553 dp
->name
= savestring (buffer
, o
- buffer
);
557 /* If the name expanded to the empty string, ignore it. */
558 if (dp
->name
[0] == '\0')
562 dp
= new = new->next
;
564 dp
= dl
->next
= dp
->next
;
565 /* @@ Are we leaking df->name here? */
576 /* Enter them as files. */
577 for (d1
= new; d1
!= 0; d1
= d1
->next
)
579 d1
->file
= lookup_file (d1
->name
);
581 d1
->file
= enter_file (d1
->name
);
585 d1
->staticpattern
= 0;
586 d1
->need_2nd_expansion
= 0;
589 /* Add newly parsed deps to f->deps. If this is the last dependency
590 line and this target has commands then put it in front so the
591 last dependency line (the one with commands) ends up being the
592 first. This is important because people expect $< to hold first
593 prerequisite from the rule with commands. If it is not the last
594 dependency line or the rule does not have commands then link it
595 at the end so it appears in makefile order. */
599 if (d
->next
== 0 && last_dep_has_cmds
)
602 for (d_ptr
= &new; *d_ptr
; d_ptr
= &(*d_ptr
)->next
)
611 for (d_ptr
= &f
->deps
; *d_ptr
; d_ptr
= &(*d_ptr
)->next
)
619 free_dep_chain (old
);
622 /* For each dependency of each file, make the `struct dep' point
623 at the appropriate `struct file' (which may have to be created).
625 Also mark the files depended on by .PRECIOUS, .PHONY, .SILENT,
626 and various other special targets. */
634 struct file
**file_slot_0
;
635 struct file
**file_slot
;
636 struct file
**file_end
;
638 /* Perform second expansion and enter each dependency
641 /* Expand .SUFFIXES first; it's dependencies are used for
643 for (f
= lookup_file (".SUFFIXES"); f
!= 0; f
= f
->prev
)
646 /* We must use hash_dump (), because within this loop
647 we might add new files to the table, possibly causing
648 an in-situ table expansion. */
649 file_slot_0
= (struct file
**) hash_dump (&files
, 0, 0);
650 file_end
= file_slot_0
+ files
.ht_fill
;
651 for (file_slot
= file_slot_0
; file_slot
< file_end
; file_slot
++)
652 for (f
= *file_slot
; f
!= 0; f
= f
->prev
)
654 if (strcmp (f
->name
, ".SUFFIXES") != 0)
659 for (f
= lookup_file (".PRECIOUS"); f
!= 0; f
= f
->prev
)
660 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
661 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
664 for (f
= lookup_file (".LOW_RESOLUTION_TIME"); f
!= 0; f
= f
->prev
)
665 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
666 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
667 f2
->low_resolution_time
= 1;
669 for (f
= lookup_file (".PHONY"); f
!= 0; f
= f
->prev
)
670 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
671 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
673 /* Mark this file as phony nonexistent target. */
676 f2
->last_mtime
= NONEXISTENT_MTIME
;
677 f2
->mtime_before_update
= NONEXISTENT_MTIME
;
680 for (f
= lookup_file (".INTERMEDIATE"); f
!= 0; f
= f
->prev
)
682 /* .INTERMEDIATE with deps listed
683 marks those deps as intermediate files. */
684 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
685 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
686 f2
->intermediate
= 1;
687 /* .INTERMEDIATE with no deps does nothing.
688 Marking all files as intermediates is useless
689 since the goal targets would be deleted after they are built. */
692 for (f
= lookup_file (".SECONDARY"); f
!= 0; f
= f
->prev
)
694 /* .SECONDARY with deps listed
695 marks those deps as intermediate files
696 in that they don't get rebuilt if not actually needed;
697 but unlike real intermediate files,
698 these are not deleted after make finishes. */
700 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
701 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
702 f2
->intermediate
= f2
->secondary
= 1;
703 /* .SECONDARY with no deps listed marks *all* files that way. */
707 hash_map (&files
, set_intermediate
);
711 f
= lookup_file (".EXPORT_ALL_VARIABLES");
712 if (f
!= 0 && f
->is_target
)
713 export_all_variables
= 1;
715 f
= lookup_file (".IGNORE");
716 if (f
!= 0 && f
->is_target
)
719 ignore_errors_flag
= 1;
721 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
722 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
723 f2
->command_flags
|= COMMANDS_NOERROR
;
726 f
= lookup_file (".SILENT");
727 if (f
!= 0 && f
->is_target
)
732 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
733 for (f2
= d
->file
; f2
!= 0; f2
= f2
->prev
)
734 f2
->command_flags
|= COMMANDS_SILENT
;
737 f
= lookup_file (".NOTPARALLEL");
738 if (f
!= 0 && f
->is_target
)
741 #ifndef NO_MINUS_C_MINUS_O
742 /* If .POSIX was defined, remove OUTPUT_OPTION to comply. */
743 /* This needs more work: what if the user sets this in the makefile?
745 define_variable (STRING_SIZE_TUPLE("OUTPUT_OPTION"), "", o_default, 1);
749 /* Remember that we've done this. */
753 /* Set the `command_state' member of FILE and all its `also_make's. */
756 set_command_state (struct file
*file
, enum cmd_state state
)
760 file
->command_state
= state
;
762 for (d
= file
->also_make
; d
!= 0; d
= d
->next
)
763 d
->file
->command_state
= state
;
766 /* Convert an external file timestamp to internal form. */
769 file_timestamp_cons (const char *fname
, time_t s
, int ns
)
771 int offset
= ORDINARY_MTIME_MIN
+ (FILE_TIMESTAMP_HI_RES
? ns
: 0);
772 FILE_TIMESTAMP product
= (FILE_TIMESTAMP
) s
<< FILE_TIMESTAMP_LO_BITS
;
773 FILE_TIMESTAMP ts
= product
+ offset
;
775 if (! (s
<= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX
)
776 && product
<= ts
&& ts
<= ORDINARY_MTIME_MAX
))
778 char buf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
779 ts
= s
<= OLD_MTIME
? ORDINARY_MTIME_MIN
: ORDINARY_MTIME_MAX
;
780 file_timestamp_sprintf (buf
, ts
);
781 error (NILF
, _("%s: Timestamp out of range; substituting %s"),
782 fname
? fname
: _("Current time"), buf
);
788 /* Return the current time as a file timestamp, setting *RESOLUTION to
791 file_timestamp_now (int *resolution
)
797 /* Don't bother with high-resolution clocks if file timestamps have
798 only one-second resolution. The code below should work, but it's
799 not worth the hassle of debugging it on hosts where it fails. */
800 #if FILE_TIMESTAMP_HI_RES
801 # if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME
803 struct timespec timespec
;
804 if (clock_gettime (CLOCK_REALTIME
, ×pec
) == 0)
808 ns
= timespec
.tv_nsec
;
813 # if HAVE_GETTIMEOFDAY
815 struct timeval timeval
;
816 if (gettimeofday (&timeval
, 0) == 0)
820 ns
= timeval
.tv_usec
* 1000;
828 s
= time ((time_t *) 0);
831 #if FILE_TIMESTAMP_HI_RES
835 return file_timestamp_cons (0, s
, ns
);
838 /* Place into the buffer P a printable representation of the file
841 file_timestamp_sprintf (char *p
, FILE_TIMESTAMP ts
)
843 time_t t
= FILE_TIMESTAMP_S (ts
);
844 struct tm
*tm
= localtime (&t
);
847 sprintf (p
, "%04d-%02d-%02d %02d:%02d:%02d",
848 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
849 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
851 sprintf (p
, "%ld", (long) t
);
853 sprintf (p
, "%lu", (unsigned long) t
);
856 /* Append nanoseconds as a fraction, but remove trailing zeros.
857 We don't know the actual timestamp resolution, since clock_getres
858 applies only to local times, whereas this timestamp might come
859 from a remote filesystem. So removing trailing zeros is the
860 best guess that we can do. */
861 sprintf (p
, ".%09d", FILE_TIMESTAMP_NS (ts
));
870 /* Print the data base of files. */
873 print_file (const void *item
)
875 struct file
*f
= (struct file
*) item
;
881 puts (_("# Not a target:"));
882 printf ("%s:%s", f
->name
, f
->double_colon
? ":" : "");
884 /* Print all normal dependencies; note any order-only deps. */
885 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
886 if (! d
->ignore_mtime
)
887 printf (" %s", dep_name (d
));
891 /* Print order-only deps, if we have any. */
894 printf (" | %s", dep_name (ood
));
895 for (d
= ood
->next
; d
!= 0; d
= d
->next
)
897 printf (" %s", dep_name (d
));
903 puts (_("# Precious file (prerequisite of .PRECIOUS)."));
905 puts (_("# Phony target (prerequisite of .PHONY)."));
907 puts (_("# Command-line target."));
909 puts (_("# A default, MAKEFILES, or -include/sinclude makefile."));
910 puts (f
->tried_implicit
911 ? _("# Implicit rule search has been done.")
912 : _("# Implicit rule search has not been done."));
914 printf (_("# Implicit/static pattern stem: `%s'\n"), f
->stem
);
916 puts (_("# File is an intermediate prerequisite."));
917 if (f
->also_make
!= 0)
919 fputs (_("# Also makes:"), stdout
);
920 for (d
= f
->also_make
; d
!= 0; d
= d
->next
)
921 printf (" %s", dep_name (d
));
924 if (f
->last_mtime
== UNKNOWN_MTIME
)
925 puts (_("# Modification time never checked."));
926 else if (f
->last_mtime
== NONEXISTENT_MTIME
)
927 puts (_("# File does not exist."));
928 else if (f
->last_mtime
== OLD_MTIME
)
929 puts (_("# File is very old."));
932 char buf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
933 file_timestamp_sprintf (buf
, f
->last_mtime
);
934 printf (_("# Last modified %s\n"), buf
);
937 ? _("# File has been updated.") : _("# File has not been updated."));
938 switch (f
->command_state
)
941 puts (_("# Commands currently running (THIS IS A BUG)."));
943 case cs_deps_running
:
944 puts (_("# Dependencies commands running (THIS IS A BUG)."));
948 switch (f
->update_status
)
953 puts (_("# Successfully updated."));
956 assert (question_flag
);
957 puts (_("# Needs to be updated (-q is set)."));
960 puts (_("# Failed to be updated."));
963 puts (_("# Invalid value in `update_status' member!"));
970 puts (_("# Invalid value in `command_state' member!"));
976 if (f
->variables
!= 0)
977 print_file_variables (f
);
980 print_commands (f
->cmds
);
983 print_file ((const void *) f
->prev
);
987 print_file_data_base (void)
989 puts (_("\n# Files"));
991 hash_map (&files
, print_file
);
993 fputs (_("\n# files hash-table stats:\n# "), stdout
);
994 hash_print_stats (&files
, stdout
);
997 #define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500)
1000 build_target_list (char *value
)
1002 static unsigned long last_targ_count
= 0;
1004 if (files
.ht_fill
!= last_targ_count
)
1006 unsigned long max
= EXPANSION_INCREMENT (strlen (value
));
1009 struct file
**fp
= (struct file
**) files
.ht_vec
;
1010 struct file
**end
= &fp
[files
.ht_size
];
1012 /* Make sure we have at least MAX bytes in the allocated buffer. */
1013 value
= xrealloc (value
, max
);
1017 for (; fp
< end
; ++fp
)
1018 if (!HASH_VACANT (*fp
) && (*fp
)->is_target
)
1020 struct file
*f
= *fp
;
1021 int l
= strlen (f
->name
);
1026 unsigned long off
= p
- value
;
1028 max
+= EXPANSION_INCREMENT (l
+ 1);
1029 value
= xrealloc (value
, max
);
1033 bcopy (f
->name
, p
, l
);
1039 last_targ_count
= files
.ht_fill
;
1046 init_hash_files (void)
1048 hash_init (&files
, 1000, file_hash_1
, file_hash_2
, file_hash_cmp
);