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