xref: /freebsd/contrib/bmake/make.h (revision c9f4001f)
1*c9f4001fSSimon J. Gerraty /*	$NetBSD: make.h,v 1.333 2024/05/07 18:26:22 sjg Exp $	*/
23955d011SMarcel Moolenaar 
33955d011SMarcel Moolenaar /*
43955d011SMarcel Moolenaar  * Copyright (c) 1988, 1989, 1990, 1993
53955d011SMarcel Moolenaar  *	The Regents of the University of California.  All rights reserved.
63955d011SMarcel Moolenaar  *
73955d011SMarcel Moolenaar  * This code is derived from software contributed to Berkeley by
83955d011SMarcel Moolenaar  * Adam de Boor.
93955d011SMarcel Moolenaar  *
103955d011SMarcel Moolenaar  * Redistribution and use in source and binary forms, with or without
113955d011SMarcel Moolenaar  * modification, are permitted provided that the following conditions
123955d011SMarcel Moolenaar  * are met:
133955d011SMarcel Moolenaar  * 1. Redistributions of source code must retain the above copyright
143955d011SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer.
153955d011SMarcel Moolenaar  * 2. Redistributions in binary form must reproduce the above copyright
163955d011SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer in the
173955d011SMarcel Moolenaar  *    documentation and/or other materials provided with the distribution.
183955d011SMarcel Moolenaar  * 3. Neither the name of the University nor the names of its contributors
193955d011SMarcel Moolenaar  *    may be used to endorse or promote products derived from this software
203955d011SMarcel Moolenaar  *    without specific prior written permission.
213955d011SMarcel Moolenaar  *
223955d011SMarcel Moolenaar  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
233955d011SMarcel Moolenaar  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
243955d011SMarcel Moolenaar  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
253955d011SMarcel Moolenaar  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
263955d011SMarcel Moolenaar  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
273955d011SMarcel Moolenaar  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
283955d011SMarcel Moolenaar  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
293955d011SMarcel Moolenaar  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
303955d011SMarcel Moolenaar  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
313955d011SMarcel Moolenaar  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
323955d011SMarcel Moolenaar  * SUCH DAMAGE.
333955d011SMarcel Moolenaar  *
343955d011SMarcel Moolenaar  *	from: @(#)make.h	8.3 (Berkeley) 6/13/95
353955d011SMarcel Moolenaar  */
363955d011SMarcel Moolenaar 
373955d011SMarcel Moolenaar /*
383955d011SMarcel Moolenaar  * Copyright (c) 1989 by Berkeley Softworks
393955d011SMarcel Moolenaar  * All rights reserved.
403955d011SMarcel Moolenaar  *
413955d011SMarcel Moolenaar  * This code is derived from software contributed to Berkeley by
423955d011SMarcel Moolenaar  * Adam de Boor.
433955d011SMarcel Moolenaar  *
443955d011SMarcel Moolenaar  * Redistribution and use in source and binary forms, with or without
453955d011SMarcel Moolenaar  * modification, are permitted provided that the following conditions
463955d011SMarcel Moolenaar  * are met:
473955d011SMarcel Moolenaar  * 1. Redistributions of source code must retain the above copyright
483955d011SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer.
493955d011SMarcel Moolenaar  * 2. Redistributions in binary form must reproduce the above copyright
503955d011SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer in the
513955d011SMarcel Moolenaar  *    documentation and/or other materials provided with the distribution.
523955d011SMarcel Moolenaar  * 3. All advertising materials mentioning features or use of this software
533955d011SMarcel Moolenaar  *    must display the following acknowledgement:
543955d011SMarcel Moolenaar  *	This product includes software developed by the University of
553955d011SMarcel Moolenaar  *	California, Berkeley and its contributors.
563955d011SMarcel Moolenaar  * 4. Neither the name of the University nor the names of its contributors
573955d011SMarcel Moolenaar  *    may be used to endorse or promote products derived from this software
583955d011SMarcel Moolenaar  *    without specific prior written permission.
593955d011SMarcel Moolenaar  *
603955d011SMarcel Moolenaar  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
613955d011SMarcel Moolenaar  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
623955d011SMarcel Moolenaar  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
633955d011SMarcel Moolenaar  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
643955d011SMarcel Moolenaar  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
653955d011SMarcel Moolenaar  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
663955d011SMarcel Moolenaar  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
673955d011SMarcel Moolenaar  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
683955d011SMarcel Moolenaar  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
693955d011SMarcel Moolenaar  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
703955d011SMarcel Moolenaar  * SUCH DAMAGE.
713955d011SMarcel Moolenaar  *
723955d011SMarcel Moolenaar  *	from: @(#)make.h	8.3 (Berkeley) 6/13/95
733955d011SMarcel Moolenaar  */
743955d011SMarcel Moolenaar 
75dba7b0efSSimon J. Gerraty /*
763955d011SMarcel Moolenaar  * make.h --
779f45a3c8SSimon J. Gerraty  *	The global definitions for make
783955d011SMarcel Moolenaar  */
793955d011SMarcel Moolenaar 
802c3632d1SSimon J. Gerraty #ifndef MAKE_MAKE_H
812c3632d1SSimon J. Gerraty #define MAKE_MAKE_H
823955d011SMarcel Moolenaar 
833955d011SMarcel Moolenaar #ifdef HAVE_CONFIG_H
843955d011SMarcel Moolenaar # include "config.h"
853955d011SMarcel Moolenaar #endif
863955d011SMarcel Moolenaar 
873955d011SMarcel Moolenaar #include <sys/types.h>
883955d011SMarcel Moolenaar #include <sys/param.h>
892c3632d1SSimon J. Gerraty #include <sys/stat.h>
903955d011SMarcel Moolenaar 
912c3632d1SSimon J. Gerraty #include <assert.h>
923955d011SMarcel Moolenaar #include <ctype.h>
93be19d90bSSimon J. Gerraty #include <fcntl.h>
94956e45f6SSimon J. Gerraty #include <stdarg.h>
953955d011SMarcel Moolenaar #include <stdio.h>
963955d011SMarcel Moolenaar #include <stdlib.h>
973955d011SMarcel Moolenaar #ifdef HAVE_STRING_H
983955d011SMarcel Moolenaar #include <string.h>
993955d011SMarcel Moolenaar #else
1003955d011SMarcel Moolenaar #include <strings.h>
1013955d011SMarcel Moolenaar #endif
1023955d011SMarcel Moolenaar #include <unistd.h>
1033955d011SMarcel Moolenaar #include <sys/cdefs.h>
1043955d011SMarcel Moolenaar 
105be19d90bSSimon J. Gerraty #ifndef FD_CLOEXEC
106be19d90bSSimon J. Gerraty #define FD_CLOEXEC 1
107be19d90bSSimon J. Gerraty #endif
108be19d90bSSimon J. Gerraty 
1093955d011SMarcel Moolenaar #if defined(__GNUC__)
1103955d011SMarcel Moolenaar #define MAKE_GNUC_PREREQ(x, y)						\
1113955d011SMarcel Moolenaar 	((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) ||			\
1123955d011SMarcel Moolenaar 	 (__GNUC__ > (x)))
1139f45a3c8SSimon J. Gerraty #else
1141748de26SSimon J. Gerraty #define MAKE_GNUC_PREREQ(x, y)	0
1159f45a3c8SSimon J. Gerraty #endif
1163955d011SMarcel Moolenaar 
1173955d011SMarcel Moolenaar #if MAKE_GNUC_PREREQ(2, 7)
1183955d011SMarcel Moolenaar #define MAKE_ATTR_UNUSED	__attribute__((__unused__))
1193955d011SMarcel Moolenaar #else
1203955d011SMarcel Moolenaar #define MAKE_ATTR_UNUSED	/* delete */
1213955d011SMarcel Moolenaar #endif
1223955d011SMarcel Moolenaar 
1233955d011SMarcel Moolenaar #if MAKE_GNUC_PREREQ(2, 5)
1243955d011SMarcel Moolenaar #define MAKE_ATTR_DEAD		__attribute__((__noreturn__))
1253955d011SMarcel Moolenaar #elif defined(__GNUC__)
1263955d011SMarcel Moolenaar #define MAKE_ATTR_DEAD		__volatile
1273955d011SMarcel Moolenaar #else
1283955d011SMarcel Moolenaar #define MAKE_ATTR_DEAD		/* delete */
1293955d011SMarcel Moolenaar #endif
1303955d011SMarcel Moolenaar 
1313955d011SMarcel Moolenaar #if MAKE_GNUC_PREREQ(2, 7)
1323955d011SMarcel Moolenaar #define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg)	\
1333955d011SMarcel Moolenaar 	    __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
1343955d011SMarcel Moolenaar #else
1353955d011SMarcel Moolenaar #define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg)	/* delete */
1363955d011SMarcel Moolenaar #endif
1373955d011SMarcel Moolenaar 
1389f45a3c8SSimon J. Gerraty #if MAKE_GNUC_PREREQ(4, 0)
1399f45a3c8SSimon J. Gerraty #define MAKE_ATTR_USE		__attribute__((__warn_unused_result__))
1409f45a3c8SSimon J. Gerraty #else
1419f45a3c8SSimon J. Gerraty #define MAKE_ATTR_USE		/* delete */
1429f45a3c8SSimon J. Gerraty #endif
1439f45a3c8SSimon J. Gerraty 
144548bfc56SSimon J. Gerraty #if MAKE_GNUC_PREREQ(8, 0)
145548bfc56SSimon J. Gerraty #define MAKE_ATTR_NOINLINE		__attribute__((__noinline__))
146548bfc56SSimon J. Gerraty #else
147548bfc56SSimon J. Gerraty #define MAKE_ATTR_NOINLINE		/* delete */
148548bfc56SSimon J. Gerraty #endif
149548bfc56SSimon J. Gerraty 
1501d3f2ddcSSimon J. Gerraty #if __STDC_VERSION__ >= 199901L || defined(lint)
151e2eeea75SSimon J. Gerraty #define MAKE_INLINE static inline MAKE_ATTR_UNUSED
1529f45a3c8SSimon J. Gerraty #else
1539f45a3c8SSimon J. Gerraty #define MAKE_INLINE static MAKE_ATTR_UNUSED
1549f45a3c8SSimon J. Gerraty #endif
15512904384SSimon J. Gerraty 
15612904384SSimon J. Gerraty /* MAKE_STATIC marks a function that may or may not be inlined. */
15712904384SSimon J. Gerraty #if defined(lint)
15812904384SSimon J. Gerraty /* As of 2021-07-31, NetBSD lint ignores __attribute__((unused)). */
15912904384SSimon J. Gerraty #define MAKE_STATIC MAKE_INLINE
16012904384SSimon J. Gerraty #else
161b0c40a00SSimon J. Gerraty #define MAKE_STATIC static MAKE_ATTR_UNUSED
16212904384SSimon J. Gerraty #endif
163e2eeea75SSimon J. Gerraty 
164b0c40a00SSimon J. Gerraty #if __STDC_VERSION__ >= 199901L || defined(lint) || defined(USE_C99_BOOLEAN)
16506b9b3e0SSimon J. Gerraty #include <stdbool.h>
16612904384SSimon J. Gerraty #elif defined(__bool_true_false_are_defined)
16712904384SSimon J. Gerraty /*
16812904384SSimon J. Gerraty  * All files of make must be compiled with the same definition of bool.
16912904384SSimon J. Gerraty  * Since one of the files includes <stdbool.h>, that means the header is
17012904384SSimon J. Gerraty  * available on this platform.  Recompile everything with -DUSE_C99_BOOLEAN.
17112904384SSimon J. Gerraty  */
17212904384SSimon J. Gerraty #error "<stdbool.h> is included in pre-C99 mode"
17312904384SSimon J. Gerraty #elif defined(bool) || defined(true) || defined(false)
17412904384SSimon J. Gerraty /*
17512904384SSimon J. Gerraty  * In pre-C99 mode, make does not expect that bool is already defined.
17612904384SSimon J. Gerraty  * You need to ensure that all translation units use the same definition for
17712904384SSimon J. Gerraty  * bool.
17812904384SSimon J. Gerraty  */
17912904384SSimon J. Gerraty #error "bool/true/false is defined in pre-C99 mode"
1802c3632d1SSimon J. Gerraty #else
18112904384SSimon J. Gerraty typedef unsigned char bool;
182b0c40a00SSimon J. Gerraty #define true	1
183b0c40a00SSimon J. Gerraty #define false	0
184956e45f6SSimon J. Gerraty #endif
1852c3632d1SSimon J. Gerraty 
1863955d011SMarcel Moolenaar #include "lst.h"
187b0c40a00SSimon J. Gerraty #include "make_malloc.h"
188b0c40a00SSimon J. Gerraty #include "str.h"
1893955d011SMarcel Moolenaar #include "hash.h"
1903955d011SMarcel Moolenaar #include "make-conf.h"
1913955d011SMarcel Moolenaar #include "buf.h"
1923955d011SMarcel Moolenaar 
1933955d011SMarcel Moolenaar /*
1943955d011SMarcel Moolenaar  * some vendors don't have this --sjg
1953955d011SMarcel Moolenaar  */
1963955d011SMarcel Moolenaar #if defined(S_IFDIR) && !defined(S_ISDIR)
1973955d011SMarcel Moolenaar # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
1983955d011SMarcel Moolenaar #endif
1993955d011SMarcel Moolenaar 
2003955d011SMarcel Moolenaar #if defined(sun) && (defined(__svr4__) || defined(__SVR4))
2013955d011SMarcel Moolenaar # define POSIX_SIGNALS
2023955d011SMarcel Moolenaar #endif
2033955d011SMarcel Moolenaar 
20406b9b3e0SSimon J. Gerraty /*
20598875883SSimon J. Gerraty  * IRIX defines OP_NONE in sys/fcntl.h
20698875883SSimon J. Gerraty  */
20798875883SSimon J. Gerraty #if defined(OP_NONE)
20898875883SSimon J. Gerraty # undef OP_NONE
20998875883SSimon J. Gerraty #endif
21098875883SSimon J. Gerraty 
21198875883SSimon J. Gerraty /*
21206b9b3e0SSimon J. Gerraty  * The typical flow of states is:
21306b9b3e0SSimon J. Gerraty  *
21406b9b3e0SSimon J. Gerraty  * The direct successful path:
21506b9b3e0SSimon J. Gerraty  * UNMADE -> BEINGMADE -> MADE.
21606b9b3e0SSimon J. Gerraty  *
21706b9b3e0SSimon J. Gerraty  * The direct error path:
21806b9b3e0SSimon J. Gerraty  * UNMADE -> BEINGMADE -> ERROR.
21906b9b3e0SSimon J. Gerraty  *
22006b9b3e0SSimon J. Gerraty  * The successful path when dependencies need to be made first:
22106b9b3e0SSimon J. Gerraty  * UNMADE -> DEFERRED -> REQUESTED -> BEINGMADE -> MADE.
22206b9b3e0SSimon J. Gerraty  *
22306b9b3e0SSimon J. Gerraty  * A node that has dependencies, and one of the dependencies cannot be made:
22406b9b3e0SSimon J. Gerraty  * UNMADE -> DEFERRED -> ABORTED.
22506b9b3e0SSimon J. Gerraty  *
22606b9b3e0SSimon J. Gerraty  * A node that turns out to be up-to-date:
22706b9b3e0SSimon J. Gerraty  * UNMADE -> BEINGMADE -> UPTODATE.
22806b9b3e0SSimon J. Gerraty  */
229e2eeea75SSimon J. Gerraty typedef enum GNodeMade {
23006b9b3e0SSimon J. Gerraty 	/* Not examined yet. */
23106b9b3e0SSimon J. Gerraty 	UNMADE,
2329f45a3c8SSimon J. Gerraty 	/*
2339f45a3c8SSimon J. Gerraty 	 * The node has been examined but is not yet ready since its
2349f45a3c8SSimon J. Gerraty 	 * dependencies have to be made first.
2359f45a3c8SSimon J. Gerraty 	 */
23606b9b3e0SSimon J. Gerraty 	DEFERRED,
23706b9b3e0SSimon J. Gerraty 
23806b9b3e0SSimon J. Gerraty 	/* The node is on the toBeMade list. */
23906b9b3e0SSimon J. Gerraty 	REQUESTED,
24006b9b3e0SSimon J. Gerraty 
2419f45a3c8SSimon J. Gerraty 	/*
2429f45a3c8SSimon J. Gerraty 	 * The node is already being made. Trying to build a node in this
2439f45a3c8SSimon J. Gerraty 	 * state indicates a cycle in the graph.
2449f45a3c8SSimon J. Gerraty 	 */
24506b9b3e0SSimon J. Gerraty 	BEINGMADE,
24606b9b3e0SSimon J. Gerraty 
24706b9b3e0SSimon J. Gerraty 	/* Was out-of-date and has been made. */
24806b9b3e0SSimon J. Gerraty 	MADE,
24906b9b3e0SSimon J. Gerraty 	/* Was already up-to-date, does not need to be made. */
25006b9b3e0SSimon J. Gerraty 	UPTODATE,
2519f45a3c8SSimon J. Gerraty 	/*
2529f45a3c8SSimon J. Gerraty 	 * An error occurred while it was being made. Used only in compat
2539f45a3c8SSimon J. Gerraty 	 * mode.
2549f45a3c8SSimon J. Gerraty 	 */
25506b9b3e0SSimon J. Gerraty 	ERROR,
2569f45a3c8SSimon J. Gerraty 	/*
2579f45a3c8SSimon J. Gerraty 	 * The target was aborted due to an error making a dependency. Used
2589f45a3c8SSimon J. Gerraty 	 * only in compat mode.
2599f45a3c8SSimon J. Gerraty 	 */
26006b9b3e0SSimon J. Gerraty 	ABORTED
2612c3632d1SSimon J. Gerraty } GNodeMade;
2623955d011SMarcel Moolenaar 
26306b9b3e0SSimon J. Gerraty /*
26406b9b3e0SSimon J. Gerraty  * The OP_ constants are used when parsing a dependency line as a way of
2652c3632d1SSimon J. Gerraty  * communicating to other parts of the program the way in which a target
2662c3632d1SSimon J. Gerraty  * should be made.
2672c3632d1SSimon J. Gerraty  *
26806b9b3e0SSimon J. Gerraty  * Some of the OP_ constants can be combined, others cannot.
269b0c40a00SSimon J. Gerraty  *
270b0c40a00SSimon J. Gerraty  * See the tests depsrc-*.mk and deptgt-*.mk.
27106b9b3e0SSimon J. Gerraty  */
272956e45f6SSimon J. Gerraty typedef enum GNodeType {
273e2eeea75SSimon J. Gerraty 	OP_NONE		= 0,
274e2eeea75SSimon J. Gerraty 
2759f45a3c8SSimon J. Gerraty 	/*
2769f45a3c8SSimon J. Gerraty 	 * The dependency operator ':' is the most common one.  The commands
2779f45a3c8SSimon J. Gerraty 	 * of this node are executed if any child is out-of-date.
2789f45a3c8SSimon J. Gerraty 	 */
2792c3632d1SSimon J. Gerraty 	OP_DEPENDS	= 1 << 0,
2809f45a3c8SSimon J. Gerraty 	/*
2819f45a3c8SSimon J. Gerraty 	 * The dependency operator '!' always executes its commands, even if
2829f45a3c8SSimon J. Gerraty 	 * its children are up-to-date.
2839f45a3c8SSimon J. Gerraty 	 */
2842c3632d1SSimon J. Gerraty 	OP_FORCE	= 1 << 1,
2859f45a3c8SSimon J. Gerraty 	/*
2869f45a3c8SSimon J. Gerraty 	 * The dependency operator '::' behaves like ':', except that it
28706b9b3e0SSimon J. Gerraty 	 * allows multiple dependency groups to be defined.  Each of these
2889f45a3c8SSimon J. Gerraty 	 * groups is executed on its own, independently from the others. Each
2899f45a3c8SSimon J. Gerraty 	 * individual dependency group is called a cohort.
2909f45a3c8SSimon J. Gerraty 	 */
2912c3632d1SSimon J. Gerraty 	OP_DOUBLEDEP	= 1 << 2,
2922c3632d1SSimon J. Gerraty 
293956e45f6SSimon J. Gerraty 	/* Matches the dependency operators ':', '!' and '::'. */
2942c3632d1SSimon J. Gerraty 	OP_OPMASK	= OP_DEPENDS | OP_FORCE | OP_DOUBLEDEP,
2952c3632d1SSimon J. Gerraty 
29606b9b3e0SSimon J. Gerraty 	/* Don't care if the target doesn't exist and can't be created. */
2972c3632d1SSimon J. Gerraty 	OP_OPTIONAL	= 1 << 3,
29806b9b3e0SSimon J. Gerraty 	/* Use associated commands for parents. */
2992c3632d1SSimon J. Gerraty 	OP_USE		= 1 << 4,
3009f45a3c8SSimon J. Gerraty 	/*
3019f45a3c8SSimon J. Gerraty 	 * Target is never out of date, but always execute commands anyway.
3029f45a3c8SSimon J. Gerraty 	 * Its time doesn't matter, so it has none...sort of.
3039f45a3c8SSimon J. Gerraty 	 */
3042c3632d1SSimon J. Gerraty 	OP_EXEC		= 1 << 5,
3059f45a3c8SSimon J. Gerraty 	/*
3069f45a3c8SSimon J. Gerraty 	 * Ignore non-zero exit status from shell commands when creating the
3079f45a3c8SSimon J. Gerraty 	 * node.
3089f45a3c8SSimon J. Gerraty 	 */
3092c3632d1SSimon J. Gerraty 	OP_IGNORE	= 1 << 6,
31006b9b3e0SSimon J. Gerraty 	/* Don't remove the target when interrupted. */
3112c3632d1SSimon J. Gerraty 	OP_PRECIOUS	= 1 << 7,
31206b9b3e0SSimon J. Gerraty 	/* Don't echo commands when executed. */
3132c3632d1SSimon J. Gerraty 	OP_SILENT	= 1 << 8,
3149f45a3c8SSimon J. Gerraty 	/*
3159f45a3c8SSimon J. Gerraty 	 * Target is a recursive make so its commands should always be
3169f45a3c8SSimon J. Gerraty 	 * executed when it is out of date, regardless of the state of the -n
3179f45a3c8SSimon J. Gerraty 	 * or -t flags.
3189f45a3c8SSimon J. Gerraty 	 */
3192c3632d1SSimon J. Gerraty 	OP_MAKE		= 1 << 9,
3209f45a3c8SSimon J. Gerraty 	/*
3219f45a3c8SSimon J. Gerraty 	 * Target is out-of-date only if any of its children was out-of-date.
3229f45a3c8SSimon J. Gerraty 	 */
3232c3632d1SSimon J. Gerraty 	OP_JOIN		= 1 << 10,
32406b9b3e0SSimon J. Gerraty 	/* Assume the children of the node have been already made. */
3252c3632d1SSimon J. Gerraty 	OP_MADE		= 1 << 11,
32606b9b3e0SSimon J. Gerraty 	/* Special .BEGIN, .END or .INTERRUPT. */
3272c3632d1SSimon J. Gerraty 	OP_SPECIAL	= 1 << 12,
32806b9b3e0SSimon J. Gerraty 	/* Like .USE, only prepend commands. */
3292c3632d1SSimon J. Gerraty 	OP_USEBEFORE	= 1 << 13,
3309f45a3c8SSimon J. Gerraty 	/*
3319f45a3c8SSimon J. Gerraty 	 * The node is invisible to its parents. I.e. it doesn't show up in
3329f45a3c8SSimon J. Gerraty 	 * the parents' local variables (.IMPSRC, .ALLSRC).
3339f45a3c8SSimon J. Gerraty 	 */
3342c3632d1SSimon J. Gerraty 	OP_INVISIBLE	= 1 << 14,
3359f45a3c8SSimon J. Gerraty 	/*
3369f45a3c8SSimon J. Gerraty 	 * The node does not become the main target, even if it is the first
3379f45a3c8SSimon J. Gerraty 	 * target in the first makefile.
3389f45a3c8SSimon J. Gerraty 	 */
3392c3632d1SSimon J. Gerraty 	OP_NOTMAIN	= 1 << 15,
34006b9b3e0SSimon J. Gerraty 	/* Not a file target; run always. */
3412c3632d1SSimon J. Gerraty 	OP_PHONY	= 1 << 16,
34206b9b3e0SSimon J. Gerraty 	/* Don't search for the file in the path. */
3432c3632d1SSimon J. Gerraty 	OP_NOPATH	= 1 << 17,
3449f45a3c8SSimon J. Gerraty 	/*
3459f45a3c8SSimon J. Gerraty 	 * In a dependency line "target: source1 .WAIT source2", source1 is
34606b9b3e0SSimon J. Gerraty 	 * made first, including its children.  Once that is finished,
34706b9b3e0SSimon J. Gerraty 	 * source2 is made, including its children.  The .WAIT keyword may
3489f45a3c8SSimon J. Gerraty 	 * appear more than once in a single dependency declaration.
3499f45a3c8SSimon J. Gerraty 	 */
3502c3632d1SSimon J. Gerraty 	OP_WAIT		= 1 << 18,
3512c3632d1SSimon J. Gerraty 	/* .NOMETA do not create a .meta file */
3522c3632d1SSimon J. Gerraty 	OP_NOMETA	= 1 << 19,
3532c3632d1SSimon J. Gerraty 	/* .META we _do_ want a .meta file */
3542c3632d1SSimon J. Gerraty 	OP_META		= 1 << 20,
3552c3632d1SSimon J. Gerraty 	/* Do not compare commands in .meta file */
3562c3632d1SSimon J. Gerraty 	OP_NOMETA_CMP	= 1 << 21,
3572c3632d1SSimon J. Gerraty 	/* Possibly a submake node */
3582c3632d1SSimon J. Gerraty 	OP_SUBMAKE	= 1 << 22,
3592c3632d1SSimon J. Gerraty 
3602c3632d1SSimon J. Gerraty 	/* Attributes applied by PMake */
3612c3632d1SSimon J. Gerraty 
362e2eeea75SSimon J. Gerraty 	/* The node is a transformation rule, such as ".c.o". */
36306b9b3e0SSimon J. Gerraty 	OP_TRANSFORM	= 1 << 30,
3642c3632d1SSimon J. Gerraty 	/* Target is a member of an archive */
365956e45f6SSimon J. Gerraty 	/* XXX: How does this differ from OP_ARCHV? */
36606b9b3e0SSimon J. Gerraty 	OP_MEMBER	= 1 << 29,
3679f45a3c8SSimon J. Gerraty 	/*
3689f45a3c8SSimon J. Gerraty 	 * The node is a library, its name has the form "-l<libname>".
3699f45a3c8SSimon J. Gerraty 	 */
37006b9b3e0SSimon J. Gerraty 	OP_LIB		= 1 << 28,
3719f45a3c8SSimon J. Gerraty 	/*
3729f45a3c8SSimon J. Gerraty 	 * The node is an archive member, its name has the form
3739f45a3c8SSimon J. Gerraty 	 * "archive(member)".
3749f45a3c8SSimon J. Gerraty 	 */
375956e45f6SSimon J. Gerraty 	/* XXX: How does this differ from OP_MEMBER? */
37606b9b3e0SSimon J. Gerraty 	OP_ARCHV	= 1 << 27,
3779f45a3c8SSimon J. Gerraty 	/*
3789f45a3c8SSimon J. Gerraty 	 * Target has all the commands it should. Used when parsing to catch
37906b9b3e0SSimon J. Gerraty 	 * multiple command groups for a target.  Only applies to the
3809f45a3c8SSimon J. Gerraty 	 * dependency operators ':' and '!', but not to '::'.
3819f45a3c8SSimon J. Gerraty 	 */
38206b9b3e0SSimon J. Gerraty 	OP_HAS_COMMANDS	= 1 << 26,
3839f45a3c8SSimon J. Gerraty 	/*
3849f45a3c8SSimon J. Gerraty 	 * The special command "..." has been seen. All further commands from
3859f45a3c8SSimon J. Gerraty 	 * this node will be saved on the .END node instead, to be executed
3869f45a3c8SSimon J. Gerraty 	 * at the very end.
3879f45a3c8SSimon J. Gerraty 	 */
38806b9b3e0SSimon J. Gerraty 	OP_SAVE_CMDS	= 1 << 25,
3899f45a3c8SSimon J. Gerraty 	/*
3909f45a3c8SSimon J. Gerraty 	 * Already processed by Suff_FindDeps, to find dependencies from
3919f45a3c8SSimon J. Gerraty 	 * suffix transformation rules.
3929f45a3c8SSimon J. Gerraty 	 */
39306b9b3e0SSimon J. Gerraty 	OP_DEPS_FOUND	= 1 << 24,
3942c3632d1SSimon J. Gerraty 	/* Node found while expanding .ALLSRC */
3959f45a3c8SSimon J. Gerraty 	OP_MARK		= 1 << 23
3962c3632d1SSimon J. Gerraty } GNodeType;
3972c3632d1SSimon J. Gerraty 
39812904384SSimon J. Gerraty typedef struct GNodeFlags {
39906b9b3e0SSimon J. Gerraty 	/* this target needs to be (re)made */
40012904384SSimon J. Gerraty 	bool remake:1;
40106b9b3e0SSimon J. Gerraty 	/* children of this target were made */
40212904384SSimon J. Gerraty 	bool childMade:1;
40306b9b3e0SSimon J. Gerraty 	/* children don't exist, and we pretend made */
40412904384SSimon J. Gerraty 	bool force:1;
40506b9b3e0SSimon J. Gerraty 	/* Set by Make_ProcessWait() */
40612904384SSimon J. Gerraty 	bool doneWait:1;
40706b9b3e0SSimon J. Gerraty 	/* Build requested by .ORDER processing */
40812904384SSimon J. Gerraty 	bool doneOrder:1;
40906b9b3e0SSimon J. Gerraty 	/* Node created from .depend */
41012904384SSimon J. Gerraty 	bool fromDepend:1;
41106b9b3e0SSimon J. Gerraty 	/* We do it once only */
41212904384SSimon J. Gerraty 	bool doneAllsrc:1;
41306b9b3e0SSimon J. Gerraty 	/* Used by MakePrintStatus */
41412904384SSimon J. Gerraty 	bool cycle:1;
41506b9b3e0SSimon J. Gerraty 	/* Used by MakePrintStatus */
41612904384SSimon J. Gerraty 	bool doneCycle:1;
4172c3632d1SSimon J. Gerraty } GNodeFlags;
4182c3632d1SSimon J. Gerraty 
419956e45f6SSimon J. Gerraty typedef struct List StringList;
420956e45f6SSimon J. Gerraty typedef struct ListNode StringListNode;
421956e45f6SSimon J. Gerraty 
422956e45f6SSimon J. Gerraty typedef struct List GNodeList;
423956e45f6SSimon J. Gerraty typedef struct ListNode GNodeListNode;
424956e45f6SSimon J. Gerraty 
425dba7b0efSSimon J. Gerraty typedef struct SearchPath {
426dba7b0efSSimon J. Gerraty 	List /* of CachedDir */ dirs;
427dba7b0efSSimon J. Gerraty } SearchPath;
428956e45f6SSimon J. Gerraty 
42906b9b3e0SSimon J. Gerraty /*
43006b9b3e0SSimon J. Gerraty  * A graph node represents a target that can possibly be made, including its
431548bfc56SSimon J. Gerraty  * relation to other targets.
43206b9b3e0SSimon J. Gerraty  */
4332c3632d1SSimon J. Gerraty typedef struct GNode {
4342c3632d1SSimon J. Gerraty 	/* The target's name, such as "clean" or "make.c" */
4352c3632d1SSimon J. Gerraty 	char *name;
4362c3632d1SSimon J. Gerraty 	/* The unexpanded name of a .USE node */
4372c3632d1SSimon J. Gerraty 	char *uname;
4389f45a3c8SSimon J. Gerraty 	/*
4399f45a3c8SSimon J. Gerraty 	 * The full pathname of the file belonging to the target.
4409f45a3c8SSimon J. Gerraty 	 *
44106b9b3e0SSimon J. Gerraty 	 * XXX: What about .PHONY targets? These don't have an associated
4429f45a3c8SSimon J. Gerraty 	 * path.
4439f45a3c8SSimon J. Gerraty 	 */
4442c3632d1SSimon J. Gerraty 	char *path;
4452c3632d1SSimon J. Gerraty 
4469f45a3c8SSimon J. Gerraty 	/*
4479f45a3c8SSimon J. Gerraty 	 * The type of operator used to define the sources (see the OP flags
44806b9b3e0SSimon J. Gerraty 	 * below).
4499f45a3c8SSimon J. Gerraty 	 *
4509f45a3c8SSimon J. Gerraty 	 * XXX: This looks like a wild mixture of type and flags.
4519f45a3c8SSimon J. Gerraty 	 */
4522c3632d1SSimon J. Gerraty 	GNodeType type;
4532c3632d1SSimon J. Gerraty 	GNodeFlags flags;
4542c3632d1SSimon J. Gerraty 
4552c3632d1SSimon J. Gerraty 	/* The state of processing on this node */
4562c3632d1SSimon J. Gerraty 	GNodeMade made;
45706b9b3e0SSimon J. Gerraty 	/* The number of unmade children */
45806b9b3e0SSimon J. Gerraty 	int unmade;
4593955d011SMarcel Moolenaar 
4609f45a3c8SSimon J. Gerraty 	/*
4619f45a3c8SSimon J. Gerraty 	 * The modification time; 0 means the node does not have a
4629f45a3c8SSimon J. Gerraty 	 * corresponding file; see GNode_IsOODate.
4639f45a3c8SSimon J. Gerraty 	 */
464956e45f6SSimon J. Gerraty 	time_t mtime;
465956e45f6SSimon J. Gerraty 	struct GNode *youngestChild;
4663955d011SMarcel Moolenaar 
4679f45a3c8SSimon J. Gerraty 	/*
4689f45a3c8SSimon J. Gerraty 	 * The GNodes for which this node is an implied source. May be empty.
4699f45a3c8SSimon J. Gerraty 	 * For example, when there is an inference rule for .c.o, the node
4709f45a3c8SSimon J. Gerraty 	 * for file.c has the node for file.o in this list.
4719f45a3c8SSimon J. Gerraty 	 */
47206b9b3e0SSimon J. Gerraty 	GNodeList implicitParents;
4733955d011SMarcel Moolenaar 
4749f45a3c8SSimon J. Gerraty 	/*
4759f45a3c8SSimon J. Gerraty 	 * The nodes that depend on this one, or in other words, the nodes
4769f45a3c8SSimon J. Gerraty 	 * for which this is a source.
4779f45a3c8SSimon J. Gerraty 	 */
47806b9b3e0SSimon J. Gerraty 	GNodeList parents;
4792c3632d1SSimon J. Gerraty 	/* The nodes on which this one depends. */
48006b9b3e0SSimon J. Gerraty 	GNodeList children;
4813955d011SMarcel Moolenaar 
4829f45a3c8SSimon J. Gerraty 	/*
4839f45a3c8SSimon J. Gerraty 	 * .ORDER nodes we need made. The nodes that must be made (if they're
4842c3632d1SSimon J. Gerraty 	 * made) before this node can be made, but that do not enter into the
4859f45a3c8SSimon J. Gerraty 	 * datedness of this node.
4869f45a3c8SSimon J. Gerraty 	 */
48706b9b3e0SSimon J. Gerraty 	GNodeList order_pred;
4889f45a3c8SSimon J. Gerraty 	/*
4899f45a3c8SSimon J. Gerraty 	 * .ORDER nodes who need us. The nodes that must be made (if they're
49006b9b3e0SSimon J. Gerraty 	 * made at all) after this node is made, but that do not depend on
4919f45a3c8SSimon J. Gerraty 	 * this node, in the normal sense.
4929f45a3c8SSimon J. Gerraty 	 */
49306b9b3e0SSimon J. Gerraty 	GNodeList order_succ;
4942c3632d1SSimon J. Gerraty 
495dba7b0efSSimon J. Gerraty 	/*
496dba7b0efSSimon J. Gerraty 	 * Other nodes of the same name, for targets that were defined using
497dba7b0efSSimon J. Gerraty 	 * the '::' dependency operator (OP_DOUBLEDEP).
498dba7b0efSSimon J. Gerraty 	 */
49906b9b3e0SSimon J. Gerraty 	GNodeList cohorts;
500956e45f6SSimon J. Gerraty 	/* The "#n" suffix for this cohort, or "" for other nodes */
5012c3632d1SSimon J. Gerraty 	char cohort_num[8];
5022c3632d1SSimon J. Gerraty 	/* The number of unmade instances on the cohorts list */
5032c3632d1SSimon J. Gerraty 	int unmade_cohorts;
5049f45a3c8SSimon J. Gerraty 	/*
5059f45a3c8SSimon J. Gerraty 	 * Pointer to the first instance of a '::' node; only set when on a
5069f45a3c8SSimon J. Gerraty 	 * cohorts list
5079f45a3c8SSimon J. Gerraty 	 */
5082c3632d1SSimon J. Gerraty 	struct GNode *centurion;
5092c3632d1SSimon J. Gerraty 
5102c3632d1SSimon J. Gerraty 	/* Last time (sequence number) we tried to make this node */
511956e45f6SSimon J. Gerraty 	unsigned int checked_seqno;
5122c3632d1SSimon J. Gerraty 
513dba7b0efSSimon J. Gerraty 	/*
514dba7b0efSSimon J. Gerraty 	 * The "local" variables that are specific to this target and this
51506b9b3e0SSimon J. Gerraty 	 * target only, such as $@, $<, $?.
516956e45f6SSimon J. Gerraty 	 *
517dba7b0efSSimon J. Gerraty 	 * Also used for the global variable scopes SCOPE_GLOBAL,
518dba7b0efSSimon J. Gerraty 	 * SCOPE_CMDLINE, SCOPE_INTERNAL, which contain variables with
519dba7b0efSSimon J. Gerraty 	 * arbitrary names.
520dba7b0efSSimon J. Gerraty 	 */
52106b9b3e0SSimon J. Gerraty 	HashTable /* of Var pointer */ vars;
5222c3632d1SSimon J. Gerraty 
5232c3632d1SSimon J. Gerraty 	/* The commands to be given to a shell to create this target. */
52406b9b3e0SSimon J. Gerraty 	StringList commands;
5252c3632d1SSimon J. Gerraty 
5269f45a3c8SSimon J. Gerraty 	/*
5279f45a3c8SSimon J. Gerraty 	 * Suffix for the node (determined by Suff_FindDeps and opaque to
5289f45a3c8SSimon J. Gerraty 	 * everyone but the Suff module)
5299f45a3c8SSimon J. Gerraty 	 */
53006b9b3e0SSimon J. Gerraty 	struct Suffix *suffix;
5312c3632d1SSimon J. Gerraty 
5329f45a3c8SSimon J. Gerraty 	/* Filename where the GNode got defined, unlimited lifetime */
5332c3632d1SSimon J. Gerraty 	const char *fname;
5349f45a3c8SSimon J. Gerraty 	/* Line number where the GNode got defined, 1-based */
5359f45a3c8SSimon J. Gerraty 	unsigned lineno;
536c59c3bf3SSimon J. Gerraty 	int exit_status;
5373955d011SMarcel Moolenaar } GNode;
5383955d011SMarcel Moolenaar 
5392f2a5ecdSSimon J. Gerraty /*
5402f2a5ecdSSimon J. Gerraty  * Keep track of whether to include <posix.mk> when parsing the line
5412f2a5ecdSSimon J. Gerraty  * '.POSIX:'.
5422f2a5ecdSSimon J. Gerraty  */
5432f2a5ecdSSimon J. Gerraty extern enum PosixState {
5442f2a5ecdSSimon J. Gerraty 	PS_NOT_YET,
5452f2a5ecdSSimon J. Gerraty 	PS_MAYBE_NEXT_LINE,
5462f2a5ecdSSimon J. Gerraty 	PS_NOW_OR_NEVER,
5472f2a5ecdSSimon J. Gerraty 	PS_TOO_LATE
5482f2a5ecdSSimon J. Gerraty } posix_state;
5492f2a5ecdSSimon J. Gerraty 
550e2eeea75SSimon J. Gerraty /* Error levels for diagnostics during parsing. */
551956e45f6SSimon J. Gerraty typedef enum ParseErrorLevel {
5529f45a3c8SSimon J. Gerraty 	/*
5539f45a3c8SSimon J. Gerraty 	 * Exit when the current top-level makefile has been parsed
5549f45a3c8SSimon J. Gerraty 	 * completely.
5559f45a3c8SSimon J. Gerraty 	 */
556956e45f6SSimon J. Gerraty 	PARSE_FATAL = 1,
557e2eeea75SSimon J. Gerraty 	/* Print "warning"; may be upgraded to fatal by the -w option. */
558956e45f6SSimon J. Gerraty 	PARSE_WARNING,
559e2eeea75SSimon J. Gerraty 	/* Informational, mainly used during development of makefiles. */
560956e45f6SSimon J. Gerraty 	PARSE_INFO
561956e45f6SSimon J. Gerraty } ParseErrorLevel;
5623955d011SMarcel Moolenaar 
5633955d011SMarcel Moolenaar /*
564956e45f6SSimon J. Gerraty  * Values returned by Cond_EvalLine and Cond_EvalCondition.
5653955d011SMarcel Moolenaar  */
5669f45a3c8SSimon J. Gerraty typedef enum CondResult {
5679f45a3c8SSimon J. Gerraty 	CR_TRUE,		/* Parse the next lines */
5689f45a3c8SSimon J. Gerraty 	CR_FALSE,		/* Skip the next lines */
5699f45a3c8SSimon J. Gerraty 	CR_ERROR		/* Unknown directive or parse error */
5709f45a3c8SSimon J. Gerraty } CondResult;
5713955d011SMarcel Moolenaar 
572148ee845SSimon J. Gerraty typedef struct {
573148ee845SSimon J. Gerraty 	enum GuardKind {
574148ee845SSimon J. Gerraty 		GK_VARIABLE,
575148ee845SSimon J. Gerraty 		GK_TARGET
576148ee845SSimon J. Gerraty 	} kind;
577148ee845SSimon J. Gerraty 	char *name;
578148ee845SSimon J. Gerraty } Guard;
579148ee845SSimon J. Gerraty 
580e2eeea75SSimon J. Gerraty /* Names of the variables that are "local" to a specific target. */
5813955d011SMarcel Moolenaar #define TARGET	"@"		/* Target of dependency */
5823955d011SMarcel Moolenaar #define OODATE	"?"		/* All out-of-date sources */
5833955d011SMarcel Moolenaar #define ALLSRC	">"		/* All sources */
5843955d011SMarcel Moolenaar #define IMPSRC	"<"		/* Source implied by transformation */
5853955d011SMarcel Moolenaar #define PREFIX	"*"		/* Common prefix */
5863955d011SMarcel Moolenaar #define ARCHIVE	"!"		/* Archive in "archive(member)" syntax */
5873955d011SMarcel Moolenaar #define MEMBER	"%"		/* Member in "archive(member)" syntax */
5883955d011SMarcel Moolenaar 
5893955d011SMarcel Moolenaar /*
5903955d011SMarcel Moolenaar  * Global Variables
5913955d011SMarcel Moolenaar  */
5923955d011SMarcel Moolenaar 
593e2eeea75SSimon J. Gerraty /* True if every target is precious */
594b0c40a00SSimon J. Gerraty extern bool allPrecious;
595e2eeea75SSimon J. Gerraty /* True if failed targets should be deleted */
596b0c40a00SSimon J. Gerraty extern bool deleteOnError;
597b0c40a00SSimon J. Gerraty /* true while processing .depend */
598b0c40a00SSimon J. Gerraty extern bool doing_depend;
599e2eeea75SSimon J. Gerraty /* .DEFAULT rule */
600e2eeea75SSimon J. Gerraty extern GNode *defaultNode;
6013955d011SMarcel Moolenaar 
60206b9b3e0SSimon J. Gerraty /*
60306b9b3e0SSimon J. Gerraty  * Variables defined internally by make which should not override those set
60406b9b3e0SSimon J. Gerraty  * by makefiles.
60506b9b3e0SSimon J. Gerraty  */
606dba7b0efSSimon J. Gerraty extern GNode *SCOPE_INTERNAL;
607dba7b0efSSimon J. Gerraty /* Variables defined in a global scope, e.g in the makefile itself. */
608dba7b0efSSimon J. Gerraty extern GNode *SCOPE_GLOBAL;
609e2eeea75SSimon J. Gerraty /* Variables defined on the command line. */
610dba7b0efSSimon J. Gerraty extern GNode *SCOPE_CMDLINE;
611e2eeea75SSimon J. Gerraty 
61206b9b3e0SSimon J. Gerraty /*
613548bfc56SSimon J. Gerraty  * Value returned by Var_Parse when an error is encountered. It points to an
614548bfc56SSimon J. Gerraty  * empty string, so naive callers needn't worry about it.
61506b9b3e0SSimon J. Gerraty  */
616e2eeea75SSimon J. Gerraty extern char var_Error[];
617e2eeea75SSimon J. Gerraty 
618e2eeea75SSimon J. Gerraty /* The time at the start of this whole process */
619e2eeea75SSimon J. Gerraty extern time_t now;
620e2eeea75SSimon J. Gerraty 
621e2eeea75SSimon J. Gerraty /*
62206b9b3e0SSimon J. Gerraty  * The list of directories to search when looking for targets (set by the
62306b9b3e0SSimon J. Gerraty  * special target .PATH).
6241bbe5942SSimon J. Gerraty  */
62506b9b3e0SSimon J. Gerraty extern SearchPath dirSearchPath;
626e2eeea75SSimon J. Gerraty /* Used for .include "...". */
627e2eeea75SSimon J. Gerraty extern SearchPath *parseIncPath;
62806b9b3e0SSimon J. Gerraty /*
629dba7b0efSSimon J. Gerraty  * Used for .include <...>, for the built-in sys.mk and for makefiles from
630dba7b0efSSimon J. Gerraty  * the command line arguments.
63106b9b3e0SSimon J. Gerraty  */
632e2eeea75SSimon J. Gerraty extern SearchPath *sysIncPath;
633e2eeea75SSimon J. Gerraty /* The default for sysIncPath. */
634e2eeea75SSimon J. Gerraty extern SearchPath *defSysIncPath;
6353955d011SMarcel Moolenaar 
636e2eeea75SSimon J. Gerraty /* Startup directory */
637e2eeea75SSimon J. Gerraty extern char curdir[];
638e2eeea75SSimon J. Gerraty /* The basename of the program name, suffixed with [n] for sub-makes.  */
63906b9b3e0SSimon J. Gerraty extern const char *progname;
640dba7b0efSSimon J. Gerraty extern int makelevel;
641e2eeea75SSimon J. Gerraty /* Name of the .depend makefile */
642e2eeea75SSimon J. Gerraty extern char *makeDependfile;
643e2eeea75SSimon J. Gerraty /* If we replaced environ, this will be non-NULL. */
644e2eeea75SSimon J. Gerraty extern char **savedEnv;
6459f45a3c8SSimon J. Gerraty extern GNode *mainNode;
6463955d011SMarcel Moolenaar 
6473955d011SMarcel Moolenaar extern pid_t myPid;
6483955d011SMarcel Moolenaar 
6493955d011SMarcel Moolenaar #define MAKEFLAGS	".MAKEFLAGS"
65051ee2c1cSSimon J. Gerraty #ifndef MAKE_LEVEL_ENV
65151ee2c1cSSimon J. Gerraty # define MAKE_LEVEL_ENV	"MAKELEVEL"
6523955d011SMarcel Moolenaar #endif
6533955d011SMarcel Moolenaar 
6549f45a3c8SSimon J. Gerraty typedef struct DebugFlags {
6559f45a3c8SSimon J. Gerraty 	bool DEBUG_ARCH:1;
6569f45a3c8SSimon J. Gerraty 	bool DEBUG_COND:1;
6579f45a3c8SSimon J. Gerraty 	bool DEBUG_CWD:1;
6589f45a3c8SSimon J. Gerraty 	bool DEBUG_DIR:1;
6599f45a3c8SSimon J. Gerraty 	bool DEBUG_ERROR:1;
6609f45a3c8SSimon J. Gerraty 	bool DEBUG_FOR:1;
6619f45a3c8SSimon J. Gerraty 	bool DEBUG_GRAPH1:1;
6629f45a3c8SSimon J. Gerraty 	bool DEBUG_GRAPH2:1;
6639f45a3c8SSimon J. Gerraty 	bool DEBUG_GRAPH3:1;
6649f45a3c8SSimon J. Gerraty 	bool DEBUG_HASH:1;
6659f45a3c8SSimon J. Gerraty 	bool DEBUG_JOB:1;
6669f45a3c8SSimon J. Gerraty 	bool DEBUG_LOUD:1;
6679f45a3c8SSimon J. Gerraty 	bool DEBUG_MAKE:1;
6689f45a3c8SSimon J. Gerraty 	bool DEBUG_META:1;
6699f45a3c8SSimon J. Gerraty 	bool DEBUG_PARSE:1;
6709f45a3c8SSimon J. Gerraty 	bool DEBUG_SCRIPT:1;
6719f45a3c8SSimon J. Gerraty 	bool DEBUG_SHELL:1;
6729f45a3c8SSimon J. Gerraty 	bool DEBUG_SUFF:1;
6739f45a3c8SSimon J. Gerraty 	bool DEBUG_TARG:1;
6749f45a3c8SSimon J. Gerraty 	bool DEBUG_VAR:1;
675956e45f6SSimon J. Gerraty } DebugFlags;
6762c3632d1SSimon J. Gerraty 
6773955d011SMarcel Moolenaar #define CONCAT(a, b) a##b
6783955d011SMarcel Moolenaar 
6799f45a3c8SSimon J. Gerraty #define DEBUG(module) (opts.debug.CONCAT(DEBUG_, module))
680956e45f6SSimon J. Gerraty 
681956e45f6SSimon J. Gerraty void debug_printf(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
682956e45f6SSimon J. Gerraty 
68306b9b3e0SSimon J. Gerraty #define DEBUG_IMPL(module, args) \
68406b9b3e0SSimon J. Gerraty 	do { \
68506b9b3e0SSimon J. Gerraty 		if (DEBUG(module)) \
68606b9b3e0SSimon J. Gerraty 			debug_printf args; \
68712904384SSimon J. Gerraty 	} while (false)
68806b9b3e0SSimon J. Gerraty 
6899f45a3c8SSimon J. Gerraty #define DEBUG0(module, fmt) \
6909f45a3c8SSimon J. Gerraty 	DEBUG_IMPL(module, (fmt))
691956e45f6SSimon J. Gerraty #define DEBUG1(module, fmt, arg1) \
69206b9b3e0SSimon J. Gerraty 	DEBUG_IMPL(module, (fmt, arg1))
693956e45f6SSimon J. Gerraty #define DEBUG2(module, fmt, arg1, arg2) \
69406b9b3e0SSimon J. Gerraty 	DEBUG_IMPL(module, (fmt, arg1, arg2))
695956e45f6SSimon J. Gerraty #define DEBUG3(module, fmt, arg1, arg2, arg3) \
69606b9b3e0SSimon J. Gerraty 	DEBUG_IMPL(module, (fmt, arg1, arg2, arg3))
697956e45f6SSimon J. Gerraty #define DEBUG4(module, fmt, arg1, arg2, arg3, arg4) \
69806b9b3e0SSimon J. Gerraty 	DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4))
699956e45f6SSimon J. Gerraty #define DEBUG5(module, fmt, arg1, arg2, arg3, arg4, arg5) \
70006b9b3e0SSimon J. Gerraty 	DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4, arg5))
701956e45f6SSimon J. Gerraty 
702956e45f6SSimon J. Gerraty typedef enum PrintVarsMode {
703e2eeea75SSimon J. Gerraty 	PVM_NONE,
704e2eeea75SSimon J. Gerraty 	PVM_UNEXPANDED,
705e2eeea75SSimon J. Gerraty 	PVM_EXPANDED
706956e45f6SSimon J. Gerraty } PrintVarsMode;
707956e45f6SSimon J. Gerraty 
708956e45f6SSimon J. Gerraty /* Command line options */
709956e45f6SSimon J. Gerraty typedef struct CmdOpts {
710548bfc56SSimon J. Gerraty 	/* -B: whether to be compatible to traditional make */
711b0c40a00SSimon J. Gerraty 	bool compatMake;
712956e45f6SSimon J. Gerraty 
7139f45a3c8SSimon J. Gerraty 	/*
714548bfc56SSimon J. Gerraty 	 * -d: debug control: There is one flag per module.  It is up to the
7159f45a3c8SSimon J. Gerraty 	 * module what debug information to print.
7169f45a3c8SSimon J. Gerraty 	 */
717956e45f6SSimon J. Gerraty 	DebugFlags debug;
718956e45f6SSimon J. Gerraty 
719956e45f6SSimon J. Gerraty 	/* -df: debug output is written here - default stderr */
720956e45f6SSimon J. Gerraty 	FILE *debug_file;
721956e45f6SSimon J. Gerraty 
7229f45a3c8SSimon J. Gerraty 	/*
7239f45a3c8SSimon J. Gerraty 	 * -dL: lint mode
724e2eeea75SSimon J. Gerraty 	 *
725e2eeea75SSimon J. Gerraty 	 * Runs make in strict mode, with additional checks and better error
7269f45a3c8SSimon J. Gerraty 	 * handling.
7279f45a3c8SSimon J. Gerraty 	 */
728b0c40a00SSimon J. Gerraty 	bool strict;
729e2eeea75SSimon J. Gerraty 
730956e45f6SSimon J. Gerraty 	/* -dV: for the -V option, print unexpanded variable values */
731b0c40a00SSimon J. Gerraty 	bool debugVflag;
732956e45f6SSimon J. Gerraty 
733956e45f6SSimon J. Gerraty 	/* -e: check environment variables before global variables */
734b0c40a00SSimon J. Gerraty 	bool checkEnvFirst;
735956e45f6SSimon J. Gerraty 
736956e45f6SSimon J. Gerraty 	/* -f: the makefiles to read */
73706b9b3e0SSimon J. Gerraty 	StringList makefiles;
738956e45f6SSimon J. Gerraty 
739956e45f6SSimon J. Gerraty 	/* -i: if true, ignore all errors from shell commands */
740b0c40a00SSimon J. Gerraty 	bool ignoreErrors;
741956e45f6SSimon J. Gerraty 
7429f45a3c8SSimon J. Gerraty 	/*
7439f45a3c8SSimon J. Gerraty 	 * -j: the maximum number of jobs that can run in parallel; this is
7449f45a3c8SSimon J. Gerraty 	 * coordinated with the submakes
7459f45a3c8SSimon J. Gerraty 	 */
746956e45f6SSimon J. Gerraty 	int maxJobs;
747956e45f6SSimon J. Gerraty 
7489f45a3c8SSimon J. Gerraty 	/*
7499f45a3c8SSimon J. Gerraty 	 * -k: if true and an error occurs while making a node, continue
7509f45a3c8SSimon J. Gerraty 	 * making nodes that do not depend on the erroneous node
7519f45a3c8SSimon J. Gerraty 	 */
752b0c40a00SSimon J. Gerraty 	bool keepgoing;
753956e45f6SSimon J. Gerraty 
754956e45f6SSimon J. Gerraty 	/* -N: execute no commands from the targets */
755b0c40a00SSimon J. Gerraty 	bool noRecursiveExecute;
756956e45f6SSimon J. Gerraty 
757956e45f6SSimon J. Gerraty 	/* -n: execute almost no commands from the targets */
758b0c40a00SSimon J. Gerraty 	bool noExecute;
759956e45f6SSimon J. Gerraty 
760dba7b0efSSimon J. Gerraty 	/*
761dba7b0efSSimon J. Gerraty 	 * -q: if true, do not really make anything, just see if the targets
762dba7b0efSSimon J. Gerraty 	 * are out-of-date
763dba7b0efSSimon J. Gerraty 	 */
7649f45a3c8SSimon J. Gerraty 	bool query;
765956e45f6SSimon J. Gerraty 
766dba7b0efSSimon J. Gerraty 	/* -r: raw mode, do not load the builtin rules. */
767b0c40a00SSimon J. Gerraty 	bool noBuiltins;
768956e45f6SSimon J. Gerraty 
769956e45f6SSimon J. Gerraty 	/* -s: don't echo the shell commands before executing them */
7709f45a3c8SSimon J. Gerraty 	bool silent;
771956e45f6SSimon J. Gerraty 
7729f45a3c8SSimon J. Gerraty 	/*
7739f45a3c8SSimon J. Gerraty 	 * -t: touch the targets if they are out-of-date, but don't actually
7749f45a3c8SSimon J. Gerraty 	 * make them
7759f45a3c8SSimon J. Gerraty 	 */
7769f45a3c8SSimon J. Gerraty 	bool touch;
777956e45f6SSimon J. Gerraty 
778956e45f6SSimon J. Gerraty 	/* -[Vv]: print expanded or unexpanded selected variables */
779956e45f6SSimon J. Gerraty 	PrintVarsMode printVars;
780956e45f6SSimon J. Gerraty 	/* -[Vv]: the variables to print */
78106b9b3e0SSimon J. Gerraty 	StringList variables;
782956e45f6SSimon J. Gerraty 
783956e45f6SSimon J. Gerraty 	/* -W: if true, makefile parsing warnings are treated as errors */
784b0c40a00SSimon J. Gerraty 	bool parseWarnFatal;
785956e45f6SSimon J. Gerraty 
786dba7b0efSSimon J. Gerraty 	/* -w: print 'Entering' and 'Leaving' for submakes */
787b0c40a00SSimon J. Gerraty 	bool enterFlag;
788956e45f6SSimon J. Gerraty 
7899f45a3c8SSimon J. Gerraty 	/*
7909f45a3c8SSimon J. Gerraty 	 * -X: if true, do not export variables set on the command line to
7919f45a3c8SSimon J. Gerraty 	 * the environment.
7929f45a3c8SSimon J. Gerraty 	 */
793b0c40a00SSimon J. Gerraty 	bool varNoExportEnv;
794956e45f6SSimon J. Gerraty 
7959f45a3c8SSimon J. Gerraty 	/*
7969f45a3c8SSimon J. Gerraty 	 * The target names specified on the command line. Used to resolve
7979f45a3c8SSimon J. Gerraty 	 * .if make(...) statements.
7989f45a3c8SSimon J. Gerraty 	 */
79906b9b3e0SSimon J. Gerraty 	StringList create;
800956e45f6SSimon J. Gerraty 
801954401e6SSimon J. Gerraty 	/*
802954401e6SSimon J. Gerraty 	 * Randomize the order in which the targets from toBeMade are made,
803954401e6SSimon J. Gerraty 	 * to catch undeclared dependencies.
804954401e6SSimon J. Gerraty 	 */
805954401e6SSimon J. Gerraty 	bool randomizeTargets;
806956e45f6SSimon J. Gerraty } CmdOpts;
807956e45f6SSimon J. Gerraty 
808956e45f6SSimon J. Gerraty extern CmdOpts opts;
8098c973ee2SSimon J. Gerraty extern bool forceJobs;
8108c973ee2SSimon J. Gerraty extern char **environ;
8113955d011SMarcel Moolenaar 
8129f45a3c8SSimon J. Gerraty /* arch.c */
8139f45a3c8SSimon J. Gerraty void Arch_Init(void);
8149f45a3c8SSimon J. Gerraty void Arch_End(void);
8153955d011SMarcel Moolenaar 
8169f45a3c8SSimon J. Gerraty bool Arch_ParseArchive(char **, GNodeList *, GNode *);
8179f45a3c8SSimon J. Gerraty void Arch_Touch(GNode *);
8189f45a3c8SSimon J. Gerraty void Arch_TouchLib(GNode *);
819148ee845SSimon J. Gerraty void Arch_UpdateMTime(GNode *);
820148ee845SSimon J. Gerraty void Arch_UpdateMemberMTime(GNode *);
8219f45a3c8SSimon J. Gerraty void Arch_FindLib(GNode *, SearchPath *);
8229f45a3c8SSimon J. Gerraty bool Arch_LibOODate(GNode *) MAKE_ATTR_USE;
8239f45a3c8SSimon J. Gerraty bool Arch_IsLib(GNode *) MAKE_ATTR_USE;
8249f45a3c8SSimon J. Gerraty 
8259f45a3c8SSimon J. Gerraty /* compat.c */
8269f45a3c8SSimon J. Gerraty bool Compat_RunCommand(const char *, GNode *, StringListNode *);
827954401e6SSimon J. Gerraty void Compat_MakeAll(GNodeList *);
8289f45a3c8SSimon J. Gerraty void Compat_Make(GNode *, GNode *);
8299f45a3c8SSimon J. Gerraty 
8309f45a3c8SSimon J. Gerraty /* cond.c */
8314fde40d9SSimon J. Gerraty extern unsigned int cond_depth;
8329f45a3c8SSimon J. Gerraty CondResult Cond_EvalCondition(const char *) MAKE_ATTR_USE;
8339f45a3c8SSimon J. Gerraty CondResult Cond_EvalLine(const char *) MAKE_ATTR_USE;
834148ee845SSimon J. Gerraty Guard *Cond_ExtractGuard(const char *) MAKE_ATTR_USE;
8354fde40d9SSimon J. Gerraty void Cond_EndFile(void);
8369f45a3c8SSimon J. Gerraty 
8379f45a3c8SSimon J. Gerraty /* dir.c; see also dir.h */
8389f45a3c8SSimon J. Gerraty 
8399f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE
str_basename(const char * pathname)8409f45a3c8SSimon J. Gerraty str_basename(const char *pathname)
8419f45a3c8SSimon J. Gerraty {
8429f45a3c8SSimon J. Gerraty 	const char *lastSlash = strrchr(pathname, '/');
8439f45a3c8SSimon J. Gerraty 	return lastSlash != NULL ? lastSlash + 1 : pathname;
8449f45a3c8SSimon J. Gerraty }
8459f45a3c8SSimon J. Gerraty 
8469f45a3c8SSimon J. Gerraty MAKE_INLINE SearchPath * MAKE_ATTR_USE
SearchPath_New(void)8479f45a3c8SSimon J. Gerraty SearchPath_New(void)
8489f45a3c8SSimon J. Gerraty {
8499f45a3c8SSimon J. Gerraty 	SearchPath *path = bmake_malloc(sizeof *path);
8509f45a3c8SSimon J. Gerraty 	Lst_Init(&path->dirs);
8519f45a3c8SSimon J. Gerraty 	return path;
8529f45a3c8SSimon J. Gerraty }
8539f45a3c8SSimon J. Gerraty 
8549f45a3c8SSimon J. Gerraty void SearchPath_Free(SearchPath *);
8559f45a3c8SSimon J. Gerraty 
8569f45a3c8SSimon J. Gerraty /* for.c */
8579f45a3c8SSimon J. Gerraty struct ForLoop;
8589f45a3c8SSimon J. Gerraty int For_Eval(const char *) MAKE_ATTR_USE;
8599f45a3c8SSimon J. Gerraty bool For_Accum(const char *, int *) MAKE_ATTR_USE;
8609f45a3c8SSimon J. Gerraty void For_Run(unsigned, unsigned);
8619f45a3c8SSimon J. Gerraty bool For_NextIteration(struct ForLoop *, Buffer *);
862148ee845SSimon J. Gerraty char *ForLoop_Details(const struct ForLoop *);
8639f45a3c8SSimon J. Gerraty void ForLoop_Free(struct ForLoop *);
8644fde40d9SSimon J. Gerraty void For_Break(struct ForLoop *);
8659f45a3c8SSimon J. Gerraty 
8669f45a3c8SSimon J. Gerraty /* job.c */
8679f45a3c8SSimon J. Gerraty void JobReapChild(pid_t, int, bool);
8689f45a3c8SSimon J. Gerraty 
8699f45a3c8SSimon J. Gerraty /* main.c */
8709f45a3c8SSimon J. Gerraty void Main_ParseArgLine(const char *);
8719f45a3c8SSimon J. Gerraty char *Cmd_Exec(const char *, char **) MAKE_ATTR_USE;
8729f45a3c8SSimon J. Gerraty void Error(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
8739f45a3c8SSimon J. Gerraty void Fatal(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
8749f45a3c8SSimon J. Gerraty void Punt(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
8759f45a3c8SSimon J. Gerraty void DieHorribly(void) MAKE_ATTR_DEAD;
8769f45a3c8SSimon J. Gerraty void Finish(int) MAKE_ATTR_DEAD;
8774fde40d9SSimon J. Gerraty int unlink_file(const char *) MAKE_ATTR_USE;
8789f45a3c8SSimon J. Gerraty void execDie(const char *, const char *);
8799f45a3c8SSimon J. Gerraty char *getTmpdir(void) MAKE_ATTR_USE;
8809f45a3c8SSimon J. Gerraty bool ParseBoolean(const char *, bool) MAKE_ATTR_USE;
8819f45a3c8SSimon J. Gerraty const char *cached_realpath(const char *, char *);
8829f45a3c8SSimon J. Gerraty bool GetBooleanExpr(const char *, bool);
8839f45a3c8SSimon J. Gerraty 
8849f45a3c8SSimon J. Gerraty /* parse.c */
8859f45a3c8SSimon J. Gerraty void Parse_Init(void);
8869f45a3c8SSimon J. Gerraty void Parse_End(void);
8879f45a3c8SSimon J. Gerraty 
888954401e6SSimon J. Gerraty void PrintLocation(FILE *, bool, const GNode *);
8899f45a3c8SSimon J. Gerraty void PrintStackTrace(bool);
8909f45a3c8SSimon J. Gerraty void Parse_Error(ParseErrorLevel, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
8919f45a3c8SSimon J. Gerraty bool Parse_VarAssign(const char *, bool, GNode *) MAKE_ATTR_USE;
8929f45a3c8SSimon J. Gerraty void Parse_File(const char *, int);
8939f45a3c8SSimon J. Gerraty void Parse_PushInput(const char *, unsigned, unsigned, Buffer,
8949f45a3c8SSimon J. Gerraty 		     struct ForLoop *);
8959f45a3c8SSimon J. Gerraty void Parse_MainName(GNodeList *);
8969f45a3c8SSimon J. Gerraty int Parse_NumErrors(void) MAKE_ATTR_USE;
8974fde40d9SSimon J. Gerraty unsigned int CurFile_CondMinDepth(void) MAKE_ATTR_USE;
898148ee845SSimon J. Gerraty void Parse_GuardElse(void);
899148ee845SSimon J. Gerraty void Parse_GuardEndif(void);
9009f45a3c8SSimon J. Gerraty 
9019f45a3c8SSimon J. Gerraty 
9029f45a3c8SSimon J. Gerraty /* suff.c */
9039f45a3c8SSimon J. Gerraty void Suff_Init(void);
9049f45a3c8SSimon J. Gerraty void Suff_End(void);
9059f45a3c8SSimon J. Gerraty 
9069f45a3c8SSimon J. Gerraty void Suff_ClearSuffixes(void);
9079f45a3c8SSimon J. Gerraty bool Suff_IsTransform(const char *) MAKE_ATTR_USE;
9089f45a3c8SSimon J. Gerraty GNode *Suff_AddTransform(const char *);
9099f45a3c8SSimon J. Gerraty void Suff_EndTransform(GNode *);
9109f45a3c8SSimon J. Gerraty void Suff_AddSuffix(const char *);
9119f45a3c8SSimon J. Gerraty SearchPath *Suff_GetPath(const char *) MAKE_ATTR_USE;
9129f45a3c8SSimon J. Gerraty void Suff_ExtendPaths(void);
9139f45a3c8SSimon J. Gerraty void Suff_AddInclude(const char *);
9149f45a3c8SSimon J. Gerraty void Suff_AddLib(const char *);
9159f45a3c8SSimon J. Gerraty void Suff_FindDeps(GNode *);
9169f45a3c8SSimon J. Gerraty SearchPath *Suff_FindPath(GNode *) MAKE_ATTR_USE;
9179f45a3c8SSimon J. Gerraty void Suff_SetNull(const char *);
9189f45a3c8SSimon J. Gerraty void Suff_PrintAll(void);
9199f45a3c8SSimon J. Gerraty char *Suff_NamesStr(void) MAKE_ATTR_USE;
9209f45a3c8SSimon J. Gerraty 
9219f45a3c8SSimon J. Gerraty /* targ.c */
9229f45a3c8SSimon J. Gerraty void Targ_Init(void);
9239f45a3c8SSimon J. Gerraty void Targ_End(void);
9249f45a3c8SSimon J. Gerraty 
9259f45a3c8SSimon J. Gerraty void Targ_Stats(void);
9269f45a3c8SSimon J. Gerraty GNodeList *Targ_List(void) MAKE_ATTR_USE;
9279f45a3c8SSimon J. Gerraty GNode *GNode_New(const char *) MAKE_ATTR_USE;
9289f45a3c8SSimon J. Gerraty GNode *Targ_FindNode(const char *) MAKE_ATTR_USE;
9299f45a3c8SSimon J. Gerraty GNode *Targ_GetNode(const char *) MAKE_ATTR_USE;
9309f45a3c8SSimon J. Gerraty GNode *Targ_NewInternalNode(const char *) MAKE_ATTR_USE;
9319f45a3c8SSimon J. Gerraty GNode *Targ_GetEndNode(void);
9329f45a3c8SSimon J. Gerraty void Targ_FindList(GNodeList *, StringList *);
9339f45a3c8SSimon J. Gerraty void Targ_PrintCmds(GNode *);
9349f45a3c8SSimon J. Gerraty void Targ_PrintNode(GNode *, int);
9359f45a3c8SSimon J. Gerraty void Targ_PrintNodes(GNodeList *, int);
9369f45a3c8SSimon J. Gerraty const char *Targ_FmtTime(time_t) MAKE_ATTR_USE;
9379f45a3c8SSimon J. Gerraty void Targ_PrintType(GNodeType);
9389f45a3c8SSimon J. Gerraty void Targ_PrintGraph(int);
9399f45a3c8SSimon J. Gerraty void Targ_Propagate(void);
9409f45a3c8SSimon J. Gerraty const char *GNodeMade_Name(GNodeMade) MAKE_ATTR_USE;
9419f45a3c8SSimon J. Gerraty 
9429f45a3c8SSimon J. Gerraty /* var.c */
9439f45a3c8SSimon J. Gerraty void Var_Init(void);
9449f45a3c8SSimon J. Gerraty void Var_End(void);
9459f45a3c8SSimon J. Gerraty 
9469f45a3c8SSimon J. Gerraty typedef enum VarEvalMode {
9479f45a3c8SSimon J. Gerraty 
9489f45a3c8SSimon J. Gerraty 	/*
9499f45a3c8SSimon J. Gerraty 	 * Only parse the expression but don't evaluate any part of it.
9509f45a3c8SSimon J. Gerraty 	 *
9519f45a3c8SSimon J. Gerraty 	 * TODO: Document what Var_Parse and Var_Subst return in this mode.
9529f45a3c8SSimon J. Gerraty 	 *  As of 2021-03-15, they return unspecified, inconsistent results.
9539f45a3c8SSimon J. Gerraty 	 */
9549f45a3c8SSimon J. Gerraty 	VARE_PARSE_ONLY,
9559f45a3c8SSimon J. Gerraty 
9568c973ee2SSimon J. Gerraty 	/*
9578c973ee2SSimon J. Gerraty 	 * Parse text in which '${...}' and '$(...)' are not parsed as
9588c973ee2SSimon J. Gerraty 	 * subexpressions (with all their individual escaping rules) but
9598c973ee2SSimon J. Gerraty 	 * instead simply as text with balanced '${}' or '$()'.  Other '$'
9608c973ee2SSimon J. Gerraty 	 * are copied verbatim.
9618c973ee2SSimon J. Gerraty 	 */
9628c973ee2SSimon J. Gerraty 	VARE_PARSE_BALANCED,
9638c973ee2SSimon J. Gerraty 
9649f45a3c8SSimon J. Gerraty 	/* Parse and evaluate the expression. */
9659f45a3c8SSimon J. Gerraty 	VARE_WANTRES,
9669f45a3c8SSimon J. Gerraty 
9679f45a3c8SSimon J. Gerraty 	/*
9689f45a3c8SSimon J. Gerraty 	 * Parse and evaluate the expression.  It is an error if a
9699f45a3c8SSimon J. Gerraty 	 * subexpression evaluates to undefined.
9709f45a3c8SSimon J. Gerraty 	 */
9719f45a3c8SSimon J. Gerraty 	VARE_UNDEFERR,
9729f45a3c8SSimon J. Gerraty 
9739f45a3c8SSimon J. Gerraty 	/*
9749f45a3c8SSimon J. Gerraty 	 * Parse and evaluate the expression.  Keep '$$' as '$$' instead of
9759f45a3c8SSimon J. Gerraty 	 * reducing it to a single '$'.  Subexpressions that evaluate to
9769f45a3c8SSimon J. Gerraty 	 * undefined expand to an empty string.
9779f45a3c8SSimon J. Gerraty 	 *
9789f45a3c8SSimon J. Gerraty 	 * Used in variable assignments using the ':=' operator.  It allows
9799f45a3c8SSimon J. Gerraty 	 * multiple such assignments to be chained without accidentally
9809f45a3c8SSimon J. Gerraty 	 * expanding '$$file' to '$file' in the first assignment and
9819f45a3c8SSimon J. Gerraty 	 * interpreting it as '${f}' followed by 'ile' in the next assignment.
9829f45a3c8SSimon J. Gerraty 	 */
9839f45a3c8SSimon J. Gerraty 	VARE_EVAL_KEEP_DOLLAR,
9849f45a3c8SSimon J. Gerraty 
9859f45a3c8SSimon J. Gerraty 	/*
9869f45a3c8SSimon J. Gerraty 	 * Parse and evaluate the expression.  Keep undefined variables as-is
9879f45a3c8SSimon J. Gerraty 	 * instead of expanding them to an empty string.
9889f45a3c8SSimon J. Gerraty 	 *
9899f45a3c8SSimon J. Gerraty 	 * Example for a ':=' assignment:
9909f45a3c8SSimon J. Gerraty 	 *	CFLAGS = $(.INCLUDES)
9919f45a3c8SSimon J. Gerraty 	 *	CFLAGS := -I.. $(CFLAGS)
9929f45a3c8SSimon J. Gerraty 	 *	# If .INCLUDES (an undocumented special variable, by the
9939f45a3c8SSimon J. Gerraty 	 *	# way) is still undefined, the updated CFLAGS becomes
9949f45a3c8SSimon J. Gerraty 	 *	# "-I.. $(.INCLUDES)".
9959f45a3c8SSimon J. Gerraty 	 */
9969f45a3c8SSimon J. Gerraty 	VARE_EVAL_KEEP_UNDEF,
9979f45a3c8SSimon J. Gerraty 
9989f45a3c8SSimon J. Gerraty 	/*
9999f45a3c8SSimon J. Gerraty 	 * Parse and evaluate the expression.  Keep '$$' as '$$' and preserve
10009f45a3c8SSimon J. Gerraty 	 * undefined subexpressions.
10019f45a3c8SSimon J. Gerraty 	 */
10029f45a3c8SSimon J. Gerraty 	VARE_KEEP_DOLLAR_UNDEF
10039f45a3c8SSimon J. Gerraty } VarEvalMode;
10049f45a3c8SSimon J. Gerraty 
10059f45a3c8SSimon J. Gerraty typedef enum VarSetFlags {
10069f45a3c8SSimon J. Gerraty 	VAR_SET_NONE		= 0,
10079f45a3c8SSimon J. Gerraty 
10089f45a3c8SSimon J. Gerraty 	/* do not export */
10099f45a3c8SSimon J. Gerraty 	VAR_SET_NO_EXPORT	= 1 << 0,
10109f45a3c8SSimon J. Gerraty 
10119f45a3c8SSimon J. Gerraty 	/*
10129f45a3c8SSimon J. Gerraty 	 * Make the variable read-only. No further modification is possible,
10138c973ee2SSimon J. Gerraty 	 * except for another call to Var_Set with the same flag. See the
10148c973ee2SSimon J. Gerraty 	 * special targets '.NOREADONLY' and '.READONLY'.
10159f45a3c8SSimon J. Gerraty 	 */
1016*c9f4001fSSimon J. Gerraty 	VAR_SET_READONLY	= 1 << 1,
1017*c9f4001fSSimon J. Gerraty 	VAR_SET_INTERNAL	= 1 << 2
10189f45a3c8SSimon J. Gerraty } VarSetFlags;
10199f45a3c8SSimon J. Gerraty 
10209f45a3c8SSimon J. Gerraty typedef enum VarExportMode {
10219f45a3c8SSimon J. Gerraty 	/* .export-env */
10229f45a3c8SSimon J. Gerraty 	VEM_ENV,
10239f45a3c8SSimon J. Gerraty 	/* .export: Initial export or update an already exported variable. */
10249f45a3c8SSimon J. Gerraty 	VEM_PLAIN,
10259f45a3c8SSimon J. Gerraty 	/* .export-literal: Do not expand the variable value. */
10269f45a3c8SSimon J. Gerraty 	VEM_LITERAL
10279f45a3c8SSimon J. Gerraty } VarExportMode;
10289f45a3c8SSimon J. Gerraty 
10299f45a3c8SSimon J. Gerraty void Var_Delete(GNode *, const char *);
10309f45a3c8SSimon J. Gerraty void Var_Undef(const char *);
10319f45a3c8SSimon J. Gerraty void Var_Set(GNode *, const char *, const char *);
10329f45a3c8SSimon J. Gerraty void Var_SetExpand(GNode *, const char *, const char *);
10339f45a3c8SSimon J. Gerraty void Var_SetWithFlags(GNode *, const char *, const char *, VarSetFlags);
10349f45a3c8SSimon J. Gerraty void Var_Append(GNode *, const char *, const char *);
10359f45a3c8SSimon J. Gerraty void Var_AppendExpand(GNode *, const char *, const char *);
10369f45a3c8SSimon J. Gerraty bool Var_Exists(GNode *, const char *) MAKE_ATTR_USE;
10379f45a3c8SSimon J. Gerraty bool Var_ExistsExpand(GNode *, const char *) MAKE_ATTR_USE;
10389f45a3c8SSimon J. Gerraty FStr Var_Value(GNode *, const char *) MAKE_ATTR_USE;
10399f45a3c8SSimon J. Gerraty const char *GNode_ValueDirect(GNode *, const char *) MAKE_ATTR_USE;
10408c973ee2SSimon J. Gerraty FStr Var_Parse(const char **, GNode *, VarEvalMode);
10418c973ee2SSimon J. Gerraty char *Var_Subst(const char *, GNode *, VarEvalMode);
10429f45a3c8SSimon J. Gerraty void Var_Expand(FStr *, GNode *, VarEvalMode);
10439f45a3c8SSimon J. Gerraty void Var_Stats(void);
10449f45a3c8SSimon J. Gerraty void Var_Dump(GNode *);
1045c59c3bf3SSimon J. Gerraty void Var_ReexportVars(GNode *);
10469f45a3c8SSimon J. Gerraty void Var_Export(VarExportMode, const char *);
10479f45a3c8SSimon J. Gerraty void Var_ExportVars(const char *);
10489f45a3c8SSimon J. Gerraty void Var_UnExport(bool, const char *);
10494fde40d9SSimon J. Gerraty void Var_ReadOnly(const char *, bool);
10509f45a3c8SSimon J. Gerraty 
10519f45a3c8SSimon J. Gerraty void Global_Set(const char *, const char *);
10529f45a3c8SSimon J. Gerraty void Global_Append(const char *, const char *);
10539f45a3c8SSimon J. Gerraty void Global_Delete(const char *);
10544fde40d9SSimon J. Gerraty void Global_Set_ReadOnly(const char *, const char *);
10559f45a3c8SSimon J. Gerraty 
1056548bfc56SSimon J. Gerraty void EvalStack_Push(const char *, const char *, const char *);
1057548bfc56SSimon J. Gerraty void EvalStack_Pop(void);
1058548bfc56SSimon J. Gerraty const char *EvalStack_Details(void);
1059548bfc56SSimon J. Gerraty 
10609f45a3c8SSimon J. Gerraty /* util.c */
10619f45a3c8SSimon J. Gerraty typedef void (*SignalProc)(int);
10629f45a3c8SSimon J. Gerraty SignalProc bmake_signal(int, SignalProc);
10639f45a3c8SSimon J. Gerraty 
10649f45a3c8SSimon J. Gerraty /* make.c */
1065e2eeea75SSimon J. Gerraty void GNode_UpdateYoungestChild(GNode *, GNode *);
10669f45a3c8SSimon J. Gerraty bool GNode_IsOODate(GNode *) MAKE_ATTR_USE;
1067956e45f6SSimon J. Gerraty void Make_ExpandUse(GNodeList *);
10689f45a3c8SSimon J. Gerraty time_t Make_Recheck(GNode *) MAKE_ATTR_USE;
10693955d011SMarcel Moolenaar void Make_HandleUse(GNode *, GNode *);
10703955d011SMarcel Moolenaar void Make_Update(GNode *);
1071b0c40a00SSimon J. Gerraty void GNode_SetLocalVars(GNode *);
1072b0c40a00SSimon J. Gerraty bool Make_Run(GNodeList *);
10739f45a3c8SSimon J. Gerraty bool shouldDieQuietly(GNode *, int) MAKE_ATTR_USE;
10743955d011SMarcel Moolenaar void PrintOnError(GNode *, const char *);
1075b0c40a00SSimon J. Gerraty void Main_ExportMAKEFLAGS(bool);
1076b0c40a00SSimon J. Gerraty bool Main_SetObjdir(bool, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
10779f45a3c8SSimon J. Gerraty int mkTempFile(const char *, char *, size_t) MAKE_ATTR_USE;
1078d5e0a182SSimon J. Gerraty void AppendWords(StringList *, char *);
10792c3632d1SSimon J. Gerraty void GNode_FprintDetails(FILE *, const char *, const GNode *, const char *);
10809f45a3c8SSimon J. Gerraty bool GNode_ShouldExecute(GNode *gn) MAKE_ATTR_USE;
1081956e45f6SSimon J. Gerraty 
10824fde40d9SSimon J. Gerraty #ifndef HAVE_STRLCPY
10834fde40d9SSimon J. Gerraty size_t strlcpy(char *, const char *, size_t);
10844fde40d9SSimon J. Gerraty #endif
10854fde40d9SSimon J. Gerraty 
1086956e45f6SSimon J. Gerraty /* See if the node was seen on the left-hand side of a dependency operator. */
10879f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE
GNode_IsTarget(const GNode * gn)1088956e45f6SSimon J. Gerraty GNode_IsTarget(const GNode *gn)
1089956e45f6SSimon J. Gerraty {
109012904384SSimon J. Gerraty 	return (gn->type & OP_OPMASK) != OP_NONE;
1091956e45f6SSimon J. Gerraty }
1092956e45f6SSimon J. Gerraty 
10939f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE
GNode_Path(const GNode * gn)1094956e45f6SSimon J. Gerraty GNode_Path(const GNode *gn)
1095956e45f6SSimon J. Gerraty {
1096956e45f6SSimon J. Gerraty 	return gn->path != NULL ? gn->path : gn->name;
1097956e45f6SSimon J. Gerraty }
1098956e45f6SSimon J. Gerraty 
10999f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE
GNode_IsWaitingFor(const GNode * gn)110006b9b3e0SSimon J. Gerraty GNode_IsWaitingFor(const GNode *gn)
110106b9b3e0SSimon J. Gerraty {
110212904384SSimon J. Gerraty 	return gn->flags.remake && gn->made <= REQUESTED;
110306b9b3e0SSimon J. Gerraty }
110406b9b3e0SSimon J. Gerraty 
11059f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE
GNode_IsReady(const GNode * gn)110606b9b3e0SSimon J. Gerraty GNode_IsReady(const GNode *gn)
110706b9b3e0SSimon J. Gerraty {
110806b9b3e0SSimon J. Gerraty 	return gn->made > DEFERRED;
110906b9b3e0SSimon J. Gerraty }
111006b9b3e0SSimon J. Gerraty 
11119f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE
GNode_IsDone(const GNode * gn)111206b9b3e0SSimon J. Gerraty GNode_IsDone(const GNode *gn)
111306b9b3e0SSimon J. Gerraty {
111406b9b3e0SSimon J. Gerraty 	return gn->made >= MADE;
111506b9b3e0SSimon J. Gerraty }
111606b9b3e0SSimon J. Gerraty 
11179f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE
GNode_IsError(const GNode * gn)111806b9b3e0SSimon J. Gerraty GNode_IsError(const GNode *gn)
111906b9b3e0SSimon J. Gerraty {
112006b9b3e0SSimon J. Gerraty 	return gn->made == ERROR || gn->made == ABORTED;
112106b9b3e0SSimon J. Gerraty }
112206b9b3e0SSimon J. Gerraty 
11239f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE
GNode_IsMainCandidate(const GNode * gn)11249f45a3c8SSimon J. Gerraty GNode_IsMainCandidate(const GNode *gn)
11259f45a3c8SSimon J. Gerraty {
11269f45a3c8SSimon J. Gerraty 	return (gn->type & (OP_NOTMAIN | OP_USE | OP_USEBEFORE |
11279f45a3c8SSimon J. Gerraty 			    OP_EXEC | OP_TRANSFORM)) == 0;
11289f45a3c8SSimon J. Gerraty }
11299f45a3c8SSimon J. Gerraty 
11309f45a3c8SSimon J. Gerraty /* Return whether the target file should be preserved on interrupt. */
11319f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE
GNode_IsPrecious(const GNode * gn)11329f45a3c8SSimon J. Gerraty GNode_IsPrecious(const GNode *gn)
11339f45a3c8SSimon J. Gerraty {
11349f45a3c8SSimon J. Gerraty 	/* XXX: Why are '::' targets precious? */
11359f45a3c8SSimon J. Gerraty 	return allPrecious || gn->type & (OP_PRECIOUS | OP_DOUBLEDEP);
11369f45a3c8SSimon J. Gerraty }
11379f45a3c8SSimon J. Gerraty 
11389f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE
GNode_VarTarget(GNode * gn)1139dba7b0efSSimon J. Gerraty GNode_VarTarget(GNode *gn) { return GNode_ValueDirect(gn, TARGET); }
11409f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE
GNode_VarOodate(GNode * gn)1141dba7b0efSSimon J. Gerraty GNode_VarOodate(GNode *gn) { return GNode_ValueDirect(gn, OODATE); }
11429f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE
GNode_VarAllsrc(GNode * gn)1143dba7b0efSSimon J. Gerraty GNode_VarAllsrc(GNode *gn) { return GNode_ValueDirect(gn, ALLSRC); }
11449f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE
GNode_VarImpsrc(GNode * gn)1145dba7b0efSSimon J. Gerraty GNode_VarImpsrc(GNode *gn) { return GNode_ValueDirect(gn, IMPSRC); }
11469f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE
GNode_VarPrefix(GNode * gn)1147dba7b0efSSimon J. Gerraty GNode_VarPrefix(GNode *gn) { return GNode_ValueDirect(gn, PREFIX); }
11489f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE
GNode_VarArchive(GNode * gn)1149dba7b0efSSimon J. Gerraty GNode_VarArchive(GNode *gn) { return GNode_ValueDirect(gn, ARCHIVE); }
11509f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE
GNode_VarMember(GNode * gn)1151dba7b0efSSimon J. Gerraty GNode_VarMember(GNode *gn) { return GNode_ValueDirect(gn, MEMBER); }
11523955d011SMarcel Moolenaar 
11539f45a3c8SSimon J. Gerraty MAKE_INLINE void * MAKE_ATTR_USE
UNCONST(const void * ptr)115412904384SSimon J. Gerraty UNCONST(const void *ptr)
115512904384SSimon J. Gerraty {
115612904384SSimon J. Gerraty 	void *ret;
115712904384SSimon J. Gerraty 	memcpy(&ret, &ptr, sizeof(ret));
115812904384SSimon J. Gerraty 	return ret;
115912904384SSimon J. Gerraty }
11603955d011SMarcel Moolenaar 
11614c620fe5SSimon J. Gerraty /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */
11624c620fe5SSimon J. Gerraty #ifdef HAVE_LIMITS_H
11634c620fe5SSimon J. Gerraty #include <limits.h>
11644c620fe5SSimon J. Gerraty #endif
11650dede8b0SSimon J. Gerraty #ifndef MAXPATHLEN
11660dede8b0SSimon J. Gerraty #define MAXPATHLEN	BMAKE_PATH_MAX
11670dede8b0SSimon J. Gerraty #endif
11684c620fe5SSimon J. Gerraty #ifndef PATH_MAX
11694c620fe5SSimon J. Gerraty #define PATH_MAX	MAXPATHLEN
11704c620fe5SSimon J. Gerraty #endif
11710dede8b0SSimon J. Gerraty 
1172c7019bf7SSimon J. Gerraty #if defined(SYSV)
1173c7019bf7SSimon J. Gerraty #define KILLPG(pid, sig) kill(-(pid), (sig))
1174c7019bf7SSimon J. Gerraty #else
1175c7019bf7SSimon J. Gerraty #define KILLPG(pid, sig) killpg((pid), (sig))
1176c7019bf7SSimon J. Gerraty #endif
1177c7019bf7SSimon J. Gerraty 
11789f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE
ch_isalnum(char ch)1179e2eeea75SSimon J. Gerraty ch_isalnum(char ch) { return isalnum((unsigned char)ch) != 0; }
11809f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE
ch_isalpha(char ch)1181e2eeea75SSimon J. Gerraty ch_isalpha(char ch) { return isalpha((unsigned char)ch) != 0; }
11829f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE
ch_isdigit(char ch)1183e2eeea75SSimon J. Gerraty ch_isdigit(char ch) { return isdigit((unsigned char)ch) != 0; }
11849f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE
ch_islower(char ch)11859f45a3c8SSimon J. Gerraty ch_islower(char ch) { return islower((unsigned char)ch) != 0; }
11869f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE
ch_isspace(char ch)1187e2eeea75SSimon J. Gerraty ch_isspace(char ch) { return isspace((unsigned char)ch) != 0; }
11889f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE
ch_isupper(char ch)1189e2eeea75SSimon J. Gerraty ch_isupper(char ch) { return isupper((unsigned char)ch) != 0; }
11909f45a3c8SSimon J. Gerraty MAKE_INLINE char MAKE_ATTR_USE
ch_tolower(char ch)1191e2eeea75SSimon J. Gerraty ch_tolower(char ch) { return (char)tolower((unsigned char)ch); }
11929f45a3c8SSimon J. Gerraty MAKE_INLINE char MAKE_ATTR_USE
ch_toupper(char ch)1193e2eeea75SSimon J. Gerraty ch_toupper(char ch) { return (char)toupper((unsigned char)ch); }
1194956e45f6SSimon J. Gerraty 
1195e2eeea75SSimon J. Gerraty MAKE_INLINE void
cpp_skip_whitespace(const char ** pp)1196956e45f6SSimon J. Gerraty cpp_skip_whitespace(const char **pp)
1197956e45f6SSimon J. Gerraty {
1198956e45f6SSimon J. Gerraty 	while (ch_isspace(**pp))
1199956e45f6SSimon J. Gerraty 		(*pp)++;
1200956e45f6SSimon J. Gerraty }
1201956e45f6SSimon J. Gerraty 
1202e2eeea75SSimon J. Gerraty MAKE_INLINE void
cpp_skip_hspace(const char ** pp)1203e2eeea75SSimon J. Gerraty cpp_skip_hspace(const char **pp)
1204e2eeea75SSimon J. Gerraty {
1205e2eeea75SSimon J. Gerraty 	while (**pp == ' ' || **pp == '\t')
1206e2eeea75SSimon J. Gerraty 		(*pp)++;
1207e2eeea75SSimon J. Gerraty }
1208e2eeea75SSimon J. Gerraty 
12099f45a3c8SSimon J. Gerraty MAKE_INLINE bool
cpp_skip_string(const char ** pp,const char * s)12109f45a3c8SSimon J. Gerraty cpp_skip_string(const char **pp, const char *s)
12119f45a3c8SSimon J. Gerraty {
12129f45a3c8SSimon J. Gerraty 	const char *p = *pp;
12139f45a3c8SSimon J. Gerraty 	while (*p == *s && *s != '\0')
12149f45a3c8SSimon J. Gerraty 		p++, s++;
12159f45a3c8SSimon J. Gerraty 	if (*s == '\0')
12169f45a3c8SSimon J. Gerraty 		*pp = p;
12179f45a3c8SSimon J. Gerraty 	return *s == '\0';
12189f45a3c8SSimon J. Gerraty }
12199f45a3c8SSimon J. Gerraty 
1220e2eeea75SSimon J. Gerraty MAKE_INLINE void
pp_skip_whitespace(char ** pp)1221956e45f6SSimon J. Gerraty pp_skip_whitespace(char **pp)
1222956e45f6SSimon J. Gerraty {
1223956e45f6SSimon J. Gerraty 	while (ch_isspace(**pp))
1224956e45f6SSimon J. Gerraty 		(*pp)++;
1225956e45f6SSimon J. Gerraty }
1226956e45f6SSimon J. Gerraty 
1227e2eeea75SSimon J. Gerraty MAKE_INLINE void
pp_skip_hspace(char ** pp)1228e2eeea75SSimon J. Gerraty pp_skip_hspace(char **pp)
1229e2eeea75SSimon J. Gerraty {
1230e2eeea75SSimon J. Gerraty 	while (**pp == ' ' || **pp == '\t')
1231e2eeea75SSimon J. Gerraty 		(*pp)++;
1232e2eeea75SSimon J. Gerraty }
1233e2eeea75SSimon J. Gerraty 
123406b9b3e0SSimon J. Gerraty #if defined(lint)
123598875883SSimon J. Gerraty void do_not_define_rcsid(void); /* for lint */
123698875883SSimon J. Gerraty # define MAKE_RCSID(id) void do_not_define_rcsid(void)
123706b9b3e0SSimon J. Gerraty #elif defined(MAKE_NATIVE)
1238956e45f6SSimon J. Gerraty # include <sys/cdefs.h>
123912904384SSimon J. Gerraty # ifndef __IDSTRING
124012904384SSimon J. Gerraty #   define __IDSTRING(name,string) \
124112904384SSimon J. Gerraty 	static const char name[] MAKE_ATTR_UNUSED = string
124212904384SSimon J. Gerraty # endif
124312904384SSimon J. Gerraty # ifndef __RCSID
124412904384SSimon J. Gerraty #   define __RCSID(s) __IDSTRING(rcsid,s)
124512904384SSimon J. Gerraty # endif
124612904384SSimon J. Gerraty # ifndef __COPYRIGHT
124712904384SSimon J. Gerraty #   define __COPYRIGHT(s) __IDSTRING(copyright,s)
124812904384SSimon J. Gerraty # endif
1249956e45f6SSimon J. Gerraty # define MAKE_RCSID(id) __RCSID(id)
125006b9b3e0SSimon J. Gerraty #elif defined(MAKE_ALL_IN_ONE) && defined(__COUNTER__)
125106b9b3e0SSimon J. Gerraty # define MAKE_RCSID_CONCAT(x, y) CONCAT(x, y)
125206b9b3e0SSimon J. Gerraty # define MAKE_RCSID(id) static volatile char \
125306b9b3e0SSimon J. Gerraty 	MAKE_RCSID_CONCAT(rcsid_, __COUNTER__)[] = id
125406b9b3e0SSimon J. Gerraty #elif defined(MAKE_ALL_IN_ONE)
125598875883SSimon J. Gerraty # define MAKE_RCSID(id) void do_not_define_rcsid(void)
1256956e45f6SSimon J. Gerraty #else
1257956e45f6SSimon J. Gerraty # define MAKE_RCSID(id) static volatile char rcsid[] = id
1258956e45f6SSimon J. Gerraty #endif
1259956e45f6SSimon J. Gerraty 
12609f45a3c8SSimon J. Gerraty #endif
1261