Annotation of src/usr.bin/make/gnode.h, Revision 1.31
1.1 espie 1: #ifndef GNODE_H
2: #define GNODE_H
1.31 ! espie 3: /* $OpenBSD: gnode.h,v 1.30 2019/12/21 15:28:17 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: /*-
43: * The structure for an individual graph node. Each node has several
44: * pieces of data associated with it.
45: * 1) the name of the target it describes
46: * 2) the location of the target file in the file system.
1.31 ! espie 47: * 3) the type of operator used to define its sources (cf parse.c)
1.1 espie 48: * 4) whether it is involved in this invocation of make
1.31 ! espie 49: * 5) whether the target has been rebuilt
! 50: * 6) whether any of its children has been rebuilt
! 51: * 7) the number of its children that are, as yet, not built
1.1 espie 52: * 8) its modification time
53: * 9) the modification time of its youngest child (qv. make.c)
54: * 10) a list of nodes for which this is a source
55: * 11) a list of nodes on which this depends
56: * 12) a list of nodes that depend on this, as gleaned from the
57: * transformation rules.
58: * 13) a list of nodes of the same name created by the :: operator
1.31 ! espie 59: * 14) a list of predecessors nodes, result of .ORDER:
! 60: * if considered for building, they should be built before this node.
! 61: * 15) a list of successors nodes, result of .ORDER:
! 62: * if considered for building, they should be built after this node.
1.1 espie 63: * 16) a Lst of ``local'' variables that are specific to this target
64: * and this target only (qv. var.c [$@ $< $?, etc.])
65: * 17) a Lst of strings that are commands to be given to a shell
66: * to create this target.
67: */
1.5 espie 68:
1.15 espie 69: #define SPECIAL_NONE 0U
70: #define SPECIAL_PATH 21U
71: #define SPECIAL_MASK 63U
72: #define SPECIAL_TARGET 64U
73: #define SPECIAL_SOURCE 128U
1.5 espie 74: #define SPECIAL_TARGETSOURCE (SPECIAL_TARGET|SPECIAL_SOURCE)
75:
1.21 espie 76: #define SPECIAL_EXEC 4U
77: #define SPECIAL_IGNORE 5U
1.23 espie 78: #define SPECIAL_NOTHING 6U
1.21 espie 79: #define SPECIAL_INVISIBLE 8U
80: #define SPECIAL_JOIN 9U
81: #define SPECIAL_MADE 11U
82: #define SPECIAL_MAIN 12U
83: #define SPECIAL_MAKE 13U
84: #define SPECIAL_MFLAGS 14U
85: #define SPECIAL_NOTMAIN 15U
86: #define SPECIAL_NOTPARALLEL 16U
87: #define SPECIAL_OPTIONAL 18U
88: #define SPECIAL_ORDER 19U
89: #define SPECIAL_PARALLEL 20U
90: #define SPECIAL_PHONY 22U
91: #define SPECIAL_PRECIOUS 23U
92: #define SPECIAL_SILENT 25U
93: #define SPECIAL_SUFFIXES 27U
94: #define SPECIAL_USE 28U
95: #define SPECIAL_WAIT 29U
96: #define SPECIAL_NOPATH 30U
97: #define SPECIAL_ERROR 31U
98: #define SPECIAL_CHEAP 32U
99: #define SPECIAL_EXPENSIVE 33U
100:
1.1 espie 101: struct GNode_ {
1.15 espie 102: unsigned int special_op; /* special op to apply */
1.31 ! espie 103: unsigned char special; /* type of special node */
! 104: char must_make; /* true if this target needs building */
! 105: char child_rebuilt; /* true if at least one child was rebuilt,
! 106: * thus triggering timestamps changes */
! 107:
! 108: char built_status;
! 109: #define UNKNOWN 0 /* Not examined yet */
! 110: #define BUILDING 1 /* In the process of building */
! 111: #define REBUILT 2 /* Was out of date and got rebuilt */
! 112: #define UPTODATE 3 /* Was already up-to-date */
! 113: #define ERROR 4 /* Error occurred while building
! 114: * (used only in compat mode) */
! 115: #define ABORTED 5 /* Was aborted due to an error
! 116: * making an inferior */
! 117: #define NOSUCHNODE 6 /* error from run_gnode */
! 118: #define HELDBACK 7 /* Another target in the same group is
! 119: * currently building, avoid race conditions */
! 120:
1.5 espie 121: char *path; /* The full pathname of the file */
1.15 espie 122: unsigned int type; /* Its type (see the OP flags, below) */
1.5 espie 123: int order; /* Its wait weight */
124:
1.31 ! espie 125: int children_left; /* The number of children left to build */
1.29 espie 126: int in_cycle; /* cycle detection */
1.5 espie 127:
1.31 ! espie 128: struct timespec mtime; /* Node's modification time */
! 129: GNode *youngest; /* Node's youngest child */
1.5 espie 130:
1.8 espie 131: GNode *impliedsrc;
1.5 espie 132: LIST cohorts; /* Other nodes for the :: operator */
133: LIST parents; /* Nodes that depend on this one */
134: LIST children; /* Nodes on which this one depends */
1.31 ! espie 135: LIST predecessors;
! 136: LIST successors;
1.5 espie 137:
138: SymTable context; /* The local variables */
139: LIST commands; /* Creation commands */
1.23 espie 140: Suff *suffix; /* Suffix for the node (determined by
1.5 espie 141: * Suff_FindDeps and opaque to everyone
142: * but the Suff module) */
1.23 espie 143: GNode *sibling; /* equivalent targets */
144: GNode *groupling; /* target lists */
145: GNode *watched; /* the node currently building */
1.14 espie 146: /* stuff for target name equivalence */
147: char *basename; /* pointer to name stripped of path */
1.23 espie 148: GNode *next;
1.5 espie 149: char name[1]; /* The target's name */
1.20 espie 150: };
151:
152: struct command
153: {
154: Location location;
155: char string[1];
1.1 espie 156: };
157:
1.14 espie 158: #define has_been_built(gn) \
1.30 espie 159: ((gn)->built_status == REBUILT || (gn)->built_status == UPTODATE)
1.14 espie 160: #define should_have_file(gn) \
161: ((gn)->special == SPECIAL_NONE && \
162: ((gn)->type & (OP_PHONY | OP_DUMMY)) == 0)
1.1 espie 163: /*
164: * The OP_ constants are used when parsing a dependency line as a way of
165: * communicating to other parts of the program the way in which a target
166: * should be made. These constants are bitwise-OR'ed together and
167: * placed in the 'type' field of each node. Any node that has
168: * a 'type' field which satisfies the OP_NOP function was never never on
169: * the lefthand side of an operator, though it may have been on the
170: * righthand side...
171: */
172: #define OP_DEPENDS 0x00000001 /* Execution of commands depends on
173: * kids (:) */
174: #define OP_FORCE 0x00000002 /* Always execute commands (!) */
175: #define OP_DOUBLEDEP 0x00000004 /* Execution of commands depends on kids
176: * per line (::) */
1.6 espie 177: #define OP_ERROR 0x00000000
1.1 espie 178: #define OP_OPMASK (OP_DEPENDS|OP_FORCE|OP_DOUBLEDEP)
179:
180: #define OP_OPTIONAL 0x00000008 /* Don't care if the target doesn't
181: * exist and can't be created */
182: #define OP_USE 0x00000010 /* Use associated commands for parents */
183: #define OP_EXEC 0x00000020 /* Target is never out of date, but always
184: * execute commands anyway. Its time
185: * doesn't matter, so it has none...sort
186: * of */
187: #define OP_IGNORE 0x00000040 /* Ignore errors when creating the node */
188: #define OP_PRECIOUS 0x00000080 /* Don't remove the target when
189: * interrupted */
190: #define OP_SILENT 0x00000100 /* Don't echo commands when executed */
1.5 espie 191: #define OP_MAKE 0x00000200 /* Target is a recursive make so its
1.1 espie 192: * commands should always be executed when
193: * it is out of date, regardless of the
194: * state of the -n or -t flags */
195: #define OP_JOIN 0x00000400 /* Target is out-of-date only if any of its
196: * children was out-of-date */
197: #define OP_MADE 0x00000800 /* Assume the node is already made; even if
198: * it really is out of date */
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
201: * local variables. */
1.14 espie 202: #define OP_NOTMAIN 0x00002000 /* The node is exempt from normal 'main
1.1 espie 203: * target' processing in parse.c */
1.14 espie 204: #define OP_PHONY 0x00004000 /* Not a file target; run always */
205: #define OP_NOPATH 0x00008000 /* Don't search for file in the path */
206: #define OP_NODEFAULT 0x00010000 /* Special node that never needs */
1.5 espie 207: /* DEFAULT commands applied */
1.14 espie 208: #define OP_DUMMY 0x00020000 /* node was created by default, but it */
1.5 espie 209: /* does not really exist. */
1.1 espie 210: /* Attributes applied by PMake */
1.14 espie 211: #define OP_TRANSFORM 0x00040000 /* The node is a transformation rule */
212: #define OP_MEMBER 0x00080000 /* Target is a member of an archive */
1.23 espie 213: #define OP_DOUBLE 0x00100000 /* normal op with double commands */
1.14 espie 214: #define OP_ARCHV 0x00200000 /* Target is an archive construct */
215: #define OP_HAS_COMMANDS 0x00400000 /* Target has all the commands it should.
1.1 espie 216: * Used when parsing to catch multiple
217: * commands for a target */
1.14 espie 218: #define OP_DEPS_FOUND 0x00800000 /* Already processed by Suff_FindDeps */
1.7 espie 219: #define OP_RESOLVED 0x01000000 /* We looked harder already */
1.19 espie 220: #define OP_CHEAP 0x02000000 /* Assume job is not recursive */
221: #define OP_EXPENSIVE 0x04000000 /* Recursive job, don't run in parallel */
1.1 espie 222:
223: /*
224: * OP_NOP will return true if the node with the given type was not the
225: * object of a dependency operator
226: */
227: #define OP_NOP(t) (((t) & OP_OPMASK) == 0x00000000)
228:
229: #define OP_NOTARGET (OP_NOTMAIN|OP_USE|OP_EXEC|OP_TRANSFORM)
230:
231:
232: #endif