1141104Sharti/*-
2141104Sharti * Copyright (c) 1988, 1989, 1990, 1993
3141104Sharti *	The Regents of the University of California.  All rights reserved.
4141104Sharti * Copyright (c) 1989 by Berkeley Softworks
5141104Sharti * All rights reserved.
6141104Sharti *
7141104Sharti * This code is derived from software contributed to Berkeley by
8141104Sharti * Adam de Boor.
9141104Sharti *
10141104Sharti * Redistribution and use in source and binary forms, with or without
11141104Sharti * modification, are permitted provided that the following conditions
12141104Sharti * are met:
13141104Sharti * 1. Redistributions of source code must retain the above copyright
14141104Sharti *    notice, this list of conditions and the following disclaimer.
15141104Sharti * 2. Redistributions in binary form must reproduce the above copyright
16141104Sharti *    notice, this list of conditions and the following disclaimer in the
17141104Sharti *    documentation and/or other materials provided with the distribution.
18141104Sharti * 3. All advertising materials mentioning features or use of this software
19141104Sharti *    must display the following acknowledgement:
20141104Sharti *	This product includes software developed by the University of
21141104Sharti *	California, Berkeley and its contributors.
22141104Sharti * 4. Neither the name of the University nor the names of its contributors
23141104Sharti *    may be used to endorse or promote products derived from this software
24141104Sharti *    without specific prior written permission.
25141104Sharti *
26141104Sharti * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27141104Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28141104Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29141104Sharti * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30141104Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31141104Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32141104Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33141104Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34141104Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35141104Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36141104Sharti * SUCH DAMAGE.
37141104Sharti *
38141104Sharti * $FreeBSD$
39141104Sharti */
40141104Sharti
41141104Sharti#ifndef GNode_h_39503bf2
42141104Sharti#define	GNode_h_39503bf2
43141104Sharti
44141104Sharti#include "lst.h"
45146177Sharti#include "util.h"
46141104Sharti
47143411Shartistruct Suff;
48141104Sharti
49141104Sharti/*
50141104Sharti * The structure for an individual graph node. Each node has several
51141104Sharti * pieces of data associated with it.
52141104Sharti */
53141104Shartitypedef struct GNode {
54141104Sharti	char	*name;	/* The target's name */
55141104Sharti	char	*path;	/* The full pathname of the target file */
56141104Sharti
57141104Sharti	/*
58141104Sharti	 * The type of operator used to define the sources (qv. parse.c)
59146066Sharti	 *
60146066Sharti	 * The OP_ constants are used when parsing a dependency line as a way of
61146066Sharti	 * communicating to other parts of the program the way in which a target
62146066Sharti	 * should be made. These constants are bitwise-OR'ed together and
63146066Sharti	 * placed in the 'type' field of each node. Any node that has
64146066Sharti	 * a 'type' field which satisfies the OP_NOP function was never never on
65146066Sharti	 * the lefthand side of an operator, though it may have been on the
66146066Sharti	 * righthand side...
67141104Sharti	 */
68141104Sharti	int	type;
69146066Sharti#define	OP_DEPENDS	0x00000001	/* Execution of commands depends on
70146066Sharti					 * kids (:) */
71146066Sharti#define	OP_FORCE	0x00000002	/* Always execute commands (!) */
72146066Sharti#define	OP_DOUBLEDEP	0x00000004	/* Execution of commands depends on
73146066Sharti					 * kids per line (::) */
74146066Sharti#define	OP_OPMASK	(OP_DEPENDS|OP_FORCE|OP_DOUBLEDEP)
75141104Sharti
76146066Sharti#define	OP_OPTIONAL	0x00000008	/* Don't care if the target doesn't
77146066Sharti					 * exist and can't be created */
78146066Sharti#define	OP_USE		0x00000010	/*
79146066Sharti					 * Use associated commands for
80146066Sharti					 * parents
81146066Sharti					 */
82146066Sharti#define	OP_EXEC		0x00000020	/* Target is never out of date, but
83146066Sharti					 * always execute commands anyway.
84146066Sharti					 * Its time doesn't matter, so it has
85146066Sharti					 * none...sort of
86146066Sharti					 */
87146066Sharti#define	OP_IGNORE	0x00000040	/*
88146066Sharti					 * Ignore errors when creating the node
89146066Sharti					 */
90146066Sharti#define	OP_PRECIOUS	0x00000080	/* Don't remove the target when
91146066Sharti					 * interrupted */
92146066Sharti#define	OP_SILENT	0x00000100	/* Don't echo commands when executed */
93146066Sharti#define	OP_MAKE		0x00000200	/*
94146066Sharti					 * Target is a recurrsive make so its
95146066Sharti					 * commands should always be executed
96146066Sharti					 * when it is out of date, regardless
97146066Sharti					 * of the state of the -n or -t flags
98146066Sharti					 */
99146066Sharti#define	OP_JOIN		0x00000400	/* Target is out-of-date only if any of
100146066Sharti					 * its children was out-of-date */
101146066Sharti#define	OP_INVISIBLE	0x00004000	/* The node is invisible to its parents.
102146066Sharti					 * I.e. it doesn't show up in the
103146066Sharti					 * parents's local variables. */
104146066Sharti#define	OP_NOTMAIN	0x00008000	/* The node is exempt from normal 'main
105146066Sharti					 * target' processing in parse.c */
106146066Sharti#define	OP_PHONY	0x00010000	/* Not a file target; run always */
107146066Sharti/* Attributes applied by PMake */
108146066Sharti#define	OP_TRANSFORM	0x80000000	/* The node is a transformation rule */
109146066Sharti#define	OP_MEMBER	0x40000000	/* Target is a member of an archive */
110146066Sharti#define	OP_LIB		0x20000000	/* Target is a library */
111146066Sharti#define	OP_ARCHV	0x10000000	/* Target is an archive construct */
112146066Sharti#define	OP_HAS_COMMANDS	0x08000000	/* Target has all the commands it
113146066Sharti					 * should.  Used when parsing to catch
114146066Sharti					 * multiple commands for a target */
115146066Sharti#define	OP_SAVE_CMDS	0x04000000	/* Saving commands on .END (Compat) */
116146066Sharti#define	OP_DEPS_FOUND	0x02000000	/* Already processed by Suff_FindDeps */
117146066Sharti
118146066Sharti/*
119146066Sharti * OP_NOP will return TRUE if the node with the given type was not the
120146066Sharti * object of a dependency operator
121146066Sharti */
122146066Sharti#define	OP_NOP(t)	(((t) & OP_OPMASK) == 0x00000000)
123146066Sharti
124141104Sharti	int	order;	/* Its wait weight */
125141104Sharti
126141104Sharti	Boolean	make;	/* TRUE if this target needs to be remade */
127141104Sharti
128141104Sharti	/* Set to reflect the state of processing on this node */
129141104Sharti	enum {
130141104Sharti		UNMADE,		/* Not examined yet */
131141104Sharti
132141104Sharti		/*
133141104Sharti		 * Target is already being made. Indicates a cycle in the graph.
134141104Sharti		 * (compat mode only)
135141104Sharti		 */
136141104Sharti		BEINGMADE,
137141104Sharti
138141104Sharti		MADE,		/* Was out-of-date and has been made */
139141104Sharti		UPTODATE,	/* Was already up-to-date */
140141104Sharti
141141104Sharti		/*
142228992Suqs		 * An error occurred while it was being
143141104Sharti		 * made (used only in compat mode)
144141104Sharti		 */
145141104Sharti		ERROR,
146141104Sharti
147141104Sharti		/*
148141104Sharti		 * The target was aborted due to an
149141104Sharti		 * error making an inferior (compat).
150141104Sharti		 */
151141104Sharti		ABORTED,
152141104Sharti
153141104Sharti		/*
154141104Sharti		 * Marked as potentially being part of a graph cycle.  If we
155141104Sharti		 * come back to a node marked this way, it is printed and
156141104Sharti		 * 'made' is changed to ENDCYCLE.
157141104Sharti		 */
158141104Sharti		CYCLE,
159141104Sharti
160141104Sharti		/*
161141104Sharti		 * The cycle has been completely printed.  Go back and
162141104Sharti		 * unmark all its members.
163141104Sharti		 */
164141104Sharti		ENDCYCLE
165141104Sharti	} made;
166141104Sharti
167141104Sharti	/* TRUE if one of this target's children was made */
168141104Sharti	Boolean	childMade;
169141104Sharti
170141104Sharti	int	unmade;		/* The number of unmade children */
171141104Sharti	int	mtime;		/* Its modification time */
172141104Sharti	int	cmtime;		/* Modification time of its youngest child */
173168893Sfjoe	struct GNode *cmtime_gn;/* Youngest child */
174141104Sharti
175141104Sharti	/*
176141104Sharti	 * Links to parents for which this is an implied source, if any. (nodes
177141104Sharti	 * that depend on this, as gleaned from the transformation rules.
178141104Sharti	 */
179141104Sharti	Lst	iParents;
180141104Sharti
181141104Sharti	/* List of nodes of the same name created by the :: operator */
182141104Sharti	Lst	cohorts;
183141104Sharti
184141104Sharti	/* Lst of nodes for which this is a source (that depend on this one) */
185141104Sharti	Lst	parents;
186141104Sharti
187146066Sharti	/* List of nodes on which this depends */
188141104Sharti	Lst	children;
189141104Sharti
190141104Sharti	/*
191141104Sharti	 * List of nodes that must be made (if they're made) after this node is,
192141104Sharti	 * but that do not depend on this node, in the normal sense.
193141104Sharti	 */
194141104Sharti	Lst	successors;
195141104Sharti
196141104Sharti	/*
197141104Sharti	 * List of nodes that must be made (if they're made) before this node
198141104Sharti	 * can be, but that do no enter into the datedness of this node.
199141104Sharti	 */
200141104Sharti	Lst	preds;
201141104Sharti
202141104Sharti	/*
203141104Sharti	 * List of ``local'' variables that are specific to this target
204141104Sharti	 * and this target only (qv. var.c [$@ $< $?, etc.])
205141104Sharti	 */
206141104Sharti	Lst	context;
207141104Sharti
208141104Sharti	/*
209141104Sharti	 * List of strings that are commands to be given to a shell
210141104Sharti	 * to create this target.
211141104Sharti	 */
212141104Sharti	Lst	commands;
213141104Sharti
214141104Sharti	/* current command executing in compat mode */
215141104Sharti	LstNode	*compat_command;
216141104Sharti
217141104Sharti	/*
218141104Sharti	 * Suffix for the node (determined by Suff_FindDeps and opaque to
219141104Sharti	 * everyone but the Suff module)
220141104Sharti	 */
221143411Sharti	struct Suff	*suffix;
222141104Sharti} GNode;
223141104Sharti
224141104Sharti#endif /* GNode_h_39503bf2 */
225