On BSD, realpath(3) doesn't fail if the target doesn't exist, so test
[make.git] / remake.c
blobc0bf709df55e31c602a64fd43ebe1d2501d0e772
1 /* Basic dependency engine for GNU Make.
2 Copyright (C) 1988-2012 Free Software Foundation, Inc.
3 This file is part of GNU Make.
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.
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.
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/>. */
17 #include "make.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"
25 #include <assert.h>
27 #ifdef HAVE_FCNTL_H
28 #include <fcntl.h>
29 #else
30 #include <sys/file.h>
31 #endif
33 #ifdef VMS
34 #include <starlet.h>
35 #endif
36 #ifdef WINDOWS32
37 #include <io.h>
38 #endif
40 extern int try_implicit_rule (struct file *file, unsigned int depth);
43 /* The test for circular dependencies is based on the 'updating' bit in
44 'struct file'. However, double colon targets have seperate 'struct
45 file's; make sure we always use the base of the double colon chain. */
47 #define start_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
48 ->updating = 1)
49 #define finish_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
50 ->updating = 0)
51 #define is_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
52 ->updating)
55 /* Incremented when a command is started (under -n, when one would be). */
56 unsigned int commands_started = 0;
58 /* Current value for pruning the scan of the goal chain (toggle 0/1). */
59 static unsigned int considered;
61 static int update_file (struct file *file, unsigned int depth);
62 static int update_file_1 (struct file *file, unsigned int depth);
63 static int check_dep (struct file *file, unsigned int depth,
64 FILE_TIMESTAMP this_mtime, int *must_make_ptr);
65 static int touch_file (struct file *file);
66 static void remake_file (struct file *file);
67 static FILE_TIMESTAMP name_mtime (const char *name);
68 static const char *library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr);
71 /* Remake all the goals in the 'struct dep' chain GOALS. Return -1 if nothing
72 was done, 0 if all goals were updated successfully, or 1 if a goal failed.
74 If rebuilding_makefiles is nonzero, these goals are makefiles, so -t, -q,
75 and -n should be disabled for them unless they were also command-line
76 targets, and we should only make one goal at a time and return as soon as
77 one goal whose 'changed' member is nonzero is successfully made. */
79 int
80 update_goal_chain (struct dep *goals)
82 int t = touch_flag, q = question_flag, n = just_print_flag;
83 int status = -1;
85 #define MTIME(file) (rebuilding_makefiles ? file_mtime_no_search (file) \
86 : file_mtime (file))
88 /* Duplicate the chain so we can remove things from it. */
90 goals = copy_dep_chain (goals);
93 /* Clear the 'changed' flag of each goal in the chain.
94 We will use the flag below to notice when any commands
95 have actually been run for a target. When no commands
96 have been run, we give an "up to date" diagnostic. */
98 struct dep *g;
99 for (g = goals; g != 0; g = g->next)
100 g->changed = 0;
103 /* All files start with the considered bit 0, so the global value is 1. */
104 considered = 1;
106 /* Update all the goals until they are all finished. */
108 while (goals != 0)
110 register struct dep *g, *lastgoal;
112 /* Start jobs that are waiting for the load to go down. */
114 start_waiting_jobs ();
116 /* Wait for a child to die. */
118 reap_children (1, 0);
120 lastgoal = 0;
121 g = goals;
122 while (g != 0)
124 /* Iterate over all double-colon entries for this file. */
125 struct file *file;
126 int stop = 0, any_not_updated = 0;
128 for (file = g->file->double_colon ? g->file->double_colon : g->file;
129 file != NULL;
130 file = file->prev)
132 unsigned int ocommands_started;
133 int x;
135 file->dontcare = g->dontcare;
137 check_renamed (file);
138 if (rebuilding_makefiles)
140 if (file->cmd_target)
142 touch_flag = t;
143 question_flag = q;
144 just_print_flag = n;
146 else
147 touch_flag = question_flag = just_print_flag = 0;
150 /* Save the old value of 'commands_started' so we can compare
151 later. It will be incremented when any commands are
152 actually run. */
153 ocommands_started = commands_started;
155 x = update_file (file, rebuilding_makefiles ? 1 : 0);
156 check_renamed (file);
158 /* Set the goal's 'changed' flag if any commands were started
159 by calling update_file above. We check this flag below to
160 decide when to give an "up to date" diagnostic. */
161 if (commands_started > ocommands_started)
162 g->changed = 1;
164 /* If we updated a file and STATUS was not already 1, set it to
165 1 if updating failed, or to 0 if updating succeeded. Leave
166 STATUS as it is if no updating was done. */
168 stop = 0;
169 if ((x != 0 || file->updated) && status < 1)
171 if (file->update_status != 0)
173 /* Updating failed, or -q triggered. The STATUS value
174 tells our caller which. */
175 status = file->update_status;
176 /* If -q just triggered, stop immediately. It doesn't
177 matter how much more we run, since we already know
178 the answer to return. */
179 stop = (question_flag && !keep_going_flag
180 && !rebuilding_makefiles);
182 else
184 FILE_TIMESTAMP mtime = MTIME (file);
185 check_renamed (file);
187 if (file->updated && g->changed &&
188 mtime != file->mtime_before_update)
190 /* Updating was done. If this is a makefile and
191 just_print_flag or question_flag is set (meaning
192 -n or -q was given and this file was specified
193 as a command-line target), don't change STATUS.
194 If STATUS is changed, we will get re-exec'd, and
195 enter an infinite loop. */
196 if (!rebuilding_makefiles
197 || (!just_print_flag && !question_flag))
198 status = 0;
199 if (rebuilding_makefiles && file->dontcare)
200 /* This is a default makefile; stop remaking. */
201 stop = 1;
206 /* Keep track if any double-colon entry is not finished.
207 When they are all finished, the goal is finished. */
208 any_not_updated |= !file->updated;
210 file->dontcare = 0;
212 if (stop)
213 break;
216 /* Reset FILE since it is null at the end of the loop. */
217 file = g->file;
219 if (stop || !any_not_updated)
221 /* If we have found nothing whatever to do for the goal,
222 print a message saying nothing needs doing. */
224 if (!rebuilding_makefiles
225 /* If the update_status is zero, we updated successfully
226 or not at all. G->changed will have been set above if
227 any commands were actually started for this goal. */
228 && file->update_status == 0 && !g->changed
229 /* Never give a message under -s or -q. */
230 && !silent_flag && !question_flag)
231 message (1, ((file->phony || file->cmds == 0)
232 ? _("Nothing to be done for '%s'.")
233 : _("'%s' is up to date.")),
234 file->name);
236 /* This goal is finished. Remove it from the chain. */
237 if (lastgoal == 0)
238 goals = g->next;
239 else
240 lastgoal->next = g->next;
242 /* Free the storage. */
243 free (g);
245 g = lastgoal == 0 ? goals : lastgoal->next;
247 if (stop)
248 break;
250 else
252 lastgoal = g;
253 g = g->next;
257 /* If we reached the end of the dependency graph toggle the considered
258 flag for the next pass. */
259 if (g == 0)
260 considered = !considered;
263 if (rebuilding_makefiles)
265 touch_flag = t;
266 question_flag = q;
267 just_print_flag = n;
270 return status;
273 /* If FILE is not up to date, execute the commands for it.
274 Return 0 if successful, 1 if unsuccessful;
275 but with some flag settings, just call 'exit' if unsuccessful.
277 DEPTH is the depth in recursions of this function.
278 We increment it during the consideration of our dependencies,
279 then decrement it again after finding out whether this file
280 is out of date.
282 If there are multiple double-colon entries for FILE,
283 each is considered in turn. */
285 static int
286 update_file (struct file *file, unsigned int depth)
288 register int status = 0;
289 register struct file *f;
291 f = file->double_colon ? file->double_colon : file;
293 /* Prune the dependency graph: if we've already been here on _this_
294 pass through the dependency graph, we don't have to go any further.
295 We won't reap_children until we start the next pass, so no state
296 change is possible below here until then. */
297 if (f->considered == considered)
299 /* Check for the case where a target has been tried and failed but
300 the diagnostics hasn't been issued. If we need the diagnostics
301 then we will have to continue. */
302 if (!(f->updated && f->update_status > 0 && !f->dontcare && f->no_diag))
304 DBF (DB_VERBOSE, _("Pruning file '%s'.\n"));
305 return f->command_state == cs_finished ? f->update_status : 0;
309 /* This loop runs until we start commands for a double colon rule, or until
310 the chain is exhausted. */
311 for (; f != 0; f = f->prev)
313 f->considered = considered;
315 status |= update_file_1 (f, depth);
316 check_renamed (f);
318 /* Clean up any alloca() used during the update. */
319 alloca (0);
321 /* If we got an error, don't bother with double_colon etc. */
322 if (status != 0 && !keep_going_flag)
323 return status;
325 if (f->command_state == cs_running
326 || f->command_state == cs_deps_running)
328 /* Don't run the other :: rules for this
329 file until this rule is finished. */
330 status = 0;
331 break;
335 /* Process the remaining rules in the double colon chain so they're marked
336 considered. Start their prerequisites, too. */
337 if (file->double_colon)
338 for (; f != 0 ; f = f->prev)
340 struct dep *d;
342 f->considered = considered;
344 for (d = f->deps; d != 0; d = d->next)
345 status |= update_file (d->file, depth + 1);
348 return status;
351 /* Show a message stating the target failed to build. */
353 static void
354 complain (struct file *file)
356 /* If this file has no_diag set then it means we tried to update it
357 before in the dontcare mode and failed. The target that actually
358 failed is not necessarily this file but could be one of its direct
359 or indirect dependencies. So traverse this file's dependencies and
360 find the one that actually caused the failure. */
362 struct dep *d;
364 for (d = file->deps; d != 0; d = d->next)
366 if (d->file->updated && d->file->update_status > 0 && file->no_diag)
368 complain (d->file);
369 break;
373 if (d == 0)
375 const char *msg_noparent
376 = _("%sNo rule to make target '%s'%s");
377 const char *msg_parent
378 = _("%sNo rule to make target '%s', needed by '%s'%s");
380 /* Didn't find any dependencies to complain about. */
381 if (!keep_going_flag)
383 if (file->parent == 0)
384 fatal (NILF, msg_noparent, "", file->name, "");
386 fatal (NILF, msg_parent, "", file->name, file->parent->name, "");
389 if (file->parent == 0)
390 error (NILF, msg_noparent, "*** ", file->name, ".");
391 else
392 error (NILF, msg_parent, "*** ", file->name, file->parent->name, ".");
394 file->no_diag = 0;
398 /* Consider a single 'struct file' and update it as appropriate. */
400 static int
401 update_file_1 (struct file *file, unsigned int depth)
403 FILE_TIMESTAMP this_mtime;
404 int noexist, must_make, deps_changed;
405 int dep_status = 0;
406 struct file *ofile;
407 struct dep *d, *ad;
408 struct dep amake;
409 int running = 0;
411 DBF (DB_VERBOSE, _("Considering target file '%s'.\n"));
413 if (file->updated)
415 if (file->update_status > 0)
417 DBF (DB_VERBOSE,
418 _("Recently tried and failed to update file '%s'.\n"));
420 /* If the file we tried to make is marked no_diag then no message
421 was printed about it when it failed during the makefile rebuild.
422 If we're trying to build it again in the normal rebuild, print a
423 message now. */
424 if (file->no_diag && !file->dontcare)
425 complain (file);
427 return file->update_status;
430 DBF (DB_VERBOSE, _("File '%s' was considered already.\n"));
431 return 0;
434 switch (file->command_state)
436 case cs_not_started:
437 case cs_deps_running:
438 break;
439 case cs_running:
440 DBF (DB_VERBOSE, _("Still updating file '%s'.\n"));
441 return 0;
442 case cs_finished:
443 DBF (DB_VERBOSE, _("Finished updating file '%s'.\n"));
444 return file->update_status;
445 default:
446 abort ();
449 /* Determine whether the diagnostics will be issued should this update
450 fail. */
451 file->no_diag = file->dontcare;
453 ++depth;
455 /* Notice recursive update of the same file. */
456 start_updating (file);
458 /* We might change file if we find a different one via vpath;
459 remember this one to turn off updating. */
460 ofile = file;
462 /* Looking at the file's modtime beforehand allows the possibility
463 that its name may be changed by a VPATH search, and thus it may
464 not need an implicit rule. If this were not done, the file
465 might get implicit commands that apply to its initial name, only
466 to have that name replaced with another found by VPATH search. */
468 this_mtime = file_mtime (file);
469 check_renamed (file);
470 noexist = this_mtime == NONEXISTENT_MTIME;
471 if (noexist)
472 DBF (DB_BASIC, _("File '%s' does not exist.\n"));
473 else if (ORDINARY_MTIME_MIN <= this_mtime && this_mtime <= ORDINARY_MTIME_MAX
474 && file->low_resolution_time)
476 /* Avoid spurious rebuilds due to low resolution time stamps. */
477 int ns = FILE_TIMESTAMP_NS (this_mtime);
478 if (ns != 0)
479 error (NILF, _("*** Warning: .LOW_RESOLUTION_TIME file '%s' has a high resolution time stamp"),
480 file->name);
481 this_mtime += FILE_TIMESTAMPS_PER_S - 1 - ns;
484 must_make = noexist;
486 /* If file was specified as a target with no commands,
487 come up with some default commands. */
489 if (!file->phony && file->cmds == 0 && !file->tried_implicit)
491 if (try_implicit_rule (file, depth))
492 DBF (DB_IMPLICIT, _("Found an implicit rule for '%s'.\n"));
493 else
494 DBF (DB_IMPLICIT, _("No implicit rule found for '%s'.\n"));
495 file->tried_implicit = 1;
497 if (file->cmds == 0 && !file->is_target
498 && default_file != 0 && default_file->cmds != 0)
500 DBF (DB_IMPLICIT, _("Using default recipe for '%s'.\n"));
501 file->cmds = default_file->cmds;
504 /* Update all non-intermediate files we depend on, if necessary, and see
505 whether any of them is more recent than this file. We need to walk our
506 deps, AND the deps of any also_make targets to ensure everything happens
507 in the correct order. */
509 amake.file = file;
510 amake.next = file->also_make;
511 ad = &amake;
512 while (ad)
514 struct dep *lastd = 0;
516 /* Find the deps we're scanning */
517 d = ad->file->deps;
518 ad = ad->next;
520 while (d)
522 FILE_TIMESTAMP mtime;
523 int maybe_make;
524 int dontcare = 0;
526 check_renamed (d->file);
528 mtime = file_mtime (d->file);
529 check_renamed (d->file);
531 if (is_updating (d->file))
533 error (NILF, _("Circular %s <- %s dependency dropped."),
534 file->name, d->file->name);
535 /* We cannot free D here because our the caller will still have
536 a reference to it when we were called recursively via
537 check_dep below. */
538 if (lastd == 0)
539 file->deps = d->next;
540 else
541 lastd->next = d->next;
542 d = d->next;
543 continue;
546 d->file->parent = file;
547 maybe_make = must_make;
549 /* Inherit dontcare flag from our parent. */
550 if (rebuilding_makefiles)
552 dontcare = d->file->dontcare;
553 d->file->dontcare = file->dontcare;
556 dep_status |= check_dep (d->file, depth, this_mtime, &maybe_make);
558 /* Restore original dontcare flag. */
559 if (rebuilding_makefiles)
560 d->file->dontcare = dontcare;
562 if (! d->ignore_mtime)
563 must_make = maybe_make;
565 check_renamed (d->file);
568 register struct file *f = d->file;
569 if (f->double_colon)
570 f = f->double_colon;
573 running |= (f->command_state == cs_running
574 || f->command_state == cs_deps_running);
575 f = f->prev;
577 while (f != 0);
580 if (dep_status != 0 && !keep_going_flag)
581 break;
583 if (!running)
584 /* The prereq is considered changed if the timestamp has changed while
585 it was built, OR it doesn't exist. */
586 d->changed = ((file_mtime (d->file) != mtime)
587 || (mtime == NONEXISTENT_MTIME));
589 lastd = d;
590 d = d->next;
594 /* Now we know whether this target needs updating.
595 If it does, update all the intermediate files we depend on. */
597 if (must_make || always_make_flag)
599 for (d = file->deps; d != 0; d = d->next)
600 if (d->file->intermediate)
602 int dontcare = 0;
604 FILE_TIMESTAMP mtime = file_mtime (d->file);
605 check_renamed (d->file);
606 d->file->parent = file;
608 /* Inherit dontcare flag from our parent. */
609 if (rebuilding_makefiles)
611 dontcare = d->file->dontcare;
612 d->file->dontcare = file->dontcare;
616 dep_status |= update_file (d->file, depth);
618 /* Restore original dontcare flag. */
619 if (rebuilding_makefiles)
620 d->file->dontcare = dontcare;
622 check_renamed (d->file);
625 register struct file *f = d->file;
626 if (f->double_colon)
627 f = f->double_colon;
630 running |= (f->command_state == cs_running
631 || f->command_state == cs_deps_running);
632 f = f->prev;
634 while (f != 0);
637 if (dep_status != 0 && !keep_going_flag)
638 break;
640 if (!running)
641 d->changed = ((file->phony && file->cmds != 0)
642 || file_mtime (d->file) != mtime);
646 finish_updating (file);
647 finish_updating (ofile);
649 DBF (DB_VERBOSE, _("Finished prerequisites of target file '%s'.\n"));
651 if (running)
653 set_command_state (file, cs_deps_running);
654 --depth;
655 DBF (DB_VERBOSE, _("The prerequisites of '%s' are being made.\n"));
656 return 0;
659 /* If any dependency failed, give up now. */
661 if (dep_status != 0)
663 file->update_status = dep_status;
664 notice_finished_file (file);
666 --depth;
668 DBF (DB_VERBOSE, _("Giving up on target file '%s'.\n"));
670 if (depth == 0 && keep_going_flag
671 && !just_print_flag && !question_flag)
672 error (NILF,
673 _("Target '%s' not remade because of errors."), file->name);
675 return dep_status;
678 if (file->command_state == cs_deps_running)
679 /* The commands for some deps were running on the last iteration, but
680 they have finished now. Reset the command_state to not_started to
681 simplify later bookkeeping. It is important that we do this only
682 when the prior state was cs_deps_running, because that prior state
683 was definitely propagated to FILE's also_make's by set_command_state
684 (called above), but in another state an also_make may have
685 independently changed to finished state, and we would confuse that
686 file's bookkeeping (updated, but not_started is bogus state). */
687 set_command_state (file, cs_not_started);
689 /* Now record which prerequisites are more
690 recent than this file, so we can define $?. */
692 deps_changed = 0;
693 for (d = file->deps; d != 0; d = d->next)
695 FILE_TIMESTAMP d_mtime = file_mtime (d->file);
696 check_renamed (d->file);
698 if (! d->ignore_mtime)
700 #if 1
701 /* %%% In version 4, remove this code completely to
702 implement not remaking deps if their deps are newer
703 than their parents. */
704 if (d_mtime == NONEXISTENT_MTIME && !d->file->intermediate)
705 /* We must remake if this dep does not
706 exist and is not intermediate. */
707 must_make = 1;
708 #endif
710 /* Set DEPS_CHANGED if this dep actually changed. */
711 deps_changed |= d->changed;
714 /* Set D->changed if either this dep actually changed,
715 or its dependent, FILE, is older or does not exist. */
716 d->changed |= noexist || d_mtime > this_mtime;
718 if (!noexist && ISDB (DB_BASIC|DB_VERBOSE))
720 const char *fmt = 0;
722 if (d->ignore_mtime)
724 if (ISDB (DB_VERBOSE))
725 fmt = _("Prerequisite '%s' is order-only for target '%s'.\n");
727 else if (d_mtime == NONEXISTENT_MTIME)
729 if (ISDB (DB_BASIC))
730 fmt = _("Prerequisite '%s' of target '%s' does not exist.\n");
732 else if (d->changed)
734 if (ISDB (DB_BASIC))
735 fmt = _("Prerequisite '%s' is newer than target '%s'.\n");
737 else if (ISDB (DB_VERBOSE))
738 fmt = _("Prerequisite '%s' is older than target '%s'.\n");
740 if (fmt)
742 print_spaces (depth);
743 printf (fmt, dep_name (d), file->name);
744 fflush (stdout);
749 /* Here depth returns to the value it had when we were called. */
750 depth--;
752 if (file->double_colon && file->deps == 0)
754 must_make = 1;
755 DBF (DB_BASIC,
756 _("Target '%s' is double-colon and has no prerequisites.\n"));
758 else if (!noexist && file->is_target && !deps_changed && file->cmds == 0
759 && !always_make_flag)
761 must_make = 0;
762 DBF (DB_VERBOSE,
763 _("No recipe for '%s' and no prerequisites actually changed.\n"));
765 else if (!must_make && file->cmds != 0 && always_make_flag)
767 must_make = 1;
768 DBF (DB_VERBOSE, _("Making '%s' due to always-make flag.\n"));
771 if (!must_make)
773 if (ISDB (DB_VERBOSE))
775 print_spaces (depth);
776 printf (_("No need to remake target '%s'"), file->name);
777 if (!streq (file->name, file->hname))
778 printf (_("; using VPATH name '%s'"), file->hname);
779 puts (".");
780 fflush (stdout);
783 notice_finished_file (file);
785 /* Since we don't need to remake the file, convert it to use the
786 VPATH filename if we found one. hfile will be either the
787 local name if no VPATH or the VPATH name if one was found. */
789 while (file)
791 file->name = file->hname;
792 file = file->prev;
795 return 0;
798 DBF (DB_BASIC, _("Must remake target '%s'.\n"));
800 /* It needs to be remade. If it's VPATH and not reset via GPATH, toss the
801 VPATH. */
802 if (!streq(file->name, file->hname))
804 DB (DB_BASIC, (_(" Ignoring VPATH name '%s'.\n"), file->hname));
805 file->ignore_vpath = 1;
808 /* Now, take appropriate actions to remake the file. */
809 remake_file (file);
811 if (file->command_state != cs_finished)
813 DBF (DB_VERBOSE, _("Recipe of '%s' is being run.\n"));
814 return 0;
817 switch (file->update_status)
819 case 2:
820 DBF (DB_BASIC, _("Failed to remake target file '%s'.\n"));
821 break;
822 case 0:
823 DBF (DB_BASIC, _("Successfully remade target file '%s'.\n"));
824 break;
825 case 1:
826 DBF (DB_BASIC, _("Target file '%s' needs remade under -q.\n"));
827 break;
828 default:
829 assert (file->update_status >= 0 && file->update_status <= 2);
830 break;
833 file->updated = 1;
834 return file->update_status;
837 /* Set FILE's 'updated' flag and re-check its mtime and the mtime's of all
838 files listed in its 'also_make' member. Under -t, this function also
839 touches FILE.
841 On return, FILE->update_status will no longer be -1 if it was. */
843 void
844 notice_finished_file (struct file *file)
846 struct dep *d;
847 int ran = file->command_state == cs_running;
848 int touched = 0;
850 file->command_state = cs_finished;
851 file->updated = 1;
853 if (touch_flag
854 /* The update status will be:
855 -1 if this target was not remade;
856 0 if 0 or more commands (+ or ${MAKE}) were run and won;
857 1 if some commands were run and lost.
858 We touch the target if it has commands which either were not run
859 or won when they ran (i.e. status is 0). */
860 && file->update_status == 0)
862 if (file->cmds != 0 && file->cmds->any_recurse)
864 /* If all the command lines were recursive,
865 we don't want to do the touching. */
866 unsigned int i;
867 for (i = 0; i < file->cmds->ncommand_lines; ++i)
868 if (!(file->cmds->lines_flags[i] & COMMANDS_RECURSE))
869 goto have_nonrecursing;
871 else
873 have_nonrecursing:
874 if (file->phony)
875 file->update_status = 0;
876 /* According to POSIX, -t doesn't affect targets with no cmds. */
877 else if (file->cmds != 0)
879 /* Should set file's modification date and do nothing else. */
880 file->update_status = touch_file (file);
882 /* Pretend we ran a real touch command, to suppress the
883 "'foo' is up to date" message. */
884 commands_started++;
886 /* Request for the timestamp to be updated (and distributed
887 to the double-colon entries). Simply setting ran=1 would
888 almost have done the trick, but messes up with the also_make
889 updating logic below. */
890 touched = 1;
895 if (file->mtime_before_update == UNKNOWN_MTIME)
896 file->mtime_before_update = file->last_mtime;
898 if ((ran && !file->phony) || touched)
900 int i = 0;
902 /* If -n, -t, or -q and all the commands are recursive, we ran them so
903 really check the target's mtime again. Otherwise, assume the target
904 would have been updated. */
906 if ((question_flag || just_print_flag || touch_flag) && file->cmds)
908 for (i = file->cmds->ncommand_lines; i > 0; --i)
909 if (! (file->cmds->lines_flags[i-1] & COMMANDS_RECURSE))
910 break;
913 /* If there were no commands at all, it's always new. */
915 else if (file->is_target && file->cmds == 0)
916 i = 1;
918 file->last_mtime = i == 0 ? UNKNOWN_MTIME : NEW_MTIME;
921 if (file->double_colon)
923 /* If this is a double colon rule and it is the last one to be
924 updated, propagate the change of modification time to all the
925 double-colon entries for this file.
927 We do it on the last update because it is important to handle
928 individual entries as separate rules with separate timestamps
929 while they are treated as targets and then as one rule with the
930 unified timestamp when they are considered as a prerequisite
931 of some target. */
933 struct file *f;
934 FILE_TIMESTAMP max_mtime = file->last_mtime;
936 /* Check that all rules were updated and at the same time find
937 the max timestamp. We assume UNKNOWN_MTIME is newer then
938 any other value. */
939 for (f = file->double_colon; f != 0 && f->updated; f = f->prev)
940 if (max_mtime != UNKNOWN_MTIME
941 && (f->last_mtime == UNKNOWN_MTIME || f->last_mtime > max_mtime))
942 max_mtime = f->last_mtime;
944 if (f == 0)
945 for (f = file->double_colon; f != 0; f = f->prev)
946 f->last_mtime = max_mtime;
949 if (ran && file->update_status != -1)
950 /* We actually tried to update FILE, which has
951 updated its also_make's as well (if it worked).
952 If it didn't work, it wouldn't work again for them.
953 So mark them as updated with the same status. */
954 for (d = file->also_make; d != 0; d = d->next)
956 d->file->command_state = cs_finished;
957 d->file->updated = 1;
958 d->file->update_status = file->update_status;
960 if (ran && !d->file->phony)
961 /* Fetch the new modification time.
962 We do this instead of just invalidating the cached time
963 so that a vpath_search can happen. Otherwise, it would
964 never be done because the target is already updated. */
965 f_mtime (d->file, 0);
967 else if (file->update_status == -1)
968 /* Nothing was done for FILE, but it needed nothing done.
969 So mark it now as "succeeded". */
970 file->update_status = 0;
973 /* Check whether another file (whose mtime is THIS_MTIME) needs updating on
974 account of a dependency which is file FILE. If it does, store 1 in
975 *MUST_MAKE_PTR. In the process, update any non-intermediate files that
976 FILE depends on (including FILE itself). Return nonzero if any updating
977 failed. */
979 static int
980 check_dep (struct file *file, unsigned int depth,
981 FILE_TIMESTAMP this_mtime, int *must_make_ptr)
983 struct file *ofile;
984 struct dep *d;
985 int dep_status = 0;
987 ++depth;
988 start_updating (file);
990 /* We might change file if we find a different one via vpath;
991 remember this one to turn off updating. */
992 ofile = file;
994 if (file->phony || !file->intermediate)
996 /* If this is a non-intermediate file, update it and record whether it
997 is newer than THIS_MTIME. */
998 FILE_TIMESTAMP mtime;
999 dep_status = update_file (file, depth);
1000 check_renamed (file);
1001 mtime = file_mtime (file);
1002 check_renamed (file);
1003 if (mtime == NONEXISTENT_MTIME || mtime > this_mtime)
1004 *must_make_ptr = 1;
1006 else
1008 /* FILE is an intermediate file. */
1009 FILE_TIMESTAMP mtime;
1011 if (!file->phony && file->cmds == 0 && !file->tried_implicit)
1013 if (try_implicit_rule (file, depth))
1014 DBF (DB_IMPLICIT, _("Found an implicit rule for '%s'.\n"));
1015 else
1016 DBF (DB_IMPLICIT, _("No implicit rule found for '%s'.\n"));
1017 file->tried_implicit = 1;
1019 if (file->cmds == 0 && !file->is_target
1020 && default_file != 0 && default_file->cmds != 0)
1022 DBF (DB_IMPLICIT, _("Using default commands for '%s'.\n"));
1023 file->cmds = default_file->cmds;
1026 check_renamed (file);
1027 mtime = file_mtime (file);
1028 check_renamed (file);
1029 if (mtime != NONEXISTENT_MTIME && mtime > this_mtime)
1030 /* If the intermediate file actually exists and is newer, then we
1031 should remake from it. */
1032 *must_make_ptr = 1;
1033 else
1035 /* Otherwise, update all non-intermediate files we depend on, if
1036 necessary, and see whether any of them is more recent than the
1037 file on whose behalf we are checking. */
1038 struct dep *ld;
1039 int deps_running = 0;
1041 /* If this target is not running, set it's state so that we check it
1042 fresh. It could be it was checked as part of an order-only
1043 prerequisite and so wasn't rebuilt then, but should be now. */
1044 if (file->command_state != cs_running)
1045 set_command_state (file, cs_not_started);
1047 ld = 0;
1048 d = file->deps;
1049 while (d != 0)
1051 int maybe_make;
1053 if (is_updating (d->file))
1055 error (NILF, _("Circular %s <- %s dependency dropped."),
1056 file->name, d->file->name);
1057 if (ld == 0)
1059 file->deps = d->next;
1060 free_dep (d);
1061 d = file->deps;
1063 else
1065 ld->next = d->next;
1066 free_dep (d);
1067 d = ld->next;
1069 continue;
1072 d->file->parent = file;
1073 maybe_make = *must_make_ptr;
1074 dep_status |= check_dep (d->file, depth, this_mtime,
1075 &maybe_make);
1076 if (! d->ignore_mtime)
1077 *must_make_ptr = maybe_make;
1078 check_renamed (d->file);
1079 if (dep_status != 0 && !keep_going_flag)
1080 break;
1082 if (d->file->command_state == cs_running
1083 || d->file->command_state == cs_deps_running)
1084 deps_running = 1;
1086 ld = d;
1087 d = d->next;
1090 if (deps_running)
1091 /* Record that some of FILE's deps are still being made.
1092 This tells the upper levels to wait on processing it until the
1093 commands are finished. */
1094 set_command_state (file, cs_deps_running);
1098 finish_updating (file);
1099 finish_updating (ofile);
1101 return dep_status;
1104 /* Touch FILE. Return zero if successful, one if not. */
1106 #define TOUCH_ERROR(call) return (perror_with_name (call, file->name), 1)
1108 static int
1109 touch_file (struct file *file)
1111 if (!silent_flag)
1112 message (0, "touch %s", file->name);
1114 /* Print-only (-n) takes precedence over touch (-t). */
1115 if (just_print_flag)
1116 return 0;
1118 #ifndef NO_ARCHIVES
1119 if (ar_name (file->name))
1120 return ar_touch (file->name);
1121 else
1122 #endif
1124 int fd = open (file->name, O_RDWR | O_CREAT, 0666);
1126 if (fd < 0)
1127 TOUCH_ERROR ("touch: open: ");
1128 else
1130 struct stat statbuf;
1131 char buf = 'x';
1132 int e;
1134 EINTRLOOP (e, fstat (fd, &statbuf));
1135 if (e < 0)
1136 TOUCH_ERROR ("touch: fstat: ");
1137 /* Rewrite character 0 same as it already is. */
1138 if (read (fd, &buf, 1) < 0)
1139 TOUCH_ERROR ("touch: read: ");
1140 if (lseek (fd, 0L, 0) < 0L)
1141 TOUCH_ERROR ("touch: lseek: ");
1142 if (write (fd, &buf, 1) < 0)
1143 TOUCH_ERROR ("touch: write: ");
1144 /* If file length was 0, we just
1145 changed it, so change it back. */
1146 if (statbuf.st_size == 0)
1148 (void) close (fd);
1149 fd = open (file->name, O_RDWR | O_TRUNC, 0666);
1150 if (fd < 0)
1151 TOUCH_ERROR ("touch: open: ");
1153 (void) close (fd);
1157 return 0;
1160 /* Having checked and updated the dependencies of FILE,
1161 do whatever is appropriate to remake FILE itself.
1162 Return the status from executing FILE's commands. */
1164 static void
1165 remake_file (struct file *file)
1167 if (file->cmds == 0)
1169 if (file->phony)
1170 /* Phony target. Pretend it succeeded. */
1171 file->update_status = 0;
1172 else if (file->is_target)
1173 /* This is a nonexistent target file we cannot make.
1174 Pretend it was successfully remade. */
1175 file->update_status = 0;
1176 else
1178 /* This is a dependency file we cannot remake. Fail. */
1179 if (!rebuilding_makefiles || !file->dontcare)
1180 complain (file);
1181 file->update_status = 2;
1184 else
1186 chop_commands (file->cmds);
1188 /* The normal case: start some commands. */
1189 if (!touch_flag || file->cmds->any_recurse)
1191 execute_file_commands (file);
1192 return;
1195 /* This tells notice_finished_file it is ok to touch the file. */
1196 file->update_status = 0;
1199 /* This does the touching under -t. */
1200 notice_finished_file (file);
1203 /* Return the mtime of a file, given a 'struct file'.
1204 Caches the time in the struct file to avoid excess stat calls.
1206 If the file is not found, and SEARCH is nonzero, VPATH searching and
1207 replacement is done. If that fails, a library (-lLIBNAME) is tried and
1208 the library's actual name (/lib/libLIBNAME.a, etc.) is substituted into
1209 FILE. */
1211 FILE_TIMESTAMP
1212 f_mtime (struct file *file, int search)
1214 FILE_TIMESTAMP mtime;
1216 /* File's mtime is not known; must get it from the system. */
1218 #ifndef NO_ARCHIVES
1219 if (ar_name (file->name))
1221 /* This file is an archive-member reference. */
1223 char *arname, *memname;
1224 struct file *arfile;
1225 time_t member_date;
1227 /* Find the archive's name. */
1228 ar_parse_name (file->name, &arname, &memname);
1230 /* Find the modification time of the archive itself.
1231 Also allow for its name to be changed via VPATH search. */
1232 arfile = lookup_file (arname);
1233 if (arfile == 0)
1234 arfile = enter_file (strcache_add (arname));
1235 mtime = f_mtime (arfile, search);
1236 check_renamed (arfile);
1237 if (search && strcmp (arfile->hname, arname))
1239 /* The archive's name has changed.
1240 Change the archive-member reference accordingly. */
1242 char *name;
1243 unsigned int arlen, memlen;
1245 arlen = strlen (arfile->hname);
1246 memlen = strlen (memname);
1248 name = xmalloc (arlen + 1 + memlen + 2);
1249 memcpy (name, arfile->hname, arlen);
1250 name[arlen] = '(';
1251 memcpy (name + arlen + 1, memname, memlen);
1252 name[arlen + 1 + memlen] = ')';
1253 name[arlen + 1 + memlen + 1] = '\0';
1255 /* If the archive was found with GPATH, make the change permanent;
1256 otherwise defer it until later. */
1257 if (arfile->name == arfile->hname)
1258 rename_file (file, name);
1259 else
1260 rehash_file (file, name);
1261 check_renamed (file);
1264 free (arname);
1266 file->low_resolution_time = 1;
1268 if (mtime == NONEXISTENT_MTIME)
1269 /* The archive doesn't exist, so its members don't exist either. */
1270 return NONEXISTENT_MTIME;
1272 member_date = ar_member_date (file->hname);
1273 mtime = (member_date == (time_t) -1
1274 ? NONEXISTENT_MTIME
1275 : file_timestamp_cons (file->hname, member_date, 0));
1277 else
1278 #endif
1280 mtime = name_mtime (file->name);
1282 if (mtime == NONEXISTENT_MTIME && search && !file->ignore_vpath)
1284 /* If name_mtime failed, search VPATH. */
1285 const char *name = vpath_search (file->name, &mtime, NULL, NULL);
1286 if (name
1287 /* Last resort, is it a library (-lxxx)? */
1288 || (file->name[0] == '-' && file->name[1] == 'l'
1289 && (name = library_search (file->name, &mtime)) != 0))
1291 if (mtime != UNKNOWN_MTIME)
1292 /* vpath_search and library_search store UNKNOWN_MTIME
1293 if they didn't need to do a stat call for their work. */
1294 file->last_mtime = mtime;
1296 /* If we found it in VPATH, see if it's in GPATH too; if so,
1297 change the name right now; if not, defer until after the
1298 dependencies are updated. */
1299 if (gpath_search (name, strlen(name) - strlen(file->name) - 1))
1301 rename_file (file, name);
1302 check_renamed (file);
1303 return file_mtime (file);
1306 rehash_file (file, name);
1307 check_renamed (file);
1308 /* If the result of a vpath search is -o or -W, preserve it.
1309 Otherwise, find the mtime of the resulting file. */
1310 if (mtime != OLD_MTIME && mtime != NEW_MTIME)
1311 mtime = name_mtime (name);
1316 /* Files can have bogus timestamps that nothing newly made will be
1317 "newer" than. Updating their dependents could just result in loops.
1318 So notify the user of the anomaly with a warning.
1320 We only need to do this once, for now. */
1322 if (!clock_skew_detected
1323 && mtime != NONEXISTENT_MTIME && mtime != NEW_MTIME
1324 && !file->updated)
1326 static FILE_TIMESTAMP adjusted_now;
1328 FILE_TIMESTAMP adjusted_mtime = mtime;
1330 #if defined(WINDOWS32) || defined(__MSDOS__)
1331 /* Experimentation has shown that FAT filesystems can set file times
1332 up to 3 seconds into the future! Play it safe. */
1334 #define FAT_ADJ_OFFSET (FILE_TIMESTAMP) 3
1336 FILE_TIMESTAMP adjustment = FAT_ADJ_OFFSET << FILE_TIMESTAMP_LO_BITS;
1337 if (ORDINARY_MTIME_MIN + adjustment <= adjusted_mtime)
1338 adjusted_mtime -= adjustment;
1339 #elif defined(__EMX__)
1340 /* FAT filesystems round time to the nearest even second!
1341 Allow for any file (NTFS or FAT) to perhaps suffer from this
1342 brain damage. */
1343 FILE_TIMESTAMP adjustment = (((FILE_TIMESTAMP_S (adjusted_mtime) & 1) == 0
1344 && FILE_TIMESTAMP_NS (adjusted_mtime) == 0)
1345 ? (FILE_TIMESTAMP) 1 << FILE_TIMESTAMP_LO_BITS
1346 : 0);
1347 #endif
1349 /* If the file's time appears to be in the future, update our
1350 concept of the present and try once more. */
1351 if (adjusted_now < adjusted_mtime)
1353 int resolution;
1354 FILE_TIMESTAMP now = file_timestamp_now (&resolution);
1355 adjusted_now = now + (resolution - 1);
1356 if (adjusted_now < adjusted_mtime)
1358 #ifdef NO_FLOAT
1359 error (NILF, _("Warning: File '%s' has modification time in the future"),
1360 file->name);
1361 #else
1362 double from_now =
1363 (FILE_TIMESTAMP_S (mtime) - FILE_TIMESTAMP_S (now)
1364 + ((FILE_TIMESTAMP_NS (mtime) - FILE_TIMESTAMP_NS (now))
1365 / 1e9));
1366 char from_now_string[100];
1368 if (from_now >= 99 && from_now <= ULONG_MAX)
1369 sprintf (from_now_string, "%lu", (unsigned long) from_now);
1370 else
1371 sprintf (from_now_string, "%.2g", from_now);
1372 error (NILF, _("Warning: File '%s' has modification time %s s in the future"),
1373 file->name, from_now_string);
1374 #endif
1375 clock_skew_detected = 1;
1380 /* Store the mtime into all the entries for this file. */
1381 if (file->double_colon)
1382 file = file->double_colon;
1386 /* If this file is not implicit but it is intermediate then it was
1387 made so by the .INTERMEDIATE target. If this file has never
1388 been built by us but was found now, it existed before make
1389 started. So, turn off the intermediate bit so make doesn't
1390 delete it, since it didn't create it. */
1391 if (mtime != NONEXISTENT_MTIME && file->command_state == cs_not_started
1392 && file->command_state == cs_not_started
1393 && !file->tried_implicit && file->intermediate)
1394 file->intermediate = 0;
1396 file->last_mtime = mtime;
1397 file = file->prev;
1399 while (file != 0);
1401 return mtime;
1405 /* Return the mtime of the file or archive-member reference NAME. */
1407 /* First, we check with stat(). If the file does not exist, then we return
1408 NONEXISTENT_MTIME. If it does, and the symlink check flag is set, then
1409 examine each indirection of the symlink and find the newest mtime.
1410 This causes one duplicate stat() when -L is being used, but the code is
1411 much cleaner. */
1413 static FILE_TIMESTAMP
1414 name_mtime (const char *name)
1416 FILE_TIMESTAMP mtime;
1417 struct stat st;
1418 int e;
1420 EINTRLOOP (e, stat (name, &st));
1421 if (e == 0)
1422 mtime = FILE_TIMESTAMP_STAT_MODTIME (name, st);
1423 else if (errno == ENOENT || errno == ENOTDIR)
1424 mtime = NONEXISTENT_MTIME;
1425 else
1427 perror_with_name ("stat: ", name);
1428 return NONEXISTENT_MTIME;
1431 /* If we get here we either found it, or it doesn't exist.
1432 If it doesn't exist see if we can use a symlink mtime instead. */
1434 #ifdef MAKE_SYMLINKS
1435 #ifndef S_ISLNK
1436 # define S_ISLNK(_m) (((_m)&S_IFMT)==S_IFLNK)
1437 #endif
1438 if (check_symlink_flag)
1440 PATH_VAR (lpath);
1442 /* Check each symbolic link segment (if any). Find the latest mtime
1443 amongst all of them (and the target file of course).
1444 Note that we have already successfully dereferenced all the links
1445 above. So, if we run into any error trying to lstat(), or
1446 readlink(), or whatever, something bizarre-o happened. Just give up
1447 and use whatever mtime we've already computed at that point. */
1448 strcpy (lpath, name);
1449 while (1)
1451 FILE_TIMESTAMP ltime;
1452 PATH_VAR (lbuf);
1453 long llen;
1454 char *p;
1456 EINTRLOOP (e, lstat (lpath, &st));
1457 if (e)
1459 /* Just take what we have so far. */
1460 if (errno != ENOENT && errno != ENOTDIR)
1461 perror_with_name ("lstat: ", lpath);
1462 break;
1465 /* If this is not a symlink, we're done (we started with the real
1466 file's mtime so we don't need to test it again). */
1467 if (!S_ISLNK (st.st_mode))
1468 break;
1470 /* If this mtime is newer than what we had, keep the new one. */
1471 ltime = FILE_TIMESTAMP_STAT_MODTIME (lpath, st);
1472 if (ltime > mtime)
1473 mtime = ltime;
1475 /* Set up to check the file pointed to by this link. */
1476 EINTRLOOP (llen, readlink (lpath, lbuf, GET_PATH_MAX));
1477 if (llen < 0)
1479 /* Eh? Just take what we have. */
1480 perror_with_name ("readlink: ", lpath);
1481 break;
1483 lbuf[llen] = '\0';
1485 /* If the target is fully-qualified or the source is just a
1486 filename, then the new path is the target. Otherwise it's the
1487 source directory plus the target. */
1488 if (lbuf[0] == '/' || (p = strrchr (lpath, '/')) == NULL)
1489 strcpy (lpath, lbuf);
1490 else if ((p - lpath) + llen + 2 > GET_PATH_MAX)
1491 /* Eh? Path too long! Again, just go with what we have. */
1492 break;
1493 else
1494 /* Create the next step in the symlink chain. */
1495 strcpy (p+1, lbuf);
1498 #endif
1500 return mtime;
1504 /* Search for a library file specified as -lLIBNAME, searching for a
1505 suitable library file in the system library directories and the VPATH
1506 directories. */
1508 static const char *
1509 library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr)
1511 static char *dirs[] =
1513 #ifndef _AMIGA
1514 "/lib",
1515 "/usr/lib",
1516 #endif
1517 #if defined(WINDOWS32) && !defined(LIBDIR)
1519 * This is completely up to the user at product install time. Just define
1520 * a placeholder.
1522 #define LIBDIR "."
1523 #endif
1524 LIBDIR, /* Defined by configuration. */
1528 const char *file = 0;
1529 char *libpatterns;
1530 FILE_TIMESTAMP mtime;
1532 /* Loop variables for the libpatterns value. */
1533 char *p;
1534 const char *p2;
1535 unsigned int len;
1536 unsigned int liblen;
1538 /* Information about the earliest (in the vpath sequence) match. */
1539 unsigned int best_vpath = 0, best_path = 0;
1541 char **dp;
1543 libpatterns = xstrdup (variable_expand ("$(.LIBPATTERNS)"));
1545 /* Skip the '-l'. */
1546 lib += 2;
1547 liblen = strlen (lib);
1549 /* Loop through all the patterns in .LIBPATTERNS, and search on each one.
1550 To implement the linker-compatible behavior we have to search through
1551 all entries in .LIBPATTERNS and choose the "earliest" one. */
1552 p2 = libpatterns;
1553 while ((p = find_next_token (&p2, &len)) != 0)
1555 static char *buf = NULL;
1556 static unsigned int buflen = 0;
1557 static int libdir_maxlen = -1;
1558 static unsigned int std_dirs = 0;
1559 char *libbuf = variable_expand ("");
1561 /* Expand the pattern using LIB as a replacement. */
1563 char c = p[len];
1564 char *p3, *p4;
1566 p[len] = '\0';
1567 p3 = find_percent (p);
1568 if (!p3)
1570 /* Give a warning if there is no pattern. */
1571 error (NILF, _(".LIBPATTERNS element '%s' is not a pattern"), p);
1572 p[len] = c;
1573 continue;
1575 p4 = variable_buffer_output (libbuf, p, p3-p);
1576 p4 = variable_buffer_output (p4, lib, liblen);
1577 p4 = variable_buffer_output (p4, p3+1, len - (p3-p));
1578 p[len] = c;
1581 /* Look first for 'libNAME.a' in the current directory. */
1582 mtime = name_mtime (libbuf);
1583 if (mtime != NONEXISTENT_MTIME)
1585 if (mtime_ptr != 0)
1586 *mtime_ptr = mtime;
1587 file = strcache_add (libbuf);
1588 /* This by definition will have the best index, so stop now. */
1589 break;
1592 /* Now try VPATH search on that. */
1595 unsigned int vpath_index, path_index;
1596 const char* f = vpath_search (libbuf, mtime_ptr ? &mtime : NULL,
1597 &vpath_index, &path_index);
1598 if (f)
1600 /* If we have a better match, record it. */
1601 if (file == 0 ||
1602 vpath_index < best_vpath ||
1603 (vpath_index == best_vpath && path_index < best_path))
1605 file = f;
1606 best_vpath = vpath_index;
1607 best_path = path_index;
1609 if (mtime_ptr != 0)
1610 *mtime_ptr = mtime;
1615 /* Now try the standard set of directories. */
1617 if (!buflen)
1619 for (dp = dirs; *dp != 0; ++dp)
1621 int l = strlen (*dp);
1622 if (l > libdir_maxlen)
1623 libdir_maxlen = l;
1624 std_dirs++;
1626 buflen = strlen (libbuf);
1627 buf = xmalloc(libdir_maxlen + buflen + 2);
1629 else if (buflen < strlen (libbuf))
1631 buflen = strlen (libbuf);
1632 buf = xrealloc (buf, libdir_maxlen + buflen + 2);
1636 /* Use the last std_dirs index for standard directories. This
1637 was it will always be greater than the VPATH index. */
1638 unsigned int vpath_index = ~((unsigned int)0) - std_dirs;
1640 for (dp = dirs; *dp != 0; ++dp)
1642 sprintf (buf, "%s/%s", *dp, libbuf);
1643 mtime = name_mtime (buf);
1644 if (mtime != NONEXISTENT_MTIME)
1646 if (file == 0 || vpath_index < best_vpath)
1648 file = strcache_add (buf);
1649 best_vpath = vpath_index;
1651 if (mtime_ptr != 0)
1652 *mtime_ptr = mtime;
1656 vpath_index++;
1662 free (libpatterns);
1663 return file;