[53] | 1 | /* Definitions for using variables in GNU Make.
|
---|
[3140] | 2 | Copyright (C) 1988-2016 Free Software Foundation, Inc.
|
---|
[53] | 3 | This file is part of GNU Make.
|
---|
| 4 |
|
---|
[503] | 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
|
---|
[1993] | 7 | Foundation; either version 3 of the License, or (at your option) any later
|
---|
| 8 | version.
|
---|
[53] | 9 |
|
---|
[503] | 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.
|
---|
[53] | 13 |
|
---|
[503] | 14 | You should have received a copy of the GNU General Public License along with
|
---|
[1993] | 15 | this program. If not, see <http://www.gnu.org/licenses/>. */
|
---|
[53] | 16 |
|
---|
| 17 | #include "hash.h"
|
---|
[2771] | 18 | #ifdef CONFIG_WITH_COMPILER
|
---|
| 19 | # include "kmk_cc_exec.h"
|
---|
| 20 | #endif
|
---|
[53] | 21 |
|
---|
| 22 | /* Codes in a variable definition saying where the definition came from.
|
---|
| 23 | Increasing numeric values signify less-overridable definitions. */
|
---|
| 24 | enum variable_origin
|
---|
| 25 | {
|
---|
[3140] | 26 | o_default, /* Variable from the default set. */
|
---|
| 27 | o_env, /* Variable from environment. */
|
---|
| 28 | o_file, /* Variable given in a makefile. */
|
---|
| 29 | o_env_override, /* Variable from environment, if -e. */
|
---|
| 30 | o_command, /* Variable given by user. */
|
---|
| 31 | o_override, /* Variable from an 'override' directive. */
|
---|
[1622] | 32 | #ifdef CONFIG_WITH_LOCAL_VARIABLES
|
---|
| 33 | o_local, /* Variable from an 'local' directive. */
|
---|
| 34 | #endif
|
---|
[3140] | 35 | o_automatic, /* Automatic variable -- cannot be set. */
|
---|
| 36 | o_invalid /* Core dump time. */
|
---|
[53] | 37 | };
|
---|
| 38 |
|
---|
| 39 | enum variable_flavor
|
---|
| 40 | {
|
---|
| 41 | f_bogus, /* Bogus (error) */
|
---|
[3140] | 42 | f_simple, /* Simple definition (:= or ::=) */
|
---|
[53] | 43 | f_recursive, /* Recursive definition (=) */
|
---|
| 44 | f_append, /* Appending definition (+=) */
|
---|
[937] | 45 | #ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
|
---|
| 46 | f_prepend, /* Prepending definition (>=) */
|
---|
| 47 | #endif
|
---|
[3140] | 48 | f_conditional, /* Conditional definition (?=) */
|
---|
| 49 | f_shell /* Shell assignment (!=) */
|
---|
[53] | 50 | };
|
---|
| 51 |
|
---|
| 52 | /* Structure that represents one variable definition.
|
---|
| 53 | Each bucket of the hash table is a chain of these,
|
---|
[3140] | 54 | chained through 'next'. */
|
---|
[53] | 55 |
|
---|
| 56 | #define EXP_COUNT_BITS 15 /* This gets all the bitfields into 32 bits */
|
---|
| 57 | #define EXP_COUNT_MAX ((1<<EXP_COUNT_BITS)-1)
|
---|
[1997] | 58 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[3140] | 59 | # define VAR_ALIGN_VALUE_ALLOC(len) ( ((len) + (unsigned int)15) & ~(unsigned int)15 )
|
---|
[1997] | 60 | #endif
|
---|
[53] | 61 |
|
---|
| 62 | struct variable
|
---|
| 63 | {
|
---|
[1877] | 64 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[3140] | 65 | char *name; /* Variable name. */
|
---|
[1877] | 66 | #else
|
---|
[1889] | 67 | const char *name; /* Variable name (in varaible_strcache). */
|
---|
[1877] | 68 | #endif
|
---|
[3140] | 69 | char *value; /* Variable value. */
|
---|
| 70 | floc fileinfo; /* Where the variable was defined. */
|
---|
| 71 | int length; /* strlen (name) */
|
---|
[530] | 72 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[1999] | 73 | unsigned int value_length; /* The length of the value. */
|
---|
[1997] | 74 | unsigned int value_alloc_len; /* The amount of memory we've actually allocated. */
|
---|
[533] | 75 | /* FIXME: make lengths unsigned! */
|
---|
[903] | 76 | #endif
|
---|
[3140] | 77 | unsigned int recursive:1; /* Gets recursively re-evaluated. */
|
---|
| 78 | unsigned int append:1; /* Nonzero if an appending target-specific
|
---|
[53] | 79 | variable. */
|
---|
| 80 | unsigned int conditional:1; /* Nonzero if set with a ?=. */
|
---|
[3140] | 81 | unsigned int per_target:1; /* Nonzero if a target-specific variable. */
|
---|
[53] | 82 | unsigned int special:1; /* Nonzero if this is a special variable. */
|
---|
| 83 | unsigned int exportable:1; /* Nonzero if the variable _could_ be
|
---|
| 84 | exported. */
|
---|
[3140] | 85 | unsigned int expanding:1; /* Nonzero if currently being expanded. */
|
---|
[2591] | 86 | unsigned int private_var:1; /* Nonzero avoids inheritance of this
|
---|
| 87 | target-specific variable. */
|
---|
[53] | 88 | unsigned int exp_count:EXP_COUNT_BITS;
|
---|
| 89 | /* If >1, allow this many self-referential
|
---|
| 90 | expansions. */
|
---|
[1932] | 91 | #ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
|
---|
| 92 | unsigned int rdonly_val:1; /* VALUE is read only (strcache/const). */
|
---|
| 93 | #endif
|
---|
[2718] | 94 | #ifdef KMK
|
---|
| 95 | unsigned int alias:1; /* Nonzero if alias. VALUE points to the real variable. */
|
---|
| 96 | unsigned int aliased:1; /* Nonzero if aliased. Cannot be undefined. */
|
---|
| 97 | #endif
|
---|
[53] | 98 | enum variable_flavor
|
---|
[3140] | 99 | flavor ENUM_BITFIELD (3); /* Variable flavor. */
|
---|
[53] | 100 | enum variable_origin
|
---|
[1437] | 101 | #ifdef CONFIG_WITH_LOCAL_VARIABLES
|
---|
| 102 | origin ENUM_BITFIELD (4); /* Variable origin. */
|
---|
| 103 | #else
|
---|
[3140] | 104 | origin ENUM_BITFIELD (3); /* Variable origin. */
|
---|
[1610] | 105 | #endif
|
---|
[53] | 106 | enum variable_export
|
---|
| 107 | {
|
---|
[3140] | 108 | v_export, /* Export this variable. */
|
---|
| 109 | v_noexport, /* Don't export this variable. */
|
---|
| 110 | v_ifset, /* Export it if it has a non-default value. */
|
---|
| 111 | v_default /* Decide in target_environment. */
|
---|
[53] | 112 | } export ENUM_BITFIELD (2);
|
---|
[2771] | 113 | #ifdef CONFIG_WITH_COMPILER
|
---|
| 114 | int recursive_without_dollar : 2; /* 0 if undetermined, 1 if value has no '$' chars, -1 if it has. */
|
---|
| 115 | #endif
|
---|
[2004] | 116 | #ifdef CONFIG_WITH_MAKE_STATS
|
---|
[2752] | 117 | unsigned int changes; /* Variable modification count. */
|
---|
| 118 | unsigned int reallocs; /* Realloc on value count. */
|
---|
| 119 | unsigned int references; /* Lookup count. */
|
---|
[2758] | 120 | unsigned long long cTicksEvalVal; /* Number of ticks spend in cEvalVal. */
|
---|
[2004] | 121 | #endif
|
---|
[2765] | 122 | #if defined (CONFIG_WITH_COMPILER) || defined (CONFIG_WITH_MAKE_STATS)
|
---|
[2770] | 123 | unsigned int evalval_count; /* Times used with $(evalval ) or $(evalctx ) since last change. */
|
---|
| 124 | unsigned int expand_count; /* Times expanded since last change (not to be confused with exp_count). */
|
---|
[2765] | 125 | #endif
|
---|
| 126 | #ifdef CONFIG_WITH_COMPILER
|
---|
[2768] | 127 | struct kmk_cc_evalprog *evalprog; /* Pointer to evalval/evalctx "program". */
|
---|
| 128 | struct kmk_cc_expandprog *expandprog; /* Pointer to variable expand "program". */
|
---|
[2765] | 129 | #endif
|
---|
[53] | 130 | };
|
---|
| 131 |
|
---|
[2770] | 132 | /* Update statistics and invalidates optimizations when a variable changes. */
|
---|
| 133 | #ifdef CONFIG_WITH_COMPILER
|
---|
| 134 | # define VARIABLE_CHANGED(v) \
|
---|
| 135 | do { \
|
---|
| 136 | MAKE_STATS_2((v)->changes++); \
|
---|
| 137 | if ((v)->evalprog || (v)->expandprog) kmk_cc_variable_changed(v); \
|
---|
| 138 | (v)->expand_count = 0; \
|
---|
| 139 | (v)->evalval_count = 0; \
|
---|
[2771] | 140 | (v)->recursive_without_dollar = 0; \
|
---|
[2770] | 141 | } while (0)
|
---|
| 142 | #else
|
---|
| 143 | # define VARIABLE_CHANGED(v) MAKE_STATS_2((v)->changes++)
|
---|
| 144 | #endif
|
---|
| 145 |
|
---|
[2771] | 146 | /* Macro that avoids a lot of CONFIG_WITH_COMPILER checks when
|
---|
| 147 | accessing recursive_without_dollar. */
|
---|
| 148 | #ifdef CONFIG_WITH_COMPILER
|
---|
| 149 | # define IS_VARIABLE_RECURSIVE_WITHOUT_DOLLAR(v) ((v)->recursive_without_dollar > 0)
|
---|
| 150 | #else
|
---|
| 151 | # define IS_VARIABLE_RECURSIVE_WITHOUT_DOLLAR(v) 0
|
---|
| 152 | #endif
|
---|
[2770] | 153 |
|
---|
| 154 |
|
---|
[2771] | 155 |
|
---|
[53] | 156 | /* Structure that represents a variable set. */
|
---|
| 157 |
|
---|
| 158 | struct variable_set
|
---|
| 159 | {
|
---|
[3140] | 160 | struct hash_table table; /* Hash table of variables. */
|
---|
[53] | 161 | };
|
---|
| 162 |
|
---|
| 163 | /* Structure that represents a list of variable sets. */
|
---|
| 164 |
|
---|
| 165 | struct variable_set_list
|
---|
| 166 | {
|
---|
[3140] | 167 | struct variable_set_list *next; /* Link in the chain. */
|
---|
| 168 | struct variable_set *set; /* Variable set. */
|
---|
[2591] | 169 | int next_is_parent; /* True if next is a parent target. */
|
---|
[53] | 170 | };
|
---|
| 171 |
|
---|
| 172 | /* Structure used for pattern-specific variables. */
|
---|
| 173 |
|
---|
| 174 | struct pattern_var
|
---|
| 175 | {
|
---|
| 176 | struct pattern_var *next;
|
---|
[903] | 177 | const char *suffix;
|
---|
| 178 | const char *target;
|
---|
[53] | 179 | unsigned int len;
|
---|
| 180 | struct variable variable;
|
---|
| 181 | };
|
---|
| 182 |
|
---|
| 183 | extern char *variable_buffer;
|
---|
| 184 | extern struct variable_set_list *current_variable_set_list;
|
---|
[2591] | 185 | extern struct variable *default_goal_var;
|
---|
[3140] | 186 | extern struct variable shell_var;
|
---|
[2591] | 187 |
|
---|
[1830] | 188 | #ifdef KMK
|
---|
[2717] | 189 | extern struct variable_set global_variable_set;
|
---|
| 190 | extern struct variable_set_list global_setlist;
|
---|
[1830] | 191 | extern unsigned int variable_buffer_length;
|
---|
[2591] | 192 | # define VARIABLE_BUFFER_ZONE 5
|
---|
[1830] | 193 | #endif
|
---|
[53] | 194 |
|
---|
| 195 | /* expand.c */
|
---|
[1830] | 196 | #ifndef KMK
|
---|
[2591] | 197 | char *
|
---|
| 198 | variable_buffer_output (char *ptr, const char *string, unsigned int length);
|
---|
[1830] | 199 | #else /* KMK */
|
---|
[3140] | 200 | # include <k/kDefs.h>
|
---|
[1830] | 201 | /* Subroutine of variable_expand and friends:
|
---|
| 202 | The text to add is LENGTH chars starting at STRING to the variable_buffer.
|
---|
| 203 | The text is added to the buffer at PTR, and the updated pointer into
|
---|
| 204 | the buffer is returned as the value. Thus, the value returned by
|
---|
| 205 | each call to variable_buffer_output should be the first argument to
|
---|
| 206 | the following call. */
|
---|
| 207 |
|
---|
[3140] | 208 | K_INLINE char *variable_buffer_output (char *ptr, const char *string, unsigned int length)
|
---|
[1830] | 209 | {
|
---|
| 210 | register unsigned int newlen = length + (ptr - variable_buffer);
|
---|
| 211 |
|
---|
| 212 | if ((newlen + VARIABLE_BUFFER_ZONE) > variable_buffer_length)
|
---|
| 213 | {
|
---|
| 214 | unsigned int offset = ptr - variable_buffer;
|
---|
| 215 | variable_buffer_length = variable_buffer_length <= 1024
|
---|
| 216 | ? 2048 : variable_buffer_length * 4;
|
---|
| 217 | if (variable_buffer_length < newlen + 100)
|
---|
| 218 | variable_buffer_length = (newlen + 100 + 1023) & ~1023U;
|
---|
| 219 | variable_buffer = xrealloc (variable_buffer, variable_buffer_length);
|
---|
| 220 | ptr = variable_buffer + offset;
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | # ifndef _MSC_VER
|
---|
| 224 | switch (length)
|
---|
| 225 | {
|
---|
[3068] | 226 | case 4: ptr[3] = string[3]; /* fall thru */
|
---|
| 227 | case 3: ptr[2] = string[2]; /* fall thru */
|
---|
| 228 | case 2: ptr[1] = string[1]; /* fall thru */
|
---|
| 229 | case 1: ptr[0] = string[0]; /* fall thru */
|
---|
[1830] | 230 | case 0:
|
---|
| 231 | break;
|
---|
| 232 | default:
|
---|
| 233 | memcpy (ptr, string, length);
|
---|
| 234 | break;
|
---|
| 235 | }
|
---|
| 236 | # else
|
---|
| 237 | memcpy (ptr, string, length);
|
---|
| 238 | # endif
|
---|
| 239 | return ptr + length;
|
---|
| 240 | }
|
---|
[3140] | 241 | #endif /* KMK */
|
---|
[1830] | 242 |
|
---|
[903] | 243 | char *variable_expand (const char *line);
|
---|
| 244 | char *variable_expand_for_file (const char *line, struct file *file);
|
---|
[1975] | 245 | #if defined (CONFIG_WITH_VALUE_LENGTH) || defined (CONFIG_WITH_COMMANDS_FUNC)
|
---|
[1847] | 246 | char *variable_expand_for_file_2 (char *o, const char *line, unsigned int lenght,
|
---|
| 247 | struct file *file, unsigned int *value_lenp);
|
---|
[1440] | 248 | #endif
|
---|
[903] | 249 | char *allocated_variable_expand_for_file (const char *line, struct file *file);
|
---|
[1809] | 250 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[3140] | 251 | #define allocated_variable_expand(line) \
|
---|
[53] | 252 | allocated_variable_expand_for_file (line, (struct file *) 0)
|
---|
[1809] | 253 | #else /* CONFIG_WITH_VALUE_LENGTH */
|
---|
[1805] | 254 | # define allocated_variable_expand(line) \
|
---|
[1808] | 255 | allocated_variable_expand_2 (line, -1, NULL)
|
---|
[1931] | 256 | char *allocated_variable_expand_2 (const char *line, unsigned int length, unsigned int *value_lenp);
|
---|
| 257 | char *allocated_variable_expand_3 (const char *line, unsigned int length,
|
---|
| 258 | unsigned int *value_lenp, unsigned int *buffer_lengthp);
|
---|
| 259 | void recycle_variable_buffer (char *buffer, unsigned int length);
|
---|
[1809] | 260 | #endif /* CONFIG_WITH_VALUE_LENGTH */
|
---|
[903] | 261 | char *expand_argument (const char *str, const char *end);
|
---|
[1827] | 262 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[2591] | 263 | char *
|
---|
| 264 | variable_expand_string (char *line, const char *string, long length);
|
---|
[1827] | 265 | #else /* CONFIG_WITH_VALUE_LENGTH */
|
---|
[3140] | 266 | # include <k/kDefs.h>
|
---|
[2591] | 267 | char *
|
---|
| 268 | variable_expand_string_2 (char *line, const char *string, long length, char **eol);
|
---|
[3140] | 269 | K_INLINE char *variable_expand_string (char *line, const char *string, long length)
|
---|
[1827] | 270 | {
|
---|
| 271 | char *ignored;
|
---|
| 272 | return variable_expand_string_2 (line, string, length, &ignored);
|
---|
| 273 | }
|
---|
| 274 | #endif /* CONFIG_WITH_VALUE_LENGTH */
|
---|
[903] | 275 | void install_variable_buffer (char **bufp, unsigned int *lenp);
|
---|
| 276 | void restore_variable_buffer (char *buf, unsigned int len);
|
---|
[3140] | 277 | char *install_variable_buffer_with_hint (char **bufp, unsigned int *lenp, unsigned int size_hint); /* bird */
|
---|
| 278 | char *ensure_variable_buffer_space (char *ptr, unsigned int size); /* bird */
|
---|
[533] | 279 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[1809] | 280 | void append_expanded_string_to_variable (struct variable *v, const char *value,
|
---|
| 281 | unsigned int value_len, int append);
|
---|
[533] | 282 | #endif
|
---|
[53] | 283 |
|
---|
| 284 | /* function.c */
|
---|
[1827] | 285 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[903] | 286 | int handle_function (char **op, const char **stringp);
|
---|
[1827] | 287 | #else
|
---|
[1927] | 288 | int handle_function (char **op, const char **stringp, const char *nameend, const char *eol);
|
---|
[1827] | 289 | #endif
|
---|
[2768] | 290 | #ifdef CONFIG_WITH_COMPILER
|
---|
| 291 | typedef char *(*make_function_ptr_t) (char *, char **, const char *);
|
---|
| 292 | make_function_ptr_t lookup_function_for_compiler (const char *name, unsigned int len,
|
---|
| 293 | unsigned char *minargsp, unsigned char *maxargsp,
|
---|
| 294 | char *expargsp, const char **funcnamep);
|
---|
| 295 | #endif
|
---|
[903] | 296 | int pattern_matches (const char *pattern, const char *percent, const char *str);
|
---|
| 297 | char *subst_expand (char *o, const char *text, const char *subst,
|
---|
| 298 | const char *replace, unsigned int slen, unsigned int rlen,
|
---|
| 299 | int by_word);
|
---|
| 300 | char *patsubst_expand_pat (char *o, const char *text, const char *pattern,
|
---|
| 301 | const char *replace, const char *pattern_percent,
|
---|
| 302 | const char *replace_percent);
|
---|
| 303 | char *patsubst_expand (char *o, const char *text, char *pattern, char *replace);
|
---|
[3140] | 304 | char *func_shell_base (char *o, char **argv, int trim_newlines);
|
---|
| 305 | void shell_completed (int exit_code, int exit_sig);
|
---|
| 306 |
|
---|
| 307 | #ifdef CONFIG_WITH_COMMANDS_FUNC /* for append.c */
|
---|
[1440] | 308 | char *func_commands (char *o, char **argv, const char *funcname);
|
---|
| 309 | #endif
|
---|
[3140] | 310 |
|
---|
[1927] | 311 | #if defined (CONFIG_WITH_VALUE_LENGTH)
|
---|
| 312 | /* Avoid calling handle_function for every variable, do the
|
---|
| 313 | basic checks in variable_expand_string_2. */
|
---|
| 314 | extern char func_char_map[256];
|
---|
[3394] | 315 | # define MAX_FUNCTION_LENGTH 14
|
---|
[1927] | 316 | # define MIN_FUNCTION_LENGTH 2
|
---|
[3140] | 317 | K_INLINE const char *may_be_function_name (const char *name, const char *eos)
|
---|
[1927] | 318 | {
|
---|
| 319 | unsigned char ch;
|
---|
| 320 | unsigned int len = name - eos;
|
---|
[53] | 321 |
|
---|
[1927] | 322 | /* Minimum length is MIN + whitespace. Check this directly.
|
---|
| 323 | ASSUMES: MIN_FUNCTION_LENGTH == 2 */
|
---|
| 324 |
|
---|
| 325 | if (MY_PREDICT_TRUE(len < MIN_FUNCTION_LENGTH + 1
|
---|
| 326 | || !func_char_map[(int)(name[0])]
|
---|
| 327 | || !func_char_map[(int)(name[1])]))
|
---|
| 328 | return 0;
|
---|
| 329 | if (MY_PREDICT_TRUE(!func_char_map[ch = name[2]]))
|
---|
[3140] | 330 | return ISSPACE (ch) ? name + 2 : 0;
|
---|
[1927] | 331 |
|
---|
| 332 | name += 3;
|
---|
| 333 | if (len > MAX_FUNCTION_LENGTH)
|
---|
| 334 | len = MAX_FUNCTION_LENGTH - 3;
|
---|
| 335 | else if (len == 3)
|
---|
| 336 | len -= 3;
|
---|
| 337 | if (!len)
|
---|
| 338 | return 0;
|
---|
| 339 |
|
---|
| 340 | /* Loop over the remaining possiblities. */
|
---|
| 341 |
|
---|
| 342 | while (func_char_map[ch = *name])
|
---|
| 343 | {
|
---|
| 344 | if (!len--)
|
---|
| 345 | return 0;
|
---|
| 346 | name++;
|
---|
| 347 | }
|
---|
[3140] | 348 | if (ch == '\0' || ISBLANK (ch))
|
---|
[1927] | 349 | return name;
|
---|
| 350 | return 0;
|
---|
| 351 | }
|
---|
| 352 | #endif /* CONFIG_WITH_VALUE_LENGTH */
|
---|
| 353 |
|
---|
[53] | 354 | /* expand.c */
|
---|
[1827] | 355 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[903] | 356 | char *recursively_expand_for_file (struct variable *v, struct file *file);
|
---|
[53] | 357 | #define recursively_expand(v) recursively_expand_for_file (v, NULL)
|
---|
[1827] | 358 | #else
|
---|
| 359 | char *recursively_expand_for_file (struct variable *v, struct file *file,
|
---|
| 360 | unsigned int *value_lenp);
|
---|
[3140] | 361 | # define recursively_expand(v) recursively_expand_for_file (v, NULL, NULL)
|
---|
| 362 | #endif /* CONFIG_WITH_VALUE_LENGTH */
|
---|
[2769] | 363 | #ifdef CONFIG_WITH_COMPILER
|
---|
| 364 | char *reference_recursive_variable (char *o, struct variable *v);
|
---|
| 365 | #endif
|
---|
[53] | 366 |
|
---|
| 367 | /* variable.c */
|
---|
[903] | 368 | struct variable_set_list *create_new_variable_set (void);
|
---|
| 369 | void free_variable_set (struct variable_set_list *);
|
---|
| 370 | struct variable_set_list *push_new_variable_scope (void);
|
---|
| 371 | void pop_variable_scope (void);
|
---|
| 372 | void define_automatic_variables (void);
|
---|
| 373 | void initialize_file_variables (struct file *file, int reading);
|
---|
| 374 | void print_file_variables (const struct file *file);
|
---|
[3140] | 375 | void print_target_variables (const struct file *file);
|
---|
[903] | 376 | void merge_variable_set_lists (struct variable_set_list **to_list,
|
---|
| 377 | struct variable_set_list *from_list);
|
---|
[3140] | 378 | #ifdef KMK
|
---|
| 379 | void print_variable_set (struct variable_set *set, const char *prefix, int pauto);
|
---|
| 380 | #endif
|
---|
| 381 |
|
---|
[1809] | 382 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[3140] | 383 | struct variable *do_variable_definition (const floc *flocp,
|
---|
[903] | 384 | const char *name, const char *value,
|
---|
| 385 | enum variable_origin origin,
|
---|
| 386 | enum variable_flavor flavor,
|
---|
| 387 | int target_var);
|
---|
[1809] | 388 | #else /* CONFIG_WITH_VALUE_LENGTH */
|
---|
| 389 | # define do_variable_definition(flocp, varname, value, origin, flavor, target_var) \
|
---|
| 390 | do_variable_definition_2 ((flocp), (varname), (value), ~0U, 0, NULL, \
|
---|
| 391 | (origin), (flavor), (target_var))
|
---|
[3140] | 392 | struct variable *do_variable_definition_2 (const floc *flocp,
|
---|
[1809] | 393 | const char *varname,
|
---|
| 394 | const char *value,
|
---|
| 395 | unsigned int value_len,
|
---|
| 396 | int simple_value, char *free_value,
|
---|
| 397 | enum variable_origin origin,
|
---|
| 398 | enum variable_flavor flavor,
|
---|
| 399 | int target_var);
|
---|
[2591] | 400 | #endif /* CONFIG_WITH_VALUE_LENGTH */
|
---|
| 401 | char *parse_variable_definition (const char *line,
|
---|
[3140] | 402 | struct variable *v);
|
---|
| 403 | struct variable *assign_variable_definition (struct variable *v, const char *line IF_WITH_VALUE_LENGTH_PARAM(char *eos));
|
---|
| 404 | struct variable *try_variable_definition (const floc *flocp, const char *line
|
---|
[2591] | 405 | IF_WITH_VALUE_LENGTH_PARAM(char *eos),
|
---|
[903] | 406 | enum variable_origin origin,
|
---|
| 407 | int target_var);
|
---|
| 408 | void init_hash_global_variable_set (void);
|
---|
| 409 | void hash_init_function_table (void);
|
---|
[3140] | 410 | void define_new_function(const floc *flocp, const char *name,
|
---|
| 411 | unsigned int min, unsigned int max, unsigned int flags,
|
---|
| 412 | gmk_func_ptr func);
|
---|
[903] | 413 | struct variable *lookup_variable (const char *name, unsigned int length);
|
---|
| 414 | struct variable *lookup_variable_in_set (const char *name, unsigned int length,
|
---|
| 415 | const struct variable_set *set);
|
---|
[2769] | 416 | #ifdef CONFIG_WITH_STRCACHE2
|
---|
| 417 | struct variable *lookup_variable_strcached (const char *name);
|
---|
| 418 | #endif
|
---|
[53] | 419 |
|
---|
[531] | 420 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[1610] | 421 | void append_string_to_variable (struct variable *v, const char *value,
|
---|
| 422 | unsigned int value_len, int append);
|
---|
[3140] | 423 | struct variable * do_variable_definition_append (const floc *flocp, struct variable *v,
|
---|
[2717] | 424 | const char *value, unsigned int value_len,
|
---|
| 425 | int simple_value, enum variable_origin origin,
|
---|
| 426 | int append);
|
---|
[531] | 427 |
|
---|
[903] | 428 | struct variable *define_variable_in_set (const char *name, unsigned int length,
|
---|
| 429 | const char *value,
|
---|
| 430 | unsigned int value_length,
|
---|
| 431 | int duplicate_value,
|
---|
| 432 | enum variable_origin origin,
|
---|
| 433 | int recursive,
|
---|
| 434 | struct variable_set *set,
|
---|
[3140] | 435 | const floc *flocp);
|
---|
[53] | 436 |
|
---|
| 437 | /* Define a variable in the current variable set. */
|
---|
| 438 |
|
---|
| 439 | #define define_variable(n,l,v,o,r) \
|
---|
[903] | 440 | define_variable_in_set((n),(l),(v),~0U,1,(o),(r),\
|
---|
[531] | 441 | current_variable_set_list->set,NILF)
|
---|
| 442 |
|
---|
| 443 | #define define_variable_vl(n,l,v,vl,dv,o,r) \
|
---|
| 444 | define_variable_in_set((n),(l),(v),(vl),(dv),(o),(r),\
|
---|
| 445 | current_variable_set_list->set,NILF)
|
---|
| 446 |
|
---|
[2591] | 447 | /* Define a variable with a constant name in the current variable set. */
|
---|
| 448 |
|
---|
| 449 | #define define_variable_cname(n,v,o,r) \
|
---|
| 450 | define_variable_in_set((n),(sizeof (n) - 1),(v),~0U,1,(o),(r),\
|
---|
| 451 | current_variable_set_list->set,NILF)
|
---|
| 452 |
|
---|
[531] | 453 | /* Define a variable with a location in the current variable set. */
|
---|
| 454 |
|
---|
| 455 | #define define_variable_loc(n,l,v,o,r,f) \
|
---|
| 456 | define_variable_in_set((n),(l),(v),~0U,1,(o),(r),\
|
---|
| 457 | current_variable_set_list->set,(f))
|
---|
| 458 |
|
---|
| 459 | /* Define a variable with a location in the global variable set. */
|
---|
| 460 |
|
---|
| 461 | #define define_variable_global(n,l,v,o,r,f) \
|
---|
| 462 | define_variable_in_set((n),(l),(v),~0U,1,(o),(r),NULL,(f))
|
---|
| 463 |
|
---|
| 464 | #define define_variable_vl_global(n,l,v,vl,dv,o,r,f) \
|
---|
| 465 | define_variable_in_set((n),(l),(v),(vl),(dv),(o),(r),NULL,(f))
|
---|
| 466 |
|
---|
| 467 | /* Define a variable in FILE's variable set. */
|
---|
| 468 |
|
---|
| 469 | #define define_variable_for_file(n,l,v,o,r,f) \
|
---|
| 470 | define_variable_in_set((n),(l),(v),~0U,1,(o),(r),(f)->variables->set,NILF)
|
---|
| 471 |
|
---|
[903] | 472 | #else /* !CONFIG_WITH_VALUE_LENGTH */
|
---|
[531] | 473 |
|
---|
[903] | 474 | struct variable *define_variable_in_set (const char *name, unsigned int length,
|
---|
| 475 | const char *value,
|
---|
| 476 | enum variable_origin origin,
|
---|
| 477 | int recursive,
|
---|
| 478 | struct variable_set *set,
|
---|
[3140] | 479 | const floc *flocp);
|
---|
[531] | 480 |
|
---|
| 481 | /* Define a variable in the current variable set. */
|
---|
| 482 |
|
---|
| 483 | #define define_variable(n,l,v,o,r) \
|
---|
[53] | 484 | define_variable_in_set((n),(l),(v),(o),(r),\
|
---|
[903] | 485 | current_variable_set_list->set,NILF) /* force merge conflict */
|
---|
[53] | 486 |
|
---|
[2591] | 487 | /* Define a variable with a constant name in the current variable set. */
|
---|
| 488 |
|
---|
| 489 | #define define_variable_cname(n,v,o,r) \
|
---|
| 490 | define_variable_in_set((n),(sizeof (n) - 1),(v),(o),(r),\
|
---|
| 491 | current_variable_set_list->set,NILF) /* force merge conflict */
|
---|
| 492 |
|
---|
[53] | 493 | /* Define a variable with a location in the current variable set. */
|
---|
| 494 |
|
---|
| 495 | #define define_variable_loc(n,l,v,o,r,f) \
|
---|
| 496 | define_variable_in_set((n),(l),(v),(o),(r),\
|
---|
[903] | 497 | current_variable_set_list->set,(f)) /* force merge conflict */
|
---|
[53] | 498 |
|
---|
| 499 | /* Define a variable with a location in the global variable set. */
|
---|
| 500 |
|
---|
| 501 | #define define_variable_global(n,l,v,o,r,f) \
|
---|
[903] | 502 | define_variable_in_set((n),(l),(v),(o),(r),NULL,(f)) /* force merge conflict */
|
---|
[53] | 503 |
|
---|
| 504 | /* Define a variable in FILE's variable set. */
|
---|
| 505 |
|
---|
| 506 | #define define_variable_for_file(n,l,v,o,r,f) \
|
---|
[903] | 507 | define_variable_in_set((n),(l),(v),(o),(r),(f)->variables->set,NILF) /* force merge conflict */
|
---|
[53] | 508 |
|
---|
[903] | 509 | #endif /* !CONFIG_WITH_VALUE_LENGTH */
|
---|
[531] | 510 |
|
---|
[2591] | 511 | void undefine_variable_in_set (const char *name, unsigned int length,
|
---|
[3140] | 512 | enum variable_origin origin,
|
---|
| 513 | struct variable_set *set);
|
---|
[2591] | 514 |
|
---|
| 515 | /* Remove variable from the current variable set. */
|
---|
| 516 |
|
---|
| 517 | #define undefine_variable_global(n,l,o) \
|
---|
| 518 | undefine_variable_in_set((n),(l),(o),NULL)
|
---|
| 519 |
|
---|
[2718] | 520 | #ifdef KMK
|
---|
| 521 | struct variable *
|
---|
| 522 | define_variable_alias_in_set (const char *name, unsigned int length,
|
---|
| 523 | struct variable *target, enum variable_origin origin,
|
---|
[3140] | 524 | struct variable_set *set, const floc *flocp);
|
---|
[2718] | 525 | #endif
|
---|
| 526 |
|
---|
[53] | 527 | /* Warn that NAME is an undefined variable. */
|
---|
| 528 |
|
---|
| 529 | #define warn_undefined(n,l) do{\
|
---|
[3140] | 530 | if (warn_undefined_variables_flag) \
|
---|
| 531 | error (reading_file, (l), \
|
---|
| 532 | _("warning: undefined variable '%.*s'"), \
|
---|
| 533 | (int)(l), (n)); \
|
---|
[53] | 534 | }while(0)
|
---|
| 535 |
|
---|
[903] | 536 | char **target_environment (struct file *file);
|
---|
[53] | 537 |
|
---|
[903] | 538 | struct pattern_var *create_pattern_var (const char *target,
|
---|
| 539 | const char *suffix);
|
---|
[53] | 540 |
|
---|
| 541 | extern int export_all_variables;
|
---|
[1946] | 542 | #ifdef CONFIG_WITH_STRCACHE2
|
---|
| 543 | extern struct strcache2 variable_strcache;
|
---|
| 544 | #endif
|
---|
[53] | 545 |
|
---|
[1503] | 546 | #ifdef KMK
|
---|
| 547 | # define MAKELEVEL_NAME "KMK_LEVEL"
|
---|
| 548 | #else
|
---|
[53] | 549 | #define MAKELEVEL_NAME "MAKELEVEL"
|
---|
[1503] | 550 | #endif
|
---|
[3140] | 551 | #define MAKELEVEL_LENGTH (CSTRLEN (MAKELEVEL_NAME))
|
---|