From d3b12ed3c57773cf953335e6a489e0ee0bc16c90 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Sat, 15 Jul 2017 15:42:32 +0200
Subject: apply patch from 4.1.0.


diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceclientproxy.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceclientproxy.cpp
index 8b1221a..78d984a 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceclientproxy.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceclientproxy.cpp
@@ -47,7 +47,7 @@
 namespace QmlDesigner {
 static void prioritizeDown()
 {
-#if defined(Q_OS_UNIX)
+#if defined(Q_OS_UNIX) && !defined(Q_OS_HAIKU)
     nice(19);
 #elif defined(Q_OS_WIN)
     SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppet.pri b/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppet.pri
index 0b364d3..592133a 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppet.pri
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppet.pri
@@ -34,7 +34,7 @@ else: RESOURCES += $$PWD/../editor3d_qt5.qrc
 
 DISTFILES += Info.plist
 
-unix:!openbsd:!osx: LIBS += -lrt # posix shared memory
+unix:!openbsd:!osx:!haiku: LIBS += -lrt # posix shared memory
 
 osx {
     CONFIG -= app_bundle
diff --git a/src/libs/sqlite/sqlite-lib.pri b/src/libs/sqlite/sqlite-lib.pri
index f1248cd..f938e76 100644
--- a/src/libs/sqlite/sqlite-lib.pri
+++ b/src/libs/sqlite/sqlite-lib.pri
@@ -6,7 +6,7 @@ shared {
 
 INCLUDEPATH += $$PWD
 
-unix:!bsd: LIBS += -ldl
+unix:!bsd:!haiku: LIBS += -ldl
 
 include(../3rdparty/sqlite/sqlite.pri)
 
diff --git a/src/libs/utils/process_stub_unix.c b/src/libs/utils/process_stub_unix.c
index 1cb3e8a..245e901 100644
--- a/src/libs/utils/process_stub_unix.c
+++ b/src/libs/utils/process_stub_unix.c
@@ -1,3 +1,4 @@
+#if 0
 /****************************************************************************
 **
 ** Copyright (C) 2016 The Qt Company Ltd.
@@ -135,8 +136,10 @@ static void sigchldHandler(int sig)
 
 /* syntax: $0 {"run"|"debug"} <pid-socket> <continuation-msg> <workdir> <env-file> <exe> <args...> */
 /* exit codes: 0 = ok, 1 = invocation error, 3 = internal error */
+#endif
 int main(int argc, char *argv[])
 {
+#if 0
     int errNo, hadInvalidCommand = 0;
     char **env = 0;
     struct sockaddr_un sau;
@@ -358,5 +361,6 @@ int main(int argc, char *argv[])
             }
     }
     assert(0);
+#endif
     return 0;
 }
diff --git a/src/plugins/qmldesigner/qmldesignerplugin.pro b/src/plugins/qmldesigner/qmldesignerplugin.pro
index 78fe856..bc72e8d 100644
--- a/src/plugins/qmldesigner/qmldesignerplugin.pro
+++ b/src/plugins/qmldesigner/qmldesignerplugin.pro
@@ -4,7 +4,7 @@ CONFIG += exceptions
 INCLUDEPATH += $$PWD
 INCLUDEPATH += $$PWD/components
 
-unix:!openbsd:!osx: LIBS += -lrt # posix shared memory
+unix:!openbsd:!osx:!haiku: LIBS += -lrt # posix shared memory
 
 include(../../qtcreatorplugin.pri)
 
diff --git a/src/shared/qbs/src/lib/corelib/tools/processutils.cpp b/src/shared/qbs/src/lib/corelib/tools/processutils.cpp
index b27592f..ca5fcd6 100644
--- a/src/shared/qbs/src/lib/corelib/tools/processutils.cpp
+++ b/src/shared/qbs/src/lib/corelib/tools/processutils.cpp
@@ -57,6 +57,8 @@
 # if !defined(Q_OS_NETBSD)
 #   include <sys/user.h>
 # endif
+#elif defined(Q_OS_HAIKU)
+// Do nothing.
 #else
 #   error Missing implementation of processNameByPid for this platform.
 #endif
-- 
2.30.2


From b4777cbfd48da52d1ba478af52aba92fbe6341fd Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Sat, 15 Jul 2017 18:20:31 +0200
Subject: Fix rpath handling.


diff --git a/qtcreator.pro b/qtcreator.pro
index 5666948..f8dc86b 100644
--- a/qtcreator.pro
+++ b/qtcreator.pro
@@ -46,7 +46,7 @@ exists(src/shared/qbs/qbs.pro) {
         QBS_APPS_RPATH_DIR = @loader_path/../Frameworks
     } else {
         QBS_PLUGINS_BUILD_DIR = $$IDE_PLUGIN_PATH
-        QBS_APPS_RPATH_DIR = \$\$ORIGIN/../$$IDE_LIBRARY_BASENAME/qtcreator
+        QBS_APPS_RPATH_DIR = $$ORIGIN/../$$IDE_LIBRARY_BASENAME/qtcreator
     }
     cache(QBS_PLUGINS_BUILD_DIR)
     cache(QBS_APPS_RPATH_DIR)
diff --git a/src/rpath.pri b/src/rpath.pri
index ef0a6b7..49dfaf6 100644
--- a/src/rpath.pri
+++ b/src/rpath.pri
@@ -16,4 +16,10 @@ macos {
     IDE_PLUGIN_RPATH = $$join(QMAKE_RPATHDIR, ":")
     QMAKE_LFLAGS += -Wl,-z,origin \'-Wl,-rpath,$${IDE_PLUGIN_RPATH}\'
     QMAKE_RPATHDIR =
+} else:haiku-* {
+    QMAKE_RPATHDIR += $ORIGIN/$$REL_PATH_TO_LIBS
+    QMAKE_RPATHDIR += $ORIGIN/$$REL_PATH_TO_PLUGINS
+	QMAKE_RPATHDIR += $ORIGIN
+    QMAKE_RPATHDIR += $ORIGIN/..
+    QMAKE_RPATHDIR += $ORIGIN/../$$IDE_LIBRARY_BASENAME/qtcreator
 }
diff --git a/src/shared/qbs/src/app/app.pri b/src/shared/qbs/src/app/app.pri
index 5cd9cb4..818df42 100644
--- a/src/shared/qbs/src/app/app.pri
+++ b/src/shared/qbs/src/app/app.pri
@@ -7,6 +7,7 @@ DEFINES += QT_NO_CAST_FROM_ASCII QT_NO_PROCESS_COMBINED_ARGUMENT_START
 else:DESTDIR = ../../../bin
 
 !isEmpty(QBS_APPS_RPATH_DIR) {
+    haiku: QMAKE_RPATHDIR += $ORIGIN/../lib/qtcreator
     linux-*:QMAKE_LFLAGS += -Wl,-z,origin \'-Wl,-rpath,$${QBS_APPS_RPATH_DIR}\'
     macx:QMAKE_LFLAGS += -Wl,-rpath,$${QBS_APPS_RPATH_DIR}
 }
-- 
2.30.2


From fcc84f8696c455ab507c70f290a82747caf5f3dc Mon Sep 17 00:00:00 2001
From: Sergei Reznikov <diver@gelios.net>
Date: Mon, 25 Jun 2018 16:18:26 +0300
Subject: Enable Terminal on Haiku


diff --git a/src/libs/utils/consoleprocess.cpp b/src/libs/utils/consoleprocess.cpp
index d0979ac..9f61a01 100644
--- a/src/libs/utils/consoleprocess.cpp
+++ b/src/libs/utils/consoleprocess.cpp
@@ -151,6 +151,9 @@ void ConsoleProcess::setSettings(QSettings *settings)
 
 Q_GLOBAL_STATIC_WITH_ARGS(const QVector<TerminalCommand>, knownTerminals, (
 {
+#ifdef Q_OS_HAIKU
+    {"Terminal", "", ""},
+#endif
     {"x-terminal-emulator", "", "-e"},
     {"xdg-terminal", "", "", true},
     {"xterm", "", "-e"},
@@ -178,7 +181,11 @@ TerminalCommand ConsoleProcess::defaultTerminalEmulator()
                 defaultTerm = {"/usr/X11/bin/xterm", "", "-e"};
 
         } else if (HostOsInfo::isAnyUnixHost()) {
+#ifdef Q_OS_HAIKU
+            return {"/system/apps/Terminal", "", ""};
+#else
             defaultTerm = {"xterm", "", "-e"};
+#endif
             const Environment env = Environment::systemEnvironment();
             for (const TerminalCommand &term : *knownTerminals) {
                 const QString result = env.searchInPath(term.command).toString();
diff --git a/src/libs/utils/unixutils.cpp b/src/libs/utils/unixutils.cpp
index 535bfa2..035ec66 100644
--- a/src/libs/utils/unixutils.cpp
+++ b/src/libs/utils/unixutils.cpp
@@ -36,7 +36,11 @@ using namespace Utils;
 
 QString UnixUtils::defaultFileBrowser()
 {
+#ifdef Q_OS_HAIKU
+    return QLatin1String("open %d");
+#else
     return QLatin1String("xdg-open %d");
+#endif
 }
 
 QString UnixUtils::fileBrowser(const QSettings *settings)
-- 
2.30.2


From 7cd8e150fb5f9184742d678d486366662485274c Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Thu, 28 May 2020 14:42:59 +1000
Subject: Don't using Manhattan style for QMenu and QMenuBar


diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp
index d2043b7..a8de63c 100644
--- a/src/plugins/coreplugin/mainwindow.cpp
+++ b/src/plugins/coreplugin/mainwindow.cpp
@@ -144,6 +144,9 @@ MainWindow::MainWindow()
             && baseName == QLatin1String("windows")) {
         baseName = QLatin1String("fusion");
     }
+#ifndef __HAIKU__
+    baseName = QLatin1String("haiku");
+#endif
 
     // if the user has specified as base style in the theme settings,
     // prefer that
@@ -156,6 +159,7 @@ MainWindow::MainWindow()
     }
 
     QApplication::setStyle(new ManhattanStyle(baseName));
+
     m_generalSettings->setShowShortcutsInContextMenu(
         GeneralSettings::showShortcutsInContextMenu());
 
diff --git a/src/plugins/coreplugin/manhattanstyle.cpp b/src/plugins/coreplugin/manhattanstyle.cpp
index a6b9466..17f37dc 100644
--- a/src/plugins/coreplugin/manhattanstyle.cpp
+++ b/src/plugins/coreplugin/manhattanstyle.cpp
@@ -218,16 +218,20 @@ int ManhattanStyle::pixelMetric(PixelMetric metric, const QStyleOption *option,
     case PM_DockWidgetHandleExtent:
     case PM_DockWidgetSeparatorExtent:
         return 1;
+#ifndef __HAIKU__
     case PM_MenuPanelWidth:
     case PM_MenuBarHMargin:
     case PM_MenuBarVMargin:
+#endif
     case PM_ToolBarFrameWidth:
         if (panelWidget(widget))
             retval = 1;
         break;
     case PM_ButtonShiftVertical:
     case PM_ButtonShiftHorizontal:
+#ifndef __HAIKU__
     case PM_MenuBarPanelWidth:
+#endif
     case PM_ToolBarItemMargin:
     case PM_ToolBarItemSpacing:
         if (panelWidget(widget))
@@ -796,6 +800,7 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
     }
 
     switch (element) {
+#ifndef __HAIKU__
     case CE_MenuItem:
         painter->save();
         if (const auto mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
@@ -853,7 +858,7 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
         }
         painter->restore();
         break;
-
+#endif
     case CE_ComboBoxLabel:
         if (const auto cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
             if (panelWidget(widget)) {
@@ -948,7 +953,7 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
             painter->restore();
         }
         break;
-
+#ifndef __HAIKU__
     case CE_MenuBarEmptyArea: {
             if (creatorTheme()->flag(Theme::FlatMenuBar))
                 painter->fillRect(option->rect, StyleHelper::baseColor());
@@ -962,7 +967,7 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
             painter->restore();
         }
         break;
-
+#endif
     case CE_ToolBar:
         {
             QRect rect = option->rect;
-- 
2.30.2


From ef780df82431157d4b7269f00921e8e288c31ac0 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Thu, 28 May 2020 15:38:35 +1000
Subject: Don't validate Qt toolkit


diff --git a/src/plugins/qtsupport/baseqtversion.cpp b/src/plugins/qtsupport/baseqtversion.cpp
index 61e9438..55304d5 100644
--- a/src/plugins/qtsupport/baseqtversion.cpp
+++ b/src/plugins/qtsupport/baseqtversion.cpp
@@ -520,7 +520,7 @@ Tasks BaseQtVersion::validateKit(const Kit *k)
         if (!tdt.isEmpty() && !tdt.contains(dt))
             result << BuildSystemTask(Task::Warning, tr("Device type is not supported by Qt version."));
     }
-
+#ifndef __HAIKU__
     if (ToolChain *tc = ToolChainKitAspect::cxxToolChain(k)) {
         Abi targetAbi = tc->targetAbi();
         Abis supportedAbis = tc->supportedAbis();
@@ -559,6 +559,7 @@ Tasks BaseQtVersion::validateKit(const Kit *k)
         const QString message = tr("The kit has a Qt version, but no C++ compiler.");
         result << BuildSystemTask(Task::Warning, message);
     }
+#endif
     return result;
 }
 
-- 
2.30.2


From 9992e8e469dd6d3f78c7c5aedac0e054b9ab0a82 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Thu, 28 May 2020 17:26:06 +1000
Subject: Make unknown host abi for Haiku


diff --git a/src/plugins/projectexplorer/abi.cpp b/src/plugins/projectexplorer/abi.cpp
index 62fd00b..1d9a942 100644
--- a/src/plugins/projectexplorer/abi.cpp
+++ b/src/plugins/projectexplorer/abi.cpp
@@ -1134,6 +1134,10 @@ Abi Abi::hostAbi()
     subos = WindowsMSysFlavor;
 #endif
     format = PEFormat;
+#elif defined (Q_OS_HAIKU)
+    os = UnknownOS;
+    subos = GenericFlavor;
+    format = UnknownFormat;
 #elif defined (Q_OS_LINUX)
     os = LinuxOS;
     subos = GenericFlavor;
-- 
2.30.2


From 21254881e0b604095c4b4152fb7ee82bcaa7f78d Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Tue, 29 Dec 2020 14:16:57 +1000
Subject: Fix build for clang 9


diff --git a/src/plugins/clangformat/clangformatutils.cpp b/src/plugins/clangformat/clangformatutils.cpp
index ff184ea..66399f7 100644
--- a/src/plugins/clangformat/clangformatutils.cpp
+++ b/src/plugins/clangformat/clangformatutils.cpp
@@ -124,7 +124,7 @@ static clang::format::FormatStyle qtcStyle()
 #if LLVM_VERSION_MAJOR >= 12
     style.IncludeStyle.IncludeCategories = {{"^<Q.*", 200, 200, true}};
 #else
-    style.IncludeStyle.IncludeCategories = {{"^<Q.*", 200, 200}};
+    style.IncludeStyle.IncludeCategories = {{"^<Q.*", 200}};
 #endif
     style.IncludeStyle.IncludeIsMainRegex = "(Test)?$";
     style.IndentCaseLabels = false;
-- 
2.30.2


From f62281aaf92fd24f3d6b4061547e4aae1871efe7 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 3 Jan 2022 11:41:36 +1000
Subject: Fix build sqlite


diff --git a/src/libs/3rdparty/sqlite/config.h b/src/libs/3rdparty/sqlite/config.h
index 345e2b0..4fe631b 100644
--- a/src/libs/3rdparty/sqlite/config.h
+++ b/src/libs/3rdparty/sqlite/config.h
@@ -35,6 +35,11 @@
 #define HAVE_UTIME 1
 #endif
 
+#ifdef __HAIKU__
+#define _DEFAULT_SOURCE 1
+#define _BSD_SOURCE 1
+#endif
+
 #if (_XOPEN_SOURCE >= 500) && !(_POSIX_C_SOURCE >= 200809L) || _DEFAULT_SOURCE || _BSD_SOURCE
 #define HAVE_USLEEP 1
 #endif
diff --git a/src/libs/3rdparty/sqlite/sqlite3.c b/src/libs/3rdparty/sqlite/sqlite3.c
index 89faea5..030c772 100644
--- a/src/libs/3rdparty/sqlite/sqlite3.c
+++ b/src/libs/3rdparty/sqlite/sqlite3.c
@@ -37710,7 +37710,7 @@ static int full_fsync(int fd, int fullSync, int dataOnly){
   */
   if( rc ) rc = fsync(fd);
 
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) || defined(__HAIKU__)
   /* fdatasync() on HFS+ doesn't yet flush the file size if it changed correctly
   ** so currently we default to the macro that redefines fdatasync to fsync
   */
diff --git a/src/libs/sqlite/createtablesqlstatementbuilder.cpp b/src/libs/sqlite/createtablesqlstatementbuilder.cpp
new file mode 100644
index 0000000..e69de29
-- 
2.30.2


From 1edd4310b32ec325e85da95ce617d316555ae51e Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 3 Jan 2022 11:46:26 +1000
Subject: Use fsync


diff --git a/src/libs/utils/savefile.cpp b/src/libs/utils/savefile.cpp
index 721a872..e6cc8c1 100644
--- a/src/libs/utils/savefile.cpp
+++ b/src/libs/utils/savefile.cpp
@@ -106,7 +106,7 @@ bool SaveFile::commit()
     }
 #ifdef Q_OS_WIN
     FlushFileBuffers(reinterpret_cast<HANDLE>(_get_osfhandle(handle())));
-#elif _POSIX_SYNCHRONIZED_IO > 0
+#elif _POSIX_SYNCHRONIZED_IO > 0 && !defined(__HAIKU__)
     fdatasync(handle());
 #else
     fsync(handle());
-- 
2.30.2


From 7cdab8fe044610b85b6baa8397de5da73179e84a Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 3 Jan 2022 11:48:00 +1000
Subject: Use localtime for FileTime::toString


diff --git a/src/shared/qbs/src/lib/corelib/tools/filetime.cpp b/src/shared/qbs/src/lib/corelib/tools/filetime.cpp
index 4ccb573..ee17422 100644
--- a/src/shared/qbs/src/lib/corelib/tools/filetime.cpp
+++ b/src/shared/qbs/src/lib/corelib/tools/filetime.cpp
@@ -115,6 +115,13 @@ double FileTime::asDouble() const
 
 QString FileTime::toString() const
 {
+#ifdef __HAIKU__
+    tm* stLocal = localtime(&m_fileTime);
+    const QString result = QStringLiteral("%1.%2.%3 %4:%5:%6")
+            .arg(stLocal->tm_mday, 2, 10, QLatin1Char('0')).arg(stLocal->tm_mon, 2, 10, QLatin1Char('0')).arg(stLocal->tm_year)
+            .arg(stLocal->tm_hour, 2, 10, QLatin1Char('0')).arg(stLocal->tm_min, 2, 10, QLatin1Char('0')).arg(stLocal->tm_sec, 2, 10, QLatin1Char('0'));
+    return result;
+#else
     auto const ft = reinterpret_cast<const FILETIME *>(&m_fileTime);
     SYSTEMTIME stUTC, stLocal;
     FileTimeToSystemTime(ft, &stUTC);
@@ -123,6 +130,7 @@ QString FileTime::toString() const
             .arg(stLocal.wDay, 2, 10, QLatin1Char('0')).arg(stLocal.wMonth, 2, 10, QLatin1Char('0')).arg(stLocal.wYear)
             .arg(stLocal.wHour, 2, 10, QLatin1Char('0')).arg(stLocal.wMinute, 2, 10, QLatin1Char('0')).arg(stLocal.wSecond, 2, 10, QLatin1Char('0'));
     return result;
+#endif
 }
 
 #else // defined(Q_OS_WIN)
-- 
2.30.2


From 51da680eafbba495ba180fbe219605e79a8b9ba8 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 3 Jan 2022 11:48:53 +1000
Subject: Disable dumpBacktrace for Haiku


diff --git a/src/libs/utils/qtcassert.cpp b/src/libs/utils/qtcassert.cpp
index 560df43..d1c2a29 100644
--- a/src/libs/utils/qtcassert.cpp
+++ b/src/libs/utils/qtcassert.cpp
@@ -40,7 +40,7 @@ void dumpBacktrace(int maxdepth)
 {
     if (maxdepth == -1)
         maxdepth = 1000;
-#if defined(Q_OS_UNIX)
+#if defined(Q_OS_UNIX) && !defined(__HAIKU__)
     void *bt[1000] = {nullptr};
     int size = backtrace(bt, sizeof(bt) / sizeof(bt[0]));
     char **lines = backtrace_symbols(bt, size);
-- 
2.30.2

