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