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);
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? sym->u.ptr: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)) continue;
89 if(cnt[r->rule] >= nreps) continue;
93 * node->flags |= VIRTUAL;
95 * node->flags |= NORECIPE;
97 * node->flags |= DELETE;
99 if(!r->tail || !r->tail->s || !*r->tail->s) {
100 a->next = newarc((Node *)0, r, stem, rmatch);
103 for(w = r->tail; w; w = w->next){
105 regsub(w->s, buf, sizeof(buf), rmatch, NREGEXP);
107 subst(stem, w->s, buf, sizeof(buf));
108 a->next = newarc(applyrules(buf, cnt), r, stem, rmatch);
113 a->next = node->prereqs;
114 node->prereqs = head.next;
123 /* delete them now */
125 for(a = node->prereqs; a; la = a, a = a->next)
127 if(a == node->prereqs)
128 node->prereqs = a->next;
130 la->next = a->next, a = la;
138 int vac = !(node->flags&PROBABLE);
140 if(node->flags&READY)
141 return(node->flags&VACUOUS);
142 node->flags |= READY;
143 for(a = node->prereqs; a; a = a->next)
144 if(a->n && vacuous(a->n) && (a->r->attr&META))
148 /* if a rule generated arcs that DON'T go; no others from that rule go */
149 for(a = node->prereqs; a; a = a->next)
150 if((a->flag&TOGO) == 0)
151 for(la = node->prereqs; la; la = la->next)
152 if((la->flag&TOGO) && (la->r == a->r)){
157 node->flags |= VACUOUS;
166 node = (Node *)Malloc(sizeof(Node));
167 symlook(name, S_NODE, (void *)node);
169 node->time = timeof(name, 0);
171 node->flags = node->time? PROBABLE : 0;
177 dumpn(char *s, Node *n)
182 Bprint(&bout, "%s%s@%p: time=%ld flags=0x%x next=%p\n",
183 s, n->name, n, n->time, n->flags, n->next);
184 for(a = n->prereqs; a; a = a->next){
185 snprint(buf, sizeof buf, "%s ", (*s == ' ')? s:"");
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;