Home | History | Annotate | Line # | Download | only in make
      1 /*	$NetBSD: make.h,v 1.361 2025/07/06 07:11:31 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 make
     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
    109 #define MAKE_GNUC_PREREQ(x, y)	0
    110 #endif
    111 
    112 #if MAKE_GNUC_PREREQ(2, 7) || lint
    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 #if MAKE_GNUC_PREREQ(8, 0)
    140 #define MAKE_ATTR_NOINLINE		__attribute__((__noinline__))
    141 #else
    142 #define MAKE_ATTR_NOINLINE		/* delete */
    143 #endif
    144 
    145 #if __STDC_VERSION__ >= 199901L || defined(lint)
    146 #define MAKE_INLINE static inline MAKE_ATTR_UNUSED
    147 #else
    148 #define MAKE_INLINE static MAKE_ATTR_UNUSED
    149 #endif
    150 
    151 /* MAKE_STATIC marks a function that may or may not be inlined. */
    152 #if defined(lint)
    153 /* As of 2021-07-31, NetBSD lint ignores __attribute__((unused)). */
    154 #define MAKE_STATIC MAKE_INLINE
    155 #else
    156 #define MAKE_STATIC static MAKE_ATTR_UNUSED
    157 #endif
    158 
    159 #if __STDC_VERSION__ >= 199901L || defined(lint) || defined(USE_C99_BOOLEAN)
    160 #include <stdbool.h>
    161 #elif defined(__bool_true_false_are_defined)
    162 /*
    163  * All files of make must be compiled with the same definition of bool.
    164  * Since one of the files includes <stdbool.h>, that means the header is
    165  * available on this platform.  Recompile everything with -DUSE_C99_BOOLEAN.
    166  */
    167 #error "<stdbool.h> is included in pre-C99 mode"
    168 #elif defined(bool) || defined(true) || defined(false)
    169 /*
    170  * In pre-C99 mode, make does not expect that bool is already defined.
    171  * You need to ensure that all translation units use the same definition for
    172  * bool.
    173  */
    174 #error "bool/true/false is defined in pre-C99 mode"
    175 #else
    176 typedef unsigned char bool;
    177 #define true	1
    178 #define false	0
    179 #endif
    180 
    181 /*
    182  * In code coverage mode with gcc>=12, calling vfork/exec does not mark any
    183  * further code from the parent process as covered. gcc-10.5.0 is fine, as
    184  * are fork/exec calls, as well as posix_spawn.
    185  */
    186 #ifndef FORK_FUNCTION
    187 #define FORK_FUNCTION vfork
    188 #endif
    189 
    190 #include "lst.h"
    191 #include "make_malloc.h"
    192 #include "str.h"
    193 #include "hash.h"
    194 #include "config.h"
    195 #include "buf.h"
    196 
    197 /*
    198  * The typical flow of states is:
    199  *
    200  * The direct successful path:
    201  * UNMADE -> BEINGMADE -> MADE.
    202  *
    203  * The direct error path:
    204  * UNMADE -> BEINGMADE -> ERROR.
    205  *
    206  * The successful path when dependencies need to be made first:
    207  * UNMADE -> DEFERRED -> REQUESTED -> BEINGMADE -> MADE.
    208  *
    209  * A node that has dependencies, and one of the dependencies cannot be made:
    210  * UNMADE -> DEFERRED -> ABORTED.
    211  *
    212  * A node that turns out to be up-to-date:
    213  * UNMADE -> BEINGMADE -> UPTODATE.
    214  */
    215 typedef enum GNodeMade {
    216 	/* Not examined yet. */
    217 	UNMADE,
    218 	/*
    219 	 * The node has been examined but is not yet ready since its
    220 	 * dependencies have to be made first.
    221 	 */
    222 	DEFERRED,
    223 
    224 	/* The node is on the toBeMade list. */
    225 	REQUESTED,
    226 
    227 	/*
    228 	 * The node is already being made. Trying to build a node in this
    229 	 * state indicates a cycle in the graph.
    230 	 */
    231 	BEINGMADE,
    232 
    233 	/* Was out-of-date and has been made. */
    234 	MADE,
    235 	/* Was already up-to-date, does not need to be made. */
    236 	UPTODATE,
    237 	/*
    238 	 * An error occurred while it was being made. Used only in compat
    239 	 * mode.
    240 	 */
    241 	ERROR,
    242 	/*
    243 	 * The target was aborted due to an error making a dependency. Used
    244 	 * only in compat mode.
    245 	 */
    246 	ABORTED
    247 } GNodeMade;
    248 
    249 /*
    250  * The OP_ constants are used when parsing a dependency line as a way of
    251  * communicating to other parts of the program the way in which a target
    252  * should be made.
    253  *
    254  * Some of the OP_ constants can be combined, others cannot.
    255  *
    256  * See the tests depsrc-*.mk and deptgt-*.mk.
    257  */
    258 typedef enum GNodeType {
    259 	OP_NONE		= 0,
    260 
    261 	/*
    262 	 * The dependency operator ':' is the most common one.  The commands
    263 	 * of this node are executed if any child is out-of-date.
    264 	 */
    265 	OP_DEPENDS	= 1 << 0,
    266 	/*
    267 	 * The dependency operator '!' always executes its commands, even if
    268 	 * its children are up-to-date.
    269 	 */
    270 	OP_FORCE	= 1 << 1,
    271 	/*
    272 	 * The dependency operator '::' behaves like ':', except that it
    273 	 * allows multiple dependency groups to be defined.  Each of these
    274 	 * groups is executed on its own, independently from the others. Each
    275 	 * individual dependency group is called a cohort.
    276 	 */
    277 	OP_DOUBLEDEP	= 1 << 2,
    278 
    279 	/* Matches the dependency operators ':', '!' and '::'. */
    280 	OP_OPMASK	= OP_DEPENDS | OP_FORCE | OP_DOUBLEDEP,
    281 
    282 	/* Don't care if the target doesn't exist and can't be created. */
    283 	OP_OPTIONAL	= 1 << 3,
    284 	/* Use associated commands for parents. */
    285 	OP_USE		= 1 << 4,
    286 	/*
    287 	 * Target is never out of date, but always execute commands anyway.
    288 	 * Its time doesn't matter, so it has none...sort of.
    289 	 */
    290 	OP_EXEC		= 1 << 5,
    291 	/*
    292 	 * Ignore non-zero exit status from shell commands when creating the
    293 	 * node.
    294 	 */
    295 	OP_IGNORE	= 1 << 6,
    296 	/* Don't remove the target when interrupted. */
    297 	OP_PRECIOUS	= 1 << 7,
    298 	/* Don't echo commands when executed. */
    299 	OP_SILENT	= 1 << 8,
    300 	/*
    301 	 * Target is a recursive make so its commands should always be
    302 	 * executed when it is out of date, regardless of the state of the -n
    303 	 * or -t flags.
    304 	 */
    305 	OP_MAKE		= 1 << 9,
    306 	/*
    307 	 * Target is out-of-date only if any of its children was out-of-date.
    308 	 */
    309 	OP_JOIN		= 1 << 10,
    310 	/* Assume the children of the node have been already made. */
    311 	OP_MADE		= 1 << 11,
    312 	/* Special .BEGIN, .END or .INTERRUPT. */
    313 	OP_SPECIAL	= 1 << 12,
    314 	/* Like .USE, only prepend commands. */
    315 	OP_USEBEFORE	= 1 << 13,
    316 	/*
    317 	 * The node is invisible to its parents. I.e. it doesn't show up in
    318 	 * the parents' local variables (.IMPSRC, .ALLSRC).
    319 	 */
    320 	OP_INVISIBLE	= 1 << 14,
    321 	/*
    322 	 * The node does not become the main target, even if it is the first
    323 	 * target in the first makefile.
    324 	 */
    325 	OP_NOTMAIN	= 1 << 15,
    326 	/* Not a file target; run always. */
    327 	OP_PHONY	= 1 << 16,
    328 	/* Don't search for the file in the path. */
    329 	OP_NOPATH	= 1 << 17,
    330 	/*
    331 	 * In a dependency line "target: source1 .WAIT source2", source1 is
    332 	 * made first, including its children.  Once that is finished,
    333 	 * source2 is made, including its children.  The .WAIT keyword may
    334 	 * appear more than once in a single dependency declaration.
    335 	 */
    336 	OP_WAIT		= 1 << 18,
    337 	/* .NOMETA do not create a .meta file */
    338 	OP_NOMETA	= 1 << 19,
    339 	/* .META we _do_ want a .meta file */
    340 	OP_META		= 1 << 20,
    341 	/* Do not compare commands in .meta file */
    342 	OP_NOMETA_CMP	= 1 << 21,
    343 	/* Possibly a submake node */
    344 	OP_SUBMAKE	= 1 << 22,
    345 
    346 	/* Attributes applied by PMake */
    347 
    348 	/* The node is a transformation rule, such as ".c.o". */
    349 	OP_TRANSFORM	= 1 << 30,
    350 	/* Target is a member of an archive */
    351 	/* XXX: How does this differ from OP_ARCHV? */
    352 	OP_MEMBER	= 1 << 29,
    353 	/*
    354 	 * The node is a library, its name has the form "-l<libname>".
    355 	 */
    356 	OP_LIB		= 1 << 28,
    357 	/*
    358 	 * The node is an archive member, its name has the form
    359 	 * "archive(member)".
    360 	 */
    361 	/* XXX: How does this differ from OP_MEMBER? */
    362 	OP_ARCHV	= 1 << 27,
    363 	/*
    364 	 * Target has all the commands it should. Used when parsing to catch
    365 	 * multiple command groups for a target.  Only applies to the
    366 	 * dependency operators ':' and '!', but not to '::'.
    367 	 */
    368 	OP_HAS_COMMANDS	= 1 << 26,
    369 	/*
    370 	 * The special command "..." has been seen. All further commands from
    371 	 * this node will be saved on the .END node instead, to be executed
    372 	 * at the very end.
    373 	 */
    374 	OP_SAVE_CMDS	= 1 << 25,
    375 	/*
    376 	 * Already processed by Suff_FindDeps, to find dependencies from
    377 	 * suffix transformation rules.
    378 	 */
    379 	OP_DEPS_FOUND	= 1 << 24,
    380 	/* Node found while expanding .ALLSRC */
    381 	OP_MARK		= 1 << 23
    382 } GNodeType;
    383 
    384 typedef struct GNodeFlags {
    385 	/* this target needs to be (re)made */
    386 	bool remake:1;
    387 	/* children of this target were made */
    388 	bool childMade:1;
    389 	/* children don't exist, and we pretend made */
    390 	bool force:1;
    391 	/* Set by Make_ProcessWait() */
    392 	bool doneWait:1;
    393 	/* Build requested by .ORDER processing */
    394 	bool doneOrder:1;
    395 	/* Node created from .depend */
    396 	bool fromDepend:1;
    397 	/* We do it once only */
    398 	bool doneAllsrc:1;
    399 	/* Used by MakePrintStatus */
    400 	bool cycle:1;
    401 	/* Used by MakePrintStatus */
    402 	bool doneCycle:1;
    403 } GNodeFlags;
    404 
    405 typedef struct List StringList;
    406 typedef struct ListNode StringListNode;
    407 
    408 typedef struct List GNodeList;
    409 typedef struct ListNode GNodeListNode;
    410 
    411 typedef struct SearchPath {
    412 	List /* of CachedDir */ dirs;
    413 } SearchPath;
    414 
    415 /*
    416  * A graph node represents a target that can possibly be made, including its
    417  * relation to other targets.
    418  */
    419 typedef struct GNode {
    420 	/* The target's name, such as "clean" or "make.c" */
    421 	char *name;
    422 	/* The unexpanded name of a .USE node */
    423 	char *uname;
    424 	/*
    425 	 * The full pathname of the file belonging to the target.
    426 	 *
    427 	 * XXX: What about .PHONY targets? These don't have an associated
    428 	 * path.
    429 	 */
    430 	char *path;
    431 
    432 	/*
    433 	 * The type of operator used to define the sources (see the OP flags
    434 	 * below).
    435 	 *
    436 	 * XXX: This looks like a wild mixture of type and flags.
    437 	 */
    438 	GNodeType type;
    439 	GNodeFlags flags;
    440 
    441 	/* The state of processing on this node */
    442 	GNodeMade made;
    443 	/* The number of unmade children */
    444 	int unmade;
    445 
    446 	/*
    447 	 * The modification time; 0 means the node does not have a
    448 	 * corresponding file; see GNode_IsOODate.
    449 	 */
    450 	time_t mtime;
    451 	struct GNode *youngestChild;
    452 
    453 	/*
    454 	 * The GNodes for which this node is an implied source. May be empty.
    455 	 * For example, when there is an inference rule for .c.o, the node
    456 	 * for file.c has the node for file.o in this list.
    457 	 */
    458 	GNodeList implicitParents;
    459 
    460 	/*
    461 	 * The nodes that depend on this one, or in other words, the nodes
    462 	 * for which this is a source.
    463 	 */
    464 	GNodeList parents;
    465 	/* The nodes on which this one depends. */
    466 	GNodeList children;
    467 
    468 	/*
    469 	 * .ORDER nodes we need made. The nodes that must be made (if they're
    470 	 * made) before this node can be made, but that do not enter into the
    471 	 * datedness of this node.
    472 	 */
    473 	GNodeList order_pred;
    474 	/*
    475 	 * .ORDER nodes who need us. The nodes that must be made (if they're
    476 	 * made at all) after this node is made, but that do not depend on
    477 	 * this node, in the normal sense.
    478 	 */
    479 	GNodeList order_succ;
    480 
    481 	/*
    482 	 * Other nodes of the same name, for targets that were defined using
    483 	 * the '::' dependency operator (OP_DOUBLEDEP).
    484 	 */
    485 	GNodeList cohorts;
    486 	/* The "#n" suffix for this cohort, or "" for other nodes */
    487 	char cohort_num[8];
    488 	/* The number of unmade instances on the cohorts list */
    489 	int unmade_cohorts;
    490 	/*
    491 	 * Pointer to the first instance of a '::' node; only set when on a
    492 	 * cohorts list
    493 	 */
    494 	struct GNode *centurion;
    495 
    496 	/* Last time (sequence number) we tried to make this node */
    497 	unsigned checked_seqno;
    498 
    499 	/*
    500 	 * The "local" variables that are specific to this target and this
    501 	 * target only, such as $@, $<, $?.
    502 	 *
    503 	 * Also used for the global variable scopes SCOPE_GLOBAL,
    504 	 * SCOPE_CMDLINE, SCOPE_INTERNAL, which contain variables with
    505 	 * arbitrary names.
    506 	 */
    507 	HashTable /* of Var pointer */ vars;
    508 
    509 	/* The commands to be given to a shell to create this target. */
    510 	StringList commands;
    511 
    512 	/*
    513 	 * Suffix for the node (determined by Suff_FindDeps and opaque to
    514 	 * everyone but the Suff module)
    515 	 */
    516 	struct Suffix *suffix;
    517 
    518 	/* Filename where the GNode got defined, unlimited lifetime */
    519 	const char *fname;
    520 	/* Line number where the GNode got defined, 1-based */
    521 	unsigned lineno;
    522 	int exit_status;
    523 } GNode;
    524 
    525 /*
    526  * Keep track of whether to include <posix.mk> when parsing the line
    527  * '.POSIX:'.
    528  */
    529 extern enum PosixState {
    530 	PS_NOT_YET,
    531 	PS_MAYBE_NEXT_LINE,
    532 	PS_NOW_OR_NEVER,
    533 	PS_SET,
    534 	PS_TOO_LATE
    535 } posix_state;
    536 
    537 /* Error levels for diagnostics during parsing. */
    538 typedef enum ParseErrorLevel {
    539 	/*
    540 	 * Exit when the current top-level makefile has been parsed
    541 	 * completely.
    542 	 */
    543 	PARSE_FATAL = 1,
    544 	/* Print "warning"; may be upgraded to fatal by the -w option. */
    545 	PARSE_WARNING,
    546 	/* Informational, mainly used during development of makefiles. */
    547 	PARSE_INFO
    548 } ParseErrorLevel;
    549 
    550 /*
    551  * Values returned by Cond_EvalLine and Cond_EvalCondition.
    552  */
    553 typedef enum CondResult {
    554 	CR_TRUE,		/* Parse the next lines */
    555 	CR_FALSE,		/* Skip the next lines */
    556 	CR_ERROR		/* Unknown directive or parse error */
    557 } CondResult;
    558 
    559 typedef struct {
    560 	enum GuardKind {
    561 		GK_VARIABLE,
    562 		GK_TARGET
    563 	} kind;
    564 	char *name;
    565 } Guard;
    566 
    567 /* Names of the variables that are "local" to a specific target. */
    568 #define TARGET	"@"		/* Target of dependency */
    569 #define OODATE	"?"		/* All out-of-date sources */
    570 #define ALLSRC	">"		/* All sources */
    571 #define IMPSRC	"<"		/* Source implied by transformation */
    572 #define PREFIX	"*"		/* Common prefix */
    573 #define ARCHIVE	"!"		/* Archive in "archive(member)" syntax */
    574 #define MEMBER	"%"		/* Member in "archive(member)" syntax */
    575 
    576 /*
    577  * Global Variables
    578  */
    579 
    580 /* True if every target is precious */
    581 extern bool allPrecious;
    582 /* True if failed targets should be deleted */
    583 extern bool deleteOnError;
    584 /* true while processing .depend */
    585 extern bool doing_depend;
    586 /* .DEFAULT rule */
    587 extern GNode *defaultNode;
    588 
    589 /*
    590  * Variables defined internally by make which should not override those set
    591  * by makefiles.
    592  */
    593 extern GNode *SCOPE_INTERNAL;
    594 /* Variables defined in a global scope, e.g in the makefile itself. */
    595 extern GNode *SCOPE_GLOBAL;
    596 /* Variables defined on the command line. */
    597 extern GNode *SCOPE_CMDLINE;
    598 
    599 /*
    600  * Value returned by Var_Parse when an error is encountered. It points to an
    601  * empty string, so naive callers needn't worry about it.
    602  */
    603 extern char var_Error[];
    604 
    605 /* The time at the start of this whole process */
    606 extern time_t now;
    607 
    608 /*
    609  * The list of directories to search when looking for targets (set by the
    610  * special target .PATH).
    611  */
    612 extern SearchPath dirSearchPath;
    613 /* Used for .include "...". */
    614 extern SearchPath *parseIncPath;
    615 /*
    616  * Used for .include <...>, for the built-in sys.mk and for makefiles from
    617  * the command line arguments.
    618  */
    619 extern SearchPath *sysIncPath;
    620 /* The default for sysIncPath. */
    621 extern SearchPath *defSysIncPath;
    622 
    623 /* Startup directory */
    624 extern char curdir[];
    625 /* The basename of the program name, suffixed with [n] for sub-makes.  */
    626 extern const char *progname;
    627 extern int makelevel;
    628 /* Name of the .depend makefile */
    629 extern char *makeDependfile;
    630 /* If we replaced environ, this will be non-NULL. */
    631 extern char **savedEnv;
    632 extern GNode *mainNode;
    633 
    634 extern pid_t myPid;
    635 
    636 #define MAKEFLAGS	".MAKEFLAGS"
    637 #ifndef MAKE_LEVEL_ENV
    638 # define MAKE_LEVEL_ENV	"MAKELEVEL"
    639 #endif
    640 
    641 typedef struct DebugFlags {
    642 	bool DEBUG_ARCH:1;
    643 	bool DEBUG_COND:1;
    644 	bool DEBUG_CWD:1;
    645 	bool DEBUG_DIR:1;
    646 	bool DEBUG_ERROR:1;
    647 	bool DEBUG_FOR:1;
    648 	bool DEBUG_GRAPH1:1;
    649 	bool DEBUG_GRAPH2:1;
    650 	bool DEBUG_GRAPH3:1;
    651 	bool DEBUG_HASH:1;
    652 	bool DEBUG_JOB:1;
    653 	bool DEBUG_LOUD:1;
    654 	bool DEBUG_MAKE:1;
    655 	bool DEBUG_META:1;
    656 	bool DEBUG_PARSE:1;
    657 	bool DEBUG_SCRIPT:1;
    658 	bool DEBUG_SHELL:1;
    659 	bool DEBUG_SUFF:1;
    660 	bool DEBUG_TARG:1;
    661 	bool DEBUG_VAR:1;
    662 } DebugFlags;
    663 
    664 #define CONCAT(a, b) a##b
    665 
    666 #define DEBUG(module) (opts.debug.CONCAT(DEBUG_, module))
    667 
    668 void debug_printf(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
    669 
    670 #define DEBUG_IMPL(module, args) \
    671 	do { \
    672 		if (DEBUG(module)) \
    673 			debug_printf args; \
    674 	} while (false)
    675 
    676 #define DEBUG0(module, fmt) \
    677 	DEBUG_IMPL(module, (fmt))
    678 #define DEBUG1(module, fmt, arg1) \
    679 	DEBUG_IMPL(module, (fmt, arg1))
    680 #define DEBUG2(module, fmt, arg1, arg2) \
    681 	DEBUG_IMPL(module, (fmt, arg1, arg2))
    682 #define DEBUG3(module, fmt, arg1, arg2, arg3) \
    683 	DEBUG_IMPL(module, (fmt, arg1, arg2, arg3))
    684 #define DEBUG4(module, fmt, arg1, arg2, arg3, arg4) \
    685 	DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4))
    686 #define DEBUG5(module, fmt, arg1, arg2, arg3, arg4, arg5) \
    687 	DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4, arg5))
    688 
    689 typedef enum PrintVarsMode {
    690 	PVM_NONE,
    691 	PVM_UNEXPANDED,
    692 	PVM_EXPANDED
    693 } PrintVarsMode;
    694 
    695 /* Command line options */
    696 typedef struct CmdOpts {
    697 	/* -B: whether to be compatible to traditional make */
    698 	bool compatMake;
    699 
    700 	/*
    701 	 * -d: debug control: There is one flag per module.  It is up to the
    702 	 * module what debug information to print.
    703 	 */
    704 	DebugFlags debug;
    705 
    706 	/* -dF: debug output is written here - default stderr */
    707 	FILE *debug_file;
    708 
    709 	/*
    710 	 * -dL: lint mode
    711 	 *
    712 	 * Runs make in strict mode, with additional checks and better error
    713 	 * handling.
    714 	 */
    715 	bool strict;
    716 
    717 	/* -dV: for the -V option, print unexpanded variable values */
    718 	bool debugVflag;
    719 
    720 	/* -e: check environment variables before global variables */
    721 	bool checkEnvFirst;
    722 
    723 	/* -f: the makefiles to read */
    724 	StringList makefiles;
    725 
    726 	/* -i: if true, ignore all errors from shell commands */
    727 	bool ignoreErrors;
    728 
    729 	/*
    730 	 * -j: the maximum number of jobs that can run in parallel; this is
    731 	 * coordinated with the submakes
    732 	 */
    733 	int maxJobs;
    734 
    735 	/*
    736 	 * -k: if true and an error occurs while making a node, continue
    737 	 * making nodes that do not depend on the erroneous node
    738 	 */
    739 	bool keepgoing;
    740 
    741 	/* -N: execute no commands from the targets */
    742 	bool noRecursiveExecute;
    743 
    744 	/* -n: execute almost no commands from the targets */
    745 	bool noExecute;
    746 
    747 	/*
    748 	 * -q: if true, do not really make anything, just see if the targets
    749 	 * are out-of-date
    750 	 */
    751 	bool query;
    752 
    753 	/* -r: raw mode, do not load the builtin rules. */
    754 	bool noBuiltins;
    755 
    756 	/* -s: don't echo the shell commands before executing them */
    757 	bool silent;
    758 
    759 	/*
    760 	 * -t: touch the targets if they are out-of-date, but don't actually
    761 	 * make them
    762 	 */
    763 	bool touch;
    764 
    765 	/* -[Vv]: print expanded or unexpanded selected variables */
    766 	PrintVarsMode printVars;
    767 	/* -[Vv]: the variables to print */
    768 	StringList variables;
    769 
    770 	/* -W: if true, makefile parsing warnings are treated as errors */
    771 	bool parseWarnFatal;
    772 
    773 	/* -w: print 'Entering' and 'Leaving' for submakes */
    774 	bool enterFlag;
    775 
    776 	/*
    777 	 * -X: if true, do not export variables set on the command line to
    778 	 * the environment.
    779 	 */
    780 	bool varNoExportEnv;
    781 
    782 	/*
    783 	 * The target names specified on the command line. Used to resolve
    784 	 * .if make(...) statements.
    785 	 */
    786 	StringList create;
    787 
    788 	/*
    789 	 * Randomize the order in which the targets from toBeMade are made,
    790 	 * to catch undeclared dependencies.
    791 	 */
    792 	bool randomizeTargets;
    793 } CmdOpts;
    794 
    795 extern CmdOpts opts;
    796 extern bool forceJobs;
    797 extern char **environ;
    798 
    799 /* arch.c */
    800 void Arch_Init(void);
    801 #ifdef CLEANUP
    802 void Arch_End(void);
    803 #endif
    804 
    805 bool Arch_ParseArchive(char **, GNodeList *, GNode *);
    806 void Arch_Touch(GNode *);
    807 void Arch_TouchLib(GNode *);
    808 void Arch_UpdateMTime(GNode *);
    809 void Arch_UpdateMemberMTime(GNode *);
    810 void Arch_FindLib(GNode *, SearchPath *);
    811 bool Arch_LibOODate(GNode *) MAKE_ATTR_USE;
    812 bool Arch_IsLib(GNode *) MAKE_ATTR_USE;
    813 
    814 /* compat.c */
    815 bool Compat_RunCommand(const char *, GNode *, StringListNode *);
    816 void Compat_MakeAll(GNodeList *);
    817 void Compat_Make(GNode *, GNode *);
    818 
    819 /* cond.c */
    820 extern unsigned cond_depth;
    821 CondResult Cond_EvalCondition(const char *) MAKE_ATTR_USE;
    822 CondResult Cond_EvalLine(const char *) MAKE_ATTR_USE;
    823 Guard *Cond_ExtractGuard(const char *) MAKE_ATTR_USE;
    824 void Cond_EndFile(void);
    825 
    826 /* dir.c; see also dir.h */
    827 
    828 MAKE_INLINE const char * MAKE_ATTR_USE
    829 str_basename(const char *pathname)
    830 {
    831 	const char *lastSlash = strrchr(pathname, '/');
    832 	return lastSlash != NULL ? lastSlash + 1 : pathname;
    833 }
    834 
    835 MAKE_INLINE SearchPath * MAKE_ATTR_USE
    836 SearchPath_New(void)
    837 {
    838 	SearchPath *path = bmake_malloc(sizeof *path);
    839 	Lst_Init(&path->dirs);
    840 	return path;
    841 }
    842 
    843 void SearchPath_Free(SearchPath *);
    844 
    845 /* for.c */
    846 struct ForLoop;
    847 int For_Eval(const char *) MAKE_ATTR_USE;
    848 bool For_Accum(const char *, int *) MAKE_ATTR_USE;
    849 void For_Run(unsigned, unsigned);
    850 bool For_NextIteration(struct ForLoop *, Buffer *);
    851 char *ForLoop_Details(const struct ForLoop *);
    852 void ForLoop_Free(struct ForLoop *);
    853 void For_Break(struct ForLoop *);
    854 
    855 /* job.c */
    856 void JobReapChild(pid_t, int, bool);
    857 
    858 /* longer than this we use a temp file */
    859 #ifndef MAKE_CMDLEN_LIMIT
    860 # define MAKE_CMDLEN_LIMIT 1000
    861 #endif
    862 /* main.c */
    863 void Main_ParseArgLine(const char *);
    864 void Cmd_Argv(const char *, size_t, const char *[5], char *, size_t,
    865     bool, bool);
    866 char *Cmd_Exec(const char *, char **) MAKE_ATTR_USE;
    867 void Var_ExportStackTrace(const char *, const char *);
    868 void Error(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
    869 void Fatal(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
    870 void Punt(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
    871 void DieHorribly(void) MAKE_ATTR_DEAD;
    872 int unlink_file(const char *) MAKE_ATTR_USE;
    873 void execDie(const char *, const char *);
    874 char *getTmpdir(void) MAKE_ATTR_USE;
    875 bool ParseBoolean(const char *, bool) MAKE_ATTR_USE;
    876 const char *cached_realpath(const char *, char *);
    877 bool GetBooleanExpr(const char *, bool);
    878 
    879 /* parse.c */
    880 extern int parseErrors;
    881 void Parse_Init(void);
    882 #ifdef CLEANUP
    883 void Parse_End(void);
    884 #endif
    885 
    886 void PrintLocation(FILE *, bool, const GNode *);
    887 const char *GetParentStackTrace(void);
    888 char *GetStackTrace(bool);
    889 void PrintStackTrace(bool);
    890 void Parse_Error(ParseErrorLevel, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
    891 bool Parse_VarAssign(const char *, bool, GNode *) MAKE_ATTR_USE;
    892 void Parse_File(const char *, int);
    893 void Parse_PushInput(const char *, unsigned, unsigned, Buffer,
    894 		     struct ForLoop *);
    895 void Parse_MainName(GNodeList *);
    896 unsigned CurFile_CondMinDepth(void) MAKE_ATTR_USE;
    897 void Parse_GuardElse(void);
    898 void Parse_GuardEndif(void);
    899 
    900 
    901 /* suff.c */
    902 void Suff_Init(void);
    903 #ifdef CLEANUP
    904 void Suff_End(void);
    905 #endif
    906 
    907 void Suff_ClearSuffixes(void);
    908 bool Suff_IsTransform(const char *) MAKE_ATTR_USE;
    909 GNode *Suff_AddTransform(const char *);
    910 void Suff_EndTransform(GNode *);
    911 void Suff_AddSuffix(const char *);
    912 SearchPath *Suff_GetPath(const char *) MAKE_ATTR_USE;
    913 void Suff_ExtendPaths(void);
    914 void Suff_AddInclude(const char *);
    915 void Suff_AddLib(const char *);
    916 void Suff_FindDeps(GNode *);
    917 SearchPath *Suff_FindPath(GNode *) MAKE_ATTR_USE;
    918 void Suff_SetNull(const char *);
    919 void Suff_PrintAll(void);
    920 char *Suff_NamesStr(void) MAKE_ATTR_USE;
    921 
    922 /* targ.c */
    923 void Targ_Init(void);
    924 void Targ_End(void);
    925 
    926 void Targ_Stats(void);
    927 GNodeList *Targ_List(void) MAKE_ATTR_USE;
    928 GNode *GNode_New(const char *) MAKE_ATTR_USE;
    929 GNode *Targ_FindNode(const char *) MAKE_ATTR_USE;
    930 GNode *Targ_GetNode(const char *) MAKE_ATTR_USE;
    931 GNode *Targ_NewInternalNode(const char *) MAKE_ATTR_USE;
    932 GNode *Targ_GetEndNode(void);
    933 void Targ_FindList(GNodeList *, StringList *);
    934 void Targ_PrintCmds(GNode *);
    935 void Targ_PrintNode(GNode *, int);
    936 void Targ_PrintNodes(GNodeList *, int);
    937 const char *Targ_FmtTime(time_t) MAKE_ATTR_USE;
    938 void Targ_PrintType(GNodeType);
    939 void Targ_PrintGraph(int);
    940 void Targ_Propagate(void);
    941 const char *GNodeMade_Name(GNodeMade) MAKE_ATTR_USE;
    942 #ifdef CLEANUP
    943 void Parse_RegisterCommand(char *);
    944 #else
    945 MAKE_INLINE
    946 void Parse_RegisterCommand(char *cmd MAKE_ATTR_UNUSED)
    947 {
    948 }
    949 #endif
    950 
    951 /* var.c */
    952 
    953 typedef enum VarEvalMode {
    954 
    955 	/*
    956 	 * Only parse the expression but don't evaluate any part of it.
    957 	 *
    958 	 * TODO: Document what Var_Parse and Var_Subst return in this mode.
    959 	 *  As of 2021-03-15, they return unspecified, inconsistent results.
    960 	 */
    961 	VARE_PARSE,
    962 
    963 	/*
    964 	 * Parse text in which '${...}' and '$(...)' are not parsed as
    965 	 * subexpressions (with all their individual escaping rules) but
    966 	 * instead simply as text with balanced '${}' or '$()'.  Other '$'
    967 	 * are copied verbatim.
    968 	 */
    969 	VARE_PARSE_BALANCED,
    970 
    971 	/* Parse and evaluate the expression. */
    972 	VARE_EVAL,
    973 
    974 	/*
    975 	 * Parse and evaluate the expression.  It is an error if a
    976 	 * subexpression evaluates to undefined.
    977 	 */
    978 	VARE_EVAL_DEFINED_LOUD,
    979 
    980 	/*
    981 	 * Parse and evaluate the expression.  It is a silent error if a
    982 	 * subexpression evaluates to undefined.
    983 	 */
    984 	VARE_EVAL_DEFINED,
    985 
    986 	/*
    987 	 * Parse and evaluate the expression.  Keep undefined variables as-is
    988 	 * instead of expanding them to an empty string.
    989 	 *
    990 	 * Example for a ':=' assignment:
    991 	 *	CFLAGS = $(.INCLUDES)
    992 	 *	CFLAGS := -I.. $(CFLAGS)
    993 	 *	# If .INCLUDES (an undocumented special variable, by the
    994 	 *	# way) is still undefined, the updated CFLAGS becomes
    995 	 *	# "-I.. $(.INCLUDES)".
    996 	 */
    997 	VARE_EVAL_KEEP_UNDEFINED,
    998 
    999 	/*
   1000 	 * Parse and evaluate the expression.  Keep '$$' as '$$' and preserve
   1001 	 * undefined subexpressions.
   1002 	 */
   1003 	VARE_EVAL_KEEP_DOLLAR_AND_UNDEFINED
   1004 } VarEvalMode;
   1005 
   1006 typedef enum VarSetFlags {
   1007 	VAR_SET_NONE		= 0,
   1008 
   1009 	/* do not export */
   1010 	VAR_SET_NO_EXPORT	= 1 << 0,
   1011 
   1012 	/*
   1013 	 * Make the variable read-only. No further modification is possible,
   1014 	 * except for another call to Var_Set with the same flag. See the
   1015 	 * special targets '.NOREADONLY' and '.READONLY'.
   1016 	 */
   1017 	VAR_SET_READONLY	= 1 << 1,
   1018 	VAR_SET_INTERNAL	= 1 << 2
   1019 } VarSetFlags;
   1020 
   1021 typedef enum VarExportMode {
   1022 	/* .export-all */
   1023 	VEM_ALL,
   1024 	/* .export-env */
   1025 	VEM_ENV,
   1026 	/* .export: Initial export or update an already exported variable. */
   1027 	VEM_PLAIN,
   1028 	/* .export-literal: Do not expand the variable value. */
   1029 	VEM_LITERAL
   1030 } VarExportMode;
   1031 
   1032 void Var_Delete(GNode *, const char *);
   1033 #ifdef CLEANUP
   1034 void Var_DeleteAll(GNode *scope);
   1035 #endif
   1036 void Var_Undef(const char *);
   1037 void Var_Set(GNode *, const char *, const char *);
   1038 void Var_SetExpand(GNode *, const char *, const char *);
   1039 void Var_SetWithFlags(GNode *, const char *, const char *, VarSetFlags);
   1040 void Var_Append(GNode *, const char *, const char *);
   1041 void Var_AppendExpand(GNode *, const char *, const char *);
   1042 bool Var_Exists(GNode *, const char *) MAKE_ATTR_USE;
   1043 bool Var_ExistsExpand(GNode *, const char *) MAKE_ATTR_USE;
   1044 FStr Var_Value(GNode *, const char *) MAKE_ATTR_USE;
   1045 const char *GNode_ValueDirect(GNode *, const char *) MAKE_ATTR_USE;
   1046 FStr Var_Parse(const char **, GNode *, VarEvalMode);
   1047 char *Var_Subst(const char *, GNode *, VarEvalMode);
   1048 char *Var_SubstInTarget(const char *, GNode *);
   1049 void Var_Expand(FStr *, GNode *, VarEvalMode);
   1050 void Var_Stats(void);
   1051 void Var_Dump(GNode *);
   1052 void Var_ReexportVars(GNode *);
   1053 void Var_Export(VarExportMode, const char *);
   1054 void Var_ExportVars(const char *);
   1055 void Var_UnExport(bool, const char *);
   1056 void Var_ReadOnly(const char *, bool);
   1057 
   1058 void Global_Set(const char *, const char *);
   1059 void Global_Append(const char *, const char *);
   1060 void Global_Delete(const char *);
   1061 void Global_Set_ReadOnly(const char *, const char *);
   1062 
   1063 void EvalStack_PushMakeflags(const char *);
   1064 void EvalStack_Pop(void);
   1065 bool EvalStack_Details(Buffer *buf) MAKE_ATTR_USE;
   1066 
   1067 /* util.c */
   1068 typedef void (*SignalProc)(int);
   1069 SignalProc bmake_signal(int, SignalProc);
   1070 
   1071 /* make.c */
   1072 void GNode_UpdateYoungestChild(GNode *, GNode *);
   1073 bool GNode_IsOODate(GNode *) MAKE_ATTR_USE;
   1074 void Make_ExpandUse(GNodeList *);
   1075 time_t Make_Recheck(GNode *) MAKE_ATTR_USE;
   1076 void Make_HandleUse(GNode *, GNode *);
   1077 void Make_Update(GNode *);
   1078 void GNode_SetLocalVars(GNode *);
   1079 bool Make_MakeParallel(GNodeList *);
   1080 bool shouldDieQuietly(GNode *, int) MAKE_ATTR_USE;
   1081 void PrintOnError(GNode *, const char *);
   1082 void Main_ExportMAKEFLAGS(bool);
   1083 bool Main_SetObjdir(bool, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
   1084 int mkTempFile(const char *, char *, size_t) MAKE_ATTR_USE;
   1085 void AppendWords(StringList *, char *);
   1086 void GNode_FprintDetails(FILE *, const char *, const GNode *, const char *);
   1087 bool GNode_ShouldExecute(GNode *gn) MAKE_ATTR_USE;
   1088 char *GNodeType_ToString(GNodeType);
   1089 
   1090 /* See if the node was seen on the left-hand side of a dependency operator. */
   1091 MAKE_INLINE bool MAKE_ATTR_USE
   1092 GNode_IsTarget(const GNode *gn)
   1093 {
   1094 	return (gn->type & OP_OPMASK) != OP_NONE;
   1095 }
   1096 
   1097 MAKE_INLINE const char * MAKE_ATTR_USE
   1098 GNode_Path(const GNode *gn)
   1099 {
   1100 	return gn->path != NULL ? gn->path : gn->name;
   1101 }
   1102 
   1103 MAKE_INLINE bool MAKE_ATTR_USE
   1104 GNode_IsWaitingFor(const GNode *gn)
   1105 {
   1106 	return gn->flags.remake && gn->made <= REQUESTED;
   1107 }
   1108 
   1109 MAKE_INLINE bool MAKE_ATTR_USE
   1110 GNode_IsReady(const GNode *gn)
   1111 {
   1112 	return gn->made > DEFERRED;
   1113 }
   1114 
   1115 MAKE_INLINE bool MAKE_ATTR_USE
   1116 GNode_IsDone(const GNode *gn)
   1117 {
   1118 	return gn->made >= MADE;
   1119 }
   1120 
   1121 MAKE_INLINE bool MAKE_ATTR_USE
   1122 GNode_IsError(const GNode *gn)
   1123 {
   1124 	return gn->made == ERROR || gn->made == ABORTED;
   1125 }
   1126 
   1127 MAKE_INLINE bool MAKE_ATTR_USE
   1128 GNode_IsMainCandidate(const GNode *gn)
   1129 {
   1130 	return (gn->type & (OP_NOTMAIN | OP_USE | OP_USEBEFORE |
   1131 			    OP_EXEC | OP_TRANSFORM)) == 0;
   1132 }
   1133 
   1134 /* Return whether the target file should be preserved on interrupt. */
   1135 MAKE_INLINE bool MAKE_ATTR_USE
   1136 GNode_IsPrecious(const GNode *gn)
   1137 {
   1138 	/* XXX: Why are '::' targets precious? */
   1139 	return allPrecious || gn->type & (OP_PRECIOUS | OP_DOUBLEDEP);
   1140 }
   1141 
   1142 MAKE_INLINE const char * MAKE_ATTR_USE
   1143 GNode_VarTarget(GNode *gn) { return GNode_ValueDirect(gn, TARGET); }
   1144 MAKE_INLINE const char * MAKE_ATTR_USE
   1145 GNode_VarOodate(GNode *gn) { return GNode_ValueDirect(gn, OODATE); }
   1146 MAKE_INLINE const char * MAKE_ATTR_USE
   1147 GNode_VarAllsrc(GNode *gn) { return GNode_ValueDirect(gn, ALLSRC); }
   1148 MAKE_INLINE const char * MAKE_ATTR_USE
   1149 GNode_VarImpsrc(GNode *gn) { return GNode_ValueDirect(gn, IMPSRC); }
   1150 MAKE_INLINE const char * MAKE_ATTR_USE
   1151 GNode_VarPrefix(GNode *gn) { return GNode_ValueDirect(gn, PREFIX); }
   1152 MAKE_INLINE const char * MAKE_ATTR_USE
   1153 GNode_VarArchive(GNode *gn) { return GNode_ValueDirect(gn, ARCHIVE); }
   1154 MAKE_INLINE const char * MAKE_ATTR_USE
   1155 GNode_VarMember(GNode *gn) { return GNode_ValueDirect(gn, MEMBER); }
   1156 
   1157 MAKE_INLINE void * MAKE_ATTR_USE
   1158 UNCONST(const void *ptr)
   1159 {
   1160 	void *ret;
   1161 	memcpy(&ret, &ptr, sizeof(ret));
   1162 	return ret;
   1163 }
   1164 
   1165 /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */
   1166 #include <limits.h>
   1167 #ifndef MAXPATHLEN
   1168 #define MAXPATHLEN	4096
   1169 #endif
   1170 #ifndef PATH_MAX
   1171 #define PATH_MAX	MAXPATHLEN
   1172 #endif
   1173 
   1174 #if defined(SYSV)
   1175 #define KILLPG(pid, sig) kill(-(pid), (sig))
   1176 #else
   1177 #define KILLPG(pid, sig) killpg((pid), (sig))
   1178 #endif
   1179 
   1180 MAKE_INLINE bool MAKE_ATTR_USE
   1181 ch_isalnum(char ch) { return isalnum((unsigned char)ch) != 0; }
   1182 MAKE_INLINE bool MAKE_ATTR_USE
   1183 ch_isalpha(char ch) { return isalpha((unsigned char)ch) != 0; }
   1184 MAKE_INLINE bool MAKE_ATTR_USE
   1185 ch_isdigit(char ch) { return isdigit((unsigned char)ch) != 0; }
   1186 MAKE_INLINE bool MAKE_ATTR_USE
   1187 ch_islower(char ch) { return islower((unsigned char)ch) != 0; }
   1188 MAKE_INLINE bool MAKE_ATTR_USE
   1189 ch_isprint(char ch) { return isprint((unsigned char)ch) != 0; }
   1190 MAKE_INLINE bool MAKE_ATTR_USE
   1191 ch_isspace(char ch) { return isspace((unsigned char)ch) != 0; }
   1192 MAKE_INLINE bool MAKE_ATTR_USE
   1193 ch_isupper(char ch) { return isupper((unsigned char)ch) != 0; }
   1194 MAKE_INLINE char MAKE_ATTR_USE
   1195 ch_tolower(char ch) { return (char)tolower((unsigned char)ch); }
   1196 MAKE_INLINE char MAKE_ATTR_USE
   1197 ch_toupper(char ch) { return (char)toupper((unsigned char)ch); }
   1198 
   1199 MAKE_INLINE void
   1200 cpp_skip_whitespace(const char **pp)
   1201 {
   1202 	while (ch_isspace(**pp))
   1203 		(*pp)++;
   1204 }
   1205 
   1206 MAKE_INLINE void
   1207 cpp_skip_hspace(const char **pp)
   1208 {
   1209 	while (**pp == ' ' || **pp == '\t')
   1210 		(*pp)++;
   1211 }
   1212 
   1213 MAKE_INLINE bool
   1214 cpp_skip_string(const char **pp, const char *s)
   1215 {
   1216 	const char *p = *pp;
   1217 	while (*p == *s && *s != '\0')
   1218 		p++, s++;
   1219 	if (*s == '\0')
   1220 		*pp = p;
   1221 	return *s == '\0';
   1222 }
   1223 
   1224 MAKE_INLINE void
   1225 pp_skip_whitespace(char **pp)
   1226 {
   1227 	while (ch_isspace(**pp))
   1228 		(*pp)++;
   1229 }
   1230 
   1231 MAKE_INLINE void
   1232 pp_skip_hspace(char **pp)
   1233 {
   1234 	while (**pp == ' ' || **pp == '\t')
   1235 		(*pp)++;
   1236 }
   1237 
   1238 #if defined(lint)
   1239 void do_not_define_rcsid(void); /* for lint */
   1240 # define MAKE_RCSID(id) void do_not_define_rcsid(void)
   1241 #elif defined(MAKE_NATIVE)
   1242 # include <sys/cdefs.h>
   1243 # define MAKE_RCSID(id) __RCSID(id)
   1244 #elif defined(MAKE_ALL_IN_ONE) && defined(__COUNTER__)
   1245 # define MAKE_RCSID_CONCAT(x, y) CONCAT(x, y)
   1246 # define MAKE_RCSID(id) static volatile char \
   1247 	MAKE_RCSID_CONCAT(rcsid_, __COUNTER__)[] = id
   1248 #elif defined(MAKE_ALL_IN_ONE)
   1249 # define MAKE_RCSID(id) void do_not_define_rcsid(void)
   1250 #else
   1251 # define MAKE_RCSID(id) static volatile char rcsid[] = id
   1252 #endif
   1253 
   1254 #endif
   1255