aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-06-02 09:56:40 +0100
committerRon Yorston <rmy@pobox.com>2024-06-02 09:56:40 +0100
commit25373f4d5f5b211fb959937eb370a03e2bacd7b3 (patch)
treeb1c00a5cd8d82ad6b018def44410ec09501ac44f
parent433d9fddde9b66727a5066ffe0e5a776da20a4f1 (diff)
downloadbusybox-w32-25373f4d5f5b211fb959937eb370a03e2bacd7b3.tar.gz
busybox-w32-25373f4d5f5b211fb959937eb370a03e2bacd7b3.tar.bz2
busybox-w32-25373f4d5f5b211fb959937eb370a03e2bacd7b3.zip
make: restore warning about invalid macro name
Commit 90c5352a9 (make: change how macros are read from the environment) was intended to ignore environment variables with invalid names. It had the unintended consequence of also ignoring macros with invalid names defined in makefiles. This was because such macros can have the same level (3) as those imported from the environment. Rather than use the level to detect importing from the environment add a flag to indicate this circumstance.
-rw-r--r--miscutils/make.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/miscutils/make.c b/miscutils/make.c
index 02da3611c..deb04ec88 100644
--- a/miscutils/make.c
+++ b/miscutils/make.c
@@ -226,8 +226,9 @@ struct macro {
226}; 226};
227 227
228// Flags passed to setmacro() 228// Flags passed to setmacro()
229#define M_IMMEDIATE 8 // immediate-expansion macro is being defined 229#define M_IMMEDIATE 0x08 // immediate-expansion macro is being defined
230#define M_VALID 16 // assert macro name is valid 230#define M_VALID 0x10 // assert macro name is valid
231#define M_ENVIRON 0x20 // macro imported from environment
231 232
232// Constants for PRAGMA. Order must match strings in set_pragma(). 233// Constants for PRAGMA. Order must match strings in set_pragma().
233enum { 234enum {
@@ -781,9 +782,10 @@ setmacro(const char *name, const char *val, int level)
781{ 782{
782 struct macro *mp; 783 struct macro *mp;
783 bool valid = level & M_VALID; 784 bool valid = level & M_VALID;
785 bool from_env = level & M_ENVIRON;
784 bool immediate = level & M_IMMEDIATE; 786 bool immediate = level & M_IMMEDIATE;
785 787
786 level &= ~(M_IMMEDIATE | M_VALID); 788 level &= ~(M_IMMEDIATE | M_VALID | M_ENVIRON);
787 mp = getmp(name); 789 mp = getmp(name);
788 if (mp) { 790 if (mp) {
789 // Don't replace existing macro from a lower level 791 // Don't replace existing macro from a lower level
@@ -798,7 +800,7 @@ setmacro(const char *name, const char *val, int level)
798 800
799 if (!valid && !is_valid_macro(name)) { 801 if (!valid && !is_valid_macro(name)) {
800 // Silently drop invalid names from the environment 802 // Silently drop invalid names from the environment
801 if (level == 3) 803 if (from_env)
802 return; 804 return;
803#if ENABLE_FEATURE_MAKE_POSIX 805#if ENABLE_FEATURE_MAKE_POSIX
804 error("invalid macro name '%s'%s", name, 806 error("invalid macro name '%s'%s", name,
@@ -2843,9 +2845,9 @@ process_macros(char **argv, int level)
2843 2845
2844 /* We want to process _most_ macro assignments. 2846 /* We want to process _most_ macro assignments.
2845 * There are exceptions for particular values from the 2847 * There are exceptions for particular values from the
2846 * environment (level 3). */ 2848 * environment. */
2847 idx = index_in_strings(SPECIAL_MACROS, *argv); 2849 idx = index_in_strings(SPECIAL_MACROS, *argv);
2848 if (!(level == 3 && 2850 if (!((level & M_ENVIRON) &&
2849 (idx == MAKEFLAGS || idx == SHELL || 2851 (idx == MAKEFLAGS || idx == SHELL ||
2850 (idx == CURDIR && !useenv && !POSIX_2017)))) { 2852 (idx == CURDIR && !useenv && !POSIX_2017)))) {
2851 if (colon) { 2853 if (colon) {
@@ -3084,7 +3086,7 @@ int make_main(int argc UNUSED_PARAM, char **argv)
3084 } 3086 }
3085 3087
3086 // Process macro definitions from the environment 3088 // Process macro definitions from the environment
3087 process_macros(environ, 3); 3089 process_macros(environ, 3 | M_ENVIRON);
3088 3090
3089 // Update MAKEFLAGS and environment 3091 // Update MAKEFLAGS and environment
3090 update_makeflags(); 3092 update_makeflags();