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