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, 675 Mass Ave, Cambridge, MA 02139, USA. */
43 extern int try_implicit_rule
PARAMS ((struct file
*file
, unsigned int depth
));
46 /* Incremented when a command is started (under -n, when one would be). */
47 unsigned int commands_started
= 0;
49 static int update_file
PARAMS ((struct file
*file
, unsigned int depth
));
50 static int update_file_1
PARAMS ((struct file
*file
, unsigned int depth
));
51 static int check_dep
PARAMS ((struct file
*file
, unsigned int depth
, FILE_TIMESTAMP this_mtime
, int *must_make_ptr
));
52 static int touch_file
PARAMS ((struct file
*file
));
53 static void remake_file
PARAMS ((struct file
*file
));
54 static FILE_TIMESTAMP name_mtime
PARAMS ((char *name
));
55 static int library_search
PARAMS ((char **lib
, FILE_TIMESTAMP
*mtime_ptr
));
58 /* Remake all the goals in the `struct dep' chain GOALS. Return -1 if nothing
59 was done, 0 if all goals were updated successfully, or 1 if a goal failed.
60 If MAKEFILES is nonzero, these goals are makefiles, so -t, -q, and -n should
61 be disabled for them unless they were also command-line targets, and we
62 should only make one goal at a time and return as soon as one goal whose
63 `changed' member is nonzero is successfully made. */
66 update_goal_chain (goals
, makefiles
)
67 register struct dep
*goals
;
70 int t
= touch_flag
, q
= question_flag
, n
= just_print_flag
;
71 unsigned int j
= job_slots
;
74 #define MTIME(file) (makefiles ? file_mtime_no_search (file) \
77 /* Duplicate the chain so we can remove things from it. */
79 goals
= copy_dep_chain (goals
);
82 /* Clear the `changed' flag of each goal in the chain.
83 We will use the flag below to notice when any commands
84 have actually been run for a target. When no commands
85 have been run, we give an "up to date" diagnostic. */
88 for (g
= goals
; g
!= 0; g
= g
->next
)
93 /* Only run one job at a time when building makefiles.
94 No one seems to know why this was done, and no one can think of a good
95 reason to do it. Hopefully an obvious one won't appear as soon as we
96 release the next version :-/. */
101 /* Update all the goals until they are all finished. */
105 register struct dep
*g
, *lastgoal
;
107 /* Start jobs that are waiting for the load to go down. */
109 start_waiting_jobs ();
111 /* Wait for a child to die. */
113 reap_children (1, 0);
119 /* Iterate over all double-colon entries for this file. */
120 struct file
*file
= g
->file
;
121 int stop
= 0, any_not_updated
= 0;
123 for (file
= g
->file
->double_colon
? g
->file
->double_colon
: g
->file
;
127 unsigned int ocommands_started
;
129 FILE_TIMESTAMP mtime
= MTIME (file
);
130 check_renamed (file
);
133 if (file
->cmd_target
)
140 touch_flag
= question_flag
= just_print_flag
= 0;
143 /* Save the old value of `commands_started' so we can compare
144 later. It will be incremented when any commands are
146 ocommands_started
= commands_started
;
148 x
= update_file (file
, makefiles
? 1 : 0);
149 check_renamed (file
);
151 /* Set the goal's `changed' flag if any commands were started
152 by calling update_file above. We check this flag below to
153 decide when to give an "up to date" diagnostic. */
154 g
->changed
+= commands_started
- ocommands_started
;
157 if (x
!= 0 || file
->updated
)
159 /* If STATUS was not already 1, set it to 1 if
160 updating failed, or to 0 if updating succeeded.
161 Leave STATUS as it is if no updating was done. */
165 if (file
->update_status
!= 0)
167 /* Updating failed, or -q triggered.
168 The STATUS value tells our caller which. */
169 status
= file
->update_status
;
170 /* If -q just triggered, stop immediately.
171 It doesn't matter how much more we run,
172 since we already know the answer to return. */
173 stop
= (!keep_going_flag
&& !question_flag
176 else if (MTIME (file
) != mtime
)
178 /* Updating was done. If this is a makefile and
179 just_print_flag or question_flag is set
180 (meaning -n or -q was given and this file was
181 specified as a command-line target), don't
182 change STATUS. If STATUS is changed, we will
183 get re-exec'd, and fall into an infinite loop. */
185 || (!just_print_flag
&& !question_flag
))
187 if (makefiles
&& file
->dontcare
)
188 /* This is a default makefile. Stop remaking. */
194 /* Keep track if any double-colon entry is not finished.
195 When they are all finished, the goal is finished. */
196 any_not_updated
|= !file
->updated
;
202 /* Reset FILE since it is null at the end of the loop. */
205 if (stop
|| !any_not_updated
)
207 /* If we have found nothing whatever to do for the goal,
208 print a message saying nothing needs doing. */
211 /* If the update_status is zero, we updated successfully
212 or not at all. G->changed will have been set above if
213 any commands were actually started for this goal. */
214 && file
->update_status
== 0 && !g
->changed
215 /* Never give a message under -s or -q. */
216 && !silent_flag
&& !question_flag
)
217 message (1, ((file
->phony
|| file
->cmds
== 0)
218 ? "Nothing to be done for `%s'."
219 : "`%s' is up to date."),
222 /* This goal is finished. Remove it from the chain. */
226 lastgoal
->next
= g
->next
;
228 /* Free the storage. */
231 g
= lastgoal
== 0 ? goals
: lastgoal
->next
;
254 /* Generate an error/fatal message if no rules are available for the target.
260 static const char msg_noparent
[]
261 = "%sNo rule to make target `%s'%s";
262 static const char msg_parent
[]
263 = "%sNo rule to make target `%s', needed by `%s'%s";
264 if (keep_going_flag
|| file
->dontcare
)
268 if (file
->parent
== 0)
269 error (NILF
, msg_noparent
, "*** ", file
->name
, ".");
271 error (NILF
, msg_parent
, "*** ",
272 file
->name
, file
->parent
->name
, ".");
273 file
->shownerror
= 1;
275 file
->update_status
= 2;
279 if (file
->parent
== 0)
280 fatal (NILF
, msg_noparent
, "", file
->name
, "");
282 fatal (NILF
, msg_parent
, "", file
->name
, file
->parent
->name
, "");
286 /* If FILE is not up to date, execute the commands for it.
287 Return 0 if successful, 1 if unsuccessful;
288 but with some flag settings, just call `exit' if unsuccessful.
290 DEPTH is the depth in recursions of this function.
291 We increment it during the consideration of our dependencies,
292 then decrement it again after finding out whether this file
295 If there are multiple double-colon entries for FILE,
296 each is considered in turn. */
299 update_file (file
, depth
)
303 register int status
= 0;
304 register struct file
*f
;
306 for (f
= file
->double_colon
? file
->double_colon
: file
; f
!= 0; f
= f
->prev
)
308 status
|= update_file_1 (f
, depth
);
311 if (status
!= 0 && !keep_going_flag
)
314 switch (f
->command_state
)
317 /* The file is done being remade. */
321 case cs_deps_running
:
322 /* Don't run the other :: rules for this
323 file until this rule is finished. */
327 assert (f
->command_state
== cs_running
);
335 /* Consider a single `struct file' and update it as appropriate. */
338 update_file_1 (file
, depth
)
342 register FILE_TIMESTAMP this_mtime
;
343 int noexist
, must_make
, deps_changed
;
345 register struct dep
*d
, *lastd
;
348 DEBUGPR ("Considering target file `%s'.\n");
352 if (file
->update_status
> 0)
354 DEBUGPR ("Recently tried and failed to update file `%s'.\n");
355 if (!file
->shownerror
)
357 int dontcare
= file
->dontcare
;
360 file
->dontcare
= dontcare
;
362 return file
->update_status
;
365 DEBUGPR ("File `%s' was considered already.\n");
369 switch (file
->command_state
)
372 case cs_deps_running
:
375 DEBUGPR ("Still updating file `%s'.\n");
378 DEBUGPR ("Finished updating file `%s'.\n");
379 return file
->update_status
;
386 /* Notice recursive update of the same file. */
389 /* Looking at the file's modtime beforehand allows the possibility
390 that its name may be changed by a VPATH search, and thus it may
391 not need an implicit rule. If this were not done, the file
392 might get implicit commands that apply to its initial name, only
393 to have that name replaced with another found by VPATH search. */
395 this_mtime
= file_mtime (file
);
396 check_renamed (file
);
397 noexist
= this_mtime
== (FILE_TIMESTAMP
) -1;
399 DEBUGPR ("File `%s' does not exist.\n");
403 /* If file was specified as a target with no commands,
404 come up with some default commands. */
406 if (!file
->phony
&& file
->cmds
== 0 && !file
->tried_implicit
)
408 if (try_implicit_rule (file
, depth
))
409 DEBUGPR ("Found an implicit rule for `%s'.\n");
411 DEBUGPR ("No implicit rule found for `%s'.\n");
412 file
->tried_implicit
= 1;
414 if (file
->cmds
== 0 && !file
->is_target
415 && default_file
!= 0 && default_file
->cmds
!= 0)
417 DEBUGPR ("Using default commands for `%s'.\n");
418 file
->cmds
= default_file
->cmds
;
421 /* Update all non-intermediate files we depend on, if necessary,
422 and see whether any of them is more recent than this file. */
428 FILE_TIMESTAMP mtime
;
430 check_renamed (d
->file
);
432 mtime
= file_mtime (d
->file
);
433 check_renamed (d
->file
);
435 if (d
->file
->updating
)
437 error (NILF
, "Circular %s <- %s dependency dropped.",
438 file
->name
, d
->file
->name
);
439 /* We cannot free D here because our the caller will still have
440 a reference to it when we were called recursively via
443 file
->deps
= d
->next
;
445 lastd
->next
= d
->next
;
450 d
->file
->parent
= file
;
451 dep_status
|= check_dep (d
->file
, depth
, this_mtime
, &must_make
);
452 check_renamed (d
->file
);
455 register struct file
*f
= d
->file
;
460 running
|= (f
->command_state
== cs_running
461 || f
->command_state
== cs_deps_running
);
467 if (dep_status
!= 0 && !keep_going_flag
)
471 d
->changed
= file_mtime (d
->file
) != mtime
;
477 /* Now we know whether this target needs updating.
478 If it does, update all the intermediate files we depend on. */
482 for (d
= file
->deps
; d
!= 0; d
= d
->next
)
483 if (d
->file
->intermediate
)
485 FILE_TIMESTAMP mtime
= file_mtime (d
->file
);
486 check_renamed (d
->file
);
487 d
->file
->parent
= file
;
488 dep_status
|= update_file (d
->file
, depth
);
489 check_renamed (d
->file
);
492 register struct file
*f
= d
->file
;
497 running
|= (f
->command_state
== cs_running
498 || f
->command_state
== cs_deps_running
);
504 if (dep_status
!= 0 && !keep_going_flag
)
508 d
->changed
= ((file
->phony
&& file
->cmds
!= 0)
509 || file_mtime (d
->file
) != mtime
);
515 DEBUGPR ("Finished dependencies of target file `%s'.\n");
519 set_command_state (file
, cs_deps_running
);
521 DEBUGPR ("The dependencies of `%s' are being made.\n");
525 /* If any dependency failed, give up now. */
529 file
->update_status
= dep_status
;
530 notice_finished_file (file
);
534 DEBUGPR ("Giving up on target file `%s'.\n");
536 if (depth
== 0 && keep_going_flag
537 && !just_print_flag
&& !question_flag
)
538 error (NILF
, "Target `%s' not remade because of errors.", file
->name
);
543 if (file
->command_state
== cs_deps_running
)
544 /* The commands for some deps were running on the last iteration, but
545 they have finished now. Reset the command_state to not_started to
546 simplify later bookkeeping. It is important that we do this only
547 when the prior state was cs_deps_running, because that prior state
548 was definitely propagated to FILE's also_make's by set_command_state
549 (called above), but in another state an also_make may have
550 independently changed to finished state, and we would confuse that
551 file's bookkeeping (updated, but not_started is bogus state). */
552 set_command_state (file
, cs_not_started
);
554 /* Now record which dependencies are more
555 recent than this file, so we can define $?. */
558 for (d
= file
->deps
; d
!= 0; d
= d
->next
)
560 FILE_TIMESTAMP d_mtime
= file_mtime (d
->file
);
561 check_renamed (d
->file
);
563 #if 1 /* %%% In version 4, remove this code completely to
564 implement not remaking deps if their deps are newer
565 than their parents. */
566 if (d_mtime
== (FILE_TIMESTAMP
) -1 && !d
->file
->intermediate
)
567 /* We must remake if this dep does not
568 exist and is not intermediate. */
572 /* Set DEPS_CHANGED if this dep actually changed. */
573 deps_changed
|= d
->changed
;
575 /* Set D->changed if either this dep actually changed,
576 or its dependent, FILE, is older or does not exist. */
577 d
->changed
|= noexist
|| d_mtime
> this_mtime
;
579 if (debug_flag
&& !noexist
)
581 print_spaces (depth
);
582 if (d_mtime
== (FILE_TIMESTAMP
) -1)
583 printf ("Dependency `%s' does not exist.\n", dep_name (d
));
585 printf ("Dependency `%s' is %s than dependent `%s'.\n",
586 dep_name (d
), d
->changed
? "newer" : "older", file
->name
);
591 /* Here depth returns to the value it had when we were called. */
594 if (file
->double_colon
&& file
->deps
== 0)
597 DEBUGPR ("Target `%s' is double-colon and has no dependencies.\n");
599 else if (!noexist
&& file
->is_target
&& !deps_changed
&& file
->cmds
== 0)
602 DEBUGPR ("No commands for `%s' and no dependencies actually changed.\n");
610 printf("No need to remake target `%s'", file
->name
);
611 if (!streq(file
->name
, file
->hname
))
612 printf("; using VPATH name `%s'", file
->hname
);
617 notice_finished_file (file
);
619 /* Since we don't need to remake the file, convert it to use the
620 VPATH filename if we found one. hfile will be either the
621 local name if no VPATH or the VPATH name if one was found. */
625 file
->name
= file
->hname
;
632 DEBUGPR ("Must remake target `%s'.\n");
634 /* It needs to be remade. If it's VPATH and not reset via GPATH, toss the
636 if (!streq(file
->name
, file
->hname
))
640 print_spaces (depth
);
641 printf(" Ignoring VPATH name `%s'.\n", file
->hname
);
644 file
->ignore_vpath
= 1;
647 /* Now, take appropriate actions to remake the file. */
650 if (file
->command_state
!= cs_finished
)
652 DEBUGPR ("Commands of `%s' are being run.\n");
656 switch (file
->update_status
)
659 DEBUGPR ("Failed to remake target file `%s'.\n");
662 DEBUGPR ("Successfully remade target file `%s'.\n");
665 DEBUGPR ("Target file `%s' needs remade under -q.\n");
668 assert (file
->update_status
>= 0 && file
->update_status
<= 2);
673 return file
->update_status
;
676 /* Set FILE's `updated' flag and re-check its mtime and the mtime's of all
677 files listed in its `also_make' member. Under -t, this function also
680 On return, FILE->update_status will no longer be -1 if it was. */
683 notice_finished_file (file
)
684 register struct file
*file
;
687 int ran
= file
->command_state
== cs_running
;
689 file
->command_state
= cs_finished
;
693 /* The update status will be:
694 -1 if this target was not remade;
695 0 if 0 or more commands (+ or ${MAKE}) were run and won;
696 1 if some commands were run and lost.
697 We touch the target if it has commands which either were not run
698 or won when they ran (i.e. status is 0). */
699 && file
->update_status
== 0)
701 if (file
->cmds
!= 0 && file
->cmds
->any_recurse
)
703 /* If all the command lines were recursive,
704 we don't want to do the touching. */
706 for (i
= 0; i
< file
->cmds
->ncommand_lines
; ++i
)
707 if (!(file
->cmds
->lines_flags
[i
] & COMMANDS_RECURSE
))
708 goto have_nonrecursing
;
714 file
->update_status
= 0;
716 /* Should set file's modification date and do nothing else. */
717 file
->update_status
= touch_file (file
);
721 if (ran
&& !file
->phony
)
725 if (just_print_flag
|| question_flag
726 || (file
->is_target
&& file
->cmds
== 0))
727 file
->last_mtime
= NEW_MTIME
;
729 file
->last_mtime
= 0;
731 /* Propagate the change of modification time to all the double-colon
732 entries for this file. */
733 for (f
= file
->double_colon
; f
!= 0; f
= f
->next
)
734 f
->last_mtime
= file
->last_mtime
;
737 if (ran
&& file
->update_status
!= -1)
738 /* We actually tried to update FILE, which has
739 updated its also_make's as well (if it worked).
740 If it didn't work, it wouldn't work again for them.
741 So mark them as updated with the same status. */
742 for (d
= file
->also_make
; d
!= 0; d
= d
->next
)
744 d
->file
->command_state
= cs_finished
;
745 d
->file
->updated
= 1;
746 d
->file
->update_status
= file
->update_status
;
748 if (ran
&& !d
->file
->phony
)
749 /* Fetch the new modification time.
750 We do this instead of just invalidating the cached time
751 so that a vpath_search can happen. Otherwise, it would
752 never be done because the target is already updated. */
753 (void) f_mtime (d
->file
, 0);
755 else if (file
->update_status
== -1)
756 /* Nothing was done for FILE, but it needed nothing done.
757 So mark it now as "succeeded". */
758 file
->update_status
= 0;
761 /* Check whether another file (whose mtime is THIS_MTIME)
762 needs updating on account of a dependency which is file FILE.
763 If it does, store 1 in *MUST_MAKE_PTR.
764 In the process, update any non-intermediate files
765 that FILE depends on (including FILE itself).
766 Return nonzero if any updating failed. */
769 check_dep (file
, depth
, this_mtime
, must_make_ptr
)
772 FILE_TIMESTAMP this_mtime
;
775 register struct dep
*d
;
781 if (!file
->intermediate
)
782 /* If this is a non-intermediate file, update it and record
783 whether it is newer than THIS_MTIME. */
785 FILE_TIMESTAMP mtime
;
786 dep_status
= update_file (file
, depth
);
787 check_renamed (file
);
788 mtime
= file_mtime (file
);
789 check_renamed (file
);
790 if (mtime
== (FILE_TIMESTAMP
) -1 || mtime
> this_mtime
)
795 /* FILE is an intermediate file. */
796 FILE_TIMESTAMP mtime
;
798 if (!file
->phony
&& file
->cmds
== 0 && !file
->tried_implicit
)
800 if (try_implicit_rule (file
, depth
))
801 DEBUGPR ("Found an implicit rule for `%s'.\n");
803 DEBUGPR ("No implicit rule found for `%s'.\n");
804 file
->tried_implicit
= 1;
806 if (file
->cmds
== 0 && !file
->is_target
807 && default_file
!= 0 && default_file
->cmds
!= 0)
809 DEBUGPR ("Using default commands for `%s'.\n");
810 file
->cmds
= default_file
->cmds
;
813 /* If the intermediate file actually exists
814 and is newer, then we should remake from it. */
815 check_renamed (file
);
816 mtime
= file_mtime (file
);
817 check_renamed (file
);
818 if (mtime
!= (FILE_TIMESTAMP
) -1 && mtime
> this_mtime
)
820 /* Otherwise, update all non-intermediate files we depend on,
821 if necessary, and see whether any of them is more
822 recent than the file on whose behalf we are checking. */
825 register struct dep
*lastd
;
831 if (d
->file
->updating
)
833 error (NILF
, "Circular %s <- %s dependency dropped.",
834 file
->name
, d
->file
->name
);
837 file
->deps
= d
->next
;
843 lastd
->next
= d
->next
;
850 d
->file
->parent
= file
;
851 dep_status
|= check_dep (d
->file
, depth
, this_mtime
, must_make_ptr
);
852 check_renamed (d
->file
);
853 if (dep_status
!= 0 && !keep_going_flag
)
856 if (d
->file
->command_state
== cs_running
857 || d
->file
->command_state
== cs_deps_running
)
858 /* Record that some of FILE's deps are still being made.
859 This tells the upper levels to wait on processing it until
860 the commands are finished. */
861 set_command_state (file
, cs_deps_running
);
873 /* Touch FILE. Return zero if successful, one if not. */
875 #define TOUCH_ERROR(call) return (perror_with_name (call, file->name), 1)
879 register struct file
*file
;
882 message (0, "touch %s", file
->name
);
885 if (ar_name (file
->name
))
886 return ar_touch (file
->name
);
890 int fd
= open (file
->name
, O_RDWR
| O_CREAT
, 0666);
893 TOUCH_ERROR ("touch: open: ");
903 status
= fstat (fd
, &statbuf
);
905 while (status
< 0 && errno
== EINTR
);
908 TOUCH_ERROR ("touch: fstat: ");
909 /* Rewrite character 0 same as it already is. */
910 if (read (fd
, &buf
, 1) < 0)
911 TOUCH_ERROR ("touch: read: ");
912 if (lseek (fd
, 0L, 0) < 0L)
913 TOUCH_ERROR ("touch: lseek: ");
914 if (write (fd
, &buf
, 1) < 0)
915 TOUCH_ERROR ("touch: write: ");
916 /* If file length was 0, we just
917 changed it, so change it back. */
918 if (statbuf
.st_size
== 0)
921 fd
= open (file
->name
, O_RDWR
| O_TRUNC
, 0666);
923 TOUCH_ERROR ("touch: open: ");
932 /* Having checked and updated the dependencies of FILE,
933 do whatever is appropriate to remake FILE itself.
934 Return the status from executing FILE's commands. */
943 /* Phony target. Pretend it succeeded. */
944 file
->update_status
= 0;
945 else if (file
->is_target
)
946 /* This is a nonexistent target file we cannot make.
947 Pretend it was successfully remade. */
948 file
->update_status
= 0;
954 chop_commands (file
->cmds
);
956 if (!touch_flag
|| file
->cmds
->any_recurse
)
958 execute_file_commands (file
);
962 /* This tells notice_finished_file it is ok to touch the file. */
963 file
->update_status
= 0;
966 /* This does the touching under -t. */
967 notice_finished_file (file
);
970 /* Return the mtime of a file, given a `struct file'.
971 Caches the time in the struct file to avoid excess stat calls.
973 If the file is not found, and SEARCH is nonzero, VPATH searching and
974 replacement is done. If that fails, a library (-lLIBNAME) is tried and
975 the library's actual name (/lib/libLIBNAME.a, etc.) is substituted into
979 f_mtime (file
, search
)
980 register struct file
*file
;
983 FILE_TIMESTAMP mtime
;
985 /* File's mtime is not known; must get it from the system. */
988 if (ar_name (file
->name
))
990 /* This file is an archive-member reference. */
992 char *arname
, *memname
;
996 /* Find the archive's name. */
997 ar_parse_name (file
->name
, &arname
, &memname
);
999 /* Find the modification time of the archive itself.
1000 Also allow for its name to be changed via VPATH search. */
1001 arfile
= lookup_file (arname
);
1004 arfile
= enter_file (arname
);
1007 mtime
= f_mtime (arfile
, search
);
1008 check_renamed (arfile
);
1009 if (search
&& strcmp (arfile
->hname
, arname
))
1011 /* The archive's name has changed.
1012 Change the archive-member reference accordingly. */
1015 unsigned int arlen
, memlen
;
1023 arname
= arfile
->hname
;
1024 arlen
= strlen (arname
);
1025 memlen
= strlen (memname
);
1027 /* free (file->name); */
1029 name
= (char *) xmalloc (arlen
+ 1 + memlen
+ 2);
1030 bcopy (arname
, name
, arlen
);
1032 bcopy (memname
, name
+ arlen
+ 1, memlen
);
1033 name
[arlen
+ 1 + memlen
] = ')';
1034 name
[arlen
+ 1 + memlen
+ 1] = '\0';
1036 /* If the archive was found with GPATH, make the change permanent;
1037 otherwise defer it until later. */
1038 if (arfile
->name
== arfile
->hname
)
1039 rename_file (file
, name
);
1041 rehash_file (file
, name
);
1042 check_renamed (file
);
1049 if (mtime
== (FILE_TIMESTAMP
) -1)
1050 /* The archive doesn't exist, so it's members don't exist either. */
1051 return (FILE_TIMESTAMP
) -1;
1053 mtime
= ar_member_date (file
->hname
);
1058 mtime
= name_mtime (file
->name
);
1060 if (mtime
== (FILE_TIMESTAMP
) -1 && search
&& !file
->ignore_vpath
)
1062 /* If name_mtime failed, search VPATH. */
1063 char *name
= file
->name
;
1064 if (vpath_search (&name
, &mtime
)
1065 /* Last resort, is it a library (-lxxx)? */
1066 || (name
[0] == '-' && name
[1] == 'l'
1067 && library_search (&name
, &mtime
)))
1070 /* vpath_search and library_search store zero in MTIME
1071 if they didn't need to do a stat call for their work. */
1072 file
->last_mtime
= mtime
;
1074 /* If we found it in VPATH, see if it's in GPATH too; if so,
1075 change the name right now; if not, defer until after the
1076 dependencies are updated. */
1077 if (gpath_search (name
, strlen(name
) - strlen(file
->name
) - 1))
1079 rename_file (file
, name
);
1080 check_renamed (file
);
1081 return file_mtime (file
);
1084 rehash_file (file
, name
);
1085 check_renamed (file
);
1086 mtime
= name_mtime (name
);
1092 /* Files can have bogus timestamps that nothing newly made will be
1093 "newer" than. Updating their dependents could just result in loops.
1094 So notify the user of the anomaly with a warning.
1096 We only need to do this once, for now. */
1098 static FILE_TIMESTAMP now
= 0;
1099 if (!clock_skew_detected
1100 && mtime
!= (FILE_TIMESTAMP
)-1 && mtime
> now
1103 /* This file's time appears to be in the future.
1104 Update our concept of the present, and compare again. */
1106 now
= file_timestamp_now ();
1110 * FAT filesystems round time to nearest even second(!). Just
1111 * allow for any file (NTFS or FAT) to perhaps suffer from this
1114 if (mtime
> now
&& (((mtime
% 2) == 0) && ((mtime
-1) > now
)))
1117 /* Scrupulous testing indicates that some Windows
1118 filesystems can set file times up to 3 sec into the future! */
1119 if (mtime
> now
+ 3)
1125 char mtimebuf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
1126 char nowbuf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
1128 file_timestamp_sprintf (mtimebuf
, mtime
);
1129 file_timestamp_sprintf (nowbuf
, now
);
1130 error (NILF
, "*** Warning: File `%s' has modification time in the future (%s > %s)",
1131 file
->name
, mtimebuf
, nowbuf
);
1132 clock_skew_detected
= 1;
1137 /* Store the mtime into all the entries for this file. */
1138 if (file
->double_colon
)
1139 file
= file
->double_colon
;
1142 file
->last_mtime
= mtime
;
1144 } while (file
!= 0);
1150 /* Return the mtime of the file or archive-member reference NAME. */
1152 static FILE_TIMESTAMP
1154 register char *name
;
1158 if (stat (name
, &st
) < 0)
1159 return (FILE_TIMESTAMP
) -1;
1161 return FILE_TIMESTAMP_STAT_MODTIME (st
);
1165 /* Search for a library file specified as -lLIBNAME, searching for a
1166 suitable library file in the system library directories and the VPATH
1170 library_search (lib
, mtime_ptr
)
1172 FILE_TIMESTAMP
*mtime_ptr
;
1174 static char *dirs
[] =
1180 #if defined(WINDOWS32) && !defined(LIBDIR)
1182 * This is completely up to the user at product install time. Just define
1187 LIBDIR
, /* Defined by configuration. */
1191 char *libname
= &(*lib
)[2]; /* Name without the `-l'. */
1192 FILE_TIMESTAMP mtime
;
1194 /* Buffer to construct possible names in. */
1195 char *buf
= xmalloc (sizeof (LIBDIR
) + 8 + strlen (libname
) + 4 + 2 + 1);
1198 /* Look first for `libNAME.a' in the current directory. */
1201 sprintf (buf
, "lib%s.a", libname
);
1203 sprintf (buf
, "%s.lib", libname
);
1205 mtime
= name_mtime (buf
);
1206 if (mtime
!= (FILE_TIMESTAMP
) -1)
1214 /* Now try VPATH search on that. */
1217 if (vpath_search (&file
, mtime_ptr
))
1224 /* Now try the standard set of directories. */
1228 /* The default library directory is at ${DJDIR}/lib. */
1229 struct variable
*djdir
= lookup_variable ("DJDIR", 5);
1233 size_t djdir_len
= strlen (djdir
->value
);
1235 if (djdir_len
> sizeof(LIBDIR
) + 8 + strlen(libname
) + 4 + 2)
1236 buf
= (char *) xrealloc (djdir_len
+ 1);
1237 sprintf (buf
, "%s/lib/lib%s.a", djdir
->value
, libname
);
1238 mtime
= name_mtime (buf
);
1239 if (mtime
!= (FILE_TIMESTAMP
) -1)
1250 for (dp
= dirs
; *dp
!= 0; ++dp
)
1253 sprintf (buf
, "%s/lib%s.a", *dp
, libname
);
1255 sprintf (buf
, "%s/%s.lib", *dp
, libname
);
1257 mtime
= name_mtime (buf
);
1258 if (mtime
!= (FILE_TIMESTAMP
) -1)