Blame SOURCES/0001-make-with-idlc-cpp-cpp-work-for-gcc-cpp-as-a-ucpp-re.patch

17f16b
From 748a9fd3a8e90e52a126190dbe0d97da6e0941ff Mon Sep 17 00:00:00 2001
17f16b
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
17f16b
Date: Wed, 11 Aug 2021 20:55:14 +0100
17f16b
Subject: [PATCH] make --with-idlc-cpp=cpp work for gcc cpp as a ucpp
17f16b
 replacement
17f16b
17f16b
e.g. the example of
17f16b
https://bugs.launchpad.net/ubuntu/+source/libreoffice/+bug/1524638
17f16b
has the same output .urd using cpp with these flags as ucpp created
17f16b
17f16b
Change-Id: Iadfd2deba7d365c66c3260fd6736c031987e107c
17f16b
---
17f16b
 config_host.mk.in           |  1 +
17f16b
 configure.ac                | 14 ++++++++++++++
17f16b
 idlc/Executable_idlc.mk     |  8 ++++++++
17f16b
 idlc/source/idlccompile.cxx |  8 ++++++++
17f16b
 4 files changed, 31 insertions(+)
17f16b
17f16b
diff --git a/config_host.mk.in b/config_host.mk.in
17f16b
index 58ca1d1c14fb..6810660067b0 100644
17f16b
--- a/config_host.mk.in
17f16b
+++ b/config_host.mk.in
17f16b
@@ -635,6 +635,7 @@ export SYSTEM_RHINO=@SYSTEM_RHINO@
17f16b
 export SYSTEM_SERF=@SYSTEM_SERF@
17f16b
 export SYSTEM_STAROFFICE=@SYSTEM_STAROFFICE@
17f16b
 export SYSTEM_UCPP=@SYSTEM_UCPP@
17f16b
+export SYSTEM_UCPP_IS_GCC=@SYSTEM_UCPP_IS_GCC@
17f16b
 export SYSTEM_VISIO=@SYSTEM_VISIO@
17f16b
 export SYSTEM_WPD=@SYSTEM_WPD@
17f16b
 export SYSTEM_WPG=@SYSTEM_WPG@
17f16b
diff --git a/configure.ac b/configure.ac
17f16b
index 3d2bf7e24555..ac226fd46ace 100644
17f16b
--- a/configure.ac
17f16b
+++ b/configure.ac
17f16b
@@ -8807,9 +8807,22 @@ dnl ===================================================================
17f16b
 dnl Check for C preprocessor to use
17f16b
 dnl ===================================================================
17f16b
 AC_MSG_CHECKING([which C preprocessor to use in idlc])
17f16b
+SYSTEM_UCPP_IS_GCC=
17f16b
 if test -n "$with_idlc_cpp"; then
17f16b
     AC_MSG_RESULT([$with_idlc_cpp])
17f16b
     AC_PATH_PROG(SYSTEM_UCPP, $with_idlc_cpp)
17f16b
+    AC_MSG_CHECKING([if $with_idlc_cpp is GCC CPP])
17f16b
+    # ucpp will accept -v (to output version), warn about the others as unknown
17f16b
+    # and return 1 (due to -v)
17f16b
+    # gcc will accept -v (as verbose), --version (to output version) and -nostdinc
17f16b
+    # and return 0 (due to --version ) if all options are supported
17f16b
+    $SYSTEM_UCPP -v --version -nostdinc >/dev/null 2>/dev/null
17f16b
+    if test $? -eq 0;  then
17f16b
+        SYSTEM_UCPP_IS_GCC=TRUE
17f16b
+        AC_MSG_RESULT([yes])
17f16b
+    else
17f16b
+        AC_MSG_RESULT([no])
17f16b
+    fi
17f16b
 else
17f16b
     AC_MSG_RESULT([ucpp])
17f16b
     AC_MSG_CHECKING([which ucpp tp use])
17f16b
@@ -8822,6 +8835,7 @@ else
17f16b
     fi
17f16b
 fi
17f16b
 AC_SUBST(SYSTEM_UCPP)
17f16b
+AC_SUBST(SYSTEM_UCPP_IS_GCC)
17f16b
 
17f16b
 dnl ===================================================================
17f16b
 dnl Check for epm (not needed for Windows)
17f16b
diff --git a/idlc/Executable_idlc.mk b/idlc/Executable_idlc.mk
17f16b
index e194e9049c77..f2f79dcb8911 100644
17f16b
--- a/idlc/Executable_idlc.mk
17f16b
+++ b/idlc/Executable_idlc.mk
17f16b
@@ -35,10 +35,18 @@ $(eval $(call gb_Executable_add_scanners,idlc,\
17f16b
 ))
17f16b
 
17f16b
 ifneq (,$(SYSTEM_UCPP))
17f16b
+
17f16b
 $(eval $(call gb_Executable_add_defs,idlc,\
17f16b
     -DSYSTEM_UCPP \
17f16b
     -DUCPP=\"file://$(SYSTEM_UCPP)\" \
17f16b
 ))
17f16b
+
17f16b
+ifneq ($(SYSTEM_UCPP_IS_GCC),)
17f16b
+$(eval $(call gb_Executable_add_defs,idlc,\
17f16b
+    -DSYSTEM_UCPP_IS_GCC \
17f16b
+))
17f16b
+endif
17f16b
+
17f16b
 endif
17f16b
 
17f16b
 $(eval $(call gb_Executable_add_exception_objects,idlc,\
17f16b
diff --git a/idlc/source/idlccompile.cxx b/idlc/source/idlccompile.cxx
17f16b
index bf3325d6821a..1902d63e0cad 100644
17f16b
--- a/idlc/source/idlccompile.cxx
17f16b
+++ b/idlc/source/idlccompile.cxx
17f16b
@@ -237,7 +237,15 @@ sal_Int32 compileFile(const OString * pathname)
17f16b
     ::std::vector< OUString> lCppArgs;
17f16b
     lCppArgs.emplace_back("-DIDL");
17f16b
     lCppArgs.emplace_back("-C");
17f16b
+#ifdef SYSTEM_UCPP_IS_GCC
17f16b
+    // -nostdinc Do not search the standard system directories for header files
17f16b
+    lCppArgs.emplace_back("-nostdinc");
17f16b
+    // with gcc cpp, even when not explicitly including anything, /usr/include/stdc-predef.h
17f16b
+    // gets inserted without -nostdinc
17f16b
+#else
17f16b
+    // -zI Do not use the standard (compile-time) include path.
17f16b
     lCppArgs.emplace_back("-zI");
17f16b
+#endif
17f16b
 
17f16b
     Options* pOptions = idlc()->getOptions();
17f16b
 
17f16b
-- 
17f16b
2.31.1
17f16b