]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 59169] Add --debug=why and --debug=print options
authorPaul Smith <psmith@gnu.org>
Sat, 5 Dec 2020 21:25:12 +0000 (16:25 -0500)
committerPaul Smith <psmith@gnu.org>
Sat, 5 Dec 2020 21:25:12 +0000 (16:25 -0500)
Add debug options to print recipes even if they would otherwise be
silent, and to print the reason that a target was considered out of
date.

Modify --trace to simply be a shorthand for --debug=print,why.

* NEWS: Announce changes.
* doc/make.texi (Summary of Options): Document the new options.
* doc/make.1: Ditto.
* src/debug.h: Add new flags DB_PRINT and DB_WHY.
* src/makeint.h: Remove the trace_flag variable.
* src/job.c (start_job_command): Check debug flags not trace_flag.
(new_job): Ditto.
* src/main.c (trace_flag): Make a static variable for switches.
(decode_debug_flags): Set DB_PRINT and DB_WHY if trace_flag is set.
* tests/scripts/variables/GNUMAKEFLAGS: Update known-good messages.
* tests/scripts/variables/MAKEFLAGS: Ditto.

NEWS
doc/make.1
doc/make.texi
src/debug.h
src/job.c
src/main.c
src/makeint.h
tests/scripts/variables/GNUMAKEFLAGS
tests/scripts/variables/MAKEFLAGS

diff --git a/NEWS b/NEWS
index 0e3ca536084f6c5482dcadc9d459b4d9a604e4d6..6802a7ce563073c17563b0fc5cfa140bc0168b43 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,14 @@ https://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=109&se
   https://www.gnu.org/software/gnulib/manual/html_node/C99-features-assumed.html
   The configure script should verify the compiler has these features.
 
+* New debug option "print" will show the recipe to be run, even when silent
+  mode is set.
+
+* New debug option "why" will show why a target is rebuilt (which
+  prerequisites caused the target to be considered out of date).
+
+* The existing --trace option is made equivalent to --debug=print,why
+
 * Target-specific variables can now be marked "unexport".
 
 * Exporting / unexporting target-specific variables is handled correctly, so
index dbd023fa4a8c9a4b319b1fbdf3907a31599a0a45..1ec661eafec04400de35509ae4e2878df4f19d3f 100644 (file)
@@ -130,21 +130,28 @@ are omitted, then the behavior is the same as if
 .B \-d
 was specified.
 .I FLAGS
-may be
-.I a
+may be any or all of the following names, comma- or space-separated.  Only the
+first character is significant: the rest may be omitted:
+.I all
 for all debugging output (same as using
 .BR \-d ),
-.I b
+.I basic
 for basic debugging,
-.I v
+.I verbose
 for more verbose basic debugging,
-.I i
-for showing implicit rules,
-.I j
-for details on invocation of commands, and
-.I m
-for debugging while remaking makefiles.  Use
-.I n
+.I implicit
+for showing implicit rule search operations,
+.I jobs
+for details on invocation of commands,
+.I makefile
+for debugging while remaking makefiles,
+.I print
+shows all recipes that are run even if they are silent, and
+.I why
+shows the reason
+.BR make
+decided to rebuild each target.  Use
+.I none
 to disable all previous debugging flags.
 .TP 0.5i
 \fB\-e\fR, \fB\-\-environment\-overrides\fR
index 45b510028ecb30702e3707e271a0442cb84eb56b..85bd66e07ed9d52da4444fcc24a6048d2e32ca6f 100644 (file)
@@ -8892,6 +8892,15 @@ the makefiles.  This option enables messages while rebuilding makefiles,
 too.  Note that the @samp{all} option does enable this option.  This
 option also enables @samp{basic} messages.
 
+@item p (@i{print})
+Prints the recipe to be executed, even when the recipe is normally
+silent (due to @code{.SILENT} or @samp{@@}).  Also prints the makefile
+name and line number where the recipe was defined.
+
+@item w (@i{why})
+Explains why each target must be remade by showing which prerequisites
+are more up to date than the target.
+
 @item n (@i{none})
 Disable all debugging currently enabled.  If additional debugging
 flags are encountered after this they will still take effect.
@@ -9123,11 +9132,8 @@ recipes were done, in order to fool future invocations of
 
 @item --trace
 @cindex @code{--trace}
-Show tracing information for @code{make} execution.  Prints the entire
-recipe to be executed, even for recipes that are normally silent (due
-to @code{.SILENT} or @samp{@@}).  Also prints the makefile name and
-line number where the recipe was defined, and information on why the
-target is being rebuilt.
+Show tracing information for @code{make} execution.  This is shorthand
+for @code{--debug=print,why}.
 
 @item -v
 @cindex @code{-v}
index 514b7e8e29b2f33b14ef255904a4da570d82d98c..4db34b9d410ceab0d448e71aa5323f5bdc459a08 100644 (file)
@@ -19,6 +19,8 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #define DB_VERBOSE      (0x002)
 #define DB_JOBS         (0x004)
 #define DB_IMPLICIT     (0x008)
+#define DB_PRINT        (0x010)
+#define DB_WHY          (0x020)
 #define DB_MAKEFILES    (0x100)
 
 #define DB_ALL          (0xfff)
index 28ddacffb83aaf463f67d35ada78cb7159081cba..d6e28d3a7a54f152c2f5ac123381bc4bc1a5af6e 100644 (file)
--- a/src/job.c
+++ b/src/job.c
@@ -29,7 +29,7 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 /* Default shell to use.  */
 #ifdef WINDOWS32
 # ifdef HAVE_STRINGS_H
-#  include <strings.h> /* for strcasecmp, strncasecmp */
+#  include <strings.h>  /* for strcasecmp, strncasecmp */
 # endif
 # include <windows.h>
 
@@ -1341,7 +1341,7 @@ start_job_command (struct child *child)
 #endif
 
   /* Print the command if appropriate.  */
-  if (just_print_flag || trace_flag
+  if (just_print_flag || ISDB (DB_PRINT)
       || (!(flags & COMMANDS_SILENT) && !run_silent))
     OS (message, 0, "%s", p);
 
@@ -1884,7 +1884,7 @@ new_job (struct file *file)
 
   /* Trace the build.
      Use message here so that changes to working directories are logged.  */
-  if (trace_flag)
+  if (ISDB (DB_WHY))
     {
       char *newer = allocated_variable_expand_for_file ("$?", c->file);
       const char *nm;
@@ -1898,12 +1898,9 @@ new_job (struct file *file)
           nm = n;
         }
 
-      if (newer[0] == '\0')
-        OSS (message, 0,
-             _("%s: target '%s' does not exist"), nm, c->file->name);
-      else
-        OSSS (message, 0,
-              _("%s: update target '%s' due to: %s"), nm, c->file->name, newer);
+      OSSS (message, 0,
+            _("%s: update target '%s' due to: %s"), nm, c->file->name,
+              newer[0] == '\0' ? _("target does not exist") : newer);
 
       free (newer);
     }
index 64e25291a0ac89a1a11ca726af6f32c0ec71373f..2c202588c6734f881e9f4fb65218c057fbebb275 100644 (file)
@@ -413,6 +413,10 @@ static const char *const usage[] =
     NULL
   };
 
+/* Nonzero if the "--trace" option was given.  */
+
+static int trace_flag = 0;
+
 /* The table of command switches.
    Order matters here: this is the order MAKEFLAGS will be constructed.
    So be sure all simple flags (single char, no argument) come first.  */
@@ -553,10 +557,6 @@ int one_shell;
 
 int output_sync = OUTPUT_SYNC_NONE;
 
-/* Nonzero if the "--trace" option was given.  */
-
-int trace_flag = 0;
-
 /* Nonzero if we have seen the '.NOTPARALLEL' target.
    This turns off parallel builds for this invocation of make.  */
 
@@ -724,6 +724,9 @@ decode_debug_flags (void)
   if (debug_flag)
     db_level = DB_ALL;
 
+  if (trace_flag)
+    db_level = DB_PRINT | DB_WHY;
+
   if (db_flags)
     for (pp=db_flags->list; *pp; ++pp)
       {
@@ -751,9 +754,15 @@ decode_debug_flags (void)
               case 'n':
                 db_level = 0;
                 break;
+              case 'p':
+                db_level |= DB_PRINT;
+                break;
               case 'v':
                 db_level |= DB_BASIC | DB_VERBOSE;
                 break;
+              case 'w':
+                db_level |= DB_WHY;
+                break;
               default:
                 OS (fatal, NILF,
                     _("unknown debug level specification '%s'"), p);
index 70ee2b6daaea0057decdec5ed4303ae94f4d29b4..015bf5c2796cfb59e83acd4548b48142ad5ff440 100644 (file)
@@ -686,7 +686,7 @@ 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 warn_undefined_variables_flag, trace_flag, posix_pedantic;
+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;
 extern unsigned long command_count;
index 063c256dfbcd6d3aecf3c6583f68db954fc9d920..30bccf68a17fa5167ca753c3f7e3a242b0df3c84 100644 (file)
@@ -19,7 +19,7 @@ $ENV{'GNUMAKEFLAGS'} = '--no-print-directory -e -r -R --trace';
 run_make_test(q!
 all: ; @echo $(MAKEFLAGS)
 !,
-              '', "#MAKEFILE#:2: target 'all' does not exist
+              '', "#MAKEFILE#:2: update target 'all' due to: target does not exist
 echo erR --trace --no-print-directory
 erR --trace --no-print-directory");
 
index 0fac74a3e4d90a544470685343d0346bf5ee07fc..752bdc30129363d2677ef67c438ac8c210dd8d47 100644 (file)
@@ -14,7 +14,7 @@ all: ; @echo $(MAKEFLAGS)
 run_make_test(q!
 all: ; @echo $(MAKEFLAGS)
 !,
-              '--no-print-directory -e -r -R --trace', "#MAKEFILE#:2: target 'all' does not exist
+              '--no-print-directory -e -r -R --trace', "#MAKEFILE#:2: update target 'all' due to: target does not exist
 echo erR --trace --no-print-directory
 erR --trace --no-print-directory");
 
@@ -23,14 +23,15 @@ erR --trace --no-print-directory");
 # Savannah bug #2216
 run_make_test(q!
 MSG = Fails
+.RECIPEPREFIX = >
 all:
-       @echo '$@: MAKEFLAGS=$(MAKEFLAGS)'
-       @MSG=Works $(MAKE) -e -f #MAKEFILE# jump
+> @echo '$@: MAKEFLAGS=$(MAKEFLAGS)'
+> @MSG=Works $(MAKE) -e -f #MAKEFILE# jump
 jump:
-       @echo '$@ $(MSG): MAKEFLAGS=$(MAKEFLAGS)'
-       @$(MAKE) -f #MAKEFILE# print
+> @echo '$@ $(MSG): MAKEFLAGS=$(MAKEFLAGS)'
+> @$(MAKE) -f #MAKEFILE# print
 print:
-       @echo '$@ $(MSG): MAKEFLAGS=$(MAKEFLAGS)'
+> @echo '$@ $(MSG): MAKEFLAGS=$(MAKEFLAGS)'
 .PHONY: all jump print
 !,
                   '--no-print-directory',
@@ -39,7 +40,3 @@ jump Works: MAKEFLAGS=e --no-print-directory
 print Works: MAKEFLAGS=e --no-print-directory');
 
 1;
-
-### Local Variables:
-### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
-### End: