make - remove intermediate files silently

635 views Asked by At

When building a chain rule make automatically invokes rm to remove any intermediate files at the end of the build process. Since I have about 400 intermediate files to delete that way, that floods console output badly.

Is there a way to silently rm those intermediate files, so that eighter nothing will be echoed after the build is finished oder a message like "Removing intermediate files" is echoed?

2

There are 2 answers

1
akond On BEST ANSWER

You could run make -s or build your very own version of make with this patch applied:

diff --git file.c file.c
index ae1c285..de3c426 100644
--- file.c
+++ file.c
@@ -410,18 +410,6 @@ remove_intermediates (int sig)
                   {
                     if (! doneany)
                       DB (DB_BASIC, (_("Removing intermediate files...\n")));
-                    if (!silent_flag)
-                      {
-                        if (! doneany)
-                          {
-                            fputs ("rm ", stdout);
-                            doneany = 1;
-                          }
-                        else
-                          putchar (' ');
-                        fputs (f->name, stdout);
-                        fflush (stdout);
-                      }
                   }
                 if (status < 0)
                   perror_with_name ("unlink: ", f->name);
1
gtramontina On

Expanding on the accepted answer, you can modify Make's flags from within the Makefile itself (as demonstrated here). So, for your situation, you can include this at the top of your Makefile:

MAKEFLAGS += --silent

The only thing to be aware of is that the --silent flag silences all Make's output. Including the "Nothing to be done" notices.

Edit:

You can also add your target as a dependency to .SILENT, as described at https://www.gnu.org/software/make/manual/html_node/Special-Targets.html.