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. */
43 extern int try_implicit_rule
PARAMS ((struct file
*file
, unsigned int depth
));
46 /* The test for circular dependencies is based on the 'updating' bit in
47 `struct file'. However, double colon targets have seperate `struct
48 file's; make sure we always use the base of the double colon chain. */
50 #define start_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
52 #define finish_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
54 #define is_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
58 /* Incremented when a command is started (under -n, when one would be). */
59 unsigned int commands_started
= 0;
61 static int update_file
PARAMS ((struct file
*file
, unsigned int depth
));
62 static int update_file_1
PARAMS ((struct file
*file
, unsigned int depth
));
63 static int check_dep
PARAMS ((struct file
*file
, unsigned int depth
, FILE_TIMESTAMP this_mtime
, int *must_make_ptr
));
64 static int touch_file
PARAMS ((struct file
*file
));
65 static void remake_file
PARAMS ((struct file
*file
));
66 static FILE_TIMESTAMP name_mtime
PARAMS ((char *name
));
67 static int library_search
PARAMS ((char **lib
, FILE_TIMESTAMP
*mtime_ptr
));
70 /* Remake all the goals in the `struct dep' chain GOALS. Return -1 if nothing
71 was done, 0 if all goals were updated successfully, or 1 if a goal failed.
72 If MAKEFILES is nonzero, these goals are makefiles, so -t, -q, and -n should
73 be disabled for them unless they were also command-line targets, and we
74 should only make one goal at a time and return as soon as one goal whose
75 `changed' member is nonzero is successfully made. */
78 update_goal_chain (goals
, makefiles
)
79 register struct dep
*goals
;
82 int t
= touch_flag
, q
= question_flag
, n
= just_print_flag
;
83 unsigned int j
= job_slots
;
86 #define MTIME(file) (makefiles ? file_mtime_no_search (file) \
89 /* Duplicate the chain so we can remove things from it. */
91 goals
= copy_dep_chain (goals
);
94 /* Clear the `changed' flag of each goal in the chain.
95 We will use the flag below to notice when any commands
96 have actually been run for a target. When no commands
97 have been run, we give an "up to date" diagnostic. */
100 for (g
= goals
; g
!= 0; g
= g
->next
)
104 /* All files start with the considered bit 0, so the global value is 1. */
107 /* Update all the goals until they are all finished. */
111 register struct dep
*g
, *lastgoal
;
113 /* Start jobs that are waiting for the load to go down. */
115 start_waiting_jobs ();
117 /* Wait for a child to die. */
119 reap_children (1, 0);
125 /* Iterate over all double-colon entries for this file. */
127 int stop
= 0, any_not_updated
= 0;
129 for (file
= g
->file
->double_colon
? g
->file
->double_colon
: g
->file
;
133 unsigned int ocommands_started
;
135 check_renamed (file
);
138 if (file
->cmd_target
)
145 touch_flag
= question_flag
= just_print_flag
= 0;
148 /* Save the old value of `commands_started' so we can compare
149 later. It will be incremented when any commands are
151 ocommands_started
= commands_started
;
153 x
= update_file (file
, makefiles
? 1 : 0);
154 check_renamed (file
);
156 /* Set the goal's `changed' flag if any commands were started
157 by calling update_file above. We check this flag below to
158 decide when to give an "up to date" diagnostic. */
159 g
->changed
+= commands_started
- ocommands_started
;
161 /* If we updated a file and STATUS was not already 1, set it to
162 1 if updating failed, or to 0 if updating succeeded. Leave
163 STATUS as it is if no updating was done. */
166 if ((x
!= 0 || file
->updated
) && status
< 1)
168 if (file
->update_status
!= 0)
170 /* Updating failed, or -q triggered. The STATUS value
171 tells our caller which. */
172 status
= file
->update_status
;
173 /* If -q just triggered, stop immediately. It doesn't
174 matter how much more we run, since we already know
175 the answer to return. */
176 stop
= (!keep_going_flag
&& !question_flag
181 FILE_TIMESTAMP mtime
= MTIME (file
);
182 check_renamed (file
);
184 if (file
->updated
&& g
->changed
&&
185 mtime
!= file
->mtime_before_update
)
187 /* Updating was done. If this is a makefile and
188 just_print_flag or question_flag is set (meaning
189 -n or -q was given and this file was specified
190 as a command-line target), don't change STATUS.
191 If STATUS is changed, we will get re-exec'd, and
192 enter an infinite loop. */
194 || (!just_print_flag
&& !question_flag
))
196 if (makefiles
&& file
->dontcare
)
197 /* This is a default makefile; stop remaking. */
203 /* Keep track if any double-colon entry is not finished.
204 When they are all finished, the goal is finished. */
205 any_not_updated
|= !file
->updated
;
211 /* Reset FILE since it is null at the end of the loop. */
214 if (stop
|| !any_not_updated
)
216 /* If we have found nothing whatever to do for the goal,
217 print a message saying nothing needs doing. */
220 /* If the update_status is zero, we updated successfully
221 or not at all. G->changed will have been set above if
222 any commands were actually started for this goal. */
223 && file
->update_status
== 0 && !g
->changed
224 /* Never give a message under -s or -q. */
225 && !silent_flag
&& !question_flag
)
226 message (1, ((file
->phony
|| file
->cmds
== 0)
227 ? _("Nothing to be done for `%s'.")
228 : _("`%s' is up to date.")),
231 /* This goal is finished. Remove it from the chain. */
235 lastgoal
->next
= g
->next
;
237 /* Free the storage. */
240 g
= lastgoal
== 0 ? goals
: lastgoal
->next
;
252 /* If we reached the end of the dependency graph toggle the considered
253 flag for the next pass. */
255 considered
= !considered
;
268 /* If FILE is not up to date, execute the commands for it.
269 Return 0 if successful, 1 if unsuccessful;
270 but with some flag settings, just call `exit' if unsuccessful.
272 DEPTH is the depth in recursions of this function.
273 We increment it during the consideration of our dependencies,
274 then decrement it again after finding out whether this file
277 If there are multiple double-colon entries for FILE,
278 each is considered in turn. */
281 update_file (file
, depth
)
285 register int status
= 0;
286 register struct file
*f
;
288 f
= file
->double_colon
? file
->double_colon
: file
;
290 /* Prune the dependency graph: if we've already been here on _this_
291 pass through the dependency graph, we don't have to go any further.
292 We won't reap_children until we start the next pass, so no state
293 change is possible below here until then. */
294 if (f
->considered
== considered
)
296 DBF (DB_VERBOSE
, _("Pruning file `%s'.\n"));
297 return f
->command_state
== cs_finished
? f
->update_status
: 0;
300 /* This loop runs until we start commands for a double colon rule, or until
301 the chain is exhausted. */
302 for (; f
!= 0; f
= f
->prev
)
304 f
->considered
= considered
;
306 status
|= update_file_1 (f
, depth
);
309 if (status
!= 0 && !keep_going_flag
)
312 if (f
->command_state
== cs_running
313 || f
->command_state
== cs_deps_running
)
315 /* Don't run the other :: rules for this
316 file until this rule is finished. */
322 /* Process the remaining rules in the double colon chain so they're marked
323 considered. Start their prerequisites, too. */
324 for (; f
!= 0 ; f
= f
->prev
)
328 f
->considered
= considered
;
330 for (d
= f
->deps
; d
!= 0; d
= d
->next
)
331 status
|= update_file (d
->file
, depth
+ 1);
337 /* Consider a single `struct file' and update it as appropriate. */
340 update_file_1 (file
, depth
)
344 register FILE_TIMESTAMP this_mtime
;
345 int noexist
, must_make
, deps_changed
;
347 register struct dep
*d
, *lastd
;
350 DBF (DB_VERBOSE
, _("Considering target file `%s'.\n"));
354 if (file
->update_status
> 0)
357 _("Recently tried and failed to update file `%s'.\n"));
358 return file
->update_status
;
361 DBF (DB_VERBOSE
, _("File `%s' was considered already.\n"));
365 switch (file
->command_state
)
368 case cs_deps_running
:
371 DBF (DB_VERBOSE
, _("Still updating file `%s'.\n"));
374 DBF (DB_VERBOSE
, _("Finished updating file `%s'.\n"));
375 return file
->update_status
;
382 /* Notice recursive update of the same file. */
383 start_updating (file
);
385 /* Looking at the file's modtime beforehand allows the possibility
386 that its name may be changed by a VPATH search, and thus it may
387 not need an implicit rule. If this were not done, the file
388 might get implicit commands that apply to its initial name, only
389 to have that name replaced with another found by VPATH search. */
391 this_mtime
= file_mtime (file
);
392 check_renamed (file
);
393 noexist
= this_mtime
== (FILE_TIMESTAMP
) -1;
395 DBF (DB_BASIC
, _("File `%s' does not exist.\n"));
399 /* If file was specified as a target with no commands,
400 come up with some default commands. */
402 if (!file
->phony
&& file
->cmds
== 0 && !file
->tried_implicit
)
404 if (try_implicit_rule (file
, depth
))
405 DBF (DB_IMPLICIT
, _("Found an implicit rule for `%s'.\n"));
407 DBF (DB_IMPLICIT
, _("No implicit rule found for `%s'.\n"));
408 file
->tried_implicit
= 1;
410 if (file
->cmds
== 0 && !file
->is_target
411 && default_file
!= 0 && default_file
->cmds
!= 0)
413 DBF (DB_IMPLICIT
, _("Using default commands for `%s'.\n"));
414 file
->cmds
= default_file
->cmds
;
417 /* Update all non-intermediate files we depend on, if necessary,
418 and see whether any of them is more recent than this file. */
424 FILE_TIMESTAMP mtime
;
426 check_renamed (d
->file
);
428 mtime
= file_mtime (d
->file
);
429 check_renamed (d
->file
);
431 if (is_updating (d
->file
))
433 error (NILF
, _("Circular %s <- %s dependency dropped."),
434 file
->name
, d
->file
->name
);
435 /* We cannot free D here because our the caller will still have
436 a reference to it when we were called recursively via
439 file
->deps
= d
->next
;
441 lastd
->next
= d
->next
;
446 d
->file
->parent
= file
;
447 dep_status
|= check_dep (d
->file
, depth
, this_mtime
, &must_make
);
448 check_renamed (d
->file
);
451 register struct file
*f
= d
->file
;
456 running
|= (f
->command_state
== cs_running
457 || f
->command_state
== cs_deps_running
);
463 if (dep_status
!= 0 && !keep_going_flag
)
467 d
->changed
= file_mtime (d
->file
) != mtime
;
473 /* Now we know whether this target needs updating.
474 If it does, update all the intermediate files we depend on. */
478 for (d
= file
->deps
; d
!= 0; d
= d
->next
)
479 if (d
->file
->intermediate
)
481 FILE_TIMESTAMP mtime
= file_mtime (d
->file
);
482 check_renamed (d
->file
);
483 d
->file
->parent
= file
;
484 dep_status
|= update_file (d
->file
, depth
);
485 check_renamed (d
->file
);
488 register struct file
*f
= d
->file
;
493 running
|= (f
->command_state
== cs_running
494 || f
->command_state
== cs_deps_running
);
500 if (dep_status
!= 0 && !keep_going_flag
)
504 d
->changed
= ((file
->phony
&& file
->cmds
!= 0)
505 || file_mtime (d
->file
) != mtime
);
509 finish_updating (file
);
511 DBF (DB_VERBOSE
, _("Finished prerequisites of target file `%s'.\n"));
515 set_command_state (file
, cs_deps_running
);
517 DBF (DB_VERBOSE
, _("The prerequisites of `%s' are being made.\n"));
521 /* If any dependency failed, give up now. */
525 file
->update_status
= dep_status
;
526 notice_finished_file (file
);
530 DBF (DB_VERBOSE
, _("Giving up on target file `%s'.\n"));
532 if (depth
== 0 && keep_going_flag
533 && !just_print_flag
&& !question_flag
)
535 _("Target `%s' not remade because of errors."), file
->name
);
540 if (file
->command_state
== cs_deps_running
)
541 /* The commands for some deps were running on the last iteration, but
542 they have finished now. Reset the command_state to not_started to
543 simplify later bookkeeping. It is important that we do this only
544 when the prior state was cs_deps_running, because that prior state
545 was definitely propagated to FILE's also_make's by set_command_state
546 (called above), but in another state an also_make may have
547 independently changed to finished state, and we would confuse that
548 file's bookkeeping (updated, but not_started is bogus state). */
549 set_command_state (file
, cs_not_started
);
551 /* Now record which dependencies are more
552 recent than this file, so we can define $?. */
555 for (d
= file
->deps
; d
!= 0; d
= d
->next
)
557 FILE_TIMESTAMP d_mtime
= file_mtime (d
->file
);
558 check_renamed (d
->file
);
560 #if 1 /* %%% In version 4, remove this code completely to
561 implement not remaking deps if their deps are newer
562 than their parents. */
563 if (d_mtime
== (FILE_TIMESTAMP
) -1 && !d
->file
->intermediate
)
564 /* We must remake if this dep does not
565 exist and is not intermediate. */
569 /* Set DEPS_CHANGED if this dep actually changed. */
570 deps_changed
|= d
->changed
;
572 /* Set D->changed if either this dep actually changed,
573 or its dependent, FILE, is older or does not exist. */
574 d
->changed
|= noexist
|| d_mtime
> this_mtime
;
576 if (!noexist
&& ISDB (DB_BASIC
|DB_VERBOSE
))
580 if (d_mtime
== (FILE_TIMESTAMP
) -1)
583 fmt
= _("Prerequisite `%s' of target `%s' does not exist.\n");
588 fmt
= _("Prerequisite `%s' is newer than target `%s'.\n");
590 else if (ISDB (DB_VERBOSE
))
591 fmt
= _("Prerequisite `%s' is older than target `%s'.\n");
595 print_spaces (depth
);
596 printf (fmt
, dep_name (d
), file
->name
);
602 /* Here depth returns to the value it had when we were called. */
605 if (file
->double_colon
&& file
->deps
== 0)
609 _("Target `%s' is double-colon and has no prerequisites.\n"));
611 else if (!noexist
&& file
->is_target
&& !deps_changed
&& file
->cmds
== 0)
615 _("No commands for `%s' and no prerequisites actually changed.\n"));
620 if (ISDB (DB_VERBOSE
))
622 print_spaces (depth
);
623 printf (_("No need to remake target `%s'"), file
->name
);
624 if (!streq (file
->name
, file
->hname
))
625 printf (_("; using VPATH name `%s'"), file
->hname
);
630 notice_finished_file (file
);
632 /* Since we don't need to remake the file, convert it to use the
633 VPATH filename if we found one. hfile will be either the
634 local name if no VPATH or the VPATH name if one was found. */
638 file
->name
= file
->hname
;
645 DBF (DB_BASIC
, _("Must remake target `%s'.\n"));
647 /* It needs to be remade. If it's VPATH and not reset via GPATH, toss the
649 if (!streq(file
->name
, file
->hname
))
651 DB (DB_BASIC
, (_(" Ignoring VPATH name `%s'.\n"), file
->hname
));
652 file
->ignore_vpath
= 1;
655 /* Now, take appropriate actions to remake the file. */
658 if (file
->command_state
!= cs_finished
)
660 DBF (DB_VERBOSE
, _("Commands of `%s' are being run.\n"));
664 switch (file
->update_status
)
667 DBF (DB_BASIC
, _("Failed to remake target file `%s'.\n"));
670 DBF (DB_BASIC
, _("Successfully remade target file `%s'.\n"));
673 DBF (DB_BASIC
, _("Target file `%s' needs remade under -q.\n"));
676 assert (file
->update_status
>= 0 && file
->update_status
<= 2);
681 return file
->update_status
;
684 /* Set FILE's `updated' flag and re-check its mtime and the mtime's of all
685 files listed in its `also_make' member. Under -t, this function also
688 On return, FILE->update_status will no longer be -1 if it was. */
691 notice_finished_file (file
)
692 register struct file
*file
;
695 int ran
= file
->command_state
== cs_running
;
697 file
->command_state
= cs_finished
;
701 /* The update status will be:
702 -1 if this target was not remade;
703 0 if 0 or more commands (+ or ${MAKE}) were run and won;
704 1 if some commands were run and lost.
705 We touch the target if it has commands which either were not run
706 or won when they ran (i.e. status is 0). */
707 && file
->update_status
== 0)
709 if (file
->cmds
!= 0 && file
->cmds
->any_recurse
)
711 /* If all the command lines were recursive,
712 we don't want to do the touching. */
714 for (i
= 0; i
< file
->cmds
->ncommand_lines
; ++i
)
715 if (!(file
->cmds
->lines_flags
[i
] & COMMANDS_RECURSE
))
716 goto have_nonrecursing
;
722 file
->update_status
= 0;
724 /* Should set file's modification date and do nothing else. */
725 file
->update_status
= touch_file (file
);
729 if (file
->mtime_before_update
== 0)
730 file
->mtime_before_update
= file
->last_mtime
;
732 if (ran
&& !file
->phony
)
737 /* If -n or -q and all the commands are recursive, we ran them so
738 really check the target's mtime again. Otherwise, assume the target
739 would have been updated. */
741 if (question_flag
|| just_print_flag
)
743 for (i
= file
->cmds
->ncommand_lines
; i
> 0; --i
)
744 if (! (file
->cmds
->lines_flags
[i
-1] & COMMANDS_RECURSE
))
748 /* If there were no commands at all, it's always new. */
750 else if (file
->is_target
&& file
->cmds
== 0)
753 file
->last_mtime
= i
== 0 ? 0 : NEW_MTIME
;
755 /* Propagate the change of modification time to all the double-colon
756 entries for this file. */
757 for (f
= file
->double_colon
; f
!= 0; f
= f
->next
)
758 f
->last_mtime
= file
->last_mtime
;
761 if (ran
&& file
->update_status
!= -1)
762 /* We actually tried to update FILE, which has
763 updated its also_make's as well (if it worked).
764 If it didn't work, it wouldn't work again for them.
765 So mark them as updated with the same status. */
766 for (d
= file
->also_make
; d
!= 0; d
= d
->next
)
768 d
->file
->command_state
= cs_finished
;
769 d
->file
->updated
= 1;
770 d
->file
->update_status
= file
->update_status
;
772 if (ran
&& !d
->file
->phony
)
773 /* Fetch the new modification time.
774 We do this instead of just invalidating the cached time
775 so that a vpath_search can happen. Otherwise, it would
776 never be done because the target is already updated. */
777 (void) f_mtime (d
->file
, 0);
779 else if (file
->update_status
== -1)
780 /* Nothing was done for FILE, but it needed nothing done.
781 So mark it now as "succeeded". */
782 file
->update_status
= 0;
785 /* Check whether another file (whose mtime is THIS_MTIME)
786 needs updating on account of a dependency which is file FILE.
787 If it does, store 1 in *MUST_MAKE_PTR.
788 In the process, update any non-intermediate files
789 that FILE depends on (including FILE itself).
790 Return nonzero if any updating failed. */
793 check_dep (file
, depth
, this_mtime
, must_make_ptr
)
796 FILE_TIMESTAMP this_mtime
;
799 register struct dep
*d
;
803 start_updating (file
);
805 if (!file
->intermediate
)
806 /* If this is a non-intermediate file, update it and record
807 whether it is newer than THIS_MTIME. */
809 FILE_TIMESTAMP mtime
;
810 dep_status
= update_file (file
, depth
);
811 check_renamed (file
);
812 mtime
= file_mtime (file
);
813 check_renamed (file
);
814 if (mtime
== (FILE_TIMESTAMP
) -1 || mtime
> this_mtime
)
819 /* FILE is an intermediate file. */
820 FILE_TIMESTAMP mtime
;
822 if (!file
->phony
&& file
->cmds
== 0 && !file
->tried_implicit
)
824 if (try_implicit_rule (file
, depth
))
825 DBF (DB_IMPLICIT
, _("Found an implicit rule for `%s'.\n"));
827 DBF (DB_IMPLICIT
, _("No implicit rule found for `%s'.\n"));
828 file
->tried_implicit
= 1;
830 if (file
->cmds
== 0 && !file
->is_target
831 && default_file
!= 0 && default_file
->cmds
!= 0)
833 DBF (DB_IMPLICIT
, _("Using default commands for `%s'.\n"));
834 file
->cmds
= default_file
->cmds
;
837 /* If the intermediate file actually exists
838 and is newer, then we should remake from it. */
839 check_renamed (file
);
840 mtime
= file_mtime (file
);
841 check_renamed (file
);
842 if (mtime
!= (FILE_TIMESTAMP
) -1 && mtime
> this_mtime
)
844 /* Otherwise, update all non-intermediate files we depend on,
845 if necessary, and see whether any of them is more
846 recent than the file on whose behalf we are checking. */
849 register struct dep
*lastd
;
855 if (is_updating (d
->file
))
857 error (NILF
, _("Circular %s <- %s dependency dropped."),
858 file
->name
, d
->file
->name
);
861 file
->deps
= d
->next
;
867 lastd
->next
= d
->next
;
874 d
->file
->parent
= file
;
875 dep_status
|= check_dep (d
->file
, depth
, this_mtime
,
877 check_renamed (d
->file
);
878 if (dep_status
!= 0 && !keep_going_flag
)
881 if (d
->file
->command_state
== cs_running
882 || d
->file
->command_state
== cs_deps_running
)
883 /* Record that some of FILE's deps are still being made.
884 This tells the upper levels to wait on processing it until
885 the commands are finished. */
886 set_command_state (file
, cs_deps_running
);
894 finish_updating (file
);
898 /* Touch FILE. Return zero if successful, one if not. */
900 #define TOUCH_ERROR(call) return (perror_with_name (call, file->name), 1)
904 register struct file
*file
;
907 message (0, "touch %s", file
->name
);
910 if (ar_name (file
->name
))
911 return ar_touch (file
->name
);
915 int fd
= open (file
->name
, O_RDWR
| O_CREAT
, 0666);
918 TOUCH_ERROR ("touch: open: ");
926 status
= fstat (fd
, &statbuf
);
927 while (status
< 0 && EINTR_SET
);
930 TOUCH_ERROR ("touch: fstat: ");
931 /* Rewrite character 0 same as it already is. */
932 if (read (fd
, &buf
, 1) < 0)
933 TOUCH_ERROR ("touch: read: ");
934 if (lseek (fd
, 0L, 0) < 0L)
935 TOUCH_ERROR ("touch: lseek: ");
936 if (write (fd
, &buf
, 1) < 0)
937 TOUCH_ERROR ("touch: write: ");
938 /* If file length was 0, we just
939 changed it, so change it back. */
940 if (statbuf
.st_size
== 0)
943 fd
= open (file
->name
, O_RDWR
| O_TRUNC
, 0666);
945 TOUCH_ERROR ("touch: open: ");
954 /* Having checked and updated the dependencies of FILE,
955 do whatever is appropriate to remake FILE itself.
956 Return the status from executing FILE's commands. */
965 /* Phony target. Pretend it succeeded. */
966 file
->update_status
= 0;
967 else if (file
->is_target
)
968 /* This is a nonexistent target file we cannot make.
969 Pretend it was successfully remade. */
970 file
->update_status
= 0;
973 const char *msg_noparent
974 = _("%sNo rule to make target `%s'%s");
975 const char *msg_parent
976 = _("%sNo rule to make target `%s', needed by `%s'%s");
978 /* This is a dependency file we cannot remake. Fail. */
979 if (!keep_going_flag
&& !file
->dontcare
)
981 if (file
->parent
== 0)
982 fatal (NILF
, msg_noparent
, "", file
->name
, "");
984 fatal (NILF
, msg_parent
, "", file
->name
, file
->parent
->name
, "");
989 if (file
->parent
== 0)
990 error (NILF
, msg_noparent
, "*** ", file
->name
, ".");
992 error (NILF
, msg_parent
, "*** ",
993 file
->name
, file
->parent
->name
, ".");
995 file
->update_status
= 2;
1000 chop_commands (file
->cmds
);
1002 /* The normal case: start some commands. */
1003 if (!touch_flag
|| file
->cmds
->any_recurse
)
1005 execute_file_commands (file
);
1009 /* This tells notice_finished_file it is ok to touch the file. */
1010 file
->update_status
= 0;
1013 /* This does the touching under -t. */
1014 notice_finished_file (file
);
1017 /* Return the mtime of a file, given a `struct file'.
1018 Caches the time in the struct file to avoid excess stat calls.
1020 If the file is not found, and SEARCH is nonzero, VPATH searching and
1021 replacement is done. If that fails, a library (-lLIBNAME) is tried and
1022 the library's actual name (/lib/libLIBNAME.a, etc.) is substituted into
1026 f_mtime (file
, search
)
1027 register struct file
*file
;
1030 FILE_TIMESTAMP mtime
;
1032 /* File's mtime is not known; must get it from the system. */
1035 if (ar_name (file
->name
))
1037 /* This file is an archive-member reference. */
1039 char *arname
, *memname
;
1040 struct file
*arfile
;
1041 int arname_used
= 0;
1043 /* Find the archive's name. */
1044 ar_parse_name (file
->name
, &arname
, &memname
);
1046 /* Find the modification time of the archive itself.
1047 Also allow for its name to be changed via VPATH search. */
1048 arfile
= lookup_file (arname
);
1051 arfile
= enter_file (arname
);
1054 mtime
= f_mtime (arfile
, search
);
1055 check_renamed (arfile
);
1056 if (search
&& strcmp (arfile
->hname
, arname
))
1058 /* The archive's name has changed.
1059 Change the archive-member reference accordingly. */
1062 unsigned int arlen
, memlen
;
1070 arname
= arfile
->hname
;
1071 arlen
= strlen (arname
);
1072 memlen
= strlen (memname
);
1074 /* free (file->name); */
1076 name
= (char *) xmalloc (arlen
+ 1 + memlen
+ 2);
1077 bcopy (arname
, name
, arlen
);
1079 bcopy (memname
, name
+ arlen
+ 1, memlen
);
1080 name
[arlen
+ 1 + memlen
] = ')';
1081 name
[arlen
+ 1 + memlen
+ 1] = '\0';
1083 /* If the archive was found with GPATH, make the change permanent;
1084 otherwise defer it until later. */
1085 if (arfile
->name
== arfile
->hname
)
1086 rename_file (file
, name
);
1088 rehash_file (file
, name
);
1089 check_renamed (file
);
1096 if (mtime
== (FILE_TIMESTAMP
) -1)
1097 /* The archive doesn't exist, so it's members don't exist either. */
1098 return (FILE_TIMESTAMP
) -1;
1100 mtime
= ar_member_date (file
->hname
);
1105 mtime
= name_mtime (file
->name
);
1107 if (mtime
== (FILE_TIMESTAMP
) -1 && search
&& !file
->ignore_vpath
)
1109 /* If name_mtime failed, search VPATH. */
1110 char *name
= file
->name
;
1111 if (vpath_search (&name
, &mtime
)
1112 /* Last resort, is it a library (-lxxx)? */
1113 || (name
[0] == '-' && name
[1] == 'l'
1114 && library_search (&name
, &mtime
)))
1117 /* vpath_search and library_search store zero in MTIME
1118 if they didn't need to do a stat call for their work. */
1119 file
->last_mtime
= mtime
;
1121 /* If we found it in VPATH, see if it's in GPATH too; if so,
1122 change the name right now; if not, defer until after the
1123 dependencies are updated. */
1124 if (gpath_search (name
, strlen(name
) - strlen(file
->name
) - 1))
1126 rename_file (file
, name
);
1127 check_renamed (file
);
1128 return file_mtime (file
);
1131 rehash_file (file
, name
);
1132 check_renamed (file
);
1133 mtime
= name_mtime (name
);
1139 /* Files can have bogus timestamps that nothing newly made will be
1140 "newer" than. Updating their dependents could just result in loops.
1141 So notify the user of the anomaly with a warning.
1143 We only need to do this once, for now. */
1145 static FILE_TIMESTAMP now
= 0;
1146 if (!clock_skew_detected
1147 && mtime
!= (FILE_TIMESTAMP
)-1 && mtime
> now
1150 /* This file's time appears to be in the future.
1151 Update our concept of the present, and compare again. */
1153 now
= file_timestamp_now ();
1157 * FAT filesystems round time to nearest even second(!). Just
1158 * allow for any file (NTFS or FAT) to perhaps suffer from this
1161 if (mtime
> now
&& (((mtime
% 2) == 0) && ((mtime
-1) > now
)))
1164 /* Scrupulous testing indicates that some Windows
1165 filesystems can set file times up to 3 sec into the future! */
1166 if (mtime
> now
+ 3)
1172 char mtimebuf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
1173 char nowbuf
[FILE_TIMESTAMP_PRINT_LEN_BOUND
+ 1];
1175 file_timestamp_sprintf (mtimebuf
, mtime
);
1176 file_timestamp_sprintf (nowbuf
, now
);
1177 error (NILF
, _("*** Warning: File `%s' has modification time in the future (%s > %s)"),
1178 file
->name
, mtimebuf
, nowbuf
);
1179 clock_skew_detected
= 1;
1184 /* Store the mtime into all the entries for this file. */
1185 if (file
->double_colon
)
1186 file
= file
->double_colon
;
1190 /* If this file is not implicit but it is intermediate then it was
1191 made so by the .INTERMEDIATE target. If this file has never
1192 been built by us but was found now, it existed before make
1193 started. So, turn off the intermediate bit so make doesn't
1194 delete it, since it didn't create it. */
1195 if (mtime
!= (FILE_TIMESTAMP
)-1 && file
->command_state
== cs_not_started
1196 && !file
->tried_implicit
&& file
->intermediate
)
1197 file
->intermediate
= 0;
1199 file
->last_mtime
= mtime
;
1208 /* Return the mtime of the file or archive-member reference NAME. */
1210 static FILE_TIMESTAMP
1212 register char *name
;
1216 if (stat (name
, &st
) < 0)
1217 return (FILE_TIMESTAMP
) -1;
1219 return FILE_TIMESTAMP_STAT_MODTIME (st
);
1223 /* Search for a library file specified as -lLIBNAME, searching for a
1224 suitable library file in the system library directories and the VPATH
1228 library_search (lib
, mtime_ptr
)
1230 FILE_TIMESTAMP
*mtime_ptr
;
1232 static char *dirs
[] =
1238 #if defined(WINDOWS32) && !defined(LIBDIR)
1240 * This is completely up to the user at product install time. Just define
1245 LIBDIR
, /* Defined by configuration. */
1249 static char *libpatterns
= NULL
;
1251 char *libname
= &(*lib
)[2]; /* Name without the `-l'. */
1252 FILE_TIMESTAMP mtime
;
1254 /* Loop variables for the libpatterns value. */
1260 /* If we don't have libpatterns, get it. */
1263 int save
= warn_undefined_variables_flag
;
1264 warn_undefined_variables_flag
= 0;
1266 libpatterns
= xstrdup (variable_expand ("$(strip $(.LIBPATTERNS))"));
1268 warn_undefined_variables_flag
= save
;
1271 /* Loop through all the patterns in .LIBPATTERNS, and search on each one. */
1273 while ((p
= find_next_token (&p2
, &len
)) != 0)
1275 static char *buf
= NULL
;
1276 static int buflen
= 0;
1277 static int libdir_maxlen
= -1;
1278 char *libbuf
= variable_expand ("");
1280 /* Expand the pattern using LIBNAME as a replacement. */
1286 p3
= find_percent (p
);
1289 /* Give a warning if there is no pattern, then remove the
1290 pattern so it's ignored next time. */
1291 error (NILF
, _(".LIBPATTERNS element `%s' is not a pattern"), p
);
1292 for (; len
; --len
, ++p
)
1297 p4
= variable_buffer_output (libbuf
, p
, p3
-p
);
1298 p4
= variable_buffer_output (p4
, libname
, strlen (libname
));
1299 p4
= variable_buffer_output (p4
, p3
+1, len
- (p3
-p
));
1303 /* Look first for `libNAME.a' in the current directory. */
1304 mtime
= name_mtime (libbuf
);
1305 if (mtime
!= (FILE_TIMESTAMP
) -1)
1307 *lib
= xstrdup (libbuf
);
1313 /* Now try VPATH search on that. */
1316 if (vpath_search (&file
, mtime_ptr
))
1322 /* Now try the standard set of directories. */
1326 for (dp
= dirs
; *dp
!= 0; ++dp
)
1328 int l
= strlen (*dp
);
1329 if (l
> libdir_maxlen
)
1332 buflen
= strlen (libbuf
);
1333 buf
= xmalloc(libdir_maxlen
+ buflen
+ 2);
1335 else if (buflen
< strlen (libbuf
))
1337 buflen
= strlen (libbuf
);
1338 buf
= xrealloc (buf
, libdir_maxlen
+ buflen
+ 2);
1341 for (dp
= dirs
; *dp
!= 0; ++dp
)
1343 sprintf (buf
, "%s/%s", *dp
, libbuf
);
1344 mtime
= name_mtime (buf
);
1345 if (mtime
!= (FILE_TIMESTAMP
) -1)
1347 *lib
= xstrdup (buf
);