config_host.mk.in                              |    1 
 configure.ac                                   |  112 +++++++++++++++++++------
 external/curl/ExternalProject_curl.mk          |    1 
 external/curl/UnpackedTarball_curl.mk          |    1 
 external/curl/configurable-z-option.patch.0    |   20 ++++
 external/openssl/ExternalProject_openssl.mk    |    1 
 external/openssl/UnpackedTarball_openssl.mk    |    1 
 external/openssl/configurable-z-option.patch.0 |   34 +++++++
 solenv/gbuild/PrecompiledHeaders.mk            |    2 
 solenv/gbuild/gbuild.mk                        |   18 ++++
 solenv/gbuild/platform/com_GCC_class.mk        |    6 -
 solenv/gbuild/platform/com_GCC_defs.mk         |   14 ---
 solenv/gbuild/platform/com_MSC_class.mk        |   18 +++-
 solenv/gbuild/platform/com_MSC_defs.mk         |   13 ++
 solenv/gcc-wrappers/wrapper.cxx                |   50 ++++++++---
 solenv/gcc-wrappers/wrapper.hxx                |    3 
 16 files changed, 234 insertions(+), 61 deletions(-)

New commits:
commit c48a5f2653f7e76421c140cbd6018deffefccaf9
Author:     Luboš Luňák <l.lu...@centrum.cz>
AuthorDate: Sat Nov 13 16:20:46 2021 +0000
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Wed Nov 17 15:21:44 2021 +0100

    support ccache for MSVC too
    
    There's no official MSVC support in ccache yet, but there are patches
    in progress of getting upstreamed. So right now it's necessary
    to get a patched ccache.
    Ccache cannot work with -Zi option, since sharing debuginfo in a .PDB
    cannot be cached. Added --enable-z7-symbols that gets enabled
    by default if ccache is detected.
    It works even with PCHs enabled, and externals seem to work too.
    I get almost 100% hit rate on a rebuild, although such a rebuild
    is slower than on Linux.
    
    Change-Id: I1d230ee1fccc441b9d9bec794cc2e1ec13161999
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125179
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/config_host.mk.in b/config_host.mk.in
index ec22f695d782..a03ac19747bc 100644
--- a/config_host.mk.in
+++ b/config_host.mk.in
@@ -209,6 +209,7 @@ export ENABLE_SYMBOLS_FOR=@ENABLE_SYMBOLS_FOR@
 export ENABLE_VALGRIND=@ENABLE_VALGRIND@
 export ENABLE_WASM_STRIP=@ENABLE_WASM_STRIP@
 export ENABLE_WERROR=@ENABLE_WERROR@
+export ENABLE_Z7_DEBUG=@ENABLE_Z7_DEBUG@
 export ENDIANNESS=@ENDIANNESS@
 export EPM=@EPM@
 export EPM_FLAGS=@EPM_FLAGS@
diff --git a/configure.ac b/configure.ac
index 7ebeeaf6e62f..0ee46bed9c74 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1758,7 +1758,7 @@ libo_FUZZ_ARG_ENABLE(cups,
 AC_ARG_ENABLE(ccache,
     AS_HELP_STRING([--disable-ccache],
         [Do not try to use ccache automatically.
-         By default, unless on Windows, we will try to detect if ccache is 
available; in that case if
+         By default we will try to detect if ccache is available; in that case 
if
          CC/CXX are not yet set, and --enable-icecream is not given, we
          attempt to use ccache. --disable-ccache disables ccache completely.
          Additionally ccache's depend mode is enabled if possible,
@@ -1766,6 +1766,12 @@ AC_ARG_ENABLE(ccache,
 ]),
 ,)
 
+AC_ARG_ENABLE(z7-debug,
+    AS_HELP_STRING([--enable-z7-debug],
+        [Makes the MSVC compiler use -Z7 for debugging instead of the default 
-Zi. Using this option takes
+         more disk spaces but allows to use ccache. Final PDB files are 
created even with this option enabled.
+         Enabled by default if ccache is detected.]))
+
 libo_FUZZ_ARG_ENABLE(online-update,
     AS_HELP_STRING([--enable-online-update],
         [Enable the online update service that will check for new versions of
@@ -3029,26 +3035,6 @@ dnl 
===================================================================
 CCACHE_DEPEND_MODE=
 if test "$enable_ccache" = "no"; then
     CCACHE=""
-elif test "$_os" = "WINNT"; then
-    # on windows/VC build do not use ccache - but perhaps sccache is around?
-    case "%$CC%$CXX%" in
-    # If $CC and/or $CXX already contain "sccache" (possibly suffixed with 
some version number etc),
-    # assume that's good then
-    *%sccache[[-_' ']]*|*/sccache[[-_' ']]*)
-        AC_MSG_NOTICE([sccache seems to be included in a pre-defined CC and/or 
CXX])
-        CCACHE_DEPEND_MODE=1
-        ;;
-    *)
-        # for sharing code below, reuse CCACHE env var
-        AC_PATH_PROG([CCACHE],[sccache],[not found])
-        if test "$CCACHE" = "not found"; then
-            CCACHE=""
-        else
-            CCACHE=`win_short_path_for_make "$CCACHE"`
-            CCACHE_DEPEND_MODE=1
-        fi
-        ;;
-    esac
 elif test -n "$enable_ccache" -o \( "$enable_ccache" = "" -a 
"$enable_icecream" != "yes" \); then
     case "%$CC%$CXX%" in
     # If $CC and/or $CXX already contain "ccache" (possibly suffixed with some 
version number etc),
@@ -3058,10 +3044,59 @@ elif test -n "$enable_ccache" -o \( "$enable_ccache" = 
"" -a "$enable_icecream"
         CCACHE_DEPEND_MODE=1
         ;;
     *)
+        # try to use our own ccache if it is available and CCACHE was not 
already defined
+        if test -z "$CCACHE"; then
+            if test "$_os" = "WINNT"; then
+                ccache_ext=.exe # e.g. openssl build needs ccache.exe, not 
just ccache
+            fi
+            if test -n "$LODE_HOME" -a -x 
"$LODE_HOME/opt/bin/ccache$ccache_ext" ; then
+                CCACHE="$LODE_HOME/opt/bin/ccache$ccache_ext"
+            elif test -x "/opt/lo/bin/ccache$ccache_ext"; then
+                CCACHE="/opt/lo/bin/ccache$ccache_ext"
+            fi
+        fi
         AC_PATH_PROG([CCACHE],[ccache],[not found])
+        if test "$CCACHE" != "not found" -a "$_os" = "WINNT"; then
+            CCACHE=`win_short_path_for_make "$CCACHE"`
+        fi
+        if test "$CCACHE" != "not found" -a "$COM" = MSC; then
+            # check that it has MSVC support (it should recognize it in 
CCACHE_COMPILERTYPE)
+            rm -f conftest.txt
+            AC_MSG_CHECKING([whether $CCACHE has MSVC support])
+            CCACHE_COMPILERTYPE=cl CCACHE_LOGFILE=conftest.txt $CCACHE echo 
>/dev/null 2>/dev/null
+            if grep -q 'Config: (environment) compiler_type = cl' 
conftest.txt; then
+                AC_MSG_RESULT(yes)
+            else
+                AC_MSG_RESULT(no)
+                CCACHE="not found"
+            fi
+            rm -f conftest.txt
+        fi
+        if test "$CCACHE" = "not found" -a "$_os" = "WINNT"; then
+            # on windows/VC perhaps sccache is around?
+            case "%$CC%$CXX%" in
+            # If $CC and/or $CXX already contain "sccache" (possibly suffixed 
with some version number etc),
+            # assume that's good then
+            *%sccache[[-_' ']]*|*/sccache[[-_' ']]*)
+                AC_MSG_NOTICE([sccache seems to be included in a pre-defined 
CC and/or CXX])
+                CCACHE_DEPEND_MODE=1
+                SCCACHE=1
+                ;;
+            *)
+                # for sharing code below, reuse CCACHE env var
+                AC_PATH_PROG([CCACHE],[sccache],[not found])
+                if test "$CCACHE" != "not found"; then
+                    CCACHE=`win_short_path_for_make "$CCACHE"`
+                    SCCACHE=1
+                    CCACHE_DEPEND_MODE=1
+                fi
+                ;;
+            esac
+        fi
         if test "$CCACHE" = "not found"; then
             CCACHE=""
-        else
+        fi
+        if test -n "$CCACHE" -a -z "$SCCACHE"; then
             CCACHE_DEPEND_MODE=1
             # Need to check for ccache version: otherwise prevents
             # caching of the results (like "-x objective-c++" for Mac)
@@ -3089,8 +3124,8 @@ if test "$enable_ccache" = "nodepend"; then
 fi
 AC_SUBST(CCACHE_DEPEND_MODE)
 
-# skip on windows - sccache defaults are good enough
-if test "$CCACHE" != "" -a "$_os" != "WINNT"; then
+# sccache defaults are good enough
+if test "$CCACHE" != "" -a -z "$SCCACHE"; then
     # e.g. (/home/rene/.config/ccache/ccache.conf) max_size = 20.0G
     # -p works with both 4.2 and 4.4
     ccache_size_msg=$([ccache -p | $AWK /max_size/'{ print $4 }' | sed -e 
's/\.[0-9]*//'])
@@ -3119,6 +3154,17 @@ if test "$CCACHE" != "" -a "$_os" != "WINNT"; then
     fi
 fi
 
+ENABLE_Z7_DEBUG=
+if test "$enable_z7_debug" != no; then
+    if test "$enable_z7_debug" = yes -o -n "$CCACHE"; then
+        ENABLE_Z7_DEBUG=TRUE
+    fi
+else
+    AC_MSG_WARN([ccache will not work with --disable-z7-debug])
+    add_warning "ccache will not work with --disable-z7-debug"
+fi
+AC_SUBST(ENABLE_Z7_DEBUG)
+
 dnl ===================================================================
 dnl  Checks for C compiler,
 dnl  The check for the C++ compiler is later on.
@@ -4264,10 +4310,17 @@ if test "$CCACHE" != ""; then
     AC_LANG_PUSH([C])
     save_CFLAGS=$CFLAGS
     CFLAGS="$CFLAGS --ccache-skip -O2"
+    # msvc does not fail on unknown options, check stdout
+    if test "$COM" = MSC; then
+        CFLAGS="$CFLAGS -nologo"
+    fi
+    save_ac_c_werror_flag=$ac_c_werror_flag
+    ac_c_werror_flag=yes
     dnl an empty program will do, we're checking the compiler flags
     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
                       [use_ccache=yes], [use_ccache=no])
     CFLAGS=$save_CFLAGS
+    ac_c_werror_flag=$save_ac_c_werror_flag
     if test $use_ccache = yes -a "${CCACHE/*sccache*/}" != ""; then
         AC_MSG_RESULT([yes])
     else
@@ -6752,6 +6805,12 @@ if test "$CCACHE" != ""; then
     AC_LANG_PUSH([C++])
     save_CXXFLAGS=$CXXFLAGS
     CXXFLAGS="$CXXFLAGS --ccache-skip -O2"
+    # msvc does not fail on unknown options, check stdout
+    if test "$COM" = MSC; then
+        CXXFLAGS="$CXXFLAGS -nologo"
+    fi
+    save_ac_cxx_werror_flag=$ac_cxx_werror_flag
+    ac_cxx_werror_flag=yes
     dnl an empty program will do, we're checking the compiler flags
     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
                       [use_ccache=yes], [use_ccache=no])
@@ -6763,6 +6822,7 @@ if test "$CCACHE" != ""; then
         AC_MSG_RESULT([no])
     fi
     CXXFLAGS=$save_CXXFLAGS
+    ac_cxx_werror_flag=$save_ac_cxx_werror_flag
     AC_LANG_POP([C++])
 fi
 
@@ -12284,7 +12344,7 @@ if test "$CCACHE" != "" -a -n "$LO_CLANG_CC" -a -n 
"$LO_CLANG_CXX"; then
     save_CC="$CC"
     CC="$LO_CLANG_CC"
     save_CFLAGS=$CFLAGS
-    CFLAGS="$CFLAGS --ccache-skip -O2"
+    CFLAGS="$CFLAGS --ccache-skip -O2 -Werror"
     dnl an empty program will do, we're checking the compiler flags
     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
                       [use_ccache=yes], [use_ccache=no])
@@ -12303,7 +12363,7 @@ if test "$CCACHE" != "" -a -n "$LO_CLANG_CC" -a -n 
"$LO_CLANG_CXX"; then
     save_CXX="$CXX"
     CXX="$LO_CLANG_CXX"
     save_CXXFLAGS=$CXXFLAGS
-    CXXFLAGS="$CXXFLAGS --ccache-skip -O2"
+    CXXFLAGS="$CXXFLAGS --ccache-skip -O2 -Werror"
     dnl an empty program will do, we're checking the compiler flags
     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
                       [use_ccache=yes], [use_ccache=no])
diff --git a/external/curl/ExternalProject_curl.mk 
b/external/curl/ExternalProject_curl.mk
index d068f2dc36f2..d7bf396ca9fd 100644
--- a/external/curl/ExternalProject_curl.mk
+++ b/external/curl/ExternalProject_curl.mk
@@ -84,6 +84,7 @@ $(call gb_ExternalProject_get_state_target,curl,build):
                        VC=12 \
                        MACHINE=$(gb_MSBUILD_PLATFORM) \
                        GEN_PDB=$(if $(call 
gb_Module__symbols_enabled,curl),yes,no) \
+                       $(if $(call 
gb_Module__symbols_enabled,curl),CFLAGS_PDB_VALUE="$(gb_DEBUGINFO_FLAGS)") \
                        DEBUG=$(if $(MSVC_USE_DEBUG_RUNTIME),yes,no) \
                        ENABLE_IPV6=yes \
                        ENABLE_SSPI=yes \
diff --git a/external/curl/UnpackedTarball_curl.mk 
b/external/curl/UnpackedTarball_curl.mk
index f1244d0fd989..73dca5ed219c 100644
--- a/external/curl/UnpackedTarball_curl.mk
+++ b/external/curl/UnpackedTarball_curl.mk
@@ -26,6 +26,7 @@ $(eval $(call gb_UnpackedTarball_add_patches,curl,\
        external/curl/curl-7.26.0_win-proxy.patch \
        external/curl/zlib.patch.0 \
        external/curl/curl-debug.patch.1 \
+       external/curl/configurable-z-option.patch.0 \
 ))
 
 ifeq ($(SYSTEM_NSS),)
diff --git a/external/curl/configurable-z-option.patch.0 
b/external/curl/configurable-z-option.patch.0
new file mode 100644
index 000000000000..160577c76533
--- /dev/null
+++ b/external/curl/configurable-z-option.patch.0
@@ -0,0 +1,20 @@
+--- winbuild/MakefileBuild.vc.sav      2021-11-13 11:43:40.756226600 +0000
++++ winbuild/MakefileBuild.vc  2021-11-13 11:52:08.921692300 +0000
+@@ -45,7 +45,7 @@
+ 
+ !IF "$(VC)"=="6"
+ CC_NODEBUG  = $(CC) /O2 /DNDEBUG
+-CC_DEBUG    = $(CC) /Od /Gm /Zi /D_DEBUG /GZ
++CC_DEBUG    = $(CC) /Od /Gm $(DEBUG_FLAGS_VALUE) /D_DEBUG /GZ
+ CFLAGS      = /I. /I../lib /I../include /nologo /W4 /GX /DWIN32 /YX /FD /c 
/DBUILDING_LIBCURL
+ !ELSE
+ CC_NODEBUG  = $(CC) /O2 /DNDEBUG
+@@ -62,7 +62,7 @@
+ # Instead of id: just create an archive, that contains all objects
+ LNKLIB     = lib.exe
+ 
+-CFLAGS_PDB = /Zi
++CFLAGS_PDB = $(DEBUG_FLAGS_VALUE)
+ LFLAGS_PDB = /incremental:no /opt:ref,icf /DEBUG
+ 
+ CFLAGS_LIBCURL_STATIC  = /DCURL_STATICLIB
diff --git a/external/openssl/ExternalProject_openssl.mk 
b/external/openssl/ExternalProject_openssl.mk
index 4c5d630721c8..e44ccf5f3436 100644
--- a/external/openssl/ExternalProject_openssl.mk
+++ b/external/openssl/ExternalProject_openssl.mk
@@ -66,6 +66,7 @@ $(call gb_ExternalProject_get_state_target,openssl,build):
                CONFIGURE_INSIST=1 $(PERL) Configure $(OPENSSL_PLATFORM) 
no-tests no-multilib \
                && export PERL="$(shell cygpath -w $(PERL))" \
                && nmake -f makefile \
+                       $(if $(call 
gb_Module__symbols_enabled,openssl),DEBUG_FLAGS_VALUE="$(gb_DEBUGINFO_FLAGS)") \
        )
        $(call gb_Trace_EndRange,openssl,EXTERNAL)
 
diff --git a/external/openssl/UnpackedTarball_openssl.mk 
b/external/openssl/UnpackedTarball_openssl.mk
index 6f00cf7f7e44..c52b427a866e 100644
--- a/external/openssl/UnpackedTarball_openssl.mk
+++ b/external/openssl/UnpackedTarball_openssl.mk
@@ -13,6 +13,7 @@ $(eval $(call 
gb_UnpackedTarball_set_tarball,openssl,$(OPENSSL_TARBALL),,openssl
 
 $(eval $(call gb_UnpackedTarball_add_patches,openssl,\
        external/openssl/openssl-no-multilib.patch.0 \
+       external/openssl/configurable-z-option.patch.0 \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/external/openssl/configurable-z-option.patch.0 
b/external/openssl/configurable-z-option.patch.0
new file mode 100644
index 000000000000..3dcf49dc81a6
--- /dev/null
+++ b/external/openssl/configurable-z-option.patch.0
@@ -0,0 +1,34 @@
+--- Configurations/10-main.conf.sav    2021-08-24 13:38:47.000000000 +0000
++++ Configurations/10-main.conf        2021-11-02 22:20:44.377653700 +0000
+@@ -13,7 +13,7 @@
+         } elsif ($disabled{asm}) {
+             # assembler is still used to compile uplink shim
+             $vc_win64a_info = { AS        => "ml64",
+-                                ASFLAGS   => "/nologo /Zi",
++                                ASFLAGS   => "/nologo $$(DEBUG_FLAGS_VALUE)",
+                                 asflags   => "/c /Cp /Cx",
+                                 asoutflag => "/Fo" };
+         } else {
+@@ -41,7 +41,7 @@
+         } elsif ($disabled{asm}) {
+             # not actually used, uplink shim is inlined into C code
+             $vc_win32_info = { AS        => "ml",
+-                               ASFLAGS   => "/nologo /Zi",
++                               ASFLAGS   => "/nologo $$(DEBUG_FLAGS_VALUE)",
+                                asflags   => "/Cp /coff /c /Cx",
+                                asoutflag => "/Fo",
+                                perlasm_scheme => "win32" };
+@@ -1231,10 +1231,10 @@
+                                 "UNICODE", "_UNICODE",
+                                 "_CRT_SECURE_NO_DEPRECATE",
+                                 "_WINSOCK_DEPRECATED_NO_WARNINGS"),
+-        lib_cflags       => add("/Zi /Fdossl_static.pdb"),
++        lib_cflags       => add("\$(DEBUG_FLAGS_VALUE)"),
+         lib_defines      => add("L_ENDIAN"),
+-        dso_cflags       => "/Zi /Fddso.pdb",
+-        bin_cflags       => "/Zi /Fdapp.pdb",
++        dso_cflags       => "\$(DEBUG_FLAGS_VALUE)",
++        bin_cflags       => "\$(DEBUG_FLAGS_VALUE)",
+         shared_ldflag    => "/dll",
+         shared_target    => "win-shared", # meaningless except it gives 
Configure a hint
+         thread_scheme    => "winthreads",
diff --git a/solenv/gbuild/PrecompiledHeaders.mk 
b/solenv/gbuild/PrecompiledHeaders.mk
index 9a8763657d2d..3b81cc77f365 100644
--- a/solenv/gbuild/PrecompiledHeaders.mk
+++ b/solenv/gbuild/PrecompiledHeaders.mk
@@ -67,7 +67,7 @@ $(call gb_PrecompiledHeader_get_target,$(1),$(3)) :
                 || ( echo "Error, PCH $(1) built by 
$$(PCH_LINKTARGETMAKEFILENAME) instead of $(3)" >&2; exit 1)
        rm -f $$@
        $$(call 
gb_PrecompiledHeader__command,$$@,$(1),$$<,$(gb_PrecompiledHeader_cxxflags_includes),$$(INCLUDE),$(3),$(5))
-       $$(call 
gb_PrecompiledHeader__sum_command,$$@,$(1),$$<,$(gb_PrecompiledHeader_cxxflags_includes),$$(INCLUDE),$(3))
+       $$(call 
gb_PrecompiledHeader__sum_command,$$@,$(1),$$<,$(gb_PrecompiledHeader_cxxflags_includes),$$(INCLUDE),$(3),$(5))
 ifeq ($(gb_FULLDEPS),$(true))
        $$(call gb_Helper_abbreviate_dirs,\
                RESPONSEFILE=$$(call gb_var2file,$$(shell 
$$(gb_MKTEMP)),200,$$(call gb_PrecompiledHeader_get_dep_target_tmp,$(1),$(3))) 
&& \
diff --git a/solenv/gbuild/gbuild.mk b/solenv/gbuild/gbuild.mk
index 08c82f5e8d1f..6d074400748d 100644
--- a/solenv/gbuild/gbuild.mk
+++ b/solenv/gbuild/gbuild.mk
@@ -377,4 +377,22 @@ endif
 
 endef
 
+# Setup for ccache.
+ifneq ($(gb_ENABLE_PCH),)
+# CCACHE_SLOPPINESS should contain pch_defines,time_macros for PCHs.
+gb_CCACHE_SLOPPINESS :=
+ifeq ($(shell test -z "$$CCACHE_SLOPPINESS" && echo 1),1)
+gb_CCACHE_SLOPPINESS := CCACHE_SLOPPINESS=pch_defines,time_macros
+else
+ifeq ($(shell echo "$$CCACHE_SLOPPINESS" | grep -q pch_defines | grep -q 
time_macros && echo 1),1)
+gb_CCACHE_SLOPPINESS := 
CCACHE_SLOPPINESS=$CCACHE_SLOPPINESS:pch_defines,time_macros
+endif
+endif
+gb_COMPILER_SETUP += $(gb_CCACHE_SLOPPINESS)
+endif
+
+ifneq ($(CCACHE_DEPEND_MODE),)
+gb_COMPILER_SETUP += CCACHE_DEPEND=1
+endif
+
 # vim: set noet sw=4:
diff --git a/solenv/gbuild/platform/com_GCC_class.mk 
b/solenv/gbuild/platform/com_GCC_class.mk
index ba12572f4341..74f744658e15 100644
--- a/solenv/gbuild/platform/com_GCC_class.mk
+++ b/solenv/gbuild/platform/com_GCC_class.mk
@@ -157,17 +157,17 @@ endef
 
 ifeq ($(COM_IS_CLANG),TRUE)
 # Clang has -fno-pch-timestamp, just checksum the file for CCACHE_PCH_EXTSUM
-# $(call 
gb_PrecompiledHeader__sum_command,pchfile,pchtarget,source,cxxflags,includes,linktargetmakefilename)
+# $(call 
gb_PrecompiledHeader__sum_command,pchfile,pchtarget,source,cxxflags,includes,linktargetmakefilename,compiler)
 define gb_PrecompiledHeader__sum_command
        $(SHA256SUM) $(1) >$(1).sum
 endef
 else
 # GCC does not generate the same .gch for the same input, so checksum the 
(preprocessed) input
-# $(call 
gb_PrecompiledHeader__sum_command,pchfile,pchtarget,source,cxxflags,includes,linktargetmakefilename)
+# $(call 
gb_PrecompiledHeader__sum_command,pchfile,pchtarget,source,cxxflags,includes,linktargetmakefilename,compiler)
 define gb_PrecompiledHeader__sum_command
 $(call gb_Helper_abbreviate_dirs,\
        CCACHE_DISABLE=1 $(gb_COMPILER_SETUP) \
-       $(gb_CXX) \
+       $(if $(7),$(7),$(gb_CXX)) \
                -x c++-header \
                $(4) \
                $(if $(WARNINGS_DISABLED),$(gb_CXXFLAGS_DISABLE_WARNINGS)) \
diff --git a/solenv/gbuild/platform/com_GCC_defs.mk 
b/solenv/gbuild/platform/com_GCC_defs.mk
index c8f81ff15dc7..589c9eedc823 100644
--- a/solenv/gbuild/platform/com_GCC_defs.mk
+++ b/solenv/gbuild/platform/com_GCC_defs.mk
@@ -326,20 +326,6 @@ gb_Helper_get_rcfile = $(1)rc
 ifneq ($(gb_ENABLE_PCH),)
 # Enable use of .sum files for PCHs.
 gb_COMPILER_SETUP += CCACHE_PCH_EXTSUM=1
-# CCACHE_SLOPPINESS should contain pch_defines,time_macros for PCHs.
-gb_CCACHE_SLOPPINESS :=
-ifeq ($(shell test -z "$$CCACHE_SLOPPINESS" && echo 1),1)
-gb_CCACHE_SLOPPINESS := CCACHE_SLOPPINESS=pch_defines,time_macros
-else
-ifeq ($(shell echo "$$CCACHE_SLOPPINESS" | grep -q pch_defines | grep -q 
time_macros && echo 1),1)
-gb_CCACHE_SLOPPINESS := 
CCACHE_SLOPPINESS=$CCACHE_SLOPPINESS:pch_defines,time_macros
-endif
-endif
-gb_COMPILER_SETUP += $(gb_CCACHE_SLOPPINESS)
-endif
-
-ifneq ($(CCACHE_DEPEND_MODE),)
-gb_COMPILER_SETUP += CCACHE_DEPEND=1
 endif
 
 # vim: set noet sw=4:
diff --git a/solenv/gbuild/platform/com_MSC_class.mk 
b/solenv/gbuild/platform/com_MSC_class.mk
index da5b682d6b8c..16eb6c2ee4d3 100644
--- a/solenv/gbuild/platform/com_MSC_class.mk
+++ b/solenv/gbuild/platform/com_MSC_class.mk
@@ -65,6 +65,7 @@ define gb_CObject__command_pattern
 $(call gb_Helper_abbreviate_dirs,\
        mkdir -p $(dir $(1)) $(dir $(4)) && \
        unset INCLUDE && \
+       $(gb_COMPILER_SETUP) \
        $(call gb_CObject__compiler,$(2),$(3),$(6)) \
                $(call gb_Helper_remove_overridden_flags, \
                        $(DEFS) \
@@ -107,6 +108,7 @@ $(call gb_Output_announce,$(2),$(true),PCH,1)
 $(call gb_Helper_abbreviate_dirs,\
        mkdir -p $(dir $(1)) $(dir $(call 
gb_PrecompiledHeader_get_dep_target,$(2),$(6))) && \
        unset INCLUDE && \
+       CCACHE_DISABLE=1 $(gb_COMPILER_SETUP) \
        $(call gb_CObject__compiler,$(4),$(3),$(7)) \
                $(call gb_Helper_remove_overridden_flags, \
                        $(4) $(if 
$(WARNINGS_DISABLED),$(gb_CXXFLAGS_DISABLE_WARNINGS))) \
@@ -120,9 +122,21 @@ $(call gb_Helper_abbreviate_dirs,\
        $(call gb_Trace_EndRange,$(2),PCH)
 endef
 
-# No ccache with MSVC, no need to create a checksum for it.
-# $(call 
gb_PrecompiledHeader__sum_command,pchfile,pchtarget,source,cxxflags,includes,linktargetmakefilename)
+# MSVC does not generate the same .pch for the same input, so checksum the 
(preprocessed) input
+# $(call 
gb_PrecompiledHeader__sum_command,pchfile,pchtarget,source,cxxflags,includes,linktargetmakefilename,compiler)
 define gb_PrecompiledHeader__sum_command
+$(call gb_Helper_abbreviate_dirs,\
+       unset INCLUDE && \
+       CCACHE_DISABLE=1 $(gb_COMPILER_SETUP) \
+       $(call gb_CObject__compiler,$(4),$(3),$(7)) \
+               $(call gb_Helper_remove_overridden_flags, \
+                       $(4)$(if 
$(WARNINGS_DISABLED),$(gb_CXXFLAGS_DISABLE_WARNINGS))) \
+               $(if $(EXTERNAL_CODE),$(if 
$(COM_IS_CLANG),-Wno-undef),$(gb_DEFS_INTERNAL)) \
+               $(gb_LTOFLAGS) \
+               $(5) \
+               -E $(3) \
+               2>&1 | $(SHA256SUM) >$(1).sum \
+               )
 endef
 
 # When building a PCH, MSVC also creates a .pdb file with debug info. So for 
reuse
diff --git a/solenv/gbuild/platform/com_MSC_defs.mk 
b/solenv/gbuild/platform/com_MSC_defs.mk
index 39c284a6a16b..7760cefcab8a 100644
--- a/solenv/gbuild/platform/com_MSC_defs.mk
+++ b/solenv/gbuild/platform/com_MSC_defs.mk
@@ -214,10 +214,18 @@ gb_LinkTarget_LDFLAGS += \
        /ignore:4217 /ignore:4049
 
 
+ifeq ($(ENABLE_Z7_DEBUG),)
 gb_DEBUGINFO_FLAGS := \
        -FS \
        -Zi \
 
+else
+# ccache does not work with -Zi
+gb_DEBUGINFO_FLAGS := \
+       -Z7 \
+
+endif
+
 # See gb_Windows_PE_TARGETTYPEFLAGS_DEBUGINFO
 gb_LINKER_DEBUGINFO_FLAGS :=
 
@@ -322,4 +330,9 @@ gb_WIN_GPG_cross_setup_exports = export 
REAL_BUILD_CC="$(filter-out -%,$(CC_FOR_
     && export CC_FOR_BUILD="$(call 
gb_Executable_get_target_for_build,gcc-wrapper) 
--wrapper-env-prefix=REAL_BUILD_ $(SOLARINC) -L$(subst ;, 
-L,$(ILIB_FOR_BUILD))" \
     && export RC='windres -O COFF --target=$(gb_WIN_GPG_WINDRES_target) 
--preprocessor=$(call gb_Executable_get_target_for_build,cpp) 
--preprocessor-arg=-+ -DRC_INVOKED -DWINAPI_FAMILY=0 $(SOLARINC)'
 
+ifneq ($(gb_ENABLE_PCH),)
+# Enable use of .sum files for PCHs.
+gb_COMPILER_SETUP += CCACHE_PCH_EXTSUM=1
+endif
+
 # vim: set noet sw=4:
diff --git a/solenv/gcc-wrappers/wrapper.cxx b/solenv/gcc-wrappers/wrapper.cxx
index 3504d3d8c5ab..fbf3f5378ae5 100644
--- a/solenv/gcc-wrappers/wrapper.cxx
+++ b/solenv/gcc-wrappers/wrapper.cxx
@@ -82,7 +82,7 @@ void setupccenv() {
     }
 }
 
-std::string processccargs(std::vector<std::string> rawargs, std::string 
&env_prefix, bool &verbose)
+std::string processccargs(const std::vector<std::string>& rawargs, std::string 
&env_prefix, bool &verbose)
 {
     // default env var prefix
     env_prefix = "REAL_";
@@ -101,16 +101,16 @@ std::string processccargs(std::vector<std::string> 
rawargs, std::string &env_pre
     args.append(" -Gy");
     args.append(" -Ob1 -Oxs -Oy-");
 
-    // apparently these must be at the end
-    // otherwise configure tests may fail
-    // note: always use -debug so a PDB file is created
-    std::string linkargs(" -link -debug");
+    std::string linkargs;
+    bool block_linkargs = false;
 
     // instead of using synced PDB access (-FS), use individual PDB files 
based on output
     const char *const pEnvIndividualPDBs(getenv("MSVC_USE_INDIVIDUAL_PDBS"));
     const bool bIndividualPDBs = (pEnvIndividualPDBs && 
!strcmp(pEnvIndividualPDBs, "TRUE"));
+    const char *const pEnvEnableZ7Debug(getenv("ENABLE_Z7_DEBUG"));
+    const bool bEnableZ7Debug = (pEnvEnableZ7Debug && 
!strcmp(pEnvEnableZ7Debug, "TRUE"));
 
-    for(std::vector<std::string>::iterator i = rawargs.begin(); i != 
rawargs.end(); ++i) {
+    for(std::vector<std::string>::const_iterator i = rawargs.begin(); i != 
rawargs.end(); ++i) {
         if (env_prefix_next_arg)
         {
             env_prefix = *i;
@@ -150,7 +150,7 @@ std::string processccargs(std::vector<std::string> rawargs, 
std::string &env_pre
                 exit(1);
             }
 
-            if (bIndividualPDBs)
+            if (bIndividualPDBs && !bEnableZ7Debug)
             {
                 if (dot == std::string::npos)
                     args.append(" -Fd" + *i + ".pdb");
@@ -159,17 +159,26 @@ std::string processccargs(std::vector<std::string> 
rawargs, std::string &env_pre
             }
         }
         else if(*i == "-g" || !(*i).compare(0,5,"-ggdb")) {
-            args.append("-Zi");
-            if (!bIndividualPDBs)
-                args.append(" -FS");
+            if(!bEnableZ7Debug)
+            {
+                args.append("-Zi");
+                if (!bIndividualPDBs)
+                    args.append(" -FS");
+            }
+            else
+            {
+                // ccache doesn't work with -Zi, the -link -debug for linking 
will create a final PDB
+                args.append("-Z7");
+            }
         }
         else if(!(*i).compare(0,2,"-D")) {
             // need to re-escape strings for preprocessor
-            for(size_t pos=(*i).find("\""); pos!=std::string::npos; 
pos=(*i).find("\"",pos)) {
-                (*i).replace(pos,0,"\\");
+            std::string str = *i;
+            for(size_t pos=str.find("\""); pos!=std::string::npos; 
pos=str.find("\"",pos)) {
+                str.replace(pos,0,"\\");
                 pos+=2;
             }
-            args.append(*i);
+            args.append(str);
         }
         else if(!(*i).compare(0,2,"-L")) {
             linkargs.append(" -LIBPATH:"+(*i).substr(2));
@@ -188,6 +197,12 @@ std::string processccargs(std::vector<std::string> 
rawargs, std::string &env_pre
         else if(!(*i).compare(0,4,"-Wl,")) {
             //TODO: drop other gcc-specific options
         }
+        else if(*i == "-c") {
+            args.append("-c");
+            // If -c is specified, there will be no linking anyway,
+            // and passing -link with -c stops ccache from caching.
+            block_linkargs = true;
+        }
         else if(*i == "-Werror")
             args.append("-WX");
         else if (*i == "--wrapper-print-cmdline")
@@ -219,7 +234,14 @@ std::string processccargs(std::vector<std::string> 
rawargs, std::string &env_pre
         exit(1);
     }
 
-    args.append(linkargs);
+    if(!block_linkargs) {
+        // apparently these must be at the end
+        // otherwise configure tests may fail
+        // note: always use -debug so a PDB file is created
+        args.append(" -link -debug ");
+        args.append(linkargs);
+    }
+
     return args;
 }
 
diff --git a/solenv/gcc-wrappers/wrapper.hxx b/solenv/gcc-wrappers/wrapper.hxx
index e4a4bb3bbeb5..d68ab90c9504 100644
--- a/solenv/gcc-wrappers/wrapper.hxx
+++ b/solenv/gcc-wrappers/wrapper.hxx
@@ -18,7 +18,8 @@ std::string getexe(std::string exename, bool maybeempty = 
false);
 
 void setupccenv();
 
-std::string processccargs(std::vector<std::string> rawargs, std::string& 
env_prefix, bool& verbose);
+std::string processccargs(const std::vector<std::string>& rawargs, 
std::string& env_prefix,
+                          bool& verbose);
 
 int startprocess(std::string command, std::string args, bool verbose);
 

Reply via email to