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