From 3609030bdb0666a1d4e2e06508d03948345c0450 Mon Sep 17 00:00:00 2001
From: Ingo Weinhold <ingo_weinhold@gmx.de>
Date: Fri, 9 Aug 2013 17:46:35 +0200
Subject: Add support for the Haiku platform


diff --git a/engine/SCons/Platform/haiku.py b/engine/SCons/Platform/haiku.py
new file mode 100644
index 0000000..547421e
--- /dev/null
+++ b/engine/SCons/Platform/haiku.py
@@ -0,0 +1,68 @@
+"""SCons.Platform.haiku
+
+Platform-specific initialization for Haiku systems.
+
+There normally shouldn't be any need to import this module directly. It
+will usually be imported through the generic SCons.Platform.Platform()
+selection method.
+"""
+
+#
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 The SCons Foundation
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = ""
+
+import commands
+import os
+import posix
+
+def findDir(identifier):
+	return commands.getoutput('finddir %s' % identifier)
+
+def generate(env):
+	posix.generate(env)
+
+	# determine, if building for the secondary architecture
+	secondaryArch = os.environ.get('HAIKU_SECONDARY_ARCH')
+	archSubDir = '/' + secondaryArch if secondaryArch else ''
+
+	# PATH
+	pathDescriptions = [
+		('B_USER_NONPACKAGED_BIN_DIRECTORY', None),
+		('B_USER_BIN_DIRECTORY', None),
+		('B_SYSTEM_NONPACKAGED_BIN_DIRECTORY', None),
+		('B_SYSTEM_BIN_DIRECTORY', None)
+		]
+
+	paths = []
+	for pathConstant, subDir in pathDescriptions:
+		path = findDir(pathConstant)
+		if subDir:
+			path += '/' + subDir
+		paths.append(path)
+
+	if secondaryArch:
+		# prepend the secondary arch subdirectories
+		paths = [path + archSubDir for path in paths] + paths
+
+	env['ENV']['PATH'] = ':'.join(paths)
diff --git a/src/engine/SCons/Platform/__init__.py b/src/engine/SCons/Platform/__init__.py
index 7d959b7..1ca4685 100644
--- a/src/engine/SCons/Platform/__init__.py
+++ b/src/engine/SCons/Platform/__init__.py
@@ -80,6 +80,8 @@ def platform_default():
             return 'aix'
         elif sys.platform.find('darwin') != -1:
             return 'darwin'
+        elif sys.platform.find('haiku') != -1:
+            return 'haiku'
         else:
             return 'posix'
     elif os.name == 'os2':
-- 
2.24.0


From 22a5f208e276e2f87cb6a4ff899c782563b1c12b Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Wed, 22 Jan 2020 22:35:19 +0100
Subject: python3 support


diff --git a/engine/SCons/Platform/haiku.py b/engine/SCons/Platform/haiku.py
index 547421e..dd83ef8 100644
--- a/engine/SCons/Platform/haiku.py
+++ b/engine/SCons/Platform/haiku.py
@@ -32,12 +32,12 @@ selection method.
 
 __revision__ = ""
 
-import commands
 import os
-import posix
+import subprocess
+from . import posix
 
 def findDir(identifier):
-	return commands.getoutput('finddir %s' % identifier)
+	return str(subprocess.check_output(['finddir', identifier], shell=False).rstrip())
 
 def generate(env):
 	posix.generate(env)
-- 
2.24.0


From c5c4b805b0096616b58889066a0d36f07a089bd1 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Mon, 27 Apr 2020 14:05:11 +0200
Subject: move platform haiku file


diff --git a/engine/SCons/Platform/haiku.py b/src/engine/SCons/Platform/haiku.py
similarity index 100%
rename from engine/SCons/Platform/haiku.py
rename to src/engine/SCons/Platform/haiku.py
-- 
2.24.0


From 59619e1319ef38b81daf9be13642fbec1a7a7925 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Mon, 27 Apr 2020 14:05:11 +0200
Subject: move platform haiku file


diff --git a/src/engine/MANIFEST.in b/src/engine/MANIFEST.in
index 3125824..231d3fc 100644
--- a/src/engine/MANIFEST.in
+++ b/src/engine/MANIFEST.in
@@ -24,6 +24,7 @@ SCons/Platform/__init__.py
 SCons/Platform/aix.py
 SCons/Platform/cygwin.py
 SCons/Platform/darwin.py
+SCons/Platform/haiku.py
 SCons/Platform/hpux.py
 SCons/Platform/irix.py
 SCons/Platform/os2.py
diff --git a/src/engine/SCons/Platform/haiku.py b/src/engine/SCons/Platform/haiku.py
index 80d3b06..b9cd656 100644
--- a/src/engine/SCons/Platform/haiku.py
+++ b/src/engine/SCons/Platform/haiku.py
@@ -61,6 +61,8 @@ def generate(env):
 			path += '/' + subDir
 		paths.append(path)
 
+	paths.append('/bin')
+
 	if secondaryArch:
 		# prepend the secondary arch subdirectories
 		paths = [path + archSubDir for path in paths] + paths
-- 
2.24.0


From b8f691d4e2685e443f9604ac548afae2e72e1910 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Mon, 27 Apr 2020 21:28:15 +0200
Subject: Haiku: add LIBRARY_PATH handling


diff --git a/SConstruct b/SConstruct
index 1adf714..e67cbf9 100644
--- a/SConstruct
+++ b/SConstruct
@@ -143,7 +143,7 @@ for a in addpaths:
 # built with the --enable-shared option.
 
 ENV = { 'PATH' : os.environ['PATH'] }
-for key in ['LOGNAME', 'PYTHONPATH', 'LD_LIBRARY_PATH']:
+for key in ['LOGNAME', 'PYTHONPATH', 'LD_LIBRARY_PATH', 'LIBRARY_PATH']:
     if key in os.environ:
         ENV[key] = os.environ[key]
 
diff --git a/test/CC/SHCCFLAGS.py b/test/CC/SHCCFLAGS.py
index 72d36b1..10989a6 100644
--- a/test/CC/SHCCFLAGS.py
+++ b/test/CC/SHCCFLAGS.py
@@ -36,6 +36,8 @@ barflags = e['SHCCFLAGS'] + ' -DBAR'
 
 if os.name == 'posix':
     os.environ['LD_LIBRARY_PATH'] = '.'
+if sys.platform[:5] == 'haiku':
+    os.environ['LIBRARY_PATH'] = '.'
 if sys.platform.find('irix') > -1:
     os.environ['LD_LIBRARYN32_PATH'] = '.'
 
diff --git a/test/CC/SHCFLAGS.py b/test/CC/SHCFLAGS.py
index 3ec6778..e9821b8 100644
--- a/test/CC/SHCFLAGS.py
+++ b/test/CC/SHCFLAGS.py
@@ -36,6 +36,8 @@ barflags = e['SHCFLAGS'] + ' -DBAR'
 
 if os.name == 'posix':
     os.environ['LD_LIBRARY_PATH'] = '.'
+if sys.platform[:5] == 'haiku':
+    os.environ['LIBRARY_PATH'] = '.'
 if sys.platform.find('irix') > -1:
     os.environ['LD_LIBRARYN32_PATH'] = '.'
 
diff --git a/test/CXX/CXXFLAGS.py b/test/CXX/CXXFLAGS.py
index 8d72708..ecfa985 100644
--- a/test/CXX/CXXFLAGS.py
+++ b/test/CXX/CXXFLAGS.py
@@ -38,6 +38,8 @@ _obj = TestSCons._obj
 
 if os.name == 'posix':
     os.environ['LD_LIBRARY_PATH'] = '.'
+if sys.platform[:5] == 'haiku':
+    os.environ['LIBRARY_PATH'] = '.'
 if sys.platform.find('irix') > -1:
     os.environ['LD_LIBRARYN32_PATH'] = '.'
 
diff --git a/test/CXX/SHCXXFLAGS.py b/test/CXX/SHCXXFLAGS.py
index 343be30..824e49f 100644
--- a/test/CXX/SHCXXFLAGS.py
+++ b/test/CXX/SHCXXFLAGS.py
@@ -37,6 +37,8 @@ _obj = TestSCons._obj
 
 if os.name == 'posix':
     os.environ['LD_LIBRARY_PATH'] = '.'
+if sys.platform[:5] == 'haiku':
+    os.environ['LIBRARY_PATH'] = '.'
 if sys.platform.find('irix') > -1:
     os.environ['LD_LIBRARYN32_PATH'] = '.'
 
diff --git a/test/LINK/VersionedLib-VariantDir.py b/test/LINK/VersionedLib-VariantDir.py
index 4a5ac40..b3eefef 100644
--- a/test/LINK/VersionedLib-VariantDir.py
+++ b/test/LINK/VersionedLib-VariantDir.py
@@ -96,6 +96,8 @@ if platform == 'cygwin' or platform == 'win32':
 
 if os.name == 'posix':
     os.environ['LD_LIBRARY_PATH'] = test.workpath('build/lib')
+if sys.platform.find('haiku') != -1:
+    os.environ['LIBRARY_PATH'] = test.workpath('build/lib')
 if sys.platform.find('irix') != -1:
     os.environ['LD_LIBRARYN32_PATH'] = test.workpath('build/lib')
 
diff --git a/test/LINK/VersionedLib-j2.py b/test/LINK/VersionedLib-j2.py
index 0cde91c..09fa82c 100644
--- a/test/LINK/VersionedLib-j2.py
+++ b/test/LINK/VersionedLib-j2.py
@@ -77,6 +77,8 @@ if platform == 'cygwin':
 
 if os.name == 'posix':
     os.environ['LD_LIBRARY_PATH'] = test.workpath('.')
+if sys.platform.find('haiku') != -1:
+    os.environ['LIBRARY_PATH'] = test.workpath('.')
 if sys.platform.find('irix') != -1:
     os.environ['LD_LIBRARYN32_PATH'] = test.workpath('.')
 
diff --git a/test/LINK/VersionedLib-subdir.py b/test/LINK/VersionedLib-subdir.py
index 66fef63..c82b268 100644
--- a/test/LINK/VersionedLib-subdir.py
+++ b/test/LINK/VersionedLib-subdir.py
@@ -88,6 +88,8 @@ if platform == 'cygwin' or platform == 'win32':
 
 if os.name == 'posix':
     os.environ['LD_LIBRARY_PATH'] = subdir
+if sys.platform.find('haiku') != -1:
+    os.environ['LIBRARY_PATH'] = subdir
 if sys.platform.find('irix') != -1:
     os.environ['LD_LIBRARYN32_PATH'] = subdir
 
diff --git a/test/Libs/SharedLibrary.py b/test/Libs/SharedLibrary.py
index 9e22cfa..8922b24 100644
--- a/test/Libs/SharedLibrary.py
+++ b/test/Libs/SharedLibrary.py
@@ -209,6 +209,8 @@ test.run(arguments = '.',
 
 if os.name == 'posix':
     os.environ['LD_LIBRARY_PATH'] = '.'
+if sys.platform.find('haiku') != -1:
+    os.environ['LIBRARY_PATH'] = '.'
 if sys.platform.find('irix') != -1:
     os.environ['LD_LIBRARYN32_PATH'] = '.'
 
diff --git a/test/LoadableModule.py b/test/LoadableModule.py
index 18a9c43..744eb84 100644
--- a/test/LoadableModule.py
+++ b/test/LoadableModule.py
@@ -112,6 +112,7 @@ test.run(arguments = '.',
 
 if sys.platform in platforms_with_dlopen:
     os.environ['LD_LIBRARY_PATH'] = test.workpath()
+    os.environ['LIBRARY_PATH'] = test.workpath()
     test.run(program = test.workpath('dlopenprog'),
              stdout = "f1.c\ndlopenprog.c\n")
                  
diff --git a/test/NodeOps.py b/test/NodeOps.py
index 99a3f6a..2b663db 100644
--- a/test/NodeOps.py
+++ b/test/NodeOps.py
@@ -46,6 +46,8 @@ _dll = TestSCons._dll
 
 if os.name == 'posix':
     os.environ['LD_LIBRARY_PATH'] = '.'
+if sys.platform[:5] == 'haiku':
+    os.environ['LIBRARY_PATH'] = '.'
 if sys.platform.find('irix') > -1:
     os.environ['LD_LIBRARYN32_PATH'] = '.'
 
diff --git a/test/Repository/SharedLibrary.py b/test/Repository/SharedLibrary.py
index 51142aa..42eb4b4 100644
--- a/test/Repository/SharedLibrary.py
+++ b/test/Repository/SharedLibrary.py
@@ -112,6 +112,8 @@ test.run(chdir='work',
 if os.name == 'posix':
     if sys.platform[:6] == 'darwin':
         os.environ['DYLD_LIBRARY_PATH'] = test.workpath('work')
+    elif sys.platform[:5] == 'haiku':
+        os.environ['LIBRARY_PATH'] = test.workpath('work')
     else:
         os.environ['LD_LIBRARY_PATH'] = test.workpath('work')
 if sys.platform.find('irix') != -1:
-- 
2.24.0

