1 /*
2  * Copyright 1993, 1995 Christopher Seiwald.
3  *
4  * This file is part of Jam - see jam.c for Copyright information.
5  */
6 
7 /*
8  * rules.h -  targets, rules, and related information
9  *
10  * This file describes the structures holding the targets, rules, and
11  * related information accumulated by interpreting the statements
12  * of the jam files.
13  *
14  * The following are defined:
15  *
16  *	RULE - a generic jam rule, the product of RULE and ACTIONS
17  *	ACTIONS - a chain of ACTIONs
18  *	ACTION - a RULE instance with targets and sources
19  *	SETTINGS - variables to set when executing a TARGET's ACTIONS
20  *	TARGETS - a chain of TARGETs
21  *	TARGET - a file or "thing" that can be built
22  *
23  * 04/11/94 (seiwald) - Combined deps & headers into deps[2] in TARGET.
24  * 04/12/94 (seiwald) - actionlist() now just appends a single action.
25  * 06/01/94 (seiwald) - new 'actions existing' does existing sources
26  * 12/20/94 (seiwald) - NOTIME renamed NOTFILE.
27  * 01/19/95 (seiwald) - split DONTKNOW into CANTFIND/CANTMAKE.
28  * 02/02/95 (seiwald) - new LEAVES modifier on targets.
29  * 02/14/95 (seiwald) - new NOUPDATE modifier on targets.
30  * 02/28/02 (seiwald) - merge EXEC_xxx flags in with RULE_xxx
31  * 06/21/02 (seiwald) - support for named parameters
32  * 07/17/02 (seiwald) - TEMPORARY sources for headers now get built
33  * 11/04/02 (seiwald) - const-ing for string literals
34  * 12/03/02 (seiwald) - fix odd includes support by grafting them onto depends
35  * 12/17/02 (seiwald) - new copysettings() to protect target-specific vars
36  * 01/14/03 (seiwald) - fix includes fix with new internal includes TARGET
37  */
38 
39 typedef struct _rule RULE;
40 typedef struct _target TARGET;
41 typedef struct _targets TARGETS;
42 typedef struct _action ACTION;
43 typedef struct _actions ACTIONS;
44 typedef struct _settings SETTINGS ;
45 
46 /* RULE - a generic jam rule, the product of RULE and ACTIONS */
47 
48 struct _rule {
49 	const char	*name;
50 	PARSE		*procedure;	/* parse tree from RULE */
51 	const char	*actions;	/* command string from ACTIONS */
52 	LIST		*bindlist;	/* variable to bind for actions */
53 	LIST		*params;	/* bind args to local vars */
54 	int		flags;		/* modifiers on ACTIONS */
55 
56 # define	RULE_UPDATED	0x01	/* $(>) is updated sources only */
57 # define	RULE_TOGETHER	0x02	/* combine actions on single target */
58 # define	RULE_IGNORE	0x04	/* ignore return status of executes */
59 # define	RULE_QUIETLY	0x08	/* don't mention it unless verbose */
60 # define	RULE_PIECEMEAL	0x10	/* split exec so each $(>) is small */
61 # define	RULE_EXISTING	0x20	/* $(>) is pre-exisitng sources only */
62 # define	RULE_MAXLINE	0x40	/* cmd specific maxline (last) */
63 
64 } ;
65 
66 /* ACTIONS - a chain of ACTIONs */
67 
68 struct _actions {
69 	ACTIONS		*next;
70 	ACTIONS		*tail;		/* valid only for head */
71 	ACTION		*action;
72 } ;
73 
74 /* ACTION - a RULE instance with targets and sources */
75 
76 struct _action {
77 	RULE		*rule;
78 	TARGETS		*targets;
79 	TARGETS		*sources;	/* aka $(>) */
80 	char		running;	/* has been started */
81 	char		status;		/* see TARGET status */
82 } ;
83 
84 /* SETTINGS - variables to set when executing a TARGET's ACTIONS */
85 
86 struct _settings {
87 	SETTINGS 	*next;
88 	const char	*symbol;	/* symbol name for var_set() */
89 	LIST		*value;		/* symbol value for var_set() */
90 } ;
91 
92 /* TARGETS - a chain of TARGETs */
93 
94 struct _targets {
95 	TARGETS		*next;
96 	TARGETS		*tail;		/* valid only for head */
97 	TARGET		*target;
98 } ;
99 
100 /* TARGET - a file or "thing" that can be built */
101 
102 struct _target {
103 	const char	*name;
104 	const char	*boundname;	/* if search() relocates target */
105 	ACTIONS		*actions;	/* rules to execute, if any */
106 	SETTINGS 	*settings;	/* variables to define */
107 
108 	char		flags;		/* status info */
109 
110 # define 	T_FLAG_TEMP 	0x01	/* TEMPORARY applied */
111 # define 	T_FLAG_NOCARE 	0x02	/* NOCARE applied */
112 # define 	T_FLAG_NOTFILE 	0x04	/* NOTFILE applied */
113 # define	T_FLAG_TOUCHED	0x08	/* ALWAYS applied or -t target */
114 # define	T_FLAG_LEAVES	0x10	/* LEAVES applied */
115 # define	T_FLAG_NOUPDATE	0x20	/* NOUPDATE applied */
116 # define	T_FLAG_INTERNAL	0x40	/* internal INCLUDES node */
117 
118 	char		binding;	/* how target relates to real file */
119 
120 # define 	T_BIND_UNBOUND	0	/* a disembodied name */
121 # define 	T_BIND_MISSING	1	/* couldn't find real file */
122 # define 	T_BIND_PARENTS	2	/* using parent's timestamp */
123 # define 	T_BIND_EXISTS	3	/* real file, timestamp valid */
124 
125 	TARGETS		*depends;	/* dependencies */
126 	TARGET		*includes;	/* includes */
127 
128 	time_t		time;		/* update time */
129 	time_t		leaf;		/* update time of leaf sources */
130 	char		fate;		/* make0()'s diagnosis */
131 
132 # define 	T_FATE_INIT	0	/* nothing done to target */
133 # define 	T_FATE_MAKING	1	/* make0(target) on stack */
134 
135 # define 	T_FATE_STABLE	2	/* target didn't need updating */
136 # define	T_FATE_NEWER	3	/* target newer than parent */
137 
138 # define	T_FATE_SPOIL	4	/* >= SPOIL rebuilds parents */
139 # define 	T_FATE_ISTMP	4	/* unneeded temp target oddly present */
140 
141 # define	T_FATE_BUILD	5	/* >= BUILD rebuilds target */
142 # define	T_FATE_TOUCHED	5	/* manually touched with -t */
143 # define	T_FATE_MISSING	6	/* is missing, needs updating */
144 # define	T_FATE_NEEDTMP	7	/* missing temp that must be rebuild */
145 # define 	T_FATE_OUTDATED	8	/* is out of date, needs updating */
146 # define 	T_FATE_UPDATE	9	/* deps updated, needs updating */
147 
148 # define 	T_FATE_BROKEN	10	/* >= BROKEN ruins parents */
149 # define 	T_FATE_CANTFIND	10	/* no rules to make missing target */
150 # define 	T_FATE_CANTMAKE	11	/* can't find dependents */
151 
152 	char		progress;	/* tracks make1() progress */
153 
154 # define	T_MAKE_INIT	0	/* make1(target) not yet called */
155 # define	T_MAKE_ONSTACK	1	/* make1(target) on stack */
156 # define	T_MAKE_ACTIVE	2	/* make1(target) in make1b() */
157 # define	T_MAKE_RUNNING	3	/* make1(target) running commands */
158 # define	T_MAKE_DONE	4	/* make1(target) done */
159 
160 	char		status;		/* execcmd() result */
161 
162 	int		asynccnt;	/* child deps outstanding */
163 	TARGETS		*parents;	/* used by make1() for completion */
164 	char		*cmds;		/* type-punned command list */
165 } ;
166 
167 RULE 	*bindrule( const char *rulename );
168 TARGET *bindtarget( const char *targetname );
169 TARGET *copytarget( const TARGET *t );
170 void 	touchtarget( const char *t );
171 TARGETS *targetlist( TARGETS *chain, LIST  *targets );
172 TARGETS *targetentry( TARGETS *chain, TARGET *target );
173 TARGETS *targetchain( TARGETS *chain, TARGETS *targets );
174 ACTIONS *actionlist( ACTIONS *chain, ACTION *action );
175 SETTINGS *addsettings( SETTINGS *v, int setflag, const char *sym, LIST *val );
176 SETTINGS *copysettings( SETTINGS *v );
177 void 	pushsettings( SETTINGS *v );
178 void 	popsettings( SETTINGS *v );
179 void 	freesettings( SETTINGS *v );
180 void	donerules();
181