xref: /original-bsd/usr.bin/make/make.h (revision 7a9bd2f5)
1 /*
2  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
3  * Copyright (c) 1988, 1989 by Adam de Boor
4  * Copyright (c) 1989 by Berkeley Softworks
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Adam de Boor.
9  *
10  * Redistribution and use in source and binary forms are permitted
11  * provided that the above copyright notice and this paragraph are
12  * duplicated in all such forms and that any documentation,
13  * advertising materials, and other materials related to such
14  * distribution and use acknowledge that the software was developed
15  * by the University of California, Berkeley.  The name of the
16  * University may not be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21  *
22  *	@(#)make.h	5.11 (Berkeley) 05/15/90
23  */
24 
25 /*-
26  * make.h --
27  *	The global definitions for pmake
28  */
29 
30 #ifndef _MAKE_H_
31 #define _MAKE_H_
32 
33 #include <sys/types.h>
34 #include <string.h>
35 #include <ctype.h>
36 #include "sprite.h"
37 #include "lst.h"
38 #include "config.h"
39 
40 /*-
41  * The structure for an individual graph node. Each node has several
42  * pieces of data associated with it.
43  *	1) the name of the target it describes
44  *	2) the location of the target file in the file system.
45  *	3) the type of operator used to define its sources (qv. parse.c)
46  *	4) whether it is involved in this invocation of make
47  *	5) whether the target has been remade
48  *	6) whether any of its children has been remade
49  *	7) the number of its children that are, as yet, unmade
50  *	8) its modification time
51  *	9) the modification time of its youngest child (qv. make.c)
52  *	10) a list of nodes for which this is a source
53  *	11) a list of nodes on which this depends
54  *	12) a list of nodes that depend on this, as gleaned from the
55  *	    transformation rules.
56  *	13) a list of nodes of the same name created by the :: operator
57  *	14) a list of nodes that must be made (if they're made) before
58  *	    this node can be, but that do no enter into the datedness of
59  *	    this node.
60  *	15) a list of nodes that must be made (if they're made) after
61  *	    this node is, but that do not depend on this node, in the
62  *	    normal sense.
63  *	16) a Lst of ``local'' variables that are specific to this target
64  *	   and this target only (qv. var.c [$@ $< $?, etc.])
65  *	17) a Lst of strings that are commands to be given to a shell
66  *	   to create this target.
67  */
68 typedef struct GNode {
69     char            *name;     	/* The target's name */
70     char    	    *path;     	/* The full pathname of the file */
71     int             type;      	/* Its type (see the OP flags, below) */
72 
73     Boolean         make;      	/* TRUE if this target needs to be remade */
74     enum {
75 	UNMADE, BEINGMADE, MADE, UPTODATE, ERROR, ABORTED,
76 	CYCLE, ENDCYCLE,
77     }	    	    made;    	/* Set to reflect the state of processing
78 				 * on this node:
79 				 *  UNMADE - Not examined yet
80 				 *  BEINGMADE - Target is already being made.
81 				 *  	Indicates a cycle in the graph. (compat
82 				 *  	mode only)
83 				 *  MADE - Was out-of-date and has been made
84 				 *  UPTODATE - Was already up-to-date
85 				 *  ERROR - An error occured while it was being
86 				 *  	made (used only in compat mode)
87 				 *  ABORTED - The target was aborted due to
88 				 *  	an error making an inferior (compat).
89 				 *  CYCLE - Marked as potentially being part of
90 				 *  	a graph cycle. If we come back to a
91 				 *  	node marked this way, it is printed
92 				 *  	and 'made' is changed to ENDCYCLE.
93 				 *  ENDCYCLE - the cycle has been completely
94 				 *  	printed. Go back and unmark all its
95 				 *  	members.
96 				 */
97     Boolean 	    childMade; 	/* TRUE if one of this target's children was
98 				 * made */
99     int             unmade;    	/* The number of unmade children */
100 
101     int             mtime;     	/* Its modification time */
102     int        	    cmtime;    	/* The modification time of its youngest
103 				 * child */
104 
105     Lst     	    iParents;  	/* Links to parents for which this is an
106 				 * implied source, if any */
107     Lst	    	    cohorts;  	/* Other nodes for the :: operator */
108     Lst             parents;   	/* Nodes that depend on this one */
109     Lst             children;  	/* Nodes on which this one depends */
110     Lst	    	    successors;	/* Nodes that must be made after this one */
111     Lst	    	    preds;  	/* Nodes that must be made before this one */
112 
113     Lst             context;   	/* The local variables */
114     Lst             commands;  	/* Creation commands */
115 
116     struct _Suff    *suffix;	/* Suffix for the node (determined by
117 				 * Suff_FindDeps and opaque to everyone
118 				 * but the Suff module) */
119 } GNode;
120 
121 /*
122  * Manifest constants
123  */
124 #define NILGNODE	((GNode *) NIL)
125 
126 /*
127  * The OP_ constants are used when parsing a dependency line as a way of
128  * communicating to other parts of the program the way in which a target
129  * should be made. These constants are bitwise-OR'ed together and
130  * placed in the 'type' field of each node. Any node that has
131  * a 'type' field which satisfies the OP_NOP function was never never on
132  * the lefthand side of an operator, though it may have been on the
133  * righthand side...
134  */
135 #define OP_DEPENDS	0x00000001  /* Execution of commands depends on
136 				     * kids (:) */
137 #define OP_FORCE	0x00000002  /* Always execute commands (!) */
138 #define OP_DOUBLEDEP	0x00000004  /* Execution of commands depends on kids
139 				     * per line (::) */
140 #define OP_OPMASK	(OP_DEPENDS|OP_FORCE|OP_DOUBLEDEP)
141 
142 #define OP_OPTIONAL	0x00000008  /* Don't care if the target doesn't
143 				     * exist and can't be created */
144 #define OP_USE		0x00000010  /* Use associated commands for parents */
145 #define OP_EXEC	  	0x00000020  /* Target is never out of date, but always
146 				     * execute commands anyway. Its time
147 				     * doesn't matter, so it has none...sort
148 				     * of */
149 #define OP_IGNORE	0x00000040  /* Ignore errors when creating the node */
150 #define OP_PRECIOUS	0x00000080  /* Don't remove the target when
151 				     * interrupted */
152 #define OP_SILENT	0x00000100  /* Don't echo commands when executed */
153 #define OP_MAKE		0x00000200  /* Target is a recurrsive make so its
154 				     * commands should always be executed when
155 				     * it is out of date, regardless of the
156 				     * state of the -n or -t flags */
157 #define OP_JOIN 	0x00000400  /* Target is out-of-date only if any of its
158 				     * children was out-of-date */
159 #define OP_INVISIBLE	0x00004000  /* The node is invisible to its parents.
160 				     * I.e. it doesn't show up in the parents's
161 				     * local variables. */
162 #define OP_NOTMAIN	0x00008000  /* The node is exempt from normal 'main
163 				     * target' processing in parse.c */
164 /* Attributes applied by PMake */
165 #define OP_TRANSFORM	0x80000000  /* The node is a transformation rule */
166 #define OP_MEMBER 	0x40000000  /* Target is a member of an archive */
167 #define OP_LIB	  	0x20000000  /* Target is a library */
168 #define OP_ARCHV  	0x10000000  /* Target is an archive construct */
169 #define OP_HAS_COMMANDS	0x08000000  /* Target has all the commands it should.
170 				     * Used when parsing to catch multiple
171 				     * commands for a target */
172 #define OP_SAVE_CMDS	0x04000000  /* Saving commands on .END (Compat) */
173 #define OP_DEPS_FOUND	0x02000000  /* Already processed by Suff_FindDeps */
174 
175 /*
176  * OP_NOP will return TRUE if the node with the given type was not the
177  * object of a dependency operator
178  */
179 #define OP_NOP(t)	(((t) & OP_OPMASK) == 0x00000000)
180 
181 /*
182  * The TARG_ constants are used when calling the Targ_FindNode and
183  * Targ_FindList functions in targ.c. They simply tell the functions what to
184  * do if the desired node(s) is (are) not found. If the TARG_CREATE constant
185  * is given, a new, empty node will be created for the target, placed in the
186  * table of all targets and its address returned. If TARG_NOCREATE is given,
187  * a NIL pointer will be returned.
188  */
189 #define TARG_CREATE	0x01	  /* create node if not found */
190 #define TARG_NOCREATE	0x00	  /* don't create it */
191 
192 /*
193  * There are several places where expandable buffers are used (parse.c and
194  * var.c). This constant is merely the starting point for those buffers. If
195  * lines tend to be much shorter than this, it would be best to reduce BSIZE.
196  * If longer, it should be increased. Reducing it will cause more copying to
197  * be done for longer lines, but will save space for shorter ones. In any
198  * case, it ought to be a power of two simply because most storage allocation
199  * schemes allocate in powers of two.
200  */
201 #define BSIZE		256	/* starting size for expandable buffers */
202 
203 /*
204  * These constants are all used by the Str_Concat function to decide how the
205  * final string should look. If STR_ADDSPACE is given, a space will be
206  * placed between the two strings. If STR_ADDSLASH is given, a '/' will
207  * be used instead of a space. If neither is given, no intervening characters
208  * will be placed between the two strings in the final output. If the
209  * STR_DOFREE bit is set, the two input strings will be freed before
210  * Str_Concat returns.
211  */
212 #define STR_ADDSPACE	0x01	/* add a space when Str_Concat'ing */
213 #define STR_DOFREE	0x02	/* free source strings after concatenation */
214 #define STR_ADDSLASH	0x04	/* add a slash when Str_Concat'ing */
215 
216 /*
217  * Error levels for parsing. PARSE_FATAL means the process cannot continue
218  * once the makefile has been parsed. PARSE_WARNING means it can. Passed
219  * as the first argument to Parse_Error.
220  */
221 #define PARSE_WARNING	2
222 #define PARSE_FATAL	1
223 
224 /*
225  * Values returned by Cond_Eval.
226  */
227 #define COND_PARSE	0   	/* Parse the next lines */
228 #define COND_SKIP 	1   	/* Skip the next lines */
229 #define COND_INVALID	2   	/* Not a conditional statement */
230 
231 /*
232  * Definitions for the "local" variables. Used only for clarity.
233  */
234 #define TARGET	  	  "@" 	/* Target of dependency */
235 #define OODATE	  	  "?" 	/* All out-of-date sources */
236 #define ALLSRC	  	  ">" 	/* All sources */
237 #define IMPSRC	  	  "<" 	/* Source implied by transformation */
238 #define PREFIX	  	  "*" 	/* Common prefix */
239 #define ARCHIVE	  	  "!" 	/* Archive in "archive(member)" syntax */
240 #define MEMBER	  	  "%" 	/* Member in "archive(member)" syntax */
241 
242 #define FTARGET           "@F"  /* file part of TARGET */
243 #define DTARGET           "@D"  /* directory part of TARGET */
244 #define FIMPSRC           "<F"  /* file part of IMPSRC */
245 #define DIMPSRC           "<D"  /* directory part of IMPSRC */
246 #define FPREFIX           "*F"  /* file part of PREFIX */
247 #define DPREFIX           "*D"  /* directory part of PREFIX */
248 
249 /*
250  * Global Variables
251  */
252 extern Lst  	create;	    	/* The list of target names specified on the
253 				 * command line. used to resolve #if
254 				 * make(...) statements */
255 extern Lst     	dirSearchPath; 	/* The list of directories to search when
256 				 * looking for targets */
257 
258 extern Boolean	ignoreErrors;  	/* True if should ignore all errors */
259 extern Boolean  beSilent;    	/* True if should print no commands */
260 extern Boolean  noExecute;    	/* True if should execute nothing */
261 extern Boolean  allPrecious;   	/* True if every target is precious */
262 extern Boolean  keepgoing;    	/* True if should continue on unaffected
263 				 * portions of the graph when have an error
264 				 * in one portion */
265 extern Boolean 	touchFlag;    	/* TRUE if targets should just be 'touched'
266 				 * if out of date. Set by the -t flag */
267 extern Boolean  usePipes;    	/* TRUE if should capture the output of
268 				 * subshells by means of pipes. Otherwise it
269 				 * is routed to temporary files from which it
270 				 * is retrieved when the shell exits */
271 extern Boolean 	queryFlag;    	/* TRUE if we aren't supposed to really make
272 				 * anything, just see if the targets are out-
273 				 * of-date */
274 
275 extern Boolean	checkEnvFirst;	/* TRUE if environment should be searched for
276 				 * variables before the global context */
277 
278 extern GNode    *DEFAULT;    	/* .DEFAULT rule */
279 
280 extern GNode    *VAR_GLOBAL;   	/* Variables defined in a global context, e.g
281 				 * in the Makefile itself */
282 extern GNode    *VAR_CMD;    	/* Variables defined on the command line */
283 extern char    	var_Error[];   	/* Value returned by Var_Parse when an error
284 				 * is encountered. It actually points to
285 				 * an empty string, so naive callers needn't
286 				 * worry about it. */
287 
288 extern time_t 	now;	    	/* The time at the start of this whole
289 				 * process */
290 
291 extern Boolean	oldVars;    	/* Do old-style variable substitution */
292 
293 /*
294  * debug control:
295  *	There is one bit per module.  It is up to the module what debug
296  *	information to print.
297  */
298 extern int debug;
299 #define	DEBUG_ARCH	0x0001
300 #define	DEBUG_COND	0x0002
301 #define	DEBUG_DIR	0x0004
302 #define	DEBUG_GRAPH1	0x0008
303 #define	DEBUG_GRAPH2	0x0010
304 #define	DEBUG_JOB	0x0020
305 #define	DEBUG_MAKE	0x0040
306 #define	DEBUG_SUFF	0x0080
307 #define	DEBUG_TARG	0x0100
308 #define	DEBUG_VAR	0x0200
309 
310 #ifdef __STDC__
311 #define CONCAT(a,b)	a##b
312 #else
313 #define I(a)	  	a
314 #define CONCAT(a,b)	I(a)b
315 #endif /* __STDC__ */
316 
317 #define	DEBUG(module)	(debug & CONCAT(DEBUG_,module))
318 
319 /*
320  * Since there are so many, all functions that return non-integer values are
321  * extracted by means of a sed script or two and stuck in the file "nonints.h"
322  */
323 #include "nonints.h"
324 
325 #endif _MAKE_H_
326