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