From 1e220b033279e199728e2fa3725bb0cb88c2fc22 Mon Sep 17 00:00:00 2001
From: Alexey Matveichev <github@matveichev.com>
Date: Sat, 12 Nov 2016 10:42:00 +0100
Subject: [PATCH] Silent rules for wmake

Added WM_SILENT_RULES check to wmake rules to produce compact output:

$ ./Allwmake -silent-rules
Enabling silent compilation rules
/home/alexey/OpenFOAM/OpenFOAM-dev/src/renumber/renumberMethods
    LN ./lnInclude
   DEP springRenumber.C
   DEP randomRenumber.C
   DEP OppositeFaceCellWaveName.C
   DEP structuredRenumber.C
   DEP CuthillMcKeeRenumber.C
   DEP manualRenumber.C
   DEP renumberMethod.C
    CC renumberMethod.C
    CC manualRenumber.C
    CC CuthillMcKeeRenumber.C
    CC randomRenumber.C
    CC springRenumber.C
    CC structuredRenumber.C
    CC OppositeFaceCellWaveName.C
    LD librenumberMethods.so
->> librenumberMethods.so

The behavior is enables by

1. WM_SILENT_RULES environment variable.
2. -silent-rules command line option for wmake/Allwmake.
---
 etc/bashrc                    |  2 ++
 wmake/makefiles/general       | 49 ++++++++++++++++++++++++++++++++++++++++++-
 wmake/rules/General/bison     | 13 ++++++++++++
 wmake/rules/General/btyacc    |  8 +++++++
 wmake/rules/General/btyacc++  |  7 +++++++
 wmake/rules/General/byacc     |  7 +++++++
 wmake/rules/General/flex      |  5 +++++
 wmake/rules/General/flex++    |  5 +++++
 wmake/rules/General/moc       |  6 ++++++
 wmake/rules/General/transform | 11 ++++++++++
 wmake/src/Makefile            | 15 +++++++++++++
 wmake/src/wmkdep.l            | 14 +++++++++++--
 wmake/wmake                   |  4 ++++
 wmake/wmakeLnInclude          |  5 +++++
 14 files changed, 148 insertions(+), 3 deletions(-)

diff --git a/etc/bashrc b/etc/bashrc
index 8b59bc2..4457726 100644
--- a/etc/bashrc
+++ b/etc/bashrc
@@ -138,6 +138,8 @@ export WM_PROJECT_USER_DIR=$HOME/$WM_PROJECT/$USER-$WM_PROJECT_VERSION
 # Add in preset user or site preferences:
 _foamSource `$WM_PROJECT_DIR/bin/foamEtcFile prefs.sh`
 
+[ -n "$WM_SILENT_RULES" ] && export WM_SILENT_RULES
+
 # Evaluate command-line parameters and record settings for later
 # these can be used to set/unset values, or specify alternative pref files
 export FOAM_SETTINGS="$@"
diff --git a/wmake/makefiles/general b/wmake/makefiles/general
index b7f4935..6905b6a 100644
--- a/wmake/makefiles/general
+++ b/wmake/makefiles/general
@@ -130,17 +130,34 @@ LIB_HEADER_DIRS = \
 
 $(EXE): $(OBJECTS)
 	@$(WM_SCRIPTS)/makeTargetDir $(EXE)
+ifneq ("$(WM_SILENT_RULES)","")
+	@echo "    LD $(notdir $(EXE))"
+	@$(LINKEXE) $(OBJECTS) -L$(LIB_PLATFORMS) \
+	    $(EXE_LIBS) $(PROJECT_LIBS) $(SYS_LIBS) \
+	    $(LINK_LIBS) $(GLIBS) -o $(EXE)
+else
 	$(LINKEXE) $(OBJECTS) -L$(LIB_PLATFORMS) \
 	    $(EXE_LIBS) $(PROJECT_LIBS) $(SYS_LIBS) \
 	    $(LINK_LIBS) $(GLIBS) -o $(EXE)
+endif
 
 exe:    $(SEXE)
+ifneq ("$(WM_SILENT_RULES)","")
+	@echo "->> $(notdir SEXE)"
+else
 	@echo \'$(SEXE)\' is up to date.
+endif
 
 $(SEXE):$(OBJECTS)
 	@$(WM_SCRIPTS)/makeTargetDir $(SEXE)
+ifneq ("$(WM_SILENT_RULES)","")
+	@echo "    LD $(notdir $(SEXE))"
+	@$(LINKEXE) $(OBJECTS) $(EXE_LIBS) \
+	    $(SYS_LIBS) $(LINK_LIBS) $(GLIBS) -o $(SEXE)
+else
 	$(LINKEXE) $(OBJECTS) $(EXE_LIBS) \
 	    $(SYS_LIBS) $(LINK_LIBS) $(GLIBS) -o $(SEXE)
+endif
 
 
 #------------------------------------------------------------------------------
@@ -150,29 +167,59 @@ $(SEXE):$(OBJECTS)
 objects: $(OBJECTS)
 
 libso:  $(LIB).$(SO)
+ifneq ("$(WM_SILENT_RULES)","")
+	@echo "->> $(notdir $(LIB)).$(SO)"
+else
 	@echo \'$(LIB).$(SO)\' is up to date.
+endif
 
 $(LIB).$(SO): $(OBJECTS)
 	@$(WM_SCRIPTS)/makeTargetDir $(LIB)
+ifneq ("$(WM_SILENT_RULES)","")
+	@echo "    LD $(notdir $(LIB)).$(SO)"
+	@$(LINKLIBSO) $(OBJECTS) -L$(LIB_PLATFORMS) \
+	    $(LIB_LIBS) $(GLIB_LIBS) -o $(LIB).$(SO)
+else
 	$(LINKLIBSO) $(OBJECTS) -L$(LIB_PLATFORMS) \
 	    $(LIB_LIBS) $(GLIB_LIBS) -o $(LIB).$(SO)
+endif
 
 lib:    $(LIB).a
+ifneq ("$(WM_SILENT_RULES)","")
+	@echo "->> $(notdir $(LIB)).a"
+else
 	@echo \'$(LIB).a\' is up to date.
+endif
 
 $(LIB).a: $(OBJECTS)
 	@$(WM_SCRIPTS)/makeTargetDir $(LIB)
 	@rm -f $(LIB).a
+ifneq ("$(WM_SILENT_RULES)","")
+	@echo "    AR $(notdir $(LIB))"
+	@$(AR) $(ARFLAGS) $(LIB).a $(OBJECTS)
+	@echo "RANLIB $(notdir $(LIB))"
+	@$(RANLIB) $(LIB).a
+else
 	$(AR) $(ARFLAGS) $(LIB).a $(OBJECTS)
 	$(RANLIB) $(LIB).a
+endif
 
 libo:   $(LIB).o
+ifneq ("$(WM_SILENT_RULES)","")
+	@echo "->> $(notdir $(LIB)).o"
+else
 	@echo \'$(LIB).o\' is up to date.
+endif
 
 $(LIB).o: $(OBJECTS)
 	@$(WM_SCRIPTS)/makeTargetDir $(LIB)
 	@rm -f $(LIB).o
+ifneq ("$(WM_SILENT_RULES)","")
+	@echo "    LD $(notdir $(LIB)).o"
+	@$(LD) -r -o $(LIB).o $(OBJECTS)
+else
 	$(LD) -r -o $(LIB).o $(OBJECTS)
+endif
 
 
 #------------------------------------------------------------------------------
@@ -205,4 +252,4 @@ ifeq ($(findstring lnInclude,$(MAKECMDGOALS))$(findstring updatedep,$(MAKECMDGOA
 endif
 
 
-#------------------------------------------------------------------------------
+#----------------------------- vim: set ft=make: ------------------------------
diff --git a/wmake/rules/General/bison b/wmake/rules/General/bison
index 4811b0e..7cb4cb5 100644
--- a/wmake/rules/General/bison
+++ b/wmake/rules/General/bison
@@ -1,5 +1,17 @@
 SUFFIXES += .y .Y
 
+
+ifneq ("$(WM_SILENT_RULES)","")
+ytoo = @echo "    yy $<"; $(WM_SCHEDULER) bison -v -d -y $< $(AND) \
+    mv y.tab.c $(@D)/$(<F).c $(AND) \
+    mv y.tab.h $(@D)/$(<F).h $(AND) \
+    $(cc) $(cFLAGS) -c  $(@D)/$(<F).c -o $@
+
+Ytoo = @echo "    YY $<"; $(WM_SCHEDULER) bison -v -d -y $< $(AND) \
+    mv y.tab.c $(@D)/$(<F).C $(AND) \
+    mv y.tab.h $(@D)/$(<F).H $(AND) \
+    $(CC) $(c++FLAGS) -c  $(@D)/$(<F).C -o $@
+else
 ytoo = $(WM_SCHEDULER) bison -v -d -y $< $(AND) \
     mv y.tab.c $(@D)/$(<F).c $(AND) \
     mv y.tab.h $(@D)/$(<F).h $(AND) \
@@ -9,3 +21,4 @@ Ytoo = $(WM_SCHEDULER) bison -v -d -y $< $(AND) \
     mv y.tab.c $(@D)/$(<F).C $(AND) \
     mv y.tab.h $(@D)/$(<F).H $(AND) \
     $(CC) $(c++FLAGS) -c  $(@D)/$(<F).C -o $@
+endif
diff --git a/wmake/rules/General/btyacc b/wmake/rules/General/btyacc
index 90124eb..dac790d 100644
--- a/wmake/rules/General/btyacc
+++ b/wmake/rules/General/btyacc
@@ -1,6 +1,14 @@
 SUFFIXES += .y
 
+
+ifneq ("$(WM_SILENT_RULES)","")
+ytoo = @echo "    yy $<"; $(WM_SCHEDULER) btyacc -v -d $(SKELETON) $< $(AND) \
+    mv y_tab.c $(@D)/$(<F).C $(AND) \
+    mv y_tab.h $(@D)/$(<F).H $(AND) \
+    $(CC) $(c++FLAGS) -c $(@D)/$(<F).C -o $@
+else
 ytoo = $(WM_SCHEDULER) btyacc -v -d $(SKELETON) $< $(AND) \
     mv y_tab.c $(@D)/$(<F).C $(AND) \
     mv y_tab.h $(@D)/$(<F).H $(AND) \
     $(CC) $(c++FLAGS) -c $(@D)/$(<F).C -o $@
+endif
diff --git a/wmake/rules/General/btyacc++ b/wmake/rules/General/btyacc++
index 2aa66cc..a8f4b4c 100644
--- a/wmake/rules/General/btyacc++
+++ b/wmake/rules/General/btyacc++
@@ -1,6 +1,13 @@
 SUFFIXES += .Y
 
+ifneq ("$(WM_SILENT_RULES)","")
+Ytoo = @echo "    YY $<"; $(WM_SCHEDULER) btyacc++ -v -d $(SKELETON) $< $(AND) \
+    mv y_tab.c $(@D)/$(<F).C $(AND) \
+    mv y_tab.h $(@D)/$(<F).H $(AND) \
+    $(CC) $(c++FLAGS) -c $(@D)/$(<F).C -o $@
+else
 Ytoo = $(WM_SCHEDULER) btyacc++ -v -d $(SKELETON) $< $(AND) \
     mv y_tab.c $(@D)/$(<F).C $(AND) \
     mv y_tab.h $(@D)/$(<F).H $(AND) \
     $(CC) $(c++FLAGS) -c $(@D)/$(<F).C -o $@
+endif
diff --git a/wmake/rules/General/byacc b/wmake/rules/General/byacc
index 1777338..f150ecc 100644
--- a/wmake/rules/General/byacc
+++ b/wmake/rules/General/byacc
@@ -1,6 +1,13 @@
 SUFFIXES += .y
 
+ifneq ("$(WM_SILENT_RULES)","")
+ytoo = @echo "    yy $<"; $(WM_SCHEDULER) byacc -v $(YYPREFIX) -d $< $(AND) \
+    mv y.tab.c $(@D)/$(<F).C $(AND) \
+    mv y.tab.h $(@D)/$(<F).H $(AND) \
+    $(CC) $(c++FLAGS) -c $(@D)/$(<F).C -o $@
+else
 ytoo = $(WM_SCHEDULER) byacc -v $(YYPREFIX) -d $< $(AND) \
     mv y.tab.c $(@D)/$(<F).C $(AND) \
     mv y.tab.h $(@D)/$(<F).H $(AND) \
     $(CC) $(c++FLAGS) -c $(@D)/$(<F).C -o $@
+endif
diff --git a/wmake/rules/General/flex b/wmake/rules/General/flex
index 3f2fe37..850f2f6 100644
--- a/wmake/rules/General/flex
+++ b/wmake/rules/General/flex
@@ -1,4 +1,9 @@
 SUFFIXES += .l
 
+ifneq ("$(WM_SILENT_RULES)","")
+ltoo = @echo "   LEX $<"; $(WM_SCHEDULER) flex -o $(@D)/$(<F).c $< $(AND) \
+    $(cc) $(cFLAGS) -c  $(@D)/$(<F).c -o $@
+else
 ltoo = $(WM_SCHEDULER) flex -o $(@D)/$(<F).c $< $(AND) \
     $(cc) $(cFLAGS) -c  $(@D)/$(<F).c -o $@
+endif
diff --git a/wmake/rules/General/flex++ b/wmake/rules/General/flex++
index 4a14062..52afe37 100644
--- a/wmake/rules/General/flex++
+++ b/wmake/rules/General/flex++
@@ -1,4 +1,9 @@
 SUFFIXES += .L
 
+ifneq ("$(WM_SILENT_RULES)","")
+Ltoo = @echo "   LEX $<"; $(WM_SCHEDULER) flex -+ -o$(@D)/$(<F).C -f $< $(AND) \
+    $(CC) $(c++FLAGS) $(c++LESSWARN) -c $(@D)/$(<F).C -o $@
+else
 Ltoo = $(WM_SCHEDULER) flex -+ -o$(@D)/$(<F).C -f $< $(AND) \
     $(CC) $(c++FLAGS) $(c++LESSWARN) -c $(@D)/$(<F).C -o $@
+endif
diff --git a/wmake/rules/General/moc b/wmake/rules/General/moc
index 02a0758..0e139f9 100644
--- a/wmake/rules/General/moc
+++ b/wmake/rules/General/moc
@@ -1,4 +1,10 @@
 SUFFIXES += .qt
 
+ifneq ("$(WM_SILENT_RULES)","")
+qttoo = @echo "   MOC $<"; \
+    $(WM_SCHEDULER) $(QTDIR)/bin/moc -f $< -o $(@D)/$(<F).C $(AND) \
+    $(CC) $(c++FLAGS) -c $(@D)/$(<F).C -o $@
+else
 qttoo = $(WM_SCHEDULER) $(QTDIR)/bin/moc -f $< -o $(@D)/$(<F).C $(AND) \
     $(CC) $(c++FLAGS) -c $(@D)/$(<F).C -o $@
+endif
diff --git a/wmake/rules/General/transform b/wmake/rules/General/transform
index 3fa0152..5787da7 100644
--- a/wmake/rules/General/transform
+++ b/wmake/rules/General/transform
@@ -2,15 +2,26 @@
 
 define DEFINE_TRANSFORM
 $(OBJECTS_DIR)/%.o : %$1
+ifneq ("$(WM_SILENT_RULES)","")
+	@echo "    CC $(value <F)"
+	@$$($(subst .,,$(1))too)
+else
 	$$($(subst .,,$(1))too)
+endif
 endef
 
 $(foreach s,$(SUFFIXES),$(eval $(call DEFINE_TRANSFORM,$(s))))
 
 $(OBJECTS_DIR)/%.dep : %
 	@$(WM_SCRIPTS)/makeTargetDir $@
+ifneq ("$(WM_SILENT_RULES)","")
 	@$(WMAKE_BIN)/wmkdep -I$(*D) $(LIB_HEADER_DIRS) $< | \
 		sed -e 's,^$(WM_PROJECT_DIR)/,$$(WM_PROJECT_DIR)/,' \
 			-e 's,^$(WM_THIRD_PARTY_DIR)/,$$(WM_THIRD_PARTY_DIR)/,' > $@
+else
+	@$(WMAKE_BIN)/wmkdep -v -I$(*D) $(LIB_HEADER_DIRS) $< | \
+		sed -e 's,^$(WM_PROJECT_DIR)/,$$(WM_PROJECT_DIR)/,' \
+			-e 's,^$(WM_THIRD_PARTY_DIR)/,$$(WM_THIRD_PARTY_DIR)/,' > $@
+endif
 
 #------------------------------------------------------------------------------
diff --git a/wmake/src/Makefile b/wmake/src/Makefile
index f14baad..3a04e3c 100644
--- a/wmake/src/Makefile
+++ b/wmake/src/Makefile
@@ -52,6 +52,7 @@ WM_COMPILE_OPTION = Opt
 GENERAL_RULES   = $(WM_DIR)/rules/General
 include $(GENERAL_RULES)/general
 
+cFLAGS += -Wno-unused-function
 
 #------------------------------------------------------------------------------
 # Targets
@@ -60,18 +61,32 @@ include $(GENERAL_RULES)/general
 all:  $(WMAKE_BIN)/dirToString $(WMAKE_BIN)/wmkdep
 
 clean:
+ifneq ("$(WM_SILENT_RULES)","")
+	@rm -f $(WMAKE_BIN)/* 2>/dev/null
+else
 	rm -f $(WMAKE_BIN)/* 2>/dev/null
+endif
 
 
 $(WMAKE_BIN)/dirToString: dirToString.c
 	@mkdir -p $(WMAKE_BIN)
+ifneq ("$(WM_SILENT_RULES)","")
+	@echo "    CC $<"
+	@$(cc) $(cFLAGS) dirToString.c -o $(WMAKE_BIN)/dirToString
+else
 	$(cc) $(cFLAGS) dirToString.c -o $(WMAKE_BIN)/dirToString
+endif
 
 
 $(WMAKE_BIN)/wmkdep: wmkdep.l
 	@mkdir -p $(WMAKE_BIN)
+ifneq ("$(WM_SILENT_RULES)","")
+	@echo "   LEX $<"; flex wmkdep.l; \
+		$(cc) $(cFLAGS) lex.yy.c -o $(WMAKE_BIN)/wmkdep
+else
 	flex wmkdep.l
 	$(cc) $(cFLAGS) lex.yy.c -o $(WMAKE_BIN)/wmkdep
+endif
 	@rm -f lex.yy.c 2>/dev/null
 
 
diff --git a/wmake/src/wmkdep.l b/wmake/src/wmkdep.l
index a98a597..9246ab1 100644
--- a/wmake/src/wmkdep.l
+++ b/wmake/src/wmkdep.l
@@ -47,6 +47,7 @@ Usage
 #include <sys/types.h>
 #include <dirent.h>
 #include <errno.h>
+#include <libgen.h>
 
 void nextFile(const char* fileName);
 void importFile(const char* fileName);
@@ -145,7 +146,7 @@ const char* bufferPaths[FILE_STACK_SIZE];
 int main(int argc, char* argv[])
 {
     char *basePos, *dotPos;
-    int i;
+    int i, verbose;
 
     if (argc == 1)
     {
@@ -154,7 +155,16 @@ int main(int argc, char* argv[])
     }
 
     sourceFile = strdup(argv[argc-1]);
-    fprintf(stderr, "Making dependency list for source file %s\n", sourceFile);
+    verbose = (strncmp(argv[1], "-v", 2) == 0);
+    if (verbose)
+    {
+        fprintf(stderr, "Making dependency list for source file %s\n",
+                sourceFile);
+    }
+    else
+    {
+        fprintf(stderr, "   DEP %s\n", basename(sourceFile));
+    }
 
 
     if ((basePos = strrchr(sourceFile, '/')) == NULL)
diff --git a/wmake/wmake b/wmake/wmake
index ebf50cd..672fc00 100755
--- a/wmake/wmake
+++ b/wmake/wmake
@@ -76,6 +76,7 @@ options:
   -no-scheduler     Compile without wmakeScheduler
   -update           Update lnInclude directories, dep files, remove deprecated
                     files and directories
+  -silent-rules     Use silent compilation rules
   -h | -help        Print the usage
 
 
@@ -166,6 +167,9 @@ do
         -no-scheduler)
             unset WM_SCHEDULER
             ;;
+        -silent-rules)
+            export WM_SILENT_RULES=1
+            ;;
         # Meant to be used following a pull, this will:
         # - remove dep files that depend on deleted files;
         # - remove stale dep files;
diff --git a/wmake/wmakeLnInclude b/wmake/wmakeLnInclude
index a9195b9..83ac510 100755
--- a/wmake/wmakeLnInclude
+++ b/wmake/wmakeLnInclude
@@ -139,7 +139,12 @@ fi
 cd $incDir || exit 1
 
 [ "$silentOpt" = true ] || {
+if [ -n "$WM_SILENT_RULES" ]
+then
+    echo "    LN $incDir" 1>&2
+else
     echo "$Script: linking include files to $incDir" 1>&2
+fi
 }
 
 
-- 
2.7.4

