1994-03-23 14:12:55 +00:00
|
|
|
|
/* Basic dependency engine for GNU Make.
|
2006-02-11 19:02:21 +00:00
|
|
|
|
Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
|
2010-07-13 01:20:10 +00:00
|
|
|
|
1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
|
|
|
|
2010 Free Software Foundation, Inc.
|
1992-01-18 02:09:28 +00:00
|
|
|
|
This file is part of GNU Make.
|
|
|
|
|
|
2006-02-11 19:02:21 +00:00
|
|
|
|
GNU Make is free software; you can redistribute it and/or modify it under the
|
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
2007-07-04 19:35:15 +00:00
|
|
|
|
Foundation; either version 3 of the License, or (at your option) any later
|
|
|
|
|
version.
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2006-02-11 19:02:21 +00:00
|
|
|
|
GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2006-02-11 19:02:21 +00:00
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
2007-07-04 19:35:15 +00:00
|
|
|
|
this program. If not, see <http://www.gnu.org/licenses/>. */
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
#include "make.h"
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#include "filedef.h"
|
1992-01-18 02:09:28 +00:00
|
|
|
|
#include "job.h"
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#include "commands.h"
|
1992-01-18 02:09:28 +00:00
|
|
|
|
#include "dep.h"
|
1999-02-22 07:23:30 +00:00
|
|
|
|
#include "variable.h"
|
1999-11-22 06:15:35 +00:00
|
|
|
|
#include "debug.h"
|
1999-02-22 07:23:30 +00:00
|
|
|
|
|
1994-09-10 15:04:57 +00:00
|
|
|
|
#include <assert.h>
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
1993-04-12 20:52:45 +00:00
|
|
|
|
#ifdef HAVE_FCNTL_H
|
1992-01-18 02:09:28 +00:00
|
|
|
|
#include <fcntl.h>
|
1993-04-12 20:52:45 +00:00
|
|
|
|
#else
|
|
|
|
|
#include <sys/file.h>
|
1992-01-18 02:09:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
#include <starlet.h>
|
|
|
|
|
#endif
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-22 21:51:45 +00:00
|
|
|
|
#include <io.h>
|
|
|
|
|
#endif
|
1996-03-20 14:57:41 +00:00
|
|
|
|
|
2006-04-07 01:43:44 +00:00
|
|
|
|
extern int try_implicit_rule (struct file *file, unsigned int depth);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
|
2000-03-27 06:54:37 +00:00
|
|
|
|
/* The test for circular dependencies is based on the 'updating' bit in
|
|
|
|
|
`struct file'. However, double colon targets have seperate `struct
|
|
|
|
|
file's; make sure we always use the base of the double colon chain. */
|
|
|
|
|
|
|
|
|
|
#define start_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
|
|
|
|
|
->updating = 1)
|
|
|
|
|
#define finish_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
|
|
|
|
|
->updating = 0)
|
|
|
|
|
#define is_updating(_f) (((_f)->double_colon ? (_f)->double_colon : (_f))\
|
|
|
|
|
->updating)
|
|
|
|
|
|
|
|
|
|
|
1993-01-25 23:30:19 +00:00
|
|
|
|
/* Incremented when a command is started (under -n, when one would be). */
|
|
|
|
|
unsigned int commands_started = 0;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2000-06-20 05:48:40 +00:00
|
|
|
|
/* Current value for pruning the scan of the goal chain (toggle 0/1). */
|
|
|
|
|
static unsigned int considered;
|
|
|
|
|
|
2006-04-07 01:43:44 +00:00
|
|
|
|
static int update_file (struct file *file, unsigned int depth);
|
|
|
|
|
static int update_file_1 (struct file *file, unsigned int depth);
|
|
|
|
|
static int check_dep (struct file *file, unsigned int depth,
|
|
|
|
|
FILE_TIMESTAMP this_mtime, int *must_make_ptr);
|
|
|
|
|
static int touch_file (struct file *file);
|
|
|
|
|
static void remake_file (struct file *file);
|
2007-03-20 03:02:26 +00:00
|
|
|
|
static FILE_TIMESTAMP name_mtime (const char *name);
|
|
|
|
|
static const char *library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr);
|
1996-03-20 14:57:41 +00:00
|
|
|
|
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
/* Remake all the goals in the `struct dep' chain GOALS. Return -1 if nothing
|
|
|
|
|
was done, 0 if all goals were updated successfully, or 1 if a goal failed.
|
2004-05-16 19:16:52 +00:00
|
|
|
|
|
|
|
|
|
If rebuilding_makefiles is nonzero, these goals are makefiles, so -t, -q,
|
|
|
|
|
and -n should be disabled for them unless they were also command-line
|
|
|
|
|
targets, and we should only make one goal at a time and return as soon as
|
|
|
|
|
one goal whose `changed' member is nonzero is successfully made. */
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
int
|
2004-05-16 19:16:52 +00:00
|
|
|
|
update_goal_chain (struct dep *goals)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
|
|
|
|
int t = touch_flag, q = question_flag, n = just_print_flag;
|
|
|
|
|
int status = -1;
|
|
|
|
|
|
2004-05-16 19:16:52 +00:00
|
|
|
|
#define MTIME(file) (rebuilding_makefiles ? file_mtime_no_search (file) \
|
1992-01-18 02:09:28 +00:00
|
|
|
|
: file_mtime (file))
|
|
|
|
|
|
|
|
|
|
/* Duplicate the chain so we can remove things from it. */
|
|
|
|
|
|
|
|
|
|
goals = copy_dep_chain (goals);
|
|
|
|
|
|
1993-01-25 23:30:19 +00:00
|
|
|
|
{
|
|
|
|
|
/* Clear the `changed' flag of each goal in the chain.
|
|
|
|
|
We will use the flag below to notice when any commands
|
|
|
|
|
have actually been run for a target. When no commands
|
|
|
|
|
have been run, we give an "up to date" diagnostic. */
|
|
|
|
|
|
|
|
|
|
struct dep *g;
|
|
|
|
|
for (g = goals; g != 0; g = g->next)
|
1999-07-15 07:36:44 +00:00
|
|
|
|
g->changed = 0;
|
1993-01-25 23:30:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-22 04:20:14 +00:00
|
|
|
|
/* All files start with the considered bit 0, so the global value is 1. */
|
|
|
|
|
considered = 1;
|
|
|
|
|
|
1992-01-18 02:09:28 +00:00
|
|
|
|
/* Update all the goals until they are all finished. */
|
|
|
|
|
|
|
|
|
|
while (goals != 0)
|
|
|
|
|
{
|
|
|
|
|
register struct dep *g, *lastgoal;
|
|
|
|
|
|
1992-06-15 21:47:19 +00:00
|
|
|
|
/* Start jobs that are waiting for the load to go down. */
|
|
|
|
|
|
|
|
|
|
start_waiting_jobs ();
|
|
|
|
|
|
1992-01-18 02:09:28 +00:00
|
|
|
|
/* Wait for a child to die. */
|
|
|
|
|
|
1992-04-21 07:44:18 +00:00
|
|
|
|
reap_children (1, 0);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
lastgoal = 0;
|
|
|
|
|
g = goals;
|
|
|
|
|
while (g != 0)
|
|
|
|
|
{
|
1994-04-05 10:37:12 +00:00
|
|
|
|
/* Iterate over all double-colon entries for this file. */
|
1999-07-08 22:32:38 +00:00
|
|
|
|
struct file *file;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
int stop = 0, any_not_updated = 0;
|
1996-03-20 14:57:41 +00:00
|
|
|
|
|
1994-04-05 10:37:12 +00:00
|
|
|
|
for (file = g->file->double_colon ? g->file->double_colon : g->file;
|
|
|
|
|
file != NULL;
|
|
|
|
|
file = file->prev)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
1994-04-05 10:37:12 +00:00
|
|
|
|
unsigned int ocommands_started;
|
|
|
|
|
int x;
|
2009-09-30 09:54:26 +00:00
|
|
|
|
|
|
|
|
|
file->dontcare = g->dontcare;
|
|
|
|
|
|
1994-04-05 10:37:12 +00:00
|
|
|
|
check_renamed (file);
|
2004-05-16 19:16:52 +00:00
|
|
|
|
if (rebuilding_makefiles)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
1994-04-05 10:37:12 +00:00
|
|
|
|
if (file->cmd_target)
|
|
|
|
|
{
|
|
|
|
|
touch_flag = t;
|
|
|
|
|
question_flag = q;
|
|
|
|
|
just_print_flag = n;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
touch_flag = question_flag = just_print_flag = 0;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1994-04-05 10:37:12 +00:00
|
|
|
|
/* Save the old value of `commands_started' so we can compare
|
|
|
|
|
later. It will be incremented when any commands are
|
|
|
|
|
actually run. */
|
|
|
|
|
ocommands_started = commands_started;
|
1993-01-25 23:30:19 +00:00
|
|
|
|
|
2004-05-16 19:16:52 +00:00
|
|
|
|
x = update_file (file, rebuilding_makefiles ? 1 : 0);
|
1994-04-05 10:37:12 +00:00
|
|
|
|
check_renamed (file);
|
1993-01-25 23:30:19 +00:00
|
|
|
|
|
1994-04-05 10:37:12 +00:00
|
|
|
|
/* Set the goal's `changed' flag if any commands were started
|
|
|
|
|
by calling update_file above. We check this flag below to
|
|
|
|
|
decide when to give an "up to date" diagnostic. */
|
2006-02-01 07:54:22 +00:00
|
|
|
|
if (commands_started > ocommands_started)
|
|
|
|
|
g->changed = 1;
|
1995-11-21 23:58:54 +00:00
|
|
|
|
|
1999-09-06 05:21:52 +00:00
|
|
|
|
/* If we updated a file and STATUS was not already 1, set it to
|
|
|
|
|
1 if updating failed, or to 0 if updating succeeded. Leave
|
|
|
|
|
STATUS as it is if no updating was done. */
|
1994-04-05 10:37:12 +00:00
|
|
|
|
|
1999-09-06 05:21:52 +00:00
|
|
|
|
stop = 0;
|
|
|
|
|
if ((x != 0 || file->updated) && status < 1)
|
|
|
|
|
{
|
|
|
|
|
if (file->update_status != 0)
|
|
|
|
|
{
|
|
|
|
|
/* Updating failed, or -q triggered. The STATUS value
|
|
|
|
|
tells our caller which. */
|
|
|
|
|
status = file->update_status;
|
|
|
|
|
/* If -q just triggered, stop immediately. It doesn't
|
|
|
|
|
matter how much more we run, since we already know
|
|
|
|
|
the answer to return. */
|
2005-02-28 09:41:25 +00:00
|
|
|
|
stop = (question_flag && !keep_going_flag
|
2004-05-16 19:16:52 +00:00
|
|
|
|
&& !rebuilding_makefiles);
|
1999-09-06 05:21:52 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FILE_TIMESTAMP mtime = MTIME (file);
|
|
|
|
|
check_renamed (file);
|
|
|
|
|
|
|
|
|
|
if (file->updated && g->changed &&
|
|
|
|
|
mtime != file->mtime_before_update)
|
1999-09-04 22:05:18 +00:00
|
|
|
|
{
|
1999-09-06 05:21:52 +00:00
|
|
|
|
/* Updating was done. If this is a makefile and
|
|
|
|
|
just_print_flag or question_flag is set (meaning
|
|
|
|
|
-n or -q was given and this file was specified
|
|
|
|
|
as a command-line target), don't change STATUS.
|
|
|
|
|
If STATUS is changed, we will get re-exec'd, and
|
|
|
|
|
enter an infinite loop. */
|
2004-05-16 19:16:52 +00:00
|
|
|
|
if (!rebuilding_makefiles
|
1999-09-06 05:21:52 +00:00
|
|
|
|
|| (!just_print_flag && !question_flag))
|
|
|
|
|
status = 0;
|
2004-05-16 19:16:52 +00:00
|
|
|
|
if (rebuilding_makefiles && file->dontcare)
|
1999-09-06 05:21:52 +00:00
|
|
|
|
/* This is a default makefile; stop remaking. */
|
|
|
|
|
stop = 1;
|
1999-09-04 22:05:18 +00:00
|
|
|
|
}
|
1999-09-06 05:21:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
1994-04-05 10:37:12 +00:00
|
|
|
|
/* Keep track if any double-colon entry is not finished.
|
|
|
|
|
When they are all finished, the goal is finished. */
|
|
|
|
|
any_not_updated |= !file->updated;
|
|
|
|
|
|
2009-09-30 09:54:26 +00:00
|
|
|
|
file->dontcare = 0;
|
|
|
|
|
|
1994-04-05 10:37:12 +00:00
|
|
|
|
if (stop)
|
|
|
|
|
break;
|
|
|
|
|
}
|
1993-01-25 23:30:19 +00:00
|
|
|
|
|
1994-04-22 21:58:26 +00:00
|
|
|
|
/* Reset FILE since it is null at the end of the loop. */
|
|
|
|
|
file = g->file;
|
|
|
|
|
|
1994-04-05 10:37:12 +00:00
|
|
|
|
if (stop || !any_not_updated)
|
|
|
|
|
{
|
|
|
|
|
/* If we have found nothing whatever to do for the goal,
|
|
|
|
|
print a message saying nothing needs doing. */
|
|
|
|
|
|
2004-05-16 19:16:52 +00:00
|
|
|
|
if (!rebuilding_makefiles
|
1994-04-05 10:37:12 +00:00
|
|
|
|
/* If the update_status is zero, we updated successfully
|
|
|
|
|
or not at all. G->changed will have been set above if
|
|
|
|
|
any commands were actually started for this goal. */
|
|
|
|
|
&& file->update_status == 0 && !g->changed
|
|
|
|
|
/* Never give a message under -s or -q. */
|
|
|
|
|
&& !silent_flag && !question_flag)
|
1995-11-26 01:38:10 +00:00
|
|
|
|
message (1, ((file->phony || file->cmds == 0)
|
1999-07-28 06:23:37 +00:00
|
|
|
|
? _("Nothing to be done for `%s'.")
|
|
|
|
|
: _("`%s' is up to date.")),
|
1995-11-26 01:38:10 +00:00
|
|
|
|
file->name);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
1994-04-05 10:37:12 +00:00
|
|
|
|
/* This goal is finished. Remove it from the chain. */
|
|
|
|
|
if (lastgoal == 0)
|
|
|
|
|
goals = g->next;
|
|
|
|
|
else
|
|
|
|
|
lastgoal->next = g->next;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
1994-04-05 10:37:12 +00:00
|
|
|
|
/* Free the storage. */
|
2006-04-09 22:09:24 +00:00
|
|
|
|
free (g);
|
1994-04-05 10:37:12 +00:00
|
|
|
|
|
|
|
|
|
g = lastgoal == 0 ? goals : lastgoal->next;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
if (stop)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lastgoal = g;
|
|
|
|
|
g = g->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-07-22 04:20:14 +00:00
|
|
|
|
|
|
|
|
|
/* If we reached the end of the dependency graph toggle the considered
|
|
|
|
|
flag for the next pass. */
|
|
|
|
|
if (g == 0)
|
|
|
|
|
considered = !considered;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-05-16 19:16:52 +00:00
|
|
|
|
if (rebuilding_makefiles)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
|
|
|
|
touch_flag = t;
|
|
|
|
|
question_flag = q;
|
|
|
|
|
just_print_flag = n;
|
|
|
|
|
}
|
2006-03-20 02:36:36 +00:00
|
|
|
|
|
1992-01-18 02:09:28 +00:00
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If FILE is not up to date, execute the commands for it.
|
|
|
|
|
Return 0 if successful, 1 if unsuccessful;
|
|
|
|
|
but with some flag settings, just call `exit' if unsuccessful.
|
|
|
|
|
|
|
|
|
|
DEPTH is the depth in recursions of this function.
|
|
|
|
|
We increment it during the consideration of our dependencies,
|
|
|
|
|
then decrement it again after finding out whether this file
|
|
|
|
|
is out of date.
|
|
|
|
|
|
|
|
|
|
If there are multiple double-colon entries for FILE,
|
|
|
|
|
each is considered in turn. */
|
|
|
|
|
|
|
|
|
|
static int
|
2002-10-14 21:54:04 +00:00
|
|
|
|
update_file (struct file *file, unsigned int depth)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
|
|
|
|
register int status = 0;
|
|
|
|
|
register struct file *f;
|
|
|
|
|
|
1999-12-08 20:13:50 +00:00
|
|
|
|
f = file->double_colon ? file->double_colon : file;
|
|
|
|
|
|
|
|
|
|
/* Prune the dependency graph: if we've already been here on _this_
|
|
|
|
|
pass through the dependency graph, we don't have to go any further.
|
|
|
|
|
We won't reap_children until we start the next pass, so no state
|
|
|
|
|
change is possible below here until then. */
|
|
|
|
|
if (f->considered == considered)
|
|
|
|
|
{
|
2009-09-30 09:54:26 +00:00
|
|
|
|
/* Check for the case where a target has been tried and failed but
|
|
|
|
|
the diagnostics hasn't been issued. If we need the diagnostics
|
|
|
|
|
then we will have to continue. */
|
|
|
|
|
if (!(f->updated && f->update_status > 0 && !f->dontcare && f->no_diag))
|
|
|
|
|
{
|
|
|
|
|
DBF (DB_VERBOSE, _("Pruning file `%s'.\n"));
|
|
|
|
|
return f->command_state == cs_finished ? f->update_status : 0;
|
|
|
|
|
}
|
1999-12-08 20:13:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-18 17:43:47 +00:00
|
|
|
|
/* This loop runs until we start commands for a double colon rule, or until
|
|
|
|
|
the chain is exhausted. */
|
1999-12-08 20:13:50 +00:00
|
|
|
|
for (; f != 0; f = f->prev)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
1999-08-23 22:15:17 +00:00
|
|
|
|
f->considered = considered;
|
|
|
|
|
|
1992-01-18 02:09:28 +00:00
|
|
|
|
status |= update_file_1 (f, depth);
|
|
|
|
|
check_renamed (f);
|
|
|
|
|
|
2006-03-20 02:36:36 +00:00
|
|
|
|
/* Clean up any alloca() used during the update. */
|
|
|
|
|
alloca (0);
|
|
|
|
|
|
2005-02-28 09:41:25 +00:00
|
|
|
|
/* If we got an error, don't bother with double_colon etc. */
|
1992-01-18 02:09:28 +00:00
|
|
|
|
if (status != 0 && !keep_going_flag)
|
2009-09-30 09:54:26 +00:00
|
|
|
|
return status;
|
1992-06-26 00:46:53 +00:00
|
|
|
|
|
1999-12-08 20:13:50 +00:00
|
|
|
|
if (f->command_state == cs_running
|
|
|
|
|
|| f->command_state == cs_deps_running)
|
|
|
|
|
{
|
1992-06-26 00:46:53 +00:00
|
|
|
|
/* Don't run the other :: rules for this
|
|
|
|
|
file until this rule is finished. */
|
1999-12-08 20:13:50 +00:00
|
|
|
|
status = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1992-06-26 00:46:53 +00:00
|
|
|
|
|
1999-12-08 20:13:50 +00:00
|
|
|
|
/* Process the remaining rules in the double colon chain so they're marked
|
|
|
|
|
considered. Start their prerequisites, too. */
|
2004-05-16 19:16:52 +00:00
|
|
|
|
if (file->double_colon)
|
|
|
|
|
for (; f != 0 ; f = f->prev)
|
|
|
|
|
{
|
|
|
|
|
struct dep *d;
|
1999-12-08 20:13:50 +00:00
|
|
|
|
|
2004-05-16 19:16:52 +00:00
|
|
|
|
f->considered = considered;
|
1999-12-08 20:13:50 +00:00
|
|
|
|
|
2004-05-16 19:16:52 +00:00
|
|
|
|
for (d = f->deps; d != 0; d = d->next)
|
|
|
|
|
status |= update_file (d->file, depth + 1);
|
|
|
|
|
}
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-16 19:16:52 +00:00
|
|
|
|
/* Show a message stating the target failed to build. */
|
|
|
|
|
|
|
|
|
|
static void
|
2009-09-30 09:54:26 +00:00
|
|
|
|
complain (struct file *file)
|
2004-05-16 19:16:52 +00:00
|
|
|
|
{
|
|
|
|
|
const char *msg_noparent
|
|
|
|
|
= _("%sNo rule to make target `%s'%s");
|
|
|
|
|
const char *msg_parent
|
|
|
|
|
= _("%sNo rule to make target `%s', needed by `%s'%s");
|
|
|
|
|
|
2009-09-30 09:54:26 +00:00
|
|
|
|
/* If this file has no_diag set then it means we tried to update it
|
|
|
|
|
before in the dontcare mode and failed. The target that actually
|
|
|
|
|
failed is not necessarily this file but could be one of its direct
|
|
|
|
|
or indirect dependencies. So traverse this file's dependencies and
|
|
|
|
|
find the one that actually caused the failure. */
|
|
|
|
|
|
|
|
|
|
struct dep *d;
|
|
|
|
|
|
|
|
|
|
for (d = file->deps; d != 0; d = d->next)
|
2004-05-16 19:16:52 +00:00
|
|
|
|
{
|
2009-09-30 09:54:26 +00:00
|
|
|
|
if (d->file->updated && d->file->update_status > 0 && file->no_diag)
|
|
|
|
|
{
|
|
|
|
|
complain (d->file);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d == 0)
|
|
|
|
|
{
|
|
|
|
|
/* Didn't find any dependencies to complain about. */
|
|
|
|
|
if (!keep_going_flag)
|
|
|
|
|
{
|
|
|
|
|
if (file->parent == 0)
|
|
|
|
|
fatal (NILF, msg_noparent, "", file->name, "");
|
|
|
|
|
|
|
|
|
|
fatal (NILF, msg_parent, "", file->name, file->parent->name, "");
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-16 19:16:52 +00:00
|
|
|
|
if (file->parent == 0)
|
2009-09-30 09:54:26 +00:00
|
|
|
|
error (NILF, msg_noparent, "*** ", file->name, ".");
|
|
|
|
|
else
|
|
|
|
|
error (NILF, msg_parent, "*** ", file->name, file->parent->name, ".");
|
2004-05-16 19:16:52 +00:00
|
|
|
|
|
2009-09-30 09:54:26 +00:00
|
|
|
|
file->no_diag = 0;
|
2004-05-16 19:16:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1992-01-18 02:09:28 +00:00
|
|
|
|
/* Consider a single `struct file' and update it as appropriate. */
|
|
|
|
|
|
|
|
|
|
static int
|
2002-10-14 21:54:04 +00:00
|
|
|
|
update_file_1 (struct file *file, unsigned int depth)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
2009-06-10 02:21:09 +00:00
|
|
|
|
FILE_TIMESTAMP this_mtime;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
int noexist, must_make, deps_changed;
|
|
|
|
|
int dep_status = 0;
|
2009-06-14 06:08:11 +00:00
|
|
|
|
struct file *ofile;
|
2009-06-10 02:21:09 +00:00
|
|
|
|
struct dep *d, *ad;
|
|
|
|
|
struct dep amake;
|
1992-12-22 21:22:05 +00:00
|
|
|
|
int running = 0;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
1999-11-27 08:09:42 +00:00
|
|
|
|
DBF (DB_VERBOSE, _("Considering target file `%s'.\n"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
if (file->updated)
|
|
|
|
|
{
|
|
|
|
|
if (file->update_status > 0)
|
|
|
|
|
{
|
1999-11-27 08:09:42 +00:00
|
|
|
|
DBF (DB_VERBOSE,
|
1999-11-22 06:15:35 +00:00
|
|
|
|
_("Recently tried and failed to update file `%s'.\n"));
|
2004-05-16 19:16:52 +00:00
|
|
|
|
|
2009-09-30 09:54:26 +00:00
|
|
|
|
/* If the file we tried to make is marked no_diag then no message
|
2004-05-16 19:16:52 +00:00
|
|
|
|
was printed about it when it failed during the makefile rebuild.
|
|
|
|
|
If we're trying to build it again in the normal rebuild, print a
|
|
|
|
|
message now. */
|
2009-09-30 09:54:26 +00:00
|
|
|
|
if (file->no_diag && !file->dontcare)
|
2004-05-16 19:16:52 +00:00
|
|
|
|
complain (file);
|
|
|
|
|
|
1992-01-18 02:09:28 +00:00
|
|
|
|
return file->update_status;
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-27 08:09:42 +00:00
|
|
|
|
DBF (DB_VERBOSE, _("File `%s' was considered already.\n"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (file->command_state)
|
|
|
|
|
{
|
|
|
|
|
case cs_not_started:
|
|
|
|
|
case cs_deps_running:
|
|
|
|
|
break;
|
|
|
|
|
case cs_running:
|
1999-11-27 08:09:42 +00:00
|
|
|
|
DBF (DB_VERBOSE, _("Still updating file `%s'.\n"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
case cs_finished:
|
1999-11-27 08:09:42 +00:00
|
|
|
|
DBF (DB_VERBOSE, _("Finished updating file `%s'.\n"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
return file->update_status;
|
|
|
|
|
default:
|
|
|
|
|
abort ();
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-30 09:54:26 +00:00
|
|
|
|
/* Determine whether the diagnostics will be issued should this update
|
|
|
|
|
fail. */
|
|
|
|
|
file->no_diag = file->dontcare;
|
|
|
|
|
|
1992-01-18 02:09:28 +00:00
|
|
|
|
++depth;
|
|
|
|
|
|
|
|
|
|
/* Notice recursive update of the same file. */
|
2000-03-27 06:54:37 +00:00
|
|
|
|
start_updating (file);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2009-06-14 06:08:11 +00:00
|
|
|
|
/* We might change file if we find a different one via vpath;
|
|
|
|
|
remember this one to turn off updating. */
|
|
|
|
|
ofile = file;
|
|
|
|
|
|
1992-01-18 02:09:28 +00:00
|
|
|
|
/* Looking at the file's modtime beforehand allows the possibility
|
|
|
|
|
that its name may be changed by a VPATH search, and thus it may
|
|
|
|
|
not need an implicit rule. If this were not done, the file
|
|
|
|
|
might get implicit commands that apply to its initial name, only
|
|
|
|
|
to have that name replaced with another found by VPATH search. */
|
|
|
|
|
|
|
|
|
|
this_mtime = file_mtime (file);
|
|
|
|
|
check_renamed (file);
|
2000-06-13 05:22:52 +00:00
|
|
|
|
noexist = this_mtime == NONEXISTENT_MTIME;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
if (noexist)
|
1999-11-22 06:15:35 +00:00
|
|
|
|
DBF (DB_BASIC, _("File `%s' does not exist.\n"));
|
2000-07-30 18:26:42 +00:00
|
|
|
|
else if (ORDINARY_MTIME_MIN <= this_mtime && this_mtime <= ORDINARY_MTIME_MAX
|
|
|
|
|
&& file->low_resolution_time)
|
2000-07-07 17:34:56 +00:00
|
|
|
|
{
|
2000-07-30 18:26:42 +00:00
|
|
|
|
/* Avoid spurious rebuilds due to low resolution time stamps. */
|
|
|
|
|
int ns = FILE_TIMESTAMP_NS (this_mtime);
|
|
|
|
|
if (ns != 0)
|
|
|
|
|
error (NILF, _("*** Warning: .LOW_RESOLUTION_TIME file `%s' has a high resolution time stamp"),
|
|
|
|
|
file->name);
|
|
|
|
|
this_mtime += FILE_TIMESTAMPS_PER_S - 1 - ns;
|
2000-07-07 17:34:56 +00:00
|
|
|
|
}
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
must_make = noexist;
|
|
|
|
|
|
|
|
|
|
/* If file was specified as a target with no commands,
|
|
|
|
|
come up with some default commands. */
|
|
|
|
|
|
|
|
|
|
if (!file->phony && file->cmds == 0 && !file->tried_implicit)
|
|
|
|
|
{
|
|
|
|
|
if (try_implicit_rule (file, depth))
|
1999-11-22 06:15:35 +00:00
|
|
|
|
DBF (DB_IMPLICIT, _("Found an implicit rule for `%s'.\n"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
else
|
1999-11-22 06:15:35 +00:00
|
|
|
|
DBF (DB_IMPLICIT, _("No implicit rule found for `%s'.\n"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
file->tried_implicit = 1;
|
|
|
|
|
}
|
1993-09-17 04:51:21 +00:00
|
|
|
|
if (file->cmds == 0 && !file->is_target
|
|
|
|
|
&& default_file != 0 && default_file->cmds != 0)
|
|
|
|
|
{
|
2007-11-04 21:54:00 +00:00
|
|
|
|
DBF (DB_IMPLICIT, _("Using default recipe for `%s'.\n"));
|
1993-09-17 04:51:21 +00:00
|
|
|
|
file->cmds = default_file->cmds;
|
|
|
|
|
}
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
/* Update all non-intermediate files we depend on, if necessary, and see
|
|
|
|
|
whether any of them is more recent than this file. We need to walk our
|
|
|
|
|
deps, AND the deps of any also_make targets to ensure everything happens
|
|
|
|
|
in the correct order. */
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
amake.file = file;
|
|
|
|
|
amake.next = file->also_make;
|
|
|
|
|
ad = &amake;
|
|
|
|
|
while (ad)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
2009-06-10 02:21:09 +00:00
|
|
|
|
struct dep *lastd = 0;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
/* Find the deps we're scanning */
|
|
|
|
|
d = ad->file->deps;
|
|
|
|
|
ad = ad->next;
|
1992-04-01 10:06:27 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
while (d)
|
|
|
|
|
{
|
|
|
|
|
FILE_TIMESTAMP mtime;
|
|
|
|
|
int maybe_make;
|
|
|
|
|
int dontcare = 0;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
check_renamed (d->file);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
mtime = file_mtime (d->file);
|
|
|
|
|
check_renamed (d->file);
|
2004-09-28 18:13:55 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
if (is_updating (d->file))
|
|
|
|
|
{
|
|
|
|
|
error (NILF, _("Circular %s <- %s dependency dropped."),
|
|
|
|
|
file->name, d->file->name);
|
|
|
|
|
/* We cannot free D here because our the caller will still have
|
|
|
|
|
a reference to it when we were called recursively via
|
|
|
|
|
check_dep below. */
|
|
|
|
|
if (lastd == 0)
|
|
|
|
|
file->deps = d->next;
|
|
|
|
|
else
|
|
|
|
|
lastd->next = d->next;
|
|
|
|
|
d = d->next;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2004-09-28 18:13:55 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
d->file->parent = file;
|
|
|
|
|
maybe_make = must_make;
|
2004-09-28 18:13:55 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
/* Inherit dontcare flag from our parent. */
|
|
|
|
|
if (rebuilding_makefiles)
|
|
|
|
|
{
|
|
|
|
|
dontcare = d->file->dontcare;
|
|
|
|
|
d->file->dontcare = file->dontcare;
|
|
|
|
|
}
|
2004-09-28 18:13:55 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
dep_status |= check_dep (d->file, depth, this_mtime, &maybe_make);
|
2004-09-28 18:13:55 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
/* Restore original dontcare flag. */
|
|
|
|
|
if (rebuilding_makefiles)
|
|
|
|
|
d->file->dontcare = dontcare;
|
2002-07-08 13:05:02 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
if (! d->ignore_mtime)
|
|
|
|
|
must_make = maybe_make;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
check_renamed (d->file);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
{
|
|
|
|
|
register struct file *f = d->file;
|
|
|
|
|
if (f->double_colon)
|
|
|
|
|
f = f->double_colon;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
running |= (f->command_state == cs_running
|
|
|
|
|
|| f->command_state == cs_deps_running);
|
|
|
|
|
f = f->prev;
|
|
|
|
|
}
|
|
|
|
|
while (f != 0);
|
|
|
|
|
}
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
if (dep_status != 0 && !keep_going_flag)
|
|
|
|
|
break;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
if (!running)
|
|
|
|
|
/* The prereq is considered changed if the timestamp has changed while
|
|
|
|
|
it was built, OR it doesn't exist. */
|
|
|
|
|
d->changed = ((file_mtime (d->file) != mtime)
|
|
|
|
|
|| (mtime == NONEXISTENT_MTIME));
|
|
|
|
|
|
|
|
|
|
lastd = d;
|
|
|
|
|
d = d->next;
|
|
|
|
|
}
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now we know whether this target needs updating.
|
|
|
|
|
If it does, update all the intermediate files we depend on. */
|
|
|
|
|
|
2002-08-08 00:11:19 +00:00
|
|
|
|
if (must_make || always_make_flag)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
|
|
|
|
for (d = file->deps; d != 0; d = d->next)
|
|
|
|
|
if (d->file->intermediate)
|
|
|
|
|
{
|
2004-09-28 18:13:55 +00:00
|
|
|
|
int dontcare = 0;
|
|
|
|
|
|
1998-10-03 05:39:55 +00:00
|
|
|
|
FILE_TIMESTAMP mtime = file_mtime (d->file);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
check_renamed (d->file);
|
|
|
|
|
d->file->parent = file;
|
2004-09-28 18:13:55 +00:00
|
|
|
|
|
|
|
|
|
/* Inherit dontcare flag from our parent. */
|
|
|
|
|
if (rebuilding_makefiles)
|
|
|
|
|
{
|
|
|
|
|
dontcare = d->file->dontcare;
|
|
|
|
|
d->file->dontcare = file->dontcare;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1992-01-18 02:09:28 +00:00
|
|
|
|
dep_status |= update_file (d->file, depth);
|
2004-09-28 18:13:55 +00:00
|
|
|
|
|
|
|
|
|
/* Restore original dontcare flag. */
|
|
|
|
|
if (rebuilding_makefiles)
|
|
|
|
|
d->file->dontcare = dontcare;
|
|
|
|
|
|
1992-01-18 02:09:28 +00:00
|
|
|
|
check_renamed (d->file);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
register struct file *f = d->file;
|
1994-04-05 10:37:12 +00:00
|
|
|
|
if (f->double_colon)
|
|
|
|
|
f = f->double_colon;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
running |= (f->command_state == cs_running
|
|
|
|
|
|| f->command_state == cs_deps_running);
|
|
|
|
|
f = f->prev;
|
|
|
|
|
}
|
|
|
|
|
while (f != 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dep_status != 0 && !keep_going_flag)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (!running)
|
|
|
|
|
d->changed = ((file->phony && file->cmds != 0)
|
|
|
|
|
|| file_mtime (d->file) != mtime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-27 06:54:37 +00:00
|
|
|
|
finish_updating (file);
|
2009-06-14 06:08:11 +00:00
|
|
|
|
finish_updating (ofile);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
1999-11-27 08:09:42 +00:00
|
|
|
|
DBF (DB_VERBOSE, _("Finished prerequisites of target file `%s'.\n"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
if (running)
|
|
|
|
|
{
|
1994-09-07 00:04:49 +00:00
|
|
|
|
set_command_state (file, cs_deps_running);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
--depth;
|
1999-11-27 08:09:42 +00:00
|
|
|
|
DBF (DB_VERBOSE, _("The prerequisites of `%s' are being made.\n"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If any dependency failed, give up now. */
|
|
|
|
|
|
|
|
|
|
if (dep_status != 0)
|
|
|
|
|
{
|
|
|
|
|
file->update_status = dep_status;
|
1994-09-07 07:06:46 +00:00
|
|
|
|
notice_finished_file (file);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2002-08-08 00:11:19 +00:00
|
|
|
|
--depth;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
1999-11-27 08:09:42 +00:00
|
|
|
|
DBF (DB_VERBOSE, _("Giving up on target file `%s'.\n"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
if (depth == 0 && keep_going_flag
|
|
|
|
|
&& !just_print_flag && !question_flag)
|
1999-09-03 22:46:28 +00:00
|
|
|
|
error (NILF,
|
|
|
|
|
_("Target `%s' not remade because of errors."), file->name);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
return dep_status;
|
|
|
|
|
}
|
|
|
|
|
|
1994-12-05 17:42:13 +00:00
|
|
|
|
if (file->command_state == cs_deps_running)
|
|
|
|
|
/* The commands for some deps were running on the last iteration, but
|
|
|
|
|
they have finished now. Reset the command_state to not_started to
|
|
|
|
|
simplify later bookkeeping. It is important that we do this only
|
|
|
|
|
when the prior state was cs_deps_running, because that prior state
|
|
|
|
|
was definitely propagated to FILE's also_make's by set_command_state
|
|
|
|
|
(called above), but in another state an also_make may have
|
|
|
|
|
independently changed to finished state, and we would confuse that
|
|
|
|
|
file's bookkeeping (updated, but not_started is bogus state). */
|
|
|
|
|
set_command_state (file, cs_not_started);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2002-08-08 00:11:19 +00:00
|
|
|
|
/* Now record which prerequisites are more
|
1992-01-18 02:09:28 +00:00
|
|
|
|
recent than this file, so we can define $?. */
|
|
|
|
|
|
|
|
|
|
deps_changed = 0;
|
|
|
|
|
for (d = file->deps; d != 0; d = d->next)
|
|
|
|
|
{
|
1998-10-03 05:39:55 +00:00
|
|
|
|
FILE_TIMESTAMP d_mtime = file_mtime (d->file);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
check_renamed (d->file);
|
|
|
|
|
|
2002-07-08 13:05:02 +00:00
|
|
|
|
if (! d->ignore_mtime)
|
|
|
|
|
{
|
|
|
|
|
#if 1
|
|
|
|
|
/* %%% In version 4, remove this code completely to
|
1992-01-18 02:09:28 +00:00
|
|
|
|
implement not remaking deps if their deps are newer
|
|
|
|
|
than their parents. */
|
2002-07-08 13:05:02 +00:00
|
|
|
|
if (d_mtime == NONEXISTENT_MTIME && !d->file->intermediate)
|
|
|
|
|
/* We must remake if this dep does not
|
|
|
|
|
exist and is not intermediate. */
|
|
|
|
|
must_make = 1;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2002-07-08 13:05:02 +00:00
|
|
|
|
/* Set DEPS_CHANGED if this dep actually changed. */
|
|
|
|
|
deps_changed |= d->changed;
|
|
|
|
|
}
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
/* Set D->changed if either this dep actually changed,
|
|
|
|
|
or its dependent, FILE, is older or does not exist. */
|
|
|
|
|
d->changed |= noexist || d_mtime > this_mtime;
|
|
|
|
|
|
1999-11-27 08:09:42 +00:00
|
|
|
|
if (!noexist && ISDB (DB_BASIC|DB_VERBOSE))
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
1999-11-22 06:15:35 +00:00
|
|
|
|
const char *fmt = 0;
|
|
|
|
|
|
2002-07-08 13:05:02 +00:00
|
|
|
|
if (d->ignore_mtime)
|
|
|
|
|
{
|
|
|
|
|
if (ISDB (DB_VERBOSE))
|
|
|
|
|
fmt = _("Prerequisite `%s' is order-only for target `%s'.\n");
|
|
|
|
|
}
|
|
|
|
|
else if (d_mtime == NONEXISTENT_MTIME)
|
1999-11-22 06:15:35 +00:00
|
|
|
|
{
|
|
|
|
|
if (ISDB (DB_BASIC))
|
|
|
|
|
fmt = _("Prerequisite `%s' of target `%s' does not exist.\n");
|
|
|
|
|
}
|
|
|
|
|
else if (d->changed)
|
|
|
|
|
{
|
|
|
|
|
if (ISDB (DB_BASIC))
|
|
|
|
|
fmt = _("Prerequisite `%s' is newer than target `%s'.\n");
|
|
|
|
|
}
|
1999-11-27 08:09:42 +00:00
|
|
|
|
else if (ISDB (DB_VERBOSE))
|
1999-11-22 06:15:35 +00:00
|
|
|
|
fmt = _("Prerequisite `%s' is older than target `%s'.\n");
|
|
|
|
|
|
|
|
|
|
if (fmt)
|
|
|
|
|
{
|
|
|
|
|
print_spaces (depth);
|
|
|
|
|
printf (fmt, dep_name (d), file->name);
|
|
|
|
|
fflush (stdout);
|
|
|
|
|
}
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Here depth returns to the value it had when we were called. */
|
|
|
|
|
depth--;
|
|
|
|
|
|
|
|
|
|
if (file->double_colon && file->deps == 0)
|
|
|
|
|
{
|
|
|
|
|
must_make = 1;
|
1999-11-22 06:15:35 +00:00
|
|
|
|
DBF (DB_BASIC,
|
|
|
|
|
_("Target `%s' is double-colon and has no prerequisites.\n"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
2002-08-08 00:11:19 +00:00
|
|
|
|
else if (!noexist && file->is_target && !deps_changed && file->cmds == 0
|
|
|
|
|
&& !always_make_flag)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
|
|
|
|
must_make = 0;
|
1999-11-27 08:09:42 +00:00
|
|
|
|
DBF (DB_VERBOSE,
|
2007-11-04 21:54:00 +00:00
|
|
|
|
_("No recipe for `%s' and no prerequisites actually changed.\n"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
2002-08-08 00:11:19 +00:00
|
|
|
|
else if (!must_make && file->cmds != 0 && always_make_flag)
|
|
|
|
|
{
|
|
|
|
|
must_make = 1;
|
|
|
|
|
DBF (DB_VERBOSE, _("Making `%s' due to always-make flag.\n"));
|
|
|
|
|
}
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
if (!must_make)
|
|
|
|
|
{
|
1999-11-27 08:09:42 +00:00
|
|
|
|
if (ISDB (DB_VERBOSE))
|
1997-04-07 07:21:16 +00:00
|
|
|
|
{
|
1999-11-22 06:15:35 +00:00
|
|
|
|
print_spaces (depth);
|
|
|
|
|
printf (_("No need to remake target `%s'"), file->name);
|
|
|
|
|
if (!streq (file->name, file->hname))
|
|
|
|
|
printf (_("; using VPATH name `%s'"), file->hname);
|
|
|
|
|
puts (".");
|
|
|
|
|
fflush (stdout);
|
1997-04-07 07:21:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
1994-09-07 07:06:46 +00:00
|
|
|
|
notice_finished_file (file);
|
1997-04-07 07:21:16 +00:00
|
|
|
|
|
|
|
|
|
/* Since we don't need to remake the file, convert it to use the
|
|
|
|
|
VPATH filename if we found one. hfile will be either the
|
|
|
|
|
local name if no VPATH or the VPATH name if one was found. */
|
|
|
|
|
|
|
|
|
|
while (file)
|
|
|
|
|
{
|
|
|
|
|
file->name = file->hname;
|
|
|
|
|
file = file->prev;
|
|
|
|
|
}
|
|
|
|
|
|
1992-01-18 02:09:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-22 06:15:35 +00:00
|
|
|
|
DBF (DB_BASIC, _("Must remake target `%s'.\n"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
1997-08-18 18:11:04 +00:00
|
|
|
|
/* It needs to be remade. If it's VPATH and not reset via GPATH, toss the
|
1998-07-30 20:54:47 +00:00
|
|
|
|
VPATH. */
|
1997-04-07 07:21:16 +00:00
|
|
|
|
if (!streq(file->name, file->hname))
|
|
|
|
|
{
|
1999-11-22 06:15:35 +00:00
|
|
|
|
DB (DB_BASIC, (_(" Ignoring VPATH name `%s'.\n"), file->hname));
|
1997-08-18 18:11:04 +00:00
|
|
|
|
file->ignore_vpath = 1;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
1992-01-18 02:09:28 +00:00
|
|
|
|
/* Now, take appropriate actions to remake the file. */
|
|
|
|
|
remake_file (file);
|
|
|
|
|
|
|
|
|
|
if (file->command_state != cs_finished)
|
|
|
|
|
{
|
2007-11-04 21:54:00 +00:00
|
|
|
|
DBF (DB_VERBOSE, _("Recipe of `%s' is being run.\n"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (file->update_status)
|
|
|
|
|
{
|
1995-03-24 05:40:22 +00:00
|
|
|
|
case 2:
|
1999-11-22 06:15:35 +00:00
|
|
|
|
DBF (DB_BASIC, _("Failed to remake target file `%s'.\n"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case 0:
|
1999-11-22 06:15:35 +00:00
|
|
|
|
DBF (DB_BASIC, _("Successfully remade target file `%s'.\n"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
break;
|
1995-03-24 05:40:22 +00:00
|
|
|
|
case 1:
|
1999-11-22 06:15:35 +00:00
|
|
|
|
DBF (DB_BASIC, _("Target file `%s' needs remade under -q.\n"));
|
1995-03-24 05:40:22 +00:00
|
|
|
|
break;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
default:
|
1995-03-24 05:40:22 +00:00
|
|
|
|
assert (file->update_status >= 0 && file->update_status <= 2);
|
1994-09-10 15:04:57 +00:00
|
|
|
|
break;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file->updated = 1;
|
|
|
|
|
return file->update_status;
|
|
|
|
|
}
|
|
|
|
|
|
1992-10-25 06:16:09 +00:00
|
|
|
|
/* Set FILE's `updated' flag and re-check its mtime and the mtime's of all
|
|
|
|
|
files listed in its `also_make' member. Under -t, this function also
|
1995-04-08 18:52:42 +00:00
|
|
|
|
touches FILE.
|
|
|
|
|
|
|
|
|
|
On return, FILE->update_status will no longer be -1 if it was. */
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
notice_finished_file (struct file *file)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
|
|
|
|
struct dep *d;
|
1994-09-07 07:06:46 +00:00
|
|
|
|
int ran = file->command_state == cs_running;
|
2002-07-08 02:26:47 +00:00
|
|
|
|
int touched = 0;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
file->command_state = cs_finished;
|
|
|
|
|
file->updated = 1;
|
|
|
|
|
|
1992-08-20 18:10:20 +00:00
|
|
|
|
if (touch_flag
|
|
|
|
|
/* The update status will be:
|
2007-05-11 20:57:21 +00:00
|
|
|
|
-1 if this target was not remade;
|
1995-01-27 09:42:00 +00:00
|
|
|
|
0 if 0 or more commands (+ or ${MAKE}) were run and won;
|
1992-08-20 18:10:20 +00:00
|
|
|
|
1 if some commands were run and lost.
|
1995-01-27 09:42:00 +00:00
|
|
|
|
We touch the target if it has commands which either were not run
|
|
|
|
|
or won when they ran (i.e. status is 0). */
|
|
|
|
|
&& file->update_status == 0)
|
1992-08-20 18:10:20 +00:00
|
|
|
|
{
|
1992-09-09 20:46:57 +00:00
|
|
|
|
if (file->cmds != 0 && file->cmds->any_recurse)
|
|
|
|
|
{
|
|
|
|
|
/* If all the command lines were recursive,
|
|
|
|
|
we don't want to do the touching. */
|
|
|
|
|
unsigned int i;
|
|
|
|
|
for (i = 0; i < file->cmds->ncommand_lines; ++i)
|
1993-02-05 22:31:31 +00:00
|
|
|
|
if (!(file->cmds->lines_flags[i] & COMMANDS_RECURSE))
|
1992-09-09 20:46:57 +00:00
|
|
|
|
goto have_nonrecursing;
|
|
|
|
|
}
|
1992-08-20 18:10:20 +00:00
|
|
|
|
else
|
1992-09-09 20:46:57 +00:00
|
|
|
|
{
|
|
|
|
|
have_nonrecursing:
|
|
|
|
|
if (file->phony)
|
|
|
|
|
file->update_status = 0;
|
2003-03-25 00:15:25 +00:00
|
|
|
|
/* According to POSIX, -t doesn't affect targets with no cmds. */
|
|
|
|
|
else if (file->cmds != 0)
|
2002-07-08 02:26:47 +00:00
|
|
|
|
{
|
|
|
|
|
/* Should set file's modification date and do nothing else. */
|
|
|
|
|
file->update_status = touch_file (file);
|
|
|
|
|
|
|
|
|
|
/* Pretend we ran a real touch command, to suppress the
|
|
|
|
|
"`foo' is up to date" message. */
|
|
|
|
|
commands_started++;
|
|
|
|
|
|
|
|
|
|
/* Request for the timestamp to be updated (and distributed
|
|
|
|
|
to the double-colon entries). Simply setting ran=1 would
|
|
|
|
|
almost have done the trick, but messes up with the also_make
|
|
|
|
|
updating logic below. */
|
|
|
|
|
touched = 1;
|
|
|
|
|
}
|
1992-09-09 20:46:57 +00:00
|
|
|
|
}
|
1992-08-20 18:10:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-13 05:22:52 +00:00
|
|
|
|
if (file->mtime_before_update == UNKNOWN_MTIME)
|
1999-09-03 22:46:28 +00:00
|
|
|
|
file->mtime_before_update = file->last_mtime;
|
|
|
|
|
|
2002-07-08 02:26:47 +00:00
|
|
|
|
if ((ran && !file->phony) || touched)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
1999-10-13 07:00:23 +00:00
|
|
|
|
int i = 0;
|
1994-04-05 10:37:12 +00:00
|
|
|
|
|
2002-07-08 02:26:47 +00:00
|
|
|
|
/* If -n, -t, or -q and all the commands are recursive, we ran them so
|
1999-10-13 07:00:23 +00:00
|
|
|
|
really check the target's mtime again. Otherwise, assume the target
|
|
|
|
|
would have been updated. */
|
|
|
|
|
|
2009-09-16 17:07:01 +00:00
|
|
|
|
if ((question_flag || just_print_flag || touch_flag) && file->cmds)
|
1999-10-15 07:00:58 +00:00
|
|
|
|
{
|
|
|
|
|
for (i = file->cmds->ncommand_lines; i > 0; --i)
|
|
|
|
|
if (! (file->cmds->lines_flags[i-1] & COMMANDS_RECURSE))
|
|
|
|
|
break;
|
|
|
|
|
}
|
1999-10-13 07:00:23 +00:00
|
|
|
|
|
|
|
|
|
/* If there were no commands at all, it's always new. */
|
|
|
|
|
|
|
|
|
|
else if (file->is_target && file->cmds == 0)
|
|
|
|
|
i = 1;
|
|
|
|
|
|
2000-06-13 05:22:52 +00:00
|
|
|
|
file->last_mtime = i == 0 ? UNKNOWN_MTIME : NEW_MTIME;
|
2005-12-07 11:33:38 +00:00
|
|
|
|
}
|
1994-04-05 10:37:12 +00:00
|
|
|
|
|
2005-12-07 11:33:38 +00:00
|
|
|
|
if (file->double_colon)
|
|
|
|
|
{
|
|
|
|
|
/* If this is a double colon rule and it is the last one to be
|
|
|
|
|
updated, propagate the change of modification time to all the
|
|
|
|
|
double-colon entries for this file.
|
|
|
|
|
|
|
|
|
|
We do it on the last update because it is important to handle
|
|
|
|
|
individual entries as separate rules with separate timestamps
|
|
|
|
|
while they are treated as targets and then as one rule with the
|
|
|
|
|
unified timestamp when they are considered as a prerequisite
|
|
|
|
|
of some target. */
|
|
|
|
|
|
|
|
|
|
struct file *f;
|
|
|
|
|
FILE_TIMESTAMP max_mtime = file->last_mtime;
|
|
|
|
|
|
|
|
|
|
/* Check that all rules were updated and at the same time find
|
|
|
|
|
the max timestamp. We assume UNKNOWN_MTIME is newer then
|
|
|
|
|
any other value. */
|
|
|
|
|
for (f = file->double_colon; f != 0 && f->updated; f = f->prev)
|
|
|
|
|
if (max_mtime != UNKNOWN_MTIME
|
|
|
|
|
&& (f->last_mtime == UNKNOWN_MTIME || f->last_mtime > max_mtime))
|
|
|
|
|
max_mtime = f->last_mtime;
|
|
|
|
|
|
|
|
|
|
if (f == 0)
|
|
|
|
|
for (f = file->double_colon; f != 0; f = f->prev)
|
|
|
|
|
f->last_mtime = max_mtime;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1994-11-23 03:42:34 +00:00
|
|
|
|
if (ran && file->update_status != -1)
|
1992-10-25 06:16:09 +00:00
|
|
|
|
/* We actually tried to update FILE, which has
|
|
|
|
|
updated its also_make's as well (if it worked).
|
|
|
|
|
If it didn't work, it wouldn't work again for them.
|
|
|
|
|
So mark them as updated with the same status. */
|
|
|
|
|
for (d = file->also_make; d != 0; d = d->next)
|
|
|
|
|
{
|
|
|
|
|
d->file->command_state = cs_finished;
|
|
|
|
|
d->file->updated = 1;
|
|
|
|
|
d->file->update_status = file->update_status;
|
|
|
|
|
|
1994-09-07 07:06:46 +00:00
|
|
|
|
if (ran && !d->file->phony)
|
1992-10-25 06:16:09 +00:00
|
|
|
|
/* Fetch the new modification time.
|
|
|
|
|
We do this instead of just invalidating the cached time
|
|
|
|
|
so that a vpath_search can happen. Otherwise, it would
|
|
|
|
|
never be done because the target is already updated. */
|
2007-03-20 03:02:26 +00:00
|
|
|
|
f_mtime (d->file, 0);
|
1992-10-25 06:16:09 +00:00
|
|
|
|
}
|
1995-04-08 18:52:42 +00:00
|
|
|
|
else if (file->update_status == -1)
|
|
|
|
|
/* Nothing was done for FILE, but it needed nothing done.
|
|
|
|
|
So mark it now as "succeeded". */
|
|
|
|
|
file->update_status = 0;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-18 20:53:44 +00:00
|
|
|
|
/* Check whether another file (whose mtime is THIS_MTIME) needs updating on
|
|
|
|
|
account of a dependency which is file FILE. If it does, store 1 in
|
|
|
|
|
*MUST_MAKE_PTR. In the process, update any non-intermediate files that
|
|
|
|
|
FILE depends on (including FILE itself). Return nonzero if any updating
|
|
|
|
|
failed. */
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
static int
|
2002-10-14 21:54:04 +00:00
|
|
|
|
check_dep (struct file *file, unsigned int depth,
|
|
|
|
|
FILE_TIMESTAMP this_mtime, int *must_make_ptr)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
2009-06-14 06:08:11 +00:00
|
|
|
|
struct file *ofile;
|
2002-07-08 13:05:02 +00:00
|
|
|
|
struct dep *d;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
int dep_status = 0;
|
|
|
|
|
|
|
|
|
|
++depth;
|
2000-03-27 06:54:37 +00:00
|
|
|
|
start_updating (file);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2009-06-14 06:08:11 +00:00
|
|
|
|
/* We might change file if we find a different one via vpath;
|
|
|
|
|
remember this one to turn off updating. */
|
|
|
|
|
ofile = file;
|
|
|
|
|
|
2005-04-08 12:51:20 +00:00
|
|
|
|
if (file->phony || !file->intermediate)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
2006-11-18 20:53:44 +00:00
|
|
|
|
/* If this is a non-intermediate file, update it and record whether it
|
|
|
|
|
is newer than THIS_MTIME. */
|
1998-10-03 05:39:55 +00:00
|
|
|
|
FILE_TIMESTAMP mtime;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
dep_status = update_file (file, depth);
|
|
|
|
|
check_renamed (file);
|
|
|
|
|
mtime = file_mtime (file);
|
|
|
|
|
check_renamed (file);
|
2000-06-13 05:22:52 +00:00
|
|
|
|
if (mtime == NONEXISTENT_MTIME || mtime > this_mtime)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
*must_make_ptr = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1996-03-20 00:56:45 +00:00
|
|
|
|
/* FILE is an intermediate file. */
|
1998-10-03 05:39:55 +00:00
|
|
|
|
FILE_TIMESTAMP mtime;
|
1996-03-20 00:56:45 +00:00
|
|
|
|
|
1998-10-03 05:39:55 +00:00
|
|
|
|
if (!file->phony && file->cmds == 0 && !file->tried_implicit)
|
1996-03-20 00:56:45 +00:00
|
|
|
|
{
|
|
|
|
|
if (try_implicit_rule (file, depth))
|
1999-11-22 06:15:35 +00:00
|
|
|
|
DBF (DB_IMPLICIT, _("Found an implicit rule for `%s'.\n"));
|
1996-03-20 00:56:45 +00:00
|
|
|
|
else
|
1999-11-22 06:15:35 +00:00
|
|
|
|
DBF (DB_IMPLICIT, _("No implicit rule found for `%s'.\n"));
|
1996-03-20 00:56:45 +00:00
|
|
|
|
file->tried_implicit = 1;
|
|
|
|
|
}
|
1998-10-03 05:39:55 +00:00
|
|
|
|
if (file->cmds == 0 && !file->is_target
|
1996-03-20 00:56:45 +00:00
|
|
|
|
&& default_file != 0 && default_file->cmds != 0)
|
|
|
|
|
{
|
1999-11-22 06:15:35 +00:00
|
|
|
|
DBF (DB_IMPLICIT, _("Using default commands for `%s'.\n"));
|
1996-03-20 00:56:45 +00:00
|
|
|
|
file->cmds = default_file->cmds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
check_renamed (file);
|
|
|
|
|
mtime = file_mtime (file);
|
|
|
|
|
check_renamed (file);
|
2000-06-13 05:22:52 +00:00
|
|
|
|
if (mtime != NONEXISTENT_MTIME && mtime > this_mtime)
|
2006-11-18 20:53:44 +00:00
|
|
|
|
/* If the intermediate file actually exists and is newer, then we
|
|
|
|
|
should remake from it. */
|
1996-03-20 00:56:45 +00:00
|
|
|
|
*must_make_ptr = 1;
|
|
|
|
|
else
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
2006-11-18 20:53:44 +00:00
|
|
|
|
/* Otherwise, update all non-intermediate files we depend on, if
|
|
|
|
|
necessary, and see whether any of them is more recent than the
|
|
|
|
|
file on whose behalf we are checking. */
|
2009-06-10 02:21:09 +00:00
|
|
|
|
struct dep *ld;
|
2007-08-15 13:53:53 +00:00
|
|
|
|
int deps_running = 0;
|
|
|
|
|
|
2009-06-06 23:16:46 +00:00
|
|
|
|
/* If this target is not running, set it's state so that we check it
|
|
|
|
|
fresh. It could be it was checked as part of an order-only
|
2007-08-15 13:53:53 +00:00
|
|
|
|
prerequisite and so wasn't rebuilt then, but should be now. */
|
2009-06-06 23:16:46 +00:00
|
|
|
|
if (file->command_state != cs_running)
|
|
|
|
|
set_command_state (file, cs_not_started);
|
1996-03-20 00:56:45 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
ld = 0;
|
1996-03-20 00:56:45 +00:00
|
|
|
|
d = file->deps;
|
|
|
|
|
while (d != 0)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
2002-08-08 00:11:19 +00:00
|
|
|
|
int maybe_make;
|
|
|
|
|
|
2000-03-27 06:54:37 +00:00
|
|
|
|
if (is_updating (d->file))
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
1999-09-06 05:21:52 +00:00
|
|
|
|
error (NILF, _("Circular %s <- %s dependency dropped."),
|
1996-03-20 00:56:45 +00:00
|
|
|
|
file->name, d->file->name);
|
2009-06-10 02:21:09 +00:00
|
|
|
|
if (ld == 0)
|
1996-03-20 00:56:45 +00:00
|
|
|
|
{
|
|
|
|
|
file->deps = d->next;
|
2006-03-17 14:24:20 +00:00
|
|
|
|
free_dep (d);
|
1996-03-20 00:56:45 +00:00
|
|
|
|
d = file->deps;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-06-10 02:21:09 +00:00
|
|
|
|
ld->next = d->next;
|
2006-03-17 14:24:20 +00:00
|
|
|
|
free_dep (d);
|
2009-06-10 02:21:09 +00:00
|
|
|
|
d = ld->next;
|
1996-03-20 00:56:45 +00:00
|
|
|
|
}
|
|
|
|
|
continue;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-20 00:56:45 +00:00
|
|
|
|
d->file->parent = file;
|
2002-07-08 13:05:02 +00:00
|
|
|
|
maybe_make = *must_make_ptr;
|
1999-09-06 05:21:52 +00:00
|
|
|
|
dep_status |= check_dep (d->file, depth, this_mtime,
|
2002-07-08 13:05:02 +00:00
|
|
|
|
&maybe_make);
|
|
|
|
|
if (! d->ignore_mtime)
|
|
|
|
|
*must_make_ptr = maybe_make;
|
1996-03-20 00:56:45 +00:00
|
|
|
|
check_renamed (d->file);
|
|
|
|
|
if (dep_status != 0 && !keep_going_flag)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (d->file->command_state == cs_running
|
|
|
|
|
|| d->file->command_state == cs_deps_running)
|
2007-08-15 13:53:53 +00:00
|
|
|
|
deps_running = 1;
|
1996-03-20 00:56:45 +00:00
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
|
ld = d;
|
1996-03-20 00:56:45 +00:00
|
|
|
|
d = d->next;
|
|
|
|
|
}
|
2007-08-15 13:53:53 +00:00
|
|
|
|
|
|
|
|
|
if (deps_running)
|
|
|
|
|
/* Record that some of FILE's deps are still being made.
|
|
|
|
|
This tells the upper levels to wait on processing it until the
|
|
|
|
|
commands are finished. */
|
|
|
|
|
set_command_state (file, cs_deps_running);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-27 06:54:37 +00:00
|
|
|
|
finish_updating (file);
|
2009-06-14 06:08:11 +00:00
|
|
|
|
finish_updating (ofile);
|
|
|
|
|
|
1992-01-18 02:09:28 +00:00
|
|
|
|
return dep_status;
|
|
|
|
|
}
|
|
|
|
|
|
1992-08-20 18:10:20 +00:00
|
|
|
|
/* Touch FILE. Return zero if successful, one if not. */
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
#define TOUCH_ERROR(call) return (perror_with_name (call, file->name), 1)
|
|
|
|
|
|
|
|
|
|
static int
|
2002-10-14 21:54:04 +00:00
|
|
|
|
touch_file (struct file *file)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
|
|
|
|
if (!silent_flag)
|
1995-11-26 01:38:10 +00:00
|
|
|
|
message (0, "touch %s", file->name);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
#ifndef NO_ARCHIVES
|
|
|
|
|
if (ar_name (file->name))
|
|
|
|
|
return ar_touch (file->name);
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
int fd = open (file->name, O_RDWR | O_CREAT, 0666);
|
|
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
|
TOUCH_ERROR ("touch: open: ");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
struct stat statbuf;
|
2006-04-09 22:09:24 +00:00
|
|
|
|
char buf = 'x';
|
2003-01-30 05:22:52 +00:00
|
|
|
|
int e;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2003-01-30 05:22:52 +00:00
|
|
|
|
EINTRLOOP (e, fstat (fd, &statbuf));
|
|
|
|
|
if (e < 0)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
TOUCH_ERROR ("touch: fstat: ");
|
|
|
|
|
/* Rewrite character 0 same as it already is. */
|
|
|
|
|
if (read (fd, &buf, 1) < 0)
|
|
|
|
|
TOUCH_ERROR ("touch: read: ");
|
|
|
|
|
if (lseek (fd, 0L, 0) < 0L)
|
|
|
|
|
TOUCH_ERROR ("touch: lseek: ");
|
|
|
|
|
if (write (fd, &buf, 1) < 0)
|
|
|
|
|
TOUCH_ERROR ("touch: write: ");
|
|
|
|
|
/* If file length was 0, we just
|
|
|
|
|
changed it, so change it back. */
|
|
|
|
|
if (statbuf.st_size == 0)
|
|
|
|
|
{
|
|
|
|
|
(void) close (fd);
|
|
|
|
|
fd = open (file->name, O_RDWR | O_TRUNC, 0666);
|
|
|
|
|
if (fd < 0)
|
|
|
|
|
TOUCH_ERROR ("touch: open: ");
|
|
|
|
|
}
|
|
|
|
|
(void) close (fd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Having checked and updated the dependencies of FILE,
|
|
|
|
|
do whatever is appropriate to remake FILE itself.
|
|
|
|
|
Return the status from executing FILE's commands. */
|
|
|
|
|
|
|
|
|
|
static void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
remake_file (struct file *file)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
|
|
|
|
if (file->cmds == 0)
|
|
|
|
|
{
|
|
|
|
|
if (file->phony)
|
|
|
|
|
/* Phony target. Pretend it succeeded. */
|
|
|
|
|
file->update_status = 0;
|
|
|
|
|
else if (file->is_target)
|
|
|
|
|
/* This is a nonexistent target file we cannot make.
|
|
|
|
|
Pretend it was successfully remade. */
|
|
|
|
|
file->update_status = 0;
|
|
|
|
|
else
|
2000-01-23 07:05:16 +00:00
|
|
|
|
{
|
|
|
|
|
/* This is a dependency file we cannot remake. Fail. */
|
2004-05-16 19:16:52 +00:00
|
|
|
|
if (!rebuilding_makefiles || !file->dontcare)
|
|
|
|
|
complain (file);
|
2000-01-23 07:05:16 +00:00
|
|
|
|
file->update_status = 2;
|
|
|
|
|
}
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
chop_commands (file->cmds);
|
|
|
|
|
|
1999-10-13 07:00:23 +00:00
|
|
|
|
/* The normal case: start some commands. */
|
1992-08-20 18:10:20 +00:00
|
|
|
|
if (!touch_flag || file->cmds->any_recurse)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
|
|
|
|
execute_file_commands (file);
|
|
|
|
|
return;
|
|
|
|
|
}
|
1999-10-13 07:00:23 +00:00
|
|
|
|
|
|
|
|
|
/* This tells notice_finished_file it is ok to touch the file. */
|
|
|
|
|
file->update_status = 0;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1992-10-25 06:16:09 +00:00
|
|
|
|
/* This does the touching under -t. */
|
1992-01-18 02:09:28 +00:00
|
|
|
|
notice_finished_file (file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return the mtime of a file, given a `struct file'.
|
1992-12-09 20:34:36 +00:00
|
|
|
|
Caches the time in the struct file to avoid excess stat calls.
|
|
|
|
|
|
|
|
|
|
If the file is not found, and SEARCH is nonzero, VPATH searching and
|
|
|
|
|
replacement is done. If that fails, a library (-lLIBNAME) is tried and
|
|
|
|
|
the library's actual name (/lib/libLIBNAME.a, etc.) is substituted into
|
|
|
|
|
FILE. */
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
1998-10-03 05:39:55 +00:00
|
|
|
|
FILE_TIMESTAMP
|
2002-10-14 21:54:04 +00:00
|
|
|
|
f_mtime (struct file *file, int search)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
1998-10-03 05:39:55 +00:00
|
|
|
|
FILE_TIMESTAMP mtime;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
/* File's mtime is not known; must get it from the system. */
|
|
|
|
|
|
|
|
|
|
#ifndef NO_ARCHIVES
|
|
|
|
|
if (ar_name (file->name))
|
|
|
|
|
{
|
|
|
|
|
/* This file is an archive-member reference. */
|
|
|
|
|
|
|
|
|
|
char *arname, *memname;
|
|
|
|
|
struct file *arfile;
|
2000-06-13 05:22:52 +00:00
|
|
|
|
time_t member_date;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
|
|
|
|
/* Find the archive's name. */
|
|
|
|
|
ar_parse_name (file->name, &arname, &memname);
|
|
|
|
|
|
|
|
|
|
/* Find the modification time of the archive itself.
|
|
|
|
|
Also allow for its name to be changed via VPATH search. */
|
|
|
|
|
arfile = lookup_file (arname);
|
|
|
|
|
if (arfile == 0)
|
2007-03-20 03:02:26 +00:00
|
|
|
|
arfile = enter_file (strcache_add (arname));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
mtime = f_mtime (arfile, search);
|
|
|
|
|
check_renamed (arfile);
|
1998-07-30 20:54:47 +00:00
|
|
|
|
if (search && strcmp (arfile->hname, arname))
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
|
|
|
|
/* The archive's name has changed.
|
|
|
|
|
Change the archive-member reference accordingly. */
|
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
|
char *name;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
unsigned int arlen, memlen;
|
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
arlen = strlen (arfile->hname);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
memlen = strlen (memname);
|
|
|
|
|
|
2006-04-09 22:09:24 +00:00
|
|
|
|
name = xmalloc (arlen + 1 + memlen + 2);
|
2007-03-20 03:02:26 +00:00
|
|
|
|
memcpy (name, arfile->hname, arlen);
|
1998-07-30 20:54:47 +00:00
|
|
|
|
name[arlen] = '(';
|
2006-04-09 22:09:24 +00:00
|
|
|
|
memcpy (name + arlen + 1, memname, memlen);
|
1998-07-30 20:54:47 +00:00
|
|
|
|
name[arlen + 1 + memlen] = ')';
|
|
|
|
|
name[arlen + 1 + memlen + 1] = '\0';
|
|
|
|
|
|
|
|
|
|
/* If the archive was found with GPATH, make the change permanent;
|
|
|
|
|
otherwise defer it until later. */
|
|
|
|
|
if (arfile->name == arfile->hname)
|
|
|
|
|
rename_file (file, name);
|
|
|
|
|
else
|
|
|
|
|
rehash_file (file, name);
|
|
|
|
|
check_renamed (file);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
free (arname);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2000-07-30 18:26:42 +00:00
|
|
|
|
file->low_resolution_time = 1;
|
|
|
|
|
|
2000-06-13 05:22:52 +00:00
|
|
|
|
if (mtime == NONEXISTENT_MTIME)
|
2000-06-07 05:43:37 +00:00
|
|
|
|
/* The archive doesn't exist, so its members don't exist either. */
|
2000-06-13 05:22:52 +00:00
|
|
|
|
return NONEXISTENT_MTIME;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2000-06-13 05:22:52 +00:00
|
|
|
|
member_date = ar_member_date (file->hname);
|
|
|
|
|
mtime = (member_date == (time_t) -1
|
|
|
|
|
? NONEXISTENT_MTIME
|
|
|
|
|
: file_timestamp_cons (file->hname, member_date, 0));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
mtime = name_mtime (file->name);
|
|
|
|
|
|
2000-06-13 05:22:52 +00:00
|
|
|
|
if (mtime == NONEXISTENT_MTIME && search && !file->ignore_vpath)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
|
|
|
|
/* If name_mtime failed, search VPATH. */
|
2009-11-12 16:42:36 +00:00
|
|
|
|
const char *name = vpath_search (file->name, &mtime, NULL, NULL);
|
2007-03-20 03:02:26 +00:00
|
|
|
|
if (name
|
1992-08-27 23:29:25 +00:00
|
|
|
|
/* Last resort, is it a library (-lxxx)? */
|
2007-03-20 03:02:26 +00:00
|
|
|
|
|| (file->name[0] == '-' && file->name[1] == 'l'
|
|
|
|
|
&& (name = library_search (file->name, &mtime)) != 0))
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
2000-06-13 05:22:52 +00:00
|
|
|
|
if (mtime != UNKNOWN_MTIME)
|
|
|
|
|
/* vpath_search and library_search store UNKNOWN_MTIME
|
1993-02-08 22:56:09 +00:00
|
|
|
|
if they didn't need to do a stat call for their work. */
|
|
|
|
|
file->last_mtime = mtime;
|
1997-08-18 18:11:04 +00:00
|
|
|
|
|
|
|
|
|
/* If we found it in VPATH, see if it's in GPATH too; if so,
|
|
|
|
|
change the name right now; if not, defer until after the
|
|
|
|
|
dependencies are updated. */
|
|
|
|
|
if (gpath_search (name, strlen(name) - strlen(file->name) - 1))
|
|
|
|
|
{
|
|
|
|
|
rename_file (file, name);
|
|
|
|
|
check_renamed (file);
|
|
|
|
|
return file_mtime (file);
|
|
|
|
|
}
|
|
|
|
|
|
1997-04-07 07:21:16 +00:00
|
|
|
|
rehash_file (file, name);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
check_renamed (file);
|
2006-02-06 16:21:59 +00:00
|
|
|
|
/* If the result of a vpath search is -o or -W, preserve it.
|
|
|
|
|
Otherwise, find the mtime of the resulting file. */
|
|
|
|
|
if (mtime != OLD_MTIME && mtime != NEW_MTIME)
|
|
|
|
|
mtime = name_mtime (name);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-02-06 16:21:59 +00:00
|
|
|
|
/* Files can have bogus timestamps that nothing newly made will be
|
|
|
|
|
"newer" than. Updating their dependents could just result in loops.
|
|
|
|
|
So notify the user of the anomaly with a warning.
|
1997-08-18 18:11:04 +00:00
|
|
|
|
|
2006-02-06 16:21:59 +00:00
|
|
|
|
We only need to do this once, for now. */
|
1996-02-29 00:27:25 +00:00
|
|
|
|
|
2006-02-06 16:21:59 +00:00
|
|
|
|
if (!clock_skew_detected
|
|
|
|
|
&& mtime != NONEXISTENT_MTIME && mtime != NEW_MTIME
|
|
|
|
|
&& !file->updated)
|
|
|
|
|
{
|
|
|
|
|
static FILE_TIMESTAMP adjusted_now;
|
2000-06-13 05:22:52 +00:00
|
|
|
|
|
2006-02-06 16:21:59 +00:00
|
|
|
|
FILE_TIMESTAMP adjusted_mtime = mtime;
|
2000-06-07 05:43:37 +00:00
|
|
|
|
|
2000-06-19 21:22:44 +00:00
|
|
|
|
#if defined(WINDOWS32) || defined(__MSDOS__)
|
2006-02-06 16:21:59 +00:00
|
|
|
|
/* Experimentation has shown that FAT filesystems can set file times
|
|
|
|
|
up to 3 seconds into the future! Play it safe. */
|
2000-11-17 06:59:08 +00:00
|
|
|
|
|
|
|
|
|
#define FAT_ADJ_OFFSET (FILE_TIMESTAMP) 3
|
|
|
|
|
|
2006-02-06 16:21:59 +00:00
|
|
|
|
FILE_TIMESTAMP adjustment = FAT_ADJ_OFFSET << FILE_TIMESTAMP_LO_BITS;
|
|
|
|
|
if (ORDINARY_MTIME_MIN + adjustment <= adjusted_mtime)
|
|
|
|
|
adjusted_mtime -= adjustment;
|
2003-03-24 23:14:15 +00:00
|
|
|
|
#elif defined(__EMX__)
|
2006-02-06 16:21:59 +00:00
|
|
|
|
/* FAT filesystems round time to the nearest even second!
|
|
|
|
|
Allow for any file (NTFS or FAT) to perhaps suffer from this
|
|
|
|
|
brain damage. */
|
|
|
|
|
FILE_TIMESTAMP adjustment = (((FILE_TIMESTAMP_S (adjusted_mtime) & 1) == 0
|
|
|
|
|
&& FILE_TIMESTAMP_NS (adjusted_mtime) == 0)
|
|
|
|
|
? (FILE_TIMESTAMP) 1 << FILE_TIMESTAMP_LO_BITS
|
|
|
|
|
: 0);
|
2000-06-07 05:43:37 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2006-02-06 16:21:59 +00:00
|
|
|
|
/* If the file's time appears to be in the future, update our
|
|
|
|
|
concept of the present and try once more. */
|
|
|
|
|
if (adjusted_now < adjusted_mtime)
|
|
|
|
|
{
|
|
|
|
|
int resolution;
|
|
|
|
|
FILE_TIMESTAMP now = file_timestamp_now (&resolution);
|
|
|
|
|
adjusted_now = now + (resolution - 1);
|
|
|
|
|
if (adjusted_now < adjusted_mtime)
|
|
|
|
|
{
|
2000-07-07 17:34:56 +00:00
|
|
|
|
#ifdef NO_FLOAT
|
2006-02-06 16:21:59 +00:00
|
|
|
|
error (NILF, _("Warning: File `%s' has modification time in the future"),
|
|
|
|
|
file->name);
|
2000-07-07 17:34:56 +00:00
|
|
|
|
#else
|
2006-02-06 16:21:59 +00:00
|
|
|
|
double from_now =
|
|
|
|
|
(FILE_TIMESTAMP_S (mtime) - FILE_TIMESTAMP_S (now)
|
|
|
|
|
+ ((FILE_TIMESTAMP_NS (mtime) - FILE_TIMESTAMP_NS (now))
|
|
|
|
|
/ 1e9));
|
2007-11-05 14:15:19 +00:00
|
|
|
|
char from_now_string[100];
|
|
|
|
|
|
|
|
|
|
if (from_now >= 99 && from_now <= ULONG_MAX)
|
|
|
|
|
sprintf (from_now_string, "%lu", (unsigned long) from_now);
|
|
|
|
|
else
|
|
|
|
|
sprintf (from_now_string, "%.2g", from_now);
|
|
|
|
|
error (NILF, _("Warning: File `%s' has modification time %s s in the future"),
|
|
|
|
|
file->name, from_now_string);
|
2000-07-07 17:34:56 +00:00
|
|
|
|
#endif
|
2006-02-06 16:21:59 +00:00
|
|
|
|
clock_skew_detected = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1996-02-29 00:27:25 +00:00
|
|
|
|
|
1996-03-01 19:14:35 +00:00
|
|
|
|
/* Store the mtime into all the entries for this file. */
|
|
|
|
|
if (file->double_colon)
|
|
|
|
|
file = file->double_colon;
|
1999-04-09 05:57:35 +00:00
|
|
|
|
|
1996-03-01 19:14:35 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
1999-04-09 05:57:35 +00:00
|
|
|
|
/* If this file is not implicit but it is intermediate then it was
|
|
|
|
|
made so by the .INTERMEDIATE target. If this file has never
|
|
|
|
|
been built by us but was found now, it existed before make
|
|
|
|
|
started. So, turn off the intermediate bit so make doesn't
|
|
|
|
|
delete it, since it didn't create it. */
|
2000-06-13 05:22:52 +00:00
|
|
|
|
if (mtime != NONEXISTENT_MTIME && file->command_state == cs_not_started
|
|
|
|
|
&& file->command_state == cs_not_started
|
1999-04-09 05:57:35 +00:00
|
|
|
|
&& !file->tried_implicit && file->intermediate)
|
|
|
|
|
file->intermediate = 0;
|
|
|
|
|
|
1996-03-01 19:14:35 +00:00
|
|
|
|
file->last_mtime = mtime;
|
|
|
|
|
file = file->prev;
|
1999-04-09 05:57:35 +00:00
|
|
|
|
}
|
|
|
|
|
while (file != 0);
|
1996-03-01 19:14:35 +00:00
|
|
|
|
|
1992-01-18 02:09:28 +00:00
|
|
|
|
return mtime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Return the mtime of the file or archive-member reference NAME. */
|
|
|
|
|
|
2005-02-28 07:48:22 +00:00
|
|
|
|
/* First, we check with stat(). If the file does not exist, then we return
|
|
|
|
|
NONEXISTENT_MTIME. If it does, and the symlink check flag is set, then
|
|
|
|
|
examine each indirection of the symlink and find the newest mtime.
|
|
|
|
|
This causes one duplicate stat() when -L is being used, but the code is
|
|
|
|
|
much cleaner. */
|
|
|
|
|
|
1998-10-03 05:39:55 +00:00
|
|
|
|
static FILE_TIMESTAMP
|
2007-03-20 03:02:26 +00:00
|
|
|
|
name_mtime (const char *name)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
2005-02-28 07:48:22 +00:00
|
|
|
|
FILE_TIMESTAMP mtime;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
struct stat st;
|
2003-01-30 05:22:52 +00:00
|
|
|
|
int e;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2003-01-30 05:22:52 +00:00
|
|
|
|
EINTRLOOP (e, stat (name, &st));
|
2005-06-25 23:00:17 +00:00
|
|
|
|
if (e == 0)
|
|
|
|
|
mtime = FILE_TIMESTAMP_STAT_MODTIME (name, st);
|
|
|
|
|
else if (errno == ENOENT || errno == ENOTDIR)
|
|
|
|
|
mtime = NONEXISTENT_MTIME;
|
|
|
|
|
else
|
2001-06-01 03:56:50 +00:00
|
|
|
|
{
|
2005-06-25 23:00:17 +00:00
|
|
|
|
perror_with_name ("stat: ", name);
|
2001-06-01 03:56:50 +00:00
|
|
|
|
return NONEXISTENT_MTIME;
|
|
|
|
|
}
|
2005-06-25 23:00:17 +00:00
|
|
|
|
|
|
|
|
|
/* If we get here we either found it, or it doesn't exist.
|
|
|
|
|
If it doesn't exist see if we can use a symlink mtime instead. */
|
2005-02-28 07:48:22 +00:00
|
|
|
|
|
|
|
|
|
#ifdef MAKE_SYMLINKS
|
|
|
|
|
#ifndef S_ISLNK
|
|
|
|
|
# define S_ISLNK(_m) (((_m)&S_IFMT)==S_IFLNK)
|
|
|
|
|
#endif
|
|
|
|
|
if (check_symlink_flag)
|
|
|
|
|
{
|
|
|
|
|
PATH_VAR (lpath);
|
|
|
|
|
|
|
|
|
|
/* Check each symbolic link segment (if any). Find the latest mtime
|
|
|
|
|
amongst all of them (and the target file of course).
|
|
|
|
|
Note that we have already successfully dereferenced all the links
|
|
|
|
|
above. So, if we run into any error trying to lstat(), or
|
|
|
|
|
readlink(), or whatever, something bizarre-o happened. Just give up
|
|
|
|
|
and use whatever mtime we've already computed at that point. */
|
|
|
|
|
strcpy (lpath, name);
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
FILE_TIMESTAMP ltime;
|
|
|
|
|
PATH_VAR (lbuf);
|
|
|
|
|
long llen;
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
EINTRLOOP (e, lstat (lpath, &st));
|
|
|
|
|
if (e)
|
|
|
|
|
{
|
2005-06-25 23:00:17 +00:00
|
|
|
|
/* Just take what we have so far. */
|
|
|
|
|
if (errno != ENOENT && errno != ENOTDIR)
|
|
|
|
|
perror_with_name ("lstat: ", lpath);
|
2005-02-28 07:48:22 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If this is not a symlink, we're done (we started with the real
|
|
|
|
|
file's mtime so we don't need to test it again). */
|
|
|
|
|
if (!S_ISLNK (st.st_mode))
|
|
|
|
|
break;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2005-02-28 07:48:22 +00:00
|
|
|
|
/* If this mtime is newer than what we had, keep the new one. */
|
|
|
|
|
ltime = FILE_TIMESTAMP_STAT_MODTIME (lpath, st);
|
|
|
|
|
if (ltime > mtime)
|
|
|
|
|
mtime = ltime;
|
|
|
|
|
|
|
|
|
|
/* Set up to check the file pointed to by this link. */
|
|
|
|
|
EINTRLOOP (llen, readlink (lpath, lbuf, GET_PATH_MAX));
|
|
|
|
|
if (llen < 0)
|
|
|
|
|
{
|
|
|
|
|
/* Eh? Just take what we have. */
|
|
|
|
|
perror_with_name ("readlink: ", lpath);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
lbuf[llen] = '\0';
|
|
|
|
|
|
|
|
|
|
/* If the target is fully-qualified or the source is just a
|
|
|
|
|
filename, then the new path is the target. Otherwise it's the
|
|
|
|
|
source directory plus the target. */
|
|
|
|
|
if (lbuf[0] == '/' || (p = strrchr (lpath, '/')) == NULL)
|
|
|
|
|
strcpy (lpath, lbuf);
|
|
|
|
|
else if ((p - lpath) + llen + 2 > GET_PATH_MAX)
|
|
|
|
|
/* Eh? Path too long! Again, just go with what we have. */
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
/* Create the next step in the symlink chain. */
|
|
|
|
|
strcpy (p+1, lbuf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return mtime;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1992-08-27 23:29:25 +00:00
|
|
|
|
/* Search for a library file specified as -lLIBNAME, searching for a
|
|
|
|
|
suitable library file in the system library directories and the VPATH
|
|
|
|
|
directories. */
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
static const char *
|
|
|
|
|
library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr)
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
1992-08-27 23:29:25 +00:00
|
|
|
|
static char *dirs[] =
|
1992-01-18 02:09:28 +00:00
|
|
|
|
{
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-09 18:02:06 +00:00
|
|
|
|
#ifndef _AMIGA
|
1992-08-27 23:29:25 +00:00
|
|
|
|
"/lib",
|
1992-12-09 20:34:36 +00:00
|
|
|
|
"/usr/lib",
|
1996-05-22 21:51:45 +00:00
|
|
|
|
#endif
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#if defined(WINDOWS32) && !defined(LIBDIR)
|
1996-05-22 21:51:45 +00:00
|
|
|
|
/*
|
|
|
|
|
* This is completely up to the user at product install time. Just define
|
|
|
|
|
* a placeholder.
|
|
|
|
|
*/
|
|
|
|
|
#define LIBDIR "."
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-09 18:02:06 +00:00
|
|
|
|
#endif
|
1992-08-27 23:29:25 +00:00
|
|
|
|
LIBDIR, /* Defined by configuration. */
|
|
|
|
|
0
|
|
|
|
|
};
|
|
|
|
|
|
2009-06-07 17:40:06 +00:00
|
|
|
|
const char *file = 0;
|
|
|
|
|
char *libpatterns;
|
1998-10-03 05:39:55 +00:00
|
|
|
|
FILE_TIMESTAMP mtime;
|
1992-08-27 23:29:25 +00:00
|
|
|
|
|
1999-02-22 07:23:30 +00:00
|
|
|
|
/* Loop variables for the libpatterns value. */
|
2007-03-20 03:02:26 +00:00
|
|
|
|
char *p;
|
|
|
|
|
const char *p2;
|
1999-10-15 07:00:58 +00:00
|
|
|
|
unsigned int len;
|
2009-06-07 17:40:06 +00:00
|
|
|
|
unsigned int liblen;
|
1992-12-09 20:34:36 +00:00
|
|
|
|
|
2009-11-12 16:42:36 +00:00
|
|
|
|
/* Information about the earliest (in the vpath sequence) match. */
|
|
|
|
|
unsigned int best_vpath, best_path;
|
|
|
|
|
unsigned int std_dirs = 0;
|
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
char **dp;
|
1992-12-09 20:34:36 +00:00
|
|
|
|
|
2009-06-07 17:40:06 +00:00
|
|
|
|
libpatterns = xstrdup (variable_expand ("$(.LIBPATTERNS)"));
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2009-06-07 17:40:06 +00:00
|
|
|
|
/* Skip the '-l'. */
|
|
|
|
|
lib += 2;
|
|
|
|
|
liblen = strlen (lib);
|
1992-01-18 02:09:28 +00:00
|
|
|
|
|
2009-11-12 16:42:36 +00:00
|
|
|
|
/* Loop through all the patterns in .LIBPATTERNS, and search on each one.
|
|
|
|
|
To implement the linker-compatible behavior we have to search through
|
|
|
|
|
all entries in .LIBPATTERNS and choose the "earliest" one. */
|
1999-02-22 07:23:30 +00:00
|
|
|
|
p2 = libpatterns;
|
|
|
|
|
while ((p = find_next_token (&p2, &len)) != 0)
|
|
|
|
|
{
|
|
|
|
|
static char *buf = NULL;
|
2004-02-24 13:50:19 +00:00
|
|
|
|
static unsigned int buflen = 0;
|
1999-02-22 07:23:30 +00:00
|
|
|
|
static int libdir_maxlen = -1;
|
|
|
|
|
char *libbuf = variable_expand ("");
|
1997-04-07 07:21:16 +00:00
|
|
|
|
|
2009-06-07 17:40:06 +00:00
|
|
|
|
/* Expand the pattern using LIB as a replacement. */
|
1997-04-07 07:21:16 +00:00
|
|
|
|
{
|
1999-02-22 07:23:30 +00:00
|
|
|
|
char c = p[len];
|
|
|
|
|
char *p3, *p4;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
|
1999-02-22 07:23:30 +00:00
|
|
|
|
p[len] = '\0';
|
|
|
|
|
p3 = find_percent (p);
|
|
|
|
|
if (!p3)
|
1997-04-07 07:21:16 +00:00
|
|
|
|
{
|
2009-06-07 17:40:06 +00:00
|
|
|
|
/* Give a warning if there is no pattern. */
|
1999-07-28 06:23:37 +00:00
|
|
|
|
error (NILF, _(".LIBPATTERNS element `%s' is not a pattern"), p);
|
2009-06-07 17:40:06 +00:00
|
|
|
|
p[len] = c;
|
1999-02-22 07:23:30 +00:00
|
|
|
|
continue;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
}
|
1999-02-22 07:23:30 +00:00
|
|
|
|
p4 = variable_buffer_output (libbuf, p, p3-p);
|
2009-06-07 17:40:06 +00:00
|
|
|
|
p4 = variable_buffer_output (p4, lib, liblen);
|
1999-02-22 07:23:30 +00:00
|
|
|
|
p4 = variable_buffer_output (p4, p3+1, len - (p3-p));
|
|
|
|
|
p[len] = c;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-02-22 07:23:30 +00:00
|
|
|
|
/* Look first for `libNAME.a' in the current directory. */
|
|
|
|
|
mtime = name_mtime (libbuf);
|
2000-06-13 05:22:52 +00:00
|
|
|
|
if (mtime != NONEXISTENT_MTIME)
|
1992-12-09 20:34:36 +00:00
|
|
|
|
{
|
1993-02-08 22:56:09 +00:00
|
|
|
|
if (mtime_ptr != 0)
|
|
|
|
|
*mtime_ptr = mtime;
|
2009-06-07 17:40:06 +00:00
|
|
|
|
file = strcache_add (libbuf);
|
2009-11-12 16:42:36 +00:00
|
|
|
|
/* This by definition will have the best index, so stop now. */
|
|
|
|
|
break;
|
1992-12-09 20:34:36 +00:00
|
|
|
|
}
|
1999-02-22 07:23:30 +00:00
|
|
|
|
|
|
|
|
|
/* Now try VPATH search on that. */
|
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
{
|
2009-11-12 16:42:36 +00:00
|
|
|
|
unsigned int vpath_index, path_index;
|
|
|
|
|
const char* f = vpath_search (libbuf, mtime_ptr ? &mtime : NULL,
|
|
|
|
|
&vpath_index, &path_index);
|
|
|
|
|
if (f)
|
|
|
|
|
{
|
|
|
|
|
/* If we have a better match, record it. */
|
|
|
|
|
if (file == 0 ||
|
|
|
|
|
vpath_index < best_vpath ||
|
|
|
|
|
(vpath_index == best_vpath && path_index < best_path))
|
|
|
|
|
{
|
|
|
|
|
file = f;
|
|
|
|
|
best_vpath = vpath_index;
|
|
|
|
|
best_path = path_index;
|
|
|
|
|
|
|
|
|
|
if (mtime_ptr != 0)
|
|
|
|
|
*mtime_ptr = mtime;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-03-20 03:02:26 +00:00
|
|
|
|
}
|
1999-02-22 07:23:30 +00:00
|
|
|
|
|
|
|
|
|
/* Now try the standard set of directories. */
|
|
|
|
|
|
|
|
|
|
if (!buflen)
|
2009-11-12 16:42:36 +00:00
|
|
|
|
{
|
|
|
|
|
for (dp = dirs; *dp != 0; ++dp)
|
|
|
|
|
{
|
|
|
|
|
int l = strlen (*dp);
|
|
|
|
|
if (l > libdir_maxlen)
|
|
|
|
|
libdir_maxlen = l;
|
|
|
|
|
std_dirs++;
|
|
|
|
|
}
|
|
|
|
|
buflen = strlen (libbuf);
|
|
|
|
|
buf = xmalloc(libdir_maxlen + buflen + 2);
|
|
|
|
|
}
|
1999-02-22 07:23:30 +00:00
|
|
|
|
else if (buflen < strlen (libbuf))
|
2009-11-12 16:42:36 +00:00
|
|
|
|
{
|
|
|
|
|
buflen = strlen (libbuf);
|
|
|
|
|
buf = xrealloc (buf, libdir_maxlen + buflen + 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
/* Use the last std_dirs index for standard directories. This
|
|
|
|
|
was it will always be greater than the VPATH index. */
|
|
|
|
|
unsigned int vpath_index = ~((unsigned int)0) - std_dirs;
|
|
|
|
|
|
|
|
|
|
for (dp = dirs; *dp != 0; ++dp)
|
|
|
|
|
{
|
|
|
|
|
sprintf (buf, "%s/%s", *dp, libbuf);
|
|
|
|
|
mtime = name_mtime (buf);
|
|
|
|
|
if (mtime != NONEXISTENT_MTIME)
|
|
|
|
|
{
|
|
|
|
|
if (file == 0 || vpath_index < best_vpath)
|
|
|
|
|
{
|
|
|
|
|
file = strcache_add (buf);
|
|
|
|
|
best_vpath = vpath_index;
|
|
|
|
|
|
|
|
|
|
if (mtime_ptr != 0)
|
|
|
|
|
*mtime_ptr = mtime;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vpath_index++;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-02-22 07:23:30 +00:00
|
|
|
|
|
1992-12-09 20:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-07 17:40:06 +00:00
|
|
|
|
free (libpatterns);
|
|
|
|
|
return file;
|
1992-01-18 02:09:28 +00:00
|
|
|
|
}
|