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
/
file.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-05
|
13KB
|
515 lines
/* Target file hash table management 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 "dep.h"
#include "file.h"
#include "variable.h"
/* Hash table of files the makefile knows how to make. */
#ifndef FILE_BUCKETS
#define FILE_BUCKETS 1007
#endif
static struct file *files[FILE_BUCKETS];
/* Number of files with the `intermediate' flag set. */
unsigned int num_intermediates = 0;
/* Access the hash table of all file records.
lookup_file given a name, return the struct file * for that name,
or nil if there is none.
enter_file similar, but create one if there is none. */
struct file *
lookup_file (name)
char *name;
{
register struct file *f;
register char *n;
register unsigned int hashval;
if (*name == '\0')
abort ();
/* This is also done in parse_file_seq, so this is redundant
for names read from makefiles. It is here for names passed
on the command line. */
while (name[0] == '.' && name[1] == '/' && name[2] != '\0')
{
name += 2;
while (*name == '/')
/* Skip following slashes: ".//foo" is "foo", not "/foo". */
++name;
}
if (*name == '\0')
/* It was all slashes after a dot. */
name = "./";
hashval = 0;
for (n = name; *n != '\0'; ++n)
HASH (hashval, *n);
hashval %= FILE_BUCKETS;
for (f = files[hashval]; f != 0; f = f->next)
if (streq (f->name, name))
return f;
return 0;
}
struct file *
enter_file (name)
char *name;
{
register struct file *f, *new;
register char *n;
register unsigned int hashval;
if (*name == '\0')
abort ();
hashval = 0;
for (n = name; *n != '\0'; ++n)
HASH (hashval, *n);
hashval %= FILE_BUCKETS;
for (f = files[hashval]; f != 0; f = f->next)
if (streq (f->name, name))
break;
if (f != 0 && !f->double_colon)
return f;
new = (struct file *) xmalloc (sizeof (struct file));
bzero ((char *) new, sizeof (struct file));
new->name = name;
new->update_status = -1;
if (f == 0)
{
/* This is a completely new file. */
new->next = files[hashval];
files[hashval] = new;
}
else
{
/* There is already a double-colon entry for this file. */
new->double_colon = f;
while (f->prev != 0)
f = f->prev;
f->prev = new;
}
return new;
}
/* Rename FILE to NAME. This is not as simple as resetting
the `name' member, since it must be put in a new hash bucket,
and possibly merged with an existing file called NAME. */
void
rename_file (file, name)
register struct file *file;
char *name;
{
char *oldname = file->name;
register unsigned int oldhash;
register char *n;
while (file->renamed != 0)
file = file->renamed;
/* Find the hash values of the old and new names. */
oldhash = 0;
for (n = oldname; *n != '\0'; ++n)
HASH (oldhash, *n);
file_hash_enter (file, name, oldhash, file->name);
}
void
file_hash_enter (file, name, oldhash, oldname)
register struct file *file;
char *name;
unsigned int oldhash;
char *oldname;
{
unsigned int oldbucket = oldhash % FILE_BUCKETS;
register unsigned int newhash, newbucket;
struct file *oldfile;
register char *n;
register struct file *f;
newhash = 0;
for (n = name; *n != '\0'; ++n)
HASH (newhash, *n);
newbucket = newhash % FILE_BUCKETS;
/* Look for an existing file under the new name. */
for (oldfile = files[newbucket]; oldfile != 0; oldfile = oldfile->next)
if (streq (oldfile->name, name))
break;
if (oldhash != 0 && (newbucket != oldbucket || oldfile != 0))
{
/* Remove FILE from its hash bucket. */
struct file *lastf = 0;
for (f = files[oldbucket]; f != file; f = f->next)
lastf = f;
if (lastf == 0)
files[oldbucket] = f->next;
else
lastf->next = f->next;
}
/* Give FILE its new name. */
file->name = name;
for (f = file->double_colon; f != 0; f = f->prev)
f->name = name;
if (oldfile == 0)
{
/* There is no existing file with the new name. */
if (newbucket != oldbucket)
{
/* Put FILE in its new hash bucket. */
file->next = files[newbucket];
files[newbucket] = file;
}
}
else
{
/* There is an existing file with the new name.
We must merge FILE into the existing file. */
register struct dep *d;
if (file->cmds != 0)
{
if (oldfile->cmds == 0)
oldfile->cmds = file->cmds;
else if (file->cmds != oldfile->cmds)
{
/* We have two sets of commands. We will go with the
one given in the rule explicitly mentioning this name,
but give a message to let the user know what's going on. */
if (oldfile->cmds->filename != 0)
makefile_error (file->cmds->filename, file->cmds->lineno,
"Commands were specified for \
file `%s' at %s:%u,",
oldname, oldfile->cmds->filename,
oldfile->cmds->lineno);
else
makefile_error (file->cmds->filename, file->cmds->lineno,
"Commands for file `%s' were found by \
implicit rule search,",
oldname);
makefile_error (file->cmds->filename, file->cmds->lineno,
"but `%s' is now considered the same file \
as `%s'.",
oldname, name);
makefile_error (file->cmds->filename, file->cmds->lineno,
"Commands for `%s' will be ignored \
in favor of those for `%s'.",
name, oldname);
}
}
/* Merge the dependencies of the two files. */
d = oldfile->deps;
if (d == 0)
oldfile->deps = file->deps;
else
{
while (d->next != 0)
d = d->next;
d->next = file->deps;
}
merge_variable_set_lists (&oldfile->variables, file->variables);
if (oldfile->double_colon && !file->double_colon)
fatal ("can't rename single-colon `%s' to double-colon `%s'",
oldname, name);
if (!oldfile->double_colon && file->double_colon)
fatal ("can't rename double-colon `%s' to single-colon `%s'",
oldname, name);
if (file->last_mtime > oldfile->last_mtime)
/* %%% Kludge so -W wins on a file that gets vpathized. */
oldfile->last_mtime = file->last_mtime;
#define MERGE(field) oldfile->field |= file->field
MERGE (precious);
MERGE (tried_implicit);
MERGE (updating);
MERGE (updated);
MERGE (is_target);
MERGE (cmd_target);
MERGE (phony);
#undef MERGE
file->renamed = oldfile;
}
}
/* Remove all nonprecious intermediate files.
If SIG is nonzero, this was caused by a fatal signal,
meaning that a different message will be printed, and
the message will go to stderr rather than stdout. */
void
remove_intermediates (sig)
int sig;
{
register int i;
register struct file *f;
char doneany;
if (!sig && just_print_flag)
return;
doneany = 0;
for (i = 0; i < FILE_BUCKETS; ++i)
for (f = files[i]; f != 0; f = f->next)
if (f->intermediate && (f->dontcare || !f->precious))
{
int status;
if (just_print_flag)
status = 0;
else
{
status = unlink (f->name);
if (status < 0 && errno == ENOENT)
continue;
}
if (!f->dontcare)
{
if (sig)
error ("*** Deleting intermediate file `%s'", f->name);
else if (!silent_flag)
{
if (! doneany)
{
fputs ("rm ", stdout);
doneany = 1;
}
else
putchar (' ');
fputs (f->name, stdout);
fflush (stdout);
}
if (status < 0)
perror_wit