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