diff --git a/src/main.c b/src/main.c index a8fa6018..27f145c5 100644 --- a/src/main.c +++ b/src/main.c @@ -195,9 +195,6 @@ static const int default_keep_going_flag = 0; int check_symlink_flag = 0; -/* Nonzero means print directory before starting and when done (-w). */ - -int print_directory; static int print_directory_flag = -1; static const int default_print_directory_flag = -1; @@ -1584,6 +1581,9 @@ main (int argc, char **argv, char **envp) define_variable_cname (GNUMAKEFLAGS_NAME, "", o_env, 0); } + /* Set MAKEFLAGS's origin to command line: in submakes MAKEFLAGS will carry + command line switches. This causes env variable MAKEFLAGS to beat + makefile modifications to MAKEFLAGS. */ decode_env_switches (STRING_SIZE_TUPLE (MAKEFLAGS_NAME), o_command); #if 0 @@ -1685,14 +1685,6 @@ main (int argc, char **argv, char **envp) /* Set always_make_flag if -B was given and we've not restarted already. */ always_make_flag = always_make_set && (restarts == 0); - /* If the user didn't specify any print-directory options, compute the - default setting: disable under -s / print in sub-makes and under -C. */ - - if (print_directory_flag == -1) - print_directory = !silent_flag && (directories != 0 || makelevel > 0); - else - print_directory = print_directory_flag; - /* If -R was given, set -r too (doesn't make sense otherwise!) */ if (no_builtin_variables_flag) no_builtin_rules_flag = 1; @@ -3109,7 +3101,7 @@ handle_non_switch_argument (const char *arg, enum variable_origin origin) } /* Decode switches from ARGC and ARGV. - They came from the environment if ENV is nonzero. */ + They came from the environment if ORIGIN is o_env. */ static void decode_switches (int argc, const char **argv, enum variable_origin origin) @@ -3639,6 +3631,19 @@ define_makeflags (int makefile) return v; } + +/* Return 1 if the working directory change message should be printed. + Otherwise, return 0. */ +int +should_print_dir (void) +{ + if (print_directory_flag >= 0) + return print_directory_flag; + + /* If the user didn't specify any print-directory options, compute the + default setting: disable under -s / print in sub-makes and under -C. */ + return !silent_flag && (makelevel > 0 || directories != NULL); +} /* Print version information. */ diff --git a/src/makeint.h b/src/makeint.h index 906cb3b6..40383b9c 100644 --- a/src/makeint.h +++ b/src/makeint.h @@ -575,6 +575,7 @@ void decode_env_switches (const char*, size_t line, enum variable_origin origin); struct variable; struct variable *define_makeflags (int makefile); +int should_print_dir (void); void temp_stdin_unlink (void); void die (int) NORETURN; void pfatal_with_name (const char *) NORETURN; @@ -752,7 +753,7 @@ extern unsigned short stopchar_map[]; extern int just_print_flag, run_silent, ignore_errors_flag, keep_going_flag; extern int print_data_base_flag, question_flag, touch_flag, always_make_flag; extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag; -extern int print_version_flag, print_directory, check_symlink_flag; +extern int print_version_flag, check_symlink_flag; extern int warn_undefined_variables_flag, posix_pedantic; extern int not_parallel, second_expansion, clock_skew_detected; extern int rebuilding_makefiles, one_shell, output_sync, verify_flag; diff --git a/src/output.c b/src/output.c index 22387dff..9122fee8 100644 --- a/src/output.c +++ b/src/output.c @@ -285,7 +285,8 @@ output_dump (struct output *out) } /* Log the working directory for this dump. */ - if (print_directory && output_sync != OUTPUT_SYNC_RECURSE) + + if (output_sync != OUTPUT_SYNC_RECURSE && should_print_dir ()) traced = log_working_directory (1); if (outfd_not_empty) @@ -369,7 +370,7 @@ output_start (void) /* If we're not syncing this output per-line or per-target, make sure we emit the "Entering..." message where appropriate. */ if (output_sync == OUTPUT_SYNC_NONE || output_sync == OUTPUT_SYNC_RECURSE) - if (! stdio_traced && print_directory) + if (! stdio_traced && should_print_dir ()) stdio_traced = log_working_directory (1); }