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# ifdef OPT_RULE_PROFILING_EXT
40# include <stdint.h>
41# endif
42
43typedef struct _rule RULE;
44typedef struct _target TARGET;
45typedef struct _targets TARGETS;
46typedef struct _action ACTION;
47typedef struct _actions ACTIONS;
48typedef struct _settings SETTINGS ;
49
50/* RULE - a generic jam rule, the product of RULE and ACTIONS */
51
52struct _rule {
53	const char	*name;
54	PARSE		*procedure;	/* parse tree from RULE */
55	const char	*actions;	/* command string from ACTIONS */
56	LIST		*bindlist;	/* variable to bind for actions */
57	LIST		*params;	/* bind args to local vars */
58	int		flags;		/* modifiers on ACTIONS */
59
60# ifdef OPT_RULE_PROFILING_EXT
61	int			invocations;
62	int64_t		invocation_time;
63	RULE		*next_profiling_rule;
64# endif
65
66# define	RULE_UPDATED	0x01	/* $(>) is updated sources only */
67# define	RULE_TOGETHER	0x02	/* combine actions on single target */
68# define	RULE_IGNORE	0x04	/* ignore return status of executes */
69# define	RULE_QUIETLY	0x08	/* don't mention it unless verbose */
70# define	RULE_PIECEMEAL	0x10	/* split exec so each $(>) is small */
71# define	RULE_EXISTING	0x20	/* $(>) is pre-exisitng sources only */
72# define	RULE_MAXLINE	0x40	/* cmd specific maxline (last) */
73
74} ;
75
76/* ACTIONS - a chain of ACTIONs */
77
78struct _actions {
79	ACTIONS		*next;
80	ACTIONS		*tail;		/* valid only for head */
81	ACTION		*action;
82} ;
83
84/* ACTION - a RULE instance with targets and sources */
85
86struct _action {
87	RULE		*rule;
88	TARGETS		*targets;
89	TARGETS		*sources;	/* aka $(>) */
90	char		running;	/* has been started */
91	char		status;		/* see TARGET status */
92} ;
93
94/* SETTINGS - variables to set when executing a TARGET's ACTIONS */
95
96struct _settings {
97	SETTINGS 	*next;
98	const char	*symbol;	/* symbol name for var_set() */
99	LIST		*value;		/* symbol value for var_set() */
100} ;
101
102/* TARGETS - a chain of TARGETs */
103
104struct _targets {
105	TARGETS		*next;
106	TARGETS		*tail;		/* valid only for head */
107	TARGET		*target;
108} ;
109
110/* TARGET - a file or "thing" that can be built */
111
112struct _target {
113	const char	*name;
114	const char	*boundname;	/* if search() relocates target */
115	ACTIONS		*actions;	/* rules to execute, if any */
116	SETTINGS 	*settings;	/* variables to define */
117
118	char		flags;		/* status info */
119
120# define 	T_FLAG_TEMP 	0x01	/* TEMPORARY applied */
121# define 	T_FLAG_NOCARE 	0x02	/* NOCARE applied */
122# define 	T_FLAG_NOTFILE 	0x04	/* NOTFILE applied */
123# define	T_FLAG_TOUCHED	0x08	/* ALWAYS applied or -t target */
124# define	T_FLAG_LEAVES	0x10	/* LEAVES applied */
125# define	T_FLAG_NOUPDATE	0x20	/* NOUPDATE applied */
126# define	T_FLAG_INTERNAL	0x40	/* internal INCLUDES node */
127
128	char		binding;	/* how target relates to real file */
129
130# define 	T_BIND_UNBOUND	0	/* a disembodied name */
131# define 	T_BIND_MISSING	1	/* couldn't find real file */
132# define 	T_BIND_PARENTS	2	/* using parent's timestamp */
133# define 	T_BIND_EXISTS	3	/* real file, timestamp valid */
134
135	TARGETS		*depends;	/* dependencies */
136	TARGET		*includes;	/* includes */
137
138	time_t		time;		/* update time */
139	time_t		leaf;		/* update time of leaf sources */
140	char		fate;		/* make0()'s diagnosis */
141
142# define 	T_FATE_INIT	0	/* nothing done to target */
143# define 	T_FATE_MAKING	1	/* make0(target) on stack */
144
145# define 	T_FATE_STABLE	2	/* target didn't need updating */
146# define	T_FATE_NEWER	3	/* target newer than parent */
147
148# define	T_FATE_SPOIL	4	/* >= SPOIL rebuilds parents */
149# define 	T_FATE_ISTMP	4	/* unneeded temp target oddly present */
150
151# define	T_FATE_BUILD	5	/* >= BUILD rebuilds target */
152# define	T_FATE_TOUCHED	5	/* manually touched with -t */
153# define	T_FATE_MISSING	6	/* is missing, needs updating */
154# define	T_FATE_NEEDTMP	7	/* missing temp that must be rebuild */
155# define 	T_FATE_OUTDATED	8	/* is out of date, needs updating */
156# define 	T_FATE_UPDATE	9	/* deps updated, needs updating */
157
158# define 	T_FATE_BROKEN	10	/* >= BROKEN ruins parents */
159# define 	T_FATE_CANTFIND	10	/* no rules to make missing target */
160# define 	T_FATE_CANTMAKE	11	/* can't find dependents */
161
162	char		progress;	/* tracks make1() progress */
163
164# define	T_MAKE_INIT	0	/* make1(target) not yet called */
165# define	T_MAKE_ONSTACK	1	/* make1(target) on stack */
166# define	T_MAKE_ACTIVE	2	/* make1(target) in make1b() */
167# define	T_MAKE_RUNNING	3	/* make1(target) running commands */
168# define	T_MAKE_DONE	4	/* make1(target) done */
169
170	char		status;		/* execcmd() result */
171
172	int		asynccnt;	/* child deps outstanding */
173	TARGETS		*parents;	/* used by make1() for completion */
174	char		*cmds;		/* type-punned command list */
175} ;
176
177RULE 	*bindrule( const char *rulename );
178TARGET *bindtarget( const char *targetname );
179TARGET *copytarget( const TARGET *t );
180void 	touchtarget( const char *t );
181TARGETS *targetlist( TARGETS *chain, LIST  *targets );
182TARGETS *targetentry( TARGETS *chain, TARGET *target );
183TARGETS *targetchain( TARGETS *chain, TARGETS *targets );
184ACTIONS *actionlist( ACTIONS *chain, ACTION *action );
185SETTINGS *addsettings( SETTINGS *v, int setflag, const char *sym, LIST *val );
186SETTINGS *copysettings( SETTINGS *v );
187void 	pushsettings( SETTINGS *v );
188void 	popsettings( SETTINGS *v );
189void 	freesettings( SETTINGS *v );
190void	donerules();
191