From d960b6ab8ec3d9e25916d6c09c22febe55a716e9 Mon Sep 17 00:00:00 2001
From: Puck Meerburg <puck@puckipedia.nl>
Date: Sun, 4 Jan 2015 19:33:38 +0100
Subject: Fix Haiku build


diff --git a/SConstruct b/SConstruct
index 4d5b446..a6fb618 100644
--- a/SConstruct
+++ b/SConstruct
@@ -33,7 +33,7 @@ opts.AddVariables(
 AddOption('--prefix', dest='prefix', type='string', nargs=1, action='store', metavar='DIR', help='installation prefix')
 
 prefix = GetOption('prefix')
-env = Environment(options = opts)
+env = Environment(options = opts, ENV=os.environ)
 
 if env['RELEASE']:
   env.Append(CPPDEFINES=["PUBLIC_RELEASE"])
@@ -46,23 +46,6 @@ if platform.system == "ppc":
 # Default compiler flags:
 env.Append(CCFLAGS = ['-Wall', '-Wno-write-strings', '-Wno-sign-compare'])
 
-if os.environ.has_key('PLATFORM'):
-  env.Replace(PLATFORM = os.environ['PLATFORM'])
-if os.environ.has_key('CC'):
-  env.Replace(CC = os.environ['CC'])
-if os.environ.has_key('CXX'):
-  env.Replace(CXX = os.environ['CXX'])
-if os.environ.has_key('WINDRES'):
-  env.Replace(WINDRES = os.environ['WINDRES'])
-if os.environ.has_key('CFLAGS'):
-  env.Append(CCFLAGS = os.environ['CFLAGS'].split())
-if os.environ.has_key('CXXFLAGS'):
-  env.Append(CXXFLAGS = os.environ['CXXFLAGS'].split())
-if os.environ.has_key('CPPFLAGS'):
-  env.Append(CPPFLAGS = os.environ['CPPFLAGS'].split())
-if os.environ.has_key('LDFLAGS'):
-  env.Append(LINKFLAGS = os.environ['LDFLAGS'].split())
-
 print "platform: ", env['PLATFORM']
 
 # compile with clang
@@ -187,7 +170,6 @@ else:
 
 Export('env')
 fceux = SConscript('src/SConscript')
-env.Program(target="fceux-net-server", source=["fceux-server/server.cpp", "fceux-server/md5.cpp", "fceux-server/throttle.cpp"])
 
 # Installation rules
 if prefix == None:
@@ -200,9 +182,6 @@ if env['PLATFORM'] == 'win32':
 fceux_src = 'src/fceux' + exe_suffix
 fceux_dst = 'bin/fceux' + exe_suffix
 
-fceux_net_server_src = 'fceux-net-server' + exe_suffix
-fceux_net_server_dst = 'bin/fceux-net-server' + exe_suffix
-
 auxlib_src = 'src/auxlib.lua'
 auxlib_dst = 'bin/auxlib.lua'
 auxlib_inst_dst = prefix + '/share/fceux/auxlib.lua'
@@ -212,13 +191,10 @@ fceux_h_dst = 'bin/fceux.chm'
 
 env.Command(fceux_h_dst, fceux_h_src, [Copy(fceux_h_dst, fceux_h_src)])
 env.Command(fceux_dst, fceux_src, [Copy(fceux_dst, fceux_src)])
-env.Command(fceux_net_server_dst, fceux_net_server_src, [Copy(fceux_net_server_dst, fceux_net_server_src)])
 env.Command(auxlib_dst, auxlib_src, [Copy(auxlib_dst, auxlib_src)])
 
 man_src = 'documentation/fceux.6'
-man_net_src = 'documentation/fceux-net-server.6'
 man_dst = prefix + '/share/man/man6/fceux.6'
-man_net_dst = prefix + '/share/man/man6/fceux-net-server.6'
 
 share_src = 'output/'
 share_dst = prefix + '/share/fceux/'
@@ -230,12 +206,24 @@ desktop_src = 'fceux.desktop'
 desktop_dst = prefix + '/share/applications/'
 
 env.Install(prefix + "/bin/", fceux)
-env.Install(prefix + "/bin/", "fceux-net-server")
 # TODO:  Where to put auxlib on "scons install?"
 env.Alias('install', env.Command(auxlib_inst_dst, auxlib_src, [Copy(auxlib_inst_dst, auxlib_src)]))
 env.Alias('install', env.Command(share_dst, share_src, [Copy(share_dst, share_src)]))
 env.Alias('install', env.Command(man_dst, man_src, [Copy(man_dst, man_src)]))
-env.Alias('install', env.Command(man_net_dst, man_net_src, [Copy(man_net_dst, man_net_src)]))
 env.Alias('install', env.Command(image_dst, image_src, [Copy(image_dst, image_src)]))
 env.Alias('install', env.Command(desktop_dst, desktop_src, [Copy(desktop_dst, desktop_src)]))
 env.Alias('install', (prefix + "/bin/"))
+
+
+if env['PLATFORM'] != 'haiku':
+	env.Program(target="fceux-net-server", source=["fceux-server/server.cpp", "fceux-server/md5.cpp", "fceux-server/throttle.cpp"])
+
+	fceux_net_server_src = 'fceux-net-server' + exe_suffix
+	fceux_net_server_dst = 'bin/fceux-net-server' + exe_suffix
+	env.Command(fceux_net_server_dst, fceux_net_server_src, [Copy(fceux_net_server_dst, fceux_net_server_src)])
+
+	env.Install(prefix + "/bin/", "fceux-net-server")
+
+	man_net_src = 'documentation/fceux-net-server.6'
+	man_net_dst = prefix + '/share/man/man6/fceux-net-server.6'
+	env.Alias('install', env.Command(man_net_dst, man_net_src, [Copy(man_net_dst, man_net_src)]))
diff --git a/src/drivers/sdl/SConscript b/src/drivers/sdl/SConscript
index 7a53b07..8f62c40 100644
--- a/src/drivers/sdl/SConscript
+++ b/src/drivers/sdl/SConscript
@@ -4,7 +4,10 @@ Import('env')
 config_string = 'pkg-config --cflags --libs x11'
 if env['PLATFORM'] == 'darwin':
   config_string = 'PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ ' + config_string
-env.ParseConfig(config_string)
+
+if env['PLATFORM'] != 'haiku':
+  env.ParseConfig(config_string)
+
 Export('env')
 
 source_list = Split(
@@ -26,5 +29,8 @@ if 'GL' in env['LIBS']:
 if env['GTK'] or env['GTK3']:
   source_list.append('gui.cpp')
 
+if env['PLATFORM'] == 'haiku':
+  env.Append(LIBS = ['network'])
+
 source_list = ['drivers/sdl/' + source for source in source_list]
 Return('source_list')
diff --git a/src/utils/ioapi.cpp b/src/utils/ioapi.cpp
index c2b536f..0363efd 100644
--- a/src/utils/ioapi.cpp
+++ b/src/utils/ioapi.cpp
@@ -14,7 +14,7 @@
         #define _CRT_SECURE_NO_WARNINGS
 #endif
 
-#if defined(__APPLE__) || defined(IOAPI_NO_64)
+#if defined(__APPLE__) || defined(__HAIKU__) || defined(IOAPI_NO_64)
 // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
 #define FOPEN_FUNC(filename, mode) fopen(filename, mode)
 #define FTELLO_FUNC(stream) ftello(stream)
-- 
1.8.3.4

