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