1 /* Basic dependency engine for GNU Make.
2 Copyright (C) 1988,89,90,91,92,93,94,95,96,97,99 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
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 GNU Make is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNU Make; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
42 extern int try_implicit_rule
PARAMS ((struct file
*file
, unsigned int depth
));
45 /* Incremented when a command is started (under -n, when one would be). */
46 unsigned int commands_started
= 0;
48 static int update_file
PARAMS ((struct file
*file
, unsigned int depth
));
49 static int update_file_1
PARAMS ((struct file
*file
, unsigned int depth
));
50 static int check_dep
PARAMS ((struct file
*file
, unsigned int depth
, FILE_TIMESTAMP this_mtime
, int *must_make_ptr
));
51 static int touch_file
PARAMS ((struct file
*file
));
52 static void remake_file
PARAMS ((struct file
*file
));
53 static FILE_TIMESTAMP name_mtime
PARAMS ((char *name
));
54 static int library_search
PARAMS ((char **lib
, FILE_TIMESTAMP
*mtime_ptr
));
57 /* Remake all the goals in the `struct dep' chain GOALS. Return -1 if nothing
58 was done, 0 if all goals were updated successfully, or 1 if a goal failed.
59 If MAKEFILES is nonzero, these goals are makefiles, so -t, -q, and -n should
60 be disabled for them unless they were also command-line targets, and we
61 should only make one goal at a time and return as soon as one goal whose
62 `changed' member is nonzero is successfully made. */
64 /* We need to know this "lower down" for correct error handling. */
65 static int updating_makefiles
= 0;
68 update_goal_chain (goals
, makefiles
)
69 register struct dep
*goals
;
72 int t
= touch_flag
, q
= question_flag
, n
= just_print_flag
;
73 unsigned int j
= job_slots
;
76 updating_makefiles
= makefiles
;
78 #define MTIME(file) (makefiles ? file_mtime_no_search (file) \
81 /* Duplicate the chain so we can remove things from it. */
83 goals
= copy_dep_chain (goals
);
86 /* Clear the `changed' flag of each goal in the chain.
87 We will use the flag below to notice when any commands
88 have actually been run for a target. When no commands
89 have been run, we give an "up to date" diagnostic. */
92 for (g
= goals
; g
!= 0; g
= g
->next
)
97 /* Only run one job at a time when building makefiles.
98 No one seems to know why this was done, and no one can think of a good
99 reason to do it. Hopefully an obvious one won't appear as soon as we
100 release the next version :-/. */
105 /* All files start with the considered bit 0, so the global value is 1. */
108 /* Update all the goals until they are all finished. */
112 register struct dep
*g
, *lastgoal
;
114 /* Start jobs that are waiting for the load to go down. */
116 start_waiting_jobs ();
118 /* Wait for a child to die. */
120 reap_children (1, 0);
126 /* Iterate over all double-colon entries for this file. */
128 int stop
= 0, any_not_updated
= 0;
130 for (file
= g
->file
->double_colon
? g
->file
->double_colon
: g
->file
;
134 unsigned int ocommands_started
;
136 check_renamed (file
);
139 if (file
->cmd_target
)
146 touch_flag
= question_flag
= just_print_flag
= 0;
149 /* Save the old value of `commands_started' so we can compare
150 later. It will be incremented when any commands are
152 ocommands_started
= commands_started
;
154 x
= update_file (file
, makefiles
? 1 : 0);
155 check_renamed (file
);
157 /* Set the goal's `changed' flag if any commands were started
158 by calling update_file above. We check this flag below to
159 decide when to give an "up to date" diagnostic. */
160 g
->changed
+= commands_started
- ocommands_started
;
162 /* If we updated a file and STATUS was not already 1, set it to
163 1 if updating failed, or to 0 if updating succeeded. Leave
164 STATUS as it is if no updating was done. */
167 if ((x
!= 0 || file
->updated
) && status
< 1)
169 if (file
->update_status
!= 0)
171 /* Updating failed, or -q triggered. The STATUS value
172 tells our caller which. */
173 status
= file
->update_status
;
174 /* If -q just triggered, stop immediately. It doesn't
175 matter how much more we run, since we already know
176 the answer to return. */
177 stop
= (!keep_going_flag
&& !question_flag
182 FILE_TIMESTAMP mtime
= MTIME (file
);
183 check_renamed (file
);
185 if (file
->updated
&& g
->changed
&&
186 mtime
!= file
->mtime_before_update
)
188 /* Updating was done. If this is a makefile and
189 just_print_flag or question_flag is set (meaning
190 -n or -q was given and this file was specified
191 as a command-line target), don't change STATUS.
192 If STATUS is changed, we will get re-exec'd, and
193 enter an infinite loop. */
195 || (!just_print_flag
&& !question_flag
))
197 if (makefiles
&& file
->dontcare
)
198 /* This is a default makefile; stop remaking. */
204 /* Keep track if any double-colon entry is not finished.
205 When they are all finished, the goal is finished. */
206 any_not_updated
|= !file
->updated
;
212 /* Reset FILE since it is null at the end of the loop. */
215 if (stop
|| !any_not_updated
)
217 /* If we have found nothing whatever to do for the goal,
218 print a message saying nothing needs doing. */
221 /* If the update_status is zero, we updated successfully
222 or not at all. G->changed will have been set above if
223 any commands were actually started for this goal. */
224 && file
->update_status
== 0 && !g
->changed
225 /* Never give a message under -s or -q. */
226 && !silent_flag
&& !question_flag
)
227 message (1, ((file
->phony
|| file
->cmds
== 0)
228 ? _("Nothing to be done for `%s'.")
229 : _("`%s' is up to date.")),
232 /* This goal is finished. Remove it from the chain. */
236 lastgoal
->next
= g
->next
;
238 /* Free the storage. */
241 g
= lastgoal
== 0 ? goals
: lastgoal
->next
;
253 /* If we reached the end of the dependency graph toggle the considered
254 flag for the next pass. */
256 considered
= !considered
;
269 /* Generate an error/fatal message if no rules are available for the target.
275 static const char msg_noparent
[]
276 = _("%sNo rule to make target `%s'%s");
277 static const char msg_parent
[]
278 = _("%sNo rule to make target `%s', needed by `%s'%s");
280 if (keep_going_flag
|| file
->dontcare
)
282 /* If the previous attempt was made while we were creating
283 makefiles, but we aren't anymore, print an error now. */
285 || (file
->mfile_status
&& !updating_makefiles
))
287 if (file
->parent
== 0)
288 error (NILF
, msg_noparent
, "*** ", file
->name
, ".");
290 error (NILF
, msg_parent
, "*** ",
291 file
->name
, file
->parent
->name
, ".");
293 file
->update_status
= 2;
294 file
->mfile_status
= updating_makefiles
;
296 else if (file
->parent
== 0)
297 fatal (NILF
, msg_noparent
, "", file
->name
, "");
299 fatal (NILF
, msg_parent
, "", file
->name
, file
->parent
->name
, "");
302 /* If FILE is not up to date, execute the commands for it.
303 Return 0 if successful, 1 if unsuccessful;
304 but with some flag settings, just call `exit' if unsuccessful.
306 DEPTH is the depth in recursions of this function.
307 We increment it during the consideration of our dependencies,
308 then decrement it again after finding out whether this file
311 If there are multiple double-colon entries for FILE,
312 each is considered in turn. */
315 update_file (file
, depth
)
319 register int status
= 0;
320 register struct file
*f
;
322 for (f
= file
->double_colon
? file
->double_colon
: file
; f
!= 0; f
= f
->prev
)
324 /* Prune the dependency graph: if we've already been here on _this_
325 pass through the dependency graph, we don't have to go any further.
326 We won't reap_children until we start the next pass, so no state
327 change is possible below here until then. */
328 if (f
->considered
== considered
)
330 DEBUGPR (_("Pruning file `%s'.\n"));
333 f
->considered
= considered
;
335 status
|= update_file_1 (f
, depth
);
338 if (status
!= 0 && !keep_going_flag
)
341 switch (f
->command_state
)
344 /* The file is done being remade. */
348 case cs_deps_running
:
349 /* Don't run the other :: rules for this
350 file until this rule is finished. */
354 assert (f
->command_state
== cs_running
);
362 /* Consider a single `struct file' and update it as appropriate. */
365 update_file_1 (file
, depth
)
369 register FILE_TIMESTAMP this_mtime
;
370 int noexist
, must_make
, deps_changed
;
372 register struct dep
*d
, *lastd
;
375 DEBUGPR (_("Considering target file `%s'.\n"));
379 if (file
->update_status
> 0)
381 DEBUGPR (_("Recently tried and failed to update file `%s'.\n"));
383 return file
->update_status
;
386 DEBUGPR (_("File `%s' was considered already.\n"));
390 switch (file
->command_state
)
393 case cs_deps_running
:
396 DEBUGPR (_("Still updating file `%s'.\n"));
399 DEBUGPR (_("Finished updating file `%s'.\n"));
400 return file
->update_status
;
407 /* Notice recursive update of the same file. */
410 /* Looking at the file's modtime beforehand allows the possibility
411 that its name may be changed by a VPATH search, and thus it may
412 not need an implicit rule. If this were not done, the file
413 might get implicit commands that apply to its initial name, only
414 to have that name replaced with another found by VPATH search. */
416 this_mtime
= file_mtime (file
);
417 check_renamed (file
);
418 noexist
= this_mtime
== (FILE_TIMESTAMP
) -1;
420 DEBUGPR (_("File `%s' does not exist.\n"));
424 /* If file was specified as a target with no commands,
425 come up with some default commands. */
427 if (!file
->phony
&& file
->cmds
== 0 && !file
->tried_implicit
)
429 if (try_implicit_rule (file
, depth
))
430 DEBUGPR (_("Found an implicit rule for `%s'.\n"));
432 DEBUGPR (_("No implicit rule found for `%s'.\n"));
433 file
->tried_implicit
= 1;
435 if (file
->cmds
== 0 && !file
->is_target
436 && default_file
!= 0 && default_file
->cmds
!= 0)
438 DEBUGPR (_("Using default commands for `%s'.\n"));
439 file
->cmds
= default_file
->cmds
;
442 /* Update all non-intermediate files we depend on, if necessary,
443 and see whether any of them is more recent than this file. */
449 FILE_TIMESTAMP mtime
;
451 check_renamed (d
->file
);
453 mtime
= file_mtime (d
->file
);
454 check_renamed (d
->file
);
456 if (d
->file
->updating
)
458 error (NILF
, _("Circular %s <- %s dependency dropped."),
459 file
->name
, d
->file
->name
);
460 /* We cannot free D here because our the caller will still have
461 a reference to it when we were called recursively via
464 file
->deps
= d
->next
;
466 lastd
->next
= d
->next
;
471 d
->file
->parent
= file
;
472 dep_status
|= check_dep (d
->file
, depth
, this_mtime
, &must_make
);
473 check_renamed (d
->file
);
476 register struct file
*f
= d
->file
;
481 running
|= (f
->command_state
== cs_running
482 || f
->command_state
== cs_deps_running
);
488 if (dep_status
!= 0 && !keep_going_flag
)
492 d
->changed
= file_mtime (d
->file
) != mtime
;
498 /* Now we know whether this target needs updating.
499 If it does, update all the intermediate files we depend on. */
503 for (d
= file
->deps
; d
!= 0; d
= d
->next
)
504 if (d
->file
->intermediate
)
506 FILE_TIMESTAMP mtime
= file_mtime (d
->file
);
507 check_renamed (d
->file
);
508 d
->file
->parent
= file
;
509 dep_status
|= update_file (d
->file
, depth
);
510 check_renamed (d
->file
);
513 register struct file
*f
= d
->file
;
518 running
|= (f
->command_state
== cs_running
519 || f
->command_state
== cs_deps_running
);
525 if (dep_status
!= 0 && !keep_going_flag
)
529 d
->changed
= ((file
->phony
&& file
->cmds
!= 0)
530 || file_mtime (d
->file
) != mtime
);
536 DEBUGPR (_("Finished prerequisites of target file `%s'.\n"));
540 set_command_state (file
, cs_deps_running
);
542 DEBUGPR (_("The prerequisites of `%s' are being made.\n"));
546 /* If any dependency failed, give up now. */
550 file
->update_status
= dep_status
;
551 notice_finished_file (file
);
555 DEBUGPR (_("Giving up on target file `%s'.\n"));
557 if (depth
== 0 && keep_going_flag
558 && !just_print_flag
&& !question_flag
)
560 _("Target `%s' not remade because of errors."), file
->name
);
565 if (file
->command_state
== cs_deps_running
)
566 /* The commands for some deps were running on the last iteration, but
567 they have finished now. Reset the command_state to not_started to
568 simplify later bookkeeping. It is important that we do this only
569 when the prior state was cs_deps_running, because that prior state
570 was definitely propagated to FILE's also_make's by set_command_state
571 (called above), but in another state an also_make may have
572 independently changed to finished state, and we would confuse that
573 file's bookkeeping (updated, but not_started is bogus state). */
574 set_command_state (file
, cs_not_started
);
576 /* Now record which dependencies are more
577 recent than this file, so we can define $?. */
580 for (d
= file
->deps
; d
!= 0; d
= d
->next
)
582 FILE_TIMESTAMP d_mtime
= file_mtime (d
->file
);
583 check_renamed (d
->file
);
585 #if 1 /* %%% In version 4, remove this code completely to
586 implement not remaking deps if their deps are newer
587 than their parents. */
588 if (d_mtime
== (FILE_TIMESTAMP
) -1 && !d
->file
->intermediate
)
589 /* We must remake if this dep does not
590 exist and is not intermediate. */
594 /* Set DEPS_CHANGED if this dep actually changed. */
595 deps_changed
|= d
->changed
;
597 /* Set D->changed if either this dep actually changed,
598 or its dependent, FILE, is older or does not exist. */
599 d
->changed
|= noexist
|| d_mtime
> this_mtime
;
601 if (debug_flag
&& !noexist
)
603 print_spaces (depth
);
604 if (d_mtime
== (FILE_TIMESTAMP
) -1)
605 printf (_("Prerequisite `%s' does not exist.\n"), dep_name (d
));
607 printf (_("Prerequisite `%s' is %s than target `%s'.\n"),
608 dep_name (d
), d
->changed
? _("newer") : _("older"), file
->name
);
613 /* Here depth returns to the value it had when we were called. */
616 if (file
->double_colon
&& file
->deps
== 0)
619 DEBUGPR (_("Target `%s' is double-colon and has no prerequisites.\n"));
621 else if (!noexist
&& file
->is_target
&& !deps_changed
&& file
->cmds
== 0)
624 DEBUGPR (_("No commands for `%s' and no prerequisites actually changed.\n"));
632 printf(_("No need to remake target `%s'"), file
->name
);
633 if (!streq(file
->name
, file
->hname
))
634 printf(_("; using VPATH name `%s'"), file
->hname
);
639 notice_finished_file (file
);
641 /* Since we don't need to remake the file, convert it to use the
642 VPATH filename if we found one. hfile will be either the
643 local name if no VPATH or the VPATH name if one was found. */
647 file
->name
= file
->hname
;
654 DEBUGPR (_("Must remake target `%s'.\n"));
656 /* It needs to be remade. If it's VPATH and not reset via GPATH, toss the
658 if (!streq(file
->name
, file
->hname
))
662 print_spaces (depth
);
663 printf(_(" Ignoring VPATH name `%s'.\n"), file
->hname
);
666 file
->ignore_vpath
= 1;
669 /* Now, take appropriate actions to remake the file. */
672 if (file
->command_state
!= cs_finished
)
674 DEBUGPR (_("Commands of `%s' are being run.\n"));
678 switch (file
->update_status
)
681 DEBUGPR (_("Failed to remake target file `%s'.\n"));
684 DEBUGPR (_("Successfully remade target file `%s'.\n"));
687 DEBUGPR (_("Target file `%s' needs remade under -q.\n"));
690 assert (file
->update_status
>= 0 && file
->update_status
<= 2);
695 return file
->update_status
;
698 /* Set FILE's `updated' flag and re-check its mtime and the mtime's of all
699 files listed in its `also_make' member. Under -t, this function also
702 On return, FILE->update_status will no longer be -1 if it was. */
705 notice_finished_file (file
)
706 register struct file
*file
;
709 int ran
= file
->command_state
== cs_running
;
711 file
->command_state
= cs_finished
;
715 /* The update status will be:
716 -1 if this target was not remade;
717 0 if 0 or more commands (+ or ${MAKE}) were run and won;
718 1 if some commands were run and lost.
719 We touch the target if it has commands which either were not run
720 or won when they ran (i.e. status is 0). */
721 && file
->update_status
== 0)
723 if (file
->cmds
!= 0 && file
->cmds
->any_recurse
)
725 /* If all the command lines were recursive,
726 we don't want to do the touching. */
728 for (i
= 0; i
< file
->cmds
->ncommand_lines
; ++i
)
729 if (!(file
->cmds
->lines_flags
[i
] & COMMANDS_RECURSE
))
730 goto have_nonrecursing
;
736 file
->update_status
= 0;
738 /* Should set file's modification date and do nothing else. */
739 file
->update_status
= touch_file (file
);
743 if (file
->mtime_before_update
== 0)
744 file
->mtime_before_update
= file
->last_mtime
;
746 if (ran
&& !file
->phony
)
750 if (just_print_flag
|| question_flag
751 || (file
->is_target
&& file
->cmds
== 0))
752 file
->last_mtime
= NEW_MTIME
;
754 file
->last_mtime
= 0;
756 /* Propagate the change of modification time to all the double-colon
757 entries for this file. */
758 for (f
= file
->double_colon
; f
!= 0; f
= f
->next
)
759 f
->last_mtime
= file
->last_mtime
;
762 if (ran
&& file
->update_status
!= -1)
763 /* We actually tried to update FILE, which has
764 updated its also_make's as well (if it worked).
765 If it didn't work, it wouldn't work again for them.
766 So mark them as updated with the same status. */
767 for (d
= file
->also_make
; d
!= 0; d
= d
->next
)
769 d
->file
->command_state
= cs_finished
;
770 d
->file
->updated
= 1;
771 d
->file
->update_status
= file
->update_status
;
773 if (ran
&& !d
->file
->phony
)
774 /* Fetch the new modification time.
775 We do this instead of just invalidating the cached time
776 so that a vpath_search can happen. Otherwise, it would
777 never be done because the target is already updated. */
778 (void) f_mtime (d
->file
, 0);
780 else if (file
->update_status
== -1)
781 /* Nothing was done for FILE, but it needed nothing done.
782 So mark it now as "succeeded". */
783 file
->update_status
= 0;
786 /* Check whether another file (whose mtime is THIS_MTIME)
787 needs updating on account of a dependency which is file FILE.
788 If it does, store 1 in *MUST_MAKE_PTR.
789 In the process, update any non-intermediate files
790 that FILE depends on (including FILE itself).
791 Return nonzero if any updating failed. */
794 check_dep (file
, depth
, this_mtime
, must_make_ptr
)
797 FILE_TIMESTAMP this_mtime
;
800 register struct dep
*d
;
806 if (!file
->intermediate
)
807 /* If this is a non-intermediate file, update it and record
808 whether it is newer than THIS_MTIME. */
810 FILE_TIMESTAMP mtime
;
811 dep_status
= update_file (file
, depth
);
812 check_renamed (file
);
813 mtime
= file_mtime (file
);
814 check_renamed (file
);
815 if (mtime
== (FILE_TIMESTAMP
) -1 || mtime
> this_mtime
)
820 /* FILE is an intermediate file. */
821 FILE_TIMESTAMP mtime
;
823 if (!file
->phony
&& file
->cmds
== 0 && !file
->tried_implicit
)
825 if (try_implicit_rule (file
, depth
))
826 DEBUGPR (_("Found an implicit rule for `%s'.\n"));
828 DEBUGPR (_("No implicit rule found for `%s'.\n"));
829 file
->tried_implicit
= 1;
831 if (file
->cmds
== 0 && !file
->is_target
832 && default_file
!= 0 && default_file
->cmds
!= 0)
834 DEBUGPR (_("Using default commands for `%s'.\n"));
835 file
->cmds
= default_file
->cmds
;
838 /* If the intermediate file actually exists
839 and is newer, then we should remake from it. */
840 check_renamed (file
);
841 mtime
= file_mtime (file
);
842 check_renamed (file
);
843 if (mtime
!= (FILE_TIMESTAMP
) -1 && mtime
> this_mtime
)
845 /* Otherwise, update all non-intermediate files we depend on,
846 if necessary, and see whether any of them is more
847 recent than the file on whose behalf we are checking. */
850 register struct dep
*lastd
;
856 if (d
->file
->updating
)
858 error (NILF
, _("Circular %s <- %s dependency dropped."),
859 file
->name
, d
->file
->name
);
862 file
->deps
= d
->next
;
868 lastd
->next
= d
->next
;
875 d
->file
->parent
= file
;
876 dep_status
|= check_dep (d
->file
, depth
, this_mtime
,
878 check_renamed (d
->file
);
879 if (dep_status
!= 0 && !keep_going_flag
)
882 if (d
->file
->command_state
== cs_running
883 || d
->file
->command_state
== cs_deps_running
)
884 /* Record that some of FILE's deps are still being made.
885 This tells the upper levels to wait on processing it until
886 the commands are finished. */
887 set_command_state (file
, cs_deps_running
);
899 /* Touch FILE. Return zero if successful, one if not. */
901 #define TOUCH_ERROR(call) return (perror_with_name (call, file->name), 1)
905 register struct file
*file
;
908 message (0, "touch %s", file
->name
);
911 if (ar_name (file
->name
))
912 return ar_touch (file
->name
);
916 int fd
= open (file
->name
, O_RDWR
| O_CREAT
, 0666);
919 TOUCH_ERROR ("touch: open: ");
927 status
= fstat (fd
, &statbuf
);
928 while (status
< 0 && EINTR_SET
);
931 TOUCH_ERROR ("touch: fstat: ");
932 /* Rewrite character 0 same as it already is. */
933 if (read (fd
, &buf
, 1) < 0)
934 TOUCH_ERROR ("touch: read: ");
935 if (lseek (fd
, 0L, 0) < 0L)
936 TOUCH_ERROR ("touch: lseek: ");
937 if (write (fd
, &buf
, 1) < 0)
938 TOUCH_ERROR ("touch: write: ");
939 /* If file length was 0, we just
940 changed it, so change it back. */
941 if (statbuf
.st_size
== 0)
944 fd
= open (file
->name
, O_RDWR
| O_TRUNC
, 0666);
946 TOUCH_ERROR ("touch: open: ");
955 /* Having checked and updated the dependencies of FILE,
956 do whatever is appropriate to remake FILE itself.
957 Return the status from executing FILE's commands. */
966 /* Phony target. Pretend it succeeded. */
967 file
->update_status
= 0;
968 else if (file
->is_target
)
969 /* This is a nonexistent target file we cannot make.
970 Pretend it was successfully remade. */
971 file
->update_status
= 0;
977 chop_commands (file
->cmds
);
979 if (!touch_flag
|| file
->cmds
->any_recurse
)
981 execute_file_commands (file
);
985 /* This tells notice_finished_file it is ok to touch the file. */
986 file
->update_status
= 0;
989 /* This does the touching under -t. */
990 notice_finished_file (file
);
993 /* Return the mtime of a file, given a `struct file'.
994 Caches the time in the struct file to avoid excess stat calls.
996 If the file is not found, and SEARCH is nonzero, VPATH searching and
997 replacement is done. If that fails, a library (-lLIBNAME) is tried and
998 the library's actual name (/lib/libLIBNAME.a, etc.) is substituted into
1002 f_mtime (file
, search
)
1003 register struct file
*file
;
1006 FILE_TIMESTAMP mtime
;
1008 /* File's mtime is not known; must get it from the system. */
1011 if (ar_name (file
->name
))
1013 /* This file is an archive-member reference. */
1015 char *arname
, *memname
;
1016 struct file
*arfile
;
1017 int arname_used
= 0;
1019 /* Find the archive's name. */
1020 ar_parse_name (file
->name
, &arname
, &memname
);
1022 /* Find the modification time of the archive itself.
1023 Also allow for its name to be changed via VPATH search. */
1024 arfile
= lookup_file (arname
);
1027 arfile
= enter_file (arname
);
1030 mtime
= f_mtime (arfile
, search
);
1031 check_renamed (arfile
);
1032 if (search
&& strcmp (arfile
->hname
, arname
))
1034 /* The archive's name has changed.
1035 Change the archive-member reference accordingly. */
1038 unsigned int arlen
, memlen
;
1046 arname
= arfile
->hname
;
1047 arlen
= strlen (arname
);
1048 memlen
= strlen (memname
);
1050 /* free (file->name); */
1052 name
= (char *) xmalloc (arlen
+ 1 + memlen
+ 2);
1053 bcopy (arname
, name
, arlen
);
1055 bcopy (memname
, name
+ arlen
+ 1, memlen
);
1056 name
[arlen
+ 1 + memlen
] = ')';
1057 name
[arlen
+ 1 + memlen
+ 1] = '\0';
1059 /* If the archive was found with GPATH, make the change permanent;
1060 otherwise defer it until later. */
1061 if (arfile
->name
== arfile
->hname
)
1062 rename_file (file
, name
);
1064 rehash_file (file
, name
);
1065 check_renamed (file
);
1072 if (mtime
== (FILE_TIMESTAMP
) -1)
1073 /* The archive doesn't exist, so it's members don't exist either. */
1074 return (FILE_TIMESTAMP
) -1;
1076 mtime
= ar_member_date (file
->hname
);
1081 mtime
= name_mtime (file
->name
);
1083 if (mtime
== (FILE_TIMESTAMP
) -1 && search
&& !file
->ignore_vpath
)
1085 /* If name_mtime failed, search VPATH. */
1086 char *name
= file
->name
;
1087 if (vpath_search (&name
, &mtime
)
1088 /* Last resort, is it a library (-lxxx)? */
1089 || (name
[0] == '-' && name
[1] == 'l'
1090 && library_search (&name
, &mtime
)))
1093 /* vpath_search and library_search store zero in MTIME
1094 if they didn't need to do a stat call for their work. */
1095 file
->last_mtime
= mtime
;
1097 /* If we found it in VPATH, see if it's in GPATH too; if so,
1098 change the name right now; if not, defer until after the
1099 dependencies are updated. */
1100 if (gpath_search (name
, strlen(name
) - strlen(file
->name
) - 1))
1102 rename_file (file
, name
);
1103 check_renamed (file
);
1104 return file_mtime (file
);
1107 rehash_file (file
, name
);
1108 check_renamed (file
);
1109 mtime
= name_mtime (name
);
1115 /* Files can have bogus timestamps that nothing newly made will be
1116 "newer" than. Updating their dependents could just result in loops.
1117 So notify the user of the anomaly with a warning.
1119 We only need to do this once, for now. */
1121 static FILE_TIMESTAMP now
= 0;
1122 if (!clock_skew_detected
1123 && mtime
!= (FILE_TIMESTAMP
)-1 && mtime
> now
1126 /* This file's time appears to be in the future.
1127 Update our concept of the present, and compare again. */
1129 now
= file_timestamp_now ();
1133 * FAT filesystems round time to nearest even second(!). Just
1134 * allow for any file (NTFS or FAT) to perhaps suffer from this
1137 if (mtime
> now
&& (((mtime
% 2) == 0) && ((mtime
-1) > now
)))
1140 /* Scrupulous testing indicates that some Windows
1141 filesystems can set file times up to 3 sec into the future! */
1142 if (mtime
> now
+ 3)
1148 char mtimebuf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
1149 char nowbuf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
1151 file_timestamp_sprintf (mtimebuf
, mtime
);
1152 file_timestamp_sprintf (nowbuf
, now
);
1153 error (NILF
, _("*** Warning: File `%s' has modification time in the future (%s > %s)"),
1154 file
->name
, mtimebuf
, nowbuf
);
1155 clock_skew_detected
= 1;
1160 /* Store the mtime into all the entries for this file. */
1161 if (file
->double_colon
)
1162 file
= file
->double_colon
;
1166 /* If this file is not implicit but it is intermediate then it was
1167 made so by the .INTERMEDIATE target. If this file has never
1168 been built by us but was found now, it existed before make
1169 started. So, turn off the intermediate bit so make doesn't
1170 delete it, since it didn't create it. */
1171 if (mtime
!= (FILE_TIMESTAMP
)-1 && file
->command_state
== cs_not_started
1172 && !file
->tried_implicit
&& file
->intermediate
)
1173 file
->intermediate
= 0;
1175 file
->last_mtime
= mtime
;
1184 /* Return the mtime of the file or archive-member reference NAME. */
1186 static FILE_TIMESTAMP
1188 register char *name
;
1192 if (stat (name
, &st
) < 0)
1193 return (FILE_TIMESTAMP
) -1;
1195 return FILE_TIMESTAMP_STAT_MODTIME (st
);
1199 /* Search for a library file specified as -lLIBNAME, searching for a
1200 suitable library file in the system library directories and the VPATH
1204 library_search (lib
, mtime_ptr
)
1206 FILE_TIMESTAMP
*mtime_ptr
;
1208 static char *dirs
[] =
1214 #if defined(WINDOWS32) && !defined(LIBDIR)
1216 * This is completely up to the user at product install time. Just define
1221 LIBDIR
, /* Defined by configuration. */
1225 static char *libpatterns
= NULL
;
1227 char *libname
= &(*lib
)[2]; /* Name without the `-l'. */
1228 FILE_TIMESTAMP mtime
;
1230 /* Loop variables for the libpatterns value. */
1236 /* If we don't have libpatterns, get it. */
1239 int save
= warn_undefined_variables_flag
;
1240 warn_undefined_variables_flag
= 0;
1242 libpatterns
= xstrdup (variable_expand ("$(strip $(.LIBPATTERNS))"));
1244 warn_undefined_variables_flag
= save
;
1247 /* Loop through all the patterns in .LIBPATTERNS, and search on each one. */
1249 while ((p
= find_next_token (&p2
, &len
)) != 0)
1251 static char *buf
= NULL
;
1252 static int buflen
= 0;
1253 static int libdir_maxlen
= -1;
1254 char *libbuf
= variable_expand ("");
1256 /* Expand the pattern using LIBNAME as a replacement. */
1262 p3
= find_percent (p
);
1265 /* Give a warning if there is no pattern, then remove the
1266 pattern so it's ignored next time. */
1267 error (NILF
, _(".LIBPATTERNS element `%s' is not a pattern"), p
);
1268 for (; len
; --len
, ++p
)
1273 p4
= variable_buffer_output (libbuf
, p
, p3
-p
);
1274 p4
= variable_buffer_output (p4
, libname
, strlen (libname
));
1275 p4
= variable_buffer_output (p4
, p3
+1, len
- (p3
-p
));
1279 /* Look first for `libNAME.a' in the current directory. */
1280 mtime
= name_mtime (libbuf
);
1281 if (mtime
!= (FILE_TIMESTAMP
) -1)
1283 *lib
= xstrdup (libbuf
);
1289 /* Now try VPATH search on that. */
1292 if (vpath_search (&file
, mtime_ptr
))
1298 /* Now try the standard set of directories. */
1302 for (dp
= dirs
; *dp
!= 0; ++dp
)
1304 int l
= strlen (*dp
);
1305 if (l
> libdir_maxlen
)
1308 buflen
= strlen (libbuf
);
1309 buf
= xmalloc(libdir_maxlen
+ buflen
+ 2);
1311 else if (buflen
< strlen (libbuf
))
1313 buflen
= strlen (libbuf
);
1314 buf
= xrealloc (buf
, libdir_maxlen
+ buflen
+ 2);
1317 for (dp
= dirs
; *dp
!= 0; ++dp
)
1319 sprintf (buf
, "%s/%s", *dp
, libbuf
);
1320 mtime
= name_mtime (buf
);
1321 if (mtime
!= (FILE_TIMESTAMP
) -1)
1323 *lib
= xstrdup (buf
);