1 #ifndef GNODE_H 2 #define GNODE_H 3 /* $OpenBSD: gnode.h,v 1.28 2013/05/30 08:58:38 espie Exp $ */ 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 30 #include <sys/time.h> 31 #ifndef LIST_TYPE 32 #include "lst_t.h" 33 #endif 34 #ifndef LOCATION_TYPE 35 #include "location.h" 36 #endif 37 #ifndef SYMTABLE_H 38 #include "symtable.h" 39 #endif 40 #include <assert.h> 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. 47 * 3) the type of operator used to define its sources (qv. parse.c) 48 * 4) whether it is involved in this invocation of make 49 * 5) whether the target has been remade 50 * 6) whether any of its children has been remade 51 * 7) the number of its children that are, as yet, unmade 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 59 * 14) a list of nodes that must be made (if they're made) before 60 * this node can be, but that do no enter into the datedness of 61 * this node. 62 * 15) a list of nodes that must be made (if they're made) after 63 * this node is, but that do not depend on this node, in the 64 * normal sense. 65 * 16) a Lst of ``local'' variables that are specific to this target 66 * and this target only (qv. var.c [$@ $< $?, etc.]) 67 * 17) a Lst of strings that are commands to be given to a shell 68 * to create this target. 69 */ 70 71 #define UNKNOWN 0 72 #define BEINGMADE 1 73 #define MADE 2 74 #define UPTODATE 3 75 #define ERROR 4 76 #define ABORTED 5 77 #define CYCLE 6 78 #define ENDCYCLE 7 79 #define NOSUCHNODE 8 80 #define BUILDING 9 81 #define HELDBACK 10 82 83 #define SPECIAL_NONE 0U 84 #define SPECIAL_PATH 21U 85 #define SPECIAL_MASK 63U 86 #define SPECIAL_TARGET 64U 87 #define SPECIAL_SOURCE 128U 88 #define SPECIAL_TARGETSOURCE (SPECIAL_TARGET|SPECIAL_SOURCE) 89 90 #define SPECIAL_EXEC 4U 91 #define SPECIAL_IGNORE 5U 92 #define SPECIAL_NOTHING 6U 93 #define SPECIAL_INVISIBLE 8U 94 #define SPECIAL_JOIN 9U 95 #define SPECIAL_MADE 11U 96 #define SPECIAL_MAIN 12U 97 #define SPECIAL_MAKE 13U 98 #define SPECIAL_MFLAGS 14U 99 #define SPECIAL_NOTMAIN 15U 100 #define SPECIAL_NOTPARALLEL 16U 101 #define SPECIAL_OPTIONAL 18U 102 #define SPECIAL_ORDER 19U 103 #define SPECIAL_PARALLEL 20U 104 #define SPECIAL_PHONY 22U 105 #define SPECIAL_PRECIOUS 23U 106 #define SPECIAL_SILENT 25U 107 #define SPECIAL_SUFFIXES 27U 108 #define SPECIAL_USE 28U 109 #define SPECIAL_WAIT 29U 110 #define SPECIAL_NOPATH 30U 111 #define SPECIAL_ERROR 31U 112 #define SPECIAL_CHEAP 32U 113 #define SPECIAL_EXPENSIVE 33U 114 115 struct GNode_ { 116 unsigned int special_op; /* special op to apply */ 117 unsigned char special;/* type of special node */ 118 char must_make; /* true if this target needs to be remade */ 119 char childMade; /* true if one of this target's children was 120 * made */ 121 char built_status; /* Set to reflect the state of processing 122 * on this node: 123 * UNKNOWN - Not examined yet 124 * BEINGMADE - Target is currently being made. 125 * BUILDING - There is a job running 126 * MADE - Was out-of-date and has been made 127 * UPTODATE - Was already up-to-date 128 * ERROR - An error occurred while it was being 129 * made (used only in compat mode) 130 * ABORTED - The target was aborted due to 131 * an error making an inferior. 132 * CYCLE - Marked as potentially being part of 133 * a graph cycle. If we come back to a 134 * node marked this way, it is printed 135 * and 'built_status' is changed to ENDCYCLE. 136 * ENDCYCLE - the cycle has been completely 137 * printed. Go back and unmark all its 138 * members. 139 */ 140 char *path; /* The full pathname of the file */ 141 unsigned int type; /* Its type (see the OP flags, below) */ 142 int order; /* Its wait weight */ 143 144 int unmade; /* The number of unmade children */ 145 146 struct timespec mtime; /* Its modification time */ 147 GNode *youngest; /* Its youngest child */ 148 149 GNode *impliedsrc; 150 LIST cohorts; /* Other nodes for the :: operator */ 151 LIST parents; /* Nodes that depend on this one */ 152 LIST children; /* Nodes on which this one depends */ 153 LIST successors; /* Nodes that must be made after this one */ 154 LIST preds; /* Nodes that must be made before this one */ 155 156 SymTable context; /* The local variables */ 157 LIST commands; /* Creation commands */ 158 Suff *suffix; /* Suffix for the node (determined by 159 * Suff_FindDeps and opaque to everyone 160 * but the Suff module) */ 161 GNode *sibling; /* equivalent targets */ 162 GNode *groupling; /* target lists */ 163 GNode *watched; /* the node currently building */ 164 /* stuff for target name equivalence */ 165 char *basename; /* pointer to name stripped of path */ 166 GNode *next; 167 char name[1]; /* The target's name */ 168 }; 169 170 struct command 171 { 172 Location location; 173 char string[1]; 174 }; 175 176 #define has_been_built(gn) \ 177 ((gn)->built_status == MADE || (gn)->built_status == UPTODATE) 178 #define should_have_file(gn) \ 179 ((gn)->special == SPECIAL_NONE && \ 180 ((gn)->type & (OP_PHONY | OP_DUMMY)) == 0) 181 /* 182 * The OP_ constants are used when parsing a dependency line as a way of 183 * communicating to other parts of the program the way in which a target 184 * should be made. These constants are bitwise-OR'ed together and 185 * placed in the 'type' field of each node. Any node that has 186 * a 'type' field which satisfies the OP_NOP function was never never on 187 * the lefthand side of an operator, though it may have been on the 188 * righthand side... 189 */ 190 #define OP_DEPENDS 0x00000001 /* Execution of commands depends on 191 * kids (:) */ 192 #define OP_FORCE 0x00000002 /* Always execute commands (!) */ 193 #define OP_DOUBLEDEP 0x00000004 /* Execution of commands depends on kids 194 * per line (::) */ 195 #define OP_ERROR 0x00000000 196 #define OP_OPMASK (OP_DEPENDS|OP_FORCE|OP_DOUBLEDEP) 197 198 #define OP_OPTIONAL 0x00000008 /* Don't care if the target doesn't 199 * exist and can't be created */ 200 #define OP_USE 0x00000010 /* Use associated commands for parents */ 201 #define OP_EXEC 0x00000020 /* Target is never out of date, but always 202 * execute commands anyway. Its time 203 * doesn't matter, so it has none...sort 204 * of */ 205 #define OP_IGNORE 0x00000040 /* Ignore errors when creating the node */ 206 #define OP_PRECIOUS 0x00000080 /* Don't remove the target when 207 * interrupted */ 208 #define OP_SILENT 0x00000100 /* Don't echo commands when executed */ 209 #define OP_MAKE 0x00000200 /* Target is a recursive make so its 210 * commands should always be executed when 211 * it is out of date, regardless of the 212 * state of the -n or -t flags */ 213 #define OP_JOIN 0x00000400 /* Target is out-of-date only if any of its 214 * children was out-of-date */ 215 #define OP_MADE 0x00000800 /* Assume the node is already made; even if 216 * it really is out of date */ 217 #define OP_INVISIBLE 0x00001000 /* The node is invisible to its parents. 218 * I.e. it doesn't show up in the parents's 219 * local variables. */ 220 #define OP_NOTMAIN 0x00002000 /* The node is exempt from normal 'main 221 * target' processing in parse.c */ 222 #define OP_PHONY 0x00004000 /* Not a file target; run always */ 223 #define OP_NOPATH 0x00008000 /* Don't search for file in the path */ 224 #define OP_NODEFAULT 0x00010000 /* Special node that never needs */ 225 /* DEFAULT commands applied */ 226 #define OP_DUMMY 0x00020000 /* node was created by default, but it */ 227 /* does not really exist. */ 228 /* Attributes applied by PMake */ 229 #define OP_TRANSFORM 0x00040000 /* The node is a transformation rule */ 230 #define OP_MEMBER 0x00080000 /* Target is a member of an archive */ 231 #define OP_DOUBLE 0x00100000 /* normal op with double commands */ 232 #define OP_ARCHV 0x00200000 /* Target is an archive construct */ 233 #define OP_HAS_COMMANDS 0x00400000 /* Target has all the commands it should. 234 * Used when parsing to catch multiple 235 * commands for a target */ 236 #define OP_DEPS_FOUND 0x00800000 /* Already processed by Suff_FindDeps */ 237 #define OP_RESOLVED 0x01000000 /* We looked harder already */ 238 #define OP_CHEAP 0x02000000 /* Assume job is not recursive */ 239 #define OP_EXPENSIVE 0x04000000 /* Recursive job, don't run in parallel */ 240 241 /* 242 * OP_NOP will return true if the node with the given type was not the 243 * object of a dependency operator 244 */ 245 #define OP_NOP(t) (((t) & OP_OPMASK) == 0x00000000) 246 247 #define OP_NOTARGET (OP_NOTMAIN|OP_USE|OP_EXEC|OP_TRANSFORM) 248 249 250 #endif 251