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)
14 * rules.h - targets, rules, and related information
16 * This file describes the structures holding the targets, rules, and related
17 * information accumulated by interpreting the statements of the jam files.
19 * The following are defined:
21 * RULE - a generic jam rule, the product of RULE and ACTIONS.
22 * ACTIONS - a chain of ACTIONs.
23 * ACTION - a RULE instance with targets and sources.
24 * SETTINGS - variables to set when executing a TARGET's ACTIONS.
25 * TARGETS - a chain of TARGETs.
26 * TARGET - an entity (e.g. a file) that can be built.
29 #ifndef RULES_DWA_20011020_H
30 #define RULES_DWA_20011020_H
34 #include "timestamp.h"
37 typedef struct _rule RULE
;
38 typedef struct _target TARGET
;
39 typedef struct _targets TARGETS
;
40 typedef struct _action ACTION
;
41 typedef struct _actions ACTIONS
;
42 typedef struct _settings SETTINGS
;
44 /* RULE - a generic jam rule, the product of RULE and ACTIONS. */
46 /* Build actions corresponding to a rule. */
50 FUNCTION
* command
; /* command string from ACTIONS */
52 int flags
; /* modifiers on ACTIONS */
54 #define RULE_NEWSRCS 0x01 /* $(>) is updated sources only */
55 #define RULE_TOGETHER 0x02 /* combine actions on single target */
56 #define RULE_IGNORE 0x04 /* ignore return status of executes */
57 #define RULE_QUIETLY 0x08 /* do not mention it unless verbose */
58 #define RULE_PIECEMEAL 0x10 /* split exec so each $(>) is small */
59 #define RULE_EXISTING 0x20 /* $(>) is pre-exisitng sources only */
62 typedef struct rule_actions rule_actions
;
63 typedef struct argument_list argument_list
;
69 rule_actions
* actions
; /* build actions, or NULL for no actions */
70 module_t
* module
; /* module in which this rule is executed */
71 int exported
; /* nonzero if this rule is supposed to appear in
72 * the global module and be automatically
73 * imported into other modules
77 /* ACTIONS - a chain of ACTIONs. */
81 ACTIONS
* tail
; /* valid only for head */
85 /* ACTION - a RULE instance with targets and sources. */
90 TARGETS
* sources
; /* aka $(>) */
91 char running
; /* has been started */
93 #define A_RUNNING_NOEXEC 1
97 /* WARNING: These variables are used to pass state required by make1cmds and
98 * are not valid anywhere else.
100 void * first_cmd
; /* Pointer to the first CMD created by this action */
101 void * last_cmd
; /* Pointer to the last CMD created by this action */
104 /* SETTINGS - variables to set when executing a TARGET's ACTIONS. */
108 OBJECT
* symbol
; /* symbol name for var_set() */
109 LIST
* value
; /* symbol value for var_set() */
112 /* TARGETS - a chain of TARGETs. */
116 TARGETS
* tail
; /* valid only for head */
120 /* TARGET - an entity (e.g. a file) that can be built. */
124 OBJECT
* boundname
; /* if search() relocates target */
125 ACTIONS
* actions
; /* rules to execute, if any */
126 SETTINGS
* settings
; /* variables to define */
128 TARGETS
* depends
; /* dependencies */
129 TARGETS
* dependants
; /* the inverse of dependencies */
130 TARGETS
* rebuilds
; /* targets that should be force-rebuilt
131 * whenever this one is
133 TARGET
* includes
; /* internal includes node */
135 timestamp time
; /* update time */
136 timestamp leaf
; /* update time of leaf sources */
138 short flags
; /* status info */
140 #define T_FLAG_TEMP 0x0001 /* TEMPORARY applied */
141 #define T_FLAG_NOCARE 0x0002 /* NOCARE applied */
142 #define T_FLAG_NOTFILE 0x0004 /* NOTFILE applied */
143 #define T_FLAG_TOUCHED 0x0008 /* ALWAYS applied or -t target */
144 #define T_FLAG_LEAVES 0x0010 /* LEAVES applied */
145 #define T_FLAG_NOUPDATE 0x0020 /* NOUPDATE applied */
146 #define T_FLAG_VISITED 0x0040 /* CWM: Used in debugging */
148 /* This flag has been added to support a new built-in rule named "RMBAD". It is
149 * used to force removal of outdated targets whose dependencies fail to build.
151 #define T_FLAG_RMOLD 0x0080 /* RMBAD applied */
153 /* This flag was added to support a new built-in rule named "FAIL_EXPECTED" used
154 * to indicate that the result of running a given action should be inverted,
155 * i.e. ok <=> fail. Useful for launching certain test runs from a Jamfile.
157 #define T_FLAG_FAIL_EXPECTED 0x0100 /* FAIL_EXPECTED applied */
159 #define T_FLAG_INTERNAL 0x0200 /* internal INCLUDES node */
161 /* Indicates that the target must be a file. Prevents matching non-files, like
162 * directories, when a target is searched.
164 #define T_FLAG_ISFILE 0x0400
166 #define T_FLAG_PRECIOUS 0x0800
168 char binding
; /* how target relates to a real file or
172 #define T_BIND_UNBOUND 0 /* a disembodied name */
173 #define T_BIND_MISSING 1 /* could not find real file */
174 #define T_BIND_PARENTS 2 /* using parent's timestamp */
175 #define T_BIND_EXISTS 3 /* real file, timestamp valid */
177 char fate
; /* make0()'s diagnosis */
179 #define T_FATE_INIT 0 /* nothing done to target */
180 #define T_FATE_MAKING 1 /* make0(target) on stack */
182 #define T_FATE_STABLE 2 /* target did not need updating */
183 #define T_FATE_NEWER 3 /* target newer than parent */
185 #define T_FATE_SPOIL 4 /* >= SPOIL rebuilds parents */
186 #define T_FATE_ISTMP 4 /* unneeded temp target oddly present */
188 #define T_FATE_BUILD 5 /* >= BUILD rebuilds target */
189 #define T_FATE_TOUCHED 5 /* manually touched with -t */
190 #define T_FATE_REBUILD 6
191 #define T_FATE_MISSING 7 /* is missing, needs updating */
192 #define T_FATE_NEEDTMP 8 /* missing temp that must be rebuild */
193 #define T_FATE_OUTDATED 9 /* is out of date, needs updating */
194 #define T_FATE_UPDATE 10 /* deps updated, needs updating */
196 #define T_FATE_BROKEN 11 /* >= BROKEN ruins parents */
197 #define T_FATE_CANTFIND 11 /* no rules to make missing target */
198 #define T_FATE_CANTMAKE 12 /* can not find dependencies */
200 char progress
; /* tracks make1() progress */
202 #define T_MAKE_INIT 0 /* make1(target) not yet called */
203 #define T_MAKE_ONSTACK 1 /* make1(target) on stack */
204 #define T_MAKE_ACTIVE 2 /* make1(target) in make1b() */
205 #define T_MAKE_RUNNING 3 /* make1(target) running commands */
206 #define T_MAKE_DONE 4 /* make1(target) done */
207 #define T_MAKE_NOEXEC_DONE 5 /* make1(target) done with -n in effect */
210 #define T_MAKE_SEMAPHORE 5 /* Special target type for semaphores */
213 char status
; /* exec_cmd() result */
216 TARGET
* semaphore
; /* used in serialization */
219 int asynccnt
; /* child deps outstanding */
220 TARGETS
* parents
; /* used by make1() for completion */
221 TARGET
* scc_root
; /* used by make to resolve cyclic includes
223 TARGET
* rescanning
; /* used by make0 to mark visited targets
226 int depth
; /* The depth of the target in the make0
229 char * cmds
; /* type-punned command list */
235 /* Action related functions. */
236 void action_free ( ACTION
* );
237 ACTIONS
* actionlist ( ACTIONS
*, ACTION
* );
238 void freeactions ( ACTIONS
* );
239 SETTINGS
* addsettings ( SETTINGS
*, int flag
, OBJECT
* symbol
, LIST
* value
);
240 void pushsettings ( module_t
*, SETTINGS
* );
241 void popsettings ( module_t
*, SETTINGS
* );
242 SETTINGS
* copysettings ( SETTINGS
* );
243 void freesettings ( SETTINGS
* );
244 void actions_refer( rule_actions
* );
245 void actions_free ( rule_actions
* );
247 /* Rule related functions. */
248 RULE
* bindrule ( OBJECT
* rulename
, module_t
* );
249 RULE
* import_rule ( RULE
* source
, module_t
*, OBJECT
* name
);
250 void rule_localize ( RULE
* rule
, module_t
* module
);
251 RULE
* new_rule_body ( module_t
*, OBJECT
* rulename
, FUNCTION
* func
, int exprt
);
252 RULE
* new_rule_actions( module_t
*, OBJECT
* rulename
, FUNCTION
* command
, LIST
* bindlist
, int flags
);
253 void rule_free ( RULE
* );
255 /* Target related functions. */
256 void bind_explicitly_located_targets();
257 TARGET
* bindtarget ( OBJECT
* const );
258 void freetargets ( TARGETS
* );
259 TARGETS
* targetchain ( TARGETS
*, TARGETS
* );
260 TARGETS
* targetentry ( TARGETS
*, TARGET
* );
261 void target_include ( TARGET
* const including
,
262 TARGET
* const included
);
263 void target_include_many ( TARGET
* const including
,
264 LIST
* const included_names
);
265 TARGETS
* targetlist ( TARGETS
*, LIST
* target_names
);
266 void touch_target ( OBJECT
* const );
267 void clear_includes ( TARGET
* );
268 TARGET
* target_scc ( TARGET
* );
270 /* Final module cleanup. */