mirror of
https://github.com/mirror/make.git
synced 2025-02-06 01:30:23 +08:00
[SV 64107] Disable builtins immediately on -R or -r
Disable builtin variables and rules immediately, when -R or -r is added to MAKEFLAGS inside the makefile. * src/main.c (disable_builtins): Add new function disable_builtins(). (main): Call disable_builtins(). (reset_makeflags): Call disable_builtins(). * tests/scripts/options/dash-r: Add tests. * tests/scripts/variables/MAKEFLAGS: Update tests.
This commit is contained in:
parent
0e06c75889
commit
0880e5c86a
58
src/main.c
58
src/main.c
@ -101,6 +101,7 @@ static void decode_switches (int argc, const char **argv,
|
||||
enum variable_origin origin);
|
||||
static void decode_env_switches (const char *envar, size_t len,
|
||||
enum variable_origin origin);
|
||||
static void disable_builtins ();
|
||||
static char *quote_for_env (char *out, const char *in);
|
||||
static void initialize_global_hash_tables (void);
|
||||
|
||||
@ -180,6 +181,8 @@ int question_flag = 0;
|
||||
|
||||
int no_builtin_rules_flag = 0;
|
||||
int no_builtin_variables_flag = 0;
|
||||
static int old_builtin_rules_flag;
|
||||
static int old_builtin_variables_flag;
|
||||
|
||||
/* Nonzero means all variables are automatically exported. */
|
||||
|
||||
@ -2052,9 +2055,9 @@ main (int argc, char **argv, char **envp)
|
||||
}
|
||||
|
||||
{
|
||||
int old_builtin_rules_flag = no_builtin_rules_flag;
|
||||
int old_builtin_variables_flag = no_builtin_variables_flag;
|
||||
int old_arg_job_slots = arg_job_slots;
|
||||
old_builtin_rules_flag = no_builtin_rules_flag;
|
||||
old_builtin_variables_flag = no_builtin_variables_flag;
|
||||
|
||||
/* Read all the makefiles. */
|
||||
read_files = read_all_makefiles (makefiles == 0 ? 0 : makefiles->list);
|
||||
@ -2100,24 +2103,7 @@ main (int argc, char **argv, char **envp)
|
||||
make_sync.syncout = syncing;
|
||||
OUTPUT_SET (&make_sync);
|
||||
|
||||
/* If -R was given, set -r too (doesn't make sense otherwise!) */
|
||||
if (no_builtin_variables_flag)
|
||||
no_builtin_rules_flag = 1;
|
||||
|
||||
/* If we've disabled builtin rules, get rid of them. */
|
||||
if (no_builtin_rules_flag && ! old_builtin_rules_flag)
|
||||
{
|
||||
if (suffix_file->builtin)
|
||||
{
|
||||
free_dep_chain (suffix_file->deps);
|
||||
suffix_file->deps = 0;
|
||||
}
|
||||
define_variable_cname ("SUFFIXES", "", o_default, 0);
|
||||
}
|
||||
|
||||
/* If we've disabled builtin variables, get rid of them. */
|
||||
if (no_builtin_variables_flag && ! old_builtin_variables_flag)
|
||||
undefine_default_variables ();
|
||||
disable_builtins ();
|
||||
}
|
||||
|
||||
#if MK_OS_W32
|
||||
@ -3094,6 +3080,7 @@ reset_makeflags (enum variable_origin origin)
|
||||
{
|
||||
decode_env_switches (STRING_SIZE_TUPLE(MAKEFLAGS_NAME), origin);
|
||||
construct_include_path (include_dirs ? include_dirs->list : NULL);
|
||||
disable_builtins ();
|
||||
define_makeflags (rebuilding_makefiles);
|
||||
}
|
||||
|
||||
@ -3451,6 +3438,37 @@ quote_for_env (char *out, const char *in)
|
||||
return out;
|
||||
}
|
||||
|
||||
/* Disable builtin variables and rules, if -R or -r is specified.
|
||||
* This function is called at parse time whenever MAKEFLAGS is modified and
|
||||
* also when the parsing phase is over. */
|
||||
|
||||
static
|
||||
void disable_builtins ()
|
||||
{
|
||||
/* If -R was given, set -r too (doesn't make sense otherwise!) */
|
||||
if (no_builtin_variables_flag)
|
||||
no_builtin_rules_flag = 1;
|
||||
|
||||
/* If we've disabled builtin rules, get rid of them. */
|
||||
if (no_builtin_rules_flag && ! old_builtin_rules_flag)
|
||||
{
|
||||
old_builtin_rules_flag = 1;
|
||||
if (suffix_file->builtin)
|
||||
{
|
||||
free_dep_chain (suffix_file->deps);
|
||||
suffix_file->deps = 0;
|
||||
}
|
||||
define_variable_cname ("SUFFIXES", "", o_default, 0);
|
||||
}
|
||||
|
||||
/* If we've disabled builtin variables, get rid of them. */
|
||||
if (no_builtin_variables_flag && ! old_builtin_variables_flag)
|
||||
{
|
||||
old_builtin_variables_flag = 1;
|
||||
undefine_default_variables ();
|
||||
}
|
||||
}
|
||||
|
||||
/* Define the MAKEFLAGS and MFLAGS variables to reflect the settings of the
|
||||
command switches. Always include options with args.
|
||||
Don't include options with the 'no_makefile' flag set if MAKEFILE. */
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
$description = "Test removing default rules and variables";
|
||||
|
||||
$details = "DETAILS";
|
||||
|
||||
touch('xxx.c');
|
||||
|
||||
# Simple check
|
||||
@ -41,4 +39,65 @@ MAKEFLAGS := -R
|
||||
all: hello.o
|
||||
!, '', "#MAKE#: *** No rule to make target 'hello.o', needed by 'all'. Stop.", 512);
|
||||
|
||||
my @flavors = ('=', ':=', ':::=', '+=');
|
||||
|
||||
# sv 64107.
|
||||
|
||||
# Use $answer to test that -R in the makefile has the same effect as -R on the
|
||||
# command line.
|
||||
|
||||
my $answer = "at parse time TEX=\nat build time TEX=\n#MAKE#: 'all' is up to date.\n";
|
||||
|
||||
# Subtest 1.
|
||||
# First run with -R command line switch.
|
||||
|
||||
for my $fl (@flavors) {
|
||||
run_make_test("
|
||||
\$(info at parse time TEX=\$(TEX))
|
||||
all:; \$(info at build time TEX=\$(TEX))
|
||||
", '-R', "$answer");
|
||||
}
|
||||
|
||||
# Subtest 2.
|
||||
# Set -R in the makefile.
|
||||
# Also, test that setting -R in MAKEFLAGS takes effect immediately.
|
||||
|
||||
for my $fl (@flavors) {
|
||||
run_make_test("
|
||||
\$(info at start time TEX=\$(TEX))
|
||||
MAKEFLAGS ${fl} -R
|
||||
\$(info at parse time TEX=\$(TEX))
|
||||
all:; \$(info at build time TEX=\$(TEX))
|
||||
", '', "at start time TEX=tex\n$answer");
|
||||
}
|
||||
|
||||
# Same as above, but also set TEX conditionally.
|
||||
|
||||
$answer = "at parse time TEX=hello\nat build time TEX=hello\n#MAKE#: 'all' is up to date.\n";
|
||||
|
||||
# Subtest 3.
|
||||
# -R on the command line.
|
||||
|
||||
for my $fl (@flavors) {
|
||||
run_make_test("
|
||||
TEX ?= hello
|
||||
\$(info at parse time TEX=\$(TEX))
|
||||
all:; \$(info at build time TEX=\$(TEX))
|
||||
", '-R', "$answer");
|
||||
}
|
||||
|
||||
# Subtest 4.
|
||||
# -R in the makefile.
|
||||
|
||||
for my $fl (@flavors) {
|
||||
run_make_test("
|
||||
\$(info at start time TEX=\$(TEX))
|
||||
MAKEFLAGS ${fl} -R
|
||||
TEX ?= hello
|
||||
\$(info at parse time TEX=\$(TEX))
|
||||
all:; \$(info at build time TEX=\$(TEX))
|
||||
", '', "at start time TEX=tex\n$answer");
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
@ -297,7 +297,7 @@ MAKEFLAGS${fl}R
|
||||
all:; \$(info \$(MAKEFLAGS))
|
||||
", 'bye=moon',
|
||||
"$answer
|
||||
R$answer
|
||||
rR$answer
|
||||
rR$answer
|
||||
#MAKE#: 'all' is up to date.\n");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user