Add VAR_INTERNAL as a context for variables set by make itself, which should not override those set by makefiles. Currently MAKEFILE is the only variable affected. Reviewed by: christosdiff -r1.223 -r1.224 src/usr.bin/make/main.c
(sjg)
--- src/usr.bin/make/main.c 2013/08/04 16:48:15 1.223
+++ src/usr.bin/make/main.c 2013/09/04 15:38:26 1.224
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: main.c,v 1.223 2013/08/04 16:48:15 sjg Exp $ */ | 1 | /* $NetBSD: main.c,v 1.224 2013/09/04 15:38:26 sjg Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1988, 1989, 1990, 1993 | 4 | * Copyright (c) 1988, 1989, 1990, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Adam de Boor. | 8 | * Adam de Boor. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -59,39 +59,39 @@ | @@ -59,39 +59,39 @@ | |||
59 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 59 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
60 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 60 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
61 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 61 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
62 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 62 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
63 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 63 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
64 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 64 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
65 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 65 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
68 | * SUCH DAMAGE. | 68 | * SUCH DAMAGE. | |
69 | */ | 69 | */ | |
70 | 70 | |||
71 | #ifndef MAKE_NATIVE | 71 | #ifndef MAKE_NATIVE | |
72 | static char rcsid[] = "$NetBSD: main.c,v 1.223 2013/08/04 16:48:15 sjg Exp $"; | 72 | static char rcsid[] = "$NetBSD: main.c,v 1.224 2013/09/04 15:38:26 sjg Exp $"; | |
73 | #else | 73 | #else | |
74 | #include <sys/cdefs.h> | 74 | #include <sys/cdefs.h> | |
75 | #ifndef lint | 75 | #ifndef lint | |
76 | __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\ | 76 | __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\ | |
77 | The Regents of the University of California. All rights reserved."); | 77 | The Regents of the University of California. All rights reserved."); | |
78 | #endif /* not lint */ | 78 | #endif /* not lint */ | |
79 | 79 | |||
80 | #ifndef lint | 80 | #ifndef lint | |
81 | #if 0 | 81 | #if 0 | |
82 | static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; | 82 | static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; | |
83 | #else | 83 | #else | |
84 | __RCSID("$NetBSD: main.c,v 1.223 2013/08/04 16:48:15 sjg Exp $"); | 84 | __RCSID("$NetBSD: main.c,v 1.224 2013/09/04 15:38:26 sjg Exp $"); | |
85 | #endif | 85 | #endif | |
86 | #endif /* not lint */ | 86 | #endif /* not lint */ | |
87 | #endif | 87 | #endif | |
88 | 88 | |||
89 | /*- | 89 | /*- | |
90 | * main.c -- | 90 | * main.c -- | |
91 | * The main file for this entire program. Exit routines etc | 91 | * The main file for this entire program. Exit routines etc | |
92 | * reside here. | 92 | * reside here. | |
93 | * | 93 | * | |
94 | * Utility functions defined in this file: | 94 | * Utility functions defined in this file: | |
95 | * Main_ParseArgLine Takes a line of arguments, breaks them and | 95 | * Main_ParseArgLine Takes a line of arguments, breaks them and | |
96 | * treats them as if they were given when first | 96 | * treats them as if they were given when first | |
97 | * invoked. Used by the parse module to implement | 97 | * invoked. Used by the parse module to implement | |
@@ -1374,27 +1374,27 @@ main(int argc, char **argv) | @@ -1374,27 +1374,27 @@ main(int argc, char **argv) | |||
1374 | * Side Effects: | 1374 | * Side Effects: | |
1375 | * lots | 1375 | * lots | |
1376 | */ | 1376 | */ | |
1377 | static int | 1377 | static int | |
1378 | ReadMakefile(const void *p, const void *q MAKE_ATTR_UNUSED) | 1378 | ReadMakefile(const void *p, const void *q MAKE_ATTR_UNUSED) | |
1379 | { | 1379 | { | |
1380 | const char *fname = p; /* makefile to read */ | 1380 | const char *fname = p; /* makefile to read */ | |
1381 | int fd; | 1381 | int fd; | |
1382 | size_t len = MAXPATHLEN; | 1382 | size_t len = MAXPATHLEN; | |
1383 | char *name, *path = bmake_malloc(len); | 1383 | char *name, *path = bmake_malloc(len); | |
1384 | 1384 | |||
1385 | if (!strcmp(fname, "-")) { | 1385 | if (!strcmp(fname, "-")) { | |
1386 | Parse_File(NULL /*stdin*/, -1); | 1386 | Parse_File(NULL /*stdin*/, -1); | |
1387 | Var_Set("MAKEFILE", "", VAR_GLOBAL, 0); | 1387 | Var_Set("MAKEFILE", "", VAR_INTERNAL, 0); | |
1388 | } else { | 1388 | } else { | |
1389 | /* if we've chdir'd, rebuild the path name */ | 1389 | /* if we've chdir'd, rebuild the path name */ | |
1390 | if (strcmp(curdir, objdir) && *fname != '/') { | 1390 | if (strcmp(curdir, objdir) && *fname != '/') { | |
1391 | size_t plen = strlen(curdir) + strlen(fname) + 2; | 1391 | size_t plen = strlen(curdir) + strlen(fname) + 2; | |
1392 | if (len < plen) | 1392 | if (len < plen) | |
1393 | path = bmake_realloc(path, len = 2 * plen); | 1393 | path = bmake_realloc(path, len = 2 * plen); | |
1394 | 1394 | |||
1395 | (void)snprintf(path, len, "%s/%s", curdir, fname); | 1395 | (void)snprintf(path, len, "%s/%s", curdir, fname); | |
1396 | fd = open(path, O_RDONLY); | 1396 | fd = open(path, O_RDONLY); | |
1397 | if (fd != -1) { | 1397 | if (fd != -1) { | |
1398 | fname = path; | 1398 | fname = path; | |
1399 | goto found; | 1399 | goto found; | |
1400 | } | 1400 | } | |
@@ -1423,27 +1423,27 @@ ReadMakefile(const void *p, const void * | @@ -1423,27 +1423,27 @@ ReadMakefile(const void *p, const void * | |||
1423 | if (name) | 1423 | if (name) | |
1424 | free(name); | 1424 | free(name); | |
1425 | free(path); | 1425 | free(path); | |
1426 | return(-1); | 1426 | return(-1); | |
1427 | } | 1427 | } | |
1428 | fname = name; | 1428 | fname = name; | |
1429 | /* | 1429 | /* | |
1430 | * set the MAKEFILE variable desired by System V fans -- the | 1430 | * set the MAKEFILE variable desired by System V fans -- the | |
1431 | * placement of the setting here means it gets set to the last | 1431 | * placement of the setting here means it gets set to the last | |
1432 | * makefile specified, as it is set by SysV make. | 1432 | * makefile specified, as it is set by SysV make. | |
1433 | */ | 1433 | */ | |
1434 | found: | 1434 | found: | |
1435 | if (!doing_depend) | 1435 | if (!doing_depend) | |
1436 | Var_Set("MAKEFILE", fname, VAR_GLOBAL, 0); | 1436 | Var_Set("MAKEFILE", fname, VAR_INTERNAL, 0); | |
1437 | Parse_File(fname, fd); | 1437 | Parse_File(fname, fd); | |
1438 | } | 1438 | } | |
1439 | free(path); | 1439 | free(path); | |
1440 | return(0); | 1440 | return(0); | |
1441 | } | 1441 | } | |
1442 | 1442 | |||
1443 | 1443 | |||
1444 | 1444 | |||
1445 | /*- | 1445 | /*- | |
1446 | * Cmd_Exec -- | 1446 | * Cmd_Exec -- | |
1447 | * Execute the command in cmd, and return the output of that command | 1447 | * Execute the command in cmd, and return the output of that command | |
1448 | * in a string. | 1448 | * in a string. | |
1449 | * | 1449 | * |
--- src/usr.bin/make/make.h 2013/06/18 20:06:09 1.91
+++ src/usr.bin/make/make.h 2013/09/04 15:38:26 1.92
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: make.h,v 1.91 2013/06/18 20:06:09 sjg Exp $ */ | 1 | /* $NetBSD: make.h,v 1.92 2013/09/04 15:38:26 sjg Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1988, 1989, 1990, 1993 | 4 | * Copyright (c) 1988, 1989, 1990, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Adam de Boor. | 8 | * Adam de Boor. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -378,26 +378,30 @@ extern Boolean doing_depend; /* TRUE if | @@ -378,26 +378,30 @@ extern Boolean doing_depend; /* TRUE if | |||
378 | 378 | |||
379 | extern Boolean checkEnvFirst; /* TRUE if environment should be searched for | 379 | extern Boolean checkEnvFirst; /* TRUE if environment should be searched for | |
380 | * variables before the global context */ | 380 | * variables before the global context */ | |
381 | extern Boolean jobServer; /* a jobServer already exists */ | 381 | extern Boolean jobServer; /* a jobServer already exists */ | |
382 | 382 | |||
383 | extern Boolean parseWarnFatal; /* TRUE if makefile parsing warnings are | 383 | extern Boolean parseWarnFatal; /* TRUE if makefile parsing warnings are | |
384 | * treated as errors */ | 384 | * treated as errors */ | |
385 | 385 | |||
386 | extern Boolean varNoExportEnv; /* TRUE if we should not export variables | 386 | extern Boolean varNoExportEnv; /* TRUE if we should not export variables | |
387 | * set on the command line to the env. */ | 387 | * set on the command line to the env. */ | |
388 | 388 | |||
389 | extern GNode *DEFAULT; /* .DEFAULT rule */ | 389 | extern GNode *DEFAULT; /* .DEFAULT rule */ | |
390 | 390 | |||
391 | extern GNode *VAR_INTERNAL; /* Variables defined internally by make | |||
392 | * which should not override those set by | |||
393 | * makefiles. | |||
394 | */ | |||
391 | extern GNode *VAR_GLOBAL; /* Variables defined in a global context, e.g | 395 | extern GNode *VAR_GLOBAL; /* Variables defined in a global context, e.g | |
392 | * in the Makefile itself */ | 396 | * in the Makefile itself */ | |
393 | extern GNode *VAR_CMD; /* Variables defined on the command line */ | 397 | extern GNode *VAR_CMD; /* Variables defined on the command line */ | |
394 | extern GNode *VAR_FOR; /* Iteration variables */ | 398 | extern GNode *VAR_FOR; /* Iteration variables */ | |
395 | extern char var_Error[]; /* Value returned by Var_Parse when an error | 399 | extern char var_Error[]; /* Value returned by Var_Parse when an error | |
396 | * is encountered. It actually points to | 400 | * is encountered. It actually points to | |
397 | * an empty string, so naive callers needn't | 401 | * an empty string, so naive callers needn't | |
398 | * worry about it. */ | 402 | * worry about it. */ | |
399 | 403 | |||
400 | extern time_t now; /* The time at the start of this whole | 404 | extern time_t now; /* The time at the start of this whole | |
401 | * process */ | 405 | * process */ | |
402 | 406 | |||
403 | extern Boolean oldVars; /* Do old-style variable substitution */ | 407 | extern Boolean oldVars; /* Do old-style variable substitution */ |
--- src/usr.bin/make/var.c 2013/07/16 20:00:56 1.183
+++ src/usr.bin/make/var.c 2013/09/04 15:38:26 1.184
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: var.c,v 1.183 2013/07/16 20:00:56 sjg Exp $ */ | 1 | /* $NetBSD: var.c,v 1.184 2013/09/04 15:38:26 sjg Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1988, 1989, 1990, 1993 | 4 | * Copyright (c) 1988, 1989, 1990, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Adam de Boor. | 8 | * Adam de Boor. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -59,34 +59,34 @@ | @@ -59,34 +59,34 @@ | |||
59 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 59 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
60 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 60 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
61 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 61 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
62 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 62 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
63 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 63 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
64 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 64 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
65 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 65 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
68 | * SUCH DAMAGE. | 68 | * SUCH DAMAGE. | |
69 | */ | 69 | */ | |
70 | 70 | |||
71 | #ifndef MAKE_NATIVE | 71 | #ifndef MAKE_NATIVE | |
72 | static char rcsid[] = "$NetBSD: var.c,v 1.183 2013/07/16 20:00:56 sjg Exp $"; | 72 | static char rcsid[] = "$NetBSD: var.c,v 1.184 2013/09/04 15:38:26 sjg Exp $"; | |
73 | #else | 73 | #else | |
74 | #include <sys/cdefs.h> | 74 | #include <sys/cdefs.h> | |
75 | #ifndef lint | 75 | #ifndef lint | |
76 | #if 0 | 76 | #if 0 | |
77 | static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; | 77 | static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; | |
78 | #else | 78 | #else | |
79 | __RCSID("$NetBSD: var.c,v 1.183 2013/07/16 20:00:56 sjg Exp $"); | 79 | __RCSID("$NetBSD: var.c,v 1.184 2013/09/04 15:38:26 sjg Exp $"); | |
80 | #endif | 80 | #endif | |
81 | #endif /* not lint */ | 81 | #endif /* not lint */ | |
82 | #endif | 82 | #endif | |
83 | 83 | |||
84 | /*- | 84 | /*- | |
85 | * var.c -- | 85 | * var.c -- | |
86 | * Variable-handling functions | 86 | * Variable-handling functions | |
87 | * | 87 | * | |
88 | * Interface: | 88 | * Interface: | |
89 | * Var_Set Set the value of a variable in the given | 89 | * Var_Set Set the value of a variable in the given | |
90 | * context. The variable is created if it doesn't | 90 | * context. The variable is created if it doesn't | |
91 | * yet exist. The value and variable name need not | 91 | * yet exist. The value and variable name need not | |
92 | * be preserved. | 92 | * be preserved. | |
@@ -166,26 +166,27 @@ static char varNoError[] = ""; | @@ -166,26 +166,27 @@ static char varNoError[] = ""; | |||
166 | * variable is appended-to, the result is placed in the global | 166 | * variable is appended-to, the result is placed in the global | |
167 | * context. | 167 | * context. | |
168 | * 2) the global context. Variables set in the Makefile are located in | 168 | * 2) the global context. Variables set in the Makefile are located in | |
169 | * the global context. It is the penultimate context searched when | 169 | * the global context. It is the penultimate context searched when | |
170 | * substituting. | 170 | * substituting. | |
171 | * 3) the command-line context. All variables set on the command line | 171 | * 3) the command-line context. All variables set on the command line | |
172 | * are placed in this context. They are UNALTERABLE once placed here. | 172 | * are placed in this context. They are UNALTERABLE once placed here. | |
173 | * 4) the local context. Each target has associated with it a context | 173 | * 4) the local context. Each target has associated with it a context | |
174 | * list. On this list are located the structures describing such | 174 | * list. On this list are located the structures describing such | |
175 | * local variables as $(@) and $(*) | 175 | * local variables as $(@) and $(*) | |
176 | * The four contexts are searched in the reverse order from which they are | 176 | * The four contexts are searched in the reverse order from which they are | |
177 | * listed. | 177 | * listed. | |
178 | */ | 178 | */ | |
179 | GNode *VAR_INTERNAL; /* variables from make itself */ | |||
179 | GNode *VAR_GLOBAL; /* variables from the makefile */ | 180 | GNode *VAR_GLOBAL; /* variables from the makefile */ | |
180 | GNode *VAR_CMD; /* variables defined on the command-line */ | 181 | GNode *VAR_CMD; /* variables defined on the command-line */ | |
181 | 182 | |||
182 | #define FIND_CMD 0x1 /* look in VAR_CMD when searching */ | 183 | #define FIND_CMD 0x1 /* look in VAR_CMD when searching */ | |
183 | #define FIND_GLOBAL 0x2 /* look in VAR_GLOBAL as well */ | 184 | #define FIND_GLOBAL 0x2 /* look in VAR_GLOBAL as well */ | |
184 | #define FIND_ENV 0x4 /* look in the environment also */ | 185 | #define FIND_ENV 0x4 /* look in the environment also */ | |
185 | 186 | |||
186 | typedef struct Var { | 187 | typedef struct Var { | |
187 | char *name; /* the variable's name */ | 188 | char *name; /* the variable's name */ | |
188 | Buffer val; /* its value */ | 189 | Buffer val; /* its value */ | |
189 | int flags; /* miscellaneous status flags */ | 190 | int flags; /* miscellaneous status flags */ | |
190 | #define VAR_IN_USE 1 /* Variable's value currently being used. | 191 | #define VAR_IN_USE 1 /* Variable's value currently being used. | |
191 | * Used to avoid recursion */ | 192 | * Used to avoid recursion */ | |
@@ -398,47 +399,54 @@ VarFind(const char *name, GNode *ctxt, i | @@ -398,47 +399,54 @@ VarFind(const char *name, GNode *ctxt, i | |||
398 | * First look for the variable in the given context. If it's not there, | 399 | * First look for the variable in the given context. If it's not there, | |
399 | * look for it in VAR_CMD, VAR_GLOBAL and the environment, in that order, | 400 | * look for it in VAR_CMD, VAR_GLOBAL and the environment, in that order, | |
400 | * depending on the FIND_* flags in 'flags' | 401 | * depending on the FIND_* flags in 'flags' | |
401 | */ | 402 | */ | |
402 | var = Hash_FindEntry(&ctxt->context, name); | 403 | var = Hash_FindEntry(&ctxt->context, name); | |
403 | 404 | |||
404 | if ((var == NULL) && (flags & FIND_CMD) && (ctxt != VAR_CMD)) { | 405 | if ((var == NULL) && (flags & FIND_CMD) && (ctxt != VAR_CMD)) { | |
405 | var = Hash_FindEntry(&VAR_CMD->context, name); | 406 | var = Hash_FindEntry(&VAR_CMD->context, name); | |
406 | } | 407 | } | |
407 | if (!checkEnvFirst && (var == NULL) && (flags & FIND_GLOBAL) && | 408 | if (!checkEnvFirst && (var == NULL) && (flags & FIND_GLOBAL) && | |
408 | (ctxt != VAR_GLOBAL)) | 409 | (ctxt != VAR_GLOBAL)) | |
409 | { | 410 | { | |
410 | var = Hash_FindEntry(&VAR_GLOBAL->context, name); | 411 | var = Hash_FindEntry(&VAR_GLOBAL->context, name); | |
412 | if ((var == NULL) && (ctxt != VAR_INTERNAL)) { | |||
413 | /* VAR_INTERNAL is subordinate to VAR_GLOBAL */ | |||
414 | var = Hash_FindEntry(&VAR_INTERNAL->context, name); | |||
415 | } | |||
411 | } | 416 | } | |
412 | if ((var == NULL) && (flags & FIND_ENV)) { | 417 | if ((var == NULL) && (flags & FIND_ENV)) { | |
413 | char *env; | 418 | char *env; | |
414 | 419 | |||
415 | if ((env = getenv(name)) != NULL) { | 420 | if ((env = getenv(name)) != NULL) { | |
416 | int len; | 421 | int len; | |
417 | 422 | |||
418 | v = bmake_malloc(sizeof(Var)); | 423 | v = bmake_malloc(sizeof(Var)); | |
419 | v->name = bmake_strdup(name); | 424 | v->name = bmake_strdup(name); | |
420 | 425 | |||
421 | len = strlen(env); | 426 | len = strlen(env); | |
422 | 427 | |||
423 | Buf_Init(&v->val, len + 1); | 428 | Buf_Init(&v->val, len + 1); | |
424 | Buf_AddBytes(&v->val, len, env); | 429 | Buf_AddBytes(&v->val, len, env); | |
425 | 430 | |||
426 | v->flags = VAR_FROM_ENV; | 431 | v->flags = VAR_FROM_ENV; | |
427 | return (v); | 432 | return (v); | |
428 | } else if (checkEnvFirst && (flags & FIND_GLOBAL) && | 433 | } else if (checkEnvFirst && (flags & FIND_GLOBAL) && | |
429 | (ctxt != VAR_GLOBAL)) | 434 | (ctxt != VAR_GLOBAL)) | |
430 | { | 435 | { | |
431 | var = Hash_FindEntry(&VAR_GLOBAL->context, name); | 436 | var = Hash_FindEntry(&VAR_GLOBAL->context, name); | |
437 | if ((var == NULL) && (ctxt != VAR_INTERNAL)) { | |||
438 | var = Hash_FindEntry(&VAR_INTERNAL->context, name); | |||
439 | } | |||
432 | if (var == NULL) { | 440 | if (var == NULL) { | |
433 | return NULL; | 441 | return NULL; | |
434 | } else { | 442 | } else { | |
435 | return ((Var *)Hash_GetValue(var)); | 443 | return ((Var *)Hash_GetValue(var)); | |
436 | } | 444 | } | |
437 | } else { | 445 | } else { | |
438 | return NULL; | 446 | return NULL; | |
439 | } | 447 | } | |
440 | } else if (var == NULL) { | 448 | } else if (var == NULL) { | |
441 | return NULL; | 449 | return NULL; | |
442 | } else { | 450 | } else { | |
443 | return ((Var *)Hash_GetValue(var)); | 451 | return ((Var *)Hash_GetValue(var)); | |
444 | } | 452 | } | |
@@ -4127,26 +4135,27 @@ Var_GetHead(char *file) | @@ -4127,26 +4135,27 @@ Var_GetHead(char *file) | |||
4127 | * Var_Init -- | 4135 | * Var_Init -- | |
4128 | * Initialize the module | 4136 | * Initialize the module | |
4129 | * | 4137 | * | |
4130 | * Results: | 4138 | * Results: | |
4131 | * None | 4139 | * None | |
4132 | * | 4140 | * | |
4133 | * Side Effects: | 4141 | * Side Effects: | |
4134 | * The VAR_CMD and VAR_GLOBAL contexts are created | 4142 | * The VAR_CMD and VAR_GLOBAL contexts are created | |
4135 | *----------------------------------------------------------------------- | 4143 | *----------------------------------------------------------------------- | |
4136 | */ | 4144 | */ | |
4137 | void | 4145 | void | |
4138 | Var_Init(void) | 4146 | Var_Init(void) | |
4139 | { | 4147 | { | |
4148 | VAR_INTERNAL = Targ_NewGN("Internal"); | |||
4140 | VAR_GLOBAL = Targ_NewGN("Global"); | 4149 | VAR_GLOBAL = Targ_NewGN("Global"); | |
4141 | VAR_CMD = Targ_NewGN("Command"); | 4150 | VAR_CMD = Targ_NewGN("Command"); | |
4142 | 4151 | |||
4143 | } | 4152 | } | |
4144 | 4153 | |||
4145 | 4154 | |||
4146 | void | 4155 | void | |
4147 | Var_End(void) | 4156 | Var_End(void) | |
4148 | { | 4157 | { | |
4149 | } | 4158 | } | |
4150 | 4159 | |||
4151 | 4160 | |||
4152 | /****************** PRINT DEBUGGING INFO *****************/ | 4161 | /****************** PRINT DEBUGGING INFO *****************/ |