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