| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: var.c,v 1.592 2020/10/30 06:44:57 rillig Exp $ */ | | 1 | /* $NetBSD: var.c,v 1.593 2020/10/30 06:59:12 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.592 2020/10/30 06:44:57 rillig Exp $"); | | 132 | MAKE_RCSID("$NetBSD: var.c,v 1.593 2020/10/30 06:59:12 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 | */ |
| @@ -152,33 +152,34 @@ char var_Error[] = ""; | | | @@ -152,33 +152,34 @@ char var_Error[] = ""; |
152 | | | 152 | |
153 | /* Special return value for Var_Parse, indicating an undefined variable in | | 153 | /* Special return value for Var_Parse, indicating an undefined variable in |
154 | * a case where VARE_UNDEFERR is not set. This undefined variable is | | 154 | * a case where VARE_UNDEFERR is not set. This undefined variable is |
155 | * typically a dynamic variable such as ${.TARGET}, whose expansion needs to | | 155 | * typically a dynamic variable such as ${.TARGET}, whose expansion needs to |
156 | * be deferred until it is defined in an actual target. */ | | 156 | * be deferred until it is defined in an actual target. */ |
157 | static char varUndefined[] = ""; | | 157 | static char varUndefined[] = ""; |
158 | | | 158 | |
159 | /* Special return value for Var_Parse, just to avoid allocating empty strings. | | 159 | /* Special return value for Var_Parse, just to avoid allocating empty strings. |
160 | * In contrast to var_Error and varUndefined, this is not an error marker but | | 160 | * In contrast to var_Error and varUndefined, this is not an error marker but |
161 | * just an ordinary successful return value. */ | | 161 | * just an ordinary successful return value. */ |
162 | static char emptyString[] = ""; | | 162 | static char emptyString[] = ""; |
163 | | | 163 | |
164 | /* | | 164 | /* |
165 | * Traditionally we consume $$ during := like any other expansion. | | 165 | * Traditionally this make consumed $$ during := like any other expansion. |
166 | * Other make's do not. | | 166 | * Other make's do not, and this make follows straight since 2016-01-09. |
| | | 167 | * |
167 | * This knob allows controlling the behavior. | | 168 | * This knob allows controlling the behavior. |
168 | * FALSE to consume $$ during := assignment. | | 169 | * FALSE to consume $$ during := assignment. |
169 | * TRUE to preserve $$ during := assignment. | | 170 | * TRUE to preserve $$ during := assignment. |
170 | */ | | 171 | */ |
171 | #define SAVE_DOLLARS ".MAKE.SAVE_DOLLARS" | | 172 | #define MAKE_SAVE_DOLLARS ".MAKE.SAVE_DOLLARS" |
172 | static Boolean save_dollars = TRUE; | | 173 | static Boolean save_dollars = TRUE; |
173 | | | 174 | |
174 | /* | | 175 | /* |
175 | * Internally, variables are contained in four different contexts. | | 176 | * Internally, variables are contained in four different contexts. |
176 | * 1) the environment. They cannot be changed. If an environment | | 177 | * 1) the environment. They cannot be changed. If an environment |
177 | * variable is appended to, the result is placed in the global | | 178 | * variable is appended to, the result is placed in the global |
178 | * context. | | 179 | * context. |
179 | * 2) the global context. Variables set in the Makefile are located in | | 180 | * 2) the global context. Variables set in the Makefile are located in |
180 | * the global context. | | 181 | * the global context. |
181 | * 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 |
182 | * are placed in this context. They are UNALTERABLE once placed here. | | 183 | * are placed in this context. They are UNALTERABLE once placed here. |
183 | * 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 |
184 | * list. On this list are located the structures describing such | | 185 | * list. On this list are located the structures describing such |
| @@ -847,27 +848,27 @@ Var_Set_with_flags(const char *name, con | | | @@ -847,27 +848,27 @@ Var_Set_with_flags(const char *name, con |
847 | if (v != NULL) | | 848 | if (v != NULL) |
848 | v->flags |= VAR_FROM_CMD; | | 849 | v->flags |= VAR_FROM_CMD; |
849 | /* | | 850 | /* |
850 | * If requested, don't export these in the environment | | 851 | * If requested, don't export these in the environment |
851 | * individually. We still put them in MAKEOVERRIDES so | | 852 | * individually. We still put them in MAKEOVERRIDES so |
852 | * that the command-line settings continue to override | | 853 | * that the command-line settings continue to override |
853 | * Makefile settings. | | 854 | * Makefile settings. |
854 | */ | | 855 | */ |
855 | if (!opts.varNoExportEnv) | | 856 | if (!opts.varNoExportEnv) |
856 | setenv(name, val ? val : "", 1); | | 857 | setenv(name, val ? val : "", 1); |
857 | | | 858 | |
858 | Var_Append(MAKEOVERRIDES, name, VAR_GLOBAL); | | 859 | Var_Append(MAKEOVERRIDES, name, VAR_GLOBAL); |
859 | } | | 860 | } |
860 | if (name[0] == '.' && strcmp(name, SAVE_DOLLARS) == 0) | | 861 | if (name[0] == '.' && strcmp(name, MAKE_SAVE_DOLLARS) == 0) |
861 | save_dollars = s2Boolean(val, save_dollars); | | 862 | save_dollars = s2Boolean(val, save_dollars); |
862 | | | 863 | |
863 | out: | | 864 | out: |
864 | free(name_freeIt); | | 865 | free(name_freeIt); |
865 | if (v != NULL) | | 866 | if (v != NULL) |
866 | VarFreeEnv(v, TRUE); | | 867 | VarFreeEnv(v, TRUE); |
867 | } | | 868 | } |
868 | | | 869 | |
869 | /*- | | 870 | /*- |
870 | *----------------------------------------------------------------------- | | 871 | *----------------------------------------------------------------------- |
871 | * Var_Set -- | | 872 | * Var_Set -- |
872 | * 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. |
873 | * | | 874 | * |