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