3
static Node *applyrules(char *, char *);
4
static void togo(Node *);
5
static int vacuous(Node *);
6
static Node *newnode(char *);
7
static void trace(char *, Arc *);
8
static void cyclechk(Node *);
9
static void ambiguous(Node *);
10
static void attribute(Node *);
19
node = applyrules(target, cnt);
22
node->flags |= PROBABLE; /* make sure it doesn't get deleted */
30
applyrules(char *target, char *cnt)
37
char stem[NAMEBLOCK], buf[NAMEBLOCK];
38
Resub rmatch[NREGEXP];
40
/* print("applyrules(%lux='%s')\n", target, target);*//**/
41
sym = symlook(target, S_NODE, 0);
43
return (Node *)(sym->value);
44
target = strdup(target);
45
node = newnode(target);
48
sym = symlook(target, S_TARGET, 0);
49
memset((char*)rmatch, 0, sizeof(rmatch));
50
for(r = sym? (Rule *)(sym->value):0; r; r = r->chain){
51
if(r->attr&META) continue;
52
if(strcmp(target, r->target)) continue;
53
if((!r->recipe || !*r->recipe) && (!r->tail || !r->tail->s || !*r->tail->s)) continue; /* no effect; ignore */
54
if(cnt[r->rule] >= nreps) continue;
56
node->flags |= PROBABLE;
59
* node->flags |= VIRTUAL;
61
* node->flags |= NORECIPE;
63
* node->flags |= DELETE;
65
if(!r->tail || !r->tail->s || !*r->tail->s) {
66
a->next = newarc((Node *)0, r, "", rmatch);
69
for(w = r->tail; w; w = w->next){
70
a->next = newarc(applyrules(w->s, cnt), r, "", rmatch);
76
for(r = metarules; r; r = r->next){
77
if((!r->recipe || !*r->recipe) && (!r->tail || !r->tail->s || !*r->tail->s)) continue; /* no effect; ignore */
78
if ((r->attr&NOVIRT) && a != &head && (a->r->attr&VIR))
83
memset((char*)rmatch, 0, sizeof(rmatch));
84
if(regexec(r->pat, node->name, rmatch, NREGEXP) == 0)
87
if(!match(node->name, r->target, stem, r->shellt)) continue;
89
if(cnt[r->rule] >= nreps) continue;
93
* node->flags |= VIRTUAL;
95
* node->flags |= NORECIPE;
97
* node->flags |= DELETE;
100
if(!r->tail || !r->tail->s || !*r->tail->s) {
101
a->next = newarc((Node *)0, r, stem, rmatch);
104
for(w = r->tail; w; w = w->next){
106
regsub(w->s, buf, sizeof buf, rmatch, NREGEXP);
108
subst(stem, w->s, buf);
109
a->next = newarc(applyrules(buf, cnt), r, stem, rmatch);
114
a->next = node->prereqs;
115
node->prereqs = head.next;
124
/* delete them now */
126
for(a = node->prereqs; a; la = a, a = a->next)
128
if(a == node->prereqs)
129
node->prereqs = a->next;
131
la->next = a->next, a = la;
139
int vac = !(node->flags&PROBABLE);
141
if(node->flags&READY)
142
return(node->flags&VACUOUS);
143
node->flags |= READY;
144
for(a = node->prereqs; a; a = a->next)
145
if(a->n && vacuous(a->n) && (a->r->attr&META))
149
/* if a rule generated arcs that DON'T go; no others from that rule go */
150
for(a = node->prereqs; a; a = a->next)
151
if((a->flag&TOGO) == 0)
152
for(la = node->prereqs; la; la = la->next)
153
if((la->flag&TOGO) && (la->r == a->r)){
158
node->flags |= VACUOUS;
167
node = (Node *)Malloc(sizeof(Node));
168
symlook(name, S_NODE, (void *)node);
170
node->time = timeof(name, 0);
172
node->flags = node->time? PROBABLE : 0;
178
dumpn(char *s, Node *n)
183
snprint(buf, sizeof buf, "%s ", (*s == ' ')? s:"");
184
Bprint(&bout, "%s%s@%ld: time=%ld flags=0x%x next=%ld\n",
185
s, n->name, n, n->time, n->flags, n->next);
186
for(a = n->prereqs; a; a = a->next)
191
trace(char *s, Arc *a)
193
fprint(2, "\t%s", s);
195
fprint(2, " <-(%s:%d)- %s", a->r->file, a->r->line,
196
a->n? a->n->name:"");
198
for(a = a->n->prereqs; a; a = a->next)
199
if(*a->r->recipe) break;
211
if((n->flags&CYCLE) && n->prereqs){
212
fprint(2, "mk: cycle in graph detected at target %s\n", n->name);
216
for(a = n->prereqs; a; a = a->next)
231
for(a = n->prereqs; a; a = a->next){
234
if(*a->r->recipe == 0) continue;
238
if(r->recipe != a->r->recipe){
239
if((r->attr&META) && !(a->r->attr&META)){
242
} else if(!(r->attr&META) && (a->r->attr&META)){
247
if(r->recipe != a->r->recipe){
249
fprint(2, "mk: ambiguous recipes for %s:\n", n->name);
267
for(a = n->prereqs; a; a = a->next){
271
n->flags |= NORECIPE;