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