summaryrefslogtreecommitdiff
path: root/src/makeint.h
diff options
context:
space:
mode:
authorDmitry Goncharov <dgoncharov@users.sf.net>2022-11-27 14:09:17 -0500
committerPaul Smith <psmith@gnu.org>2022-11-28 10:50:55 -0500
commitdc2d963989b96161472b2cd38cef5d1f4851ea34 (patch)
treed86b04155c58dee7f478d5501d565a3d45f0e09b /src/makeint.h
parent53b8f6a5da5cd8c585d0de28d7ad6a8912061c64 (diff)
downloadmake-git-dc2d963989b96161472b2cd38cef5d1f4851ea34.tar.gz
[SV 63347] Always add command line variable assignments to MAKEFLAGS
This commit introduces two visible changes: 1. Keep command line variable assignments in MAKEFLAGS at all times, even while parsing makefiles. 2. Define makeflags immediately when a makefile modifies MAKEFLAGS. The new MAKEFLAGS and MAKEOVERRIDES initialization procedure: 1. decode_switches (argc, argv, o_command) is called to parse command line variable assignments. 2. Command line variable assignments go through quote_for_env. Initialize -*-command-variables-*- to the quoted values. 3. MAKEOVERRIDES is initialized to refer to -*-command-variables-*- with origin o_env to keep the definitions in the database intact. 4. define_makeflags() is called which adds MAKEOVERRIDES to MAKEFLAGS. 5. Makefiles are parsed. If a makefile modifies MAKEFLAGS, the new value of MAKEFLAGS is defined right away. 6. Env switches are decoded again as o_env. The definitions set by decode_switches at step 1 stay intact, as o_command beats o_env. We must preserve the original intact definitions in order to detect failure cases; for example: $ cat makefile all:; $(hello) $ make hello='$(world' makefile:1: *** unterminated variable reference. Stop. * src/makeint.h: Declare enum variable_origin, struct variable and define_makeflags(). Add parameter origin to decode_env_switches(). * src/main.c (define_makeflags): Remove "all". If a variable is assigned on the command line then append MAKEOVERRIDES to MAKEFLAGS. (decode_env_switches): Replace parameter env with origin. (decode_switches): Replace parameter env with origin. Treat origin == o_command as env == 0. (handle_non_switch_argument): Replace parameter env with origin. Treat origin == o_command as env == 0. (main): Call decode_switches() with origin==o_command before parsing makefiles. Call decode_switches() with origin==o_env after parsing makefiles. * src/variable.c (set_special_var): Define makeflags at parse time, each time a makefile modifies MAKEFLAGS. (do_variable_definition): Strip command line variable assignments from MAKEFLAGS before appending extra flags. set_special_var() adds them back. * tests/scripts/variables/MAKEFLAGS: Add tests.
Diffstat (limited to 'src/makeint.h')
-rw-r--r--src/makeint.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/makeint.h b/src/makeint.h
index c726abe0..d6ac21b8 100644
--- a/src/makeint.h
+++ b/src/makeint.h
@@ -558,7 +558,11 @@ void out_of_memory (void) NORETURN;
#define ONS(_t,_a,_f,_n,_s) _t((_a), INTSTR_LENGTH + strlen (_s), \
(_f), (_n), (_s))
-void decode_env_switches (const char*, size_t line);
+enum variable_origin;
+void decode_env_switches (const char*, size_t line,
+ enum variable_origin origin);
+struct variable;
+struct variable *define_makeflags (int makefile);
void temp_stdin_unlink (void);
void die (int) NORETURN;
void pfatal_with_name (const char *) NORETURN;