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