summaryrefslogtreecommitdiff
path: root/remake.c
diff options
context:
space:
mode:
Diffstat (limited to 'remake.c')
-rw-r--r--remake.c802
1 files changed, 408 insertions, 394 deletions
diff --git a/remake.c b/remake.c
index 27d2550..138cdc6 100644
--- a/remake.c
+++ b/remake.c
@@ -1,7 +1,5 @@
/* Basic dependency engine for GNU Make.
-Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
-1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-2010 Free Software Foundation, Inc.
+Copyright (C) 1988-2013 Free Software Foundation, Inc.
This file is part of GNU Make.
GNU Make is free software; you can redistribute it and/or modify it under the
@@ -16,7 +14,7 @@ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "make.h"
+#include "makeint.h"
#include "filedef.h"
#include "job.h"
#include "commands.h"
@@ -43,7 +41,7 @@ extern int try_implicit_rule (struct file *file, unsigned int depth);
/* The test for circular dependencies is based on the 'updating' bit in
- `struct file'. However, double colon targets have seperate `struct
+ 'struct file'. However, double colon targets have separate '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))\
@@ -64,35 +62,35 @@ 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 enum update_status touch_file (struct file *file);
static void remake_file (struct file *file);
static FILE_TIMESTAMP name_mtime (const char *name);
static const char *library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr);
-/* Remake all the goals in the `struct dep' chain GOALS. Return -1 if nothing
+/* 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.
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. */
+ one goal whose 'changed' member is nonzero is successfully made. */
-int
+enum update_status
update_goal_chain (struct dep *goals)
{
int t = touch_flag, q = question_flag, n = just_print_flag;
- int status = -1;
+ enum update_status status = us_none;
-#define MTIME(file) (rebuilding_makefiles ? file_mtime_no_search (file) \
- : file_mtime (file))
+#define MTIME(file) (rebuilding_makefiles ? file_mtime_no_search (file) \
+ : file_mtime (file))
/* Duplicate the chain so we can remove things from it. */
goals = copy_dep_chain (goals);
{
- /* Clear the `changed' flag of each goal in the chain.
+ /* 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. */
@@ -122,44 +120,44 @@ update_goal_chain (struct dep *goals)
lastgoal = 0;
g = goals;
while (g != 0)
- {
- /* Iterate over all double-colon entries for this file. */
- struct file *file;
- int stop = 0, any_not_updated = 0;
-
- for (file = g->file->double_colon ? g->file->double_colon : g->file;
- file != NULL;
- file = file->prev)
- {
- unsigned int ocommands_started;
- int x;
+ {
+ /* Iterate over all double-colon entries for this file. */
+ struct file *file;
+ int stop = 0, any_not_updated = 0;
+
+ for (file = g->file->double_colon ? g->file->double_colon : g->file;
+ file != NULL;
+ file = file->prev)
+ {
+ unsigned int ocommands_started;
+ int fail;
file->dontcare = g->dontcare;
- check_renamed (file);
- if (rebuilding_makefiles)
- {
- if (file->cmd_target)
- {
- touch_flag = t;
- question_flag = q;
- just_print_flag = n;
- }
- else
- touch_flag = question_flag = just_print_flag = 0;
- }
-
- /* 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;
-
- x = update_file (file, rebuilding_makefiles ? 1 : 0);
- check_renamed (file);
-
- /* 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. */
+ check_renamed (file);
+ if (rebuilding_makefiles)
+ {
+ if (file->cmd_target)
+ {
+ touch_flag = t;
+ question_flag = q;
+ just_print_flag = n;
+ }
+ else
+ touch_flag = question_flag = just_print_flag = 0;
+ }
+
+ /* 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;
+
+ fail = update_file (file, rebuilding_makefiles ? 1 : 0);
+ check_renamed (file);
+
+ /* 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. */
if (commands_started > ocommands_started)
g->changed = 1;
@@ -167,10 +165,10 @@ update_goal_chain (struct dep *goals)
1 if updating failed, or to 0 if updating succeeded. Leave
STATUS as it is if no updating was done. */
- stop = 0;
- if ((x != 0 || file->updated) && status < 1)
+ stop = 0;
+ if ((fail || file->updated) && status < us_question)
{
- if (file->update_status != 0)
+ if (file->update_status != us_success)
{
/* Updating failed, or -q triggered. The STATUS value
tells our caller which. */
@@ -197,7 +195,7 @@ update_goal_chain (struct dep *goals)
enter an infinite loop. */
if (!rebuilding_makefiles
|| (!just_print_flag && !question_flag))
- status = 0;
+ status = us_success;
if (rebuilding_makefiles && file->dontcare)
/* This is a default makefile; stop remaking. */
stop = 1;
@@ -205,56 +203,56 @@ update_goal_chain (struct dep *goals)
}
}
- /* Keep track if any double-colon entry is not finished.
+ /* Keep track if any double-colon entry is not finished.
When they are all finished, the goal is finished. */
- any_not_updated |= !file->updated;
+ any_not_updated |= !file->updated;
file->dontcare = 0;
- if (stop)
- break;
- }
-
- /* Reset FILE since it is null at the end of the loop. */
- file = g->file;
-
- if (stop || !any_not_updated)
- {
- /* If we have found nothing whatever to do for the goal,
- print a message saying nothing needs doing. */
-
- if (!rebuilding_makefiles
- /* 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)
- message (1, ((file->phony || file->cmds == 0)
- ? _("Nothing to be done for `%s'.")
- : _("`%s' is up to date.")),
- file->name);
-
- /* This goal is finished. Remove it from the chain. */
- if (lastgoal == 0)
- goals = g->next;
- else
- lastgoal->next = g->next;
-
- /* Free the storage. */
- free (g);
-
- g = lastgoal == 0 ? goals : lastgoal->next;
-
- if (stop)
- break;
- }
- else
- {
- lastgoal = g;
- g = g->next;
- }
- }
+ if (stop)
+ break;
+ }
+
+ /* Reset FILE since it is null at the end of the loop. */
+ file = g->file;
+
+ if (stop || !any_not_updated)
+ {
+ /* If we have found nothing whatever to do for the goal,
+ print a message saying nothing needs doing. */
+
+ if (!rebuilding_makefiles
+ /* If the update_status is success, 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 == us_success && !g->changed
+ /* Never give a message under -s or -q. */
+ && !silent_flag && !question_flag)
+ message (1, ((file->phony || file->cmds == 0)
+ ? _("Nothing to be done for '%s'.")
+ : _("'%s' is up to date.")),
+ file->name);
+
+ /* This goal is finished. Remove it from the chain. */
+ if (lastgoal == 0)
+ goals = g->next;
+ else
+ lastgoal->next = g->next;
+
+ /* Free the storage. */
+ free (g);
+
+ g = lastgoal == 0 ? goals : lastgoal->next;
+
+ if (stop)
+ break;
+ }
+ else
+ {
+ lastgoal = g;
+ g = g->next;
+ }
+ }
/* If we reached the end of the dependency graph toggle the considered
flag for the next pass. */
@@ -273,8 +271,8 @@ update_goal_chain (struct dep *goals)
}
/* 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.
+ Return 0 if successful, non-0 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,
@@ -287,7 +285,7 @@ update_goal_chain (struct dep *goals)
static int
update_file (struct file *file, unsigned int depth)
{
- register int status = 0;
+ int status = 0;
register struct file *f;
f = file->double_colon ? file->double_colon : file;
@@ -299,11 +297,12 @@ update_file (struct file *file, unsigned int depth)
if (f->considered == considered)
{
/* Check for the case where a target has been tried and failed but
- the diagnostics hasn't been issued. If we need the diagnostics
+ the diagnostics haven'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))
+ if (!(f->updated && f->update_status > us_none
+ && !f->dontcare && f->no_diag))
{
- DBF (DB_VERBOSE, _("Pruning file `%s'.\n"));
+ DBF (DB_VERBOSE, _("Pruning file '%s'.\n"));
return f->command_state == cs_finished ? f->update_status : 0;
}
}
@@ -327,8 +326,8 @@ update_file (struct file *file, unsigned int depth)
if (f->command_state == cs_running
|| f->command_state == cs_deps_running)
{
- /* Don't run the other :: rules for this
- file until this rule is finished. */
+ /* Don't run the other :: rules for this
+ file until this rule is finished. */
status = 0;
break;
}
@@ -355,11 +354,6 @@ update_file (struct file *file, unsigned int depth)
static void
complain (struct file *file)
{
- 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");
-
/* 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
@@ -370,7 +364,7 @@ complain (struct file *file)
for (d = file->deps; d != 0; d = d->next)
{
- if (d->file->updated && d->file->update_status > 0 && file->no_diag)
+ if (d->file->updated && d->file->update_status > us_none && file->no_diag)
{
complain (d->file);
break;
@@ -379,6 +373,11 @@ complain (struct file *file)
if (d == 0)
{
+ 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");
+
/* Didn't find any dependencies to complain about. */
if (!keep_going_flag)
{
@@ -397,7 +396,8 @@ complain (struct file *file)
}
}
-/* Consider a single `struct file' and update it as appropriate. */
+/* Consider a single 'struct file' and update it as appropriate.
+ Return 0 on success, or non-0 on failure. */
static int
update_file_1 (struct file *file, unsigned int depth)
@@ -410,14 +410,14 @@ update_file_1 (struct file *file, unsigned int depth)
struct dep amake;
int running = 0;
- DBF (DB_VERBOSE, _("Considering target file `%s'.\n"));
+ DBF (DB_VERBOSE, _("Considering target file '%s'.\n"));
if (file->updated)
{
- if (file->update_status > 0)
- {
- DBF (DB_VERBOSE,
- _("Recently tried and failed to update file `%s'.\n"));
+ if (file->update_status > us_none)
+ {
+ DBF (DB_VERBOSE,
+ _("Recently tried and failed to update file '%s'.\n"));
/* If the file we tried to make is marked no_diag then no message
was printed about it when it failed during the makefile rebuild.
@@ -426,10 +426,10 @@ update_file_1 (struct file *file, unsigned int depth)
if (file->no_diag && !file->dontcare)
complain (file);
- return file->update_status;
- }
+ return file->update_status;
+ }
- DBF (DB_VERBOSE, _("File `%s' was considered already.\n"));
+ DBF (DB_VERBOSE, _("File '%s' was considered already.\n"));
return 0;
}
@@ -439,10 +439,10 @@ update_file_1 (struct file *file, unsigned int depth)
case cs_deps_running:
break;
case cs_running:
- DBF (DB_VERBOSE, _("Still updating file `%s'.\n"));
+ DBF (DB_VERBOSE, _("Still updating file '%s'.\n"));
return 0;
case cs_finished:
- DBF (DB_VERBOSE, _("Finished updating file `%s'.\n"));
+ DBF (DB_VERBOSE, _("Finished updating file '%s'.\n"));
return file->update_status;
default:
abort ();
@@ -471,15 +471,15 @@ update_file_1 (struct file *file, unsigned int depth)
check_renamed (file);
noexist = this_mtime == NONEXISTENT_MTIME;
if (noexist)
- DBF (DB_BASIC, _("File `%s' does not exist.\n"));
+ DBF (DB_BASIC, _("File '%s' does not exist.\n"));
else if (ORDINARY_MTIME_MIN <= this_mtime && this_mtime <= ORDINARY_MTIME_MAX
- && file->low_resolution_time)
+ && file->low_resolution_time)
{
/* 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);
+ error (NILF, _("*** Warning: .LOW_RESOLUTION_TIME file '%s' has a high resolution time stamp"),
+ file->name);
this_mtime += FILE_TIMESTAMPS_PER_S - 1 - ns;
}
@@ -491,15 +491,15 @@ update_file_1 (struct file *file, unsigned int depth)
if (!file->phony && file->cmds == 0 && !file->tried_implicit)
{
if (try_implicit_rule (file, depth))
- DBF (DB_IMPLICIT, _("Found an implicit rule for `%s'.\n"));
+ DBF (DB_IMPLICIT, _("Found an implicit rule for '%s'.\n"));
else
- DBF (DB_IMPLICIT, _("No implicit rule found for `%s'.\n"));
+ DBF (DB_IMPLICIT, _("No implicit rule found for '%s'.\n"));
file->tried_implicit = 1;
}
if (file->cmds == 0 && !file->is_target
&& default_file != 0 && default_file->cmds != 0)
{
- DBF (DB_IMPLICIT, _("Using default recipe for `%s'.\n"));
+ DBF (DB_IMPLICIT, _("Using default recipe for '%s'.\n"));
file->cmds = default_file->cmds;
}
@@ -579,7 +579,7 @@ update_file_1 (struct file *file, unsigned int depth)
while (f != 0);
}
- if (dep_status != 0 && !keep_going_flag)
+ if (dep_status && !keep_going_flag)
break;
if (!running)
@@ -599,13 +599,13 @@ update_file_1 (struct file *file, unsigned int depth)
if (must_make || always_make_flag)
{
for (d = file->deps; d != 0; d = d->next)
- if (d->file->intermediate)
- {
+ if (d->file->intermediate)
+ {
int dontcare = 0;
- FILE_TIMESTAMP mtime = file_mtime (d->file);
- check_renamed (d->file);
- d->file->parent = file;
+ FILE_TIMESTAMP mtime = file_mtime (d->file);
+ check_renamed (d->file);
+ d->file->parent = file;
/* Inherit dontcare flag from our parent. */
if (rebuilding_makefiles)
@@ -614,47 +614,51 @@ update_file_1 (struct file *file, unsigned int depth)
d->file->dontcare = file->dontcare;
}
+ /* We may have already considered this file, when we didn't know
+ we'd need to update it. Force update_file() to consider it and
+ not prune it. */
+ d->file->considered = !considered;
- dep_status |= update_file (d->file, depth);
+ dep_status |= update_file (d->file, depth);
/* Restore original dontcare flag. */
if (rebuilding_makefiles)
d->file->dontcare = dontcare;
- check_renamed (d->file);
-
- {
- 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);
- }
-
- if (dep_status != 0 && !keep_going_flag)
- break;
-
- if (!running)
- d->changed = ((file->phony && file->cmds != 0)
- || file_mtime (d->file) != mtime);
- }
+ check_renamed (d->file);
+
+ {
+ 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);
+ }
+
+ if (dep_status && !keep_going_flag)
+ break;
+
+ if (!running)
+ d->changed = ((file->phony && file->cmds != 0)
+ || file_mtime (d->file) != mtime);
+ }
}
finish_updating (file);
finish_updating (ofile);
- DBF (DB_VERBOSE, _("Finished prerequisites of target file `%s'.\n"));
+ DBF (DB_VERBOSE, _("Finished prerequisites of target file '%s'.\n"));
if (running)
{
set_command_state (file, cs_deps_running);
--depth;
- DBF (DB_VERBOSE, _("The prerequisites of `%s' are being made.\n"));
+ DBF (DB_VERBOSE, _("The prerequisites of '%s' are being made.\n"));
return 0;
}
@@ -662,17 +666,17 @@ update_file_1 (struct file *file, unsigned int depth)
if (dep_status != 0)
{
- file->update_status = dep_status;
+ file->update_status = us_failed;
notice_finished_file (file);
--depth;
- DBF (DB_VERBOSE, _("Giving up on target file `%s'.\n"));
+ DBF (DB_VERBOSE, _("Giving up on target file '%s'.\n"));
if (depth == 0 && keep_going_flag
- && !just_print_flag && !question_flag)
- error (NILF,
- _("Target `%s' not remade because of errors."), file->name);
+ && !just_print_flag && !question_flag)
+ error (NILF,
+ _("Target '%s' not remade because of errors."), file->name);
return dep_status;
}
@@ -701,8 +705,8 @@ update_file_1 (struct file *file, unsigned int depth)
{
#if 1
/* %%% In version 4, remove this code completely to
- implement not remaking deps if their deps are newer
- than their parents. */
+ implement not remaking deps if their deps are newer
+ than their parents. */
if (d_mtime == NONEXISTENT_MTIME && !d->file->intermediate)
/* We must remake if this dep does not
exist and is not intermediate. */
@@ -714,30 +718,30 @@ update_file_1 (struct file *file, unsigned int depth)
}
/* Set D->changed if either this dep actually changed,
- or its dependent, FILE, is older or does not exist. */
+ or its dependent, FILE, is older or does not exist. */
d->changed |= noexist || d_mtime > this_mtime;
if (!noexist && ISDB (DB_BASIC|DB_VERBOSE))
- {
+ {
const char *fmt = 0;
if (d->ignore_mtime)
{
if (ISDB (DB_VERBOSE))
- fmt = _("Prerequisite `%s' is order-only for target `%s'.\n");
+ fmt = _("Prerequisite '%s' is order-only for target '%s'.\n");
}
else if (d_mtime == NONEXISTENT_MTIME)
{
if (ISDB (DB_BASIC))
- fmt = _("Prerequisite `%s' of target `%s' does not exist.\n");
+ fmt = _("Prerequisite '%s' of target '%s' does not exist.\n");
}
- else if (d->changed)
+ else if (d->changed)
{
if (ISDB (DB_BASIC))
- fmt = _("Prerequisite `%s' is newer than target `%s'.\n");
+ fmt = _("Prerequisite '%s' is newer than target '%s'.\n");
}
else if (ISDB (DB_VERBOSE))
- fmt = _("Prerequisite `%s' is older than target `%s'.\n");
+ fmt = _("Prerequisite '%s' is older than target '%s'.\n");
if (fmt)
{
@@ -745,7 +749,7 @@ update_file_1 (struct file *file, unsigned int depth)
printf (fmt, dep_name (d), file->name);
fflush (stdout);
}
- }
+ }
}
/* Here depth returns to the value it had when we were called. */
@@ -755,19 +759,19 @@ update_file_1 (struct file *file, unsigned int depth)
{
must_make = 1;
DBF (DB_BASIC,
- _("Target `%s' is double-colon and has no prerequisites.\n"));
+ _("Target '%s' is double-colon and has no prerequisites.\n"));
}
else if (!noexist && file->is_target && !deps_changed && file->cmds == 0
&& !always_make_flag)
{
must_make = 0;
DBF (DB_VERBOSE,
- _("No recipe for `%s' and no prerequisites actually changed.\n"));
+ _("No recipe for '%s' and no prerequisites actually changed.\n"));
}
else if (!must_make && file->cmds != 0 && always_make_flag)
{
must_make = 1;
- DBF (DB_VERBOSE, _("Making `%s' due to always-make flag.\n"));
+ DBF (DB_VERBOSE, _("Making '%s' due to always-make flag.\n"));
}
if (!must_make)
@@ -775,9 +779,9 @@ update_file_1 (struct file *file, unsigned int depth)
if (ISDB (DB_VERBOSE))
{
print_spaces (depth);
- printf (_("No need to remake target `%s'"), file->name);
+ printf (_("No need to remake target '%s'"), file->name);
if (!streq (file->name, file->hname))
- printf (_("; using VPATH name `%s'"), file->hname);
+ printf (_("; using VPATH name '%s'"), file->hname);
puts (".");
fflush (stdout);
}
@@ -797,13 +801,13 @@ update_file_1 (struct file *file, unsigned int depth)
return 0;
}
- DBF (DB_BASIC, _("Must remake target `%s'.\n"));
+ DBF (DB_BASIC, _("Must remake target '%s'.\n"));
/* It needs to be remade. If it's VPATH and not reset via GPATH, toss the
VPATH. */
- if (!streq(file->name, file->hname))
+ if (!streq (file->name, file->hname))
{
- DB (DB_BASIC, (_(" Ignoring VPATH name `%s'.\n"), file->hname));
+ DB (DB_BASIC, (_(" Ignoring VPATH name '%s'.\n"), file->hname));
file->ignore_vpath = 1;
}
@@ -812,23 +816,22 @@ update_file_1 (struct file *file, unsigned int depth)
if (file->command_state != cs_finished)
{
- DBF (DB_VERBOSE, _("Recipe of `%s' is being run.\n"));
+ DBF (DB_VERBOSE, _("Recipe of '%s' is being run.\n"));
return 0;
}
switch (file->update_status)
{
- case 2:
- DBF (DB_BASIC, _("Failed to remake target file `%s'.\n"));
+ case us_failed:
+ DBF (DB_BASIC, _("Failed to remake target file '%s'.\n"));
break;
- case 0:
- DBF (DB_BASIC, _("Successfully remade target file `%s'.\n"));
+ case us_success:
+ DBF (DB_BASIC, _("Successfully remade target file '%s'.\n"));
break;
- case 1:
- DBF (DB_BASIC, _("Target file `%s' needs remade under -q.\n"));
+ case us_question:
+ DBF (DB_BASIC, _("Target file '%s' needs to be remade under -q.\n"));
break;
- default:
- assert (file->update_status >= 0 && file->update_status <= 2);
+ case us_none:
break;
}
@@ -836,11 +839,11 @@ update_file_1 (struct file *file, unsigned int depth)
return file->update_status;
}
-/* 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
+/* 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
touches FILE.
- On return, FILE->update_status will no longer be -1 if it was. */
+ On return, FILE->update_status will no longer be us_none if it was. */
void
notice_finished_file (struct file *file)
@@ -854,35 +857,35 @@ notice_finished_file (struct file *file)
if (touch_flag
/* The update status will be:
- -1 if this target was not remade;
- 0 if 0 or more commands (+ or ${MAKE}) were run and won;
- 1 if some commands were run and lost.
- 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)
+ us_success if 0 or more commands (+ or ${MAKE}) were run and won;
+ us_none if this target was not remade;
+ >us_none if some commands were run and lost.
+ 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 == us_success)
{
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)
- if (!(file->cmds->lines_flags[i] & COMMANDS_RECURSE))
- goto have_nonrecursing;
- }
+ {
+ /* 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)
+ if (!(file->cmds->lines_flags[i] & COMMANDS_RECURSE))
+ goto have_nonrecursing;
+ }
else
- {
- have_nonrecursing:
- if (file->phony)
- file->update_status = 0;
+ {
+ have_nonrecursing:
+ if (file->phony)
+ file->update_status = us_success;
/* According to POSIX, -t doesn't affect targets with no cmds. */
- else if (file->cmds != 0)
+ else if (file->cmds != 0)
{
/* 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. */
+ "'foo' is up to date" message. */
commands_started++;
/* Request for the timestamp to be updated (and distributed
@@ -891,7 +894,7 @@ notice_finished_file (struct file *file)
updating logic below. */
touched = 1;
}
- }
+ }
}
if (file->mtime_before_update == UNKNOWN_MTIME)
@@ -915,7 +918,7 @@ notice_finished_file (struct file *file)
/* If there were no commands at all, it's always new. */
else if (file->is_target && file->cmds == 0)
- i = 1;
+ i = 1;
file->last_mtime = i == 0 ? UNKNOWN_MTIME : NEW_MTIME;
}
@@ -948,28 +951,28 @@ notice_finished_file (struct file *file)
f->last_mtime = max_mtime;
}
- if (ran && file->update_status != -1)
+ if (ran && file->update_status != us_none)
/* 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;
-
- if (ran && !d->file->phony)
- /* 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. */
- f_mtime (d->file, 0);
+ d->file->command_state = cs_finished;
+ d->file->updated = 1;
+ d->file->update_status = file->update_status;
+
+ if (ran && !d->file->phony)
+ /* 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. */
+ f_mtime (d->file, 0);
}
- else if (file->update_status == -1)
+ else if (file->update_status == us_none)
/* Nothing was done for FILE, but it needed nothing done.
So mark it now as "succeeded". */
- file->update_status = 0;
+ file->update_status = us_success;
}
/* Check whether another file (whose mtime is THIS_MTIME) needs updating on
@@ -1003,7 +1006,7 @@ check_dep (struct file *file, unsigned int depth,
mtime = file_mtime (file);
check_renamed (file);
if (mtime == NONEXISTENT_MTIME || mtime > this_mtime)
- *must_make_ptr = 1;
+ *must_make_ptr = 1;
}
else
{
@@ -1011,19 +1014,19 @@ check_dep (struct file *file, unsigned int depth,
FILE_TIMESTAMP mtime;
if (!file->phony && file->cmds == 0 && !file->tried_implicit)
- {
- if (try_implicit_rule (file, depth))
- DBF (DB_IMPLICIT, _("Found an implicit rule for `%s'.\n"));
- else
- DBF (DB_IMPLICIT, _("No implicit rule found for `%s'.\n"));
- file->tried_implicit = 1;
- }
+ {
+ if (try_implicit_rule (file, depth))
+ DBF (DB_IMPLICIT, _("Found an implicit rule for '%s'.\n"));
+ else
+ DBF (DB_IMPLICIT, _("No implicit rule found for '%s'.\n"));
+ file->tried_implicit = 1;
+ }
if (file->cmds == 0 && !file->is_target
- && default_file != 0 && default_file->cmds != 0)
- {
- DBF (DB_IMPLICIT, _("Using default commands for `%s'.\n"));
- file->cmds = default_file->cmds;
- }
+ && default_file != 0 && default_file->cmds != 0)
+ {
+ DBF (DB_IMPLICIT, _("Using default commands for '%s'.\n"));
+ file->cmds = default_file->cmds;
+ }
check_renamed (file);
mtime = file_mtime (file);
@@ -1031,70 +1034,77 @@ check_dep (struct file *file, unsigned int depth,
if (mtime != NONEXISTENT_MTIME && mtime > this_mtime)
/* If the intermediate file actually exists and is newer, then we
should remake from it. */
- *must_make_ptr = 1;
+ *must_make_ptr = 1;
else
- {
+ {
/* 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. */
- struct dep *ld;
+ struct dep *ld;
int deps_running = 0;
/* 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
prerequisite and so wasn't rebuilt then, but should be now. */
if (file->command_state != cs_running)
- set_command_state (file, cs_not_started);
+ {
+ /* If the target was waiting for a dependency it has to be
+ reconsidered, as that dependency might have finished. */
+ if (file->command_state == cs_deps_running)
+ file->considered = !considered;
+
+ set_command_state (file, cs_not_started);
+ }
- ld = 0;
- d = file->deps;
- while (d != 0)
- {
+ ld = 0;
+ d = file->deps;
+ while (d != 0)
+ {
int maybe_make;
- if (is_updating (d->file))
- {
- error (NILF, _("Circular %s <- %s dependency dropped."),
- file->name, d->file->name);
- if (ld == 0)
- {
- file->deps = d->next;
+ if (is_updating (d->file))
+ {
+ error (NILF, _("Circular %s <- %s dependency dropped."),
+ file->name, d->file->name);
+ if (ld == 0)
+ {
+ file->deps = d->next;
free_dep (d);
- d = file->deps;
- }
- else
- {
- ld->next = d->next;
+ d = file->deps;
+ }
+ else
+ {
+ ld->next = d->next;
free_dep (d);
- d = ld->next;
- }
- continue;
- }
+ d = ld->next;
+ }
+ continue;
+ }
- d->file->parent = file;
+ d->file->parent = file;
maybe_make = *must_make_ptr;
- dep_status |= check_dep (d->file, depth, this_mtime,
+ dep_status |= check_dep (d->file, depth, this_mtime,
&maybe_make);
if (! d->ignore_mtime)
*must_make_ptr = maybe_make;
- check_renamed (d->file);
- if (dep_status != 0 && !keep_going_flag)
- break;
+ 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)
- deps_running = 1;
+ if (d->file->command_state == cs_running
+ || d->file->command_state == cs_deps_running)
+ deps_running = 1;
- ld = d;
- d = d->next;
- }
+ ld = d;
+ d = d->next;
+ }
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);
- }
+ }
}
finish_updating (file);
@@ -1103,56 +1113,61 @@ check_dep (struct file *file, unsigned int depth,
return dep_status;
}
-/* Touch FILE. Return zero if successful, one if not. */
+/* Touch FILE. Return us_success if successful, us_failed if not. */
-#define TOUCH_ERROR(call) return (perror_with_name (call, file->name), 1)
+#define TOUCH_ERROR(call) do{ perror_with_name ((call), file->name); \
+ return us_failed; }while(0)
-static int
+static enum update_status
touch_file (struct file *file)
{
if (!silent_flag)
message (0, "touch %s", file->name);
-#ifndef NO_ARCHIVES
+ /* Print-only (-n) takes precedence over touch (-t). */
+ if (just_print_flag)
+ return us_success;
+
+#ifndef NO_ARCHIVES
if (ar_name (file->name))
- return ar_touch (file->name);
+ return ar_touch (file->name) ? us_failed : us_success;
else
#endif
{
int fd = open (file->name, O_RDWR | O_CREAT, 0666);
if (fd < 0)
- TOUCH_ERROR ("touch: open: ");
+ TOUCH_ERROR ("touch: open: ");
else
- {
- struct stat statbuf;
- char buf = 'x';
+ {
+ struct stat statbuf;
+ char buf = 'x';
int e;
EINTRLOOP (e, fstat (fd, &statbuf));
- if (e < 0)
- 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);
- }
+ if (e < 0)
+ 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;
+ return us_success;
}
/* Having checked and updated the dependencies of FILE,
@@ -1165,18 +1180,18 @@ remake_file (struct file *file)
if (file->cmds == 0)
{
if (file->phony)
- /* Phony target. Pretend it succeeded. */
- file->update_status = 0;
+ /* Phony target. Pretend it succeeded. */
+ file->update_status = us_success;
else if (file->is_target)
- /* This is a nonexistent target file we cannot make.
- Pretend it was successfully remade. */
- file->update_status = 0;
+ /* This is a nonexistent target file we cannot make.
+ Pretend it was successfully remade. */
+ file->update_status = us_success;
else
{
/* This is a dependency file we cannot remake. Fail. */
if (!rebuilding_makefiles || !file->dontcare)
complain (file);
- file->update_status = 2;
+ file->update_status = us_failed;
}
}
else
@@ -1185,20 +1200,20 @@ remake_file (struct file *file)
/* The normal case: start some commands. */
if (!touch_flag || file->cmds->any_recurse)
- {
- execute_file_commands (file);
- return;
- }
+ {
+ execute_file_commands (file);
+ return;
+ }
/* This tells notice_finished_file it is ok to touch the file. */
- file->update_status = 0;
+ file->update_status = us_success;
}
/* This does the touching under -t. */
notice_finished_file (file);
}
-/* Return the mtime of a file, given a `struct file'.
+/* Return the mtime of a file, given a 'struct file'.
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
@@ -1213,7 +1228,7 @@ f_mtime (struct file *file, int search)
/* File's mtime is not known; must get it from the system. */
-#ifndef NO_ARCHIVES
+#ifndef NO_ARCHIVES
if (ar_name (file->name))
{
/* This file is an archive-member reference. */
@@ -1226,46 +1241,46 @@ f_mtime (struct file *file, int search)
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. */
+ Also allow for its name to be changed via VPATH search. */
arfile = lookup_file (arname);
if (arfile == 0)
arfile = enter_file (strcache_add (arname));
mtime = f_mtime (arfile, search);
check_renamed (arfile);
if (search && strcmp (arfile->hname, arname))
- {
- /* The archive's name has changed.
- Change the archive-member reference accordingly. */
+ {
+ /* The archive's name has changed.
+ Change the archive-member reference accordingly. */
char *name;
- unsigned int arlen, memlen;
+ unsigned int arlen, memlen;
- arlen = strlen (arfile->hname);
- memlen = strlen (memname);
+ arlen = strlen (arfile->hname);
+ memlen = strlen (memname);
- name = xmalloc (arlen + 1 + memlen + 2);
- memcpy (name, arfile->hname, arlen);
- name[arlen] = '(';
- memcpy (name + arlen + 1, memname, memlen);
- name[arlen + 1 + memlen] = ')';
- name[arlen + 1 + memlen + 1] = '\0';
+ name = alloca (arlen + 1 + memlen + 2);
+ memcpy (name, arfile->hname, arlen);
+ name[arlen] = '(';
+ memcpy (name + arlen + 1, memname, memlen);
+ 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);
+ rename_file (file, strcache_add (name));
else
- rehash_file (file, name);
+ rehash_file (file, strcache_add (name));
check_renamed (file);
- }
+ }
free (arname);
file->low_resolution_time = 1;
if (mtime == NONEXISTENT_MTIME)
- /* The archive doesn't exist, so its members don't exist either. */
- return NONEXISTENT_MTIME;
+ /* The archive doesn't exist, so its members don't exist either. */
+ return NONEXISTENT_MTIME;
member_date = ar_member_date (file->hname);
mtime = (member_date == (time_t) -1
@@ -1278,37 +1293,37 @@ f_mtime (struct file *file, int search)
mtime = name_mtime (file->name);
if (mtime == NONEXISTENT_MTIME && search && !file->ignore_vpath)
- {
- /* If name_mtime failed, search VPATH. */
- const char *name = vpath_search (file->name, &mtime, NULL, NULL);
- if (name
- /* Last resort, is it a library (-lxxx)? */
- || (file->name[0] == '-' && file->name[1] == 'l'
- && (name = library_search (file->name, &mtime)) != 0))
- {
- if (mtime != UNKNOWN_MTIME)
- /* vpath_search and library_search store UNKNOWN_MTIME
- if they didn't need to do a stat call for their work. */
- file->last_mtime = mtime;
+ {
+ /* If name_mtime failed, search VPATH. */
+ const char *name = vpath_search (file->name, &mtime, NULL, NULL);
+ if (name
+ /* Last resort, is it a library (-lxxx)? */
+ || (file->name[0] == '-' && file->name[1] == 'l'
+ && (name = library_search (file->name, &mtime)) != 0))
+ {
+ if (mtime != UNKNOWN_MTIME)
+ /* vpath_search and library_search store UNKNOWN_MTIME
+ if they didn't need to do a stat call for their work. */
+ file->last_mtime = mtime;
/* 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))
+ if (gpath_search (name, strlen (name) - strlen (file->name) - 1))
{
rename_file (file, name);
check_renamed (file);
return file_mtime (file);
}
- rehash_file (file, name);
- check_renamed (file);
+ rehash_file (file, name);
+ check_renamed (file);
/* 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);
- }
- }
+ }
+ }
}
/* Files can have bogus timestamps that nothing newly made will be
@@ -1354,7 +1369,7 @@ f_mtime (struct file *file, int search)
if (adjusted_now < adjusted_mtime)
{
#ifdef NO_FLOAT
- error (NILF, _("Warning: File `%s' has modification time in the future"),
+ error (NILF, _("Warning: File '%s' has modification time in the future"),
file->name);
#else
double from_now =
@@ -1367,7 +1382,7 @@ f_mtime (struct file *file, int search)
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"),
+ error (NILF, _("Warning: File '%s' has modification time %s s in the future"),
file->name, from_now_string);
#endif
clock_skew_detected = 1;
@@ -1382,14 +1397,13 @@ f_mtime (struct file *file, int search)
do
{
/* 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. */
+ 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. */
if (mtime != NONEXISTENT_MTIME && file->command_state == cs_not_started
- && file->command_state == cs_not_started
- && !file->tried_implicit && file->intermediate)
- file->intermediate = 0;
+ && !file->tried_implicit && file->intermediate)
+ file->intermediate = 0;
file->last_mtime = mtime;
file = file->prev;
@@ -1519,7 +1533,7 @@ library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr)
*/
#define LIBDIR "."
#endif
- LIBDIR, /* Defined by configuration. */
+ LIBDIR, /* Defined by configuration. */
0
};
@@ -1534,8 +1548,7 @@ library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr)
unsigned int liblen;
/* Information about the earliest (in the vpath sequence) match. */
- unsigned int best_vpath, best_path;
- unsigned int std_dirs = 0;
+ unsigned int best_vpath = 0, best_path = 0;
char **dp;
@@ -1554,38 +1567,39 @@ library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr)
static char *buf = NULL;
static unsigned int buflen = 0;
static int libdir_maxlen = -1;
+ static unsigned int std_dirs = 0;
char *libbuf = variable_expand ("");
/* Expand the pattern using LIB as a replacement. */
{
- char c = p[len];
- char *p3, *p4;
-
- p[len] = '\0';
- p3 = find_percent (p);
- if (!p3)
- {
- /* Give a warning if there is no pattern. */
- error (NILF, _(".LIBPATTERNS element `%s' is not a pattern"), p);
+ char c = p[len];
+ char *p3, *p4;
+
+ p[len] = '\0';
+ p3 = find_percent (p);
+ if (!p3)
+ {
+ /* Give a warning if there is no pattern. */
+ error (NILF, _(".LIBPATTERNS element '%s' is not a pattern"), p);
p[len] = c;
- continue;
- }
- p4 = variable_buffer_output (libbuf, p, p3-p);
- p4 = variable_buffer_output (p4, lib, liblen);
- p4 = variable_buffer_output (p4, p3+1, len - (p3-p));
- p[len] = c;
+ continue;
+ }
+ p4 = variable_buffer_output (libbuf, p, p3-p);
+ p4 = variable_buffer_output (p4, lib, liblen);
+ p4 = variable_buffer_output (p4, p3+1, len - (p3-p));
+ p[len] = c;
}
- /* Look first for `libNAME.a' in the current directory. */
+ /* Look first for 'libNAME.a' in the current directory. */
mtime = name_mtime (libbuf);
if (mtime != NONEXISTENT_MTIME)
- {
- if (mtime_ptr != 0)
- *mtime_ptr = mtime;
- file = strcache_add (libbuf);
+ {
+ if (mtime_ptr != 0)
+ *mtime_ptr = mtime;
+ file = strcache_add (libbuf);
/* This by definition will have the best index, so stop now. */
break;
- }
+ }
/* Now try VPATH search on that. */
@@ -1622,7 +1636,7 @@ library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr)
std_dirs++;
}
buflen = strlen (libbuf);
- buf = xmalloc(libdir_maxlen + buflen + 2);
+ buf = xmalloc (libdir_maxlen + buflen + 2);
}
else if (buflen < strlen (libbuf))
{
@@ -1636,11 +1650,11 @@ library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr)
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);