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