static void convert_suffix_rule (char *target, char *source, struct commands *cmds) { char *targname, *targpercent, *depname; char **names, **percents; struct dep *deps; unsigned int len; if (target == 0) /* Special case: TARGET being nil means we are defining a `.X.a' suffix rule; the target pattern is always `(%.o)'. */ { #ifdef VMS targname = savestring ("(%.obj)", 7); #else targname = savestring ("(%.o)", 5); #endif targpercent = targname + 1; } else { /* Construct the target name. */ len = strlen (target); targname = xmalloc (1 + len + 1); targname[0] = '%'; bcopy (target, targname + 1, len + 1); targpercent = targname; } names = (char **) xmalloc (2 * sizeof (char *)); percents = (char **) alloca (2 * sizeof (char *)); names[0] = targname; percents[0] = targpercent; names[1] = percents[1] = 0; if (source == 0) deps = 0; else { /* Construct the dependency name. */ len = strlen (source); depname = xmalloc (1 + len + 1); depname[0] = '%'; bcopy (source, depname + 1, len + 1); deps = (struct dep *) xmalloc (sizeof (struct dep)); deps->next = 0; deps->name = depname; deps->ignore_mtime = 0; deps->need_2nd_expansion = 0; } create_pattern_rule (names, percents, 0, deps, cmds, 0); }
static void convert_suffix_rule (const char *target, const char *source, struct commands *cmds) { const char **names, **percents; struct dep *deps; names = xmalloc (sizeof (const char *)); percents = xmalloc (sizeof (const char *)); if (target == 0) { /* Special case: TARGET being nil means we are defining a '.X.a' suffix rule; the target pattern is always '(%.o)'. */ #ifdef VMS *names = strcache_add_len ("(%.obj)", 7); #else *names = strcache_add_len ("(%.o)", 5); #endif *percents = *names + 1; } else { /* Construct the target name. */ 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; } if (source == 0) deps = 0; else { /* Construct the dependency name. */ unsigned int len = strlen (source); char *p = alloca (1 + len + 1); p[0] = '%'; memcpy (p + 1, source, len + 1); deps = alloc_dep (); deps->name = strcache_add_len (p, len + 1); } create_pattern_rule (names, percents, 1, 0, deps, cmds, 0); }
void convert_to_pattern () { register struct dep *d, *d2, *newd; register struct file *f; register char *rulename; register unsigned int slen, s2len; register char *name, **names; /* Compute maximum length of all the suffixes. */ maxsuffix = 0; for (d = suffix_file->deps; d != 0; d = d->next) { register unsigned int namelen = strlen (dep_name (d)); if (namelen > maxsuffix) maxsuffix = namelen; } rulename = (char *) alloca ((maxsuffix * 2) + 1); for (d = suffix_file->deps; d != 0; d = d->next) { /* Make a rule that is just the suffix, with no deps or commands. This rule exists solely to disqualify match-anything rules. */ slen = strlen (dep_name (d)); name = (char *) xmalloc (1 + slen + 1); name[0] = '%'; bcopy (dep_name (d), name + 1, slen + 1); names = (char **) xmalloc (2 * sizeof (char *)); names[0] = name; names[1] = 0; create_pattern_rule (names, (char **) 0, 0, (struct dep *) 0, (struct commands *) 0, 0); f = d->file; if (f->cmds != 0) { /* Record a pattern for this suffix's null-suffix rule. */ newd = (struct dep *) xmalloc (sizeof (struct dep)); /* Construct this again rather than using the contents of NAME (above), since that may have been freed by create_pattern_rule. */ newd->name = (char *) xmalloc (1 + slen + 1); newd->name[0] = '%'; bcopy (dep_name (d), newd->name + 1, slen + 1); newd->next = 0; names = (char **) xmalloc (2 * sizeof (char *)); names[0] = savestring ("%", 1); names[1] = 0; create_pattern_rule (names, (char **) 0, 0, newd, f->cmds, 0); } /* Record a pattern for each of this suffix's two-suffix rules. */ bcopy (dep_name (d), rulename, slen); for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next) { s2len = strlen (dep_name (d2)); if (slen == s2len && streq (dep_name (d), dep_name (d2))) continue; bcopy (dep_name (d2), rulename + slen, s2len + 1); f = lookup_file (rulename); if (f == 0 || f->cmds == 0) continue; if (s2len == 2 && rulename[slen] == '.' && rulename[slen + 1] == 'a') /* The suffix rule `.X.a:' is converted to the pattern rule `(%.o): %.X'. */ name = savestring ("(%.o)", 5); else { /* The suffix rule `.X.Y:' is converted to the pattern rule `%.Y: %.X'. */ name = (char *) xmalloc (1 + s2len + 1); name[0] = '%'; bcopy (dep_name (d2), name + 1, s2len + 1); } names = (char **) xmalloc (2 * sizeof (char *)); names[0] = name; names[1] = 0; newd = (struct dep *) xmalloc (sizeof (struct dep)); newd->next = 0; /* Construct this again (see comment above). */ newd->name = (char *) xmalloc (1 + slen + 1); newd->name[0] = '%'; bcopy (dep_name (d), newd->name + 1, slen + 1); create_pattern_rule (names, (char **) 0, 0, newd, f->cmds, 0); } } }