- Add {.,}[s-]include for silent include file failures

- Make traditional include statement include more than one file if present
  on the line.

Keeping up with the other's :-)
This commit is contained in:
christos 1998-08-06 13:42:22 +00:00
parent 02c9ad1755
commit 8bd03e9aab
2 changed files with 214 additions and 116 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: make.1,v 1.27 1998/04/01 14:18:10 christos Exp $ .\" $NetBSD: make.1,v 1.28 1998/08/06 13:42:22 christos Exp $
.\" .\"
.\" Copyright (c) 1990, 1993 .\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved. .\" The Regents of the University of California. All rights reserved.
@ -618,6 +618,14 @@ directories specified using the
.Fl I .Fl I
option are searched before the system option are searched before the system
makefile directory. makefile directory.
For compatibility with other versions of
.Nm
.Ql include file ...
is also accepted. If the include statement is prefixed with a
.Fl -
or an
.Fl s
then errors locating and/or opening include files are ignored.
.Pp .Pp
Conditional expressions are also preceded by a single dot as the first Conditional expressions are also preceded by a single dot as the first
character of a line. character of a line.

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse.c,v 1.37 1998/03/23 08:52:48 fair Exp $ */ /* $NetBSD: parse.c,v 1.38 1998/08/06 13:42:22 christos Exp $ */
/* /*
* Copyright (c) 1988, 1989, 1990, 1993 * Copyright (c) 1988, 1989, 1990, 1993
@ -39,14 +39,14 @@
*/ */
#ifdef MAKE_BOOTSTRAP #ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: parse.c,v 1.37 1998/03/23 08:52:48 fair Exp $"; static char rcsid[] = "$NetBSD: parse.c,v 1.38 1998/08/06 13:42:22 christos Exp $";
#else #else
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
#if 0 #if 0
static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
#else #else
__RCSID("$NetBSD: parse.c,v 1.37 1998/03/23 08:52:48 fair Exp $"); __RCSID("$NetBSD: parse.c,v 1.38 1998/08/06 13:42:22 christos Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
#endif #endif
@ -241,6 +241,8 @@ static struct {
{ ".WAIT", Wait, 0 }, { ".WAIT", Wait, 0 },
}; };
static void ParseErrorInternal __P((char *, size_t, int, char *, ...));
static void ParseVErrorInternal __P((char *, size_t, int, char *, va_list));
static int ParseFindKeyword __P((char *)); static int ParseFindKeyword __P((char *));
static int ParseLinkSrc __P((ClientData, ClientData)); static int ParseLinkSrc __P((ClientData, ClientData));
static int ParseDoOp __P((ClientData, ClientData)); static int ParseDoOp __P((ClientData, ClientData));
@ -303,7 +305,7 @@ ParseFindKeyword (str)
} }
/*- /*-
* Parse_Error -- * ParseVErrorInternal --
* Error message abort function for parsing. Prints out the context * Error message abort function for parsing. Prints out the context
* of the error (line number and file) as well as the message with * of the error (line number and file) as well as the message with
* two optional arguments. * two optional arguments.
@ -315,6 +317,77 @@ ParseFindKeyword (str)
* "fatals" is incremented if the level is PARSE_FATAL. * "fatals" is incremented if the level is PARSE_FATAL.
*/ */
/* VARARGS */ /* VARARGS */
static void
#ifdef __STDC__
ParseVErrorInternal(char *cfname, size_t clineno, int type, char *fmt,
va_list ap)
#else
ParseVErrorInternal(va_alist)
va_dcl
#endif
{
(void)fprintf(stderr, "\"%s\", line %d: ", cfname, (int) clineno);
if (type == PARSE_WARNING)
(void)fprintf(stderr, "warning: ");
(void)vfprintf(stderr, fmt, ap);
va_end(ap);
(void)fprintf(stderr, "\n");
(void)fflush(stderr);
if (type == PARSE_FATAL)
fatals += 1;
}
/*-
* ParseErrorInternal --
* Error function
*
* Results:
* None
*
* Side Effects:
* None
*/
/* VARARGS */
static void
#ifdef __STDC__
ParseErrorInternal(char *cfname, size_t clineno, int type, char *fmt, ...)
#else
ParseErrorInternal(va_alist)
va_dcl
#endif
{
va_list ap;
#ifdef __STDC__
va_start(ap, fmt);
#else
int type; /* Error type (PARSE_WARNING, PARSE_FATAL) */
char *fmt;
char *cfname;
size_t clineno;
va_start(ap);
cfname = va_arg(ap, char *);
clineno = va_arg(ap, size_t);
type = va_arg(ap, int);
fmt = va_arg(ap, char *);
#endif
ParseVErrorInternal(cfname, clineno, type, fmt, ap);
va_end(ap);
}
/*-
* Parse_Error --
* External interface to ParseErrorInternal; uses the default filename
* Line number.
*
* Results:
* None
*
* Side Effects:
* None
*/
/* VARARGS */
void void
#ifdef __STDC__ #ifdef __STDC__
Parse_Error(int type, char *fmt, ...) Parse_Error(int type, char *fmt, ...)
@ -334,16 +407,8 @@ Parse_Error(va_alist)
type = va_arg(ap, int); type = va_arg(ap, int);
fmt = va_arg(ap, char *); fmt = va_arg(ap, char *);
#endif #endif
ParseVErrorInternal(fname, lineno, type, fmt, ap);
(void)fprintf(stderr, "\"%s\", line %d: ", fname, lineno);
if (type == PARSE_WARNING)
(void)fprintf(stderr, "warning: ");
(void)vfprintf(stderr, fmt, ap);
va_end(ap); va_end(ap);
(void)fprintf(stderr, "\n");
(void)fflush(stderr);
if (type == PARSE_FATAL)
fatals += 1;
} }
/*- /*-
@ -1568,7 +1633,7 @@ Parse_AddIncludeDir (dir)
* ParseDoInclude -- * ParseDoInclude --
* Push to another file. * Push to another file.
* *
* The input is the line minus the #include. A file spec is a string * The input is the line minus the `.'. A file spec is a string
* enclosed in <> or "". The former is looked for only in sysIncPath. * enclosed in <> or "". The former is looked for only in sysIncPath.
* The latter in . and the directories specified by -I command line * The latter in . and the directories specified by -I command line
* options * options
@ -1582,14 +1647,16 @@ Parse_AddIncludeDir (dir)
*--------------------------------------------------------------------- *---------------------------------------------------------------------
*/ */
static void static void
ParseDoInclude (file) ParseDoInclude (line)
char *file; /* file specification */ char *line;
{ {
char *fullname; /* full pathname of file */ char *fullname; /* full pathname of file */
IFile *oldFile; /* state associated with current file */ IFile *oldFile; /* state associated with current file */
char endc; /* the character which ends the file spec */ char endc; /* the character which ends the file spec */
char *cp; /* current position in file spec */ char *cp; /* current position in file spec */
Boolean isSystem; /* TRUE if makefile is a system makefile */ Boolean isSystem; /* TRUE if makefile is a system makefile */
int silent = (*line != 'i') ? 1 : 0;
char *file = &line[7 + silent];
/* /*
* Skip to delimiter character so we know where to look * Skip to delimiter character so we know where to look
@ -1702,6 +1769,7 @@ ParseDoInclude (file)
if (fullname == (char *) NULL) { if (fullname == (char *) NULL) {
*cp = endc; *cp = endc;
if (!silent)
Parse_Error (PARSE_FATAL, "Could not find %s", file); Parse_Error (PARSE_FATAL, "Could not find %s", file);
return; return;
} }
@ -1736,6 +1804,7 @@ ParseDoInclude (file)
curFILE = fopen (fullname, "r"); curFILE = fopen (fullname, "r");
curPTR = NULL; curPTR = NULL;
if (curFILE == (FILE * ) NULL) { if (curFILE == (FILE * ) NULL) {
if (!silent)
Parse_Error (PARSE_FATAL, "Cannot open %s", fullname); Parse_Error (PARSE_FATAL, "Cannot open %s", fullname);
/* /*
* Pop to previous file * Pop to previous file
@ -1789,8 +1858,8 @@ Parse_FromString(str)
* ParseTraditionalInclude -- * ParseTraditionalInclude --
* Push to another file. * Push to another file.
* *
* The input is the line minus the "include". The file name is * The input is the current line. The file name(s) are
* the string following the "include". * following the "include".
* *
* Results: * Results:
* None * None
@ -1801,20 +1870,25 @@ Parse_FromString(str)
*--------------------------------------------------------------------- *---------------------------------------------------------------------
*/ */
static void static void
ParseTraditionalInclude (file) ParseTraditionalInclude (line)
char *file; /* file specification */ char *line;
{ {
char *fullname; /* full pathname of file */ char *fullname; /* full pathname of file */
IFile *oldFile; /* state associated with current file */ IFile *oldFile; /* state associated with current file */
char *cp; /* current position in file spec */ char *cp; /* current position in file spec */
char *prefEnd; char *prefEnd;
int done = 0;
int silent = (line[0] != 'i') ? 1 : 0;
char *file = &line[silent + 7];
char *cfname = fname;
size_t clineno = lineno;
/* /*
* Skip over whitespace * Skip over whitespace
*/ */
while ((*file == ' ') || (*file == '\t')) { while (isspace((unsigned char)*file))
file++; file++;
}
if (*file == '\0') { if (*file == '\0') {
Parse_Error (PARSE_FATAL, Parse_Error (PARSE_FATAL,
@ -1822,20 +1896,23 @@ ParseTraditionalInclude (file)
return; return;
} }
for (; !done; file = cp + 1) {
/* /*
* Skip to end of line or next whitespace * Skip to end of line or next whitespace
*/ */
for (cp = file; *cp && *cp != '\n' && *cp != '\t' && *cp != ' '; cp++) { for (cp = file; *cp && !isspace((unsigned char) *cp); cp++)
continue; continue;
}
if (*cp)
*cp = '\0'; *cp = '\0';
else
done = 1;
/* /*
* Substitute for any variables in the file name before trying to * Substitute for any variables in the file name before trying to
* find the thing. * find the thing.
*/ */
file = Var_Subst (NULL, file, VAR_CMD, FALSE); file = Var_Subst(NULL, file, VAR_CMD, FALSE);
/* /*
* Now we know the file's name, we attempt to find the durn thing. * Now we know the file's name, we attempt to find the durn thing.
@ -1848,36 +1925,36 @@ ParseTraditionalInclude (file)
* XXX - this *does* search in the current directory, right? * XXX - this *does* search in the current directory, right?
*/ */
prefEnd = strrchr (fname, '/'); prefEnd = strrchr(cfname, '/');
if (prefEnd != (char *)NULL) { if (prefEnd != NULL) {
char *newName; char *newName;
*prefEnd = '\0'; *prefEnd = '\0';
newName = str_concat (fname, file, STR_ADDSLASH); newName = str_concat(cfname, file, STR_ADDSLASH);
fullname = Dir_FindFile (newName, parseIncPath); fullname = Dir_FindFile(newName, parseIncPath);
if (fullname == (char *)NULL) { if (fullname == NULL) {
fullname = Dir_FindFile(newName, dirSearchPath); fullname = Dir_FindFile(newName, dirSearchPath);
} }
free (newName); free (newName);
*prefEnd = '/'; *prefEnd = '/';
} else { } else {
fullname = (char *)NULL; fullname = NULL;
} }
if (fullname == (char *)NULL) { if (fullname == NULL) {
/* /*
* System makefile or makefile wasn't found in same directory as * System makefile or makefile wasn't found in same directory as
* included makefile. Search for it first on the -I search path, * included makefile. Search for it first on the -I search path,
* then on the .PATH search path, if not found in a -I directory. * then on the .PATH search path, if not found in a
* XXX: Suffix specific? * -I directory. XXX: Suffix specific?
*/ */
fullname = Dir_FindFile (file, parseIncPath); fullname = Dir_FindFile(file, parseIncPath);
if (fullname == (char *)NULL) { if (fullname == NULL) {
fullname = Dir_FindFile(file, dirSearchPath); fullname = Dir_FindFile(file, dirSearchPath);
} }
} }
if (fullname == (char *)NULL) { if (fullname == NULL) {
/* /*
* Still haven't found the makefile. Look for it on the system * Still haven't found the makefile. Look for it on the system
* path as a last resort. * path as a last resort.
@ -1885,45 +1962,53 @@ ParseTraditionalInclude (file)
fullname = Dir_FindFile(file, sysIncPath); fullname = Dir_FindFile(file, sysIncPath);
} }
if (fullname == (char *) NULL) { if (fullname == NULL) {
Parse_Error (PARSE_FATAL, "Could not find %s", file); if (!silent)
return; ParseErrorInternal(cfname, clineno, PARSE_FATAL,
"Could not find %s", file);
free(file);
continue;
} }
free(file);
/* /*
* Once we find the absolute path to the file, we get to save all the * Once we find the absolute path to the file, we get to save all
* state from the current file before we can start reading this * the state from the current file before we can start reading this
* include file. The state is stored in an IFile structure which * include file. The state is stored in an IFile structure which
* is placed on a list with other IFile structures. The list makes * is placed on a list with other IFile structures. The list makes
* a very nice stack to track how we got here... * a very nice stack to track how we got here...
*/ */
oldFile = (IFile *) emalloc (sizeof (IFile)); oldFile = (IFile *) emalloc(sizeof(IFile));
oldFile->fname = fname; oldFile->fname = fname;
oldFile->F = curFILE; oldFile->F = curFILE;
oldFile->p = curPTR; oldFile->p = curPTR;
oldFile->lineno = lineno; oldFile->lineno = lineno;
(void) Lst_AtFront (includes, (ClientData)oldFile); (void) Lst_AtFront(includes, (ClientData)oldFile);
/* /*
* Once the previous state has been saved, we can get down to reading * Once the previous state has been saved, we can get down to
* the new file. We set up the name of the file to be the absolute * reading the new file. We set up the name of the file to be the
* name of the include file so error messages refer to the right * absolute name of the include file so error messages refer to the
* place. Naturally enough, we start reading at line number 0. * right place. Naturally enough, we start reading at line number 0.
*/ */
fname = fullname; fname = fullname;
lineno = 0; lineno = 0;
curFILE = fopen (fullname, "r"); curFILE = fopen(fullname, "r");
curPTR = NULL; curPTR = NULL;
if (curFILE == (FILE * ) NULL) { if (curFILE == NULL) {
Parse_Error (PARSE_FATAL, "Cannot open %s", fullname); if (!silent)
ParseErrorInternal(cfname, clineno, PARSE_FATAL,
"Cannot open %s", fullname);
/* /*
* Pop to previous file * Pop to previous file
*/ */
(void) ParseEOF(1); (void) ParseEOF(1);
} }
}
} }
#endif #endif
@ -2393,8 +2478,10 @@ Parse_File(name, stream)
for (cp = line + 1; isspace (*cp); cp++) { for (cp = line + 1; isspace (*cp); cp++) {
continue; continue;
} }
if (strncmp (cp, "include", 7) == 0) { if (strncmp(cp, "include", 7) == 0 ||
ParseDoInclude (cp + 7); ((cp[0] == 's' || cp[0] == '-') &&
strncmp(&line[1], "include", 7) == 0)) {
ParseDoInclude (cp);
goto nextLine; goto nextLine;
} else if (strncmp(cp, "undef", 5) == 0) { } else if (strncmp(cp, "undef", 5) == 0) {
char *cp2; char *cp2;
@ -2446,13 +2533,16 @@ Parse_File(name, stream)
} }
} }
#ifdef SYSVINCLUDE #ifdef SYSVINCLUDE
} else if (strncmp (line, "include", 7) == 0 && } else if (((strncmp(line, "include", 7) == 0 &&
isspace((unsigned char) line[7]) && isspace((unsigned char) line[7])) ||
((line[0] == 's' || line[0] == '-') &&
strncmp(&line[1], "include", 7) == 0 &&
isspace((unsigned char) line[8]))) &&
strchr(line, ':') == NULL) { strchr(line, ':') == NULL) {
/* /*
* It's an S3/S5-style "include". * It's an S3/S5-style "include".
*/ */
ParseTraditionalInclude (line + 7); ParseTraditionalInclude (line);
goto nextLine; goto nextLine;
#endif #endif
} else if (Parse_IsVar (line)) { } else if (Parse_IsVar (line)) {