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