home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
gnu
/
make-3.71-src.lha
/
src
/
amiga
/
make-3.71
/
remake.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-22
|
27KB
|
1,056 lines
/* Basic dependency engine for GNU Make.
Copyright (C) 1988, 89, 90, 91, 92, 93, 94 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 terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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.
You should have received a copy of the GNU General Public License
along with GNU Make; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "make.h"
#include "commands.h"
#include "job.h"
#include "dep.h"
#include "file.h"
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#else
#include <sys/file.h>
#endif
extern int try_implicit_rule ();
/* Incremented when a command is started (under -n, when one would be). */
unsigned int commands_started = 0;
static int update_file (), update_file_1 (), check_dep (), touch_file ();
static void remake_file ();
static time_t name_mtime ();
static int library_search ();
extern time_t f_mtime ();
/* 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 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. */
int
update_goal_chain (goals, makefiles)
register struct dep *goals;
int makefiles;
{
int t = touch_flag, q = question_flag, n = just_print_flag;
unsigned int j = job_slots;
int status = -1;
#define MTIME(file) (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.
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)
g->changed = 0;
}
if (makefiles)
/* Only run one job at a time. */
job_slots = 1;
/* Update all the goals until they are all finished. */
while (goals != 0)
{
register struct dep *g, *lastgoal;
/* Start jobs that are waiting for the load to go down. */
start_waiting_jobs ();
/* Wait for a child to die. */
reap_children (1, 0);
lastgoal = 0;
g = goals;
while (g != 0)
{
/* Iterate over all double-colon entries for this file. */
struct file *file = g->file;
int stop, 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;
time_t mtime = MTIME (file);
check_renamed (file);
if (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, 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. */
g->changed += commands_started - ocommands_started;
stop = 0;
if (x != 0 || file->updated)
{
/* If 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. */
if (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. */
stop = (!keep_going_flag && !question_flag
&& !makefiles);
}
else if (MTIME (file) != mtime)
{
/* 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 fall into an infinite loop. */
if (!makefiles
|| (!just_print_flag && !question_flag))
status = 0;
if (makefiles && file->dontcare)
/* This is a default makefile. Stop remaking. */
stop = 1;
}
}
}
/* Keep track if any double-colon entry is not finished.
When they are all finished, the goal is finished. */
any_not_updated |= !file->updated;
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 (!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)
{
if (file->phony || file->cmds == 0)
message ("Nothing to be done for `%s'.",
file->name);
else
message ("`%s' is up to date.", file->name);
fflush (stdout);
}
/* This goal is finished. Remove it from the chain. */
if (lastgoal == 0)
goals = g->next;
else
lastgoal->next = g->next;
/* Free the storage. */
free ((char *) g);
g = lastgoal == 0 ? goals : lastgoal->next;
if (stop)
break;
}
else
{
lastgoal = g;
g = g->next;
}
}
}
if (makefiles)
{
touch_flag = t;
question_flag = q;
just_print_flag = n;
job_slots = j;
}
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
update_file (file, depth)
struct file *file;
unsigned int depth;
{
register int status = 0;
register struct file *f;
for (f = file->double_colon ? file->double_colon : file; f != 0; f = f->prev)
{
status |= update_file_1 (f, depth);
check_renamed (f);
if (status != 0 && !keep_going_flag)
return status;
switch (f->command_state)
{
case cs_finished:
/* The file is done being remade. */
break;
case cs_running:
case cs_deps_running:
/* Don't run the other :: rules for this
file until this rule is finished. */
return 0;
default:
error ("internal error: `%s' command_state == %d in update_file",
f->name, (int) f->command_state);
abort ();
break;
}
}
return status;
}
/* Consider a single `struct file' and update it as appropriate. */
static int
update_file_1 (file, depth)
struct file *file;
unsigned int depth;
{
register time_t t