Home | History | Annotate | Line # | Download | only in make
make.h revision 1.235
      1 /*	$NetBSD: make.h,v 1.235 2020/12/18 18:17:45 rillig Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1988, 1989, 1990, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * Adam de Boor.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  *	from: @(#)make.h	8.3 (Berkeley) 6/13/95
     35  */
     36 
     37 /*
     38  * Copyright (c) 1989 by Berkeley Softworks
     39  * All rights reserved.
     40  *
     41  * This code is derived from software contributed to Berkeley by
     42  * Adam de Boor.
     43  *
     44  * Redistribution and use in source and binary forms, with or without
     45  * modification, are permitted provided that the following conditions
     46  * are met:
     47  * 1. Redistributions of source code must retain the above copyright
     48  *    notice, this list of conditions and the following disclaimer.
     49  * 2. Redistributions in binary form must reproduce the above copyright
     50  *    notice, this list of conditions and the following disclaimer in the
     51  *    documentation and/or other materials provided with the distribution.
     52  * 3. All advertising materials mentioning features or use of this software
     53  *    must display the following acknowledgement:
     54  *	This product includes software developed by the University of
     55  *	California, Berkeley and its contributors.
     56  * 4. Neither the name of the University nor the names of its contributors
     57  *    may be used to endorse or promote products derived from this software
     58  *    without specific prior written permission.
     59  *
     60  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     61  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     62  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     63  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     64  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     65  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     66  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     67  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     68  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     69  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     70  * SUCH DAMAGE.
     71  *
     72  *	from: @(#)make.h	8.3 (Berkeley) 6/13/95
     73  */
     74 
     75 /*-
     76  * make.h --
     77  *	The global definitions for pmake
     78  */
     79 
     80 #ifndef MAKE_MAKE_H
     81 #define MAKE_MAKE_H
     82 
     83 #include <sys/types.h>
     84 #include <sys/param.h>
     85 #include <sys/stat.h>
     86 
     87 #include <assert.h>
     88 #include <ctype.h>
     89 #include <fcntl.h>
     90 #include <stdarg.h>
     91 #include <stdio.h>
     92 #include <stdlib.h>
     93 #include <string.h>
     94 #include <unistd.h>
     95 
     96 #ifdef BSD4_4
     97 # include <sys/cdefs.h>
     98 #endif
     99 
    100 #ifndef FD_CLOEXEC
    101 #define FD_CLOEXEC 1
    102 #endif
    103 
    104 #if defined(__GNUC__)
    105 #define MAKE_GNUC_PREREQ(x, y)						\
    106 	((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) ||			\
    107 	 (__GNUC__ > (x)))
    108 #else /* defined(__GNUC__) */
    109 #define MAKE_GNUC_PREREQ(x, y)	0
    110 #endif /* defined(__GNUC__) */
    111 
    112 #if MAKE_GNUC_PREREQ(2, 7)
    113 #define MAKE_ATTR_UNUSED	__attribute__((__unused__))
    114 #else
    115 #define MAKE_ATTR_UNUSED	/* delete */
    116 #endif
    117 
    118 #if MAKE_GNUC_PREREQ(2, 5)
    119 #define MAKE_ATTR_DEAD		__attribute__((__noreturn__))
    120 #elif defined(__GNUC__)
    121 #define MAKE_ATTR_DEAD		__volatile
    122 #else
    123 #define MAKE_ATTR_DEAD		/* delete */
    124 #endif
    125 
    126 #if MAKE_GNUC_PREREQ(2, 7)
    127 #define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg)	\
    128 	    __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
    129 #else
    130 #define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg)	/* delete */
    131 #endif
    132 
    133 #define MAKE_INLINE static inline MAKE_ATTR_UNUSED
    134 
    135 /*
    136  * A boolean type is defined as an integer, not an enum, for historic reasons.
    137  * The only allowed values are the constants TRUE and FALSE (1 and 0).
    138  */
    139 #if defined(USE_C99_BOOLEAN)
    140 #include <stdbool.h>
    141 typedef bool Boolean;
    142 #define FALSE false
    143 #define TRUE true
    144 #elif defined(USE_DOUBLE_BOOLEAN)
    145 /* During development, to find type mismatches in function declarations. */
    146 typedef double Boolean;
    147 #define TRUE 1.0
    148 #define FALSE 0.0
    149 #elif defined(USE_UCHAR_BOOLEAN)
    150 /* During development, to find code that depends on the exact value of TRUE or
    151  * that stores other values in Boolean variables. */
    152 typedef unsigned char Boolean;
    153 #define TRUE ((unsigned char)0xFF)
    154 #define FALSE ((unsigned char)0x00)
    155 #elif defined(USE_CHAR_BOOLEAN)
    156 /* During development, to find code that uses a boolean as array index, via
    157  * -Wchar-subscripts. */
    158 typedef char Boolean;
    159 #define TRUE ((char)-1)
    160 #define FALSE ((char)0x00)
    161 #elif defined(USE_ENUM_BOOLEAN)
    162 typedef enum Boolean { FALSE, TRUE } Boolean;
    163 #else
    164 typedef int Boolean;
    165 #ifndef TRUE
    166 #define TRUE	1
    167 #endif
    168 #ifndef FALSE
    169 #define FALSE	0
    170 #endif
    171 #endif
    172 
    173 #include "lst.h"
    174 #include "enum.h"
    175 #include "hash.h"
    176 #include "config.h"
    177 #include "buf.h"
    178 #include "make_malloc.h"
    179 
    180 /*
    181  * The typical flow of states is:
    182  *
    183  * The direct successful path:
    184  * UNMADE -> BEINGMADE -> MADE.
    185  *
    186  * The direct error path:
    187  * UNMADE -> BEINGMADE -> ERROR.
    188  *
    189  * The successful path when dependencies need to be made first:
    190  * UNMADE -> DEFERRED -> REQUESTED -> BEINGMADE -> MADE.
    191  *
    192  * A node that has dependencies, and one of the dependencies cannot be made:
    193  * UNMADE -> DEFERRED -> ABORTED.
    194  *
    195  * A node that turns out to be up-to-date:
    196  * UNMADE -> BEINGMADE -> UPTODATE.
    197  */
    198 typedef enum GNodeMade {
    199 	/* Not examined yet. */
    200 	UNMADE,
    201 	/* The node has been examined but is not yet ready since its
    202 	 * dependencies have to be made first. */
    203 	DEFERRED,
    204 
    205 	/* The node is on the toBeMade list. */
    206 	REQUESTED,
    207 
    208 	/* The node is already being made. Trying to build a node in this
    209 	 * state indicates a cycle in the graph. */
    210 	BEINGMADE,
    211 
    212 	/* Was out-of-date and has been made. */
    213 	MADE,
    214 	/* Was already up-to-date, does not need to be made. */
    215 	UPTODATE,
    216 	/* An error occurred while it was being made.
    217 	 * Used only in compat mode. */
    218 	ERROR,
    219 	/* The target was aborted due to an error making a dependency.
    220 	 * Used only in compat mode. */
    221 	ABORTED
    222 } GNodeMade;
    223 
    224 /* The OP_ constants are used when parsing a dependency line as a way of
    225  * communicating to other parts of the program the way in which a target
    226  * should be made.
    227  *
    228  * Some of the OP_ constants can be combined, others cannot. */
    229 typedef enum GNodeType {
    230 	OP_NONE		= 0,
    231 
    232 	/* The dependency operator ':' is the most common one.  The commands
    233 	 * of this node are executed if any child is out-of-date. */
    234 	OP_DEPENDS	= 1 << 0,
    235 	/* The dependency operator '!' always executes its commands, even if
    236 	 * its children are up-to-date. */
    237 	OP_FORCE	= 1 << 1,
    238 	/* The dependency operator '::' behaves like ':', except that it
    239 	 * allows multiple dependency groups to be defined.  Each of these
    240 	 * groups is executed on its own, independently from the others.
    241 	 * Each individual dependency group is called a cohort. */
    242 	OP_DOUBLEDEP	= 1 << 2,
    243 
    244 	/* Matches the dependency operators ':', '!' and '::'. */
    245 	OP_OPMASK	= OP_DEPENDS | OP_FORCE | OP_DOUBLEDEP,
    246 
    247 	/* Don't care if the target doesn't exist and can't be created. */
    248 	OP_OPTIONAL	= 1 << 3,
    249 	/* Use associated commands for parents. */
    250 	OP_USE		= 1 << 4,
    251 	/* Target is never out of date, but always execute commands anyway.
    252 	 * Its time doesn't matter, so it has none...sort of. */
    253 	OP_EXEC		= 1 << 5,
    254 	/* Ignore non-zero exit status from shell commands when creating the
    255 	 * node. */
    256 	OP_IGNORE	= 1 << 6,
    257 	/* Don't remove the target when interrupted. */
    258 	OP_PRECIOUS	= 1 << 7,
    259 	/* Don't echo commands when executed. */
    260 	OP_SILENT	= 1 << 8,
    261 	/* Target is a recursive make so its commands should always be
    262 	 * executed when it is out of date, regardless of the state of the
    263 	 * -n or -t flags. */
    264 	OP_MAKE		= 1 << 9,
    265 	/* Target is out-of-date only if any of its children was out-of-date. */
    266 	OP_JOIN		= 1 << 10,
    267 	/* Assume the children of the node have been already made. */
    268 	OP_MADE		= 1 << 11,
    269 	/* Special .BEGIN, .END or .INTERRUPT. */
    270 	OP_SPECIAL	= 1 << 12,
    271 	/* Like .USE, only prepend commands. */
    272 	OP_USEBEFORE	= 1 << 13,
    273 	/* The node is invisible to its parents. I.e. it doesn't show up in
    274 	 * the parents' local variables (.IMPSRC, .ALLSRC). */
    275 	OP_INVISIBLE	= 1 << 14,
    276 	/* The node does not become the main target, even if it is the first
    277 	 * target in the first makefile. */
    278 	OP_NOTMAIN	= 1 << 15,
    279 	/* Not a file target; run always. */
    280 	OP_PHONY	= 1 << 16,
    281 	/* Don't search for the file in the path. */
    282 	OP_NOPATH	= 1 << 17,
    283 	/* In a dependency line "target: source1 .WAIT source2", source1 is
    284 	 * made first, including its children.  Once that is finished,
    285 	 * source2 is made, including its children.  The .WAIT keyword may
    286 	 * appear more than once in a single dependency declaration. */
    287 	OP_WAIT		= 1 << 18,
    288 	/* .NOMETA do not create a .meta file */
    289 	OP_NOMETA	= 1 << 19,
    290 	/* .META we _do_ want a .meta file */
    291 	OP_META		= 1 << 20,
    292 	/* Do not compare commands in .meta file */
    293 	OP_NOMETA_CMP	= 1 << 21,
    294 	/* Possibly a submake node */
    295 	OP_SUBMAKE	= 1 << 22,
    296 
    297 	/* Attributes applied by PMake */
    298 
    299 	/* The node is a transformation rule, such as ".c.o". */
    300 	OP_TRANSFORM	= 1 << 30,
    301 	/* Target is a member of an archive */
    302 	/* XXX: How does this differ from OP_ARCHV? */
    303 	OP_MEMBER	= 1 << 29,
    304 	/* The node is a library,
    305 	 * its name has the form "-l<libname>" */
    306 	OP_LIB		= 1 << 28,
    307 	/* The node is an archive member,
    308 	 * its name has the form "archive(member)" */
    309 	/* XXX: How does this differ from OP_MEMBER? */
    310 	OP_ARCHV	= 1 << 27,
    311 	/* Target has all the commands it should. Used when parsing to catch
    312 	 * multiple command groups for a target.  Only applies to the
    313 	 * dependency operators ':' and '!', but not to '::'. */
    314 	OP_HAS_COMMANDS	= 1 << 26,
    315 	/* The special command "..." has been seen. All further commands from
    316 	 * this node will be saved on the .END node instead, to be executed at
    317 	 * the very end. */
    318 	OP_SAVE_CMDS	= 1 << 25,
    319 	/* Already processed by Suff_FindDeps, to find dependencies from
    320 	 * suffix transformation rules. */
    321 	OP_DEPS_FOUND	= 1 << 24,
    322 	/* Node found while expanding .ALLSRC */
    323 	OP_MARK		= 1 << 23,
    324 
    325 	OP_NOTARGET	= OP_NOTMAIN | OP_USE | OP_EXEC | OP_TRANSFORM
    326 } GNodeType;
    327 
    328 typedef enum GNodeFlags {
    329 	GNF_NONE	= 0,
    330 	/* this target needs to be (re)made */
    331 	REMAKE		= 0x0001,
    332 	/* children of this target were made */
    333 	CHILDMADE	= 0x0002,
    334 	/* children don't exist, and we pretend made */
    335 	FORCE		= 0x0004,
    336 	/* Set by Make_ProcessWait() */
    337 	DONE_WAIT	= 0x0008,
    338 	/* Build requested by .ORDER processing */
    339 	DONE_ORDER	= 0x0010,
    340 	/* Node created from .depend */
    341 	FROM_DEPEND	= 0x0020,
    342 	/* We do it once only */
    343 	DONE_ALLSRC	= 0x0040,
    344 	/* Used by MakePrintStatus */
    345 	CYCLE		= 0x1000,
    346 	/* Used by MakePrintStatus */
    347 	DONECYCLE	= 0x2000,
    348 	/* Internal use only */
    349 	INTERNAL	= 0x4000
    350 } GNodeFlags;
    351 
    352 typedef struct List StringList;
    353 typedef struct ListNode StringListNode;
    354 
    355 typedef struct List GNodeList;
    356 typedef struct ListNode GNodeListNode;
    357 
    358 typedef struct List /* of CachedDir */ SearchPath;
    359 
    360 /* A graph node represents a target that can possibly be made, including its
    361  * relation to other targets and a lot of other details. */
    362 typedef struct GNode {
    363 	/* The target's name, such as "clean" or "make.c" */
    364 	char *name;
    365 	/* The unexpanded name of a .USE node */
    366 	char *uname;
    367 	/* The full pathname of the file belonging to the target.
    368 	 * XXX: What about .PHONY targets? These don't have an associated
    369 	 * path. */
    370 	char *path;
    371 
    372 	/* The type of operator used to define the sources (see the OP flags
    373 	 * below).
    374 	 * XXX: This looks like a wild mixture of type and flags. */
    375 	GNodeType type;
    376 	GNodeFlags flags;
    377 
    378 	/* The state of processing on this node */
    379 	GNodeMade made;
    380 	/* The number of unmade children */
    381 	int unmade;
    382 
    383 	/* The modification time; 0 means the node does not have a
    384 	 * corresponding file; see GNode_IsOODate. */
    385 	time_t mtime;
    386 	struct GNode *youngestChild;
    387 
    388 	/* The GNodes for which this node is an implied source. May be empty.
    389 	 * For example, when there is an inference rule for .c.o, the node for
    390 	 * file.c has the node for file.o in this list. */
    391 	GNodeList implicitParents;
    392 
    393 	/* The nodes that depend on this one, or in other words, the nodes for
    394 	 * which this is a source. */
    395 	GNodeList parents;
    396 	/* The nodes on which this one depends. */
    397 	GNodeList children;
    398 
    399 	/* .ORDER nodes we need made. The nodes that must be made (if they're
    400 	 * made) before this node can be made, but that do not enter into the
    401 	 * datedness of this node. */
    402 	GNodeList order_pred;
    403 	/* .ORDER nodes who need us. The nodes that must be made (if they're
    404 	 * made at all) after this node is made, but that do not depend on
    405 	 * this node, in the normal sense. */
    406 	GNodeList order_succ;
    407 
    408 	/* Other nodes of the same name, for the '::' dependency operator. */
    409 	GNodeList cohorts;
    410 	/* The "#n" suffix for this cohort, or "" for other nodes */
    411 	char cohort_num[8];
    412 	/* The number of unmade instances on the cohorts list */
    413 	int unmade_cohorts;
    414 	/* Pointer to the first instance of a '::' node; only set when on a
    415 	 * cohorts list */
    416 	struct GNode *centurion;
    417 
    418 	/* Last time (sequence number) we tried to make this node */
    419 	unsigned int checked_seqno;
    420 
    421 	/* The "local" variables that are specific to this target and this
    422 	 * target only, such as $@, $<, $?.
    423 	 *
    424 	 * Also used for the global variable scopes VAR_GLOBAL, VAR_CMDLINE,
    425 	 * VAR_INTERNAL, which contain variables with arbitrary names. */
    426 	HashTable /* of Var pointer */ vars;
    427 
    428 	/* The commands to be given to a shell to create this target. */
    429 	StringList commands;
    430 
    431 	/* Suffix for the node (determined by Suff_FindDeps and opaque to
    432 	 * everyone but the Suff module) */
    433 	struct Suffix *suffix;
    434 
    435 	/* Filename where the GNode got defined */
    436 	/* XXX: What is the lifetime of this string? */
    437 	const char *fname;
    438 	/* Line number where the GNode got defined */
    439 	int lineno;
    440 } GNode;
    441 
    442 /* Error levels for diagnostics during parsing. */
    443 typedef enum ParseErrorLevel {
    444 	/* Exit when the current top-level makefile has been parsed
    445 	 * completely. */
    446 	PARSE_FATAL = 1,
    447 	/* Print "warning"; may be upgraded to fatal by the -w option. */
    448 	PARSE_WARNING,
    449 	/* Informational, mainly used during development of makefiles. */
    450 	PARSE_INFO
    451 } ParseErrorLevel;
    452 
    453 /*
    454  * Values returned by Cond_EvalLine and Cond_EvalCondition.
    455  */
    456 typedef enum CondEvalResult {
    457 	COND_PARSE,		/* Parse the next lines */
    458 	COND_SKIP,		/* Skip the next lines */
    459 	COND_INVALID		/* Not a conditional statement */
    460 } CondEvalResult;
    461 
    462 /* Names of the variables that are "local" to a specific target. */
    463 #define TARGET	"@"	/* Target of dependency */
    464 #define OODATE	"?"	/* All out-of-date sources */
    465 #define ALLSRC	">"	/* All sources */
    466 #define IMPSRC	"<"	/* Source implied by transformation */
    467 #define PREFIX	"*"	/* Common prefix */
    468 #define ARCHIVE	"!"	/* Archive in "archive(member)" syntax */
    469 #define MEMBER	"%"	/* Member in "archive(member)" syntax */
    470 
    471 /*
    472  * Global Variables
    473  */
    474 
    475 /* True if every target is precious */
    476 extern Boolean allPrecious;
    477 /* True if failed targets should be deleted */
    478 extern Boolean deleteOnError;
    479 /* TRUE while processing .depend */
    480 extern Boolean doing_depend;
    481 /* .DEFAULT rule */
    482 extern GNode *defaultNode;
    483 
    484 /* Variables defined internally by make which should not override those set
    485  * by makefiles. */
    486 extern GNode *VAR_INTERNAL;
    487 /* Variables defined in a global context, e.g in the Makefile itself. */
    488 extern GNode *VAR_GLOBAL;
    489 /* Variables defined on the command line. */
    490 extern GNode *VAR_CMDLINE;
    491 
    492 /* Value returned by Var_Parse when an error is encountered. It actually
    493  * points to an empty string, so naive callers needn't worry about it. */
    494 extern char var_Error[];
    495 
    496 /* The time at the start of this whole process */
    497 extern time_t now;
    498 
    499 /*
    500  * If FALSE (the default behavior), undefined subexpressions in a variable
    501  * expression are discarded.  If TRUE (only during variable assignments using
    502  * the ':=' assignment operator, no matter how deeply nested), they are
    503  * preserved and possibly expanded later when the variable from the
    504  * subexpression has been defined.
    505  *
    506  * Example for a ':=' assignment:
    507  *	CFLAGS = $(.INCLUDES)
    508  *	CFLAGS := -I.. $(CFLAGS)
    509  *	# If .INCLUDES (an undocumented special variable, by the way) is
    510  *	# still undefined, the updated CFLAGS becomes "-I.. $(.INCLUDES)".
    511  */
    512 extern Boolean preserveUndefined;
    513 
    514 /* The list of directories to search when looking for targets (set by the
    515  * special target .PATH). */
    516 extern SearchPath dirSearchPath;
    517 /* Used for .include "...". */
    518 extern SearchPath *parseIncPath;
    519 /* Used for .include <...>, for the built-in sys.mk and makefiles from the
    520  * command line arguments. */
    521 extern SearchPath *sysIncPath;
    522 /* The default for sysIncPath. */
    523 extern SearchPath *defSysIncPath;
    524 
    525 /* Startup directory */
    526 extern char curdir[];
    527 /* The basename of the program name, suffixed with [n] for sub-makes.  */
    528 extern const char *progname;
    529 /* Name of the .depend makefile */
    530 extern char *makeDependfile;
    531 /* If we replaced environ, this will be non-NULL. */
    532 extern char **savedEnv;
    533 
    534 extern int makelevel;
    535 
    536 /*
    537  * We cannot vfork() in a child of vfork().
    538  * Most systems do not enforce this but some do.
    539  */
    540 #define vFork() ((getpid() == myPid) ? vfork() : fork())
    541 extern pid_t myPid;
    542 
    543 #define MAKEFLAGS	".MAKEFLAGS"
    544 #define MAKEOVERRIDES	".MAKEOVERRIDES"
    545 /* prefix when printing the target of a job */
    546 #define MAKE_JOB_PREFIX	".MAKE.JOB.PREFIX"
    547 #define MAKE_EXPORTED	".MAKE.EXPORTED"	/* exported variables */
    548 #define MAKE_MAKEFILES	".MAKE.MAKEFILES"	/* all loaded makefiles */
    549 #define MAKE_LEVEL	".MAKE.LEVEL"		/* recursion level */
    550 #define MAKE_MAKEFILE_PREFERENCE ".MAKE.MAKEFILE_PREFERENCE"
    551 #define MAKE_DEPENDFILE	".MAKE.DEPENDFILE"	/* .depend */
    552 #define MAKE_MODE	".MAKE.MODE"
    553 #ifndef MAKE_LEVEL_ENV
    554 # define MAKE_LEVEL_ENV	"MAKELEVEL"
    555 #endif
    556 
    557 typedef enum DebugFlags {
    558 	DEBUG_NONE	= 0,
    559 	DEBUG_ARCH	= 1 << 0,
    560 	DEBUG_COND	= 1 << 1,
    561 	DEBUG_CWD	= 1 << 2,
    562 	DEBUG_DIR	= 1 << 3,
    563 	DEBUG_ERROR	= 1 << 4,
    564 	DEBUG_FOR	= 1 << 5,
    565 	DEBUG_GRAPH1	= 1 << 6,
    566 	DEBUG_GRAPH2	= 1 << 7,
    567 	DEBUG_GRAPH3	= 1 << 8,
    568 	DEBUG_HASH	= 1 << 9,
    569 	DEBUG_JOB	= 1 << 10,
    570 	DEBUG_LOUD	= 1 << 11,
    571 	DEBUG_MAKE	= 1 << 12,
    572 	DEBUG_META	= 1 << 13,
    573 	DEBUG_PARSE	= 1 << 14,
    574 	DEBUG_SCRIPT	= 1 << 15,
    575 	DEBUG_SHELL	= 1 << 16,
    576 	DEBUG_SUFF	= 1 << 17,
    577 	DEBUG_TARG	= 1 << 18,
    578 	DEBUG_VAR	= 1 << 19,
    579 	DEBUG_ALL	= (1 << 20) - 1
    580 } DebugFlags;
    581 
    582 #define CONCAT(a, b) a##b
    583 
    584 #define DEBUG(module) (opts.debug & CONCAT(DEBUG_,module))
    585 
    586 void debug_printf(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
    587 
    588 #define DEBUG_IMPL(module, args) \
    589 	do { \
    590 		if (DEBUG(module)) \
    591 			debug_printf args; \
    592 	} while (0)
    593 
    594 #define DEBUG0(module, text) \
    595 	DEBUG_IMPL(module, ("%s", text))
    596 #define DEBUG1(module, fmt, arg1) \
    597 	DEBUG_IMPL(module, (fmt, arg1))
    598 #define DEBUG2(module, fmt, arg1, arg2) \
    599 	DEBUG_IMPL(module, (fmt, arg1, arg2))
    600 #define DEBUG3(module, fmt, arg1, arg2, arg3) \
    601 	DEBUG_IMPL(module, (fmt, arg1, arg2, arg3))
    602 #define DEBUG4(module, fmt, arg1, arg2, arg3, arg4) \
    603 	DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4))
    604 #define DEBUG5(module, fmt, arg1, arg2, arg3, arg4, arg5) \
    605 	DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4, arg5))
    606 
    607 typedef enum PrintVarsMode {
    608 	PVM_NONE,
    609 	PVM_UNEXPANDED,
    610 	PVM_EXPANDED
    611 } PrintVarsMode;
    612 
    613 /* Command line options */
    614 typedef struct CmdOpts {
    615 	/* -B: whether we are make compatible */
    616 	Boolean compatMake;
    617 
    618 	/* -d: debug control: There is one bit per module.  It is up to the
    619 	 * module what debug information to print. */
    620 	DebugFlags debug;
    621 
    622 	/* -df: debug output is written here - default stderr */
    623 	FILE *debug_file;
    624 
    625 	/* -dL: lint mode
    626 	 *
    627 	 * Runs make in strict mode, with additional checks and better error
    628 	 * handling. */
    629 	Boolean lint;
    630 
    631 	/* -dV: for the -V option, print unexpanded variable values */
    632 	Boolean debugVflag;
    633 
    634 	/* -e: check environment variables before global variables */
    635 	Boolean checkEnvFirst;
    636 
    637 	/* -f: the makefiles to read */
    638 	StringList makefiles;
    639 
    640 	/* -i: if true, ignore all errors from shell commands */
    641 	Boolean ignoreErrors;
    642 
    643 	/* -j: the maximum number of jobs that can run in parallel;
    644 	 * this is coordinated with the submakes */
    645 	int maxJobs;
    646 
    647 	/* -k: if true and an error occurs while making a node, continue
    648 	 * making nodes that do not depend on the erroneous node */
    649 	Boolean keepgoing;
    650 
    651 	/* -N: execute no commands from the targets */
    652 	Boolean noRecursiveExecute;
    653 
    654 	/* -n: execute almost no commands from the targets */
    655 	Boolean noExecute;
    656 
    657 	/* -q: if true, we aren't supposed to really make anything, just see
    658 	 * if the targets are out-of-date */
    659 	Boolean queryFlag;
    660 
    661 	/* -r: raw mode, without loading the builtin rules. */
    662 	Boolean noBuiltins;
    663 
    664 	/* -s: don't echo the shell commands before executing them */
    665 	Boolean beSilent;
    666 
    667 	/* -t: touch the targets if they are out-of-date, but don't actually
    668 	 * make them */
    669 	Boolean touchFlag;
    670 
    671 	/* -[Vv]: print expanded or unexpanded selected variables */
    672 	PrintVarsMode printVars;
    673 	/* -[Vv]: the variables to print */
    674 	StringList variables;
    675 
    676 	/* -W: if true, makefile parsing warnings are treated as errors */
    677 	Boolean parseWarnFatal;
    678 
    679 	/* -w: print Entering and Leaving for submakes */
    680 	Boolean enterFlag;
    681 
    682 	/* -X: if true, do not export variables set on the command line to the
    683 	 * environment. */
    684 	Boolean varNoExportEnv;
    685 
    686 	/* The target names specified on the command line.
    687 	 * Used to resolve .if make(...) statements. */
    688 	StringList create;
    689 
    690 } CmdOpts;
    691 
    692 extern CmdOpts opts;
    693 
    694 #include "nonints.h"
    695 
    696 void GNode_UpdateYoungestChild(GNode *, GNode *);
    697 Boolean GNode_IsOODate(GNode *);
    698 void Make_ExpandUse(GNodeList *);
    699 time_t Make_Recheck(GNode *);
    700 void Make_HandleUse(GNode *, GNode *);
    701 void Make_Update(GNode *);
    702 void Make_DoAllVar(GNode *);
    703 Boolean Make_Run(GNodeList *);
    704 Boolean shouldDieQuietly(GNode *, int);
    705 void PrintOnError(GNode *, const char *);
    706 void Main_ExportMAKEFLAGS(Boolean);
    707 Boolean Main_SetObjdir(Boolean, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
    708 int mkTempFile(const char *, char **);
    709 int str2Lst_Append(StringList *, char *);
    710 void GNode_FprintDetails(FILE *, const char *, const GNode *, const char *);
    711 Boolean GNode_ShouldExecute(GNode *gn);
    712 
    713 /* See if the node was seen on the left-hand side of a dependency operator. */
    714 MAKE_INLINE Boolean
    715 GNode_IsTarget(const GNode *gn)
    716 {
    717 	return (gn->type & OP_OPMASK) != 0;
    718 }
    719 
    720 MAKE_INLINE const char *
    721 GNode_Path(const GNode *gn)
    722 {
    723 	return gn->path != NULL ? gn->path : gn->name;
    724 }
    725 
    726 MAKE_INLINE Boolean
    727 GNode_IsWaitingFor(const GNode *gn)
    728 {
    729 	return (gn->flags & REMAKE) && gn->made <= REQUESTED;
    730 }
    731 
    732 MAKE_INLINE Boolean
    733 GNode_IsReady(const GNode *gn)
    734 {
    735 	return gn->made > DEFERRED;
    736 }
    737 
    738 MAKE_INLINE Boolean
    739 GNode_IsDone(const GNode *gn)
    740 {
    741 	return gn->made >= MADE;
    742 }
    743 
    744 MAKE_INLINE Boolean
    745 GNode_IsError(const GNode *gn)
    746 {
    747 	return gn->made == ERROR || gn->made == ABORTED;
    748 }
    749 
    750 MAKE_INLINE const char *
    751 GNode_VarTarget(GNode *gn) { return Var_ValueDirect(TARGET, gn); }
    752 MAKE_INLINE const char *
    753 GNode_VarOodate(GNode *gn) { return Var_ValueDirect(OODATE, gn); }
    754 MAKE_INLINE const char *
    755 GNode_VarAllsrc(GNode *gn) { return Var_ValueDirect(ALLSRC, gn); }
    756 MAKE_INLINE const char *
    757 GNode_VarImpsrc(GNode *gn) { return Var_ValueDirect(IMPSRC, gn); }
    758 MAKE_INLINE const char *
    759 GNode_VarPrefix(GNode *gn) { return Var_ValueDirect(PREFIX, gn); }
    760 MAKE_INLINE const char *
    761 GNode_VarArchive(GNode *gn) { return Var_ValueDirect(ARCHIVE, gn); }
    762 MAKE_INLINE const char *
    763 GNode_VarMember(GNode *gn) { return Var_ValueDirect(MEMBER, gn); }
    764 
    765 #ifdef __GNUC__
    766 #define UNCONST(ptr)	({		\
    767     union __unconst {			\
    768 	const void *__cp;		\
    769 	void *__p;			\
    770     } __d;				\
    771     __d.__cp = ptr, __d.__p; })
    772 #else
    773 #define UNCONST(ptr)	(void *)(ptr)
    774 #endif
    775 
    776 /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */
    777 #include <limits.h>
    778 #ifndef MAXPATHLEN
    779 #define MAXPATHLEN	4096
    780 #endif
    781 #ifndef PATH_MAX
    782 #define PATH_MAX	MAXPATHLEN
    783 #endif
    784 
    785 #if defined(SYSV)
    786 #define KILLPG(pid, sig) kill(-(pid), (sig))
    787 #else
    788 #define KILLPG(pid, sig) killpg((pid), (sig))
    789 #endif
    790 
    791 MAKE_INLINE Boolean
    792 ch_isalnum(char ch) { return isalnum((unsigned char)ch) != 0; }
    793 MAKE_INLINE Boolean
    794 ch_isalpha(char ch) { return isalpha((unsigned char)ch) != 0; }
    795 MAKE_INLINE Boolean
    796 ch_isdigit(char ch) { return isdigit((unsigned char)ch) != 0; }
    797 MAKE_INLINE Boolean
    798 ch_isspace(char ch) { return isspace((unsigned char)ch) != 0; }
    799 MAKE_INLINE Boolean
    800 ch_isupper(char ch) { return isupper((unsigned char)ch) != 0; }
    801 MAKE_INLINE char
    802 ch_tolower(char ch) { return (char)tolower((unsigned char)ch); }
    803 MAKE_INLINE char
    804 ch_toupper(char ch) { return (char)toupper((unsigned char)ch); }
    805 
    806 MAKE_INLINE void
    807 cpp_skip_whitespace(const char **pp)
    808 {
    809 	while (ch_isspace(**pp))
    810 		(*pp)++;
    811 }
    812 
    813 MAKE_INLINE void
    814 cpp_skip_hspace(const char **pp)
    815 {
    816 	while (**pp == ' ' || **pp == '\t')
    817 		(*pp)++;
    818 }
    819 
    820 MAKE_INLINE void
    821 pp_skip_whitespace(char **pp)
    822 {
    823 	while (ch_isspace(**pp))
    824 		(*pp)++;
    825 }
    826 
    827 MAKE_INLINE void
    828 pp_skip_hspace(char **pp)
    829 {
    830 	while (**pp == ' ' || **pp == '\t')
    831 		(*pp)++;
    832 }
    833 
    834 #ifdef MAKE_NATIVE
    835 #  include <sys/cdefs.h>
    836 #  ifndef lint
    837 #    define MAKE_RCSID(id) __RCSID(id)
    838 #  endif
    839 #elif defined(MAKE_ALL_IN_ONE)
    840 #  if defined(__COUNTER__)
    841 #    define MAKE_RCSID_CONCAT(x, y) CONCAT(x, y)
    842 #    define MAKE_RCSID(id) static volatile char \
    843 	MAKE_RCSID_CONCAT(rcsid_, __COUNTER__)[] = id
    844 #  else
    845 #    define MAKE_RCSID(id) extern void do_not_define_rcsid(void)
    846 #  endif
    847 #else
    848 #  define MAKE_RCSID(id) static volatile char rcsid[] = id
    849 #endif
    850 
    851 #endif /* MAKE_MAKE_H */
    852