make(1): rename VAR_CMD to VAR_CMDLINE Since make has to do with both the command line and child commands, the former name was confusing.diff -r1.169 -r1.170 src/usr.bin/make/cond.c
(rillig)
--- src/usr.bin/make/cond.c 2020/10/26 21:34:10 1.169
+++ src/usr.bin/make/cond.c 2020/10/30 07:19:30 1.170
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: cond.c,v 1.169 2020/10/26 21:34:10 rillig Exp $ */ | 1 | /* $NetBSD: cond.c,v 1.170 2020/10/30 07:19:30 rillig Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. | 4 | * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. | |
5 | * All rights reserved. | 5 | * 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. | |
@@ -83,27 +83,27 @@ | @@ -83,27 +83,27 @@ | |||
83 | * Cond_restore_depth | 83 | * Cond_restore_depth | |
84 | * Save and restore the nesting of the conditions, at | 84 | * Save and restore the nesting of the conditions, at | |
85 | * the start and end of including another makefile, to | 85 | * the start and end of including another makefile, to | |
86 | * ensure that in each makefile the conditional | 86 | * ensure that in each makefile the conditional | |
87 | * directives are well-balanced. | 87 | * directives are well-balanced. | |
88 | */ | 88 | */ | |
89 | 89 | |||
90 | #include <errno.h> | 90 | #include <errno.h> | |
91 | 91 | |||
92 | #include "make.h" | 92 | #include "make.h" | |
93 | #include "dir.h" | 93 | #include "dir.h" | |
94 | 94 | |||
95 | /* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ | 95 | /* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ | |
96 | MAKE_RCSID("$NetBSD: cond.c,v 1.169 2020/10/26 21:34:10 rillig Exp $"); | 96 | MAKE_RCSID("$NetBSD: cond.c,v 1.170 2020/10/30 07:19:30 rillig Exp $"); | |
97 | 97 | |||
98 | /* | 98 | /* | |
99 | * The parsing of conditional expressions is based on this grammar: | 99 | * The parsing of conditional expressions is based on this grammar: | |
100 | * E -> F || E | 100 | * E -> F || E | |
101 | * E -> F | 101 | * E -> F | |
102 | * F -> T && F | 102 | * F -> T && F | |
103 | * F -> T | 103 | * F -> T | |
104 | * T -> defined(variable) | 104 | * T -> defined(variable) | |
105 | * T -> make(target) | 105 | * T -> make(target) | |
106 | * T -> exists(file) | 106 | * T -> exists(file) | |
107 | * T -> empty(varspec) | 107 | * T -> empty(varspec) | |
108 | * T -> target(name) | 108 | * T -> target(name) | |
109 | * T -> commands(name) | 109 | * T -> commands(name) | |
@@ -236,27 +236,28 @@ ParseFuncArg(const char **pp, Boolean do | @@ -236,27 +236,28 @@ ParseFuncArg(const char **pp, Boolean do | |||
236 | break; | 236 | break; | |
237 | if ((ch == '&' || ch == '|') && paren_depth == 0) | 237 | if ((ch == '&' || ch == '|') && paren_depth == 0) | |
238 | break; | 238 | break; | |
239 | if (*p == '$') { | 239 | if (*p == '$') { | |
240 | /* | 240 | /* | |
241 | * Parse the variable spec and install it as part of the argument | 241 | * Parse the variable spec and install it as part of the argument | |
242 | * if it's valid. We tell Var_Parse to complain on an undefined | 242 | * if it's valid. We tell Var_Parse to complain on an undefined | |
243 | * variable, so we don't need to do it. Nor do we return an error, | 243 | * variable, so we don't need to do it. Nor do we return an error, | |
244 | * though perhaps we should... | 244 | * though perhaps we should... | |
245 | */ | 245 | */ | |
246 | void *nestedVal_freeIt; | 246 | void *nestedVal_freeIt; | |
247 | VarEvalFlags eflags = VARE_UNDEFERR | (doEval ? VARE_WANTRES : 0); | 247 | VarEvalFlags eflags = VARE_UNDEFERR | (doEval ? VARE_WANTRES : 0); | |
248 | const char *nestedVal; | 248 | const char *nestedVal; | |
249 | (void)Var_Parse(&p, VAR_CMD, eflags, &nestedVal, &nestedVal_freeIt); | 249 | (void)Var_Parse(&p, VAR_CMDLINE, eflags, &nestedVal, | |
250 | &nestedVal_freeIt); | |||
250 | /* TODO: handle errors */ | 251 | /* TODO: handle errors */ | |
251 | Buf_AddStr(&argBuf, nestedVal); | 252 | Buf_AddStr(&argBuf, nestedVal); | |
252 | free(nestedVal_freeIt); | 253 | free(nestedVal_freeIt); | |
253 | continue; | 254 | continue; | |
254 | } | 255 | } | |
255 | if (ch == '(') | 256 | if (ch == '(') | |
256 | paren_depth++; | 257 | paren_depth++; | |
257 | else if (ch == ')' && --paren_depth < 0) | 258 | else if (ch == ')' && --paren_depth < 0) | |
258 | break; | 259 | break; | |
259 | Buf_AddByte(&argBuf, *p); | 260 | Buf_AddByte(&argBuf, *p); | |
260 | p++; | 261 | p++; | |
261 | } | 262 | } | |
262 | 263 | |||
@@ -273,27 +274,27 @@ ParseFuncArg(const char **pp, Boolean do | @@ -273,27 +274,27 @@ ParseFuncArg(const char **pp, Boolean do | |||
273 | /* The PARSE_FATAL is done as a follow-up by CondEvalExpression. */ | 274 | /* The PARSE_FATAL is done as a follow-up by CondEvalExpression. */ | |
274 | return 0; | 275 | return 0; | |
275 | } | 276 | } | |
276 | 277 | |||
277 | *pp = p; | 278 | *pp = p; | |
278 | return argLen; | 279 | return argLen; | |
279 | } | 280 | } | |
280 | 281 | |||
281 | /* Test whether the given variable is defined. */ | 282 | /* Test whether the given variable is defined. */ | |
282 | static Boolean | 283 | static Boolean | |
283 | FuncDefined(size_t argLen MAKE_ATTR_UNUSED, const char *arg) | 284 | FuncDefined(size_t argLen MAKE_ATTR_UNUSED, const char *arg) | |
284 | { | 285 | { | |
285 | char *freeIt; | 286 | char *freeIt; | |
286 | Boolean result = Var_Value(arg, VAR_CMD, &freeIt) != NULL; | 287 | Boolean result = Var_Value(arg, VAR_CMDLINE, &freeIt) != NULL; | |
287 | bmake_free(freeIt); | 288 | bmake_free(freeIt); | |
288 | return result; | 289 | return result; | |
289 | } | 290 | } | |
290 | 291 | |||
291 | /* See if the given target is being made. */ | 292 | /* See if the given target is being made. */ | |
292 | static Boolean | 293 | static Boolean | |
293 | FuncMake(size_t argLen MAKE_ATTR_UNUSED, const char *arg) | 294 | FuncMake(size_t argLen MAKE_ATTR_UNUSED, const char *arg) | |
294 | { | 295 | { | |
295 | StringListNode *ln; | 296 | StringListNode *ln; | |
296 | 297 | |||
297 | for (ln = opts.create->first; ln != NULL; ln = ln->next) | 298 | for (ln = opts.create->first; ln != NULL; ln = ln->next) | |
298 | if (Str_Match(ln->datum, arg)) | 299 | if (Str_Match(ln->datum, arg)) | |
299 | return TRUE; | 300 | return TRUE; | |
@@ -433,27 +434,28 @@ CondParser_String(CondParser *par, Boole | @@ -433,27 +434,28 @@ CondParser_String(CondParser *par, Boole | |||
433 | case ' ': | 434 | case ' ': | |
434 | case '\t': | 435 | case '\t': | |
435 | if (!qt) | 436 | if (!qt) | |
436 | goto got_str; | 437 | goto got_str; | |
437 | Buf_AddByte(&buf, par->p[0]); | 438 | Buf_AddByte(&buf, par->p[0]); | |
438 | par->p++; | 439 | par->p++; | |
439 | continue; | 440 | continue; | |
440 | case '$': | 441 | case '$': | |
441 | /* if we are in quotes, an undefined variable is ok */ | 442 | /* if we are in quotes, an undefined variable is ok */ | |
442 | eflags = ((!qt && doEval) ? VARE_UNDEFERR : 0) | | 443 | eflags = ((!qt && doEval) ? VARE_UNDEFERR : 0) | | |
443 | (doEval ? VARE_WANTRES : 0); | 444 | (doEval ? VARE_WANTRES : 0); | |
444 | nested_p = par->p; | 445 | nested_p = par->p; | |
445 | atStart = nested_p == start; | 446 | atStart = nested_p == start; | |
446 | parseResult = Var_Parse(&nested_p, VAR_CMD, eflags, &str, freeIt); | 447 | parseResult = Var_Parse(&nested_p, VAR_CMDLINE, eflags, &str, | |
448 | freeIt); | |||
447 | /* TODO: handle errors */ | 449 | /* TODO: handle errors */ | |
448 | if (str == var_Error) { | 450 | if (str == var_Error) { | |
449 | if (parseResult & VPR_ANY_MSG) | 451 | if (parseResult & VPR_ANY_MSG) | |
450 | par->printedError = TRUE; | 452 | par->printedError = TRUE; | |
451 | if (*freeIt) { | 453 | if (*freeIt) { | |
452 | free(*freeIt); | 454 | free(*freeIt); | |
453 | *freeIt = NULL; | 455 | *freeIt = NULL; | |
454 | } | 456 | } | |
455 | /* | 457 | /* | |
456 | * Even if !doEval, we still report syntax errors, which | 458 | * Even if !doEval, we still report syntax errors, which | |
457 | * is what getting var_Error back with !doEval means. | 459 | * is what getting var_Error back with !doEval means. | |
458 | */ | 460 | */ | |
459 | str = NULL; | 461 | str = NULL; | |
@@ -673,27 +675,27 @@ done: | @@ -673,27 +675,27 @@ done: | |||
673 | 675 | |||
674 | static size_t | 676 | static size_t | |
675 | ParseEmptyArg(const char **linePtr, Boolean doEval, | 677 | ParseEmptyArg(const char **linePtr, Boolean doEval, | |
676 | const char *func MAKE_ATTR_UNUSED, char **argPtr) | 678 | const char *func MAKE_ATTR_UNUSED, char **argPtr) | |
677 | { | 679 | { | |
678 | void *val_freeIt; | 680 | void *val_freeIt; | |
679 | const char *val; | 681 | const char *val; | |
680 | size_t magic_res; | 682 | size_t magic_res; | |
681 | 683 | |||
682 | /* We do all the work here and return the result as the length */ | 684 | /* We do all the work here and return the result as the length */ | |
683 | *argPtr = NULL; | 685 | *argPtr = NULL; | |
684 | 686 | |||
685 | (*linePtr)--; /* Make (*linePtr)[1] point to the '('. */ | 687 | (*linePtr)--; /* Make (*linePtr)[1] point to the '('. */ | |
686 | (void)Var_Parse(linePtr, VAR_CMD, doEval ? VARE_WANTRES : 0, | 688 | (void)Var_Parse(linePtr, VAR_CMDLINE, doEval ? VARE_WANTRES : 0, | |
687 | &val, &val_freeIt); | 689 | &val, &val_freeIt); | |
688 | /* TODO: handle errors */ | 690 | /* TODO: handle errors */ | |
689 | /* If successful, *linePtr points beyond the closing ')' now. */ | 691 | /* If successful, *linePtr points beyond the closing ')' now. */ | |
690 | 692 | |||
691 | if (val == var_Error) { | 693 | if (val == var_Error) { | |
692 | free(val_freeIt); | 694 | free(val_freeIt); | |
693 | return (size_t)-1; | 695 | return (size_t)-1; | |
694 | } | 696 | } | |
695 | 697 | |||
696 | /* A variable is empty when it just contains spaces... 4/15/92, christos */ | 698 | /* A variable is empty when it just contains spaces... 4/15/92, christos */ | |
697 | cpp_skip_whitespace(&val); | 699 | cpp_skip_whitespace(&val); | |
698 | 700 | |||
699 | /* | 701 | /* |
--- src/usr.bin/make/job.c 2020/10/26 23:28:52 1.293
+++ src/usr.bin/make/job.c 2020/10/30 07:19:30 1.294
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: job.c,v 1.293 2020/10/26 23:28:52 rillig Exp $ */ | 1 | /* $NetBSD: job.c,v 1.294 2020/10/30 07:19:30 rillig Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. | 4 | * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. | |
5 | * All rights reserved. | 5 | * 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. | |
@@ -133,27 +133,27 @@ | @@ -133,27 +133,27 @@ | |||
133 | #ifndef USE_SELECT | 133 | #ifndef USE_SELECT | |
134 | #include <poll.h> | 134 | #include <poll.h> | |
135 | #endif | 135 | #endif | |
136 | #include <signal.h> | 136 | #include <signal.h> | |
137 | #include <utime.h> | 137 | #include <utime.h> | |
138 | 138 | |||
139 | #include "make.h" | 139 | #include "make.h" | |
140 | #include "dir.h" | 140 | #include "dir.h" | |
141 | #include "job.h" | 141 | #include "job.h" | |
142 | #include "pathnames.h" | 142 | #include "pathnames.h" | |
143 | #include "trace.h" | 143 | #include "trace.h" | |
144 | 144 | |||
145 | /* "@(#)job.c 8.2 (Berkeley) 3/19/94" */ | 145 | /* "@(#)job.c 8.2 (Berkeley) 3/19/94" */ | |
146 | MAKE_RCSID("$NetBSD: job.c,v 1.293 2020/10/26 23:28:52 rillig Exp $"); | 146 | MAKE_RCSID("$NetBSD: job.c,v 1.294 2020/10/30 07:19:30 rillig Exp $"); | |
147 | 147 | |||
148 | /* A shell defines how the commands are run. All commands for a target are | 148 | /* A shell defines how the commands are run. All commands for a target are | |
149 | * written into a single file, which is then given to the shell to execute | 149 | * written into a single file, which is then given to the shell to execute | |
150 | * the commands from it. The commands are written to the file using a few | 150 | * the commands from it. The commands are written to the file using a few | |
151 | * templates for echo control and error control. | 151 | * templates for echo control and error control. | |
152 | * | 152 | * | |
153 | * The name of the shell is the basename for the predefined shells, such as | 153 | * The name of the shell is the basename for the predefined shells, such as | |
154 | * "sh", "csh", "bash". For custom shells, it is the full pathname, and its | 154 | * "sh", "csh", "bash". For custom shells, it is the full pathname, and its | |
155 | * basename is used to select the type of shell; the longest match wins. | 155 | * basename is used to select the type of shell; the longest match wins. | |
156 | * So /usr/pkg/bin/bash has type sh, /usr/local/bin/tcsh has type csh. | 156 | * So /usr/pkg/bin/bash has type sh, /usr/local/bin/tcsh has type csh. | |
157 | * | 157 | * | |
158 | * The echoing of command lines is controlled using hasEchoCtl, echoOff, | 158 | * The echoing of command lines is controlled using hasEchoCtl, echoOff, | |
159 | * echoOn, noPrint and noPrintLen. When echoOff is executed by the shell, it | 159 | * echoOn, noPrint and noPrintLen. When echoOff is executed by the shell, it | |
@@ -2049,27 +2049,27 @@ Shell_Init(void) | @@ -2049,27 +2049,27 @@ Shell_Init(void) | |||
2049 | * We are using the default shell, which may be an absolute | 2049 | * We are using the default shell, which may be an absolute | |
2050 | * path if DEFSHELL_CUSTOM is defined. | 2050 | * path if DEFSHELL_CUSTOM is defined. | |
2051 | */ | 2051 | */ | |
2052 | shellName = commandShell->name; | 2052 | shellName = commandShell->name; | |
2053 | #ifdef DEFSHELL_CUSTOM | 2053 | #ifdef DEFSHELL_CUSTOM | |
2054 | if (*shellName == '/') { | 2054 | if (*shellName == '/') { | |
2055 | shellPath = shellName; | 2055 | shellPath = shellName; | |
2056 | shellName = strrchr(shellPath, '/'); | 2056 | shellName = strrchr(shellPath, '/'); | |
2057 | shellName++; | 2057 | shellName++; | |
2058 | } else | 2058 | } else | |
2059 | #endif | 2059 | #endif | |
2060 | shellPath = str_concat3(_PATH_DEFSHELLDIR, "/", shellName); | 2060 | shellPath = str_concat3(_PATH_DEFSHELLDIR, "/", shellName); | |
2061 | } | 2061 | } | |
2062 | Var_Set_with_flags(".SHELL", shellPath, VAR_CMD, VAR_SET_READONLY); | 2062 | Var_Set_with_flags(".SHELL", shellPath, VAR_CMDLINE, VAR_SET_READONLY); | |
2063 | if (commandShell->exit == NULL) { | 2063 | if (commandShell->exit == NULL) { | |
2064 | commandShell->exit = ""; | 2064 | commandShell->exit = ""; | |
2065 | } | 2065 | } | |
2066 | if (commandShell->echo == NULL) { | 2066 | if (commandShell->echo == NULL) { | |
2067 | commandShell->echo = ""; | 2067 | commandShell->echo = ""; | |
2068 | } | 2068 | } | |
2069 | if (commandShell->hasErrCtl && commandShell->exit[0] != '\0') { | 2069 | if (commandShell->hasErrCtl && commandShell->exit[0] != '\0') { | |
2070 | if (shellErrFlag && | 2070 | if (shellErrFlag && | |
2071 | strcmp(commandShell->exit, &shellErrFlag[1]) != 0) { | 2071 | strcmp(commandShell->exit, &shellErrFlag[1]) != 0) { | |
2072 | free(shellErrFlag); | 2072 | free(shellErrFlag); | |
2073 | shellErrFlag = NULL; | 2073 | shellErrFlag = NULL; | |
2074 | } | 2074 | } | |
2075 | if (!shellErrFlag) { | 2075 | if (!shellErrFlag) { |
--- src/usr.bin/make/main.c 2020/10/28 03:21:25 1.409
+++ src/usr.bin/make/main.c 2020/10/30 07:19:30 1.410
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: main.c,v 1.409 2020/10/28 03:21:25 rillig Exp $ */ | 1 | /* $NetBSD: main.c,v 1.410 2020/10/30 07:19:30 rillig 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. | |
@@ -108,27 +108,27 @@ | @@ -108,27 +108,27 @@ | |||
108 | 108 | |||
109 | #include <errno.h> | 109 | #include <errno.h> | |
110 | #include <signal.h> | 110 | #include <signal.h> | |
111 | #include <stdarg.h> | 111 | #include <stdarg.h> | |
112 | #include <time.h> | 112 | #include <time.h> | |
113 | 113 | |||
114 | #include "make.h" | 114 | #include "make.h" | |
115 | #include "dir.h" | 115 | #include "dir.h" | |
116 | #include "job.h" | 116 | #include "job.h" | |
117 | #include "pathnames.h" | 117 | #include "pathnames.h" | |
118 | #include "trace.h" | 118 | #include "trace.h" | |
119 | 119 | |||
120 | /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ | 120 | /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ | |
121 | MAKE_RCSID("$NetBSD: main.c,v 1.409 2020/10/28 03:21:25 rillig Exp $"); | 121 | MAKE_RCSID("$NetBSD: main.c,v 1.410 2020/10/30 07:19:30 rillig Exp $"); | |
122 | #if defined(MAKE_NATIVE) && !defined(lint) | 122 | #if defined(MAKE_NATIVE) && !defined(lint) | |
123 | __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " | 123 | __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " | |
124 | "The Regents of the University of California. " | 124 | "The Regents of the University of California. " | |
125 | "All rights reserved."); | 125 | "All rights reserved."); | |
126 | #endif | 126 | #endif | |
127 | 127 | |||
128 | #ifndef DEFMAXLOCAL | 128 | #ifndef DEFMAXLOCAL | |
129 | #define DEFMAXLOCAL DEFMAXJOBS | 129 | #define DEFMAXLOCAL DEFMAXJOBS | |
130 | #endif | 130 | #endif | |
131 | 131 | |||
132 | CmdOpts opts; | 132 | CmdOpts opts; | |
133 | time_t now; /* Time at start of make */ | 133 | time_t now; /* Time at start of make */ | |
134 | GNode *DEFAULT; /* .DEFAULT node */ | 134 | GNode *DEFAULT; /* .DEFAULT node */ | |
@@ -639,27 +639,27 @@ rearg: | @@ -639,27 +639,27 @@ rearg: | |||
639 | argc -= arginc; | 639 | argc -= arginc; | |
640 | } | 640 | } | |
641 | 641 | |||
642 | oldVars = TRUE; | 642 | oldVars = TRUE; | |
643 | 643 | |||
644 | /* | 644 | /* | |
645 | * See if the rest of the arguments are variable assignments and | 645 | * See if the rest of the arguments are variable assignments and | |
646 | * perform them if so. Else take them to be targets and stuff them | 646 | * perform them if so. Else take them to be targets and stuff them | |
647 | * on the end of the "create" list. | 647 | * on the end of the "create" list. | |
648 | */ | 648 | */ | |
649 | for (; argc > 1; ++argv, --argc) { | 649 | for (; argc > 1; ++argv, --argc) { | |
650 | VarAssign var; | 650 | VarAssign var; | |
651 | if (Parse_IsVar(argv[1], &var)) { | 651 | if (Parse_IsVar(argv[1], &var)) { | |
652 | Parse_DoVar(&var, VAR_CMD); | 652 | Parse_DoVar(&var, VAR_CMDLINE); | |
653 | } else { | 653 | } else { | |
654 | if (!*argv[1]) | 654 | if (!*argv[1]) | |
655 | Punt("illegal (null) argument."); | 655 | Punt("illegal (null) argument."); | |
656 | if (*argv[1] == '-' && !dashDash) | 656 | if (*argv[1] == '-' && !dashDash) | |
657 | goto rearg; | 657 | goto rearg; | |
658 | Lst_Append(opts.create, bmake_strdup(argv[1])); | 658 | Lst_Append(opts.create, bmake_strdup(argv[1])); | |
659 | } | 659 | } | |
660 | } | 660 | } | |
661 | 661 | |||
662 | return; | 662 | return; | |
663 | noarg: | 663 | noarg: | |
664 | (void)fprintf(stderr, "%s: option requires an argument -- %c\n", | 664 | (void)fprintf(stderr, "%s: option requires an argument -- %c\n", | |
665 | progname, c); | 665 | progname, c); | |
@@ -733,27 +733,27 @@ Main_SetObjdir(const char *fmt, ...) | @@ -733,27 +733,27 @@ Main_SetObjdir(const char *fmt, ...) | |||
733 | rc = TRUE; | 733 | rc = TRUE; | |
734 | if (opts.enterFlag && strcmp(objdir, curdir) != 0) | 734 | if (opts.enterFlag && strcmp(objdir, curdir) != 0) | |
735 | enterFlagObj = TRUE; | 735 | enterFlagObj = TRUE; | |
736 | } | 736 | } | |
737 | } | 737 | } | |
738 | 738 | |||
739 | return rc; | 739 | return rc; | |
740 | } | 740 | } | |
741 | 741 | |||
742 | static Boolean | 742 | static Boolean | |
743 | Main_SetVarObjdir(const char *var, const char *suffix) | 743 | Main_SetVarObjdir(const char *var, const char *suffix) | |
744 | { | 744 | { | |
745 | char *path_freeIt; | 745 | char *path_freeIt; | |
746 | const char *path = Var_Value(var, VAR_CMD, &path_freeIt); | 746 | const char *path = Var_Value(var, VAR_CMDLINE, &path_freeIt); | |
747 | const char *xpath; | 747 | const char *xpath; | |
748 | char *xpath_freeIt; | 748 | char *xpath_freeIt; | |
749 | 749 | |||
750 | if (path == NULL || path[0] == '\0') { | 750 | if (path == NULL || path[0] == '\0') { | |
751 | bmake_free(path_freeIt); | 751 | bmake_free(path_freeIt); | |
752 | return FALSE; | 752 | return FALSE; | |
753 | } | 753 | } | |
754 | 754 | |||
755 | /* expand variable substitutions */ | 755 | /* expand variable substitutions */ | |
756 | xpath = path; | 756 | xpath = path; | |
757 | xpath_freeIt = NULL; | 757 | xpath_freeIt = NULL; | |
758 | if (strchr(path, '$') != 0) { | 758 | if (strchr(path, '$') != 0) { | |
759 | (void)Var_Subst(path, VAR_GLOBAL, VARE_WANTRES, &xpath_freeIt); | 759 | (void)Var_Subst(path, VAR_GLOBAL, VARE_WANTRES, &xpath_freeIt); | |
@@ -1026,32 +1026,32 @@ init_machine_arch(void) | @@ -1026,32 +1026,32 @@ init_machine_arch(void) | |||
1026 | * MAKEOBJDIRPREFIX is set or MAKEOBJDIR contains a variable expression. | 1026 | * MAKEOBJDIRPREFIX is set or MAKEOBJDIR contains a variable expression. | |
1027 | */ | 1027 | */ | |
1028 | static void | 1028 | static void | |
1029 | HandlePWD(const struct stat *curdir_st) | 1029 | HandlePWD(const struct stat *curdir_st) | |
1030 | { | 1030 | { | |
1031 | char *pwd; | 1031 | char *pwd; | |
1032 | char *prefix_freeIt, *makeobjdir_freeIt; | 1032 | char *prefix_freeIt, *makeobjdir_freeIt; | |
1033 | const char *makeobjdir; | 1033 | const char *makeobjdir; | |
1034 | struct stat pwd_st; | 1034 | struct stat pwd_st; | |
1035 | 1035 | |||
1036 | if (ignorePWD || (pwd = getenv("PWD")) == NULL) | 1036 | if (ignorePWD || (pwd = getenv("PWD")) == NULL) | |
1037 | return; | 1037 | return; | |
1038 | 1038 | |||
1039 | if (Var_Value("MAKEOBJDIRPREFIX", VAR_CMD, &prefix_freeIt) != NULL) { | 1039 | if (Var_Value("MAKEOBJDIRPREFIX", VAR_CMDLINE, &prefix_freeIt) != NULL) { | |
1040 | bmake_free(prefix_freeIt); | 1040 | bmake_free(prefix_freeIt); | |
1041 | return; | 1041 | return; | |
1042 | } | 1042 | } | |
1043 | 1043 | |||
1044 | makeobjdir = Var_Value("MAKEOBJDIR", VAR_CMD, &makeobjdir_freeIt); | 1044 | makeobjdir = Var_Value("MAKEOBJDIR", VAR_CMDLINE, &makeobjdir_freeIt); | |
1045 | if (makeobjdir != NULL && strchr(makeobjdir, '$') != NULL) | 1045 | if (makeobjdir != NULL && strchr(makeobjdir, '$') != NULL) | |
1046 | goto ignore_pwd; | 1046 | goto ignore_pwd; | |
1047 | 1047 | |||
1048 | if (stat(pwd, &pwd_st) == 0 && | 1048 | if (stat(pwd, &pwd_st) == 0 && | |
1049 | curdir_st->st_ino == pwd_st.st_ino && | 1049 | curdir_st->st_ino == pwd_st.st_ino && | |
1050 | curdir_st->st_dev == pwd_st.st_dev) | 1050 | curdir_st->st_dev == pwd_st.st_dev) | |
1051 | (void)strncpy(curdir, pwd, MAXPATHLEN); | 1051 | (void)strncpy(curdir, pwd, MAXPATHLEN); | |
1052 | 1052 | |||
1053 | ignore_pwd: | 1053 | ignore_pwd: | |
1054 | bmake_free(makeobjdir_freeIt); | 1054 | bmake_free(makeobjdir_freeIt); | |
1055 | } | 1055 | } | |
1056 | #endif | 1056 | #endif | |
1057 | 1057 | |||
@@ -1226,30 +1226,30 @@ InitMaxJobs(void) | @@ -1226,30 +1226,30 @@ InitMaxJobs(void) | |||
1226 | free(value); | 1226 | free(value); | |
1227 | } | 1227 | } | |
1228 | 1228 | |||
1229 | /* | 1229 | /* | |
1230 | * For compatibility, look at the directories in the VPATH variable | 1230 | * For compatibility, look at the directories in the VPATH variable | |
1231 | * and add them to the search path, if the variable is defined. The | 1231 | * and add them to the search path, if the variable is defined. The | |
1232 | * variable's value is in the same format as the PATH environment | 1232 | * variable's value is in the same format as the PATH environment | |
1233 | * variable, i.e. <directory>:<directory>:<directory>... | 1233 | * variable, i.e. <directory>:<directory>:<directory>... | |
1234 | */ | 1234 | */ | |
1235 | static void | 1235 | static void | |
1236 | InitVpath(void) | 1236 | InitVpath(void) | |
1237 | { | 1237 | { | |
1238 | char *vpath, savec, *path; | 1238 | char *vpath, savec, *path; | |
1239 | if (!Var_Exists("VPATH", VAR_CMD)) | 1239 | if (!Var_Exists("VPATH", VAR_CMDLINE)) | |
1240 | return; | 1240 | return; | |
1241 | 1241 | |||
1242 | (void)Var_Subst("${VPATH}", VAR_CMD, VARE_WANTRES, &vpath); | 1242 | (void)Var_Subst("${VPATH}", VAR_CMDLINE, VARE_WANTRES, &vpath); | |
1243 | /* TODO: handle errors */ | 1243 | /* TODO: handle errors */ | |
1244 | path = vpath; | 1244 | path = vpath; | |
1245 | do { | 1245 | do { | |
1246 | char *cp; | 1246 | char *cp; | |
1247 | /* skip to end of directory */ | 1247 | /* skip to end of directory */ | |
1248 | for (cp = path; *cp != ':' && *cp != '\0'; cp++) | 1248 | for (cp = path; *cp != ':' && *cp != '\0'; cp++) | |
1249 | continue; | 1249 | continue; | |
1250 | /* Save terminator character so know when to stop */ | 1250 | /* Save terminator character so know when to stop */ | |
1251 | savec = *cp; | 1251 | savec = *cp; | |
1252 | *cp = '\0'; | 1252 | *cp = '\0'; | |
1253 | /* Add directory to search path */ | 1253 | /* Add directory to search path */ | |
1254 | (void)Dir_AddDir(dirSearchPath, path); | 1254 | (void)Dir_AddDir(dirSearchPath, path); | |
1255 | *cp = savec; | 1255 | *cp = savec; | |
@@ -1262,27 +1262,27 @@ static void | @@ -1262,27 +1262,27 @@ static void | |||
1262 | ReadMakefiles(void) | 1262 | ReadMakefiles(void) | |
1263 | { | 1263 | { | |
1264 | if (opts.makefiles->first != NULL) { | 1264 | if (opts.makefiles->first != NULL) { | |
1265 | StringListNode *ln; | 1265 | StringListNode *ln; | |
1266 | 1266 | |||
1267 | for (ln = opts.makefiles->first; ln != NULL; ln = ln->next) { | 1267 | for (ln = opts.makefiles->first; ln != NULL; ln = ln->next) { | |
1268 | if (ReadMakefile(ln->datum) != 0) | 1268 | if (ReadMakefile(ln->datum) != 0) | |
1269 | Fatal("%s: cannot open %s.", | 1269 | Fatal("%s: cannot open %s.", | |
1270 | progname, (char *)ln->datum); | 1270 | progname, (char *)ln->datum); | |
1271 | } | 1271 | } | |
1272 | } else { | 1272 | } else { | |
1273 | char *p1; | 1273 | char *p1; | |
1274 | (void)Var_Subst("${" MAKEFILE_PREFERENCE "}", | 1274 | (void)Var_Subst("${" MAKEFILE_PREFERENCE "}", | |
1275 | VAR_CMD, VARE_WANTRES, &p1); | 1275 | VAR_CMDLINE, VARE_WANTRES, &p1); | |
1276 | /* TODO: handle errors */ | 1276 | /* TODO: handle errors */ | |
1277 | (void)str2Lst_Append(opts.makefiles, p1, NULL); | 1277 | (void)str2Lst_Append(opts.makefiles, p1, NULL); | |
1278 | (void)Lst_ForEachUntil(opts.makefiles, | 1278 | (void)Lst_ForEachUntil(opts.makefiles, | |
1279 | ReadMakefileSucceeded, NULL); | 1279 | ReadMakefileSucceeded, NULL); | |
1280 | free(p1); | 1280 | free(p1); | |
1281 | } | 1281 | } | |
1282 | } | 1282 | } | |
1283 | 1283 | |||
1284 | static void | 1284 | static void | |
1285 | CleanUp(void) | 1285 | CleanUp(void) | |
1286 | { | 1286 | { | |
1287 | #ifdef CLEANUP | 1287 | #ifdef CLEANUP | |
1288 | Lst_Destroy(opts.variables, free); | 1288 | Lst_Destroy(opts.variables, free); | |
@@ -1416,27 +1416,27 @@ main(int argc, char **argv) | @@ -1416,27 +1416,27 @@ main(int argc, char **argv) | |||
1416 | /* | 1416 | /* | |
1417 | * Initialize various variables. | 1417 | * Initialize various variables. | |
1418 | * MAKE also gets this name, for compatibility | 1418 | * MAKE also gets this name, for compatibility | |
1419 | * .MAKEFLAGS gets set to the empty string just in case. | 1419 | * .MAKEFLAGS gets set to the empty string just in case. | |
1420 | * MFLAGS also gets initialized empty, for compatibility. | 1420 | * MFLAGS also gets initialized empty, for compatibility. | |
1421 | */ | 1421 | */ | |
1422 | Parse_Init(); | 1422 | Parse_Init(); | |
1423 | InitVarMake(argv[0]); | 1423 | InitVarMake(argv[0]); | |
1424 | Var_Set(MAKEFLAGS, "", VAR_GLOBAL); | 1424 | Var_Set(MAKEFLAGS, "", VAR_GLOBAL); | |
1425 | Var_Set(MAKEOVERRIDES, "", VAR_GLOBAL); | 1425 | Var_Set(MAKEOVERRIDES, "", VAR_GLOBAL); | |
1426 | Var_Set("MFLAGS", "", VAR_GLOBAL); | 1426 | Var_Set("MFLAGS", "", VAR_GLOBAL); | |
1427 | Var_Set(".ALLTARGETS", "", VAR_GLOBAL); | 1427 | Var_Set(".ALLTARGETS", "", VAR_GLOBAL); | |
1428 | /* some makefiles need to know this */ | 1428 | /* some makefiles need to know this */ | |
1429 | Var_Set(MAKE_LEVEL ".ENV", MAKE_LEVEL_ENV, VAR_CMD); | 1429 | Var_Set(MAKE_LEVEL ".ENV", MAKE_LEVEL_ENV, VAR_CMDLINE); | |
1430 | 1430 | |||
1431 | /* | 1431 | /* | |
1432 | * Set some other useful macros | 1432 | * Set some other useful macros | |
1433 | */ | 1433 | */ | |
1434 | { | 1434 | { | |
1435 | char tmp[64], *ep; | 1435 | char tmp[64], *ep; | |
1436 | 1436 | |||
1437 | makelevel = ((ep = getenv(MAKE_LEVEL_ENV)) && *ep) ? atoi(ep) : 0; | 1437 | makelevel = ((ep = getenv(MAKE_LEVEL_ENV)) && *ep) ? atoi(ep) : 0; | |
1438 | if (makelevel < 0) | 1438 | if (makelevel < 0) | |
1439 | makelevel = 0; | 1439 | makelevel = 0; | |
1440 | snprintf(tmp, sizeof(tmp), "%d", makelevel); | 1440 | snprintf(tmp, sizeof(tmp), "%d", makelevel); | |
1441 | Var_Set(MAKE_LEVEL, tmp, VAR_GLOBAL); | 1441 | Var_Set(MAKE_LEVEL, tmp, VAR_GLOBAL); | |
1442 | snprintf(tmp, sizeof(tmp), "%u", myPid); | 1442 | snprintf(tmp, sizeof(tmp), "%u", myPid); | |
@@ -1520,27 +1520,27 @@ main(int argc, char **argv) | @@ -1520,27 +1520,27 @@ main(int argc, char **argv) | |||
1520 | /* | 1520 | /* | |
1521 | * Read in the built-in rules first, followed by the specified | 1521 | * Read in the built-in rules first, followed by the specified | |
1522 | * makefiles, or the default makefile and Makefile, in that order, | 1522 | * makefiles, or the default makefile and Makefile, in that order, | |
1523 | * if no makefiles were given on the command line. | 1523 | * if no makefiles were given on the command line. | |
1524 | */ | 1524 | */ | |
1525 | if (!opts.noBuiltins) | 1525 | if (!opts.noBuiltins) | |
1526 | ReadBuiltinRules(); | 1526 | ReadBuiltinRules(); | |
1527 | ReadMakefiles(); | 1527 | ReadMakefiles(); | |
1528 | 1528 | |||
1529 | /* In particular suppress .depend for '-r -V .OBJDIR -f /dev/null' */ | 1529 | /* In particular suppress .depend for '-r -V .OBJDIR -f /dev/null' */ | |
1530 | if (!opts.noBuiltins || !opts.printVars) { | 1530 | if (!opts.noBuiltins || !opts.printVars) { | |
1531 | /* ignore /dev/null and anything starting with "no" */ | 1531 | /* ignore /dev/null and anything starting with "no" */ | |
1532 | (void)Var_Subst("${.MAKE.DEPENDFILE:N/dev/null:Nno*:T}", | 1532 | (void)Var_Subst("${.MAKE.DEPENDFILE:N/dev/null:Nno*:T}", | |
1533 | VAR_CMD, VARE_WANTRES, &makeDependfile); | 1533 | VAR_CMDLINE, VARE_WANTRES, &makeDependfile); | |
1534 | if (makeDependfile[0] != '\0') { | 1534 | if (makeDependfile[0] != '\0') { | |
1535 | /* TODO: handle errors */ | 1535 | /* TODO: handle errors */ | |
1536 | doing_depend = TRUE; | 1536 | doing_depend = TRUE; | |
1537 | (void)ReadMakefile(makeDependfile); | 1537 | (void)ReadMakefile(makeDependfile); | |
1538 | doing_depend = FALSE; | 1538 | doing_depend = FALSE; | |
1539 | } | 1539 | } | |
1540 | } | 1540 | } | |
1541 | 1541 | |||
1542 | if (enterFlagObj) | 1542 | if (enterFlagObj) | |
1543 | printf("%s: Entering directory `%s'\n", progname, objdir); | 1543 | printf("%s: Entering directory `%s'\n", progname, objdir); | |
1544 | 1544 | |||
1545 | MakeMode(NULL); | 1545 | MakeMode(NULL); | |
1546 | 1546 | |||
@@ -2117,27 +2117,27 @@ PrintOnError(GNode *gn, const char *s) | @@ -2117,27 +2117,27 @@ PrintOnError(GNode *gn, const char *s) | |||
2117 | 2117 | |||
2118 | void | 2118 | void | |
2119 | Main_ExportMAKEFLAGS(Boolean first) | 2119 | Main_ExportMAKEFLAGS(Boolean first) | |
2120 | { | 2120 | { | |
2121 | static Boolean once = TRUE; | 2121 | static Boolean once = TRUE; | |
2122 | const char *expr; | 2122 | const char *expr; | |
2123 | char *s; | 2123 | char *s; | |
2124 | 2124 | |||
2125 | if (once != first) | 2125 | if (once != first) | |
2126 | return; | 2126 | return; | |
2127 | once = FALSE; | 2127 | once = FALSE; | |
2128 | 2128 | |||
2129 | expr = "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}"; | 2129 | expr = "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}"; | |
2130 | (void)Var_Subst(expr, VAR_CMD, VARE_WANTRES, &s); | 2130 | (void)Var_Subst(expr, VAR_CMDLINE, VARE_WANTRES, &s); | |
2131 | /* TODO: handle errors */ | 2131 | /* TODO: handle errors */ | |
2132 | if (s[0] != '\0') { | 2132 | if (s[0] != '\0') { | |
2133 | #ifdef POSIX | 2133 | #ifdef POSIX | |
2134 | setenv("MAKEFLAGS", s, 1); | 2134 | setenv("MAKEFLAGS", s, 1); | |
2135 | #else | 2135 | #else | |
2136 | setenv("MAKE", s, 1); | 2136 | setenv("MAKE", s, 1); | |
2137 | #endif | 2137 | #endif | |
2138 | } | 2138 | } | |
2139 | } | 2139 | } | |
2140 | 2140 | |||
2141 | char * | 2141 | char * | |
2142 | getTmpdir(void) | 2142 | getTmpdir(void) | |
2143 | { | 2143 | { |
--- src/usr.bin/make/make.h 2020/10/28 03:21:25 1.175
+++ src/usr.bin/make/make.h 2020/10/30 07:19:30 1.176
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: make.h,v 1.175 2020/10/28 03:21:25 rillig Exp $ */ | 1 | /* $NetBSD: make.h,v 1.176 2020/10/30 07:19:30 rillig 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. | |
@@ -352,27 +352,27 @@ typedef struct GNode { | @@ -352,27 +352,27 @@ typedef struct GNode { | |||
352 | char cohort_num[8]; | 352 | char cohort_num[8]; | |
353 | /* The number of unmade instances on the cohorts list */ | 353 | /* The number of unmade instances on the cohorts list */ | |
354 | int unmade_cohorts; | 354 | int unmade_cohorts; | |
355 | /* Pointer to the first instance of a '::' node; only set when on a | 355 | /* Pointer to the first instance of a '::' node; only set when on a | |
356 | * cohorts list */ | 356 | * cohorts list */ | |
357 | struct GNode *centurion; | 357 | struct GNode *centurion; | |
358 | 358 | |||
359 | /* Last time (sequence number) we tried to make this node */ | 359 | /* Last time (sequence number) we tried to make this node */ | |
360 | unsigned int checked_seqno; | 360 | unsigned int checked_seqno; | |
361 | 361 | |||
362 | /* The "local" variables that are specific to this target and this target | 362 | /* The "local" variables that are specific to this target and this target | |
363 | * only, such as $@, $<, $?. | 363 | * only, such as $@, $<, $?. | |
364 | * | 364 | * | |
365 | * Also used for the global variable scopes VAR_GLOBAL, VAR_CMD, | 365 | * Also used for the global variable scopes VAR_GLOBAL, VAR_CMDLINE, | |
366 | * VAR_INTERNAL, which contain variables with arbitrary names. */ | 366 | * VAR_INTERNAL, which contain variables with arbitrary names. */ | |
367 | HashTable context; | 367 | HashTable context; | |
368 | 368 | |||
369 | /* The commands to be given to a shell to create this target. */ | 369 | /* The commands to be given to a shell to create this target. */ | |
370 | StringList *commands; | 370 | StringList *commands; | |
371 | 371 | |||
372 | /* Suffix for the node (determined by Suff_FindDeps and opaque to everyone | 372 | /* Suffix for the node (determined by Suff_FindDeps and opaque to everyone | |
373 | * but the Suff module) */ | 373 | * but the Suff module) */ | |
374 | struct Suff *suffix; | 374 | struct Suff *suffix; | |
375 | 375 | |||
376 | /* filename where the GNode got defined */ | 376 | /* filename where the GNode got defined */ | |
377 | const char *fname; | 377 | const char *fname; | |
378 | /* line number where the GNode got defined */ | 378 | /* line number where the GNode got defined */ | |
@@ -425,27 +425,27 @@ extern SearchPath *dirSearchPath; | @@ -425,27 +425,27 @@ extern SearchPath *dirSearchPath; | |||
425 | * looking for targets */ | 425 | * looking for targets */ | |
426 | extern Boolean allPrecious; /* True if every target is precious */ | 426 | extern Boolean allPrecious; /* True if every target is precious */ | |
427 | extern Boolean deleteOnError; /* True if failed targets should be deleted */ | 427 | extern Boolean deleteOnError; /* True if failed targets should be deleted */ | |
428 | extern Boolean doing_depend; /* TRUE if processing .depend */ | 428 | extern Boolean doing_depend; /* TRUE if processing .depend */ | |
429 | 429 | |||
430 | extern GNode *DEFAULT; /* .DEFAULT rule */ | 430 | extern GNode *DEFAULT; /* .DEFAULT rule */ | |
431 | 431 | |||
432 | extern GNode *VAR_INTERNAL; /* Variables defined internally by make | 432 | extern GNode *VAR_INTERNAL; /* Variables defined internally by make | |
433 | * which should not override those set by | 433 | * which should not override those set by | |
434 | * makefiles. | 434 | * makefiles. | |
435 | */ | 435 | */ | |
436 | extern GNode *VAR_GLOBAL; /* Variables defined in a global context, e.g | 436 | extern GNode *VAR_GLOBAL; /* Variables defined in a global context, e.g | |
437 | * in the Makefile itself */ | 437 | * in the Makefile itself */ | |
438 | extern GNode *VAR_CMD; /* Variables defined on the command line */ | 438 | extern GNode *VAR_CMDLINE; /* Variables defined on the command line */ | |
439 | extern char var_Error[]; /* Value returned by Var_Parse when an error | 439 | extern char var_Error[]; /* Value returned by Var_Parse when an error | |
440 | * is encountered. It actually points to | 440 | * is encountered. It actually points to | |
441 | * an empty string, so naive callers needn't | 441 | * an empty string, so naive callers needn't | |
442 | * worry about it. */ | 442 | * worry about it. */ | |
443 | 443 | |||
444 | extern time_t now; /* The time at the start of this whole | 444 | extern time_t now; /* The time at the start of this whole | |
445 | * process */ | 445 | * process */ | |
446 | 446 | |||
447 | extern Boolean oldVars; /* Do old-style variable substitution */ | 447 | extern Boolean oldVars; /* Do old-style variable substitution */ | |
448 | 448 | |||
449 | extern SearchPath *sysIncPath; /* The system include path. */ | 449 | extern SearchPath *sysIncPath; /* The system include path. */ | |
450 | extern SearchPath *defSysIncPath; /* The default system include path. */ | 450 | extern SearchPath *defSysIncPath; /* The default system include path. */ | |
451 | 451 |
--- src/usr.bin/make/parse.c 2020/10/29 20:37:47 1.410
+++ src/usr.bin/make/parse.c 2020/10/30 07:19:30 1.411
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: parse.c,v 1.410 2020/10/29 20:37:47 rillig Exp $ */ | 1 | /* $NetBSD: parse.c,v 1.411 2020/10/30 07:19:30 rillig 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. | |
@@ -107,27 +107,27 @@ | @@ -107,27 +107,27 @@ | |||
107 | #ifndef MAP_FILE | 107 | #ifndef MAP_FILE | |
108 | #define MAP_FILE 0 | 108 | #define MAP_FILE 0 | |
109 | #endif | 109 | #endif | |
110 | #ifndef MAP_COPY | 110 | #ifndef MAP_COPY | |
111 | #define MAP_COPY MAP_PRIVATE | 111 | #define MAP_COPY MAP_PRIVATE | |
112 | #endif | 112 | #endif | |
113 | 113 | |||
114 | #include "make.h" | 114 | #include "make.h" | |
115 | #include "dir.h" | 115 | #include "dir.h" | |
116 | #include "job.h" | 116 | #include "job.h" | |
117 | #include "pathnames.h" | 117 | #include "pathnames.h" | |
118 | 118 | |||
119 | /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ | 119 | /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ | |
120 | MAKE_RCSID("$NetBSD: parse.c,v 1.410 2020/10/29 20:37:47 rillig Exp $"); | 120 | MAKE_RCSID("$NetBSD: parse.c,v 1.411 2020/10/30 07:19:30 rillig Exp $"); | |
121 | 121 | |||
122 | /* types and constants */ | 122 | /* types and constants */ | |
123 | 123 | |||
124 | /* | 124 | /* | |
125 | * Structure for a file being read ("included file") | 125 | * Structure for a file being read ("included file") | |
126 | */ | 126 | */ | |
127 | typedef struct IFile { | 127 | typedef struct IFile { | |
128 | char *fname; /* name of file */ | 128 | char *fname; /* name of file */ | |
129 | Boolean fromForLoop; /* simulated .include by the .for loop */ | 129 | Boolean fromForLoop; /* simulated .include by the .for loop */ | |
130 | int lineno; /* current line number in file */ | 130 | int lineno; /* current line number in file */ | |
131 | int first_lineno; /* line number of start of text */ | 131 | int first_lineno; /* line number of start of text */ | |
132 | unsigned int cond_depth; /* 'if' nesting when file opened */ | 132 | unsigned int cond_depth; /* 'if' nesting when file opened */ | |
133 | Boolean depending; /* state of doing_depend on EOF */ | 133 | Boolean depending; /* state of doing_depend on EOF */ | |
@@ -731,27 +731,27 @@ static Boolean | @@ -731,27 +731,27 @@ static Boolean | |||
731 | ParseMessage(const char *directive) | 731 | ParseMessage(const char *directive) | |
732 | { | 732 | { | |
733 | const char *p = directive; | 733 | const char *p = directive; | |
734 | int mtype = *p == 'i' ? PARSE_INFO : | 734 | int mtype = *p == 'i' ? PARSE_INFO : | |
735 | *p == 'w' ? PARSE_WARNING : PARSE_FATAL; | 735 | *p == 'w' ? PARSE_WARNING : PARSE_FATAL; | |
736 | char *arg; | 736 | char *arg; | |
737 | 737 | |||
738 | while (ch_isalpha(*p)) | 738 | while (ch_isalpha(*p)) | |
739 | p++; | 739 | p++; | |
740 | if (!ch_isspace(*p)) | 740 | if (!ch_isspace(*p)) | |
741 | return FALSE; /* missing argument */ | 741 | return FALSE; /* missing argument */ | |
742 | 742 | |||
743 | cpp_skip_whitespace(&p); | 743 | cpp_skip_whitespace(&p); | |
744 | (void)Var_Subst(p, VAR_CMD, VARE_WANTRES, &arg); | 744 | (void)Var_Subst(p, VAR_CMDLINE, VARE_WANTRES, &arg); | |
745 | /* TODO: handle errors */ | 745 | /* TODO: handle errors */ | |
746 | 746 | |||
747 | Parse_Error(mtype, "%s", arg); | 747 | Parse_Error(mtype, "%s", arg); | |
748 | free(arg); | 748 | free(arg); | |
749 | 749 | |||
750 | if (mtype == PARSE_FATAL) { | 750 | if (mtype == PARSE_FATAL) { | |
751 | PrintOnError(NULL, NULL); | 751 | PrintOnError(NULL, NULL); | |
752 | exit(1); | 752 | exit(1); | |
753 | } | 753 | } | |
754 | return TRUE; | 754 | return TRUE; | |
755 | } | 755 | } | |
756 | 756 | |||
757 | /* Add the child to the parent's children. | 757 | /* Add the child to the parent's children. | |
@@ -1053,27 +1053,27 @@ ParseDependencyTargetWord(/*const*/ char | @@ -1053,27 +1053,27 @@ ParseDependencyTargetWord(/*const*/ char | |||
1053 | 1053 | |||
1054 | if (*cp == '$') { | 1054 | if (*cp == '$') { | |
1055 | /* | 1055 | /* | |
1056 | * Must be a dynamic source (would have been expanded | 1056 | * Must be a dynamic source (would have been expanded | |
1057 | * otherwise), so call the Var module to parse the puppy | 1057 | * otherwise), so call the Var module to parse the puppy | |
1058 | * so we can safely advance beyond it...There should be | 1058 | * so we can safely advance beyond it...There should be | |
1059 | * no errors in this, as they would have been discovered | 1059 | * no errors in this, as they would have been discovered | |
1060 | * in the initial Var_Subst and we wouldn't be here. | 1060 | * in the initial Var_Subst and we wouldn't be here. | |
1061 | */ | 1061 | */ | |
1062 | const char *nested_p = cp; | 1062 | const char *nested_p = cp; | |
1063 | const char *nested_val; | 1063 | const char *nested_val; | |
1064 | void *freeIt; | 1064 | void *freeIt; | |
1065 | 1065 | |||
1066 | (void)Var_Parse(&nested_p, VAR_CMD, VARE_UNDEFERR|VARE_WANTRES, | 1066 | (void)Var_Parse(&nested_p, VAR_CMDLINE, VARE_UNDEFERR|VARE_WANTRES, | |
1067 | &nested_val, &freeIt); | 1067 | &nested_val, &freeIt); | |
1068 | /* TODO: handle errors */ | 1068 | /* TODO: handle errors */ | |
1069 | free(freeIt); | 1069 | free(freeIt); | |
1070 | cp += nested_p - cp; | 1070 | cp += nested_p - cp; | |
1071 | } else | 1071 | } else | |
1072 | cp++; | 1072 | cp++; | |
1073 | } | 1073 | } | |
1074 | 1074 | |||
1075 | *pp = cp; | 1075 | *pp = cp; | |
1076 | } | 1076 | } | |
1077 | 1077 | |||
1078 | /* | 1078 | /* | |
1079 | * Certain special targets have special semantics: | 1079 | * Certain special targets have special semantics: | |
@@ -1467,27 +1467,27 @@ ParseDoDependencyTargets(char **inout_cp | @@ -1467,27 +1467,27 @@ ParseDoDependencyTargets(char **inout_cp | |||
1467 | * name of an object file inside an archive (ar file). | 1467 | * name of an object file inside an archive (ar file). | |
1468 | */ | 1468 | */ | |
1469 | if (!ParseIsEscaped(lstart, cp) && *cp == '(') { | 1469 | if (!ParseIsEscaped(lstart, cp) && *cp == '(') { | |
1470 | /* | 1470 | /* | |
1471 | * Archives must be handled specially to make sure the OP_ARCHV | 1471 | * Archives must be handled specially to make sure the OP_ARCHV | |
1472 | * flag is set in their 'type' field, for one thing, and because | 1472 | * flag is set in their 'type' field, for one thing, and because | |
1473 | * things like "archive(file1.o file2.o file3.o)" are permissible. | 1473 | * things like "archive(file1.o file2.o file3.o)" are permissible. | |
1474 | * Arch_ParseArchive will set 'line' to be the first non-blank | 1474 | * Arch_ParseArchive will set 'line' to be the first non-blank | |
1475 | * after the archive-spec. It creates/finds nodes for the members | 1475 | * after the archive-spec. It creates/finds nodes for the members | |
1476 | * and places them on the given list, returning TRUE if all | 1476 | * and places them on the given list, returning TRUE if all | |
1477 | * went well and FALSE if there was an error in the | 1477 | * went well and FALSE if there was an error in the | |
1478 | * specification. On error, line should remain untouched. | 1478 | * specification. On error, line should remain untouched. | |
1479 | */ | 1479 | */ | |
1480 | if (!Arch_ParseArchive(&line, targets, VAR_CMD)) { | 1480 | if (!Arch_ParseArchive(&line, targets, VAR_CMDLINE)) { | |
1481 | Parse_Error(PARSE_FATAL, | 1481 | Parse_Error(PARSE_FATAL, | |
1482 | "Error in archive specification: \"%s\"", line); | 1482 | "Error in archive specification: \"%s\"", line); | |
1483 | return FALSE; | 1483 | return FALSE; | |
1484 | } else { | 1484 | } else { | |
1485 | /* Done with this word; on to the next. */ | 1485 | /* Done with this word; on to the next. */ | |
1486 | cp = line; | 1486 | cp = line; | |
1487 | continue; | 1487 | continue; | |
1488 | } | 1488 | } | |
1489 | } | 1489 | } | |
1490 | 1490 | |||
1491 | if (!*cp) { | 1491 | if (!*cp) { | |
1492 | ParseErrorNoDependency(lstart); | 1492 | ParseErrorNoDependency(lstart); | |
1493 | return FALSE; | 1493 | return FALSE; | |
@@ -1569,27 +1569,27 @@ ParseDoDependencySourcesMundane(char *st | @@ -1569,27 +1569,27 @@ ParseDoDependencySourcesMundane(char *st | |||
1569 | if (*end == '(' && end > start && end[-1] != '$') { | 1569 | if (*end == '(' && end > start && end[-1] != '$') { | |
1570 | /* | 1570 | /* | |
1571 | * Only stop for a left parenthesis if it isn't at the | 1571 | * Only stop for a left parenthesis if it isn't at the | |
1572 | * start of a word (that'll be for variable changes | 1572 | * start of a word (that'll be for variable changes | |
1573 | * later) and isn't preceded by a dollar sign (a dynamic | 1573 | * later) and isn't preceded by a dollar sign (a dynamic | |
1574 | * source). | 1574 | * source). | |
1575 | */ | 1575 | */ | |
1576 | break; | 1576 | break; | |
1577 | } | 1577 | } | |
1578 | } | 1578 | } | |
1579 | 1579 | |||
1580 | if (*end == '(') { | 1580 | if (*end == '(') { | |
1581 | GNodeList *sources = Lst_New(); | 1581 | GNodeList *sources = Lst_New(); | |
1582 | if (!Arch_ParseArchive(&start, sources, VAR_CMD)) { | 1582 | if (!Arch_ParseArchive(&start, sources, VAR_CMDLINE)) { | |
1583 | Parse_Error(PARSE_FATAL, | 1583 | Parse_Error(PARSE_FATAL, | |
1584 | "Error in source archive spec \"%s\"", start); | 1584 | "Error in source archive spec \"%s\"", start); | |
1585 | return FALSE; | 1585 | return FALSE; | |
1586 | } | 1586 | } | |
1587 | 1587 | |||
1588 | while (!Lst_IsEmpty(sources)) { | 1588 | while (!Lst_IsEmpty(sources)) { | |
1589 | GNode *gn = Lst_Dequeue(sources); | 1589 | GNode *gn = Lst_Dequeue(sources); | |
1590 | ParseDoSrc(tOp, gn->name, specType); | 1590 | ParseDoSrc(tOp, gn->name, specType); | |
1591 | } | 1591 | } | |
1592 | Lst_Free(sources); | 1592 | Lst_Free(sources); | |
1593 | end = start; | 1593 | end = start; | |
1594 | } else { | 1594 | } else { | |
1595 | if (*end) { | 1595 | if (*end) { | |
@@ -1942,27 +1942,27 @@ VarAssign_EvalSubst(const char *name, co | @@ -1942,27 +1942,27 @@ VarAssign_EvalSubst(const char *name, co | |||
1942 | } | 1942 | } | |
1943 | 1943 | |||
1944 | static void | 1944 | static void | |
1945 | VarAssign_EvalShell(const char *name, const char *uvalue, GNode *ctxt, | 1945 | VarAssign_EvalShell(const char *name, const char *uvalue, GNode *ctxt, | |
1946 | const char **out_avalue, void **out_avalue_freeIt) | 1946 | const char **out_avalue, void **out_avalue_freeIt) | |
1947 | { | 1947 | { | |
1948 | const char *cmd, *errfmt; | 1948 | const char *cmd, *errfmt; | |
1949 | char *cmdOut; | 1949 | char *cmdOut; | |
1950 | void *cmd_freeIt = NULL; | 1950 | void *cmd_freeIt = NULL; | |
1951 | 1951 | |||
1952 | cmd = uvalue; | 1952 | cmd = uvalue; | |
1953 | if (strchr(cmd, '$') != NULL) { | 1953 | if (strchr(cmd, '$') != NULL) { | |
1954 | char *ecmd; | 1954 | char *ecmd; | |
1955 | (void)Var_Subst(cmd, VAR_CMD, VARE_UNDEFERR|VARE_WANTRES, &ecmd); | 1955 | (void)Var_Subst(cmd, VAR_CMDLINE, VARE_UNDEFERR | VARE_WANTRES, &ecmd); | |
1956 | /* TODO: handle errors */ | 1956 | /* TODO: handle errors */ | |
1957 | cmd = cmd_freeIt = ecmd; | 1957 | cmd = cmd_freeIt = ecmd; | |
1958 | } | 1958 | } | |
1959 | 1959 | |||
1960 | cmdOut = Cmd_Exec(cmd, &errfmt); | 1960 | cmdOut = Cmd_Exec(cmd, &errfmt); | |
1961 | Var_Set(name, cmdOut, ctxt); | 1961 | Var_Set(name, cmdOut, ctxt); | |
1962 | *out_avalue = *out_avalue_freeIt = cmdOut; | 1962 | *out_avalue = *out_avalue_freeIt = cmdOut; | |
1963 | 1963 | |||
1964 | if (errfmt) | 1964 | if (errfmt) | |
1965 | Parse_Error(PARSE_WARNING, errfmt, cmd); | 1965 | Parse_Error(PARSE_WARNING, errfmt, cmd); | |
1966 | 1966 | |||
1967 | free(cmd_freeIt); | 1967 | free(cmd_freeIt); | |
1968 | } | 1968 | } | |
@@ -2264,27 +2264,27 @@ ParseDoInclude(char *line) | @@ -2264,27 +2264,27 @@ ParseDoInclude(char *line) | |||
2264 | 2264 | |||
2265 | if (*cp != endc) { | 2265 | if (*cp != endc) { | |
2266 | Parse_Error(PARSE_FATAL, | 2266 | Parse_Error(PARSE_FATAL, | |
2267 | "Unclosed %cinclude filename. '%c' expected", | 2267 | "Unclosed %cinclude filename. '%c' expected", | |
2268 | '.', endc); | 2268 | '.', endc); | |
2269 | return; | 2269 | return; | |
2270 | } | 2270 | } | |
2271 | *cp = '\0'; | 2271 | *cp = '\0'; | |
2272 | 2272 | |||
2273 | /* | 2273 | /* | |
2274 | * Substitute for any variables in the file name before trying to | 2274 | * Substitute for any variables in the file name before trying to | |
2275 | * find the thing. | 2275 | * find the thing. | |
2276 | */ | 2276 | */ | |
2277 | (void)Var_Subst(file, VAR_CMD, VARE_WANTRES, &file); | 2277 | (void)Var_Subst(file, VAR_CMDLINE, VARE_WANTRES, &file); | |
2278 | /* TODO: handle errors */ | 2278 | /* TODO: handle errors */ | |
2279 | 2279 | |||
2280 | Parse_include_file(file, endc == '>', *line == 'd', silent); | 2280 | Parse_include_file(file, endc == '>', *line == 'd', silent); | |
2281 | free(file); | 2281 | free(file); | |
2282 | } | 2282 | } | |
2283 | 2283 | |||
2284 | /* Split filename into dirname + basename, then assign these to the | 2284 | /* Split filename into dirname + basename, then assign these to the | |
2285 | * given variables. */ | 2285 | * given variables. */ | |
2286 | static void | 2286 | static void | |
2287 | SetFilenameVars(const char *filename, const char *dirvar, const char *filevar) | 2287 | SetFilenameVars(const char *filename, const char *dirvar, const char *filevar) | |
2288 | { | 2288 | { | |
2289 | const char *slash, *dirname, *basename; | 2289 | const char *slash, *dirname, *basename; | |
2290 | void *freeIt; | 2290 | void *freeIt; | |
@@ -2479,27 +2479,27 @@ ParseTraditionalInclude(char *line) | @@ -2479,27 +2479,27 @@ ParseTraditionalInclude(char *line) | |||
2479 | int done = 0; | 2479 | int done = 0; | |
2480 | int silent = line[0] != 'i'; | 2480 | int silent = line[0] != 'i'; | |
2481 | char *file = line + (silent ? 8 : 7); | 2481 | char *file = line + (silent ? 8 : 7); | |
2482 | char *all_files; | 2482 | char *all_files; | |
2483 | 2483 | |||
2484 | DEBUG2(PARSE, "%s: %s\n", __func__, file); | 2484 | DEBUG2(PARSE, "%s: %s\n", __func__, file); | |
2485 | 2485 | |||
2486 | pp_skip_whitespace(&file); | 2486 | pp_skip_whitespace(&file); | |
2487 | 2487 | |||
2488 | /* | 2488 | /* | |
2489 | * Substitute for any variables in the file name before trying to | 2489 | * Substitute for any variables in the file name before trying to | |
2490 | * find the thing. | 2490 | * find the thing. | |
2491 | */ | 2491 | */ | |
2492 | (void)Var_Subst(file, VAR_CMD, VARE_WANTRES, &all_files); | 2492 | (void)Var_Subst(file, VAR_CMDLINE, VARE_WANTRES, &all_files); | |
2493 | /* TODO: handle errors */ | 2493 | /* TODO: handle errors */ | |
2494 | 2494 | |||
2495 | if (*file == '\0') { | 2495 | if (*file == '\0') { | |
2496 | Parse_Error(PARSE_FATAL, "Filename missing from \"include\""); | 2496 | Parse_Error(PARSE_FATAL, "Filename missing from \"include\""); | |
2497 | goto out; | 2497 | goto out; | |
2498 | } | 2498 | } | |
2499 | 2499 | |||
2500 | for (file = all_files; !done; file = cp + 1) { | 2500 | for (file = all_files; !done; file = cp + 1) { | |
2501 | /* Skip to end of line or next whitespace */ | 2501 | /* Skip to end of line or next whitespace */ | |
2502 | for (cp = file; *cp && !ch_isspace(*cp); cp++) | 2502 | for (cp = file; *cp && !ch_isspace(*cp); cp++) | |
2503 | continue; | 2503 | continue; | |
2504 | 2504 | |||
2505 | if (*cp) | 2505 | if (*cp) | |
@@ -2529,27 +2529,27 @@ ParseGmakeExport(char *line) | @@ -2529,27 +2529,27 @@ ParseGmakeExport(char *line) | |||
2529 | for (value = variable; *value && *value != '='; value++) | 2529 | for (value = variable; *value && *value != '='; value++) | |
2530 | continue; | 2530 | continue; | |
2531 | 2531 | |||
2532 | if (*value != '=') { | 2532 | if (*value != '=') { | |
2533 | Parse_Error(PARSE_FATAL, | 2533 | Parse_Error(PARSE_FATAL, | |
2534 | "Variable/Value missing from \"export\""); | 2534 | "Variable/Value missing from \"export\""); | |
2535 | return; | 2535 | return; | |
2536 | } | 2536 | } | |
2537 | *value++ = '\0'; /* terminate variable */ | 2537 | *value++ = '\0'; /* terminate variable */ | |
2538 | 2538 | |||
2539 | /* | 2539 | /* | |
2540 | * Expand the value before putting it in the environment. | 2540 | * Expand the value before putting it in the environment. | |
2541 | */ | 2541 | */ | |
2542 | (void)Var_Subst(value, VAR_CMD, VARE_WANTRES, &value); | 2542 | (void)Var_Subst(value, VAR_CMDLINE, VARE_WANTRES, &value); | |
2543 | /* TODO: handle errors */ | 2543 | /* TODO: handle errors */ | |
2544 | 2544 | |||
2545 | setenv(variable, value, 1); | 2545 | setenv(variable, value, 1); | |
2546 | free(value); | 2546 | free(value); | |
2547 | } | 2547 | } | |
2548 | #endif | 2548 | #endif | |
2549 | 2549 | |||
2550 | /* Called when EOF is reached in the current file. If we were reading an | 2550 | /* Called when EOF is reached in the current file. If we were reading an | |
2551 | * include file, the includes stack is popped and things set up to go back | 2551 | * include file, the includes stack is popped and things set up to go back | |
2552 | * to reading the previous file at the previous location. | 2552 | * to reading the previous file at the previous location. | |
2553 | * | 2553 | * | |
2554 | * Results: | 2554 | * Results: | |
2555 | * TRUE to continue parsing, i.e. it had only reached the end of an | 2555 | * TRUE to continue parsing, i.e. it had only reached the end of an | |
@@ -3019,27 +3019,27 @@ ParseDependency(char *line) | @@ -3019,27 +3019,27 @@ ParseDependency(char *line) | |||
3019 | * | 3019 | * | |
3020 | * Ideally, only the right-hand side would allow undefined | 3020 | * Ideally, only the right-hand side would allow undefined | |
3021 | * variables since it is common to have no dependencies. | 3021 | * variables since it is common to have no dependencies. | |
3022 | * Having undefined variables on the left-hand side is more | 3022 | * Having undefined variables on the left-hand side is more | |
3023 | * unusual though. Since both sides are expanded in a single | 3023 | * unusual though. Since both sides are expanded in a single | |
3024 | * pass, there is not much choice what to do here. | 3024 | * pass, there is not much choice what to do here. | |
3025 | * | 3025 | * | |
3026 | * In normal mode, it does not matter whether undefined | 3026 | * In normal mode, it does not matter whether undefined | |
3027 | * variables are allowed or not since as of 2020-09-14, | 3027 | * variables are allowed or not since as of 2020-09-14, | |
3028 | * Var_Parse does not print any parse errors in such a case. | 3028 | * Var_Parse does not print any parse errors in such a case. | |
3029 | * It simply returns the special empty string var_Error, | 3029 | * It simply returns the special empty string var_Error, | |
3030 | * which cannot be detected in the result of Var_Subst. */ | 3030 | * which cannot be detected in the result of Var_Subst. */ | |
3031 | eflags = DEBUG(LINT) ? VARE_WANTRES : VARE_UNDEFERR | VARE_WANTRES; | 3031 | eflags = DEBUG(LINT) ? VARE_WANTRES : VARE_UNDEFERR | VARE_WANTRES; | |
3032 | (void)Var_Subst(line, VAR_CMD, eflags, &expanded_line); | 3032 | (void)Var_Subst(line, VAR_CMDLINE, eflags, &expanded_line); | |
3033 | /* TODO: handle errors */ | 3033 | /* TODO: handle errors */ | |
3034 | 3034 | |||
3035 | /* Need a fresh list for the target nodes */ | 3035 | /* Need a fresh list for the target nodes */ | |
3036 | if (targets != NULL) | 3036 | if (targets != NULL) | |
3037 | Lst_Free(targets); | 3037 | Lst_Free(targets); | |
3038 | targets = Lst_New(); | 3038 | targets = Lst_New(); | |
3039 | 3039 | |||
3040 | ParseDoDependency(expanded_line); | 3040 | ParseDoDependency(expanded_line); | |
3041 | free(expanded_line); | 3041 | free(expanded_line); | |
3042 | 3042 | |||
3043 | if (shellcmd != NULL) | 3043 | if (shellcmd != NULL) | |
3044 | ParseLine_ShellCommand(shellcmd); | 3044 | ParseLine_ShellCommand(shellcmd); | |
3045 | } | 3045 | } |
--- src/usr.bin/make/targ.c 2020/10/26 21:34:10 1.125
+++ src/usr.bin/make/targ.c 2020/10/30 07:19:30 1.126
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: targ.c,v 1.125 2020/10/26 21:34:10 rillig Exp $ */ | 1 | /* $NetBSD: targ.c,v 1.126 2020/10/30 07:19:30 rillig 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. | |
@@ -111,27 +111,27 @@ | @@ -111,27 +111,27 @@ | |||
111 | * Debugging: | 111 | * Debugging: | |
112 | * Targ_PrintGraph | 112 | * Targ_PrintGraph | |
113 | * Print out the entire graphm all variables and | 113 | * Print out the entire graphm all variables and | |
114 | * statistics for the directory cache. Should print | 114 | * statistics for the directory cache. Should print | |
115 | * something for suffixes, too, but... | 115 | * something for suffixes, too, but... | |
116 | */ | 116 | */ | |
117 | 117 | |||
118 | #include <time.h> | 118 | #include <time.h> | |
119 | 119 | |||
120 | #include "make.h" | 120 | #include "make.h" | |
121 | #include "dir.h" | 121 | #include "dir.h" | |
122 | 122 | |||
123 | /* "@(#)targ.c 8.2 (Berkeley) 3/19/94" */ | 123 | /* "@(#)targ.c 8.2 (Berkeley) 3/19/94" */ | |
124 | MAKE_RCSID("$NetBSD: targ.c,v 1.125 2020/10/26 21:34:10 rillig Exp $"); | 124 | MAKE_RCSID("$NetBSD: targ.c,v 1.126 2020/10/30 07:19:30 rillig Exp $"); | |
125 | 125 | |||
126 | static GNodeList *allTargets; /* the list of all targets found so far */ | 126 | static GNodeList *allTargets; /* the list of all targets found so far */ | |
127 | #ifdef CLEANUP | 127 | #ifdef CLEANUP | |
128 | static GNodeList *allGNs; /* List of all the GNodes */ | 128 | static GNodeList *allGNs; /* List of all the GNodes */ | |
129 | #endif | 129 | #endif | |
130 | static HashTable targets; /* a hash table of same */ | 130 | static HashTable targets; /* a hash table of same */ | |
131 | 131 | |||
132 | #ifdef CLEANUP | 132 | #ifdef CLEANUP | |
133 | static void TargFreeGN(void *); | 133 | static void TargFreeGN(void *); | |
134 | #endif | 134 | #endif | |
135 | 135 | |||
136 | void | 136 | void | |
137 | Targ_Init(void) | 137 | Targ_Init(void) | |
@@ -528,27 +528,27 @@ PrintOnlySources(void) | @@ -528,27 +528,27 @@ PrintOnlySources(void) | |||
528 | * 3 => after processing, an error occurred | 528 | * 3 => after processing, an error occurred | |
529 | */ | 529 | */ | |
530 | void | 530 | void | |
531 | Targ_PrintGraph(int pass) | 531 | Targ_PrintGraph(int pass) | |
532 | { | 532 | { | |
533 | debug_printf("#*** Input graph:\n"); | 533 | debug_printf("#*** Input graph:\n"); | |
534 | Targ_PrintNodes(allTargets, pass); | 534 | Targ_PrintNodes(allTargets, pass); | |
535 | debug_printf("\n\n"); | 535 | debug_printf("\n\n"); | |
536 | debug_printf("#\n# Files that are only sources:\n"); | 536 | debug_printf("#\n# Files that are only sources:\n"); | |
537 | PrintOnlySources(); | 537 | PrintOnlySources(); | |
538 | debug_printf("#*** Global Variables:\n"); | 538 | debug_printf("#*** Global Variables:\n"); | |
539 | Var_Dump(VAR_GLOBAL); | 539 | Var_Dump(VAR_GLOBAL); | |
540 | debug_printf("#*** Command-line Variables:\n"); | 540 | debug_printf("#*** Command-line Variables:\n"); | |
541 | Var_Dump(VAR_CMD); | 541 | Var_Dump(VAR_CMDLINE); | |
542 | debug_printf("\n"); | 542 | debug_printf("\n"); | |
543 | Dir_PrintDirectories(); | 543 | Dir_PrintDirectories(); | |
544 | debug_printf("\n"); | 544 | debug_printf("\n"); | |
545 | Suff_PrintAll(); | 545 | Suff_PrintAll(); | |
546 | } | 546 | } | |
547 | 547 | |||
548 | /* Propagate some type information to cohort nodes (those from the :: | 548 | /* Propagate some type information to cohort nodes (those from the :: | |
549 | * dependency operator). | 549 | * dependency operator). | |
550 | * | 550 | * | |
551 | * Should be called after the makefiles are parsed but before any action is | 551 | * Should be called after the makefiles are parsed but before any action is | |
552 | * taken. */ | 552 | * taken. */ | |
553 | void | 553 | void | |
554 | Targ_Propagate(void) | 554 | Targ_Propagate(void) |
--- src/usr.bin/make/var.c 2020/10/30 06:59:12 1.593
+++ src/usr.bin/make/var.c 2020/10/30 07:19:30 1.594
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: var.c,v 1.593 2020/10/30 06:59:12 rillig Exp $ */ | 1 | /* $NetBSD: var.c,v 1.594 2020/10/30 07:19:30 rillig 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. | |
@@ -119,27 +119,27 @@ | @@ -119,27 +119,27 @@ | |||
119 | #include <sys/types.h> | 119 | #include <sys/types.h> | |
120 | #include <regex.h> | 120 | #include <regex.h> | |
121 | #endif | 121 | #endif | |
122 | #include <inttypes.h> | 122 | #include <inttypes.h> | |
123 | #include <limits.h> | 123 | #include <limits.h> | |
124 | #include <time.h> | 124 | #include <time.h> | |
125 | 125 | |||
126 | #include "make.h" | 126 | #include "make.h" | |
127 | #include "dir.h" | 127 | #include "dir.h" | |
128 | #include "job.h" | 128 | #include "job.h" | |
129 | #include "metachar.h" | 129 | #include "metachar.h" | |
130 | 130 | |||
131 | /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ | 131 | /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ | |
132 | MAKE_RCSID("$NetBSD: var.c,v 1.593 2020/10/30 06:59:12 rillig Exp $"); | 132 | MAKE_RCSID("$NetBSD: var.c,v 1.594 2020/10/30 07:19:30 rillig Exp $"); | |
133 | 133 | |||
134 | #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1) | 134 | #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1) | |
135 | #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2) | 135 | #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2) | |
136 | #define VAR_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(VAR, fmt, arg1, arg2, arg3) | 136 | #define VAR_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(VAR, fmt, arg1, arg2, arg3) | |
137 | #define VAR_DEBUG4(fmt, arg1, arg2, arg3, arg4) DEBUG4(VAR, fmt, arg1, arg2, arg3, arg4) | 137 | #define VAR_DEBUG4(fmt, arg1, arg2, arg3, arg4) DEBUG4(VAR, fmt, arg1, arg2, arg3, arg4) | |
138 | 138 | |||
139 | ENUM_FLAGS_RTTI_3(VarEvalFlags, | 139 | ENUM_FLAGS_RTTI_3(VarEvalFlags, | |
140 | VARE_UNDEFERR, VARE_WANTRES, VARE_ASSIGN); | 140 | VARE_UNDEFERR, VARE_WANTRES, VARE_ASSIGN); | |
141 | 141 | |||
142 | /* | 142 | /* | |
143 | * This lets us tell if we have replaced the original environ | 143 | * This lets us tell if we have replaced the original environ | |
144 | * (which we cannot free). | 144 | * (which we cannot free). | |
145 | */ | 145 | */ | |
@@ -165,44 +165,44 @@ static char emptyString[] = ""; | @@ -165,44 +165,44 @@ static char emptyString[] = ""; | |||
165 | * Traditionally this make consumed $$ during := like any other expansion. | 165 | * Traditionally this make consumed $$ during := like any other expansion. | |
166 | * Other make's do not, and this make follows straight since 2016-01-09. | 166 | * Other make's do not, and this make follows straight since 2016-01-09. | |
167 | * | 167 | * | |
168 | * This knob allows controlling the behavior. | 168 | * This knob allows controlling the behavior. | |
169 | * FALSE to consume $$ during := assignment. | 169 | * FALSE to consume $$ during := assignment. | |
170 | * TRUE to preserve $$ during := assignment. | 170 | * TRUE to preserve $$ during := assignment. | |
171 | */ | 171 | */ | |
172 | #define MAKE_SAVE_DOLLARS ".MAKE.SAVE_DOLLARS" | 172 | #define MAKE_SAVE_DOLLARS ".MAKE.SAVE_DOLLARS" | |
173 | static Boolean save_dollars = TRUE; | 173 | static Boolean save_dollars = TRUE; | |
174 | 174 | |||
175 | /* | 175 | /* | |
176 | * Internally, variables are contained in four different contexts. | 176 | * Internally, variables are contained in four different contexts. | |
177 | * 1) the environment. They cannot be changed. If an environment | 177 | * 1) the environment. They cannot be changed. If an environment | |
178 | * variable is appended to, the result is placed in the global | 178 | * variable is appended to, the result is placed in the global | |
179 | * context. | 179 | * context. | |
180 | * 2) the global context. Variables set in the Makefile are located in | 180 | * 2) the global context. Variables set in the makefiles are located | |
181 | * the global context. | 181 | * here. | |
182 | * 3) the command-line context. All variables set on the command line | 182 | * 3) the command-line context. All variables set on the command line | |
183 | * are placed in this context. They are UNALTERABLE once placed here. | 183 | * are placed in this context. | |
184 | * 4) the local context. Each target has associated with it a context | 184 | * 4) the local context. Each target has associated with it a context | |
185 | * list. On this list are located the structures describing such | 185 | * list. On this list are located the structures describing such | |
186 | * local variables as $(@) and $(*) | 186 | * local variables as $(@) and $(*) | |
187 | * The four contexts are searched in the reverse order from which they are | 187 | * The four contexts are searched in the reverse order from which they are | |
188 | * listed (but see opts.checkEnvFirst). | 188 | * listed (but see opts.checkEnvFirst). | |
189 | */ | 189 | */ | |
190 | GNode *VAR_INTERNAL; /* variables from make itself */ | 190 | GNode *VAR_INTERNAL; /* variables from make itself */ | |
191 | GNode *VAR_GLOBAL; /* variables from the makefile */ | 191 | GNode *VAR_GLOBAL; /* variables from the makefile */ | |
192 | GNode *VAR_CMD; /* variables defined on the command-line */ | 192 | GNode *VAR_CMDLINE; /* variables defined on the command-line */ | |
193 | 193 | |||
194 | typedef enum VarFindFlags { | 194 | typedef enum VarFindFlags { | |
195 | FIND_CMD = 0x01, /* look in VAR_CMD when searching */ | 195 | FIND_CMD = 0x01, /* look in VAR_CMDLINE when searching */ | |
196 | FIND_GLOBAL = 0x02, /* look in VAR_GLOBAL as well */ | 196 | FIND_GLOBAL = 0x02, /* look in VAR_GLOBAL as well */ | |
197 | FIND_ENV = 0x04 /* look in the environment also */ | 197 | FIND_ENV = 0x04 /* look in the environment also */ | |
198 | } VarFindFlags; | 198 | } VarFindFlags; | |
199 | 199 | |||
200 | typedef enum VarFlags { | 200 | typedef enum VarFlags { | |
201 | /* The variable's value is currently being used by Var_Parse or Var_Subst. | 201 | /* The variable's value is currently being used by Var_Parse or Var_Subst. | |
202 | * This marker is used to avoid endless recursion. */ | 202 | * This marker is used to avoid endless recursion. */ | |
203 | VAR_IN_USE = 0x01, | 203 | VAR_IN_USE = 0x01, | |
204 | /* The variable comes from the environment. | 204 | /* The variable comes from the environment. | |
205 | * These variables are not registered in any GNode, therefore they must | 205 | * These variables are not registered in any GNode, therefore they must | |
206 | * be freed as soon as they are not used anymore. */ | 206 | * be freed as soon as they are not used anymore. */ | |
207 | VAR_FROM_ENV = 0x02, | 207 | VAR_FROM_ENV = 0x02, | |
208 | /* The variable is exported to the environment, to be used by child | 208 | /* The variable is exported to the environment, to be used by child | |
@@ -346,58 +346,58 @@ GNode_FindVar(GNode *ctxt, const char *v | @@ -346,58 +346,58 @@ GNode_FindVar(GNode *ctxt, const char *v | |||
346 | return HashTable_FindValueHash(&ctxt->context, varname, hash); | 346 | return HashTable_FindValueHash(&ctxt->context, varname, hash); | |
347 | } | 347 | } | |
348 | 348 | |||
349 | /*- | 349 | /*- | |
350 | *----------------------------------------------------------------------- | 350 | *----------------------------------------------------------------------- | |
351 | * VarFind -- | 351 | * VarFind -- | |
352 | * Find the given variable in the given context and any other contexts | 352 | * Find the given variable in the given context and any other contexts | |
353 | * indicated. | 353 | * indicated. | |
354 | * | 354 | * | |
355 | * Input: | 355 | * Input: | |
356 | * name name to find | 356 | * name name to find | |
357 | * ctxt context in which to find it | 357 | * ctxt context in which to find it | |
358 | * flags FIND_GLOBAL look in VAR_GLOBAL as well | 358 | * flags FIND_GLOBAL look in VAR_GLOBAL as well | |
359 | * FIND_CMD look in VAR_CMD as well | 359 | * FIND_CMD look in VAR_CMDLINE as well | |
360 | * FIND_ENV look in the environment as well | 360 | * FIND_ENV look in the environment as well | |
361 | * | 361 | * | |
362 | * Results: | 362 | * Results: | |
363 | * A pointer to the structure describing the desired variable or | 363 | * A pointer to the structure describing the desired variable or | |
364 | * NULL if the variable does not exist. | 364 | * NULL if the variable does not exist. | |
365 | *----------------------------------------------------------------------- | 365 | *----------------------------------------------------------------------- | |
366 | */ | 366 | */ | |
367 | static Var * | 367 | static Var * | |
368 | VarFind(const char *name, GNode *ctxt, VarFindFlags flags) | 368 | VarFind(const char *name, GNode *ctxt, VarFindFlags flags) | |
369 | { | 369 | { | |
370 | Var *var; | 370 | Var *var; | |
371 | unsigned int nameHash; | 371 | unsigned int nameHash; | |
372 | 372 | |||
373 | /* | 373 | /* | |
374 | * If the variable name begins with a '.', it could very well be one of | 374 | * If the variable name begins with a '.', it could very well be one of | |
375 | * the local ones. We check the name against all the local variables | 375 | * the local ones. We check the name against all the local variables | |
376 | * and substitute the short version in for 'name' if it matches one of | 376 | * and substitute the short version in for 'name' if it matches one of | |
377 | * them. | 377 | * them. | |
378 | */ | 378 | */ | |
379 | name = CanonicalVarname(name); | 379 | name = CanonicalVarname(name); | |
380 | nameHash = Hash_Hash(name); | 380 | nameHash = Hash_Hash(name); | |
381 | 381 | |||
382 | /* | 382 | /* | |
383 | * First look for the variable in the given context. If it's not there, | 383 | * First look for the variable in the given context. If it's not there, | |
384 | * look for it in VAR_CMD, VAR_GLOBAL and the environment, in that order, | 384 | * look for it in VAR_CMDLINE, VAR_GLOBAL and the environment, in that order, | |
385 | * depending on the FIND_* flags in 'flags' | 385 | * depending on the FIND_* flags in 'flags' | |
386 | */ | 386 | */ | |
387 | var = GNode_FindVar(ctxt, name, nameHash); | 387 | var = GNode_FindVar(ctxt, name, nameHash); | |
388 | 388 | |||
389 | if (var == NULL && (flags & FIND_CMD) && ctxt != VAR_CMD) | 389 | if (var == NULL && (flags & FIND_CMD) && ctxt != VAR_CMDLINE) | |
390 | var = GNode_FindVar(VAR_CMD, name, nameHash); | 390 | var = GNode_FindVar(VAR_CMDLINE, name, nameHash); | |
391 | 391 | |||
392 | if (!opts.checkEnvFirst && var == NULL && (flags & FIND_GLOBAL) && | 392 | if (!opts.checkEnvFirst && var == NULL && (flags & FIND_GLOBAL) && | |
393 | ctxt != VAR_GLOBAL) | 393 | ctxt != VAR_GLOBAL) | |
394 | { | 394 | { | |
395 | var = GNode_FindVar(VAR_GLOBAL, name, nameHash); | 395 | var = GNode_FindVar(VAR_GLOBAL, name, nameHash); | |
396 | if (var == NULL && ctxt != VAR_INTERNAL) { | 396 | if (var == NULL && ctxt != VAR_INTERNAL) { | |
397 | /* VAR_INTERNAL is subordinate to VAR_GLOBAL */ | 397 | /* VAR_INTERNAL is subordinate to VAR_GLOBAL */ | |
398 | var = GNode_FindVar(VAR_INTERNAL, name, nameHash); | 398 | var = GNode_FindVar(VAR_INTERNAL, name, nameHash); | |
399 | } | 399 | } | |
400 | } | 400 | } | |
401 | 401 | |||
402 | if (var == NULL && (flags & FIND_ENV)) { | 402 | if (var == NULL && (flags & FIND_ENV)) { | |
403 | char *env; | 403 | char *env; | |
@@ -784,44 +784,44 @@ Var_Set_with_flags(const char *name, con | @@ -784,44 +784,44 @@ Var_Set_with_flags(const char *name, con | |||
784 | /* TODO: handle errors */ | 784 | /* TODO: handle errors */ | |
785 | name = name_freeIt; | 785 | name = name_freeIt; | |
786 | } | 786 | } | |
787 | 787 | |||
788 | if (name[0] == '\0') { | 788 | if (name[0] == '\0') { | |
789 | VAR_DEBUG2("Var_Set(\"%s\", \"%s\", ...) " | 789 | VAR_DEBUG2("Var_Set(\"%s\", \"%s\", ...) " | |
790 | "name expands to empty string - ignored\n", | 790 | "name expands to empty string - ignored\n", | |
791 | unexpanded_name, val); | 791 | unexpanded_name, val); | |
792 | free(name_freeIt); | 792 | free(name_freeIt); | |
793 | return; | 793 | return; | |
794 | } | 794 | } | |
795 | 795 | |||
796 | if (ctxt == VAR_GLOBAL) { | 796 | if (ctxt == VAR_GLOBAL) { | |
797 | v = VarFind(name, VAR_CMD, 0); | 797 | v = VarFind(name, VAR_CMDLINE, 0); | |
798 | if (v != NULL) { | 798 | if (v != NULL) { | |
799 | if (v->flags & VAR_FROM_CMD) { | 799 | if (v->flags & VAR_FROM_CMD) { | |
800 | VAR_DEBUG3("%s:%s = %s ignored!\n", ctxt->name, name, val); | 800 | VAR_DEBUG3("%s:%s = %s ignored!\n", ctxt->name, name, val); | |
801 | goto out; | 801 | goto out; | |
802 | } | 802 | } | |
803 | VarFreeEnv(v, TRUE); | 803 | VarFreeEnv(v, TRUE); | |
804 | } | 804 | } | |
805 | } | 805 | } | |
806 | 806 | |||
807 | /* | 807 | /* | |
808 | * We only look for a variable in the given context since anything set | 808 | * We only look for a variable in the given context since anything set | |
809 | * here will override anything in a lower context, so there's not much | 809 | * here will override anything in a lower context, so there's not much | |
810 | * point in searching them all just to save a bit of memory... | 810 | * point in searching them all just to save a bit of memory... | |
811 | */ | 811 | */ | |
812 | v = VarFind(name, ctxt, 0); | 812 | v = VarFind(name, ctxt, 0); | |
813 | if (v == NULL) { | 813 | if (v == NULL) { | |
814 | if (ctxt == VAR_CMD && !(flags & VAR_NO_EXPORT)) { | 814 | if (ctxt == VAR_CMDLINE && !(flags & VAR_NO_EXPORT)) { | |
815 | /* | 815 | /* | |
816 | * This var would normally prevent the same name being added | 816 | * This var would normally prevent the same name being added | |
817 | * to VAR_GLOBAL, so delete it from there if needed. | 817 | * to VAR_GLOBAL, so delete it from there if needed. | |
818 | * Otherwise -V name may show the wrong value. | 818 | * Otherwise -V name may show the wrong value. | |
819 | */ | 819 | */ | |
820 | Var_Delete(name, VAR_GLOBAL); | 820 | Var_Delete(name, VAR_GLOBAL); | |
821 | } | 821 | } | |
822 | VarAdd(name, val, ctxt, flags); | 822 | VarAdd(name, val, ctxt, flags); | |
823 | } else { | 823 | } else { | |
824 | if ((v->flags & VAR_READONLY) && !(flags & VAR_SET_READONLY)) { | 824 | if ((v->flags & VAR_READONLY) && !(flags & VAR_SET_READONLY)) { | |
825 | VAR_DEBUG3("%s:%s = %s ignored (read-only)\n", | 825 | VAR_DEBUG3("%s:%s = %s ignored (read-only)\n", | |
826 | ctxt->name, name, val); | 826 | ctxt->name, name, val); | |
827 | goto out; | 827 | goto out; | |
@@ -830,27 +830,27 @@ Var_Set_with_flags(const char *name, con | @@ -830,27 +830,27 @@ Var_Set_with_flags(const char *name, con | |||
830 | if (val) | 830 | if (val) | |
831 | Buf_AddStr(&v->val, val); | 831 | Buf_AddStr(&v->val, val); | |
832 | 832 | |||
833 | VAR_DEBUG3("%s:%s = %s\n", ctxt->name, name, val); | 833 | VAR_DEBUG3("%s:%s = %s\n", ctxt->name, name, val); | |
834 | if (v->flags & VAR_EXPORTED) { | 834 | if (v->flags & VAR_EXPORTED) { | |
835 | Var_Export1(name, VAR_EXPORT_PARENT); | 835 | Var_Export1(name, VAR_EXPORT_PARENT); | |
836 | } | 836 | } | |
837 | } | 837 | } | |
838 | /* | 838 | /* | |
839 | * Any variables given on the command line are automatically exported | 839 | * Any variables given on the command line are automatically exported | |
840 | * to the environment (as per POSIX standard) | 840 | * to the environment (as per POSIX standard) | |
841 | * Other than internals. | 841 | * Other than internals. | |
842 | */ | 842 | */ | |
843 | if (ctxt == VAR_CMD && !(flags & VAR_NO_EXPORT) && name[0] != '.') { | 843 | if (ctxt == VAR_CMDLINE && !(flags & VAR_NO_EXPORT) && name[0] != '.') { | |
844 | if (v == NULL) { | 844 | if (v == NULL) { | |
845 | /* we just added it */ | 845 | /* we just added it */ | |
846 | v = VarFind(name, ctxt, 0); | 846 | v = VarFind(name, ctxt, 0); | |
847 | } | 847 | } | |
848 | if (v != NULL) | 848 | if (v != NULL) | |
849 | v->flags |= VAR_FROM_CMD; | 849 | v->flags |= VAR_FROM_CMD; | |
850 | /* | 850 | /* | |
851 | * If requested, don't export these in the environment | 851 | * If requested, don't export these in the environment | |
852 | * individually. We still put them in MAKEOVERRIDES so | 852 | * individually. We still put them in MAKEOVERRIDES so | |
853 | * that the command-line settings continue to override | 853 | * that the command-line settings continue to override | |
854 | * Makefile settings. | 854 | * Makefile settings. | |
855 | */ | 855 | */ | |
856 | if (!opts.varNoExportEnv) | 856 | if (!opts.varNoExportEnv) | |
@@ -873,32 +873,32 @@ out: | @@ -873,32 +873,32 @@ out: | |||
873 | * Set the variable name to the value val in the given context. | 873 | * Set the variable name to the value val in the given context. | |
874 | * | 874 | * | |
875 | * If the variable doesn't yet exist, it is created. | 875 | * If the variable doesn't yet exist, it is created. | |
876 | * Otherwise the new value overwrites and replaces the old value. | 876 | * Otherwise the new value overwrites and replaces the old value. | |
877 | * | 877 | * | |
878 | * Input: | 878 | * Input: | |
879 | * name name of variable to set | 879 | * name name of variable to set | |
880 | * val value to give to the variable | 880 | * val value to give to the variable | |
881 | * ctxt context in which to set it | 881 | * ctxt context in which to set it | |
882 | * | 882 | * | |
883 | * Notes: | 883 | * Notes: | |
884 | * The variable is searched for only in its context before being | 884 | * The variable is searched for only in its context before being | |
885 | * created in that context. I.e. if the context is VAR_GLOBAL, | 885 | * created in that context. I.e. if the context is VAR_GLOBAL, | |
886 | * only VAR_GLOBAL->context is searched. Likewise if it is VAR_CMD, only | 886 | * only VAR_GLOBAL->context is searched. Likewise if it is VAR_CMDLINE, | |
887 | * VAR_CMD->context is searched. This is done to avoid the literally | 887 | * only VAR_CMDLINE->context is searched. This is done to avoid the | |
888 | * thousands of unnecessary strcmp's that used to be done to | 888 | * literally thousands of unnecessary strcmp's that used to be done to | |
889 | * set, say, $(@) or $(<). | 889 | * set, say, $(@) or $(<). | |
890 | * If the context is VAR_GLOBAL though, we check if the variable | 890 | * If the context is VAR_GLOBAL though, we check if the variable | |
891 | * was set in VAR_CMD from the command line and skip it if so. | 891 | * was set in VAR_CMDLINE from the command line and skip it if so. | |
892 | *----------------------------------------------------------------------- | 892 | *----------------------------------------------------------------------- | |
893 | */ | 893 | */ | |
894 | void | 894 | void | |
895 | Var_Set(const char *name, const char *val, GNode *ctxt) | 895 | Var_Set(const char *name, const char *val, GNode *ctxt) | |
896 | { | 896 | { | |
897 | Var_Set_with_flags(name, val, ctxt, 0); | 897 | Var_Set_with_flags(name, val, ctxt, 0); | |
898 | } | 898 | } | |
899 | 899 | |||
900 | /*- | 900 | /*- | |
901 | *----------------------------------------------------------------------- | 901 | *----------------------------------------------------------------------- | |
902 | * Var_Append -- | 902 | * Var_Append -- | |
903 | * The variable of the given name has the given value appended to it in | 903 | * The variable of the given name has the given value appended to it in | |
904 | * the given context. | 904 | * the given context. | |
@@ -936,27 +936,27 @@ Var_Append(const char *name, const char | @@ -936,27 +936,27 @@ Var_Append(const char *name, const char | |||
936 | if (name[0] == '\0') { | 936 | if (name[0] == '\0') { | |
937 | VAR_DEBUG2("Var_Append(\"%s\", \"%s\", ...) " | 937 | VAR_DEBUG2("Var_Append(\"%s\", \"%s\", ...) " | |
938 | "name expands to empty string - ignored\n", | 938 | "name expands to empty string - ignored\n", | |
939 | unexpanded_name, val); | 939 | unexpanded_name, val); | |
940 | free(name_freeIt); | 940 | free(name_freeIt); | |
941 | return; | 941 | return; | |
942 | } | 942 | } | |
943 | } | 943 | } | |
944 | 944 | |||
945 | v = VarFind(name, ctxt, ctxt == VAR_GLOBAL ? (FIND_CMD | FIND_ENV) : 0); | 945 | v = VarFind(name, ctxt, ctxt == VAR_GLOBAL ? (FIND_CMD | FIND_ENV) : 0); | |
946 | 946 | |||
947 | if (v == NULL) { | 947 | if (v == NULL) { | |
948 | Var_Set(name, val, ctxt); | 948 | Var_Set(name, val, ctxt); | |
949 | } else if (ctxt == VAR_CMD || !(v->flags & VAR_FROM_CMD)) { | 949 | } else if (ctxt == VAR_CMDLINE || !(v->flags & VAR_FROM_CMD)) { | |
950 | Buf_AddByte(&v->val, ' '); | 950 | Buf_AddByte(&v->val, ' '); | |
951 | Buf_AddStr(&v->val, val); | 951 | Buf_AddStr(&v->val, val); | |
952 | 952 | |||
953 | VAR_DEBUG3("%s:%s = %s\n", | 953 | VAR_DEBUG3("%s:%s = %s\n", | |
954 | ctxt->name, name, Buf_GetAll(&v->val, NULL)); | 954 | ctxt->name, name, Buf_GetAll(&v->val, NULL)); | |
955 | 955 | |||
956 | if (v->flags & VAR_FROM_ENV) { | 956 | if (v->flags & VAR_FROM_ENV) { | |
957 | HashEntry *h; | 957 | HashEntry *h; | |
958 | 958 | |||
959 | /* | 959 | /* | |
960 | * If the original variable came from the environment, we | 960 | * If the original variable came from the environment, we | |
961 | * have to install it in the global context (we could place | 961 | * have to install it in the global context (we could place | |
962 | * it in the environment, but then we should provide a way to | 962 | * it in the environment, but then we should provide a way to | |
@@ -3318,63 +3318,63 @@ bad_modifier: | @@ -3318,63 +3318,63 @@ bad_modifier: | |||
3318 | cleanup: | 3318 | cleanup: | |
3319 | *pp = p; | 3319 | *pp = p; | |
3320 | free(*freePtr); | 3320 | free(*freePtr); | |
3321 | *freePtr = NULL; | 3321 | *freePtr = NULL; | |
3322 | *exprFlags = st.exprFlags; | 3322 | *exprFlags = st.exprFlags; | |
3323 | return var_Error; | 3323 | return var_Error; | |
3324 | } | 3324 | } | |
3325 | 3325 | |||
3326 | static Boolean | 3326 | static Boolean | |
3327 | VarIsDynamic(GNode *ctxt, const char *varname, size_t namelen) | 3327 | VarIsDynamic(GNode *ctxt, const char *varname, size_t namelen) | |
3328 | { | 3328 | { | |
3329 | if ((namelen == 1 || | 3329 | if ((namelen == 1 || | |
3330 | (namelen == 2 && (varname[1] == 'F' || varname[1] == 'D'))) && | 3330 | (namelen == 2 && (varname[1] == 'F' || varname[1] == 'D'))) && | |
3331 | (ctxt == VAR_CMD || ctxt == VAR_GLOBAL)) | 3331 | (ctxt == VAR_CMDLINE || ctxt == VAR_GLOBAL)) | |
3332 | { | 3332 | { | |
3333 | /* | 3333 | /* | |
3334 | * If substituting a local variable in a non-local context, | 3334 | * If substituting a local variable in a non-local context, | |
3335 | * assume it's for dynamic source stuff. We have to handle | 3335 | * assume it's for dynamic source stuff. We have to handle | |
3336 | * this specially and return the longhand for the variable | 3336 | * this specially and return the longhand for the variable | |
3337 | * with the dollar sign escaped so it makes it back to the | 3337 | * with the dollar sign escaped so it makes it back to the | |
3338 | * caller. Only four of the local variables are treated | 3338 | * caller. Only four of the local variables are treated | |
3339 | * specially as they are the only four that will be set | 3339 | * specially as they are the only four that will be set | |
3340 | * when dynamic sources are expanded. | 3340 | * when dynamic sources are expanded. | |
3341 | */ | 3341 | */ | |
3342 | switch (varname[0]) { | 3342 | switch (varname[0]) { | |
3343 | case '@': | 3343 | case '@': | |
3344 | case '%': | 3344 | case '%': | |
3345 | case '*': | 3345 | case '*': | |
3346 | case '!': | 3346 | case '!': | |
3347 | return TRUE; | 3347 | return TRUE; | |
3348 | } | 3348 | } | |
3349 | return FALSE; | 3349 | return FALSE; | |
3350 | } | 3350 | } | |
3351 | 3351 | |||
3352 | if ((namelen == 7 || namelen == 8) && varname[0] == '.' && | 3352 | if ((namelen == 7 || namelen == 8) && varname[0] == '.' && | |
3353 | ch_isupper(varname[1]) && (ctxt == VAR_CMD || ctxt == VAR_GLOBAL)) | 3353 | ch_isupper(varname[1]) && (ctxt == VAR_CMDLINE || ctxt == VAR_GLOBAL)) | |
3354 | { | 3354 | { | |
3355 | return strcmp(varname, ".TARGET") == 0 || | 3355 | return strcmp(varname, ".TARGET") == 0 || | |
3356 | strcmp(varname, ".ARCHIVE") == 0 || | 3356 | strcmp(varname, ".ARCHIVE") == 0 || | |
3357 | strcmp(varname, ".PREFIX") == 0 || | 3357 | strcmp(varname, ".PREFIX") == 0 || | |
3358 | strcmp(varname, ".MEMBER") == 0; | 3358 | strcmp(varname, ".MEMBER") == 0; | |
3359 | } | 3359 | } | |
3360 | 3360 | |||
3361 | return FALSE; | 3361 | return FALSE; | |
3362 | } | 3362 | } | |
3363 | 3363 | |||
3364 | static const char * | 3364 | static const char * | |
3365 | UndefinedShortVarValue(char varname, const GNode *ctxt, VarEvalFlags eflags) | 3365 | UndefinedShortVarValue(char varname, const GNode *ctxt, VarEvalFlags eflags) | |
3366 | { | 3366 | { | |
3367 | if (ctxt == VAR_CMD || ctxt == VAR_GLOBAL) { | 3367 | if (ctxt == VAR_CMDLINE || ctxt == VAR_GLOBAL) { | |
3368 | /* | 3368 | /* | |
3369 | * If substituting a local variable in a non-local context, | 3369 | * If substituting a local variable in a non-local context, | |
3370 | * assume it's for dynamic source stuff. We have to handle | 3370 | * assume it's for dynamic source stuff. We have to handle | |
3371 | * this specially and return the longhand for the variable | 3371 | * this specially and return the longhand for the variable | |
3372 | * with the dollar sign escaped so it makes it back to the | 3372 | * with the dollar sign escaped so it makes it back to the | |
3373 | * caller. Only four of the local variables are treated | 3373 | * caller. Only four of the local variables are treated | |
3374 | * specially as they are the only four that will be set | 3374 | * specially as they are the only four that will be set | |
3375 | * when dynamic sources are expanded. | 3375 | * when dynamic sources are expanded. | |
3376 | */ | 3376 | */ | |
3377 | switch (varname) { | 3377 | switch (varname) { | |
3378 | case '@': | 3378 | case '@': | |
3379 | return "$(.TARGET)"; | 3379 | return "$(.TARGET)"; | |
3380 | case '%': | 3380 | case '%': | |
@@ -3591,27 +3591,27 @@ Var_Parse(const char **pp, GNode *ctxt, | @@ -3591,27 +3591,27 @@ Var_Parse(const char **pp, GNode *ctxt, | |||
3591 | *out_val = var_Error; | 3591 | *out_val = var_Error; | |
3592 | return VPR_PARSE_MSG; | 3592 | return VPR_PARSE_MSG; | |
3593 | } | 3593 | } | |
3594 | 3594 | |||
3595 | v = VarFind(varname, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); | 3595 | v = VarFind(varname, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); | |
3596 | 3596 | |||
3597 | /* At this point, p points just after the variable name, | 3597 | /* At this point, p points just after the variable name, | |
3598 | * either at ':' or at endc. */ | 3598 | * either at ':' or at endc. */ | |
3599 | 3599 | |||
3600 | /* | 3600 | /* | |
3601 | * Check also for bogus D and F forms of local variables since we're | 3601 | * Check also for bogus D and F forms of local variables since we're | |
3602 | * in a local context and the name is the right length. | 3602 | * in a local context and the name is the right length. | |
3603 | */ | 3603 | */ | |
3604 | if (v == NULL && ctxt != VAR_CMD && ctxt != VAR_GLOBAL && | 3604 | if (v == NULL && ctxt != VAR_CMDLINE && ctxt != VAR_GLOBAL && | |
3605 | namelen == 2 && (varname[1] == 'F' || varname[1] == 'D') && | 3605 | namelen == 2 && (varname[1] == 'F' || varname[1] == 'D') && | |
3606 | strchr("@%?*!<>", varname[0]) != NULL) | 3606 | strchr("@%?*!<>", varname[0]) != NULL) | |
3607 | { | 3607 | { | |
3608 | /* | 3608 | /* | |
3609 | * Well, it's local -- go look for it. | 3609 | * Well, it's local -- go look for it. | |
3610 | */ | 3610 | */ | |
3611 | char name[] = { varname[0], '\0' }; | 3611 | char name[] = { varname[0], '\0' }; | |
3612 | v = VarFind(name, ctxt, 0); | 3612 | v = VarFind(name, ctxt, 0); | |
3613 | 3613 | |||
3614 | if (v != NULL) { | 3614 | if (v != NULL) { | |
3615 | if (varname[1] == 'D') { | 3615 | if (varname[1] == 'D') { | |
3616 | extramodifiers = "H:"; | 3616 | extramodifiers = "H:"; | |
3617 | } else { /* F */ | 3617 | } else { /* F */ | |
@@ -3852,27 +3852,27 @@ Var_Subst(const char *str, GNode *ctxt, | @@ -3852,27 +3852,27 @@ Var_Subst(const char *str, GNode *ctxt, | |||
3852 | } | 3852 | } | |
3853 | } | 3853 | } | |
3854 | 3854 | |||
3855 | *out_res = Buf_DestroyCompact(&buf); | 3855 | *out_res = Buf_DestroyCompact(&buf); | |
3856 | return VPR_OK; | 3856 | return VPR_OK; | |
3857 | } | 3857 | } | |
3858 | 3858 | |||
3859 | /* Initialize the variables module. */ | 3859 | /* Initialize the variables module. */ | |
3860 | void | 3860 | void | |
3861 | Var_Init(void) | 3861 | Var_Init(void) | |
3862 | { | 3862 | { | |
3863 | VAR_INTERNAL = Targ_NewGN("Internal"); | 3863 | VAR_INTERNAL = Targ_NewGN("Internal"); | |
3864 | VAR_GLOBAL = Targ_NewGN("Global"); | 3864 | VAR_GLOBAL = Targ_NewGN("Global"); | |
3865 | VAR_CMD = Targ_NewGN("Command"); | 3865 | VAR_CMDLINE = Targ_NewGN("Command"); | |
3866 | } | 3866 | } | |
3867 | 3867 | |||
3868 | /* Clean up the variables module. */ | 3868 | /* Clean up the variables module. */ | |
3869 | void | 3869 | void | |
3870 | Var_End(void) | 3870 | Var_End(void) | |
3871 | { | 3871 | { | |
3872 | Var_Stats(); | 3872 | Var_Stats(); | |
3873 | } | 3873 | } | |
3874 | 3874 | |||
3875 | void | 3875 | void | |
3876 | Var_Stats(void) | 3876 | Var_Stats(void) | |
3877 | { | 3877 | { | |
3878 | HashTable_DebugStats(&VAR_GLOBAL->context, "VAR_GLOBAL"); | 3878 | HashTable_DebugStats(&VAR_GLOBAL->context, "VAR_GLOBAL"); |