$OpenBSD: patch-SConstruct,v 1.4 2008/03/15 10:06:01 ajacoutot Exp $
--- SConstruct.orig	Mon Mar  3 10:32:55 2008
+++ SConstruct	Mon Mar  3 10:37:57 2008
@@ -32,12 +32,12 @@ SConsignFile()
 
 def DefineOptions(filename, args):
    opts = Options(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')
@@ -50,6 +50,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.Copy()
 optionsChanged = True
@@ -143,6 +146,10 @@ def CheckOpenGL(env, conf):
       'LIBS': ['GL'], 
       'LIBPATH': ['/usr/lib', '/usr/X11R6/lib'],
       'CPPPATH': ['/usr/include']}
+  opengl['openbsd'] = { 
+      'LIBS': ['GL'], 
+      'LIBPATH': ['!!X11BASE!!/lib'],
+      'CPPPATH': ['!!X11BASE!!/include']}
   opengl['cygwin'] = {
       'LIBS': ['opengl3']}
   opengl['darwin'] = {
@@ -154,6 +161,8 @@ def CheckOpenGL(env, conf):
   else:
      if sys.platform[:5] == 'linux':
         platform = 'linux'
+     if sys.platform[:7] == 'openbsd':
+        platform = 'openbsd'
      glconfig = opengl.get(platform, {})
   for key in glconfig:
       if key != 'LIBS':
@@ -168,8 +177,8 @@ def CheckOpenGL(env, conf):
 
 def CheckLuaLib(env, conf):
   if not 'USE_WIN32' in env['CPPDEFINES']:
-     if env.WhereIs('lua-config'):
-        env.ParseConfig('lua-config --include --libs')
+     if env.WhereIs('pkg-config'):
+        env.ParseConfig('pkg-config --cflags --libs lua')
      elif env.WhereIs('pkg-config'):
         for packagename in ['lua5.1', 'lua51', 'lua']:
            exitcode, _ = ParseConfig(env, 'pkg-config --cflags --libs ' + packagename)
@@ -192,7 +201,7 @@ def CheckLuaLib(env, conf):
   lualibfound = 0
   if conf.CheckFunc('luaopen_base'):
      return 1
-  if conf.CheckLibWithHeader('lualib', 'lualib.h', 'c'):
+  if conf.CheckLibWithHeader('lua', 'lualib.h', 'c'):
      lualibfound = 1
   elif conf.CheckLibWithHeader('lualib50', 'lualib.h', 'c'):
      lualibfound = 1
@@ -207,13 +216,13 @@ 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!'
      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!'
         Exit(1)
@@ -225,12 +234,12 @@ def AutoConfigure(env):
      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'):
@@ -283,7 +292,7 @@ addBosWarsPaths(env)
 
 # define the different build environments (variants)
 release = env.Copy()
-release.Append(CCFLAGS = Split('-O2 -pipe -fomit-frame-pointer -fexpensive-optimizations -ffast-math'))
+release.Append(CCFLAGS = Split('-fomit-frame-pointer -fexpensive-optimizations -ffast-math'))
 
 if mingw['extrapath']:
   mingw.Tool('crossmingw', toolpath = ['tools/scons/'])
