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 "function.h"
33 #include "modules.h"
34 #include "timestamp.h"
35 
36 
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 ;
43 
44 /* RULE - a generic jam rule, the product of RULE and ACTIONS. */
45 
46 /* Build actions corresponding to a rule. */
47 struct rule_actions
48 {
49     int        reference_count;
50     FUNCTION * command;          /* command string from ACTIONS */
51     LIST     * bindlist;
52     int        flags;            /* modifiers on ACTIONS */
53 
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 */
60 };
61 
62 typedef struct rule_actions rule_actions;
63 typedef struct argument_list argument_list;
64 
65 struct _rule
66 {
67     OBJECT        * name;
68     FUNCTION      * procedure;
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
74                                  */
75 };
76 
77 /* ACTIONS - a chain of ACTIONs. */
78 struct _actions
79 {
80     ACTIONS * next;
81     ACTIONS * tail;           /* valid only for head */
82     ACTION  * action;
83 };
84 
85 /* ACTION - a RULE instance with targets and sources. */
86 struct _action
87 {
88     RULE    * rule;
89     TARGETS * targets;
90     TARGETS * sources;        /* aka $(>) */
91     char      running;        /* has been started */
92 #define A_INIT           0
93 #define A_RUNNING_NOEXEC 1
94 #define A_RUNNING        2
95     int       refs;
96 
97     /* WARNING: These variables are used to pass state required by make1cmds and
98      * are not valid anywhere else.
99      */
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 */
102 };
103 
104 /* SETTINGS - variables to set when executing a TARGET's ACTIONS. */
105 struct _settings
106 {
107     SETTINGS * next;
108     OBJECT   * symbol;        /* symbol name for var_set() */
109     LIST     * value;         /* symbol value for var_set() */
110 };
111 
112 /* TARGETS - a chain of TARGETs. */
113 struct _targets
114 {
115     TARGETS * next;
116     TARGETS * tail;           /* valid only for head */
117     TARGET  * target;
118 };
119 
120 /* TARGET - an entity (e.g. a file) that can be built. */
121 struct _target
122 {
123     OBJECT   * name;
124     OBJECT   * boundname;             /* if search() relocates target */
125     ACTIONS  * actions;               /* rules to execute, if any */
126     SETTINGS * settings;              /* variables to define */
127 
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
132                                        */
133     TARGET   * includes;              /* internal includes node */
134 
135     timestamp  time;                  /* update time */
136     timestamp  leaf;                  /* update time of leaf sources */
137 
138     short      flags;                 /* status info */
139 
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 */
147 
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.
150  */
151 #define T_FLAG_RMOLD          0x0080  /* RMBAD applied */
152 
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.
156  */
157 #define T_FLAG_FAIL_EXPECTED  0x0100  /* FAIL_EXPECTED applied */
158 
159 #define T_FLAG_INTERNAL       0x0200  /* internal INCLUDES node */
160 
161 /* Indicates that the target must be a file. Prevents matching non-files, like
162  * directories, when a target is searched.
163  */
164 #define T_FLAG_ISFILE         0x0400
165 
166 #define T_FLAG_PRECIOUS       0x0800
167 
168     char       binding;               /* how target relates to a real file or
169                                        * folder
170                                        */
171 
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 */
176 
177     char       fate;                  /* make0()'s diagnosis */
178 
179 #define T_FATE_INIT           0       /* nothing done to target */
180 #define T_FATE_MAKING         1       /* make0(target) on stack */
181 
182 #define T_FATE_STABLE         2       /* target did not need updating */
183 #define T_FATE_NEWER          3       /* target newer than parent */
184 
185 #define T_FATE_SPOIL          4       /* >= SPOIL rebuilds parents */
186 #define T_FATE_ISTMP          4       /* unneeded temp target oddly present */
187 
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 */
195 
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 */
199 
200     char       progress;              /* tracks make1() progress */
201 
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 */
208 
209 #ifdef OPT_SEMAPHORE
210     #define T_MAKE_SEMAPHORE  5       /* Special target type for semaphores */
211 #endif
212 
213     char       status;                /* exec_cmd() result */
214 
215 #ifdef OPT_SEMAPHORE
216     TARGET   * semaphore;             /* used in serialization */
217 #endif
218 
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
222                                        */
223     TARGET   * rescanning;            /* used by make0 to mark visited targets
224                                        * when rescanning
225                                        */
226     int        depth;                 /* The depth of the target in the make0
227                                        * stack.
228                                        */
229     char     * cmds;                  /* type-punned command list */
230 
231     char const * failed;
232 };
233 
234 
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 * );
246 
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 * );
254 
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 * );
269 
270 /* Final module cleanup. */
271 void rules_done();
272 
273 #endif
274