2 # SConstruct build file. See http://www.scons.org for details.
4 # based on a script from chenlee@ustc.edu
5 def Glob(dirs, pattern = '*' ):
9 for file in os.listdir( Dir(dir).srcnode().abspath ):
10 if fnmatch.fnmatch(file, pattern) :
11 files.append( os.path.join( dir, file ) )
14 def CheckSDLConfig(context, minVersion):
15 context.Message('Checking for sdl-config >= %s... ' % minVersion)
16 from popen2 import Popen3
17 p = Popen3(['sdl-config', '--version'])
19 out = p.fromchild.readlines()
24 # unable to parse output!
27 # TODO validate output and catch exceptions
28 version = map(int, out[0].strip().split('.'))
29 minVersion = map(int, minVersion.split('.'))
30 # TODO comparing versions that way only works for pure numeric version
31 # numbers and fails for custom extensions. I don't care about this at
32 # the moment as sdl-config never used such version numbers afaik.
33 ret = (version >= minVersion)
37 opts = Options('custom.py')
38 opts.Add('CXX', 'The C++ compiler', 'g++')
39 opts.Add('CXXFLAGS', 'Additional C++ compiler flags', '')
40 opts.Add('CPPPATH', 'Additional preprocessor paths', '')
41 opts.Add('CPPFLAGS', 'Additional preprocessor flags', '')
42 opts.Add('LIBPATH', 'Additional library paths', '')
43 opts.Add('LIBS', 'Additional libraries', '')
45 'destination directory for installation. It is prepended to PREFIX', '')
46 opts.Add('PREFIX', 'Installation prefix', '/usr/local')
47 opts.Add(ListOption('VARIANT', 'Build variant', 'optimize',
48 ['optimize', 'debug', 'profile']))
50 env = Environment(options = opts)
51 conf = Configure(env, custom_tests = {
52 'CheckSDLConfig' : CheckSDLConfig
55 # TODO check -config apps in the Configure context
57 if not conf.CheckSDLConfig('1.2.4'):
58 print "Couldn't find libSDL >= 1.2.4"
60 if not conf.CheckLib('SDL_mixer'):
61 print "Couldn't find SDL_mixer library!"
63 if not conf.CheckLib('SDL_image'):
64 print "Couldn't find SDL_image library!"
66 if not conf.CheckLib('GL'):
67 print "Couldn't find OpenGL library!"
72 if str(env['VARIANT']) == "optimize":
73 env.Append(CXXFLAGS = "-O2 -g")
74 elif str(env['VARIANT']) == "debug":
75 env.Append(CXXFLAGS = "-O0 -g3")
76 env.Append(CPPDEFINES = { "DEBUG":"1" })
77 elif str(env['VARIANT']) == "profile":
78 env.Append(CXXFLAGS = "-pg -O2")
80 env.ParseConfig('sdl-config --cflags --libs')
81 env.Append(CPPPATH = ["#", "#/src", "#/lib"])
82 env.Append(CPPDEFINES = \
83 {'DATA_PREFIX':"'\"" + env['PREFIX'] + "/share/supertux\"'" ,
84 'LOCALEDIR' :"'\"" + env['PREFIX'] + "/locales\"'"})
86 build_dir="build/" + env['PLATFORM'] + "/" + str(env['VARIANT'])
88 env.Append(LIBS = ["supertux"])
89 env.Append(LIBPATH=["#" + build_dir + "/lib"])
91 env.Export(["env", "Glob"])
92 env.SConscript("lib/SConscript", build_dir=build_dir + "/lib", duplicate=0)
93 env.SConscript("src/SConscript", build_dir=build_dir + "/src", duplicate=0)