1994-03-23 22:12:55 +08:00
|
|
|
|
/* Reading and parsing of makefiles for GNU Make.
|
2002-07-11 14:38:57 +08:00
|
|
|
|
Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
|
2007-07-05 03:35:15 +08:00
|
|
|
|
1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
|
2006-02-12 06:16:04 +08:00
|
|
|
|
Foundation, Inc.
|
1992-02-14 18:52:22 +08:00
|
|
|
|
This file is part of GNU Make.
|
|
|
|
|
|
2006-02-12 03:02:21 +08:00
|
|
|
|
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
|
2007-07-05 03:35:15 +08:00
|
|
|
|
Foundation; either version 3 of the License, or (at your option) any later
|
|
|
|
|
version.
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2006-02-12 03:02:21 +08:00
|
|
|
|
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.
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2006-02-12 03:02:21 +08:00
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
2007-07-05 03:35:15 +08:00
|
|
|
|
this program. If not, see <http://www.gnu.org/licenses/>. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
1999-07-28 14:23:37 +08:00
|
|
|
|
#include "make.h"
|
|
|
|
|
|
1998-07-31 04:54:47 +08:00
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
1999-02-22 15:23:30 +08:00
|
|
|
|
#include <glob.h>
|
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
#include "dep.h"
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#include "filedef.h"
|
|
|
|
|
#include "job.h"
|
|
|
|
|
#include "commands.h"
|
1992-02-14 18:52:22 +08:00
|
|
|
|
#include "variable.h"
|
1998-07-31 04:54:47 +08:00
|
|
|
|
#include "rule.h"
|
1999-11-22 14:15:35 +08:00
|
|
|
|
#include "debug.h"
|
2002-07-11 14:38:57 +08:00
|
|
|
|
#include "hash.h"
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#ifndef WINDOWS32
|
1996-05-14 02:39:02 +08:00
|
|
|
|
#ifndef _AMIGA
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifndef VMS
|
1992-02-14 18:52:22 +08:00
|
|
|
|
#include <pwd.h>
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#else
|
2006-04-07 09:43:44 +08:00
|
|
|
|
struct passwd *getpwnam (char *name);
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif
|
1996-05-14 02:39:02 +08:00
|
|
|
|
#endif
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#endif /* !WINDOWS32 */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
/* A 'struct ebuffer' controls the origin of the makefile we are currently
|
|
|
|
|
eval'ing.
|
|
|
|
|
*/
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
struct ebuffer
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2002-07-08 10:26:47 +08:00
|
|
|
|
char *buffer; /* Start of the current line in the buffer. */
|
|
|
|
|
char *bufnext; /* Start of the next line in the buffer. */
|
|
|
|
|
char *bufstart; /* Start of the entire buffer. */
|
|
|
|
|
unsigned int size; /* Malloc'd size of buffer. */
|
|
|
|
|
FILE *fp; /* File, or NULL if this is an internal buffer. */
|
|
|
|
|
struct floc floc; /* Info on the file in fp (if any). */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
1998-07-31 04:54:47 +08:00
|
|
|
|
/* Types of "words" that can be read in a makefile. */
|
|
|
|
|
enum make_word_type
|
|
|
|
|
{
|
|
|
|
|
w_bogus, w_eol, w_static, w_variable, w_colon, w_dcolon, w_semicolon,
|
2002-09-24 06:16:40 +08:00
|
|
|
|
w_varassign
|
1998-07-31 04:54:47 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
/* A `struct conditionals' contains the information describing
|
|
|
|
|
all the active conditionals in a makefile.
|
|
|
|
|
|
|
|
|
|
The global variable `conditionals' contains the conditionals
|
|
|
|
|
information for the current makefile. It is initialized from
|
|
|
|
|
the static structure `toplevel_conditionals' and is later changed
|
|
|
|
|
to new structures for included makefiles. */
|
|
|
|
|
|
|
|
|
|
struct conditionals
|
|
|
|
|
{
|
1992-12-24 05:14:20 +08:00
|
|
|
|
unsigned int if_cmds; /* Depth of conditional nesting. */
|
|
|
|
|
unsigned int allocated; /* Elts allocated in following arrays. */
|
2005-05-13 20:45:30 +08:00
|
|
|
|
char *ignoring; /* Are we ignoring or interpreting?
|
|
|
|
|
0=interpreting, 1=not yet interpreted,
|
|
|
|
|
2=already interpreted */
|
1992-12-24 05:14:20 +08:00
|
|
|
|
char *seen_else; /* Have we already seen an `else'? */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct conditionals toplevel_conditionals;
|
|
|
|
|
static struct conditionals *conditionals = &toplevel_conditionals;
|
1995-12-12 11:31:40 +08:00
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
/* Default directories to search for include files in */
|
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
static const char *default_include_directories[] =
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#if defined(WINDOWS32) && !defined(INCLUDEDIR)
|
2007-03-20 11:02:26 +08:00
|
|
|
|
/* This completely up to the user when they install MSVC or other packages.
|
|
|
|
|
This is defined as a placeholder. */
|
|
|
|
|
# define INCLUDEDIR "."
|
1996-05-23 05:51:45 +08:00
|
|
|
|
#endif
|
1992-08-28 08:14:48 +08:00
|
|
|
|
INCLUDEDIR,
|
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-10 02:02:06 +08:00
|
|
|
|
#ifndef _AMIGA
|
1992-02-14 18:52:22 +08:00
|
|
|
|
"/usr/gnu/include",
|
|
|
|
|
"/usr/local/include",
|
|
|
|
|
"/usr/include",
|
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-10 02:02:06 +08:00
|
|
|
|
#endif
|
1992-02-14 18:52:22 +08:00
|
|
|
|
0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* List of directories to search for include files in */
|
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
static const char **include_directories;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
/* Maximum length of an element of the above. */
|
|
|
|
|
|
|
|
|
|
static unsigned int max_incl_len;
|
|
|
|
|
|
|
|
|
|
/* The filename and pointer to line number of the
|
|
|
|
|
makefile currently being read in. */
|
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
const struct floc *reading_file = 0;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
/* The chain of makefiles read by read_makefile. */
|
|
|
|
|
|
|
|
|
|
static struct dep *read_makefiles = 0;
|
1996-03-20 22:57:41 +08:00
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
static int eval_makefile (const char *filename, int flags);
|
2006-04-07 09:43:44 +08:00
|
|
|
|
static int eval (struct ebuffer *buffer, int flags);
|
|
|
|
|
|
|
|
|
|
static long readline (struct ebuffer *ebuf);
|
|
|
|
|
static void do_define (char *name, unsigned int namelen,
|
|
|
|
|
enum variable_origin origin, struct ebuffer *ebuf);
|
|
|
|
|
static int conditional_line (char *line, int len, const struct floc *flocp);
|
2007-03-20 11:02:26 +08:00
|
|
|
|
static void record_files (struct nameseq *filenames, const char *pattern,
|
|
|
|
|
const char *pattern_percent, struct dep *deps,
|
2006-04-07 09:43:44 +08:00
|
|
|
|
unsigned int cmds_started, char *commands,
|
|
|
|
|
unsigned int commands_idx, int two_colon,
|
|
|
|
|
const struct floc *flocp);
|
|
|
|
|
static void record_target_var (struct nameseq *filenames, char *defn,
|
|
|
|
|
enum variable_origin origin, int enabled,
|
|
|
|
|
const struct floc *flocp);
|
|
|
|
|
static enum make_word_type get_next_mword (char *buffer, char *delim,
|
|
|
|
|
char **startp, unsigned int *length);
|
|
|
|
|
static void remove_comments (char *line);
|
|
|
|
|
static char *find_char_unquote (char *string, int stop1, int stop2,
|
|
|
|
|
int blank, int ignorevars);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
/* Read in all the makefiles and return the chain of their names. */
|
|
|
|
|
|
|
|
|
|
struct dep *
|
2007-03-20 11:02:26 +08:00
|
|
|
|
read_all_makefiles (const char **makefiles)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned int num_makefiles = 0;
|
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
/* Create *_LIST variables, to hold the makefiles, targets, and variables
|
|
|
|
|
we will be reading. */
|
|
|
|
|
|
|
|
|
|
define_variable ("MAKEFILE_LIST", sizeof ("MAKEFILE_LIST")-1, "", o_file, 0);
|
|
|
|
|
|
1999-11-22 14:15:35 +08:00
|
|
|
|
DB (DB_BASIC, (_("Reading makefiles...\n")));
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
/* If there's a non-null variable MAKEFILES, its value is a list of
|
|
|
|
|
files to read first thing. But don't let it prevent reading the
|
|
|
|
|
default makefiles and don't let the default goal come from there. */
|
|
|
|
|
|
|
|
|
|
{
|
1993-06-26 04:03:54 +08:00
|
|
|
|
char *value;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
char *name, *p;
|
|
|
|
|
unsigned int length;
|
|
|
|
|
|
1993-06-26 04:03:54 +08:00
|
|
|
|
{
|
|
|
|
|
/* Turn off --warn-undefined-variables while we expand MAKEFILES. */
|
|
|
|
|
int save = warn_undefined_variables_flag;
|
|
|
|
|
warn_undefined_variables_flag = 0;
|
|
|
|
|
|
|
|
|
|
value = allocated_variable_expand ("$(MAKEFILES)");
|
|
|
|
|
|
|
|
|
|
warn_undefined_variables_flag = save;
|
|
|
|
|
}
|
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
/* Set NAME to the start of next token and LENGTH to its length.
|
|
|
|
|
MAKEFILES is updated for finding remaining tokens. */
|
|
|
|
|
p = value;
|
1996-03-20 22:57:41 +08:00
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
while ((name = find_next_token ((const char **)&p, &length)) != 0)
|
1992-04-01 17:42:11 +08:00
|
|
|
|
{
|
|
|
|
|
if (*p != '\0')
|
|
|
|
|
*p++ = '\0';
|
2006-02-14 23:42:17 +08:00
|
|
|
|
eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
|
1992-04-01 17:42:11 +08:00
|
|
|
|
}
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
free (value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Read makefiles specified with -f switches. */
|
|
|
|
|
|
|
|
|
|
if (makefiles != 0)
|
|
|
|
|
while (*makefiles != 0)
|
|
|
|
|
{
|
|
|
|
|
struct dep *tail = read_makefiles;
|
|
|
|
|
register struct dep *d;
|
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (! eval_makefile (*makefiles, 0))
|
1993-12-03 04:44:03 +08:00
|
|
|
|
perror_with_name ("", *makefiles);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
/* Find the right element of read_makefiles. */
|
|
|
|
|
d = read_makefiles;
|
|
|
|
|
while (d->next != tail)
|
|
|
|
|
d = d->next;
|
|
|
|
|
|
1993-05-20 05:15:51 +08:00
|
|
|
|
/* Use the storage read_makefile allocates. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
*makefiles = dep_name (d);
|
|
|
|
|
++num_makefiles;
|
|
|
|
|
++makefiles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If there were no -f switches, try the default names. */
|
|
|
|
|
|
|
|
|
|
if (num_makefiles == 0)
|
|
|
|
|
{
|
|
|
|
|
static char *default_makefiles[] =
|
1996-05-14 02:39:02 +08:00
|
|
|
|
#ifdef VMS
|
1996-03-20 22:57:41 +08:00
|
|
|
|
/* all lower case since readdir() (the vms version) 'lowercasifies' */
|
1998-07-31 04:54:47 +08:00
|
|
|
|
{ "makefile.vms", "gnumakefile.", "makefile.", 0 };
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#else
|
1996-05-14 02:39:02 +08:00
|
|
|
|
#ifdef _AMIGA
|
|
|
|
|
{ "GNUmakefile", "Makefile", "SMakefile", 0 };
|
|
|
|
|
#else /* !Amiga && !VMS */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{ "GNUmakefile", "makefile", "Makefile", 0 };
|
1996-05-14 02:39:02 +08:00
|
|
|
|
#endif /* AMIGA */
|
|
|
|
|
#endif /* VMS */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
register char **p = default_makefiles;
|
|
|
|
|
while (*p != 0 && !file_exists_p (*p))
|
|
|
|
|
++p;
|
|
|
|
|
|
|
|
|
|
if (*p != 0)
|
1993-12-03 04:44:03 +08:00
|
|
|
|
{
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (! eval_makefile (*p, 0))
|
1993-12-03 04:44:03 +08:00
|
|
|
|
perror_with_name ("", *p);
|
|
|
|
|
}
|
1992-02-14 18:52:22 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* No default makefile was found. Add the default makefiles to the
|
|
|
|
|
`read_makefiles' chain so they will be updated if possible. */
|
|
|
|
|
struct dep *tail = read_makefiles;
|
1995-06-20 15:47:01 +08:00
|
|
|
|
/* Add them to the tail, after any MAKEFILES variable makefiles. */
|
|
|
|
|
while (tail != 0 && tail->next != 0)
|
|
|
|
|
tail = tail->next;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
for (p = default_makefiles; *p != 0; ++p)
|
|
|
|
|
{
|
2006-03-17 22:24:20 +08:00
|
|
|
|
struct dep *d = alloc_dep ();
|
2007-03-20 11:02:26 +08:00
|
|
|
|
d->file = enter_file (strcache_add (*p));
|
1992-02-14 18:52:22 +08:00
|
|
|
|
d->file->dontcare = 1;
|
1993-07-15 07:04:39 +08:00
|
|
|
|
/* Tell update_goal_chain to bail out as soon as this file is
|
|
|
|
|
made, and main not to die if we can't make this file. */
|
|
|
|
|
d->changed = RM_DONTCARE;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
if (tail == 0)
|
|
|
|
|
read_makefiles = d;
|
|
|
|
|
else
|
|
|
|
|
tail->next = d;
|
|
|
|
|
tail = d;
|
|
|
|
|
}
|
|
|
|
|
if (tail != 0)
|
|
|
|
|
tail->next = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return read_makefiles;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-26 06:01:47 +08:00
|
|
|
|
/* Install a new conditional and return the previous one. */
|
|
|
|
|
|
|
|
|
|
static struct conditionals *
|
|
|
|
|
install_conditionals (struct conditionals *new)
|
|
|
|
|
{
|
|
|
|
|
struct conditionals *save = conditionals;
|
|
|
|
|
|
2006-04-10 06:09:24 +08:00
|
|
|
|
memset (new, '\0', sizeof (*new));
|
2002-10-26 06:01:47 +08:00
|
|
|
|
conditionals = new;
|
|
|
|
|
|
|
|
|
|
return save;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free the current conditionals and reinstate a saved one. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
restore_conditionals (struct conditionals *saved)
|
|
|
|
|
{
|
|
|
|
|
/* Free any space allocated by conditional_line. */
|
|
|
|
|
if (conditionals->ignoring)
|
|
|
|
|
free (conditionals->ignoring);
|
|
|
|
|
if (conditionals->seen_else)
|
|
|
|
|
free (conditionals->seen_else);
|
|
|
|
|
|
|
|
|
|
/* Restore state. */
|
|
|
|
|
conditionals = saved;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-04 10:12:52 +08:00
|
|
|
|
static int
|
2007-03-20 11:02:26 +08:00
|
|
|
|
eval_makefile (const char *filename, int flags)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
|
|
|
|
struct dep *deps;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
struct ebuffer ebuf;
|
|
|
|
|
const struct floc *curfile;
|
2006-02-10 13:29:00 +08:00
|
|
|
|
char *expanded = 0;
|
1992-09-17 04:15:19 +08:00
|
|
|
|
int makefile_errno;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
int r;
|
1998-10-03 13:39:55 +08:00
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
filename = strcache_add (filename);
|
|
|
|
|
ebuf.floc.filenm = filename;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
ebuf.floc.lineno = 1;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
1999-11-27 16:09:42 +08:00
|
|
|
|
if (ISDB (DB_VERBOSE))
|
1994-02-17 06:55:31 +08:00
|
|
|
|
{
|
2002-07-08 10:26:47 +08:00
|
|
|
|
printf (_("Reading makefile `%s'"), filename);
|
1994-02-17 06:55:31 +08:00
|
|
|
|
if (flags & RM_NO_DEFAULT_GOAL)
|
1999-07-28 14:23:37 +08:00
|
|
|
|
printf (_(" (no default goal)"));
|
1994-02-17 06:55:31 +08:00
|
|
|
|
if (flags & RM_INCLUDED)
|
1999-07-28 14:23:37 +08:00
|
|
|
|
printf (_(" (search path)"));
|
1994-02-17 06:55:31 +08:00
|
|
|
|
if (flags & RM_DONTCARE)
|
1999-07-28 14:23:37 +08:00
|
|
|
|
printf (_(" (don't care)"));
|
1994-02-17 06:55:31 +08:00
|
|
|
|
if (flags & RM_NO_TILDE)
|
1999-07-28 14:23:37 +08:00
|
|
|
|
printf (_(" (no ~ expansion)"));
|
1994-02-17 06:55:31 +08:00
|
|
|
|
puts ("...");
|
|
|
|
|
}
|
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
/* First, get a stream to read. */
|
|
|
|
|
|
1993-06-08 08:36:13 +08:00
|
|
|
|
/* Expand ~ in FILENAME unless it came from `include',
|
|
|
|
|
in which case it was already done. */
|
1993-07-15 07:04:39 +08:00
|
|
|
|
if (!(flags & RM_NO_TILDE) && filename[0] == '~')
|
1993-06-08 08:36:13 +08:00
|
|
|
|
{
|
2006-02-10 13:29:00 +08:00
|
|
|
|
expanded = tilde_expand (filename);
|
1993-06-08 08:36:13 +08:00
|
|
|
|
if (expanded != 0)
|
|
|
|
|
filename = expanded;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
ebuf.fp = fopen (filename, "r");
|
1992-09-17 04:15:19 +08:00
|
|
|
|
/* Save the error code so we print the right message later. */
|
|
|
|
|
makefile_errno = errno;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
/* If the makefile wasn't found and it's either a makefile from
|
1993-07-15 07:04:39 +08:00
|
|
|
|
the `MAKEFILES' variable or an included makefile,
|
1992-02-14 18:52:22 +08:00
|
|
|
|
search the included makefile search path for this makefile. */
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/')
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
unsigned int i;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
for (i = 0; include_directories[i] != 0; ++i)
|
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
const char *included = concat (include_directories[i], "/", filename);
|
2006-02-10 13:29:00 +08:00
|
|
|
|
ebuf.fp = fopen (included, "r");
|
|
|
|
|
if (ebuf.fp)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
filename = strcache_add (included);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Add FILENAME to the chain of read makefiles. */
|
2006-03-17 22:24:20 +08:00
|
|
|
|
deps = alloc_dep ();
|
1992-02-14 18:52:22 +08:00
|
|
|
|
deps->next = read_makefiles;
|
|
|
|
|
read_makefiles = deps;
|
|
|
|
|
deps->file = lookup_file (filename);
|
|
|
|
|
if (deps->file == 0)
|
2007-03-20 11:02:26 +08:00
|
|
|
|
deps->file = enter_file (filename);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
filename = deps->file->name;
|
1993-07-15 07:04:39 +08:00
|
|
|
|
deps->changed = flags;
|
2004-05-17 03:16:52 +08:00
|
|
|
|
if (flags & RM_DONTCARE)
|
|
|
|
|
deps->file->dontcare = 1;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2006-02-10 13:29:00 +08:00
|
|
|
|
if (expanded)
|
|
|
|
|
free (expanded);
|
|
|
|
|
|
1993-12-03 04:44:03 +08:00
|
|
|
|
/* If the makefile can't be found at all, give up entirely. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (ebuf.fp == 0)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
1993-12-03 04:44:03 +08:00
|
|
|
|
/* If we did some searching, errno has the error from the last
|
|
|
|
|
attempt, rather from FILENAME itself. Restore it in case the
|
|
|
|
|
caller wants to use it in a message. */
|
|
|
|
|
errno = makefile_errno;
|
|
|
|
|
return 0;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
/* Add this makefile to the list. */
|
|
|
|
|
do_variable_definition (&ebuf.floc, "MAKEFILE_LIST", filename, o_file,
|
|
|
|
|
f_append, 0);
|
|
|
|
|
|
|
|
|
|
/* Evaluate the makefile */
|
|
|
|
|
|
|
|
|
|
ebuf.size = 200;
|
|
|
|
|
ebuf.buffer = ebuf.bufnext = ebuf.bufstart = xmalloc (ebuf.size);
|
|
|
|
|
|
|
|
|
|
curfile = reading_file;
|
|
|
|
|
reading_file = &ebuf.floc;
|
|
|
|
|
|
|
|
|
|
r = eval (&ebuf, !(flags & RM_NO_DEFAULT_GOAL));
|
|
|
|
|
|
|
|
|
|
reading_file = curfile;
|
|
|
|
|
|
2002-08-08 08:11:19 +08:00
|
|
|
|
fclose (ebuf.fp);
|
|
|
|
|
|
|
|
|
|
free (ebuf.bufstart);
|
2005-04-08 20:51:20 +08:00
|
|
|
|
alloca (0);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2002-10-15 05:54:04 +08:00
|
|
|
|
eval_buffer (char *buffer)
|
2002-07-08 10:26:47 +08:00
|
|
|
|
{
|
|
|
|
|
struct ebuffer ebuf;
|
2002-10-26 06:01:47 +08:00
|
|
|
|
struct conditionals *saved;
|
|
|
|
|
struct conditionals new;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
const struct floc *curfile;
|
|
|
|
|
int r;
|
|
|
|
|
|
|
|
|
|
/* Evaluate the buffer */
|
|
|
|
|
|
|
|
|
|
ebuf.size = strlen (buffer);
|
|
|
|
|
ebuf.buffer = ebuf.bufnext = ebuf.bufstart = buffer;
|
|
|
|
|
ebuf.fp = NULL;
|
|
|
|
|
|
|
|
|
|
ebuf.floc = *reading_file;
|
|
|
|
|
|
|
|
|
|
curfile = reading_file;
|
|
|
|
|
reading_file = &ebuf.floc;
|
|
|
|
|
|
2002-10-26 06:01:47 +08:00
|
|
|
|
saved = install_conditionals (&new);
|
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
r = eval (&ebuf, 1);
|
|
|
|
|
|
2002-10-26 06:01:47 +08:00
|
|
|
|
restore_conditionals (saved);
|
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
reading_file = curfile;
|
|
|
|
|
|
2005-04-08 20:51:20 +08:00
|
|
|
|
alloca (0);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Read file FILENAME as a makefile and add its contents to the data base.
|
|
|
|
|
|
2002-10-26 06:01:47 +08:00
|
|
|
|
SET_DEFAULT is true if we are allowed to set the default goal. */
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2002-10-15 05:54:04 +08:00
|
|
|
|
eval (struct ebuffer *ebuf, int set_default)
|
2002-07-08 10:26:47 +08:00
|
|
|
|
{
|
2003-01-30 15:49:17 +08:00
|
|
|
|
char *collapsed = 0;
|
|
|
|
|
unsigned int collapsed_length = 0;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
unsigned int commands_len = 200;
|
|
|
|
|
char *commands;
|
|
|
|
|
unsigned int commands_idx = 0;
|
|
|
|
|
unsigned int cmds_started, tgts_started;
|
|
|
|
|
int ignoring = 0, in_ignored_define = 0;
|
|
|
|
|
int no_targets = 0; /* Set when reading a rule without targets. */
|
|
|
|
|
struct nameseq *filenames = 0;
|
|
|
|
|
struct dep *deps = 0;
|
|
|
|
|
long nlines = 0;
|
|
|
|
|
int two_colon = 0;
|
2007-03-20 11:02:26 +08:00
|
|
|
|
const char *pattern = 0;
|
|
|
|
|
const char *pattern_percent;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
struct floc *fstart;
|
|
|
|
|
struct floc fi;
|
|
|
|
|
|
|
|
|
|
#define record_waiting_files() \
|
|
|
|
|
do \
|
2007-06-19 12:47:58 +08:00
|
|
|
|
{ \
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (filenames != 0) \
|
|
|
|
|
{ \
|
|
|
|
|
fi.lineno = tgts_started; \
|
|
|
|
|
record_files (filenames, pattern, pattern_percent, deps, \
|
|
|
|
|
cmds_started, commands, commands_idx, two_colon, \
|
2005-02-28 06:24:30 +08:00
|
|
|
|
&fi); \
|
2002-07-08 10:26:47 +08:00
|
|
|
|
} \
|
|
|
|
|
filenames = 0; \
|
|
|
|
|
commands_idx = 0; \
|
|
|
|
|
no_targets = 0; \
|
2007-03-20 11:02:26 +08:00
|
|
|
|
pattern = 0; \
|
2002-07-08 10:26:47 +08:00
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
pattern_percent = 0;
|
|
|
|
|
cmds_started = tgts_started = 1;
|
|
|
|
|
|
|
|
|
|
fstart = &ebuf->floc;
|
|
|
|
|
fi.filenm = ebuf->floc.filenm;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
/* Loop over lines in the file.
|
|
|
|
|
The strategy is to accumulate target names in FILENAMES, dependencies
|
|
|
|
|
in DEPS and commands in COMMANDS. These are used to define a rule
|
2002-07-08 10:26:47 +08:00
|
|
|
|
when the start of the next rule (or eof) is encountered.
|
|
|
|
|
|
|
|
|
|
When you see a "continue" in the loop below, that means we are moving on
|
|
|
|
|
to the next line _without_ ending any rule that we happen to be working
|
|
|
|
|
with at the moment. If you see a "goto rule_complete", then the
|
|
|
|
|
statement we just parsed also finishes the previous rule. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
1999-07-21 06:34:41 +08:00
|
|
|
|
commands = xmalloc (200);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
while (1)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2004-01-21 14:32:59 +08:00
|
|
|
|
unsigned int linelen;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
char *line;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
unsigned int wlen;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
char *p;
|
|
|
|
|
char *p2;
|
|
|
|
|
|
|
|
|
|
/* Grab the next line to be evaluated */
|
|
|
|
|
ebuf->floc.lineno += nlines;
|
|
|
|
|
nlines = readline (ebuf);
|
|
|
|
|
|
|
|
|
|
/* If there is nothing left to eval, we're done. */
|
|
|
|
|
if (nlines < 0)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* If this line is empty, skip it. */
|
|
|
|
|
line = ebuf->buffer;
|
|
|
|
|
if (line[0] == '\0')
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
linelen = strlen (line);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
1994-06-24 18:34:03 +08:00
|
|
|
|
/* Check for a shell command line first.
|
|
|
|
|
If it is not one, we can stop treating tab specially. */
|
2006-11-19 04:53:44 +08:00
|
|
|
|
if (line[0] == cmd_prefix)
|
1994-06-24 18:34:03 +08:00
|
|
|
|
{
|
|
|
|
|
if (no_targets)
|
|
|
|
|
/* Ignore the commands in a rule with no targets. */
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* If there is no preceding rule line, don't treat this line
|
|
|
|
|
as a command, even though it begins with a tab character.
|
|
|
|
|
SunOS 4 make appears to behave this way. */
|
|
|
|
|
|
|
|
|
|
if (filenames != 0)
|
|
|
|
|
{
|
|
|
|
|
if (ignoring)
|
|
|
|
|
/* Yep, this is a shell command, and we don't care. */
|
|
|
|
|
continue;
|
|
|
|
|
|
2007-11-05 05:54:00 +08:00
|
|
|
|
/* Append this command line to the line being accumulated.
|
|
|
|
|
Strip command prefix chars that appear after newlines. */
|
1994-06-24 18:34:03 +08:00
|
|
|
|
if (commands_idx == 0)
|
2002-07-08 10:26:47 +08:00
|
|
|
|
cmds_started = ebuf->floc.lineno;
|
|
|
|
|
|
2007-11-05 05:54:00 +08:00
|
|
|
|
if (linelen + commands_idx > commands_len)
|
1994-06-24 18:34:03 +08:00
|
|
|
|
{
|
2007-11-05 05:54:00 +08:00
|
|
|
|
commands_len = (linelen + commands_idx) * 2;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
commands = xrealloc (commands, commands_len);
|
1994-06-24 18:34:03 +08:00
|
|
|
|
}
|
2007-11-05 05:54:00 +08:00
|
|
|
|
p = &commands[commands_idx];
|
|
|
|
|
p2 = line + 1;
|
|
|
|
|
while (--linelen)
|
|
|
|
|
{
|
|
|
|
|
++commands_idx;
|
|
|
|
|
*(p++) = *p2;
|
|
|
|
|
if (p2[0] == '\n' && p2[1] == cmd_prefix)
|
|
|
|
|
{
|
|
|
|
|
++p2;
|
|
|
|
|
--linelen;
|
|
|
|
|
}
|
|
|
|
|
++p2;
|
|
|
|
|
}
|
|
|
|
|
*p = '\n';
|
|
|
|
|
++commands_idx;
|
1994-06-24 18:34:03 +08:00
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-25 07:14:15 +08:00
|
|
|
|
/* This line is not a shell command line. Don't worry about tabs.
|
|
|
|
|
Get more space if we need it; we don't need to preserve the current
|
|
|
|
|
contents of the buffer. */
|
1994-06-24 18:34:03 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (collapsed_length < linelen+1)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2002-07-08 10:26:47 +08:00
|
|
|
|
collapsed_length = linelen+1;
|
2003-03-25 07:14:15 +08:00
|
|
|
|
if (collapsed)
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (collapsed);
|
|
|
|
|
collapsed = xmalloc (collapsed_length);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
2002-07-08 10:26:47 +08:00
|
|
|
|
strcpy (collapsed, line);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
/* Collapse continuation lines. */
|
|
|
|
|
collapse_continuations (collapsed);
|
|
|
|
|
remove_comments (collapsed);
|
|
|
|
|
|
1998-07-31 04:54:47 +08:00
|
|
|
|
/* Compare a word, both length and contents. */
|
2007-06-19 12:47:58 +08:00
|
|
|
|
#define word1eq(s) (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))
|
1992-02-14 18:52:22 +08:00
|
|
|
|
p = collapsed;
|
1999-10-15 15:00:58 +08:00
|
|
|
|
while (isspace ((unsigned char)*p))
|
1992-02-14 18:52:22 +08:00
|
|
|
|
++p;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
1994-06-24 18:34:03 +08:00
|
|
|
|
if (*p == '\0')
|
2002-07-08 10:26:47 +08:00
|
|
|
|
/* This line is completely empty--ignore it. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
1998-07-31 04:54:47 +08:00
|
|
|
|
/* Find the end of the first token. Note we don't need to worry about
|
|
|
|
|
* ":" here since we compare tokens by length (so "export" will never
|
|
|
|
|
* be equal to "export:").
|
|
|
|
|
*/
|
1999-10-15 15:00:58 +08:00
|
|
|
|
for (p2 = p+1; *p2 != '\0' && !isspace ((unsigned char)*p2); ++p2)
|
2002-07-08 10:26:47 +08:00
|
|
|
|
;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
wlen = p2 - p;
|
1997-04-07 15:21:16 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
/* Find the start of the second token. If it looks like a target or
|
|
|
|
|
variable definition it can't be a preprocessor token so skip
|
|
|
|
|
them--this allows variables/targets named `ifdef', `export', etc. */
|
1999-10-15 15:00:58 +08:00
|
|
|
|
while (isspace ((unsigned char)*p2))
|
1997-04-07 15:21:16 +08:00
|
|
|
|
++p2;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
if ((p2[0] == ':' || p2[0] == '+' || p2[0] == '=') && p2[1] == '\0')
|
1998-07-31 04:54:47 +08:00
|
|
|
|
{
|
2002-07-08 10:26:47 +08:00
|
|
|
|
/* It can't be a preprocessor token so skip it if we're ignoring */
|
|
|
|
|
if (ignoring)
|
|
|
|
|
continue;
|
|
|
|
|
|
1998-07-31 04:54:47 +08:00
|
|
|
|
goto skip_conditionals;
|
|
|
|
|
}
|
1997-04-07 15:21:16 +08:00
|
|
|
|
|
1994-06-24 18:34:03 +08:00
|
|
|
|
/* We must first check for conditional and `define' directives before
|
|
|
|
|
ignoring anything, since they control what we will do with
|
|
|
|
|
following lines. */
|
|
|
|
|
|
2005-05-13 20:45:30 +08:00
|
|
|
|
if (!in_ignored_define)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2007-06-19 12:47:58 +08:00
|
|
|
|
int i = conditional_line (p, wlen, fstart);
|
2005-05-13 20:45:30 +08:00
|
|
|
|
if (i != -2)
|
|
|
|
|
{
|
|
|
|
|
if (i == -1)
|
|
|
|
|
fatal (fstart, _("invalid syntax in conditional"));
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
2005-05-13 20:45:30 +08:00
|
|
|
|
ignoring = i;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
1998-07-31 04:54:47 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (word1eq ("endef"))
|
1992-02-14 19:30:14 +08:00
|
|
|
|
{
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (!in_ignored_define)
|
|
|
|
|
fatal (fstart, _("extraneous `endef'"));
|
|
|
|
|
in_ignored_define = 0;
|
1992-10-25 11:24:24 +08:00
|
|
|
|
continue;
|
1992-02-14 19:30:14 +08:00
|
|
|
|
}
|
1998-07-31 04:54:47 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (word1eq ("define"))
|
1992-02-14 19:30:14 +08:00
|
|
|
|
{
|
|
|
|
|
if (ignoring)
|
|
|
|
|
in_ignored_define = 1;
|
|
|
|
|
else
|
|
|
|
|
{
|
1999-07-16 10:25:03 +08:00
|
|
|
|
if (*p2 == '\0')
|
2002-07-08 10:26:47 +08:00
|
|
|
|
fatal (fstart, _("empty variable name"));
|
1999-07-16 10:25:03 +08:00
|
|
|
|
|
1994-03-04 13:10:22 +08:00
|
|
|
|
/* Let the variable name be the whole rest of the line,
|
|
|
|
|
with trailing blanks stripped (comments have already been
|
|
|
|
|
removed), so it could be a complex variable/function
|
|
|
|
|
reference that might contain blanks. */
|
1999-10-15 15:00:58 +08:00
|
|
|
|
p = strchr (p2, '\0');
|
2000-06-07 13:43:37 +08:00
|
|
|
|
while (isblank ((unsigned char)p[-1]))
|
1994-03-04 13:10:22 +08:00
|
|
|
|
--p;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
do_define (p2, p - p2, o_file, ebuf);
|
1992-02-14 19:30:14 +08:00
|
|
|
|
}
|
1992-10-25 11:24:24 +08:00
|
|
|
|
continue;
|
1992-02-14 19:30:14 +08:00
|
|
|
|
}
|
1998-07-31 04:54:47 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (word1eq ("override"))
|
1998-07-31 04:54:47 +08:00
|
|
|
|
{
|
1999-07-16 10:25:03 +08:00
|
|
|
|
if (*p2 == '\0')
|
2002-07-08 10:26:47 +08:00
|
|
|
|
error (fstart, _("empty `override' directive"));
|
|
|
|
|
|
2000-06-07 13:43:37 +08:00
|
|
|
|
if (strneq (p2, "define", 6)
|
|
|
|
|
&& (isblank ((unsigned char)p2[6]) || p2[6] == '\0'))
|
1993-01-15 03:26:47 +08:00
|
|
|
|
{
|
|
|
|
|
if (ignoring)
|
|
|
|
|
in_ignored_define = 1;
|
|
|
|
|
else
|
|
|
|
|
{
|
1994-04-23 05:57:47 +08:00
|
|
|
|
p2 = next_token (p2 + 6);
|
1999-07-16 10:25:03 +08:00
|
|
|
|
if (*p2 == '\0')
|
2002-07-08 10:26:47 +08:00
|
|
|
|
fatal (fstart, _("empty variable name"));
|
1999-07-16 10:25:03 +08:00
|
|
|
|
|
1994-03-04 13:10:22 +08:00
|
|
|
|
/* Let the variable name be the whole rest of the line,
|
|
|
|
|
with trailing blanks stripped (comments have already been
|
|
|
|
|
removed), so it could be a complex variable/function
|
|
|
|
|
reference that might contain blanks. */
|
1999-10-15 15:00:58 +08:00
|
|
|
|
p = strchr (p2, '\0');
|
2000-06-07 13:43:37 +08:00
|
|
|
|
while (isblank ((unsigned char)p[-1]))
|
1994-03-04 13:10:22 +08:00
|
|
|
|
--p;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
do_define (p2, p - p2, o_override, ebuf);
|
1993-01-15 03:26:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
1993-02-22 03:28:27 +08:00
|
|
|
|
else if (!ignoring
|
2002-07-08 10:26:47 +08:00
|
|
|
|
&& !try_variable_definition (fstart, p2, o_override, 0))
|
|
|
|
|
error (fstart, _("invalid `override' directive"));
|
1993-01-19 08:14:29 +08:00
|
|
|
|
|
|
|
|
|
continue;
|
1993-01-15 03:26:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
if (ignoring)
|
1992-10-30 05:49:15 +08:00
|
|
|
|
/* Ignore the line. We continue here so conditionals
|
|
|
|
|
can appear in the middle of a rule. */
|
|
|
|
|
continue;
|
1998-07-31 04:54:47 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (word1eq ("export"))
|
1992-05-04 06:03:26 +08:00
|
|
|
|
{
|
2002-07-08 10:26:47 +08:00
|
|
|
|
/* 'export' by itself causes everything to be exported. */
|
1992-05-05 06:37:19 +08:00
|
|
|
|
if (*p2 == '\0')
|
2002-07-08 10:26:47 +08:00
|
|
|
|
export_all_variables = 1;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
struct variable *v;
|
|
|
|
|
|
|
|
|
|
v = try_variable_definition (fstart, p2, o_file, 0);
|
|
|
|
|
if (v != 0)
|
|
|
|
|
v->export = v_export;
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-04-10 06:09:24 +08:00
|
|
|
|
unsigned int l;
|
2007-03-20 11:02:26 +08:00
|
|
|
|
const char *cp;
|
2002-09-19 04:51:58 +08:00
|
|
|
|
char *ap;
|
|
|
|
|
|
|
|
|
|
/* Expand the line so we can use indirect and constructed
|
|
|
|
|
variable names in an export command. */
|
2007-03-20 11:02:26 +08:00
|
|
|
|
cp = ap = allocated_variable_expand (p2);
|
2002-09-19 04:51:58 +08:00
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
for (p = find_next_token (&cp, &l); p != 0;
|
|
|
|
|
p = find_next_token (&cp, &l))
|
2002-07-08 10:26:47 +08:00
|
|
|
|
{
|
2006-04-10 06:09:24 +08:00
|
|
|
|
v = lookup_variable (p, l);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (v == 0)
|
2006-04-10 06:09:24 +08:00
|
|
|
|
v = define_variable_loc (p, l, "", o_file, 0, fstart);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
v->export = v_export;
|
|
|
|
|
}
|
2002-09-19 04:51:58 +08:00
|
|
|
|
|
|
|
|
|
free (ap);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
goto rule_complete;
|
1992-05-04 06:03:26 +08:00
|
|
|
|
}
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
if (word1eq ("unexport"))
|
1992-05-04 06:03:26 +08:00
|
|
|
|
{
|
1992-05-05 06:37:19 +08:00
|
|
|
|
if (*p2 == '\0')
|
|
|
|
|
export_all_variables = 0;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
2006-04-10 06:09:24 +08:00
|
|
|
|
unsigned int l;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
struct variable *v;
|
2007-03-20 11:02:26 +08:00
|
|
|
|
const char *cp;
|
2002-09-19 04:51:58 +08:00
|
|
|
|
char *ap;
|
|
|
|
|
|
|
|
|
|
/* Expand the line so we can use indirect and constructed
|
|
|
|
|
variable names in an unexport command. */
|
2007-03-20 11:02:26 +08:00
|
|
|
|
cp = ap = allocated_variable_expand (p2);
|
2002-09-19 04:51:58 +08:00
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
for (p = find_next_token (&cp, &l); p != 0;
|
|
|
|
|
p = find_next_token (&cp, &l))
|
2002-07-08 10:26:47 +08:00
|
|
|
|
{
|
2006-04-10 06:09:24 +08:00
|
|
|
|
v = lookup_variable (p, l);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (v == 0)
|
2006-04-10 06:09:24 +08:00
|
|
|
|
v = define_variable_loc (p, l, "", o_file, 0, fstart);
|
2002-09-10 15:27:28 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
v->export = v_noexport;
|
|
|
|
|
}
|
2002-09-19 04:51:58 +08:00
|
|
|
|
|
|
|
|
|
free (ap);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
}
|
|
|
|
|
goto rule_complete;
|
1992-05-04 06:03:26 +08:00
|
|
|
|
}
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
skip_conditionals:
|
|
|
|
|
if (word1eq ("vpath"))
|
1997-04-07 15:21:16 +08:00
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
const char *cp;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
char *vpat;
|
|
|
|
|
unsigned int l;
|
2007-03-20 11:02:26 +08:00
|
|
|
|
cp = variable_expand (p2);
|
|
|
|
|
p = find_next_token (&cp, &l);
|
1997-04-07 15:21:16 +08:00
|
|
|
|
if (p != 0)
|
|
|
|
|
{
|
2006-04-10 06:09:24 +08:00
|
|
|
|
vpat = savestring (p, l);
|
2007-03-20 11:02:26 +08:00
|
|
|
|
p = find_next_token (&cp, &l);
|
1997-04-07 15:21:16 +08:00
|
|
|
|
/* No searchpath means remove all previous
|
|
|
|
|
selective VPATH's with the same pattern. */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
/* No pattern means remove all previous selective VPATH's. */
|
2006-04-10 06:09:24 +08:00
|
|
|
|
vpat = 0;
|
|
|
|
|
construct_vpath_list (vpat, p);
|
|
|
|
|
if (vpat != 0)
|
|
|
|
|
free (vpat);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
goto rule_complete;
|
1997-04-07 15:21:16 +08:00
|
|
|
|
}
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude"))
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
|
|
|
|
/* We have found an `include' line specifying a nested
|
|
|
|
|
makefile to be read at this point. */
|
2002-07-08 10:26:47 +08:00
|
|
|
|
struct conditionals *save;
|
|
|
|
|
struct conditionals new_conditionals;
|
1992-08-28 07:53:17 +08:00
|
|
|
|
struct nameseq *files;
|
1996-05-10 01:28:47 +08:00
|
|
|
|
/* "-include" (vs "include") says no error if the file does not
|
|
|
|
|
exist. "sinclude" is an alias for this from SGI. */
|
2002-07-08 10:26:47 +08:00
|
|
|
|
int noerror = (p[0] != 'i');
|
1992-08-28 07:53:17 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
p = allocated_variable_expand (p2);
|
2005-06-27 09:01:07 +08:00
|
|
|
|
|
|
|
|
|
/* If no filenames, it's a no-op. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
if (*p == '\0')
|
2006-02-14 23:42:17 +08:00
|
|
|
|
{
|
|
|
|
|
free (p);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
1992-08-28 07:53:17 +08:00
|
|
|
|
|
|
|
|
|
/* Parse the list of file names. */
|
|
|
|
|
p2 = p;
|
|
|
|
|
files = multi_glob (parse_file_seq (&p2, '\0',
|
1993-05-04 05:14:22 +08:00
|
|
|
|
sizeof (struct nameseq),
|
|
|
|
|
1),
|
|
|
|
|
sizeof (struct nameseq));
|
1992-08-28 07:53:17 +08:00
|
|
|
|
free (p);
|
|
|
|
|
|
|
|
|
|
/* Save the state of conditionals and start
|
|
|
|
|
the included makefile with a clean slate. */
|
2002-10-26 06:01:47 +08:00
|
|
|
|
save = install_conditionals (&new_conditionals);
|
1992-08-28 07:53:17 +08:00
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
/* Record the rules that are waiting so they will determine
|
|
|
|
|
the default goal before those in the included makefile. */
|
|
|
|
|
record_waiting_files ();
|
1992-08-28 07:53:17 +08:00
|
|
|
|
|
|
|
|
|
/* Read each included makefile. */
|
|
|
|
|
while (files != 0)
|
|
|
|
|
{
|
|
|
|
|
struct nameseq *next = files->next;
|
2007-03-20 11:02:26 +08:00
|
|
|
|
const char *name = files->name;
|
1999-09-04 06:46:28 +08:00
|
|
|
|
int r;
|
|
|
|
|
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (files);
|
1992-08-28 07:53:17 +08:00
|
|
|
|
files = next;
|
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
r = eval_makefile (name, (RM_INCLUDED | RM_NO_TILDE
|
1999-09-04 06:46:28 +08:00
|
|
|
|
| (noerror ? RM_DONTCARE : 0)));
|
2006-02-14 23:42:17 +08:00
|
|
|
|
if (!r && !noerror)
|
|
|
|
|
error (fstart, "%s: %s", name, strerror (errno));
|
1992-08-28 07:53:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-26 06:01:47 +08:00
|
|
|
|
/* Restore conditional state. */
|
|
|
|
|
restore_conditionals (save);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
goto rule_complete;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
if (try_variable_definition (fstart, p, o_file, 0))
|
1992-10-25 11:24:24 +08:00
|
|
|
|
/* This line has been dealt with. */
|
2002-07-08 10:26:47 +08:00
|
|
|
|
goto rule_complete;
|
|
|
|
|
|
2004-09-21 21:51:58 +08:00
|
|
|
|
/* This line starts with a tab but was not caught above because there
|
|
|
|
|
was no preceding target, and the line might have been usable as a
|
|
|
|
|
variable definition. But now we know it is definitely lossage. */
|
2006-11-19 04:53:44 +08:00
|
|
|
|
if (line[0] == cmd_prefix)
|
2007-11-05 05:54:00 +08:00
|
|
|
|
fatal(fstart, _("recipe commences before first target"));
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
/* This line describes some target files. This is complicated by
|
|
|
|
|
the existence of target-specific variables, because we can't
|
|
|
|
|
expand the entire line until we know if we have one or not. So
|
|
|
|
|
we expand the line word by word until we find the first `:',
|
|
|
|
|
then check to see if it's a target-specific variable.
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
In this algorithm, `lb_next' will point to the beginning of the
|
|
|
|
|
unexpanded parts of the input buffer, while `p2' points to the
|
|
|
|
|
parts of the expanded buffer we haven't searched yet. */
|
1998-07-31 04:54:47 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
{
|
|
|
|
|
enum make_word_type wtype;
|
|
|
|
|
enum variable_origin v_origin;
|
2002-10-14 02:50:10 +08:00
|
|
|
|
int exported;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
char *cmdleft, *semip, *lb_next;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
unsigned int plen = 0;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
char *colonp;
|
2005-02-28 05:40:23 +08:00
|
|
|
|
const char *end, *beg; /* Helpers for whitespace stripping. */
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
/* Record the previous rule. */
|
|
|
|
|
|
|
|
|
|
record_waiting_files ();
|
|
|
|
|
tgts_started = fstart->lineno;
|
|
|
|
|
|
|
|
|
|
/* Search the line for an unquoted ; that is not after an
|
|
|
|
|
unquoted #. */
|
2005-06-26 05:30:13 +08:00
|
|
|
|
cmdleft = find_char_unquote (line, ';', '#', 0, 1);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (cmdleft != 0 && *cmdleft == '#')
|
|
|
|
|
{
|
|
|
|
|
/* We found a comment before a semicolon. */
|
|
|
|
|
*cmdleft = '\0';
|
|
|
|
|
cmdleft = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (cmdleft != 0)
|
|
|
|
|
/* Found one. Cut the line short there before expanding it. */
|
|
|
|
|
*(cmdleft++) = '\0';
|
|
|
|
|
semip = cmdleft;
|
|
|
|
|
|
|
|
|
|
collapse_continuations (line);
|
|
|
|
|
|
|
|
|
|
/* We can't expand the entire line, since if it's a per-target
|
|
|
|
|
variable we don't want to expand it. So, walk from the
|
|
|
|
|
beginning, expanding as we go, and looking for "interesting"
|
|
|
|
|
chars. The first word is always expandable. */
|
2006-04-10 06:09:24 +08:00
|
|
|
|
wtype = get_next_mword(line, NULL, &lb_next, &wlen);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
switch (wtype)
|
|
|
|
|
{
|
|
|
|
|
case w_eol:
|
|
|
|
|
if (cmdleft != 0)
|
2007-11-05 05:54:00 +08:00
|
|
|
|
fatal(fstart, _("missing rule before recipe"));
|
2002-07-08 10:26:47 +08:00
|
|
|
|
/* This line contained something but turned out to be nothing
|
|
|
|
|
but whitespace (a comment?). */
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
case w_colon:
|
|
|
|
|
case w_dcolon:
|
|
|
|
|
/* We accept and ignore rules without targets for
|
|
|
|
|
compatibility with SunOS 4 make. */
|
|
|
|
|
no_targets = 1;
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-10 06:09:24 +08:00
|
|
|
|
p2 = variable_expand_string(NULL, lb_next, wlen);
|
2005-02-28 05:40:23 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
while (1)
|
|
|
|
|
{
|
2006-04-10 06:09:24 +08:00
|
|
|
|
lb_next += wlen;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (cmdleft == 0)
|
|
|
|
|
{
|
|
|
|
|
/* Look for a semicolon in the expanded line. */
|
2005-06-26 05:30:13 +08:00
|
|
|
|
cmdleft = find_char_unquote (p2, ';', 0, 0, 0);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
if (cmdleft != 0)
|
|
|
|
|
{
|
|
|
|
|
unsigned long p2_off = p2 - variable_buffer;
|
|
|
|
|
unsigned long cmd_off = cmdleft - variable_buffer;
|
|
|
|
|
char *pend = p2 + strlen(p2);
|
|
|
|
|
|
|
|
|
|
/* Append any remnants of lb, then cut the line short
|
|
|
|
|
at the semicolon. */
|
|
|
|
|
*cmdleft = '\0';
|
|
|
|
|
|
|
|
|
|
/* One school of thought says that you shouldn't expand
|
|
|
|
|
here, but merely copy, since now you're beyond a ";"
|
|
|
|
|
and into a command script. However, the old parser
|
|
|
|
|
expanded the whole line, so we continue that for
|
|
|
|
|
backwards-compatiblity. Also, it wouldn't be
|
|
|
|
|
entirely consistent, since we do an unconditional
|
|
|
|
|
expand below once we know we don't have a
|
|
|
|
|
target-specific variable. */
|
|
|
|
|
(void)variable_expand_string(pend, lb_next, (long)-1);
|
|
|
|
|
lb_next += strlen(lb_next);
|
|
|
|
|
p2 = variable_buffer + p2_off;
|
|
|
|
|
cmdleft = variable_buffer + cmd_off + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-26 05:30:13 +08:00
|
|
|
|
colonp = find_char_unquote(p2, ':', 0, 0, 0);
|
2002-08-10 09:27:16 +08:00
|
|
|
|
#ifdef HAVE_DOS_PATHS
|
2002-07-08 10:26:47 +08:00
|
|
|
|
/* The drive spec brain-damage strikes again... */
|
|
|
|
|
/* Note that the only separators of targets in this context
|
|
|
|
|
are whitespace and a left paren. If others are possible,
|
|
|
|
|
they should be added to the string in the call to index. */
|
|
|
|
|
while (colonp && (colonp[1] == '/' || colonp[1] == '\\') &&
|
|
|
|
|
colonp > p2 && isalpha ((unsigned char)colonp[-1]) &&
|
|
|
|
|
(colonp == p2 + 1 || strchr (" \t(", colonp[-2]) != 0))
|
2005-06-26 05:30:13 +08:00
|
|
|
|
colonp = find_char_unquote(colonp + 1, ':', 0, 0, 0);
|
1998-07-31 04:54:47 +08:00
|
|
|
|
#endif
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (colonp != 0)
|
|
|
|
|
break;
|
1993-05-15 06:25:11 +08:00
|
|
|
|
|
2006-04-10 06:09:24 +08:00
|
|
|
|
wtype = get_next_mword(lb_next, NULL, &lb_next, &wlen);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (wtype == w_eol)
|
|
|
|
|
break;
|
1998-07-31 04:54:47 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
p2 += strlen(p2);
|
|
|
|
|
*(p2++) = ' ';
|
2006-04-10 06:09:24 +08:00
|
|
|
|
p2 = variable_expand_string(p2, lb_next, wlen);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
/* We don't need to worry about cmdleft here, because if it was
|
|
|
|
|
found in the variable_buffer the entire buffer has already
|
|
|
|
|
been expanded... we'll never get here. */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p2 = next_token (variable_buffer);
|
|
|
|
|
|
|
|
|
|
/* If the word we're looking at is EOL, see if there's _anything_
|
|
|
|
|
on the line. If not, a variable expanded to nothing, so ignore
|
|
|
|
|
it. If so, we can't parse this line so punt. */
|
|
|
|
|
if (wtype == w_eol)
|
|
|
|
|
{
|
|
|
|
|
if (*p2 != '\0')
|
|
|
|
|
/* There's no need to be ivory-tower about this: check for
|
|
|
|
|
one of the most common bugs found in makefiles... */
|
|
|
|
|
fatal (fstart, _("missing separator%s"),
|
2007-11-05 05:54:00 +08:00
|
|
|
|
(cmd_prefix == '\t' && !strneq(line, " ", 8))
|
|
|
|
|
? "" : _(" (did you mean TAB instead of 8 spaces?)"));
|
2002-07-08 10:26:47 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Make the colon the end-of-string so we know where to stop
|
|
|
|
|
looking for targets. */
|
|
|
|
|
*colonp = '\0';
|
|
|
|
|
filenames = multi_glob (parse_file_seq (&p2, '\0',
|
|
|
|
|
sizeof (struct nameseq),
|
|
|
|
|
1),
|
|
|
|
|
sizeof (struct nameseq));
|
|
|
|
|
*p2 = ':';
|
|
|
|
|
|
|
|
|
|
if (!filenames)
|
|
|
|
|
{
|
|
|
|
|
/* We accept and ignore rules without targets for
|
|
|
|
|
compatibility with SunOS 4 make. */
|
|
|
|
|
no_targets = 1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
/* This should never be possible; we handled it above. */
|
|
|
|
|
assert (*p2 != '\0');
|
|
|
|
|
++p2;
|
1998-07-31 04:54:47 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
/* Is this a one-colon or two-colon entry? */
|
|
|
|
|
two_colon = *p2 == ':';
|
|
|
|
|
if (two_colon)
|
|
|
|
|
p2++;
|
|
|
|
|
|
|
|
|
|
/* Test to see if it's a target-specific variable. Copy the rest
|
|
|
|
|
of the buffer over, possibly temporarily (we'll expand it later
|
|
|
|
|
if it's not a target-specific variable). PLEN saves the length
|
|
|
|
|
of the unparsed section of p2, for later. */
|
|
|
|
|
if (*lb_next != '\0')
|
|
|
|
|
{
|
2004-09-21 21:51:58 +08:00
|
|
|
|
unsigned int l = p2 - variable_buffer;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
plen = strlen (p2);
|
2006-04-10 06:09:24 +08:00
|
|
|
|
variable_buffer_output (p2+plen, lb_next, strlen (lb_next)+1);
|
2004-09-21 21:51:58 +08:00
|
|
|
|
p2 = variable_buffer + l;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-14 02:50:10 +08:00
|
|
|
|
/* See if it's an "override" or "export" keyword; if so see if what
|
|
|
|
|
comes after it looks like a variable definition. */
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
2006-04-10 06:09:24 +08:00
|
|
|
|
wtype = get_next_mword (p2, NULL, &p, &wlen);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
v_origin = o_file;
|
2002-10-14 02:50:10 +08:00
|
|
|
|
exported = 0;
|
|
|
|
|
if (wtype == w_static)
|
2004-01-21 14:32:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (word1eq ("override"))
|
|
|
|
|
{
|
|
|
|
|
v_origin = o_override;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
wtype = get_next_mword (p+wlen, NULL, &p, &wlen);
|
2004-01-21 14:32:59 +08:00
|
|
|
|
}
|
|
|
|
|
else if (word1eq ("export"))
|
|
|
|
|
{
|
|
|
|
|
exported = 1;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
wtype = get_next_mword (p+wlen, NULL, &p, &wlen);
|
2004-01-21 14:32:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
if (wtype != w_eol)
|
2006-04-10 06:09:24 +08:00
|
|
|
|
wtype = get_next_mword (p+wlen, NULL, NULL, NULL);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
if (wtype == w_varassign)
|
|
|
|
|
{
|
|
|
|
|
/* If there was a semicolon found, add it back, plus anything
|
|
|
|
|
after it. */
|
|
|
|
|
if (semip)
|
|
|
|
|
{
|
2003-01-30 15:49:17 +08:00
|
|
|
|
unsigned int l = p - variable_buffer;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
*(--semip) = ';';
|
|
|
|
|
variable_buffer_output (p2 + strlen (p2),
|
|
|
|
|
semip, strlen (semip)+1);
|
2003-01-30 15:49:17 +08:00
|
|
|
|
p = variable_buffer + l;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
}
|
2004-01-21 14:32:59 +08:00
|
|
|
|
record_target_var (filenames, p, v_origin, exported, fstart);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
filenames = 0;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This is a normal target, _not_ a target-specific variable.
|
|
|
|
|
Unquote any = in the dependency list. */
|
2005-06-26 05:30:13 +08:00
|
|
|
|
find_char_unquote (lb_next, '=', 0, 0, 0);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
/* We have some targets, so don't ignore the following commands. */
|
|
|
|
|
no_targets = 0;
|
|
|
|
|
|
|
|
|
|
/* Expand the dependencies, etc. */
|
|
|
|
|
if (*lb_next != '\0')
|
|
|
|
|
{
|
|
|
|
|
unsigned int l = p2 - variable_buffer;
|
|
|
|
|
(void) variable_expand_string (p2 + plen, lb_next, (long)-1);
|
|
|
|
|
p2 = variable_buffer + l;
|
|
|
|
|
|
|
|
|
|
/* Look for a semicolon in the expanded line. */
|
|
|
|
|
if (cmdleft == 0)
|
|
|
|
|
{
|
2005-06-26 05:30:13 +08:00
|
|
|
|
cmdleft = find_char_unquote (p2, ';', 0, 0, 0);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (cmdleft != 0)
|
|
|
|
|
*(cmdleft++) = '\0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Is this a static pattern rule: `target: %targ: %dep; ...'? */
|
|
|
|
|
p = strchr (p2, ':');
|
|
|
|
|
while (p != 0 && p[-1] == '\\')
|
|
|
|
|
{
|
|
|
|
|
register char *q = &p[-1];
|
|
|
|
|
register int backslash = 0;
|
|
|
|
|
while (*q-- == '\\')
|
|
|
|
|
backslash = !backslash;
|
|
|
|
|
if (backslash)
|
|
|
|
|
p = strchr (p + 1, ':');
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
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-10 02:02:06 +08:00
|
|
|
|
#ifdef _AMIGA
|
2002-07-08 10:26:47 +08:00
|
|
|
|
/* Here, the situation is quite complicated. Let's have a look
|
|
|
|
|
at a couple of targets:
|
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-10 02:02:06 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
install: dev:make
|
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-10 02:02:06 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
dev:make: make
|
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-10 02:02:06 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
dev:make:: xyz
|
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-10 02:02:06 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
The rule is that it's only a target, if there are TWO :'s
|
|
|
|
|
OR a space around the :.
|
|
|
|
|
*/
|
|
|
|
|
if (p && !(isspace ((unsigned char)p[1]) || !p[1]
|
|
|
|
|
|| isspace ((unsigned char)p[-1])))
|
|
|
|
|
p = 0;
|
1996-05-23 05:51:45 +08:00
|
|
|
|
#endif
|
2002-08-10 09:27:16 +08:00
|
|
|
|
#ifdef HAVE_DOS_PATHS
|
|
|
|
|
{
|
|
|
|
|
int check_again;
|
|
|
|
|
do {
|
|
|
|
|
check_again = 0;
|
2003-03-25 07:14:15 +08:00
|
|
|
|
/* For DOS-style paths, skip a "C:\..." or a "C:/..." */
|
2002-08-10 09:27:16 +08:00
|
|
|
|
if (p != 0 && (p[1] == '\\' || p[1] == '/') &&
|
|
|
|
|
isalpha ((unsigned char)p[-1]) &&
|
|
|
|
|
(p == p2 + 1 || strchr (" \t:(", p[-2]) != 0)) {
|
|
|
|
|
p = strchr (p + 1, ':');
|
|
|
|
|
check_again = 1;
|
|
|
|
|
}
|
|
|
|
|
} while (check_again);
|
|
|
|
|
}
|
1995-03-09 09:42:12 +08:00
|
|
|
|
#endif
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (p != 0)
|
|
|
|
|
{
|
|
|
|
|
struct nameseq *target;
|
|
|
|
|
target = parse_file_seq (&p2, ':', sizeof (struct nameseq), 1);
|
|
|
|
|
++p2;
|
|
|
|
|
if (target == 0)
|
|
|
|
|
fatal (fstart, _("missing target pattern"));
|
|
|
|
|
else if (target->next != 0)
|
|
|
|
|
fatal (fstart, _("multiple target patterns"));
|
2007-03-20 11:02:26 +08:00
|
|
|
|
pattern_percent = find_percent_cached (&target->name);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
pattern = target->name;
|
|
|
|
|
if (pattern_percent == 0)
|
|
|
|
|
fatal (fstart, _("target pattern contains no `%%'"));
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (target);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
pattern = 0;
|
|
|
|
|
|
2005-02-28 05:40:23 +08:00
|
|
|
|
/* Strip leading and trailing whitespaces. */
|
|
|
|
|
beg = p2;
|
|
|
|
|
end = beg + strlen (beg) - 1;
|
|
|
|
|
strip_whitespace (&beg, &end);
|
|
|
|
|
|
|
|
|
|
if (beg <= end && *beg != '\0')
|
2002-07-08 21:05:02 +08:00
|
|
|
|
{
|
2005-10-24 21:01:39 +08:00
|
|
|
|
/* Put all the prerequisites here; they'll be parsed later. */
|
2006-03-17 22:24:20 +08:00
|
|
|
|
deps = alloc_dep ();
|
2007-03-20 11:02:26 +08:00
|
|
|
|
deps->name = strcache_add_len (beg, end - beg + 1);
|
2002-07-08 21:05:02 +08:00
|
|
|
|
}
|
2005-02-28 05:40:23 +08:00
|
|
|
|
else
|
|
|
|
|
deps = 0;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
commands_idx = 0;
|
|
|
|
|
if (cmdleft != 0)
|
|
|
|
|
{
|
|
|
|
|
/* Semicolon means rest of line is a command. */
|
2006-04-10 06:09:24 +08:00
|
|
|
|
unsigned int l = strlen (cmdleft);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
cmds_started = fstart->lineno;
|
|
|
|
|
|
|
|
|
|
/* Add this command line to the buffer. */
|
2006-04-10 06:09:24 +08:00
|
|
|
|
if (l + 2 > commands_len)
|
2002-07-08 10:26:47 +08:00
|
|
|
|
{
|
2006-04-10 06:09:24 +08:00
|
|
|
|
commands_len = (l + 2) * 2;
|
|
|
|
|
commands = xrealloc (commands, commands_len);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
}
|
2006-04-10 06:09:24 +08:00
|
|
|
|
memcpy (commands, cmdleft, l);
|
|
|
|
|
commands_idx += l;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
commands[commands_idx++] = '\n';
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-13 11:16:33 +08:00
|
|
|
|
/* Determine if this target should be made default. We used to do
|
|
|
|
|
this in record_files() but because of the delayed target recording
|
|
|
|
|
and because preprocessor directives are legal in target's commands
|
|
|
|
|
it is too late. Consider this fragment for example:
|
2005-02-28 06:24:30 +08:00
|
|
|
|
|
|
|
|
|
foo:
|
|
|
|
|
|
2005-05-03 21:57:20 +08:00
|
|
|
|
ifeq ($(.DEFAULT_GOAL),foo)
|
2005-02-28 06:24:30 +08:00
|
|
|
|
...
|
|
|
|
|
endif
|
|
|
|
|
|
2005-04-13 11:16:33 +08:00
|
|
|
|
Because the target is not recorded until after ifeq directive is
|
2005-05-03 21:57:20 +08:00
|
|
|
|
evaluated the .DEFAULT_GOAL does not contain foo yet as one
|
2005-04-13 11:16:33 +08:00
|
|
|
|
would expect. Because of this we have to move some of the logic
|
|
|
|
|
here. */
|
2005-02-28 06:24:30 +08:00
|
|
|
|
|
2005-05-03 21:57:20 +08:00
|
|
|
|
if (**default_goal_name == '\0' && set_default)
|
2005-02-28 06:24:30 +08:00
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
const char *name;
|
2005-02-28 06:24:30 +08:00
|
|
|
|
struct dep *d;
|
|
|
|
|
struct nameseq *t = filenames;
|
|
|
|
|
|
|
|
|
|
for (; t != 0; t = t->next)
|
|
|
|
|
{
|
|
|
|
|
int reject = 0;
|
|
|
|
|
name = t->name;
|
|
|
|
|
|
|
|
|
|
/* We have nothing to do if this is an implicit rule. */
|
|
|
|
|
if (strchr (name, '%') != 0)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* See if this target's name does not start with a `.',
|
|
|
|
|
unless it contains a slash. */
|
|
|
|
|
if (*name == '.' && strchr (name, '/') == 0
|
|
|
|
|
#ifdef HAVE_DOS_PATHS
|
|
|
|
|
&& strchr (name, '\\') == 0
|
|
|
|
|
#endif
|
2005-04-13 11:16:33 +08:00
|
|
|
|
)
|
2005-02-28 06:24:30 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* If this file is a suffix, don't let it be
|
|
|
|
|
the default goal file. */
|
|
|
|
|
for (d = suffix_file->deps; d != 0; d = d->next)
|
|
|
|
|
{
|
|
|
|
|
register struct dep *d2;
|
|
|
|
|
if (*dep_name (d) != '.' && streq (name, dep_name (d)))
|
|
|
|
|
{
|
|
|
|
|
reject = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
|
|
|
|
|
{
|
2006-04-10 06:09:24 +08:00
|
|
|
|
unsigned int l = strlen (dep_name (d2));
|
|
|
|
|
if (!strneq (name, dep_name (d2), l))
|
2005-02-28 06:24:30 +08:00
|
|
|
|
continue;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
if (streq (name + l, dep_name (d)))
|
2005-02-28 06:24:30 +08:00
|
|
|
|
{
|
|
|
|
|
reject = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reject)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!reject)
|
|
|
|
|
{
|
2005-05-03 21:57:20 +08:00
|
|
|
|
define_variable_global (".DEFAULT_GOAL", 13, t->name,
|
|
|
|
|
o_file, 0, NILF);
|
2005-02-28 06:24:30 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
1992-10-25 11:24:24 +08:00
|
|
|
|
|
|
|
|
|
/* We get here except in the case that we just read a rule line.
|
|
|
|
|
Record now the last rule we read, so following spurious
|
|
|
|
|
commands are properly diagnosed. */
|
2002-07-08 10:26:47 +08:00
|
|
|
|
rule_complete:
|
1992-10-25 11:24:24 +08:00
|
|
|
|
record_waiting_files ();
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
#undef word1eq
|
|
|
|
|
|
1992-12-24 05:14:20 +08:00
|
|
|
|
if (conditionals->if_cmds)
|
2002-07-08 10:26:47 +08:00
|
|
|
|
fatal (fstart, _("missing `endif'"));
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
/* At eof, record the last rule. */
|
|
|
|
|
record_waiting_files ();
|
|
|
|
|
|
2003-01-30 15:49:17 +08:00
|
|
|
|
if (collapsed)
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (collapsed);
|
|
|
|
|
free (commands);
|
1993-12-03 04:44:03 +08:00
|
|
|
|
|
2000-06-07 13:43:37 +08:00
|
|
|
|
return 1;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-06-26 05:30:13 +08:00
|
|
|
|
|
|
|
|
|
/* Remove comments from LINE.
|
|
|
|
|
This is done by copying the text at LINE onto itself. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
remove_comments (char *line)
|
|
|
|
|
{
|
|
|
|
|
char *comment;
|
|
|
|
|
|
|
|
|
|
comment = find_char_unquote (line, '#', 0, 0, 0);
|
|
|
|
|
|
|
|
|
|
if (comment != 0)
|
|
|
|
|
/* Cut off the line at the #. */
|
|
|
|
|
*comment = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
/* Execute a `define' directive.
|
|
|
|
|
The first line has already been read, and NAME is the name of
|
2002-07-08 10:26:47 +08:00
|
|
|
|
the variable to be defined. The following lines remain to be read. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
1998-10-03 13:39:55 +08:00
|
|
|
|
static void
|
2002-10-15 05:54:04 +08:00
|
|
|
|
do_define (char *name, unsigned int namelen,
|
|
|
|
|
enum variable_origin origin, struct ebuffer *ebuf)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2002-07-08 10:26:47 +08:00
|
|
|
|
struct floc defstart;
|
|
|
|
|
long nlines = 0;
|
|
|
|
|
int nlevels = 1;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
unsigned int length = 100;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
char *definition = xmalloc (length);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
unsigned int idx = 0;
|
|
|
|
|
char *p;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
1992-12-10 05:02:53 +08:00
|
|
|
|
/* Expand the variable name. */
|
2006-04-10 06:09:24 +08:00
|
|
|
|
char *var = alloca (namelen + 1);
|
|
|
|
|
memcpy (var, name, namelen);
|
1992-12-10 05:02:53 +08:00
|
|
|
|
var[namelen] = '\0';
|
|
|
|
|
var = variable_expand (var);
|
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
defstart = ebuf->floc;
|
|
|
|
|
|
|
|
|
|
while (1)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
1997-08-28 04:30:54 +08:00
|
|
|
|
unsigned int len;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
char *line;
|
1997-08-28 04:30:54 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
nlines = readline (ebuf);
|
2004-03-22 23:11:48 +08:00
|
|
|
|
ebuf->floc.lineno += nlines;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
/* If there is nothing left to eval, we're done. */
|
|
|
|
|
if (nlines < 0)
|
|
|
|
|
break;
|
1994-05-05 16:15:00 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
line = ebuf->buffer;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
collapse_continuations (line);
|
|
|
|
|
|
|
|
|
|
/* If the line doesn't begin with a tab, test to see if it introduces
|
|
|
|
|
another define, or ends one. */
|
|
|
|
|
|
|
|
|
|
/* Stop if we find an 'endef' */
|
2006-11-19 04:53:44 +08:00
|
|
|
|
if (line[0] != cmd_prefix)
|
2002-07-08 10:26:47 +08:00
|
|
|
|
{
|
|
|
|
|
p = next_token (line);
|
|
|
|
|
len = strlen (p);
|
|
|
|
|
|
|
|
|
|
/* If this is another 'define', increment the level count. */
|
|
|
|
|
if ((len == 6 || (len > 6 && isblank ((unsigned char)p[6])))
|
|
|
|
|
&& strneq (p, "define", 6))
|
|
|
|
|
++nlevels;
|
|
|
|
|
|
|
|
|
|
/* If this is an 'endef', decrement the count. If it's now 0,
|
|
|
|
|
we've found the last one. */
|
|
|
|
|
else if ((len == 5 || (len > 5 && isblank ((unsigned char)p[5])))
|
|
|
|
|
&& strneq (p, "endef", 5))
|
|
|
|
|
{
|
|
|
|
|
p += 5;
|
|
|
|
|
remove_comments (p);
|
|
|
|
|
if (*next_token (p) != '\0')
|
|
|
|
|
error (&ebuf->floc,
|
|
|
|
|
_("Extraneous text after `endef' directive"));
|
|
|
|
|
|
|
|
|
|
if (--nlevels == 0)
|
|
|
|
|
{
|
|
|
|
|
/* Define the variable. */
|
|
|
|
|
if (idx == 0)
|
|
|
|
|
definition[0] = '\0';
|
|
|
|
|
else
|
|
|
|
|
definition[idx - 1] = '\0';
|
|
|
|
|
|
|
|
|
|
/* Always define these variables in the global set. */
|
|
|
|
|
define_variable_global (var, strlen (var), definition,
|
|
|
|
|
origin, 1, &defstart);
|
|
|
|
|
free (definition);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Otherwise add this line to the variable definition. */
|
|
|
|
|
len = strlen (line);
|
|
|
|
|
if (idx + len + 1 > length)
|
|
|
|
|
{
|
|
|
|
|
length = (idx + len) * 2;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
definition = xrealloc (definition, length + 1);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-10 06:09:24 +08:00
|
|
|
|
memcpy (&definition[idx], line, len);
|
2002-07-08 10:26:47 +08:00
|
|
|
|
idx += len;
|
|
|
|
|
/* Separate lines with a newline. */
|
|
|
|
|
definition[idx++] = '\n';
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* No `endef'!! */
|
2002-07-08 10:26:47 +08:00
|
|
|
|
fatal (&defstart, _("missing `endef', unterminated `define'"));
|
1992-10-10 02:00:37 +08:00
|
|
|
|
|
|
|
|
|
/* NOTREACHED */
|
1998-10-03 13:39:55 +08:00
|
|
|
|
return;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Interpret conditional commands "ifdef", "ifndef", "ifeq",
|
|
|
|
|
"ifneq", "else" and "endif".
|
|
|
|
|
LINE is the input line, with the command as its first word.
|
|
|
|
|
|
|
|
|
|
FILENAME and LINENO are the filename and line number in the
|
|
|
|
|
current makefile. They are used for error messages.
|
|
|
|
|
|
2005-05-13 20:45:30 +08:00
|
|
|
|
Value is -2 if the line is not a conditional at all,
|
|
|
|
|
-1 if the line is an invalid conditional,
|
1992-02-14 18:52:22 +08:00
|
|
|
|
0 if following text should be interpreted,
|
|
|
|
|
1 if following text should be ignored. */
|
|
|
|
|
|
|
|
|
|
static int
|
2005-05-13 20:45:30 +08:00
|
|
|
|
conditional_line (char *line, int len, const struct floc *flocp)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
|
|
|
|
char *cmdname;
|
2005-05-13 20:45:30 +08:00
|
|
|
|
enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, c_else, c_endif } cmdtype;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
unsigned int o;
|
|
|
|
|
|
|
|
|
|
/* Compare a word, both length and contents. */
|
|
|
|
|
#define word1eq(s) (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1))
|
|
|
|
|
#define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
|
|
|
|
|
|
|
|
|
|
/* Make sure this line is a conditional. */
|
|
|
|
|
chkword ("ifdef", c_ifdef)
|
|
|
|
|
else chkword ("ifndef", c_ifndef)
|
|
|
|
|
else chkword ("ifeq", c_ifeq)
|
|
|
|
|
else chkword ("ifneq", c_ifneq)
|
|
|
|
|
else chkword ("else", c_else)
|
|
|
|
|
else chkword ("endif", c_endif)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
else
|
2005-05-13 20:45:30 +08:00
|
|
|
|
return -2;
|
|
|
|
|
|
|
|
|
|
/* Found one: skip past it and any whitespace after it. */
|
|
|
|
|
line = next_token (line + len);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2005-05-13 20:45:30 +08:00
|
|
|
|
#define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2005-05-13 20:45:30 +08:00
|
|
|
|
/* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */
|
|
|
|
|
if (cmdtype == c_endif)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
|
|
|
|
if (*line != '\0')
|
2005-05-13 20:45:30 +08:00
|
|
|
|
EXTRANEOUS ();
|
|
|
|
|
|
|
|
|
|
if (!conditionals->if_cmds)
|
1999-07-28 14:23:37 +08:00
|
|
|
|
fatal (flocp, _("extraneous `%s'"), cmdname);
|
2005-05-13 20:45:30 +08:00
|
|
|
|
|
|
|
|
|
--conditionals->if_cmds;
|
|
|
|
|
|
|
|
|
|
goto DONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* An 'else' statement can either be simple, or it can have another
|
|
|
|
|
conditional after it. */
|
|
|
|
|
if (cmdtype == c_else)
|
|
|
|
|
{
|
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
|
|
if (!conditionals->if_cmds)
|
|
|
|
|
fatal (flocp, _("extraneous `%s'"), cmdname);
|
|
|
|
|
|
|
|
|
|
o = conditionals->if_cmds - 1;
|
|
|
|
|
|
|
|
|
|
if (conditionals->seen_else[o])
|
|
|
|
|
fatal (flocp, _("only one `else' per conditional"));
|
|
|
|
|
|
|
|
|
|
/* Change the state of ignorance. */
|
|
|
|
|
switch (conditionals->ignoring[o])
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
/* We've just been interpreting. Never do it again. */
|
|
|
|
|
conditionals->ignoring[o] = 2;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
/* We've never interpreted yet. Maybe this time! */
|
|
|
|
|
conditionals->ignoring[o] = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* It's a simple 'else'. */
|
|
|
|
|
if (*line == '\0')
|
|
|
|
|
{
|
|
|
|
|
conditionals->seen_else[o] = 1;
|
|
|
|
|
goto DONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The 'else' has extra text. That text must be another conditional
|
|
|
|
|
and cannot be an 'else' or 'endif'. */
|
|
|
|
|
|
|
|
|
|
/* Find the length of the next word. */
|
|
|
|
|
for (p = line+1; *p != '\0' && !isspace ((unsigned char)*p); ++p)
|
|
|
|
|
;
|
|
|
|
|
len = p - line;
|
|
|
|
|
|
|
|
|
|
/* If it's 'else' or 'endif' or an illegal conditional, fail. */
|
|
|
|
|
if (word1eq("else") || word1eq("endif")
|
|
|
|
|
|| conditional_line (line, len, flocp) < 0)
|
|
|
|
|
EXTRANEOUS ();
|
1992-02-14 18:52:22 +08:00
|
|
|
|
else
|
2005-05-13 20:45:30 +08:00
|
|
|
|
{
|
|
|
|
|
/* conditional_line() created a new level of conditional.
|
|
|
|
|
Raise it back to this level. */
|
|
|
|
|
if (conditionals->ignoring[o] < 2)
|
|
|
|
|
conditionals->ignoring[o] = conditionals->ignoring[o+1];
|
|
|
|
|
--conditionals->if_cmds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goto DONE;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
1992-12-24 05:14:20 +08:00
|
|
|
|
if (conditionals->allocated == 0)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
1992-12-24 05:14:20 +08:00
|
|
|
|
conditionals->allocated = 5;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
conditionals->ignoring = xmalloc (conditionals->allocated);
|
|
|
|
|
conditionals->seen_else = xmalloc (conditionals->allocated);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-05-13 20:45:30 +08:00
|
|
|
|
o = conditionals->if_cmds++;
|
1992-12-24 05:14:20 +08:00
|
|
|
|
if (conditionals->if_cmds > conditionals->allocated)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
1992-12-24 05:14:20 +08:00
|
|
|
|
conditionals->allocated += 5;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
conditionals->ignoring = xrealloc (conditionals->ignoring,
|
|
|
|
|
conditionals->allocated);
|
|
|
|
|
conditionals->seen_else = xrealloc (conditionals->seen_else,
|
|
|
|
|
conditionals->allocated);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
1992-12-24 05:14:20 +08:00
|
|
|
|
/* Record that we have seen an `if...' but no `else' so far. */
|
2005-05-13 20:45:30 +08:00
|
|
|
|
conditionals->seen_else[o] = 0;
|
1992-12-24 05:14:20 +08:00
|
|
|
|
|
1992-06-11 10:07:33 +08:00
|
|
|
|
/* Search through the stack to see if we're already ignoring. */
|
2005-05-13 20:45:30 +08:00
|
|
|
|
for (i = 0; i < o; ++i)
|
1992-06-11 10:07:33 +08:00
|
|
|
|
if (conditionals->ignoring[i])
|
|
|
|
|
{
|
2005-05-13 20:45:30 +08:00
|
|
|
|
/* We are already ignoring, so just push a level to match the next
|
|
|
|
|
"else" or "endif", and keep ignoring. We don't want to expand
|
|
|
|
|
variables in the condition. */
|
|
|
|
|
conditionals->ignoring[o] = 1;
|
1992-06-11 10:07:33 +08:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-13 20:45:30 +08:00
|
|
|
|
if (cmdtype == c_ifdef || cmdtype == c_ifndef)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2002-09-10 15:27:28 +08:00
|
|
|
|
char *var;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
struct variable *v;
|
2005-05-13 20:45:30 +08:00
|
|
|
|
char *p;
|
2002-09-10 15:27:28 +08:00
|
|
|
|
|
|
|
|
|
/* Expand the thing we're looking up, so we can use indirect and
|
|
|
|
|
constructed variable names. */
|
|
|
|
|
var = allocated_variable_expand (line);
|
|
|
|
|
|
2004-01-21 14:32:59 +08:00
|
|
|
|
/* Make sure there's only one variable name to test. */
|
|
|
|
|
p = end_of_token (var);
|
|
|
|
|
i = p - var;
|
|
|
|
|
p = next_token (p);
|
|
|
|
|
if (*p != '\0')
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
var[i] = '\0';
|
2005-05-13 20:45:30 +08:00
|
|
|
|
v = lookup_variable (var, i);
|
|
|
|
|
|
|
|
|
|
conditionals->ignoring[o] =
|
|
|
|
|
((v != 0 && *v->value != '\0') == (cmdtype == c_ifndef));
|
2002-09-10 15:27:28 +08:00
|
|
|
|
|
|
|
|
|
free (var);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-04-10 06:09:24 +08:00
|
|
|
|
/* "ifeq" or "ifneq". */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
char *s1, *s2;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
unsigned int l;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
char termin = *line == '(' ? ',' : *line;
|
|
|
|
|
|
|
|
|
|
if (termin != ',' && termin != '"' && termin != '\'')
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
s1 = ++line;
|
|
|
|
|
/* Find the end of the first string. */
|
|
|
|
|
if (termin == ',')
|
|
|
|
|
{
|
2005-05-13 20:45:30 +08:00
|
|
|
|
int count = 0;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
for (; *line != '\0'; ++line)
|
|
|
|
|
if (*line == '(')
|
|
|
|
|
++count;
|
|
|
|
|
else if (*line == ')')
|
|
|
|
|
--count;
|
|
|
|
|
else if (*line == ',' && count <= 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
while (*line != '\0' && *line != termin)
|
|
|
|
|
++line;
|
|
|
|
|
|
|
|
|
|
if (*line == '\0')
|
|
|
|
|
return -1;
|
|
|
|
|
|
1996-06-23 05:42:02 +08:00
|
|
|
|
if (termin == ',')
|
|
|
|
|
{
|
|
|
|
|
/* Strip blanks after the first string. */
|
|
|
|
|
char *p = line++;
|
2000-06-07 13:43:37 +08:00
|
|
|
|
while (isblank ((unsigned char)p[-1]))
|
1996-06-23 05:42:02 +08:00
|
|
|
|
--p;
|
|
|
|
|
*p = '\0';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
*line++ = '\0';
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
s2 = variable_expand (s1);
|
|
|
|
|
/* We must allocate a new copy of the expanded string because
|
|
|
|
|
variable_expand re-uses the same buffer. */
|
2006-04-10 06:09:24 +08:00
|
|
|
|
l = strlen (s2);
|
|
|
|
|
s1 = alloca (l + 1);
|
|
|
|
|
memcpy (s1, s2, l + 1);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
if (termin != ',')
|
|
|
|
|
/* Find the start of the second string. */
|
|
|
|
|
line = next_token (line);
|
|
|
|
|
|
|
|
|
|
termin = termin == ',' ? ')' : *line;
|
|
|
|
|
if (termin != ')' && termin != '"' && termin != '\'')
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
/* Find the end of the second string. */
|
|
|
|
|
if (termin == ')')
|
|
|
|
|
{
|
2006-04-10 06:09:24 +08:00
|
|
|
|
int count = 0;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
s2 = next_token (line);
|
|
|
|
|
for (line = s2; *line != '\0'; ++line)
|
|
|
|
|
{
|
|
|
|
|
if (*line == '(')
|
|
|
|
|
++count;
|
|
|
|
|
else if (*line == ')')
|
1999-06-14 14:50:28 +08:00
|
|
|
|
{
|
|
|
|
|
if (count <= 0)
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
--count;
|
|
|
|
|
}
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
++line;
|
|
|
|
|
s2 = line;
|
|
|
|
|
while (*line != '\0' && *line != termin)
|
|
|
|
|
++line;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (*line == '\0')
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
*line = '\0';
|
|
|
|
|
line = next_token (++line);
|
|
|
|
|
if (*line != '\0')
|
2005-05-13 20:45:30 +08:00
|
|
|
|
EXTRANEOUS ();
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
s2 = variable_expand (s2);
|
2005-05-13 20:45:30 +08:00
|
|
|
|
conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq));
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-05-13 20:45:30 +08:00
|
|
|
|
DONE:
|
1992-02-14 18:52:22 +08:00
|
|
|
|
/* Search through the stack to see if we're ignoring. */
|
|
|
|
|
for (i = 0; i < conditionals->if_cmds; ++i)
|
|
|
|
|
if (conditionals->ignoring[i])
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Remove duplicate dependencies in CHAIN. */
|
|
|
|
|
|
2002-07-11 14:38:57 +08:00
|
|
|
|
static unsigned long
|
2002-10-15 05:54:04 +08:00
|
|
|
|
dep_hash_1 (const void *key)
|
2002-07-11 14:38:57 +08:00
|
|
|
|
{
|
|
|
|
|
return_STRING_HASH_1 (dep_name ((struct dep const *) key));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned long
|
2002-10-15 05:54:04 +08:00
|
|
|
|
dep_hash_2 (const void *key)
|
2002-07-11 14:38:57 +08:00
|
|
|
|
{
|
|
|
|
|
return_STRING_HASH_2 (dep_name ((struct dep const *) key));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2002-10-15 05:54:04 +08:00
|
|
|
|
dep_hash_cmp (const void *x, const void *y)
|
2002-07-11 14:38:57 +08:00
|
|
|
|
{
|
|
|
|
|
struct dep *dx = (struct dep *) x;
|
|
|
|
|
struct dep *dy = (struct dep *) y;
|
|
|
|
|
int cmp = strcmp (dep_name (dx), dep_name (dy));
|
|
|
|
|
|
|
|
|
|
/* If the names are the same but ignore_mtimes are not equal, one of these
|
|
|
|
|
is an order-only prerequisite and one isn't. That means that we should
|
|
|
|
|
remove the one that isn't and keep the one that is. */
|
|
|
|
|
|
|
|
|
|
if (!cmp && dx->ignore_mtime != dy->ignore_mtime)
|
|
|
|
|
dx->ignore_mtime = dy->ignore_mtime = 0;
|
|
|
|
|
|
|
|
|
|
return cmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
void
|
2002-10-15 05:54:04 +08:00
|
|
|
|
uniquize_deps (struct dep *chain)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2002-07-11 14:38:57 +08:00
|
|
|
|
struct hash_table deps;
|
|
|
|
|
register struct dep **depp;
|
|
|
|
|
|
|
|
|
|
hash_init (&deps, 500, dep_hash_1, dep_hash_2, dep_hash_cmp);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
/* Make sure that no dependencies are repeated. This does not
|
|
|
|
|
really matter for the purpose of updating targets, but it
|
|
|
|
|
might make some names be listed twice for $^ and $?. */
|
|
|
|
|
|
2002-07-11 14:38:57 +08:00
|
|
|
|
depp = &chain;
|
|
|
|
|
while (*depp)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2002-07-11 14:38:57 +08:00
|
|
|
|
struct dep *dep = *depp;
|
|
|
|
|
struct dep **dep_slot = (struct dep **) hash_find_slot (&deps, dep);
|
|
|
|
|
if (HASH_VACANT (*dep_slot))
|
|
|
|
|
{
|
|
|
|
|
hash_insert_at (&deps, dep, dep_slot);
|
|
|
|
|
depp = &dep->next;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Don't bother freeing duplicates.
|
|
|
|
|
It's dangerous and little benefit accrues. */
|
|
|
|
|
*depp = dep->next;
|
|
|
|
|
}
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
2002-07-11 14:38:57 +08:00
|
|
|
|
|
|
|
|
|
hash_free (&deps, 0);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
1998-07-31 04:54:47 +08:00
|
|
|
|
/* Record target-specific variable values for files FILENAMES.
|
|
|
|
|
TWO_COLON is nonzero if a double colon was used.
|
|
|
|
|
|
|
|
|
|
The links of FILENAMES are freed, and so are any names in it
|
|
|
|
|
that are not incorporated into other data structures.
|
|
|
|
|
|
|
|
|
|
If the target is a pattern, add the variable to the pattern-specific
|
|
|
|
|
variable value list. */
|
|
|
|
|
|
|
|
|
|
static void
|
2004-01-21 14:32:59 +08:00
|
|
|
|
record_target_var (struct nameseq *filenames, char *defn,
|
2002-10-15 05:54:04 +08:00
|
|
|
|
enum variable_origin origin, int exported,
|
|
|
|
|
const struct floc *flocp)
|
1998-07-31 04:54:47 +08:00
|
|
|
|
{
|
|
|
|
|
struct nameseq *nextf;
|
|
|
|
|
struct variable_set_list *global;
|
|
|
|
|
|
|
|
|
|
global = current_variable_set_list;
|
|
|
|
|
|
1999-11-17 15:33:47 +08:00
|
|
|
|
/* If the variable is an append version, store that but treat it as a
|
|
|
|
|
normal recursive variable. */
|
|
|
|
|
|
1998-07-31 04:54:47 +08:00
|
|
|
|
for (; filenames != 0; filenames = nextf)
|
|
|
|
|
{
|
|
|
|
|
struct variable *v;
|
2007-03-20 11:02:26 +08:00
|
|
|
|
const char *name = filenames->name;
|
|
|
|
|
const char *fname;
|
|
|
|
|
const char *percent;
|
2003-05-02 09:44:59 +08:00
|
|
|
|
struct pattern_var *p;
|
1998-07-31 04:54:47 +08:00
|
|
|
|
|
|
|
|
|
nextf = filenames->next;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (filenames);
|
1998-07-31 04:54:47 +08:00
|
|
|
|
|
|
|
|
|
/* If it's a pattern target, then add it to the pattern-specific
|
|
|
|
|
variable list. */
|
2007-03-20 11:02:26 +08:00
|
|
|
|
percent = find_percent_cached (&name);
|
1998-07-31 04:54:47 +08:00
|
|
|
|
if (percent)
|
|
|
|
|
{
|
|
|
|
|
/* Get a reference for this pattern-specific variable struct. */
|
2003-05-02 09:44:59 +08:00
|
|
|
|
p = create_pattern_var (name, percent);
|
|
|
|
|
p->variable.fileinfo = *flocp;
|
2004-09-21 21:51:58 +08:00
|
|
|
|
/* I don't think this can fail since we already determined it was a
|
|
|
|
|
variable definition. */
|
2003-05-02 09:44:59 +08:00
|
|
|
|
v = parse_variable_definition (&p->variable, defn);
|
2004-09-21 21:51:58 +08:00
|
|
|
|
assert (v != 0);
|
2004-10-06 00:56:14 +08:00
|
|
|
|
|
|
|
|
|
if (v->flavor == f_simple)
|
|
|
|
|
v->value = allocated_variable_expand (v->value);
|
|
|
|
|
else
|
|
|
|
|
v->value = xstrdup (v->value);
|
|
|
|
|
|
1998-07-31 04:54:47 +08:00
|
|
|
|
fname = p->target;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
struct file *f;
|
|
|
|
|
|
2002-09-18 05:52:45 +08:00
|
|
|
|
/* Get a file reference for this file, and initialize it.
|
|
|
|
|
We don't want to just call enter_file() because that allocates a
|
|
|
|
|
new entry if the file is a double-colon, which we don't want in
|
|
|
|
|
this situation. */
|
|
|
|
|
f = lookup_file (name);
|
|
|
|
|
if (!f)
|
2007-03-20 11:02:26 +08:00
|
|
|
|
f = enter_file (strcache_add (name));
|
2002-09-18 05:52:45 +08:00
|
|
|
|
else if (f->double_colon)
|
|
|
|
|
f = f->double_colon;
|
|
|
|
|
|
2000-02-05 15:37:40 +08:00
|
|
|
|
initialize_file_variables (f, 1);
|
1998-07-31 04:54:47 +08:00
|
|
|
|
fname = f->name;
|
2003-05-02 09:44:59 +08:00
|
|
|
|
|
|
|
|
|
current_variable_set_list = f->variables;
|
|
|
|
|
v = try_variable_definition (flocp, defn, origin, 1);
|
|
|
|
|
if (!v)
|
|
|
|
|
error (flocp, _("Malformed target-specific variable definition"));
|
|
|
|
|
current_variable_set_list = global;
|
1998-07-31 04:54:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-05-02 09:44:59 +08:00
|
|
|
|
/* Set up the variable to be *-specific. */
|
|
|
|
|
v->origin = origin;
|
1998-07-31 04:54:47 +08:00
|
|
|
|
v->per_target = 1;
|
2005-12-14 21:11:18 +08:00
|
|
|
|
v->export = exported ? v_export : v_default;
|
1998-07-31 04:54:47 +08:00
|
|
|
|
|
|
|
|
|
/* If it's not an override, check to see if there was a command-line
|
|
|
|
|
setting. If so, reset the value. */
|
|
|
|
|
if (origin != o_override)
|
|
|
|
|
{
|
|
|
|
|
struct variable *gv;
|
|
|
|
|
int len = strlen(v->name);
|
|
|
|
|
|
1999-08-01 14:05:17 +08:00
|
|
|
|
gv = lookup_variable (v->name, len);
|
1998-07-31 04:54:47 +08:00
|
|
|
|
if (gv && (gv->origin == o_env_override || gv->origin == o_command))
|
2001-06-01 11:56:50 +08:00
|
|
|
|
{
|
2003-05-02 09:44:59 +08:00
|
|
|
|
if (v->value != 0)
|
|
|
|
|
free (v->value);
|
|
|
|
|
v->value = xstrdup (gv->value);
|
|
|
|
|
v->origin = gv->origin;
|
|
|
|
|
v->recursive = gv->recursive;
|
2001-06-01 11:56:50 +08:00
|
|
|
|
v->append = 0;
|
|
|
|
|
}
|
1998-07-31 04:54:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
/* Record a description line for files FILENAMES,
|
|
|
|
|
with dependencies DEPS, commands to execute described
|
|
|
|
|
by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
|
|
|
|
|
TWO_COLON is nonzero if a double colon was used.
|
|
|
|
|
If not nil, PATTERN is the `%' pattern to make this
|
|
|
|
|
a static pattern rule, and PATTERN_PERCENT is a pointer
|
|
|
|
|
to the `%' within it.
|
|
|
|
|
|
|
|
|
|
The links of FILENAMES are freed, and so are any names in it
|
|
|
|
|
that are not incorporated into other data structures. */
|
|
|
|
|
|
|
|
|
|
static void
|
2007-03-20 11:02:26 +08:00
|
|
|
|
record_files (struct nameseq *filenames, const char *pattern,
|
|
|
|
|
const char *pattern_percent, struct dep *deps,
|
|
|
|
|
unsigned int cmds_started, char *commands,
|
2002-10-15 05:54:04 +08:00
|
|
|
|
unsigned int commands_idx, int two_colon,
|
2005-02-28 06:24:30 +08:00
|
|
|
|
const struct floc *flocp)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
|
|
|
|
struct nameseq *nextf;
|
|
|
|
|
int implicit = 0;
|
1998-07-31 04:54:47 +08:00
|
|
|
|
unsigned int max_targets = 0, target_idx = 0;
|
2007-03-20 11:02:26 +08:00
|
|
|
|
const char **targets = 0, **target_percents = 0;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
struct commands *cmds;
|
|
|
|
|
|
2005-02-28 15:48:22 +08:00
|
|
|
|
/* If we've already snapped deps, that means we're in an eval being
|
|
|
|
|
resolved after the makefiles have been read in. We can't add more rules
|
|
|
|
|
at this time, since they won't get snapped and we'll get core dumps.
|
|
|
|
|
See Savannah bug # 12124. */
|
|
|
|
|
if (snapped_deps)
|
2007-11-05 05:54:00 +08:00
|
|
|
|
fatal (flocp, _("prerequisites cannot be defined in recipes"));
|
2005-02-28 15:48:22 +08:00
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
if (commands_idx > 0)
|
|
|
|
|
{
|
2006-04-10 06:09:24 +08:00
|
|
|
|
cmds = xmalloc (sizeof (struct commands));
|
1998-10-03 13:39:55 +08:00
|
|
|
|
cmds->fileinfo.filenm = flocp->filenm;
|
|
|
|
|
cmds->fileinfo.lineno = cmds_started;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
cmds->commands = savestring (commands, commands_idx);
|
|
|
|
|
cmds->command_lines = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
cmds = 0;
|
|
|
|
|
|
|
|
|
|
for (; filenames != 0; filenames = nextf)
|
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
const char *name = filenames->name;
|
2002-07-10 20:59:07 +08:00
|
|
|
|
struct file *f;
|
2005-10-24 21:01:39 +08:00
|
|
|
|
struct dep *this = 0;
|
2007-03-20 11:02:26 +08:00
|
|
|
|
const char *implicit_percent;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
nextf = filenames->next;
|
2000-03-28 04:53:50 +08:00
|
|
|
|
free (filenames);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2005-10-24 21:01:39 +08:00
|
|
|
|
/* Check for special targets. Do it here instead of, say, snap_deps()
|
|
|
|
|
so that we can immediately use the value. */
|
2002-07-10 20:59:07 +08:00
|
|
|
|
|
|
|
|
|
if (streq (name, ".POSIX"))
|
|
|
|
|
posix_pedantic = 1;
|
2005-10-24 21:01:39 +08:00
|
|
|
|
else if (streq (name, ".SECONDEXPANSION"))
|
|
|
|
|
second_expansion = 1;
|
2002-07-10 20:59:07 +08:00
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
implicit_percent = find_percent_cached (&name);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
implicit |= implicit_percent != 0;
|
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
if (implicit)
|
|
|
|
|
{
|
|
|
|
|
if (pattern != 0)
|
|
|
|
|
fatal (flocp, _("mixed implicit and static pattern rules"));
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
if (implicit_percent == 0)
|
|
|
|
|
fatal (flocp, _("mixed implicit and normal rules"));
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
if (targets == 0)
|
|
|
|
|
{
|
|
|
|
|
max_targets = 5;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
targets = xmalloc (5 * sizeof (char *));
|
|
|
|
|
target_percents = xmalloc (5 * sizeof (char *));
|
1992-02-14 18:52:22 +08:00
|
|
|
|
target_idx = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (target_idx == max_targets - 1)
|
|
|
|
|
{
|
|
|
|
|
max_targets += 5;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
targets = xrealloc (targets, max_targets * sizeof (char *));
|
|
|
|
|
target_percents = xrealloc (target_percents,
|
|
|
|
|
max_targets * sizeof (char *));
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
targets[target_idx] = name;
|
|
|
|
|
target_percents[target_idx] = implicit_percent;
|
|
|
|
|
++target_idx;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-24 21:01:39 +08:00
|
|
|
|
/* If this is a static pattern rule:
|
|
|
|
|
`targets: target%pattern: dep%pattern; cmds',
|
|
|
|
|
make sure the pattern matches this target name. */
|
|
|
|
|
if (pattern && !pattern_matches (pattern, pattern_percent, name))
|
|
|
|
|
error (flocp, _("target `%s' doesn't match the target pattern"), name);
|
|
|
|
|
else if (deps)
|
|
|
|
|
{
|
|
|
|
|
/* If there are multiple filenames, copy the chain DEPS for all but
|
|
|
|
|
the last one. It is not safe for the same deps to go in more
|
|
|
|
|
than one place in the database. */
|
|
|
|
|
this = nextf != 0 ? copy_dep_chain (deps) : deps;
|
2005-10-27 00:06:30 +08:00
|
|
|
|
this->need_2nd_expansion = (second_expansion
|
|
|
|
|
&& strchr (this->name, '$'));
|
2005-10-24 21:01:39 +08:00
|
|
|
|
}
|
1995-12-12 11:31:40 +08:00
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
if (!two_colon)
|
|
|
|
|
{
|
|
|
|
|
/* Single-colon. Combine these dependencies
|
|
|
|
|
with others in file's existing record, if any. */
|
2007-03-20 11:02:26 +08:00
|
|
|
|
f = enter_file (strcache_add (name));
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
if (f->double_colon)
|
1998-10-03 13:39:55 +08:00
|
|
|
|
fatal (flocp,
|
1999-07-28 14:23:37 +08:00
|
|
|
|
_("target file `%s' has both : and :: entries"), f->name);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
/* If CMDS == F->CMDS, this target was listed in this rule
|
|
|
|
|
more than once. Just give a warning since this is harmless. */
|
|
|
|
|
if (cmds != 0 && cmds == f->cmds)
|
2000-03-28 04:53:50 +08:00
|
|
|
|
error (flocp,
|
|
|
|
|
_("target `%s' given more than once in the same rule."),
|
1999-02-20 02:07:49 +08:00
|
|
|
|
f->name);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
/* Check for two single-colon entries both with commands.
|
|
|
|
|
Check is_target so that we don't lose on files such as .c.o
|
|
|
|
|
whose commands were preinitialized. */
|
|
|
|
|
else if (cmds != 0 && f->cmds != 0 && f->is_target)
|
|
|
|
|
{
|
1998-10-03 13:39:55 +08:00
|
|
|
|
error (&cmds->fileinfo,
|
2007-11-05 05:54:00 +08:00
|
|
|
|
_("warning: overriding recipe for target `%s'"),
|
2000-03-28 04:53:50 +08:00
|
|
|
|
f->name);
|
1998-10-03 13:39:55 +08:00
|
|
|
|
error (&f->cmds->fileinfo,
|
2007-11-05 05:54:00 +08:00
|
|
|
|
_("warning: ignoring old recipe for target `%s'"),
|
1999-02-20 02:07:49 +08:00
|
|
|
|
f->name);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
f->is_target = 1;
|
|
|
|
|
|
|
|
|
|
/* Defining .DEFAULT with no deps or cmds clears it. */
|
|
|
|
|
if (f == default_file && this == 0 && cmds == 0)
|
|
|
|
|
f->cmds = 0;
|
|
|
|
|
if (cmds != 0)
|
|
|
|
|
f->cmds = cmds;
|
2005-02-28 05:40:23 +08:00
|
|
|
|
|
2005-10-24 21:01:39 +08:00
|
|
|
|
/* Defining .SUFFIXES with no dependencies clears out the list of
|
|
|
|
|
suffixes. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
if (f == suffix_file && this == 0)
|
1992-10-10 02:00:37 +08:00
|
|
|
|
{
|
2005-10-24 21:01:39 +08:00
|
|
|
|
free_dep_chain (f->deps);
|
1992-10-10 02:00:37 +08:00
|
|
|
|
f->deps = 0;
|
|
|
|
|
}
|
2005-02-28 05:40:23 +08:00
|
|
|
|
else if (this != 0)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
1992-11-11 05:41:55 +08:00
|
|
|
|
/* Add the file's old deps and the new ones in THIS together. */
|
|
|
|
|
|
2005-02-28 05:40:23 +08:00
|
|
|
|
if (f->deps != 0)
|
|
|
|
|
{
|
|
|
|
|
struct dep **d_ptr = &f->deps;
|
1992-11-11 05:41:55 +08:00
|
|
|
|
|
2005-02-28 05:40:23 +08:00
|
|
|
|
while ((*d_ptr)->next != 0)
|
|
|
|
|
d_ptr = &(*d_ptr)->next;
|
1992-11-11 05:41:55 +08:00
|
|
|
|
|
2005-02-28 05:40:23 +08:00
|
|
|
|
if (cmds != 0)
|
2005-08-08 13:08:00 +08:00
|
|
|
|
/* This is the rule with commands, so put its deps
|
|
|
|
|
last. The rationale behind this is that $< expands to
|
|
|
|
|
the first dep in the chain, and commands use $<
|
|
|
|
|
expecting to get the dep that rule specifies. However
|
|
|
|
|
the second expansion algorithm reverses the order thus
|
|
|
|
|
we need to make it last here. */
|
|
|
|
|
(*d_ptr)->next = this;
|
2005-02-28 05:40:23 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* This is the rule without commands. Put its
|
2005-08-08 13:08:00 +08:00
|
|
|
|
dependencies at the end but before dependencies from
|
|
|
|
|
the rule with commands (if any). This way everything
|
|
|
|
|
appears in makefile order. */
|
2005-02-28 05:40:23 +08:00
|
|
|
|
|
|
|
|
|
if (f->cmds != 0)
|
|
|
|
|
{
|
|
|
|
|
this->next = *d_ptr;
|
|
|
|
|
*d_ptr = this;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
(*d_ptr)->next = this;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
f->deps = this;
|
|
|
|
|
|
|
|
|
|
/* This is a hack. I need a way to communicate to snap_deps()
|
|
|
|
|
that the last dependency line in this file came with commands
|
|
|
|
|
(so that logic in snap_deps() can put it in front and all
|
2005-04-13 11:16:33 +08:00
|
|
|
|
this $< -logic works). I cannot simply rely on file->cmds
|
2005-02-28 05:40:23 +08:00
|
|
|
|
being not 0 because of the cases like the following:
|
|
|
|
|
|
|
|
|
|
foo: bar
|
|
|
|
|
foo:
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
I am going to temporarily "borrow" UPDATING member in
|
|
|
|
|
`struct file' for this. */
|
|
|
|
|
|
|
|
|
|
if (cmds != 0)
|
|
|
|
|
f->updating = 1;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-10-24 21:01:39 +08:00
|
|
|
|
/* Double-colon. Make a new record even if there already is one. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
f = lookup_file (name);
|
2005-10-24 21:01:39 +08:00
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
/* Check for both : and :: rules. Check is_target so
|
|
|
|
|
we don't lose on default suffix rules or makefiles. */
|
|
|
|
|
if (f != 0 && f->is_target && !f->double_colon)
|
1998-10-03 13:39:55 +08:00
|
|
|
|
fatal (flocp,
|
1999-07-28 14:23:37 +08:00
|
|
|
|
_("target file `%s' has both : and :: entries"), f->name);
|
2007-03-20 11:02:26 +08:00
|
|
|
|
f = enter_file (strcache_add (name));
|
2005-10-24 21:01:39 +08:00
|
|
|
|
/* If there was an existing entry and it was a double-colon entry,
|
|
|
|
|
enter_file will have returned a new one, making it the prev
|
|
|
|
|
pointer of the old one, and setting its double_colon pointer to
|
|
|
|
|
the first one. */
|
1994-04-05 18:14:49 +08:00
|
|
|
|
if (f->double_colon == 0)
|
2005-10-24 21:01:39 +08:00
|
|
|
|
/* This is the first entry for this name, so we must set its
|
|
|
|
|
double_colon pointer to itself. */
|
1994-04-05 18:14:49 +08:00
|
|
|
|
f->double_colon = f;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
f->is_target = 1;
|
|
|
|
|
f->deps = this;
|
|
|
|
|
f->cmds = cmds;
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-24 21:01:39 +08:00
|
|
|
|
/* If this is a static pattern rule, set the stem to the part of its
|
|
|
|
|
name that matched the `%' in the pattern, so you can use $* in the
|
|
|
|
|
commands. */
|
|
|
|
|
if (pattern)
|
2005-08-10 18:21:13 +08:00
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
static const char *percent = "%";
|
2005-08-10 18:21:13 +08:00
|
|
|
|
char *buffer = variable_expand ("");
|
2007-03-20 11:02:26 +08:00
|
|
|
|
char *o = patsubst_expand_pat (buffer, name, pattern, percent,
|
|
|
|
|
pattern_percent+1, percent+1);
|
|
|
|
|
f->stem = strcache_add_len (buffer, o - buffer);
|
2005-10-24 21:01:39 +08:00
|
|
|
|
if (this)
|
2006-03-17 22:24:20 +08:00
|
|
|
|
{
|
|
|
|
|
this->staticpattern = 1;
|
2007-03-20 11:02:26 +08:00
|
|
|
|
this->stem = f->stem;
|
2006-03-17 22:24:20 +08:00
|
|
|
|
}
|
2005-08-10 18:21:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
name = f->name;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2005-05-03 21:57:20 +08:00
|
|
|
|
/* If this target is a default target, update DEFAULT_GOAL_FILE. */
|
2005-10-24 21:01:39 +08:00
|
|
|
|
if (streq (*default_goal_name, name)
|
2005-05-03 21:57:20 +08:00
|
|
|
|
&& (default_goal_file == 0
|
2005-10-24 21:01:39 +08:00
|
|
|
|
|| ! streq (default_goal_file->name, name)))
|
2005-05-03 21:57:20 +08:00
|
|
|
|
default_goal_file = f;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (implicit)
|
|
|
|
|
{
|
2005-10-27 00:06:30 +08:00
|
|
|
|
if (deps)
|
2005-12-11 23:41:17 +08:00
|
|
|
|
deps->need_2nd_expansion = second_expansion;
|
2007-03-20 11:02:26 +08:00
|
|
|
|
create_pattern_rule (targets, target_percents, target_idx,
|
|
|
|
|
two_colon, deps, cmds, 1);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1994-04-22 04:36:47 +08:00
|
|
|
|
/* Search STRING for an unquoted STOPCHAR or blank (if BLANK is nonzero).
|
|
|
|
|
Backslashes quote STOPCHAR, blanks if BLANK is nonzero, and backslash.
|
|
|
|
|
Quoting backslashes are removed from STRING by compacting it into
|
|
|
|
|
itself. Returns a pointer to the first unquoted STOPCHAR if there is
|
2005-06-26 05:30:13 +08:00
|
|
|
|
one, or nil if there are none. STOPCHARs inside variable references are
|
|
|
|
|
ignored if IGNOREVARS is true.
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2005-06-26 05:30:13 +08:00
|
|
|
|
STOPCHAR _cannot_ be '$' if IGNOREVARS is true. */
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
find_char_unquote (char *string, int stop1, int stop2, int blank,
|
|
|
|
|
int ignorevars)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
1996-06-23 03:26:13 +08:00
|
|
|
|
unsigned int string_len = 0;
|
2007-03-20 11:02:26 +08:00
|
|
|
|
char *p = string;
|
2005-06-26 05:30:13 +08:00
|
|
|
|
|
|
|
|
|
if (ignorevars)
|
|
|
|
|
ignorevars = '$';
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
1994-04-22 04:36:47 +08:00
|
|
|
|
while (1)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2002-07-11 14:38:57 +08:00
|
|
|
|
if (stop2 && blank)
|
2005-06-26 05:30:13 +08:00
|
|
|
|
while (*p != '\0' && *p != ignorevars && *p != stop1 && *p != stop2
|
2002-07-11 14:38:57 +08:00
|
|
|
|
&& ! isblank ((unsigned char) *p))
|
|
|
|
|
++p;
|
|
|
|
|
else if (stop2)
|
2005-06-26 05:30:13 +08:00
|
|
|
|
while (*p != '\0' && *p != ignorevars && *p != stop1 && *p != stop2)
|
2002-07-11 14:38:57 +08:00
|
|
|
|
++p;
|
|
|
|
|
else if (blank)
|
2005-06-26 05:30:13 +08:00
|
|
|
|
while (*p != '\0' && *p != ignorevars && *p != stop1
|
2002-07-11 14:38:57 +08:00
|
|
|
|
&& ! isblank ((unsigned char) *p))
|
|
|
|
|
++p;
|
|
|
|
|
else
|
2005-06-26 05:30:13 +08:00
|
|
|
|
while (*p != '\0' && *p != ignorevars && *p != stop1)
|
2002-07-11 14:38:57 +08:00
|
|
|
|
++p;
|
|
|
|
|
|
1995-03-11 04:33:40 +08:00
|
|
|
|
if (*p == '\0')
|
|
|
|
|
break;
|
|
|
|
|
|
2005-06-26 05:30:13 +08:00
|
|
|
|
/* If we stopped due to a variable reference, skip over its contents. */
|
|
|
|
|
if (*p == ignorevars)
|
|
|
|
|
{
|
|
|
|
|
char openparen = p[1];
|
|
|
|
|
|
|
|
|
|
p += 2;
|
|
|
|
|
|
|
|
|
|
/* Skip the contents of a non-quoted, multi-char variable ref. */
|
|
|
|
|
if (openparen == '(' || openparen == '{')
|
|
|
|
|
{
|
|
|
|
|
unsigned int pcount = 1;
|
|
|
|
|
char closeparen = (openparen == '(' ? ')' : '}');
|
|
|
|
|
|
|
|
|
|
while (*p)
|
|
|
|
|
{
|
|
|
|
|
if (*p == openparen)
|
|
|
|
|
++pcount;
|
|
|
|
|
else if (*p == closeparen)
|
|
|
|
|
if (--pcount == 0)
|
|
|
|
|
{
|
|
|
|
|
++p;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Skipped the variable reference: look for STOPCHARS again. */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
1994-04-22 04:36:47 +08:00
|
|
|
|
if (p > string && p[-1] == '\\')
|
|
|
|
|
{
|
|
|
|
|
/* Search for more backslashes. */
|
2006-04-10 06:09:24 +08:00
|
|
|
|
int i = -2;
|
1994-04-22 04:36:47 +08:00
|
|
|
|
while (&p[i] >= string && p[i] == '\\')
|
|
|
|
|
--i;
|
|
|
|
|
++i;
|
1996-06-23 03:26:13 +08:00
|
|
|
|
/* Only compute the length if really needed. */
|
|
|
|
|
if (string_len == 0)
|
|
|
|
|
string_len = strlen (string);
|
1994-04-22 04:36:47 +08:00
|
|
|
|
/* The number of backslashes is now -I.
|
|
|
|
|
Copy P over itself to swallow half of them. */
|
2006-04-10 06:09:24 +08:00
|
|
|
|
memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1);
|
|
|
|
|
p += i/2;
|
1994-04-22 04:36:47 +08:00
|
|
|
|
if (i % 2 == 0)
|
|
|
|
|
/* All the backslashes quoted each other; the STOPCHAR was
|
|
|
|
|
unquoted. */
|
|
|
|
|
return p;
|
|
|
|
|
|
|
|
|
|
/* The STOPCHAR was quoted by a backslash. Look for another. */
|
|
|
|
|
}
|
1992-02-14 18:52:22 +08:00
|
|
|
|
else
|
1994-04-22 04:36:47 +08:00
|
|
|
|
/* No backslash in sight. */
|
|
|
|
|
return p;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
1994-04-22 04:36:47 +08:00
|
|
|
|
|
|
|
|
|
/* Never hit a STOPCHAR or blank (with BLANK nonzero). */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
1994-04-22 04:36:47 +08:00
|
|
|
|
|
2006-11-19 04:53:44 +08:00
|
|
|
|
/* Search PATTERN for an unquoted % and handle quoting. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
char *
|
2002-10-15 05:54:04 +08:00
|
|
|
|
find_percent (char *pattern)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2005-06-26 05:30:13 +08:00
|
|
|
|
return find_char_unquote (pattern, '%', 0, 0, 0);
|
1994-04-22 04:36:47 +08:00
|
|
|
|
}
|
2007-03-20 11:02:26 +08:00
|
|
|
|
|
|
|
|
|
/* Search STRING for an unquoted % and handle quoting. Returns a pointer to
|
|
|
|
|
the % or NULL if no % was found.
|
|
|
|
|
This version is used with strings in the string cache: if there's a need to
|
|
|
|
|
modify the string a new version will be added to the string cache and
|
|
|
|
|
*STRING will be set to that. */
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
find_percent_cached (const char **string)
|
|
|
|
|
{
|
|
|
|
|
const char *p = *string;
|
|
|
|
|
char *new = 0;
|
|
|
|
|
int slen;
|
|
|
|
|
|
|
|
|
|
/* If the first char is a % return now. This lets us avoid extra tests
|
|
|
|
|
inside the loop. */
|
|
|
|
|
if (*p == '%')
|
|
|
|
|
return p;
|
|
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
while (*p != '\0' && *p != '%')
|
|
|
|
|
++p;
|
|
|
|
|
|
|
|
|
|
if (*p == '\0')
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* See if this % is escaped with a backslash; if not we're done. */
|
|
|
|
|
if (p[-1] != '\\')
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
/* Search for more backslashes. */
|
|
|
|
|
char *pv;
|
|
|
|
|
int i = -2;
|
|
|
|
|
|
|
|
|
|
while (&p[i] >= *string && p[i] == '\\')
|
|
|
|
|
--i;
|
|
|
|
|
++i;
|
|
|
|
|
|
|
|
|
|
/* At this point we know we'll need to allocate a new string.
|
|
|
|
|
Make a copy if we haven't yet done so. */
|
|
|
|
|
if (! new)
|
|
|
|
|
{
|
|
|
|
|
slen = strlen (*string);
|
|
|
|
|
new = alloca (slen + 1);
|
|
|
|
|
memcpy (new, *string, slen + 1);
|
|
|
|
|
p = new + (p - *string);
|
|
|
|
|
*string = new;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* At this point *string, p, and new all point into the same string.
|
|
|
|
|
Get a non-const version of p so we can modify new. */
|
|
|
|
|
pv = new + (p - *string);
|
|
|
|
|
|
|
|
|
|
/* The number of backslashes is now -I.
|
|
|
|
|
Copy P over itself to swallow half of them. */
|
|
|
|
|
memmove (&pv[i], &pv[i/2], (slen - (pv - new)) - (i/2) + 1);
|
|
|
|
|
p += i/2;
|
|
|
|
|
|
|
|
|
|
/* If the backslashes quoted each other; the % was unquoted. */
|
|
|
|
|
if (i % 2 == 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we had to change STRING, add it to the strcache. */
|
|
|
|
|
if (new)
|
|
|
|
|
{
|
|
|
|
|
*string = strcache_add (*string);
|
|
|
|
|
p = *string + (p - new);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we didn't find a %, return NULL. Otherwise return a ptr to it. */
|
|
|
|
|
return (*p == '\0') ? NULL : p;
|
|
|
|
|
}
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
/* Parse a string into a sequence of filenames represented as a
|
|
|
|
|
chain of struct nameseq's in reverse order and return that chain.
|
|
|
|
|
|
|
|
|
|
The string is passed as STRINGP, the address of a string pointer.
|
|
|
|
|
The string pointer is updated to point at the first character
|
|
|
|
|
not parsed, which either is a null char or equals STOPCHAR.
|
|
|
|
|
|
|
|
|
|
SIZE is how big to construct chain elements.
|
|
|
|
|
This is useful if we want them actually to be other structures
|
1993-04-16 06:30:01 +08:00
|
|
|
|
that have room for additional info.
|
|
|
|
|
|
|
|
|
|
If STRIP is nonzero, strip `./'s off the beginning. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
struct nameseq *
|
2002-10-15 05:54:04 +08:00
|
|
|
|
parse_file_seq (char **stringp, int stopchar, unsigned int size, int strip)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2005-10-24 21:01:39 +08:00
|
|
|
|
struct nameseq *new = 0;
|
|
|
|
|
struct nameseq *new1, *lastnew1;
|
|
|
|
|
char *p = *stringp;
|
1996-03-20 22:57:41 +08:00
|
|
|
|
|
|
|
|
|
#ifdef VMS
|
2002-07-11 14:38:57 +08:00
|
|
|
|
# define VMS_COMMA ','
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#else
|
2002-07-11 14:38:57 +08:00
|
|
|
|
# define VMS_COMMA 0
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
const char *name;
|
|
|
|
|
char *q;
|
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
/* Skip whitespace; see if any more names are left. */
|
|
|
|
|
p = next_token (p);
|
|
|
|
|
if (*p == '\0')
|
|
|
|
|
break;
|
|
|
|
|
if (*p == stopchar)
|
|
|
|
|
break;
|
1996-03-20 22:57:41 +08:00
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
/* There are, so find the end of the next name. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
q = p;
|
2005-06-26 05:30:13 +08:00
|
|
|
|
p = find_char_unquote (q, stopchar, VMS_COMMA, 1, 0);
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
/* convert comma separated list to space separated */
|
|
|
|
|
if (p && *p == ',')
|
|
|
|
|
*p =' ';
|
|
|
|
|
#endif
|
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-10 02:02:06 +08:00
|
|
|
|
#ifdef _AMIGA
|
1999-10-15 15:00:58 +08:00
|
|
|
|
if (stopchar == ':' && p && *p == ':'
|
|
|
|
|
&& !(isspace ((unsigned char)p[1]) || !p[1]
|
|
|
|
|
|| isspace ((unsigned char)p[-1])))
|
2005-06-26 05:30:13 +08:00
|
|
|
|
p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0);
|
1996-05-23 05:51:45 +08:00
|
|
|
|
#endif
|
2002-08-10 09:27:16 +08:00
|
|
|
|
#ifdef HAVE_DOS_PATHS
|
|
|
|
|
/* For DOS paths, skip a "C:\..." or a "C:/..." until we find the
|
1998-07-31 04:54:47 +08:00
|
|
|
|
first colon which isn't followed by a slash or a backslash.
|
|
|
|
|
Note that tokens separated by spaces should be treated as separate
|
|
|
|
|
tokens since make doesn't allow path names with spaces */
|
|
|
|
|
if (stopchar == ':')
|
1999-10-15 15:00:58 +08:00
|
|
|
|
while (p != 0 && !isspace ((unsigned char)*p) &&
|
|
|
|
|
(p[1] == '\\' || p[1] == '/') && isalpha ((unsigned char)p[-1]))
|
2005-06-26 05:30:13 +08:00
|
|
|
|
p = find_char_unquote (p + 1, stopchar, VMS_COMMA, 1, 0);
|
1995-03-09 09:42:12 +08:00
|
|
|
|
#endif
|
1994-04-22 04:36:47 +08:00
|
|
|
|
if (p == 0)
|
1994-04-22 05:28:59 +08:00
|
|
|
|
p = q + strlen (q);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
1993-04-16 06:30:01 +08:00
|
|
|
|
if (strip)
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
/* Skip leading `[]'s. */
|
|
|
|
|
while (p - q > 2 && q[0] == '[' && q[1] == ']')
|
|
|
|
|
#else
|
1993-04-16 06:30:01 +08:00
|
|
|
|
/* Skip leading `./'s. */
|
|
|
|
|
while (p - q > 2 && q[0] == '.' && q[1] == '/')
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif
|
1993-04-16 06:30:01 +08:00
|
|
|
|
{
|
|
|
|
|
q += 2; /* Skip "./". */
|
|
|
|
|
while (q < p && *q == '/')
|
|
|
|
|
/* Skip following slashes: ".//foo" is "foo", not "/foo". */
|
|
|
|
|
++q;
|
|
|
|
|
}
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
/* Extract the filename just found, and skip it. */
|
1992-10-13 01:35:43 +08:00
|
|
|
|
|
|
|
|
|
if (q == p)
|
1996-03-20 22:57:41 +08:00
|
|
|
|
/* ".///" was stripped to "". */
|
2007-03-20 11:02:26 +08:00
|
|
|
|
#if defined(VMS)
|
1996-03-20 22:57:41 +08:00
|
|
|
|
continue;
|
2007-03-20 11:02:26 +08:00
|
|
|
|
#elif defined(_AMIGA)
|
|
|
|
|
name = "";
|
1996-05-14 02:39:02 +08:00
|
|
|
|
#else
|
2007-03-20 11:02:26 +08:00
|
|
|
|
name = "./";
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif
|
1992-10-13 01:35:43 +08:00
|
|
|
|
else
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
/* VMS filenames can have a ':' in them but they have to be '\'ed but we need
|
|
|
|
|
* to remove this '\' before we can use the filename.
|
|
|
|
|
* Savestring called because q may be read-only string constant.
|
|
|
|
|
*/
|
|
|
|
|
{
|
1999-07-21 13:53:23 +08:00
|
|
|
|
char *qbase = xstrdup (q);
|
1996-03-20 22:57:41 +08:00
|
|
|
|
char *pbase = qbase + (p-q);
|
|
|
|
|
char *q1 = qbase;
|
|
|
|
|
char *q2 = q1;
|
|
|
|
|
char *p1 = pbase;
|
|
|
|
|
|
|
|
|
|
while (q1 != pbase)
|
|
|
|
|
{
|
|
|
|
|
if (*q1 == '\\' && *(q1+1) == ':')
|
|
|
|
|
{
|
|
|
|
|
q1++;
|
|
|
|
|
p1--;
|
|
|
|
|
}
|
1996-05-10 01:28:47 +08:00
|
|
|
|
*q2++ = *q1++;
|
1996-03-20 22:57:41 +08:00
|
|
|
|
}
|
2007-03-20 11:02:26 +08:00
|
|
|
|
name = strcache_add_len (qbase, p1 - qbase);
|
1996-03-20 22:57:41 +08:00
|
|
|
|
free (qbase);
|
|
|
|
|
}
|
|
|
|
|
#else
|
2007-03-20 11:02:26 +08:00
|
|
|
|
name = strcache_add_len (q, p - q);
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
/* Add it to the front of the chain. */
|
2006-04-10 06:09:24 +08:00
|
|
|
|
new1 = xmalloc (size);
|
2008-03-28 11:46:39 +08:00
|
|
|
|
memset (new1, '\0', size);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
new1->name = name;
|
|
|
|
|
new1->next = new;
|
|
|
|
|
new = new1;
|
|
|
|
|
}
|
|
|
|
|
|
1993-06-10 09:31:02 +08:00
|
|
|
|
#ifndef NO_ARCHIVES
|
|
|
|
|
|
|
|
|
|
/* Look for multi-word archive references.
|
|
|
|
|
They are indicated by a elt ending with an unmatched `)' and
|
|
|
|
|
an elt further down the chain (i.e., previous in the file list)
|
|
|
|
|
with an unmatched `(' (e.g., "lib(mem"). */
|
|
|
|
|
|
1995-03-13 13:45:44 +08:00
|
|
|
|
new1 = new;
|
|
|
|
|
lastnew1 = 0;
|
|
|
|
|
while (new1 != 0)
|
1993-06-10 09:31:02 +08:00
|
|
|
|
if (new1->name[0] != '(' /* Don't catch "(%)" and suchlike. */
|
|
|
|
|
&& new1->name[strlen (new1->name) - 1] == ')'
|
1999-10-15 15:00:58 +08:00
|
|
|
|
&& strchr (new1->name, '(') == 0)
|
1993-06-10 09:31:02 +08:00
|
|
|
|
{
|
|
|
|
|
/* NEW1 ends with a `)' but does not contain a `('.
|
|
|
|
|
Look back for an elt with an opening `(' but no closing `)'. */
|
|
|
|
|
|
|
|
|
|
struct nameseq *n = new1->next, *lastn = new1;
|
1998-07-31 04:54:47 +08:00
|
|
|
|
char *paren = 0;
|
1999-10-15 15:00:58 +08:00
|
|
|
|
while (n != 0 && (paren = strchr (n->name, '(')) == 0)
|
1993-06-10 09:31:02 +08:00
|
|
|
|
{
|
|
|
|
|
lastn = n;
|
|
|
|
|
n = n->next;
|
|
|
|
|
}
|
1993-10-26 03:25:17 +08:00
|
|
|
|
if (n != 0
|
|
|
|
|
/* Ignore something starting with `(', as that cannot actually
|
|
|
|
|
be an archive-member reference (and treating it as such
|
|
|
|
|
results in an empty file name, which causes much lossage). */
|
|
|
|
|
&& n->name[0] != '(')
|
1993-06-10 09:31:02 +08:00
|
|
|
|
{
|
|
|
|
|
/* N is the first element in the archive group.
|
|
|
|
|
Its name looks like "lib(mem" (with no closing `)'). */
|
|
|
|
|
|
|
|
|
|
char *libname;
|
|
|
|
|
|
|
|
|
|
/* Copy "lib(" into LIBNAME. */
|
|
|
|
|
++paren;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
libname = alloca (paren - n->name + 1);
|
|
|
|
|
memcpy (libname, n->name, paren - n->name);
|
1993-06-10 09:31:02 +08:00
|
|
|
|
libname[paren - n->name] = '\0';
|
|
|
|
|
|
|
|
|
|
if (*paren == '\0')
|
|
|
|
|
{
|
|
|
|
|
/* N was just "lib(", part of something like "lib( a b)".
|
|
|
|
|
Edit it out of the chain and free its storage. */
|
|
|
|
|
lastn->next = n->next;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (n);
|
1993-06-10 09:31:02 +08:00
|
|
|
|
/* LASTN->next is the new stopping elt for the loop below. */
|
|
|
|
|
n = lastn->next;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Replace N's name with the full archive reference. */
|
2007-03-20 11:02:26 +08:00
|
|
|
|
n->name = strcache_add (concat (libname, paren, ")"));
|
1993-06-10 09:31:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (new1->name[1] == '\0')
|
|
|
|
|
{
|
|
|
|
|
/* NEW1 is just ")", part of something like "lib(a b )".
|
|
|
|
|
Omit it from the chain and free its storage. */
|
1994-04-02 07:44:10 +08:00
|
|
|
|
if (lastnew1 == 0)
|
|
|
|
|
new = new1->next;
|
|
|
|
|
else
|
|
|
|
|
lastnew1->next = new1->next;
|
1993-06-10 09:31:02 +08:00
|
|
|
|
lastn = new1;
|
|
|
|
|
new1 = new1->next;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (lastn);
|
1993-06-10 09:31:02 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Replace also NEW1->name, which already has closing `)'. */
|
2007-03-20 11:02:26 +08:00
|
|
|
|
new1->name = strcache_add (concat (libname, new1->name, ""));
|
1993-06-10 09:31:02 +08:00
|
|
|
|
new1 = new1->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Trace back from NEW1 (the end of the list) until N
|
|
|
|
|
(the beginning of the list), rewriting each name
|
|
|
|
|
with the full archive reference. */
|
1995-12-12 11:31:40 +08:00
|
|
|
|
|
1993-06-10 09:31:02 +08:00
|
|
|
|
while (new1 != n)
|
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
new1->name = strcache_add (concat (libname, new1->name, ")"));
|
1995-03-13 13:45:44 +08:00
|
|
|
|
lastnew1 = new1;
|
1993-06-10 09:31:02 +08:00
|
|
|
|
new1 = new1->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-03-13 13:45:44 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* No frobnication happening. Just step down the list. */
|
|
|
|
|
lastnew1 = new1;
|
|
|
|
|
new1 = new1->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lastnew1 = new1;
|
|
|
|
|
new1 = new1->next;
|
1993-06-10 09:31:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
*stringp = p;
|
|
|
|
|
return new;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
/* Find the next line of text in an eval buffer, combining continuation lines
|
|
|
|
|
into one line.
|
|
|
|
|
Return the number of actual lines read (> 1 if continuation lines).
|
|
|
|
|
Returns -1 if there's nothing left in the buffer.
|
|
|
|
|
|
|
|
|
|
After this function, ebuf->buffer points to the first character of the
|
|
|
|
|
line we just found.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Read a line of text from a STRING.
|
|
|
|
|
Since we aren't really reading from a file, don't bother with linenumbers.
|
1992-02-14 18:52:22 +08:00
|
|
|
|
*/
|
|
|
|
|
|
1998-10-03 13:39:55 +08:00
|
|
|
|
static unsigned long
|
2002-10-15 05:54:04 +08:00
|
|
|
|
readstring (struct ebuffer *ebuf)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2004-09-21 21:51:58 +08:00
|
|
|
|
char *eol;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
/* If there is nothing left in this buffer, return 0. */
|
2004-09-21 21:51:58 +08:00
|
|
|
|
if (ebuf->bufnext >= ebuf->bufstart + ebuf->size)
|
2002-07-08 10:26:47 +08:00
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
/* Set up a new starting point for the buffer, and find the end of the
|
|
|
|
|
next logical line (taking into account backslash/newline pairs). */
|
|
|
|
|
|
2004-09-21 21:51:58 +08:00
|
|
|
|
eol = ebuf->buffer = ebuf->bufnext;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
int backslash = 0;
|
2004-09-21 21:51:58 +08:00
|
|
|
|
char *bol = eol;
|
|
|
|
|
char *p;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
2004-09-21 21:51:58 +08:00
|
|
|
|
/* Find the next newline. At EOS, stop. */
|
|
|
|
|
eol = p = strchr (eol , '\n');
|
|
|
|
|
if (!eol)
|
|
|
|
|
{
|
|
|
|
|
ebuf->bufnext = ebuf->bufstart + ebuf->size + 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
2004-09-21 21:51:58 +08:00
|
|
|
|
/* Found a newline; if it's escaped continue; else we're done. */
|
|
|
|
|
while (p > bol && *(--p) == '\\')
|
|
|
|
|
backslash = !backslash;
|
|
|
|
|
if (!backslash)
|
2002-07-08 10:26:47 +08:00
|
|
|
|
break;
|
2004-09-21 21:51:58 +08:00
|
|
|
|
++eol;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Overwrite the newline char. */
|
2004-09-21 21:51:58 +08:00
|
|
|
|
*eol = '\0';
|
|
|
|
|
ebuf->bufnext = eol+1;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static long
|
2002-10-15 05:54:04 +08:00
|
|
|
|
readline (struct ebuffer *ebuf)
|
2002-07-08 10:26:47 +08:00
|
|
|
|
{
|
2002-07-11 14:38:57 +08:00
|
|
|
|
char *p;
|
|
|
|
|
char *end;
|
|
|
|
|
char *start;
|
2002-07-08 10:26:47 +08:00
|
|
|
|
long nlines = 0;
|
|
|
|
|
|
|
|
|
|
/* The behaviors between string and stream buffers are different enough to
|
|
|
|
|
warrant different functions. Do the Right Thing. */
|
|
|
|
|
|
|
|
|
|
if (!ebuf->fp)
|
|
|
|
|
return readstring (ebuf);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2002-07-11 14:38:57 +08:00
|
|
|
|
/* When reading from a file, we always start over at the beginning of the
|
|
|
|
|
buffer for each new line. */
|
|
|
|
|
|
|
|
|
|
p = start = ebuf->bufstart;
|
|
|
|
|
end = p + ebuf->size;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
*p = '\0';
|
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
while (fgets (p, end - p, ebuf->fp) != 0)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2000-11-17 14:59:08 +08:00
|
|
|
|
char *p2;
|
|
|
|
|
unsigned long len;
|
|
|
|
|
int backslash;
|
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
len = strlen (p);
|
1992-12-29 08:20:25 +08:00
|
|
|
|
if (len == 0)
|
1993-12-15 04:09:51 +08:00
|
|
|
|
{
|
|
|
|
|
/* This only happens when the first thing on the line is a '\0'.
|
|
|
|
|
It is a pretty hopeless case, but (wonder of wonders) Athena
|
|
|
|
|
lossage strikes again! (xmkmf puts NULs in its makefiles.)
|
|
|
|
|
There is nothing really to be done; we synthesize a newline so
|
|
|
|
|
the following line doesn't appear to be part of this line. */
|
2002-07-08 10:26:47 +08:00
|
|
|
|
error (&ebuf->floc,
|
|
|
|
|
_("warning: NUL character seen; rest of line ignored"));
|
1993-12-15 04:09:51 +08:00
|
|
|
|
p[0] = '\n';
|
|
|
|
|
len = 1;
|
|
|
|
|
}
|
1992-12-29 08:20:25 +08:00
|
|
|
|
|
2000-11-17 14:59:08 +08:00
|
|
|
|
/* Jump past the text we just read. */
|
1992-12-24 05:14:20 +08:00
|
|
|
|
p += len;
|
2000-11-17 14:59:08 +08:00
|
|
|
|
|
|
|
|
|
/* If the last char isn't a newline, the whole line didn't fit into the
|
|
|
|
|
buffer. Get some more buffer and try again. */
|
1992-12-24 05:14:20 +08:00
|
|
|
|
if (p[-1] != '\n')
|
2002-07-11 14:38:57 +08:00
|
|
|
|
goto more_buffer;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2000-11-17 14:59:08 +08:00
|
|
|
|
/* We got a newline, so add one to the count of lines. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
++nlines;
|
|
|
|
|
|
2003-03-25 07:14:15 +08:00
|
|
|
|
#if !defined(WINDOWS32) && !defined(__MSDOS__) && !defined(__EMX__)
|
1999-04-01 07:25:13 +08:00
|
|
|
|
/* Check to see if the line was really ended with CRLF; if so ignore
|
|
|
|
|
the CR. */
|
2002-07-11 14:38:57 +08:00
|
|
|
|
if ((p - start) > 1 && p[-2] == '\r')
|
1999-04-01 07:25:13 +08:00
|
|
|
|
{
|
|
|
|
|
--p;
|
|
|
|
|
p[-1] = '\n';
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
backslash = 0;
|
2002-07-11 14:38:57 +08:00
|
|
|
|
for (p2 = p - 2; p2 >= start; --p2)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2000-11-17 14:59:08 +08:00
|
|
|
|
if (*p2 != '\\')
|
1992-02-14 18:52:22 +08:00
|
|
|
|
break;
|
2000-11-17 14:59:08 +08:00
|
|
|
|
backslash = !backslash;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
1995-12-12 11:31:40 +08:00
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
if (!backslash)
|
|
|
|
|
{
|
|
|
|
|
p[-1] = '\0';
|
1992-12-29 08:20:25 +08:00
|
|
|
|
break;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-11 14:38:57 +08:00
|
|
|
|
/* It was a backslash/newline combo. If we have more space, read
|
|
|
|
|
another line. */
|
|
|
|
|
if (end - p >= 80)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* We need more space at the end of our buffer, so realloc it.
|
|
|
|
|
Make sure to preserve the current offset of p. */
|
|
|
|
|
more_buffer:
|
|
|
|
|
{
|
|
|
|
|
unsigned long off = p - start;
|
|
|
|
|
ebuf->size *= 2;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
start = ebuf->buffer = ebuf->bufstart = xrealloc (start, ebuf->size);
|
2002-07-11 14:38:57 +08:00
|
|
|
|
p = start + off;
|
|
|
|
|
end = start + ebuf->size;
|
|
|
|
|
*p = '\0';
|
|
|
|
|
}
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
1992-12-29 08:20:25 +08:00
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
|
if (ferror (ebuf->fp))
|
|
|
|
|
pfatal_with_name (ebuf->floc.filenm);
|
1993-12-15 04:09:51 +08:00
|
|
|
|
|
2002-08-08 08:11:19 +08:00
|
|
|
|
/* If we found some lines, return how many.
|
|
|
|
|
If we didn't, but we did find _something_, that indicates we read the last
|
|
|
|
|
line of a file with no final newline; return 1.
|
|
|
|
|
If we read nothing, we're at EOF; return -1. */
|
|
|
|
|
|
|
|
|
|
return nlines ? nlines : p == ebuf->bufstart ? -1 : 1;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
1998-07-31 04:54:47 +08:00
|
|
|
|
/* Parse the next "makefile word" from the input buffer, and return info
|
|
|
|
|
about it.
|
|
|
|
|
|
|
|
|
|
A "makefile word" is one of:
|
|
|
|
|
|
|
|
|
|
w_bogus Should never happen
|
|
|
|
|
w_eol End of input
|
|
|
|
|
w_static A static word; cannot be expanded
|
|
|
|
|
w_variable A word containing one or more variables/functions
|
|
|
|
|
w_colon A colon
|
|
|
|
|
w_dcolon A double-colon
|
|
|
|
|
w_semicolon A semicolon
|
|
|
|
|
w_varassign A variable assignment operator (=, :=, +=, or ?=)
|
|
|
|
|
|
|
|
|
|
Note that this function is only used when reading certain parts of the
|
|
|
|
|
makefile. Don't use it where special rules hold sway (RHS of a variable,
|
|
|
|
|
in a command list, etc.) */
|
|
|
|
|
|
|
|
|
|
static enum make_word_type
|
2002-10-15 05:54:04 +08:00
|
|
|
|
get_next_mword (char *buffer, char *delim, char **startp, unsigned int *length)
|
1998-07-31 04:54:47 +08:00
|
|
|
|
{
|
|
|
|
|
enum make_word_type wtype = w_bogus;
|
|
|
|
|
char *p = buffer, *beg;
|
|
|
|
|
char c;
|
|
|
|
|
|
|
|
|
|
/* Skip any leading whitespace. */
|
2000-06-07 13:43:37 +08:00
|
|
|
|
while (isblank ((unsigned char)*p))
|
1998-07-31 04:54:47 +08:00
|
|
|
|
++p;
|
|
|
|
|
|
|
|
|
|
beg = p;
|
|
|
|
|
c = *(p++);
|
|
|
|
|
switch (c)
|
|
|
|
|
{
|
|
|
|
|
case '\0':
|
|
|
|
|
wtype = w_eol;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ';':
|
|
|
|
|
wtype = w_semicolon;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '=':
|
|
|
|
|
wtype = w_varassign;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ':':
|
|
|
|
|
wtype = w_colon;
|
|
|
|
|
switch (*p)
|
|
|
|
|
{
|
|
|
|
|
case ':':
|
|
|
|
|
++p;
|
|
|
|
|
wtype = w_dcolon;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '=':
|
|
|
|
|
++p;
|
|
|
|
|
wtype = w_varassign;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '+':
|
|
|
|
|
case '?':
|
|
|
|
|
if (*p == '=')
|
|
|
|
|
{
|
|
|
|
|
++p;
|
|
|
|
|
wtype = w_varassign;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
1999-10-15 15:00:58 +08:00
|
|
|
|
if (delim && strchr (delim, c))
|
1998-07-31 04:54:47 +08:00
|
|
|
|
wtype = w_static;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Did we find something? If so, return now. */
|
|
|
|
|
if (wtype != w_bogus)
|
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
|
|
/* This is some non-operator word. A word consists of the longest
|
|
|
|
|
string of characters that doesn't contain whitespace, one of [:=#],
|
|
|
|
|
or [?+]=, or one of the chars in the DELIM string. */
|
|
|
|
|
|
|
|
|
|
/* We start out assuming a static word; if we see a variable we'll
|
|
|
|
|
adjust our assumptions then. */
|
|
|
|
|
wtype = w_static;
|
|
|
|
|
|
|
|
|
|
/* We already found the first value of "c", above. */
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
char closeparen;
|
|
|
|
|
int count;
|
|
|
|
|
|
|
|
|
|
switch (c)
|
|
|
|
|
{
|
|
|
|
|
case '\0':
|
|
|
|
|
case ' ':
|
|
|
|
|
case '\t':
|
|
|
|
|
case '=':
|
|
|
|
|
goto done_word;
|
|
|
|
|
|
|
|
|
|
case ':':
|
2002-08-10 09:27:16 +08:00
|
|
|
|
#ifdef HAVE_DOS_PATHS
|
1998-10-03 13:39:55 +08:00
|
|
|
|
/* A word CAN include a colon in its drive spec. The drive
|
|
|
|
|
spec is allowed either at the beginning of a word, or as part
|
|
|
|
|
of the archive member name, like in "libfoo.a(d:/foo/bar.o)". */
|
1999-10-15 15:00:58 +08:00
|
|
|
|
if (!(p - beg >= 2
|
|
|
|
|
&& (*p == '/' || *p == '\\') && isalpha ((unsigned char)p[-2])
|
|
|
|
|
&& (p - beg == 2 || p[-3] == '(')))
|
1998-07-31 04:54:47 +08:00
|
|
|
|
#endif
|
|
|
|
|
goto done_word;
|
|
|
|
|
|
|
|
|
|
case '$':
|
|
|
|
|
c = *(p++);
|
|
|
|
|
if (c == '$')
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* This is a variable reference, so note that it's expandable.
|
|
|
|
|
Then read it to the matching close paren. */
|
|
|
|
|
wtype = w_variable;
|
|
|
|
|
|
|
|
|
|
if (c == '(')
|
|
|
|
|
closeparen = ')';
|
|
|
|
|
else if (c == '{')
|
|
|
|
|
closeparen = '}';
|
|
|
|
|
else
|
|
|
|
|
/* This is a single-letter variable reference. */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
for (count=0; *p != '\0'; ++p)
|
|
|
|
|
{
|
|
|
|
|
if (*p == c)
|
|
|
|
|
++count;
|
|
|
|
|
else if (*p == closeparen && --count < 0)
|
|
|
|
|
{
|
|
|
|
|
++p;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
|
case '+':
|
|
|
|
|
if (*p == '=')
|
|
|
|
|
goto done_word;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '\\':
|
|
|
|
|
switch (*p)
|
|
|
|
|
{
|
1999-06-14 14:50:28 +08:00
|
|
|
|
case ':':
|
1998-07-31 04:54:47 +08:00
|
|
|
|
case ';':
|
|
|
|
|
case '=':
|
|
|
|
|
case '\\':
|
|
|
|
|
++p;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
1999-10-15 15:00:58 +08:00
|
|
|
|
if (delim && strchr (delim, c))
|
1998-07-31 04:54:47 +08:00
|
|
|
|
goto done_word;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c = *(p++);
|
|
|
|
|
}
|
|
|
|
|
done_word:
|
|
|
|
|
--p;
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
if (startp)
|
|
|
|
|
*startp = beg;
|
|
|
|
|
if (length)
|
|
|
|
|
*length = p - beg;
|
|
|
|
|
return wtype;
|
|
|
|
|
}
|
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
/* Construct the list of include directories
|
|
|
|
|
from the arguments and the default list. */
|
|
|
|
|
|
|
|
|
|
void
|
2007-03-20 11:02:26 +08:00
|
|
|
|
construct_include_path (const char **arg_dirs)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifdef VAXC /* just don't ask ... */
|
|
|
|
|
stat_t stbuf;
|
|
|
|
|
#else
|
1992-02-14 18:52:22 +08:00
|
|
|
|
struct stat stbuf;
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif
|
2007-03-20 11:02:26 +08:00
|
|
|
|
const char **dirs;
|
|
|
|
|
const char **cpp;
|
|
|
|
|
unsigned int idx;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
/* Compute the number of pointers we need in the table. */
|
|
|
|
|
idx = sizeof (default_include_directories) / sizeof (const char *);
|
|
|
|
|
if (arg_dirs)
|
|
|
|
|
for (cpp = arg_dirs; *cpp != 0; ++cpp)
|
|
|
|
|
++idx;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#ifdef __MSDOS__
|
2007-03-20 11:02:26 +08:00
|
|
|
|
/* Add one for $DJDIR. */
|
|
|
|
|
++idx;
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
dirs = xmalloc (idx * sizeof (const char *));
|
|
|
|
|
|
|
|
|
|
idx = 0;
|
|
|
|
|
max_incl_len = 0;
|
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
/* First consider any dirs specified with -I switches.
|
2007-03-20 11:02:26 +08:00
|
|
|
|
Ignore any that don't exist. Remember the maximum string length. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
if (arg_dirs)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
while (*arg_dirs != 0)
|
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
const char *dir = *(arg_dirs++);
|
|
|
|
|
char *expanded = 0;
|
2003-01-30 13:22:52 +08:00
|
|
|
|
int e;
|
1993-06-08 08:36:13 +08:00
|
|
|
|
|
|
|
|
|
if (dir[0] == '~')
|
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
expanded = tilde_expand (dir);
|
1993-06-08 08:36:13 +08:00
|
|
|
|
if (expanded != 0)
|
|
|
|
|
dir = expanded;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-30 13:22:52 +08:00
|
|
|
|
EINTRLOOP (e, stat (dir, &stbuf));
|
|
|
|
|
if (e == 0 && S_ISDIR (stbuf.st_mode))
|
2007-03-20 11:02:26 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned int len = strlen (dir);
|
|
|
|
|
/* If dir name is written with trailing slashes, discard them. */
|
|
|
|
|
while (len > 1 && dir[len - 1] == '/')
|
|
|
|
|
--len;
|
|
|
|
|
if (len > max_incl_len)
|
|
|
|
|
max_incl_len = len;
|
|
|
|
|
dirs[idx++] = strcache_add_len (dir, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (expanded)
|
|
|
|
|
free (expanded);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
/* Now add the standard default dirs at the end. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#ifdef __MSDOS__
|
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
/* The environment variable $DJDIR holds the root of the DJGPP directory
|
|
|
|
|
tree; add ${DJDIR}/include. */
|
1997-04-07 15:21:16 +08:00
|
|
|
|
struct variable *djdir = lookup_variable ("DJDIR", 5);
|
|
|
|
|
|
|
|
|
|
if (djdir)
|
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
unsigned int len = strlen (djdir->value) + 8;
|
|
|
|
|
char *defdir = alloca (len + 1);
|
1997-04-07 15:21:16 +08:00
|
|
|
|
|
|
|
|
|
strcat (strcpy (defdir, djdir->value), "/include");
|
2007-03-20 11:02:26 +08:00
|
|
|
|
dirs[idx++] = strcache_add (defdir);
|
|
|
|
|
|
|
|
|
|
if (len > max_incl_len)
|
|
|
|
|
max_incl_len = len;
|
1997-04-07 15:21:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
for (cpp = default_include_directories; *cpp != 0; ++cpp)
|
2003-01-30 13:22:52 +08:00
|
|
|
|
{
|
|
|
|
|
int e;
|
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
EINTRLOOP (e, stat (*cpp, &stbuf));
|
2003-01-30 13:22:52 +08:00
|
|
|
|
if (e == 0 && S_ISDIR (stbuf.st_mode))
|
2007-03-20 11:02:26 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned int len = strlen (*cpp);
|
|
|
|
|
/* If dir name is written with trailing slashes, discard them. */
|
|
|
|
|
while (len > 1 && (*cpp)[len - 1] == '/')
|
|
|
|
|
--len;
|
|
|
|
|
if (len > max_incl_len)
|
|
|
|
|
max_incl_len = len;
|
2007-11-05 05:54:00 +08:00
|
|
|
|
dirs[idx++] = strcache_add_len (*cpp, len);
|
2007-03-20 11:02:26 +08:00
|
|
|
|
}
|
2003-01-30 13:22:52 +08:00
|
|
|
|
}
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
dirs[idx] = 0;
|
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
/* Now add each dir to the .INCLUDE_DIRS variable. */
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
for (cpp = dirs; *cpp != 0; ++cpp)
|
|
|
|
|
do_variable_definition (NILF, ".INCLUDE_DIRS", *cpp,
|
|
|
|
|
o_default, f_append, 0);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
include_directories = dirs;
|
|
|
|
|
}
|
|
|
|
|
|
1993-06-08 08:36:13 +08:00
|
|
|
|
/* Expand ~ or ~USER at the beginning of NAME.
|
|
|
|
|
Return a newly malloc'd string or 0. */
|
|
|
|
|
|
|
|
|
|
char *
|
2007-03-20 11:02:26 +08:00
|
|
|
|
tilde_expand (const char *name)
|
1993-06-08 08:36:13 +08:00
|
|
|
|
{
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifndef VMS
|
1993-06-08 08:36:13 +08:00
|
|
|
|
if (name[1] == '/' || name[1] == '\0')
|
|
|
|
|
{
|
|
|
|
|
extern char *getenv ();
|
1993-06-26 04:03:54 +08:00
|
|
|
|
char *home_dir;
|
|
|
|
|
int is_variable;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
/* Turn off --warn-undefined-variables while we expand HOME. */
|
|
|
|
|
int save = warn_undefined_variables_flag;
|
|
|
|
|
warn_undefined_variables_flag = 0;
|
|
|
|
|
|
|
|
|
|
home_dir = allocated_variable_expand ("$(HOME)");
|
|
|
|
|
|
|
|
|
|
warn_undefined_variables_flag = save;
|
|
|
|
|
}
|
1995-12-12 11:31:40 +08:00
|
|
|
|
|
1993-06-26 04:03:54 +08:00
|
|
|
|
is_variable = home_dir[0] != '\0';
|
1993-06-08 08:36:13 +08:00
|
|
|
|
if (!is_variable)
|
|
|
|
|
{
|
|
|
|
|
free (home_dir);
|
|
|
|
|
home_dir = getenv ("HOME");
|
|
|
|
|
}
|
2007-03-20 11:02:26 +08:00
|
|
|
|
# if !defined(_AMIGA) && !defined(WINDOWS32)
|
1993-06-08 08:36:13 +08:00
|
|
|
|
if (home_dir == 0 || home_dir[0] == '\0')
|
|
|
|
|
{
|
|
|
|
|
extern char *getlogin ();
|
1998-07-31 04:54:47 +08:00
|
|
|
|
char *logname = getlogin ();
|
1993-06-08 08:36:13 +08:00
|
|
|
|
home_dir = 0;
|
1998-07-31 04:54:47 +08:00
|
|
|
|
if (logname != 0)
|
1993-06-08 08:36:13 +08:00
|
|
|
|
{
|
1998-07-31 04:54:47 +08:00
|
|
|
|
struct passwd *p = getpwnam (logname);
|
1993-06-08 08:36:13 +08:00
|
|
|
|
if (p != 0)
|
|
|
|
|
home_dir = p->pw_dir;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-03-20 11:02:26 +08:00
|
|
|
|
# endif /* !AMIGA && !WINDOWS32 */
|
1993-06-08 08:36:13 +08:00
|
|
|
|
if (home_dir != 0)
|
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
char *new = xstrdup (concat (home_dir, "", name + 1));
|
1993-06-08 08:36:13 +08:00
|
|
|
|
if (is_variable)
|
|
|
|
|
free (home_dir);
|
|
|
|
|
return new;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-03-20 11:02:26 +08:00
|
|
|
|
# if !defined(_AMIGA) && !defined(WINDOWS32)
|
1993-06-08 08:36:13 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
struct passwd *pwent;
|
1999-10-15 15:00:58 +08:00
|
|
|
|
char *userend = strchr (name + 1, '/');
|
1993-06-08 08:36:13 +08:00
|
|
|
|
if (userend != 0)
|
|
|
|
|
*userend = '\0';
|
|
|
|
|
pwent = getpwnam (name + 1);
|
|
|
|
|
if (pwent != 0)
|
|
|
|
|
{
|
|
|
|
|
if (userend == 0)
|
1999-07-21 13:53:23 +08:00
|
|
|
|
return xstrdup (pwent->pw_dir);
|
1993-06-08 08:36:13 +08:00
|
|
|
|
else
|
2007-03-20 11:02:26 +08:00
|
|
|
|
return xstrdup (concat (pwent->pw_dir, "/", userend + 1));
|
1993-06-08 08:36:13 +08:00
|
|
|
|
}
|
|
|
|
|
else if (userend != 0)
|
|
|
|
|
*userend = '/';
|
|
|
|
|
}
|
2007-03-20 11:02:26 +08:00
|
|
|
|
# endif /* !AMIGA && !WINDOWS32 */
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif /* !VMS */
|
1993-06-08 08:36:13 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1992-02-14 18:52:22 +08:00
|
|
|
|
/* Given a chain of struct nameseq's describing a sequence of filenames,
|
|
|
|
|
in reverse of the intended order, return a new chain describing the
|
|
|
|
|
result of globbing the filenames. The new chain is in forward order.
|
|
|
|
|
The links of the old chain are freed or used in the new chain.
|
|
|
|
|
Likewise for the names in the old chain.
|
|
|
|
|
|
|
|
|
|
SIZE is how big to construct chain elements.
|
|
|
|
|
This is useful if we want them actually to be other structures
|
|
|
|
|
that have room for additional info. */
|
|
|
|
|
|
|
|
|
|
struct nameseq *
|
2002-10-15 05:54:04 +08:00
|
|
|
|
multi_glob (struct nameseq *chain, unsigned int size)
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
void dir_setup_glob (glob_t *);
|
|
|
|
|
struct nameseq *new = 0;
|
|
|
|
|
struct nameseq *old;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
struct nameseq *nexto;
|
1995-12-12 11:31:40 +08:00
|
|
|
|
glob_t gl;
|
|
|
|
|
|
|
|
|
|
dir_setup_glob (&gl);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
|
|
|
|
for (old = chain; old != 0; old = nexto)
|
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
const char *gname;
|
1993-06-10 09:31:02 +08:00
|
|
|
|
#ifndef NO_ARCHIVES
|
2007-03-20 11:02:26 +08:00
|
|
|
|
char *arname = 0;
|
|
|
|
|
char *memname = 0;
|
1993-06-10 09:31:02 +08:00
|
|
|
|
#endif
|
1992-02-14 18:52:22 +08:00
|
|
|
|
nexto = old->next;
|
2007-03-20 11:02:26 +08:00
|
|
|
|
gname = old->name;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
if (gname[0] == '~')
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
1993-06-08 08:36:13 +08:00
|
|
|
|
char *newname = tilde_expand (old->name);
|
|
|
|
|
if (newname != 0)
|
2007-03-20 11:02:26 +08:00
|
|
|
|
gname = newname;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
1993-06-10 09:31:02 +08:00
|
|
|
|
#ifndef NO_ARCHIVES
|
2007-03-20 11:02:26 +08:00
|
|
|
|
if (ar_name (gname))
|
1993-06-10 09:31:02 +08:00
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
/* OLD->name is an archive member reference. Replace it with the
|
|
|
|
|
archive file name, and save the member name in MEMNAME. We will
|
|
|
|
|
glob on the archive name and then reattach MEMNAME later. */
|
|
|
|
|
ar_parse_name (gname, &arname, &memname);
|
|
|
|
|
gname = arname;
|
1993-06-10 09:31:02 +08:00
|
|
|
|
}
|
1996-05-14 02:39:02 +08:00
|
|
|
|
#endif /* !NO_ARCHIVES */
|
1993-06-10 09:31:02 +08:00
|
|
|
|
|
2007-03-20 11:02:26 +08:00
|
|
|
|
switch (glob (gname, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl))
|
1992-02-14 18:52:22 +08:00
|
|
|
|
{
|
|
|
|
|
case 0: /* Success. */
|
|
|
|
|
{
|
2007-03-20 11:02:26 +08:00
|
|
|
|
int i = gl.gl_pathc;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
while (i-- > 0)
|
|
|
|
|
{
|
1993-06-10 09:31:02 +08:00
|
|
|
|
#ifndef NO_ARCHIVES
|
|
|
|
|
if (memname != 0)
|
|
|
|
|
{
|
|
|
|
|
/* Try to glob on MEMNAME within the archive. */
|
|
|
|
|
struct nameseq *found
|
|
|
|
|
= ar_glob (gl.gl_pathv[i], memname, size);
|
2007-03-20 11:02:26 +08:00
|
|
|
|
if (! found)
|
1993-06-10 09:31:02 +08:00
|
|
|
|
{
|
|
|
|
|
/* No matches. Use MEMNAME as-is. */
|
|
|
|
|
unsigned int alen = strlen (gl.gl_pathv[i]);
|
|
|
|
|
unsigned int mlen = strlen (memname);
|
2007-03-20 11:02:26 +08:00
|
|
|
|
char *name;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
struct nameseq *elt = xmalloc (size);
|
2007-03-20 11:02:26 +08:00
|
|
|
|
memset (elt, '\0', size);
|
|
|
|
|
|
|
|
|
|
name = alloca (alen + 1 + mlen + 2);
|
|
|
|
|
memcpy (name, gl.gl_pathv[i], alen);
|
|
|
|
|
name[alen] = '(';
|
|
|
|
|
memcpy (name+alen+1, memname, mlen);
|
|
|
|
|
name[alen + 1 + mlen] = ')';
|
|
|
|
|
name[alen + 1 + mlen + 1] = '\0';
|
|
|
|
|
elt->name = strcache_add (name);
|
1993-06-10 09:31:02 +08:00
|
|
|
|
elt->next = new;
|
|
|
|
|
new = elt;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Find the end of the FOUND chain. */
|
1993-06-11 06:20:53 +08:00
|
|
|
|
struct nameseq *f = found;
|
|
|
|
|
while (f->next != 0)
|
|
|
|
|
f = f->next;
|
1993-06-10 09:31:02 +08:00
|
|
|
|
|
|
|
|
|
/* Attach the chain being built to the end of the FOUND
|
|
|
|
|
chain, and make FOUND the new NEW chain. */
|
1993-06-11 06:20:53 +08:00
|
|
|
|
f->next = new;
|
1993-06-10 09:31:02 +08:00
|
|
|
|
new = found;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
1996-05-14 02:39:02 +08:00
|
|
|
|
#endif /* !NO_ARCHIVES */
|
1993-06-10 09:31:02 +08:00
|
|
|
|
{
|
2006-04-10 06:09:24 +08:00
|
|
|
|
struct nameseq *elt = xmalloc (size);
|
2007-03-20 11:02:26 +08:00
|
|
|
|
memset (elt, '\0', size);
|
|
|
|
|
elt->name = strcache_add (gl.gl_pathv[i]);
|
1993-06-10 09:31:02 +08:00
|
|
|
|
elt->next = new;
|
|
|
|
|
new = elt;
|
|
|
|
|
}
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
globfree (&gl);
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (old);
|
1992-02-14 18:52:22 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case GLOB_NOSPACE:
|
1999-07-28 14:23:37 +08:00
|
|
|
|
fatal (NILF, _("virtual memory exhausted"));
|
1992-02-14 18:52:22 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
old->next = new;
|
|
|
|
|
new = old;
|
1992-10-10 02:00:37 +08:00
|
|
|
|
break;
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
2007-03-20 11:02:26 +08:00
|
|
|
|
|
|
|
|
|
#ifndef NO_ARCHIVES
|
|
|
|
|
if (arname)
|
|
|
|
|
free (arname);
|
|
|
|
|
#endif
|
1992-02-14 18:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new;
|
|
|
|
|
}
|