Annotation of src/usr.bin/make/make.h, Revision 1.173
1.173 ! rillig 1: /* $NetBSD: make.h,v 1.172 2020/10/25 21:51:49 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.127 rillig 133: /*
1.137 rillig 134: * A boolean type is defined as an integer, not an enum, for historic reasons.
135: * The only allowed values are the constants TRUE and FALSE (1 and 0).
1.127 rillig 136: */
137:
1.131 rillig 138: #ifdef USE_DOUBLE_BOOLEAN
139: /* During development, to find type mismatches in function declarations. */
1.130 rillig 140: typedef double Boolean;
1.162 rillig 141: #define TRUE 1.0
142: #define FALSE 0.0
1.131 rillig 143: #elif defined(USE_UCHAR_BOOLEAN)
144: /* During development, to find code that depends on the exact value of TRUE or
145: * that stores other values in Boolean variables. */
146: typedef unsigned char Boolean;
147: #define TRUE ((unsigned char)0xFF)
148: #define FALSE ((unsigned char)0x00)
1.161 rillig 149: #elif defined(USE_CHAR_BOOLEAN)
150: /* During development, to find code that uses a boolean as array index, via
151: * -Wchar-subscripts. */
152: typedef char Boolean;
153: #define TRUE ((char)-1)
154: #define FALSE ((char)0x00)
1.137 rillig 155: #elif defined(USE_ENUM_BOOLEAN)
1.159 rillig 156: typedef enum Boolean { FALSE, TRUE } Boolean;
1.130 rillig 157: #else
1.127 rillig 158: typedef int Boolean;
159: #ifndef TRUE
160: #define TRUE 1
1.140 rillig 161: #endif
1.127 rillig 162: #ifndef FALSE
163: #define FALSE 0
1.140 rillig 164: #endif
1.162 rillig 165: #endif
1.127 rillig 166:
1.1 cgd 167: #include "lst.h"
1.128 rillig 168: #include "enum.h"
1.22 mycroft 169: #include "hash.h"
1.1 cgd 170: #include "config.h"
1.3 cgd 171: #include "buf.h"
1.78 dsl 172: #include "make_malloc.h"
1.1 cgd 173:
1.119 rillig 174: typedef enum {
175: UNMADE, /* Not examined yet */
176: DEFERRED, /* Examined once (building child) */
177: REQUESTED, /* on toBeMade list */
178: BEINGMADE, /* Target is already being made.
179: * Indicates a cycle in the graph. */
180: MADE, /* Was out-of-date and has been made */
181: UPTODATE, /* Was already up-to-date */
182: ERROR, /* An error occurred while it was being
183: * made (used only in compat mode) */
184: ABORTED /* The target was aborted due to an error
185: * making an inferior (compat). */
186: } GNodeMade;
1.1 cgd 187:
1.120 rillig 188: /* The OP_ constants are used when parsing a dependency line as a way of
189: * communicating to other parts of the program the way in which a target
190: * should be made.
191: *
1.163 rillig 192: * Some of the OP_ constants can be combined, others cannot. */
1.159 rillig 193: typedef enum GNodeType {
1.165 rillig 194: /* The dependency operator ':' is the most common one. The commands of
195: * this node are executed if any child is out-of-date. */
1.120 rillig 196: OP_DEPENDS = 1 << 0,
1.165 rillig 197: /* The dependency operator '!' always executes its commands, even if
198: * its children are up-to-date. */
1.120 rillig 199: OP_FORCE = 1 << 1,
1.165 rillig 200: /* The dependency operator '::' behaves like ':', except that it allows
201: * multiple dependency groups to be defined. Each of these groups is
202: * executed on its own, independently from the others. */
1.120 rillig 203: OP_DOUBLEDEP = 1 << 2,
204:
1.164 rillig 205: /* Matches the dependency operators ':', '!' and '::'. */
1.120 rillig 206: OP_OPMASK = OP_DEPENDS|OP_FORCE|OP_DOUBLEDEP,
207:
208: /* Don't care if the target doesn't exist and can't be created */
209: OP_OPTIONAL = 1 << 3,
210: /* Use associated commands for parents */
211: OP_USE = 1 << 4,
212: /* Target is never out of date, but always execute commands anyway.
213: * Its time doesn't matter, so it has none...sort of */
1.148 rillig 214: OP_EXEC = 1 << 5,
1.160 rillig 215: /* Ignore non-zero exit status from shell commands when creating the node */
1.120 rillig 216: OP_IGNORE = 1 << 6,
217: /* Don't remove the target when interrupted */
218: OP_PRECIOUS = 1 << 7,
219: /* Don't echo commands when executed */
220: OP_SILENT = 1 << 8,
221: /* Target is a recursive make so its commands should always be executed
222: * when it is out of date, regardless of the state of the -n or -t flags */
223: OP_MAKE = 1 << 9,
224: /* Target is out-of-date only if any of its children was out-of-date */
225: OP_JOIN = 1 << 10,
226: /* Assume the children of the node have been already made */
227: OP_MADE = 1 << 11,
228: /* Special .BEGIN, .END, .INTERRUPT */
229: OP_SPECIAL = 1 << 12,
230: /* Like .USE, only prepend commands */
231: OP_USEBEFORE = 1 << 13,
232: /* The node is invisible to its parents. I.e. it doesn't show up in the
233: * parents' local variables. */
234: OP_INVISIBLE = 1 << 14,
235: /* The node is exempt from normal 'main target' processing in parse.c */
236: OP_NOTMAIN = 1 << 15,
237: /* Not a file target; run always */
238: OP_PHONY = 1 << 16,
239: /* Don't search for file in the path */
240: OP_NOPATH = 1 << 17,
241: /* .WAIT phony node */
242: OP_WAIT = 1 << 18,
243: /* .NOMETA do not create a .meta file */
244: OP_NOMETA = 1 << 19,
245: /* .META we _do_ want a .meta file */
246: OP_META = 1 << 20,
247: /* Do not compare commands in .meta file */
248: OP_NOMETA_CMP = 1 << 21,
249: /* Possibly a submake node */
250: OP_SUBMAKE = 1 << 22,
251:
252: /* Attributes applied by PMake */
253:
254: /* The node is a transformation rule */
255: OP_TRANSFORM = 1 << 31,
256: /* Target is a member of an archive */
1.169 rillig 257: /* XXX: How does this differ from OP_ARCHV? */
1.120 rillig 258: OP_MEMBER = 1 << 30,
1.169 rillig 259: /* The node is a library,
260: * its name has the form "-l<libname>" */
1.120 rillig 261: OP_LIB = 1 << 29,
1.169 rillig 262: /* The node is an archive member,
263: * its name has the form "archive(member)" */
264: /* XXX: How does this differ from OP_MEMBER? */
1.120 rillig 265: OP_ARCHV = 1 << 28,
266: /* Target has all the commands it should. Used when parsing to catch
1.160 rillig 267: * multiple command groups for a target. Only applies to the dependency
268: * operators ':' and '!', but not to '::'. */
1.120 rillig 269: OP_HAS_COMMANDS = 1 << 27,
1.145 rillig 270: /* The special command "..." has been seen. All further commands from
271: * this node will be saved on the .END node instead, to be executed at
272: * the very end. */
1.120 rillig 273: OP_SAVE_CMDS = 1 << 26,
274: /* Already processed by Suff_FindDeps */
275: OP_DEPS_FOUND = 1 << 25,
276: /* Node found while expanding .ALLSRC */
1.155 rillig 277: OP_MARK = 1 << 24,
278:
279: OP_NOTARGET = OP_NOTMAIN | OP_USE | OP_EXEC | OP_TRANSFORM
1.120 rillig 280: } GNodeType;
281:
1.159 rillig 282: typedef enum GNodeFlags {
1.119 rillig 283: REMAKE = 0x0001, /* this target needs to be (re)made */
284: CHILDMADE = 0x0002, /* children of this target were made */
285: FORCE = 0x0004, /* children don't exist, and we pretend made */
286: DONE_WAIT = 0x0008, /* Set by Make_ProcessWait() */
287: DONE_ORDER = 0x0010, /* Build requested by .ORDER processing */
288: FROM_DEPEND = 0x0020, /* Node created from .depend */
289: DONE_ALLSRC = 0x0040, /* We do it once only */
290: CYCLE = 0x1000, /* Used by MakePrintStatus */
291: DONECYCLE = 0x2000, /* Used by MakePrintStatus */
292: INTERNAL = 0x4000 /* Internal use only */
293: } GNodeFlags;
1.1 cgd 294:
1.143 rillig 295: typedef struct List StringList;
296: typedef struct ListNode StringListNode;
1.144 rillig 297:
1.143 rillig 298: typedef struct List GNodeList;
299: typedef struct ListNode GNodeListNode;
300:
1.144 rillig 301: typedef struct List /* of CachedDir */ SearchPath;
302:
1.119 rillig 303: /* A graph node represents a target that can possibly be made, including its
304: * relation to other targets and a lot of other details. */
305: typedef struct GNode {
306: /* The target's name, such as "clean" or "make.c" */
307: char *name;
308: /* The unexpanded name of a .USE node */
309: char *uname;
310: /* The full pathname of the file belonging to the target.
311: * XXX: What about .PHONY targets? These don't have an associated path. */
312: char *path;
313:
314: /* The type of operator used to define the sources (see the OP flags below).
315: * XXX: This looks like a wild mixture of type and flags. */
1.124 rillig 316: GNodeType type;
1.119 rillig 317: GNodeFlags flags;
318:
319: /* The state of processing on this node */
320: GNodeMade made;
321: int unmade; /* The number of unmade children */
322:
1.160 rillig 323: /* The modification time; 0 means the node does not have a corresponding
324: * file; see Make_OODate. */
325: time_t mtime;
1.166 rillig 326: struct GNode *youngestChild;
1.119 rillig 327:
1.133 rillig 328: /* The GNodes for which this node is an implied source. May be empty.
329: * For example, when there is an inference rule for .c.o, the node for
330: * file.c has the node for file.o in this list. */
1.143 rillig 331: GNodeList *implicitParents;
1.119 rillig 332:
1.160 rillig 333: /* Other nodes of the same name, for the '::' operator. */
1.143 rillig 334: GNodeList *cohorts;
1.119 rillig 335:
336: /* The nodes that depend on this one, or in other words, the nodes for
337: * which this is a source. */
1.143 rillig 338: GNodeList *parents;
1.119 rillig 339: /* The nodes on which this one depends. */
1.143 rillig 340: GNodeList *children;
1.119 rillig 341:
342: /* .ORDER nodes we need made. The nodes that must be made (if they're
343: * made) before this node can be made, but that do not enter into the
344: * datedness of this node. */
1.143 rillig 345: GNodeList *order_pred;
1.119 rillig 346: /* .ORDER nodes who need us. The nodes that must be made (if they're made
347: * at all) after this node is made, but that do not depend on this node,
348: * in the normal sense. */
1.143 rillig 349: GNodeList *order_succ;
1.119 rillig 350:
1.156 rillig 351: /* The "#n" suffix for this cohort, or "" for other nodes */
1.119 rillig 352: char cohort_num[8];
353: /* The number of unmade instances on the cohorts list */
354: int unmade_cohorts;
1.129 rillig 355: /* Pointer to the first instance of a '::' node; only set when on a
356: * cohorts list */
1.119 rillig 357: struct GNode *centurion;
358:
1.122 rillig 359: /* Last time (sequence number) we tried to make this node */
1.160 rillig 360: unsigned int checked_seqno;
1.119 rillig 361:
362: /* The "local" variables that are specific to this target and this target
1.160 rillig 363: * only, such as $@, $<, $?.
364: *
365: * Also used for the global variable scopes VAR_GLOBAL, VAR_CMD,
366: * VAR_INTERNAL, which contain variables with arbitrary names. */
1.158 rillig 367: HashTable context;
1.119 rillig 368:
369: /* The commands to be given to a shell to create this target. */
1.143 rillig 370: StringList *commands;
1.119 rillig 371:
372: /* Suffix for the node (determined by Suff_FindDeps and opaque to everyone
373: * but the Suff module) */
374: struct Suff *suffix;
375:
376: /* filename where the GNode got defined */
377: const char *fname;
378: /* line number where the GNode got defined */
379: int lineno;
1.1 cgd 380: } GNode;
381:
382: /*
383: * Error levels for parsing. PARSE_FATAL means the process cannot continue
1.167 rillig 384: * once the top-level makefile has been parsed. PARSE_WARNING and PARSE_INFO
385: * mean it can.
1.1 cgd 386: */
1.167 rillig 387: typedef enum ParseErrorLevel {
388: PARSE_FATAL = 1,
389: PARSE_WARNING,
390: PARSE_INFO
391: } ParseErrorLevel;
1.1 cgd 392:
393: /*
1.141 rillig 394: * Values returned by Cond_EvalLine and Cond_EvalCondition.
1.1 cgd 395: */
1.159 rillig 396: typedef enum CondEvalResult {
1.113 rillig 397: COND_PARSE, /* Parse the next lines */
398: COND_SKIP, /* Skip the next lines */
399: COND_INVALID /* Not a conditional statement */
400: } CondEvalResult;
1.1 cgd 401:
402: /*
403: * Definitions for the "local" variables. Used only for clarity.
404: */
1.148 rillig 405: #define TARGET "@" /* Target of dependency */
406: #define OODATE "?" /* All out-of-date sources */
407: #define ALLSRC ">" /* All sources */
408: #define IMPSRC "<" /* Source implied by transformation */
409: #define PREFIX "*" /* Common prefix */
410: #define ARCHIVE "!" /* Archive in "archive(member)" syntax */
411: #define MEMBER "%" /* Member in "archive(member)" syntax */
412:
413: #define FTARGET "@F" /* file part of TARGET */
414: #define DTARGET "@D" /* directory part of TARGET */
415: #define FIMPSRC "<F" /* file part of IMPSRC */
416: #define DIMPSRC "<D" /* directory part of IMPSRC */
417: #define FPREFIX "*F" /* file part of PREFIX */
418: #define DPREFIX "*D" /* directory part of PREFIX */
1.1 cgd 419:
420: /*
1.11 christos 421: * Global Variables
1.1 cgd 422: */
1.148 rillig 423: extern SearchPath *dirSearchPath;
424: /* The list of directories to search when
1.1 cgd 425: * looking for targets */
1.148 rillig 426: extern Boolean allPrecious; /* True if every target is precious */
1.101 dholland 427: extern Boolean deleteOnError; /* True if failed targets should be deleted */
1.71 dsl 428: extern Boolean doing_depend; /* TRUE if processing .depend */
1.1 cgd 429:
1.148 rillig 430: extern GNode *DEFAULT; /* .DEFAULT rule */
1.1 cgd 431:
1.92 sjg 432: extern GNode *VAR_INTERNAL; /* Variables defined internally by make
433: * which should not override those set by
434: * makefiles.
435: */
1.148 rillig 436: extern GNode *VAR_GLOBAL; /* Variables defined in a global context, e.g
1.1 cgd 437: * in the Makefile itself */
1.148 rillig 438: extern GNode *VAR_CMD; /* Variables defined on the command line */
439: extern char var_Error[]; /* Value returned by Var_Parse when an error
1.1 cgd 440: * is encountered. It actually points to
441: * an empty string, so naive callers needn't
442: * worry about it. */
443:
1.148 rillig 444: extern time_t now; /* The time at the start of this whole
1.1 cgd 445: * process */
446:
1.148 rillig 447: extern Boolean oldVars; /* Do old-style variable substitution */
1.9 christos 448:
1.144 rillig 449: extern SearchPath *sysIncPath; /* The system include path. */
450: extern SearchPath *defIncPath; /* The default include path. */
1.32 christos 451:
1.85 joerg 452: extern char curdir[]; /* Startup directory */
1.32 christos 453: extern char *progname; /* The program name */
1.80 sjg 454: extern char *makeDependfile; /* .depend */
1.88 sjg 455: extern char **savedEnv; /* if we replaced environ this will be non-NULL */
1.30 sommerfe 456:
1.111 rillig 457: extern int makelevel;
458:
1.82 sjg 459: /*
460: * We cannot vfork() in a child of vfork().
461: * Most systems do not enforce this but some do.
462: */
463: #define vFork() ((getpid() == myPid) ? vfork() : fork())
464: extern pid_t myPid;
465:
1.30 sommerfe 466: #define MAKEFLAGS ".MAKEFLAGS"
1.35 sjg 467: #define MAKEOVERRIDES ".MAKEOVERRIDES"
1.70 sjg 468: #define MAKE_JOB_PREFIX ".MAKE.JOB.PREFIX" /* prefix for job target output */
469: #define MAKE_EXPORTED ".MAKE.EXPORTED" /* variables we export */
1.160 rillig 470: #define MAKE_MAKEFILES ".MAKE.MAKEFILES" /* all makefiles already loaded */
1.79 sjg 471: #define MAKE_LEVEL ".MAKE.LEVEL" /* recursion level */
1.80 sjg 472: #define MAKEFILE_PREFERENCE ".MAKE.MAKEFILE_PREFERENCE"
473: #define MAKE_DEPENDFILE ".MAKE.DEPENDFILE" /* .depend */
474: #define MAKE_MODE ".MAKE.MODE"
1.91 sjg 475: #ifndef MAKE_LEVEL_ENV
476: # define MAKE_LEVEL_ENV "MAKELEVEL"
477: #endif
1.1 cgd 478:
1.170 rillig 479: typedef enum DebugFlags {
480: DEBUG_ARCH = 1 << 0,
481: DEBUG_COND = 1 << 1,
482: DEBUG_DIR = 1 << 2,
483: DEBUG_GRAPH1 = 1 << 3,
484: DEBUG_GRAPH2 = 1 << 4,
485: DEBUG_JOB = 1 << 5,
486: DEBUG_MAKE = 1 << 6,
487: DEBUG_SUFF = 1 << 7,
488: DEBUG_TARG = 1 << 8,
489: DEBUG_VAR = 1 << 9,
490: DEBUG_FOR = 1 << 10,
491: DEBUG_SHELL = 1 << 11,
492: DEBUG_ERROR = 1 << 12,
493: DEBUG_LOUD = 1 << 13,
494: DEBUG_META = 1 << 14,
495: DEBUG_HASH = 1 << 15,
496:
497: DEBUG_GRAPH3 = 1 << 16,
498: DEBUG_SCRIPT = 1 << 17,
499: DEBUG_PARSE = 1 << 18,
500: DEBUG_CWD = 1 << 19,
501:
502: DEBUG_LINT = 1 << 20
503: } DebugFlags;
504:
1.1 cgd 505: #define CONCAT(a,b) a##b
506:
1.173 ! rillig 507: #define DEBUG(module) (opts.debug & CONCAT(DEBUG_,module))
1.1 cgd 508:
1.151 rillig 509: void debug_printf(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
1.150 rillig 510:
1.149 rillig 511: #define DEBUG0(module, text) \
512: if (!DEBUG(module)) (void)0; \
1.150 rillig 513: else debug_printf("%s", text)
1.149 rillig 514:
515: #define DEBUG1(module, fmt, arg1) \
516: if (!DEBUG(module)) (void)0; \
1.150 rillig 517: else debug_printf(fmt, arg1)
1.149 rillig 518:
519: #define DEBUG2(module, fmt, arg1, arg2) \
520: if (!DEBUG(module)) (void)0; \
1.150 rillig 521: else debug_printf(fmt, arg1, arg2)
1.149 rillig 522:
523: #define DEBUG3(module, fmt, arg1, arg2, arg3) \
524: if (!DEBUG(module)) (void)0; \
1.150 rillig 525: else debug_printf(fmt, arg1, arg2, arg3)
1.149 rillig 526:
527: #define DEBUG4(module, fmt, arg1, arg2, arg3, arg4) \
528: if (!DEBUG(module)) (void)0; \
1.150 rillig 529: else debug_printf(fmt, arg1, arg2, arg3, arg4)
1.149 rillig 530:
531: #define DEBUG5(module, fmt, arg1, arg2, arg3, arg4, arg5) \
532: if (!DEBUG(module)) (void)0; \
1.150 rillig 533: else debug_printf(fmt, arg1, arg2, arg3, arg4, arg5)
1.149 rillig 534:
1.173 ! rillig 535: typedef enum PrintVarsMode {
! 536: COMPAT_VARS = 1,
! 537: EXPAND_VARS
! 538: } PrintVarsMode;
! 539:
! 540: /* Command line options */
! 541: typedef struct CmdOpts {
! 542: /* -B: whether we are make compatible */
! 543: Boolean compatMake;
! 544:
! 545: /* -d: debug control: There is one bit per module. It is up to the
! 546: * module what debug information to print. */
! 547: DebugFlags debug;
! 548:
! 549: /* -df: debug output is written here - default stderr */
! 550: FILE *debug_file;
! 551:
! 552: /* -e: check environment variables before global variables */
! 553: Boolean checkEnvFirst;
! 554:
! 555: /* -f: the makefiles to read */
! 556: StringList *makefiles;
! 557:
! 558: /* -i: if true, ignore all errors from shell commands */
! 559: Boolean ignoreErrors;
! 560:
! 561: /* -j: the maximum number of jobs that can run in parallel;
! 562: * this is coordinated with the submakes */
! 563: int maxJobs;
! 564:
! 565: /* -k: if true, continue on unaffected portions of the graph when an
! 566: * error occurs in one portion */
! 567: Boolean keepgoing;
! 568:
! 569: /* -N: execute no commands from the targets */
! 570: Boolean noRecursiveExecute;
! 571:
! 572: /* -n: execute almost no commands from the targets */
! 573: Boolean noExecute;
! 574:
! 575: /* -q: if true, we aren't supposed to really make anything, just see if
! 576: * the targets are out-of-date */
! 577: Boolean queryFlag;
! 578:
! 579: /* -r: raw mode, without loading the builtin rules. */
! 580: Boolean noBuiltins;
! 581:
! 582: /* -s: don't echo the shell commands before executing them */
! 583: Boolean beSilent;
! 584:
! 585: /* -t: touch the targets if they are out-of-date, but don't actually
! 586: * make them */
! 587: Boolean touchFlag;
! 588:
! 589: /* -[Vv]: print expanded or unexpanded selected variables */
! 590: PrintVarsMode printVars;
! 591: /* -[Vv]: the variables to print */
! 592: StringList *variables;
! 593:
! 594: /* -W: if true, makefile parsing warnings are treated as errors */
! 595: Boolean parseWarnFatal;
! 596:
! 597: /* -w: print Entering and Leaving for submakes */
! 598: Boolean enterFlag;
! 599:
! 600: /* -X: if true, do not export variables set on the command line to the
! 601: * environment. */
! 602: Boolean varNoExportEnv;
! 603:
! 604: /* The target names specified on the command line.
! 605: * Used to resolve .if make(...) statements. */
! 606: StringList *create;
! 607:
! 608: } CmdOpts;
! 609:
! 610: extern CmdOpts opts;
! 611:
1.1 cgd 612: #include "nonints.h"
613:
1.146 rillig 614: void Make_TimeStamp(GNode *, GNode *);
1.44 wiz 615: Boolean Make_OODate(GNode *);
1.144 rillig 616: void Make_ExpandUse(GNodeList *);
1.44 wiz 617: time_t Make_Recheck(GNode *);
618: void Make_HandleUse(GNode *, GNode *);
619: void Make_Update(GNode *);
620: void Make_DoAllVar(GNode *);
1.144 rillig 621: Boolean Make_Run(GNodeList *);
1.108 sjg 622: int dieQuietly(GNode *, int);
1.80 sjg 623: void PrintOnError(GNode *, const char *);
1.44 wiz 624: void Main_ExportMAKEFLAGS(Boolean);
1.102 christos 625: Boolean Main_SetObjdir(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
1.81 sjg 626: int mkTempFile(const char *, char **);
1.144 rillig 627: int str2Lst_Append(StringList *, char *, const char *);
1.126 rillig 628: void GNode_FprintDetails(FILE *, const char *, const GNode *, const char *);
1.157 rillig 629: Boolean NoExecute(GNode *gn);
1.155 rillig 630:
1.164 rillig 631: /* See if the node was seen on the left-hand side of a dependency operator. */
1.172 rillig 632: static MAKE_ATTR_UNUSED Boolean
1.164 rillig 633: GNode_IsTarget(const GNode *gn)
1.155 rillig 634: {
1.164 rillig 635: return (gn->type & OP_OPMASK) != 0;
1.155 rillig 636: }
637:
1.172 rillig 638: static MAKE_ATTR_UNUSED const char *
639: GNode_Path(const GNode *gn)
640: {
641: return gn->path != NULL ? gn->path : gn->name;
642: }
643:
1.46 christos 644: #ifdef __GNUC__
1.148 rillig 645: #define UNCONST(ptr) ({ \
1.46 christos 646: union __unconst { \
647: const void *__cp; \
648: void *__p; \
649: } __d; \
650: __d.__cp = ptr, __d.__p; })
651: #else
1.74 christos 652: #define UNCONST(ptr) (void *)(ptr)
1.49 sjg 653: #endif
654:
1.96 pooka 655: /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */
656: #include <limits.h>
657: #ifndef MAXPATHLEN
658: #define MAXPATHLEN 4096
659: #endif
660: #ifndef PATH_MAX
661: #define PATH_MAX MAXPATHLEN
662: #endif
663:
1.103 sjg 664: #if defined(SYSV)
665: #define KILLPG(pid, sig) kill(-(pid), (sig))
666: #else
667: #define KILLPG(pid, sig) killpg((pid), (sig))
668: #endif
669:
1.139 rillig 670: static inline MAKE_ATTR_UNUSED Boolean ch_isalnum(char ch)
671: { return isalnum((unsigned char)ch) != 0; }
672: static inline MAKE_ATTR_UNUSED Boolean ch_isalpha(char ch)
673: { return isalpha((unsigned char)ch) != 0; }
674: static inline MAKE_ATTR_UNUSED Boolean ch_isdigit(char ch)
675: { return isdigit((unsigned char)ch) != 0; }
676: static inline MAKE_ATTR_UNUSED Boolean ch_isspace(char ch)
677: { return isspace((unsigned char)ch) != 0; }
678: static inline MAKE_ATTR_UNUSED Boolean ch_isupper(char ch)
679: { return isupper((unsigned char)ch) != 0; }
680: static inline MAKE_ATTR_UNUSED char ch_tolower(char ch)
681: { return (char)tolower((unsigned char)ch); }
682: static inline MAKE_ATTR_UNUSED char ch_toupper(char ch)
683: { return (char)toupper((unsigned char)ch); }
684:
1.155 rillig 685: static inline MAKE_ATTR_UNUSED void
686: cpp_skip_whitespace(const char **pp)
687: {
688: while (ch_isspace(**pp))
689: (*pp)++;
690: }
691:
692: static inline MAKE_ATTR_UNUSED void
693: pp_skip_whitespace(char **pp)
694: {
695: while (ch_isspace(**pp))
696: (*pp)++;
697: }
698:
1.160 rillig 699: #ifdef MAKE_NATIVE
700: # include <sys/cdefs.h>
701: # ifndef lint
702: # define MAKE_RCSID(id) __RCSID(id)
703: # endif
1.142 rillig 704: #else
1.160 rillig 705: # define MAKE_RCSID(id) static volatile char rcsid[] = id
1.142 rillig 706: #endif
707:
1.116 rillig 708: #endif /* MAKE_MAKE_H */
CVSweb <webmaster@jp.NetBSD.org>