make.h revision 1.235 1 1.235 rillig /* $NetBSD: make.h,v 1.235 2020/12/18 18:17:45 rillig Exp $ */
2 1.6 christos
3 1.1 cgd /*
4 1.6 christos * Copyright (c) 1988, 1989, 1990, 1993
5 1.6 christos * The Regents of the University of California. All rights reserved.
6 1.47 agc *
7 1.47 agc * This code is derived from software contributed to Berkeley by
8 1.47 agc * Adam de Boor.
9 1.47 agc *
10 1.47 agc * Redistribution and use in source and binary forms, with or without
11 1.47 agc * modification, are permitted provided that the following conditions
12 1.47 agc * are met:
13 1.47 agc * 1. Redistributions of source code must retain the above copyright
14 1.47 agc * notice, this list of conditions and the following disclaimer.
15 1.47 agc * 2. Redistributions in binary form must reproduce the above copyright
16 1.47 agc * notice, this list of conditions and the following disclaimer in the
17 1.47 agc * documentation and/or other materials provided with the distribution.
18 1.47 agc * 3. Neither the name of the University nor the names of its contributors
19 1.47 agc * may be used to endorse or promote products derived from this software
20 1.47 agc * without specific prior written permission.
21 1.47 agc *
22 1.47 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.47 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.47 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.47 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.47 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.47 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.47 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.47 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.47 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.47 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.47 agc * SUCH DAMAGE.
33 1.47 agc *
34 1.47 agc * from: @(#)make.h 8.3 (Berkeley) 6/13/95
35 1.47 agc */
36 1.47 agc
37 1.47 agc /*
38 1.1 cgd * Copyright (c) 1989 by Berkeley Softworks
39 1.1 cgd * All rights reserved.
40 1.1 cgd *
41 1.1 cgd * This code is derived from software contributed to Berkeley by
42 1.1 cgd * Adam de Boor.
43 1.1 cgd *
44 1.1 cgd * Redistribution and use in source and binary forms, with or without
45 1.1 cgd * modification, are permitted provided that the following conditions
46 1.1 cgd * are met:
47 1.1 cgd * 1. Redistributions of source code must retain the above copyright
48 1.1 cgd * notice, this list of conditions and the following disclaimer.
49 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
50 1.1 cgd * notice, this list of conditions and the following disclaimer in the
51 1.1 cgd * documentation and/or other materials provided with the distribution.
52 1.1 cgd * 3. All advertising materials mentioning features or use of this software
53 1.1 cgd * must display the following acknowledgement:
54 1.1 cgd * This product includes software developed by the University of
55 1.1 cgd * California, Berkeley and its contributors.
56 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
57 1.1 cgd * may be used to endorse or promote products derived from this software
58 1.1 cgd * without specific prior written permission.
59 1.1 cgd *
60 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
61 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
64 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 1.1 cgd * SUCH DAMAGE.
71 1.1 cgd *
72 1.11 christos * from: @(#)make.h 8.3 (Berkeley) 6/13/95
73 1.1 cgd */
74 1.1 cgd
75 1.1 cgd /*-
76 1.1 cgd * make.h --
77 1.1 cgd * The global definitions for pmake
78 1.1 cgd */
79 1.1 cgd
80 1.116 rillig #ifndef MAKE_MAKE_H
81 1.116 rillig #define MAKE_MAKE_H
82 1.1 cgd
83 1.1 cgd #include <sys/types.h>
84 1.13 christos #include <sys/param.h>
85 1.135 rillig #include <sys/stat.h>
86 1.44 wiz
87 1.123 rillig #include <assert.h>
88 1.44 wiz #include <ctype.h>
89 1.97 christos #include <fcntl.h>
90 1.150 rillig #include <stdarg.h>
91 1.3 cgd #include <stdio.h>
92 1.44 wiz #include <stdlib.h>
93 1.1 cgd #include <string.h>
94 1.44 wiz #include <unistd.h>
95 1.12 christos
96 1.19 tv #ifdef BSD4_4
97 1.12 christos # include <sys/cdefs.h>
98 1.4 glass #endif
99 1.12 christos
100 1.97 christos #ifndef FD_CLOEXEC
101 1.97 christos #define FD_CLOEXEC 1
102 1.97 christos #endif
103 1.97 christos
104 1.52 yamt #if defined(__GNUC__)
105 1.230 rillig #define MAKE_GNUC_PREREQ(x, y) \
106 1.52 yamt ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \
107 1.52 yamt (__GNUC__ > (x)))
108 1.52 yamt #else /* defined(__GNUC__) */
109 1.230 rillig #define MAKE_GNUC_PREREQ(x, y) 0
110 1.52 yamt #endif /* defined(__GNUC__) */
111 1.52 yamt
112 1.89 joerg #if MAKE_GNUC_PREREQ(2, 7)
113 1.230 rillig #define MAKE_ATTR_UNUSED __attribute__((__unused__))
114 1.51 jmc #else
115 1.230 rillig #define MAKE_ATTR_UNUSED /* delete */
116 1.51 jmc #endif
117 1.89 joerg
118 1.89 joerg #if MAKE_GNUC_PREREQ(2, 5)
119 1.230 rillig #define MAKE_ATTR_DEAD __attribute__((__noreturn__))
120 1.89 joerg #elif defined(__GNUC__)
121 1.230 rillig #define MAKE_ATTR_DEAD __volatile
122 1.89 joerg #else
123 1.230 rillig #define MAKE_ATTR_DEAD /* delete */
124 1.51 jmc #endif
125 1.44 wiz
126 1.89 joerg #if MAKE_GNUC_PREREQ(2, 7)
127 1.89 joerg #define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg) \
128 1.89 joerg __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
129 1.89 joerg #else
130 1.89 joerg #define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg) /* delete */
131 1.87 joerg #endif
132 1.87 joerg
133 1.205 rillig #define MAKE_INLINE static inline MAKE_ATTR_UNUSED
134 1.205 rillig
135 1.127 rillig /*
136 1.137 rillig * A boolean type is defined as an integer, not an enum, for historic reasons.
137 1.137 rillig * The only allowed values are the constants TRUE and FALSE (1 and 0).
138 1.127 rillig */
139 1.235 rillig #if defined(USE_C99_BOOLEAN)
140 1.235 rillig #include <stdbool.h>
141 1.235 rillig typedef bool Boolean;
142 1.235 rillig #define FALSE false
143 1.235 rillig #define TRUE true
144 1.235 rillig #elif defined(USE_DOUBLE_BOOLEAN)
145 1.131 rillig /* During development, to find type mismatches in function declarations. */
146 1.130 rillig typedef double Boolean;
147 1.162 rillig #define TRUE 1.0
148 1.162 rillig #define FALSE 0.0
149 1.131 rillig #elif defined(USE_UCHAR_BOOLEAN)
150 1.131 rillig /* During development, to find code that depends on the exact value of TRUE or
151 1.131 rillig * that stores other values in Boolean variables. */
152 1.131 rillig typedef unsigned char Boolean;
153 1.131 rillig #define TRUE ((unsigned char)0xFF)
154 1.131 rillig #define FALSE ((unsigned char)0x00)
155 1.161 rillig #elif defined(USE_CHAR_BOOLEAN)
156 1.161 rillig /* During development, to find code that uses a boolean as array index, via
157 1.161 rillig * -Wchar-subscripts. */
158 1.161 rillig typedef char Boolean;
159 1.161 rillig #define TRUE ((char)-1)
160 1.161 rillig #define FALSE ((char)0x00)
161 1.137 rillig #elif defined(USE_ENUM_BOOLEAN)
162 1.159 rillig typedef enum Boolean { FALSE, TRUE } Boolean;
163 1.130 rillig #else
164 1.127 rillig typedef int Boolean;
165 1.127 rillig #ifndef TRUE
166 1.127 rillig #define TRUE 1
167 1.140 rillig #endif
168 1.127 rillig #ifndef FALSE
169 1.127 rillig #define FALSE 0
170 1.140 rillig #endif
171 1.162 rillig #endif
172 1.127 rillig
173 1.1 cgd #include "lst.h"
174 1.128 rillig #include "enum.h"
175 1.22 mycroft #include "hash.h"
176 1.1 cgd #include "config.h"
177 1.3 cgd #include "buf.h"
178 1.78 dsl #include "make_malloc.h"
179 1.1 cgd
180 1.216 rillig /*
181 1.216 rillig * The typical flow of states is:
182 1.216 rillig *
183 1.216 rillig * The direct successful path:
184 1.216 rillig * UNMADE -> BEINGMADE -> MADE.
185 1.216 rillig *
186 1.216 rillig * The direct error path:
187 1.216 rillig * UNMADE -> BEINGMADE -> ERROR.
188 1.216 rillig *
189 1.216 rillig * The successful path when dependencies need to be made first:
190 1.216 rillig * UNMADE -> DEFERRED -> REQUESTED -> BEINGMADE -> MADE.
191 1.216 rillig *
192 1.216 rillig * A node that has dependencies, and one of the dependencies cannot be made:
193 1.216 rillig * UNMADE -> DEFERRED -> ABORTED.
194 1.216 rillig *
195 1.216 rillig * A node that turns out to be up-to-date:
196 1.216 rillig * UNMADE -> BEINGMADE -> UPTODATE.
197 1.216 rillig */
198 1.181 rillig typedef enum GNodeMade {
199 1.219 rillig /* Not examined yet. */
200 1.219 rillig UNMADE,
201 1.219 rillig /* The node has been examined but is not yet ready since its
202 1.219 rillig * dependencies have to be made first. */
203 1.219 rillig DEFERRED,
204 1.219 rillig
205 1.219 rillig /* The node is on the toBeMade list. */
206 1.219 rillig REQUESTED,
207 1.219 rillig
208 1.219 rillig /* The node is already being made. Trying to build a node in this
209 1.219 rillig * state indicates a cycle in the graph. */
210 1.219 rillig BEINGMADE,
211 1.219 rillig
212 1.219 rillig /* Was out-of-date and has been made. */
213 1.219 rillig MADE,
214 1.219 rillig /* Was already up-to-date, does not need to be made. */
215 1.219 rillig UPTODATE,
216 1.219 rillig /* An error occurred while it was being made.
217 1.219 rillig * Used only in compat mode. */
218 1.219 rillig ERROR,
219 1.219 rillig /* The target was aborted due to an error making a dependency.
220 1.219 rillig * Used only in compat mode. */
221 1.219 rillig ABORTED
222 1.119 rillig } GNodeMade;
223 1.1 cgd
224 1.120 rillig /* The OP_ constants are used when parsing a dependency line as a way of
225 1.120 rillig * communicating to other parts of the program the way in which a target
226 1.120 rillig * should be made.
227 1.120 rillig *
228 1.163 rillig * Some of the OP_ constants can be combined, others cannot. */
229 1.159 rillig typedef enum GNodeType {
230 1.219 rillig OP_NONE = 0,
231 1.209 rillig
232 1.219 rillig /* The dependency operator ':' is the most common one. The commands
233 1.219 rillig * of this node are executed if any child is out-of-date. */
234 1.219 rillig OP_DEPENDS = 1 << 0,
235 1.219 rillig /* The dependency operator '!' always executes its commands, even if
236 1.219 rillig * its children are up-to-date. */
237 1.219 rillig OP_FORCE = 1 << 1,
238 1.219 rillig /* The dependency operator '::' behaves like ':', except that it
239 1.219 rillig * allows multiple dependency groups to be defined. Each of these
240 1.219 rillig * groups is executed on its own, independently from the others.
241 1.219 rillig * Each individual dependency group is called a cohort. */
242 1.219 rillig OP_DOUBLEDEP = 1 << 2,
243 1.219 rillig
244 1.219 rillig /* Matches the dependency operators ':', '!' and '::'. */
245 1.219 rillig OP_OPMASK = OP_DEPENDS | OP_FORCE | OP_DOUBLEDEP,
246 1.219 rillig
247 1.219 rillig /* Don't care if the target doesn't exist and can't be created. */
248 1.219 rillig OP_OPTIONAL = 1 << 3,
249 1.219 rillig /* Use associated commands for parents. */
250 1.219 rillig OP_USE = 1 << 4,
251 1.219 rillig /* Target is never out of date, but always execute commands anyway.
252 1.219 rillig * Its time doesn't matter, so it has none...sort of. */
253 1.219 rillig OP_EXEC = 1 << 5,
254 1.219 rillig /* Ignore non-zero exit status from shell commands when creating the
255 1.219 rillig * node. */
256 1.219 rillig OP_IGNORE = 1 << 6,
257 1.219 rillig /* Don't remove the target when interrupted. */
258 1.219 rillig OP_PRECIOUS = 1 << 7,
259 1.219 rillig /* Don't echo commands when executed. */
260 1.219 rillig OP_SILENT = 1 << 8,
261 1.219 rillig /* Target is a recursive make so its commands should always be
262 1.219 rillig * executed when it is out of date, regardless of the state of the
263 1.219 rillig * -n or -t flags. */
264 1.219 rillig OP_MAKE = 1 << 9,
265 1.219 rillig /* Target is out-of-date only if any of its children was out-of-date. */
266 1.219 rillig OP_JOIN = 1 << 10,
267 1.219 rillig /* Assume the children of the node have been already made. */
268 1.219 rillig OP_MADE = 1 << 11,
269 1.219 rillig /* Special .BEGIN, .END or .INTERRUPT. */
270 1.219 rillig OP_SPECIAL = 1 << 12,
271 1.219 rillig /* Like .USE, only prepend commands. */
272 1.219 rillig OP_USEBEFORE = 1 << 13,
273 1.219 rillig /* The node is invisible to its parents. I.e. it doesn't show up in
274 1.219 rillig * the parents' local variables (.IMPSRC, .ALLSRC). */
275 1.219 rillig OP_INVISIBLE = 1 << 14,
276 1.219 rillig /* The node does not become the main target, even if it is the first
277 1.219 rillig * target in the first makefile. */
278 1.219 rillig OP_NOTMAIN = 1 << 15,
279 1.219 rillig /* Not a file target; run always. */
280 1.219 rillig OP_PHONY = 1 << 16,
281 1.219 rillig /* Don't search for the file in the path. */
282 1.219 rillig OP_NOPATH = 1 << 17,
283 1.219 rillig /* In a dependency line "target: source1 .WAIT source2", source1 is
284 1.219 rillig * made first, including its children. Once that is finished,
285 1.219 rillig * source2 is made, including its children. The .WAIT keyword may
286 1.219 rillig * appear more than once in a single dependency declaration. */
287 1.219 rillig OP_WAIT = 1 << 18,
288 1.219 rillig /* .NOMETA do not create a .meta file */
289 1.219 rillig OP_NOMETA = 1 << 19,
290 1.219 rillig /* .META we _do_ want a .meta file */
291 1.219 rillig OP_META = 1 << 20,
292 1.219 rillig /* Do not compare commands in .meta file */
293 1.219 rillig OP_NOMETA_CMP = 1 << 21,
294 1.219 rillig /* Possibly a submake node */
295 1.219 rillig OP_SUBMAKE = 1 << 22,
296 1.219 rillig
297 1.219 rillig /* Attributes applied by PMake */
298 1.219 rillig
299 1.219 rillig /* The node is a transformation rule, such as ".c.o". */
300 1.219 rillig OP_TRANSFORM = 1 << 30,
301 1.219 rillig /* Target is a member of an archive */
302 1.219 rillig /* XXX: How does this differ from OP_ARCHV? */
303 1.219 rillig OP_MEMBER = 1 << 29,
304 1.219 rillig /* The node is a library,
305 1.219 rillig * its name has the form "-l<libname>" */
306 1.219 rillig OP_LIB = 1 << 28,
307 1.219 rillig /* The node is an archive member,
308 1.219 rillig * its name has the form "archive(member)" */
309 1.219 rillig /* XXX: How does this differ from OP_MEMBER? */
310 1.219 rillig OP_ARCHV = 1 << 27,
311 1.219 rillig /* Target has all the commands it should. Used when parsing to catch
312 1.219 rillig * multiple command groups for a target. Only applies to the
313 1.219 rillig * dependency operators ':' and '!', but not to '::'. */
314 1.219 rillig OP_HAS_COMMANDS = 1 << 26,
315 1.219 rillig /* The special command "..." has been seen. All further commands from
316 1.219 rillig * this node will be saved on the .END node instead, to be executed at
317 1.219 rillig * the very end. */
318 1.219 rillig OP_SAVE_CMDS = 1 << 25,
319 1.219 rillig /* Already processed by Suff_FindDeps, to find dependencies from
320 1.219 rillig * suffix transformation rules. */
321 1.219 rillig OP_DEPS_FOUND = 1 << 24,
322 1.219 rillig /* Node found while expanding .ALLSRC */
323 1.219 rillig OP_MARK = 1 << 23,
324 1.155 rillig
325 1.219 rillig OP_NOTARGET = OP_NOTMAIN | OP_USE | OP_EXEC | OP_TRANSFORM
326 1.120 rillig } GNodeType;
327 1.120 rillig
328 1.159 rillig typedef enum GNodeFlags {
329 1.231 rillig GNF_NONE = 0,
330 1.219 rillig /* this target needs to be (re)made */
331 1.219 rillig REMAKE = 0x0001,
332 1.219 rillig /* children of this target were made */
333 1.219 rillig CHILDMADE = 0x0002,
334 1.219 rillig /* children don't exist, and we pretend made */
335 1.219 rillig FORCE = 0x0004,
336 1.219 rillig /* Set by Make_ProcessWait() */
337 1.219 rillig DONE_WAIT = 0x0008,
338 1.219 rillig /* Build requested by .ORDER processing */
339 1.219 rillig DONE_ORDER = 0x0010,
340 1.219 rillig /* Node created from .depend */
341 1.219 rillig FROM_DEPEND = 0x0020,
342 1.219 rillig /* We do it once only */
343 1.219 rillig DONE_ALLSRC = 0x0040,
344 1.219 rillig /* Used by MakePrintStatus */
345 1.219 rillig CYCLE = 0x1000,
346 1.219 rillig /* Used by MakePrintStatus */
347 1.219 rillig DONECYCLE = 0x2000,
348 1.219 rillig /* Internal use only */
349 1.219 rillig INTERNAL = 0x4000
350 1.119 rillig } GNodeFlags;
351 1.1 cgd
352 1.143 rillig typedef struct List StringList;
353 1.143 rillig typedef struct ListNode StringListNode;
354 1.144 rillig
355 1.143 rillig typedef struct List GNodeList;
356 1.143 rillig typedef struct ListNode GNodeListNode;
357 1.143 rillig
358 1.144 rillig typedef struct List /* of CachedDir */ SearchPath;
359 1.144 rillig
360 1.119 rillig /* A graph node represents a target that can possibly be made, including its
361 1.119 rillig * relation to other targets and a lot of other details. */
362 1.119 rillig typedef struct GNode {
363 1.219 rillig /* The target's name, such as "clean" or "make.c" */
364 1.219 rillig char *name;
365 1.219 rillig /* The unexpanded name of a .USE node */
366 1.219 rillig char *uname;
367 1.219 rillig /* The full pathname of the file belonging to the target.
368 1.219 rillig * XXX: What about .PHONY targets? These don't have an associated
369 1.219 rillig * path. */
370 1.219 rillig char *path;
371 1.219 rillig
372 1.219 rillig /* The type of operator used to define the sources (see the OP flags
373 1.219 rillig * below).
374 1.219 rillig * XXX: This looks like a wild mixture of type and flags. */
375 1.219 rillig GNodeType type;
376 1.219 rillig GNodeFlags flags;
377 1.219 rillig
378 1.219 rillig /* The state of processing on this node */
379 1.219 rillig GNodeMade made;
380 1.219 rillig /* The number of unmade children */
381 1.219 rillig int unmade;
382 1.219 rillig
383 1.219 rillig /* The modification time; 0 means the node does not have a
384 1.219 rillig * corresponding file; see GNode_IsOODate. */
385 1.219 rillig time_t mtime;
386 1.219 rillig struct GNode *youngestChild;
387 1.219 rillig
388 1.219 rillig /* The GNodes for which this node is an implied source. May be empty.
389 1.219 rillig * For example, when there is an inference rule for .c.o, the node for
390 1.219 rillig * file.c has the node for file.o in this list. */
391 1.225 rillig GNodeList implicitParents;
392 1.219 rillig
393 1.219 rillig /* The nodes that depend on this one, or in other words, the nodes for
394 1.219 rillig * which this is a source. */
395 1.222 rillig GNodeList parents;
396 1.219 rillig /* The nodes on which this one depends. */
397 1.222 rillig GNodeList children;
398 1.219 rillig
399 1.219 rillig /* .ORDER nodes we need made. The nodes that must be made (if they're
400 1.219 rillig * made) before this node can be made, but that do not enter into the
401 1.219 rillig * datedness of this node. */
402 1.223 rillig GNodeList order_pred;
403 1.219 rillig /* .ORDER nodes who need us. The nodes that must be made (if they're
404 1.219 rillig * made at all) after this node is made, but that do not depend on
405 1.219 rillig * this node, in the normal sense. */
406 1.223 rillig GNodeList order_succ;
407 1.219 rillig
408 1.219 rillig /* Other nodes of the same name, for the '::' dependency operator. */
409 1.224 rillig GNodeList cohorts;
410 1.219 rillig /* The "#n" suffix for this cohort, or "" for other nodes */
411 1.219 rillig char cohort_num[8];
412 1.219 rillig /* The number of unmade instances on the cohorts list */
413 1.219 rillig int unmade_cohorts;
414 1.219 rillig /* Pointer to the first instance of a '::' node; only set when on a
415 1.219 rillig * cohorts list */
416 1.219 rillig struct GNode *centurion;
417 1.219 rillig
418 1.219 rillig /* Last time (sequence number) we tried to make this node */
419 1.219 rillig unsigned int checked_seqno;
420 1.219 rillig
421 1.219 rillig /* The "local" variables that are specific to this target and this
422 1.219 rillig * target only, such as $@, $<, $?.
423 1.219 rillig *
424 1.219 rillig * Also used for the global variable scopes VAR_GLOBAL, VAR_CMDLINE,
425 1.219 rillig * VAR_INTERNAL, which contain variables with arbitrary names. */
426 1.219 rillig HashTable /* of Var pointer */ vars;
427 1.219 rillig
428 1.219 rillig /* The commands to be given to a shell to create this target. */
429 1.221 rillig StringList commands;
430 1.219 rillig
431 1.219 rillig /* Suffix for the node (determined by Suff_FindDeps and opaque to
432 1.219 rillig * everyone but the Suff module) */
433 1.219 rillig struct Suffix *suffix;
434 1.219 rillig
435 1.219 rillig /* Filename where the GNode got defined */
436 1.219 rillig /* XXX: What is the lifetime of this string? */
437 1.219 rillig const char *fname;
438 1.219 rillig /* Line number where the GNode got defined */
439 1.219 rillig int lineno;
440 1.1 cgd } GNode;
441 1.1 cgd
442 1.188 rillig /* Error levels for diagnostics during parsing. */
443 1.167 rillig typedef enum ParseErrorLevel {
444 1.219 rillig /* Exit when the current top-level makefile has been parsed
445 1.219 rillig * completely. */
446 1.219 rillig PARSE_FATAL = 1,
447 1.219 rillig /* Print "warning"; may be upgraded to fatal by the -w option. */
448 1.219 rillig PARSE_WARNING,
449 1.219 rillig /* Informational, mainly used during development of makefiles. */
450 1.219 rillig PARSE_INFO
451 1.167 rillig } ParseErrorLevel;
452 1.1 cgd
453 1.1 cgd /*
454 1.141 rillig * Values returned by Cond_EvalLine and Cond_EvalCondition.
455 1.1 cgd */
456 1.159 rillig typedef enum CondEvalResult {
457 1.219 rillig COND_PARSE, /* Parse the next lines */
458 1.219 rillig COND_SKIP, /* Skip the next lines */
459 1.219 rillig COND_INVALID /* Not a conditional statement */
460 1.113 rillig } CondEvalResult;
461 1.1 cgd
462 1.190 rillig /* Names of the variables that are "local" to a specific target. */
463 1.219 rillig #define TARGET "@" /* Target of dependency */
464 1.219 rillig #define OODATE "?" /* All out-of-date sources */
465 1.219 rillig #define ALLSRC ">" /* All sources */
466 1.219 rillig #define IMPSRC "<" /* Source implied by transformation */
467 1.219 rillig #define PREFIX "*" /* Common prefix */
468 1.219 rillig #define ARCHIVE "!" /* Archive in "archive(member)" syntax */
469 1.219 rillig #define MEMBER "%" /* Member in "archive(member)" syntax */
470 1.148 rillig
471 1.1 cgd /*
472 1.11 christos * Global Variables
473 1.1 cgd */
474 1.1 cgd
475 1.190 rillig /* True if every target is precious */
476 1.190 rillig extern Boolean allPrecious;
477 1.190 rillig /* True if failed targets should be deleted */
478 1.190 rillig extern Boolean deleteOnError;
479 1.190 rillig /* TRUE while processing .depend */
480 1.190 rillig extern Boolean doing_depend;
481 1.190 rillig /* .DEFAULT rule */
482 1.207 rillig extern GNode *defaultNode;
483 1.190 rillig
484 1.190 rillig /* Variables defined internally by make which should not override those set
485 1.190 rillig * by makefiles. */
486 1.190 rillig extern GNode *VAR_INTERNAL;
487 1.190 rillig /* Variables defined in a global context, e.g in the Makefile itself. */
488 1.190 rillig extern GNode *VAR_GLOBAL;
489 1.190 rillig /* Variables defined on the command line. */
490 1.190 rillig extern GNode *VAR_CMDLINE;
491 1.190 rillig
492 1.190 rillig /* Value returned by Var_Parse when an error is encountered. It actually
493 1.190 rillig * points to an empty string, so naive callers needn't worry about it. */
494 1.190 rillig extern char var_Error[];
495 1.190 rillig
496 1.190 rillig /* The time at the start of this whole process */
497 1.190 rillig extern time_t now;
498 1.1 cgd
499 1.182 rillig /*
500 1.183 rillig * If FALSE (the default behavior), undefined subexpressions in a variable
501 1.183 rillig * expression are discarded. If TRUE (only during variable assignments using
502 1.202 rillig * the ':=' assignment operator, no matter how deeply nested), they are
503 1.183 rillig * preserved and possibly expanded later when the variable from the
504 1.183 rillig * subexpression has been defined.
505 1.180 rillig *
506 1.182 rillig * Example for a ':=' assignment:
507 1.182 rillig * CFLAGS = $(.INCLUDES)
508 1.182 rillig * CFLAGS := -I.. $(CFLAGS)
509 1.182 rillig * # If .INCLUDES (an undocumented special variable, by the way) is
510 1.182 rillig * # still undefined, the updated CFLAGS becomes "-I.. $(.INCLUDES)".
511 1.182 rillig */
512 1.183 rillig extern Boolean preserveUndefined;
513 1.9 christos
514 1.190 rillig /* The list of directories to search when looking for targets (set by the
515 1.190 rillig * special target .PATH). */
516 1.229 rillig extern SearchPath dirSearchPath;
517 1.186 rillig /* Used for .include "...". */
518 1.186 rillig extern SearchPath *parseIncPath;
519 1.186 rillig /* Used for .include <...>, for the built-in sys.mk and makefiles from the
520 1.186 rillig * command line arguments. */
521 1.186 rillig extern SearchPath *sysIncPath;
522 1.186 rillig /* The default for sysIncPath. */
523 1.186 rillig extern SearchPath *defSysIncPath;
524 1.32 christos
525 1.191 rillig /* Startup directory */
526 1.191 rillig extern char curdir[];
527 1.191 rillig /* The basename of the program name, suffixed with [n] for sub-makes. */
528 1.234 rillig extern const char *progname;
529 1.191 rillig /* Name of the .depend makefile */
530 1.191 rillig extern char *makeDependfile;
531 1.187 rillig /* If we replaced environ, this will be non-NULL. */
532 1.187 rillig extern char **savedEnv;
533 1.30 sommerfe
534 1.190 rillig extern int makelevel;
535 1.111 rillig
536 1.82 sjg /*
537 1.82 sjg * We cannot vfork() in a child of vfork().
538 1.82 sjg * Most systems do not enforce this but some do.
539 1.82 sjg */
540 1.82 sjg #define vFork() ((getpid() == myPid) ? vfork() : fork())
541 1.190 rillig extern pid_t myPid;
542 1.82 sjg
543 1.219 rillig #define MAKEFLAGS ".MAKEFLAGS"
544 1.219 rillig #define MAKEOVERRIDES ".MAKEOVERRIDES"
545 1.219 rillig /* prefix when printing the target of a job */
546 1.219 rillig #define MAKE_JOB_PREFIX ".MAKE.JOB.PREFIX"
547 1.219 rillig #define MAKE_EXPORTED ".MAKE.EXPORTED" /* exported variables */
548 1.219 rillig #define MAKE_MAKEFILES ".MAKE.MAKEFILES" /* all loaded makefiles */
549 1.219 rillig #define MAKE_LEVEL ".MAKE.LEVEL" /* recursion level */
550 1.185 rillig #define MAKE_MAKEFILE_PREFERENCE ".MAKE.MAKEFILE_PREFERENCE"
551 1.215 rillig #define MAKE_DEPENDFILE ".MAKE.DEPENDFILE" /* .depend */
552 1.80 sjg #define MAKE_MODE ".MAKE.MODE"
553 1.91 sjg #ifndef MAKE_LEVEL_ENV
554 1.91 sjg # define MAKE_LEVEL_ENV "MAKELEVEL"
555 1.91 sjg #endif
556 1.1 cgd
557 1.170 rillig typedef enum DebugFlags {
558 1.219 rillig DEBUG_NONE = 0,
559 1.219 rillig DEBUG_ARCH = 1 << 0,
560 1.219 rillig DEBUG_COND = 1 << 1,
561 1.219 rillig DEBUG_CWD = 1 << 2,
562 1.219 rillig DEBUG_DIR = 1 << 3,
563 1.219 rillig DEBUG_ERROR = 1 << 4,
564 1.219 rillig DEBUG_FOR = 1 << 5,
565 1.219 rillig DEBUG_GRAPH1 = 1 << 6,
566 1.219 rillig DEBUG_GRAPH2 = 1 << 7,
567 1.219 rillig DEBUG_GRAPH3 = 1 << 8,
568 1.219 rillig DEBUG_HASH = 1 << 9,
569 1.219 rillig DEBUG_JOB = 1 << 10,
570 1.219 rillig DEBUG_LOUD = 1 << 11,
571 1.219 rillig DEBUG_MAKE = 1 << 12,
572 1.219 rillig DEBUG_META = 1 << 13,
573 1.219 rillig DEBUG_PARSE = 1 << 14,
574 1.219 rillig DEBUG_SCRIPT = 1 << 15,
575 1.219 rillig DEBUG_SHELL = 1 << 16,
576 1.219 rillig DEBUG_SUFF = 1 << 17,
577 1.219 rillig DEBUG_TARG = 1 << 18,
578 1.219 rillig DEBUG_VAR = 1 << 19,
579 1.219 rillig DEBUG_ALL = (1 << 20) - 1
580 1.170 rillig } DebugFlags;
581 1.170 rillig
582 1.219 rillig #define CONCAT(a, b) a##b
583 1.1 cgd
584 1.219 rillig #define DEBUG(module) (opts.debug & CONCAT(DEBUG_,module))
585 1.1 cgd
586 1.151 rillig void debug_printf(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
587 1.150 rillig
588 1.232 rillig #define DEBUG_IMPL(module, args) \
589 1.232 rillig do { \
590 1.232 rillig if (DEBUG(module)) \
591 1.232 rillig debug_printf args; \
592 1.232 rillig } while (0)
593 1.232 rillig
594 1.149 rillig #define DEBUG0(module, text) \
595 1.232 rillig DEBUG_IMPL(module, ("%s", text))
596 1.149 rillig #define DEBUG1(module, fmt, arg1) \
597 1.232 rillig DEBUG_IMPL(module, (fmt, arg1))
598 1.149 rillig #define DEBUG2(module, fmt, arg1, arg2) \
599 1.232 rillig DEBUG_IMPL(module, (fmt, arg1, arg2))
600 1.149 rillig #define DEBUG3(module, fmt, arg1, arg2, arg3) \
601 1.232 rillig DEBUG_IMPL(module, (fmt, arg1, arg2, arg3))
602 1.149 rillig #define DEBUG4(module, fmt, arg1, arg2, arg3, arg4) \
603 1.232 rillig DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4))
604 1.149 rillig #define DEBUG5(module, fmt, arg1, arg2, arg3, arg4, arg5) \
605 1.232 rillig DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4, arg5))
606 1.149 rillig
607 1.173 rillig typedef enum PrintVarsMode {
608 1.219 rillig PVM_NONE,
609 1.219 rillig PVM_UNEXPANDED,
610 1.219 rillig PVM_EXPANDED
611 1.173 rillig } PrintVarsMode;
612 1.173 rillig
613 1.173 rillig /* Command line options */
614 1.173 rillig typedef struct CmdOpts {
615 1.219 rillig /* -B: whether we are make compatible */
616 1.219 rillig Boolean compatMake;
617 1.173 rillig
618 1.219 rillig /* -d: debug control: There is one bit per module. It is up to the
619 1.219 rillig * module what debug information to print. */
620 1.219 rillig DebugFlags debug;
621 1.173 rillig
622 1.219 rillig /* -df: debug output is written here - default stderr */
623 1.219 rillig FILE *debug_file;
624 1.173 rillig
625 1.219 rillig /* -dL: lint mode
626 1.219 rillig *
627 1.219 rillig * Runs make in strict mode, with additional checks and better error
628 1.219 rillig * handling. */
629 1.219 rillig Boolean lint;
630 1.204 rillig
631 1.219 rillig /* -dV: for the -V option, print unexpanded variable values */
632 1.219 rillig Boolean debugVflag;
633 1.174 rillig
634 1.219 rillig /* -e: check environment variables before global variables */
635 1.219 rillig Boolean checkEnvFirst;
636 1.173 rillig
637 1.219 rillig /* -f: the makefiles to read */
638 1.226 rillig StringList makefiles;
639 1.173 rillig
640 1.219 rillig /* -i: if true, ignore all errors from shell commands */
641 1.219 rillig Boolean ignoreErrors;
642 1.173 rillig
643 1.219 rillig /* -j: the maximum number of jobs that can run in parallel;
644 1.219 rillig * this is coordinated with the submakes */
645 1.219 rillig int maxJobs;
646 1.173 rillig
647 1.233 rillig /* -k: if true and an error occurs while making a node, continue
648 1.233 rillig * making nodes that do not depend on the erroneous node */
649 1.219 rillig Boolean keepgoing;
650 1.173 rillig
651 1.219 rillig /* -N: execute no commands from the targets */
652 1.219 rillig Boolean noRecursiveExecute;
653 1.173 rillig
654 1.219 rillig /* -n: execute almost no commands from the targets */
655 1.219 rillig Boolean noExecute;
656 1.173 rillig
657 1.219 rillig /* -q: if true, we aren't supposed to really make anything, just see
658 1.219 rillig * if the targets are out-of-date */
659 1.219 rillig Boolean queryFlag;
660 1.173 rillig
661 1.219 rillig /* -r: raw mode, without loading the builtin rules. */
662 1.219 rillig Boolean noBuiltins;
663 1.173 rillig
664 1.219 rillig /* -s: don't echo the shell commands before executing them */
665 1.219 rillig Boolean beSilent;
666 1.173 rillig
667 1.219 rillig /* -t: touch the targets if they are out-of-date, but don't actually
668 1.219 rillig * make them */
669 1.219 rillig Boolean touchFlag;
670 1.173 rillig
671 1.219 rillig /* -[Vv]: print expanded or unexpanded selected variables */
672 1.219 rillig PrintVarsMode printVars;
673 1.219 rillig /* -[Vv]: the variables to print */
674 1.227 rillig StringList variables;
675 1.173 rillig
676 1.219 rillig /* -W: if true, makefile parsing warnings are treated as errors */
677 1.219 rillig Boolean parseWarnFatal;
678 1.173 rillig
679 1.219 rillig /* -w: print Entering and Leaving for submakes */
680 1.219 rillig Boolean enterFlag;
681 1.173 rillig
682 1.219 rillig /* -X: if true, do not export variables set on the command line to the
683 1.219 rillig * environment. */
684 1.219 rillig Boolean varNoExportEnv;
685 1.173 rillig
686 1.219 rillig /* The target names specified on the command line.
687 1.219 rillig * Used to resolve .if make(...) statements. */
688 1.228 rillig StringList create;
689 1.173 rillig
690 1.173 rillig } CmdOpts;
691 1.173 rillig
692 1.173 rillig extern CmdOpts opts;
693 1.173 rillig
694 1.1 cgd #include "nonints.h"
695 1.1 cgd
696 1.199 rillig void GNode_UpdateYoungestChild(GNode *, GNode *);
697 1.200 rillig Boolean GNode_IsOODate(GNode *);
698 1.144 rillig void Make_ExpandUse(GNodeList *);
699 1.44 wiz time_t Make_Recheck(GNode *);
700 1.44 wiz void Make_HandleUse(GNode *, GNode *);
701 1.44 wiz void Make_Update(GNode *);
702 1.44 wiz void Make_DoAllVar(GNode *);
703 1.144 rillig Boolean Make_Run(GNodeList *);
704 1.194 rillig Boolean shouldDieQuietly(GNode *, int);
705 1.80 sjg void PrintOnError(GNode *, const char *);
706 1.44 wiz void Main_ExportMAKEFLAGS(Boolean);
707 1.206 sjg Boolean Main_SetObjdir(Boolean, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
708 1.81 sjg int mkTempFile(const char *, char **);
709 1.208 rillig int str2Lst_Append(StringList *, char *);
710 1.126 rillig void GNode_FprintDetails(FILE *, const char *, const GNode *, const char *);
711 1.179 rillig Boolean GNode_ShouldExecute(GNode *gn);
712 1.155 rillig
713 1.164 rillig /* See if the node was seen on the left-hand side of a dependency operator. */
714 1.205 rillig MAKE_INLINE Boolean
715 1.164 rillig GNode_IsTarget(const GNode *gn)
716 1.155 rillig {
717 1.219 rillig return (gn->type & OP_OPMASK) != 0;
718 1.155 rillig }
719 1.155 rillig
720 1.205 rillig MAKE_INLINE const char *
721 1.172 rillig GNode_Path(const GNode *gn)
722 1.172 rillig {
723 1.219 rillig return gn->path != NULL ? gn->path : gn->name;
724 1.172 rillig }
725 1.172 rillig
726 1.217 rillig MAKE_INLINE Boolean
727 1.218 rillig GNode_IsWaitingFor(const GNode *gn)
728 1.218 rillig {
729 1.218 rillig return (gn->flags & REMAKE) && gn->made <= REQUESTED;
730 1.218 rillig }
731 1.218 rillig
732 1.218 rillig MAKE_INLINE Boolean
733 1.218 rillig GNode_IsReady(const GNode *gn)
734 1.218 rillig {
735 1.218 rillig return gn->made > DEFERRED;
736 1.218 rillig }
737 1.218 rillig
738 1.218 rillig MAKE_INLINE Boolean
739 1.218 rillig GNode_IsDone(const GNode *gn)
740 1.218 rillig {
741 1.218 rillig return gn->made >= MADE;
742 1.218 rillig }
743 1.218 rillig
744 1.218 rillig MAKE_INLINE Boolean
745 1.217 rillig GNode_IsError(const GNode *gn)
746 1.217 rillig {
747 1.217 rillig return gn->made == ERROR || gn->made == ABORTED;
748 1.217 rillig }
749 1.217 rillig
750 1.205 rillig MAKE_INLINE const char *
751 1.178 rillig GNode_VarTarget(GNode *gn) { return Var_ValueDirect(TARGET, gn); }
752 1.205 rillig MAKE_INLINE const char *
753 1.178 rillig GNode_VarOodate(GNode *gn) { return Var_ValueDirect(OODATE, gn); }
754 1.205 rillig MAKE_INLINE const char *
755 1.178 rillig GNode_VarAllsrc(GNode *gn) { return Var_ValueDirect(ALLSRC, gn); }
756 1.205 rillig MAKE_INLINE const char *
757 1.178 rillig GNode_VarImpsrc(GNode *gn) { return Var_ValueDirect(IMPSRC, gn); }
758 1.205 rillig MAKE_INLINE const char *
759 1.178 rillig GNode_VarPrefix(GNode *gn) { return Var_ValueDirect(PREFIX, gn); }
760 1.205 rillig MAKE_INLINE const char *
761 1.178 rillig GNode_VarArchive(GNode *gn) { return Var_ValueDirect(ARCHIVE, gn); }
762 1.205 rillig MAKE_INLINE const char *
763 1.178 rillig GNode_VarMember(GNode *gn) { return Var_ValueDirect(MEMBER, gn); }
764 1.178 rillig
765 1.46 christos #ifdef __GNUC__
766 1.148 rillig #define UNCONST(ptr) ({ \
767 1.46 christos union __unconst { \
768 1.46 christos const void *__cp; \
769 1.46 christos void *__p; \
770 1.46 christos } __d; \
771 1.46 christos __d.__cp = ptr, __d.__p; })
772 1.46 christos #else
773 1.74 christos #define UNCONST(ptr) (void *)(ptr)
774 1.49 sjg #endif
775 1.49 sjg
776 1.96 pooka /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */
777 1.96 pooka #include <limits.h>
778 1.96 pooka #ifndef MAXPATHLEN
779 1.96 pooka #define MAXPATHLEN 4096
780 1.96 pooka #endif
781 1.96 pooka #ifndef PATH_MAX
782 1.96 pooka #define PATH_MAX MAXPATHLEN
783 1.96 pooka #endif
784 1.96 pooka
785 1.103 sjg #if defined(SYSV)
786 1.219 rillig #define KILLPG(pid, sig) kill(-(pid), (sig))
787 1.103 sjg #else
788 1.219 rillig #define KILLPG(pid, sig) killpg((pid), (sig))
789 1.103 sjg #endif
790 1.103 sjg
791 1.205 rillig MAKE_INLINE Boolean
792 1.195 rillig ch_isalnum(char ch) { return isalnum((unsigned char)ch) != 0; }
793 1.205 rillig MAKE_INLINE Boolean
794 1.195 rillig ch_isalpha(char ch) { return isalpha((unsigned char)ch) != 0; }
795 1.205 rillig MAKE_INLINE Boolean
796 1.195 rillig ch_isdigit(char ch) { return isdigit((unsigned char)ch) != 0; }
797 1.205 rillig MAKE_INLINE Boolean
798 1.195 rillig ch_isspace(char ch) { return isspace((unsigned char)ch) != 0; }
799 1.205 rillig MAKE_INLINE Boolean
800 1.195 rillig ch_isupper(char ch) { return isupper((unsigned char)ch) != 0; }
801 1.205 rillig MAKE_INLINE char
802 1.195 rillig ch_tolower(char ch) { return (char)tolower((unsigned char)ch); }
803 1.205 rillig MAKE_INLINE char
804 1.195 rillig ch_toupper(char ch) { return (char)toupper((unsigned char)ch); }
805 1.139 rillig
806 1.205 rillig MAKE_INLINE void
807 1.155 rillig cpp_skip_whitespace(const char **pp)
808 1.155 rillig {
809 1.219 rillig while (ch_isspace(**pp))
810 1.219 rillig (*pp)++;
811 1.155 rillig }
812 1.155 rillig
813 1.205 rillig MAKE_INLINE void
814 1.196 rillig cpp_skip_hspace(const char **pp)
815 1.196 rillig {
816 1.219 rillig while (**pp == ' ' || **pp == '\t')
817 1.219 rillig (*pp)++;
818 1.196 rillig }
819 1.196 rillig
820 1.205 rillig MAKE_INLINE void
821 1.155 rillig pp_skip_whitespace(char **pp)
822 1.155 rillig {
823 1.219 rillig while (ch_isspace(**pp))
824 1.219 rillig (*pp)++;
825 1.155 rillig }
826 1.155 rillig
827 1.205 rillig MAKE_INLINE void
828 1.197 rillig pp_skip_hspace(char **pp)
829 1.197 rillig {
830 1.219 rillig while (**pp == ' ' || **pp == '\t')
831 1.219 rillig (*pp)++;
832 1.197 rillig }
833 1.197 rillig
834 1.160 rillig #ifdef MAKE_NATIVE
835 1.160 rillig # include <sys/cdefs.h>
836 1.160 rillig # ifndef lint
837 1.160 rillig # define MAKE_RCSID(id) __RCSID(id)
838 1.160 rillig # endif
839 1.220 rillig #elif defined(MAKE_ALL_IN_ONE)
840 1.220 rillig # if defined(__COUNTER__)
841 1.220 rillig # define MAKE_RCSID_CONCAT(x, y) CONCAT(x, y)
842 1.220 rillig # define MAKE_RCSID(id) static volatile char \
843 1.220 rillig MAKE_RCSID_CONCAT(rcsid_, __COUNTER__)[] = id
844 1.220 rillig # else
845 1.220 rillig # define MAKE_RCSID(id) extern void do_not_define_rcsid(void)
846 1.220 rillig # endif
847 1.142 rillig #else
848 1.160 rillig # define MAKE_RCSID(id) static volatile char rcsid[] = id
849 1.142 rillig #endif
850 1.142 rillig
851 1.116 rillig #endif /* MAKE_MAKE_H */
852