From 17719dd9ab2b830b8c25a513931b28b5f1482721 Mon Sep 17 00:00:00 2001
From: Augustin Cavalier <waddlesplash@gmail.com>
Date: Wed, 30 Jul 2014 14:19:29 -0400
Subject: [PATCH] Fix build on Haiku.

---
 CMakeLists.txt                    | 24 ++++++++++++------------
 kdecore/CMakeLists.txt            |  4 ++--
 kdecore/io/kfilesystemtype_p.cpp  |  2 +-
 kdecore/io/kmountpoint.cpp        |  4 ++--
 kdecore/util/kshareddatacache_p.h |  2 +-
 kdewidgets/CMakeLists.txt         |  4 ++--
 kinit/CMakeLists.txt              |  2 ++
 kinit/kinit.cpp                   |  3 +++
 kio/kio/kprotocolmanager.cpp      |  2 ++
 kio/kio/previewjob.cpp            |  4 ++++
 kio/kio/slaveinterface_p.h        |  2 ++
 kio/misc/kpac/CMakeLists.txt      |  1 +
 kio/misc/kpac/kpac_dhcp_helper.c  |  5 +++++
 kioslave/http/CMakeLists.txt      |  6 ++++--
 kross/CMakeLists.txt              |  4 ++--
 solid/solid/CMakeLists.txt        |  3 ++-
 16 files changed, 47 insertions(+), 25 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a2620f6..5c48ce8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -188,9 +188,9 @@ endif(QCA2_FOUND)
 set(KDE4_KJS_INCLUDES ${CMAKE_SOURCE_DIR}/kjs
                       ${CMAKE_BINARY_DIR}/kjs)
 
-if(NOT WINCE)
+if(NOT WINCE AND NOT HAIKU)
     set(KDE4_KDECORE_INCLUDES ${KDE4_KJS_INCLUDES} )
-endif(NOT WINCE)
+endif(NOT WINCE AND NOT HAIKU)
 
 # kdecore depends on Qt (need only headers from kjs)
 set(KDE4_KDECORE_INCLUDES ${KDE4_KDECORE_INCLUDES}
@@ -256,9 +256,9 @@ set(KDE4_KDE3SUPPORT_INCLUDES ${CMAKE_SOURCE_DIR}/kde3support
                               ${CMAKE_SOURCE_DIR}/kde3support/kio
                               ${KDE4_KPARTS_INCLUDES})
 
-if(NOT WINCE)
+if(NOT WINCE AND NOT HAIKU)
  set(KDE4_KHTML_INCLUDES ${CMAKE_SOURCE_DIR}/khtml)
-endif(NOT WINCE)
+endif(NOT WINCE AND NOT HAIKU)
 
 
 ################# configure checks and create the configured files #################
@@ -316,20 +316,20 @@ check_library_exists(socket connect "" HAVE_SOCKET_LIBRARY)
 add_subdirectory( cmake )
 add_subdirectory( kdecore )
 add_subdirectory( kdeui )
-if (UNIX)
+if (UNIX AND NOT HAIKU)
    add_subdirectory( kpty )
    add_subdirectory( kdesu )
-endif (UNIX)
-if(NOT WINCE)
+endif (UNIX AND NOT HAIKU)
+if(NOT WINCE AND NOT HAIKU)
 add_subdirectory( kjs )
 add_subdirectory( kjsembed )
-endif(NOT WINCE)
+endif(NOT WINCE AND NOT HAIKU)
 add_subdirectory( kio )
 add_subdirectory( solid )
 add_subdirectory( kded       )
-if (QT_QT3SUPPORT_FOUND)
+if (QT_QT3SUPPORT_FOUND AND NOT HAIKU) # Uses POSIX stuff Haiku doesn't have
    add_subdirectory( kde3support  )
-endif (QT_QT3SUPPORT_FOUND)
+endif (QT_QT3SUPPORT_FOUND AND NOT HAIKU)
 add_subdirectory( kfile )
 add_subdirectory( kconf_update )
 if(NOT WINCE)
@@ -344,9 +344,9 @@ add_subdirectory( mimetypes  )
 add_subdirectory( kinit  )
 add_subdirectory( threadweaver )
 add_subdirectory( sonnet  )
-if(NOT WINCE)
+if(NOT WINCE AND NOT HAIKU)
 add_subdirectory( khtml  )
-endif(NOT WINCE)
+endif(NOT WINCE AND NOT HAIKU)
 add_subdirectory( interfaces  )
 #if ( NOT CMAKE_CROSSCOMPILING AND QT_QTDESIGNER_FOUND )
 add_subdirectory( kdewidgets  )
diff --git a/kdecore/CMakeLists.txt b/kdecore/CMakeLists.txt
index 082e252..a731b0a 100644
--- a/kdecore/CMakeLists.txt
+++ b/kdecore/CMakeLists.txt
@@ -517,7 +517,7 @@ install(TARGETS kde4-config ${INSTALL_TARGETS_DEFAULT_ARGS} )
 
 ########### next target ###############
 
-if(NOT WINCE)
+if(NOT WINCE AND NOT HAIKU)
     # kjs hash stuff for transcript plugin
     set( CREATE_HASH_TABLE ${CMAKE_SOURCE_DIR}/kjs/create_hash_table )
 
@@ -548,7 +548,7 @@ if(NOT WINCE)
 
     install( TARGETS ktranscript DESTINATION ${PLUGIN_INSTALL_DIR} )
 
-endif(NOT WINCE)
+endif(NOT WINCE AND NOT HAIKU)
 
 ########### install files ###############
 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/all_languages DESTINATION ${LOCALE_INSTALL_DIR}  )
diff --git a/kdecore/io/kfilesystemtype_p.cpp b/kdecore/io/kfilesystemtype_p.cpp
index 158f51d..ba0604c 100644
--- a/kdecore/io/kfilesystemtype_p.cpp
+++ b/kdecore/io/kfilesystemtype_p.cpp
@@ -129,11 +129,11 @@ KFileSystemType::Type determineFileSystemTypeImpl(const QByteArray& path)
 }
 #endif
 #else
+#endif
 KFileSystemType::Type determineFileSystemTypeImpl(const QByteArray& path)
 {
     return KFileSystemType::Unknown;
 }
-#endif
 
 KFileSystemType::Type KFileSystemType::fileSystemType(const QString& path)
 {
diff --git a/kdecore/io/kmountpoint.cpp b/kdecore/io/kmountpoint.cpp
index 96f5de9..d39b4cf 100644
--- a/kdecore/io/kmountpoint.cpp
+++ b/kdecore/io/kmountpoint.cpp
@@ -142,7 +142,7 @@ KMountPoint::~KMountPoint()
 #define MOUNTTYPE(var) var->mnt_type
 #define MOUNTOPTIONS(var) var->mnt_opts
 #define FSNAME(var) var->mnt_fsname
-#else
+#elif !defined(__HAIKU__)
 #define SETMNTENT fopen
 #define ENDMNTENT fclose
 #define STRUCT_MNTENT struct mnttab
@@ -421,7 +421,7 @@ KMountPoint::List KMountPoint::currentMountPoints(DetailsNeededFlags infoNeeded)
     mp->d->mountPoint = QString("/");
     result.append(mp);
 
-#else
+#elif !defined(__HAIKU__)
    STRUCT_SETMNTENT mnttab;
    if ((mnttab = SETMNTENT(MNTTAB, "r")) == 0)
       return result;
diff --git a/kdecore/util/kshareddatacache_p.h b/kdecore/util/kshareddatacache_p.h
index 931de4d..af10807 100644
--- a/kdecore/util/kshareddatacache_p.h
+++ b/kdecore/util/kshareddatacache_p.h
@@ -53,7 +53,7 @@ int ksdcArea();
 #define KSDC_THREAD_PROCESS_SHARED_SUPPORTED 1
 #endif
 
-#if defined(_POSIX_SEMAPHORES) && ((_POSIX_SEMAPHORES == 0) || (_POSIX_SEMAPHORES >= 200112L))
+#if !defined(Q_OS_HAIKU) && defined(_POSIX_SEMAPHORES) && ((_POSIX_SEMAPHORES == 0) || (_POSIX_SEMAPHORES >= 200112L))
 #include <semaphore.h>
 #define KSDC_SEMAPHORES_SUPPORTED 1
 #endif
diff --git a/kdewidgets/CMakeLists.txt b/kdewidgets/CMakeLists.txt
index 5153601..9aa1b5a 100644
--- a/kdewidgets/CMakeLists.txt
+++ b/kdewidgets/CMakeLists.txt
@@ -123,7 +123,7 @@ if(QT_QTDESIGNER_FOUND)
   install(TARGETS kdewebkitwidgets  DESTINATION ${PLUGIN_INSTALL_DIR}/plugins/designer )
 
 
-  if (QT_QT3SUPPORT_FOUND)
+  if (QT_QT3SUPPORT_FOUND AND NOT HAIKU)
 
      include_directories(
        ${CMAKE_SOURCE_DIR}/kde3support
@@ -157,7 +157,7 @@ if(QT_QTDESIGNER_FOUND)
      endif(NOT WIN32)
 
      install(TARGETS kde3supportwidgets  DESTINATION ${PLUGIN_INSTALL_DIR}/plugins/designer )
-  endif (QT_QT3SUPPORT_FOUND)
+  endif (QT_QT3SUPPORT_FOUND AND NOT HAIKU)
 endif (QT_QTDESIGNER_FOUND)
 
 ########### install files ###############
diff --git a/kinit/CMakeLists.txt b/kinit/CMakeLists.txt
index dcde429..1eda927 100644
--- a/kinit/CMakeLists.txt
+++ b/kinit/CMakeLists.txt
@@ -21,6 +21,8 @@ check_function_exists(setproctitle HAVE_SETPROCTITLE)
 # used by 4 executables in this file
 if(HAVE_SOCKET_LIBRARY)
   set(KINIT_SOCKET_LIBRARY socket)
+elseif(HAIKU)
+  set(KINIT_SOCKET_LIBRARY network)
 else(HAVE_SOCKET_LIBRARY)
   set(KINIT_SOCKET_LIBRARY)
 endif(HAVE_SOCKET_LIBRARY)
diff --git a/kinit/kinit.cpp b/kinit/kinit.cpp
index e41845a..c688356 100644
--- a/kinit/kinit.cpp
+++ b/kinit/kinit.cpp
@@ -119,6 +119,9 @@ static char sock_file[MAX_SOCK_FILE];
 #define DISPLAY "MAC_DISPLAY"
 #elif defined(Q_WS_WIN)
 #define DISPLAY "WIN_DISPLAY"
+#elif defined(Q_OS_HAIKU)
+/* this will do nothing! */
+#define DISPLAY "DISPLAY_HAIKU_NONEXISTENT"
 #else
 #error Use QT/X11 or QT/Embedded
 #endif
diff --git a/kio/kio/kprotocolmanager.cpp b/kio/kio/kprotocolmanager.cpp
index f1f356e..4e29021 100644
--- a/kio/kio/kprotocolmanager.cpp
+++ b/kio/kio/kprotocolmanager.cpp
@@ -657,6 +657,8 @@ static QString platform()
      return QL1S("Windows");
 #elif defined(Q_WS_S60)
      return QL1S("Symbian");
+#elif defined(Q_OS_HAIKU)
+     return QL1S("Haiku");
 #endif
 }
 
diff --git a/kio/kio/previewjob.cpp b/kio/kio/previewjob.cpp
index 01b674d..0a159d0 100644
--- a/kio/kio/previewjob.cpp
+++ b/kio/kio/previewjob.cpp
@@ -27,6 +27,10 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#ifdef Q_OS_HAIKU
+#undef Q_OS_UNIX // We don't have sys/shm.h
+#endif
+
 #ifdef Q_OS_UNIX
 #include <sys/ipc.h>
 #include <sys/shm.h>
diff --git a/kio/kio/slaveinterface_p.h b/kio/kio/slaveinterface_p.h
index eb95a09..20355f5 100644
--- a/kio/kio/slaveinterface_p.h
+++ b/kio/kio/slaveinterface_p.h
@@ -19,6 +19,8 @@
 #ifndef KIO_SLAVEINTERFACEPRIVATE_H
 #define KIO_SLAVEINTERFACEPRIVATE_H
 
+#include <sys/time.h>
+
 #include "global.h"
 #include "connection.h"
 #include <QtCore/QTimer>
diff --git a/kio/misc/kpac/CMakeLists.txt b/kio/misc/kpac/CMakeLists.txt
index 81fa79a..2e36926 100644
--- a/kio/misc/kpac/CMakeLists.txt
+++ b/kio/misc/kpac/CMakeLists.txt
@@ -40,6 +40,7 @@ install(TARGETS kded_proxyscout  DESTINATION ${PLUGIN_INSTALL_DIR} )
 set(kpac_dhcp_helper_SRCS kpac_dhcp_helper.c)
 
 kde4_add_executable(kpac_dhcp_helper NOGUI ${kpac_dhcp_helper_SRCS})
+target_link_libraries(kpac_dhcp_helper network)
 
 if (HAVE_NSL_LIBRARY)
   # Assume Solaris
diff --git a/kio/misc/kpac/kpac_dhcp_helper.c b/kio/misc/kpac/kpac_dhcp_helper.c
index c5c38eb..419b022 100644
--- a/kio/misc/kpac/kpac_dhcp_helper.c
+++ b/kio/misc/kpac/kpac_dhcp_helper.c
@@ -29,7 +29,9 @@
 
 #include <grp.h>
 #include <netdb.h>
+#ifndef __HAIKU__
 #include <ifaddrs.h>
+#endif
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -169,6 +171,7 @@ static struct response send_request_for(int sock, const char* hostname)
 /* Fills the DHCPINFORM request packet, returns the transaction id */
 static uint32_t send_request(int sock)
 {
+#ifndef __HAIKU__
     char hostname[NI_MAXHOST];
     struct ifaddrs *ifaddr, *ifa;
     int status = -1;
@@ -207,6 +210,8 @@ static uint32_t send_request(int sock)
       exit(1);
 
     return status;
+#endif
+    exit(1);
 }
 
 /* Reads the reply from the socket, checks it and outputs the URL to STDOUT */
diff --git a/kioslave/http/CMakeLists.txt b/kioslave/http/CMakeLists.txt
index cea76f5..6f6dd86 100644
--- a/kioslave/http/CMakeLists.txt
+++ b/kioslave/http/CMakeLists.txt
@@ -31,8 +31,10 @@ include_directories( ${KDE4_KIO_INCLUDES} ${ZLIB_INCLUDE_DIR} ${CMAKE_SOURCE_DIR
                      ${CMAKE_BINARY_DIR}/solid )
 include_directories( ${CMAKE_SOURCE_DIR}/interfaces ${CMAKE_SOURCE_DIR}/kio/httpfilter )
 
-add_subdirectory( kcookiejar )
-add_subdirectory( tests )
+if(NOT HAIKU)
+    add_subdirectory( kcookiejar )
+    add_subdirectory( tests )
+endif()
 
 ########### next target ###############
 
diff --git a/kross/CMakeLists.txt b/kross/CMakeLists.txt
index dc559f0..c6fcb1e 100644
--- a/kross/CMakeLists.txt
+++ b/kross/CMakeLists.txt
@@ -12,9 +12,9 @@ add_subdirectory( test )
 
 # KDE Javascript using kjs and kjsembed
 # test kjsembed I think
-if (NOT WINCE)
+if (NOT WINCE AND NOT HAIKU)
 add_subdirectory( kjs )
-endif(NOT WINCE)
+endif(NOT WINCE AND NOT HAIKU)
 
 # QtScript backend
 add_subdirectory( qts )
diff --git a/solid/solid/CMakeLists.txt b/solid/solid/CMakeLists.txt
index a7f1f07..5372c75 100644
--- a/solid/solid/CMakeLists.txt
+++ b/solid/solid/CMakeLists.txt
@@ -324,6 +324,7 @@ if(NOT WIN32 AND NOT APPLE)
        endif ( WITH_SOLID_UDISKS2 )
    endif (CMAKE_SYSTEM_NAME MATCHES Linux)
 
+if(NOT HAIKU)
    message(STATUS "Building Solid fstab backend." )
    set(solid_LIB_SRCS ${solid_LIB_SRCS}
    backends/fstab/fstabmanager.cpp
@@ -333,7 +334,7 @@ if(NOT WIN32 AND NOT APPLE)
    backends/fstab/fstabhandling.cpp
    backends/fstab/fstabwatcher.cpp
    )
-
+endif(NOT HAIKU)
 endif(NOT WIN32 AND NOT APPLE)
 
 if(APPLE)
-- 
1.8.3.4

