Debian Codegraph @

src/variable.h

raw symbols SCIP
1 /* Definitions for using variables in GNU Make.
2 Copyright (C) 1988-2020 Free Software Foundation, Inc.
3 This file is part of GNU Make.
4
5 GNU Make is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3 of the License, or (at your option) any later
8 version.
9
10 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program. If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef VARIABLE_H
18 #define VARIABLE_H
19
20 #include "gnuremake.h"
21 #include "hash.h"
22
23 /* Codes in a variable definition saying where the definition came from.
24 Increasing numeric values signify less-overridable definitions. */
25 enum variable_origin
26 {
27 o_default, /* Variable from the default set. */
28 o_env, /* Variable from environment. */
29 o_file, /* Variable given in a makefile. */
30 o_env_override, /* Variable from environment, if -e. */
31 o_command, /* Variable given by user. */
32 o_override, /* Variable from an 'override' directive. */
33 o_automatic, /* Automatic variable -- cannot be set. */
34 o_debugger, /* Set inside debugger. */
35 o_invalid /* Core dump time. */
36 };
37
38 enum variable_flavor
39 {
40 f_bogus, /* Bogus (error) */
41 f_simple, /* Simple definition (:= or ::=) */
42 f_recursive, /* Recursive definition (=) */
43 f_append, /* Appending definition (+=) */
44 f_conditional, /* Conditional definition (?=) */
45 f_shell, /* Shell assignment (!=) */
46 f_append_value /* Append unexpanded value */
47 };
48
49 /* Structure that represents one variable definition.
50 Each bucket of the hash table is a chain of these,
51 chained through 'next'. */
52
53 #define EXP_COUNT_BITS 15 /* This gets all the bitfields into 32 bits */
54 #define EXP_COUNT_MAX ((1<<EXP_COUNT_BITS)-1)
55
56 struct variable
57 {
58 char *name; /* Variable name. */
59 char *value; /* Variable value. */
60 gmk_floc fileinfo; /* Where the variable was defined. */
61 unsigned int length; /* strlen (name) */
62 unsigned int recursive:1; /* Gets recursively re-evaluated. */
63 unsigned int append:1; /* Nonzero if an appending target-specific
64 variable. */
65 unsigned int conditional:1; /* Nonzero if set with a ?=. */
66 unsigned int per_target:1; /* Nonzero if a target-specific variable. */
67 unsigned int special:1; /* Nonzero if this is a special variable. */
68 unsigned int exportable:1; /* Nonzero if the variable _could_ be
69 exported. */
70 unsigned int expanding:1; /* Nonzero if currently being expanded. */
71 unsigned int private_var:1; /* Nonzero avoids inheritance of this
72 target-specific variable. */
73 unsigned int exp_count:EXP_COUNT_BITS;
74 /* If >1, allow this many self-referential
75 expansions. */
76 enum variable_flavor
77 flavor ENUM_BITFIELD (4); /* Variable flavor. */
78 enum variable_origin
79 origin ENUM_BITFIELD (4); /* Variable origin. */
80 enum variable_export
81 {
82 v_export, /* Export this variable. */
83 v_noexport, /* Don't export this variable. */
84 v_ifset, /* Export it if it has a non-default value. */
85 v_default /* Decide in target_environment. */
86 } export ENUM_BITFIELD (2);
87 };
88
89 /* Structure that represents a variable set. */
90
91 struct variable_set
92 {
93 struct hash_table table; /* Hash table of variables. */
94 };
95
96 /* Structure that represents a list of variable sets. */
97
98 struct variable_set_list
99 {
100 struct variable_set_list *next; /* Link in the chain. */
101 struct variable_set *set; /* Variable set. */
102 int next_is_parent; /* True if next is a parent target. */
103 };
104
105 /* Structure used for pattern-specific variables. */
106
107 struct pattern_var
108 {
109 struct pattern_var *next;
110 const char *suffix;
111 const char *target;
112 size_t len;
113 struct variable variable;
114 };
115
116 extern char *variable_buffer;
117 extern struct variable_set_list *current_variable_set_list;
118 extern struct variable *default_goal_var;
119 extern struct variable shell_var;
120
121 /* expand.c */
122 #ifndef SIZE_MAX
123 # define SIZE_MAX ((size_t)~(size_t)0)
124 #endif
125
126 char *variable_buffer_output (char *ptr, const char *string, size_t length);
127 char *variable_expand (const char *line);
128 char *variable_expand_for_file (const char *line, struct file *file);
129 char *allocated_variable_expand_for_file (const char *line, struct file *file);
130 #define allocated_variable_expand(line) \
131 allocated_variable_expand_for_file (line, (struct file *) 0)
132 char *expand_argument (const char *str, const char *end);
133 char *variable_expand_string (char *line, const char *string, size_t length);
134 void install_variable_buffer (char **bufp, size_t *lenp);
135 void restore_variable_buffer (char *buf, size_t len);
136
137 /* function.c */
138 int handle_function (char **op, const char **stringp);
139 int pattern_matches (const char *pattern, const char *percent, const char *str);
140 char *subst_expand (char *o, const char *text, const char *subst,
141 const char *replace, size_t slen, size_t rlen,
142 int by_word);
143 char *patsubst_expand_pat (char *o, const char *text, const char *pattern,
144 const char *replace, const char *pattern_percent,
145 const char *replace_percent);
146 char *patsubst_expand (char *o, const char *text, char *pattern, char *replace);
147 char *func_shell_base (char *o, char **argv, int trim_newlines);
148 void shell_completed (int exit_code, int exit_sig);
149
150 /* expand.c */
151 char *recursively_expand_for_file (struct variable *v, struct file *file);
152 #define recursively_expand(v) recursively_expand_for_file (v, NULL)
153
154 /* variable.c */
155 struct variable_set_list *create_new_variable_set (void);
156
157 /*!
158 Return a string describing origin.
159 */
160 const char *origin2str(variable_origin_t origin);
161
162 void free_variable_set (struct variable_set_list *);
163
164 /*! Create a new variable set, push it on the current setlist,
165 and assign current_variable_set_list to it.
166 */
167 struct variable_set_list *push_new_variable_scope (void);
168
169 /*! Pop the top set off the current_variable_set_list, and free all
170 its storage. If b_toplevel set we have the top-most global scope
171 and some things don't get freed because they weren't malloc'd.
172 */
173 void pop_variable_scope (void);
174
175 /*! Define the automatic variables, and record the addresses of their
176 structures so we can change their values quickly. */
177 void define_automatic_variables (void);
178
179 /*! Initialize FILE's variable set list. If FILE already has a
180 variable set list, the topmost variable set is left intact, but the
181 the rest of the chain is replaced with FILE->parent's setlist. If
182 FILE is a double-colon rule, then we will use the "root"
183 double-colon target's variable set as the parent of FILE's variable
184 set.
185
186 If we're READing a makefile, don't do the pattern variable search now,
187 since the pattern variable might not have been defined yet. */
188 void initialize_file_variables (struct file *file, int reading);
189
190 /*! Print all the local variables of P_TARGET. Lines output have "# "
191 prepended. If you want hash table statistics too, set b_hash_stats
192 true.
193 */
194 extern void print_file_variables(const file_t *p_target, bool b_hash_stats);
195
196 /*! Print the data base of variables. */
197
198 extern void print_variable_data_base (void);
199
200 /** Print information for variable V, prefixing it with PREFIX. */
201 extern void print_variable_info (const void *item, void *arg);
202
203 void print_target_variables (const struct file *file);
204
205 /*! Print all the variables in SET. PREFIX is printed before the
206 actual variable definitions (everything else is comments). If you
207 want hash table statistics too, set b_hash_stats true.
208 */
209 void print_variable_set (struct variable_set *set, const char *prefix, int pauto);
210
211 void merge_variable_set_lists (struct variable_set_list **to_list,
212 struct variable_set_list *from_list);
213 struct variable *do_variable_definition (const gmk_floc *flocp,
214 const char *name, const char *value,
215 enum variable_origin origin,
216 enum variable_flavor flavor,
217 int target_var);
218 char *parse_variable_definition (const char *line,
219 struct variable *v);
220 struct variable *assign_variable_definition (struct variable *v, const char *line);
221 struct variable *try_variable_definition (const gmk_floc *flocp, const char *line,
222 enum variable_origin origin,
223 int target_var);
224 void init_hash_global_variable_set (void);
225 void hash_init_function_table (void);
226 void define_new_function(const gmk_floc *flocp, const char *name,
227 unsigned int min, unsigned int max, unsigned int flags,
228 gmk_func_ptr func);
229 struct variable *lookup_variable (const char *name, size_t length);
230 struct variable *lookup_variable_in_set (const char *name, size_t length,
231 const struct variable_set *set);
232
233 struct variable *define_variable_in_set (const char *name, size_t length,
234 const char *value,
235 enum variable_origin origin,
236 int recursive,
237 struct variable_set *set,
238 const gmk_floc *flocp);
239
240 /* Define a variable in the current variable set. */
241
242 #define define_variable(n,l,v,o,r) \
243 define_variable_in_set((n),(l),(v),(o),(r),\
244 current_variable_set_list->set,NILF)
245
246 /* Define a variable with a constant name in the current variable set. */
247
248 #define define_variable_cname(n,v,o,r) \
249 define_variable_in_set((n),(sizeof (n) - 1),(v),(o),(r),\
250 current_variable_set_list->set,NILF)
251
252 /* Define a variable with a location in the current variable set. */
253
254 #define define_variable_loc(n,l,v,o,r,f) \
255 define_variable_in_set((n),(l),(v),(o),(r),\
256 current_variable_set_list->set,(f))
257
258 /* Define a variable with a location in the global variable set. */
259
260 #define define_variable_global(n,l,v,o,r,f) \
261 define_variable_in_set((n),(l),(v),(o),(r),NULL,(f))
262
263 /* Define a variable in FILE's variable set. */
264
265 #define define_variable_for_file(n,l,v,o,r,f) \
266 define_variable_in_set((n),(l),(v),(o),(r),(f)->variables->set,NILF)
267
268 void undefine_variable_in_set (const char *name, size_t length,
269 enum variable_origin origin,
270 struct variable_set *set);
271
272 /* Remove variable from the current variable set. */
273
274 #define undefine_variable_global(n,l,o) \
275 undefine_variable_in_set((n),(l),(o),NULL)
276
277 /* Warn that NAME is an undefined variable. */
278
279 #define warn_undefined(n,l) do{\
280 if (warn_undefined_variables_flag) \
281 error (reading_file, (l), \
282 _("warning: undefined variable '%.*s'"), \
283 (int)(l), (n)); \
284 }while(0)
285
286 char **target_environment (struct file *file);
287
288 struct pattern_var *create_pattern_var (const char *target,
289 const char *suffix);
290
291 extern int export_all_variables;
292
293 #define MAKELEVEL_NAME "MAKELEVEL"
294 #define MAKELEVEL_LENGTH (CSTRLEN (MAKELEVEL_NAME))
295
296 #define MAKEPARENT_PID_NAME "MAKEPARENT_PID"
297 #define MAKEPARENT_PID_LENGTH (CSTRLEN (MAKEPARENT_PID_NAME))
298
299 #define MAKEPARENT_TARGET_NAME "MAKEPARENT_TARGET"
300 #define MAKEPARENT_TARGET_LENGTH (CSTRLEN (MAKEPARENT_TARGET_NAME))
301 #endif /*VARIABLE_H*/