Remove CXXFLAGS_CXX11 from Clang plugin compilation

CXXFLAGS_CXX11 is for the compiler used to compile LO proper.  The plugin needs
to be compiled in a way compatible with compiling Clang, and the compiler and
any relevant flags can be controlled with COMPILER_PLUGINS_CXX.  (And at least
on macOS when compiling LO against a locally-built recent Clang trunk,
CXXFLAGS_CXX11 will now contain -std=gnu++17, but COMPILER_PLUGINS_CXX can still
point at Apple's Xcode clang++, which does not understand -std=gnu++17.)

Also, if COMPILER_PLUGINS_CXX is not set, simply default it to g++ instead of
trying to construct an acceptable CLANGCXX value from CXX (which would be
Clang).  (The problem with using Clang without CXXFLAGS_CXX11 is that Clang,
unlike GCC, typically defaults to C++03, but building compilerplugins requires
C++11 at least.  That would cause e.g. the Gerrit/Jenkins linux_clang_dbgutil_64
builds to fail---but which also needs COMPILER_PLUGINS_CXX to be explicitly set
to "g++ -std=c++11" as GCC on those machines is still 4.8.5 defaulting to
C++03.)

Change-Id: Id4ee4e54fa871cb6e621069cd050ae5b31922b34
Reviewed-on: https://gerrit.libreoffice.org/45856
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
diff --git a/compilerplugins/Makefile-clang.mk b/compilerplugins/Makefile-clang.mk
index 89a798e..aad53a9 100644
--- a/compilerplugins/Makefile-clang.mk
+++ b/compilerplugins/Makefile-clang.mk
@@ -18,12 +18,6 @@ CLANG_DL_EXT = .so
CLANG_EXE_EXT =
endif

ifeq ($(COMPILER_PLUGINS_CXX),)
CLANGCXX=$(filter-out -m32 -m64 -fsanitize%,$(CXX))
else
CLANGCXX=$(COMPILER_PLUGINS_CXX)
endif

# Compile flags ('make CLANGCXXFLAGS=-g' if you need to debug the plugin); you
# may occasionally want to override these:
ifeq ($(OS),WNT)
@@ -113,8 +107,8 @@ ifeq ($(OS),WNT)
define clangbuildsrc
$(3): $(2) $(SRCDIR)/compilerplugins/Makefile-clang.mk $(CLANGOUTDIR)/clang-timestamp
	@echo [build CXX] $(subst $(SRCDIR)/,,$(2))
	$(QUIET)$(CLANGCXX) $(CLANGCXXFLAGS) $(CLANGWERROR) $(CLANGDEFS) \
        $(CLANGINCLUDES) /I$(BUILDDIR)/config_host $(2) $(CXXFLAGS_CXX11) /MD \
	$(QUIET)$(COMPILER_PLUGINS_CXX) $(CLANGCXXFLAGS) $(CLANGWERROR) $(CLANGDEFS) \
        $(CLANGINCLUDES) /I$(BUILDDIR)/config_host $(2) /MD \
        /c /Fo: $(3)

-include $(CLANGOUTDIR)/$(1).d #TODO
@@ -128,7 +122,7 @@ else
define clangbuildsrc
$(3): $(2) $(SRCDIR)/compilerplugins/Makefile-clang.mk $(CLANGOUTDIR)/clang-timestamp
	@echo [build CXX] $(subst $(SRCDIR)/,,$(2))
	$(QUIET)$(CLANGCXX) $(CLANGCXXFLAGS) $(CLANGWERROR) $(CLANGDEFS) $(CLANGINCLUDES) -I$(BUILDDIR)/config_host $(2) -fPIC $(CXXFLAGS_CXX11) -c -o $(3) -MMD -MT $(3) -MP -MF $(CLANGOUTDIR)/$(1).d
	$(QUIET)$(COMPILER_PLUGINS_CXX) $(CLANGCXXFLAGS) $(CLANGWERROR) $(CLANGDEFS) $(CLANGINCLUDES) -I$(BUILDDIR)/config_host $(2) -fPIC -c -o $(3) -MMD -MT $(3) -MP -MF $(CLANGOUTDIR)/$(1).d

-include $(CLANGOUTDIR)/$(1).d

@@ -143,10 +137,10 @@ $(foreach src, $(CLANGSRC), $(eval $(call clangbuildsrc,$(src),$(CLANGINDIR)/$(s
$(CLANGOUTDIR)/plugin$(CLANG_DL_EXT): $(CLANGOBJS)
	@echo [build LNK] $(subst $(BUILDDIR)/,,$@)
ifeq ($(OS),WNT)
	$(QUIET)$(CLANGCXX) /LD $(CLANGOBJS) /Fe: $@ $(CLANGLIBDIR)/clang.lib \
	$(QUIET)$(COMPILER_PLUGINS_CXX) /LD $(CLANGOBJS) /Fe: $@ $(CLANGLIBDIR)/clang.lib \
        mincore.lib version.lib /link $(COMPILER_PLUGINS_CXX_LINKFLAGS)
else
	$(QUIET)$(CLANGCXX) -shared $(CLANGOBJS) -o $@ \
	$(QUIET)$(COMPILER_PLUGINS_CXX) -shared $(CLANGOBJS) -o $@ \
		$(if $(filter MACOSX,$(OS)),-Wl$(CLANG_COMMA)-flat_namespace \
			-Wl$(CLANG_COMMA)-undefined -Wl$(CLANG_COMMA)suppress)
endif
diff --git a/configure.ac b/configure.ac
index 874a21e..208debc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6431,10 +6431,10 @@ if test "$COM_IS_CLANG" = "TRUE"; then
        AC_LANG_PUSH([C++])
        save_CPPFLAGS=$CPPFLAGS
        save_CXX=$CXX
        # compiler plugins must be built with "native" bitness of clang
        # because they link against clang libraries
        CXX=${COMPILER_PLUGINS_CXX-$(echo $CXX | sed -e s/-m64// -e s/-m32//)}
        CPPFLAGS="$CPPFLAGS $CXXFLAGS_CXX11 -I$CLANGDIR/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
        # compiler plugins must be built with "native" compiler that was used to build Clang itself:
        : "${COMPILER_PLUGINS_CXX=g++}"
        CXX=$COMPILER_PLUGINS_CXX
        CPPFLAGS="$CPPFLAGS -I$CLANGDIR/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
        AC_CHECK_HEADER(clang/AST/RecursiveASTVisitor.h,
            [COMPILER_PLUGINS=TRUE],
            [
diff --git a/distro-configs/Jenkins/linux_clang_dbgutil_64 b/distro-configs/Jenkins/linux_clang_dbgutil_64
index 61c274a..9865be0 100644
--- a/distro-configs/Jenkins/linux_clang_dbgutil_64
+++ b/distro-configs/Jenkins/linux_clang_dbgutil_64
@@ -1,2 +1,3 @@
--enable-dbgutil
--enable-compiler-plugins
COMPILER_PLUGINS_CXX=g++ -std=c++11