]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 63537] Fix setting -w in makefiles
authorDmitry Goncharov <dgoncharov@users.sf.net>
Sun, 18 Dec 2022 14:49:34 +0000 (09:49 -0500)
committerPaul Smith <psmith@gnu.org>
Mon, 19 Dec 2022 01:06:38 +0000 (20:06 -0500)
* src/makeint.h: Replace print_directory flag with should_print_dir().
* src/main.c (main): Remove print_directory flag and related code.
(should_print_dir): Create.
* src/output.c (output_dump): Use should_print_dir().
(output_start): Ditto.

src/main.c
src/makeint.h
src/output.c

index a8fa6018008b56305203279a753564ea557f41fe..27f145c5d32474f15f8228d0d7571d441f7d5bff 100644 (file)
@@ -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);
+}
 \f
 /* Print version information.  */
 
index 906cb3b68858e6a9c77bbca1bdac032890a761ba..40383b9cc653aeeba3591c2c0853468ddddf10d6 100644 (file)
@@ -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;
index 22387dff4ac8e6cb6248d836782b702da75f1dc0..9122fee809adfbdebd13f23c75e6413106d3fe70 100644 (file)
@@ -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);
 }