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