1 | /* Basic dependency engine 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, 2007 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 3 of the License, or (at your option) any later
|
---|
10 | version.
|
---|
11 |
|
---|
12 | GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
|
---|
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
---|
14 | A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU General Public License along with
|
---|
17 | this program. If not, see <http://www.gnu.org/licenses/>. */
|
---|
18 |
|
---|
19 | #include "make.h"
|
---|
20 | #include "filedef.h"
|
---|
21 | #include "job.h"
|
---|
22 | #include "commands.h"
|
---|
23 | #include "dep.h"
|
---|
24 | #include "variable.h"
|
---|
25 | #include "debug.h"
|
---|
26 |
|
---|
27 | #include <assert.h>
|
---|
28 |
|
---|
29 | #ifdef HAVE_FCNTL_H
|
---|
30 | #include <fcntl.h>
|
---|
31 | #else
|
---|
32 | #include <sys/file.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #ifdef VMS
|
---|
36 | #include <starlet.h>
|
---|
37 | #endif
|
---|
38 | #ifdef WINDOWS32
|
---|
39 | #include <io.h>
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | extern int try_implicit_rule (struct file *file, unsigned int depth);
|
---|
43 |
|
---|
44 |
|
---|
45 | /* The test for circular dependencies is based on the 'updating' bit in
|
---|
46 | `struct file'. However, double colon targets have seperate `struct
|
---|
47 | file's; make sure we always use the base of the double colon chain. */
|
---|
48 |
|
---|
49 | #define start_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
|
---|
50 | ->updating = 1)
|
---|
51 | #define finish_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
|
---|
52 | ->updating = 0)
|
---|
53 | #define is_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
|
---|
54 | ->updating)
|
---|
55 |
|
---|
56 |
|
---|
57 | /* Incremented when a command is started (under -n, when one would be). */
|
---|
58 | unsigned int commands_started = 0;
|
---|
59 |
|
---|
60 | /* Current value for pruning the scan of the goal chain (toggle 0/1). */
|
---|
61 | static unsigned int considered;
|
---|
62 |
|
---|
63 | static int update_file (struct file *file, unsigned int depth);
|
---|
64 | static int update_file_1 (struct file *file, unsigned int depth);
|
---|
65 | static int check_dep (struct file *file, unsigned int depth,
|
---|
66 | FILE_TIMESTAMP this_mtime, int *must_make_ptr);
|
---|
67 | static int touch_file (struct file *file);
|
---|
68 | static void remake_file (struct file *file);
|
---|
69 | static FILE_TIMESTAMP name_mtime (const char *name);
|
---|
70 | static const char *library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr);
|
---|
71 |
|
---|
72 | |
---|
73 |
|
---|
74 | /* Remake all the goals in the `struct dep' chain GOALS. Return -1 if nothing
|
---|
75 | was done, 0 if all goals were updated successfully, or 1 if a goal failed.
|
---|
76 |
|
---|
77 | If rebuilding_makefiles is nonzero, these goals are makefiles, so -t, -q,
|
---|
78 | and -n should be disabled for them unless they were also command-line
|
---|
79 | targets, and we should only make one goal at a time and return as soon as
|
---|
80 | one goal whose `changed' member is nonzero is successfully made. */
|
---|
81 |
|
---|
82 | int
|
---|
83 | update_goal_chain (struct dep *goals)
|
---|
84 | {
|
---|
85 | int t = touch_flag, q = question_flag, n = just_print_flag;
|
---|
86 | unsigned int j = job_slots;
|
---|
87 | int status = -1;
|
---|
88 |
|
---|
89 | #define MTIME(file) (rebuilding_makefiles ? file_mtime_no_search (file) \
|
---|
90 | : file_mtime (file))
|
---|
91 |
|
---|
92 | /* Duplicate the chain so we can remove things from it. */
|
---|
93 |
|
---|
94 | goals = copy_dep_chain (goals);
|
---|
95 |
|
---|
96 | {
|
---|
97 | /* Clear the `changed' flag of each goal in the chain.
|
---|
98 | We will use the flag below to notice when any commands
|
---|
99 | have actually been run for a target. When no commands
|
---|
100 | have been run, we give an "up to date" diagnostic. */
|
---|
101 |
|
---|
102 | struct dep *g;
|
---|
103 | for (g = goals; g != 0; g = g->next)
|
---|
104 | g->changed = 0;
|
---|
105 | }
|
---|
106 |
|
---|
107 | /* All files start with the considered bit 0, so the global value is 1. */
|
---|
108 | considered = 1;
|
---|
109 |
|
---|
110 | /* Update all the goals until they are all finished. */
|
---|
111 |
|
---|
112 | while (goals != 0)
|
---|
113 | {
|
---|
114 | register struct dep *g, *lastgoal;
|
---|
115 |
|
---|
116 | /* Start jobs that are waiting for the load to go down. */
|
---|
117 |
|
---|
118 | start_waiting_jobs ();
|
---|
119 |
|
---|
120 | /* Wait for a child to die. */
|
---|
121 |
|
---|
122 | reap_children (1, 0);
|
---|
123 |
|
---|
124 | lastgoal = 0;
|
---|
125 | g = goals;
|
---|
126 | while (g != 0)
|
---|
127 | {
|
---|
128 | /* Iterate over all double-colon entries for this file. */
|
---|
129 | struct file *file;
|
---|
130 | int stop = 0, any_not_updated = 0;
|
---|
131 |
|
---|
132 | for (file = g->file->double_colon ? g->file->double_colon : g->file;
|
---|
133 | file != NULL;
|
---|
134 | file = file->prev)
|
---|
135 | {
|
---|
136 | unsigned int ocommands_started;
|
---|
137 | int x;
|
---|
138 | check_renamed (file);
|
---|
139 | if (rebuilding_makefiles)
|
---|
140 | {
|
---|
141 | if (file->cmd_target)
|
---|
142 | {
|
---|
143 | touch_flag = t;
|
---|
144 | question_flag = q;
|
---|
145 | just_print_flag = n;
|
---|
146 | }
|
---|
147 | else
|
---|
148 | touch_flag = question_flag = just_print_flag = 0;
|
---|
149 | }
|
---|
150 |
|
---|
151 | /* Save the old value of `commands_started' so we can compare
|
---|
152 | later. It will be incremented when any commands are
|
---|
153 | actually run. */
|
---|
154 | ocommands_started = commands_started;
|
---|
155 |
|
---|
156 | x = update_file (file, rebuilding_makefiles ? 1 : 0);
|
---|
157 | check_renamed (file);
|
---|
158 |
|
---|
159 | /* Set the goal's `changed' flag if any commands were started
|
---|
160 | by calling update_file above. We check this flag below to
|
---|
161 | decide when to give an "up to date" diagnostic. */
|
---|
162 | if (commands_started > ocommands_started)
|
---|
163 | g->changed = 1;
|
---|
164 |
|
---|
165 | /* If we updated a file and STATUS was not already 1, set it to
|
---|
166 | 1 if updating failed, or to 0 if updating succeeded. Leave
|
---|
167 | STATUS as it is if no updating was done. */
|
---|
168 |
|
---|
169 | stop = 0;
|
---|
170 | if ((x != 0 || file->updated) && status < 1)
|
---|
171 | {
|
---|
172 | if (file->update_status != 0)
|
---|
173 | {
|
---|
174 | /* Updating failed, or -q triggered. The STATUS value
|
---|
175 | tells our caller which. */
|
---|
176 | status = file->update_status;
|
---|
177 | /* If -q just triggered, stop immediately. It doesn't
|
---|
178 | matter how much more we run, since we already know
|
---|
179 | the answer to return. */
|
---|
180 | stop = (question_flag && !keep_going_flag
|
---|
181 | && !rebuilding_makefiles);
|
---|
182 | }
|
---|
183 | else
|
---|
184 | {
|
---|
185 | FILE_TIMESTAMP mtime = MTIME (file);
|
---|
186 | check_renamed (file);
|
---|
187 |
|
---|
188 | if (file->updated && g->changed &&
|
---|
189 | mtime != file->mtime_before_update)
|
---|
190 | {
|
---|
191 | /* Updating was done. If this is a makefile and
|
---|
192 | just_print_flag or question_flag is set (meaning
|
---|
193 | -n or -q was given and this file was specified
|
---|
194 | as a command-line target), don't change STATUS.
|
---|
195 | If STATUS is changed, we will get re-exec'd, and
|
---|
196 | enter an infinite loop. */
|
---|
197 | if (!rebuilding_makefiles
|
---|
198 | || (!just_print_flag && !question_flag))
|
---|
199 | status = 0;
|
---|
200 | if (rebuilding_makefiles && file->dontcare)
|
---|
201 | /* This is a default makefile; stop remaking. */
|
---|
202 | stop = 1;
|
---|
203 | }
|
---|
204 | }
|
---|
205 | }
|
---|
206 |
|
---|
207 | /* Keep track if any double-colon entry is not finished.
|
---|
208 | When they are all finished, the goal is finished. */
|
---|
209 | any_not_updated |= !file->updated;
|
---|
210 |
|
---|
211 | if (stop)
|
---|
212 | break;
|
---|
213 | }
|
---|
214 |
|
---|
215 | /* Reset FILE since it is null at the end of the loop. */
|
---|
216 | file = g->file;
|
---|
217 |
|
---|
218 | if (stop || !any_not_updated)
|
---|
219 | {
|
---|
220 | /* If we have found nothing whatever to do for the goal,
|
---|
221 | print a message saying nothing needs doing. */
|
---|
222 |
|
---|
223 | if (!rebuilding_makefiles
|
---|
224 | /* If the update_status is zero, we updated successfully
|
---|
225 | or not at all. G->changed will have been set above if
|
---|
226 | any commands were actually started for this goal. */
|
---|
227 | && file->update_status == 0 && !g->changed
|
---|
228 | /* Never give a message under -s or -q. */
|
---|
229 | && !silent_flag && !question_flag)
|
---|
230 | message (1, ((file->phony || file->cmds == 0)
|
---|
231 | ? _("Nothing to be done for `%s'.")
|
---|
232 | : _("`%s' is up to date.")),
|
---|
233 | file->name);
|
---|
234 |
|
---|
235 | /* This goal is finished. Remove it from the chain. */
|
---|
236 | if (lastgoal == 0)
|
---|
237 | goals = g->next;
|
---|
238 | else
|
---|
239 | lastgoal->next = g->next;
|
---|
240 |
|
---|
241 | /* Free the storage. */
|
---|
242 | #ifndef CONFIG_WITH_ALLOC_CACHES
|
---|
243 | free (g);
|
---|
244 | #else
|
---|
245 | free_dep (g);
|
---|
246 | #endif
|
---|
247 |
|
---|
248 | g = lastgoal == 0 ? goals : lastgoal->next;
|
---|
249 |
|
---|
250 | if (stop)
|
---|
251 | break;
|
---|
252 | }
|
---|
253 | else
|
---|
254 | {
|
---|
255 | lastgoal = g;
|
---|
256 | g = g->next;
|
---|
257 | }
|
---|
258 | }
|
---|
259 |
|
---|
260 | /* If we reached the end of the dependency graph toggle the considered
|
---|
261 | flag for the next pass. */
|
---|
262 | if (g == 0)
|
---|
263 | considered = !considered;
|
---|
264 | }
|
---|
265 |
|
---|
266 | if (rebuilding_makefiles)
|
---|
267 | {
|
---|
268 | touch_flag = t;
|
---|
269 | question_flag = q;
|
---|
270 | just_print_flag = n;
|
---|
271 | job_slots = j;
|
---|
272 | }
|
---|
273 |
|
---|
274 | return status;
|
---|
275 | }
|
---|
276 | |
---|
277 |
|
---|
278 | /* If FILE is not up to date, execute the commands for it.
|
---|
279 | Return 0 if successful, 1 if unsuccessful;
|
---|
280 | but with some flag settings, just call `exit' if unsuccessful.
|
---|
281 |
|
---|
282 | DEPTH is the depth in recursions of this function.
|
---|
283 | We increment it during the consideration of our dependencies,
|
---|
284 | then decrement it again after finding out whether this file
|
---|
285 | is out of date.
|
---|
286 |
|
---|
287 | If there are multiple double-colon entries for FILE,
|
---|
288 | each is considered in turn. */
|
---|
289 |
|
---|
290 | static int
|
---|
291 | update_file (struct file *file, unsigned int depth)
|
---|
292 | {
|
---|
293 | register int status = 0;
|
---|
294 | register struct file *f;
|
---|
295 |
|
---|
296 | f = file->double_colon ? file->double_colon : file;
|
---|
297 |
|
---|
298 | /* Prune the dependency graph: if we've already been here on _this_
|
---|
299 | pass through the dependency graph, we don't have to go any further.
|
---|
300 | We won't reap_children until we start the next pass, so no state
|
---|
301 | change is possible below here until then. */
|
---|
302 | if (f->considered == considered)
|
---|
303 | {
|
---|
304 | DBF (DB_VERBOSE, _("Pruning file `%s'.\n"));
|
---|
305 | return f->command_state == cs_finished ? f->update_status : 0;
|
---|
306 | }
|
---|
307 |
|
---|
308 | /* This loop runs until we start commands for a double colon rule, or until
|
---|
309 | the chain is exhausted. */
|
---|
310 | for (; f != 0; f = f->prev)
|
---|
311 | {
|
---|
312 | f->considered = considered;
|
---|
313 |
|
---|
314 | status |= update_file_1 (f, depth);
|
---|
315 | check_renamed (f);
|
---|
316 |
|
---|
317 | /* Clean up any alloca() used during the update. */
|
---|
318 | alloca (0);
|
---|
319 |
|
---|
320 | /* If we got an error, don't bother with double_colon etc. */
|
---|
321 | if (status != 0 && !keep_going_flag)
|
---|
322 | return status;
|
---|
323 |
|
---|
324 | if (f->command_state == cs_running
|
---|
325 | || f->command_state == cs_deps_running)
|
---|
326 | {
|
---|
327 | /* Don't run the other :: rules for this
|
---|
328 | file until this rule is finished. */
|
---|
329 | status = 0;
|
---|
330 | break;
|
---|
331 | }
|
---|
332 | }
|
---|
333 |
|
---|
334 | /* Process the remaining rules in the double colon chain so they're marked
|
---|
335 | considered. Start their prerequisites, too. */
|
---|
336 | if (file->double_colon)
|
---|
337 | for (; f != 0 ; f = f->prev)
|
---|
338 | {
|
---|
339 | struct dep *d;
|
---|
340 |
|
---|
341 | f->considered = considered;
|
---|
342 |
|
---|
343 | for (d = f->deps; d != 0; d = d->next)
|
---|
344 | status |= update_file (d->file, depth + 1);
|
---|
345 | }
|
---|
346 |
|
---|
347 | return status;
|
---|
348 | }
|
---|
349 | |
---|
350 |
|
---|
351 | /* Show a message stating the target failed to build. */
|
---|
352 |
|
---|
353 | static void
|
---|
354 | complain (const struct file *file)
|
---|
355 | {
|
---|
356 | const char *msg_noparent
|
---|
357 | = _("%sNo rule to make target `%s'%s");
|
---|
358 | const char *msg_parent
|
---|
359 | = _("%sNo rule to make target `%s', needed by `%s'%s");
|
---|
360 |
|
---|
361 | if (!keep_going_flag)
|
---|
362 | {
|
---|
363 | if (file->parent == 0)
|
---|
364 | fatal (NILF, msg_noparent, "", file->name, "");
|
---|
365 |
|
---|
366 | fatal (NILF, msg_parent, "", file->name, file->parent->name, "");
|
---|
367 | }
|
---|
368 |
|
---|
369 | if (file->parent == 0)
|
---|
370 | error (NILF, msg_noparent, "*** ", file->name, ".");
|
---|
371 | else
|
---|
372 | error (NILF, msg_parent, "*** ", file->name, file->parent->name, ".");
|
---|
373 | }
|
---|
374 |
|
---|
375 | /* Consider a single `struct file' and update it as appropriate. */
|
---|
376 |
|
---|
377 | static int
|
---|
378 | update_file_1 (struct file *file, unsigned int depth)
|
---|
379 | {
|
---|
380 | register FILE_TIMESTAMP this_mtime;
|
---|
381 | int noexist, must_make, deps_changed;
|
---|
382 | int dep_status = 0;
|
---|
383 | register struct dep *d, *lastd;
|
---|
384 | int running = 0;
|
---|
385 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
386 | struct file *f2, *f3;
|
---|
387 |
|
---|
388 | /* Always work on the primary multi target file. */
|
---|
389 |
|
---|
390 | if (file->multi_head != NULL && file->multi_head != file)
|
---|
391 | {
|
---|
392 | DBS (DB_VERBOSE, (_("Considering target file `%s' -> multi head `%s'.\n"),
|
---|
393 | file->name, file->multi_head->name));
|
---|
394 | file = file->multi_head;
|
---|
395 | }
|
---|
396 | else
|
---|
397 | #endif /* CONFIG_WITH_EXPLICIT_MULTITARGET */
|
---|
398 | DBF (DB_VERBOSE, _("Considering target file `%s'.\n"));
|
---|
399 |
|
---|
400 | if (file->updated)
|
---|
401 | {
|
---|
402 | if (file->update_status > 0)
|
---|
403 | {
|
---|
404 | DBF (DB_VERBOSE,
|
---|
405 | _("Recently tried and failed to update file `%s'.\n"));
|
---|
406 |
|
---|
407 | /* If the file we tried to make is marked dontcare then no message
|
---|
408 | was printed about it when it failed during the makefile rebuild.
|
---|
409 | If we're trying to build it again in the normal rebuild, print a
|
---|
410 | message now. */
|
---|
411 | if (file->dontcare && !rebuilding_makefiles)
|
---|
412 | {
|
---|
413 | file->dontcare = 0;
|
---|
414 | complain (file);
|
---|
415 | }
|
---|
416 |
|
---|
417 | return file->update_status;
|
---|
418 | }
|
---|
419 |
|
---|
420 | DBF (DB_VERBOSE, _("File `%s' was considered already.\n"));
|
---|
421 | return 0;
|
---|
422 | }
|
---|
423 |
|
---|
424 | switch (file->command_state)
|
---|
425 | {
|
---|
426 | case cs_not_started:
|
---|
427 | case cs_deps_running:
|
---|
428 | break;
|
---|
429 | case cs_running:
|
---|
430 | DBF (DB_VERBOSE, _("Still updating file `%s'.\n"));
|
---|
431 | return 0;
|
---|
432 | case cs_finished:
|
---|
433 | DBF (DB_VERBOSE, _("Finished updating file `%s'.\n"));
|
---|
434 | return file->update_status;
|
---|
435 | default:
|
---|
436 | abort ();
|
---|
437 | }
|
---|
438 |
|
---|
439 | ++depth;
|
---|
440 |
|
---|
441 | /* Notice recursive update of the same file. */
|
---|
442 | start_updating (file);
|
---|
443 |
|
---|
444 | /* Looking at the file's modtime beforehand allows the possibility
|
---|
445 | that its name may be changed by a VPATH search, and thus it may
|
---|
446 | not need an implicit rule. If this were not done, the file
|
---|
447 | might get implicit commands that apply to its initial name, only
|
---|
448 | to have that name replaced with another found by VPATH search.
|
---|
449 |
|
---|
450 | For multi target files check the other files and use the time
|
---|
451 | of the oldest / non-existing file. */
|
---|
452 |
|
---|
453 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
454 | this_mtime = file_mtime (file);
|
---|
455 | f3 = file;
|
---|
456 | for (f2 = file->multi_next;
|
---|
457 | f2 != NULL && this_mtime != NONEXISTENT_MTIME;
|
---|
458 | f2 = f2->multi_next)
|
---|
459 | if (!f2->multi_maybe)
|
---|
460 | {
|
---|
461 | FILE_TIMESTAMP second_mtime = file_mtime (f2);
|
---|
462 | if (second_mtime < this_mtime)
|
---|
463 | {
|
---|
464 | this_mtime = second_mtime;
|
---|
465 | f3 = f2;
|
---|
466 | }
|
---|
467 | }
|
---|
468 | check_renamed (file);
|
---|
469 | noexist = this_mtime == NONEXISTENT_MTIME;
|
---|
470 | if (noexist)
|
---|
471 | DBS (DB_BASIC, (_("File `%s' does not exist.\n"), f3->name));
|
---|
472 | #else /* !CONFIG_WITH_EXPLICIT_MULTITARGET */
|
---|
473 | this_mtime = file_mtime (file);
|
---|
474 | check_renamed (file);
|
---|
475 | noexist = this_mtime == NONEXISTENT_MTIME;
|
---|
476 | if (noexist)
|
---|
477 | DBF (DB_BASIC, _("File `%s' does not exist.\n"));
|
---|
478 | #endif /* !CONFIG_WITH_EXPLICIT_MULTITARGET */
|
---|
479 | else if (ORDINARY_MTIME_MIN <= this_mtime && this_mtime <= ORDINARY_MTIME_MAX
|
---|
480 | && file->low_resolution_time)
|
---|
481 | {
|
---|
482 | /* Avoid spurious rebuilds due to low resolution time stamps. */
|
---|
483 | int ns = FILE_TIMESTAMP_NS (this_mtime);
|
---|
484 | if (ns != 0)
|
---|
485 | error (NILF, _("*** Warning: .LOW_RESOLUTION_TIME file `%s' has a high resolution time stamp"),
|
---|
486 | file->name);
|
---|
487 | this_mtime += FILE_TIMESTAMPS_PER_S - 1 - ns;
|
---|
488 | }
|
---|
489 |
|
---|
490 | must_make = noexist;
|
---|
491 |
|
---|
492 | /* If file was specified as a target with no commands,
|
---|
493 | come up with some default commands. */
|
---|
494 |
|
---|
495 | if (!file->phony && file->cmds == 0 && !file->tried_implicit)
|
---|
496 | {
|
---|
497 | if (try_implicit_rule (file, depth))
|
---|
498 | DBF (DB_IMPLICIT, _("Found an implicit rule for `%s'.\n"));
|
---|
499 | else
|
---|
500 | DBF (DB_IMPLICIT, _("No implicit rule found for `%s'.\n"));
|
---|
501 | file->tried_implicit = 1;
|
---|
502 | }
|
---|
503 | if (file->cmds == 0 && !file->is_target
|
---|
504 | && default_file != 0 && default_file->cmds != 0)
|
---|
505 | {
|
---|
506 | DBF (DB_IMPLICIT, _("Using default recipe for `%s'.\n"));
|
---|
507 | file->cmds = default_file->cmds;
|
---|
508 | }
|
---|
509 |
|
---|
510 | /* Update all non-intermediate files we depend on, if necessary,
|
---|
511 | and see whether any of them is more recent than this file.
|
---|
512 | For explicit multitarget rules we must iterate all the output
|
---|
513 | files to get the correct picture. */
|
---|
514 |
|
---|
515 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
516 | for (f2 = file; f2; f2 = f2->multi_next)
|
---|
517 | {
|
---|
518 | lastd = 0;
|
---|
519 | d = f2->deps;
|
---|
520 | #else
|
---|
521 | lastd = 0;
|
---|
522 | d = file->deps;
|
---|
523 | #endif
|
---|
524 | while (d != 0)
|
---|
525 | {
|
---|
526 | FILE_TIMESTAMP mtime;
|
---|
527 | int maybe_make;
|
---|
528 | int dontcare = 0;
|
---|
529 |
|
---|
530 | check_renamed (d->file);
|
---|
531 |
|
---|
532 | mtime = file_mtime (d->file);
|
---|
533 | check_renamed (d->file);
|
---|
534 |
|
---|
535 | if (is_updating (d->file))
|
---|
536 | {
|
---|
537 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
538 | /* silently ignore the order-only dep hack. */
|
---|
539 | if (f2->multi_maybe && d->file == file)
|
---|
540 | {
|
---|
541 | lastd = d;
|
---|
542 | d = d->next;
|
---|
543 | continue;
|
---|
544 | }
|
---|
545 | #endif
|
---|
546 |
|
---|
547 | error (NILF, _("Circular %s <- %s dependency dropped."),
|
---|
548 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
549 | f2->name, d->file->name);
|
---|
550 | #else
|
---|
551 | file->name, d->file->name);
|
---|
552 | #endif
|
---|
553 | /* We cannot free D here because our the caller will still have
|
---|
554 | a reference to it when we were called recursively via
|
---|
555 | check_dep below. */
|
---|
556 | if (lastd == 0)
|
---|
557 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
558 | f2->deps = d->next;
|
---|
559 | #else
|
---|
560 | file->deps = d->next;
|
---|
561 | #endif
|
---|
562 | else
|
---|
563 | lastd->next = d->next;
|
---|
564 | d = d->next;
|
---|
565 | continue;
|
---|
566 | }
|
---|
567 |
|
---|
568 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
569 | d->file->parent = f2;
|
---|
570 | #else
|
---|
571 | d->file->parent = file;
|
---|
572 | #endif
|
---|
573 | maybe_make = must_make;
|
---|
574 |
|
---|
575 | /* Inherit dontcare flag from our parent. */
|
---|
576 | if (rebuilding_makefiles)
|
---|
577 | {
|
---|
578 | dontcare = d->file->dontcare;
|
---|
579 | d->file->dontcare = file->dontcare;
|
---|
580 | }
|
---|
581 |
|
---|
582 |
|
---|
583 | dep_status |= check_dep (d->file, depth, this_mtime, &maybe_make);
|
---|
584 |
|
---|
585 | /* Restore original dontcare flag. */
|
---|
586 | if (rebuilding_makefiles)
|
---|
587 | d->file->dontcare = dontcare;
|
---|
588 |
|
---|
589 | if (! d->ignore_mtime)
|
---|
590 | must_make = maybe_make;
|
---|
591 |
|
---|
592 | check_renamed (d->file);
|
---|
593 |
|
---|
594 | {
|
---|
595 | register struct file *f = d->file;
|
---|
596 | if (f->double_colon)
|
---|
597 | f = f->double_colon;
|
---|
598 | do
|
---|
599 | {
|
---|
600 | running |= (f->command_state == cs_running
|
---|
601 | || f->command_state == cs_deps_running);
|
---|
602 | f = f->prev;
|
---|
603 | }
|
---|
604 | while (f != 0);
|
---|
605 | }
|
---|
606 |
|
---|
607 | if (dep_status != 0 && !keep_going_flag)
|
---|
608 | break;
|
---|
609 |
|
---|
610 | if (!running)
|
---|
611 | /* The prereq is considered changed if the timestamp has changed while
|
---|
612 | it was built, OR it doesn't exist. */
|
---|
613 | d->changed = ((file_mtime (d->file) != mtime)
|
---|
614 | || (mtime == NONEXISTENT_MTIME));
|
---|
615 |
|
---|
616 | lastd = d;
|
---|
617 | d = d->next;
|
---|
618 | }
|
---|
619 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
620 | if (dep_status != 0 && !keep_going_flag)
|
---|
621 | break;
|
---|
622 | }
|
---|
623 | #endif
|
---|
624 |
|
---|
625 | /* Now we know whether this target needs updating.
|
---|
626 | If it does, update all the intermediate files we depend on. */
|
---|
627 |
|
---|
628 | if (must_make || always_make_flag)
|
---|
629 | {
|
---|
630 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
631 | for (f2 = file; f2; f2 = f2->multi_next)
|
---|
632 | for (d = f2->deps; d != 0; d = d->next)
|
---|
633 | #else
|
---|
634 | for (d = file->deps; d != 0; d = d->next)
|
---|
635 | #endif
|
---|
636 | if (d->file->intermediate)
|
---|
637 | {
|
---|
638 | int dontcare = 0;
|
---|
639 |
|
---|
640 | FILE_TIMESTAMP mtime = file_mtime (d->file);
|
---|
641 | check_renamed (d->file);
|
---|
642 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
643 | d->file->parent = f2;
|
---|
644 | #else
|
---|
645 | d->file->parent = file;
|
---|
646 | #endif
|
---|
647 |
|
---|
648 | /* Inherit dontcare flag from our parent. */
|
---|
649 | if (rebuilding_makefiles)
|
---|
650 | {
|
---|
651 | dontcare = d->file->dontcare;
|
---|
652 | d->file->dontcare = file->dontcare;
|
---|
653 | }
|
---|
654 |
|
---|
655 |
|
---|
656 | dep_status |= update_file (d->file, depth);
|
---|
657 |
|
---|
658 | /* Restore original dontcare flag. */
|
---|
659 | if (rebuilding_makefiles)
|
---|
660 | d->file->dontcare = dontcare;
|
---|
661 |
|
---|
662 | check_renamed (d->file);
|
---|
663 |
|
---|
664 | {
|
---|
665 | register struct file *f = d->file;
|
---|
666 | if (f->double_colon)
|
---|
667 | f = f->double_colon;
|
---|
668 | do
|
---|
669 | {
|
---|
670 | running |= (f->command_state == cs_running
|
---|
671 | || f->command_state == cs_deps_running);
|
---|
672 | f = f->prev;
|
---|
673 | }
|
---|
674 | while (f != 0);
|
---|
675 | }
|
---|
676 |
|
---|
677 | if (dep_status != 0 && !keep_going_flag)
|
---|
678 | break;
|
---|
679 |
|
---|
680 | if (!running)
|
---|
681 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
682 | d->changed = ((f2->phony && f2->cmds != 0)
|
---|
683 | #else
|
---|
684 | d->changed = ((file->phony && file->cmds != 0)
|
---|
685 | #endif
|
---|
686 | || file_mtime (d->file) != mtime);
|
---|
687 | }
|
---|
688 | }
|
---|
689 |
|
---|
690 | finish_updating (file);
|
---|
691 |
|
---|
692 | DBF (DB_VERBOSE, _("Finished prerequisites of target file `%s'.\n"));
|
---|
693 |
|
---|
694 | if (running)
|
---|
695 | {
|
---|
696 | set_command_state (file, cs_deps_running);
|
---|
697 | --depth;
|
---|
698 | DBF (DB_VERBOSE, _("The prerequisites of `%s' are being made.\n"));
|
---|
699 | return 0;
|
---|
700 | }
|
---|
701 |
|
---|
702 | /* If any dependency failed, give up now. */
|
---|
703 |
|
---|
704 | if (dep_status != 0)
|
---|
705 | {
|
---|
706 | file->update_status = dep_status;
|
---|
707 | notice_finished_file (file);
|
---|
708 |
|
---|
709 | --depth;
|
---|
710 |
|
---|
711 | DBF (DB_VERBOSE, _("Giving up on target file `%s'.\n"));
|
---|
712 |
|
---|
713 | if (depth == 0 && keep_going_flag
|
---|
714 | && !just_print_flag && !question_flag)
|
---|
715 | error (NILF,
|
---|
716 | _("Target `%s' not remade because of errors."), file->name);
|
---|
717 |
|
---|
718 | return dep_status;
|
---|
719 | }
|
---|
720 |
|
---|
721 | if (file->command_state == cs_deps_running)
|
---|
722 | /* The commands for some deps were running on the last iteration, but
|
---|
723 | they have finished now. Reset the command_state to not_started to
|
---|
724 | simplify later bookkeeping. It is important that we do this only
|
---|
725 | when the prior state was cs_deps_running, because that prior state
|
---|
726 | was definitely propagated to FILE's also_make's by set_command_state
|
---|
727 | (called above), but in another state an also_make may have
|
---|
728 | independently changed to finished state, and we would confuse that
|
---|
729 | file's bookkeeping (updated, but not_started is bogus state). */
|
---|
730 | set_command_state (file, cs_not_started);
|
---|
731 |
|
---|
732 | /* Now record which prerequisites are more
|
---|
733 | recent than this file, so we can define $?. */
|
---|
734 |
|
---|
735 | deps_changed = 0;
|
---|
736 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
737 | for (f2 = file; f2; f2 = f2->multi_next)
|
---|
738 | #endif
|
---|
739 | for (d = file->deps; d != 0; d = d->next)
|
---|
740 | {
|
---|
741 | FILE_TIMESTAMP d_mtime = file_mtime (d->file);
|
---|
742 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
743 | if (d->file == file && f2->multi_maybe)
|
---|
744 | continue;
|
---|
745 | #endif
|
---|
746 | check_renamed (d->file);
|
---|
747 |
|
---|
748 | if (! d->ignore_mtime)
|
---|
749 | {
|
---|
750 | #if 1
|
---|
751 | /* %%% In version 4, remove this code completely to
|
---|
752 | implement not remaking deps if their deps are newer
|
---|
753 | than their parents. */
|
---|
754 | if (d_mtime == NONEXISTENT_MTIME && !d->file->intermediate)
|
---|
755 | /* We must remake if this dep does not
|
---|
756 | exist and is not intermediate. */
|
---|
757 | must_make = 1;
|
---|
758 | #endif
|
---|
759 |
|
---|
760 | /* Set DEPS_CHANGED if this dep actually changed. */
|
---|
761 | deps_changed |= d->changed;
|
---|
762 | }
|
---|
763 |
|
---|
764 | /* Set D->changed if either this dep actually changed,
|
---|
765 | or its dependent, FILE, is older or does not exist. */
|
---|
766 | d->changed |= noexist || d_mtime > this_mtime;
|
---|
767 |
|
---|
768 | if (!noexist && ISDB (DB_BASIC|DB_VERBOSE))
|
---|
769 | {
|
---|
770 | const char *fmt = 0;
|
---|
771 |
|
---|
772 | if (d->ignore_mtime)
|
---|
773 | {
|
---|
774 | if (ISDB (DB_VERBOSE))
|
---|
775 | fmt = _("Prerequisite `%s' is order-only for target `%s'.\n");
|
---|
776 | }
|
---|
777 | else if (d_mtime == NONEXISTENT_MTIME)
|
---|
778 | {
|
---|
779 | if (ISDB (DB_BASIC))
|
---|
780 | fmt = _("Prerequisite `%s' of target `%s' does not exist.\n");
|
---|
781 | }
|
---|
782 | else if (d->changed)
|
---|
783 | {
|
---|
784 | if (ISDB (DB_BASIC))
|
---|
785 | fmt = _("Prerequisite `%s' is newer than target `%s'.\n");
|
---|
786 | }
|
---|
787 | else if (ISDB (DB_VERBOSE))
|
---|
788 | fmt = _("Prerequisite `%s' is older than target `%s'.\n");
|
---|
789 |
|
---|
790 | if (fmt)
|
---|
791 | {
|
---|
792 | print_spaces (depth);
|
---|
793 | printf (fmt, dep_name (d), file->name);
|
---|
794 | fflush (stdout);
|
---|
795 | }
|
---|
796 | }
|
---|
797 | }
|
---|
798 |
|
---|
799 | /* Here depth returns to the value it had when we were called. */
|
---|
800 | depth--;
|
---|
801 |
|
---|
802 | if (file->double_colon && file->deps == 0)
|
---|
803 | {
|
---|
804 | must_make = 1;
|
---|
805 | DBF (DB_BASIC,
|
---|
806 | _("Target `%s' is double-colon and has no prerequisites.\n"));
|
---|
807 | }
|
---|
808 | else if (!noexist && file->is_target && !deps_changed && file->cmds == 0
|
---|
809 | && !always_make_flag)
|
---|
810 | {
|
---|
811 | must_make = 0;
|
---|
812 | DBF (DB_VERBOSE,
|
---|
813 | _("No recipe for `%s' and no prerequisites actually changed.\n"));
|
---|
814 | }
|
---|
815 | else if (!must_make && file->cmds != 0 && always_make_flag)
|
---|
816 | {
|
---|
817 | must_make = 1;
|
---|
818 | DBF (DB_VERBOSE, _("Making `%s' due to always-make flag.\n"));
|
---|
819 | }
|
---|
820 |
|
---|
821 | if (!must_make)
|
---|
822 | {
|
---|
823 | if (ISDB (DB_VERBOSE))
|
---|
824 | {
|
---|
825 | print_spaces (depth);
|
---|
826 | printf (_("No need to remake target `%s'"), file->name);
|
---|
827 | if (!streq (file->name, file->hname))
|
---|
828 | printf (_("; using VPATH name `%s'"), file->hname);
|
---|
829 | puts (".");
|
---|
830 | fflush (stdout);
|
---|
831 | }
|
---|
832 |
|
---|
833 | notice_finished_file (file);
|
---|
834 |
|
---|
835 | /* Since we don't need to remake the file, convert it to use the
|
---|
836 | VPATH filename if we found one. hfile will be either the
|
---|
837 | local name if no VPATH or the VPATH name if one was found. */
|
---|
838 |
|
---|
839 | while (file)
|
---|
840 | {
|
---|
841 | file->name = file->hname;
|
---|
842 | file = file->prev;
|
---|
843 | }
|
---|
844 |
|
---|
845 | return 0;
|
---|
846 | }
|
---|
847 |
|
---|
848 | DBF (DB_BASIC, _("Must remake target `%s'.\n"));
|
---|
849 |
|
---|
850 | /* It needs to be remade. If it's VPATH and not reset via GPATH, toss the
|
---|
851 | VPATH. */
|
---|
852 | if (!streq(file->name, file->hname))
|
---|
853 | {
|
---|
854 | DB (DB_BASIC, (_(" Ignoring VPATH name `%s'.\n"), file->hname));
|
---|
855 | file->ignore_vpath = 1;
|
---|
856 | }
|
---|
857 |
|
---|
858 | /* Now, take appropriate actions to remake the file. */
|
---|
859 | remake_file (file);
|
---|
860 |
|
---|
861 | if (file->command_state != cs_finished)
|
---|
862 | {
|
---|
863 | DBF (DB_VERBOSE, _("Recipe of `%s' is being run.\n"));
|
---|
864 | return 0;
|
---|
865 | }
|
---|
866 |
|
---|
867 | switch (file->update_status)
|
---|
868 | {
|
---|
869 | case 2:
|
---|
870 | DBF (DB_BASIC, _("Failed to remake target file `%s'.\n"));
|
---|
871 | break;
|
---|
872 | case 0:
|
---|
873 | DBF (DB_BASIC, _("Successfully remade target file `%s'.\n"));
|
---|
874 | break;
|
---|
875 | case 1:
|
---|
876 | DBF (DB_BASIC, _("Target file `%s' needs remade under -q.\n"));
|
---|
877 | break;
|
---|
878 | default:
|
---|
879 | assert (file->update_status >= 0 && file->update_status <= 2);
|
---|
880 | break;
|
---|
881 | }
|
---|
882 |
|
---|
883 | file->updated = 1;
|
---|
884 | return file->update_status;
|
---|
885 | }
|
---|
886 | |
---|
887 |
|
---|
888 | /* Set FILE's `updated' flag and re-check its mtime and the mtime's of all
|
---|
889 | files listed in its `also_make' member. Under -t, this function also
|
---|
890 | touches FILE.
|
---|
891 |
|
---|
892 | On return, FILE->update_status will no longer be -1 if it was. */
|
---|
893 |
|
---|
894 | void
|
---|
895 | notice_finished_file (struct file *file)
|
---|
896 | {
|
---|
897 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
898 | struct file *f2;
|
---|
899 | #endif
|
---|
900 | struct dep *d;
|
---|
901 | int ran = file->command_state == cs_running;
|
---|
902 | int touched = 0;
|
---|
903 | DB (DB_JOBS, (_("notice_finished_file - entering: file=%p `%s' update_status=%d command_state=%d\n"), /* bird */
|
---|
904 | (void *) file, file->name, file->update_status, file->command_state));
|
---|
905 |
|
---|
906 | file->command_state = cs_finished;
|
---|
907 | file->updated = 1;
|
---|
908 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
909 | if (file->multi_head)
|
---|
910 | {
|
---|
911 | assert (file == file->multi_head);
|
---|
912 | for (f2 = file->multi_next; f2 != 0; f2 = f2->multi_next)
|
---|
913 | {
|
---|
914 | f2->command_state = cs_finished;
|
---|
915 | f2->updated = 1;
|
---|
916 | }
|
---|
917 | }
|
---|
918 | #endif
|
---|
919 |
|
---|
920 | #ifdef CONFIG_WITH_EXTENDED_NOTPARALLEL
|
---|
921 | /* update not_parallel if the file was flagged for that. */
|
---|
922 | if ( ran
|
---|
923 | && (file->command_flags & (COMMANDS_NOTPARALLEL | COMMANDS_NO_COMMANDS))
|
---|
924 | == COMMANDS_NOTPARALLEL)
|
---|
925 | {
|
---|
926 | DB (DB_KMK, (_("not_parallel %d -> %d (file=%p `%s') [notice_finished_file]\n"), not_parallel,
|
---|
927 | not_parallel - 1, (void *) file, file->name));
|
---|
928 | assert(not_parallel >= 1);
|
---|
929 | --not_parallel;
|
---|
930 | }
|
---|
931 | #endif
|
---|
932 |
|
---|
933 | if (touch_flag
|
---|
934 | /* The update status will be:
|
---|
935 | -1 if this target was not remade;
|
---|
936 | 0 if 0 or more commands (+ or ${MAKE}) were run and won;
|
---|
937 | 1 if some commands were run and lost.
|
---|
938 | We touch the target if it has commands which either were not run
|
---|
939 | or won when they ran (i.e. status is 0). */
|
---|
940 | && file->update_status == 0)
|
---|
941 | {
|
---|
942 | if (file->cmds != 0 && file->cmds->any_recurse)
|
---|
943 | {
|
---|
944 | /* If all the command lines were recursive,
|
---|
945 | we don't want to do the touching. */
|
---|
946 | unsigned int i;
|
---|
947 | for (i = 0; i < file->cmds->ncommand_lines; ++i)
|
---|
948 | if (!(file->cmds->lines_flags[i] & COMMANDS_RECURSE))
|
---|
949 | goto have_nonrecursing;
|
---|
950 | }
|
---|
951 | else
|
---|
952 | {
|
---|
953 | have_nonrecursing:
|
---|
954 | if (file->phony)
|
---|
955 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
956 | {
|
---|
957 | file->update_status = 0;
|
---|
958 | if (file->multi_head)
|
---|
959 | for (f2 = file->multi_next; f2 != 0; f2 = f2->multi_next)
|
---|
960 | f2->update_status = 0;
|
---|
961 | }
|
---|
962 | #else
|
---|
963 | file->update_status = 0;
|
---|
964 | #endif
|
---|
965 | /* According to POSIX, -t doesn't affect targets with no cmds. */
|
---|
966 | else if (file->cmds != 0)
|
---|
967 | {
|
---|
968 | /* Should set file's modification date and do nothing else. */
|
---|
969 | file->update_status = touch_file (file);
|
---|
970 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
971 | if (file->multi_head)
|
---|
972 | for (f2 = file->multi_next; f2 != 0; f2 = f2->multi_next)
|
---|
973 | {
|
---|
974 | /* figure out this, touch if it exist ignore otherwise? */
|
---|
975 | }
|
---|
976 | #endif
|
---|
977 |
|
---|
978 | /* Pretend we ran a real touch command, to suppress the
|
---|
979 | "`foo' is up to date" message. */
|
---|
980 | commands_started++;
|
---|
981 |
|
---|
982 | /* Request for the timestamp to be updated (and distributed
|
---|
983 | to the double-colon entries). Simply setting ran=1 would
|
---|
984 | almost have done the trick, but messes up with the also_make
|
---|
985 | updating logic below. */
|
---|
986 | touched = 1;
|
---|
987 | }
|
---|
988 | }
|
---|
989 | }
|
---|
990 |
|
---|
991 | if (file->mtime_before_update == UNKNOWN_MTIME)
|
---|
992 | file->mtime_before_update = file->last_mtime;
|
---|
993 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
994 | if (file->multi_head)
|
---|
995 | for (f2 = file->multi_next; f2 != 0; f2 = f2->multi_next)
|
---|
996 | if (f2->mtime_before_update == UNKNOWN_MTIME)
|
---|
997 | f2->mtime_before_update = f2->last_mtime;
|
---|
998 | #endif
|
---|
999 |
|
---|
1000 | if ((ran && !file->phony) || touched)
|
---|
1001 | {
|
---|
1002 | int i = 0;
|
---|
1003 |
|
---|
1004 | /* If -n, -t, or -q and all the commands are recursive, we ran them so
|
---|
1005 | really check the target's mtime again. Otherwise, assume the target
|
---|
1006 | would have been updated. */
|
---|
1007 |
|
---|
1008 | if (question_flag || just_print_flag || touch_flag)
|
---|
1009 | {
|
---|
1010 | for (i = file->cmds->ncommand_lines; i > 0; --i)
|
---|
1011 | if (! (file->cmds->lines_flags[i-1] & COMMANDS_RECURSE))
|
---|
1012 | break;
|
---|
1013 | }
|
---|
1014 |
|
---|
1015 | /* If there were no commands at all, it's always new. */
|
---|
1016 |
|
---|
1017 | else if (file->is_target && file->cmds == 0)
|
---|
1018 | i = 1;
|
---|
1019 |
|
---|
1020 | file->last_mtime = i == 0 ? UNKNOWN_MTIME : NEW_MTIME;
|
---|
1021 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
1022 | if (file->multi_head)
|
---|
1023 | for (f2 = file->multi_next; f2 != 0; f2 = f2->multi_next)
|
---|
1024 | file->last_mtime = i == 0 ? UNKNOWN_MTIME : NEW_MTIME; /*??*/
|
---|
1025 | #endif
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | if (file->double_colon)
|
---|
1029 | {
|
---|
1030 | /* If this is a double colon rule and it is the last one to be
|
---|
1031 | updated, propagate the change of modification time to all the
|
---|
1032 | double-colon entries for this file.
|
---|
1033 |
|
---|
1034 | We do it on the last update because it is important to handle
|
---|
1035 | individual entries as separate rules with separate timestamps
|
---|
1036 | while they are treated as targets and then as one rule with the
|
---|
1037 | unified timestamp when they are considered as a prerequisite
|
---|
1038 | of some target. */
|
---|
1039 |
|
---|
1040 | struct file *f;
|
---|
1041 | FILE_TIMESTAMP max_mtime = file->last_mtime;
|
---|
1042 |
|
---|
1043 | /* Check that all rules were updated and at the same time find
|
---|
1044 | the max timestamp. We assume UNKNOWN_MTIME is newer then
|
---|
1045 | any other value. */
|
---|
1046 | for (f = file->double_colon; f != 0 && f->updated; f = f->prev)
|
---|
1047 | if (max_mtime != UNKNOWN_MTIME
|
---|
1048 | && (f->last_mtime == UNKNOWN_MTIME || f->last_mtime > max_mtime))
|
---|
1049 | max_mtime = f->last_mtime;
|
---|
1050 |
|
---|
1051 | if (f == 0)
|
---|
1052 | for (f = file->double_colon; f != 0; f = f->prev)
|
---|
1053 | f->last_mtime = max_mtime;
|
---|
1054 | }
|
---|
1055 |
|
---|
1056 | if (ran && file->update_status != -1)
|
---|
1057 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
1058 | {
|
---|
1059 | #endif
|
---|
1060 | /* We actually tried to update FILE, which has
|
---|
1061 | updated its also_make's as well (if it worked).
|
---|
1062 | If it didn't work, it wouldn't work again for them.
|
---|
1063 | So mark them as updated with the same status. */
|
---|
1064 | for (d = file->also_make; d != 0; d = d->next)
|
---|
1065 | {
|
---|
1066 | d->file->command_state = cs_finished;
|
---|
1067 | d->file->updated = 1;
|
---|
1068 | d->file->update_status = file->update_status;
|
---|
1069 |
|
---|
1070 | if (ran && !d->file->phony)
|
---|
1071 | /* Fetch the new modification time.
|
---|
1072 | We do this instead of just invalidating the cached time
|
---|
1073 | so that a vpath_search can happen. Otherwise, it would
|
---|
1074 | never be done because the target is already updated. */
|
---|
1075 | f_mtime (d->file, 0);
|
---|
1076 | }
|
---|
1077 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
1078 | /* Same as above but for explicit multi target rules. */
|
---|
1079 | if (file->multi_head)
|
---|
1080 | for (f2 = file->multi_next; f2 != 0; f2 = f2->multi_next)
|
---|
1081 | {
|
---|
1082 | f2->update_status = file->update_status;
|
---|
1083 | if (!f2->phony)
|
---|
1084 | f_mtime (f2, 0);
|
---|
1085 | }
|
---|
1086 | }
|
---|
1087 | #endif
|
---|
1088 | else if (file->update_status == -1)
|
---|
1089 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
1090 | {
|
---|
1091 | /* Nothing was done for FILE, but it needed nothing done.
|
---|
1092 | So mark it now as "succeeded". */
|
---|
1093 | file->update_status = 0;
|
---|
1094 | if (file->multi_head)
|
---|
1095 | for (f2 = file->multi_next; f2 != 0; f2 = f2->multi_next)
|
---|
1096 | f2->update_status = 0;
|
---|
1097 | }
|
---|
1098 | #else
|
---|
1099 | /* Nothing was done for FILE, but it needed nothing done.
|
---|
1100 | So mark it now as "succeeded". */
|
---|
1101 | file->update_status = 0;
|
---|
1102 | #endif
|
---|
1103 | }
|
---|
1104 | |
---|
1105 |
|
---|
1106 | /* Check whether another file (whose mtime is THIS_MTIME) needs updating on
|
---|
1107 | account of a dependency which is file FILE. If it does, store 1 in
|
---|
1108 | *MUST_MAKE_PTR. In the process, update any non-intermediate files that
|
---|
1109 | FILE depends on (including FILE itself). Return nonzero if any updating
|
---|
1110 | failed. */
|
---|
1111 |
|
---|
1112 | static int
|
---|
1113 | check_dep (struct file *file, unsigned int depth,
|
---|
1114 | FILE_TIMESTAMP this_mtime, int *must_make_ptr)
|
---|
1115 | {
|
---|
1116 | struct dep *d;
|
---|
1117 | int dep_status = 0;
|
---|
1118 |
|
---|
1119 | ++depth;
|
---|
1120 | start_updating (file);
|
---|
1121 |
|
---|
1122 | if (file->phony || !file->intermediate)
|
---|
1123 | {
|
---|
1124 | /* If this is a non-intermediate file, update it and record whether it
|
---|
1125 | is newer than THIS_MTIME. */
|
---|
1126 | FILE_TIMESTAMP mtime;
|
---|
1127 | dep_status = update_file (file, depth);
|
---|
1128 | check_renamed (file);
|
---|
1129 | mtime = file_mtime (file);
|
---|
1130 | check_renamed (file);
|
---|
1131 | if (mtime == NONEXISTENT_MTIME || mtime > this_mtime)
|
---|
1132 | *must_make_ptr = 1;
|
---|
1133 | }
|
---|
1134 | else
|
---|
1135 | {
|
---|
1136 | /* FILE is an intermediate file. */
|
---|
1137 | FILE_TIMESTAMP mtime;
|
---|
1138 |
|
---|
1139 | if (!file->phony && file->cmds == 0 && !file->tried_implicit)
|
---|
1140 | {
|
---|
1141 | if (try_implicit_rule (file, depth))
|
---|
1142 | DBF (DB_IMPLICIT, _("Found an implicit rule for `%s'.\n"));
|
---|
1143 | else
|
---|
1144 | DBF (DB_IMPLICIT, _("No implicit rule found for `%s'.\n"));
|
---|
1145 | file->tried_implicit = 1;
|
---|
1146 | }
|
---|
1147 | if (file->cmds == 0 && !file->is_target
|
---|
1148 | && default_file != 0 && default_file->cmds != 0)
|
---|
1149 | {
|
---|
1150 | DBF (DB_IMPLICIT, _("Using default commands for `%s'.\n"));
|
---|
1151 | file->cmds = default_file->cmds;
|
---|
1152 | }
|
---|
1153 |
|
---|
1154 | check_renamed (file);
|
---|
1155 | mtime = file_mtime (file);
|
---|
1156 | check_renamed (file);
|
---|
1157 | if (mtime != NONEXISTENT_MTIME && mtime > this_mtime)
|
---|
1158 | /* If the intermediate file actually exists and is newer, then we
|
---|
1159 | should remake from it. */
|
---|
1160 | *must_make_ptr = 1;
|
---|
1161 | else
|
---|
1162 | {
|
---|
1163 | /* Otherwise, update all non-intermediate files we depend on, if
|
---|
1164 | necessary, and see whether any of them is more recent than the
|
---|
1165 | file on whose behalf we are checking. */
|
---|
1166 | struct dep *lastd;
|
---|
1167 | int deps_running = 0;
|
---|
1168 |
|
---|
1169 | /* Reset this target's state so that we check it fresh. It could be
|
---|
1170 | that it's already been checked as part of an order-only
|
---|
1171 | prerequisite and so wasn't rebuilt then, but should be now.
|
---|
1172 |
|
---|
1173 | bird: What if we're already running the recipe? We don't wish
|
---|
1174 | it to be started once again do we? This happens with the
|
---|
1175 | SECONDARY Test #9 here now... If the idea is to re-evaluate
|
---|
1176 | the target regardless of whether it's running or no, then
|
---|
1177 | perhaps saving and restoring is a better idea?
|
---|
1178 | See bug #15919. */
|
---|
1179 | if (file->command_state != cs_running) /* bird */
|
---|
1180 | set_command_state (file, cs_not_started);
|
---|
1181 |
|
---|
1182 | lastd = 0;
|
---|
1183 | d = file->deps;
|
---|
1184 | while (d != 0)
|
---|
1185 | {
|
---|
1186 | int maybe_make;
|
---|
1187 |
|
---|
1188 | if (is_updating (d->file))
|
---|
1189 | {
|
---|
1190 | error (NILF, _("Circular %s <- %s dependency dropped."),
|
---|
1191 | file->name, d->file->name);
|
---|
1192 | if (lastd == 0)
|
---|
1193 | {
|
---|
1194 | file->deps = d->next;
|
---|
1195 | free_dep (d);
|
---|
1196 | d = file->deps;
|
---|
1197 | }
|
---|
1198 | else
|
---|
1199 | {
|
---|
1200 | lastd->next = d->next;
|
---|
1201 | free_dep (d);
|
---|
1202 | d = lastd->next;
|
---|
1203 | }
|
---|
1204 | continue;
|
---|
1205 | }
|
---|
1206 |
|
---|
1207 | d->file->parent = file;
|
---|
1208 | maybe_make = *must_make_ptr;
|
---|
1209 | dep_status |= check_dep (d->file, depth, this_mtime,
|
---|
1210 | &maybe_make);
|
---|
1211 | if (! d->ignore_mtime)
|
---|
1212 | *must_make_ptr = maybe_make;
|
---|
1213 | check_renamed (d->file);
|
---|
1214 | if (dep_status != 0 && !keep_going_flag)
|
---|
1215 | break;
|
---|
1216 |
|
---|
1217 | if (d->file->command_state == cs_running
|
---|
1218 | || d->file->command_state == cs_deps_running)
|
---|
1219 | deps_running = 1;
|
---|
1220 |
|
---|
1221 | lastd = d;
|
---|
1222 | d = d->next;
|
---|
1223 | }
|
---|
1224 |
|
---|
1225 | if (deps_running)
|
---|
1226 | /* Record that some of FILE's deps are still being made.
|
---|
1227 | This tells the upper levels to wait on processing it until the
|
---|
1228 | commands are finished. */
|
---|
1229 | set_command_state (file, cs_deps_running);
|
---|
1230 | }
|
---|
1231 | }
|
---|
1232 |
|
---|
1233 | finish_updating (file);
|
---|
1234 | return dep_status;
|
---|
1235 | }
|
---|
1236 | |
---|
1237 |
|
---|
1238 | /* Touch FILE. Return zero if successful, one if not. */
|
---|
1239 |
|
---|
1240 | #define TOUCH_ERROR(call) return (perror_with_name (call, file->name), 1)
|
---|
1241 |
|
---|
1242 | static int
|
---|
1243 | touch_file (struct file *file)
|
---|
1244 | {
|
---|
1245 | if (!silent_flag)
|
---|
1246 | message (0, "touch %s", file->name);
|
---|
1247 |
|
---|
1248 | #ifndef NO_ARCHIVES
|
---|
1249 | if (ar_name (file->name))
|
---|
1250 | return ar_touch (file->name);
|
---|
1251 | else
|
---|
1252 | #endif
|
---|
1253 | {
|
---|
1254 | int fd = open (file->name, O_RDWR | O_CREAT, 0666);
|
---|
1255 |
|
---|
1256 | if (fd < 0)
|
---|
1257 | TOUCH_ERROR ("touch: open: ");
|
---|
1258 | else
|
---|
1259 | {
|
---|
1260 | struct stat statbuf;
|
---|
1261 | char buf = 'x';
|
---|
1262 | int e;
|
---|
1263 |
|
---|
1264 | EINTRLOOP (e, fstat (fd, &statbuf));
|
---|
1265 | if (e < 0)
|
---|
1266 | TOUCH_ERROR ("touch: fstat: ");
|
---|
1267 | /* Rewrite character 0 same as it already is. */
|
---|
1268 | if (read (fd, &buf, 1) < 0)
|
---|
1269 | TOUCH_ERROR ("touch: read: ");
|
---|
1270 | if (lseek (fd, 0L, 0) < 0L)
|
---|
1271 | TOUCH_ERROR ("touch: lseek: ");
|
---|
1272 | if (write (fd, &buf, 1) < 0)
|
---|
1273 | TOUCH_ERROR ("touch: write: ");
|
---|
1274 | /* If file length was 0, we just
|
---|
1275 | changed it, so change it back. */
|
---|
1276 | if (statbuf.st_size == 0)
|
---|
1277 | {
|
---|
1278 | (void) close (fd);
|
---|
1279 | fd = open (file->name, O_RDWR | O_TRUNC, 0666);
|
---|
1280 | if (fd < 0)
|
---|
1281 | TOUCH_ERROR ("touch: open: ");
|
---|
1282 | }
|
---|
1283 | (void) close (fd);
|
---|
1284 | }
|
---|
1285 | }
|
---|
1286 |
|
---|
1287 | return 0;
|
---|
1288 | }
|
---|
1289 | |
---|
1290 |
|
---|
1291 | /* Having checked and updated the dependencies of FILE,
|
---|
1292 | do whatever is appropriate to remake FILE itself.
|
---|
1293 | Return the status from executing FILE's commands. */
|
---|
1294 |
|
---|
1295 | static void
|
---|
1296 | remake_file (struct file *file)
|
---|
1297 | {
|
---|
1298 | #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
|
---|
1299 | assert(file->multi_head == NULL || file->multi_head == file);
|
---|
1300 | #endif
|
---|
1301 |
|
---|
1302 | if (file->cmds == 0)
|
---|
1303 | {
|
---|
1304 | if (file->phony)
|
---|
1305 | /* Phony target. Pretend it succeeded. */
|
---|
1306 | file->update_status = 0;
|
---|
1307 | else if (file->is_target)
|
---|
1308 | /* This is a nonexistent target file we cannot make.
|
---|
1309 | Pretend it was successfully remade. */
|
---|
1310 | file->update_status = 0;
|
---|
1311 | else
|
---|
1312 | {
|
---|
1313 | /* This is a dependency file we cannot remake. Fail. */
|
---|
1314 | if (!rebuilding_makefiles || !file->dontcare)
|
---|
1315 | complain (file);
|
---|
1316 | file->update_status = 2;
|
---|
1317 | }
|
---|
1318 | }
|
---|
1319 | else
|
---|
1320 | {
|
---|
1321 | chop_commands (file->cmds);
|
---|
1322 |
|
---|
1323 | /* The normal case: start some commands. */
|
---|
1324 | if (!touch_flag || file->cmds->any_recurse)
|
---|
1325 | {
|
---|
1326 | execute_file_commands (file);
|
---|
1327 | return;
|
---|
1328 | }
|
---|
1329 |
|
---|
1330 | /* This tells notice_finished_file it is ok to touch the file. */
|
---|
1331 | file->update_status = 0;
|
---|
1332 | }
|
---|
1333 |
|
---|
1334 | /* This does the touching under -t. */
|
---|
1335 | notice_finished_file (file);
|
---|
1336 | }
|
---|
1337 | |
---|
1338 |
|
---|
1339 | /* Return the mtime of a file, given a `struct file'.
|
---|
1340 | Caches the time in the struct file to avoid excess stat calls.
|
---|
1341 |
|
---|
1342 | If the file is not found, and SEARCH is nonzero, VPATH searching and
|
---|
1343 | replacement is done. If that fails, a library (-lLIBNAME) is tried and
|
---|
1344 | the library's actual name (/lib/libLIBNAME.a, etc.) is substituted into
|
---|
1345 | FILE. */
|
---|
1346 |
|
---|
1347 | FILE_TIMESTAMP
|
---|
1348 | f_mtime (struct file *file, int search)
|
---|
1349 | {
|
---|
1350 | FILE_TIMESTAMP mtime;
|
---|
1351 |
|
---|
1352 | /* File's mtime is not known; must get it from the system. */
|
---|
1353 |
|
---|
1354 | #ifndef NO_ARCHIVES
|
---|
1355 | if (ar_name (file->name))
|
---|
1356 | {
|
---|
1357 | /* This file is an archive-member reference. */
|
---|
1358 |
|
---|
1359 | char *arname, *memname;
|
---|
1360 | struct file *arfile;
|
---|
1361 | time_t member_date;
|
---|
1362 |
|
---|
1363 | /* Find the archive's name. */
|
---|
1364 | ar_parse_name (file->name, &arname, &memname);
|
---|
1365 |
|
---|
1366 | /* Find the modification time of the archive itself.
|
---|
1367 | Also allow for its name to be changed via VPATH search. */
|
---|
1368 | arfile = lookup_file (arname);
|
---|
1369 | if (arfile == 0)
|
---|
1370 | arfile = enter_file (strcache_add (arname));
|
---|
1371 | mtime = f_mtime (arfile, search);
|
---|
1372 | check_renamed (arfile);
|
---|
1373 | if (search && strcmp (arfile->hname, arname))
|
---|
1374 | {
|
---|
1375 | /* The archive's name has changed.
|
---|
1376 | Change the archive-member reference accordingly. */
|
---|
1377 |
|
---|
1378 | char *name;
|
---|
1379 | unsigned int arlen, memlen;
|
---|
1380 |
|
---|
1381 | arlen = strlen (arfile->hname);
|
---|
1382 | memlen = strlen (memname);
|
---|
1383 |
|
---|
1384 | name = xmalloc (arlen + 1 + memlen + 2);
|
---|
1385 | memcpy (name, arfile->hname, arlen);
|
---|
1386 | name[arlen] = '(';
|
---|
1387 | memcpy (name + arlen + 1, memname, memlen);
|
---|
1388 | name[arlen + 1 + memlen] = ')';
|
---|
1389 | name[arlen + 1 + memlen + 1] = '\0';
|
---|
1390 |
|
---|
1391 | /* If the archive was found with GPATH, make the change permanent;
|
---|
1392 | otherwise defer it until later. */
|
---|
1393 | if (arfile->name == arfile->hname)
|
---|
1394 | rename_file (file, name);
|
---|
1395 | else
|
---|
1396 | rehash_file (file, name);
|
---|
1397 | check_renamed (file);
|
---|
1398 | }
|
---|
1399 |
|
---|
1400 | free (arname);
|
---|
1401 |
|
---|
1402 | file->low_resolution_time = 1;
|
---|
1403 |
|
---|
1404 | if (mtime == NONEXISTENT_MTIME)
|
---|
1405 | /* The archive doesn't exist, so its members don't exist either. */
|
---|
1406 | return NONEXISTENT_MTIME;
|
---|
1407 |
|
---|
1408 | member_date = ar_member_date (file->hname);
|
---|
1409 | mtime = (member_date == (time_t) -1
|
---|
1410 | ? NONEXISTENT_MTIME
|
---|
1411 | : file_timestamp_cons (file->hname, member_date, 0));
|
---|
1412 | }
|
---|
1413 | else
|
---|
1414 | #endif
|
---|
1415 | {
|
---|
1416 | mtime = name_mtime (file->name);
|
---|
1417 |
|
---|
1418 | if (mtime == NONEXISTENT_MTIME && search && !file->ignore_vpath)
|
---|
1419 | {
|
---|
1420 | /* If name_mtime failed, search VPATH. */
|
---|
1421 | const char *name = vpath_search (file->name, &mtime);
|
---|
1422 | if (name
|
---|
1423 | /* Last resort, is it a library (-lxxx)? */
|
---|
1424 | || (file->name[0] == '-' && file->name[1] == 'l'
|
---|
1425 | && (name = library_search (file->name, &mtime)) != 0))
|
---|
1426 | {
|
---|
1427 | if (mtime != UNKNOWN_MTIME)
|
---|
1428 | /* vpath_search and library_search store UNKNOWN_MTIME
|
---|
1429 | if they didn't need to do a stat call for their work. */
|
---|
1430 | file->last_mtime = mtime;
|
---|
1431 |
|
---|
1432 | /* If we found it in VPATH, see if it's in GPATH too; if so,
|
---|
1433 | change the name right now; if not, defer until after the
|
---|
1434 | dependencies are updated. */
|
---|
1435 | if (gpath_search (name, strlen(name) - strlen(file->name) - 1))
|
---|
1436 | {
|
---|
1437 | rename_file (file, name);
|
---|
1438 | check_renamed (file);
|
---|
1439 | return file_mtime (file);
|
---|
1440 | }
|
---|
1441 |
|
---|
1442 | rehash_file (file, name);
|
---|
1443 | check_renamed (file);
|
---|
1444 | /* If the result of a vpath search is -o or -W, preserve it.
|
---|
1445 | Otherwise, find the mtime of the resulting file. */
|
---|
1446 | if (mtime != OLD_MTIME && mtime != NEW_MTIME)
|
---|
1447 | mtime = name_mtime (name);
|
---|
1448 | }
|
---|
1449 | }
|
---|
1450 | }
|
---|
1451 |
|
---|
1452 | /* Files can have bogus timestamps that nothing newly made will be
|
---|
1453 | "newer" than. Updating their dependents could just result in loops.
|
---|
1454 | So notify the user of the anomaly with a warning.
|
---|
1455 |
|
---|
1456 | We only need to do this once, for now. */
|
---|
1457 |
|
---|
1458 | if (!clock_skew_detected
|
---|
1459 | && mtime != NONEXISTENT_MTIME && mtime != NEW_MTIME
|
---|
1460 | && !file->updated)
|
---|
1461 | {
|
---|
1462 | static FILE_TIMESTAMP adjusted_now;
|
---|
1463 |
|
---|
1464 | FILE_TIMESTAMP adjusted_mtime = mtime;
|
---|
1465 |
|
---|
1466 | #if defined(WINDOWS32) || defined(__MSDOS__)
|
---|
1467 | /* Experimentation has shown that FAT filesystems can set file times
|
---|
1468 | up to 3 seconds into the future! Play it safe. */
|
---|
1469 |
|
---|
1470 | #define FAT_ADJ_OFFSET (FILE_TIMESTAMP) 3
|
---|
1471 |
|
---|
1472 | FILE_TIMESTAMP adjustment = FAT_ADJ_OFFSET << FILE_TIMESTAMP_LO_BITS;
|
---|
1473 | if (ORDINARY_MTIME_MIN + adjustment <= adjusted_mtime)
|
---|
1474 | adjusted_mtime -= adjustment;
|
---|
1475 | #elif defined(__EMX__)
|
---|
1476 | /* FAT filesystems round time to the nearest even second!
|
---|
1477 | Allow for any file (NTFS or FAT) to perhaps suffer from this
|
---|
1478 | brain damage. */
|
---|
1479 | FILE_TIMESTAMP adjustment = (((FILE_TIMESTAMP_S (adjusted_mtime) & 1) == 0
|
---|
1480 | && FILE_TIMESTAMP_NS (adjusted_mtime) == 0)
|
---|
1481 | ? (FILE_TIMESTAMP) 1 << FILE_TIMESTAMP_LO_BITS
|
---|
1482 | : 0);
|
---|
1483 | #endif
|
---|
1484 |
|
---|
1485 | /* If the file's time appears to be in the future, update our
|
---|
1486 | concept of the present and try once more. */
|
---|
1487 | if (adjusted_now < adjusted_mtime)
|
---|
1488 | {
|
---|
1489 | int resolution;
|
---|
1490 | FILE_TIMESTAMP now = file_timestamp_now (&resolution);
|
---|
1491 | adjusted_now = now + (resolution - 1);
|
---|
1492 | if (adjusted_now < adjusted_mtime)
|
---|
1493 | {
|
---|
1494 | #ifdef NO_FLOAT
|
---|
1495 | error (NILF, _("Warning: File `%s' has modification time in the future"),
|
---|
1496 | file->name);
|
---|
1497 | #else
|
---|
1498 | double from_now =
|
---|
1499 | (FILE_TIMESTAMP_S (mtime) - FILE_TIMESTAMP_S (now)
|
---|
1500 | + ((FILE_TIMESTAMP_NS (mtime) - FILE_TIMESTAMP_NS (now))
|
---|
1501 | / 1e9));
|
---|
1502 | char from_now_string[100];
|
---|
1503 |
|
---|
1504 | if (from_now >= 99 && from_now <= ULONG_MAX)
|
---|
1505 | sprintf (from_now_string, "%lu", (unsigned long) from_now);
|
---|
1506 | else
|
---|
1507 | sprintf (from_now_string, "%.2g", from_now);
|
---|
1508 | error (NILF, _("Warning: File `%s' has modification time %s s in the future"),
|
---|
1509 | file->name, from_now_string);
|
---|
1510 | #endif
|
---|
1511 | clock_skew_detected = 1;
|
---|
1512 | }
|
---|
1513 | }
|
---|
1514 | }
|
---|
1515 |
|
---|
1516 | /* Store the mtime into all the entries for this file. */
|
---|
1517 | if (file->double_colon)
|
---|
1518 | file = file->double_colon;
|
---|
1519 |
|
---|
1520 | do
|
---|
1521 | {
|
---|
1522 | /* If this file is not implicit but it is intermediate then it was
|
---|
1523 | made so by the .INTERMEDIATE target. If this file has never
|
---|
1524 | been built by us but was found now, it existed before make
|
---|
1525 | started. So, turn off the intermediate bit so make doesn't
|
---|
1526 | delete it, since it didn't create it. */
|
---|
1527 | if (mtime != NONEXISTENT_MTIME && file->command_state == cs_not_started
|
---|
1528 | && file->command_state == cs_not_started
|
---|
1529 | && !file->tried_implicit && file->intermediate)
|
---|
1530 | file->intermediate = 0;
|
---|
1531 |
|
---|
1532 | file->last_mtime = mtime;
|
---|
1533 | file = file->prev;
|
---|
1534 | }
|
---|
1535 | while (file != 0);
|
---|
1536 |
|
---|
1537 | return mtime;
|
---|
1538 | }
|
---|
1539 |
|
---|
1540 |
|
---|
1541 | /* Return the mtime of the file or archive-member reference NAME. */
|
---|
1542 |
|
---|
1543 | /* First, we check with stat(). If the file does not exist, then we return
|
---|
1544 | NONEXISTENT_MTIME. If it does, and the symlink check flag is set, then
|
---|
1545 | examine each indirection of the symlink and find the newest mtime.
|
---|
1546 | This causes one duplicate stat() when -L is being used, but the code is
|
---|
1547 | much cleaner. */
|
---|
1548 |
|
---|
1549 | static FILE_TIMESTAMP
|
---|
1550 | name_mtime (const char *name)
|
---|
1551 | {
|
---|
1552 | FILE_TIMESTAMP mtime;
|
---|
1553 | struct stat st;
|
---|
1554 | int e;
|
---|
1555 |
|
---|
1556 | EINTRLOOP (e, stat (name, &st));
|
---|
1557 | if (e == 0)
|
---|
1558 | mtime = FILE_TIMESTAMP_STAT_MODTIME (name, st);
|
---|
1559 | else if (errno == ENOENT || errno == ENOTDIR)
|
---|
1560 | mtime = NONEXISTENT_MTIME;
|
---|
1561 | else
|
---|
1562 | {
|
---|
1563 | perror_with_name ("stat: ", name);
|
---|
1564 | return NONEXISTENT_MTIME;
|
---|
1565 | }
|
---|
1566 |
|
---|
1567 | /* If we get here we either found it, or it doesn't exist.
|
---|
1568 | If it doesn't exist see if we can use a symlink mtime instead. */
|
---|
1569 |
|
---|
1570 | #ifdef MAKE_SYMLINKS
|
---|
1571 | #ifndef S_ISLNK
|
---|
1572 | # define S_ISLNK(_m) (((_m)&S_IFMT)==S_IFLNK)
|
---|
1573 | #endif
|
---|
1574 | if (check_symlink_flag)
|
---|
1575 | {
|
---|
1576 | PATH_VAR (lpath);
|
---|
1577 |
|
---|
1578 | /* Check each symbolic link segment (if any). Find the latest mtime
|
---|
1579 | amongst all of them (and the target file of course).
|
---|
1580 | Note that we have already successfully dereferenced all the links
|
---|
1581 | above. So, if we run into any error trying to lstat(), or
|
---|
1582 | readlink(), or whatever, something bizarre-o happened. Just give up
|
---|
1583 | and use whatever mtime we've already computed at that point. */
|
---|
1584 | strcpy (lpath, name);
|
---|
1585 | while (1)
|
---|
1586 | {
|
---|
1587 | FILE_TIMESTAMP ltime;
|
---|
1588 | PATH_VAR (lbuf);
|
---|
1589 | long llen;
|
---|
1590 | char *p;
|
---|
1591 |
|
---|
1592 | EINTRLOOP (e, lstat (lpath, &st));
|
---|
1593 | if (e)
|
---|
1594 | {
|
---|
1595 | /* Just take what we have so far. */
|
---|
1596 | if (errno != ENOENT && errno != ENOTDIR)
|
---|
1597 | perror_with_name ("lstat: ", lpath);
|
---|
1598 | break;
|
---|
1599 | }
|
---|
1600 |
|
---|
1601 | /* If this is not a symlink, we're done (we started with the real
|
---|
1602 | file's mtime so we don't need to test it again). */
|
---|
1603 | if (!S_ISLNK (st.st_mode))
|
---|
1604 | break;
|
---|
1605 |
|
---|
1606 | /* If this mtime is newer than what we had, keep the new one. */
|
---|
1607 | ltime = FILE_TIMESTAMP_STAT_MODTIME (lpath, st);
|
---|
1608 | if (ltime > mtime)
|
---|
1609 | mtime = ltime;
|
---|
1610 |
|
---|
1611 | /* Set up to check the file pointed to by this link. */
|
---|
1612 | EINTRLOOP (llen, readlink (lpath, lbuf, GET_PATH_MAX));
|
---|
1613 | if (llen < 0)
|
---|
1614 | {
|
---|
1615 | /* Eh? Just take what we have. */
|
---|
1616 | perror_with_name ("readlink: ", lpath);
|
---|
1617 | break;
|
---|
1618 | }
|
---|
1619 | lbuf[llen] = '\0';
|
---|
1620 |
|
---|
1621 | /* If the target is fully-qualified or the source is just a
|
---|
1622 | filename, then the new path is the target. Otherwise it's the
|
---|
1623 | source directory plus the target. */
|
---|
1624 | if (lbuf[0] == '/' || (p = strrchr (lpath, '/')) == NULL)
|
---|
1625 | strcpy (lpath, lbuf);
|
---|
1626 | else if ((p - lpath) + llen + 2 > GET_PATH_MAX)
|
---|
1627 | /* Eh? Path too long! Again, just go with what we have. */
|
---|
1628 | break;
|
---|
1629 | else
|
---|
1630 | /* Create the next step in the symlink chain. */
|
---|
1631 | strcpy (p+1, lbuf);
|
---|
1632 | }
|
---|
1633 | }
|
---|
1634 | #endif
|
---|
1635 |
|
---|
1636 | return mtime;
|
---|
1637 | }
|
---|
1638 |
|
---|
1639 |
|
---|
1640 | /* Search for a library file specified as -lLIBNAME, searching for a
|
---|
1641 | suitable library file in the system library directories and the VPATH
|
---|
1642 | directories. */
|
---|
1643 |
|
---|
1644 | static const char *
|
---|
1645 | library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr)
|
---|
1646 | {
|
---|
1647 | static char *dirs[] =
|
---|
1648 | {
|
---|
1649 | #ifdef KMK
|
---|
1650 | ".",
|
---|
1651 | #else /* !KMK */
|
---|
1652 | #ifndef _AMIGA
|
---|
1653 | "/lib",
|
---|
1654 | "/usr/lib",
|
---|
1655 | #endif
|
---|
1656 | #if defined(WINDOWS32) && !defined(LIBDIR)
|
---|
1657 | /*
|
---|
1658 | * This is completely up to the user at product install time. Just define
|
---|
1659 | * a placeholder.
|
---|
1660 | */
|
---|
1661 | #define LIBDIR "."
|
---|
1662 | #endif
|
---|
1663 | # ifdef LIBDIR /* bird */
|
---|
1664 | LIBDIR, /* Defined by configuration. */
|
---|
1665 | # else /* bird */
|
---|
1666 | ".", /* bird */
|
---|
1667 | # endif /* bird */
|
---|
1668 | #endif /* !KMK */
|
---|
1669 | 0
|
---|
1670 | };
|
---|
1671 |
|
---|
1672 | static char *libpatterns = NULL;
|
---|
1673 |
|
---|
1674 | const char *libname = lib+2; /* Name without the '-l'. */
|
---|
1675 | FILE_TIMESTAMP mtime;
|
---|
1676 |
|
---|
1677 | /* Loop variables for the libpatterns value. */
|
---|
1678 | char *p;
|
---|
1679 | const char *p2;
|
---|
1680 | unsigned int len;
|
---|
1681 |
|
---|
1682 | char **dp;
|
---|
1683 |
|
---|
1684 | /* If we don't have libpatterns, get it. */
|
---|
1685 | if (!libpatterns)
|
---|
1686 | {
|
---|
1687 | int save = warn_undefined_variables_flag;
|
---|
1688 | warn_undefined_variables_flag = 0;
|
---|
1689 |
|
---|
1690 | libpatterns = xstrdup (variable_expand ("$(strip $(.LIBPATTERNS))"));
|
---|
1691 |
|
---|
1692 | warn_undefined_variables_flag = save;
|
---|
1693 | }
|
---|
1694 |
|
---|
1695 | /* Loop through all the patterns in .LIBPATTERNS, and search on each one. */
|
---|
1696 | p2 = libpatterns;
|
---|
1697 | while ((p = find_next_token (&p2, &len)) != 0)
|
---|
1698 | {
|
---|
1699 | static char *buf = NULL;
|
---|
1700 | static unsigned int buflen = 0;
|
---|
1701 | static int libdir_maxlen = -1;
|
---|
1702 | char *libbuf = variable_expand ("");
|
---|
1703 | const size_t libbuf_offset = libbuf - variable_buffer; /* bird */
|
---|
1704 |
|
---|
1705 | /* Expand the pattern using LIBNAME as a replacement. */
|
---|
1706 | {
|
---|
1707 | char c = p[len];
|
---|
1708 | char *p3, *p4;
|
---|
1709 |
|
---|
1710 | p[len] = '\0';
|
---|
1711 | p3 = find_percent (p);
|
---|
1712 | if (!p3)
|
---|
1713 | {
|
---|
1714 | /* Give a warning if there is no pattern, then remove the
|
---|
1715 | pattern so it's ignored next time. */
|
---|
1716 | error (NILF, _(".LIBPATTERNS element `%s' is not a pattern"), p);
|
---|
1717 | for (; len; --len, ++p)
|
---|
1718 | *p = ' ';
|
---|
1719 | *p = c;
|
---|
1720 | continue;
|
---|
1721 | }
|
---|
1722 | p4 = variable_buffer_output (libbuf, p, p3-p);
|
---|
1723 | p4 = variable_buffer_output (p4, libname, strlen (libname));
|
---|
1724 | p4 = variable_buffer_output (p4, p3+1, len - (p3-p));
|
---|
1725 | p[len] = c;
|
---|
1726 | libbuf = variable_buffer + libbuf_offset; /* bird - variable_buffer may have been reallocated. */
|
---|
1727 | }
|
---|
1728 |
|
---|
1729 | /* Look first for `libNAME.a' in the current directory. */
|
---|
1730 | mtime = name_mtime (libbuf);
|
---|
1731 | if (mtime != NONEXISTENT_MTIME)
|
---|
1732 | {
|
---|
1733 | if (mtime_ptr != 0)
|
---|
1734 | *mtime_ptr = mtime;
|
---|
1735 | return strcache_add (libbuf);
|
---|
1736 | }
|
---|
1737 |
|
---|
1738 | /* Now try VPATH search on that. */
|
---|
1739 |
|
---|
1740 | {
|
---|
1741 | const char *file = vpath_search (libbuf, mtime_ptr);
|
---|
1742 | if (file)
|
---|
1743 | return file;
|
---|
1744 | }
|
---|
1745 |
|
---|
1746 | /* Now try the standard set of directories. */
|
---|
1747 |
|
---|
1748 | if (!buflen)
|
---|
1749 | {
|
---|
1750 | for (dp = dirs; *dp != 0; ++dp)
|
---|
1751 | {
|
---|
1752 | int l = strlen (*dp);
|
---|
1753 | if (l > libdir_maxlen)
|
---|
1754 | libdir_maxlen = l;
|
---|
1755 | }
|
---|
1756 | buflen = strlen (libbuf);
|
---|
1757 | buf = xmalloc(libdir_maxlen + buflen + 2);
|
---|
1758 | }
|
---|
1759 | else if (buflen < strlen (libbuf))
|
---|
1760 | {
|
---|
1761 | buflen = strlen (libbuf);
|
---|
1762 | buf = xrealloc (buf, libdir_maxlen + buflen + 2);
|
---|
1763 | }
|
---|
1764 |
|
---|
1765 | for (dp = dirs; *dp != 0; ++dp)
|
---|
1766 | {
|
---|
1767 | sprintf (buf, "%s/%s", *dp, libbuf);
|
---|
1768 | mtime = name_mtime (buf);
|
---|
1769 | if (mtime != NONEXISTENT_MTIME)
|
---|
1770 | {
|
---|
1771 | if (mtime_ptr != 0)
|
---|
1772 | *mtime_ptr = mtime;
|
---|
1773 | return strcache_add (buf);
|
---|
1774 | }
|
---|
1775 | }
|
---|
1776 | }
|
---|
1777 |
|
---|
1778 | return 0;
|
---|
1779 | }
|
---|