2 * Copyright 1993, 1995 Christopher Seiwald.
4 * This file is part of Jam - see jam.c for Copyright information.
8 * Copyright 2001-2004 David Abrahams.
9 * Distributed under the Boost Software License, Version 1.0.
10 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
13 #ifndef RULES_DWA_20011020_H
14 #define RULES_DWA_20011020_H
22 * rules.h - targets, rules, and related information
24 * This file describes the structures holding the targets, rules, and
25 * related information accumulated by interpreting the statements
28 * The following are defined:
30 * RULE - a generic jam rule, the product of RULE and ACTIONS.
31 * ACTIONS - a chain of ACTIONs.
32 * ACTION - a RULE instance with targets and sources.
33 * SETTINGS - variables to set when executing a TARGET's ACTIONS.
34 * TARGETS - a chain of TARGETs.
35 * TARGET - an entity (e.g. a file) that can be built.
37 * 04/11/94 (seiwald) - Combined deps & headers into deps[2] in TARGET.
38 * 04/12/94 (seiwald) - actionlist() now just appends a single action.
39 * 06/01/94 (seiwald) - new 'actions existing' does existing sources
40 * 12/20/94 (seiwald) - NOTIME renamed NOTFILE.
41 * 01/19/95 (seiwald) - split DONTKNOW into CANTFIND/CANTMAKE.
42 * 02/02/95 (seiwald) - new LEAVES modifier on targets.
43 * 02/14/95 (seiwald) - new NOUPDATE modifier on targets.
46 typedef struct _rule RULE;
47 typedef struct _target TARGET;
48 typedef struct _targets TARGETS;
49 typedef struct _action ACTION;
50 typedef struct _actions ACTIONS;
51 typedef struct _settings SETTINGS ;
53 /* RULE - a generic jam rule, the product of RULE and ACTIONS. */
55 /* A rule's argument list. */
62 /* Build actions corresponding to a rule. */
66 char * command; /* command string from ACTIONS */
68 int flags; /* modifiers on ACTIONS */
70 #define RULE_NEWSRCS 0x01 /* $(>) is updated sources only */
71 #define RULE_TOGETHER 0x02 /* combine actions on single target */
72 #define RULE_IGNORE 0x04 /* ignore return status of executes */
73 #define RULE_QUIETLY 0x08 /* do not mention it unless verbose */
74 #define RULE_PIECEMEAL 0x10 /* split exec so each $(>) is small */
75 #define RULE_EXISTING 0x20 /* $(>) is pre-exisitng sources only */
78 typedef struct rule_actions rule_actions;
79 typedef struct argument_list argument_list;
84 PARSE * procedure; /* parse tree from RULE */
85 argument_list * arguments; /* argument checking info, or NULL for unchecked
87 rule_actions * actions; /* build actions, or NULL for no actions */
88 module_t * module; /* module in which this rule is executed */
89 int exported; /* nonzero if this rule is supposed to appear in
90 * the global module and be automatically
91 * imported into other modules
94 PyObject * python_function;
98 /* ACTIONS - a chain of ACTIONs. */
102 ACTIONS * tail; /* valid only for head */
106 /* ACTION - a RULE instance with targets and sources. */
111 TARGETS * sources; /* aka $(>) */
112 char running; /* has been started */
113 char status; /* see TARGET status */
116 /* SETTINGS - variables to set when executing a TARGET's ACTIONS. */
120 char * symbol; /* symbol name for var_set() */
121 LIST * value; /* symbol value for var_set() */
125 /* TARGETS - a chain of TARGETs. */
129 TARGETS * tail; /* valid only for head */
133 /* TARGET - an entity (e.g. a file) that can be built. */
137 char * boundname; /* if search() relocates target */
138 ACTIONS * actions; /* rules to execute, if any */
139 SETTINGS * settings; /* variables to define */
141 short flags; /* status info */
143 #define T_FLAG_TEMP 0x0001 /* TEMPORARY applied */
144 #define T_FLAG_NOCARE 0x0002 /* NOCARE applied */
145 #define T_FLAG_NOTFILE 0x0004 /* NOTFILE applied */
146 #define T_FLAG_TOUCHED 0x0008 /* ALWAYS applied or -t target */
147 #define T_FLAG_LEAVES 0x0010 /* LEAVES applied */
148 #define T_FLAG_NOUPDATE 0x0020 /* NOUPDATE applied */
149 #define T_FLAG_VISITED 0x0040 /* CWM: Used in debugging */
151 /* This flag has been added to support a new built-in rule named "RMBAD". It is
152 * used to force removal of outdated targets whose dependencies fail to build.
154 #define T_FLAG_RMOLD 0x0080 /* RMBAD applied */
156 /* This flag was added to support a new built-in rule named "FAIL_EXPECTED" used
157 * to indicate that the result of running a given action should be inverted,
158 * i.e. ok <=> fail. This is useful for launching certain test runs from a
161 #define T_FLAG_FAIL_EXPECTED 0x0100 /* FAIL_EXPECTED applied */
163 #define T_FLAG_INTERNAL 0x0200 /* internal INCLUDES node */
165 /* Indicates that the target must be a file. This prevents matching non-files,
166 * like directories, when a target is searched.
168 #define T_FLAG_ISFILE 0x0400
170 #define T_FLAG_PRECIOUS 0x0800
172 char binding; /* how target relates to a real file or
176 #define T_BIND_UNBOUND 0 /* a disembodied name */
177 #define T_BIND_MISSING 1 /* could not find real file */
178 #define T_BIND_PARENTS 2 /* using parent's timestamp */
179 #define T_BIND_EXISTS 3 /* real file, timestamp valid */
181 TARGETS * depends; /* dependencies */
182 TARGETS * dependants; /* the inverse of dependencies */
183 TARGETS * rebuilds; /* targets that should be force-rebuilt
184 * whenever this one is
186 TARGET * includes; /* internal includes node */
187 TARGET * original_target; /* original_target->includes = this */
190 time_t time; /* update time */
191 time_t leaf; /* update time of leaf sources */
193 char fate; /* make0()'s diagnosis */
195 #define T_FATE_INIT 0 /* nothing done to target */
196 #define T_FATE_MAKING 1 /* make0(target) on stack */
198 #define T_FATE_STABLE 2 /* target did not need updating */
199 #define T_FATE_NEWER 3 /* target newer than parent */
201 #define T_FATE_SPOIL 4 /* >= SPOIL rebuilds parents */
202 #define T_FATE_ISTMP 4 /* unneeded temp target oddly present */
204 #define T_FATE_BUILD 5 /* >= BUILD rebuilds target */
205 #define T_FATE_TOUCHED 5 /* manually touched with -t */
206 #define T_FATE_REBUILD 6
207 #define T_FATE_MISSING 7 /* is missing, needs updating */
208 #define T_FATE_NEEDTMP 8 /* missing temp that must be rebuild */
209 #define T_FATE_OUTDATED 9 /* is out of date, needs updating */
210 #define T_FATE_UPDATE 10 /* deps updated, needs updating */
212 #define T_FATE_BROKEN 11 /* >= BROKEN ruins parents */
213 #define T_FATE_CANTFIND 11 /* no rules to make missing target */
214 #define T_FATE_CANTMAKE 12 /* can not find dependencies */
216 char progress; /* tracks make1() progress */
218 #define T_MAKE_INIT 0 /* make1(target) not yet called */
219 #define T_MAKE_ONSTACK 1 /* make1(target) on stack */
220 #define T_MAKE_ACTIVE 2 /* make1(target) in make1b() */
221 #define T_MAKE_RUNNING 3 /* make1(target) running commands */
222 #define T_MAKE_DONE 4 /* make1(target) done */
225 #define T_MAKE_SEMAPHORE 5 /* Special target type for semaphores */
229 TARGET * semaphore; /* used in serialization */
232 char status; /* exec_cmd() result */
234 int asynccnt; /* child deps outstanding */
235 TARGETS * parents; /* used by make1() for completion */
236 char * cmds; /* type-punned command list */
242 /* Action related functions. */
243 ACTIONS * actionlist ( ACTIONS *, ACTION * );
244 void freeactions ( ACTIONS * );
245 SETTINGS * addsettings ( SETTINGS *, int flag, char * symbol, LIST * value );
246 void pushsettings ( SETTINGS * );
247 void popsettings ( SETTINGS * );
248 SETTINGS * copysettings ( SETTINGS * );
249 void freesettings ( SETTINGS * );
250 void actions_refer( rule_actions * );
251 void actions_free ( rule_actions * );
253 /* Argument list related functions. */
254 void args_free ( argument_list * );
255 argument_list * args_new ();
256 void args_refer( argument_list * );
258 /* Rule related functions. */
259 RULE * bindrule ( char * rulename, module_t * );
260 RULE * import_rule ( RULE * source, module_t *, char * name );
261 RULE * new_rule_body ( module_t *, char * rulename, argument_list *, PARSE * procedure, int exprt );
262 RULE * new_rule_actions( module_t *, char * rulename, char * command, LIST * bindlist, int flags );
263 void rule_free ( RULE * );
265 /* Target related functions. */
266 void bind_explicitly_located_targets();
267 TARGET * bindtarget ( char const * target_name );
268 TARGET * copytarget ( TARGET const * t );
269 void freetargets ( TARGETS * );
270 TARGET * search_for_target ( char * name, LIST * search_path );
271 TARGETS * targetchain ( TARGETS * chain, TARGETS * );
272 TARGETS * targetentry ( TARGETS * chain, TARGET * );
273 void target_include ( TARGET * including, TARGET * included );
274 TARGETS * targetlist ( TARGETS * chain, LIST * target_names );
275 void touch_target ( char * t );
277 /* Final module cleanup. */