1 #include <u.h> 2 #include <libc.h> 3 #include <bio.h> 4 #include <regexp.h> 5 6 extern Biobuf bout; 7 8 typedef struct Bufblock 9 { 10 struct Bufblock *next; 11 char *start; 12 char *end; 13 char *current; 14 } Bufblock; 15 16 typedef struct Word 17 { 18 char *s; 19 struct Word *next; 20 } Word; 21 22 typedef struct Envy 23 { 24 char *name; 25 Word *values; 26 } Envy; 27 28 extern Envy *envy; 29 30 typedef struct Rule 31 { 32 char *target; /* one target */ 33 Word *tail; /* constituents of targets */ 34 char *recipe; /* do it ! */ 35 short attr; /* attributes */ 36 short line; /* source line */ 37 char *file; /* source file */ 38 Word *alltargets; /* all the targets */ 39 int rule; /* rule number */ 40 Reprog *pat; /* reg exp goo */ 41 char *prog; /* to use in out of date */ 42 struct Rule *chain; /* hashed per target */ 43 struct Rule *next; 44 } Rule; 45 46 extern Rule *rules, *metarules, *patrule; 47 48 /* Rule.attr */ 49 #define META 0x0001 50 #define UNUSED 0x0002 51 #define UPD 0x0004 52 #define QUIET 0x0008 53 #define VIR 0x0010 54 #define REGEXP 0x0020 55 #define NOREC 0x0040 56 #define DEL 0x0080 57 #define NOVIRT 0x0100 58 59 #define NREGEXP 10 60 61 typedef struct Arc 62 { 63 short flag; 64 struct Node *n; 65 Rule *r; 66 char *stem; 67 char *prog; 68 char *match[NREGEXP]; 69 struct Arc *next; 70 } Arc; 71 72 /* Arc.flag */ 73 #define TOGO 1 74 75 typedef struct Node 76 { 77 char *name; 78 ulong time; 79 ushort flags; 80 Arc *prereqs; 81 struct Node *next; /* list for a rule */ 82 } Node; 83 84 /* Node.flags */ 85 #define VIRTUAL 0x0001 86 #define CYCLE 0x0002 87 #define READY 0x0004 88 #define CANPRETEND 0x0008 89 #define PRETENDING 0x0010 90 #define NOTMADE 0x0020 91 #define BEINGMADE 0x0040 92 #define MADE 0x0080 93 #define MADESET(n,m) n->flags = (n->flags&~(NOTMADE|BEINGMADE|MADE))|(m) 94 #define PROBABLE 0x0100 95 #define VACUOUS 0x0200 96 #define NORECIPE 0x0400 97 #define DELETE 0x0800 98 #define NOMINUSE 0x1000 99 100 typedef struct Job 101 { 102 Rule *r; /* master rule for job */ 103 Node *n; /* list of node targets */ 104 char *stem; 105 char **match; 106 Word *p; /* prerequistes */ 107 Word *np; /* new prerequistes */ 108 Word *t; /* targets */ 109 Word *at; /* all targets */ 110 int nproc; /* slot number */ 111 struct Job *next; 112 } Job; 113 extern Job *jobs; 114 115 typedef struct Symtab 116 { 117 short space; 118 char *name; 119 union{ 120 void *ptr; 121 uintptr value; 122 } u; 123 struct Symtab *next; 124 } Symtab; 125 126 enum { 127 S_VAR, /* variable -> value */ 128 S_TARGET, /* target -> rule */ 129 S_TIME, /* file -> time */ 130 S_PID, /* pid -> products */ 131 S_NODE, /* target name -> node */ 132 S_AGG, /* aggregate -> time */ 133 S_BITCH, /* bitched about aggregate not there */ 134 S_NOEXPORT, /* var -> noexport */ 135 S_OVERRIDE, /* can't override */ 136 S_OUTOFDATE, /* n1\377n2 -> 2(outofdate) or 1(not outofdate) */ 137 S_MAKEFILE, /* target -> node */ 138 S_MAKEVAR, /* dumpable mk variable */ 139 S_EXPORTED, /* var -> current exported value */ 140 S_BULKED, /* we have bulked this dir */ 141 S_WESET, /* variable; we set in the mkfile */ 142 S_INTERNAL, /* an internal mk variable (e.g., stem, target) */ 143 }; 144 145 extern int debug; 146 extern int nflag, tflag, iflag, kflag, aflag, mflag; 147 extern int mkinline; 148 extern char *infile; 149 extern int nreps; 150 extern char *explain; 151 extern char *termchars; 152 extern char *shell; 153 extern char *shellname; 154 extern char *shflags; 155 extern int IWS; 156 157 #define SYNERR(l) (fprint(2, "mk: %s:%d: syntax error; ", infile, ((l)>=0)?(l):mkinline)) 158 #define RERR(r) (fprint(2, "mk: %s:%d: rule error; ", (r)->file, (r)->line)) 159 #define NAMEBLOCK 1000 160 #define BIGBLOCK 20000 161 162 #define SEP(c) (((c)==' ')||((c)=='\t')||((c)=='\n')) 163 #define WORDCHR(r) ((r) > ' ' && !utfrune("!\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~", (r))) 164 165 #define DEBUG(x) (debug&(x)) 166 #define D_PARSE 0x01 167 #define D_GRAPH 0x02 168 #define D_EXEC 0x04 169 170 #define LSEEK(f,o,p) seek(f,o,p) 171 172 #define PERCENT(ch) (((ch) == '%') || ((ch) == '&')) 173 174 #include "fns.h" 175