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