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