xref: /freebsd/contrib/bmake/make.h (revision 2c3632d14fe37fa35c262ee9fb66835be0a52621)
1*2c3632d1SSimon J. Gerraty /*	$NetBSD: make.h,v 1.137 2020/09/02 23:42:58 rillig 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 
753955d011SMarcel Moolenaar /*-
763955d011SMarcel Moolenaar  * make.h --
773955d011SMarcel Moolenaar  *	The global definitions for pmake
783955d011SMarcel Moolenaar  */
793955d011SMarcel Moolenaar 
80*2c3632d1SSimon J. Gerraty #ifndef MAKE_MAKE_H
81*2c3632d1SSimon 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>
89*2c3632d1SSimon J. Gerraty #include <sys/stat.h>
903955d011SMarcel Moolenaar 
91*2c3632d1SSimon J. Gerraty #include <assert.h>
923955d011SMarcel Moolenaar #include <ctype.h>
93be19d90bSSimon J. Gerraty #include <fcntl.h>
943955d011SMarcel Moolenaar #include <stdio.h>
953955d011SMarcel Moolenaar #include <stdlib.h>
963955d011SMarcel Moolenaar #ifdef HAVE_STRING_H
973955d011SMarcel Moolenaar #include <string.h>
983955d011SMarcel Moolenaar #else
993955d011SMarcel Moolenaar #include <strings.h>
1003955d011SMarcel Moolenaar #endif
1013955d011SMarcel Moolenaar #include <unistd.h>
1023955d011SMarcel Moolenaar #include <sys/cdefs.h>
1033955d011SMarcel Moolenaar 
104be19d90bSSimon J. Gerraty #ifndef FD_CLOEXEC
105be19d90bSSimon J. Gerraty #define FD_CLOEXEC 1
106be19d90bSSimon J. Gerraty #endif
107be19d90bSSimon J. Gerraty 
1083955d011SMarcel Moolenaar #if defined(__GNUC__)
1093955d011SMarcel Moolenaar #define	MAKE_GNUC_PREREQ(x, y)						\
1103955d011SMarcel Moolenaar 	((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) ||			\
1113955d011SMarcel Moolenaar 	 (__GNUC__ > (x)))
1123955d011SMarcel Moolenaar #else /* defined(__GNUC__) */
1131748de26SSimon J. Gerraty #define	MAKE_GNUC_PREREQ(x, y)	0
1143955d011SMarcel Moolenaar #endif /* defined(__GNUC__) */
1153955d011SMarcel Moolenaar 
1163955d011SMarcel Moolenaar #if MAKE_GNUC_PREREQ(2, 7)
1173955d011SMarcel Moolenaar #define	MAKE_ATTR_UNUSED	__attribute__((__unused__))
1183955d011SMarcel Moolenaar #else
1193955d011SMarcel Moolenaar #define	MAKE_ATTR_UNUSED	/* delete */
1203955d011SMarcel Moolenaar #endif
1213955d011SMarcel Moolenaar 
1223955d011SMarcel Moolenaar #if MAKE_GNUC_PREREQ(2, 5)
1233955d011SMarcel Moolenaar #define	MAKE_ATTR_DEAD		__attribute__((__noreturn__))
1243955d011SMarcel Moolenaar #elif defined(__GNUC__)
1253955d011SMarcel Moolenaar #define	MAKE_ATTR_DEAD		__volatile
1263955d011SMarcel Moolenaar #else
1273955d011SMarcel Moolenaar #define	MAKE_ATTR_DEAD		/* delete */
1283955d011SMarcel Moolenaar #endif
1293955d011SMarcel Moolenaar 
1303955d011SMarcel Moolenaar #if MAKE_GNUC_PREREQ(2, 7)
1313955d011SMarcel Moolenaar #define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg)	\
1323955d011SMarcel Moolenaar 	    __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
1333955d011SMarcel Moolenaar #else
1343955d011SMarcel Moolenaar #define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg)	/* delete */
1353955d011SMarcel Moolenaar #endif
1363955d011SMarcel Moolenaar 
137*2c3632d1SSimon J. Gerraty /*
138*2c3632d1SSimon J. Gerraty  * A boolean type is defined as an integer, not an enum, for historic reasons.
139*2c3632d1SSimon J. Gerraty  * The only allowed values are the constants TRUE and FALSE (1 and 0).
140*2c3632d1SSimon J. Gerraty  */
141*2c3632d1SSimon J. Gerraty 
142*2c3632d1SSimon J. Gerraty #ifdef USE_DOUBLE_BOOLEAN
143*2c3632d1SSimon J. Gerraty /* During development, to find type mismatches in function declarations. */
144*2c3632d1SSimon J. Gerraty typedef double Boolean;
145*2c3632d1SSimon J. Gerraty #elif defined(USE_UCHAR_BOOLEAN)
146*2c3632d1SSimon J. Gerraty /* During development, to find code that depends on the exact value of TRUE or
147*2c3632d1SSimon J. Gerraty  * that stores other values in Boolean variables. */
148*2c3632d1SSimon J. Gerraty typedef unsigned char Boolean;
149*2c3632d1SSimon J. Gerraty #define TRUE ((unsigned char)0xFF)
150*2c3632d1SSimon J. Gerraty #define FALSE ((unsigned char)0x00)
151*2c3632d1SSimon J. Gerraty #elif defined(USE_ENUM_BOOLEAN)
152*2c3632d1SSimon J. Gerraty typedef enum { FALSE, TRUE} Boolean;
153*2c3632d1SSimon J. Gerraty #else
154*2c3632d1SSimon J. Gerraty typedef int Boolean;
155*2c3632d1SSimon J. Gerraty #endif
156*2c3632d1SSimon J. Gerraty #ifndef TRUE
157*2c3632d1SSimon J. Gerraty #define TRUE	1
158*2c3632d1SSimon J. Gerraty #endif /* TRUE */
159*2c3632d1SSimon J. Gerraty #ifndef FALSE
160*2c3632d1SSimon J. Gerraty #define FALSE	0
161*2c3632d1SSimon J. Gerraty #endif /* FALSE */
162*2c3632d1SSimon J. Gerraty 
1633955d011SMarcel Moolenaar #include "lst.h"
164*2c3632d1SSimon J. Gerraty #include "enum.h"
1653955d011SMarcel Moolenaar #include "hash.h"
1663955d011SMarcel Moolenaar #include "make-conf.h"
1673955d011SMarcel Moolenaar #include "buf.h"
1683955d011SMarcel Moolenaar #include "make_malloc.h"
1693955d011SMarcel Moolenaar 
1703955d011SMarcel Moolenaar /*
1713955d011SMarcel Moolenaar  * some vendors don't have this --sjg
1723955d011SMarcel Moolenaar  */
1733955d011SMarcel Moolenaar #if defined(S_IFDIR) && !defined(S_ISDIR)
1743955d011SMarcel Moolenaar # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
1753955d011SMarcel Moolenaar #endif
1763955d011SMarcel Moolenaar 
1773955d011SMarcel Moolenaar #if defined(sun) && (defined(__svr4__) || defined(__SVR4))
1783955d011SMarcel Moolenaar #define POSIX_SIGNALS
1793955d011SMarcel Moolenaar #endif
1803955d011SMarcel Moolenaar 
181*2c3632d1SSimon J. Gerraty typedef enum  {
182*2c3632d1SSimon J. Gerraty     UNMADE,			/* Not examined yet */
183*2c3632d1SSimon J. Gerraty     DEFERRED,			/* Examined once (building child) */
184*2c3632d1SSimon J. Gerraty     REQUESTED,			/* on toBeMade list */
185*2c3632d1SSimon J. Gerraty     BEINGMADE,			/* Target is already being made.
186*2c3632d1SSimon J. Gerraty 				 * Indicates a cycle in the graph. */
187*2c3632d1SSimon J. Gerraty     MADE,			/* Was out-of-date and has been made */
188*2c3632d1SSimon J. Gerraty     UPTODATE,			/* Was already up-to-date */
189*2c3632d1SSimon J. Gerraty     ERROR,			/* An error occurred while it was being
190*2c3632d1SSimon J. Gerraty 				 * made (used only in compat mode) */
191*2c3632d1SSimon J. Gerraty     ABORTED			/* The target was aborted due to an error
192*2c3632d1SSimon J. Gerraty 				 * making an inferior (compat). */
193*2c3632d1SSimon J. Gerraty } GNodeMade;
1943955d011SMarcel Moolenaar 
195*2c3632d1SSimon J. Gerraty /* The OP_ constants are used when parsing a dependency line as a way of
196*2c3632d1SSimon J. Gerraty  * communicating to other parts of the program the way in which a target
197*2c3632d1SSimon J. Gerraty  * should be made.
198*2c3632d1SSimon J. Gerraty  *
199*2c3632d1SSimon J. Gerraty  * These constants are bitwise-OR'ed together and placed in the 'type' field
200*2c3632d1SSimon J. Gerraty  * of each node. Any node that has a 'type' field which satisfies the OP_NOP
201*2c3632d1SSimon J. Gerraty  * function was never never on the left-hand side of an operator, though it
202*2c3632d1SSimon J. Gerraty  * may have been on the right-hand side... */
203*2c3632d1SSimon J. Gerraty typedef enum {
204*2c3632d1SSimon J. Gerraty     /* Execution of commands depends on children (:) */
205*2c3632d1SSimon J. Gerraty     OP_DEPENDS		= 1 << 0,
206*2c3632d1SSimon J. Gerraty     /* Always execute commands (!) */
207*2c3632d1SSimon J. Gerraty     OP_FORCE		= 1 << 1,
208*2c3632d1SSimon J. Gerraty     /* Execution of commands depends on children per line (::) */
209*2c3632d1SSimon J. Gerraty     OP_DOUBLEDEP	= 1 << 2,
210*2c3632d1SSimon J. Gerraty 
211*2c3632d1SSimon J. Gerraty     OP_OPMASK		= OP_DEPENDS|OP_FORCE|OP_DOUBLEDEP,
212*2c3632d1SSimon J. Gerraty 
213*2c3632d1SSimon J. Gerraty     /* Don't care if the target doesn't exist and can't be created */
214*2c3632d1SSimon J. Gerraty     OP_OPTIONAL		= 1 << 3,
215*2c3632d1SSimon J. Gerraty     /* Use associated commands for parents */
216*2c3632d1SSimon J. Gerraty     OP_USE		= 1 << 4,
217*2c3632d1SSimon J. Gerraty     /* Target is never out of date, but always execute commands anyway.
218*2c3632d1SSimon J. Gerraty      * Its time doesn't matter, so it has none...sort of */
219*2c3632d1SSimon J. Gerraty     OP_EXEC	  	= 1 << 5,
220*2c3632d1SSimon J. Gerraty     /* Ignore errors when creating the node */
221*2c3632d1SSimon J. Gerraty     OP_IGNORE		= 1 << 6,
222*2c3632d1SSimon J. Gerraty     /* Don't remove the target when interrupted */
223*2c3632d1SSimon J. Gerraty     OP_PRECIOUS		= 1 << 7,
224*2c3632d1SSimon J. Gerraty     /* Don't echo commands when executed */
225*2c3632d1SSimon J. Gerraty     OP_SILENT		= 1 << 8,
226*2c3632d1SSimon J. Gerraty     /* Target is a recursive make so its commands should always be executed
227*2c3632d1SSimon J. Gerraty      * when it is out of date, regardless of the state of the -n or -t flags */
228*2c3632d1SSimon J. Gerraty     OP_MAKE		= 1 << 9,
229*2c3632d1SSimon J. Gerraty     /* Target is out-of-date only if any of its children was out-of-date */
230*2c3632d1SSimon J. Gerraty     OP_JOIN		= 1 << 10,
231*2c3632d1SSimon J. Gerraty     /* Assume the children of the node have been already made */
232*2c3632d1SSimon J. Gerraty     OP_MADE		= 1 << 11,
233*2c3632d1SSimon J. Gerraty     /* Special .BEGIN, .END, .INTERRUPT */
234*2c3632d1SSimon J. Gerraty     OP_SPECIAL		= 1 << 12,
235*2c3632d1SSimon J. Gerraty     /* Like .USE, only prepend commands */
236*2c3632d1SSimon J. Gerraty     OP_USEBEFORE	= 1 << 13,
237*2c3632d1SSimon J. Gerraty     /* The node is invisible to its parents. I.e. it doesn't show up in the
238*2c3632d1SSimon J. Gerraty      * parents' local variables. */
239*2c3632d1SSimon J. Gerraty     OP_INVISIBLE	= 1 << 14,
240*2c3632d1SSimon J. Gerraty     /* The node is exempt from normal 'main target' processing in parse.c */
241*2c3632d1SSimon J. Gerraty     OP_NOTMAIN		= 1 << 15,
242*2c3632d1SSimon J. Gerraty     /* Not a file target; run always */
243*2c3632d1SSimon J. Gerraty     OP_PHONY		= 1 << 16,
244*2c3632d1SSimon J. Gerraty     /* Don't search for file in the path */
245*2c3632d1SSimon J. Gerraty     OP_NOPATH		= 1 << 17,
246*2c3632d1SSimon J. Gerraty     /* .WAIT phony node */
247*2c3632d1SSimon J. Gerraty     OP_WAIT		= 1 << 18,
248*2c3632d1SSimon J. Gerraty     /* .NOMETA do not create a .meta file */
249*2c3632d1SSimon J. Gerraty     OP_NOMETA		= 1 << 19,
250*2c3632d1SSimon J. Gerraty     /* .META we _do_ want a .meta file */
251*2c3632d1SSimon J. Gerraty     OP_META		= 1 << 20,
252*2c3632d1SSimon J. Gerraty     /* Do not compare commands in .meta file */
253*2c3632d1SSimon J. Gerraty     OP_NOMETA_CMP	= 1 << 21,
254*2c3632d1SSimon J. Gerraty     /* Possibly a submake node */
255*2c3632d1SSimon J. Gerraty     OP_SUBMAKE		= 1 << 22,
256*2c3632d1SSimon J. Gerraty 
257*2c3632d1SSimon J. Gerraty     /* Attributes applied by PMake */
258*2c3632d1SSimon J. Gerraty 
259*2c3632d1SSimon J. Gerraty     /* The node is a transformation rule */
260*2c3632d1SSimon J. Gerraty     OP_TRANSFORM	= 1 << 31,
261*2c3632d1SSimon J. Gerraty     /* Target is a member of an archive */
262*2c3632d1SSimon J. Gerraty     OP_MEMBER		= 1 << 30,
263*2c3632d1SSimon J. Gerraty     /* Target is a library */
264*2c3632d1SSimon J. Gerraty     OP_LIB		= 1 << 29,
265*2c3632d1SSimon J. Gerraty     /* Target is an archive construct */
266*2c3632d1SSimon J. Gerraty     OP_ARCHV		= 1 << 28,
267*2c3632d1SSimon J. Gerraty     /* Target has all the commands it should. Used when parsing to catch
268*2c3632d1SSimon J. Gerraty      * multiple commands for a target. */
269*2c3632d1SSimon J. Gerraty     OP_HAS_COMMANDS	= 1 << 27,
270*2c3632d1SSimon J. Gerraty     /* Saving commands on .END (Compat) */
271*2c3632d1SSimon J. Gerraty     OP_SAVE_CMDS	= 1 << 26,
272*2c3632d1SSimon J. Gerraty     /* Already processed by Suff_FindDeps */
273*2c3632d1SSimon J. Gerraty     OP_DEPS_FOUND	= 1 << 25,
274*2c3632d1SSimon J. Gerraty     /* Node found while expanding .ALLSRC */
275*2c3632d1SSimon J. Gerraty     OP_MARK		= 1 << 24
276*2c3632d1SSimon J. Gerraty } GNodeType;
277*2c3632d1SSimon J. Gerraty 
278*2c3632d1SSimon J. Gerraty typedef enum {
279*2c3632d1SSimon J. Gerraty     REMAKE	= 0x0001,	/* this target needs to be (re)made */
280*2c3632d1SSimon J. Gerraty     CHILDMADE	= 0x0002,	/* children of this target were made */
281*2c3632d1SSimon J. Gerraty     FORCE	= 0x0004,	/* children don't exist, and we pretend made */
282*2c3632d1SSimon J. Gerraty     DONE_WAIT	= 0x0008,	/* Set by Make_ProcessWait() */
283*2c3632d1SSimon J. Gerraty     DONE_ORDER	= 0x0010,	/* Build requested by .ORDER processing */
284*2c3632d1SSimon J. Gerraty     FROM_DEPEND	= 0x0020,	/* Node created from .depend */
285*2c3632d1SSimon J. Gerraty     DONE_ALLSRC	= 0x0040,	/* We do it once only */
286*2c3632d1SSimon J. Gerraty     CYCLE	= 0x1000,	/* Used by MakePrintStatus */
287*2c3632d1SSimon J. Gerraty     DONECYCLE	= 0x2000,	/* Used by MakePrintStatus */
288*2c3632d1SSimon J. Gerraty     INTERNAL	= 0x4000	/* Internal use only */
289*2c3632d1SSimon J. Gerraty } GNodeFlags;
290*2c3632d1SSimon J. Gerraty 
291*2c3632d1SSimon J. Gerraty /* A graph node represents a target that can possibly be made, including its
292*2c3632d1SSimon J. Gerraty  * relation to other targets and a lot of other details. */
293*2c3632d1SSimon J. Gerraty typedef struct GNode {
294*2c3632d1SSimon J. Gerraty     /* The target's name, such as "clean" or "make.c" */
295*2c3632d1SSimon J. Gerraty     char *name;
296*2c3632d1SSimon J. Gerraty     /* The unexpanded name of a .USE node */
297*2c3632d1SSimon J. Gerraty     char *uname;
298*2c3632d1SSimon J. Gerraty     /* The full pathname of the file belonging to the target.
299*2c3632d1SSimon J. Gerraty      * XXX: What about .PHONY targets? These don't have an associated path. */
300*2c3632d1SSimon J. Gerraty     char *path;
301*2c3632d1SSimon J. Gerraty 
302*2c3632d1SSimon J. Gerraty     /* The type of operator used to define the sources (see the OP flags below).
303*2c3632d1SSimon J. Gerraty      * XXX: This looks like a wild mixture of type and flags. */
304*2c3632d1SSimon J. Gerraty     GNodeType type;
305*2c3632d1SSimon J. Gerraty     /* whether it is involved in this invocation of make */
306*2c3632d1SSimon J. Gerraty     GNodeFlags flags;
307*2c3632d1SSimon J. Gerraty 
308*2c3632d1SSimon J. Gerraty     /* The state of processing on this node */
309*2c3632d1SSimon J. Gerraty     GNodeMade made;
3103955d011SMarcel Moolenaar     int unmade;			/* The number of unmade children */
3113955d011SMarcel Moolenaar 
3123955d011SMarcel Moolenaar     time_t mtime;		/* Its modification time */
3133955d011SMarcel Moolenaar     struct GNode *cmgn;		/* The youngest child */
3143955d011SMarcel Moolenaar 
315*2c3632d1SSimon J. Gerraty     /* The GNodes for which this node is an implied source. May be empty.
316*2c3632d1SSimon J. Gerraty      * For example, when there is an inference rule for .c.o, the node for
317*2c3632d1SSimon J. Gerraty      * file.c has the node for file.o in this list. */
318*2c3632d1SSimon J. Gerraty     Lst implicitParents;
3193955d011SMarcel Moolenaar 
320*2c3632d1SSimon J. Gerraty     /* Other nodes of the same name for the :: operator. */
321*2c3632d1SSimon J. Gerraty     Lst cohorts;
3223955d011SMarcel Moolenaar 
323*2c3632d1SSimon J. Gerraty     /* The nodes that depend on this one, or in other words, the nodes for
324*2c3632d1SSimon J. Gerraty      * which this is a source. */
325*2c3632d1SSimon J. Gerraty     Lst parents;
326*2c3632d1SSimon J. Gerraty     /* The nodes on which this one depends. */
327*2c3632d1SSimon J. Gerraty     Lst children;
3283955d011SMarcel Moolenaar 
329*2c3632d1SSimon J. Gerraty     /* .ORDER nodes we need made. The nodes that must be made (if they're
330*2c3632d1SSimon J. Gerraty      * made) before this node can be made, but that do not enter into the
331*2c3632d1SSimon J. Gerraty      * datedness of this node. */
332*2c3632d1SSimon J. Gerraty     Lst order_pred;
333*2c3632d1SSimon J. Gerraty     /* .ORDER nodes who need us. The nodes that must be made (if they're made
334*2c3632d1SSimon J. Gerraty      * at all) after this node is made, but that do not depend on this node,
335*2c3632d1SSimon J. Gerraty      * in the normal sense. */
336*2c3632d1SSimon J. Gerraty     Lst order_succ;
337*2c3632d1SSimon J. Gerraty 
338*2c3632d1SSimon J. Gerraty     /* #n for this cohort */
339*2c3632d1SSimon J. Gerraty     char cohort_num[8];
340*2c3632d1SSimon J. Gerraty     /* The number of unmade instances on the cohorts list */
341*2c3632d1SSimon J. Gerraty     int unmade_cohorts;
342*2c3632d1SSimon J. Gerraty     /* Pointer to the first instance of a '::' node; only set when on a
343*2c3632d1SSimon J. Gerraty      * cohorts list */
344*2c3632d1SSimon J. Gerraty     struct GNode *centurion;
345*2c3632d1SSimon J. Gerraty 
346*2c3632d1SSimon J. Gerraty     /* Last time (sequence number) we tried to make this node */
347*2c3632d1SSimon J. Gerraty     unsigned int checked;
348*2c3632d1SSimon J. Gerraty 
349*2c3632d1SSimon J. Gerraty     /* The "local" variables that are specific to this target and this target
350*2c3632d1SSimon J. Gerraty      * only, such as $@, $<, $?. */
351*2c3632d1SSimon J. Gerraty     Hash_Table context;
352*2c3632d1SSimon J. Gerraty 
353*2c3632d1SSimon J. Gerraty     /* The commands to be given to a shell to create this target. */
354*2c3632d1SSimon J. Gerraty     Lst commands;
355*2c3632d1SSimon J. Gerraty 
356*2c3632d1SSimon J. Gerraty     /* Suffix for the node (determined by Suff_FindDeps and opaque to everyone
3573955d011SMarcel Moolenaar      * but the Suff module) */
358*2c3632d1SSimon J. Gerraty     struct Suff *suffix;
359*2c3632d1SSimon J. Gerraty 
360*2c3632d1SSimon J. Gerraty     /* filename where the GNode got defined */
361*2c3632d1SSimon J. Gerraty     const char *fname;
362*2c3632d1SSimon J. Gerraty     /* line number where the GNode got defined */
363*2c3632d1SSimon J. Gerraty     int lineno;
3643955d011SMarcel Moolenaar } GNode;
3653955d011SMarcel Moolenaar 
3663955d011SMarcel Moolenaar #define NoExecute(gn) ((gn->type & OP_MAKE) ? noRecursiveExecute : noExecute)
3673955d011SMarcel Moolenaar /*
3683955d011SMarcel Moolenaar  * OP_NOP will return TRUE if the node with the given type was not the
3693955d011SMarcel Moolenaar  * object of a dependency operator
3703955d011SMarcel Moolenaar  */
3713955d011SMarcel Moolenaar #define OP_NOP(t)	(((t) & OP_OPMASK) == 0x00000000)
3723955d011SMarcel Moolenaar 
3733955d011SMarcel Moolenaar #define OP_NOTARGET (OP_NOTMAIN|OP_USE|OP_EXEC|OP_TRANSFORM)
3743955d011SMarcel Moolenaar 
3753955d011SMarcel Moolenaar /*
3763955d011SMarcel Moolenaar  * The TARG_ constants are used when calling the Targ_FindNode and
3773955d011SMarcel Moolenaar  * Targ_FindList functions in targ.c. They simply tell the functions what to
3783955d011SMarcel Moolenaar  * do if the desired node(s) is (are) not found. If the TARG_CREATE constant
3793955d011SMarcel Moolenaar  * is given, a new, empty node will be created for the target, placed in the
3803955d011SMarcel Moolenaar  * table of all targets and its address returned. If TARG_NOCREATE is given,
3813955d011SMarcel Moolenaar  * a NULL pointer will be returned.
3823955d011SMarcel Moolenaar  */
3833955d011SMarcel Moolenaar #define TARG_NOCREATE	0x00	  /* don't create it */
3843955d011SMarcel Moolenaar #define TARG_CREATE	0x01	  /* create node if not found */
3853955d011SMarcel Moolenaar #define TARG_NOHASH	0x02	  /* don't look in/add to hash table */
3863955d011SMarcel Moolenaar 
3873955d011SMarcel Moolenaar /*
3883955d011SMarcel Moolenaar  * Error levels for parsing. PARSE_FATAL means the process cannot continue
3893955d011SMarcel Moolenaar  * once the makefile has been parsed. PARSE_WARNING means it can. Passed
3903955d011SMarcel Moolenaar  * as the first argument to Parse_Error.
3913955d011SMarcel Moolenaar  */
39250d2e745SSimon J. Gerraty #define PARSE_INFO	3
3933955d011SMarcel Moolenaar #define PARSE_WARNING	2
3943955d011SMarcel Moolenaar #define PARSE_FATAL	1
3953955d011SMarcel Moolenaar 
3963955d011SMarcel Moolenaar /*
3973955d011SMarcel Moolenaar  * Values returned by Cond_Eval.
3983955d011SMarcel Moolenaar  */
399*2c3632d1SSimon J. Gerraty typedef enum {
400*2c3632d1SSimon J. Gerraty     COND_PARSE,			/* Parse the next lines */
401*2c3632d1SSimon J. Gerraty     COND_SKIP,			/* Skip the next lines */
402*2c3632d1SSimon J. Gerraty     COND_INVALID		/* Not a conditional statement */
403*2c3632d1SSimon J. Gerraty } CondEvalResult;
4043955d011SMarcel Moolenaar 
4053955d011SMarcel Moolenaar /*
4063955d011SMarcel Moolenaar  * Definitions for the "local" variables. Used only for clarity.
4073955d011SMarcel Moolenaar  */
4083955d011SMarcel Moolenaar #define TARGET	  	  "@" 	/* Target of dependency */
4093955d011SMarcel Moolenaar #define OODATE	  	  "?" 	/* All out-of-date sources */
4103955d011SMarcel Moolenaar #define ALLSRC	  	  ">" 	/* All sources */
4113955d011SMarcel Moolenaar #define IMPSRC	  	  "<" 	/* Source implied by transformation */
4123955d011SMarcel Moolenaar #define PREFIX	  	  "*" 	/* Common prefix */
4133955d011SMarcel Moolenaar #define ARCHIVE	  	  "!" 	/* Archive in "archive(member)" syntax */
4143955d011SMarcel Moolenaar #define MEMBER	  	  "%" 	/* Member in "archive(member)" syntax */
4153955d011SMarcel Moolenaar 
4163955d011SMarcel Moolenaar #define FTARGET           "@F"  /* file part of TARGET */
4173955d011SMarcel Moolenaar #define DTARGET           "@D"  /* directory part of TARGET */
4183955d011SMarcel Moolenaar #define FIMPSRC           "<F"  /* file part of IMPSRC */
4193955d011SMarcel Moolenaar #define DIMPSRC           "<D"  /* directory part of IMPSRC */
4203955d011SMarcel Moolenaar #define FPREFIX           "*F"  /* file part of PREFIX */
4213955d011SMarcel Moolenaar #define DPREFIX           "*D"  /* directory part of PREFIX */
4223955d011SMarcel Moolenaar 
4233955d011SMarcel Moolenaar /*
4243955d011SMarcel Moolenaar  * Global Variables
4253955d011SMarcel Moolenaar  */
4263955d011SMarcel Moolenaar extern Lst  	create;	    	/* The list of target names specified on the
4273955d011SMarcel Moolenaar 				 * command line. used to resolve #if
4283955d011SMarcel Moolenaar 				 * make(...) statements */
4293955d011SMarcel Moolenaar extern Lst     	dirSearchPath; 	/* The list of directories to search when
4303955d011SMarcel Moolenaar 				 * looking for targets */
4313955d011SMarcel Moolenaar 
4323955d011SMarcel Moolenaar extern Boolean	compatMake;	/* True if we are make compatible */
4333955d011SMarcel Moolenaar extern Boolean	ignoreErrors;  	/* True if should ignore all errors */
4343955d011SMarcel Moolenaar extern Boolean  beSilent;    	/* True if should print no commands */
4353955d011SMarcel Moolenaar extern Boolean  noExecute;    	/* True if should execute nothing */
4363955d011SMarcel Moolenaar extern Boolean  noRecursiveExecute;    	/* True if should execute nothing */
4373955d011SMarcel Moolenaar extern Boolean  allPrecious;   	/* True if every target is precious */
43845447996SSimon J. Gerraty extern Boolean  deleteOnError;	/* True if failed targets should be deleted */
4393955d011SMarcel Moolenaar extern Boolean  keepgoing;    	/* True if should continue on unaffected
4403955d011SMarcel Moolenaar 				 * portions of the graph when have an error
4413955d011SMarcel Moolenaar 				 * in one portion */
4423955d011SMarcel Moolenaar extern Boolean 	touchFlag;    	/* TRUE if targets should just be 'touched'
4433955d011SMarcel Moolenaar 				 * if out of date. Set by the -t flag */
4443955d011SMarcel Moolenaar extern Boolean 	queryFlag;    	/* TRUE if we aren't supposed to really make
4453955d011SMarcel Moolenaar 				 * anything, just see if the targets are out-
4463955d011SMarcel Moolenaar 				 * of-date */
4473955d011SMarcel Moolenaar extern Boolean	doing_depend;	/* TRUE if processing .depend */
4483955d011SMarcel Moolenaar 
4493955d011SMarcel Moolenaar extern Boolean	checkEnvFirst;	/* TRUE if environment should be searched for
4503955d011SMarcel Moolenaar 				 * variables before the global context */
4513955d011SMarcel Moolenaar 
4523955d011SMarcel Moolenaar extern Boolean	parseWarnFatal;	/* TRUE if makefile parsing warnings are
4533955d011SMarcel Moolenaar 				 * treated as errors */
4543955d011SMarcel Moolenaar 
4553955d011SMarcel Moolenaar extern Boolean	varNoExportEnv;	/* TRUE if we should not export variables
4563955d011SMarcel Moolenaar 				 * set on the command line to the env. */
4573955d011SMarcel Moolenaar 
4583955d011SMarcel Moolenaar extern GNode    *DEFAULT;    	/* .DEFAULT rule */
4593955d011SMarcel Moolenaar 
4601bbe5942SSimon J. Gerraty extern GNode	*VAR_INTERNAL;	/* Variables defined internally by make
4611bbe5942SSimon J. Gerraty 				 * which should not override those set by
4621bbe5942SSimon J. Gerraty 				 * makefiles.
4631bbe5942SSimon J. Gerraty 				 */
4643955d011SMarcel Moolenaar extern GNode    *VAR_GLOBAL;   	/* Variables defined in a global context, e.g
4653955d011SMarcel Moolenaar 				 * in the Makefile itself */
4663955d011SMarcel Moolenaar extern GNode    *VAR_CMD;    	/* Variables defined on the command line */
4673955d011SMarcel Moolenaar extern char    	var_Error[];   	/* Value returned by Var_Parse when an error
4683955d011SMarcel Moolenaar 				 * is encountered. It actually points to
4693955d011SMarcel Moolenaar 				 * an empty string, so naive callers needn't
4703955d011SMarcel Moolenaar 				 * worry about it. */
4713955d011SMarcel Moolenaar 
4723955d011SMarcel Moolenaar extern time_t 	now;	    	/* The time at the start of this whole
4733955d011SMarcel Moolenaar 				 * process */
4743955d011SMarcel Moolenaar 
4753955d011SMarcel Moolenaar extern Boolean	oldVars;    	/* Do old-style variable substitution */
4763955d011SMarcel Moolenaar 
4773955d011SMarcel Moolenaar extern Lst	sysIncPath;	/* The system include path. */
4783955d011SMarcel Moolenaar extern Lst	defIncPath;	/* The default include path. */
4793955d011SMarcel Moolenaar 
4803955d011SMarcel Moolenaar extern char	curdir[];	/* Startup directory */
4813955d011SMarcel Moolenaar extern char	*progname;	/* The program name */
4823955d011SMarcel Moolenaar extern char	*makeDependfile; /* .depend */
4833955d011SMarcel Moolenaar extern char	**savedEnv;	 /* if we replaced environ this will be non-NULL */
4843955d011SMarcel Moolenaar 
485*2c3632d1SSimon J. Gerraty extern int	makelevel;
486*2c3632d1SSimon J. Gerraty 
4873955d011SMarcel Moolenaar /*
4883955d011SMarcel Moolenaar  * We cannot vfork() in a child of vfork().
4893955d011SMarcel Moolenaar  * Most systems do not enforce this but some do.
4903955d011SMarcel Moolenaar  */
4913955d011SMarcel Moolenaar #define vFork() ((getpid() == myPid) ? vfork() : fork())
4923955d011SMarcel Moolenaar extern pid_t	myPid;
4933955d011SMarcel Moolenaar 
4943955d011SMarcel Moolenaar #define	MAKEFLAGS	".MAKEFLAGS"
4953955d011SMarcel Moolenaar #define	MAKEOVERRIDES	".MAKEOVERRIDES"
4963955d011SMarcel Moolenaar #define	MAKE_JOB_PREFIX	".MAKE.JOB.PREFIX" /* prefix for job target output */
4973955d011SMarcel Moolenaar #define	MAKE_EXPORTED	".MAKE.EXPORTED"   /* variables we export */
4983955d011SMarcel Moolenaar #define	MAKE_MAKEFILES	".MAKE.MAKEFILES"  /* all the makefiles we read */
4993955d011SMarcel Moolenaar #define	MAKE_LEVEL	".MAKE.LEVEL"	   /* recursion level */
5003955d011SMarcel Moolenaar #define MAKEFILE_PREFERENCE ".MAKE.MAKEFILE_PREFERENCE"
5013955d011SMarcel Moolenaar #define MAKE_DEPENDFILE	".MAKE.DEPENDFILE" /* .depend */
5023955d011SMarcel Moolenaar #define MAKE_MODE	".MAKE.MODE"
50351ee2c1cSSimon J. Gerraty #ifndef MAKE_LEVEL_ENV
50451ee2c1cSSimon J. Gerraty # define MAKE_LEVEL_ENV	"MAKELEVEL"
5053955d011SMarcel Moolenaar #endif
5063955d011SMarcel Moolenaar 
5073955d011SMarcel Moolenaar /*
5083955d011SMarcel Moolenaar  * debug control:
5093955d011SMarcel Moolenaar  *	There is one bit per module.  It is up to the module what debug
5103955d011SMarcel Moolenaar  *	information to print.
5113955d011SMarcel Moolenaar  */
512*2c3632d1SSimon J. Gerraty extern FILE *debug_file;	/* Output is written here - default stderr */
5133955d011SMarcel Moolenaar extern int debug;
5143955d011SMarcel Moolenaar #define	DEBUG_ARCH	0x00001
5153955d011SMarcel Moolenaar #define	DEBUG_COND	0x00002
5163955d011SMarcel Moolenaar #define	DEBUG_DIR	0x00004
5173955d011SMarcel Moolenaar #define	DEBUG_GRAPH1	0x00008
5183955d011SMarcel Moolenaar #define	DEBUG_GRAPH2	0x00010
5193955d011SMarcel Moolenaar #define	DEBUG_JOB	0x00020
5203955d011SMarcel Moolenaar #define	DEBUG_MAKE	0x00040
5213955d011SMarcel Moolenaar #define	DEBUG_SUFF	0x00080
5223955d011SMarcel Moolenaar #define	DEBUG_TARG	0x00100
5233955d011SMarcel Moolenaar #define	DEBUG_VAR	0x00200
5243955d011SMarcel Moolenaar #define DEBUG_FOR	0x00400
5253955d011SMarcel Moolenaar #define DEBUG_SHELL	0x00800
5263955d011SMarcel Moolenaar #define DEBUG_ERROR	0x01000
5273955d011SMarcel Moolenaar #define DEBUG_LOUD	0x02000
5283955d011SMarcel Moolenaar #define DEBUG_META	0x04000
529*2c3632d1SSimon J. Gerraty #define DEBUG_HASH	0x08000
5303955d011SMarcel Moolenaar 
5313955d011SMarcel Moolenaar #define DEBUG_GRAPH3	0x10000
5323955d011SMarcel Moolenaar #define DEBUG_SCRIPT	0x20000
5333955d011SMarcel Moolenaar #define DEBUG_PARSE	0x40000
5343955d011SMarcel Moolenaar #define DEBUG_CWD	0x80000
5353955d011SMarcel Moolenaar 
536*2c3632d1SSimon J. Gerraty #define DEBUG_LINT	0x100000
537*2c3632d1SSimon J. Gerraty 
5383955d011SMarcel Moolenaar #define CONCAT(a,b)	a##b
5393955d011SMarcel Moolenaar 
5403955d011SMarcel Moolenaar #define	DEBUG(module)	(debug & CONCAT(DEBUG_,module))
5413955d011SMarcel Moolenaar 
5423955d011SMarcel Moolenaar #include "nonints.h"
5433955d011SMarcel Moolenaar 
5443955d011SMarcel Moolenaar int Make_TimeStamp(GNode *, GNode *);
5453955d011SMarcel Moolenaar Boolean Make_OODate(GNode *);
5463955d011SMarcel Moolenaar void Make_ExpandUse(Lst);
5473955d011SMarcel Moolenaar time_t Make_Recheck(GNode *);
5483955d011SMarcel Moolenaar void Make_HandleUse(GNode *, GNode *);
5493955d011SMarcel Moolenaar void Make_Update(GNode *);
5503955d011SMarcel Moolenaar void Make_DoAllVar(GNode *);
5513955d011SMarcel Moolenaar Boolean Make_Run(Lst);
5523841c287SSimon J. Gerraty int dieQuietly(GNode *, int);
5533955d011SMarcel Moolenaar void PrintOnError(GNode *, const char *);
5543955d011SMarcel Moolenaar void Main_ExportMAKEFLAGS(Boolean);
55545447996SSimon J. Gerraty Boolean Main_SetObjdir(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
5563955d011SMarcel Moolenaar int mkTempFile(const char *, char **);
5573955d011SMarcel Moolenaar int str2Lst_Append(Lst, char *, const char *);
558*2c3632d1SSimon J. Gerraty void GNode_FprintDetails(FILE *, const char *, const GNode *, const char *);
5593955d011SMarcel Moolenaar 
5603955d011SMarcel Moolenaar #ifdef __GNUC__
5613955d011SMarcel Moolenaar #define UNCONST(ptr)	({ 		\
5623955d011SMarcel Moolenaar     union __unconst {			\
5633955d011SMarcel Moolenaar 	const void *__cp;		\
5643955d011SMarcel Moolenaar 	void *__p;			\
5653955d011SMarcel Moolenaar     } __d;				\
5663955d011SMarcel Moolenaar     __d.__cp = ptr, __d.__p; })
5673955d011SMarcel Moolenaar #else
5683955d011SMarcel Moolenaar #define UNCONST(ptr)	(void *)(ptr)
5693955d011SMarcel Moolenaar #endif
5703955d011SMarcel Moolenaar 
5713955d011SMarcel Moolenaar #ifndef MIN
572*2c3632d1SSimon J. Gerraty #define MIN(a, b) (((a) < (b)) ? (a) : (b))
5733955d011SMarcel Moolenaar #endif
5743955d011SMarcel Moolenaar #ifndef MAX
575*2c3632d1SSimon J. Gerraty #define MAX(a, b) (((a) > (b)) ? (a) : (b))
5763955d011SMarcel Moolenaar #endif
5773955d011SMarcel Moolenaar 
5784c620fe5SSimon J. Gerraty /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */
5794c620fe5SSimon J. Gerraty #ifdef HAVE_LIMITS_H
5804c620fe5SSimon J. Gerraty #include <limits.h>
5814c620fe5SSimon J. Gerraty #endif
5820dede8b0SSimon J. Gerraty #ifndef MAXPATHLEN
5830dede8b0SSimon J. Gerraty #define MAXPATHLEN	BMAKE_PATH_MAX
5840dede8b0SSimon J. Gerraty #endif
5854c620fe5SSimon J. Gerraty #ifndef PATH_MAX
5864c620fe5SSimon J. Gerraty #define PATH_MAX	MAXPATHLEN
5874c620fe5SSimon J. Gerraty #endif
5880dede8b0SSimon J. Gerraty 
589c7019bf7SSimon J. Gerraty #if defined(SYSV)
590c7019bf7SSimon J. Gerraty #define KILLPG(pid, sig)	kill(-(pid), (sig))
591c7019bf7SSimon J. Gerraty #else
592c7019bf7SSimon J. Gerraty #define KILLPG(pid, sig)	killpg((pid), (sig))
593c7019bf7SSimon J. Gerraty #endif
594c7019bf7SSimon J. Gerraty 
595*2c3632d1SSimon J. Gerraty #endif /* MAKE_MAKE_H */
596