make/tests/scripts/variables
Dmitry Goncharov dc2d963989 [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.
2022-11-28 10:50:55 -05:00
..
automatic [SV 62324] Simplify set_file_variables by passing in the stem 2022-04-24 10:39:32 -04:00
CURDIR Refresh the test suite framework implementation. 2019-09-16 08:25:33 -04:00
DEFAULT_GOAL Convert all "`'" quotes to "''" per new GNU Coding Standard guidelines. 2012-03-04 00:24:20 +00:00
define Add support for the POSIX :::= assignment operator. 2021-09-20 00:29:31 -04:00
EXTRA_PREREQS Support the .EXTRA_PREREQS special variable 2020-01-03 02:08:59 -05:00
flavors Add support for the POSIX :::= assignment operator. 2021-09-20 00:29:31 -04:00
GNUMAKEFLAGS Don't add GNUMAKEFLAGS to the environment 2022-06-19 14:35:27 -04:00
INCLUDE_DIRS Fix tests for MacOS and Windows 2022-08-30 21:05:34 -04:00
LIBPATTERNS Convert all "`'" quotes to "''" per new GNU Coding Standard guidelines. 2012-03-04 00:24:20 +00:00
MAKE Convert all "`'" quotes to "''" per new GNU Coding Standard guidelines. 2012-03-04 00:24:20 +00:00
MAKE_RESTARTS * tests/scripts/variables/MAKE_RESTARTS: Remove TAB chars 2022-02-27 18:01:13 -05:00
MAKECMDGOALS * A few script fixes and updates for 3.78. 1999-09-17 03:15:37 +00:00
MAKEFILES Add test suite support to Windows 2017-06-04 18:37:20 -04:00
MAKEFLAGS [SV 63347] Always add command line variable assignments to MAKEFLAGS 2022-11-28 10:50:55 -05:00
MAKELEVEL Fix for bug #1276: Handle SHELL according to POSIX requirements. 2004-11-28 23:11:23 +00:00
MFILE_LIST [SV 50823] Support filenames containing '$' in MAKEFILE_LIST 2017-06-04 18:37:21 -04:00
negative Add support for the POSIX :::= assignment operator. 2021-09-20 00:29:31 -04:00
private cosmetics: fix few innocuous typos 2013-05-05 20:50:37 -04:00
SHELL Support "unexport" in target-specific variables. 2020-11-29 17:57:33 -05:00
special Add specific hints for errors due to invalid conditionals 2022-11-15 10:50:34 -05:00
undefine [SV 59870] define/undefine prerequisites are not target-specific vars 2021-03-14 16:35:38 -04:00