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