make/vpath.c

588 lines
16 KiB
C
Raw Normal View History

1994-03-23 14:12:55 +00:00
/* Implementation of pattern-matching file search paths for GNU Make.
1997-08-27 20:30:54 +00:00
Copyright (C) 1988,89,91,92,93,94,95,96,97 Free Software Foundation, Inc.
1991-06-03 20:37:27 +00:00
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, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
1991-06-03 20:37:27 +00:00
#include "make.h"
#include "filedef.h"
1991-06-03 20:37:27 +00:00
#include "variable.h"
1997-04-07 07:21:16 +00:00
#ifdef WINDOWS32
Wed May 15 10:14:14 CDT 1996 Rob Tulloh <tulloh@tivoli.com> * dir.c: WIN32 does not support inode. For now, fully qualified pathname along with st_mtime will be keys for files. Fixed problem where vpath can be confused when files are added to a directory after the directory has already been read in. The code now attempts to reread the directory if it discovers that the datestamp on the directory has changed since it was cached by make. This problem only seems to occur on WIN32 right now so it is lumped under port #ifdef WIN32. * function.c: WIN32: call subproc library (CreateProcess()) instead of fork/exec. * job.c: WIN32: Added the code to do fork/exec/waitpid style processing on WIN32 systems via calls to subproc library. * main.c: WIN32: Several things added here. First, there is code for dealing with PATH and SHELL defaults. Make tries to figure out if the user has %PATH% set in the environment and sets it to %Path% if it is not set already. Make also looks to see if sh.exe is anywhere to be found. Code path through job.c will change based on existence of a working Bourne shell. The checking for default shell is done twice: once before makefiles are read in and again after. Fall back to MSDOS style execution mode if no sh.exe is found. Also added some debug support that allows user to pause make with -D switch and attach a debugger. This is especially useful for debugging recursive calls to make where problems appear only in the sub-make. * make.h: WIN32: A few macros and header files for WIN32 support. * misc.c: WIN32: Added a function end_of_token_w32() to assist in parsing code in read.c. * read.c: WIN32: Fixes similar to MSDOS which allow colon to appear in filenames. Use of colon in filenames would otherwise confuse make. * remake.c: WIN32: Added include of io.h to eliminate compiler warnings. Added some code to default LIBDIR if it is not set on WIN32. * variable.c: WIN32: Added support for detecting Path/PATH and converting them to semicolon separated lists for make's internal use. New function sync_Path_environment() which is called in job.c and function.c before creating a new process. Caller must set Path in environment since we don't have fork() to do this for us. * vpath.c: WIN32: Added detection for filenames containing forward or backward slashes. * NMakefile: WIN32: Visual C compatible makefile for use with nmake. Use this to build GNU make the first time on Windows NT or Windows 95. * README.WIN32: WIN32: Contains some helpful notes. * build_w32.bat: WIN32: If you don't like nmake, use this the first time you build GNU make on Windows NT or Windows 95. * config.h.WIN32: WIN32 version of config.h * subproc.bat: WIN32: A bat file used to build the subproc library from the top-level NMakefile. Needed because WIndows 95 (nmake) doesn't allow you to cd in a make rule. * w32/include/dirent.h * w32/compat/dirent.c: WIN32: opendir, readdir, closedir, etc. * w32/include/pathstuff.h: WIN32: used by files needed functions defined in pathstuff.c (prototypes). * w32/include/sub_proc.h: WIN32: prototypes for subproc.lib functions. * w32/include/w32err.h: WIN32: prototypes for w32err.c. * w32/pathstuff.c: WIN32: File and Path/Path conversion functions. * w32/subproc/build.bat: WIN32: build script for subproc library if you don't wish to use nmake. * w32/subproc/NMakefile: WIN32: Visual C compatible makefile for use with nmake. Used to build subproc library. * w32/subproc/misc.c: WIN32: subproc library support code * w32/subproc/proc.h: WIN32: subproc library support code * w32/subproc/sub_proc.c: WIN32: subproc library source code * w32/subproc/w32err.c: WIN32: subproc library support code
1996-05-22 21:51:45 +00:00
#include "pathstuff.h"
#endif
1991-06-03 20:37:27 +00:00
/* Structure used to represent a selective VPATH searchpath. */
struct vpath
{
struct vpath *next; /* Pointer to next struct in the linked list. */
char *pattern; /* The pattern to match. */
char *percent; /* Pointer into `pattern' where the `%' is. */
unsigned int patlen;/* Length of the pattern. */
char **searchpath; /* Null-terminated list of directories. */
unsigned int maxlen;/* Maximum length of any entry in the list. */
};
/* Linked-list of all selective VPATHs. */
static struct vpath *vpaths;
/* Structure for the general VPATH given in the variable. */
static struct vpath *general_vpath;
1997-04-07 07:21:16 +00:00
/* Structure for GPATH given in the variable. */
static struct vpath *gpaths;
1991-06-03 20:37:27 +00:00
1998-10-03 05:39:55 +00:00
static int selective_vpath_search PARAMS ((struct vpath *path, char **file, FILE_TIMESTAMP *mtime_ptr));
1991-06-03 20:37:27 +00:00
/* Reverse the chain of selective VPATH lists so they
will be searched in the order given in the makefiles
and construct the list from the VPATH variable. */
void
build_vpath_lists ()
{
register struct vpath *new = 0;
register struct vpath *old, *nexto;
register char *p;
/* Reverse the chain. */
for (old = vpaths; old != 0; old = nexto)
{
nexto = old->next;
old->next = new;
new = old;
}
vpaths = new;
/* If there is a VPATH variable with a nonnull value, construct the
general VPATH list from it. We use variable_expand rather than just
calling lookup_variable so that it will be recursively expanded. */
1993-06-25 20:03:51 +00:00
{
/* Turn off --warn-undefined-variables while we expand SHELL and IFS. */
int save = warn_undefined_variables_flag;
warn_undefined_variables_flag = 0;
1993-07-09 01:30:13 +00:00
p = variable_expand ("$(strip $(VPATH))");
1993-06-25 20:03:51 +00:00
warn_undefined_variables_flag = save;
}
1991-06-03 20:37:27 +00:00
if (*p != '\0')
{
1993-07-09 01:30:13 +00:00
/* Save the list of vpaths. */
struct vpath *save_vpaths = vpaths;
/* Empty `vpaths' so the new one will have no next, and `vpaths'
will still be nil if P contains no existing directories. */
vpaths = 0;
/* Parse P. */
1991-06-03 20:37:27 +00:00
construct_vpath_list ("%", p);
1993-07-09 01:30:13 +00:00
/* Store the created path as the general path,
and restore the old list of vpaths. */
general_vpath = vpaths;
vpaths = save_vpaths;
1991-06-03 20:37:27 +00:00
}
1997-04-07 07:21:16 +00:00
/* If there is a GPATH variable with a nonnull value, construct the
GPATH list from it. We use variable_expand rather than just
calling lookup_variable so that it will be recursively expanded. */
{
/* Turn off --warn-undefined-variables while we expand SHELL and IFS. */
int save = warn_undefined_variables_flag;
warn_undefined_variables_flag = 0;
p = variable_expand ("$(strip $(GPATH))");
warn_undefined_variables_flag = save;
}
if (*p != '\0')
{
/* Save the list of vpaths. */
struct vpath *save_vpaths = vpaths;
/* Empty `vpaths' so the new one will have no next, and `vpaths'
will still be nil if P contains no existing directories. */
vpaths = 0;
/* Parse P. */
construct_vpath_list ("%", p);
/* Store the created path as the GPATH,
and restore the old list of vpaths. */
gpaths = vpaths;
vpaths = save_vpaths;
}
1991-06-03 20:37:27 +00:00
}
/* Construct the VPATH listing for the pattern and searchpath given.
This function is called to generate selective VPATH lists and also for
the general VPATH list (which is in fact just a selective VPATH that
is applied to everything). The returned pointer is either put in the
linked list of all selective VPATH lists or in the GENERAL_VPATH
variable.
If SEARCHPATH is nil, remove all previous listings with the same
1997-08-27 20:30:54 +00:00
pattern. If PATTERN is nil, remove all VPATH listings. Existing
and readable directories that are not "." given in the searchpath
separated by the path element separator (defined in make.h) are
loaded into the directory hash table if they are not there already
and put in the VPATH searchpath for the given pattern with trailing
slashes stripped off if present (and if the directory is not the
root, "/"). The length of the longest entry in the list is put in
the structure as well. The new entry will be at the head of the
VPATHS chain. */
1991-06-03 20:37:27 +00:00
void
construct_vpath_list (pattern, dirpath)
char *pattern, *dirpath;
{
register unsigned int elem;
register char *p;
register char **vpath;
register unsigned int maxvpath;
unsigned int maxelem;
1998-07-30 20:54:47 +00:00
char *percent = NULL;
1991-06-03 20:37:27 +00:00
if (pattern != 0)
{
pattern = xstrdup (pattern);
1991-06-03 20:37:27 +00:00
percent = find_percent (pattern);
}
if (dirpath == 0)
{
/* Remove matching listings. */
register struct vpath *path, *lastpath;
1993-01-08 22:07:33 +00:00
lastpath = 0;
path = vpaths;
while (path != 0)
{
struct vpath *next = path->next;
if (pattern == 0
|| (((percent == 0 && path->percent == 0)
|| (percent - pattern == path->percent - path->pattern))
&& streq (pattern, path->pattern)))
{
/* Remove it from the linked list. */
if (lastpath == 0)
vpaths = path->next;
else
lastpath->next = next;
/* Free its unused storage. */
free (path->pattern);
free ((char *) path->searchpath);
1993-01-11 22:46:31 +00:00
free ((char *) path);
1993-01-08 22:07:33 +00:00
}
1993-12-14 19:28:59 +00:00
else
lastpath = path;
1993-01-08 22:07:33 +00:00
path = next;
}
1991-06-03 20:37:27 +00:00
if (pattern != 0)
free (pattern);
return;
}
1997-04-07 07:21:16 +00:00
#ifdef WINDOWS32
convert_vpath_to_windows32(dirpath, ';');
Wed May 15 10:14:14 CDT 1996 Rob Tulloh <tulloh@tivoli.com> * dir.c: WIN32 does not support inode. For now, fully qualified pathname along with st_mtime will be keys for files. Fixed problem where vpath can be confused when files are added to a directory after the directory has already been read in. The code now attempts to reread the directory if it discovers that the datestamp on the directory has changed since it was cached by make. This problem only seems to occur on WIN32 right now so it is lumped under port #ifdef WIN32. * function.c: WIN32: call subproc library (CreateProcess()) instead of fork/exec. * job.c: WIN32: Added the code to do fork/exec/waitpid style processing on WIN32 systems via calls to subproc library. * main.c: WIN32: Several things added here. First, there is code for dealing with PATH and SHELL defaults. Make tries to figure out if the user has %PATH% set in the environment and sets it to %Path% if it is not set already. Make also looks to see if sh.exe is anywhere to be found. Code path through job.c will change based on existence of a working Bourne shell. The checking for default shell is done twice: once before makefiles are read in and again after. Fall back to MSDOS style execution mode if no sh.exe is found. Also added some debug support that allows user to pause make with -D switch and attach a debugger. This is especially useful for debugging recursive calls to make where problems appear only in the sub-make. * make.h: WIN32: A few macros and header files for WIN32 support. * misc.c: WIN32: Added a function end_of_token_w32() to assist in parsing code in read.c. * read.c: WIN32: Fixes similar to MSDOS which allow colon to appear in filenames. Use of colon in filenames would otherwise confuse make. * remake.c: WIN32: Added include of io.h to eliminate compiler warnings. Added some code to default LIBDIR if it is not set on WIN32. * variable.c: WIN32: Added support for detecting Path/PATH and converting them to semicolon separated lists for make's internal use. New function sync_Path_environment() which is called in job.c and function.c before creating a new process. Caller must set Path in environment since we don't have fork() to do this for us. * vpath.c: WIN32: Added detection for filenames containing forward or backward slashes. * NMakefile: WIN32: Visual C compatible makefile for use with nmake. Use this to build GNU make the first time on Windows NT or Windows 95. * README.WIN32: WIN32: Contains some helpful notes. * build_w32.bat: WIN32: If you don't like nmake, use this the first time you build GNU make on Windows NT or Windows 95. * config.h.WIN32: WIN32 version of config.h * subproc.bat: WIN32: A bat file used to build the subproc library from the top-level NMakefile. Needed because WIndows 95 (nmake) doesn't allow you to cd in a make rule. * w32/include/dirent.h * w32/compat/dirent.c: WIN32: opendir, readdir, closedir, etc. * w32/include/pathstuff.h: WIN32: used by files needed functions defined in pathstuff.c (prototypes). * w32/include/sub_proc.h: WIN32: prototypes for subproc.lib functions. * w32/include/w32err.h: WIN32: prototypes for w32err.c. * w32/pathstuff.c: WIN32: File and Path/Path conversion functions. * w32/subproc/build.bat: WIN32: build script for subproc library if you don't wish to use nmake. * w32/subproc/NMakefile: WIN32: Visual C compatible makefile for use with nmake. Used to build subproc library. * w32/subproc/misc.c: WIN32: subproc library support code * w32/subproc/proc.h: WIN32: subproc library support code * w32/subproc/sub_proc.c: WIN32: subproc library source code * w32/subproc/w32err.c: WIN32: subproc library support code
1996-05-22 21:51:45 +00:00
#endif
1997-08-27 20:30:54 +00:00
/* Figure out the maximum number of VPATH entries and put it in
MAXELEM. We start with 2, one before the first separator and one
nil (the list terminator) and increment our estimated number for
each separator or blank we find. */
1991-06-03 20:37:27 +00:00
maxelem = 2;
1992-11-16 22:49:14 +00:00
p = dirpath;
1991-06-03 20:37:27 +00:00
while (*p != '\0')
if (*p++ == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*p))
1991-06-03 20:37:27 +00:00
++maxelem;
vpath = (char **) xmalloc (maxelem * sizeof (char *));
maxvpath = 0;
1997-08-27 20:30:54 +00:00
/* Skip over any initial separators and blanks. */
1991-06-03 20:37:27 +00:00
p = dirpath;
while (*p == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*p))
1992-11-10 20:29:48 +00:00
++p;
elem = 0;
1991-06-03 20:37:27 +00:00
while (*p != '\0')
{
char *v;
unsigned int len;
/* Find the end of this entry. */
v = p;
while (*p != '\0' && *p != PATH_SEPARATOR_CHAR
&& !isblank ((unsigned char)*p))
1991-06-03 20:37:27 +00:00
++p;
len = p - v;
/* Make sure there's no trailing slash,
but still allow "/" as a directory. */
1997-04-07 07:21:16 +00:00
#ifdef __MSDOS__
/* We need also to leave alone a trailing slash in "d:/". */
if (len > 3 || (len > 1 && v[1] != ':'))
#endif
1991-06-03 20:37:27 +00:00
if (len > 1 && p[-1] == '/')
--len;
1993-01-26 01:51:23 +00:00
if (len > 1 || *v != '.')
{
v = savestring (v, len);
1992-11-05 23:33:08 +00:00
1993-01-26 01:51:23 +00:00
/* Verify that the directory actually exists. */
1992-11-05 23:33:08 +00:00
1993-01-26 01:51:23 +00:00
if (dir_file_exists_p (v, ""))
{
/* It does. Put it in the list. */
vpath[elem++] = dir_name (v);
free (v);
if (len > maxvpath)
maxvpath = len;
}
else
/* The directory does not exist. Omit from the list. */
free (v);
1991-06-03 20:37:27 +00:00
}
1992-11-10 20:29:48 +00:00
1997-08-27 20:30:54 +00:00
/* Skip over separators and blanks between entries. */
while (*p == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*p))
1992-11-10 20:29:48 +00:00
++p;
1991-06-03 20:37:27 +00:00
}
if (elem > 0)
{
struct vpath *path;
/* ELEM is now incremented one element past the last
entry, to where the nil-pointer terminator goes.
Usually this is maxelem - 1. If not, shrink down. */
if (elem < (maxelem - 1))
vpath = (char **) xrealloc ((char *) vpath,
(elem + 1) * sizeof (char *));
/* Put the nil-pointer terminator on the end of the VPATH list. */
vpath[elem] = 0;
/* Construct the vpath structure and put it into the linked list. */
path = (struct vpath *) xmalloc (sizeof (struct vpath));
path->searchpath = vpath;
path->maxlen = maxvpath;
path->next = vpaths;
vpaths = path;
/* Set up the members. */
path->pattern = pattern;
path->percent = percent;
path->patlen = strlen (pattern);
}
else
1993-07-09 01:30:13 +00:00
{
/* There were no entries, so free whatever space we allocated. */
free ((char *) vpath);
if (pattern != 0)
free (pattern);
}
1991-06-03 20:37:27 +00:00
}
1997-08-18 18:11:04 +00:00
/* Search the GPATH list for a pathname string that matches the one passed
in. If it is found, return 1. Otherwise we return 0. */
1997-04-07 07:21:16 +00:00
int
1997-08-18 18:11:04 +00:00
gpath_search (file, len)
char *file;
int len;
1997-04-07 07:21:16 +00:00
{
1997-08-18 18:11:04 +00:00
register char **gp;
if (gpaths && (len <= gpaths->maxlen))
for (gp = gpaths->searchpath; *gp != NULL; ++gp)
if (strneq (*gp, file, len) && (*gp)[len] == '\0')
1997-08-18 18:11:04 +00:00
return 1;
1997-04-07 07:21:16 +00:00
return 0;
}
1991-06-03 20:37:27 +00:00
/* Search the VPATH list whose pattern matches *FILE for a directory
1993-02-08 22:50:00 +00:00
where the name pointed to by FILE exists. If it is found, we set *FILE to
the newly malloc'd name of the existing file, *MTIME_PTR (if MTIME_PTR is
not NULL) to its modtime (or zero if no stat call was done), and return 1.
Otherwise we return 0. */
1991-06-03 20:37:27 +00:00
int
1993-02-08 22:50:00 +00:00
vpath_search (file, mtime_ptr)
1991-06-03 20:37:27 +00:00
char **file;
1998-10-03 05:39:55 +00:00
FILE_TIMESTAMP *mtime_ptr;
1991-06-03 20:37:27 +00:00
{
register struct vpath *v;
/* If there are no VPATH entries or FILENAME starts at the root,
there is nothing we can do. */
Wed May 15 10:14:14 CDT 1996 Rob Tulloh <tulloh@tivoli.com> * dir.c: WIN32 does not support inode. For now, fully qualified pathname along with st_mtime will be keys for files. Fixed problem where vpath can be confused when files are added to a directory after the directory has already been read in. The code now attempts to reread the directory if it discovers that the datestamp on the directory has changed since it was cached by make. This problem only seems to occur on WIN32 right now so it is lumped under port #ifdef WIN32. * function.c: WIN32: call subproc library (CreateProcess()) instead of fork/exec. * job.c: WIN32: Added the code to do fork/exec/waitpid style processing on WIN32 systems via calls to subproc library. * main.c: WIN32: Several things added here. First, there is code for dealing with PATH and SHELL defaults. Make tries to figure out if the user has %PATH% set in the environment and sets it to %Path% if it is not set already. Make also looks to see if sh.exe is anywhere to be found. Code path through job.c will change based on existence of a working Bourne shell. The checking for default shell is done twice: once before makefiles are read in and again after. Fall back to MSDOS style execution mode if no sh.exe is found. Also added some debug support that allows user to pause make with -D switch and attach a debugger. This is especially useful for debugging recursive calls to make where problems appear only in the sub-make. * make.h: WIN32: A few macros and header files for WIN32 support. * misc.c: WIN32: Added a function end_of_token_w32() to assist in parsing code in read.c. * read.c: WIN32: Fixes similar to MSDOS which allow colon to appear in filenames. Use of colon in filenames would otherwise confuse make. * remake.c: WIN32: Added include of io.h to eliminate compiler warnings. Added some code to default LIBDIR if it is not set on WIN32. * variable.c: WIN32: Added support for detecting Path/PATH and converting them to semicolon separated lists for make's internal use. New function sync_Path_environment() which is called in job.c and function.c before creating a new process. Caller must set Path in environment since we don't have fork() to do this for us. * vpath.c: WIN32: Added detection for filenames containing forward or backward slashes. * NMakefile: WIN32: Visual C compatible makefile for use with nmake. Use this to build GNU make the first time on Windows NT or Windows 95. * README.WIN32: WIN32: Contains some helpful notes. * build_w32.bat: WIN32: If you don't like nmake, use this the first time you build GNU make on Windows NT or Windows 95. * config.h.WIN32: WIN32 version of config.h * subproc.bat: WIN32: A bat file used to build the subproc library from the top-level NMakefile. Needed because WIndows 95 (nmake) doesn't allow you to cd in a make rule. * w32/include/dirent.h * w32/compat/dirent.c: WIN32: opendir, readdir, closedir, etc. * w32/include/pathstuff.h: WIN32: used by files needed functions defined in pathstuff.c (prototypes). * w32/include/sub_proc.h: WIN32: prototypes for subproc.lib functions. * w32/include/w32err.h: WIN32: prototypes for w32err.c. * w32/pathstuff.c: WIN32: File and Path/Path conversion functions. * w32/subproc/build.bat: WIN32: build script for subproc library if you don't wish to use nmake. * w32/subproc/NMakefile: WIN32: Visual C compatible makefile for use with nmake. Used to build subproc library. * w32/subproc/misc.c: WIN32: subproc library support code * w32/subproc/proc.h: WIN32: subproc library support code * w32/subproc/sub_proc.c: WIN32: subproc library source code * w32/subproc/w32err.c: WIN32: subproc library support code
1996-05-22 21:51:45 +00:00
if (**file == '/'
1997-04-07 07:21:16 +00:00
#if defined (WINDOWS32) || defined (__MSDOS__)
|| **file == '\\'
Wed May 15 10:14:14 CDT 1996 Rob Tulloh <tulloh@tivoli.com> * dir.c: WIN32 does not support inode. For now, fully qualified pathname along with st_mtime will be keys for files. Fixed problem where vpath can be confused when files are added to a directory after the directory has already been read in. The code now attempts to reread the directory if it discovers that the datestamp on the directory has changed since it was cached by make. This problem only seems to occur on WIN32 right now so it is lumped under port #ifdef WIN32. * function.c: WIN32: call subproc library (CreateProcess()) instead of fork/exec. * job.c: WIN32: Added the code to do fork/exec/waitpid style processing on WIN32 systems via calls to subproc library. * main.c: WIN32: Several things added here. First, there is code for dealing with PATH and SHELL defaults. Make tries to figure out if the user has %PATH% set in the environment and sets it to %Path% if it is not set already. Make also looks to see if sh.exe is anywhere to be found. Code path through job.c will change based on existence of a working Bourne shell. The checking for default shell is done twice: once before makefiles are read in and again after. Fall back to MSDOS style execution mode if no sh.exe is found. Also added some debug support that allows user to pause make with -D switch and attach a debugger. This is especially useful for debugging recursive calls to make where problems appear only in the sub-make. * make.h: WIN32: A few macros and header files for WIN32 support. * misc.c: WIN32: Added a function end_of_token_w32() to assist in parsing code in read.c. * read.c: WIN32: Fixes similar to MSDOS which allow colon to appear in filenames. Use of colon in filenames would otherwise confuse make. * remake.c: WIN32: Added include of io.h to eliminate compiler warnings. Added some code to default LIBDIR if it is not set on WIN32. * variable.c: WIN32: Added support for detecting Path/PATH and converting them to semicolon separated lists for make's internal use. New function sync_Path_environment() which is called in job.c and function.c before creating a new process. Caller must set Path in environment since we don't have fork() to do this for us. * vpath.c: WIN32: Added detection for filenames containing forward or backward slashes. * NMakefile: WIN32: Visual C compatible makefile for use with nmake. Use this to build GNU make the first time on Windows NT or Windows 95. * README.WIN32: WIN32: Contains some helpful notes. * build_w32.bat: WIN32: If you don't like nmake, use this the first time you build GNU make on Windows NT or Windows 95. * config.h.WIN32: WIN32 version of config.h * subproc.bat: WIN32: A bat file used to build the subproc library from the top-level NMakefile. Needed because WIndows 95 (nmake) doesn't allow you to cd in a make rule. * w32/include/dirent.h * w32/compat/dirent.c: WIN32: opendir, readdir, closedir, etc. * w32/include/pathstuff.h: WIN32: used by files needed functions defined in pathstuff.c (prototypes). * w32/include/sub_proc.h: WIN32: prototypes for subproc.lib functions. * w32/include/w32err.h: WIN32: prototypes for w32err.c. * w32/pathstuff.c: WIN32: File and Path/Path conversion functions. * w32/subproc/build.bat: WIN32: build script for subproc library if you don't wish to use nmake. * w32/subproc/NMakefile: WIN32: Visual C compatible makefile for use with nmake. Used to build subproc library. * w32/subproc/misc.c: WIN32: subproc library support code * w32/subproc/proc.h: WIN32: subproc library support code * w32/subproc/sub_proc.c: WIN32: subproc library source code * w32/subproc/w32err.c: WIN32: subproc library support code
1996-05-22 21:51:45 +00:00
|| (*file)[1] == ':'
#endif
|| (vpaths == 0 && general_vpath == 0))
1991-06-03 20:37:27 +00:00
return 0;
for (v = vpaths; v != 0; v = v->next)
if (pattern_matches (v->pattern, v->percent, *file))
1993-02-08 22:50:00 +00:00
if (selective_vpath_search (v, file, mtime_ptr))
1991-06-03 20:37:27 +00:00
return 1;
if (general_vpath != 0
1993-02-08 22:50:00 +00:00
&& selective_vpath_search (general_vpath, file, mtime_ptr))
1991-06-03 20:37:27 +00:00
return 1;
return 0;
}
/* Search the given VPATH list for a directory where the name pointed
1993-02-08 22:50:00 +00:00
to by FILE exists. If it is found, we set *FILE to the newly malloc'd
name of the existing file, *MTIME_PTR (if MTIME_PTR is not NULL) to
its modtime (or zero if no stat call was done), and we return 1.
1991-06-03 20:37:27 +00:00
Otherwise we return 0. */
static int
1993-02-08 22:50:00 +00:00
selective_vpath_search (path, file, mtime_ptr)
1991-06-03 20:37:27 +00:00
struct vpath *path;
char **file;
1998-10-03 05:39:55 +00:00
FILE_TIMESTAMP *mtime_ptr;
1991-06-03 20:37:27 +00:00
{
int not_target;
char *name, *n;
char *filename;
register char **vpath = path->searchpath;
unsigned int maxvpath = path->maxlen;
register unsigned int i;
unsigned int flen, vlen, name_dplen;
int exists = 0;
/* Find out if *FILE is a target.
If and only if it is NOT a target, we will accept prospective
files that don't exist but are mentioned in a makefile. */
{
struct file *f = lookup_file (*file);
not_target = f == 0 || !f->is_target;
}
flen = strlen (*file);
/* Split *FILE into a directory prefix and a name-within-directory.
NAME_DPLEN gets the length of the prefix; FILENAME gets the
pointer to the name-within-directory and FLEN is its length. */
n = strrchr (*file, '/');
1997-04-07 07:21:16 +00:00
#if defined (WINDOWS32) || defined (__MSDOS__)
/* We need the rightmost slash or backslash. */
{
char *bslash = strrchr(*file, '\\');
1997-04-07 07:21:16 +00:00
if (!n || bslash > n)
n = bslash;
}
Wed May 15 10:14:14 CDT 1996 Rob Tulloh <tulloh@tivoli.com> * dir.c: WIN32 does not support inode. For now, fully qualified pathname along with st_mtime will be keys for files. Fixed problem where vpath can be confused when files are added to a directory after the directory has already been read in. The code now attempts to reread the directory if it discovers that the datestamp on the directory has changed since it was cached by make. This problem only seems to occur on WIN32 right now so it is lumped under port #ifdef WIN32. * function.c: WIN32: call subproc library (CreateProcess()) instead of fork/exec. * job.c: WIN32: Added the code to do fork/exec/waitpid style processing on WIN32 systems via calls to subproc library. * main.c: WIN32: Several things added here. First, there is code for dealing with PATH and SHELL defaults. Make tries to figure out if the user has %PATH% set in the environment and sets it to %Path% if it is not set already. Make also looks to see if sh.exe is anywhere to be found. Code path through job.c will change based on existence of a working Bourne shell. The checking for default shell is done twice: once before makefiles are read in and again after. Fall back to MSDOS style execution mode if no sh.exe is found. Also added some debug support that allows user to pause make with -D switch and attach a debugger. This is especially useful for debugging recursive calls to make where problems appear only in the sub-make. * make.h: WIN32: A few macros and header files for WIN32 support. * misc.c: WIN32: Added a function end_of_token_w32() to assist in parsing code in read.c. * read.c: WIN32: Fixes similar to MSDOS which allow colon to appear in filenames. Use of colon in filenames would otherwise confuse make. * remake.c: WIN32: Added include of io.h to eliminate compiler warnings. Added some code to default LIBDIR if it is not set on WIN32. * variable.c: WIN32: Added support for detecting Path/PATH and converting them to semicolon separated lists for make's internal use. New function sync_Path_environment() which is called in job.c and function.c before creating a new process. Caller must set Path in environment since we don't have fork() to do this for us. * vpath.c: WIN32: Added detection for filenames containing forward or backward slashes. * NMakefile: WIN32: Visual C compatible makefile for use with nmake. Use this to build GNU make the first time on Windows NT or Windows 95. * README.WIN32: WIN32: Contains some helpful notes. * build_w32.bat: WIN32: If you don't like nmake, use this the first time you build GNU make on Windows NT or Windows 95. * config.h.WIN32: WIN32 version of config.h * subproc.bat: WIN32: A bat file used to build the subproc library from the top-level NMakefile. Needed because WIndows 95 (nmake) doesn't allow you to cd in a make rule. * w32/include/dirent.h * w32/compat/dirent.c: WIN32: opendir, readdir, closedir, etc. * w32/include/pathstuff.h: WIN32: used by files needed functions defined in pathstuff.c (prototypes). * w32/include/sub_proc.h: WIN32: prototypes for subproc.lib functions. * w32/include/w32err.h: WIN32: prototypes for w32err.c. * w32/pathstuff.c: WIN32: File and Path/Path conversion functions. * w32/subproc/build.bat: WIN32: build script for subproc library if you don't wish to use nmake. * w32/subproc/NMakefile: WIN32: Visual C compatible makefile for use with nmake. Used to build subproc library. * w32/subproc/misc.c: WIN32: subproc library support code * w32/subproc/proc.h: WIN32: subproc library support code * w32/subproc/sub_proc.c: WIN32: subproc library source code * w32/subproc/w32err.c: WIN32: subproc library support code
1996-05-22 21:51:45 +00:00
#endif
1991-06-03 20:37:27 +00:00
name_dplen = n != 0 ? n - *file : 0;
filename = name_dplen > 0 ? n + 1 : *file;
if (name_dplen > 0)
flen -= name_dplen + 1;
/* Allocate enough space for the biggest VPATH entry,
a slash, the directory prefix that came with *FILE,
another slash (although this one may not always be
necessary), the filename, and a null terminator. */
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
name = (char *) xmalloc (maxvpath + 1 + name_dplen + 1 + flen + 1);
1991-06-03 20:37:27 +00:00
/* Try each VPATH entry. */
for (i = 0; vpath[i] != 0; ++i)
{
1993-02-08 22:50:00 +00:00
int exists_in_cache = 0;
1991-06-03 20:37:27 +00:00
n = name;
/* Put the next VPATH entry into NAME at N and increment N past it. */
vlen = strlen (vpath[i]);
bcopy (vpath[i], n, vlen);
n += vlen;
/* Add the directory prefix already in *FILE. */
if (name_dplen > 0)
{
1997-08-27 20:30:54 +00:00
#ifndef VMS
1991-06-03 20:37:27 +00:00
*n++ = '/';
1997-08-27 20:30:54 +00:00
#endif
1991-06-03 20:37:27 +00:00
bcopy (*file, n, name_dplen);
n += name_dplen;
}
1997-04-07 07:21:16 +00:00
#if defined (WINDOWS32) || defined (__MSDOS__)
/* Cause the next if to treat backslash and slash alike. */
if (n != name && n[-1] == '\\' )
n[-1] = '/';
#endif
1991-06-03 20:37:27 +00:00
/* Now add the name-within-directory at the end of NAME. */
1997-08-27 20:30:54 +00:00
#ifndef VMS
1991-06-03 20:37:27 +00:00
if (n != name && n[-1] != '/')
1993-03-24 20:13:56 +00:00
{
*n = '/';
bcopy (filename, n + 1, flen + 1);
}
else
1997-08-27 20:30:54 +00:00
#endif
1993-03-24 20:13:56 +00:00
bcopy (filename, n, flen + 1);
1991-06-03 20:37:27 +00:00
1993-12-23 04:42:29 +00:00
/* Check if the file is mentioned in a makefile. If *FILE is not
a target, that is enough for us to decide this file exists.
If *FILE is a target, then the file must be mentioned in the
makefile also as a target to be chosen.
The restriction that *FILE must not be a target for a
makefile-mentioned file to be chosen was added by an
inadequately commented change in July 1990; I am not sure off
hand what problem it fixes.
1997-08-27 20:30:54 +00:00
In December 1993 I loosened this restriction to allow a file
1993-12-23 04:42:29 +00:00
to be chosen if it is mentioned as a target in a makefile. This
seem logical. */
{
struct file *f = lookup_file (name);
if (f != 0)
exists = not_target || f->is_target;
}
1991-06-03 20:37:27 +00:00
if (!exists)
{
/* That file wasn't mentioned in the makefile.
See if it actually exists. */
1997-08-27 20:30:54 +00:00
#ifdef VMS
exists_in_cache = exists = dir_file_exists_p (vpath[i], filename);
#else
1991-06-03 20:37:27 +00:00
/* Clobber a null into the name at the last slash.
Now NAME is the name of the directory to look in. */
*n = '\0';
/* We know the directory is in the hash table now because either
construct_vpath_list or the code just above put it there.
Does the file we seek exist in it? */
1993-02-08 22:50:00 +00:00
exists_in_cache = exists = dir_file_exists_p (name, filename);
1997-08-27 20:30:54 +00:00
#endif
1991-06-03 20:37:27 +00:00
}
if (exists)
{
1993-02-08 22:50:00 +00:00
/* The file is in the directory cache.
Now check that it actually exists in the filesystem.
The cache may be out of date. When vpath thinks a file
exists, but stat fails for it, confusion results in the
higher levels. */
struct stat st;
1991-06-03 20:37:27 +00:00
1997-08-27 20:30:54 +00:00
#ifndef VMS
1991-06-03 20:37:27 +00:00
/* Put the slash back in NAME. */
*n = '/';
1997-08-27 20:30:54 +00:00
#endif
1991-06-03 20:37:27 +00:00
1993-02-08 22:50:00 +00:00
if (!exists_in_cache /* Makefile-mentioned file need not exist. */
1995-12-12 03:26:08 +00:00
|| stat (name, &st) == 0) /* Does it really exist? */
1993-02-08 22:50:00 +00:00
{
/* We have found a file.
Store the name we found into *FILE for the caller. */
1991-06-03 20:37:27 +00:00
1993-02-08 22:50:00 +00:00
*file = savestring (name, (n + 1 - name) + flen);
if (mtime_ptr != 0)
/* Store the modtime into *MTIME_PTR for the caller.
If we have had no need to stat the file here,
we record UNKNOWN_MTIME to indicate this. */
1998-10-03 05:39:55 +00:00
*mtime_ptr = (exists_in_cache
? FILE_TIMESTAMP_STAT_MODTIME (name, st)
: UNKNOWN_MTIME);
1993-02-08 22:50:00 +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
free (name);
1993-02-08 22:50:00 +00:00
return 1;
}
else
exists = 0;
1991-06-03 20:37:27 +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
free (name);
1991-06-03 20:37:27 +00:00
return 0;
}
/* Print the data base of VPATH search paths. */
void
print_vpath_data_base ()
{
register unsigned int nvpaths;
register struct vpath *v;
puts (_("\n# VPATH Search Paths\n"));
1991-06-03 20:37:27 +00:00
nvpaths = 0;
for (v = vpaths; v != 0; v = v->next)
{
register unsigned int i;
++nvpaths;
printf ("vpath %s ", v->pattern);
for (i = 0; v->searchpath[i] != 0; ++i)
printf ("%s%c", v->searchpath[i],
v->searchpath[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR);
1991-06-03 20:37:27 +00:00
}
if (vpaths == 0)
puts (_("# No `vpath' search paths."));
1991-06-03 20:37:27 +00:00
else
printf (_("\n# %u `vpath' search paths.\n"), nvpaths);
1991-06-03 20:37:27 +00:00
if (general_vpath == 0)
puts (_("\n# No general (`VPATH' variable) search path."));
1991-06-03 20:37:27 +00:00
else
{
register char **path = general_vpath->searchpath;
register unsigned int i;
fputs (_("\n# General (`VPATH' variable) search path:\n# "), stdout);
1991-06-03 20:37:27 +00:00
for (i = 0; path[i] != 0; ++i)
printf ("%s%c", path[i],
path[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR);
1991-06-03 20:37:27 +00:00
}
}