VirtualBox

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

Last change on this file since 1422 was 1408, checked in by bird, 17 years ago

Implemented local variable definitions - CONFIG_WITH_LOCAL_VARIABLES.

  • Property svn:eol-style set to native
File size: 11.4 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#ifdef CONFIG_WITH_LOCAL_VARIABLES /** @todo Correct priority? */
28 o_local, /* Variable from an 'local' directive. */
29#endif
30 o_file, /* Variable given in a makefile. */
31 o_env_override, /* Variable from environment, if -e. */
32 o_command, /* Variable given by user. */
33 o_override, /* Variable from an `override' directive. */
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 origin ENUM_BITFIELD (3); /* Variable origin. */
88 enum variable_export
89 {
90 v_export, /* Export this variable. */
91 v_noexport, /* Don't export this variable. */
92 v_ifset, /* Export it if it has a non-default value. */
93 v_default /* Decide in target_environment. */
94 } export ENUM_BITFIELD (2);
95 };
96
97/* Structure that represents a variable set. */
98
99struct variable_set
100 {
101 struct hash_table table; /* Hash table of variables. */
102 };
103
104/* Structure that represents a list of variable sets. */
105
106struct variable_set_list
107 {
108 struct variable_set_list *next; /* Link in the chain. */
109 struct variable_set *set; /* Variable set. */
110 };
111
112/* Structure used for pattern-specific variables. */
113
114struct pattern_var
115 {
116 struct pattern_var *next;
117 const char *suffix;
118 const char *target;
119 unsigned int len;
120 struct variable variable;
121 };
122
123extern char *variable_buffer;
124extern struct variable_set_list *current_variable_set_list;
125
126/* expand.c */
127char *variable_buffer_output (char *ptr, const char *string, unsigned int length);
128char *variable_expand (const char *line);
129char *variable_expand_for_file (const char *line, struct file *file);
130char *allocated_variable_expand_for_file (const char *line, struct file *file);
131#define allocated_variable_expand(line) \
132 allocated_variable_expand_for_file (line, (struct file *) 0)
133char *expand_argument (const char *str, const char *end);
134char *variable_expand_string (char *line, const char *string, long length);
135void install_variable_buffer (char **bufp, unsigned int *lenp);
136void restore_variable_buffer (char *buf, unsigned int len);
137#ifdef CONFIG_WITH_VALUE_LENGTH
138extern void append_expanded_string_to_variable (struct variable *v, const char *value);
139#endif
140
141/* function.c */
142int handle_function (char **op, const char **stringp);
143int pattern_matches (const char *pattern, const char *percent, const char *str);
144char *subst_expand (char *o, const char *text, const char *subst,
145 const char *replace, unsigned int slen, unsigned int rlen,
146 int by_word);
147char *patsubst_expand_pat (char *o, const char *text, const char *pattern,
148 const char *replace, const char *pattern_percent,
149 const char *replace_percent);
150char *patsubst_expand (char *o, const char *text, char *pattern, char *replace);
151
152/* expand.c */
153char *recursively_expand_for_file (struct variable *v, struct file *file);
154#define recursively_expand(v) recursively_expand_for_file (v, NULL)
155
156/* variable.c */
157struct variable_set_list *create_new_variable_set (void);
158void free_variable_set (struct variable_set_list *);
159struct variable_set_list *push_new_variable_scope (void);
160void pop_variable_scope (void);
161void define_automatic_variables (void);
162void initialize_file_variables (struct file *file, int reading);
163void print_file_variables (const struct file *file);
164void print_variable_set (struct variable_set *set, char *prefix);
165void merge_variable_set_lists (struct variable_set_list **to_list,
166 struct variable_set_list *from_list);
167struct variable *do_variable_definition (const struct floc *flocp,
168 const char *name, const char *value,
169 enum variable_origin origin,
170 enum variable_flavor flavor,
171 int target_var);
172struct variable *parse_variable_definition (struct variable *v, char *line);
173struct variable *try_variable_definition (const struct floc *flocp, char *line,
174 enum variable_origin origin,
175 int target_var);
176void init_hash_global_variable_set (void);
177void hash_init_function_table (void);
178struct variable *lookup_variable (const char *name, unsigned int length);
179struct variable *lookup_variable_in_set (const char *name, unsigned int length,
180 const struct variable_set *set);
181
182#ifdef CONFIG_WITH_VALUE_LENGTH
183
184struct variable *define_variable_in_set (const char *name, unsigned int length,
185 const char *value,
186 unsigned int value_length,
187 int duplicate_value,
188 enum variable_origin origin,
189 int recursive,
190 struct variable_set *set,
191 const struct floc *flocp);
192
193/* Define a variable in the current variable set. */
194
195#define define_variable(n,l,v,o,r) \
196 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),\
197 current_variable_set_list->set,NILF)
198
199#define define_variable_vl(n,l,v,vl,dv,o,r) \
200 define_variable_in_set((n),(l),(v),(vl),(dv),(o),(r),\
201 current_variable_set_list->set,NILF)
202
203/* Define a variable with a location in the current variable set. */
204
205#define define_variable_loc(n,l,v,o,r,f) \
206 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),\
207 current_variable_set_list->set,(f))
208
209/* Define a variable with a location in the global variable set. */
210
211#define define_variable_global(n,l,v,o,r,f) \
212 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),NULL,(f))
213
214#define define_variable_vl_global(n,l,v,vl,dv,o,r,f) \
215 define_variable_in_set((n),(l),(v),(vl),(dv),(o),(r),NULL,(f))
216
217/* Define a variable in FILE's variable set. */
218
219#define define_variable_for_file(n,l,v,o,r,f) \
220 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),(f)->variables->set,NILF)
221
222#else /* !CONFIG_WITH_VALUE_LENGTH */
223
224struct variable *define_variable_in_set (const char *name, unsigned int length,
225 const char *value,
226 enum variable_origin origin,
227 int recursive,
228 struct variable_set *set,
229 const struct floc *flocp);
230
231/* Define a variable in the current variable set. */
232
233#define define_variable(n,l,v,o,r) \
234 define_variable_in_set((n),(l),(v),(o),(r),\
235 current_variable_set_list->set,NILF) /* force merge conflict */
236
237/* Define a variable with a location in the current variable set. */
238
239#define define_variable_loc(n,l,v,o,r,f) \
240 define_variable_in_set((n),(l),(v),(o),(r),\
241 current_variable_set_list->set,(f)) /* force merge conflict */
242
243/* Define a variable with a location in the global variable set. */
244
245#define define_variable_global(n,l,v,o,r,f) \
246 define_variable_in_set((n),(l),(v),(o),(r),NULL,(f)) /* force merge conflict */
247
248/* Define a variable in FILE's variable set. */
249
250#define define_variable_for_file(n,l,v,o,r,f) \
251 define_variable_in_set((n),(l),(v),(o),(r),(f)->variables->set,NILF) /* force merge conflict */
252
253#endif /* !CONFIG_WITH_VALUE_LENGTH */
254
255/* Warn that NAME is an undefined variable. */
256
257#define warn_undefined(n,l) do{\
258 if (warn_undefined_variables_flag) \
259 error (reading_file, \
260 _("warning: undefined variable `%.*s'"), \
261 (int)(l), (n)); \
262 }while(0)
263
264char **target_environment (struct file *file);
265
266struct pattern_var *create_pattern_var (const char *target,
267 const char *suffix);
268
269extern int export_all_variables;
270
271#define MAKELEVEL_NAME "MAKELEVEL"
272#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