From 63b3bcd0d6804a07fe94d9af0fc7a7810fab538d Mon Sep 17 00:00:00 2001
From: Ingo Weinhold <ingo_weinhold@gmx.de>
Date: Sun, 16 Jun 2013 21:42:39 +0200
Subject: Haiku specific changes


diff --git a/Modules/CMakeFortranCompilerId.F.in b/Modules/CMakeFortranCompilerId.F.in
index 4d25de0..f84852a 100644
--- a/Modules/CMakeFortranCompilerId.F.in
+++ b/Modules/CMakeFortranCompilerId.F.in
@@ -74,12 +74,8 @@
         PRINT *, 'INFO:platform[IRIX]'
 #elif defined(__hpux) || defined(__hpux__)
         PRINT *, 'INFO:platform[HP-UX]'
-#elif defined(__HAIKU) || defined(__HAIKU__) || defined(_HAIKU)
+#elif defined(__HAIKU__)
         PRINT *, 'INFO:platform[Haiku]'
-#       if 0
-!       Haiku also defines __BEOS__ so we must
-!       put it prior to the check for __BEOS__
-#       endif
 #elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS)
         PRINT *, 'INFO:platform[BeOS]'
 #elif defined(__QNX__) || defined(__QNXNTO__)
diff --git a/Modules/CMakePlatformId.h.in b/Modules/CMakePlatformId.h.in
index cb3f40a..db98bc3 100644
--- a/Modules/CMakePlatformId.h.in
+++ b/Modules/CMakePlatformId.h.in
@@ -35,11 +35,8 @@
 #elif defined(__hpux) || defined(__hpux__)
 # define PLATFORM_ID "HP-UX"
 
-#elif defined(__HAIKU) || defined(__HAIKU__) || defined(_HAIKU)
+#elif defined(__HAIKU__)
 # define PLATFORM_ID "Haiku"
-/* Haiku also defines __BEOS__ so we must 
-   put it prior to the check for __BEOS__
-*/
 
 #elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS)
 # define PLATFORM_ID "BeOS"
diff --git a/Modules/CheckForPthreads.c b/Modules/CheckForPthreads.c
index d831078..02526fb 100644
--- a/Modules/CheckForPthreads.c
+++ b/Modules/CheckForPthreads.c
@@ -16,7 +16,7 @@ int main(int ac, char*av[]){
   pthread_create(&tid[0], 0, runner, (void*)1);
   pthread_create(&tid[1], 0, runner, (void*)2);
   
-#if defined(__BEOS__) && !defined(__ZETA__)  && !defined(__HAIKU__) // (no usleep on BeOS 5.)
+#if defined(__BEOS__) && !defined(__ZETA__) // (no usleep on BeOS 5.)
   usleep(1); // for strange behavior on single-processor sun
 #endif
 
diff --git a/Modules/FindGLUT.cmake b/Modules/FindGLUT.cmake
index af88997..8c0a733 100644
--- a/Modules/FindGLUT.cmake
+++ b/Modules/FindGLUT.cmake
@@ -46,20 +46,22 @@ ELSE (WIN32)
       /usr/openwin/include
       /opt/graphics/OpenGL/include
       /opt/graphics/OpenGL/contrib/libglut
+      /boot/system/develop/headers/os/opengl
       )
   
     FIND_LIBRARY( GLUT_glut_LIBRARY glut
       /usr/openwin/lib
       )
-    
-    FIND_LIBRARY( GLUT_Xi_LIBRARY Xi
-      /usr/openwin/lib
-      )
-    
-    FIND_LIBRARY( GLUT_Xmu_LIBRARY Xmu
-      /usr/openwin/lib
-      )
-    
+
+    IF(NOT BEOS AND NOT HAIKU)
+      FIND_LIBRARY( GLUT_Xi_LIBRARY Xi
+        /usr/openwin/lib
+        )
+
+      FIND_LIBRARY( GLUT_Xmu_LIBRARY Xmu
+        /usr/openwin/lib
+        )
+    ENDIF(NOT BEOS AND NOT HAIKU)
   ENDIF (APPLE)
   
 ENDIF (WIN32)
@@ -69,12 +71,18 @@ IF(GLUT_INCLUDE_DIR)
   IF(GLUT_glut_LIBRARY)
     # Is -lXi and -lXmu required on all platforms that have it?
     # If not, we need some way to figure out what platform we are on.
-    SET( GLUT_LIBRARIES
-      ${GLUT_glut_LIBRARY}
-      ${GLUT_Xmu_LIBRARY}
-      ${GLUT_Xi_LIBRARY} 
-      ${GLUT_cocoa_LIBRARY}
-      )
+    IF(BEOS OR HAIKU)
+      SET( GLUT_LIBRARIES
+        ${GLUT_glut_LIBRARY}
+        )
+    ELSE(BEOS OR HAIKU)
+      SET( GLUT_LIBRARIES
+        ${GLUT_glut_LIBRARY}
+        ${GLUT_Xmu_LIBRARY}
+        ${GLUT_Xi_LIBRARY} 
+        ${GLUT_cocoa_LIBRARY}
+        )
+    ENDIF(BEOS OR HAIKU)
     SET( GLUT_FOUND "YES" )
     
     #The following deprecated settings are for backwards compatibility with CMake1.4
@@ -84,9 +92,16 @@ IF(GLUT_INCLUDE_DIR)
   ENDIF(GLUT_glut_LIBRARY)
 ENDIF(GLUT_INCLUDE_DIR)
 
-MARK_AS_ADVANCED(
-  GLUT_INCLUDE_DIR
-  GLUT_glut_LIBRARY
-  GLUT_Xmu_LIBRARY
-  GLUT_Xi_LIBRARY
-  )
+IF(BEOS OR HAIKU)
+  MARK_AS_ADVANCED(
+    GLUT_INCLUDE_DIR
+    GLUT_glut_LIBRARY
+    )
+ELSE(BEOS OR HAIKU)
+  MARK_AS_ADVANCED(
+    GLUT_INCLUDE_DIR
+    GLUT_glut_LIBRARY
+    GLUT_Xmu_LIBRARY
+    GLUT_Xi_LIBRARY
+    )
+ENDIF(BEOS OR HAIKU)
diff --git a/Modules/FindLua51.cmake b/Modules/FindLua51.cmake
index 123fd5d..5047fbd 100644
--- a/Modules/FindLua51.cmake
+++ b/Modules/FindLua51.cmake
@@ -57,13 +57,13 @@ FIND_LIBRARY(LUA_LIBRARY
 
 IF(LUA_LIBRARY)
   # include the math library for Unix
-  IF(UNIX AND NOT APPLE)
+  IF(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU)
     FIND_LIBRARY(LUA_MATH_LIBRARY m)
     SET( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
   # For Windows and Mac, don't need to explicitly include the math library
   ELSE(UNIX AND NOT APPLE)
     SET( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
-  ENDIF(UNIX AND NOT APPLE)
+  ENDIF(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU)
 ENDIF(LUA_LIBRARY)
 
 INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
diff --git a/Modules/FindOpenGL.cmake b/Modules/FindOpenGL.cmake
index 98d8808..1ac4de6 100644
--- a/Modules/FindOpenGL.cmake
+++ b/Modules/FindOpenGL.cmake
@@ -80,6 +80,7 @@ ELSE (WIN32)
       /usr/share/doc/NVIDIA_GLX-1.0/include
       /usr/openwin/share/include
       /opt/graphics/OpenGL/include /usr/X11R6/include
+      /boot/system/develop/headers/os/opengl
     )
 
     FIND_PATH(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h
diff --git a/Modules/Platform/Haiku.cmake b/Modules/Platform/Haiku.cmake
index 8277a24..7eb0bd5 100644
--- a/Modules/Platform/Haiku.cmake
+++ b/Modules/Platform/Haiku.cmake
@@ -1,20 +1,121 @@
-SET(BEOS 1)
+# process only once
+IF(HAIKU)
+  RETURN()
+ENDIF(HAIKU)
 
-SET(CMAKE_DL_LIBS root be)
+SET(HAIKU 1)
+SET(UNIX 1)
+
+SET(CMAKE_DL_LIBS "")
 SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")
-SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-nostart")
+SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared")
 SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
 SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")
+SET(CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG "-Wl,-rpath-link,")
 SET(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
+SET(CMAKE_EXE_EXPORTS_C_FLAG "-Wl,--export-dynamic")
+
+# Determine, if the C or C++ compiler is configured for a secondary
+# architecture. If so, that will change the search paths we set below. We check
+# whether the compiler's library search paths contain a
+# "/boot/system/develop/lib/<subdir>/", which we assume to be the secondary
+# architecture specific subdirectory and extract the name of the architecture
+# accordingly.
+SET(HAIKU_COMPILER ${CMAKE_C_COMPILER})
+IF ("${HAIKU_COMPILER}" STREQUAL "")
+  SET(HAIKU_COMPILER ${CMAKE_CXX_COMPILER})
+ENDIF ("${HAIKU_COMPILER}" STREQUAL "")
+EXECUTE_PROCESS(
+  COMMAND ${HAIKU_COMPILER} -print-search-dirs
+  COMMAND sed -ne "/^libraries:/!d; s,libraries: =*\\(.*\\):,\\1,; s,:,\\n,gp"
+  COMMAND sed -ne "/\\/boot\\/system\\/develop\\/lib\\/[^\\/]*\\/$/!d; s,.*/\\([^/]*\\)/$,\\1,; p"
+  OUTPUT_VARIABLE CMAKE_HAIKU_SECONDARY_ARCH)
+STRING(STRIP "${CMAKE_HAIKU_SECONDARY_ARCH}"
+  CMAKE_HAIKU_SECONDARY_ARCH)
+
+IF ("${CMAKE_HAIKU_SECONDARY_ARCH}" STREQUAL "")
+  SET(CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR "")
+  UNSET(CMAKE_HAIKU_SECONDARY_ARCH)
+ELSE ("${CMAKE_HAIKU_SECONDARY_ARCH}" STREQUAL "")
+  SET(CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR "/${CMAKE_HAIKU_SECONDARY_ARCH}")
+
+  # Override CMAKE_*LIBRARY_ARCHITECTURE. This will cause FIND_LIBRARY to search
+  # the libraries in the correct subdirectory first. It still isn't completely
+  # correct, since the parent directories shouldn't be searched at all. The
+  # primary architecture library might still be found, if there isn't one
+  # installed for the secondary architecture or it is installed in a less
+  # specific location.
+  SET(CMAKE_LIBRARY_ARCHITECTURE ${CMAKE_HAIKU_SECONDARY_ARCH})
+  SET(CMAKE_C_LIBRARY_ARCHITECTURE ${CMAKE_HAIKU_SECONDARY_ARCH})
+  SET(CMAKE_CXX_LIBRARY_ARCHITECTURE ${CMAKE_HAIKU_SECONDARY_ARCH})
+ENDIF ("${CMAKE_HAIKU_SECONDARY_ARCH}" STREQUAL "")
+
+LIST(APPEND CMAKE_SYSTEM_PREFIX_PATH
+  /boot/common/non-packaged
+  /boot/common
+  /boot/system
+  )
+
+LIST(APPEND CMAKE_HAIKU_COMMON_INCLUDE_DIRECTORIES
+  /boot/common/non-packaged/develop/headers${CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR}
+  /boot/common/develop/headers${CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR}
+  /boot/system/develop/headers/os
+  /boot/system/develop/headers/os/app
+  /boot/system/develop/headers/os/device
+  /boot/system/develop/headers/os/drivers
+  /boot/system/develop/headers/os/game
+  /boot/system/develop/headers/os/interface
+  /boot/system/develop/headers/os/kernel
+  /boot/system/develop/headers/os/locale
+  /boot/system/develop/headers/os/mail
+  /boot/system/develop/headers/os/media
+  /boot/system/develop/headers/os/midi
+  /boot/system/develop/headers/os/midi2
+  /boot/system/develop/headers/os/net
+  /boot/system/develop/headers/os/opengl
+  /boot/system/develop/headers/os/storage
+  /boot/system/develop/headers/os/support
+  /boot/system/develop/headers/os/translation
+  /boot/system/develop/headers/os/add-ons/graphics
+  /boot/system/develop/headers/os/add-ons/input_server
+  /boot/system/develop/headers/os/add-ons/screen_saver
+  /boot/system/develop/headers/os/add-ons/tracker
+  /boot/system/develop/headers/os/be_apps/Deskbar
+  /boot/system/develop/headers/os/be_apps/NetPositive
+  /boot/system/develop/headers/os/be_apps/Tracker
+  /boot/system/develop/headers/3rdparty
+  /boot/system/develop/headers/bsd
+  /boot/system/develop/headers/glibc
+  /boot/system/develop/headers/gnu
+  /boot/system/develop/headers/posix
+  /boot/system/develop/headers${CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR}
+  )
+IF (CMAKE_HAIKU_SECONDARY_ARCH)
+  LIST(APPEND CMAKE_HAIKU_COMMON_INCLUDE_DIRECTORIES
+    /boot/system/develop/headers
+    )
+ENDIF (CMAKE_HAIKU_SECONDARY_ARCH)
+
+LIST(APPEND CMAKE_HAIKU_C_INCLUDE_DIRECTORIES
+  ${CMAKE_HAIKU_COMMON_INCLUDE_DIRECTORIES}
+  )
+
+LIST(APPEND CMAKE_HAIKU_CXX_INCLUDE_DIRECTORIES
+  ${CMAKE_HAIKU_COMMON_INCLUDE_DIRECTORIES})
+
+LIST(APPEND CMAKE_SYSTEM_INCLUDE_PATH ${CMAKE_HAIKU_C_INCLUDE_DIRECTORIES})
+
+LIST(APPEND CMAKE_HAIKU_DEVELOP_LIB_DIRECTORIES
+  /boot/common/non-packaged/develop/lib${CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR}
+  /boot/common/develop/lib${CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR}
+  /boot/system/develop/lib${CMAKE_HAIKU_SECONDARY_ARCH_SUBDIR}
+  )
+
+LIST(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
+  ${CMAKE_HAIKU_DEVELOP_LIB_DIRECTORIES}
+  )
 
-INCLUDE(Platform/UnixPaths)
-LIST(APPEND CMAKE_SYSTEM_PREFIX_PATH /boot/common)
-LIST(APPEND CMAKE_SYSTEM_INCLUDE_PATH /boot/common/include)
-LIST(APPEND CMAKE_SYSTEM_LIBRARY_PATH /boot/common/lib)
-LIST(APPEND CMAKE_SYSTEM_PROGRAM_PATH /boot/common/bin)
-LIST(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES /boot/common/lib)
-LIST(APPEND CMAKE_SYSTEM_INCLUDE_PATH /boot/develop/headers/3rdparty)
-LIST(APPEND CMAKE_SYSTEM_LIBRARY_PATH /boot/develop/lib/x86)
+LIST(APPEND CMAKE_SYSTEM_LIBRARY_PATH ${CMAKE_HAIKU_DEVELOP_LIB_DIRECTORIES})
 
 IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
   SET(CMAKE_INSTALL_PREFIX "/boot/common" CACHE PATH
diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx
index 7e5b26d..733c521 100644
--- a/Source/CPack/cmCPackGenerator.cxx
+++ b/Source/CPack/cmCPackGenerator.cxx
@@ -27,7 +27,8 @@
 #include <algorithm>
 
 #if defined(__HAIKU__)
-#include <StorageKit.h>
+#include <FindDirectory.h>
+#include <StorageDefs.h>
 #endif
 
 //----------------------------------------------------------------------
@@ -1206,10 +1207,10 @@ const char* cmCPackGenerator::GetInstallPath()
   this->InstallPath += "-";
   this->InstallPath += this->GetOption("CPACK_PACKAGE_VERSION");
 #elif defined(__HAIKU__)
-  BPath dir;
-  if (find_directory(B_COMMON_DIRECTORY, &dir) == B_OK)
+  char dir[B_PATH_NAME_LENGTH];
+  if (find_directory(B_COMMON_DIRECTORY, -1, false, dir, sizeof(dir)) == B_OK)
     {
-    this->InstallPath = dir.Path();
+    this->InstallPath = dir;
     }
   else
     {
diff --git a/Source/CPack/cmCPackGeneratorFactory.cxx b/Source/CPack/cmCPackGeneratorFactory.cxx
index a04b403..878e8c0 100644
--- a/Source/CPack/cmCPackGeneratorFactory.cxx
+++ b/Source/CPack/cmCPackGeneratorFactory.cxx
@@ -32,7 +32,7 @@
 #endif
 
 #if !defined(_WIN32) && !defined(__APPLE__) \
- && !defined(__QNXNTO__) && !defined(__BEOS__)
+ && !defined(__QNXNTO__) && !defined(__BEOS__) && !defined(__HAIKU__)
 #  include "cmCPackDebGenerator.h"
 #  include "cmCPackRPMGenerator.h"
 #endif
@@ -73,7 +73,7 @@ cmCPackGeneratorFactory::cmCPackGeneratorFactory()
     cmCPackOSXX11Generator::CreateGenerator);
 #endif
 #if !defined(_WIN32) && !defined(__APPLE__) \
-  && !defined(__QNXNTO__) && !defined(__BEOS__)
+  && !defined(__QNXNTO__) && !defined(__BEOS__) && !defined(__HAIKU__)
   this->RegisterGenerator("DEB", "Debian packages",
     cmCPackDebGenerator::CreateGenerator);
   this->RegisterGenerator("RPM", "RPM packages",
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index 75a564e..83e3c6e 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -53,14 +53,10 @@
 #include <cm_zlib.h>
 #include <cmsys/Base64.h>
 
-#if defined(__BEOS__) && !defined(__HAIKU__)
+#if defined(__BEOS__) || defined(__HAIKU__)
 #include <be/kernel/OS.h>   /* disable_debugger() API. */
 #endif
 
-#if defined(__HAIKU__)
-#include <os/kernel/OS.h>   /* disable_debugger() API. */
-#endif
-
 
 #define DEBUGOUT std::cout << __LINE__ << " "; std::cout
 #define DEBUGERR std::cerr << __LINE__ << " "; std::cerr
diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx
index cb614d4..1954662 100644
--- a/Source/cmExportCommand.cxx
+++ b/Source/cmExportCommand.cxx
@@ -20,7 +20,8 @@
 #include "cmExportBuildFileGenerator.h"
 
 #if defined(__HAIKU__)
-#include <StorageKit.h>
+#include <FindDirectory.h>
+#include <StorageDefs.h>
 #endif
 
 cmExportCommand::cmExportCommand()
@@ -297,14 +298,15 @@ void cmExportCommand::StorePackageRegistryDir(std::string const& package,
                                               const char* hash)
 {
 #if defined(__HAIKU__)
-  BPath dir;
-  if (find_directory(B_USER_SETTINGS_DIRECTORY, &dir) != B_OK)
+  char dir[B_PATH_NAME_LENGTH];
+  if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, dir, sizeof(dir)) !=
+      B_OK)
     {
     return;
     }
-  dir.Append("cmake/packages");
-  dir.Append(package.c_str());
-  std::string fname = dir.Path();
+  std::string fname = dir;
+  fname += "/cmake/packages/";
+  fname += package;
 #else
   const char* home = cmSystemTools::GetEnv("HOME");
   if(!home)
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index 5f106bc..a2f9823 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -19,7 +19,9 @@
 #endif
 
 #if defined(__HAIKU__)
-#include <StorageKit.h>
+#include <string.h>
+#include <FindDirectory.h>
+#include <StorageDefs.h>
 #endif
 
 void cmFindPackageNeedBackwardsCompatibility(const std::string& variable,
@@ -1292,12 +1294,13 @@ void cmFindPackageCommand::AddPrefixesUserRegistry()
 #if defined(_WIN32) && !defined(__CYGWIN__)
   this->LoadPackageRegistryWinUser();
 #elif defined(__HAIKU__)
-  BPath dir;
-  if (find_directory(B_USER_SETTINGS_DIRECTORY, &dir) == B_OK)
+  char dir[B_PATH_NAME_LENGTH];
+  if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, dir, sizeof(dir)) ==
+      B_OK)
     {
-    dir.Append("cmake/packages");
-    dir.Append(this->Name.c_str());
-    this->LoadPackageRegistryDir(dir.Path());
+    strlcat(dir, "/cmake/packages/", sizeof(dir));
+    strlcat(dir, this->Name.c_str(), sizeof(dir));
+    this->LoadPackageRegistryDir(dir);
     }
 #else
   if(const char* home = cmSystemTools::GetEnv("HOME"))
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 7da35eb..5867030 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -37,7 +37,8 @@
 #include <assert.h>
 
 #if defined(__HAIKU__)
-#include <StorageKit.h>
+#include <FindDirectory.h>
+#include <StorageDefs.h>
 #endif
 
 cmLocalGenerator::cmLocalGenerator()
@@ -354,12 +355,12 @@ void cmLocalGenerator::GenerateInstallRules()
     prefix = prefix_win32.c_str();
     }
 #elif defined(__HAIKU__)
+  char dir[B_PATH_NAME_LENGTH];
   if (!prefix)
     {
-    BPath dir;
-    if (find_directory(B_COMMON_DIRECTORY, &dir) == B_OK)
+    if (find_directory(B_COMMON_DIRECTORY, -1, false, dir, sizeof(dir)) == B_OK)
       {
-      prefix = dir.Path();
+      prefix = dir;
       }
     else
       {
diff --git a/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c
index 9c66a44..6fe4232 100644
--- a/Source/kwsys/ProcessUNIX.c
+++ b/Source/kwsys/ProcessUNIX.c
@@ -63,10 +63,6 @@ do.
 #include <dirent.h>    /* DIR, dirent */
 #include <ctype.h>     /* isspace */
 
-#ifdef __HAIKU__
-#undef __BEOS__
-#endif
-
 #if defined(__VMS)
 # define KWSYSPE_VMS_NONBLOCK , O_NONBLOCK
 #else
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index eefa7f5..8798615 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -145,12 +145,7 @@ public:
 #define _chdir chdir
 #endif
 
-#if defined(__HAIKU__)
-#include <os/kernel/OS.h>
-#include <os/storage/Path.h>
-#endif
-
-#if defined(__BEOS__) && !defined(__ZETA__) && !defined(__HAIKU__)
+#if defined(__BEOS__) && !defined(__ZETA__)
 #include <be/kernel/OS.h>
 #include <be/storage/Path.h>
 
diff --git a/Source/kwsys/testDynamicLoader.cxx b/Source/kwsys/testDynamicLoader.cxx
index a7adbca..16b89ad 100644
--- a/Source/kwsys/testDynamicLoader.cxx
+++ b/Source/kwsys/testDynamicLoader.cxx
@@ -15,14 +15,10 @@
 #include KWSYS_HEADER(ios/iostream)
 #include KWSYS_HEADER(stl/string)
 
-#if defined(__BEOS__) && !defined(__HAIKU__)
+#if defined(__BEOS__) || defined(__HAIKU__)
 #include <be/kernel/OS.h>  /* disable_debugger() API. */
 #endif
 
-#if defined(__HAIKU__)
-#include <os/kernel/OS.h>  /* disable_debugger() API. */
-#endif
-
 // Work-around CMake dependency scanning limitation.  This must
 // duplicate the above list of headers.
 #if 0
diff --git a/Source/kwsys/testProcess.c b/Source/kwsys/testProcess.c
index 877002a..17a068c 100644
--- a/Source/kwsys/testProcess.c
+++ b/Source/kwsys/testProcess.c
@@ -32,7 +32,7 @@
 # pragma warn -8060 /* possibly incorrect assignment */
 #endif
 
-#if defined(__BEOS__) && !defined(__ZETA__) && !defined(__HAIKU__)
+#if defined(__BEOS__) && !defined(__ZETA__)
 /* BeOS 5 doesn't have usleep(), but it has snooze(), which is identical. */
 # include <be/kernel/OS.h>
 static inline void testProcess_usleep(unsigned int msec)
diff --git a/Tests/Complex/Library/CMakeLists.txt b/Tests/Complex/Library/CMakeLists.txt
index 281e48a..7d8adb2 100644
--- a/Tests/Complex/Library/CMakeLists.txt
+++ b/Tests/Complex/Library/CMakeLists.txt
@@ -52,9 +52,9 @@ DEFINE_PROPERTY(
   FULL_DOCS "A simple etst proerty that means nothign and is used for nothing"
   )
 SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR)
-IF(NOT BEOS AND NOT WIN32)  # No libm on BeOS.
+IF(NOT BEOS AND NOT WIN32 AND NOT HAIKU)  # No libm on BeOS.
   SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES LINK_FLAGS "-lm")
-ENDIF(NOT BEOS AND NOT WIN32)
+ENDIF(NOT BEOS AND NOT WIN32 AND NOT HAIKU)
 GET_TARGET_PROPERTY(FOO_BAR_VAR CMakeTestCLibraryShared FOO)
 IF(${FOO_BAR_VAR} MATCHES "BAR")
 ELSE(${FOO_BAR_VAR} MATCHES "BAR")
diff --git a/Tests/ComplexOneConfig/Library/CMakeLists.txt b/Tests/ComplexOneConfig/Library/CMakeLists.txt
index 281e48a..7d8adb2 100644
--- a/Tests/ComplexOneConfig/Library/CMakeLists.txt
+++ b/Tests/ComplexOneConfig/Library/CMakeLists.txt
@@ -52,9 +52,9 @@ DEFINE_PROPERTY(
   FULL_DOCS "A simple etst proerty that means nothign and is used for nothing"
   )
 SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR)
-IF(NOT BEOS AND NOT WIN32)  # No libm on BeOS.
+IF(NOT BEOS AND NOT WIN32 AND NOT HAIKU)  # No libm on BeOS.
   SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES LINK_FLAGS "-lm")
-ENDIF(NOT BEOS AND NOT WIN32)
+ENDIF(NOT BEOS AND NOT WIN32 AND NOT HAIKU)
 GET_TARGET_PROPERTY(FOO_BAR_VAR CMakeTestCLibraryShared FOO)
 IF(${FOO_BAR_VAR} MATCHES "BAR")
 ELSE(${FOO_BAR_VAR} MATCHES "BAR")
diff --git a/Tests/ComplexRelativePaths/Library/CMakeLists.txt b/Tests/ComplexRelativePaths/Library/CMakeLists.txt
index 281e48a..7d8adb2 100644
--- a/Tests/ComplexRelativePaths/Library/CMakeLists.txt
+++ b/Tests/ComplexRelativePaths/Library/CMakeLists.txt
@@ -52,9 +52,9 @@ DEFINE_PROPERTY(
   FULL_DOCS "A simple etst proerty that means nothign and is used for nothing"
   )
 SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR)
-IF(NOT BEOS AND NOT WIN32)  # No libm on BeOS.
+IF(NOT BEOS AND NOT WIN32 AND NOT HAIKU)  # No libm on BeOS.
   SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES LINK_FLAGS "-lm")
-ENDIF(NOT BEOS AND NOT WIN32)
+ENDIF(NOT BEOS AND NOT WIN32 AND NOT HAIKU)
 GET_TARGET_PROPERTY(FOO_BAR_VAR CMakeTestCLibraryShared FOO)
 IF(${FOO_BAR_VAR} MATCHES "BAR")
 ELSE(${FOO_BAR_VAR} MATCHES "BAR")
diff --git a/Utilities/cmcurl/CMake/CurlTests.c b/Utilities/cmcurl/CMake/CurlTests.c
index d74a4f0..c5ba7c2 100644
--- a/Utilities/cmcurl/CMake/CurlTests.c
+++ b/Utilities/cmcurl/CMake/CurlTests.c
@@ -38,7 +38,7 @@ main ()
 # define PLATFORM_AIX_V3
 #endif
 
-#if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || (defined(__BEOS__) && !defined(__HAIKU__))
+#if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
 #error "O_NONBLOCK does not work on this platform"
 #endif
   int socket;
diff --git a/Utilities/cmcurl/select.c b/Utilities/cmcurl/select.c
index 51adbcf..82f9dc2 100644
--- a/Utilities/cmcurl/select.c
+++ b/Utilities/cmcurl/select.c
@@ -39,7 +39,7 @@
 #error "We can't compile without select() support!"
 #endif
 
-#if defined(__BEOS__) && !defined(__HAIKU__)
+#if defined(__BEOS__)
 /* BeOS has FD_SET defined in socket.h */
 #include <socket.h>
 #endif
diff --git a/Utilities/cmzlib/zconf.h b/Utilities/cmzlib/zconf.h
index 6eb52d1..7a3b6fd 100644
--- a/Utilities/cmzlib/zconf.h
+++ b/Utilities/cmzlib/zconf.h
@@ -237,7 +237,7 @@
 #  endif
 #endif
 
-#if defined (__BEOS__) && !defined (__HAIKU__)
+#if defined (__BEOS__)
 #  ifdef ZLIB_DLL
 #    ifdef ZLIB_INTERNAL
 #      define ZEXPORT   __declspec(dllexport)
diff --git a/Utilities/cmzlib/zutil.h b/Utilities/cmzlib/zutil.h
index 74ef1f8..3053cd8 100644
--- a/Utilities/cmzlib/zutil.h
+++ b/Utilities/cmzlib/zutil.h
@@ -147,12 +147,6 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
 #  define OS_CODE  0x0f
 #endif
 
-/* Haiku defines both __HAIKU__ and __BEOS__ (for now) */
-/* many BeOS workarounds are no longer needed in Haiku */
-#if defined(__HAIKU__) && defined(__BEOS__)
-#undef __BEOS__
-#endif
-
 #if defined(_BEOS_) || defined(RISCOS) 
 #  define fdopen(fd,mode) NULL /* No fdopen() */
 #endif
diff --git a/bootstrap b/bootstrap
index c999888..c573a90 100755
--- a/bootstrap
+++ b/bootstrap
@@ -142,7 +142,9 @@ if ${cmake_system_mingw}; then
     cmake_default_prefix="c:/Program Files/CMake"
   fi
 elif ${cmake_system_haiku}; then
-  cmake_default_prefix=`/bin/finddir B_COMMON_DIRECTORY`
+  cmake_default_prefix=`finddir B_COMMON_DIRECTORY`
+  cmake_man_dir="/documentation/man"
+  cmake_doc_dir="/documentation/packages/cmake-${cmake_version}"
 else
   cmake_default_prefix="/usr/local"
 fi
-- 
1.7.10.2

