aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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();