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
|
---|
4 | Foundation, Inc.
|
---|
5 | This file is part of GNU Make.
|
---|
6 |
|
---|
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.
|
---|
10 |
|
---|
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.
|
---|
14 |
|
---|
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. */
|
---|
18 |
|
---|
19 | #include "make.h"
|
---|
20 |
|
---|
21 | #include <assert.h>
|
---|
22 |
|
---|
23 | #include "dep.h"
|
---|
24 | #include "filedef.h"
|
---|
25 | #include "job.h"
|
---|
26 | #include "commands.h"
|
---|
27 | #include "variable.h"
|
---|
28 | #include "debug.h"
|
---|
29 | #include "hash.h"
|
---|
30 |
|
---|
31 |
|
---|
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. */
|
---|
39 | int snapped_deps = 0;
|
---|
40 |
|
---|
41 | /* Hash table of files the makefile knows how to make. */
|
---|
42 |
|
---|
43 | static unsigned long
|
---|
44 | file_hash_1 (const void *key)
|
---|
45 | {
|
---|
46 | return_ISTRING_HASH_1 (((struct file const *) key)->hname);
|
---|
47 | }
|
---|
48 |
|
---|
49 | static unsigned long
|
---|
50 | file_hash_2 (const void *key)
|
---|
51 | {
|
---|
52 | return_ISTRING_HASH_2 (((struct file const *) key)->hname);
|
---|
53 | }
|
---|
54 |
|
---|
55 | static int
|
---|
56 | file_hash_cmp (const void *x, const void *y)
|
---|
57 | {
|
---|
58 | return_ISTRING_COMPARE (((struct file const *) x)->hname,
|
---|
59 | ((struct file const *) y)->hname);
|
---|
60 | }
|
---|
61 |
|
---|
62 | #ifndef FILE_BUCKETS
|
---|
63 | #define FILE_BUCKETS 1007
|
---|
64 | #endif
|
---|
65 | static struct hash_table files;
|
---|
66 |
|
---|
67 | /* Whether or not .SECONDARY with no prerequisites was given. */
|
---|
68 | static int all_secondary = 0;
|
---|
69 |
|
---|
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 | */
|
---|
74 |
|
---|
75 | struct file *
|
---|
76 | lookup_file (const char *name)
|
---|
77 | {
|
---|
78 | struct file *f;
|
---|
79 | struct file file_key;
|
---|
80 | #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
|
---|
81 | char *lname;
|
---|
82 | #endif
|
---|
83 |
|
---|
84 | assert (*name != '\0');
|
---|
85 |
|
---|
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. */
|
---|
89 | #ifdef VMS
|
---|
90 | # ifndef WANT_CASE_SENSITIVE_TARGETS
|
---|
91 | if (*name != '.')
|
---|
92 | {
|
---|
93 | const char *n;
|
---|
94 | char *ln;
|
---|
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;
|
---|
98 | *ln = '\0';
|
---|
99 | name = lname;
|
---|
100 | }
|
---|
101 | # endif
|
---|
102 |
|
---|
103 | while (name[0] == '[' && name[1] == ']' && name[2] != '\0')
|
---|
104 | name += 2;
|
---|
105 | #endif
|
---|
106 | while (name[0] == '.' && name[1] == '/' && name[2] != '\0')
|
---|
107 | {
|
---|
108 | name += 2;
|
---|
109 | while (*name == '/')
|
---|
110 | /* Skip following slashes: ".//foo" is "foo", not "/foo". */
|
---|
111 | ++name;
|
---|
112 | }
|
---|
113 |
|
---|
114 | if (*name == '\0')
|
---|
115 | /* It was all slashes after a dot. */
|
---|
116 | #if defined(VMS)
|
---|
117 | name = "[]";
|
---|
118 | #elif defined(_AMIGA)
|
---|
119 | name = "";
|
---|
120 | #else
|
---|
121 | name = "./";
|
---|
122 | #endif
|
---|
123 |
|
---|
124 | file_key.hname = name;
|
---|
125 | f = hash_find_item (&files, &file_key);
|
---|
126 | #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
|
---|
127 | if (*name != '.')
|
---|
128 | free (lname);
|
---|
129 | #endif
|
---|
130 |
|
---|
131 | return f;
|
---|
132 | }
|
---|
133 |
|
---|
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.
|
---|
137 | */
|
---|
138 |
|
---|
139 | struct file *
|
---|
140 | enter_file (const char *name)
|
---|
141 | {
|
---|
142 | struct file *f;
|
---|
143 | struct file *new;
|
---|
144 | struct file **file_slot;
|
---|
145 | struct file file_key;
|
---|
146 |
|
---|
147 | assert (*name != '\0');
|
---|
148 | assert (strcache_iscached (name));
|
---|
149 |
|
---|
150 | #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
|
---|
151 | if (*name != '.')
|
---|
152 | {
|
---|
153 | const char *n;
|
---|
154 | char *lname, *ln;
|
---|
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);
|
---|
159 | else
|
---|
160 | *ln = *n;
|
---|
161 |
|
---|
162 | *ln = '\0';
|
---|
163 | name = strcache_add (lname);
|
---|
164 | free (lname);
|
---|
165 | }
|
---|
166 | #endif
|
---|
167 |
|
---|
168 | file_key.hname = name;
|
---|
169 | file_slot = (struct file **) hash_find_slot (&files, &file_key);
|
---|
170 | f = *file_slot;
|
---|
171 | if (! HASH_VACANT (f) && !f->double_colon)
|
---|
172 | return f;
|
---|
173 |
|
---|
174 | new = xmalloc (sizeof (struct file));
|
---|
175 | memset (new, '\0', sizeof (struct file));
|
---|
176 | new->name = new->hname = name;
|
---|
177 | new->update_status = -1;
|
---|
178 |
|
---|
179 | if (HASH_VACANT (f))
|
---|
180 | {
|
---|
181 | new->last = new;
|
---|
182 | hash_insert_at (&files, new, file_slot);
|
---|
183 | }
|
---|
184 | else
|
---|
185 | {
|
---|
186 | /* There is already a double-colon entry for this file. */
|
---|
187 | new->double_colon = f;
|
---|
188 | f->last->prev = new;
|
---|
189 | f->last = new;
|
---|
190 | }
|
---|
191 |
|
---|
192 | return new;
|
---|
193 | }
|
---|
194 | |
---|
195 |
|
---|
196 | /* Rehash FILE to NAME. This is not as simple as resetting
|
---|
197 | the `hname' member, since it must be put in a new hash bucket,
|
---|
198 | and possibly merged with an existing file called NAME. */
|
---|
199 |
|
---|
200 | void
|
---|
201 | rehash_file (struct file *from_file, const char *to_hname)
|
---|
202 | {
|
---|
203 | struct file file_key;
|
---|
204 | struct file **file_slot;
|
---|
205 | struct file *to_file;
|
---|
206 | struct file *deleted_file;
|
---|
207 | struct file *f;
|
---|
208 |
|
---|
209 | /* If it's already that name, we're done. */
|
---|
210 | file_key.hname = to_hname;
|
---|
211 | if (! file_hash_cmp (from_file, &file_key))
|
---|
212 | return;
|
---|
213 |
|
---|
214 | /* Find the end of the renamed list for the "from" file. */
|
---|
215 | file_key.hname = from_file->hname;
|
---|
216 | while (from_file->renamed != 0)
|
---|
217 | from_file = from_file->renamed;
|
---|
218 | if (file_hash_cmp (from_file, &file_key))
|
---|
219 | /* hname changed unexpectedly!! */
|
---|
220 | abort ();
|
---|
221 |
|
---|
222 | /* Remove the "from" file from the hash. */
|
---|
223 | deleted_file = hash_delete (&files, from_file);
|
---|
224 | if (deleted_file != from_file)
|
---|
225 | /* from_file isn't the one stored in files */
|
---|
226 | abort ();
|
---|
227 |
|
---|
228 | /* Find where the newly renamed file will go in the hash. */
|
---|
229 | file_key.hname = to_hname;
|
---|
230 | file_slot = (struct file **) hash_find_slot (&files, &file_key);
|
---|
231 | to_file = *file_slot;
|
---|
232 |
|
---|
233 | /* Change the hash name for this file. */
|
---|
234 | from_file->hname = to_hname;
|
---|
235 | for (f = from_file->double_colon; f != 0; f = f->prev)
|
---|
236 | f->hname = to_hname;
|
---|
237 |
|
---|
238 | /* If the new name doesn't exist yet just set it to the renamed file. */
|
---|
239 | if (HASH_VACANT (to_file))
|
---|
240 | {
|
---|
241 | hash_insert_at (&files, from_file, file_slot);
|
---|
242 | return;
|
---|
243 | }
|
---|
244 |
|
---|
245 | /* TO_FILE already exists under TO_HNAME.
|
---|
246 | We must retain TO_FILE and merge FROM_FILE into it. */
|
---|
247 |
|
---|
248 | if (from_file->cmds != 0)
|
---|
249 | {
|
---|
250 | if (to_file->cmds == 0)
|
---|
251 | to_file->cmds = from_file->cmds;
|
---|
252 | else if (from_file->cmds != to_file->cmds)
|
---|
253 | {
|
---|
254 | /* We have two sets of commands. We will go with the
|
---|
255 | one given in the rule explicitly mentioning this name,
|
---|
256 | but give a message to let the user know what's going on. */
|
---|
257 | if (to_file->cmds->fileinfo.filenm != 0)
|
---|
258 | error (&from_file->cmds->fileinfo,
|
---|
259 | _("Commands were specified for file `%s' at %s:%lu,"),
|
---|
260 | from_file->name, to_file->cmds->fileinfo.filenm,
|
---|
261 | to_file->cmds->fileinfo.lineno);
|
---|
262 | else
|
---|
263 | error (&from_file->cmds->fileinfo,
|
---|
264 | _("Commands for file `%s' were found by implicit rule search,"),
|
---|
265 | from_file->name);
|
---|
266 | error (&from_file->cmds->fileinfo,
|
---|
267 | _("but `%s' is now considered the same file as `%s'."),
|
---|
268 | from_file->name, to_hname);
|
---|
269 | error (&from_file->cmds->fileinfo,
|
---|
270 | _("Commands for `%s' will be ignored in favor of those for `%s'."),
|
---|
271 | to_hname, from_file->name);
|
---|
272 | }
|
---|
273 | }
|
---|
274 |
|
---|
275 | /* Merge the dependencies of the two files. */
|
---|
276 |
|
---|
277 | if (to_file->deps == 0)
|
---|
278 | to_file->deps = from_file->deps;
|
---|
279 | else
|
---|
280 | {
|
---|
281 | struct dep *deps = to_file->deps;
|
---|
282 | while (deps->next != 0)
|
---|
283 | deps = deps->next;
|
---|
284 | deps->next = from_file->deps;
|
---|
285 | }
|
---|
286 |
|
---|
287 | merge_variable_set_lists (&to_file->variables, from_file->variables);
|
---|
288 |
|
---|
289 | if (to_file->double_colon && from_file->is_target && !from_file->double_colon)
|
---|
290 | fatal (NILF, _("can't rename single-colon `%s' to double-colon `%s'"),
|
---|
291 | from_file->name, to_hname);
|
---|
292 | if (!to_file->double_colon && from_file->double_colon)
|
---|
293 | {
|
---|
294 | if (to_file->is_target)
|
---|
295 | fatal (NILF, _("can't rename double-colon `%s' to single-colon `%s'"),
|
---|
296 | from_file->name, to_hname);
|
---|
297 | else
|
---|
298 | to_file->double_colon = from_file->double_colon;
|
---|
299 | }
|
---|
300 |
|
---|
301 | if (from_file->last_mtime > to_file->last_mtime)
|
---|
302 | /* %%% Kludge so -W wins on a file that gets vpathized. */
|
---|
303 | to_file->last_mtime = from_file->last_mtime;
|
---|
304 |
|
---|
305 | to_file->mtime_before_update = from_file->mtime_before_update;
|
---|
306 |
|
---|
307 | #define MERGE(field) to_file->field |= from_file->field
|
---|
308 | MERGE (precious);
|
---|
309 | MERGE (tried_implicit);
|
---|
310 | MERGE (updating);
|
---|
311 | MERGE (updated);
|
---|
312 | MERGE (is_target);
|
---|
313 | MERGE (cmd_target);
|
---|
314 | MERGE (phony);
|
---|
315 | MERGE (ignore_vpath);
|
---|
316 | #undef MERGE
|
---|
317 |
|
---|
318 | from_file->renamed = to_file;
|
---|
319 | }
|
---|
320 |
|
---|
321 | /* Rename FILE to NAME. This is not as simple as resetting
|
---|
322 | the `name' member, since it must be put in a new hash bucket,
|
---|
323 | and possibly merged with an existing file called NAME. */
|
---|
324 |
|
---|
325 | void
|
---|
326 | rename_file (struct file *from_file, const char *to_hname)
|
---|
327 | {
|
---|
328 | rehash_file (from_file, to_hname);
|
---|
329 | while (from_file)
|
---|
330 | {
|
---|
331 | from_file->name = from_file->hname;
|
---|
332 | from_file = from_file->prev;
|
---|
333 | }
|
---|
334 | }
|
---|
335 | |
---|
336 |
|
---|
337 | /* Remove all nonprecious intermediate files.
|
---|
338 | If SIG is nonzero, this was caused by a fatal signal,
|
---|
339 | meaning that a different message will be printed, and
|
---|
340 | the message will go to stderr rather than stdout. */
|
---|
341 |
|
---|
342 | void
|
---|
343 | remove_intermediates (int sig)
|
---|
344 | {
|
---|
345 | struct file **file_slot;
|
---|
346 | struct file **file_end;
|
---|
347 | int doneany = 0;
|
---|
348 |
|
---|
349 | /* If there's no way we will ever remove anything anyway, punt early. */
|
---|
350 | if (question_flag || touch_flag || all_secondary)
|
---|
351 | return;
|
---|
352 |
|
---|
353 | if (sig && just_print_flag)
|
---|
354 | return;
|
---|
355 |
|
---|
356 | file_slot = (struct file **) files.ht_vec;
|
---|
357 | file_end = file_slot + files.ht_size;
|
---|
358 | for ( ; file_slot < file_end; file_slot++)
|
---|
359 | if (! HASH_VACANT (*file_slot))
|
---|
360 | {
|
---|
361 | struct file *f = *file_slot;
|
---|
362 | /* Is this file eligible for automatic deletion?
|
---|
363 | Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
|
---|
364 | given on the command-line, and it's either a -include makefile or
|
---|
365 | it's not precious. */
|
---|
366 | if (f->intermediate && (f->dontcare || !f->precious)
|
---|
367 | && !f->secondary && !f->cmd_target)
|
---|
368 | {
|
---|
369 | int status;
|
---|
370 | if (f->update_status == -1)
|
---|
371 | /* If nothing would have created this file yet,
|
---|
372 | don't print an "rm" command for it. */
|
---|
373 | continue;
|
---|
374 | if (just_print_flag)
|
---|
375 | status = 0;
|
---|
376 | else
|
---|
377 | {
|
---|
378 | status = unlink (f->name);
|
---|
379 | if (status < 0 && errno == ENOENT)
|
---|
380 | continue;
|
---|
381 | }
|
---|
382 | if (!f->dontcare)
|
---|
383 | {
|
---|
384 | if (sig)
|
---|
385 | error (NILF, _("*** Deleting intermediate file `%s'"), f->name);
|
---|
386 | else
|
---|
387 | {
|
---|
388 | if (! doneany)
|
---|
389 | DB (DB_BASIC, (_("Removing intermediate files...\n")));
|
---|
390 | if (!silent_flag)
|
---|
391 | {
|
---|
392 | if (! doneany)
|
---|
393 | {
|
---|
394 | fputs ("rm ", stdout);
|
---|
395 | doneany = 1;
|
---|
396 | }
|
---|
397 | else
|
---|
398 | putchar (' ');
|
---|
399 | fputs (f->name, stdout);
|
---|
400 | fflush (stdout);
|
---|
401 | }
|
---|
402 | }
|
---|
403 | if (status < 0)
|
---|
404 | perror_with_name ("unlink: ", f->name);
|
---|
405 | }
|
---|
406 | }
|
---|
407 | }
|
---|
408 |
|
---|
409 | if (doneany && !sig)
|
---|
410 | {
|
---|
411 | putchar ('\n');
|
---|
412 | fflush (stdout);
|
---|
413 | }
|
---|
414 | }
|
---|
415 | |
---|
416 |
|
---|
417 | struct dep *
|
---|
418 | parse_prereqs (char *p)
|
---|
419 | {
|
---|
420 | struct dep *new = (struct dep *)
|
---|
421 | multi_glob (parse_file_seq (&p, '|', sizeof (struct dep), 1),
|
---|
422 | sizeof (struct dep));
|
---|
423 |
|
---|
424 | if (*p)
|
---|
425 | {
|
---|
426 | /* Files that follow '|' are "order-only" prerequisites that satisfy the
|
---|
427 | dependency by existing: their modification times are irrelevant. */
|
---|
428 | struct dep *ood;
|
---|
429 |
|
---|
430 | ++p;
|
---|
431 | ood = (struct dep *)
|
---|
432 | multi_glob (parse_file_seq (&p, '\0', sizeof (struct dep), 1),
|
---|
433 | sizeof (struct dep));
|
---|
434 |
|
---|
435 | if (! new)
|
---|
436 | new = ood;
|
---|
437 | else
|
---|
438 | {
|
---|
439 | struct dep *dp;
|
---|
440 | for (dp = new; dp->next != NULL; dp = dp->next)
|
---|
441 | ;
|
---|
442 | dp->next = ood;
|
---|
443 | }
|
---|
444 |
|
---|
445 | for (; ood != NULL; ood = ood->next)
|
---|
446 | ood->ignore_mtime = 1;
|
---|
447 | }
|
---|
448 |
|
---|
449 | return new;
|
---|
450 | }
|
---|
451 |
|
---|
452 | /* Set the intermediate flag. */
|
---|
453 |
|
---|
454 | static void
|
---|
455 | set_intermediate (const void *item)
|
---|
456 | {
|
---|
457 | struct file *f = (struct file *) item;
|
---|
458 | f->intermediate = 1;
|
---|
459 | }
|
---|
460 |
|
---|
461 | /* Expand and parse each dependency line. */
|
---|
462 | static void
|
---|
463 | expand_deps (struct file *f)
|
---|
464 | {
|
---|
465 | struct dep *d;
|
---|
466 | struct dep *old = f->deps;
|
---|
467 | const char *file_stem = f->stem;
|
---|
468 | unsigned int last_dep_has_cmds = f->updating;
|
---|
469 | int initialized = 0;
|
---|
470 |
|
---|
471 | f->updating = 0;
|
---|
472 | f->deps = 0;
|
---|
473 |
|
---|
474 | for (d = old; d != 0; d = d->next)
|
---|
475 | {
|
---|
476 | size_t buffer_offset; /* bird */
|
---|
477 | struct dep *new, *d1;
|
---|
478 | char *p;
|
---|
479 |
|
---|
480 | if (! d->name)
|
---|
481 | continue;
|
---|
482 |
|
---|
483 | /* Create the dependency list.
|
---|
484 | If we're not doing 2nd expansion, then it's just the name. We will
|
---|
485 | still need to massage it though. */
|
---|
486 | if (! d->need_2nd_expansion)
|
---|
487 | {
|
---|
488 | p = variable_expand ("");
|
---|
489 | buffer_offset = p - variable_buffer;
|
---|
490 | variable_buffer_output (p, d->name, strlen (d->name) + 1);
|
---|
491 | p = variable_buffer + buffer_offset; /* bird - variable_buffer may have been reallocated. (observed it) */
|
---|
492 | }
|
---|
493 | else
|
---|
494 | {
|
---|
495 | /* If it's from a static pattern rule, convert the patterns into
|
---|
496 | "$*" so they'll expand properly. */
|
---|
497 | if (d->staticpattern)
|
---|
498 | {
|
---|
499 | char *o;
|
---|
500 | char *buffer = variable_expand ("");
|
---|
501 | buffer_offset = buffer - variable_buffer; /* bird */
|
---|
502 |
|
---|
503 | o = subst_expand (buffer, d->name, "%", "$*", 1, 2, 0);
|
---|
504 | buffer = variable_buffer + buffer_offset; /* bird - variable_buffer may have been reallocated. */
|
---|
505 |
|
---|
506 | d->name = strcache_add_len (buffer, o - buffer);
|
---|
507 | d->staticpattern = 0; /* Clear staticpattern so that we don't
|
---|
508 | re-expand %s below. */
|
---|
509 | }
|
---|
510 |
|
---|
511 | /* We are going to do second expansion so initialize file variables
|
---|
512 | for the file. Since the stem for static pattern rules comes from
|
---|
513 | individual dep lines, we will temporarily set f->stem to d->stem.
|
---|
514 | */
|
---|
515 | if (!initialized)
|
---|
516 | {
|
---|
517 | initialize_file_variables (f, 0);
|
---|
518 | initialized = 1;
|
---|
519 | }
|
---|
520 |
|
---|
521 | if (d->stem != 0)
|
---|
522 | f->stem = d->stem;
|
---|
523 |
|
---|
524 | set_file_variables (f);
|
---|
525 |
|
---|
526 | p = variable_expand_for_file (d->name, f);
|
---|
527 |
|
---|
528 | if (d->stem != 0)
|
---|
529 | f->stem = file_stem;
|
---|
530 | }
|
---|
531 |
|
---|
532 | /* Parse the prerequisites. */
|
---|
533 | new = parse_prereqs (p);
|
---|
534 |
|
---|
535 | /* If this dep list was from a static pattern rule, expand the %s. We
|
---|
536 | use patsubst_expand to translate the prerequisites' patterns into
|
---|
537 | plain prerequisite names. */
|
---|
538 | if (new && d->staticpattern)
|
---|
539 | {
|
---|
540 | const char *pattern = "%";
|
---|
541 | char *buffer = variable_expand ("");
|
---|
542 | const size_t buffer_offset = buffer - variable_buffer; /* bird */
|
---|
543 | struct dep *dp = new, *dl = 0;
|
---|
544 |
|
---|
545 | while (dp != 0)
|
---|
546 | {
|
---|
547 | char *percent;
|
---|
548 | int nl = strlen (dp->name) + 1;
|
---|
549 | char *nm = alloca (nl);
|
---|
550 | memcpy (nm, dp->name, nl);
|
---|
551 | percent = find_percent (nm);
|
---|
552 | if (percent)
|
---|
553 | {
|
---|
554 | char *o;
|
---|
555 |
|
---|
556 | /* We have to handle empty stems specially, because that
|
---|
557 | would be equivalent to $(patsubst %,dp->name,) which
|
---|
558 | will always be empty. */
|
---|
559 | if (d->stem[0] == '\0')
|
---|
560 | {
|
---|
561 | memmove (percent, percent+1, strlen (percent));
|
---|
562 | o = variable_buffer_output (buffer, nm, strlen (nm) + 1);
|
---|
563 | }
|
---|
564 | else
|
---|
565 | o = patsubst_expand_pat (buffer, d->stem, pattern, nm,
|
---|
566 | pattern+1, percent+1);
|
---|
567 | buffer = variable_buffer + buffer_offset; /* bird - variable_buffer may have been reallocated. */
|
---|
568 |
|
---|
569 |
|
---|
570 | /* If the name expanded to the empty string, ignore it. */
|
---|
571 | if (buffer[0] == '\0')
|
---|
572 | {
|
---|
573 | struct dep *df = dp;
|
---|
574 | if (dp == new)
|
---|
575 | dp = new = new->next;
|
---|
576 | else
|
---|
577 | dp = dl->next = dp->next;
|
---|
578 | free_dep (df);
|
---|
579 | continue;
|
---|
580 | }
|
---|
581 |
|
---|
582 | /* Save the name. */
|
---|
583 | dp->name = strcache_add_len (buffer, o - buffer);
|
---|
584 | }
|
---|
585 | dl = dp;
|
---|
586 | dp = dp->next;
|
---|
587 | }
|
---|
588 | }
|
---|
589 |
|
---|
590 | /* Enter them as files. */
|
---|
591 | for (d1 = new; d1 != 0; d1 = d1->next)
|
---|
592 | {
|
---|
593 | d1->file = lookup_file (d1->name);
|
---|
594 | if (d1->file == 0)
|
---|
595 | d1->file = enter_file (d1->name);
|
---|
596 | d1->name = 0;
|
---|
597 | d1->staticpattern = 0;
|
---|
598 | d1->need_2nd_expansion = 0;
|
---|
599 | }
|
---|
600 |
|
---|
601 | /* Add newly parsed deps to f->deps. If this is the last dependency
|
---|
602 | line and this target has commands then put it in front so the
|
---|
603 | last dependency line (the one with commands) ends up being the
|
---|
604 | first. This is important because people expect $< to hold first
|
---|
605 | prerequisite from the rule with commands. If it is not the last
|
---|
606 | dependency line or the rule does not have commands then link it
|
---|
607 | at the end so it appears in makefile order. */
|
---|
608 |
|
---|
609 | if (new != 0)
|
---|
610 | {
|
---|
611 | if (d->next == 0 && last_dep_has_cmds)
|
---|
612 | {
|
---|
613 | struct dep **d_ptr;
|
---|
614 | for (d_ptr = &new; *d_ptr; d_ptr = &(*d_ptr)->next)
|
---|
615 | ;
|
---|
616 |
|
---|
617 | *d_ptr = f->deps;
|
---|
618 | f->deps = new;
|
---|
619 | }
|
---|
620 | else
|
---|
621 | {
|
---|
622 | struct dep **d_ptr;
|
---|
623 | for (d_ptr = &f->deps; *d_ptr; d_ptr = &(*d_ptr)->next)
|
---|
624 | ;
|
---|
625 |
|
---|
626 | *d_ptr = new;
|
---|
627 | }
|
---|
628 | }
|
---|
629 | }
|
---|
630 |
|
---|
631 | free_dep_chain (old);
|
---|
632 | }
|
---|
633 |
|
---|
634 | /* For each dependency of each file, make the `struct dep' point
|
---|
635 | at the appropriate `struct file' (which may have to be created).
|
---|
636 |
|
---|
637 | Also mark the files depended on by .PRECIOUS, .PHONY, .SILENT,
|
---|
638 | and various other special targets. */
|
---|
639 |
|
---|
640 | void
|
---|
641 | snap_deps (void)
|
---|
642 | {
|
---|
643 | struct file *f;
|
---|
644 | struct file *f2;
|
---|
645 | struct dep *d;
|
---|
646 | struct file **file_slot_0;
|
---|
647 | struct file **file_slot;
|
---|
648 | struct file **file_end;
|
---|
649 |
|
---|
650 | /* Perform second expansion and enter each dependency name as a file. */
|
---|
651 |
|
---|
652 | /* Expand .SUFFIXES first; it's dependencies are used for $$* calculation. */
|
---|
653 | for (f = lookup_file (".SUFFIXES"); f != 0; f = f->prev)
|
---|
654 | expand_deps (f);
|
---|
655 |
|
---|
656 | /* For every target that's not .SUFFIXES, expand its dependencies.
|
---|
657 | We must use hash_dump (), because within this loop we might add new files
|
---|
658 | to the table, possibly causing an in-situ table expansion. */
|
---|
659 | file_slot_0 = (struct file **) hash_dump (&files, 0, 0);
|
---|
660 | file_end = file_slot_0 + files.ht_fill;
|
---|
661 | for (file_slot = file_slot_0; file_slot < file_end; file_slot++)
|
---|
662 | for (f = *file_slot; f != 0; f = f->prev)
|
---|
663 | if (strcmp (f->name, ".SUFFIXES") != 0)
|
---|
664 | expand_deps (f);
|
---|
665 | free (file_slot_0);
|
---|
666 |
|
---|
667 | /* Now manage all the special targets. */
|
---|
668 |
|
---|
669 | for (f = lookup_file (".PRECIOUS"); 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)
|
---|
672 | f2->precious = 1;
|
---|
673 |
|
---|
674 | for (f = lookup_file (".LOW_RESOLUTION_TIME"); f != 0; f = f->prev)
|
---|
675 | for (d = f->deps; d != 0; d = d->next)
|
---|
676 | for (f2 = d->file; f2 != 0; f2 = f2->prev)
|
---|
677 | f2->low_resolution_time = 1;
|
---|
678 |
|
---|
679 | for (f = lookup_file (".PHONY"); f != 0; f = f->prev)
|
---|
680 | for (d = f->deps; d != 0; d = d->next)
|
---|
681 | for (f2 = d->file; f2 != 0; f2 = f2->prev)
|
---|
682 | {
|
---|
683 | /* Mark this file as phony nonexistent target. */
|
---|
684 | f2->phony = 1;
|
---|
685 | f2->is_target = 1;
|
---|
686 | f2->last_mtime = NONEXISTENT_MTIME;
|
---|
687 | f2->mtime_before_update = NONEXISTENT_MTIME;
|
---|
688 | }
|
---|
689 |
|
---|
690 | for (f = lookup_file (".INTERMEDIATE"); f != 0; f = f->prev)
|
---|
691 | /* Mark .INTERMEDIATE deps as intermediate files. */
|
---|
692 | for (d = f->deps; d != 0; d = d->next)
|
---|
693 | for (f2 = d->file; f2 != 0; f2 = f2->prev)
|
---|
694 | f2->intermediate = 1;
|
---|
695 | /* .INTERMEDIATE with no deps does nothing.
|
---|
696 | Marking all files as intermediates is useless since the goal targets
|
---|
697 | would be deleted after they are built. */
|
---|
698 |
|
---|
699 | for (f = lookup_file (".SECONDARY"); f != 0; f = f->prev)
|
---|
700 | /* Mark .SECONDARY deps as both intermediate and secondary. */
|
---|
701 | if (f->deps)
|
---|
702 | for (d = f->deps; d != 0; d = d->next)
|
---|
703 | for (f2 = d->file; f2 != 0; f2 = f2->prev)
|
---|
704 | f2->intermediate = f2->secondary = 1;
|
---|
705 | /* .SECONDARY with no deps listed marks *all* files that way. */
|
---|
706 | else
|
---|
707 | {
|
---|
708 | all_secondary = 1;
|
---|
709 | hash_map (&files, set_intermediate);
|
---|
710 | }
|
---|
711 |
|
---|
712 | f = lookup_file (".EXPORT_ALL_VARIABLES");
|
---|
713 | if (f != 0 && f->is_target)
|
---|
714 | export_all_variables = 1;
|
---|
715 |
|
---|
716 | f = lookup_file (".IGNORE");
|
---|
717 | if (f != 0 && f->is_target)
|
---|
718 | {
|
---|
719 | if (f->deps == 0)
|
---|
720 | ignore_errors_flag = 1;
|
---|
721 | else
|
---|
722 | for (d = f->deps; d != 0; d = d->next)
|
---|
723 | for (f2 = d->file; f2 != 0; f2 = f2->prev)
|
---|
724 | f2->command_flags |= COMMANDS_NOERROR;
|
---|
725 | }
|
---|
726 |
|
---|
727 | f = lookup_file (".SILENT");
|
---|
728 | if (f != 0 && f->is_target)
|
---|
729 | {
|
---|
730 | if (f->deps == 0)
|
---|
731 | silent_flag = 1;
|
---|
732 | else
|
---|
733 | for (d = f->deps; d != 0; d = d->next)
|
---|
734 | for (f2 = d->file; f2 != 0; f2 = f2->prev)
|
---|
735 | f2->command_flags |= COMMANDS_SILENT;
|
---|
736 | }
|
---|
737 |
|
---|
738 | f = lookup_file (".NOTPARALLEL");
|
---|
739 | if (f != 0 && f->is_target)
|
---|
740 | #ifndef CONFIG_WITH_EXTENDED_NOTPARALLEL
|
---|
741 | not_parallel = 1;
|
---|
742 | #else /* CONFIG_WITH_EXTENDED_NOTPARALLEL */
|
---|
743 | {
|
---|
744 | if (f->deps == 0)
|
---|
745 | {
|
---|
746 | DB (DB_KMK, (_("not_parallel -1\n")));
|
---|
747 | not_parallel = -1;
|
---|
748 | }
|
---|
749 | else
|
---|
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_NOTPARALLEL;
|
---|
753 | }
|
---|
754 | #endif /* CONFIG_WITH_EXTENDED_NOTPARALLEL */
|
---|
755 |
|
---|
756 | #ifndef NO_MINUS_C_MINUS_O
|
---|
757 | /* If .POSIX was defined, remove OUTPUT_OPTION to comply. */
|
---|
758 | /* This needs more work: what if the user sets this in the makefile?
|
---|
759 | if (posix_pedantic)
|
---|
760 | define_variable (STRING_SIZE_TUPLE("OUTPUT_OPTION"), "", o_default, 1);
|
---|
761 | */
|
---|
762 | #endif
|
---|
763 |
|
---|
764 | /* Remember that we've done this. */
|
---|
765 | snapped_deps = 1;
|
---|
766 | }
|
---|
767 | |
---|
768 |
|
---|
769 | /* Set the `command_state' member of FILE and all its `also_make's. */
|
---|
770 |
|
---|
771 | void
|
---|
772 | set_command_state (struct file *file, enum cmd_state state)
|
---|
773 | {
|
---|
774 | struct dep *d;
|
---|
775 |
|
---|
776 | file->command_state = state;
|
---|
777 |
|
---|
778 | for (d = file->also_make; d != 0; d = d->next)
|
---|
779 | d->file->command_state = state;
|
---|
780 |
|
---|
781 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
782 | if (file->multi_head)
|
---|
783 | {
|
---|
784 | assert (file == file->multi_head);
|
---|
785 | for (file = file->multi_head; file != 0; file = file->multi_next)
|
---|
786 | file->command_state = state;
|
---|
787 | }
|
---|
788 | #endif
|
---|
789 | }
|
---|
790 | |
---|
791 |
|
---|
792 | /* Convert an external file timestamp to internal form. */
|
---|
793 |
|
---|
794 | FILE_TIMESTAMP
|
---|
795 | file_timestamp_cons (const char *fname, time_t s, int ns)
|
---|
796 | {
|
---|
797 | int offset = ORDINARY_MTIME_MIN + (FILE_TIMESTAMP_HI_RES ? ns : 0);
|
---|
798 | FILE_TIMESTAMP product = (FILE_TIMESTAMP) s << FILE_TIMESTAMP_LO_BITS;
|
---|
799 | FILE_TIMESTAMP ts = product + offset;
|
---|
800 |
|
---|
801 | if (! (s <= FILE_TIMESTAMP_S (ORDINARY_MTIME_MAX)
|
---|
802 | && product <= ts && ts <= ORDINARY_MTIME_MAX))
|
---|
803 | {
|
---|
804 | char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
|
---|
805 | ts = s <= OLD_MTIME ? ORDINARY_MTIME_MIN : ORDINARY_MTIME_MAX;
|
---|
806 | file_timestamp_sprintf (buf, ts);
|
---|
807 | error (NILF, _("%s: Timestamp out of range; substituting %s"),
|
---|
808 | fname ? fname : _("Current time"), buf);
|
---|
809 | }
|
---|
810 |
|
---|
811 | return ts;
|
---|
812 | }
|
---|
813 | |
---|
814 |
|
---|
815 | /* Return the current time as a file timestamp, setting *RESOLUTION to
|
---|
816 | its resolution. */
|
---|
817 | FILE_TIMESTAMP
|
---|
818 | file_timestamp_now (int *resolution)
|
---|
819 | {
|
---|
820 | int r;
|
---|
821 | time_t s;
|
---|
822 | int ns;
|
---|
823 |
|
---|
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
|
---|
829 | {
|
---|
830 | struct timespec timespec;
|
---|
831 | if (clock_gettime (CLOCK_REALTIME, ×pec) == 0)
|
---|
832 | {
|
---|
833 | r = 1;
|
---|
834 | s = timespec.tv_sec;
|
---|
835 | ns = timespec.tv_nsec;
|
---|
836 | goto got_time;
|
---|
837 | }
|
---|
838 | }
|
---|
839 | # endif
|
---|
840 | # if HAVE_GETTIMEOFDAY
|
---|
841 | {
|
---|
842 | struct timeval timeval;
|
---|
843 | if (gettimeofday (&timeval, 0) == 0)
|
---|
844 | {
|
---|
845 | r = 1000;
|
---|
846 | s = timeval.tv_sec;
|
---|
847 | ns = timeval.tv_usec * 1000;
|
---|
848 | goto got_time;
|
---|
849 | }
|
---|
850 | }
|
---|
851 | # endif
|
---|
852 | #endif
|
---|
853 |
|
---|
854 | r = 1000000000;
|
---|
855 | s = time ((time_t *) 0);
|
---|
856 | ns = 0;
|
---|
857 |
|
---|
858 | #if FILE_TIMESTAMP_HI_RES
|
---|
859 | got_time:
|
---|
860 | #endif
|
---|
861 | *resolution = r;
|
---|
862 | return file_timestamp_cons (0, s, ns);
|
---|
863 | }
|
---|
864 |
|
---|
865 | /* Place into the buffer P a printable representation of the file
|
---|
866 | timestamp TS. */
|
---|
867 | void
|
---|
868 | file_timestamp_sprintf (char *p, FILE_TIMESTAMP ts)
|
---|
869 | {
|
---|
870 | time_t t = FILE_TIMESTAMP_S (ts);
|
---|
871 | struct tm *tm = localtime (&t);
|
---|
872 |
|
---|
873 | if (tm)
|
---|
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);
|
---|
877 | else if (t < 0)
|
---|
878 | sprintf (p, "%ld", (long) t);
|
---|
879 | else
|
---|
880 | sprintf (p, "%lu", (unsigned long) t);
|
---|
881 | p += strlen (p);
|
---|
882 |
|
---|
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));
|
---|
888 | p += strlen (p) - 1;
|
---|
889 | while (*p == '0')
|
---|
890 | p--;
|
---|
891 | p += *p != '.';
|
---|
892 |
|
---|
893 | *p = '\0';
|
---|
894 | }
|
---|
895 | |
---|
896 |
|
---|
897 | /* Print the data base of files. */
|
---|
898 |
|
---|
899 | static void
|
---|
900 | print_file (const void *item)
|
---|
901 | {
|
---|
902 | const struct file *f = item;
|
---|
903 | struct dep *d;
|
---|
904 | struct dep *ood = 0;
|
---|
905 |
|
---|
906 | putchar ('\n');
|
---|
907 | if (!f->is_target)
|
---|
908 | puts (_("# Not a target:"));
|
---|
909 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
910 | if (f->multi_head)
|
---|
911 | {
|
---|
912 | const struct file *f2;
|
---|
913 | if (f->multi_head == f)
|
---|
914 | {
|
---|
915 | int multi_maybe = -1;
|
---|
916 | assert (!f->multi_maybe);
|
---|
917 | assert (!f->double_colon);
|
---|
918 |
|
---|
919 | printf ("%s", f->name);
|
---|
920 | for (f2 = f->multi_next; f2 != 0; f2 = f2->multi_next)
|
---|
921 | {
|
---|
922 | printf (" %s%s", f2->multi_maybe != multi_maybe
|
---|
923 | ? f2->multi_maybe ? "+| " : "+ " : "",
|
---|
924 | f2->name);
|
---|
925 | multi_maybe = f2->multi_maybe;
|
---|
926 | }
|
---|
927 | putchar (':');
|
---|
928 | }
|
---|
929 | else
|
---|
930 | printf ("%s:%s", f->name, f->double_colon ? ":" : "");
|
---|
931 | }
|
---|
932 | else
|
---|
933 | #endif
|
---|
934 | printf ("%s:%s", f->name, f->double_colon ? ":" : "");
|
---|
935 |
|
---|
936 | /* Print all normal dependencies; note any order-only deps. */
|
---|
937 | for (d = f->deps; d != 0; d = d->next)
|
---|
938 | if (! d->ignore_mtime)
|
---|
939 | printf (" %s", dep_name (d));
|
---|
940 | else if (! ood)
|
---|
941 | ood = d;
|
---|
942 |
|
---|
943 | /* Print order-only deps, if we have any. */
|
---|
944 | if (ood)
|
---|
945 | {
|
---|
946 | printf (" | %s", dep_name (ood));
|
---|
947 | for (d = ood->next; d != 0; d = d->next)
|
---|
948 | if (d->ignore_mtime)
|
---|
949 | printf (" %s", dep_name (d));
|
---|
950 | }
|
---|
951 |
|
---|
952 | putchar ('\n');
|
---|
953 |
|
---|
954 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
955 | if (f->multi_head && f->multi_head != f)
|
---|
956 | {
|
---|
957 | const struct file *f2;
|
---|
958 | fputs (_("# In multi target list:"), stdout);
|
---|
959 | for (f2 = f->multi_head; f2 != 0; f2 = f2->multi_next)
|
---|
960 | printf (" %s%s", f2->name, f == f2 ? "(*)" : "");
|
---|
961 | putchar ('\n');
|
---|
962 | if (f->multi_maybe)
|
---|
963 | puts (_("# File is an optional multi target member."));
|
---|
964 | }
|
---|
965 | #endif
|
---|
966 |
|
---|
967 | if (f->precious)
|
---|
968 | puts (_("# Precious file (prerequisite of .PRECIOUS)."));
|
---|
969 | if (f->phony)
|
---|
970 | puts (_("# Phony target (prerequisite of .PHONY)."));
|
---|
971 | if (f->cmd_target)
|
---|
972 | puts (_("# Command-line target."));
|
---|
973 | if (f->dontcare)
|
---|
974 | puts (_("# A default, MAKEFILES, or -include/sinclude makefile."));
|
---|
975 | puts (f->tried_implicit
|
---|
976 | ? _("# Implicit rule search has been done.")
|
---|
977 | : _("# Implicit rule search has not been done."));
|
---|
978 | if (f->stem != 0)
|
---|
979 | printf (_("# Implicit/static pattern stem: `%s'\n"), f->stem);
|
---|
980 | if (f->intermediate)
|
---|
981 | puts (_("# File is an intermediate prerequisite."));
|
---|
982 | if (f->also_make != 0)
|
---|
983 | {
|
---|
984 | fputs (_("# Also makes:"), stdout);
|
---|
985 | for (d = f->also_make; d != 0; d = d->next)
|
---|
986 | printf (" %s", dep_name (d));
|
---|
987 | putchar ('\n');
|
---|
988 | }
|
---|
989 | if (f->last_mtime == UNKNOWN_MTIME)
|
---|
990 | puts (_("# Modification time never checked."));
|
---|
991 | else if (f->last_mtime == NONEXISTENT_MTIME)
|
---|
992 | puts (_("# File does not exist."));
|
---|
993 | else if (f->last_mtime == OLD_MTIME)
|
---|
994 | puts (_("# File is very old."));
|
---|
995 | else
|
---|
996 | {
|
---|
997 | char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
|
---|
998 | file_timestamp_sprintf (buf, f->last_mtime);
|
---|
999 | printf (_("# Last modified %s\n"), buf);
|
---|
1000 | }
|
---|
1001 | puts (f->updated
|
---|
1002 | ? _("# File has been updated.") : _("# File has not been updated."));
|
---|
1003 | switch (f->command_state)
|
---|
1004 | {
|
---|
1005 | case cs_running:
|
---|
1006 | puts (_("# Commands currently running (THIS IS A BUG)."));
|
---|
1007 | break;
|
---|
1008 | case cs_deps_running:
|
---|
1009 | puts (_("# Dependencies commands running (THIS IS A BUG)."));
|
---|
1010 | break;
|
---|
1011 | case cs_not_started:
|
---|
1012 | case cs_finished:
|
---|
1013 | switch (f->update_status)
|
---|
1014 | {
|
---|
1015 | case -1:
|
---|
1016 | break;
|
---|
1017 | case 0:
|
---|
1018 | puts (_("# Successfully updated."));
|
---|
1019 | break;
|
---|
1020 | case 1:
|
---|
1021 | assert (question_flag);
|
---|
1022 | puts (_("# Needs to be updated (-q is set)."));
|
---|
1023 | break;
|
---|
1024 | case 2:
|
---|
1025 | puts (_("# Failed to be updated."));
|
---|
1026 | break;
|
---|
1027 | default:
|
---|
1028 | puts (_("# Invalid value in `update_status' member!"));
|
---|
1029 | fflush (stdout);
|
---|
1030 | fflush (stderr);
|
---|
1031 | abort ();
|
---|
1032 | }
|
---|
1033 | break;
|
---|
1034 | default:
|
---|
1035 | puts (_("# Invalid value in `command_state' member!"));
|
---|
1036 | fflush (stdout);
|
---|
1037 | fflush (stderr);
|
---|
1038 | abort ();
|
---|
1039 | }
|
---|
1040 |
|
---|
1041 | if (f->variables != 0)
|
---|
1042 | print_file_variables (f);
|
---|
1043 |
|
---|
1044 | if (f->cmds != 0)
|
---|
1045 | print_commands (f->cmds);
|
---|
1046 |
|
---|
1047 | if (f->prev)
|
---|
1048 | print_file ((const void *) f->prev);
|
---|
1049 | }
|
---|
1050 |
|
---|
1051 | void
|
---|
1052 | print_file_data_base (void)
|
---|
1053 | {
|
---|
1054 | puts (_("\n# Files"));
|
---|
1055 |
|
---|
1056 | hash_map (&files, print_file);
|
---|
1057 |
|
---|
1058 | fputs (_("\n# files hash-table stats:\n# "), stdout);
|
---|
1059 | hash_print_stats (&files, stdout);
|
---|
1060 | }
|
---|
1061 | |
---|
1062 |
|
---|
1063 | /* Verify the integrity of the data base of files. */
|
---|
1064 |
|
---|
1065 | #define VERIFY_CACHED(_p,_n) \
|
---|
1066 | do{\
|
---|
1067 | if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \
|
---|
1068 | printf ("%s: Field %s not cached: %s\n", _p->name, # _n, _p->_n); \
|
---|
1069 | }while(0)
|
---|
1070 |
|
---|
1071 | static void
|
---|
1072 | verify_file (const void *item)
|
---|
1073 | {
|
---|
1074 | const struct file *f = item;
|
---|
1075 | const struct dep *d;
|
---|
1076 |
|
---|
1077 | VERIFY_CACHED (f, name);
|
---|
1078 | VERIFY_CACHED (f, hname);
|
---|
1079 | VERIFY_CACHED (f, vpath);
|
---|
1080 | VERIFY_CACHED (f, stem);
|
---|
1081 |
|
---|
1082 | /* Check the deps. */
|
---|
1083 | for (d = f->deps; d != 0; d = d->next)
|
---|
1084 | {
|
---|
1085 | VERIFY_CACHED (d, name);
|
---|
1086 | VERIFY_CACHED (d, stem);
|
---|
1087 | }
|
---|
1088 | }
|
---|
1089 |
|
---|
1090 | void
|
---|
1091 | verify_file_data_base (void)
|
---|
1092 | {
|
---|
1093 | hash_map (&files, verify_file);
|
---|
1094 | }
|
---|
1095 |
|
---|
1096 | #define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500)
|
---|
1097 |
|
---|
1098 | char *
|
---|
1099 | build_target_list (char *value)
|
---|
1100 | {
|
---|
1101 | static unsigned long last_targ_count = 0;
|
---|
1102 |
|
---|
1103 | if (files.ht_fill != last_targ_count)
|
---|
1104 | {
|
---|
1105 | unsigned long max = EXPANSION_INCREMENT (strlen (value));
|
---|
1106 | unsigned long len;
|
---|
1107 | char *p;
|
---|
1108 | struct file **fp = (struct file **) files.ht_vec;
|
---|
1109 | struct file **end = &fp[files.ht_size];
|
---|
1110 |
|
---|
1111 | /* Make sure we have at least MAX bytes in the allocated buffer. */
|
---|
1112 | value = xrealloc (value, max);
|
---|
1113 |
|
---|
1114 | p = value;
|
---|
1115 | len = 0;
|
---|
1116 | for (; fp < end; ++fp)
|
---|
1117 | if (!HASH_VACANT (*fp) && (*fp)->is_target)
|
---|
1118 | {
|
---|
1119 | struct file *f = *fp;
|
---|
1120 | int l = strlen (f->name);
|
---|
1121 |
|
---|
1122 | len += l + 1;
|
---|
1123 | if (len > max)
|
---|
1124 | {
|
---|
1125 | unsigned long off = p - value;
|
---|
1126 |
|
---|
1127 | max += EXPANSION_INCREMENT (l + 1);
|
---|
1128 | value = xrealloc (value, max);
|
---|
1129 | p = &value[off];
|
---|
1130 | }
|
---|
1131 |
|
---|
1132 | memcpy (p, f->name, l);
|
---|
1133 | p += l;
|
---|
1134 | *(p++) = ' ';
|
---|
1135 | }
|
---|
1136 | *(p-1) = '\0';
|
---|
1137 |
|
---|
1138 | last_targ_count = files.ht_fill;
|
---|
1139 | }
|
---|
1140 |
|
---|
1141 | return value;
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 | void
|
---|
1145 | init_hash_files (void)
|
---|
1146 | {
|
---|
1147 | #ifdef KMK
|
---|
1148 | hash_init (&files, 8192, file_hash_1, file_hash_2, file_hash_cmp);
|
---|
1149 | #else
|
---|
1150 | hash_init (&files, 1000, file_hash_1, file_hash_2, file_hash_cmp);
|
---|
1151 | #endif
|
---|
1152 | }
|
---|
1153 |
|
---|
1154 | /* EOF */
|
---|