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

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