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