1 /* Basic dependency engine for GNU Make.
2 Copyright (C) 1988,89,90,91,92,93,94,95,96,97 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. */
46 extern int try_implicit_rule
PARAMS ((struct file
*file
, unsigned int depth
));
49 /* Incremented when a command is started (under -n, when one would be). */
50 unsigned int commands_started
= 0;
52 static int update_file
PARAMS ((struct file
*file
, unsigned int depth
));
53 static int update_file_1
PARAMS ((struct file
*file
, unsigned int depth
));
54 static int check_dep
PARAMS ((struct file
*file
, unsigned int depth
, FILE_TIMESTAMP this_mtime
, int *must_make_ptr
));
55 static int touch_file
PARAMS ((struct file
*file
));
56 static void remake_file
PARAMS ((struct file
*file
));
57 static FILE_TIMESTAMP name_mtime
PARAMS ((char *name
));
58 static int library_search
PARAMS ((char **lib
, FILE_TIMESTAMP
*mtime_ptr
));
61 /* Remake all the goals in the `struct dep' chain GOALS. Return -1 if nothing
62 was done, 0 if all goals were updated successfully, or 1 if a goal failed.
63 If MAKEFILES is nonzero, these goals are makefiles, so -t, -q, and -n should
64 be disabled for them unless they were also command-line targets, and we
65 should only make one goal at a time and return as soon as one goal whose
66 `changed' member is nonzero is successfully made. */
69 update_goal_chain (goals
, makefiles
)
70 register struct dep
*goals
;
73 int t
= touch_flag
, q
= question_flag
, n
= just_print_flag
;
74 unsigned int j
= job_slots
;
77 #define MTIME(file) (makefiles ? file_mtime_no_search (file) \
80 /* Duplicate the chain so we can remove things from it. */
82 goals
= copy_dep_chain (goals
);
85 /* Clear the `changed' flag of each goal in the chain.
86 We will use the flag below to notice when any commands
87 have actually been run for a target. When no commands
88 have been run, we give an "up to date" diagnostic. */
91 for (g
= goals
; g
!= 0; g
= g
->next
)
96 /* Only run one job at a time when building makefiles.
97 No one seems to know why this was done, and no one can think of a good
98 reason to do it. Hopefully an obvious one won't appear as soon as we
99 release the next version :-/. */
104 /* Update all the goals until they are all finished. */
108 register struct dep
*g
, *lastgoal
;
110 /* Start jobs that are waiting for the load to go down. */
112 start_waiting_jobs ();
114 /* Wait for a child to die. */
116 reap_children (1, 0);
122 /* Iterate over all double-colon entries for this file. */
123 struct file
*file
= g
->file
;
124 int stop
= 0, any_not_updated
= 0;
126 for (file
= g
->file
->double_colon
? g
->file
->double_colon
: g
->file
;
130 unsigned int ocommands_started
;
132 FILE_TIMESTAMP mtime
= MTIME (file
);
133 check_renamed (file
);
136 if (file
->cmd_target
)
143 touch_flag
= question_flag
= just_print_flag
= 0;
146 /* Save the old value of `commands_started' so we can compare
147 later. It will be incremented when any commands are
149 ocommands_started
= commands_started
;
151 x
= update_file (file
, makefiles
? 1 : 0);
152 check_renamed (file
);
154 /* Set the goal's `changed' flag if any commands were started
155 by calling update_file above. We check this flag below to
156 decide when to give an "up to date" diagnostic. */
157 g
->changed
+= commands_started
- ocommands_started
;
160 if (x
!= 0 || file
->updated
)
162 /* If STATUS was not already 1, set it to 1 if
163 updating failed, or to 0 if updating succeeded.
164 Leave STATUS as it is if no updating was done. */
168 if (file
->update_status
!= 0)
170 /* Updating failed, or -q triggered.
171 The STATUS value tells our caller which. */
172 status
= file
->update_status
;
173 /* If -q just triggered, stop immediately.
174 It doesn't matter how much more we run,
175 since we already know the answer to return. */
176 stop
= (!keep_going_flag
&& !question_flag
179 else if (MTIME (file
) != mtime
)
181 /* Updating was done. If this is a makefile and
182 just_print_flag or question_flag is set
183 (meaning -n or -q was given and this file was
184 specified as a command-line target), don't
185 change STATUS. If STATUS is changed, we will
186 get re-exec'd, and fall into an infinite loop. */
188 || (!just_print_flag
&& !question_flag
))
190 if (makefiles
&& file
->dontcare
)
191 /* This is a default makefile. Stop remaking. */
197 /* Keep track if any double-colon entry is not finished.
198 When they are all finished, the goal is finished. */
199 any_not_updated
|= !file
->updated
;
205 /* Reset FILE since it is null at the end of the loop. */
208 if (stop
|| !any_not_updated
)
210 /* If we have found nothing whatever to do for the goal,
211 print a message saying nothing needs doing. */
214 /* If the update_status is zero, we updated successfully
215 or not at all. G->changed will have been set above if
216 any commands were actually started for this goal. */
217 && file
->update_status
== 0 && !g
->changed
218 /* Never give a message under -s or -q. */
219 && !silent_flag
&& !question_flag
)
220 message (1, ((file
->phony
|| file
->cmds
== 0)
221 ? "Nothing to be done for `%s'."
222 : "`%s' is up to date."),
225 /* This goal is finished. Remove it from the chain. */
229 lastgoal
->next
= g
->next
;
231 /* Free the storage. */
234 g
= lastgoal
== 0 ? goals
: lastgoal
->next
;
257 /* Generate an error/fatal message if no rules are available for the target.
263 static const char msg_noparent
[]
264 = "%sNo rule to make target `%s'%s";
265 static const char msg_parent
[]
266 = "%sNo rule to make target `%s', needed by `%s'%s";
267 if (keep_going_flag
|| file
->dontcare
)
271 if (file
->parent
== 0)
272 error (NILF
, msg_noparent
, "*** ", file
->name
, ".");
274 error (NILF
, msg_parent
, "*** ",
275 file
->name
, file
->parent
->name
, ".");
276 file
->shownerror
= 1;
278 file
->update_status
= 2;
282 if (file
->parent
== 0)
283 fatal (NILF
, msg_noparent
, "", file
->name
, "");
285 fatal (NILF
, msg_parent
, "", file
->name
, file
->parent
->name
, "");
289 /* If FILE is not up to date, execute the commands for it.
290 Return 0 if successful, 1 if unsuccessful;
291 but with some flag settings, just call `exit' if unsuccessful.
293 DEPTH is the depth in recursions of this function.
294 We increment it during the consideration of our dependencies,
295 then decrement it again after finding out whether this file
298 If there are multiple double-colon entries for FILE,
299 each is considered in turn. */
302 update_file (file
, depth
)
306 register int status
= 0;
307 register struct file
*f
;
309 for (f
= file
->double_colon
? file
->double_colon
: file
; f
!= 0; f
= f
->prev
)
311 status
|= update_file_1 (f
, depth
);
314 if (status
!= 0 && !keep_going_flag
)
317 switch (f
->command_state
)
320 /* The file is done being remade. */
324 case cs_deps_running
:
325 /* Don't run the other :: rules for this
326 file until this rule is finished. */
330 assert (f
->command_state
== cs_running
);
338 /* Consider a single `struct file' and update it as appropriate. */
341 update_file_1 (file
, depth
)
345 register FILE_TIMESTAMP this_mtime
;
346 int noexist
, must_make
, deps_changed
;
348 register struct dep
*d
, *lastd
;
351 DEBUGPR ("Considering target file `%s'.\n");
355 if (file
->update_status
> 0)
357 DEBUGPR ("Recently tried and failed to update file `%s'.\n");
358 if (!file
->shownerror
)
360 int dontcare
= file
->dontcare
;
363 file
->dontcare
= dontcare
;
365 return file
->update_status
;
368 DEBUGPR ("File `%s' was considered already.\n");
372 switch (file
->command_state
)
375 case cs_deps_running
:
378 DEBUGPR ("Still updating file `%s'.\n");
381 DEBUGPR ("Finished updating file `%s'.\n");
382 return file
->update_status
;
389 /* Notice recursive update of the same file. */
392 /* Looking at the file's modtime beforehand allows the possibility
393 that its name may be changed by a VPATH search, and thus it may
394 not need an implicit rule. If this were not done, the file
395 might get implicit commands that apply to its initial name, only
396 to have that name replaced with another found by VPATH search. */
398 this_mtime
= file_mtime (file
);
399 check_renamed (file
);
400 noexist
= this_mtime
== (FILE_TIMESTAMP
) -1;
402 DEBUGPR ("File `%s' does not exist.\n");
406 /* If file was specified as a target with no commands,
407 come up with some default commands. */
409 if (!file
->phony
&& file
->cmds
== 0 && !file
->tried_implicit
)
411 if (try_implicit_rule (file
, depth
))
412 DEBUGPR ("Found an implicit rule for `%s'.\n");
414 DEBUGPR ("No implicit rule found for `%s'.\n");
415 file
->tried_implicit
= 1;
417 if (file
->cmds
== 0 && !file
->is_target
418 && default_file
!= 0 && default_file
->cmds
!= 0)
420 DEBUGPR ("Using default commands for `%s'.\n");
421 file
->cmds
= default_file
->cmds
;
424 /* Update all non-intermediate files we depend on, if necessary,
425 and see whether any of them is more recent than this file. */
431 FILE_TIMESTAMP mtime
;
433 check_renamed (d
->file
);
435 mtime
= file_mtime (d
->file
);
436 check_renamed (d
->file
);
438 if (d
->file
->updating
)
440 error (NILF
, "Circular %s <- %s dependency dropped.",
441 file
->name
, d
->file
->name
);
442 /* We cannot free D here because our the caller will still have
443 a reference to it when we were called recursively via
446 file
->deps
= d
->next
;
448 lastd
->next
= d
->next
;
453 d
->file
->parent
= file
;
454 dep_status
|= check_dep (d
->file
, depth
, this_mtime
, &must_make
);
455 check_renamed (d
->file
);
458 register struct file
*f
= d
->file
;
463 running
|= (f
->command_state
== cs_running
464 || f
->command_state
== cs_deps_running
);
470 if (dep_status
!= 0 && !keep_going_flag
)
474 d
->changed
= file_mtime (d
->file
) != mtime
;
480 /* Now we know whether this target needs updating.
481 If it does, update all the intermediate files we depend on. */
485 for (d
= file
->deps
; d
!= 0; d
= d
->next
)
486 if (d
->file
->intermediate
)
488 FILE_TIMESTAMP mtime
= file_mtime (d
->file
);
489 check_renamed (d
->file
);
490 d
->file
->parent
= file
;
491 dep_status
|= update_file (d
->file
, depth
);
492 check_renamed (d
->file
);
495 register struct file
*f
= d
->file
;
500 running
|= (f
->command_state
== cs_running
501 || f
->command_state
== cs_deps_running
);
507 if (dep_status
!= 0 && !keep_going_flag
)
511 d
->changed
= ((file
->phony
&& file
->cmds
!= 0)
512 || file_mtime (d
->file
) != mtime
);
518 DEBUGPR ("Finished dependencies of target file `%s'.\n");
522 set_command_state (file
, cs_deps_running
);
524 DEBUGPR ("The dependencies of `%s' are being made.\n");
528 /* If any dependency failed, give up now. */
532 file
->update_status
= dep_status
;
533 notice_finished_file (file
);
537 DEBUGPR ("Giving up on target file `%s'.\n");
539 if (depth
== 0 && keep_going_flag
540 && !just_print_flag
&& !question_flag
)
541 error (NILF
, "Target `%s' not remade because of errors.", file
->name
);
546 if (file
->command_state
== cs_deps_running
)
547 /* The commands for some deps were running on the last iteration, but
548 they have finished now. Reset the command_state to not_started to
549 simplify later bookkeeping. It is important that we do this only
550 when the prior state was cs_deps_running, because that prior state
551 was definitely propagated to FILE's also_make's by set_command_state
552 (called above), but in another state an also_make may have
553 independently changed to finished state, and we would confuse that
554 file's bookkeeping (updated, but not_started is bogus state). */
555 set_command_state (file
, cs_not_started
);
557 /* Now record which dependencies are more
558 recent than this file, so we can define $?. */
561 for (d
= file
->deps
; d
!= 0; d
= d
->next
)
563 FILE_TIMESTAMP d_mtime
= file_mtime (d
->file
);
564 check_renamed (d
->file
);
566 #if 1 /* %%% In version 4, remove this code completely to
567 implement not remaking deps if their deps are newer
568 than their parents. */
569 if (d_mtime
== (FILE_TIMESTAMP
) -1 && !d
->file
->intermediate
)
570 /* We must remake if this dep does not
571 exist and is not intermediate. */
575 /* Set DEPS_CHANGED if this dep actually changed. */
576 deps_changed
|= d
->changed
;
578 /* Set D->changed if either this dep actually changed,
579 or its dependent, FILE, is older or does not exist. */
580 d
->changed
|= noexist
|| d_mtime
> this_mtime
;
582 if (debug_flag
&& !noexist
)
584 print_spaces (depth
);
585 if (d_mtime
== (FILE_TIMESTAMP
) -1)
586 printf ("Dependency `%s' does not exist.\n", dep_name (d
));
588 printf ("Dependency `%s' is %s than dependent `%s'.\n",
589 dep_name (d
), d
->changed
? "newer" : "older", file
->name
);
594 /* Here depth returns to the value it had when we were called. */
597 if (file
->double_colon
&& file
->deps
== 0)
600 DEBUGPR ("Target `%s' is double-colon and has no dependencies.\n");
602 else if (!noexist
&& file
->is_target
&& !deps_changed
&& file
->cmds
== 0)
605 DEBUGPR ("No commands for `%s' and no dependencies actually changed.\n");
613 printf("No need to remake target `%s'", file
->name
);
614 if (!streq(file
->name
, file
->hname
))
615 printf("; using VPATH name `%s'", file
->hname
);
620 notice_finished_file (file
);
622 /* Since we don't need to remake the file, convert it to use the
623 VPATH filename if we found one. hfile will be either the
624 local name if no VPATH or the VPATH name if one was found. */
628 file
->name
= file
->hname
;
635 DEBUGPR ("Must remake target `%s'.\n");
637 /* It needs to be remade. If it's VPATH and not reset via GPATH, toss the
639 if (!streq(file
->name
, file
->hname
))
643 print_spaces (depth
);
644 printf(" Ignoring VPATH name `%s'.\n", file
->hname
);
647 file
->ignore_vpath
= 1;
650 /* Now, take appropriate actions to remake the file. */
653 if (file
->command_state
!= cs_finished
)
655 DEBUGPR ("Commands of `%s' are being run.\n");
659 switch (file
->update_status
)
662 DEBUGPR ("Failed to remake target file `%s'.\n");
665 DEBUGPR ("Successfully remade target file `%s'.\n");
668 DEBUGPR ("Target file `%s' needs remade under -q.\n");
671 assert (file
->update_status
>= 0 && file
->update_status
<= 2);
676 return file
->update_status
;
679 /* Set FILE's `updated' flag and re-check its mtime and the mtime's of all
680 files listed in its `also_make' member. Under -t, this function also
683 On return, FILE->update_status will no longer be -1 if it was. */
686 notice_finished_file (file
)
687 register struct file
*file
;
690 int ran
= file
->command_state
== cs_running
;
692 file
->command_state
= cs_finished
;
696 /* The update status will be:
697 -1 if this target was not remade;
698 0 if 0 or more commands (+ or ${MAKE}) were run and won;
699 1 if some commands were run and lost.
700 We touch the target if it has commands which either were not run
701 or won when they ran (i.e. status is 0). */
702 && file
->update_status
== 0)
704 if (file
->cmds
!= 0 && file
->cmds
->any_recurse
)
706 /* If all the command lines were recursive,
707 we don't want to do the touching. */
709 for (i
= 0; i
< file
->cmds
->ncommand_lines
; ++i
)
710 if (!(file
->cmds
->lines_flags
[i
] & COMMANDS_RECURSE
))
711 goto have_nonrecursing
;
717 file
->update_status
= 0;
719 /* Should set file's modification date and do nothing else. */
720 file
->update_status
= touch_file (file
);
724 if (ran
&& !file
->phony
)
728 if (just_print_flag
|| question_flag
729 || (file
->is_target
&& file
->cmds
== 0))
730 file
->last_mtime
= NEW_MTIME
;
732 file
->last_mtime
= 0;
734 /* Propagate the change of modification time to all the double-colon
735 entries for this file. */
736 for (f
= file
->double_colon
; f
!= 0; f
= f
->next
)
737 f
->last_mtime
= file
->last_mtime
;
740 if (ran
&& file
->update_status
!= -1)
741 /* We actually tried to update FILE, which has
742 updated its also_make's as well (if it worked).
743 If it didn't work, it wouldn't work again for them.
744 So mark them as updated with the same status. */
745 for (d
= file
->also_make
; d
!= 0; d
= d
->next
)
747 d
->file
->command_state
= cs_finished
;
748 d
->file
->updated
= 1;
749 d
->file
->update_status
= file
->update_status
;
751 if (ran
&& !d
->file
->phony
)
752 /* Fetch the new modification time.
753 We do this instead of just invalidating the cached time
754 so that a vpath_search can happen. Otherwise, it would
755 never be done because the target is already updated. */
756 (void) f_mtime (d
->file
, 0);
758 else if (file
->update_status
== -1)
759 /* Nothing was done for FILE, but it needed nothing done.
760 So mark it now as "succeeded". */
761 file
->update_status
= 0;
764 /* Check whether another file (whose mtime is THIS_MTIME)
765 needs updating on account of a dependency which is file FILE.
766 If it does, store 1 in *MUST_MAKE_PTR.
767 In the process, update any non-intermediate files
768 that FILE depends on (including FILE itself).
769 Return nonzero if any updating failed. */
772 check_dep (file
, depth
, this_mtime
, must_make_ptr
)
775 FILE_TIMESTAMP this_mtime
;
778 register struct dep
*d
;
784 if (!file
->intermediate
)
785 /* If this is a non-intermediate file, update it and record
786 whether it is newer than THIS_MTIME. */
788 FILE_TIMESTAMP mtime
;
789 dep_status
= update_file (file
, depth
);
790 check_renamed (file
);
791 mtime
= file_mtime (file
);
792 check_renamed (file
);
793 if (mtime
== (FILE_TIMESTAMP
) -1 || mtime
> this_mtime
)
798 /* FILE is an intermediate file. */
799 FILE_TIMESTAMP mtime
;
801 if (!file
->phony
&& file
->cmds
== 0 && !file
->tried_implicit
)
803 if (try_implicit_rule (file
, depth
))
804 DEBUGPR ("Found an implicit rule for `%s'.\n");
806 DEBUGPR ("No implicit rule found for `%s'.\n");
807 file
->tried_implicit
= 1;
809 if (file
->cmds
== 0 && !file
->is_target
810 && default_file
!= 0 && default_file
->cmds
!= 0)
812 DEBUGPR ("Using default commands for `%s'.\n");
813 file
->cmds
= default_file
->cmds
;
816 /* If the intermediate file actually exists
817 and is newer, then we should remake from it. */
818 check_renamed (file
);
819 mtime
= file_mtime (file
);
820 check_renamed (file
);
821 if (mtime
!= (FILE_TIMESTAMP
) -1 && mtime
> this_mtime
)
823 /* Otherwise, update all non-intermediate files we depend on,
824 if necessary, and see whether any of them is more
825 recent than the file on whose behalf we are checking. */
828 register struct dep
*lastd
;
834 if (d
->file
->updating
)
836 error (NILF
, "Circular %s <- %s dependency dropped.",
837 file
->name
, d
->file
->name
);
840 file
->deps
= d
->next
;
846 lastd
->next
= d
->next
;
853 d
->file
->parent
= file
;
854 dep_status
|= check_dep (d
->file
, depth
, this_mtime
, must_make_ptr
);
855 check_renamed (d
->file
);
856 if (dep_status
!= 0 && !keep_going_flag
)
859 if (d
->file
->command_state
== cs_running
860 || d
->file
->command_state
== cs_deps_running
)
861 /* Record that some of FILE's deps are still being made.
862 This tells the upper levels to wait on processing it until
863 the commands are finished. */
864 set_command_state (file
, cs_deps_running
);
876 /* Touch FILE. Return zero if successful, one if not. */
878 #define TOUCH_ERROR(call) return (perror_with_name (call, file->name), 1)
882 register struct file
*file
;
885 message (0, "touch %s", file
->name
);
888 if (ar_name (file
->name
))
889 return ar_touch (file
->name
);
893 int fd
= open (file
->name
, O_RDWR
| O_CREAT
, 0666);
896 TOUCH_ERROR ("touch: open: ");
906 status
= fstat (fd
, &statbuf
);
908 while (status
< 0 && errno
== EINTR
);
911 TOUCH_ERROR ("touch: fstat: ");
912 /* Rewrite character 0 same as it already is. */
913 if (read (fd
, &buf
, 1) < 0)
914 TOUCH_ERROR ("touch: read: ");
915 if (lseek (fd
, 0L, 0) < 0L)
916 TOUCH_ERROR ("touch: lseek: ");
917 if (write (fd
, &buf
, 1) < 0)
918 TOUCH_ERROR ("touch: write: ");
919 /* If file length was 0, we just
920 changed it, so change it back. */
921 if (statbuf
.st_size
== 0)
924 fd
= open (file
->name
, O_RDWR
| O_TRUNC
, 0666);
926 TOUCH_ERROR ("touch: open: ");
935 /* Having checked and updated the dependencies of FILE,
936 do whatever is appropriate to remake FILE itself.
937 Return the status from executing FILE's commands. */
946 /* Phony target. Pretend it succeeded. */
947 file
->update_status
= 0;
948 else if (file
->is_target
)
949 /* This is a nonexistent target file we cannot make.
950 Pretend it was successfully remade. */
951 file
->update_status
= 0;
957 chop_commands (file
->cmds
);
959 if (!touch_flag
|| file
->cmds
->any_recurse
)
961 execute_file_commands (file
);
965 /* This tells notice_finished_file it is ok to touch the file. */
966 file
->update_status
= 0;
969 /* This does the touching under -t. */
970 notice_finished_file (file
);
973 /* Return the mtime of a file, given a `struct file'.
974 Caches the time in the struct file to avoid excess stat calls.
976 If the file is not found, and SEARCH is nonzero, VPATH searching and
977 replacement is done. If that fails, a library (-lLIBNAME) is tried and
978 the library's actual name (/lib/libLIBNAME.a, etc.) is substituted into
982 f_mtime (file
, search
)
983 register struct file
*file
;
986 FILE_TIMESTAMP mtime
;
988 /* File's mtime is not known; must get it from the system. */
991 if (ar_name (file
->name
))
993 /* This file is an archive-member reference. */
995 char *arname
, *memname
;
999 /* Find the archive's name. */
1000 ar_parse_name (file
->name
, &arname
, &memname
);
1002 /* Find the modification time of the archive itself.
1003 Also allow for its name to be changed via VPATH search. */
1004 arfile
= lookup_file (arname
);
1007 arfile
= enter_file (arname
);
1010 mtime
= f_mtime (arfile
, search
);
1011 check_renamed (arfile
);
1012 if (search
&& strcmp (arfile
->hname
, arname
))
1014 /* The archive's name has changed.
1015 Change the archive-member reference accordingly. */
1018 unsigned int arlen
, memlen
;
1026 arname
= arfile
->hname
;
1027 arlen
= strlen (arname
);
1028 memlen
= strlen (memname
);
1030 /* free (file->name); */
1032 name
= (char *) xmalloc (arlen
+ 1 + memlen
+ 2);
1033 bcopy (arname
, name
, arlen
);
1035 bcopy (memname
, name
+ arlen
+ 1, memlen
);
1036 name
[arlen
+ 1 + memlen
] = ')';
1037 name
[arlen
+ 1 + memlen
+ 1] = '\0';
1039 /* If the archive was found with GPATH, make the change permanent;
1040 otherwise defer it until later. */
1041 if (arfile
->name
== arfile
->hname
)
1042 rename_file (file
, name
);
1044 rehash_file (file
, name
);
1045 check_renamed (file
);
1052 if (mtime
== (FILE_TIMESTAMP
) -1)
1053 /* The archive doesn't exist, so it's members don't exist either. */
1054 return (FILE_TIMESTAMP
) -1;
1056 mtime
= ar_member_date (file
->hname
);
1061 mtime
= name_mtime (file
->name
);
1063 if (mtime
== (FILE_TIMESTAMP
) -1 && search
&& !file
->ignore_vpath
)
1065 /* If name_mtime failed, search VPATH. */
1066 char *name
= file
->name
;
1067 if (vpath_search (&name
, &mtime
)
1068 /* Last resort, is it a library (-lxxx)? */
1069 || (name
[0] == '-' && name
[1] == 'l'
1070 && library_search (&name
, &mtime
)))
1073 /* vpath_search and library_search store zero in MTIME
1074 if they didn't need to do a stat call for their work. */
1075 file
->last_mtime
= mtime
;
1077 /* If we found it in VPATH, see if it's in GPATH too; if so,
1078 change the name right now; if not, defer until after the
1079 dependencies are updated. */
1080 if (gpath_search (name
, strlen(name
) - strlen(file
->name
) - 1))
1082 rename_file (file
, name
);
1083 check_renamed (file
);
1084 return file_mtime (file
);
1087 rehash_file (file
, name
);
1088 check_renamed (file
);
1089 mtime
= name_mtime (name
);
1095 /* Files can have bogus timestamps that nothing newly made will be
1096 "newer" than. Updating their dependents could just result in loops.
1097 So notify the user of the anomaly with a warning.
1099 We only need to do this once, for now. */
1101 static FILE_TIMESTAMP now
= 0;
1102 if (!clock_skew_detected
1103 && mtime
!= (FILE_TIMESTAMP
)-1 && mtime
> now
1106 /* This file's time appears to be in the future.
1107 Update our concept of the present, and compare again. */
1109 now
= file_timestamp_now ();
1113 * FAT filesystems round time to nearest even second(!). Just
1114 * allow for any file (NTFS or FAT) to perhaps suffer from this
1117 if (mtime
> now
&& (((mtime
% 2) == 0) && ((mtime
-1) > now
)))
1120 /* Scrupulous testing indicates that some Windows
1121 filesystems can set file times up to 3 sec into the future! */
1122 if (mtime
> now
+ 3)
1128 char mtimebuf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
1129 char nowbuf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
1131 file_timestamp_sprintf (mtimebuf
, mtime
);
1132 file_timestamp_sprintf (nowbuf
, now
);
1133 error (NILF
, "*** Warning: File `%s' has modification time in the future (%s > %s)",
1134 file
->name
, mtimebuf
, nowbuf
);
1135 clock_skew_detected
= 1;
1140 /* Store the mtime into all the entries for this file. */
1141 if (file
->double_colon
)
1142 file
= file
->double_colon
;
1146 /* If this file is not implicit but it is intermediate then it was
1147 made so by the .INTERMEDIATE target. If this file has never
1148 been built by us but was found now, it existed before make
1149 started. So, turn off the intermediate bit so make doesn't
1150 delete it, since it didn't create it. */
1151 if (mtime
!= (FILE_TIMESTAMP
)-1 && file
->command_state
== cs_not_started
1152 && !file
->tried_implicit
&& file
->intermediate
)
1153 file
->intermediate
= 0;
1155 file
->last_mtime
= mtime
;
1164 /* Return the mtime of the file or archive-member reference NAME. */
1166 static FILE_TIMESTAMP
1168 register char *name
;
1172 if (stat (name
, &st
) < 0)
1173 return (FILE_TIMESTAMP
) -1;
1175 return FILE_TIMESTAMP_STAT_MODTIME (st
);
1179 /* Search for a library file specified as -lLIBNAME, searching for a
1180 suitable library file in the system library directories and the VPATH
1184 library_search (lib
, mtime_ptr
)
1186 FILE_TIMESTAMP
*mtime_ptr
;
1188 static char *dirs
[] =
1194 #if defined(WINDOWS32) && !defined(LIBDIR)
1196 * This is completely up to the user at product install time. Just define
1201 LIBDIR
, /* Defined by configuration. */
1205 static char *libpatterns
= NULL
;
1207 char *libname
= &(*lib
)[2]; /* Name without the `-l'. */
1208 FILE_TIMESTAMP mtime
;
1210 /* Loop variables for the libpatterns value. */
1216 /* If we don't have libpatterns, get it. */
1219 int save
= warn_undefined_variables_flag
;
1220 warn_undefined_variables_flag
= 0;
1222 libpatterns
= xstrdup (variable_expand ("$(strip $(.LIBPATTERNS))"));
1224 warn_undefined_variables_flag
= save
;
1227 /* Loop through all the patterns in .LIBPATTERNS, and search on each one. */
1229 while ((p
= find_next_token (&p2
, &len
)) != 0)
1231 static char *buf
= NULL
;
1232 static int buflen
= 0;
1233 static int libdir_maxlen
= -1;
1234 char *libbuf
= variable_expand ("");
1236 /* Expand the pattern using LIBNAME as a replacement. */
1242 p3
= find_percent (p
);
1245 /* Give a warning if there is no pattern, then remove the
1246 pattern so it's ignored next time. */
1247 error (NILF
, ".LIBPATTERNS element `%s' is not a pattern", p
);
1248 for (; len
; --len
, ++p
)
1253 p4
= variable_buffer_output (libbuf
, p
, p3
-p
);
1254 p4
= variable_buffer_output (p4
, libname
, strlen (libname
));
1255 p4
= variable_buffer_output (p4
, p3
+1, len
- (p3
-p
));
1259 /* Look first for `libNAME.a' in the current directory. */
1260 mtime
= name_mtime (libbuf
);
1261 if (mtime
!= (FILE_TIMESTAMP
) -1)
1263 *lib
= xstrdup (libbuf
);
1269 /* Now try VPATH search on that. */
1272 if (vpath_search (&file
, mtime_ptr
))
1278 /* Now try the standard set of directories. */
1282 for (dp
= dirs
; *dp
!= 0; ++dp
)
1284 int l
= strlen (*dp
);
1285 if (l
> libdir_maxlen
)
1288 buflen
= strlen (libbuf
);
1289 buf
= xmalloc(libdir_maxlen
+ buflen
+ 2);
1291 else if (buflen
< strlen (libbuf
))
1293 buflen
= strlen (libbuf
);
1294 buf
= xrealloc (buf
, libdir_maxlen
+ buflen
+ 2);
1297 for (dp
= dirs
; *dp
!= 0; ++dp
)
1299 sprintf (buf
, "%s/%s", *dp
, libbuf
);
1300 mtime
= name_mtime (buf
);
1301 if (mtime
!= (FILE_TIMESTAMP
) -1)
1303 *lib
= xstrdup (buf
);