-# based on a script from chenlee@ustc.edu
-def Glob(dirs, pattern = '*' ):
- import os, fnmatch
- files = []
- for dir in dirs:
- for file in os.listdir( Dir(dir).srcnode().abspath ):
- if fnmatch.fnmatch(file, pattern) :
- files.append( os.path.join( dir, file ) )
- return files
-
-opts = Options('custom.py')
+class ConfigHeader:
+ def __init__(self):
+ self.defines = { }
+ self.prefix = ""
+ self.postfix = ""
+
+ def SetPrefix(self, prefix):
+ self.prefix = prefix
+
+ def SetPostfix(self, postfix):
+ self.postfix = postfix
+
+ def Define(self, name, value = ""):
+ self.defines[name] = value
+
+ def Save(self, filename):
+ file = open(filename, 'w')
+ file.write("/* %s. Generated by SConstruct */\n" % (filename))
+ file.write("\n")
+ file.write(self.prefix + "\n")
+ for key, value in self.defines.iteritems():
+ file.write("#define %s \"%s\"\n" % (key, value))
+ file.write(self.postfix + "\n")
+ file.close()
+
+def Glob(pattern):
+ path = GetBuildPath('SConscript').replace('SConscript', '')
+
+ result = []
+ for i in glob.glob(path + pattern):
+ result.append(i.replace(path, ''))
+
+ return result
+
+def InstallData(files):
+ for file in files:
+ dir = os.path.dirname(file)
+ destdir = os.path.join(env.subst('$DESTDIR/$APPDATADIR'), dir)
+ env.Install(destdir, file)
+
+def InstallExec(files):
+ for file in files:
+ destfile = env.subst('$DESTDIR/$BINDIR/$PROGRAM_PREFIX') + file + \
+ env.subst('$PROGRAM_POSTFIX')
+ env.InstallAs(destfile, file)
+
+# thanks to Michael P Jung
+def CheckSDLConfig(context, minVersion):
+ context.Message('Checking for sdl-config >= %s... ' % minVersion)
+ from popen2 import Popen3
+ p = Popen3(['sdl-config', '--version'])
+ ret = p.wait()
+ out = p.fromchild.readlines()
+ if ret != 0:
+ context.Result(False)
+ return False
+ if len(out) != 1:
+ # unable to parse output!
+ context.Result(False)
+ return False
+ # TODO validate output and catch exceptions
+ version = map(int, out[0].strip().split('.'))
+ minVersion = map(int, minVersion.split('.'))
+ # TODO comparing versions that way only works for pure numeric version
+ # numbers and fails for custom extensions. I don't care about this at
+ # the moment as sdl-config never used such version numbers afaik.
+ ret = (version >= minVersion)
+ context.Result(ret)
+ return ret
+
+# User configurable options
+opts = Options('build_config.py')