2to3 and additional fixes

Index: SConstruct
--- SConstruct.orig
+++ SConstruct
@@ -32,12 +32,12 @@ SConsignFile()
 
 def DefineOptions(filename, args):
    opts = Variables(filename, args)
-   opts.Add('CPPPATH', 'Additional preprocessor paths', ['/usr/local/include'])
+   opts.Add('CPPPATH', 'Additional preprocessor paths', ['/usr/local/include'], Split(''))
    opts.Add('CPPFLAGS', 'Additional preprocessor flags')
    opts.Add('CPPDEFINES', 'defined constants', Split(''))
-   opts.Add('LIBPATH', 'Additional library paths', ['/usr/local/lib'])
+   opts.Add('LIBPATH', 'Additional library paths', ['/usr/local/lib'], Split(''))
    opts.Add('LIBS', 'Additional libraries')
-   opts.Add('CCFLAGS', 'C Compiler flags', Split(ccflags))
+   opts.Add('CCFLAGS', 'C Compiler flags', Split(ccflags), Split(''))
    opts.Add('LINKFLAGS', 'Linker Compiler flags')
    opts.Add('CC', 'C Compiler')
    opts.Add('CXX', 'C++ Compiler')
@@ -51,6 +51,9 @@ def DefineOptions(filename, args):
 opts = DefineOptions("build_options.py", ARGUMENTS)
 env = Environment(ENV = {'PATH':os.environ['PATH']}) # for an unknown reason Environment(options=opts) doesnt work well
 opts.Update(env) # Needed as Environment(options=opts) doesnt seem to work
+env['CCFLAGS'] = Split(ccflags) + Split(env['CCFLAGS'])
+env['CPPPATH'] = Split(env['CPPPATH'])
+env['LIBPATH'] = Split(env['LIBPATH'])
 Help(opts.GenerateHelpText(env))
 mingw = env.Clone()
 optionsChanged = True
@@ -122,7 +125,7 @@ def ParseConfig(env, command, function=None):
                 flags['LINKFLAGS'].append(arg)
             else:
                 flags['CCFLAGS'].append(arg)
-        apply(env.Append, (), flags)
+        env.Append(*(), **flags)
         return static_libs
 
     if function is None:
@@ -144,6 +147,10 @@ def CheckOpenGL(env, conf):
       'LIBS': ['GL'], 
       'LIBPATH': ['/usr/lib', '/usr/X11R6/lib'],
       'CPPPATH': ['/usr/include']}
+  opengl['openbsd'] = { 
+      'LIBS': ['GL'], 
+      'LIBPATH': ['/usr/X11R6/lib'],
+      'CPPPATH': ['/usr/X11R6/include']}
   opengl['cygwin'] = {
       'LIBS': ['opengl3']}
   opengl['darwin'] = {
@@ -155,6 +162,8 @@ def CheckOpenGL(env, conf):
   else:
      if sys.platform[:5] == 'linux' or sys.platform.startswith('gnukfreebsd'):
         platform = 'linux'
+     if sys.platform[:7] == 'openbsd':
+        platform = 'openbsd'
      glconfig = opengl.get(platform, {})
   for key in glconfig:
       if key != 'LIBS':
@@ -168,17 +177,12 @@ def CheckOpenGL(env, conf):
   return True
 
 def CheckLuaLib(env, conf):
-  if not 'USE_WIN32' in env['CPPDEFINES']:
-     if env.WhereIs('pkg-config'):
-        for packagename in ['lua5.1', 'lua51', 'lua']:
-           exitcode,_ = ParseConfig(env, 'pkg-config --cflags --libs ' + packagename)
-           if exitcode == 0:
-              break
+  env.ParseConfig('pkg-config --cflags --libs lua51')
   if conf.CheckLibWithHeader('lua51', 'lua.h', 'c'):
     return 1
   if conf.CheckLibWithHeader('lua5.1', 'lua.h', 'c'):
     return 1
-  if not conf.CheckLibWithHeader('lua', 'lua.h', 'c'):
+  if not conf.CheckLibWithHeader('lua', 'lualib.h', 'c'):
     return 0
   # make sure we have lualib which is included in lua 5.1
   if conf.CheckFunc('luaopen_base'):
@@ -189,30 +193,30 @@ def AutoConfigure(env):
   conf = Configure(env)
 
   ## check for required libs ##
-  if not conf.CheckLibWithHeader('png', 'png.h', 'c'):
-     print 'Did not find png library or headers, exiting!'
-     Exit(1)
   if not conf.CheckLibWithHeader('z', 'zlib.h', 'c'):
-     print 'Did not find the zlib library or headers, exiting!'
+     print('Did not find the zlib library or headers, exiting!')
      Exit(1)
-  if not 'USE_WIN32' in env['CPPDEFINES'] and not sys.platform.startswith('freebsd'):
+  if not conf.CheckLibWithHeader('png', 'png.h', 'c'):
+     print('Did not find png library or headers, exiting!')
+     Exit(1)
+  if not 'USE_WIN32' in env['CPPDEFINES'] and not sys.platform.startswith('openbsd'):
      if not conf.CheckLib('dl'):
-        print 'Did not find dl library or header which is needed on some systems for lua. Exiting!'
+        print('Did not find dl library or header which is needed on some systems for lua. Exiting!')
         Exit(1)
   if not CheckLuaLib(env, conf):
-     print 'Did not find required lua library. Exiting!'
+     print('Did not find required lua library. Exiting!')
      Exit(1)
   if not CheckOpenGL(env, conf):
-     print 'Did not find required OpenGL library. Exiting!'
+     print('Did not find required OpenGL library. Exiting!')
      Exit(1)
 
   # Check for optional libraries #
+  if conf.CheckLib('ogg'):
+     env.Append(CPPDEFINES = 'USE_OGG')
   if conf.CheckLib('vorbis'):
      env.Append(CPPDEFINES = 'USE_VORBIS')
   if conf.CheckLib('theora'):
      env.Append(CPPDEFINES = 'USE_THEORA')
-  if conf.CheckLib('ogg'):
-     env.Append(CPPDEFINES = 'USE_OGG')
 
   # check for optional functions
   if conf.CheckFunc('strcasestr'):
@@ -232,7 +236,7 @@ def AutoConfigure(env):
     env.ParseConfig('sdl-config --libs')
     if sys.platform != "darwin" and not '-Dmain=SDL_main' in env['CCFLAGS']:
        if not conf.CheckLibWithHeader('SDL', 'SDL.h', 'c'):
-          print 'Did not find SDL library or headers, exiting!'
+          print('Did not find SDL library or headers, exiting!')
           Exit(1)
 
   env = conf.Finish()
@@ -245,14 +249,14 @@ def AutoConfigureIfNeeded(env, name):
             # Remove outdated cache file
             os.remove(cachename)
    if optionsChanged or not os.path.exists(cachename):
-      print cachename + " doesn't exist or out of date."
-      print "Generating new build config cache ..."
+      print(cachename + " doesn't exist or out of date.")
+      print("Generating new build config cache ...")
       cache = DefineOptions(cachename, {})
       AutoConfigure(env)
       cache.Save(cachename, env)
    else:
       cache = DefineOptions(cachename, {})
-      print "Using " + cachename
+      print("Using " + cachename)
       cache.Update(env)
 
 AutoConfigureIfNeeded(env, '')
@@ -265,7 +269,7 @@ addBosWarsPaths(env)
 
 # define the different build environments (variants)
 release = env.Clone()
-release.Append(CCFLAGS = Split('-O2 -pipe -fomit-frame-pointer -fexpensive-optimizations -ffast-math'))
+release.Append(CCFLAGS = Split('-fomit-frame-pointer -ffast-math'))
 
 if mingw['extrapath']:
   mingw.Tool('crossmingw', toolpath = ['tools/scons/'])
@@ -311,7 +315,7 @@ if sys.platform.startswith('linux') or sys.platform.st
 def DefineVariant(venv, v, vv = None):
    if vv == None:
       vv = '-' + v
-   BuildDir('build/' + v, engineSourceDir, duplicate = 0)
+   VariantDir('build/' + v, engineSourceDir, duplicate = 0)
    r = venv.Program('build/boswars' + vv, buildSourcesList('build/' + v))
    Alias(v, 'boswars' + vv)
    return r 
