From 48ac97a8b3f1c45aec5c4da6697271271a40447b Mon Sep 17 00:00:00 2001
From: Sergei Reznikov <diver@gelios.net>
Date: Sat, 15 Feb 2020 14:52:59 +0300
Subject: Make Elementary the default on Haiku


diff --git a/vcl/source/app/IconThemeSelector.cxx b/vcl/source/app/IconThemeSelector.cxx
index 225414f..a971e11 100644
--- a/vcl/source/app/IconThemeSelector.cxx
+++ b/vcl/source/app/IconThemeSelector.cxx
@@ -58,6 +58,9 @@ IconThemeSelector::GetIconThemeForDesktopEnvironment(const OUString& desktopEnvi
 #ifdef _WIN32
     (void)desktopEnvironment;
     return "colibre";
+#elif defined(__HAIKU__)
+    (void)desktopEnvironment;
+    return "elementary";
 #else
     OUString r;
     if ( desktopEnvironment.equalsIgnoreAsciiCase("plasma5") ||
-- 
2.30.2


From fd45d44ed4bf5ae2e2bf5133d717d06bdb02e80f Mon Sep 17 00:00:00 2001
From: Sergei Reznikov <diver@gelios.net>
Date: Wed, 24 Oct 2018 17:01:09 +0300
Subject: Show used vcl backend on Haiku


diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index c4c3be9..119380d 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -1155,7 +1155,7 @@ OUString Application::GetHWOSConfInfo()
         aDetails.append( VclResId(SV_APP_DEFAULT) );
     aDetails.append( "; " );
 
-#if (defined LINUX || defined _WIN32 || defined MACOSX)
+#if (defined LINUX || defined _WIN32 || defined MACOSX || defined (__HAIKU__))
     aDetails.append( SV_APP_VCLBACKEND );
     aDetails.append( GetToolkitName() );
     aDetails.append( "; " );
-- 
2.30.2


From 4cb5c782004fad268369ae122a2bf768fef8afa4 Mon Sep 17 00:00:00 2001
From: Sergei Reznikov <diver@gelios.net>
Date: Wed, 24 Oct 2018 17:01:34 +0300
Subject: Identify Haiku in about window


diff --git a/vcl/unx/generic/app/geninst.cxx b/vcl/unx/generic/app/geninst.cxx
index b661163..329265a 100644
--- a/vcl/unx/generic/app/geninst.cxx
+++ b/vcl/unx/generic/app/geninst.cxx
@@ -70,6 +70,8 @@ OUString SalGenericInstance::getOSVersion()
         }
         fclose( pVersion );
     }
+#elif defined(__HAIKU__)
+	aKernelVer = "Haiku";
 #endif
     return aKernelVer;
 }
-- 
2.30.2


From f7bb3b40c0db4cb585ff3194d56851cc198a85a1 Mon Sep 17 00:00:00 2001
From: Sergei Reznikov <diver@gelios.net>
Date: Wed, 24 Oct 2018 17:02:04 +0300
Subject: Workaround a crash on quit. See Haiku #13159


diff --git a/desktop/source/app/main.c b/desktop/source/app/main.c
index 643c42a..d4b47cb 100644
--- a/desktop/source/app/main.c
+++ b/desktop/source/app/main.c
@@ -17,6 +17,12 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#ifdef __HAIKU__
+#include <unistd.h>
+#include <sys/types.h>
+#include <signal.h>
+#endif
+
 #include <sal/main.h>
 
 #include "sofficemain.h"
@@ -50,6 +56,9 @@ SAL_IMPLEMENT_MAIN() {
 #ifdef __gnu_linux__
     g_Exiting = 1;
 #endif
+#endif
+#ifdef __HAIKU__
+    kill (getpid(), SIGKILL);
 #endif
     return ret;
 }
-- 
2.30.2


From 6d24f90e27eded9fb6ce8e810ce2204f281d4cd3 Mon Sep 17 00:00:00 2001
From: Sergei Reznikov <diver@gelios.net>
Date: Sat, 15 Feb 2020 15:04:53 +0300
Subject: Implement ShellExec on Haiku


diff --git a/shell/source/unix/exec/shellexec.cxx b/shell/source/unix/exec/shellexec.cxx
index 3daea4a..d114d79 100644
--- a/shell/source/unix/exec/shellexec.cxx
+++ b/shell/source/unix/exec/shellexec.cxx
@@ -180,6 +180,9 @@ void SAL_CALL ShellExec::execute( const OUString& aCommand, const OUString& aPar
             aBuffer.append(" -R");
         }
         aBuffer.append(" --");
+
+#elif __HAIKU__
+		aBuffer.append("open");
 #else
         // Just use xdg-open on non-Mac
         aBuffer.append("/usr/bin/xdg-open");
-- 
2.30.2


From 100bbddc67616bec1cea5c1e3026bf5d92400b27 Mon Sep 17 00:00:00 2001
From: Sergei Reznikov <diver@gelios.net>
Date: Sat, 20 Jul 2019 01:18:50 +0300
Subject: Comment out linking with pthread


diff --git a/solenv/gbuild/platform/unxgcc.mk b/solenv/gbuild/platform/unxgcc.mk
index 8854aab..f0489a8 100644
--- a/solenv/gbuild/platform/unxgcc.mk
+++ b/solenv/gbuild/platform/unxgcc.mk
@@ -45,9 +45,9 @@ gb_CFLAGS := \
 # At least libstdc++ (which is approximated here with !HAVE_LIBCXX) needs -pthread when including
 # various C++ headers like <thread>, see <https://gcc.gnu.org/onlinedocs/gcc-8.3.0/libstdc++/manual/
 # manual/using.html#manual.intro.using.flags>:
-ifeq ($(HAVE_LIBCXX),)
-gb_CXX_LINKFLAGS := -pthread
-endif
+#ifeq ($(HAVE_LIBCXX),)
+#gb_CXX_LINKFLAGS := -pthread
+#endif
 
 gb_CXXFLAGS := \
 	$(gb_CXXFLAGS_COMMON) \
-- 
2.30.2


From de8ccf90be170c93118a8ca834f6be76299647d2 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 11 Aug 2019 11:46:49 +1000
Subject: Workaround for ambiguous methods


diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 088f5a2..1288061 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -92,6 +92,17 @@ public:
         return 0;
     }
 
+    size_type erase2( const Value& x )
+    {
+        std::pair<const_iterator, bool> const ret(Find_t()(m_vector.begin(), m_vector.end(), x));
+        if (ret.second)
+        {
+            m_vector.erase(m_vector.begin() + (ret.first - m_vector.begin()));
+            return 1;
+        }
+        return 0;
+    }
+
     void erase( size_t index )
     {
         m_vector.erase(m_vector.begin() + index);
diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx
index 8636d6b..0defdfc 100644
--- a/sc/source/core/data/attarray.cxx
+++ b/sc/source/core/data/attarray.cxx
@@ -375,7 +375,7 @@ void ScAttrArray::RemoveCondFormat( SCROW nStartRow, SCROW nEndRow, sal_uInt32 n
                     if(itr != rCondFormatData.end())
                     {
                         ScCondFormatIndexes aNewCondFormatData(rCondFormatData);
-                        aNewCondFormatData.erase(nIndex);
+                        aNewCondFormatData.erase2(nIndex);
                         ScCondFormatItem aItem( std::move(aNewCondFormatData) );
                         pPatternAttr->GetItemSet().Put( aItem );
                         SetPatternArea( nTempStartRow, nTempEndRow, std::move(pPatternAttr), true );
-- 
2.30.2


From 6f74461991764e2aa85a6398f98f70cd68f1dd84 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 11 Aug 2019 11:47:40 +1000
Subject: Add XP_HAIKU defs for xmlsec


diff --git a/svl/Library_svl.mk b/svl/Library_svl.mk
index c49417d..ec75755 100644
--- a/svl/Library_svl.mk
+++ b/svl/Library_svl.mk
@@ -95,6 +95,12 @@ $(eval $(call gb_Library_use_system_win32_libs,svl,\
     shlwapi \
 ))
 
+ifeq ($(OS),HAIKU)
+$(eval $(call gb_Library_add_defs,svl,\
+    -DXP_HAIKU=1 \
+))
+endif
+
 ifeq ($(OS),WNT)
 $(eval $(call gb_Library_add_defs,svl,\
     -DSVL_CRYPTO_MSCRYPTO \
diff --git a/xmlsecurity/Library_xsec_xmlsec.mk b/xmlsecurity/Library_xsec_xmlsec.mk
index bd2cb6a..9d6a90c 100644
--- a/xmlsecurity/Library_xsec_xmlsec.mk
+++ b/xmlsecurity/Library_xsec_xmlsec.mk
@@ -116,6 +116,12 @@ $(eval $(call gb_Library_add_defs,xsec_xmlsec,\
 	-DXMLSEC_CRYPTO_NSS \
 ))
 
+ifeq ($(OS),HAIKU)
+$(eval $(call gb_Library_add_defs,xsec_xmlsec,\
+	-DXP_HAIKU=1 \
+))
+endif
+
 ifeq ($(SYSTEM_XMLSEC),)
 $(eval $(call gb_Library_add_libs,xsec_xmlsec,\
 	$(call gb_UnpackedTarball_get_dir,xmlsec)/src/nss/.libs/libxmlsec1-nss.a \
-- 
2.30.2


From 279237b4cf6bed4d76fb77bd23bbf1eb5ff9a4a7 Mon Sep 17 00:00:00 2001
From: Sergei Reznikov <diver@gelios.net>
Date: Sat, 15 Feb 2020 15:08:51 +0300
Subject: Cast to boolean


diff --git a/vcl/source/filter/jpeg/jpegc.cxx b/vcl/source/filter/jpeg/jpegc.cxx
index 8a57f55..4835901 100644
--- a/vcl/source/filter/jpeg/jpegc.cxx
+++ b/vcl/source/filter/jpeg/jpegc.cxx
@@ -163,13 +163,13 @@ static void ReadJPEG(JpegStuff& rContext, JPEGReader* pJPEGReader, void* pInputS
     rContext.aOwner.set(&rContext.cinfo);
     jpeg_svstream_src(&rContext.cinfo, pInputStream);
     SourceManagerStruct *source = reinterpret_cast<SourceManagerStruct*>(rContext.cinfo.src);
-    jpeg_read_header(&rContext.cinfo, TRUE);
+    jpeg_read_header(&rContext.cinfo, static_cast<boolean>(TRUE));
 
     rContext.cinfo.scale_num = 1;
     rContext.cinfo.scale_denom = 1;
     rContext.cinfo.output_gamma = 1.0;
-    rContext.cinfo.raw_data_out = FALSE;
-    rContext.cinfo.quantize_colors = FALSE;
+    rContext.cinfo.raw_data_out = static_cast<boolean>(FALSE);
+    rContext.cinfo.quantize_colors = static_cast<boolean>(FALSE);
 
     /* change scale for preview import */
     long nPreviewWidth = previewSize.Width();
@@ -204,8 +204,8 @@ static void ReadJPEG(JpegStuff& rContext, JPEGReader* pJPEGReader, void* pInputS
         if (rContext.cinfo.scale_denom > 1)
         {
             rContext.cinfo.dct_method            = JDCT_FASTEST;
-            rContext.cinfo.do_fancy_upsampling   = FALSE;
-            rContext.cinfo.do_block_smoothing    = FALSE;
+            rContext.cinfo.do_fancy_upsampling   = static_cast<boolean>(FALSE);
+            rContext.cinfo.do_block_smoothing    = static_cast<boolean>(FALSE);
         }
     }
 
@@ -394,7 +394,7 @@ bool WriteJPEG( JPEGWriter* pJPEGWriter, void* pOutputStream,
     }
 
     jpeg_set_defaults( &cinfo );
-    jpeg_set_quality( &cinfo, static_cast<int>(nQualityPercent), FALSE );
+    jpeg_set_quality( &cinfo, static_cast<int>(nQualityPercent), static_cast<boolean>(FALSE) );
 
     cinfo.density_unit = 1;
     cinfo.X_density = rPPI.getX();
@@ -419,7 +419,7 @@ bool WriteJPEG( JPEGWriter* pJPEGWriter, void* pOutputStream,
         cinfo.comp_info[0].v_samp_factor = 2;
     }
 
-    jpeg_start_compress( &cinfo, TRUE );
+    jpeg_start_compress( &cinfo, static_cast<boolean>(TRUE) );
 
     for( nY = 0; nY < nHeight; nY++ )
     {
@@ -454,10 +454,10 @@ void Transform(void* pInputStream, void* pOutputStream, long nAngle)
     jvirt_barray_ptr* aSourceCoefArrays      = nullptr;
     jvirt_barray_ptr* aDestinationCoefArrays = nullptr;
 
-    aTransformOption.force_grayscale = FALSE;
-    aTransformOption.trim            = FALSE;
-    aTransformOption.perfect         = FALSE;
-    aTransformOption.crop            = FALSE;
+    aTransformOption.force_grayscale = static_cast<boolean>(FALSE);
+    aTransformOption.trim            = static_cast<boolean>(FALSE);
+    aTransformOption.perfect         = static_cast<boolean>(FALSE);
+    aTransformOption.crop            = static_cast<boolean>(FALSE);
 
     // Angle to transform option
     // 90 Clockwise = 270 Counterclockwise
@@ -486,7 +486,7 @@ void Transform(void* pInputStream, void* pOutputStream, long nAngle)
     aDestinationInfo.err->error_exit     = errorExit;
     aDestinationInfo.err->output_message = outputMessage;
 
-    aDestinationInfo.optimize_coding = TRUE;
+    aDestinationInfo.optimize_coding = static_cast<boolean>(TRUE);
 
     JpegDecompressOwner aDecompressOwner;
     JpegCompressOwner aCompressOwner;
@@ -506,7 +506,7 @@ void Transform(void* pInputStream, void* pOutputStream, long nAngle)
     jpeg_svstream_src (&aSourceInfo, pInputStream);
 
     jcopy_markers_setup(&aSourceInfo, aCopyOption);
-    jpeg_read_header(&aSourceInfo, TRUE);
+    jpeg_read_header(&aSourceInfo, static_cast<boolean>(TRUE));
     jtransform_request_workspace(&aSourceInfo, &aTransformOption);
 
     aSourceCoefArrays = jpeg_read_coefficients(&aSourceInfo);
@@ -516,7 +516,7 @@ void Transform(void* pInputStream, void* pOutputStream, long nAngle)
     jpeg_svstream_dest (&aDestinationInfo, pOutputStream);
 
     // Compute optimal Huffman coding tables instead of precomputed tables
-    aDestinationInfo.optimize_coding = TRUE;
+    aDestinationInfo.optimize_coding = static_cast<boolean>(TRUE);
     jpeg_write_coefficients(&aDestinationInfo, aDestinationCoefArrays);
     jcopy_markers_execute(&aSourceInfo, &aDestinationInfo, aCopyOption);
     jtransform_execute_transformation(&aSourceInfo, &aDestinationInfo, aSourceCoefArrays, &aTransformOption);
-- 
2.30.2


From fff5e4c77ae219e8130cda8e02d7a552e9a3d9ce Mon Sep 17 00:00:00 2001
From: Sergei Reznikov <diver@gelios.net>
Date: Sat, 15 Feb 2020 17:45:08 +0300
Subject: Revert fstack-protector check removal in
 9db11a8ab648f4d04e59e6bb94cd640f64835447


diff --git a/config_host.mk.in b/config_host.mk.in
index 1b5fa47..0e4d79e 100644
--- a/config_host.mk.in
+++ b/config_host.mk.in
@@ -244,6 +244,7 @@ export USING_X11=@USING_X11@
 export HAMCREST_JAR=@HAMCREST_JAR@
 export HAVE_BROKEN_GCC_WMAYBE_UNINITIALIZED=@HAVE_BROKEN_GCC_WMAYBE_UNINITIALIZED@
 export HAVE_GCC_AVX=@HAVE_GCC_AVX@
+export HAVE_GCC_STACK_PROTECTOR_STRONG=@HAVE_GCC_STACK_PROTECTOR_STRONG@
 export HAVE_GCC_BUILTIN_ATOMIC=@HAVE_GCC_BUILTIN_ATOMIC@
 export HAVE_GCC_BUILTIN_FFS=@HAVE_GCC_BUILTIN_FFS@
 export HAVE_GCC_FNO_ENFORCE_EH_SPECS=@HAVE_GCC_FNO_ENFORCE_EH_SPECS@
diff --git a/configure.ac b/configure.ac
index 388bee3..352aa6a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6213,6 +6213,17 @@ if test "$GCC" = "yes" -o "$COM_IS_CLANG" = TRUE; then
         AC_MSG_RESULT([no])
     fi
 
+    AC_MSG_CHECKING([whether $CC_BASE supports -fstack-protector-strong])
+    save_CFLAGS=$CFLAGS
+    CFLAGS="$CFLAGS -O0 -Werror -fstack-protector-strong"
+    AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ char a[8]; a[7] = 0; ]])],[ HAVE_GCC_STACK_PROTECTOR_STRONG=TRUE ],[])
+    CFLAGS=$save_CFLAGS
+    if test "$HAVE_GCC_STACK_PROTECTOR_STRONG" = "TRUE"; then
+        AC_MSG_RESULT([yes])
+    else
+        AC_MSG_RESULT([no])
+    fi
+
     AC_MSG_CHECKING([whether $CC_BASE supports atomic functions])
     AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
     int v = 0;
@@ -6384,6 +6395,7 @@ AC_LANG_POP([C++])
 fi
 
 AC_SUBST(HAVE_GCC_AVX)
+AC_SUBST(HAVE_GCC_STACK_PROTECTOR_STRONG)
 AC_SUBST(HAVE_GCC_BUILTIN_ATOMIC)
 AC_SUBST(HAVE_GCC_BUILTIN_FFS)
 AC_SUBST(HAVE_GCC_STACK_CLASH_PROTECTION)
diff --git a/solenv/gbuild/platform/com_GCC_defs.mk b/solenv/gbuild/platform/com_GCC_defs.mk
index 712a61d..2c3d5f1 100644
--- a/solenv/gbuild/platform/com_GCC_defs.mk
+++ b/solenv/gbuild/platform/com_GCC_defs.mk
@@ -67,7 +67,6 @@ gb_CFLAGS_COMMON := \
 	-fmessage-length=0 \
 	-fno-common \
 	-pipe \
-	-fstack-protector-strong \
 
 gb_CXXFLAGS_COMMON := \
 	-Wall \
@@ -82,7 +81,6 @@ gb_CXXFLAGS_COMMON := \
 	-fmessage-length=0 \
 	-fno-common \
 	-pipe \
-	-fstack-protector-strong \
 
 gb_CXXFLAGS_DISABLE_WARNINGS = -w
 
@@ -136,7 +134,11 @@ endif
 gb_VISIBILITY_FLAGS_CXX := -fvisibility-inlines-hidden
 gb_CXXFLAGS_COMMON += $(gb_VISIBILITY_FLAGS_CXX)
 
+ifeq ($(HAVE_GCC_STACK_PROTECTOR_STRONG),TRUE)
+gb_CFLAGS_COMMON += -fstack-protector-strong
+gb_CXXFLAGS_COMMON += -fstack-protector-strong
 gb_LinkTarget_LDFLAGS += -fstack-protector-strong
+endif
 
 ifneq ($(ENABLE_PCH),)
 ifeq ($(COM_IS_CLANG),TRUE)
-- 
2.30.2


From f549994ffcc7ff9f6e6ed0439eea9f14c764f849 Mon Sep 17 00:00:00 2001
From: Ken Mays <kmays2000@gmail.com>
Date: Tue, 9 Feb 2021 12:15:02 +0300
Subject: Add CSTDDEF include to O3TL


diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx
index e822fde..33a1487 100644
--- a/include/o3tl/lru_map.hxx
+++ b/include/o3tl/lru_map.hxx
@@ -14,6 +14,7 @@
 #include <cassert>
 #include <list>
 #include <unordered_map>
+#include <cstddef>
 
 namespace o3tl
 {
-- 
2.30.2


From f21b6bd70c6ae4f8e035443f9131d076064b67e1 Mon Sep 17 00:00:00 2001
From: Ken Mays <kmays2000@gmail.com>
Date: Tue, 9 Feb 2021 12:26:19 +0300
Subject: Fix Bison 3.8 issue with SQLbison.y


diff --git a/connectivity/source/parse/sqlbison.y b/connectivity/source/parse/sqlbison.y
index c9d423e..b444277 100644
--- a/connectivity/source/parse/sqlbison.y
+++ b/connectivity/source/parse/sqlbison.y
@@ -74,10 +74,15 @@ inline connectivity::OSQLInternalNode* newNode(const OUString& _newValue,
 
 // yyi is the internal number of the rule that is currently being reduced
 // This can be mapped to external rule number via the yyrmap.
+#if YYBISON >= 30800
+#define SQL_NEW_RULE 			newNode("", SQLNodeType::Rule, yyr1[yyrule])
+#define SQL_NEW_LISTRULE 		newNode("", SQLNodeType::ListRule, yyr1[yyrule])
+#define SQL_NEW_COMMALISTRULE   newNode("", SQLNodeType::CommaListRule, yyr1[yynrule])
+#else
 #define SQL_NEW_RULE 			newNode("", SQLNodeType::Rule, yyr1[yyn])
 #define SQL_NEW_LISTRULE 		newNode("", SQLNodeType::ListRule, yyr1[yyn])
 #define SQL_NEW_COMMALISTRULE   newNode("", SQLNodeType::CommaListRule, yyr1[yyn])
-
+#endif
 
 extern connectivity::OSQLParser* xxx_pGLOBAL_SQLPARSER;
 
-- 
2.30.2


From 4b0704963393ad3fd3a814f3d96d62b1e4ddbb9c Mon Sep 17 00:00:00 2001
From: Ken Mays <kmays2000@gmail.com>
Date: Tue, 9 Feb 2021 13:15:24 +0300
Subject: Fix GCC11/12 issue with SAL_STREAM


diff --git a/include/sal/log.hxx b/include/sal/log.hxx
index 00d533a..f85c7d8 100644
--- a/include/sal/log.hxx
+++ b/include/sal/log.hxx
@@ -161,7 +161,10 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) {
 
     @since LibreOffice 3.5
 */
-#if defined _LIBCPP_VERSION || (defined _MSC_VER && _MSC_VER >= 1915)
+#if defined _LIBCPP_VERSION \
+    || (defined _GLIBCXX_RELEASE \
+        && (_GLIBCXX_RELEASE >= 12 || (_GLIBCXX_RELEASE == 11 && __GLIBCXX__ > 20210428))) \
+    || (defined _MSC_VER && _MSC_VER >= 1915)
 #define SAL_STREAM(stream) \
     (::std::ostringstream() << stream).str()
 #else
-- 
2.30.2

