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