Annotation of src/usr.bin/make/make.h, Revision 1.269
1.269 ! rillig 1: /* $NetBSD: make.h,v 1.268 2021/11/28 19:51:06 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:
1.244 rillig 75: /*
1.1 cgd 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.259 rillig 104: #if defined(__GNUC__)
1.230 rillig 105: #define MAKE_GNUC_PREREQ(x, y) \
1.52 yamt 106: ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \
107: (__GNUC__ > (x)))
108: #else /* defined(__GNUC__) */
1.230 rillig 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)
1.230 rillig 113: #define MAKE_ATTR_UNUSED __attribute__((__unused__))
1.51 jmc 114: #else
1.230 rillig 115: #define MAKE_ATTR_UNUSED /* delete */
1.51 jmc 116: #endif
1.89 joerg 117:
118: #if MAKE_GNUC_PREREQ(2, 5)
1.230 rillig 119: #define MAKE_ATTR_DEAD __attribute__((__noreturn__))
1.89 joerg 120: #elif defined(__GNUC__)
1.230 rillig 121: #define MAKE_ATTR_DEAD __volatile
1.89 joerg 122: #else
1.230 rillig 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
1.264 rillig 134:
135: /* MAKE_STATIC marks a function that may or may not be inlined. */
136: #if defined(lint)
137: /* As of 2021-07-31, NetBSD lint ignores __attribute__((unused)). */
138: #define MAKE_STATIC MAKE_INLINE
139: #else
1.262 rillig 140: #define MAKE_STATIC static MAKE_ATTR_UNUSED
1.264 rillig 141: #endif
1.205 rillig 142:
1.257 rillig 143: #if __STDC_VERSION__ >= 199901L || defined(lint) || defined(USE_C99_BOOLEAN)
1.235 rillig 144: #include <stdbool.h>
1.265 rillig 145: #elif defined(__bool_true_false_are_defined)
146: /*
147: * All files of make must be compiled with the same definition of bool.
148: * Since one of the files includes <stdbool.h>, that means the header is
149: * available on this platform. Recompile everything with -DUSE_C99_BOOLEAN.
150: */
151: #error "<stdbool.h> is included in pre-C99 mode"
152: #elif defined(bool) || defined(true) || defined(false)
153: /*
154: * In pre-C99 mode, make does not expect that bool is already defined.
155: * You need to ensure that all translation units use the same definition for
156: * bool.
157: */
158: #error "bool/true/false is defined in pre-C99 mode"
1.130 rillig 159: #else
1.265 rillig 160: typedef unsigned char bool;
1.257 rillig 161: #define true 1
162: #define false 0
1.140 rillig 163: #endif
1.127 rillig 164:
1.1 cgd 165: #include "lst.h"
1.261 rillig 166: #include "make_malloc.h"
167: #include "str.h"
1.22 mycroft 168: #include "hash.h"
1.1 cgd 169: #include "config.h"
1.3 cgd 170: #include "buf.h"
1.1 cgd 171:
1.216 rillig 172: /*
173: * The typical flow of states is:
174: *
175: * The direct successful path:
176: * UNMADE -> BEINGMADE -> MADE.
177: *
178: * The direct error path:
179: * UNMADE -> BEINGMADE -> ERROR.
180: *
181: * The successful path when dependencies need to be made first:
182: * UNMADE -> DEFERRED -> REQUESTED -> BEINGMADE -> MADE.
183: *
184: * A node that has dependencies, and one of the dependencies cannot be made:
185: * UNMADE -> DEFERRED -> ABORTED.
186: *
187: * A node that turns out to be up-to-date:
188: * UNMADE -> BEINGMADE -> UPTODATE.
189: */
1.181 rillig 190: typedef enum GNodeMade {
1.219 rillig 191: /* Not examined yet. */
192: UNMADE,
193: /* The node has been examined but is not yet ready since its
194: * dependencies have to be made first. */
195: DEFERRED,
196:
197: /* The node is on the toBeMade list. */
198: REQUESTED,
199:
200: /* The node is already being made. Trying to build a node in this
201: * state indicates a cycle in the graph. */
202: BEINGMADE,
203:
204: /* Was out-of-date and has been made. */
205: MADE,
206: /* Was already up-to-date, does not need to be made. */
207: UPTODATE,
208: /* An error occurred while it was being made.
209: * Used only in compat mode. */
210: ERROR,
211: /* The target was aborted due to an error making a dependency.
212: * Used only in compat mode. */
213: ABORTED
1.119 rillig 214: } GNodeMade;
1.1 cgd 215:
1.241 rillig 216: /*
217: * The OP_ constants are used when parsing a dependency line as a way of
1.120 rillig 218: * communicating to other parts of the program the way in which a target
219: * should be made.
220: *
1.241 rillig 221: * Some of the OP_ constants can be combined, others cannot.
1.263 rillig 222: *
223: * See the tests depsrc-*.mk and deptgt-*.mk.
1.241 rillig 224: */
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.269 ! rillig 324: typedef struct GNodeFlags {
1.219 rillig 325: /* this target needs to be (re)made */
1.268 rillig 326: bool remake:1;
1.219 rillig 327: /* children of this target were made */
1.268 rillig 328: bool childMade:1;
1.219 rillig 329: /* children don't exist, and we pretend made */
1.268 rillig 330: bool force:1;
1.219 rillig 331: /* Set by Make_ProcessWait() */
1.268 rillig 332: bool doneWait:1;
1.219 rillig 333: /* Build requested by .ORDER processing */
1.268 rillig 334: bool doneOrder:1;
1.219 rillig 335: /* Node created from .depend */
1.268 rillig 336: bool fromDepend:1;
1.219 rillig 337: /* We do it once only */
1.268 rillig 338: bool doneAllsrc:1;
1.219 rillig 339: /* Used by MakePrintStatus */
1.268 rillig 340: bool cycle:1;
1.219 rillig 341: /* Used by MakePrintStatus */
1.268 rillig 342: bool doneCycle:1;
1.119 rillig 343: } GNodeFlags;
1.1 cgd 344:
1.143 rillig 345: typedef struct List StringList;
346: typedef struct ListNode StringListNode;
1.144 rillig 347:
1.143 rillig 348: typedef struct List GNodeList;
349: typedef struct ListNode GNodeListNode;
350:
1.246 rillig 351: typedef struct SearchPath {
352: List /* of CachedDir */ dirs;
353: } SearchPath;
1.144 rillig 354:
1.241 rillig 355: /*
356: * A graph node represents a target that can possibly be made, including its
357: * relation to other targets and a lot of other details.
358: */
1.119 rillig 359: typedef struct GNode {
1.219 rillig 360: /* The target's name, such as "clean" or "make.c" */
361: char *name;
362: /* The unexpanded name of a .USE node */
363: char *uname;
364: /* The full pathname of the file belonging to the target.
365: * XXX: What about .PHONY targets? These don't have an associated
366: * path. */
367: char *path;
368:
369: /* The type of operator used to define the sources (see the OP flags
370: * below).
371: * XXX: This looks like a wild mixture of type and flags. */
372: GNodeType type;
373: GNodeFlags flags;
374:
375: /* The state of processing on this node */
376: GNodeMade made;
377: /* The number of unmade children */
378: int unmade;
379:
380: /* The modification time; 0 means the node does not have a
381: * corresponding file; see GNode_IsOODate. */
382: time_t mtime;
383: struct GNode *youngestChild;
384:
385: /* The GNodes for which this node is an implied source. May be empty.
386: * For example, when there is an inference rule for .c.o, the node for
387: * file.c has the node for file.o in this list. */
1.225 rillig 388: GNodeList implicitParents;
1.219 rillig 389:
390: /* The nodes that depend on this one, or in other words, the nodes for
391: * which this is a source. */
1.222 rillig 392: GNodeList parents;
1.219 rillig 393: /* The nodes on which this one depends. */
1.222 rillig 394: GNodeList children;
1.219 rillig 395:
396: /* .ORDER nodes we need made. The nodes that must be made (if they're
397: * made) before this node can be made, but that do not enter into the
398: * datedness of this node. */
1.223 rillig 399: GNodeList order_pred;
1.219 rillig 400: /* .ORDER nodes who need us. The nodes that must be made (if they're
401: * made at all) after this node is made, but that do not depend on
402: * this node, in the normal sense. */
1.223 rillig 403: GNodeList order_succ;
1.219 rillig 404:
1.245 rillig 405: /*
406: * Other nodes of the same name, for targets that were defined using
407: * the '::' dependency operator (OP_DOUBLEDEP).
408: */
1.224 rillig 409: GNodeList cohorts;
1.219 rillig 410: /* The "#n" suffix for this cohort, or "" for other nodes */
411: char cohort_num[8];
412: /* The number of unmade instances on the cohorts list */
413: int unmade_cohorts;
414: /* Pointer to the first instance of a '::' node; only set when on a
415: * cohorts list */
416: struct GNode *centurion;
417:
418: /* Last time (sequence number) we tried to make this node */
419: unsigned int checked_seqno;
420:
1.252 rillig 421: /*
422: * The "local" variables that are specific to this target and this
1.219 rillig 423: * target only, such as $@, $<, $?.
424: *
1.252 rillig 425: * Also used for the global variable scopes SCOPE_GLOBAL,
426: * SCOPE_CMDLINE, SCOPE_INTERNAL, which contain variables with
427: * arbitrary names.
428: */
1.219 rillig 429: HashTable /* of Var pointer */ vars;
430:
431: /* The commands to be given to a shell to create this target. */
1.221 rillig 432: StringList commands;
1.219 rillig 433:
434: /* Suffix for the node (determined by Suff_FindDeps and opaque to
435: * everyone but the Suff module) */
436: struct Suffix *suffix;
437:
438: /* Filename where the GNode got defined */
439: /* XXX: What is the lifetime of this string? */
440: const char *fname;
441: /* Line number where the GNode got defined */
442: int lineno;
1.1 cgd 443: } GNode;
444:
1.188 rillig 445: /* Error levels for diagnostics during parsing. */
1.167 rillig 446: typedef enum ParseErrorLevel {
1.219 rillig 447: /* Exit when the current top-level makefile has been parsed
448: * completely. */
449: PARSE_FATAL = 1,
450: /* Print "warning"; may be upgraded to fatal by the -w option. */
451: PARSE_WARNING,
452: /* Informational, mainly used during development of makefiles. */
453: PARSE_INFO
1.167 rillig 454: } ParseErrorLevel;
1.1 cgd 455:
456: /*
1.141 rillig 457: * Values returned by Cond_EvalLine and Cond_EvalCondition.
1.1 cgd 458: */
1.159 rillig 459: typedef enum CondEvalResult {
1.219 rillig 460: COND_PARSE, /* Parse the next lines */
461: COND_SKIP, /* Skip the next lines */
462: COND_INVALID /* Not a conditional statement */
1.113 rillig 463: } CondEvalResult;
1.1 cgd 464:
1.190 rillig 465: /* Names of the variables that are "local" to a specific target. */
1.219 rillig 466: #define TARGET "@" /* Target of dependency */
467: #define OODATE "?" /* All out-of-date sources */
468: #define ALLSRC ">" /* All sources */
469: #define IMPSRC "<" /* Source implied by transformation */
470: #define PREFIX "*" /* Common prefix */
471: #define ARCHIVE "!" /* Archive in "archive(member)" syntax */
472: #define MEMBER "%" /* Member in "archive(member)" syntax */
1.148 rillig 473:
1.1 cgd 474: /*
1.11 christos 475: * Global Variables
1.1 cgd 476: */
477:
1.190 rillig 478: /* True if every target is precious */
1.257 rillig 479: extern bool allPrecious;
1.190 rillig 480: /* True if failed targets should be deleted */
1.257 rillig 481: extern bool deleteOnError;
482: /* true while processing .depend */
483: extern bool doing_depend;
1.190 rillig 484: /* .DEFAULT rule */
1.207 rillig 485: extern GNode *defaultNode;
1.190 rillig 486:
1.241 rillig 487: /*
488: * Variables defined internally by make which should not override those set
489: * by makefiles.
490: */
1.252 rillig 491: extern GNode *SCOPE_INTERNAL;
1.255 rillig 492: /* Variables defined in a global scope, e.g in the makefile itself. */
1.252 rillig 493: extern GNode *SCOPE_GLOBAL;
1.190 rillig 494: /* Variables defined on the command line. */
1.252 rillig 495: extern GNode *SCOPE_CMDLINE;
1.190 rillig 496:
1.241 rillig 497: /*
498: * Value returned by Var_Parse when an error is encountered. It actually
499: * points to an empty string, so naive callers needn't worry about it.
500: */
1.190 rillig 501: extern char var_Error[];
502:
503: /* The time at the start of this whole process */
504: extern time_t now;
1.1 cgd 505:
1.241 rillig 506: /*
507: * The list of directories to search when looking for targets (set by the
508: * special target .PATH).
509: */
1.229 rillig 510: extern SearchPath dirSearchPath;
1.186 rillig 511: /* Used for .include "...". */
512: extern SearchPath *parseIncPath;
1.241 rillig 513: /*
1.249 rillig 514: * Used for .include <...>, for the built-in sys.mk and for makefiles from
515: * the command line arguments.
1.241 rillig 516: */
1.186 rillig 517: extern SearchPath *sysIncPath;
518: /* The default for sysIncPath. */
519: extern SearchPath *defSysIncPath;
1.32 christos 520:
1.191 rillig 521: /* Startup directory */
522: extern char curdir[];
523: /* The basename of the program name, suffixed with [n] for sub-makes. */
1.234 rillig 524: extern const char *progname;
1.248 rillig 525: extern int makelevel;
1.191 rillig 526: /* Name of the .depend makefile */
527: extern char *makeDependfile;
1.187 rillig 528: /* If we replaced environ, this will be non-NULL. */
529: extern char **savedEnv;
1.30 sommerfe 530:
1.190 rillig 531: extern pid_t myPid;
1.82 sjg 532:
1.219 rillig 533: #define MAKEFLAGS ".MAKEFLAGS"
534: #define MAKEOVERRIDES ".MAKEOVERRIDES"
535: /* prefix when printing the target of a job */
536: #define MAKE_JOB_PREFIX ".MAKE.JOB.PREFIX"
537: #define MAKE_EXPORTED ".MAKE.EXPORTED" /* exported variables */
538: #define MAKE_MAKEFILES ".MAKE.MAKEFILES" /* all loaded makefiles */
539: #define MAKE_LEVEL ".MAKE.LEVEL" /* recursion level */
1.185 rillig 540: #define MAKE_MAKEFILE_PREFERENCE ".MAKE.MAKEFILE_PREFERENCE"
1.215 rillig 541: #define MAKE_DEPENDFILE ".MAKE.DEPENDFILE" /* .depend */
1.80 sjg 542: #define MAKE_MODE ".MAKE.MODE"
1.91 sjg 543: #ifndef MAKE_LEVEL_ENV
544: # define MAKE_LEVEL_ENV "MAKELEVEL"
545: #endif
1.1 cgd 546:
1.170 rillig 547: typedef enum DebugFlags {
1.219 rillig 548: DEBUG_NONE = 0,
549: DEBUG_ARCH = 1 << 0,
550: DEBUG_COND = 1 << 1,
551: DEBUG_CWD = 1 << 2,
552: DEBUG_DIR = 1 << 3,
553: DEBUG_ERROR = 1 << 4,
554: DEBUG_FOR = 1 << 5,
555: DEBUG_GRAPH1 = 1 << 6,
556: DEBUG_GRAPH2 = 1 << 7,
557: DEBUG_GRAPH3 = 1 << 8,
558: DEBUG_HASH = 1 << 9,
559: DEBUG_JOB = 1 << 10,
560: DEBUG_LOUD = 1 << 11,
561: DEBUG_MAKE = 1 << 12,
562: DEBUG_META = 1 << 13,
563: DEBUG_PARSE = 1 << 14,
564: DEBUG_SCRIPT = 1 << 15,
565: DEBUG_SHELL = 1 << 16,
566: DEBUG_SUFF = 1 << 17,
567: DEBUG_TARG = 1 << 18,
568: DEBUG_VAR = 1 << 19,
569: DEBUG_ALL = (1 << 20) - 1
1.170 rillig 570: } DebugFlags;
571:
1.219 rillig 572: #define CONCAT(a, b) a##b
1.1 cgd 573:
1.236 rillig 574: #define DEBUG(module) ((opts.debug & CONCAT(DEBUG_, module)) != 0)
1.1 cgd 575:
1.151 rillig 576: void debug_printf(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
1.150 rillig 577:
1.232 rillig 578: #define DEBUG_IMPL(module, args) \
579: do { \
580: if (DEBUG(module)) \
581: debug_printf args; \
1.266 rillig 582: } while (false)
1.232 rillig 583:
1.149 rillig 584: #define DEBUG0(module, text) \
1.232 rillig 585: DEBUG_IMPL(module, ("%s", text))
1.149 rillig 586: #define DEBUG1(module, fmt, arg1) \
1.232 rillig 587: DEBUG_IMPL(module, (fmt, arg1))
1.149 rillig 588: #define DEBUG2(module, fmt, arg1, arg2) \
1.232 rillig 589: DEBUG_IMPL(module, (fmt, arg1, arg2))
1.149 rillig 590: #define DEBUG3(module, fmt, arg1, arg2, arg3) \
1.232 rillig 591: DEBUG_IMPL(module, (fmt, arg1, arg2, arg3))
1.149 rillig 592: #define DEBUG4(module, fmt, arg1, arg2, arg3, arg4) \
1.232 rillig 593: DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4))
1.149 rillig 594: #define DEBUG5(module, fmt, arg1, arg2, arg3, arg4, arg5) \
1.232 rillig 595: DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4, arg5))
1.149 rillig 596:
1.173 rillig 597: typedef enum PrintVarsMode {
1.219 rillig 598: PVM_NONE,
599: PVM_UNEXPANDED,
600: PVM_EXPANDED
1.173 rillig 601: } PrintVarsMode;
602:
603: /* Command line options */
604: typedef struct CmdOpts {
1.219 rillig 605: /* -B: whether we are make compatible */
1.257 rillig 606: bool compatMake;
1.173 rillig 607:
1.219 rillig 608: /* -d: debug control: There is one bit per module. It is up to the
609: * module what debug information to print. */
610: DebugFlags debug;
1.173 rillig 611:
1.219 rillig 612: /* -df: debug output is written here - default stderr */
613: FILE *debug_file;
1.173 rillig 614:
1.219 rillig 615: /* -dL: lint mode
616: *
617: * Runs make in strict mode, with additional checks and better error
618: * handling. */
1.257 rillig 619: bool strict;
1.204 rillig 620:
1.219 rillig 621: /* -dV: for the -V option, print unexpanded variable values */
1.257 rillig 622: bool debugVflag;
1.174 rillig 623:
1.219 rillig 624: /* -e: check environment variables before global variables */
1.257 rillig 625: bool checkEnvFirst;
1.173 rillig 626:
1.219 rillig 627: /* -f: the makefiles to read */
1.226 rillig 628: StringList makefiles;
1.173 rillig 629:
1.219 rillig 630: /* -i: if true, ignore all errors from shell commands */
1.257 rillig 631: bool ignoreErrors;
1.173 rillig 632:
1.219 rillig 633: /* -j: the maximum number of jobs that can run in parallel;
634: * this is coordinated with the submakes */
635: int maxJobs;
1.173 rillig 636:
1.233 rillig 637: /* -k: if true and an error occurs while making a node, continue
638: * making nodes that do not depend on the erroneous node */
1.257 rillig 639: bool keepgoing;
1.173 rillig 640:
1.219 rillig 641: /* -N: execute no commands from the targets */
1.257 rillig 642: bool noRecursiveExecute;
1.173 rillig 643:
1.219 rillig 644: /* -n: execute almost no commands from the targets */
1.257 rillig 645: bool noExecute;
1.173 rillig 646:
1.250 rillig 647: /*
648: * -q: if true, do not really make anything, just see if the targets
649: * are out-of-date
650: */
1.257 rillig 651: bool queryFlag;
1.173 rillig 652:
1.250 rillig 653: /* -r: raw mode, do not load the builtin rules. */
1.257 rillig 654: bool noBuiltins;
1.173 rillig 655:
1.219 rillig 656: /* -s: don't echo the shell commands before executing them */
1.257 rillig 657: bool beSilent;
1.173 rillig 658:
1.219 rillig 659: /* -t: touch the targets if they are out-of-date, but don't actually
660: * make them */
1.257 rillig 661: bool touchFlag;
1.173 rillig 662:
1.219 rillig 663: /* -[Vv]: print expanded or unexpanded selected variables */
664: PrintVarsMode printVars;
665: /* -[Vv]: the variables to print */
1.227 rillig 666: StringList variables;
1.173 rillig 667:
1.219 rillig 668: /* -W: if true, makefile parsing warnings are treated as errors */
1.257 rillig 669: bool parseWarnFatal;
1.173 rillig 670:
1.250 rillig 671: /* -w: print 'Entering' and 'Leaving' for submakes */
1.257 rillig 672: bool enterFlag;
1.173 rillig 673:
1.219 rillig 674: /* -X: if true, do not export variables set on the command line to the
675: * environment. */
1.257 rillig 676: bool varNoExportEnv;
1.173 rillig 677:
1.219 rillig 678: /* The target names specified on the command line.
679: * Used to resolve .if make(...) statements. */
1.228 rillig 680: StringList create;
1.173 rillig 681:
682: } CmdOpts;
683:
684: extern CmdOpts opts;
685:
1.1 cgd 686: #include "nonints.h"
687:
1.199 rillig 688: void GNode_UpdateYoungestChild(GNode *, GNode *);
1.257 rillig 689: bool GNode_IsOODate(GNode *);
1.144 rillig 690: void Make_ExpandUse(GNodeList *);
1.44 wiz 691: time_t Make_Recheck(GNode *);
692: void Make_HandleUse(GNode *, GNode *);
693: void Make_Update(GNode *);
1.260 rillig 694: void GNode_SetLocalVars(GNode *);
1.257 rillig 695: bool Make_Run(GNodeList *);
696: bool shouldDieQuietly(GNode *, int);
1.80 sjg 697: void PrintOnError(GNode *, const char *);
1.257 rillig 698: void Main_ExportMAKEFLAGS(bool);
699: bool Main_SetObjdir(bool, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
1.256 sjg 700: int mkTempFile(const char *, char *, size_t);
1.208 rillig 701: int str2Lst_Append(StringList *, char *);
1.126 rillig 702: void GNode_FprintDetails(FILE *, const char *, const GNode *, const char *);
1.257 rillig 703: bool GNode_ShouldExecute(GNode *gn);
1.155 rillig 704:
1.164 rillig 705: /* See if the node was seen on the left-hand side of a dependency operator. */
1.257 rillig 706: MAKE_INLINE bool
1.164 rillig 707: GNode_IsTarget(const GNode *gn)
1.155 rillig 708: {
1.219 rillig 709: return (gn->type & OP_OPMASK) != 0;
1.155 rillig 710: }
711:
1.205 rillig 712: MAKE_INLINE const char *
1.172 rillig 713: GNode_Path(const GNode *gn)
714: {
1.219 rillig 715: return gn->path != NULL ? gn->path : gn->name;
1.172 rillig 716: }
717:
1.257 rillig 718: MAKE_INLINE bool
1.218 rillig 719: GNode_IsWaitingFor(const GNode *gn)
720: {
1.268 rillig 721: return gn->flags.remake && gn->made <= REQUESTED;
1.218 rillig 722: }
723:
1.257 rillig 724: MAKE_INLINE bool
1.218 rillig 725: GNode_IsReady(const GNode *gn)
726: {
727: return gn->made > DEFERRED;
728: }
729:
1.257 rillig 730: MAKE_INLINE bool
1.218 rillig 731: GNode_IsDone(const GNode *gn)
732: {
733: return gn->made >= MADE;
734: }
735:
1.257 rillig 736: MAKE_INLINE bool
1.217 rillig 737: GNode_IsError(const GNode *gn)
738: {
739: return gn->made == ERROR || gn->made == ABORTED;
740: }
741:
1.205 rillig 742: MAKE_INLINE const char *
1.254 rillig 743: GNode_VarTarget(GNode *gn) { return GNode_ValueDirect(gn, TARGET); }
1.205 rillig 744: MAKE_INLINE const char *
1.254 rillig 745: GNode_VarOodate(GNode *gn) { return GNode_ValueDirect(gn, OODATE); }
1.205 rillig 746: MAKE_INLINE const char *
1.254 rillig 747: GNode_VarAllsrc(GNode *gn) { return GNode_ValueDirect(gn, ALLSRC); }
1.205 rillig 748: MAKE_INLINE const char *
1.254 rillig 749: GNode_VarImpsrc(GNode *gn) { return GNode_ValueDirect(gn, IMPSRC); }
1.205 rillig 750: MAKE_INLINE const char *
1.254 rillig 751: GNode_VarPrefix(GNode *gn) { return GNode_ValueDirect(gn, PREFIX); }
1.205 rillig 752: MAKE_INLINE const char *
1.254 rillig 753: GNode_VarArchive(GNode *gn) { return GNode_ValueDirect(gn, ARCHIVE); }
1.205 rillig 754: MAKE_INLINE const char *
1.254 rillig 755: GNode_VarMember(GNode *gn) { return GNode_ValueDirect(gn, MEMBER); }
1.178 rillig 756:
1.264 rillig 757: MAKE_INLINE void *
758: UNCONST(const void *ptr)
759: {
760: void *ret;
761: memcpy(&ret, &ptr, sizeof(ret));
762: return ret;
763: }
1.49 sjg 764:
1.96 pooka 765: /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */
766: #include <limits.h>
767: #ifndef MAXPATHLEN
768: #define MAXPATHLEN 4096
769: #endif
770: #ifndef PATH_MAX
771: #define PATH_MAX MAXPATHLEN
772: #endif
773:
1.103 sjg 774: #if defined(SYSV)
1.219 rillig 775: #define KILLPG(pid, sig) kill(-(pid), (sig))
1.103 sjg 776: #else
1.219 rillig 777: #define KILLPG(pid, sig) killpg((pid), (sig))
1.103 sjg 778: #endif
779:
1.257 rillig 780: MAKE_INLINE bool
1.195 rillig 781: ch_isalnum(char ch) { return isalnum((unsigned char)ch) != 0; }
1.257 rillig 782: MAKE_INLINE bool
1.195 rillig 783: ch_isalpha(char ch) { return isalpha((unsigned char)ch) != 0; }
1.257 rillig 784: MAKE_INLINE bool
1.195 rillig 785: ch_isdigit(char ch) { return isdigit((unsigned char)ch) != 0; }
1.257 rillig 786: MAKE_INLINE bool
1.195 rillig 787: ch_isspace(char ch) { return isspace((unsigned char)ch) != 0; }
1.257 rillig 788: MAKE_INLINE bool
1.195 rillig 789: ch_isupper(char ch) { return isupper((unsigned char)ch) != 0; }
1.205 rillig 790: MAKE_INLINE char
1.195 rillig 791: ch_tolower(char ch) { return (char)tolower((unsigned char)ch); }
1.205 rillig 792: MAKE_INLINE char
1.195 rillig 793: ch_toupper(char ch) { return (char)toupper((unsigned char)ch); }
1.139 rillig 794:
1.205 rillig 795: MAKE_INLINE void
1.155 rillig 796: cpp_skip_whitespace(const char **pp)
797: {
1.219 rillig 798: while (ch_isspace(**pp))
799: (*pp)++;
1.155 rillig 800: }
801:
1.205 rillig 802: MAKE_INLINE void
1.196 rillig 803: cpp_skip_hspace(const char **pp)
804: {
1.219 rillig 805: while (**pp == ' ' || **pp == '\t')
806: (*pp)++;
1.196 rillig 807: }
808:
1.205 rillig 809: MAKE_INLINE void
1.155 rillig 810: pp_skip_whitespace(char **pp)
811: {
1.219 rillig 812: while (ch_isspace(**pp))
813: (*pp)++;
1.155 rillig 814: }
815:
1.205 rillig 816: MAKE_INLINE void
1.197 rillig 817: pp_skip_hspace(char **pp)
818: {
1.219 rillig 819: while (**pp == ' ' || **pp == '\t')
820: (*pp)++;
1.197 rillig 821: }
822:
1.238 rillig 823: #if defined(lint)
1.249 rillig 824: # define MAKE_RCSID(id) extern void do_not_define_rcsid(void)
1.238 rillig 825: #elif defined(MAKE_NATIVE)
1.249 rillig 826: # include <sys/cdefs.h>
827: # define MAKE_RCSID(id) __RCSID(id)
1.238 rillig 828: #elif defined(MAKE_ALL_IN_ONE) && defined(__COUNTER__)
1.249 rillig 829: # define MAKE_RCSID_CONCAT(x, y) CONCAT(x, y)
830: # define MAKE_RCSID(id) static volatile char \
1.238 rillig 831: MAKE_RCSID_CONCAT(rcsid_, __COUNTER__)[] = id
1.220 rillig 832: #elif defined(MAKE_ALL_IN_ONE)
1.249 rillig 833: # define MAKE_RCSID(id) extern void do_not_define_rcsid(void)
1.142 rillig 834: #else
1.249 rillig 835: # define MAKE_RCSID(id) static volatile char rcsid[] = id
1.142 rillig 836: #endif
837:
1.116 rillig 838: #endif /* MAKE_MAKE_H */
CVSweb <webmaster@jp.NetBSD.org>