2 # SConstruct build file. See http://www.scons.org for details.
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 # thanks to Michael P Jung
15 def CheckSDLConfig(context, minVersion):
16 context.Message('Checking for sdl-config >= %s... ' % minVersion)
17 from popen2 import Popen3
18 p = Popen3(['sdl-config', '--version'])
20 out = p.fromchild.readlines()
25 # unable to parse output!
28 # TODO validate output and catch exceptions
29 version = map(int, out[0].strip().split('.'))
30 minVersion = map(int, minVersion.split('.'))
31 # TODO comparing versions that way only works for pure numeric version
32 # numbers and fails for custom extensions. I don't care about this at
33 # the moment as sdl-config never used such version numbers afaik.
34 ret = (version >= minVersion)
39 opts = Options('build_config.py')
40 opts.Add('CXX', 'The C++ compiler', 'g++')
41 opts.Add('CXXFLAGS', 'Additional C++ compiler flags', '')
42 opts.Add('CPPPATH', 'Additional preprocessor paths', '')
43 opts.Add('CPPFLAGS', 'Additional preprocessor flags', '')
44 opts.Add('CPPDEFINES', 'defined constants', '')
45 opts.Add('LIBPATH', 'Additional library paths', '')
46 opts.Add('LIBS', 'Additional libraries', '')
48 'destination directory for installation. It is prepended to PREFIX', '')
49 opts.Add('PREFIX', 'Installation prefix', '/usr/local')
50 opts.Add(EnumOption('VARIANT', 'Build variant', 'optimize',
51 ['optimize', 'debug', 'profile']))
53 env = Environment(options = opts)
55 if not os.path.exists("build_config.py"):
56 print "build_config.py doesn't exist - Generating new build config..."
58 conf = Configure(env, custom_tests = {
59 'CheckSDLConfig' : CheckSDLConfig
62 if not conf.CheckSDLConfig('1.2.4'):
63 print "Couldn't find libSDL >= 1.2.4"
65 if not conf.CheckLib('SDL_mixer'):
66 print "Couldn't find SDL_mixer library!"
68 if not conf.CheckLib('SDL_image'):
69 print "Couldn't find SDL_image library!"
71 if not conf.CheckLib('GL'):
72 print "Couldn't find OpenGL library!"
77 env.ParseConfig('sdl-config --cflags --libs')
78 env.Append(CPPDEFINES = \
79 {'DATA_PREFIX':"'\"" + env['PREFIX'] + "/share/supertux\"'" ,
80 'LOCALEDIR' :"'\"" + env['PREFIX'] + "/locales\"'"})
81 opts.Save("build_config.py", env)
83 print "Using build_config.py"
86 if env['VARIANT'] == "optimize":
87 env.Append(CXXFLAGS = "-O2 -g")
88 elif env['VARIANT'] == "debug":
89 env.Append(CXXFLAGS = "-O0 -g3")
90 env.Append(CPPDEFINES = { "DEBUG":"1" })
91 elif env['VARIANT'] == "profile":
92 env.Append(CXXFLAGS = "-pg -O2")
94 build_dir="build/" + env['PLATFORM'] + "/" + env['VARIANT']
96 env.Append(CPPPATH = ["#", "#/src", "#/lib"])
97 env.Append(LIBS = ["supertux"])
98 env.Append(LIBPATH=["#" + build_dir + "/lib"])
100 env.Export(["env", "Glob"])
101 env.SConscript("lib/SConscript", build_dir=build_dir + "/lib", duplicate=0)
102 env.SConscript("src/SConscript", build_dir=build_dir + "/src", duplicate=0)