[53] | 1 | /* Internals of variables for 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 |
|
---|
[3140] | 17 | #include "makeint.h"
|
---|
[503] | 18 |
|
---|
| 19 | #include <assert.h>
|
---|
| 20 |
|
---|
[3140] | 21 | #include "filedef.h"
|
---|
[53] | 22 | #include "dep.h"
|
---|
| 23 | #include "job.h"
|
---|
| 24 | #include "commands.h"
|
---|
| 25 | #include "variable.h"
|
---|
| 26 | #include "rule.h"
|
---|
| 27 | #ifdef WINDOWS32
|
---|
| 28 | #include "pathstuff.h"
|
---|
| 29 | #endif
|
---|
| 30 | #include "hash.h"
|
---|
[917] | 31 | #ifdef KMK
|
---|
| 32 | # include "kbuild.h"
|
---|
[2451] | 33 | # ifdef WINDOWS32
|
---|
| 34 | # include <Windows.h>
|
---|
| 35 | # else
|
---|
| 36 | # include <sys/utsname.h>
|
---|
| 37 | # endif
|
---|
[917] | 38 | #endif
|
---|
[1915] | 39 | #ifdef CONFIG_WITH_STRCACHE2
|
---|
| 40 | # include <stddef.h>
|
---|
| 41 | #endif
|
---|
[2765] | 42 | #ifdef CONFIG_WITH_COMPILER
|
---|
| 43 | # include "kmk_cc_exec.h"
|
---|
| 44 | #endif
|
---|
[53] | 45 |
|
---|
[2718] | 46 | #ifdef KMK
|
---|
| 47 | /** Gets the real variable if alias. For use when looking up variables. */
|
---|
| 48 | # define RESOLVE_ALIAS_VARIABLE(v) \
|
---|
| 49 | do { \
|
---|
| 50 | if ((v) != NULL && (v)->alias) \
|
---|
| 51 | { \
|
---|
| 52 | (v) = (struct variable *)(v)->value; \
|
---|
| 53 | assert ((v)->aliased); \
|
---|
| 54 | assert (!(v)->alias); \
|
---|
| 55 | } \
|
---|
| 56 | } while (0)
|
---|
| 57 | #endif
|
---|
| 58 |
|
---|
[2893] | 59 | #ifdef KMK
|
---|
| 60 | /* Incremented every time a variable is modified, so that target_environment
|
---|
| 61 | knows when to regenerate the table of exported global variables. */
|
---|
| 62 | static size_t global_variable_generation = 0;
|
---|
| 63 | #endif
|
---|
[2718] | 64 |
|
---|
[3140] | 65 | /* Incremented every time we add or remove a global variable. */
|
---|
| 66 | static unsigned long variable_changenum;
|
---|
[2893] | 67 |
|
---|
[53] | 68 | /* Chain of all pattern-specific variables. */
|
---|
| 69 |
|
---|
| 70 | static struct pattern_var *pattern_vars;
|
---|
| 71 |
|
---|
[2591] | 72 | /* Pointer to the last struct in the pack of a specific size, from 1 to 255.*/
|
---|
[53] | 73 |
|
---|
[2591] | 74 | static struct pattern_var *last_pattern_vars[256];
|
---|
[53] | 75 |
|
---|
[2591] | 76 | /* Create a new pattern-specific variable struct. The new variable is
|
---|
| 77 | inserted into the PATTERN_VARS list in the shortest patterns first
|
---|
| 78 | order to support the shortest stem matching (the variables are
|
---|
| 79 | matched in the reverse order so the ones with the longest pattern
|
---|
| 80 | will be considered first). Variables with the same pattern length
|
---|
| 81 | are inserted in the definition order. */
|
---|
[53] | 82 |
|
---|
| 83 | struct pattern_var *
|
---|
[903] | 84 | create_pattern_var (const char *target, const char *suffix)
|
---|
[53] | 85 | {
|
---|
[2591] | 86 | register unsigned int len = strlen (target);
|
---|
[903] | 87 | register struct pattern_var *p = xmalloc (sizeof (struct pattern_var));
|
---|
[53] | 88 |
|
---|
[2591] | 89 | if (pattern_vars != 0)
|
---|
| 90 | {
|
---|
| 91 | if (len < 256 && last_pattern_vars[len] != 0)
|
---|
| 92 | {
|
---|
| 93 | p->next = last_pattern_vars[len]->next;
|
---|
| 94 | last_pattern_vars[len]->next = p;
|
---|
| 95 | }
|
---|
| 96 | else
|
---|
| 97 | {
|
---|
| 98 | /* Find the position where we can insert this variable. */
|
---|
| 99 | register struct pattern_var **v;
|
---|
| 100 |
|
---|
| 101 | for (v = &pattern_vars; ; v = &(*v)->next)
|
---|
| 102 | {
|
---|
| 103 | /* Insert at the end of the pack so that patterns with the
|
---|
| 104 | same length appear in the order they were defined .*/
|
---|
| 105 |
|
---|
| 106 | if (*v == 0 || (*v)->len > len)
|
---|
| 107 | {
|
---|
| 108 | p->next = *v;
|
---|
| 109 | *v = p;
|
---|
| 110 | break;
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
[53] | 115 | else
|
---|
[2591] | 116 | {
|
---|
| 117 | pattern_vars = p;
|
---|
| 118 | p->next = 0;
|
---|
| 119 | }
|
---|
[53] | 120 |
|
---|
| 121 | p->target = target;
|
---|
[2591] | 122 | p->len = len;
|
---|
[53] | 123 | p->suffix = suffix + 1;
|
---|
| 124 |
|
---|
[2591] | 125 | if (len < 256)
|
---|
| 126 | last_pattern_vars[len] = p;
|
---|
| 127 |
|
---|
[53] | 128 | return p;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | /* Look up a target in the pattern-specific variable list. */
|
---|
| 132 |
|
---|
| 133 | static struct pattern_var *
|
---|
[903] | 134 | lookup_pattern_var (struct pattern_var *start, const char *target)
|
---|
[53] | 135 | {
|
---|
| 136 | struct pattern_var *p;
|
---|
[3140] | 137 | unsigned int targlen = strlen (target);
|
---|
[53] | 138 |
|
---|
| 139 | for (p = start ? start->next : pattern_vars; p != 0; p = p->next)
|
---|
| 140 | {
|
---|
[903] | 141 | const char *stem;
|
---|
[53] | 142 | unsigned int stemlen;
|
---|
| 143 |
|
---|
| 144 | if (p->len > targlen)
|
---|
| 145 | /* It can't possibly match. */
|
---|
| 146 | continue;
|
---|
| 147 |
|
---|
| 148 | /* From the lengths of the filename and the pattern parts,
|
---|
| 149 | find the stem: the part of the filename that matches the %. */
|
---|
| 150 | stem = target + (p->suffix - p->target - 1);
|
---|
| 151 | stemlen = targlen - p->len + 1;
|
---|
| 152 |
|
---|
| 153 | /* Compare the text in the pattern before the stem, if any. */
|
---|
| 154 | if (stem > target && !strneq (p->target, target, stem - target))
|
---|
| 155 | continue;
|
---|
| 156 |
|
---|
| 157 | /* Compare the text in the pattern after the stem, if any.
|
---|
| 158 | We could test simply using streq, but this way we compare the
|
---|
| 159 | first two characters immediately. This saves time in the very
|
---|
| 160 | common case where the first character matches because it is a
|
---|
| 161 | period. */
|
---|
| 162 | if (*p->suffix == stem[stemlen]
|
---|
| 163 | && (*p->suffix == '\0' || streq (&p->suffix[1], &stem[stemlen+1])))
|
---|
| 164 | break;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | return p;
|
---|
| 168 | }
|
---|
| 169 | |
---|
[1887] | 170 |
|
---|
[1946] | 171 | #ifdef CONFIG_WITH_STRCACHE2
|
---|
[1887] | 172 | struct strcache2 variable_strcache;
|
---|
| 173 | #endif
|
---|
[53] | 174 |
|
---|
| 175 | /* Hash table of all global variable definitions. */
|
---|
[1902] | 176 |
|
---|
[53] | 177 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
| 178 | static unsigned long
|
---|
| 179 | variable_hash_1 (const void *keyv)
|
---|
| 180 | {
|
---|
[1889] | 181 | struct variable const *key = (struct variable const *) keyv;
|
---|
[53] | 182 | return_STRING_N_HASH_1 (key->name, key->length);
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | static unsigned long
|
---|
| 186 | variable_hash_2 (const void *keyv)
|
---|
| 187 | {
|
---|
| 188 | struct variable const *key = (struct variable const *) keyv;
|
---|
| 189 | return_STRING_N_HASH_2 (key->name, key->length);
|
---|
| 190 | }
|
---|
[1886] | 191 |
|
---|
[1829] | 192 | static int
|
---|
| 193 | variable_hash_cmp (const void *xv, const void *yv)
|
---|
| 194 | {
|
---|
| 195 | struct variable const *x = (struct variable const *) xv;
|
---|
[1886] | 196 | struct variable const *y = (struct variable const *) yv;
|
---|
| 197 | int result = x->length - y->length;
|
---|
| 198 | if (result)
|
---|
[1829] | 199 | return result;
|
---|
[1886] | 200 |
|
---|
[53] | 201 | return_STRING_N_COMPARE (x->name, y->name, x->length);
|
---|
[1902] | 202 | }
|
---|
[53] | 203 | #endif /* !CONFIG_WITH_STRCACHE2 */
|
---|
[3140] | 204 |
|
---|
[1793] | 205 | #ifndef VARIABLE_BUCKETS
|
---|
[3140] | 206 | # ifdef KMK /* Move to Makefile.kmk? (insanely high, but wtf, it gets the collitions down) */
|
---|
[903] | 207 | # define VARIABLE_BUCKETS 65535
|
---|
[3140] | 208 | # else /*!KMK*/
|
---|
[903] | 209 | #define VARIABLE_BUCKETS 523
|
---|
[53] | 210 | # endif /*!KMK*/
|
---|
[3140] | 211 | #endif
|
---|
[1449] | 212 | #ifndef PERFILE_VARIABLE_BUCKETS
|
---|
[3140] | 213 | # ifdef KMK /* Move to Makefile.kmk? */
|
---|
[1449] | 214 | # define PERFILE_VARIABLE_BUCKETS 127
|
---|
[3140] | 215 | # else
|
---|
[1536] | 216 | #define PERFILE_VARIABLE_BUCKETS 23
|
---|
[53] | 217 | # endif
|
---|
[3140] | 218 | #endif
|
---|
[1444] | 219 | #ifndef SMALL_SCOPE_VARIABLE_BUCKETS
|
---|
[1793] | 220 | # ifdef KMK /* Move to Makefile.kmk? */
|
---|
[1444] | 221 | # define SMALL_SCOPE_VARIABLE_BUCKETS 63
|
---|
[3140] | 222 | # else
|
---|
[1536] | 223 | #define SMALL_SCOPE_VARIABLE_BUCKETS 13
|
---|
[53] | 224 | # endif
|
---|
[2893] | 225 | #endif
|
---|
| 226 | #ifndef ENVIRONMENT_VARIABLE_BUCKETS /* added by bird. */
|
---|
| 227 | # define ENVIRONMENT_VARIABLE_BUCKETS 256
|
---|
[53] | 228 | #endif
|
---|
[2717] | 229 |
|
---|
| 230 |
|
---|
| 231 | #ifdef KMK /* Drop the 'static' */
|
---|
| 232 | struct variable_set global_variable_set;
|
---|
| 233 | struct variable_set_list global_setlist
|
---|
[53] | 234 | #else
|
---|
| 235 | static struct variable_set global_variable_set;
|
---|
[2717] | 236 | static struct variable_set_list global_setlist
|
---|
[2591] | 237 | #endif
|
---|
[53] | 238 | = { 0, &global_variable_set, 0 };
|
---|
| 239 | struct variable_set_list *current_variable_set_list = &global_setlist;
|
---|
| 240 | |
---|
| 241 |
|
---|
| 242 | /* Implement variables. */
|
---|
| 243 |
|
---|
| 244 | void
|
---|
[1902] | 245 | init_hash_global_variable_set (void)
|
---|
[903] | 246 | {
|
---|
[3140] | 247 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[1902] | 248 | hash_init (&global_variable_set.table, VARIABLE_BUCKETS,
|
---|
[3090] | 249 | variable_hash_1, variable_hash_2, variable_hash_cmp);
|
---|
[1902] | 250 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
| 251 | strcache2_init (&variable_strcache, "variable", 262144, 0, 0, 0);
|
---|
| 252 | hash_init_strcached (&global_variable_set.table, VARIABLE_BUCKETS,
|
---|
[53] | 253 | &variable_strcache, offsetof (struct variable, name));
|
---|
| 254 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | /* Define variable named NAME with value VALUE in SET. VALUE is copied.
|
---|
| 258 | LENGTH is the length of NAME, which does not need to be null-terminated.
|
---|
| 259 | ORIGIN specifies the origin of the variable (makefile, command line
|
---|
| 260 | or environment).
|
---|
| 261 | If RECURSIVE is nonzero a flag is set in the variable saying
|
---|
[531] | 262 | that it should be recursively re-expanded. */
|
---|
[53] | 263 |
|
---|
| 264 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[1809] | 265 | struct variable *
|
---|
| 266 | define_variable_in_set (const char *name, unsigned int length,
|
---|
| 267 | const char *value, unsigned int value_len,
|
---|
[3140] | 268 | int duplicate_value, enum variable_origin origin,
|
---|
[531] | 269 | int recursive, struct variable_set *set,
|
---|
| 270 | const floc *flocp)
|
---|
| 271 | #else
|
---|
[903] | 272 | struct variable *
|
---|
[534] | 273 | define_variable_in_set (const char *name, unsigned int length,
|
---|
[3140] | 274 | const char *value, enum variable_origin origin,
|
---|
[534] | 275 | int recursive, struct variable_set *set,
|
---|
[53] | 276 | const floc *flocp)
|
---|
| 277 | #endif
|
---|
| 278 | {
|
---|
| 279 | struct variable *v;
|
---|
| 280 | struct variable **var_slot;
|
---|
[2893] | 281 | struct variable var_key;
|
---|
| 282 |
|
---|
| 283 | #ifdef KMK
|
---|
| 284 | if (set == NULL || set == &global_variable_set)
|
---|
| 285 | global_variable_generation++;
|
---|
[2717] | 286 | #endif
|
---|
| 287 |
|
---|
| 288 | if (env_overrides && origin == o_env)
|
---|
[2549] | 289 | origin = o_env_override;
|
---|
[53] | 290 |
|
---|
| 291 | #ifndef KMK
|
---|
[2717] | 292 | if (set == NULL)
|
---|
| 293 | set = &global_variable_set;
|
---|
| 294 | #else /* KMK */
|
---|
| 295 | /* Intercept kBuild object variable definitions. */
|
---|
| 296 | if (name[0] == '[' && length > 3)
|
---|
| 297 | {
|
---|
| 298 | v = try_define_kbuild_object_variable_via_accessor (name, length,
|
---|
| 299 | value, value_len, duplicate_value,
|
---|
| 300 | origin, recursive, flocp);
|
---|
| 301 | if (v != VAR_NOT_KBUILD_ACCESSOR)
|
---|
[2549] | 302 | return v;
|
---|
| 303 | }
|
---|
[2717] | 304 | if (set == NULL)
|
---|
| 305 | {
|
---|
| 306 | if (g_pTopKbEvalData)
|
---|
| 307 | return define_kbuild_object_variable_in_top_obj (name, length,
|
---|
[2549] | 308 | value, value_len, duplicate_value,
|
---|
| 309 | origin, recursive, flocp);
|
---|
[2717] | 310 | set = &global_variable_set;
|
---|
[2549] | 311 | }
|
---|
[1886] | 312 | #endif /* KMK */
|
---|
[53] | 313 |
|
---|
| 314 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
| 315 | var_key.name = (char *) name;
|
---|
[3140] | 316 | var_key.length = length;
|
---|
[53] | 317 | var_slot = (struct variable **) hash_find_slot (&set->table, &var_key);
|
---|
[3140] | 318 | v = *var_slot;
|
---|
| 319 |
|
---|
| 320 | #ifdef VMS
|
---|
| 321 | /* VMS does not populate envp[] with DCL symbols and logical names which
|
---|
| 322 | historically are mapped to environent variables.
|
---|
| 323 | If the variable is not yet defined, then we need to check if getenv()
|
---|
| 324 | can find it. Do not do this for origin == o_env to avoid infinte
|
---|
| 325 | recursion */
|
---|
| 326 | if (HASH_VACANT (v) && (origin != o_env))
|
---|
| 327 | {
|
---|
| 328 | struct variable * vms_variable;
|
---|
| 329 | char * vname = alloca (length + 1);
|
---|
| 330 | char * vvalue;
|
---|
| 331 |
|
---|
| 332 | strncpy (vname, name, length);
|
---|
| 333 | vvalue = getenv(vname);
|
---|
| 334 |
|
---|
| 335 | /* Values starting with '$' are probably foreign commands.
|
---|
| 336 | We want to treat them as Shell aliases and not look them up here */
|
---|
| 337 | if ((vvalue != NULL) && (vvalue[0] != '$'))
|
---|
| 338 | {
|
---|
| 339 | vms_variable = lookup_variable(name, length);
|
---|
| 340 | /* Refresh the slot */
|
---|
| 341 | var_slot = (struct variable **) hash_find_slot (&set->table,
|
---|
| 342 | &var_key);
|
---|
| 343 | v = *var_slot;
|
---|
| 344 | }
|
---|
| 345 | }
|
---|
[2717] | 346 | #endif
|
---|
| 347 |
|
---|
[53] | 348 | /* if (env_overrides && origin == o_env)
|
---|
[1890] | 349 | origin = o_env_override; - bird moved this up */
|
---|
[2717] | 350 |
|
---|
[1890] | 351 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
[2717] | 352 | name = strcache2_add (&variable_strcache, name, length);
|
---|
[1890] | 353 | if ( set != &global_variable_set
|
---|
[2717] | 354 | || !(v = strcache2_get_user_val (&variable_strcache, name)))
|
---|
| 355 | {
|
---|
[1902] | 356 | var_key.name = name;
|
---|
[1890] | 357 | var_key.length = length;
|
---|
| 358 | var_slot = (struct variable **) hash_find_slot_strcached (&set->table, &var_key);
|
---|
| 359 | v = *var_slot;
|
---|
[1915] | 360 | }
|
---|
| 361 | else
|
---|
| 362 | {
|
---|
| 363 | assert (!v || (v->name == name && !HASH_VACANT (v)));
|
---|
[1890] | 364 | var_slot = 0;
|
---|
[53] | 365 | }
|
---|
| 366 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
[2718] | 367 | if (! HASH_VACANT (v))
|
---|
| 368 | {
|
---|
| 369 | #ifdef KMK
|
---|
[53] | 370 | RESOLVE_ALIAS_VARIABLE(v);
|
---|
[3140] | 371 | #endif
|
---|
| 372 | if (env_overrides && v->origin == o_env)
|
---|
| 373 | /* V came from in the environment. Since it was defined
|
---|
[53] | 374 | before the switches were parsed, it wasn't affected by -e. */
|
---|
| 375 | v->origin = o_env_override;
|
---|
[3140] | 376 |
|
---|
| 377 | /* A variable of this name is already defined.
|
---|
[53] | 378 | If the old definition is from a stronger source
|
---|
[3140] | 379 | than this one, don't redefine it. */
|
---|
[530] | 380 | if ((int) origin >= (int) v->origin)
|
---|
[1809] | 381 | {
|
---|
| 382 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[531] | 383 | if (value_len == ~0U)
|
---|
[1809] | 384 | value_len = strlen (value);
|
---|
[1932] | 385 | else
|
---|
[531] | 386 | assert (value_len == strlen (value));
|
---|
[1932] | 387 | if (!duplicate_value || duplicate_value == -1)
|
---|
| 388 | {
|
---|
| 389 | # ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
|
---|
| 390 | if (v->value != 0 && !v->rdonly_val)
|
---|
[1997] | 391 | free (v->value);
|
---|
[1932] | 392 | v->rdonly_val = duplicate_value == -1;
|
---|
| 393 | v->value = (char *) value;
|
---|
[531] | 394 | v->value_alloc_len = 0;
|
---|
| 395 | # else
|
---|
[1997] | 396 | if (v->value != 0)
|
---|
[1809] | 397 | free (v->value);
|
---|
[1932] | 398 | v->value = (char *) value;
|
---|
[531] | 399 | v->value_alloc_len = value_len + 1;
|
---|
| 400 | # endif
|
---|
| 401 | }
|
---|
[1997] | 402 | else
|
---|
[533] | 403 | {
|
---|
[1932] | 404 | if (v->value_alloc_len <= value_len)
|
---|
| 405 | {
|
---|
| 406 | # ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
|
---|
| 407 | if (v->rdonly_val)
|
---|
| 408 | v->rdonly_val = 0;
|
---|
| 409 | else
|
---|
[1997] | 410 | # endif
|
---|
[533] | 411 | free (v->value);
|
---|
[2004] | 412 | v->value_alloc_len = VAR_ALIGN_VALUE_ALLOC (value_len + 1);
|
---|
[533] | 413 | v->value = xmalloc (v->value_alloc_len);
|
---|
[1809] | 414 | MAKE_STATS_2(v->reallocs++);
|
---|
[531] | 415 | }
|
---|
[1809] | 416 | memcpy (v->value, value, value_len + 1);
|
---|
[1932] | 417 | }
|
---|
[3140] | 418 | v->value_length = value_len;
|
---|
| 419 | #else /* !CONFIG_WITH_VALUE_LENGTH */
|
---|
[1932] | 420 | free (v->value);
|
---|
[53] | 421 | v->value = xstrdup (value);
|
---|
| 422 | #endif /* !CONFIG_WITH_VALUE_LENGTH */
|
---|
| 423 | if (flocp != 0)
|
---|
| 424 | v->fileinfo = *flocp;
|
---|
[3140] | 425 | else
|
---|
| 426 | v->fileinfo.filenm = 0;
|
---|
| 427 | v->origin = origin;
|
---|
| 428 | v->recursive = recursive;
|
---|
[53] | 429 | VARIABLE_CHANGED (v);
|
---|
| 430 | }
|
---|
| 431 | return v;
|
---|
| 432 | }
|
---|
| 433 |
|
---|
[1864] | 434 | /* Create a new variable definition and add it to the hash table. */
|
---|
[903] | 435 |
|
---|
[1864] | 436 | #ifndef CONFIG_WITH_ALLOC_CACHES
|
---|
| 437 | v = xmalloc (sizeof (struct variable));
|
---|
| 438 | #else
|
---|
[1877] | 439 | v = alloccache_alloc (&variable_cache);
|
---|
[2591] | 440 | #endif
|
---|
[1877] | 441 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[1886] | 442 | v->name = xstrndup (name, length);
|
---|
[1877] | 443 | #else
|
---|
[53] | 444 | v->name = name; /* already cached. */
|
---|
| 445 | #endif
|
---|
[3140] | 446 | v->length = length;
|
---|
| 447 | hash_insert_at (&set->table, v, var_slot);
|
---|
| 448 | if (set == &global_variable_set)
|
---|
[530] | 449 | ++variable_changenum;
|
---|
[1809] | 450 |
|
---|
| 451 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[531] | 452 | if (value_len == ~0U)
|
---|
[1809] | 453 | value_len = strlen (value);
|
---|
| 454 | else
|
---|
[1932] | 455 | assert (value_len == strlen (value));
|
---|
[533] | 456 | v->value_length = value_len;
|
---|
[1932] | 457 | if (!duplicate_value || duplicate_value == -1)
|
---|
| 458 | {
|
---|
| 459 | # ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
|
---|
| 460 | v->rdonly_val = duplicate_value == -1;
|
---|
[903] | 461 | v->value_alloc_len = v->rdonly_val ? 0 : value_len + 1;
|
---|
[533] | 462 | # endif
|
---|
[531] | 463 | v->value = (char *)value;
|
---|
| 464 | }
|
---|
[1932] | 465 | else
|
---|
| 466 | {
|
---|
| 467 | # ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
|
---|
[1997] | 468 | v->rdonly_val = 0;
|
---|
[533] | 469 | # endif
|
---|
[1809] | 470 | v->value_alloc_len = VAR_ALIGN_VALUE_ALLOC (value_len + 1);
|
---|
[531] | 471 | v->value = xmalloc (v->value_alloc_len);
|
---|
[1997] | 472 | memcpy (v->value, value, value_len + 1);
|
---|
[53] | 473 | }
|
---|
[1997] | 474 | #else /* !CONFIG_WITH_VALUE_LENGTH */
|
---|
[53] | 475 | v->value = xstrdup (value);
|
---|
| 476 | #endif /* !CONFIG_WITH_VALUE_LENGTH */
|
---|
| 477 | if (flocp != 0)
|
---|
| 478 | v->fileinfo = *flocp;
|
---|
| 479 | else
|
---|
| 480 | v->fileinfo.filenm = 0;
|
---|
| 481 | v->origin = origin;
|
---|
| 482 | v->recursive = recursive;
|
---|
| 483 | v->special = 0;
|
---|
| 484 | v->expanding = 0;
|
---|
| 485 | v->exp_count = 0;
|
---|
[2591] | 486 | v->per_target = 0;
|
---|
[2718] | 487 | v->append = 0;
|
---|
| 488 | v->private_var = 0;
|
---|
| 489 | #ifdef KMK
|
---|
| 490 | v->alias = 0;
|
---|
[53] | 491 | v->aliased = 0;
|
---|
[2765] | 492 | #endif
|
---|
[2771] | 493 | v->export = v_default;
|
---|
[2765] | 494 | #ifdef CONFIG_WITH_COMPILER
|
---|
| 495 | v->recursive_without_dollar = 0;
|
---|
| 496 | v->evalprog = 0;
|
---|
| 497 | v->expandprog = 0;
|
---|
| 498 | v->evalval_count = 0;
|
---|
| 499 | v->expand_count = 0;
|
---|
| 500 | #else
|
---|
| 501 | MAKE_STATS_2(v->expand_count = 0);
|
---|
[2004] | 502 | MAKE_STATS_2(v->evalval_count = 0);
|
---|
| 503 | #endif
|
---|
[2752] | 504 | MAKE_STATS_2(v->changes = 0);
|
---|
[2758] | 505 | MAKE_STATS_2(v->reallocs = 0);
|
---|
[53] | 506 | MAKE_STATS_2(v->references = 0);
|
---|
| 507 | MAKE_STATS_2(v->cTicksEvalVal = 0);
|
---|
| 508 |
|
---|
| 509 | v->exportable = 1;
|
---|
| 510 | if (*name != '_' && (*name < 'A' || *name > 'Z')
|
---|
| 511 | && (*name < 'a' || *name > 'z'))
|
---|
| 512 | v->exportable = 0;
|
---|
| 513 | else
|
---|
| 514 | {
|
---|
| 515 | for (++name; *name != '\0'; ++name)
|
---|
| 516 | if (*name != '_' && (*name < 'a' || *name > 'z')
|
---|
| 517 | && (*name < 'A' || *name > 'Z') && !ISDIGIT(*name))
|
---|
| 518 | break;
|
---|
| 519 |
|
---|
| 520 | if (*name != '\0')
|
---|
| 521 | v->exportable = 0;
|
---|
[1890] | 522 | }
|
---|
| 523 |
|
---|
| 524 | #ifdef CONFIG_WITH_STRCACHE2
|
---|
| 525 | /* If it's the global set, remember the variable. */
|
---|
| 526 | if (set == &global_variable_set)
|
---|
[53] | 527 | strcache2_set_user_val (&variable_strcache, v->name, v);
|
---|
| 528 | #endif
|
---|
| 529 | return v;
|
---|
[2591] | 530 | }
|
---|
| 531 | |
---|
| 532 |
|
---|
| 533 |
|
---|
| 534 | /* Undefine variable named NAME in SET. LENGTH is the length of NAME, which
|
---|
| 535 | does not need to be null-terminated. ORIGIN specifies the origin of the
|
---|
[3140] | 536 | variable (makefile, command line or environment). */
|
---|
| 537 |
|
---|
| 538 | static void
|
---|
| 539 | free_variable_name_and_value (const void *item)
|
---|
| 540 | {
|
---|
| 541 | struct variable *v = (struct variable *) item;
|
---|
| 542 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
| 543 | free (v->name);
|
---|
| 544 | #endif
|
---|
| 545 | #ifdef CONFIG_WITH_COMPILER
|
---|
| 546 | if (v->evalprog || v->expandprog)
|
---|
| 547 | kmk_cc_variable_deleted (v);
|
---|
| 548 | #endif
|
---|
| 549 | #ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
|
---|
| 550 | if (!v->rdonly_val)
|
---|
[2591] | 551 | #endif
|
---|
| 552 | free (v->value);
|
---|
[3140] | 553 | }
|
---|
| 554 |
|
---|
| 555 | void
|
---|
| 556 | free_variable_set (struct variable_set_list *list)
|
---|
| 557 | {
|
---|
| 558 | hash_map (&list->set->table, free_variable_name_and_value);
|
---|
| 559 | #ifndef CONFIG_WITH_ALLOC_CACHES
|
---|
| 560 | hash_free (&list->set->table, 1);
|
---|
| 561 | free (list->set);
|
---|
| 562 | free (list);
|
---|
| 563 | #else
|
---|
| 564 | hash_free_cached (&list->set->table, 1, &variable_cache);
|
---|
| 565 | alloccache_free (&variable_set_cache, list->set);
|
---|
| 566 | alloccache_free (&variable_set_list_cache, list);
|
---|
| 567 | #endif
|
---|
[2591] | 568 | }
|
---|
| 569 |
|
---|
| 570 | void
|
---|
| 571 | undefine_variable_in_set (const char *name, unsigned int length,
|
---|
| 572 | enum variable_origin origin,
|
---|
| 573 | struct variable_set *set)
|
---|
| 574 | {
|
---|
| 575 | struct variable *v;
|
---|
| 576 | struct variable **var_slot;
|
---|
| 577 | struct variable var_key;
|
---|
| 578 |
|
---|
[2717] | 579 | if (set == NULL)
|
---|
[2591] | 580 | set = &global_variable_set;
|
---|
| 581 |
|
---|
| 582 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[2717] | 583 | var_key.name = (char *) name;
|
---|
| 584 | var_key.length = length;
|
---|
| 585 | var_slot = (struct variable **) hash_find_slot (&set->table, &var_key);
|
---|
| 586 | #else
|
---|
| 587 | var_key.name = strcache2_lookup(&variable_strcache, name, length);
|
---|
| 588 | if (!var_key.name)
|
---|
| 589 | return;
|
---|
[2893] | 590 | var_key.length = length;
|
---|
| 591 | var_slot = (struct variable **) hash_find_slot_strcached (&set->table, &var_key);
|
---|
| 592 | #endif
|
---|
| 593 | #ifdef KMK
|
---|
[2591] | 594 | if (set == &global_variable_set)
|
---|
| 595 | global_variable_generation++;
|
---|
| 596 | #endif
|
---|
| 597 |
|
---|
| 598 | if (env_overrides && origin == o_env)
|
---|
| 599 | origin = o_env_override;
|
---|
| 600 |
|
---|
[2718] | 601 | v = *var_slot;
|
---|
| 602 | if (! HASH_VACANT (v))
|
---|
| 603 | {
|
---|
| 604 | #ifdef KMK
|
---|
[3140] | 605 | if (v->aliased || v->alias)
|
---|
[2718] | 606 | {
|
---|
[3140] | 607 | if (v->aliased)
|
---|
[2718] | 608 | OS (error, NULL, _("Cannot undefine the aliased variable '%s'"), v->name);
|
---|
| 609 | else
|
---|
| 610 | OS (error, NULL, _("Cannot undefine the variable alias '%s'"), v->name);
|
---|
| 611 | return;
|
---|
[2591] | 612 | }
|
---|
[3140] | 613 | #endif
|
---|
| 614 |
|
---|
| 615 | if (env_overrides && v->origin == o_env)
|
---|
[2591] | 616 | /* V came from in the environment. Since it was defined
|
---|
[3140] | 617 | before the switches were parsed, it wasn't affected by -e. */
|
---|
| 618 | v->origin = o_env_override;
|
---|
[2591] | 619 |
|
---|
[3140] | 620 | /* Undefine only if this undefinition is from an equal or stronger
|
---|
[2591] | 621 | source than the variable definition. */
|
---|
[2717] | 622 | if ((int) origin >= (int) v->origin)
|
---|
| 623 | {
|
---|
| 624 | hash_delete_at (&set->table, var_slot);
|
---|
| 625 | #ifdef CONFIG_WITH_STRCACHE2
|
---|
[2591] | 626 | if (set == &global_variable_set)
|
---|
[3302] | 627 | strcache2_set_user_val (&variable_strcache, v->name, NULL);
|
---|
[3140] | 628 | #endif
|
---|
[3302] | 629 | free_variable_name_and_value (v);
|
---|
| 630 | #ifndef CONFIG_WITH_ALLOC_CACHES
|
---|
| 631 | free (v);
|
---|
[3140] | 632 | #else
|
---|
| 633 | alloccache_free (&variable_cache, v);
|
---|
| 634 | #endif
|
---|
[2591] | 635 | if (set == &global_variable_set)
|
---|
| 636 | ++variable_changenum;
|
---|
| 637 | }
|
---|
[2718] | 638 | }
|
---|
| 639 | }
|
---|
| 640 |
|
---|
| 641 | #ifdef KMK
|
---|
| 642 | /* Define variable named NAME as an alias of the variable TARGET.
|
---|
| 643 | SET defaults to the global set if NULL. FLOCP is just for completeness. */
|
---|
| 644 |
|
---|
[3140] | 645 | struct variable *
|
---|
[2718] | 646 | define_variable_alias_in_set (const char *name, unsigned int length,
|
---|
| 647 | struct variable *target, enum variable_origin origin,
|
---|
| 648 | struct variable_set *set, const floc *flocp)
|
---|
| 649 | {
|
---|
[2893] | 650 | struct variable *v;
|
---|
| 651 | struct variable **var_slot;
|
---|
| 652 |
|
---|
| 653 | #ifdef KMK
|
---|
| 654 | if (set == NULL || set == &global_variable_set)
|
---|
[2718] | 655 | global_variable_generation++;
|
---|
| 656 | #endif
|
---|
| 657 |
|
---|
| 658 | /* Look it up the hash table slot for it. */
|
---|
| 659 | name = strcache2_add (&variable_strcache, name, length);
|
---|
| 660 | if ( set != &global_variable_set
|
---|
| 661 | || !(v = strcache2_get_user_val (&variable_strcache, name)))
|
---|
| 662 | {
|
---|
| 663 | struct variable var_key;
|
---|
| 664 |
|
---|
| 665 | var_key.name = name;
|
---|
| 666 | var_key.length = length;
|
---|
| 667 | var_slot = (struct variable **) hash_find_slot_strcached (&set->table, &var_key);
|
---|
| 668 | v = *var_slot;
|
---|
| 669 | }
|
---|
| 670 | else
|
---|
| 671 | {
|
---|
| 672 | assert (!v || (v->name == name && !HASH_VACANT (v)));
|
---|
| 673 | var_slot = 0;
|
---|
| 674 | }
|
---|
| 675 | if (! HASH_VACANT (v))
|
---|
| 676 | {
|
---|
| 677 | /* A variable of this name is already defined.
|
---|
| 678 | If the old definition is from a stronger source
|
---|
| 679 | than this one, don't redefine it. */
|
---|
| 680 |
|
---|
| 681 | if (env_overrides && v->origin == o_env)
|
---|
| 682 | /* V came from in the environment. Since it was defined
|
---|
| 683 | before the switches were parsed, it wasn't affected by -e. */
|
---|
| 684 | v->origin = o_env_override;
|
---|
| 685 |
|
---|
| 686 | if ((int) origin < (int) v->origin)
|
---|
| 687 | return v;
|
---|
[2770] | 688 |
|
---|
[2718] | 689 | if (v->value != 0 && !v->rdonly_val)
|
---|
| 690 | free (v->value);
|
---|
| 691 | VARIABLE_CHANGED (v);
|
---|
| 692 | }
|
---|
| 693 | else
|
---|
| 694 | {
|
---|
| 695 | /* Create a new variable definition and add it to the hash table. */
|
---|
| 696 | v = alloccache_alloc (&variable_cache);
|
---|
| 697 | v->name = name; /* already cached. */
|
---|
| 698 | v->length = length;
|
---|
| 699 | hash_insert_at (&set->table, v, var_slot);
|
---|
| 700 | v->special = 0;
|
---|
| 701 | v->expanding = 0;
|
---|
| 702 | v->exp_count = 0;
|
---|
| 703 | v->per_target = 0;
|
---|
| 704 | v->append = 0;
|
---|
[2765] | 705 | v->private_var = 0;
|
---|
[2771] | 706 | v->aliased = 0;
|
---|
[2765] | 707 | v->export = v_default;
|
---|
| 708 | #ifdef CONFIG_WITH_COMPILER
|
---|
| 709 | v->recursive_without_dollar = 0;
|
---|
| 710 | v->evalprog = 0;
|
---|
| 711 | v->expandprog = 0;
|
---|
| 712 | v->evalval_count = 0;
|
---|
| 713 | v->expand_count = 0;
|
---|
| 714 | #else
|
---|
[2718] | 715 | MAKE_STATS_2(v->expand_count = 0);
|
---|
| 716 | MAKE_STATS_2(v->evalval_count = 0);
|
---|
[2758] | 717 | #endif
|
---|
| 718 | MAKE_STATS_2(v->changes = 0);
|
---|
[2718] | 719 | MAKE_STATS_2(v->reallocs = 0);
|
---|
| 720 | MAKE_STATS_2(v->references = 0);
|
---|
| 721 | MAKE_STATS_2(v->cTicksEvalVal = 0);
|
---|
| 722 | v->exportable = 1;
|
---|
| 723 | if (*name != '_' && (*name < 'A' || *name > 'Z')
|
---|
| 724 | && (*name < 'a' || *name > 'z'))
|
---|
| 725 | v->exportable = 0;
|
---|
| 726 | else
|
---|
| 727 | {
|
---|
| 728 | for (++name; *name != '\0'; ++name)
|
---|
| 729 | if (*name != '_' && (*name < 'a' || *name > 'z')
|
---|
| 730 | && (*name < 'A' || *name > 'Z') && !ISDIGIT(*name))
|
---|
| 731 | break;
|
---|
| 732 |
|
---|
| 733 | if (*name != '\0')
|
---|
| 734 | v->exportable = 0;
|
---|
| 735 | }
|
---|
| 736 |
|
---|
| 737 | /* If it's the global set, remember the variable. */
|
---|
| 738 | if (set == &global_variable_set)
|
---|
| 739 | strcache2_set_user_val (&variable_strcache, v->name, v);
|
---|
| 740 | }
|
---|
| 741 |
|
---|
| 742 | /* Common variable setup. */
|
---|
| 743 | v->alias = 1;
|
---|
| 744 | v->rdonly_val = 1;
|
---|
| 745 | v->value = (char *)target;
|
---|
| 746 | v->value_length = sizeof(*target); /* Non-zero to provoke trouble. */
|
---|
| 747 | v->value_alloc_len = sizeof(*target);
|
---|
| 748 | if (flocp != 0)
|
---|
| 749 | v->fileinfo = *flocp;
|
---|
| 750 | else
|
---|
| 751 | v->fileinfo.filenm = 0;
|
---|
| 752 | v->origin = origin;
|
---|
| 753 | v->recursive = 0;
|
---|
| 754 |
|
---|
| 755 | /* Mark the target as aliased. */
|
---|
| 756 | target->aliased = 1;
|
---|
| 757 |
|
---|
| 758 | return v;
|
---|
[53] | 759 | }
|
---|
| 760 | #endif /* KMK */
|
---|
| 761 |
|
---|
| 762 | /* If the variable passed in is "special", handle its special nature.
|
---|
| 763 | Currently there are two such variables, both used for introspection:
|
---|
| 764 | .VARIABLES expands to a list of all the variables defined in this instance
|
---|
| 765 | of make.
|
---|
| 766 | .TARGETS expands to a list of all the targets defined in this
|
---|
| 767 | instance of make.
|
---|
| 768 | Returns the variable reference passed in. */
|
---|
| 769 |
|
---|
[1993] | 770 | #define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500)
|
---|
[53] | 771 |
|
---|
[3140] | 772 | static struct variable *
|
---|
[53] | 773 | lookup_special_var (struct variable *var)
|
---|
| 774 | {
|
---|
| 775 | static unsigned long last_changenum = 0;
|
---|
| 776 |
|
---|
| 777 |
|
---|
| 778 | /* This one actually turns out to be very hard, due to the way the parser
|
---|
| 779 | records targets. The way it works is that target information is collected
|
---|
| 780 | internally until make knows the target is completely specified. It unitl
|
---|
| 781 | it sees that some new construct (a new target or variable) is defined that
|
---|
| 782 | it knows the previous one is done. In short, this means that if you do
|
---|
| 783 | this:
|
---|
| 784 |
|
---|
| 785 | all:
|
---|
| 786 |
|
---|
| 787 | TARGS := $(.TARGETS)
|
---|
| 788 |
|
---|
| 789 | then $(TARGS) won't contain "all", because it's not until after the
|
---|
| 790 | variable is created that the previous target is completed.
|
---|
| 791 |
|
---|
| 792 | Changing this would be a major pain. I think a less complex way to do it
|
---|
| 793 | would be to pre-define the target files as soon as the first line is
|
---|
| 794 | parsed, then come back and do the rest of the definition as now. That
|
---|
| 795 | would allow $(.TARGETS) to be correct without a major change to the way
|
---|
| 796 | the parser works.
|
---|
| 797 |
|
---|
| 798 | if (streq (var->name, ".TARGETS"))
|
---|
| 799 | var->value = build_target_list (var->value);
|
---|
[3140] | 800 | else
|
---|
[53] | 801 | */
|
---|
[1949] | 802 |
|
---|
[53] | 803 | if (variable_changenum != last_changenum && streq (var->name, ".VARIABLES"))
|
---|
[1949] | 804 | {
|
---|
| 805 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 806 | unsigned long max = EXPANSION_INCREMENT (strlen (var->value));
|
---|
[53] | 807 | #else
|
---|
| 808 | unsigned long max = EXPANSION_INCREMENT (var->value_length);
|
---|
| 809 | #endif
|
---|
| 810 | unsigned long len;
|
---|
| 811 | char *p;
|
---|
| 812 | struct variable **vp = (struct variable **) global_variable_set.table.ht_vec;
|
---|
| 813 | struct variable **end = &vp[global_variable_set.table.ht_size];
|
---|
[2004] | 814 |
|
---|
[53] | 815 | /* Make sure we have at least MAX bytes in the allocated buffer. */
|
---|
| 816 | var->value = xrealloc (var->value, max);
|
---|
| 817 | MAKE_STATS_2(var->reallocs++);
|
---|
| 818 |
|
---|
| 819 | /* Walk through the hash of variables, constructing a list of names. */
|
---|
| 820 | p = var->value;
|
---|
| 821 | len = 0;
|
---|
| 822 | for (; vp < end; ++vp)
|
---|
| 823 | if (!HASH_VACANT (*vp))
|
---|
| 824 | {
|
---|
| 825 | struct variable *v = *vp;
|
---|
| 826 | int l = v->length;
|
---|
| 827 |
|
---|
| 828 | len += l + 1;
|
---|
| 829 | if (len > max)
|
---|
| 830 | {
|
---|
| 831 | unsigned long off = p - var->value;
|
---|
| 832 |
|
---|
[2004] | 833 | max += EXPANSION_INCREMENT (l + 1);
|
---|
[53] | 834 | var->value = xrealloc (var->value, max);
|
---|
| 835 | p = &var->value[off];
|
---|
[903] | 836 | MAKE_STATS_2(var->reallocs++);
|
---|
[53] | 837 | }
|
---|
| 838 |
|
---|
| 839 | memcpy (p, v->name, l);
|
---|
| 840 | p += l;
|
---|
[1949] | 841 | *(p++) = ' ';
|
---|
| 842 | }
|
---|
| 843 | *(p-1) = '\0';
|
---|
| 844 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[2770] | 845 | var->value_length = p - var->value - 1;
|
---|
[53] | 846 | var->value_alloc_len = max;
|
---|
[3140] | 847 | #endif
|
---|
| 848 | VARIABLE_CHANGED (var);
|
---|
[53] | 849 |
|
---|
| 850 | /* Remember the current variable change number. */
|
---|
| 851 | last_changenum = variable_changenum;
|
---|
| 852 | }
|
---|
| 853 |
|
---|
| 854 | return var;
|
---|
[2591] | 855 | }
|
---|
[1907] | 856 |
|
---|
| 857 | |
---|
| 858 |
|
---|
| 859 | #if 0 /*FIX THIS - def KMK*/ /* bird: speed */
|
---|
| 860 | MY_INLINE struct variable *
|
---|
| 861 | lookup_cached_variable (const char *name)
|
---|
| 862 | {
|
---|
| 863 | const struct variable_set_list *setlist = current_variable_set_list;
|
---|
| 864 | struct hash_table *ht;
|
---|
| 865 | unsigned int hash_1;
|
---|
| 866 | unsigned int hash_2;
|
---|
| 867 | unsigned int idx;
|
---|
| 868 | struct variable *v;
|
---|
| 869 |
|
---|
| 870 | /* first set, first entry, both unrolled. */
|
---|
| 871 |
|
---|
[1993] | 872 | if (setlist->set == &global_variable_set)
|
---|
[1907] | 873 | {
|
---|
| 874 | v = (struct variable *) strcache2_get_user_val (&variable_strcache, name);
|
---|
| 875 | if (MY_PREDICT_TRUE (v))
|
---|
| 876 | return MY_PREDICT_FALSE (v->special) ? lookup_special_var (v) : v;
|
---|
[1914] | 877 | assert (setlist->next == 0);
|
---|
[1907] | 878 | return 0;
|
---|
[1915] | 879 | }
|
---|
[1907] | 880 |
|
---|
| 881 | hash_1 = strcache2_calc_ptr_hash (&variable_strcache, name);
|
---|
| 882 | ht = &setlist->set->table;
|
---|
| 883 | MAKE_STATS (ht->ht_lookups++);
|
---|
| 884 | idx = hash_1 & (ht->ht_size - 1);
|
---|
| 885 | v = ht->ht_vec[idx];
|
---|
[1993] | 886 | if (v != 0)
|
---|
[1907] | 887 | {
|
---|
| 888 | if ( (void *)v != hash_deleted_item
|
---|
[1913] | 889 | && v->name == name)
|
---|
[1907] | 890 | return MY_PREDICT_FALSE (v->special) ? lookup_special_var (v) : v;
|
---|
| 891 |
|
---|
| 892 | /* the rest of the loop */
|
---|
| 893 | hash_2 = strcache2_get_hash (&variable_strcache, name) | 1;
|
---|
| 894 | for (;;)
|
---|
[1915] | 895 | {
|
---|
[1907] | 896 | idx += hash_2;
|
---|
| 897 | idx &= (ht->ht_size - 1);
|
---|
| 898 | v = (struct variable *) ht->ht_vec[idx];
|
---|
| 899 | MAKE_STATS (ht->ht_collisions++); /* there are hardly any deletions, so don't bother with not counting deleted clashes. */
|
---|
| 900 |
|
---|
[1993] | 901 | if (v == 0)
|
---|
[1907] | 902 | break;
|
---|
| 903 | if ( (void *)v != hash_deleted_item
|
---|
| 904 | && v->name == name)
|
---|
[1913] | 905 | return MY_PREDICT_FALSE (v->special) ? lookup_special_var (v) : v;
|
---|
[1907] | 906 | } /* inner collision loop */
|
---|
| 907 | }
|
---|
| 908 | else
|
---|
| 909 | hash_2 = strcache2_get_hash (&variable_strcache, name) | 1;
|
---|
| 910 |
|
---|
| 911 |
|
---|
| 912 | /* The other sets, if any. */
|
---|
| 913 |
|
---|
| 914 | setlist = setlist->next;
|
---|
| 915 | while (setlist)
|
---|
| 916 | {
|
---|
[1993] | 917 | if (setlist->set == &global_variable_set)
|
---|
[1907] | 918 | {
|
---|
| 919 | v = (struct variable *) strcache2_get_user_val (&variable_strcache, name);
|
---|
| 920 | if (MY_PREDICT_TRUE (v))
|
---|
| 921 | return MY_PREDICT_FALSE (v->special) ? lookup_special_var (v) : v;
|
---|
| 922 | assert (setlist->next == 0);
|
---|
| 923 | return 0;
|
---|
[1915] | 924 | }
|
---|
[1907] | 925 |
|
---|
| 926 | /* first iteration unrolled */
|
---|
| 927 | ht = &setlist->set->table;
|
---|
| 928 | MAKE_STATS (ht->ht_lookups++);
|
---|
| 929 | idx = hash_1 & (ht->ht_size - 1);
|
---|
| 930 | v = ht->ht_vec[idx];
|
---|
[1993] | 931 | if (v != 0)
|
---|
[1907] | 932 | {
|
---|
| 933 | if ( (void *)v != hash_deleted_item
|
---|
| 934 | && v->name == name)
|
---|
| 935 | return MY_PREDICT_FALSE (v->special) ? lookup_special_var (v) : v;
|
---|
| 936 |
|
---|
| 937 | /* the rest of the loop */
|
---|
| 938 | for (;;)
|
---|
[1915] | 939 | {
|
---|
[1907] | 940 | idx += hash_2;
|
---|
| 941 | idx &= (ht->ht_size - 1);
|
---|
| 942 | v = (struct variable *) ht->ht_vec[idx];
|
---|
| 943 | MAKE_STATS (ht->ht_collisions++); /* see reason above */
|
---|
| 944 |
|
---|
[1993] | 945 | if (v == 0)
|
---|
[1907] | 946 | break;
|
---|
| 947 | if ( (void *)v != hash_deleted_item
|
---|
| 948 | && v->name == name)
|
---|
| 949 | return MY_PREDICT_FALSE (v->special) ? lookup_special_var (v) : v;
|
---|
| 950 | } /* inner collision loop */
|
---|
| 951 | }
|
---|
| 952 |
|
---|
| 953 | /* next */
|
---|
| 954 | setlist = setlist->next;
|
---|
| 955 | }
|
---|
| 956 |
|
---|
| 957 | return 0;
|
---|
| 958 | }
|
---|
| 959 |
|
---|
| 960 | # ifndef NDEBUG
|
---|
| 961 | struct variable *
|
---|
| 962 | lookup_variable_for_assert (const char *name, unsigned int length)
|
---|
| 963 | {
|
---|
| 964 | const struct variable_set_list *setlist;
|
---|
| 965 | struct variable var_key;
|
---|
| 966 | var_key.name = name;
|
---|
| 967 | var_key.length = length;
|
---|
| 968 |
|
---|
| 969 | for (setlist = current_variable_set_list;
|
---|
| 970 | setlist != 0; setlist = setlist->next)
|
---|
[1993] | 971 | {
|
---|
[1907] | 972 | struct variable *v;
|
---|
| 973 | v = (struct variable *) hash_find_item_strcached (&setlist->set->table, &var_key);
|
---|
| 974 | if (v)
|
---|
| 975 | return MY_PREDICT_FALSE (v->special) ? lookup_special_var (v) : v;
|
---|
| 976 | }
|
---|
| 977 | return 0;
|
---|
[53] | 978 | }
|
---|
| 979 | # endif /* !NDEBUG */
|
---|
[3140] | 980 | #endif /* KMK - need for speed */
|
---|
[53] | 981 |
|
---|
| 982 | /* Lookup a variable whose name is a string starting at NAME
|
---|
| 983 | and with LENGTH chars. NAME need not be null-terminated.
|
---|
| 984 | Returns address of the 'struct variable' containing all info
|
---|
| 985 | on the variable, or nil if no such variable is defined. */
|
---|
[2591] | 986 |
|
---|
[53] | 987 | struct variable *
|
---|
| 988 | lookup_variable (const char *name, unsigned int length)
|
---|
[1907] | 989 | {
|
---|
| 990 | #if 1 /*FIX THIS - ndef KMK*/
|
---|
| 991 | const struct variable_set_list *setlist;
|
---|
[2591] | 992 | struct variable var_key;
|
---|
[1887] | 993 | #else /* KMK */
|
---|
| 994 | struct variable *v;
|
---|
[2717] | 995 | #endif /* KMK */
|
---|
[53] | 996 | int is_parent = 0;
|
---|
[2717] | 997 | #ifdef CONFIG_WITH_STRCACHE2
|
---|
| 998 | const char *cached_name;
|
---|
| 999 | #endif
|
---|
| 1000 |
|
---|
| 1001 | # ifdef KMK
|
---|
| 1002 | /* Check for kBuild-define- local variable accesses and handle these first. */
|
---|
[2752] | 1003 | if (length > 3 && name[0] == '[')
|
---|
[2758] | 1004 | {
|
---|
[2752] | 1005 | struct variable *v = lookup_kbuild_object_variable_accessor(name, length);
|
---|
| 1006 | if (v != VAR_NOT_KBUILD_ACCESSOR)
|
---|
[2717] | 1007 | {
|
---|
| 1008 | MAKE_STATS_2 (v->references++);
|
---|
| 1009 | return v;
|
---|
| 1010 | }
|
---|
[1887] | 1011 | }
|
---|
| 1012 | # endif
|
---|
[1946] | 1013 |
|
---|
[1887] | 1014 | #ifdef CONFIG_WITH_STRCACHE2
|
---|
| 1015 | /* lookup the name in the string case, if it's not there it won't
|
---|
| 1016 | be in any of the sets either. */
|
---|
| 1017 | cached_name = strcache2_lookup (&variable_strcache, name, length);
|
---|
[2591] | 1018 | if (!cached_name)
|
---|
[1887] | 1019 | return NULL;
|
---|
[53] | 1020 | name = cached_name;
|
---|
| 1021 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
| 1022 | #if 1 /*FIX THIS - ndef KMK */
|
---|
| 1023 |
|
---|
| 1024 | var_key.name = (char *) name;
|
---|
| 1025 | var_key.length = length;
|
---|
| 1026 |
|
---|
| 1027 | for (setlist = current_variable_set_list;
|
---|
| 1028 | setlist != 0; setlist = setlist->next)
|
---|
[1902] | 1029 | {
|
---|
[53] | 1030 | const struct variable_set *set = setlist->set;
|
---|
[1902] | 1031 | struct variable *v;
|
---|
| 1032 |
|
---|
| 1033 | # ifndef CONFIG_WITH_STRCACHE2
|
---|
[2591] | 1034 | v = (struct variable *) hash_find_item ((struct hash_table *) &set->table, &var_key);
|
---|
[2718] | 1035 | # else /* CONFIG_WITH_STRCACHE2 */
|
---|
| 1036 | v = (struct variable *) hash_find_item_strcached ((struct hash_table *) &set->table, &var_key);
|
---|
| 1037 | # endif /* CONFIG_WITH_STRCACHE2 */
|
---|
| 1038 | if (v && (!is_parent || !v->private_var))
|
---|
[2758] | 1039 | {
|
---|
[3140] | 1040 | # ifdef KMK
|
---|
[2718] | 1041 | RESOLVE_ALIAS_VARIABLE(v);
|
---|
[2591] | 1042 | # endif
|
---|
| 1043 | MAKE_STATS_2 (v->references++);
|
---|
[53] | 1044 | return v->special ? lookup_special_var (v) : v;
|
---|
| 1045 | }
|
---|
[1907] | 1046 |
|
---|
| 1047 | is_parent |= setlist->next_is_parent;
|
---|
| 1048 | }
|
---|
| 1049 |
|
---|
[53] | 1050 | #else /* KMK - need for speed */
|
---|
[1907] | 1051 |
|
---|
| 1052 | v = lookup_cached_variable (name);
|
---|
| 1053 | assert (lookup_variable_for_assert(name, length) == v);
|
---|
| 1054 | #ifdef VMS
|
---|
| 1055 | if (v)
|
---|
[3140] | 1056 | #endif
|
---|
| 1057 | return v;
|
---|
[53] | 1058 | #endif /* KMK - need for speed */
|
---|
| 1059 | #ifdef VMS
|
---|
| 1060 | /* VMS does not populate envp[] with DCL symbols and logical names which
|
---|
| 1061 | historically are mapped to enviroment varables and returned by getenv() */
|
---|
| 1062 | {
|
---|
| 1063 | char *vname = alloca (length + 1);
|
---|
| 1064 | char *value;
|
---|
| 1065 | strncpy (vname, name, length);
|
---|
| 1066 | vname[length] = 0;
|
---|
| 1067 | value = getenv (vname);
|
---|
| 1068 | if (value != 0)
|
---|
| 1069 | {
|
---|
| 1070 | char *sptr;
|
---|
| 1071 | int scnt;
|
---|
| 1072 |
|
---|
| 1073 | sptr = value;
|
---|
| 1074 | scnt = 0;
|
---|
| 1075 |
|
---|
| 1076 | while ((sptr = strchr (sptr, '$')))
|
---|
| 1077 | {
|
---|
| 1078 | scnt++;
|
---|
| 1079 | sptr++;
|
---|
| 1080 | }
|
---|
| 1081 |
|
---|
| 1082 | if (scnt > 0)
|
---|
| 1083 | {
|
---|
| 1084 | char *nvalue;
|
---|
| 1085 | char *nptr;
|
---|
| 1086 |
|
---|
| 1087 | nvalue = alloca (strlen (value) + scnt + 1);
|
---|
| 1088 | sptr = value;
|
---|
| 1089 | nptr = nvalue;
|
---|
| 1090 |
|
---|
| 1091 | while (*sptr)
|
---|
| 1092 | {
|
---|
| 1093 | if (*sptr == '$')
|
---|
| 1094 | {
|
---|
| 1095 | *nptr++ = '$';
|
---|
| 1096 | *nptr++ = '$';
|
---|
| 1097 | }
|
---|
| 1098 | else
|
---|
| 1099 | {
|
---|
| 1100 | *nptr++ = *sptr;
|
---|
| 1101 | }
|
---|
| 1102 | sptr++;
|
---|
| 1103 | }
|
---|
| 1104 |
|
---|
| 1105 | *nptr = '\0';
|
---|
| 1106 | return define_variable (vname, length, nvalue, o_env, 1);
|
---|
| 1107 |
|
---|
| 1108 | }
|
---|
| 1109 |
|
---|
| 1110 | return define_variable (vname, length, value, o_env, 1);
|
---|
| 1111 | }
|
---|
| 1112 | }
|
---|
[2769] | 1113 | #endif /* VMS */
|
---|
| 1114 |
|
---|
| 1115 | return 0;
|
---|
| 1116 | }
|
---|
| 1117 |
|
---|
| 1118 | #ifdef CONFIG_WITH_STRCACHE2
|
---|
| 1119 | /* Alternative version of lookup_variable that takes a name that's already in
|
---|
| 1120 | the variable string cache. */
|
---|
| 1121 | struct variable *
|
---|
| 1122 | lookup_variable_strcached (const char *name)
|
---|
| 1123 | {
|
---|
| 1124 | struct variable *v;
|
---|
| 1125 | #if 1 /*FIX THIS - ndef KMK*/
|
---|
| 1126 | const struct variable_set_list *setlist;
|
---|
| 1127 | struct variable var_key;
|
---|
| 1128 | #endif /* KMK */
|
---|
| 1129 | int is_parent = 0;
|
---|
| 1130 |
|
---|
| 1131 | #ifndef NDEBUG
|
---|
| 1132 | strcache2_verify_entry (&variable_strcache, name);
|
---|
| 1133 | #endif
|
---|
| 1134 |
|
---|
| 1135 | #ifdef KMK
|
---|
| 1136 | /* Check for kBuild-define- local variable accesses and handle these first. */
|
---|
| 1137 | if (strcache2_get_len(&variable_strcache, name) > 3 && name[0] == '[')
|
---|
| 1138 | {
|
---|
| 1139 | v = lookup_kbuild_object_variable_accessor(name, strcache2_get_len(&variable_strcache, name));
|
---|
| 1140 | if (v != VAR_NOT_KBUILD_ACCESSOR)
|
---|
| 1141 | {
|
---|
| 1142 | MAKE_STATS_2 (v->references++);
|
---|
| 1143 | return v;
|
---|
| 1144 | }
|
---|
| 1145 | }
|
---|
| 1146 | #endif
|
---|
| 1147 |
|
---|
| 1148 | #if 1 /*FIX THIS - ndef KMK */
|
---|
| 1149 |
|
---|
| 1150 | var_key.name = (char *) name;
|
---|
| 1151 | var_key.length = strcache2_get_len(&variable_strcache, name);
|
---|
| 1152 |
|
---|
| 1153 | for (setlist = current_variable_set_list;
|
---|
| 1154 | setlist != 0; setlist = setlist->next)
|
---|
| 1155 | {
|
---|
| 1156 | const struct variable_set *set = setlist->set;
|
---|
| 1157 |
|
---|
| 1158 | v = (struct variable *) hash_find_item_strcached ((struct hash_table *) &set->table, &var_key);
|
---|
| 1159 | if (v && (!is_parent || !v->private_var))
|
---|
| 1160 | {
|
---|
| 1161 | # ifdef KMK
|
---|
| 1162 | RESOLVE_ALIAS_VARIABLE(v);
|
---|
| 1163 | # endif
|
---|
| 1164 | MAKE_STATS_2 (v->references++);
|
---|
| 1165 | return v->special ? lookup_special_var (v) : v;
|
---|
| 1166 | }
|
---|
| 1167 |
|
---|
| 1168 | is_parent |= setlist->next_is_parent;
|
---|
| 1169 | }
|
---|
| 1170 |
|
---|
| 1171 | #else /* KMK - need for speed */
|
---|
| 1172 |
|
---|
| 1173 | v = lookup_cached_variable (name);
|
---|
| 1174 | assert (lookup_variable_for_assert(name, length) == v);
|
---|
| 1175 | #ifdef VMS
|
---|
| 1176 | if (v)
|
---|
| 1177 | #endif
|
---|
| 1178 | return v;
|
---|
| 1179 | #endif /* KMK - need for speed */
|
---|
| 1180 | #ifdef VMS
|
---|
| 1181 | # error "Port me (split out the relevant code from lookup_varaible and call it)"
|
---|
| 1182 | #endif
|
---|
[53] | 1183 | return 0;
|
---|
| 1184 | }
|
---|
| 1185 | #endif
|
---|
[3140] | 1186 |
|
---|
[53] | 1187 | |
---|
| 1188 |
|
---|
| 1189 | /* Lookup a variable whose name is a string starting at NAME
|
---|
| 1190 | and with LENGTH chars in set SET. NAME need not be null-terminated.
|
---|
| 1191 | Returns address of the 'struct variable' containing all info
|
---|
| 1192 | on the variable, or nil if no such variable is defined. */
|
---|
| 1193 |
|
---|
[1902] | 1194 | struct variable *
|
---|
| 1195 | lookup_variable_in_set (const char *name, unsigned int length,
|
---|
| 1196 | const struct variable_set *set)
|
---|
| 1197 | {
|
---|
| 1198 | struct variable var_key;
|
---|
| 1199 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[1887] | 1200 | var_key.name = (char *) name;
|
---|
[2752] | 1201 | var_key.length = length;
|
---|
[53] | 1202 |
|
---|
[2717] | 1203 | return (struct variable *) hash_find_item ((struct hash_table *) &set->table, &var_key);
|
---|
| 1204 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
| 1205 | const char *cached_name;
|
---|
| 1206 | struct variable *v;
|
---|
[2736] | 1207 |
|
---|
[2717] | 1208 | # ifdef KMK
|
---|
[2718] | 1209 | /* Check for kBuild-define- local variable accesses and handle these first. */
|
---|
| 1210 | if (length > 3 && name[0] == '[' && set == &global_variable_set)
|
---|
[2758] | 1211 | {
|
---|
[2718] | 1212 | v = lookup_kbuild_object_variable_accessor(name, length);
|
---|
| 1213 | if (v != VAR_NOT_KBUILD_ACCESSOR)
|
---|
[2717] | 1214 | {
|
---|
| 1215 | RESOLVE_ALIAS_VARIABLE(v);
|
---|
| 1216 | MAKE_STATS_2 (v->references++);
|
---|
[1887] | 1217 | return v;
|
---|
[1890] | 1218 | }
|
---|
[1887] | 1219 | }
|
---|
| 1220 | # endif
|
---|
| 1221 |
|
---|
[1890] | 1222 | /* lookup the name in the string case, if it's not there it won't
|
---|
| 1223 | be in any of the sets either. Optimize lookups in the global set. */
|
---|
| 1224 | cached_name = strcache2_lookup(&variable_strcache, name, length);
|
---|
| 1225 | if (!cached_name)
|
---|
| 1226 | return NULL;
|
---|
| 1227 |
|
---|
[2718] | 1228 | if (set == &global_variable_set)
|
---|
| 1229 | {
|
---|
| 1230 | v = strcache2_get_user_val (&variable_strcache, cached_name);
|
---|
| 1231 | assert (!v || v->name == cached_name);
|
---|
[1890] | 1232 | }
|
---|
[2718] | 1233 | else
|
---|
| 1234 | {
|
---|
| 1235 | var_key.name = cached_name;
|
---|
| 1236 | var_key.length = length;
|
---|
| 1237 |
|
---|
| 1238 | v = (struct variable *) hash_find_item_strcached (
|
---|
[2758] | 1239 | (struct hash_table *) &set->table, &var_key);
|
---|
[2718] | 1240 | }
|
---|
[1902] | 1241 | # ifdef KMK
|
---|
[53] | 1242 | RESOLVE_ALIAS_VARIABLE(v);
|
---|
| 1243 | # endif
|
---|
| 1244 | MAKE_STATS_2 (if (v) v->references++);
|
---|
| 1245 | return v;
|
---|
| 1246 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
| 1247 | }
|
---|
| 1248 | |
---|
| 1249 |
|
---|
[903] | 1250 | /* Initialize FILE's variable set list. If FILE already has a variable set
|
---|
[53] | 1251 | list, the topmost variable set is left intact, but the the rest of the
|
---|
| 1252 | chain is replaced with FILE->parent's setlist. If FILE is a double-colon
|
---|
| 1253 | rule, then we will use the "root" double-colon target's variable set as the
|
---|
| 1254 | parent of FILE's variable set.
|
---|
| 1255 |
|
---|
[503] | 1256 | If we're READING a makefile, don't do the pattern variable search now,
|
---|
[53] | 1257 | since the pattern variable might not have been defined yet. */
|
---|
| 1258 |
|
---|
| 1259 | void
|
---|
[1864] | 1260 | initialize_file_variables (struct file *file, int reading)
|
---|
[53] | 1261 | {
|
---|
[3140] | 1262 | struct variable_set_list *l = file->variables;
|
---|
[903] | 1263 |
|
---|
[1902] | 1264 | if (l == 0)
|
---|
[1864] | 1265 | {
|
---|
| 1266 | #ifndef CONFIG_WITH_ALLOC_CACHES
|
---|
| 1267 | l = (struct variable_set_list *)
|
---|
| 1268 | xmalloc (sizeof (struct variable_set_list));
|
---|
[1902] | 1269 | l->set = xmalloc (sizeof (struct variable_set));
|
---|
| 1270 | #else /* CONFIG_WITH_ALLOC_CACHES */
|
---|
[53] | 1271 | l = (struct variable_set_list *)
|
---|
| 1272 | alloccache_alloc (&variable_set_list_cache);
|
---|
[1902] | 1273 | l->set = (struct variable_set *)
|
---|
| 1274 | alloccache_alloc (&variable_set_cache);
|
---|
| 1275 | #endif /* CONFIG_WITH_ALLOC_CACHES */
|
---|
| 1276 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[53] | 1277 | hash_init (&l->set->table, PERFILE_VARIABLE_BUCKETS,
|
---|
| 1278 | variable_hash_1, variable_hash_2, variable_hash_cmp);
|
---|
| 1279 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
| 1280 | hash_init_strcached (&l->set->table, PERFILE_VARIABLE_BUCKETS,
|
---|
| 1281 | &variable_strcache, offsetof (struct variable, name));
|
---|
| 1282 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
| 1283 | file->variables = l;
|
---|
| 1284 | }
|
---|
| 1285 |
|
---|
| 1286 | /* If this is a double-colon, then our "parent" is the "root" target for
|
---|
| 1287 | this double-colon rule. Since that rule has the same name, parent,
|
---|
[2591] | 1288 | etc. we can just use its variables as the "next" for ours. */
|
---|
[53] | 1289 |
|
---|
| 1290 | if (file->double_colon && file->double_colon != file)
|
---|
| 1291 | {
|
---|
| 1292 | initialize_file_variables (file->double_colon, reading);
|
---|
| 1293 | l->next = file->double_colon->variables;
|
---|
| 1294 | l->next_is_parent = 0;
|
---|
| 1295 | return;
|
---|
| 1296 | }
|
---|
| 1297 |
|
---|
| 1298 | if (file->parent == 0)
|
---|
[2591] | 1299 | l->next = &global_setlist;
|
---|
[53] | 1300 | else
|
---|
| 1301 | {
|
---|
| 1302 | initialize_file_variables (file->parent, reading);
|
---|
| 1303 | l->next = file->parent->variables;
|
---|
| 1304 | }
|
---|
| 1305 | l->next_is_parent = 1;
|
---|
| 1306 |
|
---|
| 1307 | /* If we're not reading makefiles and we haven't looked yet, see if
|
---|
| 1308 | we can find pattern variables for this target. */
|
---|
| 1309 |
|
---|
| 1310 | if (!reading && !file->pat_searched)
|
---|
| 1311 | {
|
---|
| 1312 | struct pattern_var *p;
|
---|
| 1313 |
|
---|
| 1314 | p = lookup_pattern_var (0, file->name);
|
---|
| 1315 | if (p != 0)
|
---|
| 1316 | {
|
---|
| 1317 | struct variable_set_list *global = current_variable_set_list;
|
---|
| 1318 |
|
---|
| 1319 | /* We found at least one. Set up a new variable set to accumulate
|
---|
[287] | 1320 | all the pattern variables that match this target. */
|
---|
| 1321 |
|
---|
| 1322 | file->pat_variables = create_new_variable_set ();
|
---|
| 1323 | current_variable_set_list = file->pat_variables;
|
---|
| 1324 |
|
---|
| 1325 | do
|
---|
| 1326 | {
|
---|
| 1327 | /* We found one, so insert it into the set. */
|
---|
| 1328 |
|
---|
| 1329 | struct variable *v;
|
---|
| 1330 |
|
---|
| 1331 | if (p->variable.flavor == f_simple)
|
---|
| 1332 | {
|
---|
| 1333 | v = define_variable_loc (
|
---|
| 1334 | p->variable.name, strlen (p->variable.name),
|
---|
| 1335 | p->variable.value, p->variable.origin,
|
---|
[1811] | 1336 | 0, &p->variable.fileinfo);
|
---|
[287] | 1337 |
|
---|
| 1338 | v->flavor = f_simple;
|
---|
| 1339 | }
|
---|
| 1340 | else
|
---|
[1811] | 1341 | {
|
---|
| 1342 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1343 | v = do_variable_definition (
|
---|
| 1344 | &p->variable.fileinfo, p->variable.name,
|
---|
| 1345 | p->variable.value, p->variable.origin,
|
---|
| 1346 | p->variable.flavor, 1);
|
---|
[287] | 1347 | #else
|
---|
| 1348 | v = do_variable_definition_2 (
|
---|
| 1349 | &p->variable.fileinfo, p->variable.name,
|
---|
| 1350 | p->variable.value, p->variable.value_length, 0, 0,
|
---|
| 1351 | p->variable.origin, p->variable.flavor, 1);
|
---|
[2591] | 1352 | #endif
|
---|
[287] | 1353 | }
|
---|
[53] | 1354 |
|
---|
| 1355 | /* Also mark it as a per-target and copy export status. */
|
---|
| 1356 | v->per_target = p->variable.per_target;
|
---|
| 1357 | v->export = p->variable.export;
|
---|
| 1358 | v->private_var = p->variable.private_var;
|
---|
| 1359 | }
|
---|
| 1360 | while ((p = lookup_pattern_var (p, file->name)) != 0);
|
---|
| 1361 |
|
---|
| 1362 | current_variable_set_list = global;
|
---|
| 1363 | }
|
---|
| 1364 | file->pat_searched = 1;
|
---|
| 1365 | }
|
---|
[2591] | 1366 |
|
---|
[53] | 1367 | /* If we have a pattern variable match, set it up. */
|
---|
[2591] | 1368 |
|
---|
[53] | 1369 | if (file->pat_variables != 0)
|
---|
| 1370 | {
|
---|
| 1371 | file->pat_variables->next = l->next;
|
---|
| 1372 | file->pat_variables->next_is_parent = l->next_is_parent;
|
---|
| 1373 | l->next = file->pat_variables;
|
---|
| 1374 | l->next_is_parent = 0;
|
---|
| 1375 | }
|
---|
| 1376 | }
|
---|
| 1377 | |
---|
| 1378 |
|
---|
| 1379 | /* Pop the top set off the current variable set list,
|
---|
| 1380 | and free all its storage. */
|
---|
[1864] | 1381 |
|
---|
[903] | 1382 | struct variable_set_list *
|
---|
[1864] | 1383 | create_new_variable_set (void)
|
---|
| 1384 | {
|
---|
| 1385 | register struct variable_set_list *setlist;
|
---|
[1902] | 1386 | register struct variable_set *set;
|
---|
[53] | 1387 |
|
---|
[3140] | 1388 | #ifndef CONFIG_WITH_ALLOC_CACHES
|
---|
[1902] | 1389 | set = xmalloc (sizeof (struct variable_set));
|
---|
| 1390 | #else
|
---|
| 1391 | set = (struct variable_set *) alloccache_alloc (&variable_set_cache);
|
---|
| 1392 | #endif
|
---|
[53] | 1393 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[1864] | 1394 | hash_init (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS,
|
---|
[53] | 1395 | variable_hash_1, variable_hash_2, variable_hash_cmp);
|
---|
| 1396 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
[1864] | 1397 | hash_init_strcached (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS,
|
---|
| 1398 | &variable_strcache, offsetof (struct variable, name));
|
---|
| 1399 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
| 1400 |
|
---|
[53] | 1401 | #ifndef CONFIG_WITH_ALLOC_CACHES
|
---|
| 1402 | setlist = (struct variable_set_list *)
|
---|
[2591] | 1403 | xmalloc (sizeof (struct variable_set_list));
|
---|
[53] | 1404 | #else
|
---|
| 1405 | setlist = (struct variable_set_list *)
|
---|
| 1406 | alloccache_alloc (&variable_set_list_cache);
|
---|
| 1407 | #endif
|
---|
[503] | 1408 | setlist->set = set;
|
---|
| 1409 | setlist->next = current_variable_set_list;
|
---|
| 1410 | setlist->next_is_parent = 0;
|
---|
| 1411 |
|
---|
| 1412 | return setlist;
|
---|
| 1413 | }
|
---|
[53] | 1414 |
|
---|
| 1415 | /* Create a new variable set and push it on the current setlist.
|
---|
| 1416 | If we're pushing a global scope (that is, the current scope is the global
|
---|
[3140] | 1417 | scope) then we need to "push" it the other way: file variable sets point
|
---|
[503] | 1418 | directly to the global_setlist so we need to replace that with the new one.
|
---|
| 1419 | */
|
---|
| 1420 |
|
---|
| 1421 | struct variable_set_list *
|
---|
| 1422 | push_new_variable_scope (void)
|
---|
| 1423 | {
|
---|
| 1424 | current_variable_set_list = create_new_variable_set ();
|
---|
| 1425 | if (current_variable_set_list->next == &global_setlist)
|
---|
| 1426 | {
|
---|
| 1427 | /* It was the global, so instead of new -> &global we want to replace
|
---|
| 1428 | &global with the new one and have &global -> new, with current still
|
---|
| 1429 | pointing to &global */
|
---|
| 1430 | struct variable_set *set = current_variable_set_list->set;
|
---|
[53] | 1431 | current_variable_set_list->set = global_setlist.set;
|
---|
[503] | 1432 | global_setlist.set = set;
|
---|
| 1433 | current_variable_set_list->next = global_setlist.next;
|
---|
| 1434 | global_setlist.next = current_variable_set_list;
|
---|
| 1435 | current_variable_set_list = &global_setlist;
|
---|
| 1436 | }
|
---|
| 1437 | return (current_variable_set_list);
|
---|
| 1438 | }
|
---|
| 1439 |
|
---|
[3140] | 1440 | void
|
---|
[503] | 1441 | pop_variable_scope (void)
|
---|
| 1442 | {
|
---|
| 1443 | struct variable_set_list *setlist;
|
---|
| 1444 | struct variable_set *set;
|
---|
| 1445 |
|
---|
| 1446 | /* Can't call this if there's no scope to pop! */
|
---|
| 1447 | assert (current_variable_set_list->next != NULL);
|
---|
| 1448 |
|
---|
| 1449 | if (current_variable_set_list != &global_setlist)
|
---|
| 1450 | {
|
---|
| 1451 | /* We're not pointing to the global setlist, so pop this one. */
|
---|
| 1452 | setlist = current_variable_set_list;
|
---|
| 1453 | set = setlist->set;
|
---|
| 1454 | current_variable_set_list = setlist->next;
|
---|
| 1455 | }
|
---|
| 1456 | else
|
---|
| 1457 | {
|
---|
[2591] | 1458 | /* This set is the one in the global_setlist, but there is another global
|
---|
[503] | 1459 | set beyond that. We want to copy that set to global_setlist, then
|
---|
| 1460 | delete what used to be in global_setlist. */
|
---|
| 1461 | setlist = global_setlist.next;
|
---|
[1864] | 1462 | set = global_setlist.set;
|
---|
[903] | 1463 | global_setlist.set = setlist->set;
|
---|
[503] | 1464 | global_setlist.next = setlist->next;
|
---|
| 1465 | global_setlist.next_is_parent = setlist->next_is_parent;
|
---|
[903] | 1466 | }
|
---|
[1864] | 1467 |
|
---|
| 1468 | /* Free the one we no longer need. */
|
---|
| 1469 | #ifndef CONFIG_WITH_ALLOC_CACHES
|
---|
| 1470 | free (setlist);
|
---|
| 1471 | hash_map (&set->table, free_variable_name_and_value);
|
---|
| 1472 | hash_free (&set->table, 1);
|
---|
[503] | 1473 | free (set);
|
---|
[53] | 1474 | #else
|
---|
| 1475 | alloccache_free (&variable_set_list_cache, setlist);
|
---|
| 1476 | hash_map (&set->table, free_variable_name_and_value);
|
---|
| 1477 | hash_free_cached (&set->table, 1, &variable_cache);
|
---|
| 1478 | alloccache_free (&variable_set_cache, set);
|
---|
| 1479 | #endif
|
---|
| 1480 | }
|
---|
| 1481 | |
---|
| 1482 |
|
---|
| 1483 | /* Merge FROM_SET into TO_SET, freeing unused storage in FROM_SET. */
|
---|
[3140] | 1484 |
|
---|
| 1485 | static void
|
---|
[53] | 1486 | merge_variable_sets (struct variable_set *to_set,
|
---|
| 1487 | struct variable_set *from_set)
|
---|
| 1488 | {
|
---|
[3140] | 1489 | struct variable **from_var_slot = (struct variable **) from_set->table.ht_vec;
|
---|
| 1490 | struct variable **from_var_end = from_var_slot + from_set->table.ht_size;
|
---|
[1902] | 1491 |
|
---|
[3140] | 1492 | int inc = to_set == &global_variable_set ? 1 : 0;
|
---|
[1902] | 1493 |
|
---|
| 1494 | for ( ; from_var_slot < from_var_end; from_var_slot++)
|
---|
| 1495 | if (! HASH_VACANT (*from_var_slot))
|
---|
| 1496 | {
|
---|
[3140] | 1497 | struct variable *from_var = *from_var_slot;
|
---|
| 1498 | struct variable **to_var_slot
|
---|
| 1499 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
| 1500 | = (struct variable **) hash_find_slot (&to_set->table, *from_var_slot);
|
---|
| 1501 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
| 1502 | = (struct variable **) hash_find_slot_strcached (&to_set->table,
|
---|
| 1503 | *from_var_slot);
|
---|
| 1504 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
[2718] | 1505 | if (HASH_VACANT (*to_var_slot))
|
---|
| 1506 | {
|
---|
[3140] | 1507 | hash_insert_at (&to_set->table, from_var, to_var_slot);
|
---|
[2718] | 1508 | variable_changenum += inc;
|
---|
[3140] | 1509 | }
|
---|
[2718] | 1510 | else
|
---|
[2765] | 1511 | {
|
---|
| 1512 | /* GKM FIXME: delete in from_set->table */
|
---|
| 1513 | #ifdef KMK
|
---|
| 1514 | if (from_var->aliased)
|
---|
[2718] | 1515 | OS (fatal, NULL, ("Attempting to delete aliased variable '%s'"), from_var->name);
|
---|
| 1516 | if (from_var->alias)
|
---|
| 1517 | OS (fatal, NULL, ("Attempting to delete variable aliased '%s'"), from_var->name);
|
---|
| 1518 | #endif
|
---|
[3140] | 1519 | #ifdef CONFIG_WITH_COMPILER
|
---|
| 1520 | if (from_var->evalprog || from_var->expandprog)
|
---|
[53] | 1521 | kmk_cc_variable_deleted (from_var);
|
---|
| 1522 | #endif
|
---|
| 1523 | #ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
|
---|
| 1524 | if (!from_var->rdonly_val)
|
---|
| 1525 | #endif
|
---|
| 1526 | free (from_var->value);
|
---|
| 1527 | free (from_var);
|
---|
| 1528 | }
|
---|
| 1529 | }
|
---|
[503] | 1530 | }
|
---|
[53] | 1531 |
|
---|
| 1532 | /* Merge SETLIST1 into SETLIST0, freeing unused storage in SETLIST1. */
|
---|
[503] | 1533 |
|
---|
| 1534 | void
|
---|
| 1535 | merge_variable_set_lists (struct variable_set_list **setlist0,
|
---|
[53] | 1536 | struct variable_set_list *setlist1)
|
---|
[503] | 1537 | {
|
---|
| 1538 | struct variable_set_list *to = *setlist0;
|
---|
| 1539 | struct variable_set_list *last0 = 0;
|
---|
| 1540 |
|
---|
| 1541 | /* If there's nothing to merge, stop now. */
|
---|
| 1542 | if (!setlist1)
|
---|
| 1543 | return;
|
---|
[53] | 1544 |
|
---|
[503] | 1545 | /* This loop relies on the fact that all setlists terminate with the global
|
---|
[53] | 1546 | setlist (before NULL). If that's not true, arguably we SHOULD die. */
|
---|
[503] | 1547 | if (to)
|
---|
| 1548 | while (setlist1 != &global_setlist && to != &global_setlist)
|
---|
| 1549 | {
|
---|
| 1550 | struct variable_set_list *from = setlist1;
|
---|
| 1551 | setlist1 = setlist1->next;
|
---|
[53] | 1552 |
|
---|
| 1553 | merge_variable_sets (to->set, from->set);
|
---|
[3140] | 1554 |
|
---|
[53] | 1555 | last0 = to;
|
---|
[3140] | 1556 | to = to->next;
|
---|
[53] | 1557 | }
|
---|
| 1558 |
|
---|
| 1559 | if (setlist1 != &global_setlist)
|
---|
[2452] | 1560 | {
|
---|
[2451] | 1561 | if (last0 == 0)
|
---|
| 1562 | *setlist0 = setlist1;
|
---|
| 1563 | else
|
---|
[2452] | 1564 | last0->next = setlist1;
|
---|
[2451] | 1565 | }
|
---|
| 1566 | }
|
---|
| 1567 | |
---|
| 1568 |
|
---|
| 1569 | #if defined(KMK) && !defined(WINDOWS32)
|
---|
| 1570 | /* Parses out the next number from the uname release level string. Fast
|
---|
| 1571 | forwards to the end of the string when encountering some non-conforming
|
---|
| 1572 | chars. */
|
---|
| 1573 |
|
---|
| 1574 | static unsigned long parse_release_number (const char **ppsz)
|
---|
| 1575 | {
|
---|
| 1576 | unsigned long ul;
|
---|
| 1577 | char *psz = (char *)*ppsz;
|
---|
| 1578 | if (ISDIGIT (*psz))
|
---|
| 1579 | {
|
---|
| 1580 | ul = strtoul (psz, &psz, 10);
|
---|
| 1581 | if (psz != NULL && *psz == '.')
|
---|
| 1582 | psz++;
|
---|
| 1583 | else
|
---|
[53] | 1584 | psz = strchr (*ppsz, '\0');
|
---|
| 1585 | *ppsz = psz;
|
---|
| 1586 | }
|
---|
| 1587 | else
|
---|
| 1588 | ul = 0;
|
---|
| 1589 | return ul;
|
---|
[3140] | 1590 | }
|
---|
[1439] | 1591 | #endif
|
---|
[53] | 1592 | |
---|
[1439] | 1593 |
|
---|
| 1594 | /* Define the automatic variables, and record the addresses
|
---|
[1503] | 1595 | of their structures so we can change their values quickly. */
|
---|
| 1596 |
|
---|
| 1597 | void
|
---|
[3394] | 1598 | define_automatic_variables (void)
|
---|
[2451] | 1599 | {
|
---|
| 1600 | struct variable *v;
|
---|
| 1601 | #ifndef KMK
|
---|
[764] | 1602 | char buf[200];
|
---|
[53] | 1603 | #else
|
---|
| 1604 | char buf[1024];
|
---|
[2591] | 1605 | const char *val;
|
---|
[53] | 1606 | struct variable *envvar1;
|
---|
| 1607 | struct variable *envvar2;
|
---|
[3140] | 1608 | # ifndef WINDOWS32
|
---|
| 1609 | struct utsname uts;
|
---|
| 1610 | # endif
|
---|
| 1611 | unsigned long ulMajor = 0, ulMinor = 0, ulPatch = 0, ul4th = 0;
|
---|
| 1612 | #endif
|
---|
[1503] | 1613 |
|
---|
[2591] | 1614 | sprintf (buf, "%u", makelevel);
|
---|
[3140] | 1615 | define_variable_cname (MAKELEVEL_NAME, buf, o_env, 0);
|
---|
[1503] | 1616 |
|
---|
[53] | 1617 | sprintf (buf, "%s%s%s",
|
---|
[225] | 1618 | version_string,
|
---|
[2591] | 1619 | (remote_description == 0 || remote_description[0] == '\0')
|
---|
[225] | 1620 | ? "" : "-",
|
---|
[576] | 1621 | (remote_description == 0 || remote_description[0] == '\0')
|
---|
| 1622 | ? "" : remote_description);
|
---|
[2591] | 1623 | #ifndef KMK
|
---|
[576] | 1624 | define_variable_cname ("MAKE_VERSION", buf, o_default, 0);
|
---|
[2591] | 1625 | define_variable_cname ("MAKE_HOST", make_host, o_default, 0);
|
---|
[576] | 1626 | #else /* KMK */
|
---|
[2591] | 1627 |
|
---|
[1554] | 1628 | /* Define KMK_VERSION to indicate kMk. */
|
---|
[2591] | 1629 | define_variable_cname ("KMK_VERSION", buf, o_default, 0);
|
---|
[576] | 1630 |
|
---|
[1554] | 1631 | /* Define KBUILD_VERSION* */
|
---|
| 1632 | sprintf (buf, "%d", KBUILD_VERSION_MAJOR);
|
---|
[2591] | 1633 | define_variable_cname ("KBUILD_VERSION_MAJOR", buf, o_default, 0);
|
---|
[576] | 1634 | sprintf (buf, "%d", KBUILD_VERSION_MINOR);
|
---|
[1503] | 1635 | define_variable_cname ("KBUILD_VERSION_MINOR", buf, o_default, 0);
|
---|
| 1636 | sprintf (buf, "%d", KBUILD_VERSION_PATCH);
|
---|
| 1637 | define_variable_cname ("KBUILD_VERSION_PATCH", buf, o_default, 0);
|
---|
| 1638 | sprintf (buf, "%d", KBUILD_SVN_REV);
|
---|
| 1639 | define_variable_cname ("KBUILD_KMK_REVISION", buf, o_default, 0);
|
---|
[3140] | 1640 |
|
---|
[1503] | 1641 | sprintf (buf, "%d.%d.%d-r%d", KBUILD_VERSION_MAJOR, KBUILD_VERSION_MINOR,
|
---|
[2591] | 1642 | KBUILD_VERSION_PATCH, KBUILD_SVN_REV);
|
---|
[1503] | 1643 | define_variable_cname ("KBUILD_VERSION", buf, o_default, 0);
|
---|
[3421] | 1644 |
|
---|
[576] | 1645 | /* The host defaults. The BUILD_* stuff will be replaced by KBUILD_* soon. */
|
---|
[1503] | 1646 | envvar1 = lookup_variable (STRING_SIZE_TUPLE ("KBUILD_HOST"));
|
---|
| 1647 | envvar2 = lookup_variable (STRING_SIZE_TUPLE ("BUILD_PLATFORM"));
|
---|
| 1648 | val = envvar1 ? envvar1->value : envvar2 ? envvar2->value : KBUILD_HOST;
|
---|
| 1649 | if (envvar1 && envvar2 && strcmp (envvar1->value, envvar2->value))
|
---|
[3140] | 1650 | OS (error, NULL, _("KBUILD_HOST and BUILD_PLATFORM differs, using KBUILD_HOST=%s."), val);
|
---|
[1503] | 1651 | if (!envvar1)
|
---|
[2591] | 1652 | define_variable_cname ("KBUILD_HOST", val, o_default, 0);
|
---|
[1503] | 1653 | if (!envvar2)
|
---|
[3421] | 1654 | define_variable_cname ("BUILD_PLATFORM", "$(KBUILD_HOST)", o_default, 1);
|
---|
[1503] | 1655 |
|
---|
| 1656 | envvar1 = lookup_variable (STRING_SIZE_TUPLE ("KBUILD_HOST_ARCH"));
|
---|
| 1657 | envvar2 = lookup_variable (STRING_SIZE_TUPLE ("BUILD_PLATFORM_ARCH"));
|
---|
| 1658 | val = envvar1 ? envvar1->value : envvar2 ? envvar2->value : KBUILD_HOST_ARCH;
|
---|
| 1659 | if (envvar1 && envvar2 && strcmp (envvar1->value, envvar2->value))
|
---|
[3140] | 1660 | OS (error, NULL, _("KBUILD_HOST_ARCH and BUILD_PLATFORM_ARCH differs, using KBUILD_HOST_ARCH=%s."), val);
|
---|
[1503] | 1661 | if (!envvar1)
|
---|
[2591] | 1662 | define_variable_cname ("KBUILD_HOST_ARCH", val, o_default, 0);
|
---|
[1503] | 1663 | if (!envvar2)
|
---|
[3421] | 1664 | define_variable_cname ("BUILD_PLATFORM_ARCH", "$(KBUILD_HOST_ARCH)", o_default, 1);
|
---|
[1503] | 1665 |
|
---|
[2451] | 1666 | envvar1 = lookup_variable (STRING_SIZE_TUPLE ("KBUILD_HOST_CPU"));
|
---|
[3394] | 1667 | envvar2 = lookup_variable (STRING_SIZE_TUPLE ("BUILD_PLATFORM_CPU"));
|
---|
| 1668 | val = envvar1 ? envvar1->value : envvar2 ? envvar2->value : KBUILD_HOST_CPU;
|
---|
| 1669 | if (envvar1 && envvar2 && strcmp (envvar1->value, envvar2->value))
|
---|
[3395] | 1670 | OS (error, NULL, _("KBUILD_HOST_CPU and BUILD_PLATFORM_CPU differs, using KBUILD_HOST_CPU=%s."), val);
|
---|
| 1671 | if (!envvar1)
|
---|
[3394] | 1672 | define_variable_cname ("KBUILD_HOST_CPU", val, o_default, 0);
|
---|
| 1673 | if (!envvar2)
|
---|
[3395] | 1674 | define_variable_cname ("BUILD_PLATFORM_CPU", "$(KBUILD_HOST_CPU)", o_default, 1);
|
---|
[3394] | 1675 |
|
---|
| 1676 | /* The host kernel version. */
|
---|
| 1677 | # if defined(WINDOWS32)
|
---|
[3395] | 1678 | {
|
---|
| 1679 | OSVERSIONINFOEXW oix;
|
---|
[3394] | 1680 | NTSTATUS (WINAPI *pfnRtlGetVersion)(OSVERSIONINFOEXW *);
|
---|
| 1681 | *(FARPROC *)&pfnRtlGetVersion = GetProcAddress (GetModuleHandleW (L"NTDLL.DLL"),
|
---|
[3395] | 1682 | "RtlGetVersion"); /* GetVersionEx lies */
|
---|
| 1683 | memset (&oix, '\0', sizeof (oix));
|
---|
[3394] | 1684 | oix.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEXW);
|
---|
| 1685 | if (!pfnRtlGetVersion || pfnRtlGetVersion (&oix) < 0)
|
---|
| 1686 | {
|
---|
| 1687 | memset (&oix, '\0', sizeof (oix));
|
---|
| 1688 | oix.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEXW);
|
---|
| 1689 | if (!GetVersionExW((LPOSVERSIONINFOW)&oix))
|
---|
| 1690 | {
|
---|
| 1691 | memset (&oix, '\0', sizeof (oix));
|
---|
| 1692 | oix.dwOSVersionInfoSize = sizeof (OSVERSIONINFOW);
|
---|
| 1693 | GetVersionExW ((LPOSVERSIONINFOW)&oix);
|
---|
| 1694 | }
|
---|
| 1695 | }
|
---|
| 1696 | if (oix.dwPlatformId == VER_PLATFORM_WIN32_NT)
|
---|
| 1697 | {
|
---|
| 1698 | ulMajor = oix.dwMajorVersion;
|
---|
| 1699 | ulMinor = oix.dwMinorVersion;
|
---|
| 1700 | ulPatch = oix.wServicePackMajor;
|
---|
| 1701 | ul4th = oix.wServicePackMinor;
|
---|
[3395] | 1702 | }
|
---|
| 1703 | else
|
---|
| 1704 | {
|
---|
| 1705 | ulMajor = oix.dwPlatformId == 1 ? 0 /*Win95/98/ME*/
|
---|
| 1706 | : oix.dwPlatformId == 3 ? 1 /*WinCE*/
|
---|
| 1707 | : 2; /*??*/
|
---|
[3394] | 1708 | ulMinor = oix.dwMajorVersion;
|
---|
| 1709 | ulPatch = oix.dwMinorVersion;
|
---|
[2451] | 1710 | ul4th = oix.wServicePackMajor;
|
---|
| 1711 | }
|
---|
| 1712 | oix.dwBuildNumber &= 0x3fffffff;
|
---|
| 1713 | sprintf (buf, "%lu", oix.dwBuildNumber);
|
---|
| 1714 | define_variable_cname ("KBUILD_HOST_VERSION_BUILD", buf, o_default, 0);
|
---|
| 1715 |
|
---|
| 1716 | sprintf (buf, "%lu.%lu.%lu.%lu.%lu", ulMajor, ulMinor, ulPatch, ul4th, oix.dwBuildNumber);
|
---|
[3181] | 1717 | define_variable_cname ("KBUILD_HOST_VERSION", buf, o_default, 0);
|
---|
| 1718 | }
|
---|
| 1719 | # else
|
---|
| 1720 | memset (&uts, 0, sizeof(uts));
|
---|
| 1721 | uname (&uts);
|
---|
| 1722 | val = uts.release;
|
---|
[2451] | 1723 | ulMajor = parse_release_number (&val);
|
---|
| 1724 | ulMinor = parse_release_number (&val);
|
---|
[2591] | 1725 | ulPatch = parse_release_number (&val);
|
---|
[3395] | 1726 | ul4th = parse_release_number (&val);
|
---|
[2451] | 1727 |
|
---|
| 1728 | define_variable_cname ("KBUILD_HOST_UNAME_SYSNAME", uts.sysname, o_default, 0);
|
---|
[2591] | 1729 | define_variable_cname ("KBUILD_HOST_UNAME_RELEASE", uts.release, o_default, 0);
|
---|
[2451] | 1730 | define_variable_cname ("KBUILD_HOST_UNAME_VERSION", uts.version, o_default, 0);
|
---|
| 1731 | define_variable_cname ("KBUILD_HOST_UNAME_MACHINE", uts.machine, o_default, 0);
|
---|
[2591] | 1732 | define_variable_cname ("KBUILD_HOST_UNAME_NODENAME", uts.nodename, o_default, 0);
|
---|
[2451] | 1733 |
|
---|
| 1734 | sprintf (buf, "%lu.%lu.%lu.%lu", ulMajor, ulMinor, ulPatch, ul4th);
|
---|
[2591] | 1735 | define_variable_cname ("KBUILD_HOST_VERSION", buf, o_default, 0);
|
---|
[2451] | 1736 | # endif
|
---|
[917] | 1737 |
|
---|
[2591] | 1738 | sprintf (buf, "%lu", ulMajor);
|
---|
| 1739 | define_variable_cname ("KBUILD_HOST_VERSION_MAJOR", buf, o_default, 0);
|
---|
[1503] | 1740 |
|
---|
[3420] | 1741 | sprintf (buf, "%lu", ulMinor);
|
---|
| 1742 | define_variable_cname ("KBUILD_HOST_VERSION_MINOR", buf, o_default, 0);
|
---|
[578] | 1743 |
|
---|
[303] | 1744 | sprintf (buf, "%lu", ulPatch);
|
---|
[1121] | 1745 | define_variable_cname ("KBUILD_HOST_VERSION_PATCH", buf, o_default, 0);
|
---|
| 1746 |
|
---|
| 1747 | /* The kBuild locations. */
|
---|
[1716] | 1748 | define_variable_cname ("KBUILD_PATH", get_kbuild_path (), o_default, 0);
|
---|
[2548] | 1749 | define_variable_cname ("KBUILD_BIN_PATH", get_kbuild_bin_path (), o_default, 0);
|
---|
| 1750 |
|
---|
[1121] | 1751 | define_variable_cname ("PATH_KBUILD", "$(KBUILD_PATH)", o_default, 1);
|
---|
| 1752 | define_variable_cname ("PATH_KBUILD_BIN", "$(KBUILD_BIN_PATH)", o_default, 1);
|
---|
| 1753 |
|
---|
| 1754 | /* Define KMK_FEATURES to indicate various working KMK features. */
|
---|
[2024] | 1755 | # if defined (CONFIG_WITH_RSORT) \
|
---|
[1121] | 1756 | && defined (CONFIG_WITH_ABSPATHEX) \
|
---|
| 1757 | && defined (CONFIG_WITH_TOUPPER_TOLOWER) \
|
---|
| 1758 | && defined (CONFIG_WITH_DEFINED) \
|
---|
[1122] | 1759 | && defined (CONFIG_WITH_VALUE_LENGTH) \
|
---|
[2532] | 1760 | && defined (CONFIG_WITH_COMPARE) \
|
---|
[1171] | 1761 | && defined (CONFIG_WITH_STACK) \
|
---|
[1439] | 1762 | && defined (CONFIG_WITH_MATH) \
|
---|
[1915] | 1763 | && defined (CONFIG_WITH_XARGS) \
|
---|
[1440] | 1764 | && defined (CONFIG_WITH_EXPLICIT_MULTITARGET) \
|
---|
[2151] | 1765 | && defined (CONFIG_WITH_DOT_MUST_MAKE) \
|
---|
[2164] | 1766 | && defined (CONFIG_WITH_PREPEND_ASSIGNMENT) \
|
---|
[2172] | 1767 | && defined (CONFIG_WITH_SET_CONDITIONALS) \
|
---|
[2151] | 1768 | && defined (CONFIG_WITH_DATE) \
|
---|
[2489] | 1769 | && defined (CONFIG_WITH_FILE_SIZE) \
|
---|
[1121] | 1770 | && defined (CONFIG_WITH_WHERE_FUNCTION) \
|
---|
[2591] | 1771 | && defined (CONFIG_WITH_WHICH) \
|
---|
[3394] | 1772 | && defined (CONFIG_WITH_EVALPLUS) \
|
---|
[2591] | 1773 | && (defined (CONFIG_WITH_MAKE_STATS) || defined (CONFIG_WITH_MINIMAL_STATS)) \
|
---|
| 1774 | && defined (CONFIG_WITH_COMMANDS_FUNC) \
|
---|
| 1775 | && defined (CONFIG_WITH_PRINTF) \
|
---|
| 1776 | && defined (CONFIG_WITH_LOOP_FUNCTIONS) \
|
---|
| 1777 | && defined (CONFIG_WITH_ROOT_FUNC) \
|
---|
| 1778 | && defined (CONFIG_WITH_STRING_FUNCTIONS) \
|
---|
| 1779 | && defined (CONFIG_WITH_DEFINED_FUNCTIONS) \
|
---|
| 1780 | && defined (KMK_HELPERS)
|
---|
| 1781 | define_variable_cname ("KMK_FEATURES",
|
---|
| 1782 | "append-dash-n abspath includedep-queue install-hard-linking umask quote versort"
|
---|
| 1783 | " kBuild-define"
|
---|
| 1784 | " rsort"
|
---|
| 1785 | " abspathex"
|
---|
| 1786 | " toupper tolower"
|
---|
| 1787 | " defined"
|
---|
| 1788 | " comp-vars comp-cmds comp-cmds-ex"
|
---|
| 1789 | " stack"
|
---|
| 1790 | " math-int"
|
---|
| 1791 | " xargs"
|
---|
| 1792 | " explicit-multitarget"
|
---|
| 1793 | " dot-must-make"
|
---|
| 1794 | " prepend-assignment"
|
---|
| 1795 | " set-conditionals intersects"
|
---|
| 1796 | " date"
|
---|
| 1797 | " file-size"
|
---|
| 1798 | " expr if-expr select"
|
---|
| 1799 | " where"
|
---|
| 1800 | " which"
|
---|
[552] | 1801 | " evalctx evalval evalvalctx evalcall evalcall2 eval-opt-var"
|
---|
[938] | 1802 | " make-stats"
|
---|
[3394] | 1803 | " commands"
|
---|
[2548] | 1804 | " printf"
|
---|
[917] | 1805 | " for while"
|
---|
| 1806 | " root"
|
---|
[903] | 1807 | " length insert pos lastpos substr translate"
|
---|
[917] | 1808 | " kb-src-tool kb-obj-base kb-obj-suff kb-src-prop kb-src-one kb-exp-tmpl"
|
---|
| 1809 | " firstdefined lastdefined"
|
---|
[764] | 1810 | , o_default, 0);
|
---|
[917] | 1811 | # else /* MSC can't deal with strings mixed with #if/#endif, thus the slow way. */
|
---|
| 1812 | # error "All features should be enabled by default!"
|
---|
[552] | 1813 | strcpy (buf, "append-dash-n abspath includedep-queue install-hard-linking umask quote versort"
|
---|
[1716] | 1814 | " kBuild-define");
|
---|
| 1815 | # if defined (CONFIG_WITH_RSORT)
|
---|
| 1816 | strcat (buf, " rsort");
|
---|
[917] | 1817 | # endif
|
---|
[1440] | 1818 | # if defined (CONFIG_WITH_ABSPATHEX)
|
---|
[764] | 1819 | strcat (buf, " abspathex");
|
---|
[917] | 1820 | # endif
|
---|
| 1821 | # if defined (CONFIG_WITH_TOUPPER_TOLOWER)
|
---|
[764] | 1822 | strcat (buf, " toupper tolower");
|
---|
[917] | 1823 | # endif
|
---|
| 1824 | # if defined (CONFIG_WITH_DEFINED)
|
---|
[764] | 1825 | strcat (buf, " defined");
|
---|
[917] | 1826 | # endif
|
---|
| 1827 | # if defined (CONFIG_WITH_VALUE_LENGTH) && defined(CONFIG_WITH_COMPARE)
|
---|
[821] | 1828 | strcat (buf, " comp-vars comp-cmds comp-cmds-ex");
|
---|
[938] | 1829 | # endif
|
---|
| 1830 | # if defined (CONFIG_WITH_STACK)
|
---|
| 1831 | strcat (buf, " stack");
|
---|
[2024] | 1832 | # endif
|
---|
| 1833 | # if defined (CONFIG_WITH_MATH)
|
---|
| 1834 | strcat (buf, " math-int");
|
---|
[1109] | 1835 | # endif
|
---|
[938] | 1836 | # if defined (CONFIG_WITH_XARGS)
|
---|
| 1837 | strcat (buf, " xargs");
|
---|
[1109] | 1838 | # endif
|
---|
[2021] | 1839 | # if defined (CONFIG_WITH_EXPLICIT_MULTITARGET)
|
---|
[1109] | 1840 | strcat (buf, " explicit-multitarget");
|
---|
[1121] | 1841 | # endif
|
---|
| 1842 | # if defined (CONFIG_WITH_DOT_MUST_MAKE)
|
---|
| 1843 | strcat (buf, " dot-must-make");
|
---|
[1122] | 1844 | # endif
|
---|
| 1845 | # if defined (CONFIG_WITH_PREPEND_ASSIGNMENT)
|
---|
| 1846 | strcat (buf, " prepend-assignment");
|
---|
[1752] | 1847 | # endif
|
---|
[2164] | 1848 | # if defined (CONFIG_WITH_SET_CONDITIONALS)
|
---|
[1752] | 1849 | strcat (buf, " set-conditionals intersects");
|
---|
[2532] | 1850 | # endif
|
---|
| 1851 | # if defined (CONFIG_WITH_DATE)
|
---|
| 1852 | strcat (buf, " date");
|
---|
[1171] | 1853 | # endif
|
---|
| 1854 | # if defined (CONFIG_WITH_FILE_SIZE)
|
---|
| 1855 | strcat (buf, " file-size");
|
---|
[1439] | 1856 | # endif
|
---|
[1935] | 1857 | # if defined (CONFIG_WITH_IF_CONDITIONALS)
|
---|
[1438] | 1858 | strcat (buf, " expr if-expr select");
|
---|
[1915] | 1859 | # endif
|
---|
[1438] | 1860 | # if defined (CONFIG_WITH_WHERE_FUNCTION)
|
---|
| 1861 | strcat (buf, " where");
|
---|
[1440] | 1862 | # endif
|
---|
| 1863 | # if defined (CONFIG_WITH_WHICH)
|
---|
| 1864 | strcat (buf, " which");
|
---|
[2151] | 1865 | # endif
|
---|
| 1866 | # if defined (CONFIG_WITH_EVALPLUS)
|
---|
| 1867 | strcat (buf, " evalctx evalval evalvalctx evalcall evalcall2 eval-opt-var");
|
---|
[2164] | 1868 | # endif
|
---|
| 1869 | # if defined (CONFIG_WITH_MAKE_STATS) || defined (CONFIG_WITH_MINIMAL_STATS)
|
---|
| 1870 | strcat (buf, " make-stats");
|
---|
[2172] | 1871 | # endif
|
---|
| 1872 | # if defined (CONFIG_WITH_COMMANDS_FUNC)
|
---|
| 1873 | strcat (buf, " commands");
|
---|
[2151] | 1874 | # endif
|
---|
| 1875 | # if defined (CONFIG_WITH_PRINTF)
|
---|
| 1876 | strcat (buf, " printf");
|
---|
[2489] | 1877 | # endif
|
---|
| 1878 | # if defined (CONFIG_WITH_LOOP_FUNCTIONS)
|
---|
| 1879 | strcat (buf, " for while");
|
---|
[938] | 1880 | # endif
|
---|
[2011] | 1881 | # if defined (CONFIG_WITH_ROOT_FUNC)
|
---|
[552] | 1882 | strcat (buf, " root");
|
---|
[2591] | 1883 | # endif
|
---|
[764] | 1884 | # if defined (CONFIG_WITH_STRING_FUNCTIONS)
|
---|
[576] | 1885 | strcat (buf, " length insert pos lastpos substr translate");
|
---|
[552] | 1886 | # endif
|
---|
[303] | 1887 | # if defined (CONFIG_WITH_DEFINED_FUNCTIONS)
|
---|
[225] | 1888 | strcat (buf, " firstdefined lastdefined");
|
---|
[350] | 1889 | # endif
|
---|
[2591] | 1890 | # if defined (KMK_HELPERS)
|
---|
[225] | 1891 | strcat (buf, " kb-src-tool kb-obj-base kb-obj-suff kb-src-prop kb-src-one kb-exp-tmpl");
|
---|
| 1892 | # endif
|
---|
[53] | 1893 | define_variable_cname ("KMK_FEATURES", buf, o_default, 0);
|
---|
| 1894 | # endif
|
---|
| 1895 |
|
---|
| 1896 | #endif /* KMK */
|
---|
| 1897 |
|
---|
| 1898 | #ifdef CONFIG_WITH_KMK_BUILTIN
|
---|
| 1899 | /* The supported kMk Builtin commands. */
|
---|
| 1900 | define_variable_cname ("KMK_BUILTIN", "append cat chmod cp cmp echo expr install kDepIDB ln md5sum mkdir mv printf rm rmdir sleep test", o_default, 0);
|
---|
| 1901 | #endif
|
---|
[2591] | 1902 |
|
---|
[53] | 1903 | #ifdef __MSDOS__
|
---|
| 1904 | /* Allow to specify a special shell just for Make,
|
---|
[3140] | 1905 | and use $COMSPEC as the default $SHELL when appropriate. */
|
---|
[53] | 1906 | {
|
---|
| 1907 | static char shell_str[] = "SHELL";
|
---|
[3140] | 1908 | const int shlen = sizeof (shell_str) - 1;
|
---|
| 1909 | struct variable *mshp = lookup_variable ("MAKESHELL", 9);
|
---|
[53] | 1910 | struct variable *comp = lookup_variable ("COMSPEC", 7);
|
---|
[3140] | 1911 |
|
---|
| 1912 | /* $(MAKESHELL) overrides $(SHELL) even if -e is in effect. */
|
---|
[53] | 1913 | if (mshp)
|
---|
| 1914 | (void) define_variable (shell_str, shlen,
|
---|
| 1915 | mshp->value, o_env_override, 0);
|
---|
| 1916 | else if (comp)
|
---|
| 1917 | {
|
---|
| 1918 | /* $(COMSPEC) shouldn't override $(SHELL). */
|
---|
| 1919 | struct variable *shp = lookup_variable (shell_str, shlen);
|
---|
| 1920 |
|
---|
| 1921 | if (!shp)
|
---|
| 1922 | (void) define_variable (shell_str, shlen, comp->value, o_env, 0);
|
---|
| 1923 | }
|
---|
| 1924 | }
|
---|
| 1925 | #elif defined(__EMX__)
|
---|
| 1926 | {
|
---|
| 1927 | static char shell_str[] = "SHELL";
|
---|
| 1928 | const int shlen = sizeof (shell_str) - 1;
|
---|
| 1929 | struct variable *shell = lookup_variable (shell_str, shlen);
|
---|
[3140] | 1930 | struct variable *replace = lookup_variable ("MAKESHELL", 9);
|
---|
| 1931 |
|
---|
| 1932 | /* if $MAKESHELL is defined in the environment assume o_env_override */
|
---|
| 1933 | if (replace && *replace->value && replace->origin == o_env)
|
---|
| 1934 | replace->origin = o_env_override;
|
---|
| 1935 |
|
---|
| 1936 | /* if $MAKESHELL is not defined use $SHELL but only if the variable
|
---|
[53] | 1937 | did not come from the environment */
|
---|
| 1938 | if (!replace || !*replace->value)
|
---|
| 1939 | if (shell && *shell->value && (shell->origin == o_env
|
---|
| 1940 | || shell->origin == o_env_override))
|
---|
| 1941 | {
|
---|
| 1942 | /* overwrite whatever we got from the environment */
|
---|
| 1943 | free (shell->value);
|
---|
| 1944 | shell->value = xstrdup (default_shell);
|
---|
| 1945 | shell->origin = o_default;
|
---|
| 1946 | }
|
---|
| 1947 |
|
---|
| 1948 | /* Some people do not like cmd to be used as the default
|
---|
| 1949 | if $SHELL is not defined in the Makefile.
|
---|
| 1950 | With -DNO_CMD_DEFAULT you can turn off this behaviour */
|
---|
| 1951 | # ifndef NO_CMD_DEFAULT
|
---|
| 1952 | /* otherwise use $COMSPEC */
|
---|
| 1953 | if (!replace || !*replace->value)
|
---|
| 1954 | replace = lookup_variable ("COMSPEC", 7);
|
---|
| 1955 |
|
---|
[3140] | 1956 | /* otherwise use $OS2_SHELL */
|
---|
[53] | 1957 | if (!replace || !*replace->value)
|
---|
| 1958 | replace = lookup_variable ("OS2_SHELL", 9);
|
---|
| 1959 | # else
|
---|
[3140] | 1960 | # warning NO_CMD_DEFAULT: GNU make will not use CMD.EXE as default shell
|
---|
[53] | 1961 | # endif
|
---|
| 1962 |
|
---|
| 1963 | if (replace && *replace->value)
|
---|
| 1964 | /* overwrite $SHELL */
|
---|
[287] | 1965 | (void) define_variable (shell_str, shlen, replace->value,
|
---|
| 1966 | replace->origin, 0);
|
---|
[2591] | 1967 | else
|
---|
[1993] | 1968 | /* provide a definition if there is none */
|
---|
| 1969 | (void) define_variable (shell_str, shlen, default_shell,
|
---|
| 1970 | o_default, 0);
|
---|
[53] | 1971 | }
|
---|
[287] | 1972 |
|
---|
| 1973 | #endif
|
---|
| 1974 |
|
---|
| 1975 | /* This won't override any definition, but it will provide one if there
|
---|
[53] | 1976 | isn't one there. */
|
---|
| 1977 | v = define_variable_cname ("SHELL", default_shell, o_default, 0);
|
---|
| 1978 | #ifdef __MSDOS__
|
---|
| 1979 | v->export = v_export; /* Export always SHELL. */
|
---|
[1999] | 1980 | #endif
|
---|
[1932] | 1981 |
|
---|
| 1982 | /* On MSDOS we do use SHELL from environment, since it isn't a standard
|
---|
| 1983 | environment variable on MSDOS, so whoever sets it, does that on purpose.
|
---|
[1999] | 1984 | On OS/2 we do not use SHELL from environment but we have already handled
|
---|
[1932] | 1985 | that problem above. */
|
---|
[53] | 1986 | #if !defined(__MSDOS__) && !defined(__EMX__)
|
---|
| 1987 | /* Don't let SHELL come from the environment. */
|
---|
[1999] | 1988 | if (*v->value == '\0' || v->origin == o_env || v->origin == o_env_override)
|
---|
[531] | 1989 | {
|
---|
[533] | 1990 | # ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
|
---|
[1999] | 1991 | if (v->rdonly_val)
|
---|
[53] | 1992 | v->rdonly_val = 0;
|
---|
| 1993 | else
|
---|
| 1994 | # endif
|
---|
| 1995 | free (v->value);
|
---|
[2591] | 1996 | v->origin = o_file;
|
---|
[53] | 1997 | v->value = xstrdup (default_shell);
|
---|
| 1998 | # ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 1999 | v->value_length = strlen (v->value);
|
---|
| 2000 | v->value_alloc_len = v->value_length + 1;
|
---|
| 2001 | # endif
|
---|
[3140] | 2002 | }
|
---|
| 2003 | #endif
|
---|
| 2004 |
|
---|
| 2005 | /* Make sure MAKEFILES gets exported if it is set. */
|
---|
| 2006 | v = define_variable_cname ("MAKEFILES", "", o_default, 0);
|
---|
| 2007 | v->export = v_ifset;
|
---|
| 2008 |
|
---|
| 2009 | /* Define the magic D and F variables in terms of
|
---|
| 2010 | the automatic variables they are variations of. */
|
---|
| 2011 |
|
---|
| 2012 | #if defined(__MSDOS__) || defined(WINDOWS32)
|
---|
| 2013 | /* For consistency, remove the trailing backslash as well as slash. */
|
---|
| 2014 | define_variable_cname ("@D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $@)))",
|
---|
| 2015 | o_automatic, 1);
|
---|
| 2016 | define_variable_cname ("%D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $%)))",
|
---|
| 2017 | o_automatic, 1);
|
---|
| 2018 | define_variable_cname ("*D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $*)))",
|
---|
[2591] | 2019 | o_automatic, 1);
|
---|
| 2020 | define_variable_cname ("<D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $<)))",
|
---|
| 2021 | o_automatic, 1);
|
---|
| 2022 | define_variable_cname ("?D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $?)))",
|
---|
| 2023 | o_automatic, 1);
|
---|
| 2024 | define_variable_cname ("^D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $^)))",
|
---|
| 2025 | o_automatic, 1);
|
---|
[53] | 2026 | define_variable_cname ("+D", "$(patsubst %/,%,$(patsubst %\\,%,$(dir $+)))",
|
---|
[2591] | 2027 | o_automatic, 1);
|
---|
| 2028 | #else /* not __MSDOS__, not WINDOWS32 */
|
---|
| 2029 | define_variable_cname ("@D", "$(patsubst %/,%,$(dir $@))", o_automatic, 1);
|
---|
| 2030 | define_variable_cname ("%D", "$(patsubst %/,%,$(dir $%))", o_automatic, 1);
|
---|
| 2031 | define_variable_cname ("*D", "$(patsubst %/,%,$(dir $*))", o_automatic, 1);
|
---|
| 2032 | define_variable_cname ("<D", "$(patsubst %/,%,$(dir $<))", o_automatic, 1);
|
---|
| 2033 | define_variable_cname ("?D", "$(patsubst %/,%,$(dir $?))", o_automatic, 1);
|
---|
[1934] | 2034 | define_variable_cname ("^D", "$(patsubst %/,%,$(dir $^))", o_automatic, 1);
|
---|
| 2035 | define_variable_cname ("+D", "$(patsubst %/,%,$(dir $+))", o_automatic, 1);
|
---|
| 2036 | #endif
|
---|
| 2037 | define_variable_cname ("@F", "$(notdir $@)", o_automatic, 1);
|
---|
| 2038 | define_variable_cname ("%F", "$(notdir $%)", o_automatic, 1);
|
---|
| 2039 | define_variable_cname ("*F", "$(notdir $*)", o_automatic, 1);
|
---|
[53] | 2040 | define_variable_cname ("<F", "$(notdir $<)", o_automatic, 1);
|
---|
| 2041 | define_variable_cname ("?F", "$(notdir $?)", o_automatic, 1);
|
---|
| 2042 | define_variable_cname ("^F", "$(notdir $^)", o_automatic, 1);
|
---|
| 2043 | define_variable_cname ("+F", "$(notdir $+)", o_automatic, 1);
|
---|
[2893] | 2044 | #ifdef CONFIG_WITH_LAZY_DEPS_VARS
|
---|
| 2045 | define_variable ("^", 1, "$(deps $@)", o_automatic, 1);
|
---|
| 2046 | define_variable ("+", 1, "$(deps-all $@)", o_automatic, 1);
|
---|
| 2047 | define_variable ("?", 1, "$(deps-newer $@)", o_automatic, 1);
|
---|
| 2048 | define_variable ("|", 1, "$(deps-oo $@)", o_automatic, 1);
|
---|
| 2049 | #endif /* CONFIG_WITH_LAZY_DEPS_VARS */
|
---|
| 2050 | }
|
---|
| 2051 | |
---|
| 2052 |
|
---|
| 2053 | int export_all_variables;
|
---|
| 2054 |
|
---|
| 2055 | #ifdef KMK
|
---|
| 2056 | /* Cached table containing the exports of the global_variable_set. When
|
---|
| 2057 | there are many global variables, it can be so expensive to construct the
|
---|
| 2058 | child environment that we have a majority of job slot idle. */
|
---|
| 2059 | static size_t global_variable_set_exports_generation = ~(size_t)0;
|
---|
| 2060 | static struct hash_table global_variable_set_exports;
|
---|
| 2061 |
|
---|
| 2062 | static void update_global_variable_set_exports(void)
|
---|
| 2063 | {
|
---|
| 2064 | struct variable **v_slot;
|
---|
| 2065 | struct variable **v_end;
|
---|
| 2066 |
|
---|
| 2067 | /* Re-initialize the table. */
|
---|
| 2068 | if (global_variable_set_exports_generation != ~(size_t)0)
|
---|
| 2069 | hash_free (&global_variable_set_exports, 0);
|
---|
| 2070 | hash_init_strcached (&global_variable_set_exports, ENVIRONMENT_VARIABLE_BUCKETS,
|
---|
| 2071 | &variable_strcache, offsetof (struct variable, name));
|
---|
| 2072 |
|
---|
| 2073 | /* do pretty much the same as target_environment. */
|
---|
| 2074 | v_slot = (struct variable **) global_variable_set.table.ht_vec;
|
---|
| 2075 | v_end = v_slot + global_variable_set.table.ht_size;
|
---|
| 2076 | for ( ; v_slot < v_end; v_slot++)
|
---|
| 2077 | if (! HASH_VACANT (*v_slot))
|
---|
| 2078 | {
|
---|
| 2079 | struct variable **new_slot;
|
---|
| 2080 | struct variable *v = *v_slot;
|
---|
| 2081 |
|
---|
| 2082 | switch (v->export)
|
---|
| 2083 | {
|
---|
| 2084 | case v_default:
|
---|
| 2085 | if (v->origin == o_default || v->origin == o_automatic)
|
---|
| 2086 | /* Only export default variables by explicit request. */
|
---|
| 2087 | continue;
|
---|
| 2088 |
|
---|
| 2089 | /* The variable doesn't have a name that can be exported. */
|
---|
| 2090 | if (! v->exportable)
|
---|
| 2091 | continue;
|
---|
| 2092 |
|
---|
| 2093 | if (! export_all_variables
|
---|
| 2094 | && v->origin != o_command
|
---|
| 2095 | && v->origin != o_env && v->origin != o_env_override)
|
---|
| 2096 | continue;
|
---|
| 2097 | break;
|
---|
| 2098 |
|
---|
| 2099 | case v_export:
|
---|
| 2100 | break;
|
---|
| 2101 |
|
---|
| 2102 | case v_noexport:
|
---|
| 2103 | {
|
---|
| 2104 | /* If this is the SHELL variable and it's not exported,
|
---|
| 2105 | then add the value from our original environment, if
|
---|
| 2106 | the original environment defined a value for SHELL. */
|
---|
| 2107 | extern struct variable shell_var;
|
---|
| 2108 | if (streq (v->name, "SHELL") && shell_var.value)
|
---|
| 2109 | {
|
---|
| 2110 | v = &shell_var;
|
---|
| 2111 | break;
|
---|
| 2112 | }
|
---|
| 2113 | continue;
|
---|
| 2114 | }
|
---|
| 2115 |
|
---|
| 2116 | case v_ifset:
|
---|
| 2117 | if (v->origin == o_default)
|
---|
| 2118 | continue;
|
---|
| 2119 | break;
|
---|
| 2120 | }
|
---|
| 2121 |
|
---|
| 2122 | assert (strcache2_is_cached (&variable_strcache, v->name));
|
---|
[53] | 2123 | new_slot = (struct variable **) hash_find_slot_strcached (&global_variable_set_exports, v);
|
---|
[3140] | 2124 | if (HASH_VACANT (*new_slot))
|
---|
[53] | 2125 | hash_insert_at (&global_variable_set_exports, v, new_slot);
|
---|
| 2126 | }
|
---|
| 2127 |
|
---|
| 2128 | /* done */
|
---|
| 2129 | global_variable_set_exports_generation = global_variable_generation;
|
---|
| 2130 | }
|
---|
| 2131 |
|
---|
| 2132 | #endif
|
---|
| 2133 |
|
---|
| 2134 | /* Create a new environment for FILE's commands.
|
---|
| 2135 | If FILE is nil, this is for the 'shell' function.
|
---|
| 2136 | The child's MAKELEVEL variable is incremented. */
|
---|
| 2137 |
|
---|
[1889] | 2138 | char **
|
---|
| 2139 | target_environment (struct file *file)
|
---|
| 2140 | {
|
---|
[53] | 2141 | struct variable_set_list *set_list;
|
---|
[2893] | 2142 | register struct variable_set_list *s;
|
---|
| 2143 | struct hash_table table;
|
---|
| 2144 | struct variable **v_slot;
|
---|
| 2145 | struct variable **v_end;
|
---|
| 2146 | struct variable makelevel_key;
|
---|
[53] | 2147 | char **result_0;
|
---|
| 2148 | char **result;
|
---|
| 2149 | #ifdef CONFIG_WITH_STRCACHE2
|
---|
| 2150 | const char *cached_name;
|
---|
| 2151 | #endif
|
---|
[1902] | 2152 |
|
---|
[2893] | 2153 | #ifdef KMK
|
---|
[3140] | 2154 | if (global_variable_set_exports_generation != global_variable_generation)
|
---|
[1902] | 2155 | update_global_variable_set_exports();
|
---|
[2893] | 2156 | #endif
|
---|
[1902] | 2157 |
|
---|
| 2158 | if (file == 0)
|
---|
[53] | 2159 | set_list = current_variable_set_list;
|
---|
| 2160 | else
|
---|
| 2161 | set_list = file->variables;
|
---|
| 2162 |
|
---|
| 2163 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
| 2164 | hash_init (&table, ENVIRONMENT_VARIABLE_BUCKETS,
|
---|
[2893] | 2165 | variable_hash_1, variable_hash_2, variable_hash_cmp);
|
---|
| 2166 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
| 2167 | hash_init_strcached (&table, ENVIRONMENT_VARIABLE_BUCKETS,
|
---|
| 2168 | &variable_strcache, offsetof (struct variable, name));
|
---|
| 2169 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
| 2170 |
|
---|
| 2171 | /* Run through all the variable sets in the list,
|
---|
[53] | 2172 | accumulating variables in TABLE. */
|
---|
| 2173 | for (s = set_list; s != 0; s = s->next)
|
---|
| 2174 | {
|
---|
[3140] | 2175 | struct variable_set *set = s->set;
|
---|
| 2176 | #ifdef KMK
|
---|
| 2177 | if (set == &global_variable_set)
|
---|
| 2178 | {
|
---|
[53] | 2179 | assert(s->next == NULL);
|
---|
[3140] | 2180 | break;
|
---|
| 2181 | }
|
---|
| 2182 | #endif
|
---|
| 2183 | v_slot = (struct variable **) set->table.ht_vec;
|
---|
| 2184 | v_end = v_slot + set->table.ht_size;
|
---|
| 2185 | for ( ; v_slot < v_end; v_slot++)
|
---|
[53] | 2186 | if (! HASH_VACANT (*v_slot))
|
---|
[1877] | 2187 | {
|
---|
[3140] | 2188 | struct variable **new_slot;
|
---|
[53] | 2189 | struct variable *v = *v_slot;
|
---|
[1877] | 2190 |
|
---|
| 2191 | /* If this is a per-target variable and it hasn't been touched
|
---|
| 2192 | already then look up the global version and take its export
|
---|
[3140] | 2193 | value. */
|
---|
[1877] | 2194 | if (v->per_target && v->export == v_default)
|
---|
[3140] | 2195 | {
|
---|
| 2196 | struct variable *gv;
|
---|
| 2197 |
|
---|
[53] | 2198 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[3140] | 2199 | gv = lookup_variable_in_set (v->name, strlen (v->name),
|
---|
| 2200 | &global_variable_set);
|
---|
| 2201 | #else
|
---|
| 2202 | assert ((int)strlen(v->name) == v->length);
|
---|
| 2203 | gv = lookup_variable_in_set (v->name, v->length,
|
---|
| 2204 | &global_variable_set);
|
---|
[53] | 2205 | #endif
|
---|
| 2206 | if (gv)
|
---|
| 2207 | v->export = gv->export;
|
---|
| 2208 | }
|
---|
| 2209 |
|
---|
[3140] | 2210 | switch (v->export)
|
---|
| 2211 | {
|
---|
| 2212 | case v_default:
|
---|
| 2213 | if (v->origin == o_default || v->origin == o_automatic)
|
---|
| 2214 | /* Only export default variables by explicit request. */
|
---|
[53] | 2215 | continue;
|
---|
[3140] | 2216 |
|
---|
| 2217 | /* The variable doesn't have a name that can be exported. */
|
---|
[53] | 2218 | if (! v->exportable)
|
---|
[3140] | 2219 | continue;
|
---|
| 2220 |
|
---|
| 2221 | if (! export_all_variables
|
---|
| 2222 | && v->origin != o_command
|
---|
| 2223 | && v->origin != o_env && v->origin != o_env_override)
|
---|
| 2224 | continue;
|
---|
| 2225 | break;
|
---|
| 2226 |
|
---|
| 2227 | case v_export:
|
---|
| 2228 | break;
|
---|
| 2229 |
|
---|
| 2230 | case v_noexport:
|
---|
[53] | 2231 | {
|
---|
[3140] | 2232 | /* If this is the SHELL variable and it's not exported,
|
---|
| 2233 | then add the value from our original environment, if
|
---|
| 2234 | the original environment defined a value for SHELL. */
|
---|
| 2235 | if (streq (v->name, "SHELL") && shell_var.value)
|
---|
| 2236 | {
|
---|
[53] | 2237 | v = &shell_var;
|
---|
[1902] | 2238 | break;
|
---|
[3140] | 2239 | }
|
---|
[1902] | 2240 | continue;
|
---|
[1968] | 2241 | }
|
---|
[1902] | 2242 |
|
---|
| 2243 | case v_ifset:
|
---|
[3140] | 2244 | if (v->origin == o_default)
|
---|
| 2245 | continue;
|
---|
| 2246 | break;
|
---|
[53] | 2247 | }
|
---|
| 2248 |
|
---|
[2893] | 2249 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
| 2250 | new_slot = (struct variable **) hash_find_slot (&table, v);
|
---|
| 2251 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
| 2252 | assert (strcache2_is_cached (&variable_strcache, v->name));
|
---|
| 2253 | new_slot = (struct variable **) hash_find_slot_strcached (&table, v);
|
---|
| 2254 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
| 2255 | if (HASH_VACANT (*new_slot))
|
---|
| 2256 | hash_insert_at (&table, v, new_slot);
|
---|
| 2257 | }
|
---|
| 2258 | }
|
---|
| 2259 |
|
---|
| 2260 | #ifdef KMK
|
---|
| 2261 | /* Add the global exports to table. */
|
---|
| 2262 | v_slot = (struct variable **) global_variable_set_exports.ht_vec;
|
---|
| 2263 | v_end = v_slot + global_variable_set_exports.ht_size;
|
---|
| 2264 | for ( ; v_slot < v_end; v_slot++)
|
---|
[1887] | 2265 | if (! HASH_VACANT (*v_slot))
|
---|
[3140] | 2266 | {
|
---|
[53] | 2267 | struct variable **new_slot;
|
---|
| 2268 | struct variable *v = *v_slot;
|
---|
[1887] | 2269 | assert (strcache2_is_cached (&variable_strcache, v->name));
|
---|
| 2270 | new_slot = (struct variable **) hash_find_slot_strcached (&table, v);
|
---|
| 2271 | if (HASH_VACANT (*new_slot))
|
---|
[1902] | 2272 | hash_insert_at (&table, v, new_slot);
|
---|
| 2273 | }
|
---|
[1889] | 2274 | #endif
|
---|
| 2275 |
|
---|
| 2276 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
| 2277 | makelevel_key.name = (char *)MAKELEVEL_NAME;
|
---|
[1902] | 2278 | makelevel_key.length = MAKELEVEL_LENGTH;
|
---|
[1889] | 2279 | hash_delete (&table, &makelevel_key);
|
---|
[1887] | 2280 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
[53] | 2281 | /* lookup the name in the string case, if it's not there it won't
|
---|
[903] | 2282 | be in any of the sets either. */
|
---|
[53] | 2283 | cached_name = strcache2_lookup (&variable_strcache,
|
---|
| 2284 | MAKELEVEL_NAME, MAKELEVEL_LENGTH);
|
---|
| 2285 | if (cached_name)
|
---|
| 2286 | {
|
---|
| 2287 | makelevel_key.name = cached_name;
|
---|
| 2288 | makelevel_key.length = MAKELEVEL_LENGTH;
|
---|
[3140] | 2289 | hash_delete_strcached (&table, &makelevel_key);
|
---|
[53] | 2290 | }
|
---|
[3140] | 2291 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
| 2292 |
|
---|
| 2293 | result = result_0 = xmalloc ((table.ht_fill + 2) * sizeof (char *));
|
---|
| 2294 |
|
---|
| 2295 | v_slot = (struct variable **) table.ht_vec;
|
---|
| 2296 | v_end = v_slot + table.ht_size;
|
---|
[1827] | 2297 | for ( ; v_slot < v_end; v_slot++)
|
---|
[3140] | 2298 | if (! HASH_VACANT (*v_slot))
|
---|
[1827] | 2299 | {
|
---|
| 2300 | struct variable *v = *v_slot;
|
---|
| 2301 |
|
---|
[53] | 2302 | /* If V is recursively expanded and didn't come from the environment,
|
---|
[3140] | 2303 | expand its value. If it came from the environment, it should
|
---|
| 2304 | go back into the environment unchanged. */
|
---|
| 2305 | if (v->recursive
|
---|
[53] | 2306 | && v->origin != o_env && v->origin != o_env_override)
|
---|
[3140] | 2307 | {
|
---|
| 2308 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 2309 | char *value = recursively_expand_for_file (v, file);
|
---|
| 2310 | #else
|
---|
| 2311 | char *value = recursively_expand_for_file (v, file, NULL);
|
---|
[53] | 2312 | #endif
|
---|
[3140] | 2313 | #ifdef WINDOWS32
|
---|
| 2314 | if (strcmp (v->name, "Path") == 0 ||
|
---|
| 2315 | strcmp (v->name, "PATH") == 0)
|
---|
[53] | 2316 | convert_Path_to_windows32 (value, ';');
|
---|
[3140] | 2317 | #endif
|
---|
| 2318 | *result++ = xstrdup (concat (3, v->name, "=", value));
|
---|
[53] | 2319 | free (value);
|
---|
| 2320 | }
|
---|
[903] | 2321 | else
|
---|
| 2322 | {
|
---|
[53] | 2323 | #ifdef WINDOWS32
|
---|
| 2324 | if (strcmp (v->name, "Path") == 0 ||
|
---|
| 2325 | strcmp (v->name, "PATH") == 0)
|
---|
| 2326 | convert_Path_to_windows32 (v->value, ';');
|
---|
| 2327 | #endif
|
---|
| 2328 | *result++ = xstrdup (concat (3, v->name, "=", v->value));
|
---|
| 2329 | }
|
---|
[533] | 2330 | }
|
---|
[1610] | 2331 |
|
---|
| 2332 | *result = xmalloc (100);
|
---|
| 2333 | sprintf (*result, "%s=%u", MAKELEVEL_NAME, makelevel + 1);
|
---|
| 2334 | *++result = 0;
|
---|
| 2335 |
|
---|
| 2336 | hash_free (&table, 0);
|
---|
| 2337 |
|
---|
| 2338 | return result_0;
|
---|
| 2339 | }
|
---|
[2718] | 2340 | |
---|
| 2341 |
|
---|
| 2342 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[1610] | 2343 | /* Worker function for do_variable_definition_append() and
|
---|
[1617] | 2344 | append_expanded_string_to_variable().
|
---|
| 2345 | The APPEND argument indicates whether it's an append or prepend operation. */
|
---|
| 2346 | void append_string_to_variable (struct variable *v, const char *value, unsigned int value_len, int append)
|
---|
| 2347 | {
|
---|
[1610] | 2348 | /* The previous definition of the variable was recursive.
|
---|
[1997] | 2349 | The new value is the unexpanded old and new values. */
|
---|
[1610] | 2350 | unsigned int new_value_len = value_len + (v->value_length != 0 ? 1 + v->value_length : 0);
|
---|
[2005] | 2351 | int done_1st_prepend_copy = 0;
|
---|
| 2352 | #ifdef KMK
|
---|
| 2353 | assert (!v->alias);
|
---|
| 2354 | #endif
|
---|
[1997] | 2355 |
|
---|
[2006] | 2356 | /* Drop empty strings. Use $(NO_SUCH_VARIABLE) if a space is wanted. */
|
---|
[1932] | 2357 | if (!value_len)
|
---|
| 2358 | return;
|
---|
| 2359 |
|
---|
[1610] | 2360 | /* adjust the size. */
|
---|
[1932] | 2361 | if (v->value_alloc_len <= new_value_len + 1)
|
---|
[1610] | 2362 | {
|
---|
| 2363 | if (v->value_alloc_len < 256)
|
---|
| 2364 | v->value_alloc_len = 256;
|
---|
| 2365 | else
|
---|
| 2366 | v->value_alloc_len *= 2;
|
---|
| 2367 | if (v->value_alloc_len < new_value_len + 1)
|
---|
| 2368 | v->value_alloc_len = VAR_ALIGN_VALUE_ALLOC (new_value_len + 1 + value_len /*future*/ );
|
---|
[1932] | 2369 | # ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
|
---|
| 2370 | if ((append || !v->value_length) && !v->rdonly_val)
|
---|
| 2371 | # else
|
---|
| 2372 | if (append || !v->value_length)
|
---|
| 2373 | # endif
|
---|
| 2374 | v->value = xrealloc (v->value, v->value_alloc_len);
|
---|
[1610] | 2375 | else
|
---|
| 2376 | {
|
---|
[2004] | 2377 | /* avoid the extra memcpy the xrealloc may have to do */
|
---|
[1610] | 2378 | char *new_buf = xmalloc (v->value_alloc_len);
|
---|
| 2379 | memcpy (&new_buf[value_len + 1], v->value, v->value_length + 1);
|
---|
| 2380 | done_1st_prepend_copy = 1;
|
---|
| 2381 | # ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
|
---|
| 2382 | if (v->rdonly_val)
|
---|
| 2383 | v->rdonly_val = 0;
|
---|
| 2384 | else
|
---|
| 2385 | # endif
|
---|
| 2386 | free (v->value);
|
---|
| 2387 | v->value = new_buf;
|
---|
| 2388 | }
|
---|
| 2389 | MAKE_STATS_2(v->reallocs++);
|
---|
| 2390 | }
|
---|
| 2391 |
|
---|
| 2392 | /* insert the new bits */
|
---|
| 2393 | if (v->value_length != 0)
|
---|
| 2394 | {
|
---|
| 2395 | if (append)
|
---|
| 2396 | {
|
---|
| 2397 | v->value[v->value_length] = ' ';
|
---|
| 2398 | memcpy (&v->value[v->value_length + 1], value, value_len + 1);
|
---|
[2770] | 2399 | }
|
---|
[1610] | 2400 | else
|
---|
| 2401 | {
|
---|
[2717] | 2402 | if (!done_1st_prepend_copy)
|
---|
[3140] | 2403 | memmove (&v->value[value_len + 1], v->value, v->value_length + 1);
|
---|
[1809] | 2404 | v->value[value_len] = ' ';
|
---|
| 2405 | memcpy (v->value, value, value_len);
|
---|
| 2406 | }
|
---|
[533] | 2407 | }
|
---|
| 2408 | else
|
---|
| 2409 | memcpy (v->value, value, value_len + 1);
|
---|
| 2410 | v->value_length = new_value_len;
|
---|
| 2411 | VARIABLE_CHANGED (v);
|
---|
| 2412 | }
|
---|
| 2413 |
|
---|
| 2414 | struct variable *
|
---|
| 2415 | do_variable_definition_append (const floc *flocp, struct variable *v,
|
---|
| 2416 | const char *value, unsigned int value_len,
|
---|
| 2417 | int simple_value, enum variable_origin origin,
|
---|
| 2418 | int append)
|
---|
| 2419 | {
|
---|
| 2420 | if (env_overrides && origin == o_env)
|
---|
| 2421 | origin = o_env_override;
|
---|
| 2422 |
|
---|
| 2423 | if (env_overrides && v->origin == o_env)
|
---|
| 2424 | /* V came from in the environment. Since it was defined
|
---|
| 2425 | before the switches were parsed, it wasn't affected by -e. */
|
---|
| 2426 | v->origin = o_env_override;
|
---|
[534] | 2427 |
|
---|
[1107] | 2428 | /* A variable of this name is already defined.
|
---|
[1809] | 2429 | If the old definition is from a stronger source
|
---|
| 2430 | than this one, don't redefine it. */
|
---|
| 2431 | if ((int) origin < (int) v->origin)
|
---|
| 2432 | return v;
|
---|
[534] | 2433 | v->origin = origin;
|
---|
[1610] | 2434 |
|
---|
| 2435 | /* location */
|
---|
| 2436 | if (flocp != 0)
|
---|
[1809] | 2437 | v->fileinfo = *flocp;
|
---|
[533] | 2438 |
|
---|
| 2439 | /* The juicy bits, append the specified value to the variable
|
---|
| 2440 | This is a heavily exercised code path in kBuild. */
|
---|
| 2441 | if (value_len == ~0U)
|
---|
| 2442 | value_len = strlen (value);
|
---|
| 2443 | if (v->recursive || simple_value)
|
---|
[1993] | 2444 | append_string_to_variable (v, value, value_len, append);
|
---|
| 2445 | else
|
---|
| 2446 | /* The previous definition of the variable was simple.
|
---|
| 2447 | The new value comes from the old value, which was expanded
|
---|
| 2448 | when it was set; and from the expanded new value. */
|
---|
| 2449 | append_expanded_string_to_variable (v, value, value_len, append);
|
---|
| 2450 |
|
---|
| 2451 | /* update the variable */
|
---|
| 2452 | return v;
|
---|
| 2453 | }
|
---|
| 2454 | #endif /* CONFIG_WITH_VALUE_LENGTH */
|
---|
| 2455 | |
---|
| 2456 |
|
---|
| 2457 | static struct variable *
|
---|
[3140] | 2458 | set_special_var (struct variable *var)
|
---|
| 2459 | {
|
---|
| 2460 | if (streq (var->name, RECIPEPREFIX_NAME))
|
---|
| 2461 | {
|
---|
| 2462 | /* The user is resetting the command introduction prefix. This has to
|
---|
| 2463 | happen immediately, so that subsequent rules are interpreted
|
---|
| 2464 | properly. */
|
---|
| 2465 | cmd_prefix = var->value[0]=='\0' ? RECIPEPREFIX_DEFAULT : var->value[0];
|
---|
| 2466 | }
|
---|
| 2467 |
|
---|
| 2468 | return var;
|
---|
| 2469 | }
|
---|
| 2470 | |
---|
| 2471 |
|
---|
| 2472 | /* Given a string, shell-execute it and return a malloc'ed string of the
|
---|
| 2473 | * result. This removes only ONE newline (if any) at the end, for maximum
|
---|
| 2474 | * compatibility with the *BSD makes. If it fails, returns NULL. */
|
---|
| 2475 |
|
---|
| 2476 | static char *
|
---|
| 2477 | shell_result (const char *p)
|
---|
| 2478 | {
|
---|
| 2479 | char *buf;
|
---|
| 2480 | unsigned int len;
|
---|
[53] | 2481 | char *args[2];
|
---|
| 2482 | char *result;
|
---|
| 2483 |
|
---|
| 2484 | install_variable_buffer (&buf, &len);
|
---|
[1809] | 2485 |
|
---|
[3140] | 2486 | args[0] = (char *) p;
|
---|
[903] | 2487 | args[1] = NULL;
|
---|
[53] | 2488 | variable_buffer_output (func_shell_base (variable_buffer, args, 0), "\0", 1);
|
---|
[1809] | 2489 | result = strdup (variable_buffer);
|
---|
[3140] | 2490 |
|
---|
[1809] | 2491 | restore_variable_buffer (buf, len);
|
---|
| 2492 | return result;
|
---|
| 2493 | }
|
---|
| 2494 | |
---|
| 2495 |
|
---|
| 2496 | /* Given a variable, a value, and a flavor, define the variable.
|
---|
| 2497 | See the try_variable_definition() function for details on the parameters. */
|
---|
[53] | 2498 |
|
---|
[903] | 2499 | struct variable *
|
---|
| 2500 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[53] | 2501 | do_variable_definition (const floc *flocp, const char *varname,
|
---|
| 2502 | const char *value, enum variable_origin origin,
|
---|
| 2503 | enum variable_flavor flavor, int target_var)
|
---|
[526] | 2504 | #else /* CONFIG_WITH_VALUE_LENGTH */
|
---|
[2717] | 2505 | do_variable_definition_2 (const floc *flocp,
|
---|
[937] | 2506 | const char *varname, const char *value,
|
---|
[2717] | 2507 | unsigned int value_len, int simple_value,
|
---|
| 2508 | char *free_value,
|
---|
| 2509 | enum variable_origin origin,
|
---|
| 2510 | enum variable_flavor flavor,
|
---|
[937] | 2511 | int target_var)
|
---|
[53] | 2512 | #endif /* CONFIG_WITH_VALUE_LENGTH */
|
---|
| 2513 | {
|
---|
| 2514 | const char *p;
|
---|
| 2515 | char *alloc_value = NULL;
|
---|
| 2516 | struct variable *v;
|
---|
| 2517 | int append = 0;
|
---|
| 2518 | int conditional = 0;
|
---|
| 2519 | const size_t varname_len = strlen (varname); /* bird */
|
---|
| 2520 |
|
---|
| 2521 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 2522 | if (value_len == ~0U)
|
---|
| 2523 | value_len = strlen (value);
|
---|
[3140] | 2524 | else
|
---|
[53] | 2525 | assert (value_len == strlen (value));
|
---|
[1809] | 2526 | #endif
|
---|
[53] | 2527 |
|
---|
[1809] | 2528 | /* Calculate the variable's new value in VALUE. */
|
---|
| 2529 |
|
---|
| 2530 | switch (flavor)
|
---|
| 2531 | {
|
---|
| 2532 | default:
|
---|
| 2533 | case f_bogus:
|
---|
| 2534 | /* Should not be possible. */
|
---|
| 2535 | abort ();
|
---|
[2591] | 2536 | case f_simple:
|
---|
[1809] | 2537 | /* A simple variable definition "var := value". Expand the value.
|
---|
| 2538 | We have to allocate memory since otherwise it'll clobber the
|
---|
| 2539 | variable buffer, and we may still need that if we're looking at a
|
---|
| 2540 | target-specific variable. */
|
---|
| 2541 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 2542 | p = alloc_value = allocated_variable_expand (value);
|
---|
| 2543 | #else /* CONFIG_WITH_VALUE_LENGTH */
|
---|
| 2544 | if (!simple_value)
|
---|
[53] | 2545 | p = alloc_value = allocated_variable_expand_2 (value, value_len, &value_len);
|
---|
[3140] | 2546 | else
|
---|
| 2547 | {
|
---|
| 2548 | if (value_len == ~0U)
|
---|
| 2549 | value_len = strlen (value);
|
---|
| 2550 | if (!free_value)
|
---|
| 2551 | p = alloc_value = xstrndup (value, value_len);
|
---|
| 2552 | else
|
---|
| 2553 | {
|
---|
| 2554 | assert (value == free_value);
|
---|
| 2555 | p = alloc_value = free_value;
|
---|
[53] | 2556 | free_value = 0;
|
---|
| 2557 | }
|
---|
| 2558 | }
|
---|
[526] | 2559 | #endif /* CONFIG_WITH_VALUE_LENGTH */
|
---|
[53] | 2560 | break;
|
---|
[1993] | 2561 | case f_shell:
|
---|
| 2562 | {
|
---|
| 2563 | /* A shell definition "var != value". Expand value, pass it to
|
---|
| 2564 | the shell, and store the result in recursively-expanded var. */
|
---|
| 2565 | char *q = allocated_variable_expand (value);
|
---|
| 2566 | p = alloc_value = shell_result (q);
|
---|
| 2567 | free (q);
|
---|
| 2568 | flavor = f_recursive;
|
---|
| 2569 | break;
|
---|
[53] | 2570 | }
|
---|
| 2571 | case f_conditional:
|
---|
| 2572 | /* A conditional variable definition "var ?= value".
|
---|
| 2573 | The value is set IFF the variable is not defined yet. */
|
---|
| 2574 | v = lookup_variable (varname, varname_len);
|
---|
| 2575 | if (v)
|
---|
[3140] | 2576 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[53] | 2577 | return v->special ? set_special_var (v) : v;
|
---|
| 2578 | #else /* CONFIG_WITH_VALUE_LENGTH */
|
---|
[937] | 2579 | {
|
---|
[53] | 2580 | if (free_value)
|
---|
[937] | 2581 | free (free_value);
|
---|
[53] | 2582 | return v->special ? set_special_var (v) : v;
|
---|
[937] | 2583 | }
|
---|
| 2584 | #endif /* CONFIG_WITH_VALUE_LENGTH */
|
---|
| 2585 |
|
---|
| 2586 | conditional = 1;
|
---|
| 2587 | flavor = f_recursive;
|
---|
| 2588 | /* FALLTHROUGH */
|
---|
[53] | 2589 | case f_recursive:
|
---|
| 2590 | /* A recursive variable definition "var = value".
|
---|
| 2591 | The value is used verbatim. */
|
---|
| 2592 | p = value;
|
---|
| 2593 | break;
|
---|
[526] | 2594 | #ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
|
---|
[53] | 2595 | case f_append:
|
---|
[287] | 2596 | case f_prepend:
|
---|
| 2597 | {
|
---|
| 2598 | const enum variable_flavor org_flavor = flavor;
|
---|
| 2599 | #else
|
---|
| 2600 | case f_append:
|
---|
[53] | 2601 | {
|
---|
[2717] | 2602 | #endif
|
---|
| 2603 |
|
---|
| 2604 | /* If we have += but we're in a target variable context, we want to
|
---|
| 2605 | append only with other variables in the context of this target. */
|
---|
| 2606 | if (target_var)
|
---|
| 2607 | {
|
---|
| 2608 | append = 1;
|
---|
| 2609 | v = lookup_variable_in_set (varname, varname_len,
|
---|
| 2610 | current_variable_set_list->set);
|
---|
| 2611 |
|
---|
| 2612 | /* Don't append from the global set if a previous non-appending
|
---|
| 2613 | target-specific variable definition exists. */
|
---|
| 2614 | if (v && !v->append)
|
---|
| 2615 | append = 0;
|
---|
| 2616 | }
|
---|
| 2617 | #ifdef KMK
|
---|
| 2618 | else if ( g_pTopKbEvalData
|
---|
| 2619 | || ( varname_len > 3
|
---|
| 2620 | && varname[0] == '['
|
---|
| 2621 | && is_kbuild_object_variable_accessor (varname, varname_len)) )
|
---|
[53] | 2622 | {
|
---|
[526] | 2623 | v = kbuild_object_variable_pre_append (varname, varname_len,
|
---|
[53] | 2624 | value, value_len, simple_value,
|
---|
| 2625 | origin, org_flavor == f_append, flocp);
|
---|
| 2626 | if (free_value)
|
---|
| 2627 | free (free_value);
|
---|
| 2628 | return v;
|
---|
| 2629 | }
|
---|
| 2630 | #endif
|
---|
| 2631 | #ifdef CONFIG_WITH_LOCAL_VARIABLES
|
---|
| 2632 | /* If 'local', restrict it to the current variable context. */
|
---|
| 2633 | else if (origin == o_local)
|
---|
[533] | 2634 | v = lookup_variable_in_set (varname, varname_len,
|
---|
| 2635 | current_variable_set_list->set);
|
---|
[1809] | 2636 | #endif
|
---|
| 2637 | else
|
---|
[937] | 2638 | v = lookup_variable (varname, varname_len);
|
---|
[1809] | 2639 |
|
---|
[937] | 2640 | if (v == 0)
|
---|
[1809] | 2641 | {
|
---|
[937] | 2642 | /* There was no old value.
|
---|
[1809] | 2643 | This becomes a normal recursive definition. */
|
---|
| 2644 | p = value;
|
---|
| 2645 | flavor = f_recursive;
|
---|
[533] | 2646 | }
|
---|
| 2647 | else
|
---|
[53] | 2648 | {
|
---|
| 2649 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 2650 | v->append = append;
|
---|
[903] | 2651 | v = do_variable_definition_append (flocp, v, value, value_len,
|
---|
[2591] | 2652 | simple_value, origin,
|
---|
[53] | 2653 | # ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
|
---|
| 2654 | org_flavor == f_append);
|
---|
| 2655 | # else
|
---|
| 2656 | 1);
|
---|
| 2657 | # endif
|
---|
| 2658 | if (free_value)
|
---|
| 2659 | free (free_value);
|
---|
| 2660 | return v;
|
---|
| 2661 | #else /* !CONFIG_WITH_VALUE_LENGTH */
|
---|
| 2662 |
|
---|
| 2663 | /* Paste the old and new values together in VALUE. */
|
---|
| 2664 |
|
---|
[2591] | 2665 | unsigned int oldlen, vallen;
|
---|
[53] | 2666 | const char *val;
|
---|
[531] | 2667 | char *tp = NULL;
|
---|
[53] | 2668 |
|
---|
[2591] | 2669 | val = value;
|
---|
[937] | 2670 | if (v->recursive)
|
---|
| 2671 | /* The previous definition of the variable was recursive.
|
---|
| 2672 | The new value is the unexpanded old and new values. */
|
---|
[2591] | 2673 | flavor = f_recursive;
|
---|
| 2674 | else
|
---|
| 2675 | /* The previous definition of the variable was simple.
|
---|
[937] | 2676 | The new value comes from the old value, which was expanded
|
---|
| 2677 | when it was set; and from the expanded new value. Allocate
|
---|
| 2678 | memory for the expansion as we may still need the rest of the
|
---|
| 2679 | buffer if we're looking at a target-specific variable. */
|
---|
[2591] | 2680 | val = tp = allocated_variable_expand (val);
|
---|
| 2681 |
|
---|
| 2682 | oldlen = strlen (v->value);
|
---|
[937] | 2683 | vallen = strlen (val);
|
---|
[2591] | 2684 | p = alloc_value = xmalloc (oldlen + 1 + vallen + 1);
|
---|
[3140] | 2685 | # ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
|
---|
[531] | 2686 | if (org_flavor == f_prepend)
|
---|
[53] | 2687 | {
|
---|
| 2688 | memcpy (alloc_value, val, vallen);
|
---|
| 2689 | alloc_value[oldlen] = ' ';
|
---|
| 2690 | memcpy (&alloc_value[oldlen + 1], v->value, oldlen + 1);
|
---|
| 2691 | }
|
---|
| 2692 | else
|
---|
| 2693 | # endif /* CONFIG_WITH_PREPEND_ASSIGNMENT */
|
---|
[3140] | 2694 | {
|
---|
[53] | 2695 | memcpy (alloc_value, v->value, oldlen);
|
---|
| 2696 | alloc_value[oldlen] = ' ';
|
---|
| 2697 | memcpy (&alloc_value[oldlen + 1], val, vallen + 1);
|
---|
| 2698 | }
|
---|
| 2699 |
|
---|
| 2700 | free (tp);
|
---|
| 2701 | #endif /* !CONFIG_WITH_VALUE_LENGTH */
|
---|
| 2702 | }
|
---|
| 2703 | }
|
---|
| 2704 | }
|
---|
| 2705 |
|
---|
| 2706 | #ifdef __MSDOS__
|
---|
| 2707 | /* Many Unix Makefiles include a line saying "SHELL=/bin/sh", but
|
---|
[287] | 2708 | non-Unix systems don't conform to this default configuration (in
|
---|
[53] | 2709 | fact, most of them don't even have '/bin'). On the other hand,
|
---|
| 2710 | $SHELL in the environment, if set, points to the real pathname of
|
---|
| 2711 | the shell.
|
---|
[903] | 2712 | Therefore, we generally won't let lines like "SHELL=/bin/sh" from
|
---|
[3140] | 2713 | the Makefile override $SHELL from the environment. But first, we
|
---|
| 2714 | look for the basename of the shell in the directory where SHELL=
|
---|
[53] | 2715 | points, and along the $PATH; if it is found in any of these places,
|
---|
[3140] | 2716 | we define $SHELL to be the actual pathname of the shell. Thus, if
|
---|
[903] | 2717 | you have bash.exe installed as d:/unix/bash.exe, and d:/unix is on
|
---|
| 2718 | your $PATH, then SHELL=/usr/local/bin/bash will have the effect of
|
---|
| 2719 | defining SHELL to be "d:/unix/bash.exe". */
|
---|
[3140] | 2720 | if ((origin == o_file || origin == o_override)
|
---|
[53] | 2721 | && strcmp (varname, "SHELL") == 0)
|
---|
| 2722 | {
|
---|
[3140] | 2723 | PATH_VAR (shellpath);
|
---|
[53] | 2724 | extern char * __dosexec_find_on_path (const char *, char *[], char *);
|
---|
[3140] | 2725 |
|
---|
| 2726 | /* See if we can find "/bin/sh.exe", "/bin/sh.com", etc. */
|
---|
| 2727 | if (__dosexec_find_on_path (p, NULL, shellpath))
|
---|
| 2728 | {
|
---|
| 2729 | char *tp;
|
---|
| 2730 |
|
---|
[53] | 2731 | for (tp = shellpath; *tp; tp++)
|
---|
[3140] | 2732 | if (*tp == '\\')
|
---|
| 2733 | *tp = '/';
|
---|
| 2734 |
|
---|
| 2735 | v = define_variable_loc (varname, varname_len,
|
---|
| 2736 | shellpath, origin, flavor == f_recursive,
|
---|
| 2737 | flocp);
|
---|
| 2738 | }
|
---|
| 2739 | else
|
---|
| 2740 | {
|
---|
| 2741 | const char *shellbase, *bslash;
|
---|
[53] | 2742 | struct variable *pathv = lookup_variable ("PATH", 4);
|
---|
[3140] | 2743 | char *path_string;
|
---|
| 2744 | char *fake_env[2];
|
---|
| 2745 | size_t pathlen = 0;
|
---|
| 2746 |
|
---|
| 2747 | shellbase = strrchr (p, '/');
|
---|
| 2748 | bslash = strrchr (p, '\\');
|
---|
| 2749 | if (!shellbase || bslash > shellbase)
|
---|
| 2750 | shellbase = bslash;
|
---|
| 2751 | if (!shellbase && p[1] == ':')
|
---|
| 2752 | shellbase = p + 1;
|
---|
| 2753 | if (shellbase)
|
---|
| 2754 | shellbase++;
|
---|
[53] | 2755 | else
|
---|
[3140] | 2756 | shellbase = p;
|
---|
[903] | 2757 |
|
---|
| 2758 | /* Search for the basename of the shell (with standard
|
---|
| 2759 | executable extensions) along the $PATH. */
|
---|
[3140] | 2760 | if (pathv)
|
---|
[53] | 2761 | pathlen = strlen (pathv->value);
|
---|
| 2762 | path_string = xmalloc (5 + pathlen + 2 + 1);
|
---|
| 2763 | /* On MSDOS, current directory is considered as part of $PATH. */
|
---|
[3140] | 2764 | sprintf (path_string, "PATH=.;%s", pathv ? pathv->value : "");
|
---|
| 2765 | fake_env[0] = path_string;
|
---|
[53] | 2766 | fake_env[1] = 0;
|
---|
[3140] | 2767 | if (__dosexec_find_on_path (shellbase, fake_env, shellpath))
|
---|
| 2768 | {
|
---|
[53] | 2769 | char *tp;
|
---|
| 2770 |
|
---|
| 2771 | for (tp = shellpath; *tp; tp++)
|
---|
| 2772 | if (*tp == '\\')
|
---|
[526] | 2773 | *tp = '/';
|
---|
| 2774 |
|
---|
[503] | 2775 | v = define_variable_loc (varname, varname_len,
|
---|
[53] | 2776 | shellpath, origin,
|
---|
[3140] | 2777 | flavor == f_recursive, flocp);
|
---|
[53] | 2778 | }
|
---|
| 2779 | else
|
---|
[3140] | 2780 | v = lookup_variable (varname, varname_len);
|
---|
[53] | 2781 |
|
---|
| 2782 | free (path_string);
|
---|
| 2783 | }
|
---|
| 2784 | }
|
---|
[526] | 2785 | else
|
---|
[531] | 2786 | #endif /* __MSDOS__ */
|
---|
| 2787 | #ifdef WINDOWS32
|
---|
[534] | 2788 | if ( varname_len == sizeof("SHELL") - 1 /* bird */
|
---|
[53] | 2789 | && (origin == o_file || origin == o_override || origin == o_command)
|
---|
| 2790 | && streq (varname, "SHELL"))
|
---|
| 2791 | {
|
---|
| 2792 | extern const char *default_shell;
|
---|
| 2793 |
|
---|
| 2794 | /* Call shell locator function. If it returns TRUE, then
|
---|
| 2795 | set no_default_sh_exe to indicate sh was found and
|
---|
| 2796 | set new value for SHELL variable. */
|
---|
[1993] | 2797 |
|
---|
[2591] | 2798 | if (find_and_set_default_shell (p))
|
---|
[1993] | 2799 | {
|
---|
| 2800 | v = define_variable_in_set (varname, varname_len, default_shell,
|
---|
[2591] | 2801 | # ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[1993] | 2802 | ~0U, 1 /* duplicate_value */,
|
---|
| 2803 | # endif
|
---|
| 2804 | origin, flavor == f_recursive,
|
---|
[2029] | 2805 | (target_var
|
---|
| 2806 | ? current_variable_set_list->set
|
---|
| 2807 | : NULL),
|
---|
[1993] | 2808 | flocp);
|
---|
| 2809 | no_default_sh_exe = 0;
|
---|
| 2810 | }
|
---|
| 2811 | else
|
---|
| 2812 | {
|
---|
| 2813 | char *tp = alloc_value;
|
---|
| 2814 |
|
---|
| 2815 | alloc_value = allocated_variable_expand (p);
|
---|
| 2816 |
|
---|
[2591] | 2817 | if (find_and_set_default_shell (alloc_value))
|
---|
[3140] | 2818 | {
|
---|
[1993] | 2819 | v = define_variable_in_set (varname, varname_len, p,
|
---|
[53] | 2820 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 2821 | ~0U, 1 /* duplicate_value */,
|
---|
| 2822 | #endif
|
---|
| 2823 | origin, flavor == f_recursive,
|
---|
| 2824 | (target_var
|
---|
| 2825 | ? current_variable_set_list->set
|
---|
| 2826 | : NULL),
|
---|
| 2827 | flocp);
|
---|
| 2828 | no_default_sh_exe = 0;
|
---|
| 2829 | }
|
---|
[526] | 2830 | else
|
---|
[531] | 2831 | v = lookup_variable (varname, varname_len);
|
---|
| 2832 |
|
---|
| 2833 | free (tp);
|
---|
[53] | 2834 | }
|
---|
[1408] | 2835 | }
|
---|
| 2836 | else
|
---|
| 2837 | #endif
|
---|
[53] | 2838 |
|
---|
[1408] | 2839 | /* If we are defining variables inside an $(eval ...), we might have a
|
---|
[53] | 2840 | different variable context pushed, not the global context (maybe we're
|
---|
| 2841 | inside a $(call ...) or something. Since this function is only ever
|
---|
| 2842 | invoked in places where we want to define globally visible variables,
|
---|
| 2843 | make sure we define this variable in the global set. */
|
---|
| 2844 |
|
---|
[531] | 2845 | v = define_variable_in_set (varname, varname_len, p,
|
---|
[3140] | 2846 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[1809] | 2847 | value_len, !alloc_value,
|
---|
| 2848 | #endif
|
---|
| 2849 | origin, flavor == f_recursive,
|
---|
[534] | 2850 | #ifdef CONFIG_WITH_LOCAL_VARIABLES
|
---|
[53] | 2851 | (target_var || origin == o_local
|
---|
[1993] | 2852 | #else
|
---|
[53] | 2853 | (target_var
|
---|
| 2854 | #endif
|
---|
[2591] | 2855 | ? current_variable_set_list->set : NULL),
|
---|
[53] | 2856 | flocp);
|
---|
[3140] | 2857 | v->append = append;
|
---|
| 2858 | v->conditional = conditional;
|
---|
[53] | 2859 |
|
---|
[2591] | 2860 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[3140] | 2861 | free (alloc_value);
|
---|
| 2862 | #else
|
---|
| 2863 | if (free_value)
|
---|
| 2864 | free (free_value);
|
---|
| 2865 | #endif
|
---|
| 2866 |
|
---|
| 2867 | return v->special ? set_special_var (v) : v;
|
---|
[53] | 2868 | }
|
---|
[2591] | 2869 | |
---|
[3140] | 2870 |
|
---|
[53] | 2871 | /* Parse P (a null-terminated string) as a variable definition.
|
---|
[2591] | 2872 |
|
---|
[3140] | 2873 | If it is not a variable definition, return NULL and the contents of *VAR
|
---|
[53] | 2874 | are undefined, except NAME is set to the first non-space character or NIL.
|
---|
[3140] | 2875 |
|
---|
| 2876 | If it is a variable definition, return a pointer to the char after the
|
---|
| 2877 | assignment token and set the following fields (only) of *VAR:
|
---|
| 2878 | name : name of the variable (ALWAYS SET) (NOT NUL-TERMINATED!)
|
---|
[2591] | 2879 | length : length of the variable name
|
---|
[53] | 2880 | value : value of the variable (nul-terminated)
|
---|
| 2881 | flavor : flavor of the variable
|
---|
[2591] | 2882 | Other values in *VAR are unchanged.
|
---|
| 2883 | */
|
---|
| 2884 |
|
---|
[3140] | 2885 | char *
|
---|
| 2886 | parse_variable_definition (const char *p, struct variable *var)
|
---|
[2591] | 2887 | {
|
---|
| 2888 | int wspace = 0;
|
---|
[3140] | 2889 | const char *e = NULL;
|
---|
| 2890 |
|
---|
| 2891 | /** @todo merge 4.2.1: parse_variable_definition does more now */
|
---|
| 2892 | NEXT_TOKEN (p);
|
---|
| 2893 | var->name = (char *)p;
|
---|
| 2894 | var->length = 0;
|
---|
| 2895 |
|
---|
| 2896 | while (1)
|
---|
| 2897 | {
|
---|
| 2898 | int c = *p++;
|
---|
| 2899 |
|
---|
| 2900 | /* If we find a comment or EOS, it's not a variable definition. */
|
---|
| 2901 | if (STOP_SET (c, MAP_COMMENT|MAP_NUL))
|
---|
| 2902 | return NULL;
|
---|
[2591] | 2903 |
|
---|
[3140] | 2904 | if (c == '$')
|
---|
[53] | 2905 | {
|
---|
[3140] | 2906 | /* This begins a variable expansion reference. Make sure we don't
|
---|
| 2907 | treat chars inside the reference as assignment tokens. */
|
---|
| 2908 | char closeparen;
|
---|
| 2909 | unsigned int count;
|
---|
| 2910 |
|
---|
| 2911 | c = *p++;
|
---|
| 2912 | if (c == '(')
|
---|
| 2913 | closeparen = ')';
|
---|
| 2914 | else if (c == '{')
|
---|
| 2915 | closeparen = '}';
|
---|
| 2916 | else if (c == '\0')
|
---|
| 2917 | return NULL;
|
---|
[2591] | 2918 | else
|
---|
[3140] | 2919 | /* '$$' or '$X'. Either way, nothing special to do here. */
|
---|
[2591] | 2920 | continue;
|
---|
| 2921 |
|
---|
[3140] | 2922 | /* P now points past the opening paren or brace.
|
---|
[2591] | 2923 | Count parens or braces until it is matched. */
|
---|
| 2924 | for (count = 1; *p != '\0'; ++p)
|
---|
[3140] | 2925 | {
|
---|
| 2926 | if (*p == closeparen && --count == 0)
|
---|
[2591] | 2927 | {
|
---|
| 2928 | ++p;
|
---|
| 2929 | break;
|
---|
| 2930 | }
|
---|
| 2931 | if (*p == c)
|
---|
| 2932 | ++count;
|
---|
| 2933 | }
|
---|
| 2934 | continue;
|
---|
[3140] | 2935 | }
|
---|
| 2936 |
|
---|
| 2937 | /* If we find whitespace skip it, and remember we found it. */
|
---|
| 2938 | if (ISBLANK (c))
|
---|
| 2939 | {
|
---|
| 2940 | wspace = 1;
|
---|
[2591] | 2941 | e = p - 1;
|
---|
[3140] | 2942 | NEXT_TOKEN (p);
|
---|
[2591] | 2943 | c = *p;
|
---|
| 2944 | if (c == '\0')
|
---|
| 2945 | return NULL;
|
---|
| 2946 | ++p;
|
---|
| 2947 | }
|
---|
[3140] | 2948 |
|
---|
[2591] | 2949 |
|
---|
| 2950 | if (c == '=')
|
---|
[3140] | 2951 | {
|
---|
[2591] | 2952 | var->flavor = f_recursive;
|
---|
| 2953 | if (! e)
|
---|
| 2954 | e = p - 1;
|
---|
[3140] | 2955 | break;
|
---|
[2591] | 2956 | }
|
---|
| 2957 |
|
---|
| 2958 | /* Match assignment variants (:=, +=, ?=, !=) */
|
---|
[3140] | 2959 | if (*p == '=')
|
---|
[2591] | 2960 | {
|
---|
[3140] | 2961 | switch (c)
|
---|
| 2962 | {
|
---|
| 2963 | case ':':
|
---|
[2591] | 2964 | var->flavor = f_simple;
|
---|
| 2965 | break;
|
---|
| 2966 | case '+':
|
---|
| 2967 | var->flavor = f_append;
|
---|
| 2968 | break;
|
---|
| 2969 | #ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
|
---|
| 2970 | case '<':
|
---|
| 2971 | var->flavor = f_prepend;
|
---|
[3140] | 2972 | break;
|
---|
| 2973 | #endif
|
---|
| 2974 | case '?':
|
---|
| 2975 | var->flavor = f_conditional;
|
---|
[2591] | 2976 | break;
|
---|
| 2977 | case '!':
|
---|
[3140] | 2978 | var->flavor = f_shell;
|
---|
| 2979 | break;
|
---|
| 2980 | default:
|
---|
| 2981 | /* If we skipped whitespace, non-assignments means no var. */
|
---|
| 2982 | if (wspace)
|
---|
| 2983 | return NULL;
|
---|
| 2984 |
|
---|
| 2985 | /* Might be assignment, or might be $= or #=. Check. */
|
---|
| 2986 | continue;
|
---|
| 2987 | }
|
---|
| 2988 | if (! e)
|
---|
| 2989 | e = p - 1;
|
---|
| 2990 | ++p;
|
---|
| 2991 | break;
|
---|
| 2992 | }
|
---|
[2591] | 2993 |
|
---|
| 2994 | /* Check for POSIX ::= syntax */
|
---|
| 2995 | if (c == ':')
|
---|
[53] | 2996 | {
|
---|
| 2997 | /* A colon other than :=/::= is not a variable defn. */
|
---|
[3140] | 2998 | if (*p != ':' || p[1] != '=')
|
---|
| 2999 | return NULL;
|
---|
| 3000 |
|
---|
| 3001 | /* POSIX allows ::= to be the same as GNU make's := */
|
---|
| 3002 | var->flavor = f_simple;
|
---|
| 3003 | if (! e)
|
---|
| 3004 | e = p - 1;
|
---|
| 3005 | p += 2;
|
---|
| 3006 | break;
|
---|
[2591] | 3007 | }
|
---|
| 3008 |
|
---|
| 3009 | /* If we skipped whitespace, non-assignments means no var. */
|
---|
| 3010 | if (wspace)
|
---|
| 3011 | return NULL;
|
---|
[3140] | 3012 | }
|
---|
[2591] | 3013 |
|
---|
| 3014 | var->length = e - var->name;
|
---|
| 3015 | var->value = next_token (p);
|
---|
| 3016 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
[3140] | 3017 | var->value_alloc_len = ~(unsigned int)0;
|
---|
[2591] | 3018 | var->value_length = -1;
|
---|
| 3019 | # ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
|
---|
| 3020 | var->rdonly_val = 0;
|
---|
| 3021 | # endif
|
---|
| 3022 | #endif
|
---|
[3140] | 3023 | return (char *)p;
|
---|
[2591] | 3024 | }
|
---|
| 3025 | |
---|
[530] | 3026 |
|
---|
[3140] | 3027 | /* Try to interpret LINE (a null-terminated string) as a variable definition.
|
---|
| 3028 |
|
---|
| 3029 | If LINE was recognized as a variable definition, a pointer to its 'struct
|
---|
| 3030 | variable' is returned. If LINE is not a variable definition, NULL is
|
---|
| 3031 | returned. */
|
---|
[534] | 3032 |
|
---|
[53] | 3033 | struct variable *
|
---|
| 3034 | assign_variable_definition (struct variable *v, const char *line IF_WITH_VALUE_LENGTH_PARAM(char *eos))
|
---|
[1809] | 3035 | {
|
---|
[3140] | 3036 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
| 3037 | char *name;
|
---|
| 3038 | #endif
|
---|
[53] | 3039 |
|
---|
[1809] | 3040 | if (!parse_variable_definition (line, v))
|
---|
[3140] | 3041 | return NULL;
|
---|
[1809] | 3042 |
|
---|
[53] | 3043 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 3044 | if (eos)
|
---|
[3140] | 3045 | {
|
---|
[53] | 3046 | v->value_length = eos - v->value;
|
---|
| 3047 | assert (strchr (v->value, '\0') == eos);
|
---|
| 3048 | }
|
---|
| 3049 | #endif
|
---|
| 3050 |
|
---|
| 3051 | /* Expand the name, so "$(foo)bar = baz" works. */
|
---|
[1408] | 3052 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[53] | 3053 | name = alloca (v->length + 1);
|
---|
| 3054 | memcpy (name, v->name, v->length);
|
---|
| 3055 | name[v->length] = '\0';
|
---|
| 3056 | v->name = allocated_variable_expand (name);
|
---|
[2591] | 3057 | #else /* CONFIG_WITH_VALUE_LENGTH */
|
---|
[53] | 3058 | v->name = allocated_variable_expand_2 (v->name, v->length, NULL);
|
---|
[3140] | 3059 | #endif /* CONFIG_WITH_VALUE_LENGTH */
|
---|
[53] | 3060 |
|
---|
| 3061 | if (v->name[0] == '\0')
|
---|
| 3062 | O (fatal, &v->fileinfo, _("empty variable name"));
|
---|
| 3063 |
|
---|
[3140] | 3064 | return v;
|
---|
[2591] | 3065 | }
|
---|
[53] | 3066 | |
---|
| 3067 |
|
---|
| 3068 | /* Try to interpret LINE (a null-terminated string) as a variable definition.
|
---|
| 3069 |
|
---|
| 3070 | ORIGIN may be o_file, o_override, o_env, o_env_override, o_local,
|
---|
| 3071 | or o_command specifying that the variable definition comes
|
---|
| 3072 | from a makefile, an override directive, the environment with
|
---|
| 3073 | or without the -e switch, or the command line.
|
---|
| 3074 |
|
---|
| 3075 | See the comments for assign_variable_definition().
|
---|
[1811] | 3076 |
|
---|
[2591] | 3077 | If LINE was recognized as a variable definition, a pointer to its 'struct
|
---|
[53] | 3078 | variable' is returned. If LINE is not a variable definition, NULL is
|
---|
| 3079 | returned. */
|
---|
| 3080 |
|
---|
| 3081 | struct variable *
|
---|
[1811] | 3082 | try_variable_definition (const floc *flocp, const char *line
|
---|
[2591] | 3083 | IF_WITH_VALUE_LENGTH_PARAM(char *eos),
|
---|
[1811] | 3084 | enum variable_origin origin, int target_var)
|
---|
[53] | 3085 | {
|
---|
[1999] | 3086 | struct variable v;
|
---|
[1811] | 3087 | struct variable *vp;
|
---|
| 3088 |
|
---|
| 3089 | if (flocp != 0)
|
---|
[1889] | 3090 | v.fileinfo = *flocp;
|
---|
[53] | 3091 | else
|
---|
[1889] | 3092 | v.fileinfo.filenm = 0;
|
---|
| 3093 |
|
---|
| 3094 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[53] | 3095 | if (!assign_variable_definition (&v, line))
|
---|
| 3096 | return 0;
|
---|
| 3097 |
|
---|
| 3098 | vp = do_variable_definition (flocp, v.name, v.value,
|
---|
[2765] | 3099 | origin, v.flavor, target_var);
|
---|
| 3100 | #else
|
---|
| 3101 | if (!assign_variable_definition (&v, line, eos))
|
---|
| 3102 | return 0;
|
---|
[2771] | 3103 |
|
---|
| 3104 | vp = do_variable_definition_2 (flocp, v.name, v.value, v.value_length,
|
---|
| 3105 | 0, NULL, origin, v.flavor, target_var);
|
---|
[2005] | 3106 | #endif
|
---|
| 3107 |
|
---|
| 3108 | #ifndef CONFIG_WITH_STRCACHE2
|
---|
[2752] | 3109 | free (v.name);
|
---|
[2006] | 3110 | #else
|
---|
| 3111 | free ((char *)v.name);
|
---|
[2005] | 3112 | #endif
|
---|
| 3113 |
|
---|
[53] | 3114 | return vp;
|
---|
| 3115 | }
|
---|
| 3116 | |
---|
| 3117 |
|
---|
| 3118 | #if defined (CONFIG_WITH_COMPILER) || defined (CONFIG_WITH_MAKE_STATS)
|
---|
[903] | 3119 | static unsigned long var_stats_evalvals, var_stats_evalvaled;
|
---|
| 3120 | static unsigned long var_stats_expands, var_stats_expanded;
|
---|
[53] | 3121 | #endif
|
---|
[2718] | 3122 | #ifdef CONFIG_WITH_COMPILER
|
---|
| 3123 | static unsigned long var_stats_expandprogs, var_stats_evalprogs;
|
---|
| 3124 | #endif
|
---|
| 3125 | #ifdef CONFIG_WITH_MAKE_STATS
|
---|
[53] | 3126 | static unsigned long var_stats_changes, var_stats_changed;
|
---|
| 3127 | static unsigned long var_stats_reallocs, var_stats_realloced;
|
---|
| 3128 | static unsigned long var_stats_references, var_stats_referenced;
|
---|
[3140] | 3129 | static unsigned long var_stats_val_len, var_stats_val_alloc_len;
|
---|
| 3130 | static unsigned long var_stats_val_rdonly_len;
|
---|
| 3131 | #endif
|
---|
[53] | 3132 |
|
---|
| 3133 | /* Print information for variable V, prefixing it with PREFIX. */
|
---|
| 3134 |
|
---|
| 3135 | static void
|
---|
| 3136 | print_variable (const void *item, void *arg)
|
---|
| 3137 | {
|
---|
| 3138 | const struct variable *v = item;
|
---|
| 3139 | const char *prefix = arg;
|
---|
| 3140 | const char *origin;
|
---|
| 3141 | #ifdef KMK
|
---|
| 3142 | const struct variable *alias = v;
|
---|
| 3143 | RESOLVE_ALIAS_VARIABLE(v);
|
---|
| 3144 | #endif
|
---|
| 3145 |
|
---|
| 3146 | switch (v->origin)
|
---|
| 3147 | {
|
---|
[3140] | 3148 | case o_automatic:
|
---|
[53] | 3149 | origin = _("automatic");
|
---|
[1408] | 3150 | break;
|
---|
| 3151 | case o_default:
|
---|
| 3152 | origin = _("default");
|
---|
| 3153 | break;
|
---|
| 3154 | case o_env:
|
---|
[53] | 3155 | origin = _("environment");
|
---|
| 3156 | break;
|
---|
| 3157 | case o_file:
|
---|
| 3158 | origin = _("makefile");
|
---|
| 3159 | break;
|
---|
| 3160 | case o_env_override:
|
---|
[2591] | 3161 | origin = _("environment under -e");
|
---|
| 3162 | break;
|
---|
[2718] | 3163 | case o_command:
|
---|
[53] | 3164 | origin = _("command line");
|
---|
[3140] | 3165 | break;
|
---|
| 3166 | case o_override:
|
---|
[2718] | 3167 | origin = _("'override' directive");
|
---|
| 3168 | break;
|
---|
| 3169 | #ifdef CONFIG_WITH_LOCAL_VARIABLES
|
---|
| 3170 | case o_local:
|
---|
| 3171 | origin = _("`local' directive");
|
---|
| 3172 | break;
|
---|
| 3173 | #endif
|
---|
| 3174 | case o_invalid:
|
---|
| 3175 | default:
|
---|
| 3176 | abort ();
|
---|
[2765] | 3177 | }
|
---|
| 3178 | fputs ("# ", stdout);
|
---|
[2771] | 3179 | fputs (origin, stdout);
|
---|
[2765] | 3180 | if (v->private_var)
|
---|
[2771] | 3181 | fputs (" private", stdout);
|
---|
[2765] | 3182 | #ifndef KMK
|
---|
[2771] | 3183 | if (v->fileinfo.filenm)
|
---|
[2765] | 3184 | printf (_(" (from '%s', line %lu)"),
|
---|
[2771] | 3185 | v->fileinfo.filenm, v->fileinfo.lineno + v->fileinfo.offset);
|
---|
| 3186 | #else /* KMK */
|
---|
[2765] | 3187 | if (alias->fileinfo.filenm)
|
---|
| 3188 | printf (_(" (from '%s', line %lu)"),
|
---|
| 3189 | alias->fileinfo.filenm, alias->fileinfo.lineno);
|
---|
[2771] | 3190 | if (alias->aliased)
|
---|
| 3191 | fputs (" aliased", stdout);
|
---|
| 3192 | if (alias->alias)
|
---|
| 3193 | printf (_(", alias for '%s'"), v->name);
|
---|
[2765] | 3194 | #endif /* KMK */
|
---|
[2771] | 3195 |
|
---|
[2765] | 3196 | #if defined (CONFIG_WITH_COMPILER) || defined (CONFIG_WITH_MAKE_STATS)
|
---|
| 3197 | if (v->evalval_count != 0)
|
---|
[2771] | 3198 | {
|
---|
| 3199 | # ifdef CONFIG_WITH_MAKE_STATS
|
---|
| 3200 | printf (_(", %u evalvals (%llu ticks)"), v->evalval_count, v->cTicksEvalVal);
|
---|
| 3201 | # else
|
---|
[2765] | 3202 | printf (_(", %u evalvals"), v->evalval_count);
|
---|
[2771] | 3203 | # endif
|
---|
| 3204 | var_stats_evalvaled++;
|
---|
| 3205 | }
|
---|
| 3206 | var_stats_evalvals += v->evalval_count;
|
---|
[2765] | 3207 |
|
---|
| 3208 | if (v->expand_count != 0)
|
---|
| 3209 | {
|
---|
[2005] | 3210 | printf (_(", %u expands"), v->expand_count);
|
---|
| 3211 | var_stats_expanded++;
|
---|
[2771] | 3212 | }
|
---|
| 3213 | var_stats_expands += v->expand_count;
|
---|
| 3214 |
|
---|
| 3215 | # ifdef CONFIG_WITH_COMPILER
|
---|
[2005] | 3216 | if (v->evalprog != 0)
|
---|
[2758] | 3217 | {
|
---|
[2005] | 3218 | printf (_(", evalprog"));
|
---|
[2771] | 3219 | var_stats_evalprogs++;
|
---|
| 3220 | }
|
---|
| 3221 | if (v->expandprog != 0)
|
---|
| 3222 | {
|
---|
[2005] | 3223 | printf (_(", expandprog"));
|
---|
[2758] | 3224 | var_stats_expandprogs++;
|
---|
[2752] | 3225 | }
|
---|
[2771] | 3226 | # endif
|
---|
| 3227 | #endif
|
---|
| 3228 |
|
---|
| 3229 | #ifdef CONFIG_WITH_MAKE_STATS
|
---|
[2752] | 3230 | if (v->changes != 0)
|
---|
[2758] | 3231 | {
|
---|
[2006] | 3232 | printf (_(", %u changes"), v->changes);
|
---|
| 3233 | var_stats_changed++;
|
---|
| 3234 | }
|
---|
| 3235 | var_stats_changes += v->changes;
|
---|
| 3236 |
|
---|
| 3237 | if (v->reallocs != 0)
|
---|
| 3238 | {
|
---|
[2005] | 3239 | printf (_(", %u reallocs"), v->reallocs);
|
---|
[53] | 3240 | var_stats_realloced++;
|
---|
| 3241 | }
|
---|
| 3242 | var_stats_reallocs += v->reallocs;
|
---|
[3140] | 3243 |
|
---|
[53] | 3244 | if (v->references != 0)
|
---|
[2718] | 3245 | {
|
---|
[53] | 3246 | printf (_(", %u references"), v->references);
|
---|
[2718] | 3247 | var_stats_referenced++;
|
---|
| 3248 | }
|
---|
| 3249 | var_stats_references += v->references;
|
---|
[53] | 3250 |
|
---|
| 3251 | var_stats_val_len += v->value_length;
|
---|
[2591] | 3252 | if (v->value_alloc_len)
|
---|
[53] | 3253 | var_stats_val_alloc_len += v->value_alloc_len;
|
---|
[2718] | 3254 | else
|
---|
[53] | 3255 | var_stats_val_rdonly_len += v->value_length;
|
---|
[2718] | 3256 | assert (v->value_length == strlen (v->value));
|
---|
| 3257 | /*assert (v->rdonly_val ? !v->value_alloc_len : v->value_alloc_len > v->value_length); - FIXME */
|
---|
| 3258 | #endif /* CONFIG_WITH_MAKE_STATS */
|
---|
[53] | 3259 | putchar ('\n');
|
---|
| 3260 | fputs (prefix, stdout);
|
---|
| 3261 |
|
---|
| 3262 | /* Is this a 'define'? */
|
---|
[3140] | 3263 | if (v->recursive && strchr (v->value, '\n') != 0)
|
---|
| 3264 | #ifndef KMK /** @todo language feature for aliases */
|
---|
[53] | 3265 | printf ("define %s\n%s\nendef\n", v->name, v->value);
|
---|
[3140] | 3266 | #else
|
---|
[53] | 3267 | printf ("define %s\n%s\nendef\n", alias->name, v->value);
|
---|
[3140] | 3268 | #endif
|
---|
| 3269 | else
|
---|
| 3270 | {
|
---|
| 3271 | char *p;
|
---|
| 3272 |
|
---|
| 3273 | #ifndef KMK /** @todo language feature for aliases */
|
---|
| 3274 | printf ("%s %s= ", v->name, v->recursive ? v->append ? "+" : "" : ":");
|
---|
[53] | 3275 | #else
|
---|
| 3276 | printf ("%s %s= ", alias->name, v->recursive ? v->append ? "+" : "" : ":");
|
---|
| 3277 | #endif
|
---|
| 3278 |
|
---|
| 3279 | /* Check if the value is just whitespace. */
|
---|
[3140] | 3280 | p = next_token (v->value);
|
---|
| 3281 | if (p != v->value && *p == '\0')
|
---|
| 3282 | /* All whitespace. */
|
---|
| 3283 | printf ("$(subst ,,%s)", v->value);
|
---|
| 3284 | else if (v->recursive)
|
---|
| 3285 | fputs (v->value, stdout);
|
---|
| 3286 | else
|
---|
| 3287 | /* Double up dollar signs. */
|
---|
| 3288 | for (p = v->value; *p != '\0'; ++p)
|
---|
| 3289 | {
|
---|
| 3290 | if (*p == '$')
|
---|
| 3291 | putchar ('$');
|
---|
| 3292 | putchar (*p);
|
---|
| 3293 | }
|
---|
| 3294 | putchar ('\n');
|
---|
| 3295 | }
|
---|
| 3296 | }
|
---|
| 3297 |
|
---|
| 3298 |
|
---|
| 3299 | static void
|
---|
[53] | 3300 | print_auto_variable (const void *item, void *arg)
|
---|
| 3301 | {
|
---|
| 3302 | const struct variable *v = item;
|
---|
[3140] | 3303 |
|
---|
| 3304 | if (v->origin == o_automatic)
|
---|
| 3305 | print_variable (item, arg);
|
---|
[53] | 3306 | }
|
---|
[3140] | 3307 |
|
---|
[53] | 3308 |
|
---|
[2765] | 3309 | static void
|
---|
| 3310 | print_noauto_variable (const void *item, void *arg)
|
---|
| 3311 | {
|
---|
| 3312 | const struct variable *v = item;
|
---|
[2771] | 3313 |
|
---|
| 3314 | if (v->origin != o_automatic)
|
---|
| 3315 | print_variable (item, arg);
|
---|
[2005] | 3316 | }
|
---|
| 3317 |
|
---|
[2752] | 3318 |
|
---|
| 3319 | /* Print all the variables in SET. PREFIX is printed before
|
---|
| 3320 | the actual variable definitions (everything else is comments). */
|
---|
[2765] | 3321 |
|
---|
[2005] | 3322 | #ifndef KMK
|
---|
[3140] | 3323 | static
|
---|
| 3324 | #endif
|
---|
[53] | 3325 | void
|
---|
[2006] | 3326 | print_variable_set (struct variable_set *set, const char *prefix, int pauto)
|
---|
| 3327 | {
|
---|
[2765] | 3328 | #if defined (CONFIG_WITH_COMPILER) || defined (CONFIG_WITH_MAKE_STATS)
|
---|
[2006] | 3329 | var_stats_expands = var_stats_expanded = var_stats_evalvals
|
---|
| 3330 | = var_stats_evalvaled = 0;
|
---|
| 3331 | #endif
|
---|
| 3332 | #ifdef CONFIG_WITH_COMPILER
|
---|
| 3333 | var_stats_expandprogs = var_stats_evalprogs = 0;
|
---|
[2011] | 3334 | #endif
|
---|
[2006] | 3335 | #ifdef CONFIG_WITH_MAKE_STATS
|
---|
| 3336 | var_stats_changes = var_stats_changed = var_stats_reallocs
|
---|
| 3337 | = var_stats_realloced = var_stats_references = var_stats_referenced
|
---|
| 3338 | = var_stats_val_len = var_stats_val_alloc_len
|
---|
| 3339 | = var_stats_val_rdonly_len = 0;
|
---|
| 3340 | #endif
|
---|
| 3341 |
|
---|
| 3342 | hash_map_arg (&set->table, (pauto ? print_auto_variable : print_variable),
|
---|
| 3343 | (void *)prefix);
|
---|
| 3344 |
|
---|
| 3345 | if (set->table.ht_fill)
|
---|
| 3346 | {
|
---|
| 3347 | #ifdef CONFIG_WITH_MAKE_STATS
|
---|
| 3348 | unsigned long fragmentation;
|
---|
| 3349 |
|
---|
| 3350 | fragmentation = var_stats_val_alloc_len - (var_stats_val_len - var_stats_val_rdonly_len);
|
---|
| 3351 | printf(_("# variable set value stats:\n\
|
---|
[2752] | 3352 | # strings %7lu bytes, readonly %6lu bytes\n"),
|
---|
| 3353 | var_stats_val_len, var_stats_val_rdonly_len);
|
---|
| 3354 |
|
---|
| 3355 | if (var_stats_val_alloc_len)
|
---|
| 3356 | printf(_("# allocated %7lu bytes, fragmentation %6lu bytes (%u%%)\n"),
|
---|
| 3357 | var_stats_val_alloc_len, fragmentation,
|
---|
[2765] | 3358 | (unsigned int)((100.0 * fragmentation) / var_stats_val_alloc_len));
|
---|
| 3359 |
|
---|
| 3360 | if (var_stats_changed)
|
---|
| 3361 | printf(_("# changed %5lu (%2u%%), changes %6lu\n"),
|
---|
| 3362 | var_stats_changed,
|
---|
| 3363 | (unsigned int)((100.0 * var_stats_changed) / set->table.ht_fill),
|
---|
| 3364 | var_stats_changes);
|
---|
| 3365 |
|
---|
| 3366 | if (var_stats_realloced)
|
---|
| 3367 | printf(_("# reallocated %5lu (%2u%%), reallocations %6lu\n"),
|
---|
| 3368 | var_stats_realloced,
|
---|
| 3369 | (unsigned int)((100.0 * var_stats_realloced) / set->table.ht_fill),
|
---|
| 3370 | var_stats_reallocs);
|
---|
[2771] | 3371 |
|
---|
| 3372 | if (var_stats_referenced)
|
---|
| 3373 | printf(_("# referenced %5lu (%2u%%), references %6lu\n"),
|
---|
| 3374 | var_stats_referenced,
|
---|
| 3375 | (unsigned int)((100.0 * var_stats_referenced) / set->table.ht_fill),
|
---|
| 3376 | var_stats_references);
|
---|
| 3377 | #endif
|
---|
| 3378 | #if defined (CONFIG_WITH_COMPILER) || defined (CONFIG_WITH_MAKE_STATS)
|
---|
[2006] | 3379 | if (var_stats_evalvals)
|
---|
[2005] | 3380 | printf(_("# evalvaled %5lu (%2u%%), evalval calls %6lu\n"),
|
---|
[53] | 3381 | var_stats_evalvaled,
|
---|
| 3382 | (unsigned int)((100.0 * var_stats_evalvaled) / set->table.ht_fill),
|
---|
| 3383 | var_stats_evalvals);
|
---|
| 3384 | if (var_stats_expands)
|
---|
| 3385 | printf(_("# expanded %5lu (%2u%%), expands %6lu\n"),
|
---|
| 3386 | var_stats_expanded,
|
---|
| 3387 | (unsigned int)((100.0 * var_stats_expanded) / set->table.ht_fill),
|
---|
| 3388 | var_stats_expands);
|
---|
| 3389 | #endif
|
---|
| 3390 | #ifdef CONFIG_WITH_COMPILER
|
---|
| 3391 | if (var_stats_expandprogs || var_stats_evalprogs)
|
---|
| 3392 | printf(_("# eval progs %5lu (%2u%%), expand progs %6lu (%2u%%)\n"),
|
---|
| 3393 | var_stats_evalprogs,
|
---|
[3140] | 3394 | (unsigned int)((100.0 * var_stats_evalprogs) / set->table.ht_fill),
|
---|
[53] | 3395 | var_stats_expandprogs,
|
---|
| 3396 | (unsigned int)((100.0 * var_stats_expandprogs) / set->table.ht_fill));
|
---|
| 3397 | #endif
|
---|
| 3398 | }
|
---|
| 3399 |
|
---|
[3140] | 3400 | fputs (_("# variable set hash-table stats:\n"), stdout);
|
---|
[53] | 3401 | fputs ("# ", stdout);
|
---|
| 3402 | hash_print_stats (&set->table, stdout);
|
---|
| 3403 | putc ('\n', stdout);
|
---|
| 3404 | }
|
---|
| 3405 |
|
---|
[3140] | 3406 | /* Print the data base of variables. */
|
---|
[53] | 3407 |
|
---|
| 3408 | void
|
---|
| 3409 | print_variable_data_base (void)
|
---|
| 3410 | {
|
---|
| 3411 | puts (_("\n# Variables\n"));
|
---|
| 3412 |
|
---|
| 3413 | print_variable_set (&global_variable_set, "", 0);
|
---|
[1877] | 3414 |
|
---|
| 3415 | puts (_("\n# Pattern-specific Variable Values"));
|
---|
| 3416 |
|
---|
| 3417 | {
|
---|
[53] | 3418 | struct pattern_var *p;
|
---|
| 3419 | unsigned int rules = 0;
|
---|
[1918] | 3420 |
|
---|
| 3421 | for (p = pattern_vars; p != 0; p = p->next)
|
---|
| 3422 | {
|
---|
| 3423 | ++rules;
|
---|
| 3424 | printf ("\n%s :\n", p->target);
|
---|
| 3425 | print_variable (&p->variable, (void *)"# ");
|
---|
| 3426 | }
|
---|
| 3427 |
|
---|
| 3428 | if (rules == 0)
|
---|
[53] | 3429 | puts (_("\n# No pattern-specific variable values."));
|
---|
| 3430 | else
|
---|
| 3431 | printf (_("\n# %u pattern-specific variable values"), rules);
|
---|
| 3432 | }
|
---|
[903] | 3433 |
|
---|
[53] | 3434 | #ifdef CONFIG_WITH_STRCACHE2
|
---|
| 3435 | strcache2_print_stats (&variable_strcache, "# ");
|
---|
[3140] | 3436 | #endif
|
---|
[53] | 3437 | }
|
---|
| 3438 |
|
---|
[3140] | 3439 | #ifdef CONFIG_WITH_PRINT_STATS_SWITCH
|
---|
| 3440 | void
|
---|
| 3441 | print_variable_stats (void)
|
---|
| 3442 | {
|
---|
| 3443 | fputs (_("\n# Global variable hash-table stats:\n# "), stdout);
|
---|
| 3444 | hash_print_stats (&global_variable_set.table, stdout);
|
---|
| 3445 | fputs ("\n", stdout);
|
---|
| 3446 | }
|
---|
| 3447 | #endif
|
---|
| 3448 |
|
---|
| 3449 | /* Print all the local variables of FILE. */
|
---|
| 3450 |
|
---|
| 3451 | void
|
---|
| 3452 | print_file_variables (const struct file *file)
|
---|
| 3453 | {
|
---|
| 3454 | if (file->variables != 0)
|
---|
| 3455 | print_variable_set (file->variables->set, "# ", 1);
|
---|
[53] | 3456 | }
|
---|
| 3457 |
|
---|
| 3458 | void
|
---|
| 3459 | print_target_variables (const struct file *file)
|
---|
[287] | 3460 | {
|
---|
[53] | 3461 | if (file->variables != 0)
|
---|
| 3462 | {
|
---|
| 3463 | int l = strlen (file->name);
|
---|
| 3464 | char *t = alloca (l + 3);
|
---|
| 3465 |
|
---|
[3140] | 3466 | strcpy (t, file->name);
|
---|
| 3467 | t[l] = ':';
|
---|
[53] | 3468 | t[l+1] = ' ';
|
---|
[3140] | 3469 | t[l+2] = '\0';
|
---|
[53] | 3470 |
|
---|
[2591] | 3471 | hash_map_arg (&file->variables->set->table, print_noauto_variable, t);
|
---|
[53] | 3472 | }
|
---|
| 3473 | }
|
---|
| 3474 |
|
---|
| 3475 | #ifdef WINDOWS32
|
---|
| 3476 | void
|
---|
| 3477 | sync_Path_environment (void)
|
---|
| 3478 | {
|
---|
| 3479 | char *path = allocated_variable_expand ("$(PATH)");
|
---|
| 3480 | static char *environ_path = NULL;
|
---|
| 3481 |
|
---|
| 3482 | if (!path)
|
---|
| 3483 | return;
|
---|
| 3484 |
|
---|
| 3485 | /* If done this before, free the previous entry before allocating new one. */
|
---|
| 3486 | free (environ_path);
|
---|
| 3487 |
|
---|
| 3488 | /* Create something WINDOWS32 world can grok. */
|
---|
| 3489 | convert_Path_to_windows32 (path, ';');
|
---|
| 3490 | environ_path = xstrdup (concat (3, "PATH", "=", path));
|
---|
| 3491 | putenv (environ_path);
|
---|
| 3492 | free (path);
|
---|
| 3493 | }
|
---|
| 3494 | #endif
|
---|