Annotation of src/usr.bin/make/gnode.h, Revision 1.39
1.1 espie 1: #ifndef GNODE_H
2: #define GNODE_H
1.39 ! espie 3: /* $OpenBSD: gnode.h,v 1.38 2020/01/26 12:37:47 espie Exp $ */
1.1 espie 4:
5: /*
6: * Copyright (c) 2001 Marc Espie.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: *
17: * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
18: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
21: * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28: */
29:
1.24 espie 30: #include <sys/time.h>
1.1 espie 31: #ifndef LIST_TYPE
32: #include "lst_t.h"
33: #endif
1.18 espie 34: #ifndef LOCATION_TYPE
35: #include "location.h"
36: #endif
1.1 espie 37: #ifndef SYMTABLE_H
38: #include "symtable.h"
39: #endif
1.26 espie 40: #include <assert.h>
1.1 espie 41:
42: /*-
1.33 espie 43: * The structure for an individual graph node. Each node has a lot of
44: * of data associated with it.
45: * 1) the *name*of the target it describes (at end because ohash)
46: * 2) the *path* to the target file
47: * 3) the *type* of operator used to define its sources
48: * (cf parse.c, mostly : :: ! but...)
49: * 4) *must_make*: whether it is involved in this invocation of make
50: * 5) *built_status*: has the target been rebuilt/is up-to-date...
51: * 6) *child_rebuild*: at least one of its children has been rebuilt
52: * 7) *children_left*: number of children still to consider
53: * 8) *mtime*: node's modification time
54: * 9) *youngest*: youngest child (cf make.c)
55: * 10) *parents*: list of nodes for which this is a dependency
56: * 11) *children*: list of nodes on which this depends
57: * 12) *cohorts*: list of nodes of the same name created by the :: operator
58: * 13) *predecessors*: list of nodes, result of .ORDER:
1.31 espie 59: * if considered for building, they should be built before this node.
1.33 espie 60: * 14) *successors*: list of nodes, result of .ORDER:
1.31 espie 61: * if considered for building, they should be built after this node.
1.33 espie 62: * 15) *localvars*: ``local'' variables specific to this target
63: * and this target only (cf var.c [$@ $< $?, etc.])
64: * 16) *commands*: the actual LIST of strings to pass to the shell
1.1 espie 65: * to create this target.
66: */
1.5 espie 67:
1.37 espie 68: /* constants for specials
1.35 espie 69: * Most of these values are only handled by parse.c.
70: * In many cases, there is a corresponding OP_* flag
71: */
1.33 espie 72: #define SPECIAL_NONE 0U
1.35 espie 73: #define SPECIAL_PATH 62U /* handled by parse.c and suff.c */
1.5 espie 74:
1.35 espie 75: #define SPECIAL_EXEC 4U
1.21 espie 76: #define SPECIAL_IGNORE 5U
1.36 espie 77: #define SPECIAL_NOTHING 6U /* this is used for things we
78: * recognize for compatibility but
79: * don't do anything with... */
1.38 espie 80: #define SPECIAL_DEPRECATED 7U /* this is an old keyword and it will
81: * trigger a fatal error. */
1.35 espie 82: #define SPECIAL_INVISIBLE 8U
1.21 espie 83: #define SPECIAL_JOIN 9U
84: #define SPECIAL_MADE 11U
85: #define SPECIAL_MAIN 12U
86: #define SPECIAL_MAKE 13U
87: #define SPECIAL_MFLAGS 14U
1.35 espie 88: #define SPECIAL_NOTMAIN 15U
89: #define SPECIAL_NOTPARALLEL 16U
90: #define SPECIAL_OPTIONAL 18U
1.21 espie 91: #define SPECIAL_ORDER 19U
92: #define SPECIAL_PARALLEL 20U
93: #define SPECIAL_PHONY 22U
94: #define SPECIAL_PRECIOUS 23U
95: #define SPECIAL_SILENT 25U
96: #define SPECIAL_SUFFIXES 27U
1.35 espie 97: #define SPECIAL_USE 28U
1.21 espie 98: #define SPECIAL_WAIT 29U
99: #define SPECIAL_NOPATH 30U
100: #define SPECIAL_ERROR 31U
101: #define SPECIAL_CHEAP 32U
102: #define SPECIAL_EXPENSIVE 33U
103:
1.1 espie 104: struct GNode_ {
1.33 espie 105: unsigned int type; /* node type (see the OP flags, below) */
106: unsigned int special_op; /* special op to apply (only used in parse.c) */
107: unsigned char special; /* type of special node or SPECIAL_NONE */
1.32 espie 108: bool must_make; /* true if this target needs building */
109: bool child_rebuilt; /* true if at least one child was rebuilt,
1.31 espie 110: * thus triggering timestamps changes */
111:
112: char built_status;
113: #define UNKNOWN 0 /* Not examined yet */
114: #define BUILDING 1 /* In the process of building */
115: #define REBUILT 2 /* Was out of date and got rebuilt */
116: #define UPTODATE 3 /* Was already up-to-date */
117: #define ERROR 4 /* Error occurred while building
118: * (used only in compat mode) */
119: #define ABORTED 5 /* Was aborted due to an error
120: * making an inferior */
121: #define NOSUCHNODE 6 /* error from run_gnode */
122: #define HELDBACK 7 /* Another target in the same group is
1.33 espie 123: * currently building, avoid race conditions
124: * Only used in the parallel engine make.c */
1.31 espie 125:
1.33 espie 126: char *path; /* full pathname of the file */
127: int order; /* wait weight (see .ORDER/predecessors/successors) */
1.5 espie 128:
1.33 espie 129: int children_left; /* number of children left to build */
1.5 espie 130:
1.31 espie 131: struct timespec mtime; /* Node's modification time */
132: GNode *youngest; /* Node's youngest child */
1.5 espie 133:
1.33 espie 134: GNode *impliedsrc; /* found by suff, to help with localvars */
1.5 espie 135: LIST cohorts; /* Other nodes for the :: operator */
136: LIST parents; /* Nodes that depend on this one */
137: LIST children; /* Nodes on which this one depends */
1.31 espie 138: LIST predecessors;
139: LIST successors;
1.5 espie 140:
1.33 espie 141: SymTable localvars;
1.5 espie 142: LIST commands; /* Creation commands */
1.23 espie 143: Suff *suffix; /* Suffix for the node (determined by
1.5 espie 144: * Suff_FindDeps and opaque to everyone
145: * but the Suff module) */
1.33 espie 146: GNode *groupling; /* target lists, for HELDBACK: do not build two
147: * at the same time */
148: GNode *watched; /* the node currently building for HELDBACK */
149:
150: /* stuff for target name equivalence: */
151: GNode *sibling; /* equivalent targets (not complete yet) */
1.14 espie 152: char *basename; /* pointer to name stripped of path */
1.23 espie 153: GNode *next;
1.33 espie 154:
155: bool in_cycle; /* cycle detection */
1.5 espie 156: char name[1]; /* The target's name */
1.20 espie 157: };
158:
159: struct command
160: {
161: Location location;
162: char string[1];
1.1 espie 163: };
164:
1.14 espie 165: #define has_been_built(gn) \
1.30 espie 166: ((gn)->built_status == REBUILT || (gn)->built_status == UPTODATE)
1.14 espie 167: #define should_have_file(gn) \
168: ((gn)->special == SPECIAL_NONE && \
169: ((gn)->type & (OP_PHONY | OP_DUMMY)) == 0)
1.1 espie 170: /*
171: * The OP_ constants are used when parsing a dependency line as a way of
172: * communicating to other parts of the program the way in which a target
173: * should be made. These constants are bitwise-OR'ed together and
174: * placed in the 'type' field of each node. Any node that has
175: * a 'type' field which satisfies the OP_NOP function was never never on
176: * the lefthand side of an operator, though it may have been on the
177: * righthand side...
178: */
1.34 espie 179: #define OP_ZERO 0x00000000 /* No dependency operator seen so far */
1.1 espie 180: #define OP_DEPENDS 0x00000001 /* Execution of commands depends on
181: * kids (:) */
182: #define OP_FORCE 0x00000002 /* Always execute commands (!) */
183: #define OP_DOUBLEDEP 0x00000004 /* Execution of commands depends on kids
184: * per line (::) */
1.34 espie 185: #define OP_ERROR 0x00000007
1.1 espie 186: #define OP_OPMASK (OP_DEPENDS|OP_FORCE|OP_DOUBLEDEP)
187:
188: #define OP_OPTIONAL 0x00000008 /* Don't care if the target doesn't
189: * exist and can't be created */
190: #define OP_USE 0x00000010 /* Use associated commands for parents */
191: #define OP_IGNORE 0x00000040 /* Ignore errors when creating the node */
192: #define OP_PRECIOUS 0x00000080 /* Don't remove the target when
193: * interrupted */
194: #define OP_SILENT 0x00000100 /* Don't echo commands when executed */
1.5 espie 195: #define OP_MAKE 0x00000200 /* Target is a recursive make so its
1.1 espie 196: * commands should always be executed when
197: * it is out of date, regardless of the
198: * state of the -n or -t flags */
1.14 espie 199: #define OP_INVISIBLE 0x00001000 /* The node is invisible to its parents.
1.1 espie 200: * I.e. it doesn't show up in the parents's
1.39 ! espie 201: * local variables. Used by :: for
! 202: * supplementary nodes (cohorts). */
1.14 espie 203: #define OP_NOTMAIN 0x00002000 /* The node is exempt from normal 'main
1.1 espie 204: * target' processing in parse.c */
1.14 espie 205: #define OP_PHONY 0x00004000 /* Not a file target; run always */
206: #define OP_NOPATH 0x00008000 /* Don't search for file in the path */
207: #define OP_NODEFAULT 0x00010000 /* Special node that never needs */
1.5 espie 208: /* DEFAULT commands applied */
1.14 espie 209: #define OP_DUMMY 0x00020000 /* node was created by default, but it */
1.5 espie 210: /* does not really exist. */
1.1 espie 211: /* Attributes applied by PMake */
1.14 espie 212: #define OP_TRANSFORM 0x00040000 /* The node is a transformation rule */
213: #define OP_MEMBER 0x00080000 /* Target is a member of an archive */
1.23 espie 214: #define OP_DOUBLE 0x00100000 /* normal op with double commands */
1.14 espie 215: #define OP_ARCHV 0x00200000 /* Target is an archive construct */
216: #define OP_HAS_COMMANDS 0x00400000 /* Target has all the commands it should.
1.1 espie 217: * Used when parsing to catch multiple
218: * commands for a target */
1.14 espie 219: #define OP_DEPS_FOUND 0x00800000 /* Already processed by Suff_FindDeps */
1.7 espie 220: #define OP_RESOLVED 0x01000000 /* We looked harder already */
1.19 espie 221: #define OP_CHEAP 0x02000000 /* Assume job is not recursive */
222: #define OP_EXPENSIVE 0x04000000 /* Recursive job, don't run in parallel */
1.1 espie 223:
224: /*
225: * OP_NOP will return true if the node with the given type was not the
226: * object of a dependency operator
227: */
1.34 espie 228: #define OP_NOP(t) (((t) & OP_OPMASK) == OP_ZERO)
1.1 espie 229:
1.39 ! espie 230: #define OP_NOTARGET (OP_NOTMAIN|OP_USE|OP_TRANSFORM)
1.1 espie 231:
232:
233: #endif