VirtualBox

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

Last change on this file since 1223 was 937, checked in by bird, 18 years ago

Implemented the prepend assignment operator '<='.

  • Property svn:eol-style set to native
File size: 11.3 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 o_automatic, /* Automatic variable -- cannot be set. */
32 o_invalid /* Core dump time. */
33 };
34
35enum variable_flavor
36 {
37 f_bogus, /* Bogus (error) */
38 f_simple, /* Simple definition (:=) */
39 f_recursive, /* Recursive definition (=) */
40 f_append, /* Appending definition (+=) */
41#ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
42 f_prepend, /* Prepending definition (>=) */
43#endif
44 f_conditional /* Conditional definition (?=) */
45 };
46
47/* Structure that represents one variable definition.
48 Each bucket of the hash table is a chain of these,
49 chained through `next'. */
50
51#define EXP_COUNT_BITS 15 /* This gets all the bitfields into 32 bits */
52#define EXP_COUNT_MAX ((1<<EXP_COUNT_BITS)-1)
53
54struct variable
55 {
56 char *name; /* Variable name. */
57 int length; /* strlen (name) */
58#ifdef VARIABLE_HASH /* bird */
59 int hash1; /* the primary hash */
60 int hash2; /* the secondary hash */
61#endif
62#ifdef CONFIG_WITH_VALUE_LENGTH
63 int value_length; /* The length of the value, usually unused. */
64 int value_alloc_len; /* The amount of memory we've actually allocated. */
65 /* FIXME: make lengths unsigned! */
66#endif
67 char *value; /* Variable value. */
68 struct floc fileinfo; /* Where the variable was defined. */
69 unsigned int recursive:1; /* Gets recursively re-evaluated. */
70 unsigned int append:1; /* Nonzero if an appending target-specific
71 variable. */
72 unsigned int conditional:1; /* Nonzero if set with a ?=. */
73 unsigned int per_target:1; /* Nonzero if a target-specific variable. */
74 unsigned int special:1; /* Nonzero if this is a special variable. */
75 unsigned int exportable:1; /* Nonzero if the variable _could_ be
76 exported. */
77 unsigned int expanding:1; /* Nonzero if currently being expanded. */
78 unsigned int exp_count:EXP_COUNT_BITS;
79 /* If >1, allow this many self-referential
80 expansions. */
81 enum variable_flavor
82 flavor ENUM_BITFIELD (3); /* Variable flavor. */
83 enum variable_origin
84 origin ENUM_BITFIELD (3); /* Variable origin. */
85 enum variable_export
86 {
87 v_export, /* Export this variable. */
88 v_noexport, /* Don't export this variable. */
89 v_ifset, /* Export it if it has a non-default value. */
90 v_default /* Decide in target_environment. */
91 } export ENUM_BITFIELD (2);
92 };
93
94/* Structure that represents a variable set. */
95
96struct variable_set
97 {
98 struct hash_table table; /* Hash table of variables. */
99 };
100
101/* Structure that represents a list of variable sets. */
102
103struct variable_set_list
104 {
105 struct variable_set_list *next; /* Link in the chain. */
106 struct variable_set *set; /* Variable set. */
107 };
108
109/* Structure used for pattern-specific variables. */
110
111struct pattern_var
112 {
113 struct pattern_var *next;
114 const char *suffix;
115 const char *target;
116 unsigned int len;
117 struct variable variable;
118 };
119
120extern char *variable_buffer;
121extern struct variable_set_list *current_variable_set_list;
122
123/* expand.c */
124char *variable_buffer_output (char *ptr, const char *string, unsigned int length);
125char *variable_expand (const char *line);
126char *variable_expand_for_file (const char *line, struct file *file);
127char *allocated_variable_expand_for_file (const char *line, struct file *file);
128#define allocated_variable_expand(line) \
129 allocated_variable_expand_for_file (line, (struct file *) 0)
130char *expand_argument (const char *str, const char *end);
131char *variable_expand_string (char *line, const char *string, long length);
132void install_variable_buffer (char **bufp, unsigned int *lenp);
133void restore_variable_buffer (char *buf, unsigned int len);
134#ifdef CONFIG_WITH_VALUE_LENGTH
135extern void append_expanded_string_to_variable (struct variable *v, const char *value);
136#endif
137
138/* function.c */
139int handle_function (char **op, const char **stringp);
140int pattern_matches (const char *pattern, const char *percent, const char *str);
141char *subst_expand (char *o, const char *text, const char *subst,
142 const char *replace, unsigned int slen, unsigned int rlen,
143 int by_word);
144char *patsubst_expand_pat (char *o, const char *text, const char *pattern,
145 const char *replace, const char *pattern_percent,
146 const char *replace_percent);
147char *patsubst_expand (char *o, const char *text, char *pattern, char *replace);
148
149/* expand.c */
150char *recursively_expand_for_file (struct variable *v, struct file *file);
151#define recursively_expand(v) recursively_expand_for_file (v, NULL)
152
153/* variable.c */
154struct variable_set_list *create_new_variable_set (void);
155void free_variable_set (struct variable_set_list *);
156struct variable_set_list *push_new_variable_scope (void);
157void pop_variable_scope (void);
158void define_automatic_variables (void);
159void initialize_file_variables (struct file *file, int reading);
160void print_file_variables (const struct file *file);
161void print_variable_set (struct variable_set *set, char *prefix);
162void merge_variable_set_lists (struct variable_set_list **to_list,
163 struct variable_set_list *from_list);
164struct variable *do_variable_definition (const struct floc *flocp,
165 const char *name, const char *value,
166 enum variable_origin origin,
167 enum variable_flavor flavor,
168 int target_var);
169struct variable *parse_variable_definition (struct variable *v, char *line);
170struct variable *try_variable_definition (const struct floc *flocp, char *line,
171 enum variable_origin origin,
172 int target_var);
173void init_hash_global_variable_set (void);
174void hash_init_function_table (void);
175struct variable *lookup_variable (const char *name, unsigned int length);
176struct variable *lookup_variable_in_set (const char *name, unsigned int length,
177 const struct variable_set *set);
178
179#ifdef CONFIG_WITH_VALUE_LENGTH
180
181struct variable *define_variable_in_set (const char *name, unsigned int length,
182 const char *value,
183 unsigned int value_length,
184 int duplicate_value,
185 enum variable_origin origin,
186 int recursive,
187 struct variable_set *set,
188 const struct floc *flocp);
189
190/* Define a variable in the current variable set. */
191
192#define define_variable(n,l,v,o,r) \
193 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),\
194 current_variable_set_list->set,NILF)
195
196#define define_variable_vl(n,l,v,vl,dv,o,r) \
197 define_variable_in_set((n),(l),(v),(vl),(dv),(o),(r),\
198 current_variable_set_list->set,NILF)
199
200/* Define a variable with a location in the current variable set. */
201
202#define define_variable_loc(n,l,v,o,r,f) \
203 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),\
204 current_variable_set_list->set,(f))
205
206/* Define a variable with a location in the global variable set. */
207
208#define define_variable_global(n,l,v,o,r,f) \
209 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),NULL,(f))
210
211#define define_variable_vl_global(n,l,v,vl,dv,o,r,f) \
212 define_variable_in_set((n),(l),(v),(vl),(dv),(o),(r),NULL,(f))
213
214/* Define a variable in FILE's variable set. */
215
216#define define_variable_for_file(n,l,v,o,r,f) \
217 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),(f)->variables->set,NILF)
218
219#else /* !CONFIG_WITH_VALUE_LENGTH */
220
221struct variable *define_variable_in_set (const char *name, unsigned int length,
222 const char *value,
223 enum variable_origin origin,
224 int recursive,
225 struct variable_set *set,
226 const struct floc *flocp);
227
228/* Define a variable in the current variable set. */
229
230#define define_variable(n,l,v,o,r) \
231 define_variable_in_set((n),(l),(v),(o),(r),\
232 current_variable_set_list->set,NILF) /* force merge conflict */
233
234/* Define a variable with a location in the current variable set. */
235
236#define define_variable_loc(n,l,v,o,r,f) \
237 define_variable_in_set((n),(l),(v),(o),(r),\
238 current_variable_set_list->set,(f)) /* force merge conflict */
239
240/* Define a variable with a location in the global variable set. */
241
242#define define_variable_global(n,l,v,o,r,f) \
243 define_variable_in_set((n),(l),(v),(o),(r),NULL,(f)) /* force merge conflict */
244
245/* Define a variable in FILE's variable set. */
246
247#define define_variable_for_file(n,l,v,o,r,f) \
248 define_variable_in_set((n),(l),(v),(o),(r),(f)->variables->set,NILF) /* force merge conflict */
249
250#endif /* !CONFIG_WITH_VALUE_LENGTH */
251
252/* Warn that NAME is an undefined variable. */
253
254#define warn_undefined(n,l) do{\
255 if (warn_undefined_variables_flag) \
256 error (reading_file, \
257 _("warning: undefined variable `%.*s'"), \
258 (int)(l), (n)); \
259 }while(0)
260
261char **target_environment (struct file *file);
262
263struct pattern_var *create_pattern_var (const char *target,
264 const char *suffix);
265
266extern int export_all_variables;
267
268#define MAKELEVEL_NAME "MAKELEVEL"
269#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