Annotation of src/usr.bin/make/make.h, Revision 1.189
1.189 ! rillig 1: /* $NetBSD: make.h,v 1.188 2020/11/04 13:40:20 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.181 rillig 174: typedef enum GNodeMade {
1.119 rillig 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
1.189 ! rillig 233: * parents' local variables (.IMPSRC, .ALLSRC). */
1.120 rillig 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,
1.189 ! rillig 241: /* In a dependency line "target: source1 .WAIT source2", source1 is made
! 242: * first, including its children. Once that is finished, source2 is made,
! 243: * including its children. The .WAIT keyword may appear more than once in
! 244: * a single dependency declaration. */
1.120 rillig 245: OP_WAIT = 1 << 18,
246: /* .NOMETA do not create a .meta file */
247: OP_NOMETA = 1 << 19,
248: /* .META we _do_ want a .meta file */
249: OP_META = 1 << 20,
250: /* Do not compare commands in .meta file */
251: OP_NOMETA_CMP = 1 << 21,
252: /* Possibly a submake node */
253: OP_SUBMAKE = 1 << 22,
254:
255: /* Attributes applied by PMake */
256:
1.189 ! rillig 257: /* The node is a transformation rule, such as ".c.o". */
1.120 rillig 258: OP_TRANSFORM = 1 << 31,
259: /* Target is a member of an archive */
1.169 rillig 260: /* XXX: How does this differ from OP_ARCHV? */
1.120 rillig 261: OP_MEMBER = 1 << 30,
1.169 rillig 262: /* The node is a library,
263: * its name has the form "-l<libname>" */
1.120 rillig 264: OP_LIB = 1 << 29,
1.169 rillig 265: /* The node is an archive member,
266: * its name has the form "archive(member)" */
267: /* XXX: How does this differ from OP_MEMBER? */
1.120 rillig 268: OP_ARCHV = 1 << 28,
269: /* Target has all the commands it should. Used when parsing to catch
1.160 rillig 270: * multiple command groups for a target. Only applies to the dependency
271: * operators ':' and '!', but not to '::'. */
1.120 rillig 272: OP_HAS_COMMANDS = 1 << 27,
1.145 rillig 273: /* The special command "..." has been seen. All further commands from
274: * this node will be saved on the .END node instead, to be executed at
275: * the very end. */
1.120 rillig 276: OP_SAVE_CMDS = 1 << 26,
277: /* Already processed by Suff_FindDeps */
278: OP_DEPS_FOUND = 1 << 25,
279: /* Node found while expanding .ALLSRC */
1.155 rillig 280: OP_MARK = 1 << 24,
281:
282: OP_NOTARGET = OP_NOTMAIN | OP_USE | OP_EXEC | OP_TRANSFORM
1.120 rillig 283: } GNodeType;
284:
1.159 rillig 285: typedef enum GNodeFlags {
1.119 rillig 286: REMAKE = 0x0001, /* this target needs to be (re)made */
287: CHILDMADE = 0x0002, /* children of this target were made */
288: FORCE = 0x0004, /* children don't exist, and we pretend made */
289: DONE_WAIT = 0x0008, /* Set by Make_ProcessWait() */
290: DONE_ORDER = 0x0010, /* Build requested by .ORDER processing */
291: FROM_DEPEND = 0x0020, /* Node created from .depend */
292: DONE_ALLSRC = 0x0040, /* We do it once only */
293: CYCLE = 0x1000, /* Used by MakePrintStatus */
294: DONECYCLE = 0x2000, /* Used by MakePrintStatus */
295: INTERNAL = 0x4000 /* Internal use only */
296: } GNodeFlags;
1.1 cgd 297:
1.143 rillig 298: typedef struct List StringList;
299: typedef struct ListNode StringListNode;
1.144 rillig 300:
1.143 rillig 301: typedef struct List GNodeList;
302: typedef struct ListNode GNodeListNode;
303:
1.144 rillig 304: typedef struct List /* of CachedDir */ SearchPath;
305:
1.119 rillig 306: /* A graph node represents a target that can possibly be made, including its
307: * relation to other targets and a lot of other details. */
308: typedef struct GNode {
309: /* The target's name, such as "clean" or "make.c" */
310: char *name;
311: /* The unexpanded name of a .USE node */
312: char *uname;
313: /* The full pathname of the file belonging to the target.
314: * XXX: What about .PHONY targets? These don't have an associated path. */
315: char *path;
316:
317: /* The type of operator used to define the sources (see the OP flags below).
318: * XXX: This looks like a wild mixture of type and flags. */
1.124 rillig 319: GNodeType type;
1.119 rillig 320: GNodeFlags flags;
321:
322: /* The state of processing on this node */
323: GNodeMade made;
324: int unmade; /* The number of unmade children */
325:
1.160 rillig 326: /* The modification time; 0 means the node does not have a corresponding
327: * file; see Make_OODate. */
328: time_t mtime;
1.166 rillig 329: struct GNode *youngestChild;
1.119 rillig 330:
1.133 rillig 331: /* The GNodes for which this node is an implied source. May be empty.
332: * For example, when there is an inference rule for .c.o, the node for
333: * file.c has the node for file.o in this list. */
1.143 rillig 334: GNodeList *implicitParents;
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.188 rillig 351: /* Other nodes of the same name, for the '::' dependency operator. */
352: GNodeList *cohorts;
1.156 rillig 353: /* The "#n" suffix for this cohort, or "" for other nodes */
1.119 rillig 354: char cohort_num[8];
355: /* The number of unmade instances on the cohorts list */
356: int unmade_cohorts;
1.129 rillig 357: /* Pointer to the first instance of a '::' node; only set when on a
358: * cohorts list */
1.119 rillig 359: struct GNode *centurion;
360:
1.122 rillig 361: /* Last time (sequence number) we tried to make this node */
1.160 rillig 362: unsigned int checked_seqno;
1.119 rillig 363:
364: /* The "local" variables that are specific to this target and this target
1.160 rillig 365: * only, such as $@, $<, $?.
366: *
1.176 rillig 367: * Also used for the global variable scopes VAR_GLOBAL, VAR_CMDLINE,
1.160 rillig 368: * VAR_INTERNAL, which contain variables with arbitrary names. */
1.177 rillig 369: HashTable /* of Var pointer */ context;
1.119 rillig 370:
371: /* The commands to be given to a shell to create this target. */
1.143 rillig 372: StringList *commands;
1.119 rillig 373:
374: /* Suffix for the node (determined by Suff_FindDeps and opaque to everyone
375: * but the Suff module) */
376: struct Suff *suffix;
377:
1.188 rillig 378: /* Filename where the GNode got defined */
1.119 rillig 379: const char *fname;
1.188 rillig 380: /* Line number where the GNode got defined */
1.119 rillig 381: int lineno;
1.1 cgd 382: } GNode;
383:
1.188 rillig 384: /* Error levels for diagnostics during parsing. */
1.167 rillig 385: typedef enum ParseErrorLevel {
1.188 rillig 386: /* Exit when the current top-level makefile has been parsed completely. */
1.167 rillig 387: PARSE_FATAL = 1,
1.188 rillig 388: /* Print "warning"; may be upgraded to fatal by the -w option. */
1.167 rillig 389: PARSE_WARNING,
1.188 rillig 390: /* Informational, mainly used during development of makefiles. */
1.167 rillig 391: PARSE_INFO
392: } ParseErrorLevel;
1.1 cgd 393:
394: /*
1.141 rillig 395: * Values returned by Cond_EvalLine and Cond_EvalCondition.
1.1 cgd 396: */
1.159 rillig 397: typedef enum CondEvalResult {
1.113 rillig 398: COND_PARSE, /* Parse the next lines */
399: COND_SKIP, /* Skip the next lines */
400: COND_INVALID /* Not a conditional statement */
401: } CondEvalResult;
1.1 cgd 402:
403: /*
404: * Definitions for the "local" variables. Used only for clarity.
405: */
1.148 rillig 406: #define TARGET "@" /* Target of dependency */
407: #define OODATE "?" /* All out-of-date sources */
408: #define ALLSRC ">" /* All sources */
409: #define IMPSRC "<" /* Source implied by transformation */
410: #define PREFIX "*" /* Common prefix */
411: #define ARCHIVE "!" /* Archive in "archive(member)" syntax */
412: #define MEMBER "%" /* Member in "archive(member)" syntax */
413:
1.1 cgd 414: /*
1.11 christos 415: * Global Variables
1.1 cgd 416: */
1.148 rillig 417: extern SearchPath *dirSearchPath;
418: /* The list of directories to search when
1.1 cgd 419: * looking for targets */
1.148 rillig 420: extern Boolean allPrecious; /* True if every target is precious */
1.101 dholland 421: extern Boolean deleteOnError; /* True if failed targets should be deleted */
1.71 dsl 422: extern Boolean doing_depend; /* TRUE if processing .depend */
1.1 cgd 423:
1.148 rillig 424: extern GNode *DEFAULT; /* .DEFAULT rule */
1.1 cgd 425:
1.92 sjg 426: extern GNode *VAR_INTERNAL; /* Variables defined internally by make
427: * which should not override those set by
428: * makefiles.
429: */
1.148 rillig 430: extern GNode *VAR_GLOBAL; /* Variables defined in a global context, e.g
1.1 cgd 431: * in the Makefile itself */
1.176 rillig 432: extern GNode *VAR_CMDLINE; /* Variables defined on the command line */
1.148 rillig 433: extern char var_Error[]; /* Value returned by Var_Parse when an error
1.1 cgd 434: * is encountered. It actually points to
435: * an empty string, so naive callers needn't
436: * worry about it. */
437:
1.148 rillig 438: extern time_t now; /* The time at the start of this whole
1.1 cgd 439: * process */
440:
1.182 rillig 441: /*
1.183 rillig 442: * If FALSE (the default behavior), undefined subexpressions in a variable
443: * expression are discarded. If TRUE (only during variable assignments using
444: * the ':=' assignment operator, in the top-level expansion), they are
445: * preserved and possibly expanded later when the variable from the
446: * subexpression has been defined.
1.180 rillig 447: *
1.182 rillig 448: * Example for a ':=' assignment:
449: * CFLAGS = $(.INCLUDES)
450: * CFLAGS := -I.. $(CFLAGS)
451: * # If .INCLUDES (an undocumented special variable, by the way) is
452: * # still undefined, the updated CFLAGS becomes "-I.. $(.INCLUDES)".
453: */
1.183 rillig 454: extern Boolean preserveUndefined;
1.9 christos 455:
1.186 rillig 456: /* Used for .include "...". */
457: extern SearchPath *parseIncPath;
458: /* Used for .include <...>, for the built-in sys.mk and makefiles from the
459: * command line arguments. */
460: extern SearchPath *sysIncPath;
461: /* The default for sysIncPath. */
462: extern SearchPath *defSysIncPath;
1.32 christos 463:
1.187 rillig 464: extern char curdir[]; /* Startup directory */
465: extern char *progname; /* The program name */
466: extern char *makeDependfile; /* .depend */
467: /* If we replaced environ, this will be non-NULL. */
468: extern char **savedEnv;
1.30 sommerfe 469:
1.111 rillig 470: extern int makelevel;
471:
1.82 sjg 472: /*
473: * We cannot vfork() in a child of vfork().
474: * Most systems do not enforce this but some do.
475: */
476: #define vFork() ((getpid() == myPid) ? vfork() : fork())
477: extern pid_t myPid;
478:
1.30 sommerfe 479: #define MAKEFLAGS ".MAKEFLAGS"
1.35 sjg 480: #define MAKEOVERRIDES ".MAKEOVERRIDES"
1.70 sjg 481: #define MAKE_JOB_PREFIX ".MAKE.JOB.PREFIX" /* prefix for job target output */
482: #define MAKE_EXPORTED ".MAKE.EXPORTED" /* variables we export */
1.160 rillig 483: #define MAKE_MAKEFILES ".MAKE.MAKEFILES" /* all makefiles already loaded */
1.79 sjg 484: #define MAKE_LEVEL ".MAKE.LEVEL" /* recursion level */
1.185 rillig 485: #define MAKE_MAKEFILE_PREFERENCE ".MAKE.MAKEFILE_PREFERENCE"
1.80 sjg 486: #define MAKE_DEPENDFILE ".MAKE.DEPENDFILE" /* .depend */
487: #define MAKE_MODE ".MAKE.MODE"
1.91 sjg 488: #ifndef MAKE_LEVEL_ENV
489: # define MAKE_LEVEL_ENV "MAKELEVEL"
490: #endif
1.1 cgd 491:
1.170 rillig 492: typedef enum DebugFlags {
493: DEBUG_ARCH = 1 << 0,
494: DEBUG_COND = 1 << 1,
495: DEBUG_DIR = 1 << 2,
496: DEBUG_GRAPH1 = 1 << 3,
497: DEBUG_GRAPH2 = 1 << 4,
498: DEBUG_JOB = 1 << 5,
499: DEBUG_MAKE = 1 << 6,
500: DEBUG_SUFF = 1 << 7,
501: DEBUG_TARG = 1 << 8,
502: DEBUG_VAR = 1 << 9,
503: DEBUG_FOR = 1 << 10,
504: DEBUG_SHELL = 1 << 11,
505: DEBUG_ERROR = 1 << 12,
506: DEBUG_LOUD = 1 << 13,
507: DEBUG_META = 1 << 14,
508: DEBUG_HASH = 1 << 15,
509:
510: DEBUG_GRAPH3 = 1 << 16,
511: DEBUG_SCRIPT = 1 << 17,
512: DEBUG_PARSE = 1 << 18,
513: DEBUG_CWD = 1 << 19,
514:
515: DEBUG_LINT = 1 << 20
516: } DebugFlags;
517:
1.1 cgd 518: #define CONCAT(a,b) a##b
519:
1.173 rillig 520: #define DEBUG(module) (opts.debug & CONCAT(DEBUG_,module))
1.1 cgd 521:
1.151 rillig 522: void debug_printf(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
1.150 rillig 523:
1.149 rillig 524: #define DEBUG0(module, text) \
525: if (!DEBUG(module)) (void)0; \
1.150 rillig 526: else debug_printf("%s", text)
1.149 rillig 527:
528: #define DEBUG1(module, fmt, arg1) \
529: if (!DEBUG(module)) (void)0; \
1.150 rillig 530: else debug_printf(fmt, arg1)
1.149 rillig 531:
532: #define DEBUG2(module, fmt, arg1, arg2) \
533: if (!DEBUG(module)) (void)0; \
1.150 rillig 534: else debug_printf(fmt, arg1, arg2)
1.149 rillig 535:
536: #define DEBUG3(module, fmt, arg1, arg2, arg3) \
537: if (!DEBUG(module)) (void)0; \
1.150 rillig 538: else debug_printf(fmt, arg1, arg2, arg3)
1.149 rillig 539:
540: #define DEBUG4(module, fmt, arg1, arg2, arg3, arg4) \
541: if (!DEBUG(module)) (void)0; \
1.150 rillig 542: else debug_printf(fmt, arg1, arg2, arg3, arg4)
1.149 rillig 543:
544: #define DEBUG5(module, fmt, arg1, arg2, arg3, arg4, arg5) \
545: if (!DEBUG(module)) (void)0; \
1.150 rillig 546: else debug_printf(fmt, arg1, arg2, arg3, arg4, arg5)
1.149 rillig 547:
1.173 rillig 548: typedef enum PrintVarsMode {
549: COMPAT_VARS = 1,
550: EXPAND_VARS
551: } PrintVarsMode;
552:
553: /* Command line options */
554: typedef struct CmdOpts {
555: /* -B: whether we are make compatible */
556: Boolean compatMake;
557:
558: /* -d: debug control: There is one bit per module. It is up to the
559: * module what debug information to print. */
560: DebugFlags debug;
561:
562: /* -df: debug output is written here - default stderr */
563: FILE *debug_file;
564:
1.174 rillig 565: /* -dV: for the -V option, print unexpanded variable values */
566: Boolean debugVflag;
567:
1.173 rillig 568: /* -e: check environment variables before global variables */
569: Boolean checkEnvFirst;
570:
571: /* -f: the makefiles to read */
572: StringList *makefiles;
573:
574: /* -i: if true, ignore all errors from shell commands */
575: Boolean ignoreErrors;
576:
577: /* -j: the maximum number of jobs that can run in parallel;
578: * this is coordinated with the submakes */
579: int maxJobs;
580:
581: /* -k: if true, continue on unaffected portions of the graph when an
582: * error occurs in one portion */
583: Boolean keepgoing;
584:
585: /* -N: execute no commands from the targets */
586: Boolean noRecursiveExecute;
587:
588: /* -n: execute almost no commands from the targets */
589: Boolean noExecute;
590:
591: /* -q: if true, we aren't supposed to really make anything, just see if
592: * the targets are out-of-date */
593: Boolean queryFlag;
594:
595: /* -r: raw mode, without loading the builtin rules. */
596: Boolean noBuiltins;
597:
598: /* -s: don't echo the shell commands before executing them */
599: Boolean beSilent;
600:
601: /* -t: touch the targets if they are out-of-date, but don't actually
602: * make them */
603: Boolean touchFlag;
604:
605: /* -[Vv]: print expanded or unexpanded selected variables */
606: PrintVarsMode printVars;
607: /* -[Vv]: the variables to print */
608: StringList *variables;
609:
610: /* -W: if true, makefile parsing warnings are treated as errors */
611: Boolean parseWarnFatal;
612:
613: /* -w: print Entering and Leaving for submakes */
614: Boolean enterFlag;
615:
616: /* -X: if true, do not export variables set on the command line to the
617: * environment. */
618: Boolean varNoExportEnv;
619:
620: /* The target names specified on the command line.
621: * Used to resolve .if make(...) statements. */
622: StringList *create;
623:
624: } CmdOpts;
625:
626: extern CmdOpts opts;
627:
1.1 cgd 628: #include "nonints.h"
629:
1.146 rillig 630: void Make_TimeStamp(GNode *, GNode *);
1.44 wiz 631: Boolean Make_OODate(GNode *);
1.144 rillig 632: void Make_ExpandUse(GNodeList *);
1.44 wiz 633: time_t Make_Recheck(GNode *);
634: void Make_HandleUse(GNode *, GNode *);
635: void Make_Update(GNode *);
636: void Make_DoAllVar(GNode *);
1.144 rillig 637: Boolean Make_Run(GNodeList *);
1.108 sjg 638: int dieQuietly(GNode *, int);
1.80 sjg 639: void PrintOnError(GNode *, const char *);
1.44 wiz 640: void Main_ExportMAKEFLAGS(Boolean);
1.102 christos 641: Boolean Main_SetObjdir(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
1.81 sjg 642: int mkTempFile(const char *, char **);
1.144 rillig 643: int str2Lst_Append(StringList *, char *, const char *);
1.126 rillig 644: void GNode_FprintDetails(FILE *, const char *, const GNode *, const char *);
1.179 rillig 645: Boolean GNode_ShouldExecute(GNode *gn);
1.155 rillig 646:
1.164 rillig 647: /* See if the node was seen on the left-hand side of a dependency operator. */
1.172 rillig 648: static MAKE_ATTR_UNUSED Boolean
1.164 rillig 649: GNode_IsTarget(const GNode *gn)
1.155 rillig 650: {
1.164 rillig 651: return (gn->type & OP_OPMASK) != 0;
1.155 rillig 652: }
653:
1.172 rillig 654: static MAKE_ATTR_UNUSED const char *
655: GNode_Path(const GNode *gn)
656: {
657: return gn->path != NULL ? gn->path : gn->name;
658: }
659:
1.178 rillig 660: static MAKE_ATTR_UNUSED const char *
661: GNode_VarTarget(GNode *gn) { return Var_ValueDirect(TARGET, gn); }
662: static MAKE_ATTR_UNUSED const char *
663: GNode_VarOodate(GNode *gn) { return Var_ValueDirect(OODATE, gn); }
664: static MAKE_ATTR_UNUSED const char *
665: GNode_VarAllsrc(GNode *gn) { return Var_ValueDirect(ALLSRC, gn); }
666: static MAKE_ATTR_UNUSED const char *
667: GNode_VarImpsrc(GNode *gn) { return Var_ValueDirect(IMPSRC, gn); }
668: static MAKE_ATTR_UNUSED const char *
669: GNode_VarPrefix(GNode *gn) { return Var_ValueDirect(PREFIX, gn); }
670: static MAKE_ATTR_UNUSED const char *
671: GNode_VarArchive(GNode *gn) { return Var_ValueDirect(ARCHIVE, gn); }
672: static MAKE_ATTR_UNUSED const char *
673: GNode_VarMember(GNode *gn) { return Var_ValueDirect(MEMBER, gn); }
674:
1.46 christos 675: #ifdef __GNUC__
1.148 rillig 676: #define UNCONST(ptr) ({ \
1.46 christos 677: union __unconst { \
678: const void *__cp; \
679: void *__p; \
680: } __d; \
681: __d.__cp = ptr, __d.__p; })
682: #else
1.74 christos 683: #define UNCONST(ptr) (void *)(ptr)
1.49 sjg 684: #endif
685:
1.96 pooka 686: /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */
687: #include <limits.h>
688: #ifndef MAXPATHLEN
689: #define MAXPATHLEN 4096
690: #endif
691: #ifndef PATH_MAX
692: #define PATH_MAX MAXPATHLEN
693: #endif
694:
1.103 sjg 695: #if defined(SYSV)
696: #define KILLPG(pid, sig) kill(-(pid), (sig))
697: #else
698: #define KILLPG(pid, sig) killpg((pid), (sig))
699: #endif
700:
1.139 rillig 701: static inline MAKE_ATTR_UNUSED Boolean ch_isalnum(char ch)
702: { return isalnum((unsigned char)ch) != 0; }
703: static inline MAKE_ATTR_UNUSED Boolean ch_isalpha(char ch)
704: { return isalpha((unsigned char)ch) != 0; }
705: static inline MAKE_ATTR_UNUSED Boolean ch_isdigit(char ch)
706: { return isdigit((unsigned char)ch) != 0; }
707: static inline MAKE_ATTR_UNUSED Boolean ch_isspace(char ch)
708: { return isspace((unsigned char)ch) != 0; }
709: static inline MAKE_ATTR_UNUSED Boolean ch_isupper(char ch)
710: { return isupper((unsigned char)ch) != 0; }
711: static inline MAKE_ATTR_UNUSED char ch_tolower(char ch)
712: { return (char)tolower((unsigned char)ch); }
713: static inline MAKE_ATTR_UNUSED char ch_toupper(char ch)
714: { return (char)toupper((unsigned char)ch); }
715:
1.155 rillig 716: static inline MAKE_ATTR_UNUSED void
717: cpp_skip_whitespace(const char **pp)
718: {
719: while (ch_isspace(**pp))
720: (*pp)++;
721: }
722:
723: static inline MAKE_ATTR_UNUSED void
724: pp_skip_whitespace(char **pp)
725: {
726: while (ch_isspace(**pp))
727: (*pp)++;
728: }
729:
1.160 rillig 730: #ifdef MAKE_NATIVE
731: # include <sys/cdefs.h>
732: # ifndef lint
733: # define MAKE_RCSID(id) __RCSID(id)
734: # endif
1.142 rillig 735: #else
1.160 rillig 736: # define MAKE_RCSID(id) static volatile char rcsid[] = id
1.142 rillig 737: #endif
738:
1.116 rillig 739: #endif /* MAKE_MAKE_H */
CVSweb <webmaster@jp.NetBSD.org>