From 4b015738184f2746c282c02b45c5f0a3747d1fa6 Mon Sep 17 00:00:00 2001
From: Alexander von Gluck IV <kallisti5@unixzen.com>
Date: Wed, 22 Jan 2014 05:04:31 +0000
Subject: haiku: fix Host.h for endian.h


diff --git a/include/llvm/Support/Host.h b/include/llvm/Support/Host.h
index 28c4cc7..ab985a4 100644
--- a/include/llvm/Support/Host.h
+++ b/include/llvm/Support/Host.h
@@ -16,7 +16,7 @@
 
 #include "llvm/ADT/StringMap.h"
 
-#if defined(__linux__) || defined(__GNU__)
+#if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__)
 #include <endian.h>
 #else
 #if !defined(BYTE_ORDER) && !defined(LLVM_ON_WIN32)
-- 
2.2.2


From a2db9ce7f1e6645c3034551aa38391ec0fb11d0a Mon Sep 17 00:00:00 2001
From: Adrien Destugues <pulkomandy@pulkomandy.tk>
Date: Wed, 18 Jun 2014 15:32:09 +0000
Subject: llvm: add a soname to libLTO.

This makes PrepareInstalledDevelLib happy.

diff --git a/tools/lto/Makefile b/tools/lto/Makefile
index cedbee1..5ce530d 100644
--- a/tools/lto/Makefile
+++ b/tools/lto/Makefile
@@ -22,6 +22,10 @@ ifdef LLVM_VERSION_INFO
 CXX.Flags += -DLLVM_VERSION_INFO='"$(LLVM_VERSION_INFO)"'
 endif
 
+ifeq ($(HOST_OS),Haiku)
+	LLVMLibsOptions := $(LLVMLibsOptions) -Wl,-soname=$(SharedPrefix)LTO$(SHLIBEXT)
+endif
+
 ifeq ($(HOST_OS),Darwin)
     # Special hack to allow libLTO to have an offset version number.
     ifdef LLVM_LTO_VERSION_OFFSET
-- 
2.2.2


From 7a01e9f8b6141494e7ba36b9600f36c443526e33 Mon Sep 17 00:00:00 2001
From: Jessica Hamilton <jessica.l.hamilton@gmail.com>
Date: Sat, 9 May 2015 13:50:54 +1200
Subject: Haiku: Use PROJ_libdir when embedding RPATH.

* With Haiku packages, PROJ_libdir will be a
  path local to the package itself, so we
  don't need a path relative to $ORIGIN, which
  can break with our hybrid installations.

diff --git a/Makefile.rules b/Makefile.rules
index fde77f9..542b631 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -578,7 +578,7 @@ ifeq ($(TARGET_OS),Darwin)
 endif
 
 ifdef SHARED_LIBRARY
-ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
+ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW Haiku))
 ifneq ($(HOST_OS),Darwin)
   LD.Flags += $(RPATH) -Wl,'$$ORIGIN'
 endif
@@ -615,7 +615,11 @@ ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
   endif
   ifneq ($(HOST_OS), Darwin)
     ifdef TOOLNAME
-      LD.Flags += $(RPATH) -Wl,'$$ORIGIN/../lib'
+      ifneq ($(HOST_OS), Haiku)
+        LD.Flags += $(RPATH) -Wl,'$$ORIGIN/../lib'
+      else
+        LD.Flags += $(RPATH) -Wl,${PROJ_libdir}
+      endif
     endif
   else
     ifneq ($(DARWIN_MAJVERS),4)
-- 
2.2.2


From 866845211a56ab1c5748713d151d7fb99c028270 Mon Sep 17 00:00:00 2001
From: Jessica Hamilton <jessica.l.hamilton@gmail.com>
Date: Sat, 9 May 2015 17:21:33 +1200
Subject: Haiku: Use configured paths, rather than hardcoding them.

* Also updates llvm-config to use the configured paths.
* Updates libtool.m4 to use the FindPath API for locating
  the runtime library paths for the correct architecture.

diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index fcf5e3b..5b0a74b 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -1808,13 +1808,14 @@ if test "${prefix}" = "NONE" ; then
   prefix="/usr/local"
 fi
 eval LLVM_PREFIX="${prefix}";
-eval LLVM_BINDIR="${prefix}/bin";
-eval LLVM_DATADIR="${prefix}/share/llvm";
-eval LLVM_DOCSDIR="${prefix}/share/doc/llvm";
-eval LLVM_ETCDIR="${prefix}/etc/llvm";
-eval LLVM_INCLUDEDIR="${prefix}/include";
-eval LLVM_INFODIR="${prefix}/info";
-eval LLVM_MANDIR="${prefix}/man";
+eval LLVM_BINDIR="${bindir}";
+eval LLVM_DATADIR="${datadir}/llvm";
+eval LLVM_DOCSDIR="${docdir}";
+eval LLVM_ETCDIR="${sysconfdir}/llvm";
+eval LLVM_INCLUDEDIR="${includedir}";
+eval LLVM_INFODIR="${infodir}";
+eval LLVM_LIBDIR="${libdir}";
+eval LLVM_MANDIR="${mandir}";
 LLVM_CONFIGTIME=`date`
 AC_SUBST(LLVM_PREFIX)
 AC_SUBST(LLVM_BINDIR)
@@ -1823,6 +1824,7 @@ AC_SUBST(LLVM_DOCSDIR)
 AC_SUBST(LLVM_ETCDIR)
 AC_SUBST(LLVM_INCLUDEDIR)
 AC_SUBST(LLVM_INFODIR)
+AC_SUBST(LLVM_LIBDIR)
 AC_SUBST(LLVM_MANDIR)
 AC_SUBST(LLVM_CONFIGTIME)
 
@@ -1847,6 +1849,8 @@ AC_DEFINE_UNQUOTED(LLVM_INCLUDEDIR, "$LLVM_INCLUDEDIR",
                    [Installation directory for include files])
 AC_DEFINE_UNQUOTED(LLVM_INFODIR, "$LLVM_INFODIR",
                    [Installation directory for .info files])
+AC_DEFINE_UNQUOTED(LLVM_LIBDIR, "$LLVM_LIBDIR",
+                   [Installation directory for library files])
 AC_DEFINE_UNQUOTED(LLVM_MANDIR, "$LLVM_MANDIR",
                    [Installation directory for man pages])
 AC_DEFINE_UNQUOTED(LLVM_CONFIGTIME, "$LLVM_CONFIGTIME",
diff --git a/autoconf/m4/libtool.m4 b/autoconf/m4/libtool.m4
index 385d00b..6116201 100644
--- a/autoconf/m4/libtool.m4
+++ b/autoconf/m4/libtool.m4
@@ -1454,6 +1454,14 @@ gnu*)
   hardcode_into_libs=yes
   ;;
 
+haiku*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  haiku_arch=`getarch`
+  sys_lib_dlsearch_path_spec="`findpaths -a ${haiku_arch} -c ' ' B_FIND_PATH_LIB_DIRECTORY`"
+  ;;
+
 hpux9* | hpux10* | hpux11*)
   # Give a soname corresponding to the major version so that dld.sl refuses to
   # link against other versions.
diff --git a/configure b/configure
index 17b958c..aff513d 100755
--- a/configure
+++ b/configure
@@ -795,6 +795,7 @@ LLVM_DOCSDIR
 LLVM_ETCDIR
 LLVM_INCLUDEDIR
 LLVM_INFODIR
+LLVM_LIBDIR
 LLVM_MANDIR
 LLVM_CONFIGTIME
 BINDINGS_TO_BUILD
@@ -9139,6 +9140,14 @@ gnu*)
   hardcode_into_libs=yes
   ;;
 
+haiku*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  haiku_arch=`getarch`
+  sys_lib_dlsearch_path_spec="`findpaths -a ${haiku_arch} -c ' ' B_FIND_PATH_LIB_DIRECTORY`"
+  ;;
+
 hpux9* | hpux10* | hpux11*)
   # Give a soname corresponding to the major version so that dld.sl refuses to
   # link against other versions.
@@ -22048,13 +22057,14 @@ if test "${prefix}" = "NONE" ; then
   prefix="/usr/local"
 fi
 eval LLVM_PREFIX="${prefix}";
-eval LLVM_BINDIR="${prefix}/bin";
-eval LLVM_DATADIR="${prefix}/share/llvm";
-eval LLVM_DOCSDIR="${prefix}/share/doc/llvm";
-eval LLVM_ETCDIR="${prefix}/etc/llvm";
-eval LLVM_INCLUDEDIR="${prefix}/include";
-eval LLVM_INFODIR="${prefix}/info";
-eval LLVM_MANDIR="${prefix}/man";
+eval LLVM_BINDIR="${bindir}";
+eval LLVM_DATADIR="${datadir}/llvm";
+eval LLVM_DOCSDIR="${docdir}";
+eval LLVM_ETCDIR="${sysconfdir}/llvm";
+eval LLVM_INCLUDEDIR="${includedir}";
+eval LLVM_LIBDIR="${libdir}";
+eval LLVM_INFODIR="${infodir}";
+eval LLVM_MANDIR="${mandir}";
 LLVM_CONFIGTIME=`date`
 
 
@@ -22107,6 +22117,11 @@ _ACEOF
 
 
 cat >>confdefs.h <<_ACEOF
+#define LLVM_LIBDIR "$LLVM_LIBDIR"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
 #define LLVM_MANDIR "$LLVM_MANDIR"
 _ACEOF
 
@@ -23257,10 +23272,11 @@ LLVM_DOCSDIR!$LLVM_DOCSDIR$ac_delim
 LLVM_ETCDIR!$LLVM_ETCDIR$ac_delim
 LLVM_INCLUDEDIR!$LLVM_INCLUDEDIR$ac_delim
 LLVM_INFODIR!$LLVM_INFODIR$ac_delim
+LLVM_LIBDIR!$LLVM_LIBDIR$ac_delim
 LLVM_MANDIR!$LLVM_MANDIR$ac_delim
 _ACEOF
 
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 98; then
     break
   elif $ac_last_try; then
     { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake
index 5c72ad8..642a2ea 100644
--- a/include/llvm/Config/config.h.cmake
+++ b/include/llvm/Config/config.h.cmake
@@ -531,6 +531,9 @@
 /* Installation directory for .info files */
 #cmakedefine LLVM_INFODIR "${LLVM_INFODIR}"
 
+/* Installation directory for library files */
+#cmakedefine LLVM_LIBDIR "${LLVM_LIBDIR}"
+
 /* Installation directory for man pages */
 #cmakedefine LLVM_MANDIR "${LLVM_MANDIR}"
 
diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in
index 2317823..f0cc2f4 100644
--- a/include/llvm/Config/config.h.in
+++ b/include/llvm/Config/config.h.in
@@ -566,6 +566,9 @@
 /* Installation directory for .info files */
 #undef LLVM_INFODIR
 
+/* Installation directory library files */
+#undef LLVM_LIBDIR
+
 /* Installation directory for man pages */
 #undef LLVM_MANDIR
 
diff --git a/include/llvm/Config/llvm-config.h.cmake b/include/llvm/Config/llvm-config.h.cmake
index 80616ef..9b88a6a 100644
--- a/include/llvm/Config/llvm-config.h.cmake
+++ b/include/llvm/Config/llvm-config.h.cmake
@@ -49,6 +49,9 @@
 /* Installation directory for .info files */
 #cmakedefine LLVM_INFODIR "${LLVM_INFODIR}"
 
+/* Installation directory for library files */
+#cmakedefine LLVM_LIBDIR "${LLVM_LIBDIR}"
+
 /* Installation directory for man pages */
 #cmakedefine LLVM_MANDIR "${LLVM_MANDIR}"
 
diff --git a/include/llvm/Config/llvm-config.h.in b/include/llvm/Config/llvm-config.h.in
index a4fae55..e2598f8 100644
--- a/include/llvm/Config/llvm-config.h.in
+++ b/include/llvm/Config/llvm-config.h.in
@@ -49,6 +49,9 @@
 /* Installation directory for .info files */
 #undef LLVM_INFODIR
 
+/* Installation directory for library files */
+#undef LLVM_LIBDIR
+
 /* Installation directory for man pages */
 #undef LLVM_MANDIR
 
diff --git a/projects/sample/autoconf/configure.ac b/projects/sample/autoconf/configure.ac
index 03cd214..f3455e7 100644
--- a/projects/sample/autoconf/configure.ac
+++ b/projects/sample/autoconf/configure.ac
@@ -1412,13 +1412,14 @@ if test "${prefix}" = "NONE" ; then
   prefix="/usr/local"
 fi
 eval LLVM_PREFIX="${prefix}";
-eval LLVM_BINDIR="${prefix}/bin";
-eval LLVM_DATADIR="${prefix}/share/llvm";
-eval LLVM_DOCSDIR="${prefix}/share/doc/llvm";
-eval LLVM_ETCDIR="${prefix}/etc/llvm";
-eval LLVM_INCLUDEDIR="${prefix}/include";
-eval LLVM_INFODIR="${prefix}/info";
-eval LLVM_MANDIR="${prefix}/man";
+eval LLVM_BINDIR="${bindir}";
+eval LLVM_DATADIR="${datadir}/llvm";
+eval LLVM_DOCSDIR="${docdir}";
+eval LLVM_ETCDIR="${sysconfdir}/llvm";
+eval LLVM_INCLUDEDIR="${includedir}";
+eval LLVM_INFODIR="${infodir}";
+eval LLVM_LIBDIR="${libdir}";
+eval LLVM_MANDIR="${mandir}";
 LLVM_CONFIGTIME=`date`
 AC_SUBST(LLVM_PREFIX)
 AC_SUBST(LLVM_BINDIR)
@@ -1427,6 +1428,7 @@ AC_SUBST(LLVM_DOCSDIR)
 AC_SUBST(LLVM_ETCDIR)
 AC_SUBST(LLVM_INCLUDEDIR)
 AC_SUBST(LLVM_INFODIR)
+AC_SUBST(LLVM_LIBDIR)
 AC_SUBST(LLVM_MANDIR)
 AC_SUBST(LLVM_CONFIGTIME)
 
@@ -1446,6 +1448,8 @@ AC_DEFINE_UNQUOTED(LLVM_INCLUDEDIR, "$LLVM_INCLUDEDIR",
                    [Installation directory for include files])
 AC_DEFINE_UNQUOTED(LLVM_INFODIR, "$LLVM_INFODIR",
                    [Installation directory for .info files])
+AC_DEFINE_UNQUOTED(LLVM_LIBDIR, "$LLVM_LIBDIR",
+                   [Installation directory for library files])
 AC_DEFINE_UNQUOTED(LLVM_MANDIR, "$LLVM_MANDIR",
                    [Installation directory for man pages])
 AC_DEFINE_UNQUOTED(LLVM_CONFIGTIME, "$LLVM_CONFIGTIME",
diff --git a/projects/sample/autoconf/m4/libtool.m4 b/projects/sample/autoconf/m4/libtool.m4
index b8bd4b8..e504b05 100644
--- a/projects/sample/autoconf/m4/libtool.m4
+++ b/projects/sample/autoconf/m4/libtool.m4
@@ -1454,6 +1454,14 @@ gnu*)
   hardcode_into_libs=yes
   ;;
 
+haiku*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  haiku_arch=`getarch`
+  sys_lib_dlsearch_path_spec="`findpaths -a ${haiku_arch} -c ' ' B_FIND_PATH_LIB_DIRECTORY`"
+  ;;
+
 hpux9* | hpux10* | hpux11*)
   # Give a soname corresponding to the major version so that dld.sl refuses to
   # link against other versions.
diff --git a/projects/sample/configure b/projects/sample/configure
index bc04c96..b511655 100755
--- a/projects/sample/configure
+++ b/projects/sample/configure
@@ -779,6 +779,7 @@ LLVM_DOCSDIR
 LLVM_ETCDIR
 LLVM_INCLUDEDIR
 LLVM_INFODIR
+LLVM_LIBDIR
 LLVM_MANDIR
 LLVM_CONFIGTIME
 BINDINGS_TO_BUILD
@@ -8916,6 +8917,14 @@ gnu*)
   hardcode_into_libs=yes
   ;;
 
+haiku*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  haiku_arch=`getarch`
+  sys_lib_dlsearch_path_spec="`findpaths -a ${haiku_arch} -c ' ' B_FIND_PATH_LIB_DIRECTORY`"
+  ;;
+
 hpux9* | hpux10* | hpux11*)
   # Give a soname corresponding to the major version so that dld.sl refuses to
   # link against other versions.
@@ -21281,6 +21290,7 @@ eval LLVM_DOCSDIR="${prefix}/share/doc/llvm";
 eval LLVM_ETCDIR="${prefix}/etc/llvm";
 eval LLVM_INCLUDEDIR="${prefix}/include";
 eval LLVM_INFODIR="${prefix}/info";
+eval LLVM_LIBDIR="${prefix}/lib";
 eval LLVM_MANDIR="${prefix}/man";
 LLVM_CONFIGTIME=`date`
 
@@ -21332,6 +21342,11 @@ _ACEOF
 
 
 cat >>confdefs.h <<_ACEOF
+#define LLVM_LIBDIR "$LLVM_LIBDIR"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
 #define LLVM_MANDIR "$LLVM_MANDIR"
 _ACEOF
 
@@ -22400,6 +22415,7 @@ LLVM_DOCSDIR!$LLVM_DOCSDIR$ac_delim
 LLVM_ETCDIR!$LLVM_ETCDIR$ac_delim
 LLVM_INCLUDEDIR!$LLVM_INCLUDEDIR$ac_delim
 LLVM_INFODIR!$LLVM_INFODIR$ac_delim
+LLVM_LIBDIR!$LLVM_LIBDIR$ac_delim
 LLVM_MANDIR!$LLVM_MANDIR$ac_delim
 LLVM_CONFIGTIME!$LLVM_CONFIGTIME$ac_delim
 BINDINGS_TO_BUILD!$BINDINGS_TO_BUILD$ac_delim
@@ -22412,7 +22428,7 @@ LIBOBJS!$LIBOBJS$ac_delim
 LTLIBOBJS!$LTLIBOBJS$ac_delim
 _ACEOF
 
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 92; then
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 93; then
     break
   elif $ac_last_try; then
     { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
index 3924e2e..dc69158 100644
--- a/tools/llvm-config/llvm-config.cpp
+++ b/tools/llvm-config/llvm-config.cpp
@@ -252,6 +252,13 @@ int main(int argc, char **argv) {
     ActiveBinDir = ActivePrefix + "/bin";
     ActiveLibDir = ActivePrefix + "/lib";
     ActiveIncludeOption = "-I" + ActiveIncludeDir;
+    #if defined(LLVM_PREFIX) && defined(LLVM_INCLUDEDIR) && defined(LLVM_BINDIR) && defined(LLVM_LIBDIR)
+    ActivePrefix = LLVM_PREFIX;
+    ActiveIncludeDir = LLVM_INCLUDEDIR;
+    ActiveBinDir = LLVM_BINDIR;
+    ActiveLibDir = LLVM_LIBDIR;
+    ActiveIncludeOption = "-I" + std::string(LLVM_INCLUDEDIR);
+    #endif
   }
 
   raw_ostream &OS = outs();
-- 
2.2.2

