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 Free Software
|
---|
4 | Foundation, Inc.
|
---|
5 | This file is part of GNU Make.
|
---|
6 |
|
---|
7 | GNU Make is free software; you can redistribute it and/or modify it under the
|
---|
8 | terms of the GNU General Public License as published by the Free Software
|
---|
9 | Foundation; either version 2, or (at your option) any later version.
|
---|
10 |
|
---|
11 | GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
|
---|
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
---|
13 | A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
---|
14 |
|
---|
15 | You should have received a copy of the GNU General Public License along with
|
---|
16 | GNU Make; see the file COPYING. If not, write to the Free Software
|
---|
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */
|
---|
18 |
|
---|
19 | #include "make.h"
|
---|
20 | #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 | free (g);
|
---|
243 |
|
---|
244 | g = lastgoal == 0 ? goals : lastgoal->next;
|
---|
245 |
|
---|
246 | if (stop)
|
---|
247 | break;
|
---|
248 | }
|
---|
249 | else
|
---|
250 | {
|
---|
251 | lastgoal = g;
|
---|
252 | g = g->next;
|
---|
253 | }
|
---|
254 | }
|
---|
255 |
|
---|
256 | /* If we reached the end of the dependency graph toggle the considered
|
---|
257 | flag for the next pass. */
|
---|
258 | if (g == 0)
|
---|
259 | considered = !considered;
|
---|
260 | }
|
---|
261 |
|
---|
262 | if (rebuilding_makefiles)
|
---|
263 | {
|
---|
264 | touch_flag = t;
|
---|
265 | question_flag = q;
|
---|
266 | just_print_flag = n;
|
---|
267 | job_slots = j;
|
---|
268 | }
|
---|
269 |
|
---|
270 | return status;
|
---|
271 | }
|
---|
272 | |
---|
273 |
|
---|
274 | /* If FILE is not up to date, execute the commands for it.
|
---|
275 | Return 0 if successful, 1 if unsuccessful;
|
---|
276 | but with some flag settings, just call `exit' if unsuccessful.
|
---|
277 |
|
---|
278 | DEPTH is the depth in recursions of this function.
|
---|
279 | We increment it during the consideration of our dependencies,
|
---|
280 | then decrement it again after finding out whether this file
|
---|
281 | is out of date.
|
---|
282 |
|
---|
283 | If there are multiple double-colon entries for FILE,
|
---|
284 | each is considered in turn. */
|
---|
285 |
|
---|
286 | static int
|
---|
287 | update_file (struct file *file, unsigned int depth)
|
---|
288 | {
|
---|
289 | register int status = 0;
|
---|
290 | register struct file *f;
|
---|
291 |
|
---|
292 | f = file->double_colon ? file->double_colon : file;
|
---|
293 |
|
---|
294 | /* Prune the dependency graph: if we've already been here on _this_
|
---|
295 | pass through the dependency graph, we don't have to go any further.
|
---|
296 | We won't reap_children until we start the next pass, so no state
|
---|
297 | change is possible below here until then. */
|
---|
298 | if (f->considered == considered)
|
---|
299 | {
|
---|
300 | DBF (DB_VERBOSE, _("Pruning file `%s'.\n"));
|
---|
301 | return f->command_state == cs_finished ? f->update_status : 0;
|
---|
302 | }
|
---|
303 |
|
---|
304 | /* This loop runs until we start commands for a double colon rule, or until
|
---|
305 | the chain is exhausted. */
|
---|
306 | for (; f != 0; f = f->prev)
|
---|
307 | {
|
---|
308 | f->considered = considered;
|
---|
309 |
|
---|
310 | status |= update_file_1 (f, depth);
|
---|
311 | check_renamed (f);
|
---|
312 |
|
---|
313 | /* Clean up any alloca() used during the update. */
|
---|
314 | alloca (0);
|
---|
315 |
|
---|
316 | /* If we got an error, don't bother with double_colon etc. */
|
---|
317 | if (status != 0 && !keep_going_flag)
|
---|
318 | return status;
|
---|
319 |
|
---|
320 | if (f->command_state == cs_running
|
---|
321 | || f->command_state == cs_deps_running)
|
---|
322 | {
|
---|
323 | /* Don't run the other :: rules for this
|
---|
324 | file until this rule is finished. */
|
---|
325 | status = 0;
|
---|
326 | break;
|
---|
327 | }
|
---|
328 | }
|
---|
329 |
|
---|
330 | /* Process the remaining rules in the double colon chain so they're marked
|
---|
331 | considered. Start their prerequisites, too. */
|
---|
332 | if (file->double_colon)
|
---|
333 | for (; f != 0 ; f = f->prev)
|
---|
334 | {
|
---|
335 | struct dep *d;
|
---|
336 |
|
---|
337 | f->considered = considered;
|
---|
338 |
|
---|
339 | for (d = f->deps; d != 0; d = d->next)
|
---|
340 | status |= update_file (d->file, depth + 1);
|
---|
341 | }
|
---|
342 |
|
---|
343 | return status;
|
---|
344 | }
|
---|
345 | |
---|
346 |
|
---|
347 | /* Show a message stating the target failed to build. */
|
---|
348 |
|
---|
349 | static void
|
---|
350 | complain (const struct file *file)
|
---|
351 | {
|
---|
352 | const char *msg_noparent
|
---|
353 | = _("%sNo rule to make target `%s'%s");
|
---|
354 | const char *msg_parent
|
---|
355 | = _("%sNo rule to make target `%s', needed by `%s'%s");
|
---|
356 |
|
---|
357 | if (!keep_going_flag)
|
---|
358 | {
|
---|
359 | if (file->parent == 0)
|
---|
360 | fatal (NILF, msg_noparent, "", file->name, "");
|
---|
361 |
|
---|
362 | fatal (NILF, msg_parent, "", file->name, file->parent->name, "");
|
---|
363 | }
|
---|
364 |
|
---|
365 | if (file->parent == 0)
|
---|
366 | error (NILF, msg_noparent, "*** ", file->name, ".");
|
---|
367 | else
|
---|
368 | error (NILF, msg_parent, "*** ", file->name, file->parent->name, ".");
|
---|
369 | }
|
---|
370 |
|
---|
371 | /* Consider a single `struct file' and update it as appropriate. */
|
---|
372 |
|
---|
373 | static int
|
---|
374 | update_file_1 (struct file *file, unsigned int depth)
|
---|
375 | {
|
---|
376 | register FILE_TIMESTAMP this_mtime;
|
---|
377 | int noexist, must_make, deps_changed;
|
---|
378 | int dep_status = 0;
|
---|
379 | register struct dep *d, *lastd;
|
---|
380 | int running = 0;
|
---|
381 |
|
---|
382 | DBF (DB_VERBOSE, _("Considering target file `%s'.\n"));
|
---|
383 |
|
---|
384 | if (file->updated)
|
---|
385 | {
|
---|
386 | if (file->update_status > 0)
|
---|
387 | {
|
---|
388 | DBF (DB_VERBOSE,
|
---|
389 | _("Recently tried and failed to update file `%s'.\n"));
|
---|
390 |
|
---|
391 | /* If the file we tried to make is marked dontcare then no message
|
---|
392 | was printed about it when it failed during the makefile rebuild.
|
---|
393 | If we're trying to build it again in the normal rebuild, print a
|
---|
394 | message now. */
|
---|
395 | if (file->dontcare && !rebuilding_makefiles)
|
---|
396 | {
|
---|
397 | file->dontcare = 0;
|
---|
398 | complain (file);
|
---|
399 | }
|
---|
400 |
|
---|
401 | return file->update_status;
|
---|
402 | }
|
---|
403 |
|
---|
404 | DBF (DB_VERBOSE, _("File `%s' was considered already.\n"));
|
---|
405 | return 0;
|
---|
406 | }
|
---|
407 |
|
---|
408 | switch (file->command_state)
|
---|
409 | {
|
---|
410 | case cs_not_started:
|
---|
411 | case cs_deps_running:
|
---|
412 | break;
|
---|
413 | case cs_running:
|
---|
414 | DBF (DB_VERBOSE, _("Still updating file `%s'.\n"));
|
---|
415 | return 0;
|
---|
416 | case cs_finished:
|
---|
417 | DBF (DB_VERBOSE, _("Finished updating file `%s'.\n"));
|
---|
418 | return file->update_status;
|
---|
419 | default:
|
---|
420 | abort ();
|
---|
421 | }
|
---|
422 |
|
---|
423 | ++depth;
|
---|
424 |
|
---|
425 | /* Notice recursive update of the same file. */
|
---|
426 | start_updating (file);
|
---|
427 |
|
---|
428 | /* Looking at the file's modtime beforehand allows the possibility
|
---|
429 | that its name may be changed by a VPATH search, and thus it may
|
---|
430 | not need an implicit rule. If this were not done, the file
|
---|
431 | might get implicit commands that apply to its initial name, only
|
---|
432 | to have that name replaced with another found by VPATH search. */
|
---|
433 |
|
---|
434 | this_mtime = file_mtime (file);
|
---|
435 | check_renamed (file);
|
---|
436 | noexist = this_mtime == NONEXISTENT_MTIME;
|
---|
437 | if (noexist)
|
---|
438 | DBF (DB_BASIC, _("File `%s' does not exist.\n"));
|
---|
439 | else if (ORDINARY_MTIME_MIN <= this_mtime && this_mtime <= ORDINARY_MTIME_MAX
|
---|
440 | && file->low_resolution_time)
|
---|
441 | {
|
---|
442 | /* Avoid spurious rebuilds due to low resolution time stamps. */
|
---|
443 | int ns = FILE_TIMESTAMP_NS (this_mtime);
|
---|
444 | if (ns != 0)
|
---|
445 | error (NILF, _("*** Warning: .LOW_RESOLUTION_TIME file `%s' has a high resolution time stamp"),
|
---|
446 | file->name);
|
---|
447 | this_mtime += FILE_TIMESTAMPS_PER_S - 1 - ns;
|
---|
448 | }
|
---|
449 |
|
---|
450 | must_make = noexist;
|
---|
451 |
|
---|
452 | /* If file was specified as a target with no commands,
|
---|
453 | come up with some default commands. */
|
---|
454 |
|
---|
455 | if (!file->phony && file->cmds == 0 && !file->tried_implicit)
|
---|
456 | {
|
---|
457 | if (try_implicit_rule (file, depth))
|
---|
458 | DBF (DB_IMPLICIT, _("Found an implicit rule for `%s'.\n"));
|
---|
459 | else
|
---|
460 | DBF (DB_IMPLICIT, _("No implicit rule found for `%s'.\n"));
|
---|
461 | file->tried_implicit = 1;
|
---|
462 | }
|
---|
463 | if (file->cmds == 0 && !file->is_target
|
---|
464 | && default_file != 0 && default_file->cmds != 0)
|
---|
465 | {
|
---|
466 | DBF (DB_IMPLICIT, _("Using default commands for `%s'.\n"));
|
---|
467 | file->cmds = default_file->cmds;
|
---|
468 | }
|
---|
469 |
|
---|
470 | /* Update all non-intermediate files we depend on, if necessary,
|
---|
471 | and see whether any of them is more recent than this file. */
|
---|
472 |
|
---|
473 | lastd = 0;
|
---|
474 | d = file->deps;
|
---|
475 | while (d != 0)
|
---|
476 | {
|
---|
477 | FILE_TIMESTAMP mtime;
|
---|
478 | int maybe_make;
|
---|
479 | int dontcare = 0;
|
---|
480 |
|
---|
481 | check_renamed (d->file);
|
---|
482 |
|
---|
483 | mtime = file_mtime (d->file);
|
---|
484 | check_renamed (d->file);
|
---|
485 |
|
---|
486 | if (is_updating (d->file))
|
---|
487 | {
|
---|
488 | error (NILF, _("Circular %s <- %s dependency dropped."),
|
---|
489 | file->name, d->file->name);
|
---|
490 | /* We cannot free D here because our the caller will still have
|
---|
491 | a reference to it when we were called recursively via
|
---|
492 | check_dep below. */
|
---|
493 | if (lastd == 0)
|
---|
494 | file->deps = d->next;
|
---|
495 | else
|
---|
496 | lastd->next = d->next;
|
---|
497 | d = d->next;
|
---|
498 | continue;
|
---|
499 | }
|
---|
500 |
|
---|
501 | d->file->parent = file;
|
---|
502 | maybe_make = must_make;
|
---|
503 |
|
---|
504 | /* Inherit dontcare flag from our parent. */
|
---|
505 | if (rebuilding_makefiles)
|
---|
506 | {
|
---|
507 | dontcare = d->file->dontcare;
|
---|
508 | d->file->dontcare = file->dontcare;
|
---|
509 | }
|
---|
510 |
|
---|
511 |
|
---|
512 | dep_status |= check_dep (d->file, depth, this_mtime, &maybe_make);
|
---|
513 |
|
---|
514 | /* Restore original dontcare flag. */
|
---|
515 | if (rebuilding_makefiles)
|
---|
516 | d->file->dontcare = dontcare;
|
---|
517 |
|
---|
518 | if (! d->ignore_mtime)
|
---|
519 | must_make = maybe_make;
|
---|
520 |
|
---|
521 | check_renamed (d->file);
|
---|
522 |
|
---|
523 | {
|
---|
524 | register struct file *f = d->file;
|
---|
525 | if (f->double_colon)
|
---|
526 | f = f->double_colon;
|
---|
527 | do
|
---|
528 | {
|
---|
529 | running |= (f->command_state == cs_running
|
---|
530 | || f->command_state == cs_deps_running);
|
---|
531 | f = f->prev;
|
---|
532 | }
|
---|
533 | while (f != 0);
|
---|
534 | }
|
---|
535 |
|
---|
536 | if (dep_status != 0 && !keep_going_flag)
|
---|
537 | break;
|
---|
538 |
|
---|
539 | if (!running)
|
---|
540 | /* The prereq is considered changed if the timestamp has changed while
|
---|
541 | it was built, OR it doesn't exist. */
|
---|
542 | d->changed = ((file_mtime (d->file) != mtime)
|
---|
543 | || (mtime == NONEXISTENT_MTIME));
|
---|
544 |
|
---|
545 | lastd = d;
|
---|
546 | d = d->next;
|
---|
547 | }
|
---|
548 |
|
---|
549 | /* Now we know whether this target needs updating.
|
---|
550 | If it does, update all the intermediate files we depend on. */
|
---|
551 |
|
---|
552 | if (must_make || always_make_flag)
|
---|
553 | {
|
---|
554 | for (d = file->deps; d != 0; d = d->next)
|
---|
555 | if (d->file->intermediate)
|
---|
556 | {
|
---|
557 | int dontcare = 0;
|
---|
558 |
|
---|
559 | FILE_TIMESTAMP mtime = file_mtime (d->file);
|
---|
560 | check_renamed (d->file);
|
---|
561 | d->file->parent = file;
|
---|
562 |
|
---|
563 | /* Inherit dontcare flag from our parent. */
|
---|
564 | if (rebuilding_makefiles)
|
---|
565 | {
|
---|
566 | dontcare = d->file->dontcare;
|
---|
567 | d->file->dontcare = file->dontcare;
|
---|
568 | }
|
---|
569 |
|
---|
570 |
|
---|
571 | dep_status |= update_file (d->file, depth);
|
---|
572 |
|
---|
573 | /* Restore original dontcare flag. */
|
---|
574 | if (rebuilding_makefiles)
|
---|
575 | d->file->dontcare = dontcare;
|
---|
576 |
|
---|
577 | check_renamed (d->file);
|
---|
578 |
|
---|
579 | {
|
---|
580 | register struct file *f = d->file;
|
---|
581 | if (f->double_colon)
|
---|
582 | f = f->double_colon;
|
---|
583 | do
|
---|
584 | {
|
---|
585 | running |= (f->command_state == cs_running
|
---|
586 | || f->command_state == cs_deps_running);
|
---|
587 | f = f->prev;
|
---|
588 | }
|
---|
589 | while (f != 0);
|
---|
590 | }
|
---|
591 |
|
---|
592 | if (dep_status != 0 && !keep_going_flag)
|
---|
593 | break;
|
---|
594 |
|
---|
595 | if (!running)
|
---|
596 | d->changed = ((file->phony && file->cmds != 0)
|
---|
597 | || file_mtime (d->file) != mtime);
|
---|
598 | }
|
---|
599 | }
|
---|
600 |
|
---|
601 | finish_updating (file);
|
---|
602 |
|
---|
603 | DBF (DB_VERBOSE, _("Finished prerequisites of target file `%s'.\n"));
|
---|
604 |
|
---|
605 | if (running)
|
---|
606 | {
|
---|
607 | set_command_state (file, cs_deps_running);
|
---|
608 | --depth;
|
---|
609 | DBF (DB_VERBOSE, _("The prerequisites of `%s' are being made.\n"));
|
---|
610 | return 0;
|
---|
611 | }
|
---|
612 |
|
---|
613 | /* If any dependency failed, give up now. */
|
---|
614 |
|
---|
615 | if (dep_status != 0)
|
---|
616 | {
|
---|
617 | file->update_status = dep_status;
|
---|
618 | notice_finished_file (file);
|
---|
619 |
|
---|
620 | --depth;
|
---|
621 |
|
---|
622 | DBF (DB_VERBOSE, _("Giving up on target file `%s'.\n"));
|
---|
623 |
|
---|
624 | if (depth == 0 && keep_going_flag
|
---|
625 | && !just_print_flag && !question_flag)
|
---|
626 | error (NILF,
|
---|
627 | _("Target `%s' not remade because of errors."), file->name);
|
---|
628 |
|
---|
629 | return dep_status;
|
---|
630 | }
|
---|
631 |
|
---|
632 | if (file->command_state == cs_deps_running)
|
---|
633 | /* The commands for some deps were running on the last iteration, but
|
---|
634 | they have finished now. Reset the command_state to not_started to
|
---|
635 | simplify later bookkeeping. It is important that we do this only
|
---|
636 | when the prior state was cs_deps_running, because that prior state
|
---|
637 | was definitely propagated to FILE's also_make's by set_command_state
|
---|
638 | (called above), but in another state an also_make may have
|
---|
639 | independently changed to finished state, and we would confuse that
|
---|
640 | file's bookkeeping (updated, but not_started is bogus state). */
|
---|
641 | set_command_state (file, cs_not_started);
|
---|
642 |
|
---|
643 | /* Now record which prerequisites are more
|
---|
644 | recent than this file, so we can define $?. */
|
---|
645 |
|
---|
646 | deps_changed = 0;
|
---|
647 | for (d = file->deps; d != 0; d = d->next)
|
---|
648 | {
|
---|
649 | FILE_TIMESTAMP d_mtime = file_mtime (d->file);
|
---|
650 | check_renamed (d->file);
|
---|
651 |
|
---|
652 | if (! d->ignore_mtime)
|
---|
653 | {
|
---|
654 | #if 1
|
---|
655 | /* %%% In version 4, remove this code completely to
|
---|
656 | implement not remaking deps if their deps are newer
|
---|
657 | than their parents. */
|
---|
658 | if (d_mtime == NONEXISTENT_MTIME && !d->file->intermediate)
|
---|
659 | /* We must remake if this dep does not
|
---|
660 | exist and is not intermediate. */
|
---|
661 | must_make = 1;
|
---|
662 | #endif
|
---|
663 |
|
---|
664 | /* Set DEPS_CHANGED if this dep actually changed. */
|
---|
665 | deps_changed |= d->changed;
|
---|
666 | }
|
---|
667 |
|
---|
668 | /* Set D->changed if either this dep actually changed,
|
---|
669 | or its dependent, FILE, is older or does not exist. */
|
---|
670 | d->changed |= noexist || d_mtime > this_mtime;
|
---|
671 |
|
---|
672 | if (!noexist && ISDB (DB_BASIC|DB_VERBOSE))
|
---|
673 | {
|
---|
674 | const char *fmt = 0;
|
---|
675 |
|
---|
676 | if (d->ignore_mtime)
|
---|
677 | {
|
---|
678 | if (ISDB (DB_VERBOSE))
|
---|
679 | fmt = _("Prerequisite `%s' is order-only for target `%s'.\n");
|
---|
680 | }
|
---|
681 | else if (d_mtime == NONEXISTENT_MTIME)
|
---|
682 | {
|
---|
683 | if (ISDB (DB_BASIC))
|
---|
684 | fmt = _("Prerequisite `%s' of target `%s' does not exist.\n");
|
---|
685 | }
|
---|
686 | else if (d->changed)
|
---|
687 | {
|
---|
688 | if (ISDB (DB_BASIC))
|
---|
689 | fmt = _("Prerequisite `%s' is newer than target `%s'.\n");
|
---|
690 | }
|
---|
691 | else if (ISDB (DB_VERBOSE))
|
---|
692 | fmt = _("Prerequisite `%s' is older than target `%s'.\n");
|
---|
693 |
|
---|
694 | if (fmt)
|
---|
695 | {
|
---|
696 | print_spaces (depth);
|
---|
697 | printf (fmt, dep_name (d), file->name);
|
---|
698 | fflush (stdout);
|
---|
699 | }
|
---|
700 | }
|
---|
701 | }
|
---|
702 |
|
---|
703 | /* Here depth returns to the value it had when we were called. */
|
---|
704 | depth--;
|
---|
705 |
|
---|
706 | if (file->double_colon && file->deps == 0)
|
---|
707 | {
|
---|
708 | must_make = 1;
|
---|
709 | DBF (DB_BASIC,
|
---|
710 | _("Target `%s' is double-colon and has no prerequisites.\n"));
|
---|
711 | }
|
---|
712 | else if (!noexist && file->is_target && !deps_changed && file->cmds == 0
|
---|
713 | && !always_make_flag)
|
---|
714 | {
|
---|
715 | must_make = 0;
|
---|
716 | DBF (DB_VERBOSE,
|
---|
717 | _("No commands for `%s' and no prerequisites actually changed.\n"));
|
---|
718 | }
|
---|
719 | else if (!must_make && file->cmds != 0 && always_make_flag)
|
---|
720 | {
|
---|
721 | must_make = 1;
|
---|
722 | DBF (DB_VERBOSE, _("Making `%s' due to always-make flag.\n"));
|
---|
723 | }
|
---|
724 |
|
---|
725 | if (!must_make)
|
---|
726 | {
|
---|
727 | if (ISDB (DB_VERBOSE))
|
---|
728 | {
|
---|
729 | print_spaces (depth);
|
---|
730 | printf (_("No need to remake target `%s'"), file->name);
|
---|
731 | if (!streq (file->name, file->hname))
|
---|
732 | printf (_("; using VPATH name `%s'"), file->hname);
|
---|
733 | puts (".");
|
---|
734 | fflush (stdout);
|
---|
735 | }
|
---|
736 |
|
---|
737 | notice_finished_file (file);
|
---|
738 |
|
---|
739 | /* Since we don't need to remake the file, convert it to use the
|
---|
740 | VPATH filename if we found one. hfile will be either the
|
---|
741 | local name if no VPATH or the VPATH name if one was found. */
|
---|
742 |
|
---|
743 | while (file)
|
---|
744 | {
|
---|
745 | file->name = file->hname;
|
---|
746 | file = file->prev;
|
---|
747 | }
|
---|
748 |
|
---|
749 | return 0;
|
---|
750 | }
|
---|
751 |
|
---|
752 | DBF (DB_BASIC, _("Must remake target `%s'.\n"));
|
---|
753 |
|
---|
754 | /* It needs to be remade. If it's VPATH and not reset via GPATH, toss the
|
---|
755 | VPATH. */
|
---|
756 | if (!streq(file->name, file->hname))
|
---|
757 | {
|
---|
758 | DB (DB_BASIC, (_(" Ignoring VPATH name `%s'.\n"), file->hname));
|
---|
759 | file->ignore_vpath = 1;
|
---|
760 | }
|
---|
761 |
|
---|
762 | /* Now, take appropriate actions to remake the file. */
|
---|
763 | remake_file (file);
|
---|
764 |
|
---|
765 | if (file->command_state != cs_finished)
|
---|
766 | {
|
---|
767 | DBF (DB_VERBOSE, _("Commands of `%s' are being run.\n"));
|
---|
768 | return 0;
|
---|
769 | }
|
---|
770 |
|
---|
771 | switch (file->update_status)
|
---|
772 | {
|
---|
773 | case 2:
|
---|
774 | DBF (DB_BASIC, _("Failed to remake target file `%s'.\n"));
|
---|
775 | break;
|
---|
776 | case 0:
|
---|
777 | DBF (DB_BASIC, _("Successfully remade target file `%s'.\n"));
|
---|
778 | break;
|
---|
779 | case 1:
|
---|
780 | DBF (DB_BASIC, _("Target file `%s' needs remade under -q.\n"));
|
---|
781 | break;
|
---|
782 | default:
|
---|
783 | assert (file->update_status >= 0 && file->update_status <= 2);
|
---|
784 | break;
|
---|
785 | }
|
---|
786 |
|
---|
787 | file->updated = 1;
|
---|
788 | return file->update_status;
|
---|
789 | }
|
---|
790 | |
---|
791 |
|
---|
792 | /* Set FILE's `updated' flag and re-check its mtime and the mtime's of all
|
---|
793 | files listed in its `also_make' member. Under -t, this function also
|
---|
794 | touches FILE.
|
---|
795 |
|
---|
796 | On return, FILE->update_status will no longer be -1 if it was. */
|
---|
797 |
|
---|
798 | void
|
---|
799 | notice_finished_file (struct file *file)
|
---|
800 | {
|
---|
801 | struct dep *d;
|
---|
802 | int ran = file->command_state == cs_running;
|
---|
803 | int touched = 0;
|
---|
804 | DB (DB_JOBS, (_("notice_finished_file - entering: file=%p `%s' update_status=%d command_state=%d\n"), /* bird */
|
---|
805 | file, file->name, file->update_status, file->command_state));
|
---|
806 | file->command_state = cs_finished;
|
---|
807 | file->updated = 1;
|
---|
808 |
|
---|
809 | #ifdef CONFIG_WITH_EXTENDED_NOTPARALLEL
|
---|
810 | /* update not_parallel if the file was flagged for that. */
|
---|
811 | if ( ran
|
---|
812 | && (file->command_flags & (COMMANDS_NOTPARALLEL | COMMANDS_NO_COMMANDS))
|
---|
813 | == COMMANDS_NOTPARALLEL)
|
---|
814 | {
|
---|
815 | DB (DB_KMK, (_("not_parallel %d -> %d (file=%p `%s') [notice_finished_file]\n"), not_parallel,
|
---|
816 | not_parallel - 1, file, file->name));
|
---|
817 | assert(not_parallel >= 1);
|
---|
818 | --not_parallel;
|
---|
819 | }
|
---|
820 | #endif
|
---|
821 |
|
---|
822 | if (touch_flag
|
---|
823 | /* The update status will be:
|
---|
824 | -1 if this target was not remade;
|
---|
825 | 0 if 0 or more commands (+ or ${MAKE}) were run and won;
|
---|
826 | 1 if some commands were run and lost.
|
---|
827 | We touch the target if it has commands which either were not run
|
---|
828 | or won when they ran (i.e. status is 0). */
|
---|
829 | && file->update_status == 0)
|
---|
830 | {
|
---|
831 | if (file->cmds != 0 && file->cmds->any_recurse)
|
---|
832 | {
|
---|
833 | /* If all the command lines were recursive,
|
---|
834 | we don't want to do the touching. */
|
---|
835 | unsigned int i;
|
---|
836 | for (i = 0; i < file->cmds->ncommand_lines; ++i)
|
---|
837 | if (!(file->cmds->lines_flags[i] & COMMANDS_RECURSE))
|
---|
838 | goto have_nonrecursing;
|
---|
839 | }
|
---|
840 | else
|
---|
841 | {
|
---|
842 | have_nonrecursing:
|
---|
843 | if (file->phony)
|
---|
844 | file->update_status = 0;
|
---|
845 | /* According to POSIX, -t doesn't affect targets with no cmds. */
|
---|
846 | else if (file->cmds != 0)
|
---|
847 | {
|
---|
848 | /* Should set file's modification date and do nothing else. */
|
---|
849 | file->update_status = touch_file (file);
|
---|
850 |
|
---|
851 | /* Pretend we ran a real touch command, to suppress the
|
---|
852 | "`foo' is up to date" message. */
|
---|
853 | commands_started++;
|
---|
854 |
|
---|
855 | /* Request for the timestamp to be updated (and distributed
|
---|
856 | to the double-colon entries). Simply setting ran=1 would
|
---|
857 | almost have done the trick, but messes up with the also_make
|
---|
858 | updating logic below. */
|
---|
859 | touched = 1;
|
---|
860 | }
|
---|
861 | }
|
---|
862 | }
|
---|
863 |
|
---|
864 | if (file->mtime_before_update == UNKNOWN_MTIME)
|
---|
865 | file->mtime_before_update = file->last_mtime;
|
---|
866 |
|
---|
867 | if ((ran && !file->phony) || touched)
|
---|
868 | {
|
---|
869 | int i = 0;
|
---|
870 |
|
---|
871 | /* If -n, -t, or -q and all the commands are recursive, we ran them so
|
---|
872 | really check the target's mtime again. Otherwise, assume the target
|
---|
873 | would have been updated. */
|
---|
874 |
|
---|
875 | if (question_flag || just_print_flag || touch_flag)
|
---|
876 | {
|
---|
877 | for (i = file->cmds->ncommand_lines; i > 0; --i)
|
---|
878 | if (! (file->cmds->lines_flags[i-1] & COMMANDS_RECURSE))
|
---|
879 | break;
|
---|
880 | }
|
---|
881 |
|
---|
882 | /* If there were no commands at all, it's always new. */
|
---|
883 |
|
---|
884 | else if (file->is_target && file->cmds == 0)
|
---|
885 | i = 1;
|
---|
886 |
|
---|
887 | file->last_mtime = i == 0 ? UNKNOWN_MTIME : NEW_MTIME;
|
---|
888 | }
|
---|
889 |
|
---|
890 | if (file->double_colon)
|
---|
891 | {
|
---|
892 | /* If this is a double colon rule and it is the last one to be
|
---|
893 | updated, propagate the change of modification time to all the
|
---|
894 | double-colon entries for this file.
|
---|
895 |
|
---|
896 | We do it on the last update because it is important to handle
|
---|
897 | individual entries as separate rules with separate timestamps
|
---|
898 | while they are treated as targets and then as one rule with the
|
---|
899 | unified timestamp when they are considered as a prerequisite
|
---|
900 | of some target. */
|
---|
901 |
|
---|
902 | struct file *f;
|
---|
903 | FILE_TIMESTAMP max_mtime = file->last_mtime;
|
---|
904 |
|
---|
905 | /* Check that all rules were updated and at the same time find
|
---|
906 | the max timestamp. We assume UNKNOWN_MTIME is newer then
|
---|
907 | any other value. */
|
---|
908 | for (f = file->double_colon; f != 0 && f->updated; f = f->prev)
|
---|
909 | if (max_mtime != UNKNOWN_MTIME
|
---|
910 | && (f->last_mtime == UNKNOWN_MTIME || f->last_mtime > max_mtime))
|
---|
911 | max_mtime = f->last_mtime;
|
---|
912 |
|
---|
913 | if (f == 0)
|
---|
914 | for (f = file->double_colon; f != 0; f = f->prev)
|
---|
915 | f->last_mtime = max_mtime;
|
---|
916 | }
|
---|
917 |
|
---|
918 | if (ran && file->update_status != -1)
|
---|
919 | /* We actually tried to update FILE, which has
|
---|
920 | updated its also_make's as well (if it worked).
|
---|
921 | If it didn't work, it wouldn't work again for them.
|
---|
922 | So mark them as updated with the same status. */
|
---|
923 | for (d = file->also_make; d != 0; d = d->next)
|
---|
924 | {
|
---|
925 | d->file->command_state = cs_finished;
|
---|
926 | d->file->updated = 1;
|
---|
927 | d->file->update_status = file->update_status;
|
---|
928 |
|
---|
929 | if (ran && !d->file->phony)
|
---|
930 | /* Fetch the new modification time.
|
---|
931 | We do this instead of just invalidating the cached time
|
---|
932 | so that a vpath_search can happen. Otherwise, it would
|
---|
933 | never be done because the target is already updated. */
|
---|
934 | f_mtime (d->file, 0);
|
---|
935 | }
|
---|
936 | else if (file->update_status == -1)
|
---|
937 | /* Nothing was done for FILE, but it needed nothing done.
|
---|
938 | So mark it now as "succeeded". */
|
---|
939 | file->update_status = 0;
|
---|
940 | }
|
---|
941 | |
---|
942 |
|
---|
943 | /* Check whether another file (whose mtime is THIS_MTIME) needs updating on
|
---|
944 | account of a dependency which is file FILE. If it does, store 1 in
|
---|
945 | *MUST_MAKE_PTR. In the process, update any non-intermediate files that
|
---|
946 | FILE depends on (including FILE itself). Return nonzero if any updating
|
---|
947 | failed. */
|
---|
948 |
|
---|
949 | static int
|
---|
950 | check_dep (struct file *file, unsigned int depth,
|
---|
951 | FILE_TIMESTAMP this_mtime, int *must_make_ptr)
|
---|
952 | {
|
---|
953 | struct dep *d;
|
---|
954 | int dep_status = 0;
|
---|
955 |
|
---|
956 | ++depth;
|
---|
957 | start_updating (file);
|
---|
958 |
|
---|
959 | if (file->phony || !file->intermediate)
|
---|
960 | {
|
---|
961 | /* If this is a non-intermediate file, update it and record whether it
|
---|
962 | is newer than THIS_MTIME. */
|
---|
963 | FILE_TIMESTAMP mtime;
|
---|
964 | dep_status = update_file (file, depth);
|
---|
965 | check_renamed (file);
|
---|
966 | mtime = file_mtime (file);
|
---|
967 | check_renamed (file);
|
---|
968 | if (mtime == NONEXISTENT_MTIME || mtime > this_mtime)
|
---|
969 | *must_make_ptr = 1;
|
---|
970 | }
|
---|
971 | else
|
---|
972 | {
|
---|
973 | /* FILE is an intermediate file. */
|
---|
974 | FILE_TIMESTAMP mtime;
|
---|
975 |
|
---|
976 | if (!file->phony && file->cmds == 0 && !file->tried_implicit)
|
---|
977 | {
|
---|
978 | if (try_implicit_rule (file, depth))
|
---|
979 | DBF (DB_IMPLICIT, _("Found an implicit rule for `%s'.\n"));
|
---|
980 | else
|
---|
981 | DBF (DB_IMPLICIT, _("No implicit rule found for `%s'.\n"));
|
---|
982 | file->tried_implicit = 1;
|
---|
983 | }
|
---|
984 | if (file->cmds == 0 && !file->is_target
|
---|
985 | && default_file != 0 && default_file->cmds != 0)
|
---|
986 | {
|
---|
987 | DBF (DB_IMPLICIT, _("Using default commands for `%s'.\n"));
|
---|
988 | file->cmds = default_file->cmds;
|
---|
989 | }
|
---|
990 |
|
---|
991 | check_renamed (file);
|
---|
992 | mtime = file_mtime (file);
|
---|
993 | check_renamed (file);
|
---|
994 | if (mtime != NONEXISTENT_MTIME && mtime > this_mtime)
|
---|
995 | /* If the intermediate file actually exists and is newer, then we
|
---|
996 | should remake from it. */
|
---|
997 | *must_make_ptr = 1;
|
---|
998 | else
|
---|
999 | {
|
---|
1000 | /* Otherwise, update all non-intermediate files we depend on, if
|
---|
1001 | necessary, and see whether any of them is more recent than the
|
---|
1002 | file on whose behalf we are checking. */
|
---|
1003 | struct dep *lastd;
|
---|
1004 |
|
---|
1005 | lastd = 0;
|
---|
1006 | d = file->deps;
|
---|
1007 | while (d != 0)
|
---|
1008 | {
|
---|
1009 | int maybe_make;
|
---|
1010 |
|
---|
1011 | if (is_updating (d->file))
|
---|
1012 | {
|
---|
1013 | error (NILF, _("Circular %s <- %s dependency dropped."),
|
---|
1014 | file->name, d->file->name);
|
---|
1015 | if (lastd == 0)
|
---|
1016 | {
|
---|
1017 | file->deps = d->next;
|
---|
1018 | free_dep (d);
|
---|
1019 | d = file->deps;
|
---|
1020 | }
|
---|
1021 | else
|
---|
1022 | {
|
---|
1023 | lastd->next = d->next;
|
---|
1024 | free_dep (d);
|
---|
1025 | d = lastd->next;
|
---|
1026 | }
|
---|
1027 | continue;
|
---|
1028 | }
|
---|
1029 |
|
---|
1030 | d->file->parent = file;
|
---|
1031 | maybe_make = *must_make_ptr;
|
---|
1032 | dep_status |= check_dep (d->file, depth, this_mtime,
|
---|
1033 | &maybe_make);
|
---|
1034 | if (! d->ignore_mtime)
|
---|
1035 | *must_make_ptr = maybe_make;
|
---|
1036 | check_renamed (d->file);
|
---|
1037 | if (dep_status != 0 && !keep_going_flag)
|
---|
1038 | break;
|
---|
1039 |
|
---|
1040 | if (d->file->command_state == cs_running
|
---|
1041 | || d->file->command_state == cs_deps_running)
|
---|
1042 | /* Record that some of FILE's deps are still being made.
|
---|
1043 | This tells the upper levels to wait on processing it until
|
---|
1044 | the commands are finished. */
|
---|
1045 | set_command_state (file, cs_deps_running);
|
---|
1046 |
|
---|
1047 | lastd = d;
|
---|
1048 | d = d->next;
|
---|
1049 | }
|
---|
1050 | }
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | finish_updating (file);
|
---|
1054 | return dep_status;
|
---|
1055 | }
|
---|
1056 | |
---|
1057 |
|
---|
1058 | /* Touch FILE. Return zero if successful, one if not. */
|
---|
1059 |
|
---|
1060 | #define TOUCH_ERROR(call) return (perror_with_name (call, file->name), 1)
|
---|
1061 |
|
---|
1062 | static int
|
---|
1063 | touch_file (struct file *file)
|
---|
1064 | {
|
---|
1065 | if (!silent_flag)
|
---|
1066 | message (0, "touch %s", file->name);
|
---|
1067 |
|
---|
1068 | #ifndef NO_ARCHIVES
|
---|
1069 | if (ar_name (file->name))
|
---|
1070 | return ar_touch (file->name);
|
---|
1071 | else
|
---|
1072 | #endif
|
---|
1073 | {
|
---|
1074 | int fd = open (file->name, O_RDWR | O_CREAT, 0666);
|
---|
1075 |
|
---|
1076 | if (fd < 0)
|
---|
1077 | TOUCH_ERROR ("touch: open: ");
|
---|
1078 | else
|
---|
1079 | {
|
---|
1080 | struct stat statbuf;
|
---|
1081 | char buf = 'x';
|
---|
1082 | int e;
|
---|
1083 |
|
---|
1084 | EINTRLOOP (e, fstat (fd, &statbuf));
|
---|
1085 | if (e < 0)
|
---|
1086 | TOUCH_ERROR ("touch: fstat: ");
|
---|
1087 | /* Rewrite character 0 same as it already is. */
|
---|
1088 | if (read (fd, &buf, 1) < 0)
|
---|
1089 | TOUCH_ERROR ("touch: read: ");
|
---|
1090 | if (lseek (fd, 0L, 0) < 0L)
|
---|
1091 | TOUCH_ERROR ("touch: lseek: ");
|
---|
1092 | if (write (fd, &buf, 1) < 0)
|
---|
1093 | TOUCH_ERROR ("touch: write: ");
|
---|
1094 | /* If file length was 0, we just
|
---|
1095 | changed it, so change it back. */
|
---|
1096 | if (statbuf.st_size == 0)
|
---|
1097 | {
|
---|
1098 | (void) close (fd);
|
---|
1099 | fd = open (file->name, O_RDWR | O_TRUNC, 0666);
|
---|
1100 | if (fd < 0)
|
---|
1101 | TOUCH_ERROR ("touch: open: ");
|
---|
1102 | }
|
---|
1103 | (void) close (fd);
|
---|
1104 | }
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | return 0;
|
---|
1108 | }
|
---|
1109 | |
---|
1110 |
|
---|
1111 | /* Having checked and updated the dependencies of FILE,
|
---|
1112 | do whatever is appropriate to remake FILE itself.
|
---|
1113 | Return the status from executing FILE's commands. */
|
---|
1114 |
|
---|
1115 | static void
|
---|
1116 | remake_file (struct file *file)
|
---|
1117 | {
|
---|
1118 | if (file->cmds == 0)
|
---|
1119 | {
|
---|
1120 | if (file->phony)
|
---|
1121 | /* Phony target. Pretend it succeeded. */
|
---|
1122 | file->update_status = 0;
|
---|
1123 | else if (file->is_target)
|
---|
1124 | /* This is a nonexistent target file we cannot make.
|
---|
1125 | Pretend it was successfully remade. */
|
---|
1126 | file->update_status = 0;
|
---|
1127 | else
|
---|
1128 | {
|
---|
1129 | /* This is a dependency file we cannot remake. Fail. */
|
---|
1130 | if (!rebuilding_makefiles || !file->dontcare)
|
---|
1131 | complain (file);
|
---|
1132 | file->update_status = 2;
|
---|
1133 | }
|
---|
1134 | }
|
---|
1135 | else
|
---|
1136 | {
|
---|
1137 | chop_commands (file->cmds);
|
---|
1138 |
|
---|
1139 | /* The normal case: start some commands. */
|
---|
1140 | if (!touch_flag || file->cmds->any_recurse)
|
---|
1141 | {
|
---|
1142 | execute_file_commands (file);
|
---|
1143 | return;
|
---|
1144 | }
|
---|
1145 |
|
---|
1146 | /* This tells notice_finished_file it is ok to touch the file. */
|
---|
1147 | file->update_status = 0;
|
---|
1148 | }
|
---|
1149 |
|
---|
1150 | /* This does the touching under -t. */
|
---|
1151 | notice_finished_file (file);
|
---|
1152 | }
|
---|
1153 | |
---|
1154 |
|
---|
1155 | /* Return the mtime of a file, given a `struct file'.
|
---|
1156 | Caches the time in the struct file to avoid excess stat calls.
|
---|
1157 |
|
---|
1158 | If the file is not found, and SEARCH is nonzero, VPATH searching and
|
---|
1159 | replacement is done. If that fails, a library (-lLIBNAME) is tried and
|
---|
1160 | the library's actual name (/lib/libLIBNAME.a, etc.) is substituted into
|
---|
1161 | FILE. */
|
---|
1162 |
|
---|
1163 | FILE_TIMESTAMP
|
---|
1164 | f_mtime (struct file *file, int search)
|
---|
1165 | {
|
---|
1166 | FILE_TIMESTAMP mtime;
|
---|
1167 |
|
---|
1168 | /* File's mtime is not known; must get it from the system. */
|
---|
1169 |
|
---|
1170 | #ifndef NO_ARCHIVES
|
---|
1171 | if (ar_name (file->name))
|
---|
1172 | {
|
---|
1173 | /* This file is an archive-member reference. */
|
---|
1174 |
|
---|
1175 | char *arname, *memname;
|
---|
1176 | struct file *arfile;
|
---|
1177 | time_t member_date;
|
---|
1178 |
|
---|
1179 | /* Find the archive's name. */
|
---|
1180 | ar_parse_name (file->name, &arname, &memname);
|
---|
1181 |
|
---|
1182 | /* Find the modification time of the archive itself.
|
---|
1183 | Also allow for its name to be changed via VPATH search. */
|
---|
1184 | arfile = lookup_file (arname);
|
---|
1185 | if (arfile == 0)
|
---|
1186 | arfile = enter_file (strcache_add (arname));
|
---|
1187 | mtime = f_mtime (arfile, search);
|
---|
1188 | check_renamed (arfile);
|
---|
1189 | if (search && strcmp (arfile->hname, arname))
|
---|
1190 | {
|
---|
1191 | /* The archive's name has changed.
|
---|
1192 | Change the archive-member reference accordingly. */
|
---|
1193 |
|
---|
1194 | char *name;
|
---|
1195 | unsigned int arlen, memlen;
|
---|
1196 |
|
---|
1197 | arlen = strlen (arfile->hname);
|
---|
1198 | memlen = strlen (memname);
|
---|
1199 |
|
---|
1200 | name = xmalloc (arlen + 1 + memlen + 2);
|
---|
1201 | memcpy (name, arfile->hname, arlen);
|
---|
1202 | name[arlen] = '(';
|
---|
1203 | memcpy (name + arlen + 1, memname, memlen);
|
---|
1204 | name[arlen + 1 + memlen] = ')';
|
---|
1205 | name[arlen + 1 + memlen + 1] = '\0';
|
---|
1206 |
|
---|
1207 | /* If the archive was found with GPATH, make the change permanent;
|
---|
1208 | otherwise defer it until later. */
|
---|
1209 | if (arfile->name == arfile->hname)
|
---|
1210 | rename_file (file, name);
|
---|
1211 | else
|
---|
1212 | rehash_file (file, name);
|
---|
1213 | check_renamed (file);
|
---|
1214 | }
|
---|
1215 |
|
---|
1216 | free (arname);
|
---|
1217 |
|
---|
1218 | file->low_resolution_time = 1;
|
---|
1219 |
|
---|
1220 | if (mtime == NONEXISTENT_MTIME)
|
---|
1221 | /* The archive doesn't exist, so its members don't exist either. */
|
---|
1222 | return NONEXISTENT_MTIME;
|
---|
1223 |
|
---|
1224 | member_date = ar_member_date (file->hname);
|
---|
1225 | mtime = (member_date == (time_t) -1
|
---|
1226 | ? NONEXISTENT_MTIME
|
---|
1227 | : file_timestamp_cons (file->hname, member_date, 0));
|
---|
1228 | }
|
---|
1229 | else
|
---|
1230 | #endif
|
---|
1231 | {
|
---|
1232 | mtime = name_mtime (file->name);
|
---|
1233 |
|
---|
1234 | if (mtime == NONEXISTENT_MTIME && search && !file->ignore_vpath)
|
---|
1235 | {
|
---|
1236 | /* If name_mtime failed, search VPATH. */
|
---|
1237 | const char *name = vpath_search (file->name, &mtime);
|
---|
1238 | if (name
|
---|
1239 | /* Last resort, is it a library (-lxxx)? */
|
---|
1240 | || (file->name[0] == '-' && file->name[1] == 'l'
|
---|
1241 | && (name = library_search (file->name, &mtime)) != 0))
|
---|
1242 | {
|
---|
1243 | if (mtime != UNKNOWN_MTIME)
|
---|
1244 | /* vpath_search and library_search store UNKNOWN_MTIME
|
---|
1245 | if they didn't need to do a stat call for their work. */
|
---|
1246 | file->last_mtime = mtime;
|
---|
1247 |
|
---|
1248 | /* If we found it in VPATH, see if it's in GPATH too; if so,
|
---|
1249 | change the name right now; if not, defer until after the
|
---|
1250 | dependencies are updated. */
|
---|
1251 | if (gpath_search (name, strlen(name) - strlen(file->name) - 1))
|
---|
1252 | {
|
---|
1253 | rename_file (file, name);
|
---|
1254 | check_renamed (file);
|
---|
1255 | return file_mtime (file);
|
---|
1256 | }
|
---|
1257 |
|
---|
1258 | rehash_file (file, name);
|
---|
1259 | check_renamed (file);
|
---|
1260 | /* If the result of a vpath search is -o or -W, preserve it.
|
---|
1261 | Otherwise, find the mtime of the resulting file. */
|
---|
1262 | if (mtime != OLD_MTIME && mtime != NEW_MTIME)
|
---|
1263 | mtime = name_mtime (name);
|
---|
1264 | }
|
---|
1265 | }
|
---|
1266 | }
|
---|
1267 |
|
---|
1268 | /* Files can have bogus timestamps that nothing newly made will be
|
---|
1269 | "newer" than. Updating their dependents could just result in loops.
|
---|
1270 | So notify the user of the anomaly with a warning.
|
---|
1271 |
|
---|
1272 | We only need to do this once, for now. */
|
---|
1273 |
|
---|
1274 | if (!clock_skew_detected
|
---|
1275 | && mtime != NONEXISTENT_MTIME && mtime != NEW_MTIME
|
---|
1276 | && !file->updated)
|
---|
1277 | {
|
---|
1278 | static FILE_TIMESTAMP adjusted_now;
|
---|
1279 |
|
---|
1280 | FILE_TIMESTAMP adjusted_mtime = mtime;
|
---|
1281 |
|
---|
1282 | #if defined(WINDOWS32) || defined(__MSDOS__)
|
---|
1283 | /* Experimentation has shown that FAT filesystems can set file times
|
---|
1284 | up to 3 seconds into the future! Play it safe. */
|
---|
1285 |
|
---|
1286 | #define FAT_ADJ_OFFSET (FILE_TIMESTAMP) 3
|
---|
1287 |
|
---|
1288 | FILE_TIMESTAMP adjustment = FAT_ADJ_OFFSET << FILE_TIMESTAMP_LO_BITS;
|
---|
1289 | if (ORDINARY_MTIME_MIN + adjustment <= adjusted_mtime)
|
---|
1290 | adjusted_mtime -= adjustment;
|
---|
1291 | #elif defined(__EMX__)
|
---|
1292 | /* FAT filesystems round time to the nearest even second!
|
---|
1293 | Allow for any file (NTFS or FAT) to perhaps suffer from this
|
---|
1294 | brain damage. */
|
---|
1295 | FILE_TIMESTAMP adjustment = (((FILE_TIMESTAMP_S (adjusted_mtime) & 1) == 0
|
---|
1296 | && FILE_TIMESTAMP_NS (adjusted_mtime) == 0)
|
---|
1297 | ? (FILE_TIMESTAMP) 1 << FILE_TIMESTAMP_LO_BITS
|
---|
1298 | : 0);
|
---|
1299 | #endif
|
---|
1300 |
|
---|
1301 | /* If the file's time appears to be in the future, update our
|
---|
1302 | concept of the present and try once more. */
|
---|
1303 | if (adjusted_now < adjusted_mtime)
|
---|
1304 | {
|
---|
1305 | int resolution;
|
---|
1306 | FILE_TIMESTAMP now = file_timestamp_now (&resolution);
|
---|
1307 | adjusted_now = now + (resolution - 1);
|
---|
1308 | if (adjusted_now < adjusted_mtime)
|
---|
1309 | {
|
---|
1310 | #ifdef NO_FLOAT
|
---|
1311 | error (NILF, _("Warning: File `%s' has modification time in the future"),
|
---|
1312 | file->name);
|
---|
1313 | #else
|
---|
1314 | double from_now =
|
---|
1315 | (FILE_TIMESTAMP_S (mtime) - FILE_TIMESTAMP_S (now)
|
---|
1316 | + ((FILE_TIMESTAMP_NS (mtime) - FILE_TIMESTAMP_NS (now))
|
---|
1317 | / 1e9));
|
---|
1318 | error (NILF, _("Warning: File `%s' has modification time %.2g s in the future"),
|
---|
1319 | file->name, from_now);
|
---|
1320 | #endif
|
---|
1321 | clock_skew_detected = 1;
|
---|
1322 | }
|
---|
1323 | }
|
---|
1324 | }
|
---|
1325 |
|
---|
1326 | /* Store the mtime into all the entries for this file. */
|
---|
1327 | if (file->double_colon)
|
---|
1328 | file = file->double_colon;
|
---|
1329 |
|
---|
1330 | do
|
---|
1331 | {
|
---|
1332 | /* If this file is not implicit but it is intermediate then it was
|
---|
1333 | made so by the .INTERMEDIATE target. If this file has never
|
---|
1334 | been built by us but was found now, it existed before make
|
---|
1335 | started. So, turn off the intermediate bit so make doesn't
|
---|
1336 | delete it, since it didn't create it. */
|
---|
1337 | if (mtime != NONEXISTENT_MTIME && file->command_state == cs_not_started
|
---|
1338 | && file->command_state == cs_not_started
|
---|
1339 | && !file->tried_implicit && file->intermediate)
|
---|
1340 | file->intermediate = 0;
|
---|
1341 |
|
---|
1342 | file->last_mtime = mtime;
|
---|
1343 | file = file->prev;
|
---|
1344 | }
|
---|
1345 | while (file != 0);
|
---|
1346 |
|
---|
1347 | return mtime;
|
---|
1348 | }
|
---|
1349 |
|
---|
1350 |
|
---|
1351 | /* Return the mtime of the file or archive-member reference NAME. */
|
---|
1352 |
|
---|
1353 | /* First, we check with stat(). If the file does not exist, then we return
|
---|
1354 | NONEXISTENT_MTIME. If it does, and the symlink check flag is set, then
|
---|
1355 | examine each indirection of the symlink and find the newest mtime.
|
---|
1356 | This causes one duplicate stat() when -L is being used, but the code is
|
---|
1357 | much cleaner. */
|
---|
1358 |
|
---|
1359 | static FILE_TIMESTAMP
|
---|
1360 | name_mtime (const char *name)
|
---|
1361 | {
|
---|
1362 | FILE_TIMESTAMP mtime;
|
---|
1363 | struct stat st;
|
---|
1364 | int e;
|
---|
1365 |
|
---|
1366 | EINTRLOOP (e, stat (name, &st));
|
---|
1367 | if (e == 0)
|
---|
1368 | mtime = FILE_TIMESTAMP_STAT_MODTIME (name, st);
|
---|
1369 | else if (errno == ENOENT || errno == ENOTDIR)
|
---|
1370 | mtime = NONEXISTENT_MTIME;
|
---|
1371 | else
|
---|
1372 | {
|
---|
1373 | perror_with_name ("stat: ", name);
|
---|
1374 | return NONEXISTENT_MTIME;
|
---|
1375 | }
|
---|
1376 |
|
---|
1377 | /* If we get here we either found it, or it doesn't exist.
|
---|
1378 | If it doesn't exist see if we can use a symlink mtime instead. */
|
---|
1379 |
|
---|
1380 | #ifdef MAKE_SYMLINKS
|
---|
1381 | #ifndef S_ISLNK
|
---|
1382 | # define S_ISLNK(_m) (((_m)&S_IFMT)==S_IFLNK)
|
---|
1383 | #endif
|
---|
1384 | if (check_symlink_flag)
|
---|
1385 | {
|
---|
1386 | PATH_VAR (lpath);
|
---|
1387 |
|
---|
1388 | /* Check each symbolic link segment (if any). Find the latest mtime
|
---|
1389 | amongst all of them (and the target file of course).
|
---|
1390 | Note that we have already successfully dereferenced all the links
|
---|
1391 | above. So, if we run into any error trying to lstat(), or
|
---|
1392 | readlink(), or whatever, something bizarre-o happened. Just give up
|
---|
1393 | and use whatever mtime we've already computed at that point. */
|
---|
1394 | strcpy (lpath, name);
|
---|
1395 | while (1)
|
---|
1396 | {
|
---|
1397 | FILE_TIMESTAMP ltime;
|
---|
1398 | PATH_VAR (lbuf);
|
---|
1399 | long llen;
|
---|
1400 | char *p;
|
---|
1401 |
|
---|
1402 | EINTRLOOP (e, lstat (lpath, &st));
|
---|
1403 | if (e)
|
---|
1404 | {
|
---|
1405 | /* Just take what we have so far. */
|
---|
1406 | if (errno != ENOENT && errno != ENOTDIR)
|
---|
1407 | perror_with_name ("lstat: ", lpath);
|
---|
1408 | break;
|
---|
1409 | }
|
---|
1410 |
|
---|
1411 | /* If this is not a symlink, we're done (we started with the real
|
---|
1412 | file's mtime so we don't need to test it again). */
|
---|
1413 | if (!S_ISLNK (st.st_mode))
|
---|
1414 | break;
|
---|
1415 |
|
---|
1416 | /* If this mtime is newer than what we had, keep the new one. */
|
---|
1417 | ltime = FILE_TIMESTAMP_STAT_MODTIME (lpath, st);
|
---|
1418 | if (ltime > mtime)
|
---|
1419 | mtime = ltime;
|
---|
1420 |
|
---|
1421 | /* Set up to check the file pointed to by this link. */
|
---|
1422 | EINTRLOOP (llen, readlink (lpath, lbuf, GET_PATH_MAX));
|
---|
1423 | if (llen < 0)
|
---|
1424 | {
|
---|
1425 | /* Eh? Just take what we have. */
|
---|
1426 | perror_with_name ("readlink: ", lpath);
|
---|
1427 | break;
|
---|
1428 | }
|
---|
1429 | lbuf[llen] = '\0';
|
---|
1430 |
|
---|
1431 | /* If the target is fully-qualified or the source is just a
|
---|
1432 | filename, then the new path is the target. Otherwise it's the
|
---|
1433 | source directory plus the target. */
|
---|
1434 | if (lbuf[0] == '/' || (p = strrchr (lpath, '/')) == NULL)
|
---|
1435 | strcpy (lpath, lbuf);
|
---|
1436 | else if ((p - lpath) + llen + 2 > GET_PATH_MAX)
|
---|
1437 | /* Eh? Path too long! Again, just go with what we have. */
|
---|
1438 | break;
|
---|
1439 | else
|
---|
1440 | /* Create the next step in the symlink chain. */
|
---|
1441 | strcpy (p+1, lbuf);
|
---|
1442 | }
|
---|
1443 | }
|
---|
1444 | #endif
|
---|
1445 |
|
---|
1446 | return mtime;
|
---|
1447 | }
|
---|
1448 |
|
---|
1449 |
|
---|
1450 | /* Search for a library file specified as -lLIBNAME, searching for a
|
---|
1451 | suitable library file in the system library directories and the VPATH
|
---|
1452 | directories. */
|
---|
1453 |
|
---|
1454 | static const char *
|
---|
1455 | library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr)
|
---|
1456 | {
|
---|
1457 | static char *dirs[] =
|
---|
1458 | {
|
---|
1459 | #ifdef KMK
|
---|
1460 | ".",
|
---|
1461 | #else /* !KMK */
|
---|
1462 | #ifndef _AMIGA
|
---|
1463 | "/lib",
|
---|
1464 | "/usr/lib",
|
---|
1465 | #endif
|
---|
1466 | #if defined(WINDOWS32) && !defined(LIBDIR)
|
---|
1467 | /*
|
---|
1468 | * This is completely up to the user at product install time. Just define
|
---|
1469 | * a placeholder.
|
---|
1470 | */
|
---|
1471 | #define LIBDIR "."
|
---|
1472 | #endif
|
---|
1473 | LIBDIR, /* Defined by configuration. */
|
---|
1474 | #endif /* !KMK */
|
---|
1475 | 0
|
---|
1476 | };
|
---|
1477 |
|
---|
1478 | static char *libpatterns = NULL;
|
---|
1479 |
|
---|
1480 | const char *libname = lib+2; /* Name without the '-l'. */
|
---|
1481 | FILE_TIMESTAMP mtime;
|
---|
1482 |
|
---|
1483 | /* Loop variables for the libpatterns value. */
|
---|
1484 | char *p;
|
---|
1485 | const char *p2;
|
---|
1486 | unsigned int len;
|
---|
1487 |
|
---|
1488 | char **dp;
|
---|
1489 |
|
---|
1490 | /* If we don't have libpatterns, get it. */
|
---|
1491 | if (!libpatterns)
|
---|
1492 | {
|
---|
1493 | int save = warn_undefined_variables_flag;
|
---|
1494 | warn_undefined_variables_flag = 0;
|
---|
1495 |
|
---|
1496 | libpatterns = xstrdup (variable_expand ("$(strip $(.LIBPATTERNS))"));
|
---|
1497 |
|
---|
1498 | warn_undefined_variables_flag = save;
|
---|
1499 | }
|
---|
1500 |
|
---|
1501 | /* Loop through all the patterns in .LIBPATTERNS, and search on each one. */
|
---|
1502 | p2 = libpatterns;
|
---|
1503 | while ((p = find_next_token (&p2, &len)) != 0)
|
---|
1504 | {
|
---|
1505 | static char *buf = NULL;
|
---|
1506 | static unsigned int buflen = 0;
|
---|
1507 | static int libdir_maxlen = -1;
|
---|
1508 | char *libbuf = variable_expand ("");
|
---|
1509 | const size_t libbuf_offset = libbuf - variable_buffer; /* bird */
|
---|
1510 |
|
---|
1511 | /* Expand the pattern using LIBNAME as a replacement. */
|
---|
1512 | {
|
---|
1513 | char c = p[len];
|
---|
1514 | char *p3, *p4;
|
---|
1515 |
|
---|
1516 | p[len] = '\0';
|
---|
1517 | p3 = find_percent (p);
|
---|
1518 | if (!p3)
|
---|
1519 | {
|
---|
1520 | /* Give a warning if there is no pattern, then remove the
|
---|
1521 | pattern so it's ignored next time. */
|
---|
1522 | error (NILF, _(".LIBPATTERNS element `%s' is not a pattern"), p);
|
---|
1523 | for (; len; --len, ++p)
|
---|
1524 | *p = ' ';
|
---|
1525 | *p = c;
|
---|
1526 | continue;
|
---|
1527 | }
|
---|
1528 | p4 = variable_buffer_output (libbuf, p, p3-p);
|
---|
1529 | p4 = variable_buffer_output (p4, libname, strlen (libname));
|
---|
1530 | p4 = variable_buffer_output (p4, p3+1, len - (p3-p));
|
---|
1531 | p[len] = c;
|
---|
1532 | libbuf = variable_buffer + libbuf_offset; /* bird - variable_buffer may have been reallocated. */
|
---|
1533 | }
|
---|
1534 |
|
---|
1535 | /* Look first for `libNAME.a' in the current directory. */
|
---|
1536 | mtime = name_mtime (libbuf);
|
---|
1537 | if (mtime != NONEXISTENT_MTIME)
|
---|
1538 | {
|
---|
1539 | if (mtime_ptr != 0)
|
---|
1540 | *mtime_ptr = mtime;
|
---|
1541 | return strcache_add (libbuf);
|
---|
1542 | }
|
---|
1543 |
|
---|
1544 | /* Now try VPATH search on that. */
|
---|
1545 |
|
---|
1546 | {
|
---|
1547 | const char *file = vpath_search (libbuf, mtime_ptr);
|
---|
1548 | if (file)
|
---|
1549 | return file;
|
---|
1550 | }
|
---|
1551 |
|
---|
1552 | /* Now try the standard set of directories. */
|
---|
1553 |
|
---|
1554 | if (!buflen)
|
---|
1555 | {
|
---|
1556 | for (dp = dirs; *dp != 0; ++dp)
|
---|
1557 | {
|
---|
1558 | int l = strlen (*dp);
|
---|
1559 | if (l > libdir_maxlen)
|
---|
1560 | libdir_maxlen = l;
|
---|
1561 | }
|
---|
1562 | buflen = strlen (libbuf);
|
---|
1563 | buf = xmalloc(libdir_maxlen + buflen + 2);
|
---|
1564 | }
|
---|
1565 | else if (buflen < strlen (libbuf))
|
---|
1566 | {
|
---|
1567 | buflen = strlen (libbuf);
|
---|
1568 | buf = xrealloc (buf, libdir_maxlen + buflen + 2);
|
---|
1569 | }
|
---|
1570 |
|
---|
1571 | for (dp = dirs; *dp != 0; ++dp)
|
---|
1572 | {
|
---|
1573 | sprintf (buf, "%s/%s", *dp, libbuf);
|
---|
1574 | mtime = name_mtime (buf);
|
---|
1575 | if (mtime != NONEXISTENT_MTIME)
|
---|
1576 | {
|
---|
1577 | if (mtime_ptr != 0)
|
---|
1578 | *mtime_ptr = mtime;
|
---|
1579 | return strcache_add (buf);
|
---|
1580 | }
|
---|
1581 | }
|
---|
1582 | }
|
---|
1583 |
|
---|
1584 | return 0;
|
---|
1585 | }
|
---|