From 0be676587939332de0de419e542f56beca91ad4c Mon Sep 17 00:00:00 2001
From: Chris Roberts <cpr420@gmail.com>
Date: Sun, 5 Jul 2020 14:21:41 -0600
Subject: Add support for Haiku


diff --git a/lddtree.sh b/lddtree.sh
index 96163e3..ed21863 100755
--- a/lddtree.sh
+++ b/lddtree.sh
@@ -45,7 +45,12 @@ elf_specs() {
 		sed -E 's: (LINUX|GNU)$: NONE:'
 }
 
-lib_paths_fallback="${ROOT}lib* ${ROOT}usr/lib* ${ROOT}usr/local/lib*"
+if [[ ${OSTYPE} == "haiku" ]] ; then
+	lib_paths_fallback="${ROOT}lib* ${ROOT}boot/system/lib* ${ROOT}boot/home/config/lib* ${ROOT}boot/system/non-packaged/lib* ${ROOT}boot/home/config/non-packaged/lib*"
+else
+	lib_paths_fallback="${ROOT}lib* ${ROOT}usr/lib* ${ROOT}usr/local/lib*"
+fi
+
 c_ldso_paths_loaded='false'
 find_elf() {
 	_find_elf=''
@@ -77,6 +82,11 @@ find_elf() {
 		fi
 		check_paths "${elf}" ${c_last_needed_by_rpaths} && return 0
 
+		if [[ -n ${LIBRARY_PATH} ]] ; then
+			# Use LIBRARY_PATH on Haiku
+			LD_LIBRARY_PATH=${LIBRARY_PATH}
+		fi
+
 		if [[ -n ${LD_LIBRARY_PATH} ]] ; then
 			# Need to handle empty paths as $PWD,
 			# and handle spaces in between the colons
diff --git a/porting.h b/porting.h
index 636e862..d63b149 100644
--- a/porting.h
+++ b/porting.h
@@ -59,6 +59,8 @@
 # include <sys/isa_defs.h>
 #elif defined(__MACH__)
 # include <machine/endian.h>
+#elif defined(__HAIKU__)
+# include <endian.h>
 #endif
 
 #if defined(__GLIBC__) || defined(__UCLIBC__)
-- 
2.27.0

