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