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