VirtualBox

source: kBuild/trunk/src/kmk/variable.h@ 1809

Last change on this file since 1809 was 1809, checked in by bird, 16 years ago

kmk: More length and alloc optimizations. Made all the length optimizations from yesterday CONFIG_WITH_VALUE_LENGTH instead of KMK.

  • Property svn:eol-style set to native
File size: 13.2 KB
Line 
1/* Definitions for using variables in GNU Make.
2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
4Foundation, Inc.
5This file is part of GNU Make.
6
7GNU Make is free software; you can redistribute it and/or modify it under the
8terms of the GNU General Public License as published by the Free Software
9Foundation; either version 2, or (at your option) any later version.
10
11GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License along with
16GNU Make; see the file COPYING. If not, write to the Free Software
17Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */
18
19#include "hash.h"
20
21/* Codes in a variable definition saying where the definition came from.
22 Increasing numeric values signify less-overridable definitions. */
23enum variable_origin
24 {
25 o_default, /* Variable from the default set. */
26 o_env, /* Variable from environment. */
27 o_file, /* Variable given in a makefile. */
28 o_env_override, /* Variable from environment, if -e. */
29 o_command, /* Variable given by user. */
30 o_override, /* Variable from an `override' directive. */
31#ifdef CONFIG_WITH_LOCAL_VARIABLES
32 o_local, /* Variable from an 'local' directive. */
33#endif
34 o_automatic, /* Automatic variable -- cannot be set. */
35 o_invalid /* Core dump time. */
36 };
37
38enum variable_flavor
39 {
40 f_bogus, /* Bogus (error) */
41 f_simple, /* Simple definition (:=) */
42 f_recursive, /* Recursive definition (=) */
43 f_append, /* Appending definition (+=) */
44#ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
45 f_prepend, /* Prepending definition (>=) */
46#endif
47 f_conditional /* Conditional definition (?=) */
48 };
49
50/* Structure that represents one variable definition.
51 Each bucket of the hash table is a chain of these,
52 chained through `next'. */
53
54#define EXP_COUNT_BITS 15 /* This gets all the bitfields into 32 bits */
55#define EXP_COUNT_MAX ((1<<EXP_COUNT_BITS)-1)
56
57struct variable
58 {
59 char *name; /* Variable name. */
60 int length; /* strlen (name) */
61#ifdef VARIABLE_HASH /* bird */
62 int hash1; /* the primary hash */
63 int hash2; /* the secondary hash */
64#endif
65#ifdef CONFIG_WITH_VALUE_LENGTH
66 int value_length; /* The length of the value, usually unused. */
67 int value_alloc_len; /* The amount of memory we've actually allocated. */
68 /* FIXME: make lengths unsigned! */
69#endif
70 char *value; /* Variable value. */
71 struct floc fileinfo; /* Where the variable was defined. */
72 unsigned int recursive:1; /* Gets recursively re-evaluated. */
73 unsigned int append:1; /* Nonzero if an appending target-specific
74 variable. */
75 unsigned int conditional:1; /* Nonzero if set with a ?=. */
76 unsigned int per_target:1; /* Nonzero if a target-specific variable. */
77 unsigned int special:1; /* Nonzero if this is a special variable. */
78 unsigned int exportable:1; /* Nonzero if the variable _could_ be
79 exported. */
80 unsigned int expanding:1; /* Nonzero if currently being expanded. */
81 unsigned int exp_count:EXP_COUNT_BITS;
82 /* If >1, allow this many self-referential
83 expansions. */
84 enum variable_flavor
85 flavor ENUM_BITFIELD (3); /* Variable flavor. */
86 enum variable_origin
87#ifdef CONFIG_WITH_LOCAL_VARIABLES
88 origin ENUM_BITFIELD (4); /* Variable origin. */
89#else
90 origin ENUM_BITFIELD (3); /* Variable origin. */
91#endif
92 enum variable_export
93 {
94 v_export, /* Export this variable. */
95 v_noexport, /* Don't export this variable. */
96 v_ifset, /* Export it if it has a non-default value. */
97 v_default /* Decide in target_environment. */
98 } export ENUM_BITFIELD (2);
99 };
100
101/* Structure that represents a variable set. */
102
103struct variable_set
104 {
105 struct hash_table table; /* Hash table of variables. */
106 };
107
108/* Structure that represents a list of variable sets. */
109
110struct variable_set_list
111 {
112 struct variable_set_list *next; /* Link in the chain. */
113 struct variable_set *set; /* Variable set. */
114 };
115
116/* Structure used for pattern-specific variables. */
117
118struct pattern_var
119 {
120 struct pattern_var *next;
121 const char *suffix;
122 const char *target;
123 unsigned int len;
124 struct variable variable;
125 };
126
127extern char *variable_buffer;
128extern struct variable_set_list *current_variable_set_list;
129
130/* expand.c */
131char *variable_buffer_output (char *ptr, const char *string, unsigned int length);
132char *variable_expand (const char *line);
133char *variable_expand_for_file (const char *line, struct file *file);
134#ifdef CONFIG_WITH_COMMANDS_FUNC
135char *variable_expand_for_file_2 (char *o, const char *line, struct file *file);
136#endif
137char *allocated_variable_expand_for_file (const char *line, struct file *file);
138#ifndef CONFIG_WITH_VALUE_LENGTH
139#define allocated_variable_expand(line) \
140 allocated_variable_expand_for_file (line, (struct file *) 0)
141#else /* CONFIG_WITH_VALUE_LENGTH */
142# define allocated_variable_expand(line) \
143 allocated_variable_expand_2 (line, -1, NULL)
144char *allocated_variable_expand_2(const char *line, unsigned int length, unsigned int *value_len);
145#endif /* CONFIG_WITH_VALUE_LENGTH */
146char *expand_argument (const char *str, const char *end);
147char *variable_expand_string (char *line, const char *string, long length);
148#ifdef CONFIG_WITH_VALUE_LENGTH
149char *variable_expand_string_2 (char *line, const char *string, long length, char **eol);
150#endif
151void install_variable_buffer (char **bufp, unsigned int *lenp);
152void restore_variable_buffer (char *buf, unsigned int len);
153#ifdef CONFIG_WITH_VALUE_LENGTH
154void append_expanded_string_to_variable (struct variable *v, const char *value,
155 unsigned int value_len, int append);
156#endif
157
158/* function.c */
159int handle_function (char **op, const char **stringp);
160int pattern_matches (const char *pattern, const char *percent, const char *str);
161char *subst_expand (char *o, const char *text, const char *subst,
162 const char *replace, unsigned int slen, unsigned int rlen,
163 int by_word);
164char *patsubst_expand_pat (char *o, const char *text, const char *pattern,
165 const char *replace, const char *pattern_percent,
166 const char *replace_percent);
167char *patsubst_expand (char *o, const char *text, char *pattern, char *replace);
168#ifdef CONFIG_WITH_COMMANDS_FUNC
169char *func_commands (char *o, char **argv, const char *funcname);
170#endif
171
172/* expand.c */
173char *recursively_expand_for_file (struct variable *v, struct file *file);
174#define recursively_expand(v) recursively_expand_for_file (v, NULL)
175
176/* variable.c */
177struct variable_set_list *create_new_variable_set (void);
178void free_variable_set (struct variable_set_list *);
179struct variable_set_list *push_new_variable_scope (void);
180void pop_variable_scope (void);
181void define_automatic_variables (void);
182void initialize_file_variables (struct file *file, int reading);
183void print_file_variables (const struct file *file);
184void print_variable_set (struct variable_set *set, char *prefix);
185void merge_variable_set_lists (struct variable_set_list **to_list,
186 struct variable_set_list *from_list);
187#ifndef CONFIG_WITH_VALUE_LENGTH
188struct variable *do_variable_definition (const struct floc *flocp,
189 const char *name, const char *value,
190 enum variable_origin origin,
191 enum variable_flavor flavor,
192 int target_var);
193#else /* CONFIG_WITH_VALUE_LENGTH */
194# define do_variable_definition(flocp, varname, value, origin, flavor, target_var) \
195 do_variable_definition_2 ((flocp), (varname), (value), ~0U, 0, NULL, \
196 (origin), (flavor), (target_var))
197
198struct variable *do_variable_definition_2 (const struct floc *flocp,
199 const char *varname,
200 const char *value,
201 unsigned int value_len,
202 int simple_value, char *free_value,
203 enum variable_origin origin,
204 enum variable_flavor flavor,
205 int target_var);
206#endif /* CONFIG_WITH_VALUE_LENGTH */
207struct variable *parse_variable_definition (struct variable *v, char *line);
208struct variable *try_variable_definition (const struct floc *flocp, char *line,
209 enum variable_origin origin,
210 int target_var);
211void init_hash_global_variable_set (void);
212void hash_init_function_table (void);
213struct variable *lookup_variable (const char *name, unsigned int length);
214struct variable *lookup_variable_in_set (const char *name, unsigned int length,
215 const struct variable_set *set);
216
217#ifdef CONFIG_WITH_VALUE_LENGTH
218void append_string_to_variable (struct variable *v, const char *value,
219 unsigned int value_len, int append);
220
221struct variable *define_variable_in_set (const char *name, unsigned int length,
222 const char *value,
223 unsigned int value_length,
224 int duplicate_value,
225 enum variable_origin origin,
226 int recursive,
227 struct variable_set *set,
228 const struct floc *flocp);
229
230/* Define a variable in the current variable set. */
231
232#define define_variable(n,l,v,o,r) \
233 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),\
234 current_variable_set_list->set,NILF)
235
236#define define_variable_vl(n,l,v,vl,dv,o,r) \
237 define_variable_in_set((n),(l),(v),(vl),(dv),(o),(r),\
238 current_variable_set_list->set,NILF)
239
240/* Define a variable with a location in the current variable set. */
241
242#define define_variable_loc(n,l,v,o,r,f) \
243 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),\
244 current_variable_set_list->set,(f))
245
246/* Define a variable with a location in the global variable set. */
247
248#define define_variable_global(n,l,v,o,r,f) \
249 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),NULL,(f))
250
251#define define_variable_vl_global(n,l,v,vl,dv,o,r,f) \
252 define_variable_in_set((n),(l),(v),(vl),(dv),(o),(r),NULL,(f))
253
254/* Define a variable in FILE's variable set. */
255
256#define define_variable_for_file(n,l,v,o,r,f) \
257 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),(f)->variables->set,NILF)
258
259#else /* !CONFIG_WITH_VALUE_LENGTH */
260
261struct variable *define_variable_in_set (const char *name, unsigned int length,
262 const char *value,
263 enum variable_origin origin,
264 int recursive,
265 struct variable_set *set,
266 const struct floc *flocp);
267
268/* Define a variable in the current variable set. */
269
270#define define_variable(n,l,v,o,r) \
271 define_variable_in_set((n),(l),(v),(o),(r),\
272 current_variable_set_list->set,NILF) /* force merge conflict */
273
274/* Define a variable with a location in the current variable set. */
275
276#define define_variable_loc(n,l,v,o,r,f) \
277 define_variable_in_set((n),(l),(v),(o),(r),\
278 current_variable_set_list->set,(f)) /* force merge conflict */
279
280/* Define a variable with a location in the global variable set. */
281
282#define define_variable_global(n,l,v,o,r,f) \
283 define_variable_in_set((n),(l),(v),(o),(r),NULL,(f)) /* force merge conflict */
284
285/* Define a variable in FILE's variable set. */
286
287#define define_variable_for_file(n,l,v,o,r,f) \
288 define_variable_in_set((n),(l),(v),(o),(r),(f)->variables->set,NILF) /* force merge conflict */
289
290#endif /* !CONFIG_WITH_VALUE_LENGTH */
291
292/* Warn that NAME is an undefined variable. */
293
294#define warn_undefined(n,l) do{\
295 if (warn_undefined_variables_flag) \
296 error (reading_file, \
297 _("warning: undefined variable `%.*s'"), \
298 (int)(l), (n)); \
299 }while(0)
300
301char **target_environment (struct file *file);
302
303struct pattern_var *create_pattern_var (const char *target,
304 const char *suffix);
305
306extern int export_all_variables;
307
308#ifdef KMK
309# define MAKELEVEL_NAME "KMK_LEVEL"
310#else
311#define MAKELEVEL_NAME "MAKELEVEL"
312#endif
313#define MAKELEVEL_LENGTH (sizeof (MAKELEVEL_NAME) - 1)
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette