1992-01-11 11:37:36 +00:00
|
|
|
|
/* Pattern and suffix rule internals for GNU Make.
|
2013-05-17 05:46:11 +00:00
|
|
|
|
Copyright (C) 1988-2013 Free Software Foundation, Inc.
|
1992-01-11 11:37:36 +00:00
|
|
|
|
This file is part of GNU Make.
|
|
|
|
|
|
2006-02-11 19:02:21 +00: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-04 19:35:15 +00:00
|
|
|
|
Foundation; either version 3 of the License, or (at your option) any later
|
|
|
|
|
version.
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
2006-02-11 19:02:21 +00: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-01-11 11:37:36 +00:00
|
|
|
|
|
2006-02-11 19:02:21 +00:00
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
2007-07-04 19:35:15 +00:00
|
|
|
|
this program. If not, see <http://www.gnu.org/licenses/>. */
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
2013-01-20 16:01:01 +00:00
|
|
|
|
#include "makeint.h"
|
2007-03-20 03:02:26 +00:00
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
1992-01-11 11:37:36 +00:00
|
|
|
|
#include "dep.h"
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#include "filedef.h"
|
|
|
|
|
#include "job.h"
|
|
|
|
|
#include "commands.h"
|
1992-01-11 11:37:36 +00:00
|
|
|
|
#include "variable.h"
|
|
|
|
|
#include "rule.h"
|
|
|
|
|
|
2006-04-07 01:43:44 +00:00
|
|
|
|
static void freerule (struct rule *rule, struct rule *lastrule);
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
/* Chain of all pattern rules. */
|
|
|
|
|
|
|
|
|
|
struct rule *pattern_rules;
|
|
|
|
|
|
|
|
|
|
/* Pointer to last rule in the chain, so we can add onto the end. */
|
|
|
|
|
|
|
|
|
|
struct rule *last_pattern_rule;
|
|
|
|
|
|
|
|
|
|
/* Number of rules in the chain. */
|
|
|
|
|
|
|
|
|
|
unsigned int num_pattern_rules;
|
|
|
|
|
|
1993-06-30 22:40:50 +00:00
|
|
|
|
/* Maximum number of target patterns of any pattern rule. */
|
|
|
|
|
|
|
|
|
|
unsigned int max_pattern_targets;
|
|
|
|
|
|
1992-01-11 11:37:36 +00:00
|
|
|
|
/* Maximum number of dependencies of any pattern rule. */
|
|
|
|
|
|
|
|
|
|
unsigned int max_pattern_deps;
|
|
|
|
|
|
|
|
|
|
/* Maximum length of the name of a dependencies of any pattern rule. */
|
|
|
|
|
|
|
|
|
|
unsigned int max_pattern_dep_length;
|
|
|
|
|
|
|
|
|
|
/* Pointer to structure for the file .SUFFIXES
|
|
|
|
|
whose dependencies are the suffixes to be searched. */
|
|
|
|
|
|
|
|
|
|
struct file *suffix_file;
|
|
|
|
|
|
|
|
|
|
/* Maximum length of a suffix. */
|
|
|
|
|
|
|
|
|
|
unsigned int maxsuffix;
|
|
|
|
|
|
|
|
|
|
/* Compute the maximum dependency length and maximum number of
|
|
|
|
|
dependencies of all implicit rules. Also sets the subdir
|
|
|
|
|
flag for a rule when appropriate, possibly removing the rule
|
|
|
|
|
completely when appropriate. */
|
|
|
|
|
|
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
count_implicit_rule_limits (void)
|
1992-01-11 11:37:36 +00:00
|
|
|
|
{
|
|
|
|
|
char *name;
|
2004-02-24 13:50:19 +00:00
|
|
|
|
int namelen;
|
2013-04-16 05:47:05 +00:00
|
|
|
|
struct rule *rule;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
1993-06-30 22:40:50 +00:00
|
|
|
|
num_pattern_rules = max_pattern_targets = max_pattern_deps = 0;
|
|
|
|
|
max_pattern_dep_length = 0;
|
|
|
|
|
|
1992-01-11 11:37:36 +00:00
|
|
|
|
name = 0;
|
|
|
|
|
namelen = 0;
|
1992-04-26 19:19:06 +00:00
|
|
|
|
rule = pattern_rules;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
while (rule != 0)
|
|
|
|
|
{
|
|
|
|
|
unsigned int ndeps = 0;
|
2007-03-20 03:02:26 +00:00
|
|
|
|
struct dep *dep;
|
1992-04-26 19:19:06 +00:00
|
|
|
|
struct rule *next = rule->next;
|
1993-06-30 22:40:50 +00:00
|
|
|
|
|
1992-01-11 11:37:36 +00:00
|
|
|
|
++num_pattern_rules;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
if (rule->num > max_pattern_targets)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
max_pattern_targets = rule->num;
|
1993-06-30 22:40:50 +00:00
|
|
|
|
|
1992-01-11 11:37:36 +00:00
|
|
|
|
for (dep = rule->deps; dep != 0; dep = dep->next)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
{
|
2009-09-24 02:41:44 +00:00
|
|
|
|
const char *dname = dep_name (dep);
|
|
|
|
|
unsigned int len = strlen (dname);
|
1996-03-20 14:57:41 +00:00
|
|
|
|
|
|
|
|
|
#ifdef VMS
|
2009-09-24 02:41:44 +00:00
|
|
|
|
const char *p = strrchr (dname, ']');
|
2007-03-20 03:02:26 +00:00
|
|
|
|
const char *p2;
|
2000-01-22 05:43:03 +00:00
|
|
|
|
if (p == 0)
|
2009-09-24 02:41:44 +00:00
|
|
|
|
p = strrchr (dname, ':');
|
|
|
|
|
p2 = p != 0 ? strchr (dname, '%') : 0;
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#else
|
2009-09-24 02:41:44 +00:00
|
|
|
|
const char *p = strrchr (dname, '/');
|
|
|
|
|
const char *p2 = p != 0 ? strchr (dname, '%') : 0;
|
2000-01-22 05:43:03 +00:00
|
|
|
|
#endif
|
2009-09-24 02:41:44 +00:00
|
|
|
|
ndeps++;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
2013-05-17 06:29:46 +00:00
|
|
|
|
if (len > max_pattern_dep_length)
|
|
|
|
|
max_pattern_dep_length = len;
|
|
|
|
|
|
|
|
|
|
if (p != 0 && p2 > p)
|
|
|
|
|
{
|
|
|
|
|
/* There is a slash before the % in the dep name.
|
|
|
|
|
Extract the directory name. */
|
|
|
|
|
if (p == dname)
|
|
|
|
|
++p;
|
|
|
|
|
if (p - dname > namelen)
|
|
|
|
|
{
|
|
|
|
|
namelen = p - dname;
|
|
|
|
|
name = xrealloc (name, namelen + 1);
|
|
|
|
|
}
|
|
|
|
|
memcpy (name, dname, p - dname);
|
|
|
|
|
name[p - dname] = '\0';
|
|
|
|
|
|
|
|
|
|
/* In the deps of an implicit rule the 'changed' flag
|
|
|
|
|
actually indicates that the dependency is in a
|
|
|
|
|
nonexistent subdirectory. */
|
|
|
|
|
|
|
|
|
|
dep->changed = !dir_file_exists_p (name, "");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
/* This dependency does not reside in a subdirectory. */
|
|
|
|
|
dep->changed = 0;
|
|
|
|
|
}
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
if (ndeps > max_pattern_deps)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
max_pattern_deps = ndeps;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
1992-04-26 19:19:06 +00:00
|
|
|
|
rule = next;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
}
|
1998-07-30 20:54:47 +00:00
|
|
|
|
|
1992-01-11 11:37:36 +00:00
|
|
|
|
if (name != 0)
|
|
|
|
|
free (name);
|
|
|
|
|
}
|
|
|
|
|
|
1993-05-24 23:02:13 +00:00
|
|
|
|
/* Create a pattern rule from a suffix rule.
|
|
|
|
|
TARGET is the target suffix; SOURCE is the source suffix.
|
|
|
|
|
CMDS are the commands.
|
2012-03-04 00:24:20 +00:00
|
|
|
|
If TARGET is nil, it means the target pattern should be '(%.o)'.
|
1993-05-24 23:02:13 +00:00
|
|
|
|
If SOURCE is nil, it means there should be no deps. */
|
|
|
|
|
|
|
|
|
|
static void
|
2007-03-20 03:02:26 +00:00
|
|
|
|
convert_suffix_rule (const char *target, const char *source,
|
|
|
|
|
struct commands *cmds)
|
1993-05-24 23:02:13 +00:00
|
|
|
|
{
|
2007-03-20 03:02:26 +00:00
|
|
|
|
const char **names, **percents;
|
1993-05-24 23:02:13 +00:00
|
|
|
|
struct dep *deps;
|
2007-03-20 03:02:26 +00:00
|
|
|
|
|
|
|
|
|
names = xmalloc (sizeof (const char *));
|
|
|
|
|
percents = xmalloc (sizeof (const char *));
|
1993-05-24 23:02:13 +00:00
|
|
|
|
|
|
|
|
|
if (target == 0)
|
1993-10-21 20:48:08 +00:00
|
|
|
|
{
|
2012-03-04 00:24:20 +00:00
|
|
|
|
/* Special case: TARGET being nil means we are defining a '.X.a' suffix
|
|
|
|
|
rule; the target pattern is always '(%.o)'. */
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#ifdef VMS
|
2007-03-20 03:02:26 +00:00
|
|
|
|
*names = strcache_add_len ("(%.obj)", 7);
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#else
|
2007-03-20 03:02:26 +00:00
|
|
|
|
*names = strcache_add_len ("(%.o)", 5);
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#endif
|
2007-03-20 03:02:26 +00:00
|
|
|
|
*percents = *names + 1;
|
1993-10-21 20:48:08 +00:00
|
|
|
|
}
|
1993-05-24 23:02:13 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Construct the target name. */
|
2007-03-20 03:02:26 +00:00
|
|
|
|
unsigned int len = strlen (target);
|
|
|
|
|
char *p = alloca (1 + len + 1);
|
|
|
|
|
p[0] = '%';
|
|
|
|
|
memcpy (p + 1, target, len + 1);
|
|
|
|
|
*names = strcache_add_len (p, len + 1);
|
|
|
|
|
*percents = *names;
|
1993-05-24 23:02:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (source == 0)
|
|
|
|
|
deps = 0;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Construct the dependency name. */
|
2007-03-20 03:02:26 +00:00
|
|
|
|
unsigned int len = strlen (source);
|
|
|
|
|
char *p = alloca (1 + len + 1);
|
|
|
|
|
p[0] = '%';
|
|
|
|
|
memcpy (p + 1, source, len + 1);
|
2006-03-17 14:24:20 +00:00
|
|
|
|
deps = alloc_dep ();
|
2007-03-20 03:02:26 +00:00
|
|
|
|
deps->name = strcache_add_len (p, len + 1);
|
1993-05-24 23:02:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
create_pattern_rule (names, percents, 1, 0, deps, cmds, 0);
|
1993-05-24 23:02:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
1992-01-11 11:37:36 +00:00
|
|
|
|
/* Convert old-style suffix rules to pattern rules.
|
2007-03-20 03:02:26 +00:00
|
|
|
|
All rules for the suffixes on the .SUFFIXES list are converted and added to
|
|
|
|
|
the chain of pattern rules. */
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
convert_to_pattern (void)
|
1992-01-11 11:37:36 +00:00
|
|
|
|
{
|
2007-03-20 03:02:26 +00:00
|
|
|
|
struct dep *d, *d2;
|
|
|
|
|
char *rulename;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
/* We will compute every potential suffix rule (.x.y) from the list of
|
|
|
|
|
suffixes in the .SUFFIXES target's dependencies and see if it exists.
|
|
|
|
|
First find the longest of the suffixes. */
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
maxsuffix = 0;
|
|
|
|
|
for (d = suffix_file->deps; d != 0; d = d->next)
|
|
|
|
|
{
|
2007-03-20 03:02:26 +00:00
|
|
|
|
unsigned int l = strlen (dep_name (d));
|
|
|
|
|
if (l > maxsuffix)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
maxsuffix = l;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
/* Space to construct the suffix rule target name. */
|
2006-04-09 22:09:24 +00:00
|
|
|
|
rulename = alloca ((maxsuffix * 2) + 1);
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
for (d = suffix_file->deps; d != 0; d = d->next)
|
|
|
|
|
{
|
2007-03-20 03:02:26 +00:00
|
|
|
|
unsigned int slen;
|
|
|
|
|
|
1992-01-11 11:37:36 +00:00
|
|
|
|
/* Make a rule that is just the suffix, with no deps or commands.
|
2013-05-17 06:29:46 +00:00
|
|
|
|
This rule exists solely to disqualify match-anything rules. */
|
2006-04-09 22:09:24 +00:00
|
|
|
|
convert_suffix_rule (dep_name (d), 0, 0);
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
if (d->file->cmds != 0)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
/* Record a pattern for this suffix's null-suffix rule. */
|
|
|
|
|
convert_suffix_rule ("", dep_name (d), d->file->cmds);
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
/* Add every other suffix to this one and see if it exists as a
|
|
|
|
|
two-suffix rule. */
|
1993-05-24 23:02:13 +00:00
|
|
|
|
slen = strlen (dep_name (d));
|
2006-04-09 22:09:24 +00:00
|
|
|
|
memcpy (rulename, dep_name (d), slen);
|
2007-03-20 03:02:26 +00:00
|
|
|
|
|
1992-01-11 11:37:36 +00:00
|
|
|
|
for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
{
|
2007-03-20 03:02:26 +00:00
|
|
|
|
struct file *f;
|
|
|
|
|
unsigned int s2len;
|
|
|
|
|
|
2013-05-17 06:29:46 +00:00
|
|
|
|
s2len = strlen (dep_name (d2));
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
/* Can't build something from itself. */
|
2013-05-17 06:29:46 +00:00
|
|
|
|
if (slen == s2len && streq (dep_name (d), dep_name (d2)))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
memcpy (rulename + slen, dep_name (d2), s2len + 1);
|
|
|
|
|
f = lookup_file (rulename);
|
|
|
|
|
if (f == 0 || f->cmds == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (s2len == 2 && rulename[slen] == '.' && rulename[slen + 1] == 'a')
|
|
|
|
|
/* A suffix rule '.X.a:' generates the pattern rule '(%.o): %.X'.
|
|
|
|
|
It also generates a normal '%.a: %.X' rule below. */
|
|
|
|
|
convert_suffix_rule (NULL, /* Indicates '(%.o)'. */
|
|
|
|
|
dep_name (d),
|
|
|
|
|
f->cmds);
|
|
|
|
|
|
|
|
|
|
/* The suffix rule '.X.Y:' is converted
|
|
|
|
|
to the pattern rule '%.Y: %.X'. */
|
|
|
|
|
convert_suffix_rule (dep_name (d2), dep_name (d), f->cmds);
|
|
|
|
|
}
|
1992-01-11 11:37:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
/* Install the pattern rule RULE (whose fields have been filled in) at the end
|
|
|
|
|
of the list (so that any rules previously defined will take precedence).
|
|
|
|
|
If this rule duplicates a previous one (identical target and dependencies),
|
|
|
|
|
the old one is replaced if OVERRIDE is nonzero, otherwise this new one is
|
|
|
|
|
thrown out. When an old rule is replaced, the new one is put at the end of
|
|
|
|
|
the list. Return nonzero if RULE is used; zero if not. */
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
static int
|
2002-10-14 21:54:04 +00:00
|
|
|
|
new_pattern_rule (struct rule *rule, int override)
|
1992-01-11 11:37:36 +00:00
|
|
|
|
{
|
2007-03-20 03:02:26 +00:00
|
|
|
|
struct rule *r, *lastrule;
|
|
|
|
|
unsigned int i, j;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
rule->in_use = 0;
|
|
|
|
|
rule->terminal = 0;
|
|
|
|
|
|
|
|
|
|
rule->next = 0;
|
|
|
|
|
|
|
|
|
|
/* Search for an identical rule. */
|
1992-05-26 05:26:26 +00:00
|
|
|
|
lastrule = 0;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
for (r = pattern_rules; r != 0; lastrule = r, r = r->next)
|
2007-03-20 03:02:26 +00:00
|
|
|
|
for (i = 0; i < rule->num; ++i)
|
1992-03-24 09:50:46 +00:00
|
|
|
|
{
|
2013-05-17 06:29:46 +00:00
|
|
|
|
for (j = 0; j < r->num; ++j)
|
|
|
|
|
if (!streq (rule->targets[i], r->targets[j]))
|
|
|
|
|
break;
|
2007-03-20 03:02:26 +00:00
|
|
|
|
/* If all the targets matched... */
|
2013-05-17 06:29:46 +00:00
|
|
|
|
if (j == r->num)
|
|
|
|
|
{
|
|
|
|
|
struct dep *d, *d2;
|
|
|
|
|
for (d = rule->deps, d2 = r->deps;
|
|
|
|
|
d != 0 && d2 != 0; d = d->next, d2 = d2->next)
|
|
|
|
|
if (!streq (dep_name (d), dep_name (d2)))
|
|
|
|
|
break;
|
|
|
|
|
if (d == 0 && d2 == 0)
|
|
|
|
|
{
|
|
|
|
|
/* All the dependencies matched. */
|
|
|
|
|
if (override)
|
|
|
|
|
{
|
|
|
|
|
/* Remove the old rule. */
|
|
|
|
|
freerule (r, lastrule);
|
|
|
|
|
/* Install the new one. */
|
|
|
|
|
if (pattern_rules == 0)
|
|
|
|
|
pattern_rules = rule;
|
|
|
|
|
else
|
|
|
|
|
last_pattern_rule->next = rule;
|
|
|
|
|
last_pattern_rule = rule;
|
|
|
|
|
|
|
|
|
|
/* We got one. Stop looking. */
|
|
|
|
|
goto matched;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* The old rule stays intact. Destroy the new one. */
|
|
|
|
|
freerule (rule, (struct rule *) 0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1992-03-24 09:50:46 +00:00
|
|
|
|
}
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
matched:;
|
|
|
|
|
|
|
|
|
|
if (r == 0)
|
|
|
|
|
{
|
|
|
|
|
/* There was no rule to replace. */
|
|
|
|
|
if (pattern_rules == 0)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
pattern_rules = rule;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
else
|
2013-05-17 06:29:46 +00:00
|
|
|
|
last_pattern_rule->next = rule;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
last_pattern_rule = rule;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Install an implicit pattern rule based on the three text strings
|
|
|
|
|
in the structure P points to. These strings come from one of
|
|
|
|
|
the arrays of default implicit pattern rules.
|
2012-03-04 00:24:20 +00:00
|
|
|
|
TERMINAL specifies what the 'terminal' field of the rule should be. */
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
install_pattern_rule (struct pspec *p, int terminal)
|
1992-01-11 11:37:36 +00:00
|
|
|
|
{
|
2007-03-20 03:02:26 +00:00
|
|
|
|
struct rule *r;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
char *ptr;
|
|
|
|
|
|
2006-04-09 22:09:24 +00:00
|
|
|
|
r = xmalloc (sizeof (struct rule));
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
r->num = 1;
|
|
|
|
|
r->targets = xmalloc (sizeof (const char *));
|
|
|
|
|
r->suffixes = xmalloc (sizeof (const char *));
|
|
|
|
|
r->lens = xmalloc (sizeof (unsigned int));
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
r->lens[0] = strlen (p->target);
|
2007-03-20 03:02:26 +00:00
|
|
|
|
r->targets[0] = p->target;
|
|
|
|
|
r->suffixes[0] = find_percent_cached (&r->targets[0]);
|
|
|
|
|
assert (r->suffixes[0] != NULL);
|
|
|
|
|
++r->suffixes[0];
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
ptr = p->dep;
|
2009-09-24 02:41:44 +00:00
|
|
|
|
r->deps = PARSE_FILE_SEQ (&ptr, struct dep, '\0', NULL, 0);
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
if (new_pattern_rule (r, 0))
|
|
|
|
|
{
|
|
|
|
|
r->terminal = terminal;
|
2006-04-09 22:09:24 +00:00
|
|
|
|
r->cmds = xmalloc (sizeof (struct commands));
|
1998-10-03 05:39:55 +00:00
|
|
|
|
r->cmds->fileinfo.filenm = 0;
|
|
|
|
|
r->cmds->fileinfo.lineno = 0;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
/* These will all be string literals, but we malloc space for them
|
2013-05-17 06:29:46 +00:00
|
|
|
|
anyway because somebody might want to free them later. */
|
1999-07-21 05:53:23 +00:00
|
|
|
|
r->cmds->commands = xstrdup (p->commands);
|
1992-01-11 11:37:36 +00:00
|
|
|
|
r->cmds->command_lines = 0;
|
2010-11-06 21:56:23 +00:00
|
|
|
|
r->cmds->recipe_prefix = RECIPEPREFIX_DEFAULT;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Free all the storage used in RULE and take it out of the
|
|
|
|
|
pattern_rules chain. LASTRULE is the rule whose next pointer
|
|
|
|
|
points to RULE. */
|
|
|
|
|
|
|
|
|
|
static void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
freerule (struct rule *rule, struct rule *lastrule)
|
1992-01-11 11:37:36 +00:00
|
|
|
|
{
|
|
|
|
|
struct rule *next = rule->next;
|
|
|
|
|
|
2009-09-27 02:15:36 +00:00
|
|
|
|
free_dep_chain (rule->deps);
|
1999-07-20 22:34:41 +00:00
|
|
|
|
|
2010-07-19 07:10:53 +00:00
|
|
|
|
/* MSVC erroneously warns without a cast here. */
|
|
|
|
|
free ((void *)rule->targets);
|
|
|
|
|
free ((void *)rule->suffixes);
|
2006-04-09 22:09:24 +00:00
|
|
|
|
free (rule->lens);
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
/* We can't free the storage for the commands because there
|
|
|
|
|
are ways that they could be in more than one place:
|
|
|
|
|
* If the commands came from a suffix rule, they could also be in
|
2012-03-04 00:24:20 +00:00
|
|
|
|
the 'struct file's for other suffix rules or plain targets given
|
1992-01-11 11:37:36 +00:00
|
|
|
|
on the same makefile line.
|
|
|
|
|
* If two suffixes that together make a two-suffix rule were each
|
|
|
|
|
given twice in the .SUFFIXES list, and in the proper order, two
|
|
|
|
|
identical pattern rules would be created and the second one would
|
2012-03-04 00:24:20 +00:00
|
|
|
|
be discarded here, but both would contain the same 'struct commands'
|
|
|
|
|
pointer from the 'struct file' for the suffix rule. */
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
2006-04-09 22:09:24 +00:00
|
|
|
|
free (rule);
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
if (pattern_rules == rule)
|
1992-04-26 19:19:06 +00:00
|
|
|
|
if (lastrule != 0)
|
1992-01-11 11:37:36 +00:00
|
|
|
|
abort ();
|
|
|
|
|
else
|
|
|
|
|
pattern_rules = next;
|
1992-04-29 00:44:29 +00:00
|
|
|
|
else if (lastrule != 0)
|
1992-01-11 11:37:36 +00:00
|
|
|
|
lastrule->next = next;
|
|
|
|
|
if (last_pattern_rule == rule)
|
|
|
|
|
last_pattern_rule = lastrule;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
/* Create a new pattern rule with the targets in the nil-terminated array
|
|
|
|
|
TARGETS. TARGET_PERCENTS is an array of pointers to the % in each element
|
|
|
|
|
of TARGETS. N is the number of items in the array (not counting the nil
|
|
|
|
|
element). The new rule has dependencies DEPS and commands from COMMANDS.
|
1992-01-11 11:37:36 +00:00
|
|
|
|
It is a terminal rule if TERMINAL is nonzero. This rule overrides
|
|
|
|
|
identical rules with different commands if OVERRIDE is nonzero.
|
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
The storage for TARGETS and its elements and TARGET_PERCENTS is used and
|
|
|
|
|
must not be freed until the rule is destroyed. */
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
void
|
2007-03-20 03:02:26 +00:00
|
|
|
|
create_pattern_rule (const char **targets, const char **target_percents,
|
|
|
|
|
unsigned int n, int terminal, struct dep *deps,
|
2002-10-14 21:54:04 +00:00
|
|
|
|
struct commands *commands, int override)
|
1992-01-11 11:37:36 +00:00
|
|
|
|
{
|
2007-03-20 03:02:26 +00:00
|
|
|
|
unsigned int i;
|
2006-04-09 22:09:24 +00:00
|
|
|
|
struct rule *r = xmalloc (sizeof (struct rule));
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
r->num = n;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
r->cmds = commands;
|
|
|
|
|
r->deps = deps;
|
|
|
|
|
r->targets = targets;
|
2007-03-20 03:02:26 +00:00
|
|
|
|
r->suffixes = target_percents;
|
|
|
|
|
r->lens = xmalloc (n * sizeof (unsigned int));
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
for (i = 0; i < n; ++i)
|
1992-01-11 11:37:36 +00:00
|
|
|
|
{
|
|
|
|
|
r->lens[i] = strlen (targets[i]);
|
2007-03-20 03:02:26 +00:00
|
|
|
|
assert (r->suffixes[i] != NULL);
|
|
|
|
|
++r->suffixes[i];
|
1992-01-11 11:37:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (new_pattern_rule (r, override))
|
|
|
|
|
r->terminal = terminal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print the data base of rules. */
|
|
|
|
|
|
2013-05-17 06:29:46 +00:00
|
|
|
|
static void /* Useful to call from gdb. */
|
2002-10-14 21:54:04 +00:00
|
|
|
|
print_rule (struct rule *r)
|
1993-10-18 11:04:04 +00:00
|
|
|
|
{
|
2007-03-20 03:02:26 +00:00
|
|
|
|
unsigned int i;
|
1993-10-18 11:04:04 +00:00
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
|
for (i = 0; i < r->num; ++i)
|
1993-10-18 11:04:04 +00:00
|
|
|
|
{
|
|
|
|
|
fputs (r->targets[i], stdout);
|
2007-03-20 03:02:26 +00:00
|
|
|
|
putchar ((i + 1 == r->num) ? ':' : ' ');
|
1993-10-18 11:04:04 +00:00
|
|
|
|
}
|
|
|
|
|
if (r->terminal)
|
|
|
|
|
putchar (':');
|
|
|
|
|
|
2009-09-24 02:41:44 +00:00
|
|
|
|
print_prereqs (r->deps);
|
1993-10-18 11:04:04 +00:00
|
|
|
|
|
|
|
|
|
if (r->cmds != 0)
|
|
|
|
|
print_commands (r->cmds);
|
|
|
|
|
}
|
|
|
|
|
|
1992-01-11 11:37:36 +00:00
|
|
|
|
void
|
2002-10-14 21:54:04 +00:00
|
|
|
|
print_rule_data_base (void)
|
1992-01-11 11:37:36 +00:00
|
|
|
|
{
|
2007-03-20 03:02:26 +00:00
|
|
|
|
unsigned int rules, terminal;
|
|
|
|
|
struct rule *r;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
2001-08-19 04:55:51 +00:00
|
|
|
|
puts (_("\n# Implicit Rules"));
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
1993-02-21 21:58:43 +00:00
|
|
|
|
rules = terminal = 0;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
for (r = pattern_rules; r != 0; r = r->next)
|
|
|
|
|
{
|
|
|
|
|
++rules;
|
|
|
|
|
|
|
|
|
|
putchar ('\n');
|
1993-10-18 11:04:04 +00:00
|
|
|
|
print_rule (r);
|
1992-01-11 11:37:36 +00:00
|
|
|
|
|
1993-10-18 11:04:04 +00:00
|
|
|
|
if (r->terminal)
|
2013-05-17 06:29:46 +00:00
|
|
|
|
++terminal;
|
1992-01-11 11:37:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rules == 0)
|
1999-07-28 06:23:37 +00:00
|
|
|
|
puts (_("\n# No implicit rules."));
|
1992-01-11 11:37:36 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
1999-07-28 06:23:37 +00:00
|
|
|
|
printf (_("\n# %u implicit rules, %u"), rules, terminal);
|
2013-05-17 06:29:46 +00:00
|
|
|
|
#ifndef NO_FLOAT
|
1992-01-11 11:37:36 +00:00
|
|
|
|
printf (" (%.1f%%)", (double) terminal / (double) rules * 100.0);
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-09 18:02:06 +00:00
|
|
|
|
#else
|
|
|
|
|
{
|
2013-05-17 06:29:46 +00:00
|
|
|
|
int f = (terminal * 1000 + 5) / rules;
|
|
|
|
|
printf (" (%d.%d%%)", f/10, f%10);
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-09 18:02:06 +00:00
|
|
|
|
}
|
1992-01-11 11:37:36 +00:00
|
|
|
|
#endif
|
1999-07-28 06:23:37 +00:00
|
|
|
|
puts (_(" terminal."));
|
1992-01-11 11:37:36 +00:00
|
|
|
|
}
|
1992-07-14 23:08:36 +00:00
|
|
|
|
|
|
|
|
|
if (num_pattern_rules != rules)
|
1998-10-13 20:59:08 +00:00
|
|
|
|
{
|
|
|
|
|
/* This can happen if a fatal error was detected while reading the
|
|
|
|
|
makefiles and thus count_implicit_rule_limits wasn't called yet. */
|
|
|
|
|
if (num_pattern_rules != 0)
|
2009-06-09 15:35:38 +00:00
|
|
|
|
fatal (NILF, _("BUG: num_pattern_rules is wrong! %u != %u"),
|
1998-10-13 20:59:08 +00:00
|
|
|
|
num_pattern_rules, rules);
|
|
|
|
|
}
|
1992-01-11 11:37:36 +00:00
|
|
|
|
}
|