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